Add exclude other filesystems option (#673)
This commit is contained in:
parent
0a35e542a3
commit
c64ab05648
|
@ -37,6 +37,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
#[structopt(flatten)]
|
||||
allow_hard_links: AllowHardLinks,
|
||||
#[structopt(flatten)]
|
||||
|
@ -54,6 +57,9 @@ pub enum Commands {
|
|||
delete_folders: bool,
|
||||
#[structopt(flatten)]
|
||||
file_to_save: FileToSave,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "big", about = "Finds big files", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka big -d /home/rafal/ /home/piszczal -e /home/rafal/Roman -n 25 -x VIDEO -f results.txt")]
|
||||
BiggestFiles {
|
||||
|
@ -73,6 +79,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "empty-files", about = "Finds empty files", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka empty-files -d /home/rafal /home/szczekacz -e /home/rafal/Pulpit -R -f results.txt")]
|
||||
EmptyFiles {
|
||||
|
@ -90,6 +99,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "temp", about = "Finds temporary files", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka temp -d /home/rafal/ -E */.git */tmp* *Pulpit -f results.txt -D")]
|
||||
Temporary {
|
||||
|
@ -105,6 +117,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "image", about = "Finds similar images", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka image -d /home/rafal/ -E */.git */tmp* *Pulpit -f results.txt")]
|
||||
SimilarImages {
|
||||
|
@ -124,6 +139,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
#[structopt(short = "g", long, default_value = "Gradient", parse(try_from_str = parse_similar_hash_algorithm), help = "Hash algorithm (allowed: Mean, Gradient, Blockhash, VertGradient, DoubleGradient)")]
|
||||
hash_alg: HashAlg,
|
||||
#[structopt(short = "z", long, default_value = "Lanczos3", parse(try_from_str = parse_similar_image_filter), help = "Hash algorithm (allowed: Lanczos3, Nearest, Triangle, Faussian, Catmullrom)")]
|
||||
|
@ -147,6 +165,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
#[structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = "8192", help = "Minimum size in bytes", long_help = "Minimum size of checked files in bytes, assigning bigger value may speed up searching")]
|
||||
minimal_file_size: u64,
|
||||
#[structopt(short = "i", long, parse(try_from_str = parse_maximal_file_size), default_value = "18446744073709551615", help = "Maximum size in bytes", long_help = "Maximum size of checked files in bytes, assigning lower value may speed up searching")]
|
||||
|
@ -168,6 +189,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "broken", about = "Finds broken files", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka broken -d /home/kicikici/ /home/szczek -e /home/kicikici/jestempsem -x jpg -f results.txt")]
|
||||
BrokenFiles {
|
||||
|
@ -185,6 +209,9 @@ pub enum Commands {
|
|||
file_to_save: FileToSave,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
},
|
||||
#[structopt(name = "video", about = "Finds similar video files", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka videos -d /home/rafal -f results.txt")]
|
||||
SimilarVideos {
|
||||
|
@ -202,6 +229,9 @@ pub enum Commands {
|
|||
allowed_extensions: AllowedExtensions,
|
||||
#[structopt(flatten)]
|
||||
not_recursive: NotRecursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
#[structopt(flatten)]
|
||||
exclude_other_filesystems: ExcludeOtherFilesystems,
|
||||
#[structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = "8192", help = "Minimum size in bytes", long_help = "Minimum size of checked files in bytes, assigning bigger value may speed up searching")]
|
||||
minimal_file_size: u64,
|
||||
#[structopt(short = "i", long, parse(try_from_str = parse_maximal_file_size), default_value = "18446744073709551615", help = "Maximum size in bytes", long_help = "Maximum size of checked files in bytes, assigning lower value may speed up searching")]
|
||||
|
@ -269,6 +299,13 @@ pub struct NotRecursive {
|
|||
pub not_recursive: bool,
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExcludeOtherFilesystems {
|
||||
#[structopt(short = "X", long, help = "Exclude files on other filesystmes")]
|
||||
pub exclude_other_filesystems: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct FileToSave {
|
||||
#[structopt(short, long, value_name = "file-name", help = "Saves the results into the file")]
|
||||
|
|
|
@ -44,6 +44,8 @@ fn main() {
|
|||
hash_type,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
allow_hard_links,
|
||||
dryrun,
|
||||
} => {
|
||||
|
@ -60,6 +62,8 @@ fn main() {
|
|||
df.set_delete_method(delete_method);
|
||||
df.set_hash_type(hash_type);
|
||||
df.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
df.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
df.set_ignore_hard_links(!allow_hard_links.allow_hard_links);
|
||||
df.set_dryrun(dryrun.dryrun);
|
||||
|
||||
|
@ -82,6 +86,8 @@ fn main() {
|
|||
file_to_save,
|
||||
excluded_directories,
|
||||
excluded_items,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
} => {
|
||||
let mut ef = EmptyFolder::new();
|
||||
|
||||
|
@ -89,6 +95,8 @@ fn main() {
|
|||
ef.set_excluded_directory(excluded_directories.excluded_directories);
|
||||
ef.set_excluded_items(excluded_items.excluded_items);
|
||||
ef.set_delete_folder(delete_folders);
|
||||
#[cfg(target_family = "unix")]
|
||||
ef.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
|
||||
ef.find_empty_folders(None, None);
|
||||
|
||||
|
@ -111,6 +119,8 @@ fn main() {
|
|||
number_of_files,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
delete_files,
|
||||
} => {
|
||||
let mut bf = BigFile::new();
|
||||
|
@ -121,6 +131,8 @@ fn main() {
|
|||
bf.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
|
||||
bf.set_number_of_files_to_check(number_of_files);
|
||||
bf.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
bf.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
if delete_files {
|
||||
bf.set_delete_method(big_file::DeleteMethod::Delete);
|
||||
}
|
||||
|
@ -146,6 +158,8 @@ fn main() {
|
|||
delete_files,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
} => {
|
||||
let mut ef = EmptyFiles::new();
|
||||
|
||||
|
@ -154,6 +168,8 @@ fn main() {
|
|||
ef.set_excluded_items(excluded_items.excluded_items);
|
||||
ef.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
|
||||
ef.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
ef.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
|
||||
if delete_files {
|
||||
ef.set_delete_method(empty_files::DeleteMethod::Delete);
|
||||
|
@ -176,6 +192,8 @@ fn main() {
|
|||
directories,
|
||||
excluded_directories,
|
||||
excluded_items,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
delete_files,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
|
@ -186,6 +204,8 @@ fn main() {
|
|||
tf.set_excluded_directory(excluded_directories.excluded_directories);
|
||||
tf.set_excluded_items(excluded_items.excluded_items);
|
||||
tf.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
tf.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
|
||||
if delete_files {
|
||||
tf.set_delete_method(temporary::DeleteMethod::Delete);
|
||||
|
@ -213,6 +233,8 @@ fn main() {
|
|||
maximal_file_size,
|
||||
similarity_preset,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
hash_alg,
|
||||
image_filter,
|
||||
hash_size,
|
||||
|
@ -225,6 +247,8 @@ fn main() {
|
|||
sf.set_minimal_file_size(minimal_file_size);
|
||||
sf.set_maximal_file_size(maximal_file_size);
|
||||
sf.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
sf.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
sf.set_image_filter(image_filter);
|
||||
sf.set_hash_alg(hash_alg);
|
||||
sf.set_hash_size(hash_size);
|
||||
|
@ -251,6 +275,8 @@ fn main() {
|
|||
// delete_files,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
minimal_file_size,
|
||||
maximal_file_size,
|
||||
music_similarity,
|
||||
|
@ -263,6 +289,8 @@ fn main() {
|
|||
mf.set_minimal_file_size(minimal_file_size);
|
||||
mf.set_maximal_file_size(maximal_file_size);
|
||||
mf.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
mf.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
mf.set_music_similarity(music_similarity);
|
||||
|
||||
// if delete_files {
|
||||
|
@ -289,6 +317,8 @@ fn main() {
|
|||
allowed_extensions,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
delete_files,
|
||||
} => {
|
||||
let mut ifs = InvalidSymlinks::new();
|
||||
|
@ -298,6 +328,8 @@ fn main() {
|
|||
ifs.set_excluded_items(excluded_items.excluded_items);
|
||||
ifs.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
|
||||
ifs.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
ifs.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
if delete_files {
|
||||
ifs.set_delete_method(invalid_symlinks::DeleteMethod::Delete);
|
||||
}
|
||||
|
@ -323,6 +355,8 @@ fn main() {
|
|||
delete_files,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
} => {
|
||||
let mut br = BrokenFiles::new();
|
||||
|
||||
|
@ -331,6 +365,8 @@ fn main() {
|
|||
br.set_excluded_items(excluded_items.excluded_items);
|
||||
br.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
|
||||
br.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
br.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
|
||||
if delete_files {
|
||||
br.set_delete_method(broken_files::DeleteMethod::Delete);
|
||||
|
@ -355,6 +391,8 @@ fn main() {
|
|||
excluded_items,
|
||||
file_to_save,
|
||||
not_recursive,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems,
|
||||
tolerance,
|
||||
minimal_file_size,
|
||||
maximal_file_size,
|
||||
|
@ -367,6 +405,8 @@ fn main() {
|
|||
vr.set_excluded_items(excluded_items.excluded_items);
|
||||
vr.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
|
||||
vr.set_recursive_search(!not_recursive.not_recursive);
|
||||
#[cfg(target_family = "unix")]
|
||||
vr.set_exclude_other_filesystems(exclude_other_filesystems.exclude_other_filesystems);
|
||||
vr.set_minimal_file_size(minimal_file_size);
|
||||
vr.set_maximal_file_size(maximal_file_size);
|
||||
vr.set_tolerance(tolerance);
|
||||
|
|
|
@ -23,6 +23,7 @@ core_directory_must_be_directory = Directories: Provided path must point at the
|
|||
core_included_directory_zero_valid_directories = Included Directory ERROR: Not found even one correct path to included which is required
|
||||
core_excluded_directory_pointless_slash = Directories: Excluding / is pointless, because it means that no files will be scanned
|
||||
core_directory_overlap = Directories: All directories to search overlaps with excluded directories
|
||||
core_directory_unable_to_get_device_id = Directories: Unable to get device id from folder { $path }
|
||||
|
||||
core_ffmpeg_not_found = Cannot find proper installation of FFmpeg
|
||||
core_ffmpeg_missing_in_snap = Similar Videos don't work currently with snap, if you want help look at - { $url }
|
||||
|
|
|
@ -116,6 +116,11 @@ impl BigFile {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
/// List of allowed extensions, only files with this extensions will be checking if are duplicates
|
||||
pub fn set_allowed_extensions(&mut self, allowed_extensions: String) {
|
||||
self.allowed_extensions.set_allowed_extensions(allowed_extensions, &mut self.text_messages);
|
||||
|
@ -217,6 +222,15 @@ impl BigFile {
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.directories.exclude_other_filesystems() {
|
||||
match self.directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
} else if metadata.is_file() {
|
||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
@ -388,6 +402,8 @@ impl DebugPrint for BigFile {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Number of files to check - {:?}", self.number_of_files_to_check);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
|
@ -148,6 +148,11 @@ impl BrokenFiles {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> bool {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages)
|
||||
}
|
||||
|
@ -262,6 +267,15 @@ impl BrokenFiles {
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.directories.exclude_other_filesystems() {
|
||||
match self.directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
} else if metadata.is_file() {
|
||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
@ -565,6 +579,8 @@ impl DebugPrint for BrokenFiles {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
|
@ -213,6 +213,15 @@ impl<'a, 'b, F> DirTraversalBuilder<'a, 'b, F> {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn exclude_other_filesystems(mut self, exclude_other_filesystems: bool) -> Self {
|
||||
match self.directories {
|
||||
Some(ref mut directories) => directories.set_exclude_other_filesystems(exclude_other_filesystems),
|
||||
None => panic!("Directories is None"),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn group_by<G, T>(self, group_by: G) -> DirTraversalBuilder<'a, 'b, G>
|
||||
where
|
||||
G: Fn(&FileEntry) -> T,
|
||||
|
@ -417,6 +426,15 @@ where
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if directories.exclude_other_filesystems() {
|
||||
match directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
}
|
||||
(EntryType::Dir, Collect::EmptyFolders) => {
|
||||
|
@ -426,6 +444,16 @@ where
|
|||
set_as_not_empty_folder_list.push(current_folder.clone());
|
||||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if directories.exclude_other_filesystems() {
|
||||
match directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder.clone());
|
||||
folder_entries_list.push((
|
||||
next_folder.clone(),
|
||||
|
@ -479,6 +507,15 @@ where
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if directories.exclude_other_filesystems() {
|
||||
match directories.is_on_other_filesystems(¤t_file_name) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
// Creating new file entry
|
||||
let fe: FileEntry = FileEntry {
|
||||
path: current_file_name.clone(),
|
||||
|
@ -510,6 +547,15 @@ where
|
|||
}
|
||||
}
|
||||
(EntryType::File, Collect::EmptyFolders) | (EntryType::Symlink, Collect::EmptyFolders) => {
|
||||
#[cfg(target_family = "unix")]
|
||||
if directories.exclude_other_filesystems() {
|
||||
match directories.is_on_other_filesystems(¤t_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
set_as_not_empty_folder_list.push(current_folder.clone());
|
||||
}
|
||||
(EntryType::File, Collect::InvalidSymlinks) => {
|
||||
|
@ -539,6 +585,15 @@ where
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if directories.exclude_other_filesystems() {
|
||||
match directories.is_on_other_filesystems(¤t_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
let mut destination_path = PathBuf::new();
|
||||
let type_of_error;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::time::SystemTime;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::{fs, os::unix::fs::MetadataExt};
|
||||
|
||||
use crate::common::Common;
|
||||
use crate::common_messages::Messages;
|
||||
|
@ -11,6 +13,10 @@ pub struct Directories {
|
|||
pub excluded_directories: Vec<PathBuf>,
|
||||
pub included_directories: Vec<PathBuf>,
|
||||
pub reference_directories: Vec<PathBuf>,
|
||||
#[cfg(target_family = "unix")]
|
||||
exclude_other_filesystems: Option<bool>,
|
||||
#[cfg(target_family = "unix")]
|
||||
included_dev_ids: Vec<u64>,
|
||||
}
|
||||
|
||||
impl Directories {
|
||||
|
@ -146,6 +152,11 @@ impl Directories {
|
|||
Common::print_time(start_time, SystemTime::now(), "set_excluded_directory".to_string());
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.exclude_other_filesystems = Some(exclude_other_filesystems)
|
||||
}
|
||||
|
||||
/// Remove unused entries when included or excluded overlaps with each other or are duplicated etc.
|
||||
pub fn optimize_directories(&mut self, recursive_search: bool, text_messages: &mut Messages) -> bool {
|
||||
let start_time: SystemTime = SystemTime::now();
|
||||
|
@ -284,6 +295,21 @@ impl Directories {
|
|||
self.excluded_directories.sort();
|
||||
self.included_directories.sort();
|
||||
Common::print_time(start_time, SystemTime::now(), "optimize_directories".to_string());
|
||||
|
||||
// Get device IDs for included directories
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.exclude_other_filesystems() {
|
||||
for d in &self.included_directories {
|
||||
match fs::metadata(d) {
|
||||
Ok(m) => self.included_dev_ids.push(m.dev()),
|
||||
Err(_) => text_messages.errors.push(flc!(
|
||||
"core_directory_unable_to_get_device_id",
|
||||
generate_translation_hashmap(vec![("path", d.display().to_string())])
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -295,4 +321,23 @@ impl Directories {
|
|||
// We're assuming that `excluded_directories` are already normalized
|
||||
self.excluded_directories.iter().any(|p| p.as_path() == path)
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn exclude_other_filesystems(&self) -> bool {
|
||||
self.exclude_other_filesystems.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Checks whether a specified directory is on other filesystems rather then include
|
||||
/// directories
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn is_on_other_filesystems(&self, path: impl AsRef<Path>) -> Result<bool, String> {
|
||||
let path = path.as_ref();
|
||||
match fs::metadata(path) {
|
||||
Ok(m) => Ok(!self.included_dev_ids.iter().any(|&id| id == m.dev())),
|
||||
Err(_) => Err(flc!(
|
||||
"core_directory_unable_to_get_device_id",
|
||||
generate_translation_hashmap(vec![("path", path.display().to_string())])
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,6 +267,11 @@ impl DuplicateFinder {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages);
|
||||
}
|
||||
|
@ -986,6 +991,8 @@ impl DebugPrint for DuplicateFinder {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Minimum file size - {:?}", self.minimal_file_size);
|
||||
println!("Checking Method - {:?}", self.check_method);
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
|
|
|
@ -96,6 +96,11 @@ impl EmptyFiles {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> bool {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages)
|
||||
}
|
||||
|
@ -197,6 +202,8 @@ impl DebugPrint for EmptyFiles {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
|
@ -67,6 +67,11 @@ impl EmptyFolder {
|
|||
&self.information
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_excluded_items(&mut self, excluded_items: Vec<String>) {
|
||||
self.excluded_items.set_excluded_items(excluded_items, &mut self.text_messages);
|
||||
}
|
||||
|
|
|
@ -95,6 +95,11 @@ impl InvalidSymlinks {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> bool {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages)
|
||||
}
|
||||
|
@ -193,6 +198,8 @@ impl DebugPrint for InvalidSymlinks {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
|
@ -195,6 +195,11 @@ impl SameMusic {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
/// Set included dir which needs to be relative, exists etc.
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages);
|
||||
|
@ -826,6 +831,8 @@ impl DebugPrint for SameMusic {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
|
@ -238,6 +238,12 @@ impl SimilarImages {
|
|||
pub fn set_recursive_search(&mut self, recursive_search: bool) {
|
||||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_allowed_extensions(&mut self, allowed_extensions: String) {
|
||||
self.allowed_extensions.set_allowed_extensions(allowed_extensions, &mut self.text_messages);
|
||||
}
|
||||
|
@ -390,6 +396,15 @@ impl SimilarImages {
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.directories.exclude_other_filesystems() {
|
||||
match self.directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
} else if metadata.is_file() {
|
||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
|
|
@ -166,6 +166,11 @@ impl SimilarVideos {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_minimal_file_size(&mut self, minimal_file_size: u64) {
|
||||
self.minimal_file_size = match minimal_file_size {
|
||||
0 => 1,
|
||||
|
@ -329,6 +334,15 @@ impl SimilarVideos {
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.directories.exclude_other_filesystems() {
|
||||
match self.directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
} else if metadata.is_file() {
|
||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
|
|
@ -109,6 +109,11 @@ impl Temporary {
|
|||
self.recursive_search = recursive_search;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn set_exclude_other_filesystems(&mut self, exclude_other_filesystems: bool) {
|
||||
self.directories.set_exclude_other_filesystems(exclude_other_filesystems);
|
||||
}
|
||||
|
||||
pub fn set_included_directory(&mut self, included_directory: Vec<PathBuf>) -> bool {
|
||||
self.directories.set_included_directory(included_directory, &mut self.text_messages)
|
||||
}
|
||||
|
@ -219,6 +224,15 @@ impl Temporary {
|
|||
continue 'dir;
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
if self.directories.exclude_other_filesystems() {
|
||||
match self.directories.is_on_other_filesystems(&next_folder) {
|
||||
Ok(true) => continue 'dir,
|
||||
Err(e) => warnings.push(e.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
dir_result.push(next_folder);
|
||||
} else if metadata.is_file() {
|
||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
@ -362,6 +376,8 @@ impl DebugPrint for Temporary {
|
|||
println!("Included directories - {:?}", self.directories.included_directories);
|
||||
println!("Excluded directories - {:?}", self.directories.excluded_directories);
|
||||
println!("Recursive search - {}", self.recursive_search);
|
||||
#[cfg(target_family = "unix")]
|
||||
println!("Skip other filesystmes - {}", self.directories.exclude_other_filesystems());
|
||||
println!("Delete Method - {:?}", self.delete_method);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue