This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gently-rm: swap checks & match target, not source
Fixes #7579. We want to know two things with gently-rm: 1. Is the parent directory under npm's control? (1a. Is the thing to be deleted under that parent directory if so?) 2. Is the thing to be deleted under npm's control? There are some additional complications, but that's the core of it, so to make clearer what was going on, I rearranged the code to prioritize answering those two questions, and added a bunch of comments explaining what's happening in an effort that that would make clearer *why* the code is written the way it is. When npm removes a file or directory, it verifies whether the thing being removed is under npm's control. This isn't something that can be ascertained directly, so gentlyRm checks to see if there's a plausible case that this file was something that was originally installed by npm. Mostly it just verifies whether either the deletion target or the parent directory (which could be passed in as the base, or could be the prefix otherwise) is under one of the paths that npm might have reason to mess with. It will also deal with a certain amount of symbolic link trickery, but symlink verification was overly aggressive before, and has been eased up some.
- Loading branch information