Fix tests & clear node directories before startup

This commit is contained in:
Omar Abdulla
2025-08-01 13:09:47 +03:00
parent c2c3e81125
commit 57ba765aa2
17 changed files with 146 additions and 59 deletions
+29
View File
@@ -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(())
}
+3
View File
@@ -0,0 +1,3 @@
mod clear_dir;
pub use clear_dir::*;
+1
View File
@@ -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;