Remove deletes the object from both the cache and the source
(ctx context.Context)
| 286 | |
| 287 | // Remove deletes the object from both the cache and the source |
| 288 | func (o *Object) Remove(ctx context.Context) error { |
| 289 | if err := o.refreshFromSource(ctx, false); err != nil { |
| 290 | return err |
| 291 | } |
| 292 | // pause background uploads if active |
| 293 | if o.CacheFs.opt.TempWritePath != "" { |
| 294 | o.CacheFs.backgroundRunner.pause() |
| 295 | defer o.CacheFs.backgroundRunner.play() |
| 296 | // don't allow started uploads |
| 297 | if o.isTempFile() && o.tempFileStartedUpload() { |
| 298 | return fmt.Errorf("%v is currently uploading, can't delete", o) |
| 299 | } |
| 300 | } |
| 301 | err := o.Object.Remove(ctx) |
| 302 | if err != nil { |
| 303 | return err |
| 304 | } |
| 305 | |
| 306 | fs.Debugf(o, "removing object") |
| 307 | _ = o.CacheFs.cache.RemoveObject(o.abs()) |
| 308 | _ = o.CacheFs.cache.removePendingUpload(o.abs()) |
| 309 | parentCd := NewDirectory(o.CacheFs, cleanPath(path.Dir(o.Remote()))) |
| 310 | _ = o.CacheFs.cache.ExpireDir(parentCd) |
| 311 | // advertise to ChangeNotify if wrapped doesn't do that |
| 312 | o.CacheFs.notifyChangeUpstreamIfNeeded(parentCd.Remote(), fs.EntryDirectory) |
| 313 | |
| 314 | return nil |
| 315 | } |
| 316 | |
| 317 | // Hash requests a hash of the object and stores in the cache |
| 318 | // since it might or might not be called, this is lazy loaded |