Skip to content

cargo clean: Validate that target_dir is not a file #16765

Merged
weihanglo merged 2 commits intorust-lang:masterfrom
TanmayArya-1p:target-dir-not-file
Mar 20, 2026
Merged

cargo clean: Validate that target_dir is not a file #16765
weihanglo merged 2 commits intorust-lang:masterfrom
TanmayArya-1p:target-dir-not-file

Conversation

@TanmayArya-1p
Copy link
Contributor

@TanmayArya-1p TanmayArya-1p commented Mar 19, 2026

As discussed in #16712 , this is a separate PR that adds validation to cargo clean to make sure target-dir is not a file

Tests:

  • Added unit tests for when target-dir is found to be a file.
  • I also noticed that there was no unit test asserting the expected behaviour discussed in cargo clean when target is a symlink only deletes symlink #7510 (comment) when the target-dir is a symlink. I added a unit test that asserts that when the target-dir is a symlink, cargo should just delete the symlink and should not delete the content it is pointing to.

@TanmayArya-1p
Copy link
Contributor Author

In the other PR(#16712 ), some cases i didn't consider that might break scripts:

  • cargo clean --target-dir non-existent-path - Current behaviour: runs without errors and reports that it removed 0 files.
  • cargo clean --target-dir symlink-path - Current behaviour: as discussed here , cargo just deletes the symlink regardless of what it points to.

Both of these had a behaviour change in the other PR. In this PR i've made them preserve cargo's current behaviour.

@weihanglo
Copy link
Member

In the other PR(#16712 ), some cases i didn't consider that might break scripts:

  • cargo clean --target-dir non-existent-path - Current behaviour: runs without errors and reports that it removed 0 files.
  • cargo clean --target-dir symlink-path - Current behaviour: as discussed here , cargo just deletes the symlink regardless of what it points to.

Both of these had a behaviour change in the other PR. In this PR i've made them preserve cargo's current behaviour.

Sounds reasonable to me as an incremental improvement!

@TanmayArya-1p TanmayArya-1p marked this pull request as ready for review March 20, 2026 12:41
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weihanglo weihanglo added this pull request to the merge queue Mar 20, 2026
Merged via the queue into rust-lang:master with commit d817355 Mar 20, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2026
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Mar 20, 2026
Update cargo submodule

13 commits in cbb9bb8bd0fb272b1be0d63a010701ecb3d1d6d3..d81735547e5f2844322f36380ab66f549cda11b9
2026-03-13 14:34:16 +0000 to 2026-03-20 13:20:51 +0000
- cargo clean: Validate that target_dir is not a file  (rust-lang/cargo#16765)
- fix: fetching non-standard git refspecs on non-github repos (rust-lang/cargo#16768)
- Update tar to 0.4.45 (rust-lang/cargo#16771)
- chore: Remove edition_lint_opts from Lint (rust-lang/cargo#16762)
- refactor: split out several smaller changes to prepare for async http (rust-lang/cargo#16763)
- fix(compile): Make build.warnings ignore non-local deps (rust-lang/cargo#16760)
- fix: detect circular publish dependency cycle in workspace publish (rust-lang/cargo#16722)
- refactor(shell): Pull out term integration into `anstyle-progress` (rust-lang/cargo#16757)
- test: reproduce rustfix panic on overlapping suggestions (rust-lang/cargo#16705)
- fix: Avoid panic for package specs with an empty fragment (rust-lang/cargo#16754)
- refactor(registry): avoid dynamic dispatch for Registry trait (rust-lang/cargo#16752)
- refactor(shell): Pull out hyperlink logic into anstyle-hyperlink (rust-lang/cargo#16749)
- refactor(install): Remove dead code (rust-lang/cargo#16718)

r? ghost
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Mar 21, 2026
Update cargo submodule

14 commits in cbb9bb8bd0fb272b1be0d63a010701ecb3d1d6d3..e84cb639edfea2c42efd563b72a9be0cc5de6523
2026-03-13 14:34:16 +0000 to 2026-03-21 01:27:07 +0000
- Fix symlink_and_directory when running in a long target dir name (rust-lang/cargo#16775)
- cargo clean: Validate that target_dir is not a file  (rust-lang/cargo#16765)
- fix: fetching non-standard git refspecs on non-github repos (rust-lang/cargo#16768)
- Update tar to 0.4.45 (rust-lang/cargo#16771)
- chore: Remove edition_lint_opts from Lint (rust-lang/cargo#16762)
- refactor: split out several smaller changes to prepare for async http (rust-lang/cargo#16763)
- fix(compile): Make build.warnings ignore non-local deps (rust-lang/cargo#16760)
- fix: detect circular publish dependency cycle in workspace publish (rust-lang/cargo#16722)
- refactor(shell): Pull out term integration into `anstyle-progress` (rust-lang/cargo#16757)
- test: reproduce rustfix panic on overlapping suggestions (rust-lang/cargo#16705)
- fix: Avoid panic for package specs with an empty fragment (rust-lang/cargo#16754)
- refactor(registry): avoid dynamic dispatch for Registry trait (rust-lang/cargo#16752)
- refactor(shell): Pull out hyperlink logic into anstyle-hyperlink (rust-lang/cargo#16749)
- refactor(install): Remove dead code (rust-lang/cargo#16718)
@rustbot rustbot added this to the 1.96.0 milestone Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants