Skip to content

Count a hardlinked file once in Stats [patch] - #191

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/stats-hardlinks-189
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/stats-hardlinks-189

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #189

What changed

Stats took its headline numbers from the uncollapsed FileHashes/HashGroups, so a file and its hardlink showed up as a duplicate file that Scan, DryRun and Deduplicate never act on. The file's size was also counted once per path.

  • Duplicate files now comes from the collapsed, deletable groups (Sum(g => g.Files.Count - 1)), as the extension breakdown already did. That also makes the emptyCopies subtraction unnecessary.
  • Total size sizes each hashed file once, collapsing paths with Deduplicator.CollapseSameFile, which is now internal.
  • A new line, Extra paths to the same file (counted once): N, appears when there are any, so Total files (which still counts paths) can be reconciled.

With the issue's reproduction (a.txt, a hardlink b.txt, and a unique c.txt), Stats now reports Total size: 23 B and Duplicate files: 0.

Tests

I added two tests to SameFileTests.cs:

  • StatsCountsAFileAndItsHardlinkAsOneFile: a file plus its hardlink gives no duplicate, and its size is counted once.
  • StatsAgreesWithDryRunForACopyAndAHardlinkPair: a copy plus a hardlink pair gives Duplicate files: 1, which matches the .bin breakdown and DryRun's Files to delete: 1.

Both tests fail with the fix reverted and pass with it. The full suite passes: 106 passed, 3 skipped. The 3 skips are the permission tests that can't be staged as root.

#190 (deleting one name of a hardlinked non-keeper) has the same root cause but changes deletion policy, so it gets its own PR.


Generated by Claude Code

Stats took its headline numbers from the uncollapsed hash results, so a
file and its hardlink showed as one duplicate file that Scan, DryRun and
Deduplicate never act on, and the file's size was counted once per path.
Duplicate files now comes from the collapsed groups, as the extension
breakdown already did, and total size counts each file once. The extra
paths are reported on their own line.

Fixes #189

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0198HLiVUinCNr1rdcUTMQee
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 047b598 into main Oct 20, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/stats-hardlinks-189 branch October 20, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants