|
|
@ -149,13 +149,16 @@ func Run(rpcCfg RPCConfig) error {
|
|
|
|
|
|
|
|
|
|
|
|
// Parse ini file.
|
|
|
|
// Parse ini file.
|
|
|
|
loopDir := lncfg.CleanAndExpandPath(config.LoopDir)
|
|
|
|
loopDir := lncfg.CleanAndExpandPath(config.LoopDir)
|
|
|
|
configFile := getConfigPath(config, loopDir)
|
|
|
|
configFile, hasExplicitConfig := getConfigPath(config, loopDir)
|
|
|
|
|
|
|
|
|
|
|
|
if err := flags.IniParse(configFile, &config); err != nil {
|
|
|
|
if err := flags.IniParse(configFile, &config); err != nil {
|
|
|
|
// If it's a parsing related error, then we'll return
|
|
|
|
// File not existing is OK as long as it wasn't specified
|
|
|
|
// immediately, otherwise we can proceed as possibly the config
|
|
|
|
// explicitly. All other errors (parsing, EACCESS...) indicate
|
|
|
|
// file doesn't exist which is OK.
|
|
|
|
// misconfiguration and need to be reported. In case of
|
|
|
|
if _, ok := err.(*flags.IniError); ok {
|
|
|
|
// non-not-found FS errors there's high likelihood that other
|
|
|
|
|
|
|
|
// operations in data directory would also fail so we treat it
|
|
|
|
|
|
|
|
// as early detection of a problem.
|
|
|
|
|
|
|
|
if hasExplicitConfig || !os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -247,23 +250,24 @@ func Run(rpcCfg RPCConfig) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// getConfigPath gets our config path based on the values that are set in our
|
|
|
|
// getConfigPath gets our config path based on the values that are set in our
|
|
|
|
// config.
|
|
|
|
// config. The returned bool is set to true if the config file path was set
|
|
|
|
func getConfigPath(cfg Config, loopDir string) string {
|
|
|
|
// explicitly by the user and thus should not be ignored if it doesn't exist.
|
|
|
|
|
|
|
|
func getConfigPath(cfg Config, loopDir string) (string, bool) {
|
|
|
|
// If the config file path provided by the user is set, then we just
|
|
|
|
// If the config file path provided by the user is set, then we just
|
|
|
|
// use this value.
|
|
|
|
// use this value.
|
|
|
|
if cfg.ConfigFile != defaultConfigFile {
|
|
|
|
if cfg.ConfigFile != defaultConfigFile {
|
|
|
|
return lncfg.CleanAndExpandPath(cfg.ConfigFile)
|
|
|
|
return lncfg.CleanAndExpandPath(cfg.ConfigFile), true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the user has set a loop directory that is different to the default
|
|
|
|
// If the user has set a loop directory that is different to the default
|
|
|
|
// we will use this loop directory as the location of our config file.
|
|
|
|
// we will use this loop directory as the location of our config file.
|
|
|
|
// We do not namespace by network, because this is a custom loop dir.
|
|
|
|
// We do not namespace by network, because this is a custom loop dir.
|
|
|
|
if loopDir != LoopDirBase {
|
|
|
|
if loopDir != LoopDirBase {
|
|
|
|
return filepath.Join(loopDir, defaultConfigFilename)
|
|
|
|
return filepath.Join(loopDir, defaultConfigFilename), false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, we are using our default loop directory, and the user did
|
|
|
|
// Otherwise, we are using our default loop directory, and the user did
|
|
|
|
// not set a config file path. We use our default loop dir, namespaced
|
|
|
|
// not set a config file path. We use our default loop dir, namespaced
|
|
|
|
// by network.
|
|
|
|
// by network.
|
|
|
|
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename)
|
|
|
|
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename), false
|
|
|
|
}
|
|
|
|
}
|
|
|
|