Merge pull request #1509 from wpaulino/lnddir-lnd-conf

config: use config file within lnddir unless overwritten
This commit is contained in:
Olaoluwa Osuntokun 2018-07-06 18:59:56 -05:00 committed by GitHub
commit cef29e74d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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