Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make behavior of removeDirectoryRecursive more consistent
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`. The former is more elegant to implement but for backward compatibility `removeDirectoryRecursive` shall retain the Python-like behavior. Another function `removePathRecursive` was added to implement the POSIX behavior, although it is currently not exported.
- Loading branch information