use std::path::{Path, PathBuf};
pub(crate) struct Scratch(PathBuf);
impl Scratch {
pub(crate) fn new(name: &str) -> Scratch {
let dir = Scratch::path(name);
std::fs::remove_dir_all(&dir).ok();
std::fs::create_dir_all(&dir).expect("scratch dir");
Scratch(dir)
}
pub(crate) fn path(name: &str) -> PathBuf {
std::env::temp_dir().join(format!("fats-{name}-{}", std::process::id()))
}
}
impl std::ops::Deref for Scratch {
type Target = Path;
fn deref(&self) -> &Path {
&self.0
}
}
impl Drop for Scratch {
fn drop(&mut self) {
std::fs::remove_dir_all(&self.0).ok();
}
}