Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(errors): better error message for hot/cold repo in check #297

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions 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 All @@ -426,7 +426,7 @@ fn check_packs(
}

// TODO: Add documentation
/// Checks if all packs in the backend are also in the index
///Checks if all packs in the backend are also in the index
simonsan marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Arguments
///
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
Loading