diff --git a/src/ArtisanPatcher.php b/src/ArtisanPatcher.php index 0536718..83dc676 100644 --- a/src/ArtisanPatcher.php +++ b/src/ArtisanPatcher.php @@ -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.'); }