From 341add84dcb7bff9d3b2597d83f9163038cc0a92 Mon Sep 17 00:00:00 2001 From: jakka Date: Thu, 19 Jun 2025 23:33:17 +0300 Subject: removed failing db file check. readded test compile config --- src/files.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 52b4058..7f346cc 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,5 +1,6 @@ use anyhow::{Result, anyhow}; use futures_util::StreamExt; +#[cfg(not(test))] use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; use pin_utils::pin_mut; use std::{ @@ -14,7 +15,9 @@ use walkdir::WalkDir; use crate::{db::Database, flac::encode_file}; +#[cfg(not(test))] const BAR_TEMPLATE: &str = "{msg:<} [{wide_bar:.green/cyan}] Elapsed: {elapsed} {pos:>7}/{len:7}"; +#[cfg(not(test))] const SPINNER_TEMPLATE: &str = "Removed from db: {pos:.green}"; #[derive(Debug)] @@ -84,7 +87,7 @@ pub async fn index_files_recursively( let abspath = path.as_ref().canonicalize()?; let mut tasks: JoinSet> = JoinSet::new(); - + #[cfg(not(test))] 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"); @@ -97,13 +100,15 @@ pub async fn index_files_recursively( if let Some(ext) = path.extension() { if ext == "flac" { let newconn = conn.clone(); - + #[cfg(not(test))] let newbar = bar.clone(); tasks.spawn(async move { handle_file(path, newconn).await?; + #[cfg(not(test))] newbar.inc(1); Ok(()) }); + #[cfg(not(test))] bar.inc_length(1); } } @@ -122,7 +127,7 @@ pub async fn index_files_recursively( _ => {} } } - + #[cfg(not(test))] bar.abandon_with_message("Indexing aborted"); return Ok(()) }, @@ -134,7 +139,7 @@ pub async fn index_files_recursively( _ => {} } } - + #[cfg(not(test))] bar.finish_with_message("Finished indexing"); Ok(()) } @@ -145,18 +150,20 @@ pub async fn reencode_files(conn: &Database, canceltoken: CancellationToken) -> let mut tasks = JoinSet::new(); + #[cfg(not(test))] let bar = ProgressBar::with_draw_target( Some(conn.get_toencode_number().await?), ProgressDrawTarget::stdout_with_hz(60), ) .with_style(ProgressStyle::with_template(BAR_TEMPLATE)?.progress_chars("#>-")) - .with_message("Indexing"); + .with_message("Reencoding"); while let Some(Ok(row)) = stream.next().await { if let Some(file) = row.get_value(0)?.as_text() { let filename = Path::new(file).canonicalize()?; if filename.exists() { let newconn = conn.clone(); + #[cfg(not(test))] let newbar = bar.clone(); tasks.spawn(async move { let file = filename.clone(); @@ -169,6 +176,7 @@ pub async fn reencode_files(conn: &Database, canceltoken: CancellationToken) -> if let Err(error) = newconn.update_file(&filename).await { return Err(anyhow!(FileError::new(&filename, error))); }; + #[cfg(not(test))] newbar.inc(1); Ok(()) }); @@ -187,7 +195,7 @@ pub async fn reencode_files(conn: &Database, canceltoken: CancellationToken) -> _ => {} } } - + #[cfg(not(test))] bar.abandon_with_message("Reencoding aborted"); return Ok(()) }, @@ -199,7 +207,7 @@ pub async fn reencode_files(conn: &Database, canceltoken: CancellationToken) -> _ => {} } } - + #[cfg(not(test))] bar.finish_with_message("Finished encoding"); Ok(()) @@ -210,18 +218,19 @@ pub async fn clean_files(conn: &Database) -> Result<()> { let query_res = conn.init_clean_files().await?; pin_mut!(query_res); - + #[cfg(not(test))] let spinner = ProgressBar::with_draw_target(None, ProgressDrawTarget::stdout_with_hz(60)) .with_style(ProgressStyle::with_template(SPINNER_TEMPLATE)?); while let Some(Ok(row)) = query_res.next().await { let path = PathBuf::from(row.get_str(0)?); let newconn = conn.clone(); - + #[cfg(not(test))] let newspinner = spinner.clone(); tasks.spawn(async move { if !path.exists() { newconn.remove_file(path).await?; + #[cfg(not(test))] newspinner.inc(1); } Ok(()) @@ -229,7 +238,7 @@ pub async fn clean_files(conn: &Database) -> Result<()> { } tasks.join_all().await; - + #[cfg(not(test))] spinner.finish(); conn.0.execute("VACUUM", ()).await?; -- cgit v1.3.1