(ctx context.Context, n *node)
| 555 | } |
| 556 | |
| 557 | func (up *Uploader) uploadNodeRegularFile(ctx context.Context, n *node) (*client.PutResult, error) { |
| 558 | var filebb *schema.Builder |
| 559 | if up.fileOpts.contentsOnly { |
| 560 | filebb = schema.NewFileMap("") |
| 561 | } else { |
| 562 | filebb = schema.NewCommonFileMap(n.fullPath, n.fi) |
| 563 | } |
| 564 | filebb.SetType("file") |
| 565 | |
| 566 | up.fdGate.Start() |
| 567 | defer up.fdGate.Done() |
| 568 | |
| 569 | file, err := up.open(n.fullPath) |
| 570 | if err != nil { |
| 571 | return nil, err |
| 572 | } |
| 573 | defer file.Close() |
| 574 | if !up.fileOpts.contentsOnly { |
| 575 | if up.fileOpts.exifTime { |
| 576 | modtime, err := schema.FileTime(file) |
| 577 | if err != nil { |
| 578 | cmdmain.Logf("warning: getting time from EXIF failed for %v: %v", n.fullPath, err) |
| 579 | } else { |
| 580 | filebb.SetModTime(modtime) |
| 581 | } |
| 582 | } |
| 583 | if up.fileOpts.wantCapCtime() { |
| 584 | filebb.CapCreationTime() |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | var ( |
| 589 | size = n.fi.Size() |
| 590 | fileContents io.Reader = io.LimitReader(file, size) |
| 591 | br blob.Ref // of file schemaref |
| 592 | wholeRef []blob.Ref // wholeRef[1], if any, is the legacy sha1 version of the contents. |
| 593 | pr *client.PutResult // of the final "file" schema blob |
| 594 | ) |
| 595 | |
| 596 | const dupCheckThreshold = 256 << 10 |
| 597 | if size > dupCheckThreshold { |
| 598 | var err error |
| 599 | hasLegacySHA1, err := up.Client.HasLegacySHA1() |
| 600 | if err != nil { |
| 601 | log.Printf("Cannot discover if server has legacy sha1: %v", err) |
| 602 | } else { |
| 603 | up.doLegacySHA1 = hasLegacySHA1 |
| 604 | } |
| 605 | wholeRef, err = up.wholeFileDigest(n.fullPath) |
| 606 | if err == nil { |
| 607 | ok := false |
| 608 | pr, ok = up.fileMapFromDuplicate(ctx, up.statReceiver(n), filebb, wholeRef) |
| 609 | if ok { |
| 610 | br = pr.BlobRef |
| 611 | android.NoteFileUploaded(n.fullPath, !pr.Skipped) |
| 612 | if up.fileOpts.wantVivify() { |
| 613 | // we can return early in that case, because the other options |
| 614 | // are disallowed in the vivify case. |
no test coverage detected