MCPcopy Index your code
hub / github.com/perkeep/perkeep / RunCommand

Method RunCommand

cmd/pk/packblobs.go:57–112  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

55}
56
57func (c *packBlobsCmd) RunCommand(args []string) error {
58 if len(args) != 0 {
59 return cmdmain.UsageError("doesn't take arguments")
60 }
61 req := &search.SearchQuery{
62 Limit: -1,
63 Sort: search.BlobRefAsc,
64 Constraint: &search.Constraint{
65 File: &search.FileConstraint{
66 FileSize: &search.IntConstraint{
67 Min: 512 << 10,
68 },
69 },
70 },
71 }
72 cl := newClient(c.server)
73 looseClient, err := cl.NewPathClient("/bs-loose/")
74 if err != nil {
75 return fmt.Errorf("NewPathClient: %v", err)
76 }
77
78 res, err := cl.Query(ctxbg, req)
79 if err != nil {
80 return err
81 }
82 total := len(res.Blobs)
83 n := 0
84 var buf bytes.Buffer
85 for _, sr := range res.Blobs {
86 n++
87 fileRef := sr.Blob
88 rc, _, err := looseClient.Fetch(ctxbg, fileRef)
89 if err == os.ErrNotExist {
90 fmt.Printf("%d/%d: %v already done\n", n, total, fileRef)
91 continue
92 }
93 if err != nil {
94 log.Printf("error fetching %v: %v\n", fileRef, err)
95 continue
96 }
97 buf.Reset()
98 _, err = io.Copy(&buf, rc)
99 rc.Close()
100 if err != nil {
101 log.Printf("error reading %v: %v\n", fileRef, err)
102 continue
103 }
104 _, err = cl.ReceiveBlob(ctxbg, fileRef, &buf)
105 if err != nil {
106 log.Printf("error write %v: %v\n", fileRef, err)
107 continue
108 }
109 fmt.Printf("%d/%d: %v\n", n, total, fileRef)
110 }
111 return nil
112}

Callers

nothing calls this directly

Calls 8

UsageErrorTypeAlias · 0.92
NewPathClientMethod · 0.80
PrintfMethod · 0.80
newClientFunction · 0.70
QueryMethod · 0.65
FetchMethod · 0.65
CloseMethod · 0.65
ReceiveBlobMethod · 0.65

Tested by

no test coverage detected