diff options
author | syn <isaqtm@gmail.com> | 2020-01-16 14:46:01 +0300 |
---|---|---|
committer | syn <isaqtm@gmail.com> | 2020-01-16 14:46:01 +0300 |
commit | e149c37f16b19236887afeadfbe774eabeb3510d (patch) | |
tree | de35d9913d7209476d7d92584921b18674bee56b /src | |
parent | e6e6285d4faca3795de4250b4ca07fc1d57b849b (diff) | |
download | evr-e149c37f16b19236887afeadfbe774eabeb3510d.tar.gz |
Support tmp dir to place binaries
Diffstat (limited to 'src')
-rw-r--r-- | src/backends/mod.rs | 18 | ||||
-rw-r--r-- | src/main.rs | 2 |
2 files changed, 20 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) +} diff --git a/src/main.rs b/src/main.rs index 0e97682..589cae2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +extern crate lazy_static; + use clap::AppSettings; use structopt::StructOpt; use env_logger; |