MCPcopy
hub / github.com/rclone/rclone / getBucket

Method getBucket

backend/cache/storage_persistent.go:145–168  ·  view source on GitHub ↗

getBucket prepares and cleans a specific path of the form: /var/tmp and will iterate through each path component to get to the nested bucket of the final part (in this example: tmp)

(dir string, createIfMissing bool, tx *bolt.Tx)

Source from the content-addressed store, hash-verified

143// getBucket prepares and cleans a specific path of the form: /var/tmp and will iterate through each path component
144// to get to the nested bucket of the final part (in this example: tmp)
145func (b *Persistent) getBucket(dir string, createIfMissing bool, tx *bolt.Tx) *bolt.Bucket {
146 cleanPath(dir)
147
148 entries := strings.FieldsFunc(dir, func(c rune) bool {
149 // cover Windows where rclone still uses '/' as path separator
150 // this should be safe as '/' is not a valid Windows character
151 return (os.PathSeparator == c || c == rune('/'))
152 })
153 bucket := tx.Bucket([]byte(RootBucket))
154
155 for _, entry := range entries {
156 if createIfMissing {
157 bucket, _ = bucket.CreateBucketIfNotExists([]byte(entry))
158 } else {
159 bucket = bucket.Bucket([]byte(entry))
160 }
161
162 if bucket == nil {
163 return nil
164 }
165 }
166
167 return bucket
168}
169
170// GetDir will retrieve data of a cached directory
171func (b *Persistent) GetDir(remote string) (*Directory, error) {

Callers 9

GetDirMethod · 0.95
AddBatchDirMethod · 0.95
GetDirEntriesMethod · 0.95
RemoveDirMethod · 0.95
ExpireDirMethod · 0.95
GetObjectMethod · 0.95
AddObjectMethod · 0.95
RemoveObjectMethod · 0.95
HasEntryMethod · 0.95

Calls 1

cleanPathFunction · 0.85

Tested by

no test coverage detected