Skip to content

inconsistent behavior of removeDirectoryRecursive with symbolic links #15

Description

@Rufflewind

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: (1) bugThe described behavior is not working as intended.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions