[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).
This commit is contained in:
parent
81b59b9eca
commit
8442ab1b99
@ -161,6 +161,12 @@ class Filesystem
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (true !== @unlink($file)) {
|
if (true !== @unlink($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 {
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
|
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
|
||||||
}
|
}
|
||||||
@ -168,6 +174,7 @@ class Filesystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change mode for an array of files or directories.
|
* Change mode for an array of files or directories.
|
||||||
|
Reference in New Issue
Block a user