From eea101b1675233a1a6aee8a73da47b61466a9012 Mon Sep 17 00:00:00 2001 From: Seb Molenaar Date: Sun, 12 Jul 2026 22:38:45 +0100 Subject: [PATCH] Preserve artisan file permissions --- src/ArtisanPatcher.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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.'); }