|
|
|
@ -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,49 +80,58 @@ 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);
|
|
|
|
|
|
|
|
|
|
messages.extend_with_another_messages(msg);
|
|
|
|
|
|
|
|
|
|
if let Some(dir) = dir {
|
|
|
|
|
checked_directories.push(dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.excluded_directories = checked_directories;
|
|
|
|
|
|
|
|
|
|
messages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !directory.is_dir() {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (None, messages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checked_directories.push(directory);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
self.excluded_directories = checked_directories;
|
|
|
|
|
|
|
|
|
|
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")]
|
|
|
|
@ -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))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|