Skip to content

fix: account for APFS clones in size scans - #212

Open
andriyor wants to merge 2 commits into
momenbasel:mainfrom
andriyor:fix/apfs-clone-aware-size-accounting
Open

andriyor wants to merge 2 commits into
momenbasel:mainfrom
andriyor:fix/apfs-clone-aware-size-accounting

Conversation

@andriyor

Copy link
Copy Markdown

Summary

APFS full clones (e.g. cp -c, Finder duplicates, app bundles sharing blocks) report a full allocated size per inode, so tree-size scans counted the same blocks once per clone and inflated totals.

  • Add FileAllocation: one lstat plus a getattrlist for ATTR_CMNEXT_CLONEID / ATTR_CMNEXT_EXT_FLAGS. Files flagged EF_SHARES_ALL_BLOCKS are identified by clone ID, others by device + inode, so full clone groups and hard links count once per scanned tree.
  • Consolidate the size walks in ScanEngine, LanguageFilesScanner and FileSizeCalculator into FileSizeCalculator.directorySize(of:includeHidden:onEntry:); StorageExplorer and AppleStorageService use the shared FileAllocation metadata.
  • Uninstall items needing admin removal now get a real recursive size, computed on a detached task rather than the main actor.
  • README: note clone handling in Space Explorer.

Limitation

A partially modified clone gets a new clone ID and is counted in full. APFS exposes no per-extent sharing info through this API, so partial clones may still overcount, but they never undercount.

Test plan

  • New testDirectorySizeCountsFullAPFSClonesOnceAndModifiedClonesSeparately (uses clonefile(), skips on non-APFS temp dirs)
  • StorageExplorerTests, AppleStorageServiceTests, LocalizationFilesTests, AppStateTests pass
  • Verified manually: clone IDs and EF_SHARES_ALL_BLOCKS match across cp -c copies; a modified clone gets a new ID

🤖 Generated with Claude Code

andriyor and others added 2 commits November 21, 2026 14:09
… actor

- Consolidate the ScanEngine, LanguageFilesScanner and FileSizeCalculator
  tree walks into FileSizeCalculator.directorySize so APFS clone dedup
  lives in one place.
- Use lstat file type from FileAllocation instead of an extra
  resourceValues call per entry; drop AppleStorageService's duplicate lstat.
- Size admin-removal uninstall items on a detached task instead of the
  main actor; reuse cached sizes for the permission retry path.
- Add a clonefile-based test for full vs. modified clones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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