MCPcopy
hub / github.com/perkeep/perkeep / doStat

Method doStat

pkg/client/upload.go:186–234  ·  view source on GitHub ↗

doStat does an HTTP request for the stat. the number of blobs is used verbatim. No extra splitting or batching is done at this layer. The semantics are the same as blobserver.BlobStatter. gate controls whether it uses httpGate to pause on requests.

(ctx context.Context, blobs []blob.Ref, wait time.Duration, gated bool, fn func(blob.SizedRef) error)

Source from the content-addressed store, hash-verified

184// The semantics are the same as blobserver.BlobStatter.
185// gate controls whether it uses httpGate to pause on requests.
186func (c *Client) doStat(ctx context.Context, blobs []blob.Ref, wait time.Duration, gated bool, fn func(blob.SizedRef) error) error {
187 var buf bytes.Buffer
188 fmt.Fprintf(&buf, "camliversion=1")
189 if wait > 0 {
190 secs := int(wait.Seconds())
191 if secs == 0 {
192 secs = 1
193 }
194 fmt.Fprintf(&buf, "&maxwaitsec=%d", secs)
195 }
196 for i, blob := range blobs {
197 fmt.Fprintf(&buf, "&blob%d=%s", i+1, blob)
198 }
199
200 pfx, err := c.prefix()
201 if err != nil {
202 return err
203 }
204 req := c.newRequest(ctx, "POST", fmt.Sprintf("%s/camli/stat", pfx), &buf)
205 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
206
207 var resp *http.Response
208 if gated {
209 resp, err = c.doReqGated(req)
210 } else {
211 resp, err = c.httpClient.Do(req)
212 }
213 if err != nil {
214 return fmt.Errorf("stat HTTP error: %w", err)
215 }
216 if resp.Body != nil {
217 defer resp.Body.Close()
218 }
219
220 if resp.StatusCode != 200 {
221 return fmt.Errorf("stat response had http status %d", resp.StatusCode)
222 }
223
224 stat, err := parseStatResponse(resp)
225 if err != nil {
226 return err
227 }
228 for _, sb := range stat.HaveMap {
229 if err := fn(sb); err != nil {
230 return err
231 }
232 }
233 return nil
234}
235
236// Figure out the size of the contents.
237// If the size was provided, trust it.

Callers 1

StatBlobsMethod · 0.95

Calls 6

prefixMethod · 0.95
newRequestMethod · 0.95
doReqGatedMethod · 0.95
parseStatResponseFunction · 0.85
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected