fileMapFromDuplicate queries the server's search interface for an existing file with an entire contents matching 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 neces
(ctx context.Context, bs blobserver.StatReceiver, fileMap *schema.Builder, wholeRef []blob.Ref)
| 508 | // exist, ok is false. |
| 509 | // If required, Vivify is also done here. |
| 510 | func (up *Uploader) fileMapFromDuplicate(ctx context.Context, bs blobserver.StatReceiver, fileMap *schema.Builder, wholeRef []blob.Ref) (pr *client.PutResult, ok bool) { |
| 511 | if noDupSearch { |
| 512 | return |
| 513 | } |
| 514 | _, err := up.Client.SearchRoot() |
| 515 | if err != nil { |
| 516 | return |
| 517 | } |
| 518 | dupFileRef, err := up.Client.SearchExistingFileSchema(ctx, wholeRef...) |
| 519 | if err != nil { |
| 520 | log.Printf("Warning: error searching for already-uploaded copy of %v: %v", wholeRef, err) |
| 521 | return nil, false |
| 522 | } |
| 523 | if !dupFileRef.Valid() { |
| 524 | return nil, false |
| 525 | } |
| 526 | cmdmain.Logf("Found dup of contents %s in file schema %s", wholeRef, dupFileRef) |
| 527 | dupMap, err := up.Client.FetchSchemaBlob(ctx, dupFileRef) |
| 528 | if err != nil { |
| 529 | log.Printf("Warning: error fetching %v: %v", dupFileRef, err) |
| 530 | return nil, false |
| 531 | } |
| 532 | |
| 533 | fileMap.PopulateParts(dupMap.PartsSize(), dupMap.ByteParts()) |
| 534 | |
| 535 | json, err := fileMap.JSON() |
| 536 | if err != nil { |
| 537 | return nil, false |
| 538 | } |
| 539 | uh := client.NewUploadHandleFromString(json) |
| 540 | if up.fileOpts.wantVivify() { |
| 541 | uh.Vivify = true |
| 542 | } |
| 543 | if !uh.Vivify && uh.BlobRef == dupFileRef { |
| 544 | // Unchanged (same filename, modtime, JSON serialization, etc) |
| 545 | // Different signer (e.g. existing file has a sha1 signer, and we're now using a |
| 546 | // sha224 signer) means we upload a new file schema. |
| 547 | return &client.PutResult{BlobRef: dupFileRef, Size: uint32(len(json)), Skipped: true}, true |
| 548 | } |
| 549 | pr, err = up.Upload(ctx, uh) |
| 550 | if err != nil { |
| 551 | log.Printf("Warning: error uploading file map after finding server dup of %v: %v", wholeRef, err) |
| 552 | return nil, false |
| 553 | } |
| 554 | return pr, true |
| 555 | } |
| 556 | |
| 557 | func (up *Uploader) uploadNodeRegularFile(ctx context.Context, n *node) (*client.PutResult, error) { |
| 558 | var filebb *schema.Builder |
no test coverage detected