MCPcopy
hub / github.com/perkeep/perkeep / UpdateShareChain

Method UpdateShareChain

pkg/client/get.go:165–190  ·  view source on GitHub ↗

UpdateShareChain reads the schema of b from r, and instructs the client that all blob refs found in this schema should use b as a preceding chain link, in all subsequent shared blobs fetches. If the client was not created with NewFromShareRoot, ErrNotSharing is returned.

(b blob.Ref, r io.Reader)

Source from the content-addressed store, hash-verified

163// all subsequent shared blobs fetches. If the client was not created with
164// NewFromShareRoot, ErrNotSharing is returned.
165func (c *Client) UpdateShareChain(b blob.Ref, r io.Reader) error {
166 c.viaMu.Lock()
167 defer c.viaMu.Unlock()
168 if c.via == nil {
169 // Not in sharing mode, so return immediately.
170 return ErrNotSharing
171 }
172 // Slurp 1 MB to find references to other blobrefs for the via path.
173 var buf bytes.Buffer
174 const maxSlurp = 1 << 20
175 if _, err := io.Copy(&buf, io.LimitReader(r, maxSlurp)); err != nil {
176 return err
177 }
178 // If it looks like a JSON schema blob (starts with '{')
179 if schema.LikelySchemaBlob(buf.Bytes()) {
180 for _, blobstr := range blobsRx.FindAllString(buf.String(), -1) {
181 br, ok := blob.Parse(blobstr)
182 if !ok {
183 c.printf("Invalid blob ref %q noticed in schema of %v", blobstr, b)
184 continue
185 }
186 c.via[br] = b
187 }
188 }
189 return nil
190}
191
192func (c *Client) ReceiveBlob(ctx context.Context, br blob.Ref, source io.Reader) (blob.SizedRef, error) {
193 if c.sto != nil {

Callers 2

fetchViaMethod · 0.95
mainFunction · 0.95

Calls 6

printfMethod · 0.95
LikelySchemaBlobFunction · 0.92
ParseFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected