summaryrefslogtreecommitdiffstats
path: root/utils/config.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-11-16 08:40:26 -0600
committerGitHub <noreply@github.com>2017-11-16 08:40:26 -0600
commitbf6bb9bce9723799991478e5aea745686045ad65 (patch)
treef9d84501c5db96563f53410aaa546aac8085157f /utils/config.go
parent6eb4b4604c79b0052cb7ab8ac97c9b90fa61e918 (diff)
downloadchat-bf6bb9bce9723799991478e5aea745686045ad65.tar.gz
chat-bf6bb9bce9723799991478e5aea745686045ad65.tar.bz2
chat-bf6bb9bce9723799991478e5aea745686045ad65.zip
fix config cli option (#7850)
Diffstat (limited to 'utils/config.go')
-rw-r--r--utils/config.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/utils/config.go b/utils/config.go
index 9a59a2dc0..1dea32535 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -70,11 +70,20 @@ func RemoveConfigListener(id string) {
delete(cfgListeners, id)
}
+// FindConfigFile attempts to find an existing configuration file. fileName can be an absolute or
+// relative path or name such as "/opt/mattermost/config.json" or simply "config.json". An empty
+// string is returned if no configuration is found.
func FindConfigFile(fileName string) (path string) {
- for _, dir := range []string{"./config", "../config", "../../config", "."} {
- path, _ := filepath.Abs(filepath.Join(dir, fileName))
- if _, err := os.Stat(path); err == nil {
- return path
+ if filepath.IsAbs(fileName) {
+ if _, err := os.Stat(fileName); err == nil {
+ return fileName
+ }
+ } else {
+ for _, dir := range []string{"./config", "../config", "../../config", "."} {
+ path, _ := filepath.Abs(filepath.Join(dir, fileName))
+ if _, err := os.Stat(path); err == nil {
+ return path
+ }
}
}
return ""
@@ -310,8 +319,8 @@ func ReadConfigFile(path string, allowEnvironmentOverrides bool) (*model.Config,
}
// EnsureConfigFile will attempt to locate a config file with the given name. If it does not exist,
-// it will attempt to locate a default config file, and copy it. In either case, the config file
-// path is returned.
+// it will attempt to locate a default config file, and copy it to a file named fileName in the same
+// directory. In either case, the config file path is returned.
func EnsureConfigFile(fileName string) (string, error) {
if configFile := FindConfigFile(fileName); configFile != "" {
return configFile, nil