Skip to content

fix: count real on-disk size, not logical length (0.6.1) - #5

Merged
kingchenc merged 1 commit into
mainfrom
fix/on-disk-size
Jul 17, 2026
Merged

kingchenc merged 1 commit into
mainfrom
fix/on-disk-size

Conversation

@kingchenc

Copy link
Copy Markdown
Owner

Problem

Scanning summed each file''s logical metadata length (Metadata::len). For cloud placeholders (OneDrive online-only files) that advertise their full cloud size but occupy ~0 bytes locally, this massively over-reports. On a real drive: 246 GB used on a 223 GB disk, and a single OneDrive tree reporting 70 GB while holding 13 GB.

Fix

Scan + rm/reclaim byte counts now use the allocated on-disk size:

  • Windows: GetCompressedFileSizeW, called only for files whose attributes (sparse / compressed / offline / reparse / recall-on-access) can diverge — normal files stay a single stat on the hot path.
  • Unix: st_blocks * 512.

Duplicate detection keeps the logical content size (byte-identical files must group by content, not allocation). FileEntry gains logical_size next to size (now on-disk).

Verified

  • cargo fmt / clippy -D warnings clean, all tests green.
  • Fresh binary on C:\Users\sasch\OneDrive: 12.9 GB (was 70.2 GB logical) — matches real occupancy.

Scanning summed each file's logical metadata length (`Metadata::len`),
which massively over-reports for cloud placeholders: OneDrive online-only
files advertise their full cloud size but occupy ~0 bytes locally. On a real
drive this produced impossible totals (246 GB used on a 223 GB disk; a
single OneDrive tree reporting 70 GB while holding 13 GB).

Scanning and the rm/reclaim byte counts now use the allocated on-disk size:
GetCompressedFileSizeW on Windows (only for files whose attributes — sparse,
compressed, offline, reparse, recall-on-access — can diverge, so the hot path
stays a single stat for normal files) and st_blocks*512 on Unix. Duplicate
detection keeps using the logical content size, since byte-identical files
must group by content regardless of allocation.

FileEntry gains `logical_size` alongside `size` (now on-disk). Scan tests
assert lower bounds on totals since on-disk rounds up to the block size.
@kingchenc
kingchenc merged commit 4005756 into main Jul 17, 2026
5 of 7 checks passed
@kingchenc
kingchenc deleted the fix/on-disk-size branch July 17, 2026 23:20
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.

1 participant