cache: fix dir cache issue - #2117
This commit is contained in:
parent
89748feaa5
commit
d76da1f5fd
3 changed files with 83 additions and 7 deletions
21
backend/cache/storage_persistent.go
vendored
21
backend/cache/storage_persistent.go
vendored
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue