config: use config file within lnddir unless overwritten

This commit is contained in:
Wilmer Paulino 2018-07-06 12:44:36 -07:00
parent a0b2fadea3
commit 833d037f66
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -331,16 +331,23 @@ func loadConfig() (*config, error) {
// If the provided lnd directory is not the default, we'll modify the
// path to all of the files and directories that will live within it.
lndDir := cleanAndExpandPath(preCfg.LndDir)
configFilePath := cleanAndExpandPath(preCfg.ConfigFile)
if lndDir != defaultLndDir {
defaultCfg.ConfigFile = filepath.Join(lndDir, defaultConfigFilename)
defaultCfg.DataDir = filepath.Join(lndDir, defaultDataDirname)
defaultCfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
defaultCfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename)
defaultCfg.AdminMacPath = filepath.Join(lndDir, defaultAdminMacFilename)
defaultCfg.InvoiceMacPath = filepath.Join(lndDir, defaultInvoiceMacFilename)
defaultCfg.ReadMacPath = filepath.Join(lndDir, defaultReadMacFilename)
defaultCfg.LogDir = filepath.Join(lndDir, defaultLogDirname)
defaultCfg.Tor.V2PrivateKeyPath = filepath.Join(lndDir, defaultTorV2PrivateKeyFilename)
// If the config file path has not been modified by the user,
// then we'll use the default config file path. However, if the
// user has modified their lnddir, then we should assume they
// intend to use the config file within it.
if configFilePath == defaultConfigFile {
preCfg.ConfigFile = filepath.Join(lndDir, defaultConfigFilename)
}
preCfg.DataDir = filepath.Join(lndDir, defaultDataDirname)
preCfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
preCfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename)
preCfg.AdminMacPath = filepath.Join(lndDir, defaultAdminMacFilename)
preCfg.InvoiceMacPath = filepath.Join(lndDir, defaultInvoiceMacFilename)
preCfg.ReadMacPath = filepath.Join(lndDir, defaultReadMacFilename)
preCfg.LogDir = filepath.Join(lndDir, defaultLogDirname)
preCfg.Tor.V2PrivateKeyPath = filepath.Join(lndDir, defaultTorV2PrivateKeyFilename)
}
// Create the lnd directory if it doesn't already exist.
@ -364,9 +371,8 @@ func loadConfig() (*config, error) {
// Next, load any additional configuration options from the file.
var configFileError error
cfg := defaultCfg
configFile := cleanAndExpandPath(preCfg.ConfigFile)
if err := flags.IniParse(configFile, &cfg); err != nil {
cfg := preCfg
if err := flags.IniParse(cfg.ConfigFile, &cfg); err != nil {
configFileError = err
}