Skip to content

Commit

Permalink
fix(errors): better error message for hot/cold repo in check (#297)
Browse files Browse the repository at this point in the history
Fixes rustic-rs/rustic#1229

---------

Co-authored-by: Alexander Weiss <[email protected]>
Co-authored-by: aawsome <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2024
1 parent e84373e commit f68ffa3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion crates/core/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn check_packs(

if let Some(hot_be) = hot_be {
let p = pb.progress_spinner("listing packs in hot repo...");
check_packs_list(hot_be, tree_packs)?;
check_packs_list_hot(hot_be, tree_packs, &packs)?;
p.finish();
}

Expand Down Expand Up @@ -456,6 +456,46 @@ fn check_packs_list(be: &impl ReadBackend, mut packs: HashMap<PackId, u32>) -> R
Ok(())
}

/// Checks if all packs in the backend are also in the index
///
/// # Arguments
///
/// * `be` - The backend to check
/// * `packs` - The packs to check
///
/// # Errors
///
/// If a pack is missing or has a different size
fn check_packs_list_hot(
be: &impl ReadBackend,
mut treepacks: HashMap<PackId, u32>,
packs: &HashMap<PackId, u32>,
) -> RusticResult<()> {
for (id, size) in be
.list_with_size(FileType::Pack)
.map_err(RusticErrorKind::Backend)?
{
match treepacks.remove(&PackId::from(id)) {
None => {
if packs.contains_key(&PackId::from(id)) {
warn!("hot pack {id} is a data pack. This should not happen.");
} else {
warn!("hot pack {id} not referenced in index. Can be a parallel backup job. To repair: 'rustic repair index'.");
}
}
Some(index_size) if index_size != size => {
error!("hot pack {id}: size computed by index: {index_size}, actual size: {size}. To repair: 'rustic repair index'.");
}
_ => {} //everything ok
}
}

for (id, _) in treepacks {
error!("tree pack {id} is referenced by the index but not present in hot repo! To repair: 'rustic repair index'.",);
}
Ok(())
}

/// Check if all snapshots and contained trees can be loaded and contents exist in the index
///
/// # Arguments
Expand Down

0 comments on commit f68ffa3

Please sign in to comment.