From 73526917a1f5b05a40c46da59fc0c4a75423b594 Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 7 Mar 2014 16:22:46 +0100 Subject: [PATCH] camtool list/sync: fix 3 bugs 1) revert to printing to stdout (broke in 08923e1c00a52a0d9caa7693b375b42789fed052) for actual output 2) do not warn about different identities when "syncing" to stdout 3) check blob was actually described before using its fields Change-Id: Ibb3aa4c560e1b0036aba080807400e8820163cc9 --- cmd/camtool/list.go | 13 +++++++++---- cmd/camtool/sync.go | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/camtool/list.go b/cmd/camtool/list.go index e464a1a07..b159a1d9c 100644 --- a/cmd/camtool/list.go +++ b/cmd/camtool/list.go @@ -71,14 +71,14 @@ func (c *listCmd) RunCommand(args []string) error { return c.syncCmd.RunCommand(args) } - stdout := os.Stdout - defer func() { os.Stdout = stdout }() + stdout := cmdmain.Stdout + defer func() { cmdmain.Stdout = stdout }() pr, pw, err := os.Pipe() if err != nil { return fmt.Errorf("Could not create pipe to read from stdout: %v", err) } defer pr.Close() - os.Stdout = pw + cmdmain.Stdout = pw if err := c.setClient(); err != nil { return err @@ -107,7 +107,12 @@ func (c *listCmd) RunCommand(args []string) error { return fmt.Errorf("Error when describing blobs %v: %v", blobRefs, err) } for _, v := range blobRefs { - blob := described.Meta[v.String()] + blob, ok := described.Meta[v.String()] + if !ok { + // This can happen if the index is out of sync with the storage we enum from. + fmt.Fprintf(stdout, "%v \n", v) + continue + } detailed := detail(blob) if detailed != "" { detailed = fmt.Sprintf("\t%v", detailed) diff --git a/cmd/camtool/sync.go b/cmd/camtool/sync.go index 78692dfb8..ed84f10cd 100644 --- a/cmd/camtool/sync.go +++ b/cmd/camtool/sync.go @@ -117,7 +117,7 @@ func (c *syncCmd) RunCommand(args []string) error { differentKeyIDs := fmt.Sprintf("WARNING: the source server GPG key ID (%v) and the destination's (%v) differ. All blobs will be synced, but because the indexer at the other side is indexing claims by a different user, you may not see what you expect in that server's web UI, etc.", c.srcKeyID, c.destKeyID) - if c.srcKeyID != c.destKeyID { // both blank is ok. + if c.dest != "stdout" && c.srcKeyID != c.destKeyID { // both blank is ok. // Warn at the top (and hope the user sees it and can abort if it was a mistake): fmt.Fprintln(cmdmain.Stderr, differentKeyIDs) // Warn also at the end (in case the user missed the first one) @@ -325,7 +325,7 @@ func (c *syncCmd) doPass(src, dest, thirdLeg blobserver.Storage) (stats SyncStat if c.dest == "stdout" { for sb := range srcBlobs { - fmt.Fprintf(cmdmain.Stderr, "%s %d\n", sb.Ref, sb.Size) + fmt.Fprintf(cmdmain.Stdout, "%s %d\n", sb.Ref, sb.Size) } checkSourceError() return @@ -385,7 +385,7 @@ func (c *syncCmd) doPass(src, dest, thirdLeg blobserver.Storage) (stats SyncStat } for sb := range syncBlobs { - fmt.Fprintf(cmdmain.Stderr, "Destination needs blob: %s\n", sb) + fmt.Fprintf(cmdmain.Stdout, "Destination needs blob: %s\n", sb) blobReader, size, err := src.FetchStreaming(sb.Ref) if err != nil {