#![allow(dead_code)]
use std::{fs, io, path::Path, thread, time::Duration};
pub(crate) fn remove_dir_all(path: &Path) {
const ATTEMPTS: u32 = 100;
const BACKOFF: Duration = Duration::from_millis(100);
let mut last = None;
for attempt in 0..ATTEMPTS {
match fs::remove_dir_all(path) {
Ok(()) => return,
Err(error) if error.kind() == io::ErrorKind::NotFound => return,
Err(error) => {
last = Some(error);
if attempt + 1 < ATTEMPTS {
thread::sleep(BACKOFF);
}
}
}
}
let mut survivors = Vec::new();
collect(path, path, &mut survivors);
survivors.sort();
panic!(
"cannot remove fixture {} after {ATTEMPTS} attempts: {}\nstill present: {survivors:?}",
path.display(),
last.expect("a failure was recorded")
);
}
fn collect(root: &Path, current: &Path, found: &mut Vec<String>) {
let Ok(entries) = fs::read_dir(current) else {
return;
};
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
collect(root, &path, found);
} else if let Ok(relative) = path.strip_prefix(root) {
found.push(relative.to_string_lossy().replace('\\', "/"));
}
}
}