From fdd266f28e256bdbb15c0fc0fe1d1d05ce310ebe Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Tue, 6 Sep 2016 15:46:21 +0200 Subject: [PATCH] Consider the umask setting when dumping a file. --- src/Symfony/Component/Filesystem/Filesystem.php | 3 +-- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 72ab9bf8cf17..5a6f009f8afb 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -554,8 +554,7 @@ public function dumpFile($filename, $content) throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename); } - // Ignore for filesystems that do not support umask - @chmod($tmpFile, 0666); + @chmod($tmpFile, 0666 & ~umask()); $this->rename($tmpFile, $filename, true); } diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 9a65543098d7..58523c22154c 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1101,13 +1101,19 @@ public function testDumpFile() { $filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt'; + // skip mode check on Windows + if ('\\' !== DIRECTORY_SEPARATOR) { + $oldMask = umask(0002); + } + $this->filesystem->dumpFile($filename, 'bar'); $this->assertFileExists($filename); $this->assertSame('bar', file_get_contents($filename)); // skip mode check on Windows if ('\\' !== DIRECTORY_SEPARATOR) { - $this->assertFilePermissions(666, $filename); + $this->assertFilePermissions(664, $filename); + umask($oldMask); } }