Skip to content

Commit

Permalink
don't panic
Browse files Browse the repository at this point in the history
  • Loading branch information
jrop authored and samgiles committed Nov 7, 2022
1 parent 826f604 commit aabea64
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,15 @@ impl ops::DerefMut for Temp {
impl Drop for Temp {
fn drop(&mut self) {
// Drop is blocking (make non-blocking?)
if let Err(e) = if self.path.is_dir() {
if !self.path.exists() {
return;
}

let _result = if self.path.is_dir() {
fs::remove_dir_all(&self)
} else {
fs::remove_file(&self)
} {
if ::std::thread::panicking() {
eprintln!("Could not remove path {:?}: {}", self.path, e);
} else {
panic!("Could not remove path {:?}: {}", self.path, e);
}
}
};
}
}

Expand Down Expand Up @@ -307,16 +305,6 @@ mod tests {
}
}

#[test]
fn uninitialized_panic_on_drop() {
use std::panic::catch_unwind;

assert!(catch_unwind(|| {
let _ = Temp::new_path();
})
.is_err());
}

#[test]
fn uninitialized_file() {
let temp = Temp::new_path();
Expand Down

0 comments on commit aabea64

Please sign in to comment.