From aa27e6ceffe23f489d1e10ef538d38dd767949ff Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 12 Feb 2024 12:23:12 -0800 Subject: [PATCH] Make clippy stop complaining about insane repair callback (#3104) --- src/index.rs | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/index.rs b/src/index.rs index 2689380b33..a2e27b6b13 100644 --- a/src/index.rs +++ b/src/index.rs @@ -252,31 +252,34 @@ impl Index { let once = Once::new(); let progress_bar = Mutex::new(None); - let database = match Database::builder() - .set_cache_size(db_cache_size) - .set_repair_callback(move |progress: &mut RepairSession| { - once.call_once(|| println!("Index file `{}` needs recovery. This can take a long time, especially for the --index-sats index.", index_path.display())); - - if !(cfg!(test) || log_enabled!(log::Level::Info) || integration_test()) { - let mut guard = progress_bar.lock().unwrap(); + let repair_callback = move |progress: &mut RepairSession| { + once.call_once(|| println!("Index file `{}` needs recovery. This can take a long time, especially for the --index-sats index.", index_path.display())); + + if !(cfg!(test) || log_enabled!(log::Level::Info) || integration_test()) { + let mut guard = progress_bar.lock().unwrap(); + + let progress_bar = guard.get_or_insert_with(|| { + let progress_bar = ProgressBar::new(100); + progress_bar.set_style( + ProgressStyle::with_template("[repairing database] {wide_bar} {pos}/{len}").unwrap(), + ); + progress_bar + }); - let progress_bar = guard.get_or_insert_with(|| { - let progress_bar = ProgressBar::new(100); - progress_bar.set_style( - ProgressStyle::with_template("[repairing database] {wide_bar} {pos}/{len}").unwrap(), - ); - progress_bar - }); + #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + progress_bar.set_position((progress.progress() * 100.0) as u64); + } + }; - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] - progress_bar.set_position((progress.progress() * 100.0) as u64); - } - }) + let database = match Database::builder() + .set_cache_size(db_cache_size) + .set_repair_callback(repair_callback) .open(&path) { Ok(database) => { { - let schema_version = database.begin_read()? + let schema_version = database + .begin_read()? .open_table(STATISTIC_TO_COUNT)? .get(&Statistic::Schema.key())? .map(|x| x.value()) @@ -362,11 +365,7 @@ impl Index { u64::from(options.index_transactions), )?; - Self::set_statistic( - &mut statistics, - Statistic::Schema, - SCHEMA_VERSION, - )?; + Self::set_statistic(&mut statistics, Statistic::Schema, SCHEMA_VERSION)?; } tx.commit()?;