cache: fix dir cache issue - #2117

This commit is contained in:
Remus Bunduc 2018-03-13 23:43:34 +02:00 committed by remusb
parent 89748feaa5
commit d76da1f5fd
3 changed files with 83 additions and 7 deletions

View file

@ -169,6 +169,27 @@ func (b *Persistent) getBucket(dir string, createIfMissing bool, tx *bolt.Tx) *b
return bucket
}
// GetDir will retrieve data of a cached directory
func (b *Persistent) GetDir(remote string) (*Directory, error) {
cd := &Directory{}
err := b.db.View(func(tx *bolt.Tx) error {
bucket := b.getBucket(remote, false, tx)
if bucket == nil {
return errors.Errorf("couldn't open bucket (%v)", remote)
}
data := bucket.Get([]byte("."))
if data != nil {
return json.Unmarshal(data, cd)
}
return errors.Errorf("%v not found", remote)
})
return cd, err
}
// AddDir will update a CachedDirectory metadata and all its entries
func (b *Persistent) AddDir(cachedDir *Directory) error {
return b.db.Update(func(tx *bolt.Tx) error {