diff --git a/Cargo.lock b/Cargo.lock index 3ae2b54..28e49b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,7 +89,7 @@ dependencies = [ [[package]] name = "garbage" -version = "0.2.0-rc1" +version = "0.2.0-rc2" dependencies = [ "anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/dir.rs b/src/dir.rs index 97b3945..4573333 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -68,6 +68,16 @@ impl TrashDir { Ok(target) } + /// Get the `info` directory + pub fn check_info_dir(&self) -> Result, Error> { + let target = self.0.join("info"); + if !target.exists() { + Ok(None) + } else { + Ok(Some(target)) + } + } + /// Iterate over trash infos within this trash directory pub fn iter(&self) -> Result { let iter = WalkDir::new(&self.info_dir()?) diff --git a/src/main.rs b/src/main.rs index ae31c49..f9dc82f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,9 +46,9 @@ fn main() { Ok(_) => (), Err(err) => { eprintln!("Error: {:?}", err); - for cause in err.chain() { - eprintln!("- {:?}", cause); - } + // for cause in err.chain() { + // eprintln!("- {:?}", cause); + // } } } } diff --git a/src/ops/put.rs b/src/ops/put.rs index dd90fd0..9373d8c 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -169,7 +169,8 @@ impl DeletionStrategy { let (trash_dir, requires_copy) = self.get_target_trash(); // prompt if not suppressed - if !options.force { + // TODO: streamline this logic better + if !options.force && (requires_copy || options.prompt) { // TODO: actually handle prompting instead of manually flushing if requires_copy { eprint!( diff --git a/src/ops/restore.rs b/src/ops/restore.rs index 08ebb5c..108a753 100644 --- a/src/ops/restore.rs +++ b/src/ops/restore.rs @@ -19,7 +19,12 @@ pub struct RestoreOptions { pub fn restore(options: RestoreOptions) -> Result<()> { let trash_dir = TrashDir::from_opt(options.trash_dir); + if trash_dir.check_info_dir()?.is_none() { + bail!("There's no trash directory here."); + } + // get list of files sorted by deletion date + // TODO: possible to get this to be streaming? let files = { let mut files = trash_dir .iter() @@ -36,6 +41,10 @@ pub fn restore(options: RestoreOptions) -> Result<()> { files }; + if files.len() == 0 { + bail!("No files in this trash directory."); + } + for (i, info) in files.iter().enumerate() { println!( "[{}]\t{}\t{}",