Skip to content

Commit

Permalink
File utils
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Sep 26, 2024
1 parent c98bd27 commit 532e54b
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install Dependencies
run: sudo apt update || true; sudo apt install libgtk-4-dev libheif-dev librsvg2-dev wget fuse libfuse2 -y
run: sudo apt update || true; sudo apt install libgtk-4-dev libheif-dev librsvg2-dev wget fuse libfuse2 desktop-file-utils -y

- name: Setup rust version
run: rustup default ${{ matrix.toolchain }}
Expand Down
8 changes: 3 additions & 5 deletions czkawka_core/src/bad_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ const WORKAROUNDS: &[(&str, &str)] = &[
("pptx", "ppsx"), // Powerpoint
("sh", "bash"), // Linux
("sh", "guess"), // GNU
("sh", "lua"), // Lua
("sh", "js"), // Javascript
("sh", "pl"), // Gnome/Linux
("sh", "pm"), // Gnome/Linux
("sh", "py"), // Python
Expand Down Expand Up @@ -268,10 +270,6 @@ impl BadExtensions {

let mut hashmap_workarounds: HashMap<&str, Vec<&str>> = Default::default();
for (proper, found) in WORKAROUNDS {
// This should be enabled when items will have only 1 possible workaround items, but looks that some have 2 or even more, so at least for now this is disabled
// if hashmap_workarounds.contains_key(found) {
// panic!("Already have {} key", found);
// }
hashmap_workarounds.entry(found).or_default().push(proper);
}

Expand Down Expand Up @@ -441,7 +439,7 @@ impl PrintResults for BadExtensions {
writeln!(writer, "Found {} files with invalid extension.\n", self.information.number_of_files_with_bad_extension)?;

for file_entry in &self.bad_extensions_files {
writeln!(writer, "{:?} ----- {}", file_entry.path, file_entry.proper_extensions)?;
writeln!(writer, "\"{}\" ----- {}", file_entry.path.to_string_lossy(), file_entry.proper_extensions)?;
}

Ok(())
Expand Down
8 changes: 7 additions & 1 deletion czkawka_core/src/big_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ impl PrintResults for BigFile {
writeln!(writer, "{} the smallest files.\n\n", self.information.number_of_real_files)?;
}
for file_entry in &self.big_files {
writeln!(writer, "{} ({}) - {:?}", format_size(file_entry.size, BINARY), file_entry.size, file_entry.path)?;
writeln!(
writer,
"{} ({}) - \"{}\"",
format_size(file_entry.size, BINARY),
file_entry.size,
file_entry.path.to_string_lossy()
)?;
}
} else {
writeln!(writer, "Not found any files.")?;
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/broken_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl PrintResults for BrokenFiles {
if !self.broken_files.is_empty() {
writeln!(writer, "Found {} broken files.", self.information.number_of_broken_files)?;
for file_entry in &self.broken_files {
writeln!(writer, "{:?} - {}", file_entry.path, file_entry.error_string)?;
writeln!(writer, "\"{}\" - {}", file_entry.path.to_string_lossy(), file_entry.error_string)?;
}
} else {
write!(writer, "Not found any broken files.")?;
Expand Down
16 changes: 8 additions & 8 deletions czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ impl PrintResults for DuplicateFinder {
for (name, vector) in self.files_with_identical_names.iter().rev() {
writeln!(writer, "Name - {} - {} files ", name, vector.len())?;
for j in vector {
writeln!(writer, "{:?}", j.path)?;
writeln!(writer, "\"{}\"", j.path.to_string_lossy())?;
}
writeln!(writer)?;
}
Expand All @@ -1061,7 +1061,7 @@ impl PrintResults for DuplicateFinder {
writeln!(writer, "Name - {} - {} files ", name, vector.len())?;
writeln!(writer, "Reference file - {:?}", file_entry.path)?;
for j in vector {
writeln!(writer, "{:?}", j.path)?;
writeln!(writer, "\"{}\"", j.path.to_string_lossy())?;
}
writeln!(writer)?;
}
Expand All @@ -1083,7 +1083,7 @@ impl PrintResults for DuplicateFinder {
for ((size, name), vector) in self.files_with_identical_size_names.iter().rev() {
writeln!(writer, "Name - {}, {} - {} files ", name, format_size(*size, BINARY), vector.len())?;
for j in vector {
writeln!(writer, "{:?}", j.path)?;
writeln!(writer, "\"{}\"", j.path.to_string_lossy())?;
}
writeln!(writer)?;
}
Expand All @@ -1101,7 +1101,7 @@ impl PrintResults for DuplicateFinder {
writeln!(writer, "Name - {}, {} - {} files ", name, format_size(*size, BINARY), vector.len())?;
writeln!(writer, "Reference file - {:?}", file_entry.path)?;
for j in vector {
writeln!(writer, "{:?}", j.path)?;
writeln!(writer, "\"{}\"", j.path.to_string_lossy())?;
}
writeln!(writer)?;
}
Expand All @@ -1125,7 +1125,7 @@ impl PrintResults for DuplicateFinder {
for (size, vector) in self.files_with_identical_size.iter().rev() {
write!(writer, "\n---- Size {} ({}) - {} files \n", format_size(*size, BINARY), size, vector.len())?;
for file_entry in vector {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}
}
} else if !self.files_with_identical_size_referenced.is_empty() {
Expand All @@ -1144,7 +1144,7 @@ impl PrintResults for DuplicateFinder {
writeln!(writer, "\n---- Size {} ({}) - {} files", format_size(*size, BINARY), size, vector.len())?;
writeln!(writer, "Reference file - {:?}", file_entry.path)?;
for file_entry in vector {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}
}
} else {
Expand All @@ -1168,7 +1168,7 @@ impl PrintResults for DuplicateFinder {
for vector in vectors_vector {
writeln!(writer, "\n---- Size {} ({}) - {} files", format_size(*size, BINARY), size, vector.len())?;
for file_entry in vector {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}
}
}
Expand All @@ -1189,7 +1189,7 @@ impl PrintResults for DuplicateFinder {
writeln!(writer, "\n---- Size {} ({}) - {} files", format_size(*size, BINARY), size, vector.len())?;
writeln!(writer, "Reference file - {:?}", file_entry.path)?;
for file_entry in vector {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/empty_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl PrintResults for EmptyFiles {
if !self.empty_files.is_empty() {
writeln!(writer, "Found {} empty files.", self.information.number_of_empty_files)?;
for file_entry in &self.empty_files {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}
} else {
write!(writer, "Not found any empty files.")?;
Expand Down
6 changes: 3 additions & 3 deletions czkawka_core/src/invalid_symlinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ impl PrintResults for InvalidSymlinks {
for file_entry in &self.invalid_symlinks {
writeln!(
writer,
"{:?}\t\t{:?}\t\t{}",
file_entry.path,
file_entry.symlink_info.destination_path,
"\"{}\"\t\t\"{}\"\t\t{}",
file_entry.path.to_string_lossy(),
file_entry.symlink_info.destination_path.to_string_lossy(),
match file_entry.symlink_info.type_of_error {
ErrorType::InfiniteRecursion => "Infinite Recursion",
ErrorType::NonExistentFile => "Non Existent File",
Expand Down
30 changes: 24 additions & 6 deletions czkawka_core/src/same_music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,14 @@ impl PrintResults for SameMusic {
for file_entry in vec_file_entry {
writeln!(
writer,
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: {:?}",
file_entry.track_title, file_entry.track_artist, file_entry.year, file_entry.length, file_entry.genre, file_entry.bitrate, file_entry.path
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: \"{}\"",
file_entry.track_title,
file_entry.track_artist,
file_entry.year,
file_entry.length,
file_entry.genre,
file_entry.bitrate,
file_entry.path.to_string_lossy()
)?;
}
writeln!(writer)?;
Expand All @@ -936,14 +942,26 @@ impl PrintResults for SameMusic {
writeln!(writer)?;
writeln!(
writer,
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: {:?}",
file_entry.track_title, file_entry.track_artist, file_entry.year, file_entry.length, file_entry.genre, file_entry.bitrate, file_entry.path
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: \"{}\"",
file_entry.track_title,
file_entry.track_artist,
file_entry.year,
file_entry.length,
file_entry.genre,
file_entry.bitrate,
file_entry.path.to_string_lossy()
)?;
for file_entry in vec_file_entry {
writeln!(
writer,
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: {:?}",
file_entry.track_title, file_entry.track_artist, file_entry.year, file_entry.length, file_entry.genre, file_entry.bitrate, file_entry.path
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: \"{}\"",
file_entry.track_title,
file_entry.track_artist,
file_entry.year,
file_entry.length,
file_entry.genre,
file_entry.bitrate,
file_entry.path.to_string_lossy()
)?;
}
writeln!(writer)?;
Expand Down
8 changes: 4 additions & 4 deletions czkawka_core/src/similar_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ impl PrintResults for SimilarImages {
for file_entry in struct_similar {
writeln!(
writer,
"{:?} - {}x{} - {} - {}",
file_entry.path,
"\"{}\" - {}x{} - {} - {}",
file_entry.path.to_string_lossy(),
file_entry.width,
file_entry.height,
format_size(file_entry.size, BINARY),
Expand All @@ -841,8 +841,8 @@ impl PrintResults for SimilarImages {
writeln!(writer)?;
writeln!(
writer,
"{:?} - {}x{} - {} - {}",
file_entry.path,
"\"{}\" - {}x{} - {} - {}",
file_entry.path.to_string_lossy(),
file_entry.width,
file_entry.height,
format_size(file_entry.size, BINARY),
Expand Down
6 changes: 3 additions & 3 deletions czkawka_core/src/similar_videos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl PrintResults for SimilarVideos {
for struct_similar in &self.similar_vectors {
writeln!(writer, "Found {} videos which have similar friends", struct_similar.len())?;
for file_entry in struct_similar {
writeln!(writer, "{:?} - {}", file_entry.path, format_size(file_entry.size, BINARY))?;
writeln!(writer, "\"{}\" - {}", file_entry.path.to_string_lossy(), format_size(file_entry.size, BINARY))?;
}
writeln!(writer)?;
}
Expand All @@ -383,9 +383,9 @@ impl PrintResults for SimilarVideos {
for (fe, struct_similar) in &self.similar_referenced_vectors {
writeln!(writer, "Found {} videos which have similar friends", struct_similar.len())?;
writeln!(writer)?;
writeln!(writer, "{:?} - {}", fe.path, format_size(fe.size, BINARY))?;
writeln!(writer, "\"{}\" - {}", fe.path.to_string_lossy(), format_size(fe.size, BINARY))?;
for file_entry in struct_similar {
writeln!(writer, "{:?} - {}", file_entry.path, format_size(file_entry.size, BINARY))?;
writeln!(writer, "\"{}\" - {}", file_entry.path.to_string_lossy(), format_size(file_entry.size, BINARY))?;
}
writeln!(writer)?;
}
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl PrintResults for Temporary {
writeln!(writer, "Found {} temporary files.\n", self.information.number_of_temporary_files)?;

for file_entry in &self.temporary_files {
writeln!(writer, "{:?}", file_entry.path)?;
writeln!(writer, "\"{}\"", file_entry.path.to_string_lossy())?;
}

Ok(())
Expand Down

0 comments on commit 532e54b

Please sign in to comment.