Format
This commit is contained in:
parent
5f7e5a3b86
commit
8460f29c3a
|
@ -22,35 +22,21 @@ impl Directories {
|
|||
Default::default()
|
||||
}
|
||||
|
||||
pub fn set_reference_directory(&mut self, reference_directory: Vec<PathBuf>) {
|
||||
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(|d| {
|
||||
let mut directory = d.clone();
|
||||
if directory.to_string_lossy().contains('*') {
|
||||
return None;
|
||||
}
|
||||
.filter_map(|directory| {
|
||||
let (dir, msg) = Self::canonicalize_and_clear_path(directory, false);
|
||||
|
||||
if !directory.exists() {
|
||||
return None;
|
||||
}
|
||||
if !directory.is_dir() {
|
||||
return None;
|
||||
}
|
||||
messages.extend_with_another_messages(msg);
|
||||
|
||||
// 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)
|
||||
dir
|
||||
})
|
||||
.collect::<Vec<PathBuf>>();
|
||||
|
||||
messages
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> Messages {
|
||||
|
@ -64,41 +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);
|
||||
|
||||
// Try to canonicalize them
|
||||
if let Ok(dir) = directory.canonicalize() {
|
||||
directory = dir;
|
||||
if let Some(dir) = dir {
|
||||
checked_directories.push(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);
|
||||
}
|
||||
};
|
||||
checked_directories.push(directory);
|
||||
}
|
||||
|
||||
if checked_directories.is_empty() {
|
||||
|
@ -121,51 +80,60 @@ impl Directories {
|
|||
let directories: Vec<PathBuf> = excluded_directory;
|
||||
|
||||
let mut checked_directories: Vec<PathBuf> = Vec::new();
|
||||
for mut directory in directories {
|
||||
for directory in directories {
|
||||
let directory_as_string = directory.to_string_lossy();
|
||||
if directory_as_string == "/" {
|
||||
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;
|
||||
}
|
||||
|
||||
if !directory.exists() {
|
||||
// No error when excluded directories are missing
|
||||
continue;
|
||||
}
|
||||
let (dir, msg) = Self::canonicalize_and_clear_path(&directory, true);
|
||||
|
||||
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);
|
||||
|
||||
// Try to canonicalize them
|
||||
if let Ok(dir) = directory.canonicalize() {
|
||||
directory = dir;
|
||||
if let Some(dir) = dir {
|
||||
checked_directories.push(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);
|
||||
}
|
||||
}
|
||||
|
||||
checked_directories.push(directory);
|
||||
}
|
||||
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_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")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.exclude_other_filesystems = Some(exclude_other_filesystems);
|
||||
|
@ -327,12 +295,6 @@ impl Directories {
|
|||
}
|
||||
|
||||
pub fn is_in_referenced_directory(&self, path: &Path) -> bool {
|
||||
dbg!(
|
||||
&self.reference_directories,
|
||||
path,
|
||||
self.reference_directories.iter().any(|e| path.starts_with(e)),
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
);
|
||||
self.reference_directories.iter().any(|e| path.starts_with(e))
|
||||
}
|
||||
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Reference in a new issue