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
|
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**
|
* **Windows Recycle Bin not supported**
|
||||||
|
|
||||||
|
@ -28,6 +28,27 @@ $ garbage list
|
||||||
$ garbage empty [days]
|
$ 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
|
About
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -49,8 +49,6 @@ enum Command {
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
// println!("{:?}", *garbage::MOUNTS);
|
|
||||||
|
|
||||||
let cmd = Command::from_args();
|
let cmd = Command::from_args();
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Empty { dry, days } => match ops::empty(dry, days) {
|
Command::Empty { dry, days } => match ops::empty(dry, days) {
|
||||||
|
@ -59,14 +57,19 @@ fn main() -> Result<(), Error> {
|
||||||
},
|
},
|
||||||
Command::List => {
|
Command::List => {
|
||||||
let home_trash = TrashDir::get_home_trash();
|
let home_trash = TrashDir::get_home_trash();
|
||||||
for info in home_trash.iter().unwrap() {
|
let mut files = home_trash
|
||||||
let info = match info {
|
.iter()
|
||||||
Ok(info) => info,
|
.unwrap()
|
||||||
|
.filter_map(|entry| match entry {
|
||||||
|
Ok(info) => Some(info),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("failed to get file info: {:?}", 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());
|
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<()> {
|
pub fn put(paths: Vec<PathBuf>, recursive: bool) -> Result<()> {
|
||||||
// println!("HOME MOUNT: {:?}", *HOME_MOUNT);
|
|
||||||
let strategy = DeletionStrategy::Copy;
|
let strategy = DeletionStrategy::Copy;
|
||||||
for path in paths {
|
for path in paths {
|
||||||
println!(
|
|
||||||
"PATH: {:?}, MOUNTPOINT: {:?}",
|
|
||||||
&path,
|
|
||||||
MOUNTS.get_mount_point(&path)
|
|
||||||
);
|
|
||||||
if let Err(err) = strategy.delete(path) {
|
if let Err(err) = strategy.delete(path) {
|
||||||
eprintln!("{:?}", err);
|
eprintln!("{:?}", err);
|
||||||
}
|
}
|
||||||
|
@ -168,9 +162,6 @@ impl DeletionStrategy {
|
||||||
|
|
||||||
// don't allow deleting '.' or '..'
|
// don't allow deleting '.' or '..'
|
||||||
let current_dir = env::current_dir()?;
|
let current_dir = env::current_dir()?;
|
||||||
println!("target: {:?}", target);
|
|
||||||
println!("current_dir: {:?}", current_dir);
|
|
||||||
println!("current_dir parent: {:?}", current_dir.parent());
|
|
||||||
ensure!(
|
ensure!(
|
||||||
!(target == current_dir
|
!(target == current_dir
|
||||||
|| (current_dir.parent().is_some() && target == current_dir.parent().unwrap())),
|
|| (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"),
|
None => bail!("no trash dir could be selected, u suck"),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Trash dir: {:?}", trash_dir);
|
|
||||||
println!("Copying?: {:?}", copy);
|
|
||||||
|
|
||||||
// preparing metadata
|
// preparing metadata
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
let elapsed = now.timestamp_millis();
|
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_path = trash_dir.info_dir()?.join(file_name + ".trashinfo");
|
||||||
|
|
||||||
let trash_info = TrashInfo {
|
let trash_info = TrashInfo {
|
||||||
path: target.to_path_buf(),
|
path: utils::into_absolute(target)?,
|
||||||
deletion_date: now,
|
deletion_date: now,
|
||||||
deleted_path: trash_file_path.clone(),
|
deleted_path: trash_file_path.clone(),
|
||||||
info_path: trash_info_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 {
|
} else {
|
||||||
fs::copy(path, &target_name);
|
fs::copy(path, &target_name);
|
||||||
}
|
}
|
||||||
println!("entry path: {:?}", relative_path);
|
|
||||||
println!("> copied to: {:?}", target_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue