From 04338d31c9ea6e2384dd8bfd8c9a03494ccd5cfa Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 28 May 2014 12:55:37 -0500 Subject: [PATCH] Handle alternate data directories. If the data directory is modified on the command line or from the config file, all paths relative to the directory, if unmodified, must be changed to reference it. --- config.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 1102177..9d6bb83 100644 --- a/config.go +++ b/config.go @@ -39,7 +39,6 @@ const ( var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) btcwalletHomeDir = btcutil.AppDataDir("btcwallet", false) - defaultCAFile = filepath.Join(btcwalletHomeDir, defaultCAFilename) btcdHomedirCAFile = filepath.Join(btcdHomeDir, "rpc.cert") defaultConfigFile = filepath.Join(btcwalletHomeDir, defaultConfigFilename) defaultDataDir = btcwalletHomeDir @@ -206,6 +205,18 @@ func loadConfig() (*config, []string, error) { log.Warnf("%v", configFileError) } + // If an alternate data directory was specified, and paths with defaults + // relative to the data dir are unchanged, modify each path to be + // relative to the new data dir. + if cfg.DataDir != defaultDataDir { + if cfg.RPCKey == defaultRPCKeyFile { + cfg.RPCKey = filepath.Join(cfg.DataDir, "rpc.key") + } + if cfg.RPCCert == defaultRPCCertFile { + cfg.RPCCert = filepath.Join(cfg.DataDir, "rpc.cert") + } + } + // Choose the active network params based on the mainnet net flag. if cfg.MainNet { activeNet = &mainNetParams @@ -229,7 +240,7 @@ func loadConfig() (*config, []string, error) { // If CAFile is unset, choose either the copy or local btcd cert. if cfg.CAFile == "" { - cfg.CAFile = defaultCAFile + cfg.CAFile = filepath.Join(cfg.DataDir, defaultCAFilename) // If the CA copy does not exist, check if we're connecting to // a local btcd and switch to its RPC cert if it exists.