diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-09-29 17:05:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 12:05:13 +0300 |
commit | 3878e985b66cc6d4cb4d2b0e7406d5cf91af6191 (patch) | |
tree | 31229c29c2b57041d1941ec28b043165cbe4642d /modules/storage/local.go | |
parent | 4c6ac08182b5a14eaaffaafafef160bd90c4ae81 (diff) | |
download | gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.tar.gz gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.zip |
Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/storage/local.go')
-rw-r--r-- | modules/storage/local.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/modules/storage/local.go b/modules/storage/local.go index a937a831f1..4185981664 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -59,7 +59,7 @@ func (l *LocalStorage) Save(path string, r io.Reader) (int64, error) { } // Stat returns the info of the file -func (l *LocalStorage) Stat(path string) (ObjectInfo, error) { +func (l *LocalStorage) Stat(path string) (os.FileInfo, error) { return os.Stat(filepath.Join(l.dir, path)) } @@ -73,3 +73,28 @@ func (l *LocalStorage) Delete(path string) error { func (l *LocalStorage) URL(path, name string) (*url.URL, error) { return nil, ErrURLNotSupported } + +// IterateObjects iterates across the objects in the local storage +func (l *LocalStorage) IterateObjects(fn func(path string, obj Object) error) error { + return filepath.Walk(l.dir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if path == l.dir { + return nil + } + if info.IsDir() { + return nil + } + relPath, err := filepath.Rel(l.dir, path) + if err != nil { + return err + } + obj, err := os.Open(path) + if err != nil { + return err + } + defer obj.Close() + return fn(relPath, obj) + }) +} |