Skip to content

Commit

Permalink
Properly chain together bury error
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekuil committed Jan 31, 2017
1 parent 3bd5513 commit 88d876e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ Send files to the graveyard (/tmp/graveyard-$USER by default) instead of unlinki
.long("inspect"))
.get_matches();

let graveyard = &{
let graveyard: Cow<str> = match (matches.value_of("graveyard"), env::var("GRAVEYARD")) {
(Some(flag), _) => flag.into(),
(_, Ok(env)) => env.into(),
_ => format!("{}-{}", GRAVEYARD, get_user()).into()
};
PathBuf::from(&*graveyard)
let _graveyard: Cow<str> = match (matches.value_of("graveyard"), env::var("GRAVEYARD")) {
(Some(flag), _) => flag.into(),
(_, Ok(env)) => env.into(),
_ => format!("{}-{}", GRAVEYARD, get_user()).into()
};
let graveyard = Path::new(&*_graveyard);

if matches.is_present("decompose") {
if prompt_yes("Really unlink the entire graveyard?") {
Expand Down Expand Up @@ -254,10 +252,10 @@ Send files to the graveyard (/tmp/graveyard-$USER by default) instead of unlinki
}
};

if let Err(e) = bury(source, dest) {
println!("Failed to bury file: {}", e);
bury(source, dest).or_else(|e| {
fs::remove_dir_all(dest).is_ok();
}
Err(e)
}).chain_err(|| "Failed to bury file")?;
// Clean up any partial buries due to permission error
write_log(source, dest, record)
.chain_err(|| format!("Failed to write record at {}", record.display()))?;
Expand Down

0 comments on commit 88d876e

Please sign in to comment.