From 58dd0b9cc948756a03adb4670046e7b114204d2f Mon Sep 17 00:00:00 2001 From: Nicole Cordes Date: Sun, 31 Jan 2016 14:41:28 +0100 Subject: [PATCH] [Filesystem] Try to delete broken symlinks If you delete the target of a symlink (at least on Windows systems) you don't get the kind of the target anymore (obviously). Therefore it might happen that a broken symlink to a directory should be removed with unlink() which fails. This patch adds another check for a broken symlink and tries to remove with rmdir() before throwing an exception. It helps to clean up test folders on Windows systems (so already proofed by the existing tests). --- src/Symfony/Component/Filesystem/Filesystem.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 8e96f1a87da8b..96b5c02192375 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -172,7 +172,14 @@ public function remove($files) } } else { if (true !== @unlink($file)) { - throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file); + // handle broken symlinks on Windows systems + if (is_link($file) && false === @readlink($file)) { + if (true !== @rmdir($file)) { + throw new IOException(sprintf('Failed to remove broken symlink "%s".', $file), 0, null, $file); + } + } else { + throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file); + } } } }