Skip to content

Commit

Permalink
Get default cache dir from FIL_PROOFS_CACHE_DIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jul 10, 2020
1 parent d444bc0 commit e294a6c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions storage-proofs/core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -43,23 +44,24 @@ 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 {
fn new() -> Result<Settings, ConfigError> {
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()
}
Expand Down

0 comments on commit e294a6c

Please sign in to comment.