aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xdsconfig/config.go')
-rw-r--r--lib/xdsconfig/config.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go
index ee20bd2..ca5b5cb 100644
--- a/lib/xdsconfig/config.go
+++ b/lib/xdsconfig/config.go
@@ -21,6 +21,8 @@ import (
"fmt"
"io"
"os"
+ "os/user"
+ "path"
"path/filepath"
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
@@ -53,8 +55,8 @@ type Options struct {
const (
DefaultAPIVersion = "1"
DefaultPort = "8000"
- DefaultShareDir = "${HOME}/.xds/server/projects"
- DefaultSTHomeDir = "${HOME}/.xds/server/syncthing-config"
+ DefaultShareDir = "projects"
+ DefaultSTHomeDir = "syncthing-config"
DefaultSdkScriptsDir = "${EXEPATH}/sdks"
DefaultSdkDbUpdate = "startup"
)
@@ -63,12 +65,12 @@ const (
func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
var err error
- dfltShareDir := DefaultShareDir
- dfltSTHomeDir := DefaultSTHomeDir
- if resDir, err := common.ResolveEnvVar(DefaultShareDir); err == nil {
+ dfltShareDir := path.Join(ConfigRootDir(), DefaultShareDir)
+ dfltSTHomeDir := path.Join(ConfigRootDir(), DefaultSTHomeDir)
+ if resDir, err := common.ResolveEnvVar(dfltShareDir); err == nil {
dfltShareDir = resDir
}
- if resDir, err := common.ResolveEnvVar(DefaultSTHomeDir); err == nil {
+ if resDir, err := common.ResolveEnvVar(dfltSTHomeDir); err == nil {
dfltSTHomeDir = resDir
}
@@ -157,3 +159,18 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
return &c, nil
}
+
+// ConfigRootDir return the root directory where xds server save all config files
+func ConfigRootDir() string {
+ root := "$HOME"
+ if usr, err := user.Current(); err == nil {
+ root = usr.HomeDir
+ }
+
+ // Default $HOME/.xds/server but may be changed by an env variable
+ if envVar, envDef := os.LookupEnv("XDS_SERVER_ROOT_CFG_DIR"); envDef {
+ root = envVar
+ }
+
+ return path.Join(root, "/.xds/server")
+}