Skip to content

Commit

Permalink
Consider the umask setting when dumping a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 8, 2016
1 parent be4255e commit fdd266f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -554,8 +554,7 @@ public function dumpFile($filename, $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);
@chmod($tmpFile, 0666 & ~umask());
$this->rename($tmpFile, $filename, true);
}

Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -1101,13 +1101,19 @@ public function testDumpFile()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';

// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$oldMask = umask(0002);
}

$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertSame('bar', file_get_contents($filename));

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

Expand Down

0 comments on commit fdd266f

Please sign in to comment.