Skip to content

fix: stop Stats counting files it could not hash as duplicates [patch] - #142

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/stats-unhashed-files-137
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/stats-unhashed-files-137

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #137

What changed

Stats.Run worked out Duplicate files as files.Count - hashGroups.Count. files is every file the scan found. FileHasher.HashFiles drops any file it can't read, so every unreadable file was counted as a duplicate. One unreadable file in a tree with no duplicates gave Duplicate files: 1 next to Duplicate groups: 0.

Stats.cs now works from the files that were hashed:

  • Duplicate files is fileHashes.Count - hashGroups.Count.
  • Total size sums fileHashes.Keys. This leaves out files the other statistics already skip, and a file deleted after the scan no longer throws FileNotFoundException here.
  • A new Unreadable files: N line appears under Total files only when N > 0, so output for a clean tree hasn't changed.

Tests

Two new tests in VerbOutputTests:

  • StatsReportsAFileItCannotHashAsUnreadable: a tree with two unique files and a third held open with FileShare.None. It expects 1 unreadable file, 9 B total size and 0 duplicate files. The test holds a share lock instead of changing permissions because root reads through permissions, and .NET enforces FileShare.None on every platform.
  • StatsOmitsTheUnreadableLineWhenEveryFileHashes.

With Stats.cs reverted, the first test fails. With the fix, the full suite has 48 passes and 0 failures. The other 2 tests are the existing permission-based ones, which report inconclusive when run as root.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YLYtHwwqdY3Tk9vpkwT6Sw


Generated by Claude Code

Stats derived "Duplicate files" from the scanned list, but HashFiles
drops a file it cannot read, so each unreadable file was reported as a
duplicate of nothing. The counts and the total size now come from the
files that hashed, and the files that did not are reported on their own
"Unreadable files" line.

Fixes #137

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

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stats counts files that failed to hash as "Duplicate files"

2 participants