Updated config to allow the ability to change the home directory (#109)

Can use -A or --appdata to change the directory for dcrd to store files.
This commit is contained in:
Dan.. Noyes 2016-04-13 15:29:26 -04:00 committed by John C. Vernaleo
parent 936b379408
commit 851569f14e
2 changed files with 16 additions and 0 deletions

View File

@ -68,6 +68,7 @@ var runServiceCommand func(string) error
//
// See loadConfig for details on the configuration load process.
type config struct {
DcrdHomeDir string `short:"A" long:"appdata" description:"Path to dcrd home directory"`
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
DataDir string `short:"b" long:"datadir" description:"Directory to store data"`
@ -313,6 +314,7 @@ func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *fl
func loadConfig() (*config, []string, error) {
// Default config.
cfg := config{
DcrdHomeDir: dcrdHomeDir,
ConfigFile: defaultConfigFile,
DebugLevel: defaultLogLevel,
MaxPeers: defaultMaxPeers,
@ -371,6 +373,18 @@ func loadConfig() (*config, []string, error) {
os.Exit(0)
}
// Update the home directory for dcrd if specified. Since the home
// directory is updated, other variables need to be updated to
// reflect the new changes.
if len(preCfg.DcrdHomeDir) > 0 {
cfg.DcrdHomeDir, _ = filepath.Abs(preCfg.DcrdHomeDir)
cfg.ConfigFile = filepath.Join(cfg.DcrdHomeDir, defaultConfigFilename)
cfg.DataDir = filepath.Join(cfg.DcrdHomeDir, defaultDataDirname)
cfg.RPCKey = filepath.Join(cfg.DcrdHomeDir, "rpc.key")
cfg.RPCCert = filepath.Join(cfg.DcrdHomeDir, "rpc.cert")
cfg.LogDir = filepath.Join(cfg.DcrdHomeDir, defaultLogDirname)
}
// Load additional config from file.
var configFileError error
parser := newConfigParser(&cfg, &serviceOpts, flags.Default)

View File

@ -44,6 +44,8 @@ func dcrdMain(serverChan chan<- *server) error {
// Show version at startup.
dcrdLog.Infof("Version %s", version())
// Show dcrd home dir location
dcrdLog.Debugf("Dcrd home dir: %s", cfg.DcrdHomeDir)
// Enable http profiling server if requested.
if cfg.Profile != "" {