diff options
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) + }) +} |