Skip to content

Commit d4243a2

Browse files
committed
[Filesystem] Fixed a bug in remove being unable to remove symlinks to unexisting file or directory.
1 parent 11a676d commit d4243a2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function remove($files)
8888
$files = iterator_to_array($this->toIterator($files));
8989
$files = array_reverse($files);
9090
foreach ($files as $file) {
91-
if (!file_exists($file)) {
91+
if (!file_exists($file) && !is_link($file)) {
9292
continue;
9393
}
9494

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,22 @@ public function testRemoveIgnoresNonExistingFiles()
297297
$this->assertTrue(!is_dir($basePath.'dir'));
298298
}
299299

300+
public function testRemoveCleansInvalidLinks()
301+
{
302+
$this->markAsSkippeIfSymlinkIsMissing();
303+
304+
$basePath = $this->workspace.DIRECTORY_SEPARATOR.'directory'.DIRECTORY_SEPARATOR;
305+
306+
mkdir($basePath);
307+
mkdir($basePath.'dir');
308+
// create symlink to unexisting file
309+
symlink($basePath.'file', $basePath.'link');
310+
311+
$this->filesystem->remove($basePath);
312+
313+
$this->assertTrue(!is_dir($basePath));
314+
}
315+
300316
public function testChmodChangesFileMode()
301317
{
302318
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';

0 commit comments

Comments
 (0)