The way removeDirectoryRecursive dir works right now is totally inconsistent:
- If there's a directory-like symbolic link, the function removes it without recursing into it, unless the symbolic link is not removable for some reason (e.g. no permission), in which case it recurses into it and wipes out everything inside.
- If
dir itself is actually a directory-like symbolic link, it will recurse into it but fail to remove dir itself.
The causes of these two problems are:
- Instead of explicitly checking whether path refers to a true directory, it assumes any unremovable file that also satisfies
directoryExists must necessarily be a directory. This is false, because directoryExists dereferences the symbolic link.
getDirectoryContents should not be called until dir is verified to be a true directory.
Note that there are two possible ways to handle the case where dir is not a true directory:
- One can delete it silently, similar to the behavior of the POSIX command
rm -r.
- Or one can raise an error, similar to the behavior of the Python function
shutil.rmtree.
See also:
The way
removeDirectoryRecursive dirworks right now is totally inconsistent:diritself is actually a directory-like symbolic link, it will recurse into it but fail to removediritself.The causes of these two problems are:
directoryExistsmust necessarily be a directory. This is false, becausedirectoryExistsdereferences the symbolic link.getDirectoryContentsshould not be called untildiris verified to be a true directory.Note that there are two possible ways to handle the case where
diris not a true directory:rm -r.shutil.rmtree.See also: