Skip to content

Commit

Permalink
bug #14246 [Filesystem] dumpFile() negates default file permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidde Boomsma committed Jan 6, 2016
1 parent 5931ef7 commit 53d6d4b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -1076,7 +1076,7 @@ public function testDumpFile()

// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->assertFilePermissions(600, $filename);
$this->assertFilePermissions(666, $filename);
}
}

Expand Down

0 comments on commit 53d6d4b

Please sign in to comment.