diff options
Diffstat (limited to 'src/backends/mod.rs')
-rw-r--r-- | src/backends/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/backends/mod.rs b/src/backends/mod.rs index f24a162..82ec6a7 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -1,4 +1,6 @@ use std::path::{ Path, PathBuf }; +use std::env::temp_dir; +use lazy_static::lazy_static; pub mod python; pub mod clang; @@ -6,6 +8,10 @@ pub mod clang; pub use python::PythonBackend; pub use clang::ClangBackend; +lazy_static! { + static ref EVR_TMP_DIR: PathBuf = temp_dir().join("evr-tmp"); +} + pub trait Backend { fn get_template(&self) -> Option<&str>; @@ -19,3 +25,15 @@ pub trait Backend { None } } + +fn mk_tmp_dir() -> std::io::Result<&'static std::path::PathBuf> { + if !EVR_TMP_DIR.exists() { + std::fs::create_dir(&*EVR_TMP_DIR)?; + } else { + if !EVR_TMP_DIR.is_dir() { + return Err(std::io::Error::new(std::io::ErrorKind::AlreadyExists, + "tmp dir already exists and not a directory")) + } + } + Ok(&*EVR_TMP_DIR) +} |