Cotton code
31 lines · 1.5 KB · RustRaw
//! The phone fold on one database file — for proving it on a COPY.//!//! `cargo run -p cotton-store --example phone-fold -- /path/to/copy.db`//!//! Prints the three counts (handles folded, duplicates collapsed, collisions//! turned into suggestions) and the full report. Refuses anything under//! `~/CottonDB` or `/Applications`: only ever a copy.use cotton_store::phone_fold::{fold_phones, folded};use cotton_store::Driver;fn main() {    let Some(path) = std::env::args().nth(1) else {        eprintln!("usage: phone-fold /path/to/copy.db");        std::process::exit(2);    };    let real = std::path::Path::new(&path).canonicalize().unwrap_or_else(|e| panic!("{path}: {e}"));    let home = std::env::var("HOME").unwrap_or_default();    if real.starts_with(format!("{home}/CottonDB")) || real.starts_with("/Applications") {        eprintln!("{}: not a copy — refused", real.display());        std::process::exit(2);    }    let db = Driver::open(&real).unwrap_or_else(|e| panic!("{}: {e}", real.display()));    let already = folded(&db).expect("the header");    let report = fold_phones(&db).expect("the fold");    println!("already folded before this run: {already}");    println!("handles folded: {}", report.handles_moved);    println!("duplicates collapsed: {}", report.handles_collapsed);    println!("collisions kept as stored: {}", report.handles_kept);    println!("region pass (owner's own number's country) ran: {}", report.region_pass);    println!("{report}");}