| 71 | } |
| 72 | |
| 73 | func (c *listCmd) RunCommand(args []string) error { |
| 74 | c.describe = c.describe || c.camliType != "" |
| 75 | |
| 76 | if !c.describe { |
| 77 | return c.syncCmd.RunCommand(args) |
| 78 | } |
| 79 | |
| 80 | stdout := cmdmain.Stdout |
| 81 | defer func() { cmdmain.Stdout = stdout }() |
| 82 | pr, pw, err := os.Pipe() |
| 83 | if err != nil { |
| 84 | return fmt.Errorf("Could not create pipe to read from stdout: %v", err) |
| 85 | } |
| 86 | defer pr.Close() |
| 87 | cmdmain.Stdout = pw |
| 88 | |
| 89 | if err := c.setClient(); err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | scanner := bufio.NewScanner(pr) |
| 94 | go func() { |
| 95 | err := c.syncCmd.RunCommand(args) |
| 96 | if err != nil { |
| 97 | log.Printf("Error when enumerating source with sync: %v", err) |
| 98 | } |
| 99 | pw.Close() |
| 100 | }() |
| 101 | |
| 102 | blobRefs := make([]blob.Ref, 0, describeBatchSize) |
| 103 | describe := func() error { |
| 104 | if len(blobRefs) == 0 { |
| 105 | return nil |
| 106 | } |
| 107 | // TODO(mpl): setting depth to 1, not 0, because otherwise r.depth() in pkg/search/handler.go defaults to 4. Can't remember why we disallowed 0 right now, and I do not want to change that in pkg/search/handler.go and risk breaking things. |
| 108 | described, err := c.cl.Describe(context.Background(), &search.DescribeRequest{ |
| 109 | BlobRefs: blobRefs, |
| 110 | Depth: 1, |
| 111 | }) |
| 112 | if err != nil { |
| 113 | return fmt.Errorf("Error when describing blobs %v: %v", blobRefs, err) |
| 114 | } |
| 115 | for _, v := range blobRefs { |
| 116 | blob, ok := described.Meta[v.String()] |
| 117 | if !ok { |
| 118 | // This can happen if the index is out of sync with the storage we enum from. |
| 119 | fmt.Fprintf(stdout, "%v <not described>\n", v) |
| 120 | continue |
| 121 | } |
| 122 | |
| 123 | if c.camliType == "" || string(blob.CamliType) == c.camliType { |
| 124 | detailed := detail(blob) |
| 125 | if detailed != "" { |
| 126 | detailed = fmt.Sprintf("\t%v", detailed) |
| 127 | } |
| 128 | fmt.Fprintf(stdout, "%v %v%v\n", v, blob.Size, detailed) |
| 129 | } |
| 130 | } |