From 08bf3bae79fd8cc30ec1d6f884c3650d9b2d5474 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 2 Apr 2020 22:45:20 +0200 Subject: [PATCH 1/3] debug: explicitly pass stdout to dump functions --- cmd/restic/cmd_debug.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 8e7bdfb8e..59e6ba07d 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -107,13 +107,11 @@ func printPacks(repo *repository.Repository, wr io.Writer) error { } } - return prettyPrintJSON(os.Stdout, p) + return prettyPrintJSON(wr, p) }) - - return nil } -func dumpIndexes(repo restic.Repository) error { +func dumpIndexes(repo restic.Repository, wr io.Writer) error { return repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error { fmt.Printf("index_id: %v\n", id) @@ -122,7 +120,7 @@ func dumpIndexes(repo restic.Repository) error { return err } - return idx.Dump(os.Stdout) + return idx.Dump(wr) }) } @@ -153,7 +151,7 @@ func runDebugDump(gopts GlobalOptions, args []string) error { switch tpe { case "indexes": - return dumpIndexes(repo) + return dumpIndexes(repo, os.Stdout) case "snapshots": return debugPrintSnapshots(repo, os.Stdout) case "packs": @@ -166,7 +164,7 @@ func runDebugDump(gopts GlobalOptions, args []string) error { } fmt.Printf("\nindexes:\n") - err = dumpIndexes(repo) + err = dumpIndexes(repo, os.Stdout) if err != nil { return err } From 7aa2f8a61ebbf07570c4528cd236ea13e5cf3fc5 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 4 Apr 2020 00:00:21 +0200 Subject: [PATCH 2/3] debug: get stdout/stderr from gopts/globalOptions --- cmd/restic/cmd_debug.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 59e6ba07d..12c44dd19 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "os" "github.com/spf13/cobra" @@ -90,7 +89,7 @@ func printPacks(repo *repository.Repository, wr io.Writer) error { blobs, err := pack.List(repo.Key(), restic.ReaderAt(repo.Backend(), h), size) if err != nil { - fmt.Fprintf(os.Stderr, "error for pack %v: %v\n", id.Str(), err) + fmt.Fprintf(globalOptions.stderr, "error for pack %v: %v\n", id.Str(), err) return nil } @@ -151,20 +150,20 @@ func runDebugDump(gopts GlobalOptions, args []string) error { switch tpe { case "indexes": - return dumpIndexes(repo, os.Stdout) + return dumpIndexes(repo, gopts.stdout) case "snapshots": - return debugPrintSnapshots(repo, os.Stdout) + return debugPrintSnapshots(repo, gopts.stdout) case "packs": - return printPacks(repo, os.Stdout) + return printPacks(repo, gopts.stdout) case "all": fmt.Printf("snapshots:\n") - err := debugPrintSnapshots(repo, os.Stdout) + err := debugPrintSnapshots(repo, gopts.stdout) if err != nil { return err } fmt.Printf("\nindexes:\n") - err = dumpIndexes(repo, os.Stdout) + err = dumpIndexes(repo, gopts.stdout) if err != nil { return err } From fb842759fc53f335e0f588d3543ebccb341e3bb6 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 2 Apr 2020 22:50:08 +0200 Subject: [PATCH 3/3] debug: don't load the repository index The existing commands don't need a loaded repository index which can take several minutes to load on larger repositories. --- cmd/restic/cmd_debug.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 12c44dd19..bbba32cc3 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -141,11 +141,6 @@ func runDebugDump(gopts GlobalOptions, args []string) error { } } - err = repo.LoadIndex(gopts.ctx) - if err != nil { - return err - } - tpe := args[0] switch tpe {