Skip to content

Commit

Permalink
Merge pull request #3 from drdo/skip-progress-bar-for-zero-deletions
Browse files Browse the repository at this point in the history
Do not show a delete progress bar if there's nothing to delete
  • Loading branch information
drdo authored May 19, 2024
2 parents 8ab0fd6 + e09fcdf commit 31970a1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,21 @@ fn sync_snapshots(
) -> anyhow::Result<()> {
// Figure out what snapshots we need to fetch
let missing_snapshots: Vec<Box<str>> = {
// Fetch snapshot list
let pb = new_pb("Fetching repository snapshot list {spinner}");
let repo_snapshots = restic.snapshots()?
.into_iter()
.map(|s| s.id)
.collect::<Vec<Box<str>>>();
pb.finish();
{ // Delete snapshots from the DB that were deleted on the repo
let groups_to_delete = cache.get_snapshots()?
.into_iter()
.filter(|snapshot| ! repo_snapshots.contains(&snapshot))
.map(|snapshot_id| cache.get_snapshot_group(snapshot_id))
.collect::<Result<HashSet<u64>, rusqlite::Error>>()?;


// Delete snapshots from the DB that were deleted on the repo
let groups_to_delete = cache.get_snapshots()?
.into_iter()
.filter(|snapshot| ! repo_snapshots.contains(&snapshot))
.map(|snapshot_id| cache.get_snapshot_group(snapshot_id))
.collect::<Result<HashSet<u64>, rusqlite::Error>>()?;
if groups_to_delete.len() > 0 {
eprintln!("Need to delete {} groups", groups_to_delete.len());
let pb = new_pb("{wide_bar} [{pos}/{len}] {spinner}");
pb.set_length(groups_to_delete.len() as u64);
Expand Down

0 comments on commit 31970a1

Please sign in to comment.