MCPcopy
hub / github.com/rclone/rclone / AddBatchDir

Method AddBatchDir

backend/cache/storage_persistent.go:197–236  ·  view source on GitHub ↗

AddBatchDir will update a list of CachedDirectory metadata and all their entries

(cachedDirs []*Directory)

Source from the content-addressed store, hash-verified

195
196// AddBatchDir will update a list of CachedDirectory metadata and all their entries
197func (b *Persistent) AddBatchDir(cachedDirs []*Directory) error {
198 if len(cachedDirs) == 0 {
199 return nil
200 }
201
202 return b.db.Update(func(tx *bolt.Tx) error {
203 var bucket *bolt.Bucket
204 if cachedDirs[0].Dir == "" {
205 bucket = tx.Bucket([]byte(RootBucket))
206 } else {
207 bucket = b.getBucket(cachedDirs[0].Dir, true, tx)
208 }
209 if bucket == nil {
210 return fmt.Errorf("couldn't open bucket (%v)", cachedDirs[0].Dir)
211 }
212
213 for _, cachedDir := range cachedDirs {
214 var b *bolt.Bucket
215 var err error
216 if cachedDir.Name == "" {
217 b = bucket
218 } else {
219 b, err = bucket.CreateBucketIfNotExists([]byte(cachedDir.Name))
220 }
221 if err != nil {
222 return err
223 }
224
225 encoded, err := json.Marshal(cachedDir)
226 if err != nil {
227 return fmt.Errorf("couldn't marshal object (%v): %v", cachedDir, err)
228 }
229 err = b.Put([]byte("."), encoded)
230 if err != nil {
231 return err
232 }
233 }
234 return nil
235 })
236}
237
238// GetDirEntries will return a CachedDirectory, its list of dir entries and/or an error if it encountered issues
239func (b *Persistent) GetDirEntries(cachedDir *Directory) (fs.DirEntries, error) {

Callers 2

AddDirMethod · 0.95
ListMethod · 0.80

Calls 4

getBucketMethod · 0.95
UpdateMethod · 0.65
PutMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected