Update will change the object data
(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)
| 247 | |
| 248 | // Update will change the object data |
| 249 | func (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 |
| 288 | func (o *Object) Remove(ctx context.Context) error { |