Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Sep 26, 2024
1 parent ad832ea commit 9c75851
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
pwd
cp target/release/czkawka_gui AppDir/usr/bin
./linuxdeploy-x86_64.AppImage --appdir AppDir --plugin gtk --icon-file data/icons/com.github.qarmin.czkawka.svg --desktop-file data/com.github.qarmin.czkawka.desktop
./appimagetool --comp zstd --mksquashfs-opt -Xcompression-level --mksquashfs-opt 20 \
./appimagetool-x86_64.AppImage --comp zstd --mksquashfs-opt -Xcompression-level --mksquashfs-opt 20 \
-u "gh-releases-zsync|$GITHUB_REPOSITORY_OWNER|czkawka|latest|*.AppImage.zsync" \
./AppDir
Expand Down
49 changes: 25 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions ci_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn main() {

for _ in 0..ATTEMPTS {
test_empty_files();
test_big_files();
test_smallest_files();
test_biggest_files();
test_empty_folders();
Expand Down Expand Up @@ -373,6 +374,11 @@ fn test_empty_files() {
run_test(&["empty-files", "-d", "TestFiles", "-D"], vec!["EmptyFile"], vec![], vec![]);
}

fn test_big_files() {
info!("test_big_files");
run_test(&["big", "-d", "TestFiles", "-n", "2", "-D"], vec![], vec![], vec![]);
}

////////////////////////////////////
////////////////////////////////////
/////////HELPER FUNCTIONS///////////
Expand Down Expand Up @@ -454,8 +460,7 @@ fn collect_all_files_and_dirs(dir: &str) -> std::io::Result<CollectedFiles> {
let mut symlinks = BTreeSet::new();

let mut folders_to_check = vec![dir.to_string()];
while !folders_to_check.is_empty() {
let folder = folders_to_check.pop().expect("Should not fail in tests");
while let Some(folder) = folders_to_check.pop() {
let rd = fs::read_dir(folder)?;
for entry in rd {
let entry = entry?;
Expand Down
15 changes: 10 additions & 5 deletions czkawka_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ fn main() {
})
.expect("Failed to spawn calculation thread");
ctrlc::set_handler(move || {
println!("Get Sender");
stop_sender.send(()).expect("Could not send signal on channel.");
println!("Get Ctrl+C signal, stopping...");
if let Err(e) = stop_sender.send(()) {
eprintln!("Failed to send stop signal {e}(it is possible that the program is already stopped)");
};
})
.expect("Error setting Ctrl-C handler");

Expand Down Expand Up @@ -348,9 +350,12 @@ fn save_and_print_results<T: CommonData + PrintResults>(component: &mut T, commo
}
}

if !cfg!(debug_assertions) {
component.print_results_to_output();
}
// if !cfg!(debug_assertions) {
component.print_results_to_output();
// }
// else {
// println!("Results are not printed in debug mode");
// }
component.get_text_messages().print_messages();
}

Expand Down
3 changes: 2 additions & 1 deletion czkawka_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ os_info = { version = "3", default-features = false }
log = "0.4.22"
handsome_logger = "0.8"
fun_time = { version = "0.3", features = ["log"] }
itertools = "0.13"

[target.'cfg(windows)'.dependencies]
# Don't update anymore! This crate has a bug. I've submitted a patch upstream, but the change is breaking. The current code relies on the bug to work correctly!
# Warning by CalunVier 2024.7.15
[target.'cfg(windows)'.dependencies]
file-id = "=0.2.1"

[build-dependencies]
Expand Down
28 changes: 15 additions & 13 deletions czkawka_core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ pub fn get_dynamic_image_from_heic(path: &str) -> Result<DynamicImage> {
}

#[cfg(feature = "libraw")]
pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path>) -> Option<DynamicImage> {
let buf = fs::read(path.as_ref()).ok()?;
pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path>) -> Result<DynamicImage> {
let buf = fs::read(path.as_ref())?;

let processor = Processor::new();
let start_timer = Instant::now();
Expand All @@ -276,19 +276,22 @@ pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path>) -> Option<Dynami
let height = processed.height();

let data = processed.to_vec();
let data_len = data.len();

let buffer = ImageBuffer::from_raw(width, height, data)?;
// Utwórz DynamicImage z ImageBuffer
Some(DynamicImage::ImageRgb8(buffer))
let buffer = ImageBuffer::from_raw(width, height, data).ok_or(anyhow::anyhow!(format!(
"Cannot create ImageBuffer from raw image with width: {width} and height: {height} and data length: {data_len}",
)))?;

Ok(DynamicImage::ImageRgb8(buffer))
}

#[cfg(not(feature = "libraw"))]
pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path> + std::fmt::Debug) -> Option<DynamicImage> {
pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path> + std::fmt::Debug) -> Result<DynamicImage, String> {
let mut start_timer = Instant::now();
let mut times = Vec::new();

let loader = RawLoader::new();
let raw = loader.decode_file(path.as_ref()).ok()?;
let raw = loader.decode_file(path.as_ref()).map_err(|e| format!("Error decoding file: {e:?}"))?;

times.push(("After decoding", start_timer.elapsed()));
start_timer = Instant::now();
Expand All @@ -298,28 +301,27 @@ pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path> + std::fmt::Debug
times.push(("After creating source", start_timer.elapsed()));
start_timer = Instant::now();

let mut pipeline = Pipeline::new_from_source(source).ok()?;
let mut pipeline = Pipeline::new_from_source(source).map_err(|e| format!("Error creating pipeline: {e:?}"))?;

times.push(("After creating pipeline", start_timer.elapsed()));
start_timer = Instant::now();

pipeline.run(None);
let image = pipeline.output_8bit(None).ok()?;
let image = pipeline.output_8bit(None).map_err(|e| format!("Error running pipeline: {e:?}"))?;

times.push(("After creating image", start_timer.elapsed()));
start_timer = Instant::now();

let image = ImageBuffer::<Rgb<u8>, Vec<u8>>::from_raw(image.width as u32, image.height as u32, image.data)?;
let image = ImageBuffer::<Rgb<u8>, Vec<u8>>::from_raw(image.width as u32, image.height as u32, image.data).ok_or_else(|| "Failed to create image buffer".to_string())?;

times.push(("After creating image buffer", start_timer.elapsed()));
start_timer = Instant::now();
// println!("Properly hashed {:?}", path);
let res = Some(DynamicImage::ImageRgb8(image));
let res = DynamicImage::ImageRgb8(image);
times.push(("After creating dynamic image", start_timer.elapsed()));

let str_timer = times.into_iter().map(|(name, time)| format!("{name}: {time:?}")).collect::<Vec<_>>().join(", ");
debug!("Loading raw image --- {str_timer}");
res
Ok(res)
}

pub fn split_path(path: &Path) -> (String, String) {
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ fn filter_hard_links(vec_file_entry: &[FileEntry]) -> Vec<FileEntry> {
let mut identical: Vec<FileEntry> = Vec::with_capacity(vec_file_entry.len());
for f in vec_file_entry {
if let Ok(meta) = file_id::get_low_res_file_id(&f.path) {
if let file_id::FileId::HighRes {file_id, ..} = meta {
if let file_id::FileId::HighRes { file_id, .. } = meta {
if !inodes.insert(file_id) {
continue;
}
Expand Down
29 changes: 11 additions & 18 deletions czkawka_core/src/same_music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,38 +586,31 @@ impl SameMusic {
continue;
}

let temp_collected_similar_items = files_to_compare
let (mut collected_similar_items, errors): (Vec<_>, Vec<_>) = files_to_compare
.par_iter()
.map(|e_entry| {
let e_string = e_entry.path.to_string_lossy().to_string();
if used_paths.contains(&e_string) || e_string == f_string {
return Ok(None);
return None;
}
let mut segments = match match_fingerprints(&f_entry.fingerprint, &e_entry.fingerprint, configuration) {
Ok(segments) => segments,
Err(e) => return Err(format!("Error while comparing fingerprints: {e}")),
Err(e) => return Some(Err(format!("Error while comparing fingerprints: {e}"))),
};
segments.retain(|s| s.duration(configuration) > minimum_segment_duration && s.score < maximum_difference);
if segments.is_empty() {
Ok(None)
None
} else {
Ok(Some((e_string, e_entry)))
Some(Ok((e_string, e_entry)))
}
})
.collect::<Vec<_>>();
.flatten()
.partition_map(|res| match res {
Ok(entry) => itertools::Either::Left(entry),
Err(err) => itertools::Either::Right(err),
});

let mut collected_similar_items = Vec::with_capacity(temp_collected_similar_items.len());
for result in temp_collected_similar_items {
match result {
Ok(Some(data)) => {
collected_similar_items.push(data);
}
Ok(None) => (),
Err(e) => {
self.common_data.text_messages.errors.push(e);
}
}
}
self.common_data.text_messages.errors.extend(errors);

collected_similar_items.retain(|(path, _entry)| !used_paths.contains(path));
if !collected_similar_items.is_empty() {
Expand Down
Loading

0 comments on commit 9c75851

Please sign in to comment.