Repository: qarmin/czkawka (language: rust)

Issue:
Reference folders do not work in version 6.1.0
**Desktop (please complete the following information):**

- Czkawka version<!--  e.g. 6.1.0 cli/gui -->: 6.1.0
- OS version<!--  e.g Ubuntu 22.04, Windows 11, Mac 15.1 ARM -->: Windows 10
- Terminal output[optional]:

<!--
Add terminal output only if needed - if there are some errors or warnings or you have performance/freeze issues.  
Very helpful in this situation will be logs from czkawka run with RUST_LOG environment variable set e.g. 
`RUST_LOG=debug ./czkawka` which will print more detailed info about executed function
-->

**Bug Description**
The reference folder option is selected but it does not work



Discussion / hints:
Cannot reproduce problem

![Screenshot from 2023-10-15 11-11-49](https://github.com/qarmin/czkawka/assets/41945903/1acbaf51-d7b0-47eb-a120-11cd273dc395)
![Screenshot from 2023-10-15 11-12-09](https://github.com/qarmin/czkawka/assets/41945903/854c892f-de2d-4764-8504-1d86df7c2564)
![Screenshot from 2023-10-15 11-12-23](https://github.com/qarmin/czkawka/assets/41945903/2ebcebc5-4c22-4090-901d-0accfeddb064)

Looks that problem happens only on windows
![Bez tytułu](https://github.com/qarmin/czkawka/assets/107509404/6e634606-ab46-4851-8a17-1384cbf79e1c)


Fix patch:
diff --git a/czkawka_core/i18n/en/czkawka_core.ftl b/czkawka_core/i18n/en/czkawka_core.ftl
index 1bac2fc3c..da3fd040f 100644
--- a/czkawka_core/i18n/en/czkawka_core.ftl
+++ b/czkawka_core/i18n/en/czkawka_core.ftl
@@ -18,7 +18,6 @@ core_folder_no_modification_date = Unable to get modification date from folder {
 
 core_missing_no_chosen_included_directory = At least one directory must be provided
 core_directory_wildcard_no_supported = Directories: Wildcards in path are not supported, ignoring { $path }
-core_directory_relative_path = Directories: Relative path are not supported, ignoring { $path }
 core_directory_must_exists = Directories:  Provided folder path must exist, ignoring { $path }
 core_directory_must_be_directory = Directories: Provided path must point at the directory, ignoring { $path }
 core_included_directory_zero_valid_directories = Included Directory ERROR: Not found even one correct path to included which is required
diff --git a/czkawka_core/src/common_directory.rs b/czkawka_core/src/common_directory.rs
index 9c6eb8cba..f85390e5d 100644
--- a/czkawka_core/src/common_directory.rs
+++ b/czkawka_core/src/common_directory.rs
@@ -22,8 +22,21 @@ impl Directories {
         Default::default()
     }
 
-    pub fn set_reference_directory(&mut self, reference_directory: Vec<PathBuf>) {
-        self.reference_directories = reference_directory;
+    pub fn set_reference_directory(&mut self, reference_directory: &[PathBuf]) -> Messages {
+        let mut messages: Messages = Messages::new();
+
+        self.reference_directories = reference_directory
+            .iter()
+            .filter_map(|directory| {
+                let (dir, msg) = Self::canonicalize_and_clear_path(directory, false);
+
+                messages.extend_with_another_messages(msg);
+
+                dir
+            })
+            .collect::<Vec<PathBuf>>();
+
+        messages
     }
 
     pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> Messages {
@@ -37,44 +50,14 @@ impl Directories {
         let directories: Vec<PathBuf> = included_directory;
 
         let mut checked_directories: Vec<PathBuf> = Vec::new();
-        for mut directory in directories {
-            if directory.to_string_lossy().contains('*') {
-                messages.warnings.push(flc!(
-                    "core_directory_wildcard_no_supported",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
+        for directory in directories {
+            let (dir, msg) = Self::canonicalize_and_clear_path(&directory, false);
 
-            if !directory.exists() {
-                messages.warnings.push(flc!(
-                    "core_directory_must_exists",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
-            if !directory.is_dir() {
-                messages.warnings.push(flc!(
-                    "core_directory_must_be_directory",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
+            messages.extend_with_another_messages(msg);
 
-            // If not checking windows strange paths, try to canonicalize them
-            if !directory.starts_with("\\") {
-                let Ok(dir2) = directory.canonicalize() else {
-                    messages.warnings.push(flc!(
-                        "core_directory_must_exists",
-                        generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                    ));
-                    continue;
-                };
-
-                directory = dir2;
+            if let Some(dir) = dir {
+                checked_directories.push(dir);
             }
-
-            checked_directories.push(directory);
         }
 
         if checked_directories.is_empty() {
@@ -103,46 +86,52 @@ impl Directories {
                 messages.errors.push(flc!("core_excluded_directory_pointless_slash"));
                 break;
             }
-            if directory_as_string.contains('*') {
-                messages.warnings.push(flc!(
-                    "core_directory_wildcard_no_supported",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
-            #[cfg(not(target_family = "windows"))]
-            if directory.is_relative() {
-                messages.warnings.push(flc!(
-                    "core_directory_relative_path",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
-            #[cfg(target_family = "windows")]
-            if directory.is_relative() && !directory.starts_with("\\") {
-                messages.warnings.push(flc!(
-                    "core_directory_relative_path",
-                    generate_translation_hashmap(vec![("path", directory.display().to_string())])
-                ));
-                continue;
-            }
 
-            if !directory.exists() {
-                // No error when excluded directories are missing
-                continue;
+            let (dir, msg) = Self::canonicalize_and_clear_path(&directory, true);
+
+            messages.extend_with_another_messages(msg);
+
+            if let Some(dir) = dir {
+                checked_directories.push(dir);
             }
-            if !directory.is_dir() {
+        }
+        self.excluded_directories = checked_directories;
+
+        messages
+    }
+
+    fn canonicalize_and_clear_path(directory: &Path, is_excluded: bool) -> (Option<PathBuf>, Messages) {
+        let mut messages = Messages::new();
+        let mut directory = directory.to_path_buf();
+        if !directory.exists() {
+            if !is_excluded {
                 messages.warnings.push(flc!(
-                    "core_directory_must_be_directory",
+                    "core_directory_must_exists",
                     generate_translation_hashmap(vec![("path", directory.display().to_string())])
                 ));
-                continue;
             }
-            checked_directories.push(directory);
+            return (None, messages);
         }
-        self.excluded_directories = checked_directories;
 
-        messages
+        if !directory.is_dir() {
+            messages.warnings.push(flc!(
+                "core_directory_must_be_directory",
+                generate_translation_hashmap(vec![("path", directory.display().to_string())])
+            ));
+            return (None, messages);
+        }
+
+        // Try to canonicalize them
+        if let Ok(dir) = directory.canonicalize() {
+            directory = dir;
+        }
+        if cfg!(windows) {
+            let path_str = directory.to_string_lossy().to_string();
+            if let Some(path_str) = path_str.strip_prefix(r"\\?\") {
+                directory = PathBuf::from(path_str);
+            }
+        }
+        (Some(directory), messages)
     }
 
     #[cfg(target_family = "unix")]
diff --git a/czkawka_core/src/common_tool.rs b/czkawka_core/src/common_tool.rs
index 694abe009..6964d1b22 100644
--- a/czkawka_core/src/common_tool.rs
+++ b/czkawka_core/src/common_tool.rs
@@ -112,7 +112,8 @@ pub trait CommonData {
     }
 
     fn set_reference_directory(&mut self, reference_directory: Vec<PathBuf>) {
-        self.get_cd_mut().directories.set_reference_directory(reference_directory);
+        let messages = self.get_cd_mut().directories.set_reference_directory(&reference_directory);
+        self.get_cd_mut().text_messages.extend_with_another_messages(messages);
     }
 
     #[cfg(target_family = "unix")]


Test patch: