8000 [Filesystem] Consider the umask setting when dumping a file by leofeyer · Pull Request #19872 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Filesystem] Consider the umask setting when dumping a file #19872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
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());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also adjust the test case to test this behavior? (be aware of windows not having umask)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing I could adjust, because the Symfony unit test suite explicitly sets the umask to 0, so the expected file permissions in the tests will always be 666 on both Unix and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hboomsma Ah, I see. Thank you. 😄

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

Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
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