Skip to content

Commit

Permalink
Still read config file from Library/Preferences if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jan 6, 2021
1 parent 10b072d commit f993de1
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,19 @@ fn config_from_env() -> EnvConfig {
EnvConfig { cache }
}

fn config_file(env_var: &str, leaf: &str) -> PathBuf {
if let Some(env_value) = env::var_os(env_var) {
return env_value.into();
}
let dirs =
ProjectDirs::from("", ORGANIZATION, APP_NAME).expect("Unable to get config directory");
let path = dirs.preference_dir().join(leaf);
if path.exists() {
return path;
}
dirs.config_dir().join(leaf)
}

#[derive(Debug, Default, PartialEq, Eq)]
pub struct Config {
pub caches: Vec<CacheType>,
Expand All @@ -557,13 +570,7 @@ impl Config {
pub fn load() -> Result<Config> {
let env_conf = config_from_env();

let file_conf_path = env::var_os("SCCACHE_CONF")
.map(PathBuf::from)
.unwrap_or_else(|| {
let dirs = ProjectDirs::from("", ORGANIZATION, APP_NAME)
.expect("Unable to get config directory");
dirs.config_dir().join("config")
});
let file_conf_path = config_file("SCCACHE_CONF", "config");
let file_conf = try_read_config_file(&file_conf_path)
.context("Failed to load config file")?
.unwrap_or_default();
Expand Down Expand Up @@ -641,13 +648,7 @@ impl CachedConfig {
}

fn file_config_path() -> PathBuf {
env::var_os("SCCACHE_CACHED_CONF")
.map(PathBuf::from)
.unwrap_or_else(|| {
let dirs = ProjectDirs::from("", ORGANIZATION, APP_NAME)
.expect("Unable to get config directory");
dirs.config_dir().join("cached-config")
})
config_file("SCCACHE_CACHED_CONF", "cached-config")
}
fn load_file_config() -> Result<CachedFileConfig> {
let file_conf_path = &*CACHED_CONFIG_PATH;
Expand Down

0 comments on commit f993de1

Please sign in to comment.