Fix config directory to read config.toml from $XDG_CONFIG_HOME/boilr, rather than $XDG_CONFIG_HOME (#338)

This commit is contained in:
Daedalusspacegames
2023-03-27 20:57:17 +02:00
committed by GitHub
parent eb8db42487
commit f181379914
+5 -6
View File
@@ -8,7 +8,7 @@ pub fn get_config_folder() -> PathBuf {
let config_home = std::env::var("XDG_CONFIG_HOME");
let home = std::env::var("HOME");
match (config_home, home) {
(Ok(p), _) => Path::new(&p).to_path_buf(),
(Ok(p), _) => Path::new(&p).join("boilr"),
(Err(_), Ok(home)) => Path::new(&home).join(".config").join("boilr"),
_ => Path::new("").to_path_buf(),
}
@@ -64,14 +64,13 @@ mod tests {
// Parameters for set environment 'XDG_CONFIG_HOME'
std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap_or_default() + "/.config/boilr",
std::env::var("HOME").unwrap_or_default() + "/.config",
);
let xdg_config_home = std::env::var("XDG_CONFIG_HOME").unwrap_or_default();
let xdg_config_home = std::env::var("XDG_CONFIG_HOME").unwrap_or_default() + "/boilr";
let config_path = get_config_folder();
let test_path = PathBuf::from(xdg_config_home);
assert_eq!(config_path, test_path);
assert_eq!(config_path, PathBuf::from(xdg_config_home));
}
#[test]
@@ -79,7 +78,7 @@ mod tests {
fn check_return_config_path() {
std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap_or_default() + "/.config/boilr",
std::env::var("HOME").unwrap_or_default() + "/.config",
);
let config_path = get_config_folder();