8000 bug #19872 [Filesystem] Consider the umask setting when dumping a fil… · symfony/symfony@da565de · GitHub
[go: up one dir, main page]

Skip to content

Commit da565de

Browse files
committed
bug #19872 [Filesystem] Consider the umask setting when dumping a file (leofeyer)
This PR was merged into the 3.1 branch. Discussion ---------- [Filesystem] Consider the umask setting when dumping a file | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14246 , #17063 | License | MIT | Doc PR | - `Filesystem::dumpFile()` does not consider the umask setting and thus creates files with write permissions for everyone (`0666`). Other `chmod()` calls in Symfony do consider the umask setting (see e.g. [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/File/File.php#L101) or [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/File/UploadedFile.php#L230)), therefore I have adjusted the `dumpFile()` method accordingly. Commits ------- fdd266f Consider the umask setting when dumping a file.
2 parents c2b660d + fdd266f commit da565de

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ public function dumpFile($filename, $content)
556556
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
557557
}
558558

559-
// Ignore for filesystems that do not support umask
560-
@chmod($tmpFile, 0666);
559+
@chmod($tmpFile, 0666 & ~umask());
561560
$this->rename($tmpFile, $filename, true);
562561
}
563562

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,13 +1101,19 @@ public function testDumpFile()
11011101
{
11021102
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
11031103

1104+
// skip mode check on Windows
1105+
if ('\\' !== DIRECTORY_SEPARATOR) {
1106+
$oldMask = umask(0002);
1107+
}
1108+
11041109
$this->filesystem->dumpFile($filename, 'bar');
11051110
$this->assertFileExists($filename);
11061111
$this->assertSame('bar', file_get_contents($filename));
11071112

11081113
// skip mode check on Windows
11091114
if ('\\' !== DIRECTORY_SEPARATOR) {
1110-
$this->assertFilePermissions(666, $filename);
1115+
$this->assertFilePermissions(664, $filename);
1116+
umask($oldMask);
11111117
}
11121118
}
11131119

0 commit comments

Comments
 (0)
0