use std::path::{Path, PathBuf};
pub(crate) struct TempDir {
path: PathBuf,
}
impl TempDir {
pub(crate) fn new(label: &str) -> Self {
let nonce = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("clock")
.as_nanos();
let path = std::env::temp_dir().join(format!(
"windows-file-watcher-{label}-{}-{nonce}",
std::process::id()
));
std::fs::create_dir(&path).expect("create temp dir");
Self { path }
}
pub(crate) fn path(&self) -> &Path {
&self.path
}
pub(crate) fn cleanup(self) {
let _ = std::fs::remove_dir_all(&self.path);
}
}