fix: use remove_dir_all in cargo clean to resolve race condition#11442
fix: use remove_dir_all in cargo clean to resolve race condition#11442bors merged 5 commits intorust-lang:masterfrom
remove_dir_all in cargo clean to resolve race condition#11442Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. Please see the contribution instructions for more information. |
weihanglo
left a comment
There was a problem hiding this comment.
I believe it might introduce a bit more readdir calls underneath the hood, though I am fine with that. It was using remove_dir_all back to the day before this got merged.
I had vague memories of another PR related to it but it just touched test code (#11333). The thing that doesn't quite feel right to me is that this feels like a hack: "If new contents are added to the "removed" directory, let's try removing the contents again". How many "agains" are sufficient?. This is inherently a race condition that we can't win theoretically though we might be able to make it work practically. I'm just wondering if its an effort that is worth it. |
My original point is back in the day Cargo didn't have a progress bar for Just give a data from mine: I use |
It did a This brings up an interesting thought: This change is effectively a |
|
Apparently this is also hitting Windows: brson/wasm-opt-rs#116 (comment) And the rabbit hole goes deep: rust-lang/rust#29497 Would it make sense to accept that removing contents and then calling In which case, |
|
Note that, as far as I know, But yeah, |
|
r? @weihanglo |
It is only a naive filesystem walk and remove. The purpose of Cargo doing this is to display the progress bar if needed and show info in verbose mode. There might be ways to improve but I don't see any alternative can remove @trevyn. The question epage raised might need a response to clarify in what situation a remove failure needs a recovery. I don't have a particular preference though.
|
|
@weihanglo the cargo way has better progress bar and error messaging which is great. The standard library can't offer that currently (though I would like to expose some of the primitives so crates can build upon them in the future). But I was more responding to @epage concern that this would be basically just a |
|
FWIW I'm very happy to work with folk to extend the |
|
Two other thoughts. The 0.5 and lower versions of the If programs work with So one possible approach would be to :
This would cause new compilations to operate in a fresh directory, and should be quite robust. We could put this back in the |
Agree with @epage on this. Ran into this issue, #11441 Given a similar issue is in #11872 Root cause is clearly not MacOS related (still stumped why .DS_Store appeared in my target directory).
All clearly seem to fail on multiple platforms without logging a proper error. std::remove_dir should panic here IMO. It doesn't. Adding panics to cargo clean is the wrong level of abstraction. Fixing As per #11441 (comment), the Finder issue was impossible for me to replicate. |
|
@weihanglo : To address @epage 's question:
in light of @ChrisDenton 's observation that:
I've added a fallback from Please let me know if this is suitable, and if you have any other concerns! |
I've not refreshed myself on the context of this PR but if there is a stronger variant for us to fallback to that will do the right thing for us with maybe some degraded quality of experience, that makes sense to me. |
weihanglo
left a comment
There was a problem hiding this comment.
Thanks.
As a side note, we still look for a better way around remove_dir_all. The performance of the ad-hoc implementation in Cargo is not pretty good, especially for walking the filesystem.
|
@bors r+ |
remove_dir_allremove_dir_all in cargo clean to resolve race condition
|
☀️ Test successful - checks-actions |
Update cargo 14 commits in f7b95e31642e09c2b6eabb18ed75007dda6677a0..b0fa79679e717cd077b7fc0fa4166f47107f1ba9 2023-05-30 19:25:02 +0000 to 2023-06-03 14:19:48 +0000 - Emit error when users try to use a toolchain via the `add` or `install` command (rust-lang/cargo#12226) - Support "default" option for `build.jobs` (rust-lang/cargo#12222) - Fix typo in changelog (rust-lang/cargo#12227) - chore: Sort `-Z` flags match statement (rust-lang/cargo#12223) - Update curl-sys (rust-lang/cargo#12218) - Bump to 0.73.0; update changelog (rust-lang/cargo#12219) - refactor: housekeeping for 1.70.0 (rust-lang/cargo#12217) - nit: fix typo in changelog for 1.70 (rust-lang/cargo#12215) - Remove a noop `.clone` (rust-lang/cargo#12213) - refactor: compiler invocations (rust-lang/cargo#12211) - cargo clean: use `remove_dir_all` (rust-lang/cargo#11442) - Add a small note about indexes ignoring SemVer build metadata. (rust-lang/cargo#12206) - Revert "chore: detect the channel a PR wants to merge into" (rust-lang/cargo#12204) - Don't distinguish `Debuginfo::None` and `Debuginfo::Explicit(None)` (rust-lang/cargo#12205) r? `@ghost`
Update cargo 14 commits in f7b95e31642e09c2b6eabb18ed75007dda6677a0..b0fa79679e717cd077b7fc0fa4166f47107f1ba9 2023-05-30 19:25:02 +0000 to 2023-06-03 14:19:48 +0000 - Emit error when users try to use a toolchain via the `add` or `install` command (rust-lang/cargo#12226) - Support "default" option for `build.jobs` (rust-lang/cargo#12222) - Fix typo in changelog (rust-lang/cargo#12227) - chore: Sort `-Z` flags match statement (rust-lang/cargo#12223) - Update curl-sys (rust-lang/cargo#12218) - Bump to 0.73.0; update changelog (rust-lang/cargo#12219) - refactor: housekeeping for 1.70.0 (rust-lang/cargo#12217) - nit: fix typo in changelog for 1.70 (rust-lang/cargo#12215) - Remove a noop `.clone` (rust-lang/cargo#12213) - refactor: compiler invocations (rust-lang/cargo#12211) - cargo clean: use `remove_dir_all` (rust-lang/cargo#11442) - Add a small note about indexes ignoring SemVer build metadata. (rust-lang/cargo#12206) - Revert "chore: detect the channel a PR wants to merge into" (rust-lang/cargo#12204) - Don't distinguish `Debuginfo::None` and `Debuginfo::Explicit(None)` (rust-lang/cargo#12205) r? `@ghost`
Fixes #11441