Skip to content

Commit 8442ab1

Browse files
IchHabRechtnicolas-grekas
authored andcommitted
[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).
1 parent 81b59b9 commit 8442ab1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,15 @@ public function remove($files)
161161
}
162162
} else {
163163
if (true !== @unlink($file)) {
164-
$error = error_get_last();
165-
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
164+
// handle broken symlinks on Windows systems
165+
if (is_link($file) && false === @readlink($file)) {
166+
if (true !== @rmdir($file)) {
167+
throw new IOException(sprintf('Failed to remove broken symlink "%s".', $file), 0, null, $file);
168+
}
169+
} else {
170+
$error = error_get_last();
171+
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
172+
}
166173
}
167174
}
168175
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy