Preserve artisan file permissions

This commit is contained in:
2026-07-12 22:38:45 +01:00
parent f3fa1f73af
commit eea101b167
+9
View File
@@ -150,12 +150,21 @@ class ArtisanPatcher
private function write(string $contents): void
{
$temporaryPath = $this->artisanPath.'.british-artisan.tmp';
$permissions = fileperms($this->artisanPath);
if ($permissions === false) {
throw new RuntimeException('Could not read the artisan file permissions.');
}
try {
if (file_put_contents($temporaryPath, $contents, LOCK_EX) === false) {
throw new RuntimeException('Could not write the temporary artisan file.');
}
if (! chmod($temporaryPath, $permissions & 0777)) {
throw new RuntimeException('Could not preserve the artisan file permissions.');
}
if (! rename($temporaryPath, $this->artisanPath)) {
throw new RuntimeException('Could not replace the artisan file.');
}