From 085e813936e0a04c54cc0fe5bae864ed79751651 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 3 Jan 2015 20:08:02 +0100 Subject: [PATCH] [Filesystem] keep exec perms when copying --- src/Symfony/Component/Filesystem/Filesystem.php | 6 ++---- .../Filesystem/Tests/FilesystemTest.php | 17 ++--------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 1d32b951e4..251b333d87 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -69,10 +69,8 @@ class Filesystem throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile); } - if (is_executable($originFile)) { - // User Executable | Group Executable | Other Executable - chmod($targetFile, fileperms($targetFile) | 0x0040 | 0x0008 | 0x0001); - } + // Like `cp`, preserve executable permission bits + @chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111)); if (stream_is_local($originFile) && $bytesCopied !== filesize($originFile)) { throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s %g bytes copied".', $originFile, $targetFile, $bytesCopied), 0, null, $originFile); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index bf682f8770..744aa8a544 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1002,23 +1002,10 @@ class FilesystemTest extends FilesystemTestCase $targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file'; file_put_contents($sourceFilePath, 'SOURCE FILE'); - chmod($sourceFilePath, 0755); + chmod($sourceFilePath, 0745); $this->filesystem->copy($sourceFilePath, $targetFilePath); - $this->assertFilePermissions(755, $targetFilePath); - } - - public function testCopyShouldNotKeepWritePermissionOtherThanCurrentUser() - { - $sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file'; - $targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file'; - - file_put_contents($sourceFilePath, 'SOURCE FILE'); - chmod($sourceFilePath, 0777); - - $this->filesystem->copy($sourceFilePath, $targetFilePath); - - $this->assertFilePermissions(755, $targetFilePath); + $this->assertFilePermissions(767, $targetFilePath); } }