Skip to content

Commit

Permalink
Make clippy stop complaining about insane repair callback (#3104)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Feb 12, 2024
1 parent 9e5d3d1 commit b6fcc26
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()?;
Expand Down

0 comments on commit b6fcc26

Please sign in to comment.