From 61b368ddead8f764504a3ef1e0749ff5bc2aba4b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 2 Aug 2020 12:17:23 +0200 Subject: [PATCH] cat: only load index if really necessary --- cmd/restic/cmd_cat.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index a9ee82d8c..8d31fa257 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -69,7 +69,6 @@ func runCat(gopts GlobalOptions, args []string) error { } } - // handle all types that don't need an index switch tpe { case "config": buf, err := json.MarshalIndent(repo.Config(), "", " ") @@ -142,15 +141,7 @@ func runCat(gopts GlobalOptions, args []string) error { Println(string(buf)) return nil - } - // load index, handle all the other types - err = repo.LoadIndex(gopts.ctx) - if err != nil { - return err - } - - switch tpe { case "pack": h := restic.Handle{Type: restic.PackFile, Name: id.String()} buf, err := backend.LoadAll(gopts.ctx, nil, repo.Backend(), h) @@ -167,6 +158,11 @@ func runCat(gopts GlobalOptions, args []string) error { return err case "blob": + err = repo.LoadIndex(gopts.ctx) + if err != nil { + return err + } + for _, t := range []restic.BlobType{restic.DataBlob, restic.TreeBlob} { bh := restic.BlobHandle{ID: id, Type: t} if !repo.Index().Has(bh) {