Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d74144f

Browse filesBrowse files
committed
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 ------- a0f9f2c check permissions if dump target dir is missing
2 parents 2b79f48 + a0f9f2c commit d74144f
Copy full SHA for d74144f

File tree

3 files changed

+27
-0
lines changed
Filter options

3 files changed

+27
-0
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,16 @@ public function dumpFile($filename, $content, $mode = 0666)
532532
$dir = dirname($filename);
533533

534534
if (!is_dir($dir)) {
535+
$oldCwd = getcwd();
536+
537+
if (!@chdir(dirname($dir))) {
538+
// When the parent directory misses the executable permission bit, we are unable to enter it and thus
539+
// cannot check if the target directory exists.
540+
throw new IOException(sprintf('Unable to detect if the target directory "%s" exists.', $dir));
541+
}
542+
543+
chdir($oldCwd);
544+
535545
$this->mkdir($dir);
536546
}
537547

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,22 @@ public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
11021102
$this->assertFilePermissions(745, $filename);
11031103
}
11041104

1105+
/**
1106+
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
1107+
* @expectedExceptionMessageRegExp /^Unable to detect if the target directory ".*" exists\.$/
1108+
*/
1109+
public function testDumpFailsWithExceptionIfExecutablePermissionsForTheParentDirectoryAreMissing()
1110+
{
1111+
$this->markAsSkippedIfChmodIsMissing();
1112+
1113+
$target = $this->workspace.DIRECTORY_SEPARATOR.'foo';
1114+
$file = $target.DIRECTORY_SEPARATOR.'foobar';
1115+
mkdir($target);
1116+
chmod($this->workspace, 0666);
1117+
1118+
$this->filesystem->dumpFile($file, 'baz');
1119+
}
1120+
11051121
public function testCopyShouldKeepExecutionPermission()
11061122
{
11071123
$this->markAsSkippedIfChmodIsMissing();

‎src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected function tearDown()
6161
$this->longPathNamesWindows = array();
6262
}
6363

64+
chmod($this->workspace, 0777);
6465
$this->filesystem->remove($this->workspace);
6566
umask($this->umask);
6667
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.