Update in to the object with the modTime given of the given size When called from outside an Fs by rclone, src.Size() will always be >= 0. But for unknown-sized objects (indicated by src.Size() == -1), Upload should either return an error or update the object properly (rather than e.g. calling pani
(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)
| 67 | // But for unknown-sized objects (indicated by src.Size() == -1), Upload should either |
| 68 | // return an error or update the object properly (rather than e.g. calling panic). |
| 69 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error { |
| 70 | entries, err := o.fs.actionEntries(o.candidates()...) |
| 71 | if err == fs.ErrorPermissionDenied { |
| 72 | // There are no candidates in this object which can be written to |
| 73 | // So attempt to create a new object instead |
| 74 | newO, err := o.fs.put(ctx, in, src, false, options...) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | // Update current object |
| 79 | o.update(newO.(*Object)) |
| 80 | return nil |
| 81 | } else if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | if len(entries) == 1 { |
| 85 | obj := entries[0].(*upstream.Object) |
| 86 | return obj.Update(ctx, in, src, options...) |
| 87 | } |
| 88 | // Multi-threading |
| 89 | readers, errChan := multiReader(len(entries), in) |
| 90 | errs := Errors(make([]error, len(entries)+1)) |
| 91 | multithread(len(entries), func(i int) { |
| 92 | if o, ok := entries[i].(*upstream.Object); ok { |
| 93 | err := o.Update(ctx, readers[i], src, options...) |
| 94 | if err != nil { |
| 95 | errs[i] = fmt.Errorf("%s: %w", o.UpstreamFs().Name(), err) |
| 96 | if len(entries) > 1 { |
| 97 | // Drain the input buffer to allow other uploads to continue |
| 98 | _, _ = io.Copy(io.Discard, readers[i]) |
| 99 | } |
| 100 | } |
| 101 | } else { |
| 102 | errs[i] = fs.ErrorNotAFile |
| 103 | } |
| 104 | }) |
| 105 | errs[len(entries)] = <-errChan |
| 106 | return errs.Err() |
| 107 | } |
| 108 | |
| 109 | // Remove candidate objects selected by ACTION policy |
| 110 | func (o *Object) Remove(ctx context.Context) error { |