mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-05-01 19:18:00 +00:00
60328cd493
* Add a quick run script * Add more context to errors * Fix the issue with corpus directory canonicalization * Update the quick run script * Edit the runner script * Support specifying the path of the polkadot sdk
32 lines
1.0 KiB
Rust
32 lines
1.0 KiB
Rust
use std::{
|
|
fs::{read_dir, remove_dir_all, remove_file},
|
|
path::Path,
|
|
};
|
|
|
|
use anyhow::{Context, Result};
|
|
|
|
/// 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<()> {
|
|
for entry in read_dir(path.as_ref())
|
|
.with_context(|| format!("Failed to read directory: {}", path.as_ref().display()))?
|
|
{
|
|
let entry = entry.with_context(|| {
|
|
format!(
|
|
"Failed to read an entry in directory: {}",
|
|
path.as_ref().display()
|
|
)
|
|
})?;
|
|
let entry_path = entry.path();
|
|
|
|
if entry_path.is_file() {
|
|
remove_file(&entry_path)
|
|
.with_context(|| format!("Failed to remove file: {}", entry_path.display()))?
|
|
} else {
|
|
remove_dir_all(&entry_path)
|
|
.with_context(|| format!("Failed to remove directory: {}", entry_path.display()))?
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|