IO error just skips topdir check instead of failing entire operation

This commit is contained in:
Michael Zhang 2021-12-30 22:17:48 -06:00
parent f76f21ffc2
commit f43568de81
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -98,7 +98,7 @@ pub fn put(options: PutOptions) -> Result<()> {
// println!("Strategy: {:?}", strategy); // println!("Strategy: {:?}", strategy);
if options.dry { if options.dry {
eprintln!("Dry-deleting: {}", path.to_str().unwrap()); eprintln!("Dry-deleting {:?} with strategy {:?}", path, strategy);
} else if let Err(err) = strategy.delete(path, &options) { } else if let Err(err) = strategy.delete(path, &options) {
eprintln!("{}", err); eprintln!("{}", err);
} }
@ -140,12 +140,19 @@ impl DeletionStrategy {
} }
// try to use the $topdir/.Trash directory // try to use the $topdir/.Trash directory
if should_use_topdir_trash(&target_mount) { // NOTE: really wish i could break from if statements...
'topdir: while should_use_topdir_trash(&target_mount) {
let topdir_trash_dir = target_mount let topdir_trash_dir = target_mount
.join(".Trash") .join(".Trash")
.join(utils::get_uid().to_string()); .join(utils::get_uid().to_string());
let trash_dir = TrashDir::from(topdir_trash_dir); let trash_dir = TrashDir::from(&topdir_trash_dir);
trash_dir.create()?; match trash_dir.create() {
Ok(_) => (),
Err(err) => {
info!("Not deleting {:?} in mount's trash-dir {:?} because of IO error: {:?}", target, topdir_trash_dir, err);
break 'topdir;
}
}
return Ok(DeletionStrategy::MoveTo(trash_dir)); return Ok(DeletionStrategy::MoveTo(trash_dir));
} }