Skip to content

Mitigate dependency upon ConfigCache #7753

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

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
With dumpFile() in the Filesystem class, the mode must be a param.
Clients of ConfigCache are/were using 0666 & ~umask().
  • Loading branch information
mpdude committed Apr 21, 2013
commit 327befe5927f4a89b8b8a50eb6c41a9f2bb33c20
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class CompilerDebugDumpPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$filesystem = new Filesystem();
$filesystem->dumpFile($this->getCompilerLogFilename($container), implode("\n", $container->getCompiler()->getLog()));
$filesystem->dumpFile(
$this->getCompilerLogFilename($container),
implode("\n", $container->getCompiler()->getLog()),
0666 & ~umask()
);
}

public static function getCompilerLogFilename(ContainerInterface $container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$dumper = new XmlDumper($container);
$fs = new Filesystem();
$fs->dumpFile($container->getParameter('debug.container.dump'), $dumper->dump());
$filesystem = new Filesystem();
$filesystem->dumpFile(
$container->getParameter('debug.container.dump'),
$dumper->dump(),
0666 & ~umask()
);
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Config/ConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ public function isFresh()
*/
public function write($content, array $metadata = null)
{
$mode = 0666 & ~umask();
$filesystem = new Filesystem();
$filesystem->dumpFile($this->file, $content);
$filesystem->dumpFile($this->file, $content, $mode);

if (null !== $metadata && true === $this->debug) {
$filesystem->dumpFile($this->getMetaFile(), serialize($metadata));
$filesystem->dumpFile($this->getMetaFile(), serialize($metadata), $mode);
}
}
}
11 changes: 6 additions & 5 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,12 @@ private function toIterator($files)
/**
* Atomically dumps content into a file.
*
* @param string $filename The file to be written to.
* @param string $content The data to write into the file.
* @throws IOException If the file cannot be written to.
* @param string $filename The file to be written to.
* @param string $content The data to write into the file.
* @param integer $mode The file mode (octal).
* @throws IOException If the file cannot be written to.
*/
public function dumpFile($filename, $content)
public function dumpFile($filename, $content, $mode = 0666)
{
$dir = dirname($filename);

Expand All @@ -455,6 +456,6 @@ public function dumpFile($filename, $content)
}

$this->rename($tmpFile, $filename);
$this->chmod($filename, 0666, umask());
$this->chmod($filename, $mode);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how it was before, but wouldn't it be better to chmod() first before moving the file in place?

}
}