From d531f8909d3ee47ea11a7a0dc60ea70819c16032 Mon Sep 17 00:00:00 2001 From: jakka Date: Tue, 30 Sep 2025 17:00:59 +0300 Subject: removed useless trait, reorganized code, isolated modules --- src/db.rs | 203 +++++++++++++++++++++++++++-------------------------------- src/files.rs | 50 ++++++++------- src/flac.rs | 4 +- src/main.rs | 7 +-- 4 files changed, 125 insertions(+), 139 deletions(-) diff --git a/src/db.rs b/src/db.rs index 809e5e0..ba14c1a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -20,126 +20,109 @@ const DEDUPE_DB: &str = "DELETE FROM flacs WHERE rowid NOT IN (SELECT MAX(rowid) FROM flacs GROUP BY path)"; const GET_MODTIME: &str = "SELECT modtime FROM flacs WHERE path = ?1"; -pub trait Database { - type Conn; - fn new(path: Option<&PathBuf>) -> Result; - fn insert_file(&self, filename: &Path) -> Result<()>; - fn update_file(&self, filename: &Path) -> Result<()>; - fn check_file(&self, filename: &Path) -> Result; - fn init_clean_files(&self) -> Result, rusqlite::Error>; - fn remove_file(&self, filename: &Path) -> Result<()>; - fn get_toencode_files(&self) -> Result, rusqlite::Error>; - fn get_toencode_number(&self) -> Result; - fn get_modtime(&self, file: &Path) -> Result; - fn vacuum(&self) -> Result<()>; +pub(crate) fn init_connection(path: Option<&PathBuf>) -> Result { + let conn = if let Some(file) = path { + Connection::open(file)? + } else if let Some(base_dir) = BaseDirs::new() { + let file = Path::new(base_dir.data_dir()).join("reencoder.db"); + Connection::open(file)? + } else { + return Err(anyhow!("Failed to locate data directory")); + }; + conn.execute(TABLE_CREATE, ())?; + Ok(conn) } -impl Database for Connection { - type Conn = Connection; - fn new(path: Option<&PathBuf>) -> Result { - let conn = if let Some(file) = path { - Connection::open(file)? - } else if let Some(base_dir) = BaseDirs::new() { - let file = Path::new(base_dir.data_dir()).join("reencoder.db"); - Connection::open(file)? - } else { - return Err(anyhow!("Failed to locate data directory")); - }; - conn.execute(TABLE_CREATE, ())?; - Ok(conn) - } - - fn insert_file(&self, filename: &Path) -> Result<()> { - let toencode = !matches!(get_vendor(filename)?.as_str(), CURRENT_VENDOR); +pub(crate) fn insert_file(conn: &Connection, filename: &Path) -> Result<()> { + let toencode = !matches!(get_vendor(filename)?.as_str(), CURRENT_VENDOR); - let modtime = filename - .metadata()? - .modified()? - .duration_since(UNIX_EPOCH)? - .as_secs(); + let modtime = filename + .metadata()? + .modified()? + .duration_since(UNIX_EPOCH)? + .as_secs(); - self.execute( - ADD_ITEM, - params![filename.to_str().unwrap(), toencode, modtime], - )?; + conn.execute( + ADD_ITEM, + params![filename.to_str().unwrap(), toencode, modtime], + )?; - Ok(()) - } + Ok(()) +} - fn update_file(&self, filename: &Path) -> Result<()> { - let modtime = filename - .metadata()? - .modified()? - .duration_since(UNIX_EPOCH)? - .as_secs(); +pub(crate) fn update_file(conn: &Connection, filename: &Path) -> Result<()> { + let modtime = filename + .metadata()? + .modified()? + .duration_since(UNIX_EPOCH)? + .as_secs(); - self.execute( - UPDATE_ITEM, - params![filename.to_str().unwrap(), false, modtime], - )?; + conn.execute( + UPDATE_ITEM, + params![filename.to_str().unwrap(), false, modtime], + )?; - Ok(()) - } + Ok(()) +} - fn check_file(&self, filename: &Path) -> Result { - if self.query_one(CHECK_FILE, params!(filename.to_str().unwrap()), |row| { - let num: bool = row.get(0)?; - Ok(num) - })? { - Ok(true) - } else { - Ok(false) - } +pub(crate) fn check_file(conn: &Connection, filename: &Path) -> Result { + if conn.query_one(CHECK_FILE, params!(filename.to_str().unwrap()), |row| { + let num: bool = row.get(0)?; + Ok(num) + })? { + Ok(true) + } else { + Ok(false) } +} - fn init_clean_files(&self) -> Result, rusqlite::Error> { - self.execute(DEDUPE_DB, ())?; - let mut stmt = self.prepare(FETCH_FILES)?; - let mut rows = stmt.query(())?; - let mut files = Vec::new(); - while let Ok(Some(row)) = rows.next() { - let path: String = row.get(0)?; - files.push(PathBuf::from(path)); - } - Ok(files) +pub(crate) fn init_clean_files(conn: &Connection) -> Result, rusqlite::Error> { + conn.execute(DEDUPE_DB, ())?; + let mut stmt = conn.prepare(FETCH_FILES)?; + let mut rows = stmt.query(())?; + let mut files = Vec::new(); + while let Ok(Some(row)) = rows.next() { + let path: String = row.get(0)?; + files.push(PathBuf::from(path)); } + Ok(files) +} - fn remove_file(&self, filename: &Path) -> Result<()> { - self.execute(REMOVE_FILE, params!(filename.to_str().unwrap()))?; - Ok(()) - } +pub(crate) fn remove_file(conn: &Connection, filename: &Path) -> Result<()> { + conn.execute(REMOVE_FILE, params!(filename.to_str().unwrap()))?; + Ok(()) +} - fn get_toencode_files(&self) -> Result, rusqlite::Error> { - let mut stmt = self.prepare(TOENCODE_PATHS)?; - let mut rows = stmt.query(())?; - let mut files: Vec = Vec::new(); - while let Ok(Some(row)) = rows.next() { - let path: String = row.get(0)?; - files.push(PathBuf::from(path)); - } - Ok(files) +pub(crate) fn get_toencode_files(conn: &Connection) -> Result, rusqlite::Error> { + let mut stmt = conn.prepare(TOENCODE_PATHS)?; + let mut rows = stmt.query(())?; + let mut files: Vec = Vec::new(); + while let Ok(Some(row)) = rows.next() { + let path: String = row.get(0)?; + files.push(PathBuf::from(path)); } + Ok(files) +} - fn get_toencode_number(&self) -> Result { - self.query_one(TOENCODE_NUMBER, (), |row| { - let num: u64 = row.get(0)?; - Ok(num) - }) - } +pub(crate) fn get_toencode_number(conn: &Connection) -> Result { + conn.query_one(TOENCODE_NUMBER, (), |row| { + let num: u64 = row.get(0)?; + Ok(num) + }) +} - fn get_modtime(&self, file: &Path) -> Result { - Ok( - self.query_one(GET_MODTIME, params![file.to_str().unwrap()], |row| { - let modtime: u64 = row.get(0)?; - Ok(modtime) - })?, - ) - } +pub(crate) fn get_modtime(conn: &Connection, file: &Path) -> Result { + Ok( + conn.query_one(GET_MODTIME, params![file.to_str().unwrap()], |row| { + let modtime: u64 = row.get(0)?; + Ok(modtime) + })?, + ) +} - fn vacuum(&self) -> Result<()> { - self.execute("VACUUM", ())?; - Ok(()) - } +pub(crate) fn vacuum(conn: &Connection) -> Result<()> { + conn.execute("VACUUM", ())?; + Ok(()) } #[cfg(test)] @@ -156,10 +139,10 @@ mod tests { "./samples/32bit.flac", ]; let mut counter = 0; - let conn = Connection::new(Some(&dbname)).unwrap(); + let conn = init_connection(Some(&dbname)).unwrap(); for file in filenames { let filename = PathBuf::from(file); - conn.insert_file(&filename).unwrap(); + insert_file(&conn, &filename).unwrap(); } let mut stmt = conn.prepare(TOENCODE_PATHS).unwrap(); let mut returned = stmt.query(()).unwrap(); @@ -179,10 +162,9 @@ mod tests { "./samples/24bit.flac", "./samples/32bit.flac", ]; - let conn = Connection::new(Some(&dbname)).unwrap(); + let conn = init_connection(Some(&dbname)).unwrap(); for file in filenames { - conn.insert_file(&Path::new(file).canonicalize().unwrap()) - .unwrap(); + insert_file(&conn, &Path::new(file).canonicalize().unwrap()).unwrap(); } conn.execute( @@ -199,8 +181,11 @@ mod tests { ) .unwrap(); - conn.update_file(&Path::new("./samples/16bit.flac").canonicalize().unwrap()) - .unwrap(); + update_file( + &conn, + &Path::new("./samples/16bit.flac").canonicalize().unwrap(), + ) + .unwrap(); let mut stmt = conn.prepare(TOENCODE_PATHS).unwrap(); let mut returned = stmt.query(()).unwrap(); diff --git a/src/files.rs b/src/files.rs index afb42d7..3b00de1 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,3 +1,5 @@ +use crate::db; +use crate::flac::handle_encode; use anyhow::{Result, anyhow}; #[cfg(not(test))] use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; @@ -15,8 +17,6 @@ use std::{ }; use walkdir::WalkDir; -use crate::{db::Database, flac::handle_encode}; - #[cfg(not(test))] const BAR_TEMPLATE: &str = "{msg:<} [{wide_bar:.green/cyan}] Elapsed: {elapsed} {pos:>7}/{len:7}"; #[cfg(not(test))] @@ -51,25 +51,25 @@ impl Display for FileError { impl Error for FileError {} fn handle_file(file: &Path, conn: &Connection) -> Result<()> { - if conn.check_file(file)? { + if db::check_file(conn, file)? { let modtime = file .metadata()? .modified()? .duration_since(UNIX_EPOCH)? .as_secs(); - let db_modtime = conn.get_modtime(file)?; + let db_modtime = db::get_modtime(conn, file)?; if modtime != db_modtime { - conn.update_file(file)?; + db::update_file(conn, file)?; } return Ok(()); } - conn.insert_file(file)?; + db::insert_file(conn, file)?; Ok(()) } -pub fn index_files_recursively( +pub(crate) fn index_files_recursively( path: &Path, conn: &Connection, handler: Arc, @@ -129,16 +129,20 @@ pub fn index_files_recursively( Ok(()) } -pub fn reencode_files(conn: Connection, handler: Arc, threads: usize) -> Result<()> { +pub(crate) fn reencode_files( + conn: Connection, + handler: Arc, + threads: usize, +) -> Result<()> { #[cfg(not(test))] let bar = ProgressBar::with_draw_target( - Some(conn.get_toencode_number()?), + Some(db::get_toencode_number(&conn)?), ProgressDrawTarget::stdout_with_hz(60), ) .with_style(ProgressStyle::with_template(BAR_TEMPLATE)?.progress_chars("#>-")) .with_message("Reencoding"); - let mut files = conn.get_toencode_files()?.into_iter(); + let mut files = db::get_toencode_files(&conn)?.into_iter(); let lock = Arc::new(Mutex::new(conn)); @@ -170,7 +174,7 @@ pub fn reencode_files(conn: Connection, handler: Arc, threads: usize match handle_encode(&file, handler) { Err(error) => eprintln!("{}", FileError::new(&file, error)), Ok(false) => { - if let Err(error) = lock.lock().unwrap().update_file(&file) { + if let Err(error) = db::update_file(&lock.lock().unwrap(), &file) { eprintln!("{}", FileError::new(&file, error)); } #[cfg(not(test))] @@ -194,8 +198,8 @@ pub fn reencode_files(conn: Connection, handler: Arc, threads: usize Ok(()) } -pub fn clean_files(conn: &Connection, handler: Arc) -> Result<()> { - let files = conn.init_clean_files()?; +pub(crate) fn clean_files(conn: &Connection, handler: Arc) -> Result<()> { + let files = db::init_clean_files(conn)?; #[cfg(not(test))] let spinner = ProgressBar::with_draw_target(None, ProgressDrawTarget::stdout_with_hz(60)) @@ -206,7 +210,7 @@ pub fn clean_files(conn: &Connection, handler: Arc) -> Result<()> { files.iter().for_each(|file| { #[allow(clippy::collapsible_if)] if handler.load(Ordering::SeqCst) && !file.exists() { - if let Err(error) = conn.remove_file(file) { + if let Err(error) = db::remove_file(conn, file) { eprintln!("{}", FileError::new(file, error)) }; #[cfg(not(test))] @@ -216,7 +220,7 @@ pub fn clean_files(conn: &Connection, handler: Arc) -> Result<()> { #[cfg(not(test))] spinner.finish(); - conn.vacuum()?; + db::vacuum(conn)?; Ok(()) } @@ -229,7 +233,7 @@ mod tests { fn test_index_lots_of_files() { let dbname = PathBuf::from("temp3.db"); let handler = Arc::new(AtomicBool::new(true)); - let conn = Connection::new(Some(&dbname)).unwrap(); + let conn = db::init_connection(Some(&dbname)).unwrap(); index_files_recursively(Path::new("./testfiles"), &conn, handler).unwrap(); std::fs::remove_file(dbname).unwrap(); } @@ -238,7 +242,7 @@ mod tests { fn test_clean_files() { let dbname = PathBuf::from("temp4.db"); let handler = Arc::new(AtomicBool::new(true)); - let conn = Connection::new(Some(&dbname)).unwrap(); + let conn = db::init_connection(Some(&dbname)).unwrap(); let filenames = [ "./samples/16bit.flac", "./samples/24bit.flac", @@ -248,13 +252,13 @@ mod tests { std::fs::copy("./samples/32bit.flac", "./samples/nonexisting.flac").unwrap(); for file in filenames { let filename = PathBuf::from(file); - conn.insert_file(&filename).unwrap(); + db::insert_file(&conn, &filename).unwrap(); } std::fs::remove_file("./samples/nonexisting.flac").unwrap(); clean_files(&conn, handler).unwrap(); - let counter = conn.init_clean_files().unwrap().len(); + let counter = db::init_clean_files(&conn).unwrap().len(); std::fs::remove_file(dbname).unwrap(); assert!(counter == 3) } @@ -263,13 +267,13 @@ mod tests { fn test_reencode_lots_of_files() { let dbname = PathBuf::from("temp5.db"); let handler = Arc::new(AtomicBool::new(true)); - let conn = Connection::new(Some(&dbname)).unwrap(); + let conn = db::init_connection(Some(&dbname)).unwrap(); let temp = handler.clone(); index_files_recursively(Path::new("./testfiles"), &conn, temp).unwrap(); - println!("\n{}", conn.get_toencode_number().unwrap()); + println!("\n{}", db::get_toencode_number(&conn).unwrap()); reencode_files(conn, handler, 4).unwrap(); - let conn = Connection::new(Some(&dbname)).unwrap(); - println!("\n{}", conn.get_toencode_number().unwrap()); + let conn = db::init_connection(Some(&dbname)).unwrap(); + println!("\n{}", db::get_toencode_number(&conn).unwrap()); std::fs::remove_file(dbname).unwrap(); } } diff --git a/src/flac.rs b/src/flac.rs index e882cd7..eb603d7 100644 --- a/src/flac.rs +++ b/src/flac.rs @@ -141,7 +141,7 @@ fn encode_file(filename: &Path, handler: Arc) -> Result { Ok(false) } -pub fn handle_encode(filename: &Path, handler: Arc) -> Result { +pub(crate) fn handle_encode(filename: &Path, handler: Arc) -> Result { match encode_file(filename, handler) { Err(error) => { let _ = std::fs::remove_file(filename.with_extension("tmp")); @@ -151,7 +151,7 @@ pub fn handle_encode(filename: &Path, handler: Arc) -> Result } } -pub fn get_vendor(file: &Path) -> Result { +pub(crate) fn get_vendor(file: &Path) -> Result { let blocklist = metadata::BlockList::open(file)?; if let Some(data) = blocklist.get::() { Ok(data.vendor_string.to_owned()) diff --git a/src/main.rs b/src/main.rs index d1e4562..de3da62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ use anyhow::Result; use clap::{Arg, ArgAction, Command, ValueHint, command, value_parser}; use clap_complete::{Generator, Shell, generate}; use console::style; -use rusqlite::Connection; use std::{ path::PathBuf, sync::{ @@ -14,8 +13,6 @@ use std::{ }, }; -use crate::db::Database; - fn build_cli() -> Command { command!() .arg( @@ -93,12 +90,12 @@ fn main() -> Result<()> { r.store(false, Ordering::SeqCst); })?; - let conn = Connection::new(args.get_one::("db"))?; + let conn = db::init_connection(args.get_one::("db"))?; let path = args.get_one::("path"); if path.is_none() && !args.get_flag("clean") && !args.get_flag("doit") { - let count = conn.get_toencode_number()?; + let count = db::get_toencode_number(&conn)?; println!("Files to reencode:\t{}", style(count).green()); return Ok(()); } -- cgit v1.3.1 From b9dfa39e4d72ce8e454bf8ac1449e6436e9bec4a Mon Sep 17 00:00:00 2001 From: jakka Date: Tue, 30 Sep 2025 17:10:19 +0300 Subject: changelog edit and version bump --- CHANGELOG.md | 8 ++++++++ Cargo.lock | 18 +++++++++--------- Cargo.toml | 10 +++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd6aea..bf8e6c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,21 @@ +# v0.3.1 + +* removed useless trait +* isolated all module functions + # v0.3.0 + * removed claxon dep in favor of flac_codec, same for metaflac * cleaned up code a bit # v0.2.6-fix + * remembered about changelog.md * fixed incorrect encoded_by tag match * minor code improvements and fixes # v0.1.2 + * added better bar incremental logic by passing it to threads * added graceful shutdown (albeit its a bit slow) * checks file if it exists before reencoding diff --git a/Cargo.lock b/Cargo.lock index e52de08..17eae1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" [[package]] name = "anstyle-parse" @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "flac-reencoder" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "clap", @@ -484,9 +484,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] @@ -582,18 +582,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.16" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.16" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 9a93d47..160981e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flac-reencoder" -version = "0.3.0" +version = "0.3.1" edition = "2024" repository = "https://github.com/doujincafe/reencoder/" license = "BSD-3-Clause" @@ -19,7 +19,7 @@ indicatif = { version = "0.18.0", features = ["improved_unicode"] } walkdir = "2.5.0" console = { version = "0.16.0", features = ["windows-console-colors"] } rusqlite = { version = "0.36.0", default-features = false, features = [ - "modern_sqlite", + "modern_sqlite", ] } ctrlc = "3.4.7" flac-codec = { version = "1.2.0", features = ["rayon"] } @@ -31,13 +31,13 @@ linked = ["flac-bound/libflac-nobuild"] [dev-dependencies] flac-bound = { version = "0.5.0", default-features = false, features = [ - "libflac-nobuild", + "libflac-nobuild", ] } [target.'cfg(windows)'.dependencies] rusqlite = { version = "0.36.0", default-features = false, features = [ - "bundled-windows", + "bundled-windows", ] } flac-bound = { version = "0.5.0", default-features = false, features = [ - "libflac-noogg", + "libflac-noogg", ] } -- cgit v1.3.1 From dfe983c1875eea0c58cc0beee0d834398b3644a3 Mon Sep 17 00:00:00 2001 From: jakka Date: Sun, 5 Oct 2025 13:39:04 +0300 Subject: updated deps, most notably libflac-sys --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17eae1b..0db5da7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "anstream" -version = "0.6.20" +version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" dependencies = [ "anstyle", "anstyle-parse", @@ -87,9 +87,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "cc" -version = "1.2.39" +version = "1.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" +checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" dependencies = [ "find-msvc-tools", "shlex", @@ -269,9 +269,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "find-msvc-tools" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" +checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" [[package]] name = "flac-bound" @@ -384,9 +384,9 @@ checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" [[package]] name = "libflac-sys" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01b01d08e4f670c184ffe3c3e5efbf0bd6e88c8cca796c278c86bbf49583545c" +checksum = "6fc5cbb957a914952ee9b8667e82b984c6dc280087df01497fc5b4776d303582" dependencies = [ "cmake", "libc", -- cgit v1.3.1 From a43d0a822636946d3b6161d5a91bfe2124203db1 Mon Sep 17 00:00:00 2001 From: jakka Date: Sun, 5 Oct 2025 13:39:55 +0300 Subject: version bump due to updated libflac deps --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0db5da7..9cc9199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "flac-reencoder" -version = "0.3.1" +version = "0.3.2" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 160981e..98b5421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flac-reencoder" -version = "0.3.1" +version = "0.3.2" edition = "2024" repository = "https://github.com/doujincafe/reencoder/" license = "BSD-3-Clause" -- cgit v1.3.1 From 8d02beb03f0ca847ea603bc2967f173b64ffcac3 Mon Sep 17 00:00:00 2001 From: jakka Date: Sun, 5 Oct 2025 13:42:35 +0300 Subject: version bump due to updated rusqlite deps --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9cc9199..a724f04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "libsqlite3-sys" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91632f3b4fb6bd1d72aa3d78f41ffecfcf2b1a6648d8c241dbe7dbfaf4875e15" +checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f" dependencies = [ "cc", "pkg-config", @@ -524,9 +524,9 @@ dependencies = [ [[package]] name = "rusqlite" -version = "0.36.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de23c3319433716cf134eed225fe9986bc24f63bed9be9f20c329029e672dc7" +checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f" dependencies = [ "bitflags", "fallible-iterator", diff --git a/Cargo.toml b/Cargo.toml index 98b5421..819d95e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ flac-bound = { version = "0.5.0", default-features = false } indicatif = { version = "0.18.0", features = ["improved_unicode"] } walkdir = "2.5.0" console = { version = "0.16.0", features = ["windows-console-colors"] } -rusqlite = { version = "0.36.0", default-features = false, features = [ +rusqlite = { version = "0.37.0", default-features = false, features = [ "modern_sqlite", ] } ctrlc = "3.4.7" @@ -35,7 +35,7 @@ flac-bound = { version = "0.5.0", default-features = false, features = [ ] } [target.'cfg(windows)'.dependencies] -rusqlite = { version = "0.36.0", default-features = false, features = [ +rusqlite = { version = "0.37.0", default-features = false, features = [ "bundled-windows", ] } flac-bound = { version = "0.5.0", default-features = false, features = [ -- cgit v1.3.1 From 18636a5bd5b6ab71f51b9291852080e4948bed65 Mon Sep 17 00:00:00 2001 From: jakka Date: Sun, 5 Oct 2025 13:46:56 +0300 Subject: version bump due to updated rusqlite deps --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a724f04..fbae675 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "flac-reencoder" -version = "0.3.2" +version = "0.3.3" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 819d95e..6c4ee2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flac-reencoder" -version = "0.3.2" +version = "0.3.3" edition = "2024" repository = "https://github.com/doujincafe/reencoder/" license = "BSD-3-Clause" -- cgit v1.3.1 From 7f9aa7d6c650b8d32dc7eca02975c3e876c72c9d Mon Sep 17 00:00:00 2001 From: jakka Date: Sun, 5 Oct 2025 13:51:20 +0300 Subject: edited changelog and readme --- CHANGELOG.md | 27 ++++++++++++++++----------- README.md | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8e6c2..6c25fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,27 @@ +# v0.3.3 + +- updated deps, most notably libflac-sys and rusqlite +- edited changelog + # v0.3.1 -* removed useless trait -* isolated all module functions +- removed useless trait +- isolated all module functions # v0.3.0 -* removed claxon dep in favor of flac_codec, same for metaflac -* cleaned up code a bit +- removed claxon dep in favor of flac_codec, same for metaflac +- cleaned up code a bit # v0.2.6-fix -* remembered about changelog.md -* fixed incorrect encoded_by tag match -* minor code improvements and fixes +- remembered about changelog.md +- fixed incorrect encoded_by tag match +- minor code improvements and fixes # v0.1.2 -* added better bar incremental logic by passing it to threads -* added graceful shutdown (albeit its a bit slow) -* checks file if it exists before reencoding -* removes temporary file if it was left uncleaned from the previous session +- added better bar incremental logic by passing it to threads +- added graceful shutdown (albeit its a bit slow) +- checks file if it exists before reencoding +- removes temporary file if it was left uncleaned from the previous session diff --git a/README.md b/README.md index 37cb744..f71ae40 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,21 @@ scans a specified folder and reencodes flacs if they needed to be reencoded +## installation + +you can use cargo to install: +`cargo install flac-reencoder` + +or clone the repo and build it yourself + +to build statically just run the default build command: +`cargo build -r` + +to dynamically link to libsqlite3 and libflac libs, use the following command: +`cargo build -r --no-default-features -F linked` + ``` -Usage: reencoder [OPTIONS] [path] +Usage: flac-reencoder [OPTIONS] [path] Arguments: [path] Path for indexing/reencoding -- cgit v1.3.1 From d9871c81dd945ea188d9d7a31993b7bb1735d257 Mon Sep 17 00:00:00 2001 From: jakka Date: Wed, 8 Oct 2025 14:27:11 +0300 Subject: better file scanning logic - stopped walking down the filetree two times, now files are sent thru channels from a walker thread --- Cargo.lock | 56 +++++++++++++++++++++++++-------------------------- src/files.rs | 66 ++++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbae675..a934c2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,7 +168,7 @@ dependencies = [ "libc", "once_cell", "unicode-width", - "windows-sys 0.61.1", + "windows-sys 0.61.2", ] [[package]] @@ -213,7 +213,7 @@ checksum = "881c5d0a13b2f1498e2306e82cbada78390e152d4b1378fb28a84f4dcd0dc4f3" dependencies = [ "dispatch", "nix", - "windows-sys 0.61.1", + "windows-sys 0.61.2", ] [[package]] @@ -234,7 +234,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.1", + "windows-sys 0.61.2", ] [[package]] @@ -614,9 +614,9 @@ checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] name = "unit-prefix" @@ -727,14 +727,14 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.1", + "windows-sys 0.61.2", ] [[package]] name = "windows-link" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" @@ -747,18 +747,18 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.61.1" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f109e41dd4a3c848907eb83d5a42ea98b3769495597450cf6d153507b166f0f" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] [[package]] name = "windows-targets" -version = "0.53.4" +version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", "windows_aarch64_gnullvm", @@ -773,48 +773,48 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" [[package]] name = "windows_aarch64_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" [[package]] name = "windows_i686_gnu" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" [[package]] name = "windows_i686_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" [[package]] name = "windows_i686_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" [[package]] name = "windows_x86_64_gnu" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" [[package]] name = "windows_x86_64_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" [[package]] name = "windows_x86_64_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" diff --git a/src/files.rs b/src/files.rs index 3b00de1..995e938 100644 --- a/src/files.rs +++ b/src/files.rs @@ -11,6 +11,7 @@ use std::{ sync::{ Arc, Mutex, atomic::{AtomicBool, AtomicUsize, Ordering}, + mpsc, }, thread::{self, sleep}, time::{Duration, UNIX_EPOCH}, @@ -83,40 +84,49 @@ pub(crate) fn index_files_recursively( let bar = ProgressBar::with_draw_target(Some(0), ProgressDrawTarget::stdout_with_hz(60)) .with_style(ProgressStyle::with_template(BAR_TEMPLATE)?.progress_chars("#>-")) .with_message("Indexing"); + thread::scope(|s| { + let (filesend, filerecv) = mpsc::channel(); - for entry in WalkDir::new(&abspath) { - if handler.load(Ordering::SeqCst) { - let path = entry?.into_path(); - if !path.is_file() { - continue; - } - if path.extension().is_some_and(|x| x == "flac") { - #[cfg(not(test))] - bar.inc_length(1); - } - } else { - break; - } - } + #[cfg(not(test))] + let newbar = bar.clone(); - for entry in WalkDir::new(abspath) { - if handler.load(Ordering::SeqCst) { - let path = entry.unwrap().into_path(); - if !path.is_file() { - continue; - } - if path.extension().is_some_and(|x| x == "flac") { - if let Err(error) = handle_file(&path, conn) { - eprintln!("{}", FileError::new(&path, error)); + let newhandler = handler.clone(); + + s.spawn(move || { + for entry in WalkDir::new(&abspath) { + if newhandler.load(Ordering::SeqCst) { + if let Err(error) = entry { + #[cfg(not(test))] + newbar.println(format!("{}", error)); + } else { + let path = entry.unwrap().into_path(); + if !path.is_file() { + continue; + } + if path.extension().is_some_and(|x| x == "flac") { + let _ = filesend.send(path.to_owned()); + #[cfg(not(test))] + newbar.inc_length(1); + } + } } else { - #[cfg(not(test))] - bar.inc(1); + break; } } - } else { - break; + }); + + while let Ok(path) = filerecv.recv() + && handler.load(Ordering::SeqCst) + { + if let Err(error) = handle_file(&path, conn) { + #[cfg(not(test))] + bar.println(format!("{}", FileError::new(&path, error))); + } else { + #[cfg(not(test))] + bar.inc(1); + } } - } + }); #[cfg(not(test))] { -- cgit v1.3.1 From 6924f47d1d216698501a65c0ff9bec5019d8e05e Mon Sep 17 00:00:00 2001 From: jakka Date: Wed, 8 Oct 2025 14:49:46 +0300 Subject: handled lints --- src/files.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/files.rs b/src/files.rs index 995e938..63c87fa 100644 --- a/src/files.rs +++ b/src/files.rs @@ -92,6 +92,7 @@ pub(crate) fn index_files_recursively( let newhandler = handler.clone(); + #[allow(unused_variables)] s.spawn(move || { for entry in WalkDir::new(&abspath) { if newhandler.load(Ordering::SeqCst) { @@ -118,6 +119,7 @@ pub(crate) fn index_files_recursively( while let Ok(path) = filerecv.recv() && handler.load(Ordering::SeqCst) { + #[allow(unused_variables)] if let Err(error) = handle_file(&path, conn) { #[cfg(not(test))] bar.println(format!("{}", FileError::new(&path, error))); -- cgit v1.3.1 From 72760456c9da3d4737ef0555edffcf6fe0a1f087 Mon Sep 17 00:00:00 2001 From: jakka Date: Thu, 9 Oct 2025 09:42:10 +0300 Subject: removed unneeded feature --- Cargo.lock | 52 ---------------------------------------------------- Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a934c2e..105b81d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,31 +180,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - [[package]] name = "ctrlc" version = "3.5.0" @@ -243,12 +218,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - [[package]] name = "encode_unicode" version = "1.0.0" @@ -291,7 +260,6 @@ dependencies = [ "arrayvec", "bitstream-io", "md5", - "rayon", ] [[package]] @@ -491,26 +459,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rayon" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_users" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 6c4ee2e..43fa761 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ rusqlite = { version = "0.37.0", default-features = false, features = [ "modern_sqlite", ] } ctrlc = "3.4.7" -flac-codec = { version = "1.2.0", features = ["rayon"] } +flac-codec = { version = "1.2.0" } [features] default = ["bundled"] -- cgit v1.3.1