MCPcopy
hub / github.com/perkeep/perkeep / FileHasContents

Method FileHasContents

pkg/client/client.go:913–928  ·  view source on GitHub ↗

FileHasContents returns true iff f refers to a "file" or "bytes" schema blob, the server is configured with a "download helper", and the server responds that all chunks of 'f' are available and match the digest of wholeRef.

(ctx context.Context, f, wholeRef blob.Ref)

Source from the content-addressed store, hash-verified

911// the server is configured with a "download helper", and the server responds
912// that all chunks of 'f' are available and match the digest of wholeRef.
913func (c *Client) FileHasContents(ctx context.Context, f, wholeRef blob.Ref) bool {
914 if err := c.condDiscovery(); err != nil {
915 return false
916 }
917 if c.downloadHelper == "" {
918 return false
919 }
920 req := c.newRequest(ctx, "HEAD", c.downloadHelper+f.String()+"/?verifycontents="+wholeRef.String())
921 res, err := c.expect2XX(req)
922 if err != nil {
923 log.Printf("download helper HEAD error: %v", err)
924 return false
925 }
926 defer res.Body.Close()
927 return res.Header.Get("X-Camli-Contents") == wholeRef.String()
928}
929
930// prefix returns the URL prefix before "/camli/", or before
931// the blobref hash in case of a share URL.

Callers 1

Calls 7

condDiscoveryMethod · 0.95
newRequestMethod · 0.95
expect2XXMethod · 0.95
PrintfMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected