MCPcopy
hub / github.com/perkeep/perkeep / populateMutationMap

Method populateMutationMap

pkg/index/receive.go:358–388  ·  view source on GitHub ↗

populateMutationMap populates keys & values that will be committed into the returned map. the blobref can be trusted at this point (it's been fully consumed and verified to match), and the sniffer has been populated.

(ctx context.Context, fetcher *missTrackFetcher, br blob.Ref, sniffer *BlobSniffer)

Source from the content-addressed store, hash-verified

356// the blobref can be trusted at this point (it's been fully consumed
357// and verified to match), and the sniffer has been populated.
358func (ix *Index) populateMutationMap(ctx context.Context, fetcher *missTrackFetcher, br blob.Ref, sniffer *BlobSniffer) (*mutationMap, error) {
359 mm := &mutationMap{
360 kv: map[string]string{
361 "meta:" + br.String(): fmt.Sprintf("%d|%s", sniffer.Size(), sniffer.MIMEType()),
362 },
363 }
364 var err error
365 if schemaBlob, ok := sniffer.SchemaBlob(); ok {
366 err = ix.populateMutationMapForSchema(ctx, fetcher, schemaBlob, mm)
367 }
368
369 if err != nil && err != errMissingDep {
370 return nil, err
371 }
372 var haveVal string
373 if err == errMissingDep {
374 haveVal = fmt.Sprintf("%d", sniffer.Size())
375 } else {
376 haveVal = fmt.Sprintf("%d|indexed", sniffer.Size())
377 }
378 mm.kv["have:"+br.String()] = haveVal
379 if len(fetcher.missing) == 0 {
380 // If err == nil, we're good. Else (err == errMissingDep), we
381 // know the error did not come from a fetching miss (because
382 // len(fetcher.missing) == 0) , but from an index miss. Therefore
383 // we know the miss has already been noted and will be dealt with
384 // later, so we can also pretend everything's fine.
385 return mm, nil
386 }
387 return mm, err
388}
389
390// keepFirstN keeps the first N bytes written to it in Bytes.
391type keepFirstN struct {

Callers 1

ReceiveBlobMethod · 0.95

Calls 5

MIMETypeMethod · 0.80
SchemaBlobMethod · 0.80
SizeMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected