Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed regression when using Symfony on filesystems without chmod support #10532

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 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class CompilerDebugDumpPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$filename = self::getCompilerLogFilename($container);

$filesystem = new Filesystem();
$filesystem->dumpFile(
self::getCompilerLogFilename($container),
implode("\n", $container->getCompiler()->getLog()),
0666 & ~umask()
);
$filesystem->dumpFile($filename, implode("\n", $container->getCompiler()->getLog()), null);
// discard chmod failure (some filesystem may not support it)
@chmod($filename, 0666 & ~umask());
}

public static function getCompilerLogFilename(ContainerInterface $container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$dumper = new XmlDumper($container);
$filename = $container->getParameter('debug.container.dump');
$filesystem = new Filesystem();
$filesystem->dumpFile(
$container->getParameter('debug.container.dump'),
$dumper->dump(),
0666 & ~umask()
);
$filesystem->dumpFile($filename, $dumper->dump(), null);
// discard chmod failure (some filesystem may not support it)
@chmod($filename, 0666 & ~umask());
}
}
6 changes: 4 additions & 2 deletions src/Symfony/Component/Config/ConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ public function write($content, array $metadata = null)
{
$mode = 0666 & ~umask();
$filesystem = new Filesystem();
$filesystem->dumpFile($this->file, $content, $mode);
$filesystem->dumpFile($this->file, $content, null);
@chmod($this->file, $mode);

if (null !== $metadata && true === $this->debug) {
$filesystem->dumpFile($this->getMetaFile(), serialize($metadata), $mode);
$filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
@chmod($this->getMetaFile(), $mode);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Filesystem/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.3.12
------

* deprecated dumpFile() file mode argument.

2.3.0
-----

Expand Down
13 changes: 8 additions & 5 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,11 @@ 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.
* @param integer $mode The file mode (octal).
* @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 null|integer $mode The file mode (octal). If null, file permissions are not modified
* Deprecated since version 2.3.12, to be removed in 3.0.
* @throws IOException If the file cannot be written to.
*/
public function dumpFile($filename, $content, $mode = 0666)
{
Expand All @@ -466,6 +467,8 @@ public function dumpFile($filename, $content, $mode = 0666)
}

$this->rename($tmpFile, $filename, true);
$this->chmod($filename, $mode);
if (null !== $mode) {
$this->chmod($filename, $mode);
}
}
}
15 changes: 15 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,21 @@ public function testDumpFile()
}
}

public function testDumpFileWithNullMode()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';

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

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

// skip mode check on Windows
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
$this->assertEquals(600, $this->getFilePermissions($filename));
}
}

public function testDumpFileOverwritesAnExistingFile()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo.txt';
Expand Down