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

Skip to content

Commit 0b58828

Browse files
author
Erik Trapman
committed
[FileSystem] remove symlinks under windows
1 parent 66ff060 commit 0b58828

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public function remove($files)
9494

9595
if (is_dir($file) && !is_link($file)) {
9696
$this->remove(new \FilesystemIterator($file));
97-
97+
rmdir($file);
98+
} elseif(is_dir($file) && is_link($file)) {
99+
// https://bugs.php.net/bug.php?id=52176 windows thinks symlinks are directories
98100
rmdir($file);
99101
} else {
100102
unlink($file);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,20 @@ public function testSymlink()
421421
$this->assertTrue(is_link($link));
422422
$this->assertEquals($file, readlink($link));
423423
}
424+
425+
/**
426+
* @depends testSymlink
427+
*/
428+
public function testRemoveSymlink()
429+
{
430+
$this->markAsSkippedIfSymlinkIsMissing();
431+
432+
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
433+
434+
$this->filesystem->remove($link);
435+
436+
$this->assertTrue(!is_link($link));
437+
}
424438

425439
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
426440
{

0 commit comments

Comments
 (0)