Repository navigation
Account for (uplift) hardlinks when calculating clean file size - #17485
Conversation
|
r? @weihanglo rustbot has assigned @weihanglo. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
fwiw, I tried So it seems to be even closer to |
|
Errr, geez didn't realized the windows I guess the PR is still reviewable as the approach should work, I'll just need to use @rustbot author |
|
imo this PR addresses one specific concern and I think that is fully reasonable. We shouldn't block some improvement on trying to make it perfect, especially since each time of improvement likely needs its own decision of whether it is worth it / correct. |
cd990f6 to
6426b25
Compare
6426b25 to
2f806ad
Compare
2f806ad to
5651d3c
Compare
|
I think the |
cc74001
Update cargo submodule 10 commits in 495c385d0875c4ba51eb72ea0448a2d4c018b8d4..98a09e7e7d62850f14e5b6132101fc1edd19a16f 2026-09-16 12:48:58 +0000 to 2026-09-21 19:03:16 +0000 - feat(build-rs): trim-paths inputs (rust-lang/cargo#17491) - Remove README CI badge (rust-lang/cargo#17495) - feat(builtin-deps): Add unstable `builtin-dependencies` feature (rust-lang/cargo#17497) - test(prerelease): concurrent downloads snapshots be unordered (rust-lang/cargo#17492) - Account for (uplift) hardlinks when calculating clean file size (rust-lang/cargo#17485) - feat(hints): extract mostly-unused diagnostics (rust-lang/cargo#17457) - fix(build-rs): make `unstable` compile (rust-lang/cargo#17489) - refactor(context): Split config keys in code, not at runtime (rust-lang/cargo#17490) - fix(prerelease): preserve locked prerelease deps (rust-lang/cargo#17464) - Remove -Zasymmetric-token / cargo:paseto (rust-lang/cargo#17486) r? ghost
Update cargo submodule 10 commits in 495c385d0875c4ba51eb72ea0448a2d4c018b8d4..98a09e7e7d62850f14e5b6132101fc1edd19a16f 2026-09-16 12:48:58 +0000 to 2026-09-21 19:03:16 +0000 - feat(build-rs): trim-paths inputs (rust-lang/cargo#17491) - Remove README CI badge (rust-lang/cargo#17495) - feat(builtin-deps): Add unstable `builtin-dependencies` feature (rust-lang/cargo#17497) - test(prerelease): concurrent downloads snapshots be unordered (rust-lang/cargo#17492) - Account for (uplift) hardlinks when calculating clean file size (rust-lang/cargo#17485) - feat(hints): extract mostly-unused diagnostics (rust-lang/cargo#17457) - fix(build-rs): make `unstable` compile (rust-lang/cargo#17489) - refactor(context): Split config keys in code, not at runtime (rust-lang/cargo#17490) - fix(prerelease): preserve locked prerelease deps (rust-lang/cargo#17464) - Remove -Zasymmetric-token / cargo:paseto (rust-lang/cargo#17486) r? ghost
Update cargo submodule 10 commits in 495c385d0875c4ba51eb72ea0448a2d4c018b8d4..98a09e7e7d62850f14e5b6132101fc1edd19a16f 2026-09-16 12:48:58 +0000 to 2026-09-21 19:03:16 +0000 - feat(build-rs): trim-paths inputs (rust-lang/cargo#17491) - Remove README CI badge (rust-lang/cargo#17495) - feat(builtin-deps): Add unstable `builtin-dependencies` feature (rust-lang/cargo#17497) - test(prerelease): concurrent downloads snapshots be unordered (rust-lang/cargo#17492) - Account for (uplift) hardlinks when calculating clean file size (rust-lang/cargo#17485) - feat(hints): extract mostly-unused diagnostics (rust-lang/cargo#17457) - fix(build-rs): make `unstable` compile (rust-lang/cargo#17489) - refactor(context): Split config keys in code, not at runtime (rust-lang/cargo#17490) - fix(prerelease): preserve locked prerelease deps (rust-lang/cargo#17464) - Remove -Zasymmetric-token / cargo:paseto (rust-lang/cargo#17486) r? ghost
Update cargo submodule 10 commits in 495c385d0875c4ba51eb72ea0448a2d4c018b8d4..98a09e7e7d62850f14e5b6132101fc1edd19a16f 2026-09-16 12:48:58 +0000 to 2026-09-21 19:03:16 +0000 - feat(build-rs): trim-paths inputs (rust-lang/cargo#17491) - Remove README CI badge (rust-lang/cargo#17495) - feat(builtin-deps): Add unstable `builtin-dependencies` feature (rust-lang/cargo#17497) - test(prerelease): concurrent downloads snapshots be unordered (rust-lang/cargo#17492) - Account for (uplift) hardlinks when calculating clean file size (rust-lang/cargo#17485) - feat(hints): extract mostly-unused diagnostics (rust-lang/cargo#17457) - fix(build-rs): make `unstable` compile (rust-lang/cargo#17489) - refactor(context): Split config keys in code, not at runtime (rust-lang/cargo#17490) - fix(prerelease): preserve locked prerelease deps (rust-lang/cargo#17464) - Remove -Zasymmetric-token / cargo:paseto (rust-lang/cargo#17486) r? ghost
What does this PR try to resolve?
Reported in #15823.
Currently the size we show in
cargo cleandoes not account for hardlinks.This can lead to large over estimations when there are large files hardlinked during uplifting (like binaries)
I personally have seen Cargo report 2Tb saved when my disk was 1Tb 😆
I briefly considered if we should show both the apparent size and the size on disk, but decided to just stick to showing the size on disk to avoid confusion and feel its want the majority of users will want/expect.
Note: This does not mean the size estimation is now perfectly accurate.
Still missing
targetMetadata::len()does not account for account for filesystem specific allocations. (I thinkMetadataExt::blocks()could handle this better on unix. I didn't do this since testing it would be a bit annoying due to it being filesystem specific, though could be added later)How to test and review this PR?
You can test this pretty easily testable using
du -sh targetand comparing that withcargo clean --dry-run.Testing on ripgrep
(note: we under report now due to reasons above, but its much closer to the true size than before)
AI usage disclosure
I used AI during the investigation of this, but all of the code is handwritten.
I also used it to help simplify the test case and make it more idiomatic/match the style of other tests