← Back to context

Comment by makecheck

7 years ago

Recursive delete has always been a misfeature of computing, out of a mistaken entitlement to convenience when you are performing a fundamentally risky operation on a target you can never know the state of.

At best, it is redundant with a recursive search feature that chooses “delete” as the operation. And if you want “do something else then delete”, you can no longer call a recursive-delete command anyway so why not just learn how to enumerate files first and give your system a fighting chance to audit first?

Disk cleanup code should always create lists of known target files, attempt to delete only that list of files, then do the platform equivalent of “rmdir” at the end to attempt to remove the directory. If that fails, congratulations: your ass was saved by not deleting something you didn’t know was there.