aboutsummaryrefslogtreecommitdiffstats
path: root/modules/storage/local.go
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@vip.qq.com>2023-03-13 18:23:51 +0800
committerGitHub <noreply@github.com>2023-03-13 18:23:51 +0800
commitcdc9e91750036fc370db65a44618f3139db11ae1 (patch)
tree8a7ae4158086eb157d8aaa5689ff164c8b2d4d78 /modules/storage/local.go
parent757b4c17e900f1d11a81bc9467d90e6c245ee8f2 (diff)
downloadgitea-cdc9e91750036fc370db65a44618f3139db11ae1.tar.gz
gitea-cdc9e91750036fc370db65a44618f3139db11ae1.zip
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 <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/storage/local.go')
-rw-r--r--modules/storage/local.go8
1 files changed, 6 insertions, 2 deletions
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
}