Canonicalize also windows paths (#1093)
* Canonicalize also windows paths * El capone * Hehe * HASASS * Also regree * K * Kek * Format
This commit is contained in:
parent
44400e08af
commit
59ff9f3e3c
|
@ -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_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_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_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_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
|
core_included_directory_zero_valid_directories = Included Directory ERROR: Not found even one correct path to included which is required
|
||||||
|
|
|
@ -22,8 +22,21 @@ impl Directories {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_reference_directory(&mut self, reference_directory: Vec<PathBuf>) {
|
pub fn set_reference_directory(&mut self, reference_directory: &[PathBuf]) -> Messages {
|
||||||
self.reference_directories = reference_directory;
|
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 {
|
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 directories: Vec<PathBuf> = included_directory;
|
||||||
|
|
||||||
let mut checked_directories: Vec<PathBuf> = Vec::new();
|
let mut checked_directories: Vec<PathBuf> = Vec::new();
|
||||||
for mut directory in directories {
|
for directory in directories {
|
||||||
if directory.to_string_lossy().contains('*') {
|
let (dir, msg) = Self::canonicalize_and_clear_path(&directory, false);
|
||||||
messages.warnings.push(flc!(
|
|
||||||
"core_directory_wildcard_no_supported",
|
|
||||||
generate_translation_hashmap(vec![("path", directory.display().to_string())])
|
|
||||||
));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !directory.exists() {
|
messages.extend_with_another_messages(msg);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If not checking windows strange paths, try to canonicalize them
|
if let Some(dir) = dir {
|
||||||
if !directory.starts_with("\\") {
|
checked_directories.push(dir);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checked_directories.push(directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if checked_directories.is_empty() {
|
if checked_directories.is_empty() {
|
||||||
|
@ -103,48 +86,54 @@ impl Directories {
|
||||||
messages.errors.push(flc!("core_excluded_directory_pointless_slash"));
|
messages.errors.push(flc!("core_excluded_directory_pointless_slash"));
|
||||||
break;
|
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() {
|
let (dir, msg) = Self::canonicalize_and_clear_path(&directory, true);
|
||||||
// No error when excluded directories are missing
|
|
||||||
continue;
|
messages.extend_with_another_messages(msg);
|
||||||
|
|
||||||
|
if let Some(dir) = dir {
|
||||||
|
checked_directories.push(dir);
|
||||||
}
|
}
|
||||||
if !directory.is_dir() {
|
|
||||||
messages.warnings.push(flc!(
|
|
||||||
"core_directory_must_be_directory",
|
|
||||||
generate_translation_hashmap(vec![("path", directory.display().to_string())])
|
|
||||||
));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
checked_directories.push(directory);
|
|
||||||
}
|
}
|
||||||
self.excluded_directories = checked_directories;
|
self.excluded_directories = checked_directories;
|
||||||
|
|
||||||
messages
|
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_exists",
|
||||||
|
generate_translation_hashmap(vec![("path", directory.display().to_string())])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return (None, 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")]
|
#[cfg(target_family = "unix")]
|
||||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||||
self.exclude_other_filesystems = Some(exclude_other_filesystems);
|
self.exclude_other_filesystems = Some(exclude_other_filesystems);
|
||||||
|
|
|
@ -112,7 +112,8 @@ pub trait CommonData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_reference_directory(&mut self, reference_directory: Vec<PathBuf>) {
|
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")]
|
#[cfg(target_family = "unix")]
|
||||||
|
|
Loading…
Reference in a new issue