1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 14:06:58 -05:00

fix confdir env startup priority

This commit is contained in:
vcptr 2020-03-23 16:33:49 +08:00 committed by kslr
parent 3f6ef26a00
commit 94ea326d89

View File

@ -47,6 +47,9 @@ func fileExists(file string) bool {
} }
func dirExists(file string) bool { func dirExists(file string) bool {
if file == "" {
return false
}
info, err := os.Stat(file) info, err := os.Stat(file)
return err == nil && info.IsDir() return err == nil && info.IsDir()
} }
@ -65,8 +68,18 @@ func readConfDir(dirPath string) {
func getConfigFilePath() (cmdarg.Arg, error) { func getConfigFilePath() (cmdarg.Arg, error) {
if dirExists(configDir) { if dirExists(configDir) {
log.Println("Using confdir from arg:", configDir)
readConfDir(configDir) readConfDir(configDir)
} else {
if envConfDir := platform.GetConfDirPath(); dirExists(envConfDir) {
log.Println("Using confdir from env:", envConfDir)
readConfDir(envConfDir)
if len(configFiles) > 0 {
return configFiles, nil
}
}
} }
if len(configFiles) > 0 { if len(configFiles) > 0 {
return configFiles, nil return configFiles, nil
} }
@ -84,14 +97,6 @@ func getConfigFilePath() (cmdarg.Arg, error) {
return cmdarg.Arg{configFile}, nil return cmdarg.Arg{configFile}, nil
} }
if envConfDir := platform.GetConfDirPath(); dirExists(envConfDir) {
log.Println("Using confdir from env: ", envConfDir)
readConfDir(envConfDir)
if len(configFiles) > 0 {
return configFiles, nil
}
}
log.Println("Using config from STDIN") log.Println("Using config from STDIN")
return cmdarg.Arg{"stdin:"}, nil return cmdarg.Arg{"stdin:"}, nil
} }