(src, dst string, opts putOptions)
| 509 | } |
| 510 | |
| 511 | func putFileWithResult(src, dst string, opts putOptions) (putResult, error) { |
| 512 | ifExists, err := normalizePutIfExists(opts.ifExists) |
| 513 | if err != nil { |
| 514 | return putResult{}, err |
| 515 | } |
| 516 | |
| 517 | dbx := filesNewFunc(config) |
| 518 | action, existingMetadata, err := checkPutDestination(dbx, dst, ifExists) |
| 519 | if err != nil { |
| 520 | return putResult{}, err |
| 521 | } |
| 522 | if action == putDestinationSkip { |
| 523 | reportPutSkipped(opts, dst) |
| 524 | return newPutResult(putStatusSkipped, putKindFile, src, dst, existingMetadata) |
| 525 | } |
| 526 | |
| 527 | contents, err := os.Open(src) |
| 528 | if err != nil { |
| 529 | return putResult{}, err |
| 530 | } |
| 531 | defer contents.Close() |
| 532 | |
| 533 | contentsInfo, err := contents.Stat() |
| 534 | if err != nil { |
| 535 | return putResult{}, err |
| 536 | } |
| 537 | |
| 538 | commitInfo := files.NewCommitInfo(dst) |
| 539 | commitInfo.Mode.Tag = writeModeForIfExists(ifExists) |
| 540 | commitInfo.StrictConflict = ifExists != putIfExistsOverwrite |
| 541 | |
| 542 | commitInfo.ClientModified = dropboxClientModified(contentsInfo.ModTime()) |
| 543 | |
| 544 | if contentsInfo.Size() > singleShotUploadSizeCutoff { |
| 545 | metadata, err := uploadChunked(dbx, uploadProgressReader(contents, contentsInfo.Size(), putErrorOutput(opts)), commitInfo, contentsInfo.Size(), opts.workers, opts.chunkSize, opts.debug) |
| 546 | if err != nil && ifExists == putIfExistsSkip && isUploadDestinationFileConflict(err) { |
| 547 | reportPutSkipped(opts, dst) |
| 548 | return newPutResult(putStatusSkipped, putKindFile, src, dst, nil) |
| 549 | } |
| 550 | if err != nil { |
| 551 | return putResult{}, err |
| 552 | } |
| 553 | return newPutResult(putStatusUploaded, putKindFile, src, dst, metadata) |
| 554 | } |
| 555 | |
| 556 | uploadArg := &files.UploadArg{CommitInfo: *commitInfo} |
| 557 | metadata, err := uploadSingleShot(dbx, contents, uploadArg, contentsInfo.Size(), putErrorOutput(opts)) |
| 558 | if err != nil && ifExists == putIfExistsSkip && isUploadDestinationFileConflict(err) { |
| 559 | reportPutSkipped(opts, dst) |
| 560 | return newPutResult(putStatusSkipped, putKindFile, src, dst, nil) |
| 561 | } |
| 562 | if err != nil { |
| 563 | return putResult{}, err |
| 564 | } |
| 565 | return newPutResult(putStatusUploaded, putKindFile, src, dst, metadata) |
| 566 | } |
| 567 | |
| 568 | func writeModeForIfExists(ifExists string) string { |
no test coverage detected