diff --git a/Cargo.toml b/Cargo.toml index dd30164..cfbf1da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mvw" -version = "0.1.5" +version = "0.1.6" edition = "2021" [profile.release] diff --git a/src/dirlist.rs b/src/dirlist.rs index d33bd1d..01095a6 100644 --- a/src/dirlist.rs +++ b/src/dirlist.rs @@ -16,7 +16,7 @@ impl ToString for DirListEntry { fn to_string(&self) -> String { match self { DirListEntry::Text(line) => line.clone(), - DirListEntry::Path(path) => path.display().to_string(), + DirListEntry::Path(path) => path.display().to_string()[2..].to_string(), } } } @@ -38,6 +38,7 @@ impl DirList { .collect() }; + let mut path_list : Vec = vec![]; for path in paths { let path_string = path.display().to_string(); @@ -45,8 +46,8 @@ impl DirList { path_list.push(DirListEntry::Path(path)); } } - // This sort is probably not /really/ needed, but just nice - //path_list.sort(); + + path_list.sort_by_key(|dir| dir.to_string()); Self { safe_source: true, @@ -92,10 +93,7 @@ impl DirList { let mut file = File::create(target_file).expect("no such file"); for entry in &self.entries { - match entry { - DirListEntry::Text(line) => writeln!(file, "{}", line).expect("Unable to write to file"), - DirListEntry::Path(path) => writeln!(file, "{}", path.display().to_string()).expect("Unable to write to file"), - } + writeln!(file, "{}", entry.to_string()).expect("Unable to write to file"); } } @@ -117,16 +115,16 @@ impl DirList { intermediate_files.insert(unique.clone(), target_list.entries[i].to_string().clone()); if ! self.noop { match &self.entries[i] { - DirListEntry::Text(name) => fs::rename(name.to_string(), &unique).expect("failed to rename file"), - DirListEntry::Path(path) => fs::rename(path.as_path(), &unique).expect("failed to rename file"), + DirListEntry::Text(name) => fs::rename(name.to_string(), &unique).expect("failed to rename file (text based, unique)"), + DirListEntry::Path(path) => fs::rename(path.as_path(), &unique).expect("failed to rename file (path based, unique)"), } } if self.verbose { println!("Moving {} -> {}", self.entries[i].to_string(), unique); } } else { if ! self.noop { match &self.entries[i] { - DirListEntry::Text(name) => fs::rename(name.to_string(), &target_list.entries[i].to_string()).expect("failed to rename file"), - DirListEntry::Path(path) => fs::rename(path.as_path(), &target_list.entries[i].to_string()).expect("failed to rename file"), + DirListEntry::Text(name) => fs::rename(name.to_string(), &target_list.entries[i].to_string()).expect("failed to rename file (text based)"), + DirListEntry::Path(path) => fs::rename(path.as_path(), &target_list.entries[i].to_string()).expect("failed to rename file (path based)"), } } if self.verbose { println!("Moving {} -> {}", self.entries[i].to_string(), target_list.entries[i].to_string()); } @@ -134,7 +132,7 @@ impl DirList { } } for (src, dst) in intermediate_files.iter() { - if ! self.noop { fs::rename(src, dst).expect("failed to rename file"); } + if ! self.noop { fs::rename(src, dst).expect("failed to rename file (intermediate name)"); } if self.verbose { println!("Moving {} -> {}", src, dst); } } Ok(())