Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add globalhome root flag to set home root directory #927

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type config struct {
LogDir string `long:"logdir" description:"Directory to log output."`
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
DBTimeout time.Duration `long:"dbtimeout" description:"The timeout value to use when opening the wallet database."`
GlobalHomeRoot string `short:"g" long:"globalhomeroot" description:"Global root home directory"`

// Wallet options
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`
Expand Down Expand Up @@ -302,6 +303,28 @@ func loadConfig() (*config, []string, error) {
os.Exit(0)
}

// Check if global home root path is set and reassigns the config, datadir,
// rpc & rpccert paths to the global root
if len(preCfg.GlobalHomeRoot) > 0 {
globalAppDataDir := filepath.Join(preCfg.GlobalHomeRoot, "Btcwallet")

if _, err := os.Stat(globalAppDataDir); os.IsNotExist(err) {
perm := os.FileMode(0700)
err = os.Mkdir(globalAppDataDir, perm)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating Btcd directory: %v\n",
err)
}
}

preCfg.ConfigFile = cfgutil.NewExplicitString(filepath.Join(globalAppDataDir, defaultConfigFilename))
cfg.AppDataDir = cfgutil.NewExplicitString(globalAppDataDir)
cfg.LogDir = filepath.Join(globalAppDataDir, defaultLogDirname)
cfg.RPCKey = cfgutil.NewExplicitString(filepath.Join(globalAppDataDir, "rpc.key"))
cfg.RPCCert = cfgutil.NewExplicitString(filepath.Join(globalAppDataDir, "rpc.cert"))
cfg.CAFile = cfgutil.NewExplicitString(filepath.Join(preCfg.GlobalHomeRoot, "Btcd/rpc.cert"))
}

// Load additional config from file.
var configFileError error
parser := flags.NewParser(&cfg, flags.Default)
Expand Down
Loading