Projects STRLCPY deduplicator Commits 2c75a017
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    Cargo.lock
    skipped 40 lines
    41 41  checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
    42 42   
    43 43  [[package]]
     44 +name = "bstr"
     45 +version = "0.2.17"
     46 +source = "registry+https://github.com/rust-lang/crates.io-index"
     47 +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
     48 +dependencies = [
     49 + "lazy_static",
     50 + "memchr",
     51 + "regex-automata",
     52 + "serde",
     53 +]
     54 + 
     55 +[[package]]
    44 56  name = "bumpalo"
    45 57  version = "3.11.1"
    46 58  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 177 lines
    224 236  ]
    225 237   
    226 238  [[package]]
     239 +name = "csv"
     240 +version = "1.1.6"
     241 +source = "registry+https://github.com/rust-lang/crates.io-index"
     242 +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
     243 +dependencies = [
     244 + "bstr",
     245 + "csv-core",
     246 + "itoa",
     247 + "ryu",
     248 + "serde",
     249 +]
     250 + 
     251 +[[package]]
     252 +name = "csv-core"
     253 +version = "0.1.10"
     254 +source = "registry+https://github.com/rust-lang/crates.io-index"
     255 +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
     256 +dependencies = [
     257 + "memchr",
     258 +]
     259 + 
     260 +[[package]]
    227 261  name = "cxx"
    228 262  version = "1.0.85"
    229 263  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 39 lines
    269 303   
    270 304  [[package]]
    271 305  name = "deduplicator"
    272  -version = "0.0.5"
     306 +version = "0.0.6"
    273 307  dependencies = [
    274 308   "anyhow",
    275 309   "chrono",
    skipped 4 lines
    280 314   "glob",
    281 315   "humansize",
    282 316   "itertools",
     317 + "prettytable-rs",
    283 318   "rayon",
    284 319   "sqlite",
    285 320   "thiserror",
    skipped 2 lines
    288 323  ]
    289 324   
    290 325  [[package]]
     326 +name = "dirs-next"
     327 +version = "2.0.0"
     328 +source = "registry+https://github.com/rust-lang/crates.io-index"
     329 +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
     330 +dependencies = [
     331 + "cfg-if",
     332 + "dirs-sys-next",
     333 +]
     334 + 
     335 +[[package]]
     336 +name = "dirs-sys-next"
     337 +version = "0.1.2"
     338 +source = "registry+https://github.com/rust-lang/crates.io-index"
     339 +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
     340 +dependencies = [
     341 + "libc",
     342 + "redox_users",
     343 + "winapi",
     344 +]
     345 + 
     346 +[[package]]
    291 347  name = "either"
    292 348  version = "1.8.0"
    293 349  source = "registry+https://github.com/rust-lang/crates.io-index"
    294 350  checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
     351 + 
     352 +[[package]]
     353 +name = "encode_unicode"
     354 +version = "1.0.0"
     355 +source = "registry+https://github.com/rust-lang/crates.io-index"
     356 +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
    295 357   
    296 358  [[package]]
    297 359  name = "errno"
    skipped 26 lines
    324 386  ]
    325 387   
    326 388  [[package]]
     389 +name = "getrandom"
     390 +version = "0.2.8"
     391 +source = "registry+https://github.com/rust-lang/crates.io-index"
     392 +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
     393 +dependencies = [
     394 + "cfg-if",
     395 + "libc",
     396 + "wasi 0.11.0+wasi-snapshot-preview1",
     397 +]
     398 + 
     399 +[[package]]
    327 400  name = "glob"
    328 401  version = "0.3.0"
    329 402  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 86 lines
    416 489  dependencies = [
    417 490   "either",
    418 491  ]
     492 + 
     493 +[[package]]
     494 +name = "itoa"
     495 +version = "0.4.8"
     496 +source = "registry+https://github.com/rust-lang/crates.io-index"
     497 +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
    419 498   
    420 499  [[package]]
    421 500  name = "js-sys"
    skipped 160 lines
    582 661  checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
    583 662   
    584 663  [[package]]
     664 +name = "prettytable-rs"
     665 +version = "0.10.0"
     666 +source = "registry+https://github.com/rust-lang/crates.io-index"
     667 +checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
     668 +dependencies = [
     669 + "csv",
     670 + "encode_unicode",
     671 + "is-terminal",
     672 + "lazy_static",
     673 + "term",
     674 + "unicode-width",
     675 +]
     676 + 
     677 +[[package]]
    585 678  name = "proc-macro-error"
    586 679  version = "1.0.4"
    587 680  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 67 lines
    655 748  ]
    656 749   
    657 750  [[package]]
     751 +name = "redox_users"
     752 +version = "0.4.3"
     753 +source = "registry+https://github.com/rust-lang/crates.io-index"
     754 +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
     755 +dependencies = [
     756 + "getrandom",
     757 + "redox_syscall",
     758 + "thiserror",
     759 +]
     760 + 
     761 +[[package]]
     762 +name = "regex-automata"
     763 +version = "0.1.10"
     764 +source = "registry+https://github.com/rust-lang/crates.io-index"
     765 +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
     766 + 
     767 +[[package]]
    658 768  name = "rustix"
    659 769  version = "0.36.5"
    660 770  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 8 lines
    669 779  ]
    670 780   
    671 781  [[package]]
     782 +name = "rustversion"
     783 +version = "1.0.11"
     784 +source = "registry+https://github.com/rust-lang/crates.io-index"
     785 +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
     786 + 
     787 +[[package]]
     788 +name = "ryu"
     789 +version = "1.0.12"
     790 +source = "registry+https://github.com/rust-lang/crates.io-index"
     791 +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
     792 + 
     793 +[[package]]
    672 794  name = "scopeguard"
    673 795  version = "1.1.0"
    674 796  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 4 lines
    679 801  version = "1.0.3"
    680 802  source = "registry+https://github.com/rust-lang/crates.io-index"
    681 803  checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
     804 + 
     805 +[[package]]
     806 +name = "serde"
     807 +version = "1.0.152"
     808 +source = "registry+https://github.com/rust-lang/crates.io-index"
     809 +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
    682 810   
    683 811  [[package]]
    684 812  name = "signal-hook"
    skipped 86 lines
    771 899   "proc-macro2",
    772 900   "quote",
    773 901   "unicode-ident",
     902 +]
     903 + 
     904 +[[package]]
     905 +name = "term"
     906 +version = "0.7.0"
     907 +source = "registry+https://github.com/rust-lang/crates.io-index"
     908 +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
     909 +dependencies = [
     910 + "dirs-next",
     911 + "rustversion",
     912 + "winapi",
    774 913  ]
    775 914   
    776 915  [[package]]
    skipped 261 lines
  • ■ ■ ■ ■ ■
    Cargo.toml
    1 1  [package]
    2 2  name = "deduplicator"
    3  -version = "0.0.5"
     3 +version = "0.0.6"
    4 4  edition = "2021"
    5 5  description = "find,filter,delete Duplicates"
    6 6  license = "MIT"
    skipped 11 lines
    18 18  glob = "0.3.0"
    19 19  humansize = "2.1.2"
    20 20  itertools = "0.10.5"
     21 +prettytable-rs = "0.10.0"
    21 22  rayon = "1.6.1"
    22 23  sqlite = "0.30.3"
    23 24  thiserror = "1.0.38"
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    src/output.rs
    skipped 7 lines
    8 8   
    9 9  use crate::database::File;
    10 10  use crate::params::Params;
     11 +use prettytable::{row, Cell, Row, format, Table};
    11 12   
    12 13  fn format_path(path: &str, opts: &Params) -> Result<String> {
    13 14   let display_path = path.replace(&opts.get_directory()?, "");
    skipped 7 lines
    21 22   display_path
    22 23   };
    23 24   
    24  - Ok(format!("...{}", display_range))
     25 + Ok(format!("...{:<32}", display_range))
    25 26  }
    26 27   
    27 28  fn file_size(path: &String) -> Result<String> {
    28 29   let mdata = fs::metadata(path)?;
    29  - let formatted_size = format_size(mdata.len(), DECIMAL);
     30 + let formatted_size = format!("{:>12}", format_size(mdata.len(), DECIMAL));
    30 31   Ok(formatted_size)
    31 32  }
    32 33   
    skipped 4 lines
    37 38   Ok(modified_time.format("%Y-%m-%d %H:%M:%S").to_string())
    38 39  }
    39 40   
    40  -fn print_divider() {
    41  - println!("-------------------+-------------------------------------+------------------+----------------------------------+");
    42  -}
    43  - 
    44  -pub fn print(duplicates: Vec<File>, opts: &Params) {
    45  - print_divider();
    46  - println!(
    47  - "| {0: <16} | {1: <35} | {2: <16} | {3: <32} |",
    48  - "hash", "filename", "size", "updated_at"
    49  - );
    50  - print_divider();
    51  - 
    52  - let mut dup_index: HashMap<String, Vec<File>> = HashMap::new();
    53  - 
     41 +fn group_duplicates(duplicates: Vec<File>) -> HashMap<String, Vec<File>> {
     42 + let mut duplicate_mapper: HashMap<String, Vec<File>> = HashMap::new();
    54 43   duplicates.into_iter().for_each(|file| {
    55  - dup_index
     44 + duplicate_mapper
    56 45   .entry(file.hash.clone())
    57 46   .and_modify(|value| value.push(file.clone()))
    58 47   .or_insert_with(|| vec![file]);
    59 48   });
    60 49   
    61  - dup_index.iter().for_each(|(_, group)| {
     50 + duplicate_mapper
     51 +}
     52 + 
     53 +pub fn print(duplicates: Vec<File>, opts: &Params) {
     54 + let mut output_table = Table::new();
     55 + let grouped_duplicates: HashMap<String, Vec<File>> = group_duplicates(duplicates);
     56 + 
     57 + output_table.set_titles(row!["hash", "duplicates"]);
     58 + grouped_duplicates.iter().for_each(|(hash, group)| {
     59 + let mut inner_table = Table::new();
     60 + // inner_table.set_format(inner_table_format);
     61 + inner_table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
     62 + //inner_table.set_titles(row!["filename", "size", "updated_at"]);
    62 63   group.iter().for_each(|file| {
    63  - println!(
    64  - "| {0: <16} | {1: <35} | {2: <16} | {3: <32} |",
    65  - file.hash.red(),
    66  - format_path(&file.path, opts).unwrap_or_default().yellow(),
    67  - file_size(&file.path).unwrap_or_default().blue(),
    68  - modified_time(&file.path).unwrap_or_default().blue()
    69  - );
     64 + inner_table.add_row(row![
     65 + format_path(&file.path, opts).unwrap_or_default().blue(),
     66 + file_size(&file.path).unwrap_or_default().red(),
     67 + modified_time(&file.path).unwrap_or_default().yellow()
     68 + ]);
    70 69   });
    71  - print_divider();
     70 + output_table.add_row(row![hash.green(), inner_table]);
    72 71   });
     72 + 
     73 + output_table.printstd();
    73 74  }
    74 75   
Please wait...
Page is in error, reload to recover