Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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