AddObject will create a cached object in its parent directory
(cachedObject *Object)
| 388 | |
| 389 | // AddObject will create a cached object in its parent directory |
| 390 | func (b *Persistent) AddObject(cachedObject *Object) error { |
| 391 | return b.db.Update(func(tx *bolt.Tx) error { |
| 392 | bucket := b.getBucket(cachedObject.Dir, true, tx) |
| 393 | if bucket == nil { |
| 394 | return fmt.Errorf("couldn't open parent bucket for %v", cachedObject) |
| 395 | } |
| 396 | // cache Object Info |
| 397 | encoded, err := json.Marshal(cachedObject) |
| 398 | if err != nil { |
| 399 | return fmt.Errorf("couldn't marshal object (%v) info: %v", cachedObject, err) |
| 400 | } |
| 401 | err = bucket.Put([]byte(cachedObject.Name), encoded) |
| 402 | if err != nil { |
| 403 | return fmt.Errorf("couldn't cache object (%v) info: %v", cachedObject, err) |
| 404 | } |
| 405 | return nil |
| 406 | }) |
| 407 | } |
| 408 | |
| 409 | // RemoveObject will delete a single cached object and all the chunks which belong to it |
| 410 | func (b *Persistent) RemoveObject(fp string) error { |