Implement escaping to allow clean -p to delete all files when directory contains glob characters#10072
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon. Please see the contribution instructions for more information. |
|
Ah, you need to make sure to escape only the part of the path that isn't intended to be a pattern. The code that calls |
Sorry about that! I was under the impression that only I could see draft PR's... I just pushed the correct solution. Here's the output of running your script on my machine: ➜ cargo_test rm -rf glob-in-rm && ./reproduce.sh
~/Projects/cargo_test/glob-in-rm/hello ~/Projects/cargo_test/glob-in-rm
Created binary (application) `foo` package
Checking foo v0.1.0 (/Users/russweas/Projects/cargo_test/glob-in-rm/hello/foo)
Finished dev [unoptimized + debuginfo] target(s) in 0.65s
~/Projects/cargo_test/glob-in-rm
~/Projects/cargo_test/glob-in-rm/[hello] ~/Projects/cargo_test/glob-in-rm
Created binary (application) `foo` package
Checking foo v0.1.0 (/Users/russweas/Projects/cargo_test/glob-in-rm/[hello]/foo)
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
~/Projects/cargo_test/glob-in-rm
Files [hello]/foo/target/.rustc_info.json and hello/foo/target/.rustc_info.json differ |
|
Nice! Draft PRs are visible to everyone, they are just marked as "not ready to merge". The idea of a draft PR is to get feedback on work that's not yet completed, or just to have a place to allow discussion on a fix before it's done. I think it was totally fine to open this as a draft :) |
Now I know 😆. At my internship I used draft PR's like a Todo list of things I was working on, so I would make a tiny change then push it. |
|
Note: would also need to incorporate these changes into #10070 cargo/src/cargo/ops/cargo_clean.rs Lines 176 to 184 in 2f375da |
|
Tests passed, pushed final commit to undo superfluous formatting changes |
|
Thanks for this! Would you be up for adding some tests for this as well? |
|
@alexcrichton @jonhoo Test added! LMK if I need more coverage, but I think this + existing tests should cover everything. The only other thing I can think of is checking for each kind of build artifact, but I feel that's already covered in other tests, since all this PR changed is top-level glob escaping. |
|
And just squashed the commits, I noticed it was getting excessive |
|
Looks like the test works on |
Implement glob escaping for clean -p Add pattern escape for glob matching cargo clean files Implement correct solution for rust-lang#10068 Removed superfluous formatting changes Update rm_rf_glob()'s error handling Remove dir_glob reference for non-glob function Added test Satisfy clippy Add MSVC support for test
|
@bors: r+ Thanks! |
|
📌 Commit effc720 has been approved by |
|
☀️ Test successful - checks-actions |
Update cargo 11 commits in 2e2a16e983f597da62bc132eb191bc3276d4b1bb..ad50d0d266213e0cc4f6e526a39d96faae9a3842 2021-11-08 15:13:38 +0000 to 2021-11-17 18:36:37 +0000 - Warn when alias shadows external subcommand (rust-lang/cargo#10082) - Implement escaping to allow clean -p to delete all files when directory contains glob characters (rust-lang/cargo#10072) - Match any error when failing to find executables (rust-lang/cargo#10092) - Enhance error message for target auto-discovery (rust-lang/cargo#10090) - Include note about bug while building on macOS in mdbook (rust-lang/cargo#10073) - Improve the help text of the --quiet args for all commands (rust-lang/cargo#10080) - `future-incompat-report` checks both stdout and stderr for color support (rust-lang/cargo#10024) - Remove needless borrow to make clippy happy (rust-lang/cargo#10081) - Describe the background color of the timing graph (rust-lang/cargo#10076) - Make ProfileChecking comments a doc comments (rust-lang/cargo#10077) - Fix test: hash value depends on endianness and bitness. (rust-lang/cargo#10011)
Closes #10068.
Runs
glob::Pattern::escapeon path input torm_rf_glob(). This fixes a bug in whichcargo clean -pfails to delete a number of files fromtarget/if the path to target contains glob characters.