From cdc9e91750036fc370db65a44618f3139db11ae1 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Mon, 13 Mar 2023 18:23:51 +0800 Subject: add path prefix to ObjectStorage.Iterator (#23332) Support to iterator subdirectory in ObjectStorage for ObjectStorage.Iterator method. It's required for https://github.com/go-gitea/gitea/pull/22738 to make artifact files cleanable. --------- Co-authored-by: Jason Song Co-authored-by: Lunny Xiao --- modules/storage/local.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'modules/storage/local.go') diff --git a/modules/storage/local.go b/modules/storage/local.go index 05bf1fb28a..15f5761e8f 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -127,8 +127,12 @@ 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 + if prefix != "" { + dir = filepath.Join(l.dir, util.CleanPath(prefix)) + } + return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil { return err } -- cgit v1.2.3