(ctx interface{}, t *Transfer, cb ProgressCallback, authOkFunc func())
| 42 | } |
| 43 | |
| 44 | func (a *basicUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb ProgressCallback, authOkFunc func()) error { |
| 45 | rel, err := t.Rel("upload") |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | if rel == nil { |
| 50 | return errors.New(tr.Tr.Get("No upload action for object: %s", t.Oid)) |
| 51 | } |
| 52 | |
| 53 | req, err := a.newHTTPRequest("PUT", rel) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | if req.Header.Get("Transfer-Encoding") == "chunked" { |
| 59 | req.TransferEncoding = []string{"chunked"} |
| 60 | } else { |
| 61 | req.Header.Set("Content-Length", strconv.FormatInt(t.Size, 10)) |
| 62 | } |
| 63 | |
| 64 | req.ContentLength = t.Size |
| 65 | |
| 66 | f, err := os.OpenFile(t.Path, os.O_RDONLY, 0644) |
| 67 | if err != nil { |
| 68 | return errors.Wrap(err, tr.Tr.Get("basic upload")) |
| 69 | } |
| 70 | defer f.Close() |
| 71 | |
| 72 | if err := a.setContentTypeFor(req, f); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | // Ensure progress callbacks made while uploading |
| 77 | // Wrap callback to give name context |
| 78 | ccb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 79 | if cb != nil { |
| 80 | return cb(t.Name, totalSize, readSoFar, readSinceLast) |
| 81 | } |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | cbr := tools.NewFileBodyWithCallback(f, t.Size, ccb) |
| 86 | var reader lfsapi.ReadSeekCloser = cbr |
| 87 | |
| 88 | // Signal auth was ok on first read; this frees up other workers to start |
| 89 | if authOkFunc != nil { |
| 90 | reader = newStartCallbackReader(reader, func() error { |
| 91 | authOkFunc() |
| 92 | return nil |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | req.Body = reader |
| 97 | |
| 98 | req = a.apiClient.LogRequest(req, "lfs.data.upload") |
| 99 | res, err := a.makeRequest(t, req) |
| 100 | if err != nil { |
| 101 | if errors.IsUnprocessableEntityError(err) { |
nothing calls this directly
no test coverage detected