mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-14 05:11:07 +00:00
Fix tests & clear node directories before startup
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
use std::{
|
||||
fs::{read_dir, remove_dir_all, remove_file},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
|
||||
/// This method clears the passed directory of all of the files and directories contained within
|
||||
/// without deleting the directory.
|
||||
pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> {
|
||||
let path = path.as_ref();
|
||||
|
||||
if !path.is_dir() {
|
||||
bail!("The provided path is not a directory: {}", path.display());
|
||||
}
|
||||
|
||||
for entry in read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let entry_path = entry.path();
|
||||
|
||||
if entry_path.is_file() {
|
||||
remove_file(entry_path)?
|
||||
} else {
|
||||
remove_dir_all(entry_path)?
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mod clear_dir;
|
||||
|
||||
pub use clear_dir::*;
|
||||
@@ -1,6 +1,7 @@
|
||||
//! This crate provides common concepts, functionality, types, macros, and more that other crates in
|
||||
//! the workspace can benefit from.
|
||||
|
||||
pub mod fs;
|
||||
pub mod iterators;
|
||||
pub mod macros;
|
||||
pub mod types;
|
||||
|
||||
Reference in New Issue
Block a user