mirror of https://github.com/restic/restic.git
Merge pull request #2230 from cdhowie/issue-2229
Extend find --show-pack-id to work with --tree
This commit is contained in:
commit
ecc2458de8
|
@ -62,7 +62,7 @@ func init() {
|
||||||
f.BoolVar(&findOptions.BlobID, "blob", false, "pattern is a blob-ID")
|
f.BoolVar(&findOptions.BlobID, "blob", false, "pattern is a blob-ID")
|
||||||
f.BoolVar(&findOptions.TreeID, "tree", false, "pattern is a tree-ID")
|
f.BoolVar(&findOptions.TreeID, "tree", false, "pattern is a tree-ID")
|
||||||
f.BoolVar(&findOptions.PackID, "pack", false, "pattern is a pack-ID")
|
f.BoolVar(&findOptions.PackID, "pack", false, "pattern is a pack-ID")
|
||||||
f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob)")
|
f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob or --tree)")
|
||||||
f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern")
|
f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern")
|
||||||
f.BoolVarP(&findOptions.ListLong, "long", "l", false, "use a long listing format showing size and mode")
|
f.BoolVarP(&findOptions.ListLong, "long", "l", false, "use a long listing format showing size and mode")
|
||||||
|
|
||||||
|
@ -450,28 +450,37 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Finder) findBlobsPacks(ctx context.Context) {
|
func (f *Finder) findObjectPack(ctx context.Context, id string, t restic.BlobType) {
|
||||||
idx := f.repo.Index()
|
idx := f.repo.Index()
|
||||||
for i := range f.blobIDs {
|
|
||||||
rid, err := restic.ParseID(i)
|
rid, err := restic.ParseID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Printf("Note: cannot find pack for blob '%s', unable to parse ID: %v\n", i, err)
|
Printf("Note: cannot find pack for object '%s', unable to parse ID: %v\n", id, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blobs, found := idx.Lookup(rid, restic.DataBlob)
|
blobs, found := idx.Lookup(rid, t)
|
||||||
if !found {
|
if !found {
|
||||||
Printf("Blob %s not found in the index\n", rid.Str())
|
Printf("Object %s not found in the index\n", rid.Str())
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range blobs {
|
for _, b := range blobs {
|
||||||
if b.ID.Equal(rid) {
|
if b.ID.Equal(rid) {
|
||||||
Printf("Blob belongs to pack %s\n ... Pack %s: %s\n", b.PackID, b.PackID.Str(), b.String())
|
Printf("Object belongs to pack %s\n ... Pack %s: %s\n", b.PackID, b.PackID.Str(), b.String())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Finder) findObjectsPacks(ctx context.Context) {
|
||||||
|
for i := range f.blobIDs {
|
||||||
|
f.findObjectPack(ctx, i, restic.DataBlob)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range f.treeIDs {
|
||||||
|
f.findObjectPack(ctx, i, restic.TreeBlob)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
||||||
|
@ -565,8 +574,8 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
|
||||||
}
|
}
|
||||||
f.out.Finish()
|
f.out.Finish()
|
||||||
|
|
||||||
if opts.ShowPackID && f.blobIDs != nil {
|
if opts.ShowPackID && (f.blobIDs != nil || f.treeIDs != nil) {
|
||||||
f.findBlobsPacks(ctx)
|
f.findObjectsPacks(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue