[Filesystem] Fixed a bug in remove being unable to remove symlinks to unexisting file or directory.

This commit is contained in:
Jakub Zalas 2012-04-07 00:01:32 +01:00
parent 11a676d672
commit d4243a28b6
2 changed files with 17 additions and 1 deletions

View File

@ -88,7 +88,7 @@ class Filesystem
$files = iterator_to_array($this->toIterator($files));
$files = array_reverse($files);
foreach ($files as $file) {
if (!file_exists($file)) {
if (!file_exists($file) && !is_link($file)) {
continue;
}

View File

@ -297,6 +297,22 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(!is_dir($basePath.'dir'));
}
public function testRemoveCleansInvalidLinks()
{
$this->markAsSkippeIfSymlinkIsMissing();
$basePath = $this->workspace.DIRECTORY_SEPARATOR.'directory'.DIRECTORY_SEPARATOR;
mkdir($basePath);
mkdir($basePath.'dir');
// create symlink to unexisting file
symlink($basePath.'file', $basePath.'link');
$this->filesystem->remove($basePath);
$this->assertTrue(!is_dir($basePath));
}
public function testChmodChangesFileMode()
{
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';