fix bugs
This commit is contained in:
parent
bc5fff8a48
commit
513f7db8e2
5 changed files with 25 additions and 5 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -89,7 +89,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "garbage"
|
name = "garbage"
|
||||||
version = "0.2.0-rc1"
|
version = "0.2.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
10
src/dir.rs
10
src/dir.rs
|
@ -68,6 +68,16 @@ impl TrashDir {
|
||||||
Ok(target)
|
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
|
/// Iterate over trash infos within this trash directory
|
||||||
pub fn iter(&self) -> Result<TrashDirIter, Error> {
|
pub fn iter(&self) -> Result<TrashDirIter, Error> {
|
||||||
let iter = WalkDir::new(&self.info_dir()?)
|
let iter = WalkDir::new(&self.info_dir()?)
|
||||||
|
|
|
@ -46,9 +46,9 @@ fn main() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
for cause in err.chain() {
|
// for cause in err.chain() {
|
||||||
eprintln!("- {:?}", cause);
|
// eprintln!("- {:?}", cause);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,8 @@ impl DeletionStrategy {
|
||||||
let (trash_dir, requires_copy) = self.get_target_trash();
|
let (trash_dir, requires_copy) = self.get_target_trash();
|
||||||
|
|
||||||
// prompt if not suppressed
|
// 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
|
// TODO: actually handle prompting instead of manually flushing
|
||||||
if requires_copy {
|
if requires_copy {
|
||||||
eprint!(
|
eprint!(
|
||||||
|
|
|
@ -19,7 +19,12 @@ pub struct RestoreOptions {
|
||||||
pub fn restore(options: RestoreOptions) -> Result<()> {
|
pub fn restore(options: RestoreOptions) -> Result<()> {
|
||||||
let trash_dir = TrashDir::from_opt(options.trash_dir);
|
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
|
// get list of files sorted by deletion date
|
||||||
|
// TODO: possible to get this to be streaming?
|
||||||
let files = {
|
let files = {
|
||||||
let mut files = trash_dir
|
let mut files = trash_dir
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -36,6 +41,10 @@ pub fn restore(options: RestoreOptions) -> Result<()> {
|
||||||
files
|
files
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if files.len() == 0 {
|
||||||
|
bail!("No files in this trash directory.");
|
||||||
|
}
|
||||||
|
|
||||||
for (i, info) in files.iter().enumerate() {
|
for (i, info) in files.iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"[{}]\t{}\t{}",
|
"[{}]\t{}\t{}",
|
||||||
|
|
Loading…
Reference in a new issue