Skip to content

fix(clean): Don't double count hardlinks when actually cleaning - #17805

Merged
ranger-ross merged 2 commits into
rust-lang:masterfrom
phr4nky:fix-clean-hardlink-size
Nov 27, 2026
Merged

ranger-ross merged 2 commits into
rust-lang:masterfrom
phr4nky:fix-clean-hardlink-size

Conversation

@phr4nky

@phr4nky phr4nky commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

Fixes #17812

Follow-up to #17485 (cc #15823).

The hardlink deduplication in cargo clean's size summary only works with --dry-run. During a real clean, each link is removed right after it is counted, so the last remaining link of a hardlinked file reports nlink == 1. The nlink <= 1 short-circuit then counts it again without checking the set of already seen files.

With a 1 KiB file and one hardlink to it:

$ cargo clean --dry-run
     Summary 2 files, 1.0KiB total
$ cargo clean
     Removed 2 files, 2.0KiB total

The fix still inserts into the set only for files with more than one link, so the memory use stays the same, and it checks the set for files with a single link.

Notes to reviewers

The first commit extends clean_accounts_for_hardlinks with a non-dry-run cargo clean and records the current 2.0KiB output. The second commit fixes it, and the snapshot changes to 1.0KiB.


🤖 LLM involvement: An LLM-based coding assistant was used to find the bug, write the reproducer, and draft the fix, tests and this description. The change was reviewed by a human, and the affected test suites were run locally before submitting.

The hardlink deduplication only worked with `--dry-run`. When files are
removed, the last remaining link of a hardlinked file reports a link
count of 1, so it was counted again without consulting the set of
already seen files.
@rustbot rustbot added Command-clean S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2026
@rustbot

rustbot commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Muscraft (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

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

@weihanglo

Copy link
Copy Markdown
Member

See #17808 (comment). Put this back to draft. Thanks for your understanding.

@weihanglo
weihanglo marked this pull request as draft November 26, 2026 01:47
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2026
@phr4nky
phr4nky marked this pull request as ready for review November 26, 2026 02:05
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2026

@ranger-ross ranger-ross left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, I can't believe I forgot to test cargo clean in the original PR 😅

View changes since this review

@ranger-ross
ranger-ross added this pull request to the merge queue Nov 27, 2026
Merged via the queue into rust-lang:master with commit 2a5e21d Nov 27, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 27, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 28, 2026
Update cargo submodule

14 commits in ae8f06eb41b8c4a534d0f280f1b9d287f45ead73..39eba940bf913a566c4763c836cbe24b9f975200
2026-11-21 04:06:35 +0000 to 2026-11-27 22:28:03 +0000
- feat(config)!: Delegate `Definition` origin to `Origin` and precedence to `Scope` (rust-lang/cargo#17822)
- Reduce the usage of `sleep_ms()` in testsuite (rust-lang/cargo#17819)
- fix(clean): Don't double count hardlinks when actually cleaning (rust-lang/cargo#17805)
- Reduce the usage of `sleep_ms()` in freshness tests (rust-lang/cargo#17816)
- fix(git): run gc in foreground to avoid race (rust-lang/cargo#17818)
- fix(script): Skip a UTF-8 BOM before parsing the frontmatter (rust-lang/cargo#17806)
- Reduce the usage of `sleep_ms()` in testsuite (rust-lang/cargo#17815)
- fix(compile): Differentiate levels of debug info  (rust-lang/cargo#17798)
- fix(profiles): line-tables-only on nightly only (rust-lang/cargo#17797)
- fix(cli): Suggest `--profile debug` on all commands that default to `dev` (rust-lang/cargo#17796)
- refactor: clarify home is cargo home (rust-lang/cargo#17790)
- refactor(config)!: various polish (rust-lang/cargo#17787)
- refactor(git): extract git backends to their own modules (rust-lang/cargo#17789)
- docs: fix typos in documentation (rust-lang/cargo#17783)

r? ghost
@rustbot rustbot added this to the 1.102.0 milestone Nov 28, 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.

cargo clean double counts hardlinked files when not using --dry-run

5 participants