use std::env;
use std::path::{Path, PathBuf};
pub fn test_volume_letter() -> String {
if env::var_os("CI").is_some() {
if let Ok(cwd) = env::current_dir() {
let s = cwd.display().to_string();
if s.len() >= 2 && s.chars().nth(1) == Some(':') {
return s.chars().next().unwrap().to_string();
}
}
}
let ramdisk = Path::new("R:\\");
if ramdisk.exists() {
return "R".to_string();
}
env::var("SystemDrive")
.ok()
.and_then(|s| s.chars().next())
.unwrap_or('C')
.to_string()
}
pub struct TempDirGuard(pub PathBuf);
impl TempDirGuard {
pub fn new<P: AsRef<Path>>(path: P) -> std::io::Result<Self> {
let p = path.as_ref().to_path_buf();
let _ = std::fs::remove_dir_all(&p);
std::fs::create_dir_all(&p)?;
Ok(TempDirGuard(p))
}
pub fn path(&self) -> &Path {
&self.0
}
}
impl Drop for TempDirGuard {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}