mirror of
https://gitlab.com/arnekeller/symlink-dupes.git
synced 2024-11-25 00:54:58 +00:00
Only try to de-duplicate files + print progress
This commit is contained in:
parent
6872bca04b
commit
ac0a95044a
@ -1,3 +1,4 @@
|
||||
use std::ffi::OsString;
|
||||
use std::{collections::HashMap, env, fs, hash::Hasher, os::unix::fs::symlink, path::PathBuf};
|
||||
|
||||
use ahash::AHasher;
|
||||
@ -11,7 +12,9 @@ fn main() {
|
||||
let dir: PathBuf = PathBuf::from(&args[1]);
|
||||
let mut filenames = fs::read_dir(&dir).unwrap()
|
||||
.map(Result::unwrap)
|
||||
.map(|x| (x.metadata().unwrap().modified().unwrap(), x.file_name()))
|
||||
.map(|x| (x.metadata().unwrap(), x.file_name()))
|
||||
.filter(|(metadata, _)| metadata.is_file()) // exclude symlinks and directories
|
||||
.map(|(metadata, name)| (metadata.modified().unwrap(), name))
|
||||
.collect::<Vec<_>>();
|
||||
filenames.sort();
|
||||
let mut hashes = HashMap::new();
|
||||
@ -27,6 +30,7 @@ fn main() {
|
||||
if hashes.contains_key(&key) {
|
||||
fs::remove_file(&full_path).unwrap();
|
||||
symlink(hashes[&key], &full_path).unwrap();
|
||||
println!("linking {} -> {}", full_path.display(), (&hashes[&key] as &OsString).to_string_lossy());
|
||||
fs_set_times::set_symlink_times(&full_path, None, Some(file.0.into())).unwrap();
|
||||
} else {
|
||||
hashes.insert(key, &file.1);
|
||||
|
Loading…
Reference in New Issue
Block a user