From 04208aad8ec925f27938419b066f92861dc40f34 Mon Sep 17 00:00:00 2001 From: jakka Date: Wed, 2 Jul 2025 12:00:11 +0300 Subject: continued working --- Cargo.lock | 7 ++++++ Cargo.toml | 1 + src/files.rs | 69 ++++++++++++++++++++++++++++++------------------------------ 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61212a3..5d50e4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,6 +519,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "easy-parallel" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2afbb9b0aef60e4f0d2b18129b6c0dff035a6f7dbbd17c2f38c1432102ee223c" + [[package]] name = "either" version = "1.15.0" @@ -588,6 +594,7 @@ dependencies = [ "console 0.15.11", "ctrlc", "directories", + "easy-parallel", "flac-bound", "futures-util", "i24", diff --git a/Cargo.toml b/Cargo.toml index f245ccd..2d892fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ futures-util = "0.3.31" smol-macros = "0.1.1" macro_rules_attribute = "0.2.2" ctrlc = "3.4.7" +easy-parallel = "3.3.1" diff --git a/src/files.rs b/src/files.rs index 29cd2a9..da2c911 100644 --- a/src/files.rs +++ b/src/files.rs @@ -101,46 +101,45 @@ pub fn index_files_recursively( let (tx, rx) = mpsc::channel(); let ex = Executor::new(); - WalkDir::new(abspath) - .into_iter() - .par_bridge() - .for_each(|entry| { - if running.load(Ordering::SeqCst) { - let path = entry.unwrap().into_path(); - if !path.is_file() { - return; - } - if path.extension().is_some_and(|x| x == "flac") { - let newconn = conn.clone(); - let newrunning = running.clone(); - let newtx = tx.clone(); - #[cfg(not(test))] - let newbar = bar.clone(); - - ex.spawn(async move { - if !newrunning.load(Ordering::SeqCst) { - match handle_file(&path, newconn).await { - Err(error) => newtx.send(FileError::new(path, error)), - Ok(_) => { - #[cfg(not(test))] - newbar.inc(1); - Ok(()) - } + for entry in WalkDir::new(abspath) { + if running.load(Ordering::SeqCst) { + let path = entry.unwrap().into_path(); + if !path.is_file() { + continue; + } + if path.extension().is_some_and(|x| x == "flac") { + let newconn = conn.clone(); + let newrunning = running.clone(); + let newtx = tx.clone(); + #[cfg(not(test))] + let newbar = bar.clone(); + + ex.spawn(async move { + if !newrunning.load(Ordering::SeqCst) { + match handle_file(&path, newconn).await { + Err(error) => newtx.send(FileError::new(path, error)), + Ok(_) => { + #[cfg(not(test))] + newbar.inc(1); + Ok(()) } - } else { - Ok(()) } - }) - .detach(); + } else { + Ok(()) + } + }) + .detach(); - #[cfg(not(test))] - bar.inc_length(1); - } + #[cfg(not(test))] + bar.inc_length(1); } - }); + } + } - while let Ok(message) = rx.recv() { - eprintln!("{}", message); + while !ex.is_empty() { + if let Ok(message) = rx.recv() { + eprintln!("{}", message); + } } #[cfg(not(test))] -- cgit v1.3.1