forked from TrueCloudLab/restic
Simplify rebuild-index code
This commit is contained in:
parent
68b74e359e
commit
d8d2cc6dd9
1 changed files with 21 additions and 31 deletions
|
@ -59,10 +59,11 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
|
|||
|
||||
var obsoleteIndexes restic.IDs
|
||||
packSizeFromList := make(map[restic.ID]int64)
|
||||
packSizeFromIndex := make(map[restic.ID]int64)
|
||||
removePacks := restic.NewIDSet()
|
||||
|
||||
if opts.ReadAllPacks {
|
||||
// get old index files
|
||||
// get list of old index files but start with empty index
|
||||
err := repo.List(ctx, restic.IndexFile, func(id restic.ID, size int64) error {
|
||||
obsoleteIndexes = append(obsoleteIndexes, id)
|
||||
return nil
|
||||
|
@ -70,27 +71,17 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Verbosef("finding pack files in repo...\n")
|
||||
err = repo.List(ctx, restic.PackFile, func(id restic.ID, size int64) error {
|
||||
packSizeFromList[id] = size
|
||||
removePacks.Insert(id)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
Verbosef("loading indexes...\n")
|
||||
err := repo.LoadIndex(gopts.ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
packSizeFromIndex = repo.Index().PackSize(ctx, false)
|
||||
}
|
||||
|
||||
Verbosef("getting pack files to read...\n")
|
||||
packSizeFromIndex := repo.Index().PackSize(ctx, false)
|
||||
|
||||
err = repo.List(ctx, restic.PackFile, func(id restic.ID, packSize int64) error {
|
||||
err := repo.List(ctx, restic.PackFile, func(id restic.ID, packSize int64) error {
|
||||
size, ok := packSizeFromIndex[id]
|
||||
if !ok || size != packSize {
|
||||
// Pack was not referenced in index or size does not match
|
||||
|
@ -108,7 +99,6 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
|
|||
// when rebuilding the index
|
||||
removePacks.Insert(id)
|
||||
}
|
||||
}
|
||||
|
||||
if len(packSizeFromList) > 0 {
|
||||
Verbosef("reading pack files\n")
|
||||
|
@ -123,7 +113,7 @@ func rebuildIndex(opts RebuildIndexOptions, gopts GlobalOptions, repo *repositor
|
|||
}
|
||||
}
|
||||
|
||||
err := rebuildIndexFiles(gopts, repo, removePacks, obsoleteIndexes)
|
||||
err = rebuildIndexFiles(gopts, repo, removePacks, obsoleteIndexes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue