8000 minor #21902 [Filesystem] respect the umask argument in dumpFile() (x… · symfony/symfony@fda2472 · GitHub
[go: up one dir, main page]

Skip to content

Commit fda2472

Browse files
committed
minor #21902 [Filesystem] respect the umask argument in dumpFile() (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [Filesystem] respect the umask argument in dumpFile() | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21823 | License | MIT | Doc PR | In #21823 we introduced a small BC break: The `dumpFile()` method of the `Filesystem` class allowed to pass the desired file permissions (support for this feature was dropped in Symfony 3.0). Commits ------- 3a7cd08 respect the umask argument in dumpFile()
2 parents c91db73 + 3a7cd08 commit fda2472

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ public function dumpFile($filename, $content, $mode = 0666)
516516
}
517517

518518
$this->chmod($tmpFile, $mode);
519-
} else {
520-
@chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());
519+
} elseif (file_exists($filename)) {
520+
@chmod($tmpFile, fileperms($filename));
521521
}
522522

523523
$this->rename($tmpFile, $filename, true);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,19 @@ public function testDumpFileOverwritesAnExistingFile()
10501050
$this->assertSame('bar', file_get_contents($filename));
10511051
}
10521052

1053+
public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
1054+
{
1055+
$this->markAsSkippedIfChmodIsMissing();
1056+
1057+
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo.txt';
1058+
file_put_contents($filename, 'FOO BAR');
1059+
chmod($filename, 0745);
1060+
1061+
$this->filesystem->dumpFile($filename, 'bar', null);
1062+
1063+
$this->assertFilePermissions(745, $filename);
1064+
}
1065+
10531066
public function testCopyShouldKeepExecutionPermission()
10541067
{
10551068
$this->markAsSkippedIfChmodIsMissing();

0 commit comments

Comments
 (0)
0