rebuild-index: Ignore broken index files

Previously, an e.g. truncated index could prevent rebuild-index from
working.
This commit is contained in:
Michael Eischer 2021-08-22 17:58:21 +02:00
parent 66382b2861
commit 64258a2c2a

View file

@ -73,7 +73,27 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
} }
} else { } else {
Verbosef("loading indexes...\n") Verbosef("loading indexes...\n")
err := repo.LoadIndex(gopts.ctx) mi := repository.NewMasterIndex()
err := repository.ForAllIndexes(ctx, repo, func(id restic.ID, idx *repository.Index, oldFormat bool, err error) error {
if err != nil {
Warnf("removing invalid index %v: %v\n", id, err)
obsoleteIndexes = append(obsoleteIndexes, id)
return nil
}
mi.Insert(idx)
return nil
})
if err != nil {
return err
}
err = mi.MergeFinalIndexes()
if err != nil {
return err
}
err = repo.SetIndex(mi)
if err != nil { if err != nil {
return err return err
} }