From c80876c0b3338bd247d1f0053303454f33659494 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Mon, 6 Mar 2023 20:06:19 +0800 Subject: [PATCH 1/9] add path prefix to ObjectStorage.Iterator --- cmd/dump.go | 6 +++--- modules/doctor/storage.go | 2 +- modules/storage/helper.go | 2 +- modules/storage/helper_test.go | 2 +- modules/storage/local.go | 9 +++++++-- modules/storage/local_test.go | 34 ++++++++++++++++++++++++++++++++++ modules/storage/minio.go | 11 +++++++++-- modules/storage/storage.go | 4 ++-- 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index c802849f8e50f..00d279b99187d 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -250,7 +250,7 @@ func runDump(ctx *cli.Context) error { if ctx.IsSet("skip-lfs-data") && ctx.Bool("skip-lfs-data") { log.Info("Skip dumping LFS data") - } else if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error { + } else if err := storage.LFS.IterateObjects("", func(objPath string, object storage.Object) error { info, err := object.Stat() if err != nil { return err @@ -351,7 +351,7 @@ func runDump(ctx *cli.Context) error { if ctx.IsSet("skip-attachment-data") && ctx.Bool("skip-attachment-data") { log.Info("Skip dumping attachment data") - } else if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error { + } else if err := storage.Attachments.IterateObjects("", func(objPath string, object storage.Object) error { info, err := object.Stat() if err != nil { return err @@ -364,7 +364,7 @@ func runDump(ctx *cli.Context) error { if ctx.IsSet("skip-package-data") && ctx.Bool("skip-package-data") { log.Info("Skip dumping package data") - } else if err := storage.Packages.IterateObjects(func(objPath string, object storage.Object) error { + } else if err := storage.Packages.IterateObjects("", func(objPath string, object storage.Object) error { info, err := object.Stat() if err != nil { return err diff --git a/modules/doctor/storage.go b/modules/doctor/storage.go index aa987de4477b4..c20566d67593d 100644 --- a/modules/doctor/storage.go +++ b/modules/doctor/storage.go @@ -31,7 +31,7 @@ func commonCheckStorage(ctx context.Context, logger log.Logger, autofix bool, op totalSize, orphanedSize := int64(0), int64(0) var pathsToDelete []string - if err := opts.storer.IterateObjects(func(p string, obj storage.Object) error { + if err := opts.storer.IterateObjects("", func(p string, obj storage.Object) error { defer obj.Close() totalCount++ diff --git a/modules/storage/helper.go b/modules/storage/helper.go index 1ab99d98b31bc..d1959830b977d 100644 --- a/modules/storage/helper.go +++ b/modules/storage/helper.go @@ -90,6 +90,6 @@ func (s discardStorage) URL(_, _ string) (*url.URL, error) { return nil, fmt.Errorf("%s", s) } -func (s discardStorage) IterateObjects(_ func(string, Object) error) error { +func (s discardStorage) IterateObjects(_ string, _ func(string, Object) error) error { return fmt.Errorf("%s", s) } diff --git a/modules/storage/helper_test.go b/modules/storage/helper_test.go index 7d74671c544a8..f4c2d0467f7e7 100644 --- a/modules/storage/helper_test.go +++ b/modules/storage/helper_test.go @@ -42,7 +42,7 @@ func Test_discardStorage(t *testing.T) { assert.Errorf(t, err, string(tt)) } { - err := tt.IterateObjects(func(_ string, _ Object) error { return nil }) + err := tt.IterateObjects("", func(_ string, _ Object) error { return nil }) assert.Error(t, err, string(tt)) } }) diff --git a/modules/storage/local.go b/modules/storage/local.go index 05bf1fb28a56c..3fa3ed95c0e6c 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -127,8 +127,13 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) { } // IterateObjects iterates across the objects in the local storage -func (l *LocalStorage) IterateObjects(fn func(path string, obj Object) error) error { - return filepath.WalkDir(l.dir, func(path string, d os.DirEntry, err error) error { +func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { + dir := l.dir + prefix = strings.TrimSpace(prefix) + if prefix != "" { + dir = filepath.Join(strings.TrimSuffix(l.dir, "/"), "/"+strings.TrimPrefix(prefix, "/")) + } + return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil { return err } diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 994c54e8590dc..2cea2f846b1cc 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -4,6 +4,8 @@ package storage import ( + "bytes" + "context" "testing" "github.com/stretchr/testify/assert" @@ -50,3 +52,35 @@ func TestBuildLocalPath(t *testing.T) { }) } } + +func TestLocalStorageIterator(t *testing.T) { + l, err := NewLocalStorage(context.Background(), LocalStorageConfig{Path: "testdata/"}) + assert.NoError(t, err) + + test_files := [][]string{ + {"a/1.txt", "a1"}, + {"/a/1.txt", "aa1"}, + {"b/1.txt", "b1"}, + {"b/2.txt", "b2"}, + {"b/3.txt", "b3"}, + } + for _, f := range test_files { + _, err = l.Save(f[0], bytes.NewBufferString(f[1]), -1) + assert.NoError(t, err) + } + + expected_list := map[string][]string{ + "a": {"a/1.txt", "a/a/1.txt"}, + "b": {"b/1.txt", "b/2.txt", "b/3.txt"}, + "": {"a/1.txt", "a/a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt"}, + "/": {"a/1.txt", "a/a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt"}, + } + for dir, expected := range expected_list { + err = l.IterateObjects(dir, func(path string, f Object) error { + defer f.Close() + assert.Contains(t, expected, path) + return nil + }) + assert.NoError(t, err) + } +} diff --git a/modules/storage/minio.go b/modules/storage/minio.go index 24da14b634631..b318081479c4b 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -209,12 +209,19 @@ func (m *MinioStorage) URL(path, name string) (*url.URL, error) { } // IterateObjects iterates across the objects in the miniostorage -func (m *MinioStorage) IterateObjects(fn func(path string, obj Object) error) error { +func (m *MinioStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { opts := minio.GetObjectOptions{} lobjectCtx, cancel := context.WithCancel(m.ctx) defer cancel() + + basePath := m.basePath + prefix = strings.TrimSpace(prefix) + if prefix != "" { + basePath = strings.TrimSuffix(m.basePath, "/") + "/" + strings.TrimPrefix(prefix, "/") + } + for mObjInfo := range m.client.ListObjects(lobjectCtx, m.bucket, minio.ListObjectsOptions{ - Prefix: m.basePath, + Prefix: basePath, Recursive: true, }) { object, err := m.client.GetObject(lobjectCtx, m.bucket, mObjInfo.Key, opts) diff --git a/modules/storage/storage.go b/modules/storage/storage.go index d8998b19225fe..caecab306e630 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -65,7 +65,7 @@ type ObjectStorage interface { Stat(path string) (os.FileInfo, error) Delete(path string) error URL(path, name string) (*url.URL, error) - IterateObjects(func(path string, obj Object) error) error + IterateObjects(path string, iterator func(path string, obj Object) error) error } // Copy copies a file from source ObjectStorage to dest ObjectStorage @@ -87,7 +87,7 @@ func Copy(dstStorage ObjectStorage, dstPath string, srcStorage ObjectStorage, sr // Clean delete all the objects in this storage func Clean(storage ObjectStorage) error { - return storage.IterateObjects(func(path string, obj Object) error { + return storage.IterateObjects("", func(path string, obj Object) error { _ = obj.Close() return storage.Delete(path) }) From cc7b591d79da1e607b6f80668d8df7aaaa2ec408 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Mon, 6 Mar 2023 21:40:38 +0800 Subject: [PATCH 2/9] handle some danger path to iterator in object storage --- modules/storage/local.go | 7 +++++-- modules/storage/local_test.go | 28 +++++++++++++++++++++++----- modules/storage/storage.go | 3 +++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/storage/local.go b/modules/storage/local.go index 3fa3ed95c0e6c..dbd7ffaab673f 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -129,9 +129,12 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) { // IterateObjects iterates across the objects in the local storage func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { dir := l.dir - prefix = strings.TrimSpace(prefix) if prefix != "" { - dir = filepath.Join(strings.TrimSuffix(l.dir, "/"), "/"+strings.TrimPrefix(prefix, "/")) + prefix_trim := filepath.Clean(prefix) + dir = filepath.Join(l.dir, prefix_trim) + if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) { + return ErrIllegalPath + } } return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil { diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 2cea2f846b1cc..66795686eef1d 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -59,10 +59,11 @@ func TestLocalStorageIterator(t *testing.T) { test_files := [][]string{ {"a/1.txt", "a1"}, - {"/a/1.txt", "aa1"}, + {"/a/1.txt", "aa1"}, // same as above, but with leading slash that will be trim {"b/1.txt", "b1"}, {"b/2.txt", "b2"}, {"b/3.txt", "b3"}, + {"b/x 4.txt", "bx4"}, } for _, f := range test_files { _, err = l.Save(f[0], bytes.NewBufferString(f[1]), -1) @@ -70,17 +71,34 @@ func TestLocalStorageIterator(t *testing.T) { } expected_list := map[string][]string{ - "a": {"a/1.txt", "a/a/1.txt"}, - "b": {"b/1.txt", "b/2.txt", "b/3.txt"}, - "": {"a/1.txt", "a/a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt"}, - "/": {"a/1.txt", "a/a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt"}, + "a": {"a/1.txt"}, + "b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "/../../../tmp": {}, // empty dir } for dir, expected := range expected_list { + count := 0 err = l.IterateObjects(dir, func(path string, f Object) error { defer f.Close() assert.Contains(t, expected, path) + count++ return nil }) assert.NoError(t, err) + assert.Equal(t, count, len(expected)) + } + + // illegal dir + illegal_dirs := []string{ + "../a", + "../../etc/hosts", + } + for _, dir := range illegal_dirs { + err = l.IterateObjects(dir, func(path string, f Object) error { + defer f.Close() + return nil + }) + assert.Error(t, err, ErrIllegalPath) } } diff --git a/modules/storage/storage.go b/modules/storage/storage.go index caecab306e630..ca8fd8f907ea9 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -18,6 +18,9 @@ import ( // ErrURLNotSupported represents url is not supported var ErrURLNotSupported = errors.New("url method not supported") +// ErrIllegalPath represents path is illegal +var ErrIllegalPath = errors.New("illegal path") + // ErrInvalidConfiguration is called when there is invalid configuration for a storage type ErrInvalidConfiguration struct { cfg interface{} From 003d9a05e408fe67adb1bf8dc7478fa986035f55 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Wed, 8 Mar 2023 23:11:19 +0800 Subject: [PATCH 3/9] drop filepath.Clean for useless --- modules/storage/local.go | 3 +-- modules/storage/local_test.go | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/storage/local.go b/modules/storage/local.go index dbd7ffaab673f..f0274cab99925 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -130,8 +130,7 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) { func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { dir := l.dir if prefix != "" { - prefix_trim := filepath.Clean(prefix) - dir = filepath.Join(l.dir, prefix_trim) + dir = filepath.Join(l.dir, prefix) if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) { return ErrIllegalPath } diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 66795686eef1d..dee5c6c1e5142 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -71,11 +71,11 @@ func TestLocalStorageIterator(t *testing.T) { } expected_list := map[string][]string{ - "a": {"a/1.txt"}, - "b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, - "": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, - "/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, - "/../../../tmp": {}, // empty dir + "a": {"a/1.txt"}, + "b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, + "a/b/../../a": {"a/1.txt"}, } for dir, expected := range expected_list { count := 0 @@ -93,6 +93,7 @@ func TestLocalStorageIterator(t *testing.T) { illegal_dirs := []string{ "../a", "../../etc/hosts", + "../a/../b", } for _, dir := range illegal_dirs { err = l.IterateObjects(dir, func(path string, f Object) error { From 75af3b64c6e95bccfdf3370423155310a5117999 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 9 Mar 2023 18:22:02 +0800 Subject: [PATCH 4/9] use util.CleanPath --- modules/storage/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/storage/local.go b/modules/storage/local.go index f0274cab99925..e585537cc3175 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -130,7 +130,7 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) { func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { dir := l.dir if prefix != "" { - dir = filepath.Join(l.dir, prefix) + dir = util.CleanPath(filepath.Join(l.dir, prefix)) if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) { return ErrIllegalPath } From bf0c532ab5c80adbb81b5966846d7934001b607f Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 9 Mar 2023 21:10:10 +0800 Subject: [PATCH 5/9] fix tests and lints for ObjectStorage --- modules/storage/local_test.go | 12 ++++++------ tests/test_utils.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index dee5c6c1e5142..5fd7ade2b6e84 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -57,7 +57,7 @@ func TestLocalStorageIterator(t *testing.T) { l, err := NewLocalStorage(context.Background(), LocalStorageConfig{Path: "testdata/"}) assert.NoError(t, err) - test_files := [][]string{ + testFiles := [][]string{ {"a/1.txt", "a1"}, {"/a/1.txt", "aa1"}, // same as above, but with leading slash that will be trim {"b/1.txt", "b1"}, @@ -65,19 +65,19 @@ func TestLocalStorageIterator(t *testing.T) { {"b/3.txt", "b3"}, {"b/x 4.txt", "bx4"}, } - for _, f := range test_files { + for _, f := range testFiles { _, err = l.Save(f[0], bytes.NewBufferString(f[1]), -1) assert.NoError(t, err) } - expected_list := map[string][]string{ + expectedList := map[string][]string{ "a": {"a/1.txt"}, "b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, "": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, "/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"}, "a/b/../../a": {"a/1.txt"}, } - for dir, expected := range expected_list { + for dir, expected := range expectedList { count := 0 err = l.IterateObjects(dir, func(path string, f Object) error { defer f.Close() @@ -90,12 +90,12 @@ func TestLocalStorageIterator(t *testing.T) { } // illegal dir - illegal_dirs := []string{ + illegalDirs := []string{ "../a", "../../etc/hosts", "../a/../b", } - for _, dir := range illegal_dirs { + for _, dir := range illegalDirs { err = l.IterateObjects(dir, func(path string, f Object) error { defer f.Close() return nil diff --git a/tests/test_utils.go b/tests/test_utils.go index e3e5becfbedf3..102dd3d298fb0 100644 --- a/tests/test_utils.go +++ b/tests/test_utils.go @@ -201,7 +201,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() { lfsFixtures, err := storage.NewStorage("", storage.LocalStorageConfig{Path: path.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta")}) assert.NoError(t, err) assert.NoError(t, storage.Clean(storage.LFS)) - assert.NoError(t, lfsFixtures.IterateObjects(func(path string, _ storage.Object) error { + assert.NoError(t, lfsFixtures.IterateObjects("", func(path string, _ storage.Object) error { _, err := storage.Copy(storage.LFS, path, lfsFixtures, path) return err })) @@ -258,7 +258,7 @@ func ResetFixtures(t *testing.T) { lfsFixtures, err := storage.NewStorage("", storage.LocalStorageConfig{Path: path.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta")}) assert.NoError(t, err) assert.NoError(t, storage.Clean(storage.LFS)) - assert.NoError(t, lfsFixtures.IterateObjects(func(path string, _ storage.Object) error { + assert.NoError(t, lfsFixtures.IterateObjects("", func(path string, _ storage.Object) error { _, err := storage.Copy(storage.LFS, path, lfsFixtures, path) return err })) From 1b9ca2944fd393323483779c7996df54424e3a57 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 9 Mar 2023 21:25:13 +0800 Subject: [PATCH 6/9] fix tests that create local object storage test directory in os temp dir --- modules/storage/local_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 5fd7ade2b6e84..2641d7a0eb060 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -6,6 +6,8 @@ package storage import ( "bytes" "context" + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -54,7 +56,8 @@ func TestBuildLocalPath(t *testing.T) { } func TestLocalStorageIterator(t *testing.T) { - l, err := NewLocalStorage(context.Background(), LocalStorageConfig{Path: "testdata/"}) + dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir") + l, err := NewLocalStorage(context.Background(), LocalStorageConfig{Path: dir}) assert.NoError(t, err) testFiles := [][]string{ From 44c4c82364818d081a9f549756b82dc3a25f0fac Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Fri, 10 Mar 2023 19:40:35 +0800 Subject: [PATCH 7/9] update util.CleanPath usage, drop useless error const --- modules/storage/local.go | 5 +---- modules/storage/local_test.go | 14 -------------- modules/storage/storage.go | 3 --- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/modules/storage/local.go b/modules/storage/local.go index e585537cc3175..15f5761e8f055 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -130,10 +130,7 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) { func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error { dir := l.dir if prefix != "" { - dir = util.CleanPath(filepath.Join(l.dir, prefix)) - if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) { - return ErrIllegalPath - } + dir = filepath.Join(l.dir, util.CleanPath(prefix)) } return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil { diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 2641d7a0eb060..2b112df8f12b3 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -91,18 +91,4 @@ func TestLocalStorageIterator(t *testing.T) { assert.NoError(t, err) assert.Equal(t, count, len(expected)) } - - // illegal dir - illegalDirs := []string{ - "../a", - "../../etc/hosts", - "../a/../b", - } - for _, dir := range illegalDirs { - err = l.IterateObjects(dir, func(path string, f Object) error { - defer f.Close() - return nil - }) - assert.Error(t, err, ErrIllegalPath) - } } diff --git a/modules/storage/storage.go b/modules/storage/storage.go index ca8fd8f907ea9..caecab306e630 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -18,9 +18,6 @@ import ( // ErrURLNotSupported represents url is not supported var ErrURLNotSupported = errors.New("url method not supported") -// ErrIllegalPath represents path is illegal -var ErrIllegalPath = errors.New("illegal path") - // ErrInvalidConfiguration is called when there is invalid configuration for a storage type ErrInvalidConfiguration struct { cfg interface{} From ea9c8b94b5f905290b9906bc17cc66692d609233 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 11 Mar 2023 22:32:07 +0800 Subject: [PATCH 8/9] fix trim wrong basepath in object storage in minio --- modules/storage/minio.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/storage/minio.go b/modules/storage/minio.go index b318081479c4b..2ec0e0665e081 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -230,7 +230,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, m.basePath), &minioObject{object}) + return fn(strings.TrimPrefix(mObjInfo.Key, basePath), &minioObject{object}) }(object, fn); err != nil { return convertMinioErr(err) } From 61c82f47d3502ad631522fca743b3213f4677e12 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Mon, 13 Mar 2023 12:15:27 +0800 Subject: [PATCH 9/9] use minio common buildMinioPath to handle iterator preifx --- modules/storage/minio.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/storage/minio.go b/modules/storage/minio.go index 2ec0e0665e081..8cc06bcdd3df2 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -215,9 +215,8 @@ func (m *MinioStorage) IterateObjects(prefix string, fn func(path string, obj Ob defer cancel() basePath := m.basePath - prefix = strings.TrimSpace(prefix) if prefix != "" { - basePath = strings.TrimSuffix(m.basePath, "/") + "/" + strings.TrimPrefix(prefix, "/") + basePath = m.buildMinioPath(prefix) } for mObjInfo := range m.client.ListObjects(lobjectCtx, m.bucket, minio.ListObjectsOptions{