This commit is contained in:
Michael Zhang 2020-03-05 23:50:17 -06:00
parent bc5fff8a48
commit 513f7db8e2
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 25 additions and 5 deletions

2
Cargo.lock generated
View file

@ -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)",

View file

@ -68,6 +68,16 @@ impl TrashDir {
Ok(target)
}
/// Get the `info` directory
pub fn check_info_dir(&self) -> Result<Option<PathBuf>, 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<TrashDirIter, Error> {
let iter = WalkDir::new(&self.info_dir()?)

View file

@ -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);
// }
}
}
}

View file

@ -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!(

View file

@ -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{}",