Repository navigation
Never delete empty files when deduplicating [patch] - #165
Merged
Merged
Conversation
Every zero-length file hashes the same, so __init__.py, .gitkeep and py.typed markers across a tree formed one duplicate group, and Deduplicate deleted all but one of them while reclaiming 0 bytes. Empty groups are still reported, but DeleteDuplicates, the deletion plan that DryRun and Deduplicate print, and Scan's listing now keep every copy. Fixes #151 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZFyLG9PgeKn5RpzhWEUQ
Addresses SonarCloud S3358 and MSTEST0037 on this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZFyLG9PgeKn5RpzhWEUQ
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #151
What changed
Every zero-length file has the same SHA-256. That put
__init__.py,.gitkeepandpy.typedfiles from all over a tree into one group, andDeduplicatedeleted all but one of them while reporting 0 B reclaimed.Deduplicator.IsDeletable(group), which is false for a zero-length group.DeleteDuplicatesskips groups that aren't deletable, so their files are never deleted.DuplicateReport.PlanDeletions, the listing DryRun and Deduplicate print, lists every file in an empty group asKEEPunder "Empty files are never deleted", and counts none of them.[KEEP, empty]rather than[DELETE].FindDuplicatesis unchanged, so empty files are still reported as a group andEmptyFilesAreDuplicatesOfEachOtherstill holds.DryRunEquivalenceTests.PredictedDeletionsapplies the same filter, so the preview and the deletion still agree.Tests
DeduplicatorTests.EmptyFilesAreNeverDeleted: two empty__init__.pyfiles plus one real duplicate pair. Only the real duplicate is deleted.DuplicateReportTests.PlanKeepsEveryEmptyFile: three empty files. The plan deletes 0 files and 0 bytes, and lists all three asKEEP.With
IsDeletablestubbed to always return true (the old behaviour), both new tests fail. With the fix, the full suite passes: 61 passed, 2 skipped. The 2 skips are pre-existing tests that need an unprivileged user. I also ranDeduplicateon a real tree holding three empty files and one duplicate pair: it deleted only the duplicate.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q5ZFyLG9PgeKn5RpzhWEUQ
Generated by Claude Code