diff options
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v6/shared')
4 files changed, 50 insertions, 11 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/filesstore.go b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/filesstore.go index ef02895d..c17ea1f6 100644 --- a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/filesstore.go +++ b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/filesstore.go @@ -35,6 +35,7 @@ type FileBackend interface { FileModTime(path string) (time.Time, error) ListDirectory(path string) ([]string, error) + ListDirectoryRecursively(path string) ([]string, error) RemoveDirectory(path string) error } diff --git a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/localstore.go b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/localstore.go index 5ed882de..e2d53e49 100644 --- a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/localstore.go +++ b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/localstore.go @@ -188,19 +188,48 @@ func (b *LocalFileBackend) RemoveFile(path string) error { return nil } -func (b *LocalFileBackend) ListDirectory(path string) ([]string, error) { - var paths []string - fileInfos, err := ioutil.ReadDir(filepath.Join(b.directory, path)) +// basePath: path to get to the file but won't be added to the end result +// path: basePath+path current directory we are looking at +// maxDepth: parameter to prevent infinite recursion, once this is reached we won't look any further +func appendRecursively(basePath, path string, maxDepth int) ([]string, error) { + results := []string{} + dirEntries, err := os.ReadDir(filepath.Join(basePath, path)) if err != nil { if os.IsNotExist(err) { - return paths, nil + return results, nil } - return nil, errors.Wrapf(err, "unable to list the directory %s", path) + return results, errors.Wrapf(err, "unable to list the directory %s", path) } - for _, fileInfo := range fileInfos { - paths = append(paths, filepath.Join(path, fileInfo.Name())) + for _, dirEntry := range dirEntries { + entryName := dirEntry.Name() + entryPath := filepath.Join(path, entryName) + if entryName == "." || entryName == ".." || entryPath == path { + continue + } + if dirEntry.IsDir() { + if maxDepth <= 0 { + mlog.Warn("Max Depth reached", mlog.String("path", entryPath)) + results = append(results, entryPath) + continue // we'll ignore it if max depth is reached. + } + nestedResults, err := appendRecursively(basePath, entryPath, maxDepth-1) + if err != nil { + return results, err + } + results = append(results, nestedResults...) + } else { + results = append(results, entryPath) + } } - return paths, nil + return results, nil +} + +func (b *LocalFileBackend) ListDirectory(path string) ([]string, error) { + return appendRecursively(b.directory, path, 0) +} + +func (b *LocalFileBackend) ListDirectoryRecursively(path string) ([]string, error) { + return appendRecursively(b.directory, path, 10) } func (b *LocalFileBackend) RemoveDirectory(path string) error { diff --git a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/s3store.go b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/s3store.go index c45f626a..5ab6f1ce 100644 --- a/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/s3store.go +++ b/vendor/github.com/mattermost/mattermost-server/v6/shared/filestore/s3store.go @@ -396,7 +396,7 @@ func getPathsFromObjectInfos(in <-chan s3.ObjectInfo) <-chan s3.ObjectInfo { return out } -func (b *S3FileBackend) ListDirectory(path string) ([]string, error) { +func (b *S3FileBackend) listDirectory(path string, recursion bool) ([]string, error) { path = filepath.Join(b.pathPrefix, path) if !strings.HasSuffix(path, "/") && path != "" { // s3Clnt returns only the path itself when "/" is not present @@ -405,7 +405,8 @@ func (b *S3FileBackend) ListDirectory(path string) ([]string, error) { } opts := s3.ListObjectsOptions{ - Prefix: path, + Prefix: path, + Recursive: recursion, } var paths []string for object := range b.client.ListObjects(context.Background(), b.bucket, opts) { @@ -424,6 +425,14 @@ func (b *S3FileBackend) ListDirectory(path string) ([]string, error) { return paths, nil } +func (b *S3FileBackend) ListDirectory(path string) ([]string, error) { + return b.listDirectory(path, false) +} + +func (b *S3FileBackend) ListDirectoryRecursively(path string) ([]string, error) { + return b.listDirectory(path, true) +} + func (b *S3FileBackend) RemoveDirectory(path string) error { opts := s3.ListObjectsOptions{ Prefix: filepath.Join(b.pathPrefix, path), diff --git a/vendor/github.com/mattermost/mattermost-server/v6/shared/mlog/levels.go b/vendor/github.com/mattermost/mattermost-server/v6/shared/mlog/levels.go index c0b30996..1c88e816 100644 --- a/vendor/github.com/mattermost/mattermost-server/v6/shared/mlog/levels.go +++ b/vendor/github.com/mattermost/mattermost-server/v6/shared/mlog/levels.go @@ -14,7 +14,7 @@ var ( LvlInfo = logr.Info // ID = 4 LvlDebug = logr.Debug // ID = 5 LvlTrace = logr.Trace // ID = 6 - StdAll = []Level{LvlPanic, LvlFatal, LvlError, LvlWarn, LvlInfo, LvlDebug, LvlTrace} + StdAll = []Level{LvlPanic, LvlFatal, LvlError, LvlWarn, LvlInfo, LvlDebug, LvlTrace, LvlStdLog} // non-standard "critical" level LvlCritical = Level{ID: 7, Name: "critical"} // used by redirected standard logger |