From 8f41ac456fc92a9ec333579498e9933d73404905 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Tue, 20 Jun 2017 22:29:59 +0200 Subject: Remove duplicate fields and set default SDK dir. - Removed duplicate fields between Config and FileConfig - set /xdt/sdk as default SDK directory --- lib/xdsconfig/fileconfig.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'lib/xdsconfig/fileconfig.go') diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index 01bd4c9..99e5382 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -77,7 +77,6 @@ func updateConfigFromFile(c *Config, confFile string) error { if err := json.NewDecoder(fd).Decode(&fCfg); err != nil { return err } - c.FileConf = fCfg // Support environment variables (IOW ${MY_ENV_VAR} syntax) in config.json for _, field := range []*string{ @@ -94,30 +93,33 @@ func updateConfigFromFile(c *Config, confFile string) error { } } - // Config file settings overwrite default config - - if fCfg.WebAppDir != "" { - c.WebAppDir = strings.Trim(fCfg.WebAppDir, " ") + // Use config file settings else use default config + if fCfg.WebAppDir == "" { + fCfg.WebAppDir = c.FileConf.WebAppDir + } + if fCfg.ShareRootDir == "" { + fCfg.ShareRootDir = c.FileConf.ShareRootDir } - // Is it a full path ? - if !strings.HasPrefix(c.WebAppDir, "/") && exePath != "" { + if fCfg.SdkRootDir == "" { + fCfg.SdkRootDir = c.FileConf.SdkRootDir + } + if fCfg.HTTPPort == "" { + fCfg.HTTPPort = c.FileConf.HTTPPort + } + + // Resolve webapp dir (support relative or full path) + fCfg.WebAppDir = strings.Trim(fCfg.WebAppDir, " ") + if !strings.HasPrefix(fCfg.WebAppDir, "/") && exePath != "" { // Check first from current directory for _, rootD := range []string{cwd, exePath} { - ff := path.Join(rootD, c.WebAppDir, "index.html") + ff := path.Join(rootD, fCfg.WebAppDir, "index.html") if common.Exists(ff) { - c.WebAppDir = path.Join(rootD, c.WebAppDir) + fCfg.WebAppDir = path.Join(rootD, fCfg.WebAppDir) break } } } - if fCfg.ShareRootDir != "" { - c.ShareRootDir = fCfg.ShareRootDir - } - - if fCfg.HTTPPort != "" { - c.HTTPPort = fCfg.HTTPPort - } - + c.FileConf = fCfg return nil } -- cgit 1.2.3-korg