info = files + '.trashinfo'

This commit is contained in:
Michael Zhang 2019-07-26 10:13:47 -05:00
parent 388c9e4452
commit 1835637071
No known key found for this signature in database
GPG key ID: 5BAEFE5D04F0CE6C
3 changed files with 10 additions and 5 deletions

View file

@ -113,12 +113,13 @@ fn main() {
let stdin = io::stdin();
let mut s = String::new();
println!("which file to restore? [0..{}]", files.len());
println!("which file to restore? [0..{}]", files.len() - 1);
stdin.read_line(&mut s).unwrap();
match s.trim_end().parse::<usize>() {
Ok(i) if i < files.len() => {
let info = files.get(i).unwrap();
println!("moving {:?} to {:?}", &info.deleted_path, &info.path);
fs::rename(&info.deleted_path, &info.path);
}
_ => println!("Invalid number."),

View file

@ -51,13 +51,13 @@ pub fn put(path: impl AsRef<Path>, recursive: bool) -> Result<(), Error> {
let home_trash = TrashDir::get_home_trash();
let file_name = format!(
"{}.{}.trashinfo",
"{}.{}",
elapsed,
path.file_name().unwrap().to_str().unwrap()
);
let trash_file_path = home_trash.files_dir()?.join(&file_name);
let trash_info_path = home_trash.info_dir()?.join(&file_name);
let trash_info_path = home_trash.info_dir()?.join(file_name + ".trashinfo");
let trash_info = TrashInfo {
path: path.clone(),

View file

@ -65,8 +65,12 @@ impl Iterator for TrashDirIter {
entry
};
let name = entry.path().file_name().unwrap();
let deleted_path = self.0.join("files").join(name);
let name = entry.path().file_name().unwrap().to_str().unwrap();
let deleted_path = if !name.ends_with(".trashinfo") {
return self.next();
} else {
self.0.join("files").join(name.trim_right_matches(".trashinfo"))
};
Some(TrashInfo::from_files(entry.path(), deleted_path).map_err(Error::from))
}
}