From 53d6d4b5b36854c3867e503c8468795b01ca9faf Mon Sep 17 00:00:00 2001 From: Hidde Boomsma Date: Fri, 18 Dec 2015 12:43:50 +0100 Subject: [PATCH] bug #14246 [Filesystem] dumpFile() negates default file permissions --- src/Symfony/Component/Filesystem/Filesystem.php | 4 ++++ src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 522aacca64eb..f6c3b63f28fb 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -522,12 +522,16 @@ public function dumpFile($filename, $content) throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir); } + // Will create a temp file with 0600 access rights + // when the filesystem supports chmod. $tmpFile = $this->tempnam($dir, basename($filename)); if (false === @file_put_contents($tmpFile, $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); $this->rename($tmpFile, $filename, true); } diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 7843df435396..43838c76d217 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1076,7 +1076,7 @@ public function testDumpFile() // skip mode check on Windows if ('\\' !== DIRECTORY_SEPARATOR) { - $this->assertFilePermissions(600, $filename); + $this->assertFilePermissions(666, $filename); } }