• (nodebb)

    Frist,

    Also, it takes three parameters and uses one of them.

    As you see in the next snippet, it's an exception handler that's used with shutil.rmtree, so that's the parameter list it needs.

  • DanielOfMyr (unregistered)

    I'm curious about how and where this code is used

  • (nodebb) in reply to Dragnslcr

    Possibly it should do something with those parameters, though. The current logic is "if there's an error deleting a file, add write permission, and then delete it again". I don't think that will work anyway - IIRC you need write permission to the directory containing the file, not write permission to the file itself, to delete it. And if the error is due to something other than the file not being writable, deleting it again will still fail.

  • (nodebb) in reply to SteelCamel2

    IIRC you need write permission to the directory containing the file, not write permission to the file itself, to delete it

    In my experience, you need both write permissions (to the file and to the directory that contains the name that you want to delete(1).

    (1) That's not a circumlocution. If you want to delete the file, you have to delete all of its hard links.

  • jmeh (unregistered)

    I like the name safe_rmtree on it's own. It's like "safe chainsaw", no it's not. If it does what it is supposed to it isn't safe. The whole bit about minimum depth is probably to make it really hard to remove a top level directory. I guess he did it by accident at some point and decided to add this as a safe guard.

    As for the sleep(0.1) the idea is probably to give the file system time to flush changes to disk. Wrong way to do it but might make the program run better after deleting a big tree, particularly if the code is old enough to be running on a mechanical hard disk.

  • Brian (unregistered)
    Comment held for moderation.

Leave a comment on “Brillant Python Programmers”

Log In or post as a guest

Replying to comment #690973:

« Return to Article