Skip to content

Commit

Permalink
minor #21902 [Filesystem] respect the umask argument in dumpFile() (x…
Browse files Browse the repository at this point in the history
…abbuh)

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()
  • Loading branch information
fabpot committed Mar 6, 2017
2 parents c91db73 + 3a7cd08 commit fda2472
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -516,8 +516,8 @@ public function dumpFile($filename, $content, $mode = 0666)
}

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

$this->rename($tmpFile, $filename, true);
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -1050,6 +1050,19 @@ public function testDumpFileOverwritesAnExistingFile()
$this->assertSame('bar', file_get_contents($filename));
}

public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
{
$this->markAsSkippedIfChmodIsMissing();

$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo.txt';
file_put_contents($filename, 'FOO BAR');
chmod($filename, 0745);

$this->filesystem->dumpFile($filename, 'bar', null);

$this->assertFilePermissions(745, $filename);
}

public function testCopyShouldKeepExecutionPermission()
{
$this->markAsSkippedIfChmodIsMissing();
Expand Down

0 comments on commit fda2472

Please sign in to comment.