1
0
Fork 0
mirror of synced 2024-04-27 09:12:06 +12:00

Add better errors explanation(native from libraries) (#446)

This commit is contained in:
Rafał Mikrut 2021-11-14 15:53:55 +01:00 committed by GitHub
parent dc8c14ea3c
commit 742139379c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 310 additions and 308 deletions

8
Cargo.lock generated
View file

@ -249,9 +249,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.71"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
dependencies = [
"jobserver",
]
@ -2083,9 +2083,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
dependencies = [
"tinyvec_macros",
]

View file

@ -165,23 +165,23 @@ impl BigFile {
let current_folder = folders_to_check.pop().unwrap();
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -223,15 +223,15 @@ impl BigFile {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
} // Permissions Denied
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
}
},
};
@ -363,21 +363,19 @@ impl SaveResults for BigFile {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push("Failed to create file ".to_string() + file_name.as_str());
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -206,8 +206,8 @@ impl BrokenFiles {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -216,15 +216,15 @@ impl BrokenFiles {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -243,7 +243,10 @@ impl BrokenFiles {
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -273,14 +276,14 @@ impl BrokenFiles {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
size: metadata.len(),
@ -401,7 +404,7 @@ impl BrokenFiles {
Some(Some(file_entry))
}
},
Err(_) => Some(None),
Err(_inspected) => Some(None), // TODO maybe throw error or something
},
#[cfg(feature = "broken_audio")]
TypeOfFile::Audio => match fs::File::open(&file_entry.path) {
@ -414,7 +417,7 @@ impl BrokenFiles {
Some(Some(file_entry))
}
},
Err(_) => Some(None),
Err(_inspected) => Some(None), // TODO maybe throw error or something
},
// This means that cache read invalid value because maybe cache comes from different czkawka version
@ -529,21 +532,19 @@ impl SaveResults for BrokenFiles {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}
@ -585,15 +586,15 @@ fn save_cache_to_file(hashmap_file_entry: &BTreeMap<String, FileEntry>, text_mes
text_messages.messages.push(format!("Config dir {} is a file!", cache_dir.display()));
return;
}
} else if fs::create_dir_all(&cache_dir).is_err() {
text_messages.messages.push(format!("Cannot create config dir {}", cache_dir.display()));
} else if let Err(e) = fs::create_dir_all(&cache_dir) {
text_messages.messages.push(format!("Cannot create config dir {}, reason {}", cache_dir.display(), e));
return;
}
let cache_file = cache_dir.join(CACHE_FILE_NAME);
let file_handler = match OpenOptions::new().truncate(true).write(true).create(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
text_messages.messages.push(format!("Cannot create or open cache file {}", cache_file.display()));
Err(e) => {
text_messages.messages.push(format!("Cannot create or open cache file {}, reason {}", cache_file.display(), e));
return;
}
};
@ -604,8 +605,8 @@ fn save_cache_to_file(hashmap_file_entry: &BTreeMap<String, FileEntry>, text_mes
if file_entry.size > 1024 {
let string: String = format!("{}//{}//{}//{}", file_entry.path.display(), file_entry.size, file_entry.modified_date, file_entry.error_string);
if writeln!(writer, "{}", string).is_err() {
text_messages.messages.push(format!("Failed to save some data to cache file {}", cache_file.display()));
if let Err(e) = writeln!(writer, "{}", string) {
text_messages.messages.push(format!("Failed to save some data to cache file {}, reason {}", cache_file.display(), e));
return;
};
}
@ -617,9 +618,10 @@ fn load_cache_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String,
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
let cache_dir = PathBuf::from(proj_dirs.cache_dir());
let cache_file = cache_dir.join(CACHE_FILE_NAME);
// TODO add before checking if cache exists(if not just return) but if exists then enable error
let file_handler = match OpenOptions::new().read(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
// text_messages.messages.push(format!("Cannot find or open cache file {}", cache_file.display())); // This shouldn't be write to output
return None;
}
@ -633,8 +635,8 @@ fn load_cache_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String,
for (index, line) in reader.lines().enumerate() {
let line = match line {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}", index + 1, cache_file.display()));
Err(e) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}, reason {}", index + 1, cache_file.display(), e));
return None;
}
};
@ -651,15 +653,19 @@ fn load_cache_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String,
path: PathBuf::from(uuu[0]),
size: match uuu[1].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid size value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid size value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},
modified_date: match uuu[2].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},

View file

@ -20,15 +20,11 @@ impl Common {
for entry in entries {
path = Path::new(entry);
if path.is_dir() {
match fs::remove_dir_all(&entry) {
Ok(_) => (),
Err(_) => warnings.push("Failed to remove folder ".to_owned() + entry.as_str()),
}
} else {
match fs::remove_file(&entry) {
Ok(_) => (),
Err(_) => warnings.push("Failed to remove file ".to_owned() + entry.as_str()),
if let Err(e) = fs::remove_dir_all(&entry) {
warnings.push(format!("Failed to remove folder {}, reason {}", entry, e));
}
} else if let Err(e) = fs::remove_file(&entry) {
warnings.push(format!("Failed to remove file {}, reason {}", entry, e));
}
}
warnings
@ -37,15 +33,11 @@ impl Common {
let path: &Path = Path::new(entry);
let mut warning: String = String::from("");
if path.is_dir() {
match fs::remove_dir_all(&entry) {
Ok(_) => (),
Err(_) => warning = "Failed to remove folder ".to_owned() + entry,
}
} else {
match fs::remove_file(&entry) {
Ok(_) => (),
Err(_) => warning = "Failed to remove file ".to_owned() + entry,
if let Err(e) = fs::remove_dir_all(&entry) {
warning = format!("Failed to remove folder {}, reason {}", entry, e)
}
} else if let Err(e) = fs::remove_file(&entry) {
warning = format!("Failed to remove file {}, reason {}", entry, e)
}
warning
}

View file

@ -357,8 +357,8 @@ impl DuplicateFinder {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -367,15 +367,15 @@ impl DuplicateFinder {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
@ -399,7 +399,10 @@ impl DuplicateFinder {
// let mut have_valid_extension: bool;
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue 'dir,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -425,14 +428,14 @@ impl DuplicateFinder {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue 'dir;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
hash: "".to_string(),
@ -528,8 +531,8 @@ impl DuplicateFinder {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -538,15 +541,15 @@ impl DuplicateFinder {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
@ -570,7 +573,10 @@ impl DuplicateFinder {
// let mut have_valid_extension: bool;
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue 'dir,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -597,14 +603,14 @@ impl DuplicateFinder {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue 'dir;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
hash: "".to_string(),
@ -1084,21 +1090,19 @@ impl SaveResults for DuplicateFinder {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}
match self.check_method {
@ -1350,15 +1354,15 @@ fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages: &mu
text_messages.messages.push(format!("Config dir {} is a file!", cache_dir.display()));
return;
}
} else if fs::create_dir_all(&cache_dir).is_err() {
text_messages.messages.push(format!("Cannot create config dir {}", cache_dir.display()));
} else if let Err(e) = fs::create_dir_all(&cache_dir) {
text_messages.messages.push(format!("Cannot create config dir {}, reason {}", cache_dir.display(), e));
return;
}
let cache_file = cache_dir.join(CACHE_FILE_NAME.replace(".", format!("_{:?}.", type_of_hash).as_str()));
let file_handler = match OpenOptions::new().truncate(true).write(true).create(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
text_messages.messages.push(format!("Cannot create or open cache file {}", cache_file.display()));
Err(e) => {
text_messages.messages.push(format!("Cannot create or open cache file {}, reason {}", cache_file.display(), e));
return;
}
};
@ -1369,8 +1373,8 @@ fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages: &mu
if file_entry.size >= minimal_cache_file_size {
let string: String = format!("{}//{}//{}//{}", file_entry.path.display(), file_entry.size, file_entry.modified_date, file_entry.hash);
if writeln!(writer, "{}", string).is_err() {
text_messages.messages.push(format!("Failed to save some data to cache file {}", cache_file.display()));
if let Err(e) = writeln!(writer, "{}", string) {
text_messages.messages.push(format!("Failed to save some data to cache file {}, reason {}", cache_file.display(), e));
return;
};
}
@ -1386,7 +1390,7 @@ pub trait MyHasher {
fn hash_calculation(buffer: &mut [u8], file_entry: &FileEntry, hash_type: &HashType, limit: u64) -> Result<(String, u64), String> {
let mut file_handler = match File::open(&file_entry.path) {
Ok(t) => t,
Err(_) => return Err(format!("Unable to check hash of file {}", file_entry.path.display())),
Err(e) => return Err(format!("Unable to check hash of file {}, reason {}", file_entry.path.display(), e)),
};
let hasher = &mut *hash_type.hasher();
let mut current_file_read_bytes: u64 = 0;
@ -1394,7 +1398,7 @@ fn hash_calculation(buffer: &mut [u8], file_entry: &FileEntry, hash_type: &HashT
let n = match file_handler.read(buffer) {
Ok(0) => break,
Ok(t) => t,
Err(_) => return Err(format!("Error happened when checking hash of file {}", file_entry.path.display())),
Err(e) => return Err(format!("Error happened when checking hash of file {}, reason {}", file_entry.path.display(), e)),
};
current_file_read_bytes += n as u64;
@ -1413,7 +1417,7 @@ fn load_hashes_from_file(text_messages: &mut Messages, type_of_hash: &HashType)
let cache_file = cache_dir.join(CACHE_FILE_NAME.replace(".", format!("_{:?}.", type_of_hash).as_str()));
let file_handler = match OpenOptions::new().read(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
// text_messages.messages.push(format!("Cannot find or open cache file {}", cache_file.display())); // This shouldn't be write to output
return None;
}
@ -1427,8 +1431,8 @@ fn load_hashes_from_file(text_messages: &mut Messages, type_of_hash: &HashType)
for (index, line) in reader.lines().enumerate() {
let line = match line {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}", index + 1, cache_file.display()));
Err(e) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}, reason {}", index + 1, cache_file.display(), e));
return None;
}
};
@ -1445,15 +1449,19 @@ fn load_hashes_from_file(text_messages: &mut Messages, type_of_hash: &HashType)
path: PathBuf::from(uuu[0]),
size: match uuu[1].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid size value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid size value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},
modified_date: match uuu[2].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},

View file

@ -177,8 +177,8 @@ impl EmptyFiles {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -187,15 +187,15 @@ impl EmptyFiles {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -214,7 +214,10 @@ impl EmptyFiles {
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -239,14 +242,14 @@ impl EmptyFiles {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
};
@ -332,21 +335,19 @@ impl SaveResults for EmptyFiles {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -195,7 +195,7 @@ impl EmptyFolder {
// Checked folder may be deleted or we may not have permissions to open it so we assume that this folder is not be empty
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
folders_checked.get_mut(&current_folder).unwrap().is_empty = FolderEmptiness::No;
continue;
}
@ -204,14 +204,14 @@ impl EmptyFolder {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
set_as_not_empty_folder(&mut folders_checked, &current_folder);
continue 'dir;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
set_as_not_empty_folder(&mut folders_checked, &current_folder);
continue 'dir;
} //Permissions denied
@ -233,16 +233,14 @@ impl EmptyFolder {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("Folder {} seems to be modified before Unix Epoch.", current_folder.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Failed to read modification date of folder {}", current_folder.display()));
// Can't read data, so assuming that is not empty
set_as_not_empty_folder(&mut folders_checked, &current_folder);
continue 'dir;
Err(e) => {
self.text_messages.warnings.push(format!("Failed to read modification date of folder {}, reason {}", current_folder.display(), e));
0
}
},
},
@ -275,7 +273,7 @@ impl EmptyFolder {
for name in self.empty_folder_list.keys() {
match fs::remove_dir_all(name) {
Ok(_) => (),
Err(_) => self.text_messages.warnings.push(format!("Failed to remove folder {}", name.display())),
Err(e) => self.text_messages.warnings.push(format!("Failed to remove folder {}, reason {}", name.display(), e)),
};
}
@ -335,15 +333,15 @@ impl SaveResults for EmptyFolder {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push("Failed to create file ".to_string() + file_name.as_str());
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(writer, "Results of searching {:?} with excluded directories {:?}", self.directories.included_directories, self.directories.excluded_directories).is_err() {
self.text_messages.errors.push("Failed to save results to file ".to_string() + file_name.as_str());
if let Err(e) = writeln!(writer, "Results of searching {:?} with excluded directories {:?}", self.directories.included_directories, self.directories.excluded_directories) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -186,8 +186,8 @@ impl InvalidSymlinks {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -196,15 +196,15 @@ impl InvalidSymlinks {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -225,7 +225,10 @@ impl InvalidSymlinks {
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -264,8 +267,8 @@ impl InvalidSymlinks {
current_path = match current_path.read_link() {
Ok(t) => t,
Err(_) => {
// Looks that some next symlinks are broken, but we do nothing with it
Err(_inspected) => {
// Looks that some next symlinks are broken, but we do nothing with it - TODO why they are broken
continue 'dir;
}
};
@ -273,7 +276,7 @@ impl InvalidSymlinks {
number_of_loop += 1;
}
}
Err(_) => {
Err(_inspected) => {
// Failed to load info about it
type_of_error = ErrorType::NonExistentFile;
}
@ -287,14 +290,14 @@ impl InvalidSymlinks {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
};
@ -379,21 +382,19 @@ impl SaveResults for InvalidSymlinks {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -233,8 +233,8 @@ impl SameMusic {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -243,15 +243,15 @@ impl SameMusic {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue 'dir;
} //Permissions denied
};
@ -288,13 +288,13 @@ impl SameMusic {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
continue 'dir;
} // Permissions Denied
},
@ -370,7 +370,7 @@ impl SameMusic {
let tag = match Tag::new().read_from_path(&file_entry.path) {
Ok(t) => t,
Err(_) => return Some(None), // Data not in utf-8, etc.
Err(_inspected) => return Some(None), // Data not in utf-8, etc., TODO this should be probably added to warnings, errors
};
file_entry.title = match tag.title() {
@ -684,21 +684,19 @@ impl SaveResults for SameMusic {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -233,8 +233,8 @@ impl SimilarImages {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -243,15 +243,15 @@ impl SimilarImages {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -275,7 +275,10 @@ impl SimilarImages {
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -299,14 +302,14 @@ impl SimilarImages {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
@ -410,7 +413,7 @@ impl SimilarImages {
let image = match image::open(file_entry.path.clone()) {
Ok(t) => t,
Err(_) => return Some(None), // Something is wrong with image
Err(_inspected) => return Some(None), // Something is wrong with image
};
let dimensions = image.dimensions();
@ -598,21 +601,19 @@ impl SaveResults for SimilarImages {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push("Failed to create file ".to_string() + file_name.as_str());
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}
@ -676,15 +677,15 @@ fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages: &mu
text_messages.messages.push(format!("Config dir {} is a file!", cache_dir.display()));
return;
}
} else if fs::create_dir_all(&cache_dir).is_err() {
text_messages.messages.push(format!("Cannot create config dir {}", cache_dir.display()));
} else if let Err(e) = fs::create_dir_all(&cache_dir) {
text_messages.messages.push(format!("Cannot create config dir {}, reason {}", cache_dir.display(), e));
return;
}
let cache_file = cache_dir.join(CACHE_FILE_NAME);
let file_handler = match OpenOptions::new().truncate(true).write(true).create(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
text_messages.messages.push(format!("Cannot create or open cache file {}", cache_file.display()));
Err(e) => {
text_messages.messages.push(format!("Cannot create or open cache file {}, reason {}", cache_file.display(), e));
return;
}
};
@ -700,8 +701,8 @@ fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages: &mu
}
string += file_entry.hash[file_entry.hash.len() - 1].to_string().as_str();
if writeln!(writer, "{}", string).is_err() {
text_messages.messages.push(format!("Failed to save some data to cache file {}", cache_file.display()));
if let Err(e) = writeln!(writer, "{}", string) {
text_messages.messages.push(format!("Failed to save some data to cache file {}, reason {}", cache_file.display(), e));
return;
};
}
@ -713,7 +714,7 @@ fn load_hashes_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String
let cache_file = cache_dir.join(CACHE_FILE_NAME);
let file_handler = match OpenOptions::new().read(true).open(&cache_file) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
// text_messages.messages.push(format!("Cannot find or open cache file {}", cache_file.display())); // This shouldn't be write to output
return None;
}
@ -727,8 +728,8 @@ fn load_hashes_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String
for (index, line) in reader.lines().enumerate() {
let line = match line {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}", index + 1, cache_file.display()));
Err(e) => {
text_messages.warnings.push(format!("Failed to load line number {} from cache file {}, reason {}", index + 1, cache_file.display(), e));
return None;
}
};
@ -743,8 +744,10 @@ fn load_hashes_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String
for i in 0..hash.len() {
hash[i] = match uuu[4 + i].parse::<u8>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid hash value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid hash value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
};
@ -772,16 +775,20 @@ fn load_hashes_from_file(text_messages: &mut Messages) -> Option<BTreeMap<String
path: PathBuf::from(uuu[0]),
size: match uuu[1].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid size value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid size value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},
dimensions: uuu[2].to_string(),
modified_date: match uuu[3].parse::<u64>() {
Ok(t) => t,
Err(_) => {
text_messages.warnings.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}", index + 1, line, cache_file.display()));
Err(e) => {
text_messages
.warnings
.push(format!("Found invalid modified date value in line {} - ({}) in cache file {}, reason {}", index + 1, line, cache_file.display(), e));
continue;
}
},

View file

@ -168,8 +168,8 @@ impl Temporary {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -178,15 +178,15 @@ impl Temporary {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -205,7 +205,10 @@ impl Temporary {
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -227,14 +230,14 @@ impl Temporary {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
};
@ -317,21 +320,19 @@ impl SaveResults for Temporary {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -202,8 +202,8 @@ impl ZeroedFiles {
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot open dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot open dir {}, reason {}", current_folder.display(), e));
continue;
} // Permissions denied
};
@ -212,15 +212,15 @@ impl ZeroedFiles {
'dir: for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read entry in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}", current_folder.display()));
Err(e) => {
self.text_messages.warnings.push(format!("Cannot read metadata in dir {}, reason {}", current_folder.display(), e));
continue;
} //Permissions denied
};
@ -243,7 +243,10 @@ impl ZeroedFiles {
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
Err(_inspected) => {
println!("File {:?} has not valid UTF-8 name", entry_data);
continue 'dir;
}
}
.to_lowercase();
@ -268,14 +271,14 @@ impl ZeroedFiles {
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
Err(_) => {
Err(_inspected) => {
self.text_messages.warnings.push(format!("File {} seems to be modified before Unix Epoch.", current_file_name.display()));
0
}
},
Err(_) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}", current_file_name.display()));
continue;
Err(e) => {
self.text_messages.warnings.push(format!("Unable to get modification date from file {}, reason {}", current_file_name.display(), e));
0
} // Permissions Denied
},
};
@ -342,7 +345,7 @@ impl ZeroedFiles {
let mut n;
let mut file_handler: File = match File::open(&file_entry.path) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
return Some(None);
}
};
@ -351,7 +354,7 @@ impl ZeroedFiles {
let mut buffer = [0u8; 64];
n = match file_handler.read(&mut buffer) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
return Some(None);
}
};
@ -365,7 +368,7 @@ impl ZeroedFiles {
let mut buffer = [0u8; 1024 * 32];
n = match file_handler.read(&mut buffer) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
return Some(None);
}
};
@ -467,21 +470,19 @@ impl SaveResults for ZeroedFiles {
let file_handler = match File::create(&file_name) {
Ok(t) => t,
Err(_) => {
self.text_messages.errors.push(format!("Failed to create file {}", file_name));
Err(e) => {
self.text_messages.errors.push(format!("Failed to create file {}, reason {}", file_name, e));
return false;
}
};
let mut writer = BufWriter::new(file_handler);
if writeln!(
if let Err(e) = writeln!(
writer,
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.is_err()
{
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
) {
self.text_messages.errors.push(format!("Failed to save results to file {}, reason {}", file_name, e));
return false;
}

View file

@ -9,22 +9,22 @@ const INSTRUCTION_SITE: &str = "https://github.com/qarmin/czkawka/blob/master/in
pub fn connect_about_buttons(gui_data: &GuiData) {
let button_donation = gui_data.about.button_donation.clone();
button_donation.connect_clicked(move |_| {
if open::that(SPONSOR_SITE).is_err() {
println!("Failed to open sponsor site: {}", SPONSOR_SITE)
if let Err(e) = open::that(SPONSOR_SITE) {
println!("Failed to open sponsor site: {}, reason {}", SPONSOR_SITE, e)
};
});
let button_instruction = gui_data.about.button_instruction.clone();
button_instruction.connect_clicked(move |_| {
if open::that(INSTRUCTION_SITE).is_err() {
println!("Failed to open instruction site: {}", INSTRUCTION_SITE)
if let Err(e) = open::that(INSTRUCTION_SITE) {
println!("Failed to open instruction site: {}, reason {}", INSTRUCTION_SITE, e)
};
});
let button_repository = gui_data.about.button_repository.clone();
button_repository.connect_clicked(move |_| {
if open::that(REPOSITORY_SITE).is_err() {
println!("Failed to open repository site: {}", REPOSITORY_SITE)
if let Err(e) = open::that(REPOSITORY_SITE) {
println!("Failed to open repository site: {}, reason {}", REPOSITORY_SITE, e)
};
});
}

View file

@ -316,7 +316,7 @@ pub fn empty_folder_remover(tree_view: &gtk::TreeView, column_file_name: i32, co
current_folder = folders_to_check.pop().unwrap();
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
error_happened = true;
break 'dir;
}
@ -325,14 +325,14 @@ pub fn empty_folder_remover(tree_view: &gtk::TreeView, column_file_name: i32, co
for entry in read_dir {
let entry_data = match entry {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
error_happened = true;
break 'dir;
}
};
let metadata: Metadata = match entry_data.metadata() {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
error_happened = true;
break 'dir;
}
@ -343,7 +343,7 @@ pub fn empty_folder_remover(tree_view: &gtk::TreeView, column_file_name: i32, co
+ "/"
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => {
Err(_inspected) => {
error_happened = true;
break 'dir;
}
@ -361,14 +361,14 @@ pub fn empty_folder_remover(tree_view: &gtk::TreeView, column_file_name: i32, co
Ok(_) => {
model.remove(&iter);
}
Err(_) => error_happened = true,
Err(_inspected) => error_happened = true,
}
} else {
match trash::delete(format!("{}/{}", path, name)) {
Ok(_) => {
model.remove(&iter);
}
Err(_) => error_happened = true,
Err(_inspected) => error_happened = true,
}
}
}
@ -414,14 +414,14 @@ pub fn basic_remove(tree_view: &gtk::TreeView, column_file_name: i32, column_pat
Ok(_) => {
model.remove(&iter);
}
Err(_) => messages += format!("Failed to remove file {}/{} because file doesn't exists or you don't have permissions.\n", path, name).as_str(),
Err(e) => messages += format!("Failed to remove file {}/{}, reason {}\n", path, name, e).as_str(),
}
} else {
match trash::delete(format!("{}/{}", path, name)) {
Ok(_) => {
model.remove(&iter);
}
Err(_) => messages += format!("Failed to remove file {}/{} because file doesn't exists or you don't have permissions.\n", path, name).as_str(),
Err(e) => messages += format!("Failed to remove file {}/{}, reason {}\n", path, name, e).as_str(),
}
}
}
@ -477,19 +477,11 @@ pub fn tree_remove(tree_view: &gtk::TreeView, column_file_name: i32, column_path
vec_file_name.dedup();
for file_name in vec_file_name {
if !use_trash {
if fs::remove_file(format!("{}/{}", path.clone(), file_name.clone())).is_err() {
messages += format!(
"Failed to remove file {}/{}. It is possible that you already deleted it, because similar images shows all possible file doesn't exists or you don't have permissions.\n",
path, file_name
)
.as_str()
if let Err(e) = fs::remove_file(format!("{}/{}", path.clone(), file_name.clone())) {
messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
}
} else if trash::delete(format!("{}/{}", path.clone(), file_name.clone())).is_err() {
messages += format!(
"Failed to remove file {}/{}. It is possible that you already deleted it, because similar images shows all possible file doesn't exists or you don't have permissions.\n",
path, file_name
)
.as_str()
} else if let Err(e) = trash::delete(format!("{}/{}", path.clone(), file_name.clone())) {
messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
}
vec_path_to_delete.push((path.clone(), file_name.clone()));

View file

@ -153,8 +153,8 @@ pub fn hardlink_symlink(tree_view: gtk::TreeView, column_file_name: i32, column_
for file_to_hardlink in symhardlink_data.files_to_symhardlink {
match make_hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
Ok(_) => (),
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to hardlink {}.", file_to_hardlink).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to hardlink {}, reason {}", file_to_hardlink, e).as_str());
continue;
}
}
@ -166,8 +166,8 @@ pub fn hardlink_symlink(tree_view: gtk::TreeView, column_file_name: i32, column_
for file_to_symlink in symhardlink_data.files_to_symhardlink {
match fs::remove_file(&file_to_symlink) {
Ok(_) => (),
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink, reason {}", file_to_symlink, e).as_str());
continue;
}
};
@ -176,19 +176,18 @@ pub fn hardlink_symlink(tree_view: gtk::TreeView, column_file_name: i32, column_
{
match std::os::unix::fs::symlink(&symhardlink_data.original_data, &file_to_symlink) {
Ok(_) => (),
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink, reason {}", file_to_symlink, e).as_str());
continue;
}
};
}
// TODO Add this, because for now it not working ()
#[cfg(target_family = "windows")]
{
match std::os::windows::fs::symlink_file(&symhardlink_data.original_data, &file_to_symlink) {
Ok(_) => (),
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink.", file_to_symlink).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to remove file {} when creating symlink, reason {}", file_to_symlink, e).as_str());
continue;
}
};

View file

@ -635,8 +635,8 @@ fn show_preview(tree_view: &TreeView, text_view_errors: &TextView, check_button_
add_text_to_text_view(text_view_errors, format!("Path {} doesn't point at folder, which is needed by image preview", cache_dir.display()).as_str());
break 'dir;
}
} else if fs::create_dir_all(cache_dir).is_err() {
add_text_to_text_view(text_view_errors, format!("Failed to create dir {} needed by image preview", cache_dir.display()).as_str());
} else if let Err(e) = fs::create_dir_all(cache_dir) {
add_text_to_text_view(text_view_errors, format!("Failed to create dir {} needed by image preview, reason {}", cache_dir.display(), e).as_str());
break 'dir;
}
let path = tree_model.value(&tree_model.iter(&tree_path).unwrap(), column_path).get::<String>().unwrap();
@ -652,8 +652,8 @@ fn show_preview(tree_view: &TreeView, text_view_errors: &TextView, check_button_
let img = match image::open(&file_name) {
Ok(t) => t,
Err(_) => {
add_text_to_text_view(text_view_errors, format!("Failed to open temporary image file {}", file_name).as_str());
Err(e) => {
add_text_to_text_view(text_view_errors, format!("Failed to open temporary image file {}, reason {}", file_name, e).as_str());
break 'dir;
}
};
@ -680,8 +680,8 @@ fn show_preview(tree_view: &TreeView, text_view_errors: &TextView, check_button_
}
let img = img.resize(new_size.0, new_size.1, FilterType::Triangle);
let file_dir = cache_dir.join(format!("cached_file.{}", extension.to_string_lossy()));
if img.save(&file_dir).is_err() {
add_text_to_text_view(text_view_errors, format!("Failed to save temporary image file to {}", file_dir.display()).as_str());
if let Err(e) = img.save(&file_dir) {
add_text_to_text_view(text_view_errors, format!("Failed to save temporary image file to {}, reason {}", file_dir.display(), e).as_str());
break 'dir;
}
let string_dir = file_dir.to_string_lossy().to_string();

View file

@ -32,8 +32,8 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
add_text_to_text_view(&text_view_errors, format!("Cannot create save file inside {} because this isn't a folder.", config_dir.display()).as_str());
return;
}
} else if fs::create_dir_all(config_dir).is_err() {
add_text_to_text_view(&text_view_errors, format!("Failed configuration to create configuration folder {}", config_dir.display()).as_str());
} else if let Err(e) = fs::create_dir_all(config_dir) {
add_text_to_text_view(&text_view_errors, format!("Failed configuration to create configuration folder {}, reason {}", config_dir.display(), e).as_str());
return;
}
let mut data_to_save: Vec<String> = Vec::with_capacity(16);
@ -147,8 +147,8 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
let mut config_file_handler = match File::create(&config_file) {
Ok(t) => t,
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to create config file {}", config_dir.display()).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to create config file {}, reason {}", config_dir.display(), e).as_str());
return;
}
};
@ -156,10 +156,10 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
let mut data_saved: bool = false;
for data in data_to_save {
match writeln!(config_file_handler, "{}", data) {
Ok(_) => {
Ok(_inspected) => {
data_saved = true;
}
Err(_) => {
Err(_inspected) => {
data_saved = false;
break;
}
@ -217,8 +217,8 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
// Loading Data
let loaded_data: String = match fs::read_to_string(&config_file) {
Ok(t) => t,
Err(_) => {
add_text_to_text_view(&text_view_errors, format!("Failed to read data from file {:?}.", config_file).as_str());
Err(e) => {
add_text_to_text_view(&text_view_errors, format!("Failed to read data from file {:?}, reason {}", config_file, e).as_str());
return;
}
};
@ -521,7 +521,7 @@ pub fn reset_configuration(gui_data: &GuiData, manual_clearing: bool) {
let current_dir: String = match env::current_dir() {
Ok(t) => t.to_str().unwrap().to_string(),
Err(_) => {
Err(_inspected) => {
if cfg!(target_family = "unix") {
add_text_to_text_view(&text_view_errors, "Failed to read current directory, setting /home instead");
"/home".to_string()