From e294a6ce0a714a80631e69dc839b0b7509dcf402 Mon Sep 17 00:00:00 2001 From: porcuquine Date: Thu, 9 Jul 2020 21:48:15 -0700 Subject: [PATCH] Get default cache dir from FIL_PROOFS_CACHE_DIR. --- storage-proofs/core/src/settings.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/storage-proofs/core/src/settings.rs b/storage-proofs/core/src/settings.rs index a372e0d8f..5ea74c2ab 100644 --- a/storage-proofs/core/src/settings.rs +++ b/storage-proofs/core/src/settings.rs @@ -11,6 +11,7 @@ lazy_static! { } const SETTINGS_PATH: &str = "./rust-fil-proofs.config.toml"; +const PREFIX: &str = "FIL_PROOFS"; #[derive(Debug, Serialize, Deserialize)] #[serde(default)] @@ -43,15 +44,16 @@ impl Default for Settings { sdr_parents_cache_size: 2_048, window_post_synthesis_num_cpus: num_cpus::get() as u32, parameter_cache: "/var/tmp/filecoin-proof-parameters/".to_string(), - parent_cache: tmp("filecoin-parents"), + parent_cache: cache("filecoin-parents"), } } } -fn tmp(s: &str) -> String { - let mut tmp = env::var("TMPDIR").unwrap_or_else(|_| "/var/tmp/".to_string()); - tmp.push_str(s); - tmp +fn cache(s: &str) -> String { + let cache_var = format!("{}_CACHE_DIR", PREFIX); + let mut cache_name = env::var(cache_var).unwrap_or_else(|_| "/var/tmp/".to_string()); + cache_name.push_str(s); + cache_name } impl Settings { @@ -59,7 +61,7 @@ impl Settings { let mut s = Config::new(); s.merge(File::with_name(SETTINGS_PATH).required(false))?; - s.merge(Environment::with_prefix("FIL_PROOFS"))?; + s.merge(Environment::with_prefix(PREFIX))?; s.try_into() }