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 | |
parent | e6e6285d4faca3795de4250b4ca07fc1d57b849b (diff) | |
download | evr-e149c37f16b19236887afeadfbe774eabeb3510d.tar.gz |
Support tmp dir to place binaries
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/backends/mod.rs | 18 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 22 insertions, 0 deletions
@@ -67,6 +67,7 @@ version = "0.1.0" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -14,3 +14,4 @@ serde_derive = "1" log = "0.4" env_logger = "0.7.1" wait-timeout = "0.1.5" +lazy_static = "1.4.0" 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; |