From 70e649b36a8c3a6eb963b8a1403dcb7f60624526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa=20Montoro?= Date: Tue, 4 Aug 2020 13:58:48 +0200 Subject: [PATCH] MM-27178: Use FileSettings.Directory in export tool (#15100) * MM-27178: use FileSettings.Directory in export * Set empty FileSettings.Directory to default value * Validate that FileSettings.Directory is non-empty * Don't set FileSettings.Directory to / in fixConfig * Run make i18n-extract Co-authored-by: Mattermod --- cmd/mattermost/commands/export.go | 5 +++++ config/utils.go | 2 +- i18n/en.json | 4 ++++ model/config.go | 6 +++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/mattermost/commands/export.go b/cmd/mattermost/commands/export.go index beb6ad7bba..1fefc98550 100644 --- a/cmd/mattermost/commands/export.go +++ b/cmd/mattermost/commands/export.go @@ -206,6 +206,11 @@ func bulkExportCmdF(command *cobra.Command, args []string) error { // Path to directory of custom emoji pathToEmojiDir := "data/emoji/" + customDataDir := a.Config().FileSettings.Directory + if customDataDir != nil && *customDataDir != "" { + pathToEmojiDir = *customDataDir + "emoji/" + } + // Name of the directory to export custom emoji dirNameToExportEmoji := "exported_emoji" diff --git a/config/utils.go b/config/utils.go index 7644f3156b..78a16d054f 100644 --- a/config/utils.go +++ b/config/utils.go @@ -67,7 +67,7 @@ func fixConfig(cfg *model.Config) bool { // Ensure the directory for a local file store has a trailing slash. if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if !strings.HasSuffix(*cfg.FileSettings.Directory, "/") { + if *cfg.FileSettings.Directory != "" && !strings.HasSuffix(*cfg.FileSettings.Directory, "/") { *cfg.FileSettings.Directory += "/" changed = true } diff --git a/i18n/en.json b/i18n/en.json index fde6956016..110ee4365d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5722,6 +5722,10 @@ "id": "model.config.is_valid.data_retention.message_retention_days_too_low.app_error", "translation": "Message retention must be one day or longer." }, + { + "id": "model.config.is_valid.directory.app_error", + "translation": "Invalid Local Storage Directory. Must be a non-empty string." + }, { "id": "model.config.is_valid.display.custom_url_schemes.app_error", "translation": "The custom URL scheme {{.Scheme}} is invalid. Custom URL schemes must start with a letter and contain only letters, numbers, plus (+), period (.) and hyphen (-)." diff --git a/model/config.go b/model/config.go index 6634107583..e7c9d1ffeb 100644 --- a/model/config.go +++ b/model/config.go @@ -1280,7 +1280,7 @@ func (s *FileSettings) SetDefaults(isUpdate bool) { s.DriverName = NewString(IMAGE_DRIVER_LOCAL) } - if s.Directory == nil { + if s.Directory == nil || *s.Directory == "" { s.Directory = NewString(FILE_SETTINGS_DEFAULT_DIRECTORY) } @@ -3018,6 +3018,10 @@ func (s *FileSettings) isValid() *AppError { return NewAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "", http.StatusBadRequest) } + if *s.Directory == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.directory.app_error", nil, "", http.StatusBadRequest) + } + return nil }