bug #16797 [Filesystem] Recursivly widen non-executable directories (Slamdunk)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #16797).

Discussion
----------

[Filesystem] Recursivly widen non-executable directories

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | none
The `\FilesystemIterator` throws an `UnexpectedValueException` if the directory is non-executable.

Commits
-------

fb75651 [Filesystem] Recursivly widen non-executable directories
This commit is contained in:
Fabien Potencier 2015-12-18 18:05:30 +01:00
commit 0c2f1d94de
2 changed files with 19 additions and 3 deletions

View File

@ -177,12 +177,12 @@ class Filesystem
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
if (true !== @chmod($file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file %s', $file));
}
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
}
}

View File

@ -479,6 +479,22 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(753, $this->getFilePermissions($directory));
}
public function testChmodChangesZeroModeOnSubdirectoriesOnRecursive()
{
$this->markAsSkippedIfChmodIsMissing();
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
$subdirectory = $directory.DIRECTORY_SEPARATOR.'subdirectory';
mkdir($directory);
mkdir($subdirectory);
chmod($subdirectory, 0000);
$this->filesystem->chmod($directory, 0753, 0000, true);
$this->assertFilePermissions(753, $subdirectory);
}
public function testChown()
{
$this->markAsSkippedIfPosixIsMissing();