MCPcopy
hub / github.com/rclone/rclone / Update

Method Update

backend/cache/object.go:249–285  ·  view source on GitHub ↗

Update will change the object data

(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

247
248// Update will change the object data
249func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
250 if err := o.refreshFromSource(ctx, false); err != nil {
251 return err
252 }
253 // pause background uploads if active
254 if o.CacheFs.opt.TempWritePath != "" {
255 o.CacheFs.backgroundRunner.pause()
256 defer o.CacheFs.backgroundRunner.play()
257 // don't allow started uploads
258 if o.isTempFile() && o.tempFileStartedUpload() {
259 return fmt.Errorf("%v is currently uploading, can't update", o)
260 }
261 }
262 fs.Debugf(o, "updating object contents with size %v", src.Size())
263
264 // FIXME use reliable upload
265 err := o.Object.Update(ctx, in, src, options...)
266 if err != nil {
267 fs.Errorf(o, "error updating source: %v", err)
268 return err
269 }
270
271 // deleting cached chunks and info to be replaced with new ones
272 _ = o.CacheFs.cache.RemoveObject(o.abs())
273 // advertise to ChangeNotify if wrapped doesn't do that
274 o.CacheFs.notifyChangeUpstreamIfNeeded(o.Remote(), fs.EntryObject)
275
276 o.CacheModTime = src.ModTime(ctx).UnixNano()
277 o.CacheSize = src.Size()
278 o.cacheHashesMu.Lock()
279 o.CacheHashes = make(map[hash.Type]string)
280 o.cacheHashesMu.Unlock()
281 o.CacheTs = time.Now()
282 o.persist()
283
284 return nil
285}
286
287// Remove deletes the object from both the cache and the source
288func (o *Object) Remove(ctx context.Context) error {

Callers 3

updateObjectRemoteMethod · 0.95
updateDataMethod · 0.95

Calls 15

refreshFromSourceMethod · 0.95
isTempFileMethod · 0.95
tempFileStartedUploadMethod · 0.95
absMethod · 0.95
RemoteMethod · 0.95
persistMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
pauseMethod · 0.80
playMethod · 0.80
RemoveObjectMethod · 0.80

Tested by 3

updateObjectRemoteMethod · 0.76
updateDataMethod · 0.76