MCPcopy
hub / github.com/rclone/rclone / RemoveDir

Method RemoveDir

backend/cache/storage_persistent.go:302–338  ·  view source on GitHub ↗

RemoveDir will delete a CachedDirectory, all its objects and all the chunks stored for it

(fp string)

Source from the content-addressed store, hash-verified

300
301// RemoveDir will delete a CachedDirectory, all its objects and all the chunks stored for it
302func (b *Persistent) RemoveDir(fp string) error {
303 var err error
304 parentDir, dirName := path.Split(fp)
305 if fp == "" {
306 err = b.db.Update(func(tx *bolt.Tx) error {
307 err := tx.DeleteBucket([]byte(RootBucket))
308 if err != nil {
309 fs.Debugf(fp, "couldn't delete from cache: %v", err)
310 return err
311 }
312 _, _ = tx.CreateBucketIfNotExists([]byte(RootBucket))
313 return nil
314 })
315 } else {
316 err = b.db.Update(func(tx *bolt.Tx) error {
317 bucket := b.getBucket(cleanPath(parentDir), false, tx)
318 if bucket == nil {
319 return fmt.Errorf("couldn't open bucket (%v)", fp)
320 }
321 // delete the cached dir
322 err := bucket.DeleteBucket([]byte(cleanPath(dirName)))
323 if err != nil {
324 fs.Debugf(fp, "couldn't delete from cache: %v", err)
325 }
326 return nil
327 })
328 }
329
330 // delete chunks on disk
331 // safe to ignore as the files might not have been open
332 if err == nil {
333 _ = os.RemoveAll(path.Join(b.dataPath, fp))
334 _ = os.MkdirAll(b.dataPath, os.ModePerm)
335 }
336
337 return err
338}
339
340// ExpireDir will flush a CachedDirectory and all its objects from the objects
341// chunks will remain as they are

Callers 6

ListMethod · 0.80
RmdirMethod · 0.80
DirMoveMethod · 0.80
MergeDirsMethod · 0.80
DirCacheFlushMethod · 0.80
RmdirMethod · 0.80

Calls 9

getBucketMethod · 0.95
DebugfFunction · 0.92
cleanPathFunction · 0.85
DeleteBucketMethod · 0.80
JoinMethod · 0.80
UpdateMethod · 0.65
RemoveAllMethod · 0.65
ErrorfMethod · 0.45
MkdirAllMethod · 0.45

Tested by

no test coverage detected