@@ -15,16 +15,28 @@ import (
1515 log "github.com/sirupsen/logrus"
1616)
1717
18- func InitConfig () {
18+ // Program working directory
19+ func PWD () string {
1920 if flags .ForceBinDir {
20- if ! filepath .IsAbs (flags .DataDir ) {
21- ex , err := os .Executable ()
22- if err != nil {
23- utils .Log .Fatal (err )
24- }
25- exPath := filepath .Dir (ex )
26- flags .DataDir = filepath .Join (exPath , flags .DataDir )
21+ ex , err := os .Executable ()
22+ if err != nil {
23+ log .Fatal (err )
2724 }
25+ pwd := filepath .Dir (ex )
26+ return pwd
27+ }
28+ d , err := os .Getwd ()
29+ if err != nil {
30+ d = "."
31+ }
32+ return d
33+ }
34+
35+ func InitConfig () {
36+ pwd := PWD ()
37+ dataDir := flags .DataDir
38+ if ! filepath .IsAbs (dataDir ) {
39+ flags .DataDir = filepath .Join (pwd , flags .DataDir )
2840 }
2941 configPath := filepath .Join (flags .DataDir , "config.json" )
3042 log .Infof ("reading config file: %s" , configPath )
@@ -34,7 +46,7 @@ func InitConfig() {
3446 if err != nil {
3547 log .Fatalf ("failed to create config file: %+v" , err )
3648 }
37- conf .Conf = conf .DefaultConfig ()
49+ conf .Conf = conf .DefaultConfig (dataDir )
3850 LastLaunchedVersion = conf .Version
3951 conf .Conf .LastLaunchedVersion = conf .Version
4052 if ! utils .WriteJsonToFile (configPath , conf .Conf ) {
@@ -45,7 +57,7 @@ func InitConfig() {
4557 if err != nil {
4658 log .Fatalf ("reading config file error: %+v" , err )
4759 }
48- conf .Conf = conf .DefaultConfig ()
60+ conf .Conf = conf .DefaultConfig (dataDir )
4961 err = utils .Json .Unmarshal (configBytes , conf .Conf )
5062 if err != nil {
5163 log .Fatalf ("load config error: %+v" , err )
@@ -71,12 +83,17 @@ func InitConfig() {
7183 confFromEnv ()
7284 }
7385 // convert abs path
74- if ! filepath .IsAbs (conf .Conf .TempDir ) {
75- absPath , err := filepath .Abs (conf .Conf .TempDir )
76- if err != nil {
77- log .Fatalf ("get abs path error: %+v" , err )
86+ convertAbsPath := func (path * string ) {
87+ if ! filepath .IsAbs (* path ) {
88+ * path = filepath .Join (pwd , * path )
7889 }
79- conf .Conf .TempDir = absPath
90+ }
91+ convertAbsPath (& conf .Conf .TempDir )
92+ convertAbsPath (& conf .Conf .BleveDir )
93+ convertAbsPath (& conf .Conf .Log .Name )
94+ convertAbsPath (& conf .Conf .Database .DBFile )
95+ if conf .Conf .DistDir != "" {
96+ convertAbsPath (& conf .Conf .DistDir )
8097 }
8198 err := os .MkdirAll (conf .Conf .TempDir , 0o777 )
8299 if err != nil {
0 commit comments