pico
created pr with
66.1
changed pr name to
chore(pobj.fs): feature parity with minio
added 66.2
1: a3f9ef2 = 1: a3f9ef2 chore: rm UserMetadata
2: ccd89b0 = 2: ccd89b0 refactor(shared): mime type pkg
3: 8621e35 = 3: 8621e35 chore(pobj.fs): provide metadata
-: ------- > 4: 831b150 chore(storage.fs): add tests
cmds
checkout latest patchset:
ssh pr.pico.sh print 66 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 66.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 66
Patchset
66.2
chore(storage.fs): add tests
Eric Bower
2025-04-21T18:43:56ZSemantic diff summary
1 added,
3 modified,
0 signature changed,
0 removed
across 2 analyzed files
+25
-4
pkg/pobj/storage/fs.go
#
| ... | ... | @@ -76,7 +76,7 @@ func (s *StorageFS) UpsertBucket(name string) (Bucket, error) { | |
| 76 | 76 | return bucket, nil | |
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | - | dir := filepath.Join(s.Dir, bucket.Path) | |
| 79 | + | dir := filepath.Join(s.Dir, name) | |
| 80 | 80 | s.Logger.Info("bucket not found, creating", "dir", dir, "err", err) | |
| 81 | 81 | err = os.MkdirAll(dir, os.ModePerm) | |
| 82 | 82 | if err != nil { |
| ... | ... | @@ -91,6 +91,8 @@ func (s *StorageFS) GetBucketQuota(bucket Bucket) (uint64, error) { | |
| 91 | 91 | return uint64(dsize), err | |
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | + | // DeleteBucket will delete all contents regardless if files exist inside of it. | |
| 95 | + | // This is different from minio impl which requires all files be deleted first. | |
| 94 | 96 | func (s *StorageFS) DeleteBucket(bucket Bucket) error { | |
| 95 | 97 | return os.RemoveAll(bucket.Path) | |
| 96 | 98 | } |
| ... | ... | @@ -150,15 +152,34 @@ func (s *StorageFS) DeleteObject(bucket Bucket, fpath string) error { | |
| 150 | 152 | return err | |
| 151 | 153 | } | |
| 152 | 154 | ||
| 153 | - | // try to remove dir if it is empty | |
| 155 | + | // traverse up the folder tree and remove all empty folders | |
| 154 | 156 | dir := filepath.Dir(loc) | |
| 155 | - | _ = os.Remove(dir) | |
| 157 | + | for dir != "" { | |
| 158 | + | err = os.Remove(dir) | |
| 159 | + | if err != nil { | |
| 160 | + | break | |
| 161 | + | } | |
| 162 | + | fp := strings.Split(dir, "/") | |
| 163 | + | dir = "/" + filepath.Join(fp[:len(fp)-1]...) | |
| 164 | + | } | |
| 156 | 165 | ||
| 157 | 166 | return nil | |
| 158 | 167 | } | |
| 159 | 168 | ||
| 160 | 169 | func (s *StorageFS) ListBuckets() ([]string, error) { | |
| 161 | - | return []string{}, fmt.Errorf("not implemented") | |
| 170 | + | entries, err := os.ReadDir(s.Dir) | |
| 171 | + | if err != nil { | |
| 172 | + | return []string{}, err | |
| 173 | + | } | |
| 174 | + | ||
| 175 | + | buckets := []string{} | |
| 176 | + | for _, e := range entries { | |
| 177 | + | if !e.IsDir() { | |
| 178 | + | continue | |
| 179 | + | } | |
| 180 | + | buckets = append(buckets, e.Name()) | |
| 181 | + | } | |
| 182 | + | return buckets, nil | |
| 162 | 183 | } | |
| 163 | 184 | ||
| 164 | 185 | func (s *StorageFS) ListObjects(bucket Bucket, dir string, recursive bool) ([]os.FileInfo, error) { |