Skip to content

Commit

Permalink
bug #24105 [Filesystem] check permissions if dump target dir is missi…
Browse files Browse the repository at this point in the history
…ng (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Filesystem] check permissions if dump target dir is missing

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24097
| License       | MIT
| Doc PR        |

`is_dir()` returns `false` if the parent directory misses the executable
bit even when the directory itself is present.

Commits
-------

a0f9f2c check permissions if dump target dir is missing
  • Loading branch information
fabpot committed Sep 7, 2017
2 parents 2b79f48 + a0f9f2c commit d74144f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -532,6 +532,16 @@ public function dumpFile($filename, $content, $mode = 0666)
$dir = dirname($filename);

if (!is_dir($dir)) {
$oldCwd = getcwd();

if (!@chdir(dirname($dir))) {
// When the parent directory misses the executable permission bit, we are unable to enter it and thus
// cannot check if the target directory exists.
throw new IOException(sprintf('Unable to detect if the target directory "%s" exists.', $dir));
}

chdir($oldCwd);

$this->mkdir($dir);
}

Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -1102,6 +1102,22 @@ public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
$this->assertFilePermissions(745, $filename);
}

/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
* @expectedExceptionMessageRegExp /^Unable to detect if the target directory ".*" exists\.$/
*/
public function testDumpFailsWithExceptionIfExecutablePermissionsForTheParentDirectoryAreMissing()
{
$this->markAsSkippedIfChmodIsMissing();

$target = $this->workspace.DIRECTORY_SEPARATOR.'foo';
$file = $target.DIRECTORY_SEPARATOR.'foobar';
mkdir($target);
chmod($this->workspace, 0666);

$this->filesystem->dumpFile($file, 'baz');
}

public function testCopyShouldKeepExecutionPermission()
{
$this->markAsSkippedIfChmodIsMissing();
Expand Down
Expand Up @@ -61,6 +61,7 @@ protected function tearDown()
$this->longPathNamesWindows = array();
}

chmod($this->workspace, 0777);
$this->filesystem->remove($this->workspace);
umask($this->umask);
}
Expand Down

0 comments on commit d74144f

Please sign in to comment.