Update an object if it has changed
(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)
| 387 | |
| 388 | // Update an object if it has changed |
| 389 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) { |
| 390 | bucketName, _ := o.split() |
| 391 | err = o.fs.makeBucket(ctx, bucketName) |
| 392 | if err != nil { |
| 393 | return err |
| 394 | } |
| 395 | |
| 396 | // determine if we like upload single or multipart. |
| 397 | size := src.Size() |
| 398 | multipart := size < 0 || size >= int64(o.fs.opt.UploadCutoff) |
| 399 | if isZeroLength(in) { |
| 400 | multipart = false |
| 401 | } |
| 402 | if multipart { |
| 403 | err = o.uploadMultipart(ctx, src, in, options...) |
| 404 | if err != nil { |
| 405 | return err |
| 406 | } |
| 407 | } else { |
| 408 | ui, err := o.prepareUpload(ctx, src, options) |
| 409 | if err != nil { |
| 410 | return fmt.Errorf("failed to prepare upload: %w", err) |
| 411 | } |
| 412 | var resp objectstorage.PutObjectResponse |
| 413 | err = o.fs.pacer.CallNoRetry(func() (bool, error) { |
| 414 | ui.req.PutObjectBody = io.NopCloser(in) |
| 415 | resp, err = o.fs.srv.PutObject(ctx, *ui.req) |
| 416 | return shouldRetry(ctx, resp.HTTPResponse(), err) |
| 417 | }) |
| 418 | if err != nil { |
| 419 | fs.Errorf(o, "put object failed %v", err) |
| 420 | return err |
| 421 | } |
| 422 | } |
| 423 | // Read the metadata from the newly created object |
| 424 | o.meta = nil // wipe old metadata |
| 425 | return o.readMetaData(ctx) |
| 426 | } |
| 427 | |
| 428 | func (o *Object) applyPutOptions(req *objectstorage.PutObjectRequest, options ...fs.OpenOption) { |
| 429 | // Apply upload options |
no test coverage detected