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)
| 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) |
| 145 | func (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 |
| 171 | func (b *Persistent) GetDir(remote string) (*Directory, error) { |
no test coverage detected