RemoveDir will delete a CachedDirectory, all its objects and all the chunks stored for it
(fp string)
| 300 | |
| 301 | // RemoveDir will delete a CachedDirectory, all its objects and all the chunks stored for it |
| 302 | func (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 |
no test coverage detected