Skip to content

Commit 48b4bcf

Browse files
committed
bug #17063 bug #14246 [Filesystem] dumpFile() negates default file permissions (Hidde Boomsma)
This PR was merged into the 3.0 branch. Discussion ---------- bug #14246 [Filesystem] dumpFile() negates default file permissions | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14246 | License | MIT | Doc PR | none Remain BC compatible with Symfony 2.8. Without this change a chmod is needed after calling `dumpFile`, making it non atomic. Commits ------- 53d6d4b bug #14246 [Filesystem] dumpFile() negates default file permissions
2 parents d14eae4 + 53d6d4b commit 48b4bcf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

+4
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,16 @@ public function dumpFile($filename, $content)
522522
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
523523
}
524524

525+
// Will create a temp file with 0600 access rights
526+
// when the filesystem supports chmod.
525527
$tmpFile = $this->tempnam($dir, basename($filename));
526528

527529
if (false === @file_put_contents($tmpFile, $content)) {
528530
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
529531
}
530532

533+
// Ignore for filesystems that do not support umask
534+
@chmod($tmpFile, 0666);
531535
$this->rename($tmpFile, $filename, true);
532536
}
533537

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ public function testDumpFile()
10761076

10771077
// skip mode check on Windows
10781078
if ('\\' !== DIRECTORY_SEPARATOR) {
1079-
$this->assertFilePermissions(600, $filename);
1079+
$this->assertFilePermissions(666, $filename);
10801080
}
10811081
}
10821082

0 commit comments

Comments
 (0)