From e149c37f16b19236887afeadfbe774eabeb3510d Mon Sep 17 00:00:00 2001 From: syn Date: Thu, 16 Jan 2020 14:46:01 +0300 Subject: Support tmp dir to place binaries --- src/backends/mod.rs | 18 ++++++++++++++++++ src/main.rs | 2 ++ 2 files changed, 20 insertions(+) (limited to 'src') 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; -- cgit v1.2.1-18-gbd029