From 3a7cd08fe7bc628b4b896f40fd572b59af631d73 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 6 Mar 2017 19:56:39 +0100 Subject: [PATCH] respect the umask argument in dumpFile() --- src/Symfony/Component/Filesystem/Filesystem.php | 4 ++-- .../Component/Filesystem/Tests/FilesystemTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 16d83dc2e5..3a5e332b9e 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -516,8 +516,8 @@ class Filesystem } $this->chmod($tmpFile, $mode); - } else { - @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask()); + } elseif (file_exists($filename)) { + @chmod($tmpFile, fileperms($filename)); } $this->rename($tmpFile, $filename, true); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 4f7457898b..f879e64170 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1050,6 +1050,19 @@ class FilesystemTest extends FilesystemTestCase $this->assertSame('bar', file_get_contents($filename)); } + public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile() + { + $this->markAsSkippedIfChmodIsMissing(); + + $filename = $this->workspace.DIRECTORY_SEPARATOR.'foo.txt'; + file_put_contents($filename, 'FOO BAR'); + chmod($filename, 0745); + + $this->filesystem->dumpFile($filename, 'bar', null); + + $this->assertFilePermissions(745, $filename); + } + public function testCopyShouldKeepExecutionPermission() { $this->markAsSkippedIfChmodIsMissing();