Ignore hidden files when loading configs and make error more explicit. Fix #234

This commit is contained in:
Federico Terzi 2020-04-15 18:47:59 +02:00
parent eab0a59f64
commit 7907980447

View File

@ -267,6 +267,7 @@ impl Configs {
}
}
}else{
eprintln!("Error: Cannot load file {:?}", path);
Err(ConfigLoadError::FileNotFound)
}
}
@ -377,6 +378,11 @@ impl ConfigSet {
continue;
}
// Skip hidden files
if path.file_name().unwrap_or_default().to_str().unwrap_or_default().starts_with(".") {
continue;
}
let mut config = Configs::load_config(&path)?;
// Make sure the config does not contain reserved fields
@ -952,6 +958,32 @@ mod tests {
assert_eq!(config_set.specific.len(), 0);
}
#[test]
fn test_hidden_files_are_ignored() {
let (data_dir, package_dir) = create_temp_espanso_directories_with_default_content(
r###"
matches:
- trigger: ":lol"
replace: "LOL"
- trigger: ":yess"
replace: "Bob"
"###
);
create_user_config_file(data_dir.path(), ".specific.yml", r###"
name: specific1
exclude_default_entries: true
matches:
- trigger: "hello"
replace: "newstring"
"###);
let config_set = ConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
assert_eq!(config_set.specific.len(), 0);
}
#[test]
fn test_config_set_no_parent_configs_works_correctly() {
let (data_dir, package_dir) = create_temp_espanso_directories();