2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

find: stop file listing after resolving all pack files

This commit is contained in:
Michael Eischer 2021-05-15 23:37:59 +02:00
parent 6c01078f3d
commit 40745b4f82

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"strings" "strings"
"time" "time"
@ -399,6 +400,8 @@ func (f *Finder) findIDs(ctx context.Context, sn *restic.Snapshot) error {
}) })
} }
var errorAllPacksFound = fmt.Errorf("all packs found")
// packsToBlobs converts the list of pack IDs to a list of blob IDs that // packsToBlobs converts the list of pack IDs to a list of blob IDs that
// belong to those packs. // belong to those packs.
func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error { func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
@ -410,13 +413,8 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
f.blobIDs = make(map[string]struct{}) f.blobIDs = make(map[string]struct{})
} }
allPacksFound := false
debug.Log("Looking for packs...") debug.Log("Looking for packs...")
err := f.repo.List(ctx, restic.PackFile, func(id restic.ID, size int64) error { err := f.repo.List(ctx, restic.PackFile, func(id restic.ID, size int64) error {
if allPacksFound {
return nil
}
idStr := id.String() idStr := id.String()
if _, ok := packIDs[idStr]; !ok { if _, ok := packIDs[idStr]; !ok {
// Look for short ID form // Look for short ID form
@ -438,16 +436,16 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
} }
// Stop searching when all packs have been found // Stop searching when all packs have been found
if len(packIDs) == 0 { if len(packIDs) == 0 {
allPacksFound = true return errorAllPacksFound
} }
return nil return nil
}) })
if err != nil { if err != nil && err != errorAllPacksFound {
return err return err
} }
if !allPacksFound { if err != errorAllPacksFound {
return errors.Fatal("unable to find all specified pack(s)") return errors.Fatal("unable to find all specified pack(s)")
} }