1
0
Fork 0
mirror of synced 2024-04-28 09:33:30 +12:00

Add support for finding broken zip and audio files (#210)

This commit is contained in:
Rafał Mikrut 2021-01-15 11:04:52 +01:00 committed by GitHub
parent 0c10a6a0ba
commit cc8d42e0ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1341 additions and 57 deletions

View file

@ -28,7 +28,7 @@ jobs:
linux-cli-${{github.ref}}-${{github.sha}}
- name: Install basic libraries
run: sudo apt-get update; sudo apt install libgtk-3-dev -y
run: sudo apt-get update; sudo apt install libgtk-3-dev libasound2-dev -y
- name: Build CLI Debug
run: cargo build --bin czkawka_cli
@ -146,7 +146,7 @@ jobs:
linux-gui-${{github.ref}}-${{github.sha}}
- name: Install Gtk, Mingw, unzip, zip and wget
run: sudo apt-get update; sudo apt install libgtk-3-dev -y
run: sudo apt-get update; sudo apt install libgtk-3-dev libasound2-dev -y
- name: Build GUI Debug
run: cargo build --bin czkawka_gui
@ -192,7 +192,7 @@ jobs:
linux-appimage-gui-${{github.ref}}-${{github.sha}}
- name: Install Gtk,
run: sudo apt-get update; sudo apt install libgtk-3-dev librsvg2-dev wget -y
run: sudo apt-get update; sudo apt install libgtk-3-dev libasound2-dev librsvg2-dev wget -y
- name: Build GUI Release
run: cargo build --release --bin czkawka_gui

View file

@ -25,7 +25,7 @@ jobs:
override: true
- name: Install Gtk
run: sudo apt install -y libgtk-3-dev
run: sudo apt install -y libgtk-3-dev libasound2-dev
- name: Check the format
run: cargo fmt --all -- --check

1324
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -48,7 +48,7 @@ If the app does not run when clicking at a launcher, run it through a terminal.
You don't need to have any additional libraries for CLI Czkawka
#### GUI Requirements
##### Linux
For Czkawka GUI you need to have at least GTK 3.22.
For Czkawka GUI you need to have at least GTK 3.22 and also Alsa installed(for finding broken music files).
It should be installed by default on all the most popular distros.
##### Windows
`czkawka_gui.exe` extracted from zip file `windows_czkawka_gui.zip` needs to have all files inside around, because use them.
@ -122,12 +122,12 @@ If you want to compile CLI frontend, then just skip lines which contains `gtk` w
```shell
sudo apt install -y curl # Needed by Rust update tool
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Download the latest stable Rust
sudo apt install -y libgtk-3-dev
sudo apt install -y libgtk-3-dev libasound2-dev
```
#### Fedora/CentOS/Rocky Linux
```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Download the latest stable Rust
sudo yum install gtk3-devel glib2-devel
sudo yum install gtk3-devel glib2-devel alsa-lib-devel
```
#### MacOS
You need to install Homebrew and GTK Libraries

View file

@ -29,4 +29,8 @@ bitflags = "1.2.1"
audiotags = "0.2.7182"
# Futures - needed by async progress sender
futures = "0.3.8"
futures = "0.3.9"
# Needed by broken files
zip = "0.5.9"
rodio = "0.13.0"

View file

@ -48,6 +48,8 @@ pub struct FileEntry {
pub enum TypeOfFile {
Unknown = -1,
Image = 0,
ArchiveZIP,
Audio,
}
/// Info struck with helpful information's about results
@ -356,16 +358,17 @@ impl BrokenFiles {
check_was_breaked.store(true, Ordering::Relaxed);
return None;
}
let file_entry = file_entry.1;
match file_entry.1.type_of_file {
match file_entry.type_of_file {
TypeOfFile::Image => {
match image::open(&file_entry.1.path) {
match image::open(&file_entry.path) {
Ok(_) => Some(None),
Err(t) => {
let error_string = t.to_string();
// This error is a problem with image library, remove check when https://github.com/image-rs/jpeg-decoder/issues/130 will be fixed
if !error_string.contains("spectral selection is not allowed in non-progressive scan") {
let mut file_entry = file_entry.1.clone();
let mut file_entry = file_entry.clone();
file_entry.error_string = error_string;
Some(Some(file_entry))
} else {
@ -374,6 +377,32 @@ impl BrokenFiles {
} // Something is wrong with image
}
}
TypeOfFile::ArchiveZIP => match fs::File::open(&file_entry.path) {
Ok(file) => match zip::ZipArchive::new(file) {
Ok(_) => Some(None),
Err(e) => {
// TODO Maybe filter out unnecessary types of errors
let error_string = e.to_string();
let mut file_entry = file_entry.clone();
file_entry.error_string = error_string;
Some(Some(file_entry))
}
},
Err(_) => Some(None),
},
TypeOfFile::Audio => match fs::File::open(&file_entry.path) {
Ok(file) => match rodio::Decoder::new(BufReader::new(file)) {
Ok(_) => Some(None),
Err(e) => {
let error_string = e.to_string();
let mut file_entry = file_entry.clone();
file_entry.error_string = error_string;
Some(Some(file_entry))
}
},
Err(_) => Some(None),
},
// This means that cache read invalid value because maybe cache comes from different czkawka version
TypeOfFile::Unknown => Some(None),
}
@ -529,7 +558,6 @@ impl PrintResults for BrokenFiles {
}
fn save_cache_to_file(hashmap_file_entry: &HashMap<String, FileEntry>, text_messages: &mut Messages) {
println!("Allowed to save {} entries", hashmap_file_entry.len());
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
// Lin: /home/username/.cache/czkawka
// Win: C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache
@ -635,9 +663,15 @@ fn load_cache_from_file(text_messages: &mut Messages) -> Option<HashMap<String,
fn check_extension_avaibility(file_name_lowercase: &str) -> TypeOfFile {
// Checking allowed image extensions
let allowed_image_extensions = ["jpg", "jpeg", "png", "bmp", "ico", "tiff", "pnm", "tga", "ff", "gif"];
if allowed_image_extensions.iter().any(|e| file_name_lowercase.ends_with(format!(".{}", e).as_str())) {
let allowed_image_extensions = [".jpg", ".jpeg", ".png", ".bmp", ".ico", ".tiff", ".pnm", ".tga", ".ff", ".gif"];
let allowed_archive_zip_extensions = [".zip"]; // Probably also should work [".xz", ".bz2"], but from my tests they not working
let allowed_audio_extensions = [".mp3", ".flac", ".wav", ".ogg"]; // Probably also should work [".xz", ".bz2"], but from my tests they not working
if allowed_image_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
TypeOfFile::Image
} else if allowed_archive_zip_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
TypeOfFile::ArchiveZIP
} else if allowed_audio_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
TypeOfFile::Audio
} else {
TypeOfFile::Unknown
}

View file

@ -126,13 +126,11 @@ Finally, each hash is compared with the others and if the distance between them
### Broken Files
This tool is created to find files which are corrupted or have invalid extension.
Currently only checking of images is implemented.
At first files from specific group(image,archive,audio) are collected and then this files are opened.
At first image files are collected and then this files are opened.
If an error happens when opening this file then it means that this file is corrupted or unsupported.
If an error happens when opening this image then it means that this file is corrupted.
Only some image extensions are supported, because I rely on image crate. Also some false positives may be shown(e.g. https://github.com/image-rs/jpeg-decoder/issues/130)
Only some file extensions are supported, because I rely on external crates. Also some false positives may be shown(e.g. https://github.com/image-rs/jpeg-decoder/issues/130) so always open file to check if it is really broken.
## Config/Cache files
For now Czkawka store only 2 files on disk: