aaa
This commit is contained in:
parent
22fbd032dd
commit
bd09365dd5
4 changed files with 34 additions and 24 deletions
25
README.md
25
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
|
||||
-----
|
||||
|
||||
|
|
17
src/main.rs
17
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::<Vec<_>>();
|
||||
files.sort_unstable_by_key(|info| info.deletion_date);
|
||||
for info in files {
|
||||
println!("{}\t{}", info.deletion_date, info.path.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,8 @@ pub enum Error {
|
|||
}
|
||||
|
||||
pub fn put(paths: Vec<PathBuf>, 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(),
|
||||
|
|
|
@ -40,8 +40,6 @@ pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()
|
|||
} else {
|
||||
fs::copy(path, &target_name);
|
||||
}
|
||||
println!("entry path: {:?}", relative_path);
|
||||
println!("> copied to: {:?}", target_name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue