Skip to content

Commit

Permalink
Somewhere over China: Let's not be quite so ignorant about errors dur…
Browse files Browse the repository at this point in the history
…ing deletion
  • Loading branch information
Sebastian Thiel committed Jun 8, 2019
1 parent ef8cf56 commit eb4f978
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/interactive/app_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ use failure::Error;
use jwalk::{DirEntry, WalkDir};
use petgraph::prelude::NodeIndex;
use pretty_assertions::assert_eq;
use std::env::temp_dir;
use std::fs::{copy, create_dir_all, remove_dir, remove_file};
use std::io::ErrorKind;
use std::{ffi::OsStr, ffi::OsString, fmt, path::Path, path::PathBuf};
use std::{
env::temp_dir,
ffi::OsStr,
ffi::OsString,
fmt,
fs::{copy, create_dir_all, remove_dir, remove_file},
io,
io::ErrorKind,
path::Path,
path::PathBuf,
};
use termion::input::TermRead;
use tui::backend::TestBackend;
use tui_react::Terminal;
Expand Down Expand Up @@ -340,11 +347,11 @@ struct WritableFixture {

impl Drop for WritableFixture {
fn drop(&mut self) {
delete_recursive(&self.root);
delete_recursive(&self.root).unwrap();
}
}

fn delete_recursive(path: impl AsRef<Path>) {
fn delete_recursive(path: impl AsRef<Path>) -> Result<(), io::Error> {
let mut files: Vec<_> = Vec::new();
let mut dirs: Vec<_> = Vec::new();

Expand All @@ -356,12 +363,12 @@ fn delete_recursive(path: impl AsRef<Path>) {
false => files.push(p),
}
}
for fp in files {
remove_file(fp).ok();
}
for dp in dirs {
remove_dir(dp).ok();
}

files
.iter()
.map(|f| remove_file(f))
.chain(dirs.iter().map(|d| remove_dir(d)))
.collect::<Result<_, _>>()
}

fn copy_recursive(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<(), Error> {
Expand Down

0 comments on commit eb4f978

Please sign in to comment.