How xueaaaa/go-duplicate works
go-duplicate is a CLI for finding content-identical files and cleaning up redundant copies. The main workflow validates the requested directory and options, recursively scans files, narrows candidates by size and sampled fingerprint, confirms matches with full SHA-256, then reports results and optionally deletes or hard-links redundant copies. Plain and JSON reports expose scan statistics and potential savings. The graph follows calls visible in the excerpts and README; helper-level filesystem behavior for deletion and hard-linking is not shown in the sampled source.
Main entry points: cmd/find.go Find command · finder/find.go Candidate matching · main.go Program entry · scan.go Recursive scan
Components 18
CLI workflow
- Program entry
main.go - Find command
cmd/find.go - Run parameters
internal/params/params.go
Duplicate discovery
- Recursive scan
internal/file/scan.go - File record
internal/file/file.go - Candidate matching
internal/finder/find.go - Partial fingerprint
internal/hash/fingerprint.go - Full SHA-256
internal/hash/hash.go - Duplicate groups
internal/finder/group.go - Progress and FS errors
internal/util
Reports and statistics
- Scan statistics
internal/output/stats.go - Space savings
internal/units/calculate_save_space.go - Plain report
internal/output/plain.go - JSON report
internal/output/json.go
Duplicate cleanup
- Confirmation prompt
internal/output/confirm.go - Delete duplicates
internal/finder/delete.go - Replace with hardlinks
internal/finder/hardlink.go
Other components
- User
Connections 18
- User → Program entry: runs CLI
main.go - Program entry → Find command: executes command
main.go - Find command → Run parameters: sets options
cmd/find.go - Find command → Candidate matching: starts scan
cmd/find.go - Candidate matching → Recursive scan: scans tree
internal/finder/find.go - Recursive scan → File record: emits records
internal/file/scan.go - Candidate matching → Partial fingerprint: narrows candidates
internal/finder/find.go - Candidate matching → Full SHA-256: confirms content
internal/finder/find.go - Partial fingerprint → Full SHA-256: hashes small files
internal/hash/fingerprint.go - Candidate matching → Duplicate groups: forms groups
internal/finder/find.go - Candidate matching → Progress and FS errors: tracks scan progress
internal/finder/find.go - Find command → Scan statistics: builds statistics
cmd/find.go - Scan statistics → Space savings: calculates savings
internal/output/stats.go - Find command → Plain report: writes plain output
cmd/find.go - Find command → JSON report: writes JSON output
cmd/find.go - Find command → Confirmation prompt: requests approval
cmd/find.go - Find command → Delete duplicates: deletes copies
cmd/find.go - Find command → Replace with hardlinks: replaces copies
cmd/find.go