From 7907980447add18508c89c278afccf5de7be9c0d Mon Sep 17 00:00:00 2001
From: Federico Terzi <federicoterzi96@gmail.com>
Date: Wed, 15 Apr 2020 18:47:59 +0200
Subject: [PATCH] Ignore hidden files when loading configs and make error more
 explicit. Fix #234

---
 src/config/mod.rs | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/config/mod.rs b/src/config/mod.rs
index d4d6589..cd1ad94 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -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();