Skip to content

Commit b1e4613

Browse files
authored
Preserve permissions (#183)
* Preserve file permissions in BuildCommand::class * Test preserving file permissions
1 parent c7911df commit b1e4613

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Traits/CopiesToBuildDirectory.php

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public function copyToBuildDirectory(): bool
111111
} catch (Throwable $e) {
112112
warning('[WARNING] '.$e->getMessage());
113113
}
114+
115+
$perms = fileperms($item->getPathname());
116+
117+
if ($perms === false) {
118+
continue;
119+
}
120+
121+
chmod($target, $perms);
114122
}
115123

116124
$this->keepRequiredDirectories();

tests/Unit/CopyToBuildDirectoryTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,15 @@ protected function buildPath(string $path = ''): string
206206

207207
expect($required)->each->toBeFile();
208208
});
209+
210+
it('preserves file permissions', function () use ($sourcePath, $buildPath, $command) {
211+
createFiles("$sourcePath/file-under-test.txt");
212+
213+
chmod("$sourcePath/file-under-test.txt", octdec('0775'));
214+
215+
$originalPermissions = fileperms("$sourcePath/file-under-test.txt");
216+
217+
$command->copyToBuildDirectory();
218+
219+
expect(fileperms("$buildPath/file-under-test.txt"))->toBe($originalPermissions);
220+
});

0 commit comments

Comments
 (0)