mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
find: support resolving multiple pack ids to blobs
Just passing the list of blobs to packsToBlobs would also work in most cases, however, it could cause unexpected results when multiple pack files have the same prefix. Forget found prefixes to prevent this.
This commit is contained in:
parent
790294dc26
commit
6c01078f3d
@ -411,7 +411,6 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allPacksFound := false
|
allPacksFound := false
|
||||||
packsFound := 0
|
|
||||||
|
|
||||||
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 {
|
||||||
@ -424,6 +423,10 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
|
|||||||
if _, ok := packIDs[id.Str()]; !ok {
|
if _, ok := packIDs[id.Str()]; !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
delete(packIDs, id.Str())
|
||||||
|
} else {
|
||||||
|
// forget found id
|
||||||
|
delete(packIDs, idStr)
|
||||||
}
|
}
|
||||||
debug.Log("Found pack %s", idStr)
|
debug.Log("Found pack %s", idStr)
|
||||||
blobs, _, err := f.repo.ListPack(ctx, id, size)
|
blobs, _, err := f.repo.ListPack(ctx, id, size)
|
||||||
@ -434,8 +437,7 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
|
|||||||
f.blobIDs[b.ID.String()] = struct{}{}
|
f.blobIDs[b.ID.String()] = struct{}{}
|
||||||
}
|
}
|
||||||
// Stop searching when all packs have been found
|
// Stop searching when all packs have been found
|
||||||
packsFound++
|
if len(packIDs) == 0 {
|
||||||
if packsFound >= len(packIDs) {
|
|
||||||
allPacksFound = true
|
allPacksFound = true
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -561,7 +563,7 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if opts.PackID {
|
if opts.PackID {
|
||||||
err := f.packsToBlobs(ctx, []string{f.pat.pattern[0]}) // TODO: support multiple packs
|
err := f.packsToBlobs(ctx, f.pat.pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user