bug #24105 [Filesystem] check permissions if dump target dir is missing (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
-------

a0f9f2c537 check permissions if dump target dir is missing
This commit is contained in:
Fabien Potencier 2017-09-07 07:43:15 -07:00
commit d74144fc0b
3 changed files with 27 additions and 0 deletions

View File

@ -532,6 +532,16 @@ class Filesystem
$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);
}

View File

@ -1102,6 +1102,22 @@ class FilesystemTest extends FilesystemTestCase
$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();

View File

@ -61,6 +61,7 @@ class FilesystemTestCase extends TestCase
$this->longPathNamesWindows = array();
}
chmod($this->workspace, 0777);
$this->filesystem->remove($this->workspace);
umask($this->umask);
}