[MM-40179] Go into directories when trying to export attachments (#19249)

* MM-40179 traverse directories when trying to export

* fix test

* fix s3 to behabe the same way

* add test for paths way too deep

* test recursion only on localstorage

* make list directories non recursively the default approach

* fix linting error

* fix non-recursive case

Co-authored-by: = <=>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Guillermo Vayá
2022-03-15 12:57:29 +01:00
коммит произвёл GitHub
родитель 9d10199e5f
Коммит 4bf3d6a7f5
9 изменённых файлов: 183 добавлений и 17 удалений

Просмотреть файл

@@ -840,6 +840,7 @@ type AppIface interface {
LimitedClientConfig() map[string]string
ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError)
ListDirectory(path string) ([]string, *model.AppError)
ListDirectoryRecursively(path string) ([]string, *model.AppError)
ListExports() ([]string, *model.AppError)
ListImports() ([]string, *model.AppError)
ListPluginKeys(pluginID string, page, perPage int) ([]string, *model.AppError)

Просмотреть файл

@@ -179,11 +179,24 @@ func (s *Server) removeFile(path string) *model.AppError {
}
func (a *App) ListDirectory(path string) ([]string, *model.AppError) {
return a.Srv().listDirectory(path)
return a.Srv().listDirectory(path, false)
}
func (s *Server) listDirectory(path string) ([]string, *model.AppError) {
paths, nErr := s.FileBackend().ListDirectory(path)
func (a *App) ListDirectoryRecursively(path string) ([]string, *model.AppError) {
return a.Srv().listDirectory(path, true)
}
func (s *Server) listDirectory(path string, recursion bool) ([]string, *model.AppError) {
backend := s.FileBackend()
var paths []string
var nErr error
if recursion {
paths, nErr = backend.ListDirectoryRecursively(path)
} else {
paths, nErr = backend.ListDirectory(path)
}
if nErr != nil {
return nil, model.NewAppError("ListDirectory", "api.file.list_directory.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}

Просмотреть файл

@@ -11395,6 +11395,28 @@ func (a *OpenTracingAppLayer) ListDirectory(path string) ([]string, *model.AppEr
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) ListDirectoryRecursively(path string) ([]string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListDirectoryRecursively")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.ListDirectoryRecursively(path)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) ListExports() ([]string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListExports")

Просмотреть файл

@@ -823,7 +823,7 @@ func (ch *Channels) notifyPluginEnabled(manifest *model.Manifest) error {
}
func (ch *Channels) getPluginsFromFolder() (map[string]*pluginSignaturePath, *model.AppError) {
fileStorePaths, appErr := ch.srv.listDirectory(fileStorePluginFolder)
fileStorePaths, appErr := ch.srv.listDirectory(fileStorePluginFolder, false)
if appErr != nil {
return nil, model.NewAppError("getPluginsFromDir", "app.plugin.sync.list_filestore.app_error", nil, appErr.Error(), http.StatusInternalServerError)
}