MCPcopy
hub / github.com/perkeep/perkeep / fileMapFromDuplicate

Method fileMapFromDuplicate

pkg/client/upload.go:514–544  ·  view source on GitHub ↗

fileMapFromDuplicate queries the server's search interface for an existing file blob for the file contents any of wholeRef. If the server has it, it's validated, and then fileMap (which must already be partially populated) has its "parts" field populated, and then fileMap is uploaded (if necessary).

(ctx context.Context, fileMap *schema.Builder, wholeRef []blob.Ref)

Source from the content-addressed store, hash-verified

512// and then fileMap is uploaded (if necessary).
513// If no file blob is found, a zero blob.Ref (and no error) is returned.
514func (c *Client) fileMapFromDuplicate(ctx context.Context, fileMap *schema.Builder, wholeRef []blob.Ref) (blob.Ref, error) {
515 dupFileRef, err := c.SearchExistingFileSchema(ctx, wholeRef...)
516 if err != nil {
517 return blob.Ref{}, err
518 }
519 if !dupFileRef.Valid() {
520 // because SearchExistingFileSchema returns blob.Ref{}, nil when file is not found.
521 return blob.Ref{}, nil
522 }
523 dupMap, err := c.FetchSchemaBlob(ctx, dupFileRef)
524 if err != nil {
525 return blob.Ref{}, fmt.Errorf("could not find existing file blob for wholeRef %q: %v", wholeRef, err)
526 }
527 fileMap.PopulateParts(dupMap.PartsSize(), dupMap.ByteParts())
528 json, err := fileMap.JSON()
529 if err != nil {
530 return blob.Ref{}, fmt.Errorf("could not write file map for wholeRef %q: %v", wholeRef, err)
531 }
532 bref := blob.RefFromString(json)
533 if bref == dupFileRef {
534 // Unchanged (same filename, modtime, JSON serialization, etc)
535 // Different signer (e.g. existing file has a sha1 signer, and
536 // we're now using a sha224 signer) means we upload a new file schema.
537 return dupFileRef, nil
538 }
539 sbr, err := c.ReceiveBlob(ctx, bref, strings.NewReader(json))
540 if err != nil {
541 return blob.Ref{}, err
542 }
543 return sbr.Ref, nil
544}

Callers 1

UploadFileMethod · 0.95

Calls 9

FetchSchemaBlobMethod · 0.95
ReceiveBlobMethod · 0.95
RefFromStringFunction · 0.92
PopulatePartsMethod · 0.80
BytePartsMethod · 0.80
ValidMethod · 0.45
PartsSizeMethod · 0.45
JSONMethod · 0.45

Tested by

no test coverage detected