From 833d037f66197483b0c9fcafd35a4baa00127e05 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 6 Jul 2018 12:44:36 -0700 Subject: [PATCH] config: use config file within lnddir unless overwritten --- config.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/config.go b/config.go index 4092725c..de692567 100644 --- a/config.go +++ b/config.go @@ -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 }