Files
deduplicator/src/main.rs
T
Sreedev Kodichath cc7144afbc [ADD] resolver: bulk duplicate resolution via --keep/--force
The tool could only act on duplicates through the default listing or the
manual per-group interactive prompt, with no way to resolve groups in bulk
by a rule. This blocked any scripted or automated use, and bulk resolution
is the top item in the README's proposed operations.

Add a resolver module that reduces each duplicate group to a single kept
file. --keep <newest|oldest|first|last|shortest|shallowest> selects the
keeper: newest/oldest by mtime, first/last and shortest/shallowest by
path, each resolved to a unique keeper through total-order path tiebreaks
so the outcome is deterministic and order-independent. Selection is a pure,
independently tested function; deletion is a separate step.

Deletion is guarded: --keep alone previews (KEEP/DELETE lines and a
would-free summary) and removes nothing, so a mistaken invocation is
harmless. --force performs the deletion, continues past individual
failures, reports freed space, and exits non-zero if any file could not be
removed. clap enforces that --keep excludes --interactive and that --force
requires --keep, so misuse fails before any file is touched.

Also fixes the interactive table's column width, which sized on path
component count instead of path string length so the columns never aligned.
2026-07-26 19:27:49 +02:00

29 lines
641 B
Rust

mod fileinfo;
mod formatter;
mod interactive;
mod params;
mod pipeline;
mod processor;
mod resolver;
mod scanner;
use self::{formatter::Formatter, interactive::Interactive};
use anyhow::Result;
use clap::Parser;
use params::Params;
fn main() -> Result<()> {
let params = Params::parse();
let report = pipeline::run(&params)?;
match params.keep {
Some(strategy) => resolver::run(&report, strategy, params.force, &params)?,
None => match params.interactive {
true => Interactive::init(&report.groups, &params)?,
false => Formatter::print(&report, &params),
},
}
Ok(())
}