From 7cb3188fbce25c683a6ca43fc1a77efbbdb1321e Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sun, 11 Mar 2018 00:44:05 -0800 Subject: [PATCH] testnet cmd: ensure config dir exists. closes #1290 --- cmd/tendermint/commands/testnet.go | 11 ++++++----- types/priv_validator.go | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/tendermint/commands/testnet.go b/cmd/tendermint/commands/testnet.go index f5551a95e..3864e7ad5 100644 --- a/cmd/tendermint/commands/testnet.go +++ b/cmd/tendermint/commands/testnet.go @@ -75,15 +75,16 @@ func testnetFiles(cmd *cobra.Command, args []string) { // Initialize per-machine core directory func initMachCoreDirectory(base, mach string) error { + // Create priv_validator.json file if not present + defaultConfig := cfg.DefaultBaseConfig() dir := filepath.Join(base, mach) - err := cmn.EnsureDir(dir, 0777) + privValPath := filepath.Join(dir, defaultConfig.PrivValidator) + dir = filepath.Dir(privValPath) + err := cmn.EnsureDir(dir, 0700) if err != nil { return err } - - // Create priv_validator.json file if not present - defaultConfig := cfg.DefaultBaseConfig() - ensurePrivValidator(filepath.Join(dir, defaultConfig.PrivValidator)) + ensurePrivValidator(privValPath) return nil } diff --git a/types/priv_validator.go b/types/priv_validator.go index b1ab4710a..daa456bc0 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -98,6 +98,7 @@ type PrivValidator interface { // PrivValidatorFS implements PrivValidator using data persisted to disk // to prevent double signing. The Signer itself can be mutated to use // something besides the default, for instance a hardware signer. +// NOTE: the directory containing the privVal.filePath must already exist. type PrivValidatorFS struct { Address Address `json:"address"` PubKey crypto.PubKey `json:"pub_key"` @@ -217,18 +218,17 @@ func (privVal *PrivValidatorFS) Save() { } func (privVal *PrivValidatorFS) save() { - if privVal.filePath == "" { - cmn.PanicSanity("Cannot save PrivValidator: filePath not set") + outFile := privVal.filePath + if outFile == "" { + panic("Cannot save PrivValidator: filePath not set") } jsonBytes, err := json.Marshal(privVal) if err != nil { - // `@; BOOM!!! - cmn.PanicCrisis(err) + panic(err) } - err = cmn.WriteFileAtomic(privVal.filePath, jsonBytes, 0600) + err = cmn.WriteFileAtomic(outFile, jsonBytes, 0600) if err != nil { - // `@; BOOM!!! - cmn.PanicCrisis(err) + panic(err) } }