ntfs_reader/
test_utils.rs1use std::env;
2use std::path::{Path, PathBuf};
3
4pub fn test_volume_letter() -> String {
10 if env::var_os("CI").is_some() {
11 if let Ok(cwd) = env::current_dir() {
12 let s = cwd.display().to_string();
13 if s.len() >= 2 && s.chars().nth(1) == Some(':') {
16 return s.chars().next().unwrap().to_string();
17 }
18 }
19 }
20
21 let ramdisk = Path::new("R:\\");
24 if ramdisk.exists() {
25 return "R".to_string();
26 }
27
28 env::var("SystemDrive")
29 .ok()
30 .and_then(|s| s.chars().next())
31 .unwrap_or('C')
32 .to_string()
33}
34
35pub struct TempDirGuard(pub PathBuf);
36
37impl TempDirGuard {
38 pub fn new<P: AsRef<Path>>(path: P) -> std::io::Result<Self> {
39 let p = path.as_ref().to_path_buf();
40 let _ = std::fs::remove_dir_all(&p);
41 std::fs::create_dir_all(&p)?;
42 Ok(TempDirGuard(p))
43 }
44
45 pub fn path(&self) -> &Path {
46 &self.0
47 }
48}
49
50impl Drop for TempDirGuard {
51 fn drop(&mut self) {
52 let _ = std::fs::remove_dir_all(&self.0);
53 }
54}