diff --git a/README.md b/README.md index 9407ced..5861e44 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ garbage ======= -rust ver of trash-cli, basic functionality is in, code is probably shit +[![crates.io](https://img.shields.io/crates/v/garbage.svg)](https://crates.io/crates/garbage) -full free-desktop compliance when +rust ver of trash-cli, basic functionality is in, code is probably shit (edit: hopefully less shit now) * **Windows Recycle Bin not supported** @@ -28,6 +28,27 @@ $ garbage list $ garbage empty [days] ``` +If you use a bash-ish shell, feel free to add this to your shell's rc file: + +```sh +alias rm='$HOME/.cargo/bin/garbage put' # or wherever garbage is +``` + +Features +-------- + +- [x] Put +- [ ] List +- [ ] Restore (need to fuck around with DeletionStrategy) +- [ ] Tests... + +Spec Compliance +--------------- + +- [x] Picking a Trash Directory +- [x] Emptying +- [ ] Directory size cache + About ----- diff --git a/src/main.rs b/src/main.rs index 5da3fb6..917bd17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,8 +49,6 @@ enum Command { fn main() -> Result<(), Error> { env_logger::init(); - // println!("{:?}", *garbage::MOUNTS); - let cmd = Command::from_args(); match cmd { Command::Empty { dry, days } => match ops::empty(dry, days) { @@ -59,14 +57,19 @@ fn main() -> Result<(), Error> { }, Command::List => { let home_trash = TrashDir::get_home_trash(); - for info in home_trash.iter().unwrap() { - let info = match info { - Ok(info) => info, + let mut files = home_trash + .iter() + .unwrap() + .filter_map(|entry| match entry { + Ok(info) => Some(info), Err(err) => { eprintln!("failed to get file info: {:?}", err); - continue; + None } - }; + }) + .collect::>(); + files.sort_unstable_by_key(|info| info.deletion_date); + for info in files { println!("{}\t{}", info.deletion_date, info.path.to_str().unwrap()); } } diff --git a/src/ops/put.rs b/src/ops/put.rs index 4c0dd4d..a754ecb 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -18,14 +18,8 @@ pub enum Error { } pub fn put(paths: Vec, recursive: bool) -> Result<()> { - // println!("HOME MOUNT: {:?}", *HOME_MOUNT); let strategy = DeletionStrategy::Copy; for path in paths { - println!( - "PATH: {:?}, MOUNTPOINT: {:?}", - &path, - MOUNTS.get_mount_point(&path) - ); if let Err(err) = strategy.delete(path) { eprintln!("{:?}", err); } @@ -168,9 +162,6 @@ impl DeletionStrategy { // don't allow deleting '.' or '..' let current_dir = env::current_dir()?; - println!("target: {:?}", target); - println!("current_dir: {:?}", current_dir); - println!("current_dir parent: {:?}", current_dir.parent()); ensure!( !(target == current_dir || (current_dir.parent().is_some() && target == current_dir.parent().unwrap())), @@ -185,9 +176,6 @@ impl DeletionStrategy { None => bail!("no trash dir could be selected, u suck"), }; - println!("Trash dir: {:?}", trash_dir); - println!("Copying?: {:?}", copy); - // preparing metadata let now = Local::now(); let elapsed = now.timestamp_millis(); @@ -201,7 +189,7 @@ impl DeletionStrategy { let trash_info_path = trash_dir.info_dir()?.join(file_name + ".trashinfo"); let trash_info = TrashInfo { - path: target.to_path_buf(), + path: utils::into_absolute(target)?, deletion_date: now, deleted_path: trash_file_path.clone(), info_path: trash_info_path.clone(), diff --git a/src/utils.rs b/src/utils.rs index 72f4c57..148570b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -40,8 +40,6 @@ pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<() } else { fs::copy(path, &target_name); } - println!("entry path: {:?}", relative_path); - println!("> copied to: {:?}", target_name); } Ok(())