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

Skip to content

Commit 0c2f1d9

Browse files
committed
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
2 parents f371445 + fb75651 commit 0c2f1d9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ public function remove($files)
177177
public function chmod($files, $mode, $umask = 0000, $recursive = false)
178178
{
179179
foreach ($this->toIterator($files) as $file) {
180-
if ($recursive && is_dir($file) && !is_link($file)) {
181-
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
182-
}
183180
if (true !== @chmod($file, $mode & ~$umask)) {
184181
throw new IOException(sprintf('Failed to chmod file %s', $file));
185182
}
183+
if ($recursive && is_dir($file) && !is_link($file)) {
184+
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
185+
}
186186
}
187187
}
188188

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,22 @@ public function testChmodChangesModeOfTraversableFileObject()
479479
$this->assertEquals(753, $this->getFilePermissions($directory));
480480
}
481481

482+
public function testChmodChangesZeroModeOnSubdirectoriesOnRecursive()
483+
{
484+
$this->markAsSkippedIfChmodIsMissing();
485+
486+
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
487+
$subdirectory = $directory.DIRECTORY_SEPARATOR.'subdirectory';
488+
489+
mkdir($directory);
490+
mkdir($subdirectory);
491+
chmod($subdirectory, 0000);
492+
493+
$this->filesystem->chmod($directory, 0753, 0000, true);
494+
495+
$this->assertFilePermissions(753, $subdirectory);
496+
}
497+
482498
public function testChown()
483499
{
484500
$this->markAsSkippedIfPosixIsMissing();

0 commit comments

Comments
 (0)