aboutsummaryrefslogtreecommitdiffstats
path: root/modules/storage/minio.go
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@vip.qq.com>2023-05-14 06:33:25 +0800
committerGitHub <noreply@github.com>2023-05-13 22:33:25 +0000
commit61ad4c607b09f102151298af98757dbae2c2fa88 (patch)
tree64067be6a02eba93d947183878c0e86a927bf810 /modules/storage/minio.go
parent4810fe55e3e73edb962052df46bef125eb1817b3 (diff)
downloadgitea-61ad4c607b09f102151298af98757dbae2c2fa88.tar.gz
gitea-61ad4c607b09f102151298af98757dbae2c2fa88.zip
fix minio storage iterator path (#24691)
minio storage iterator shows different behavior with local fs iterator. in local fs storage: ``` go s.IterateObjects("prefix", func(path,obj) println(path) // show "prefix/xxx.file" }) ``` in minio storage: ```go s.IterateObjects("prefix", func(path,obj) println(path) // show "xxx.file" }) ``` I think local fs is correct, minio use wrong `basePath` to trim storage path prefix. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules/storage/minio.go')
-rw-r--r--modules/storage/minio.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/storage/minio.go b/modules/storage/minio.go
index 250f17827f..c78f351e9c 100644
--- a/modules/storage/minio.go
+++ b/modules/storage/minio.go
@@ -129,7 +129,11 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
}
func (m *MinioStorage) buildMinioPath(p string) string {
- return util.PathJoinRelX(m.basePath, p)
+ p = util.PathJoinRelX(m.basePath, p)
+ if p == "." {
+ p = "" // minio doesn't use dot as relative path
+ }
+ return p
}
// Open opens a file
@@ -224,14 +228,15 @@ func (m *MinioStorage) URL(path, name string) (*url.URL, error) {
}
// IterateObjects iterates across the objects in the miniostorage
-func (m *MinioStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error {
+func (m *MinioStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error {
opts := minio.GetObjectOptions{}
lobjectCtx, cancel := context.WithCancel(m.ctx)
defer cancel()
basePath := m.basePath
- if prefix != "" {
- basePath = m.buildMinioPath(prefix)
+ if dirName != "" {
+ // ending slash is required for avoiding matching like "foo/" and "foobar/" with prefix "foo"
+ basePath = m.buildMinioPath(dirName) + "/"
}
for mObjInfo := range m.client.ListObjects(lobjectCtx, m.bucket, minio.ListObjectsOptions{
@@ -244,7 +249,7 @@ func (m *MinioStorage) IterateObjects(prefix string, fn func(path string, obj Ob
}
if err := func(object *minio.Object, fn func(path string, obj Object) error) error {
defer object.Close()
- return fn(strings.TrimPrefix(mObjInfo.Key, basePath), &minioObject{object})
+ return fn(strings.TrimPrefix(mObjInfo.Key, m.basePath), &minioObject{object})
}(object, fn); err != nil {
return convertMinioErr(err)
}