backport: Fix unsafe-reset-all for working with default home (#9103) (#9113)

This commit is contained in:
Callum Waters
2022-08-01 17:35:22 +02:00
committed by GitHub
parent 7e902dc79a
commit 708a62fc31
3 changed files with 20 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ var ResetStateCmd = &cobra.Command{
Short: "Remove all the data and WAL",
PreRun: deprecateSnakeCase,
RunE: func(cmd *cobra.Command, args []string) (err error) {
config, err = ParseConfig()
config, err = ParseConfig(cmd)
if err != nil {
return err
}
@@ -54,7 +54,7 @@ var ResetPrivValidatorCmd = &cobra.Command{
// XXX: this is totally unsafe.
// it's only suitable for testnets.
func resetAllCmd(cmd *cobra.Command, args []string) (err error) {
config, err = ParseConfig()
config, err = ParseConfig(cmd)
if err != nil {
return err
}
@@ -71,7 +71,7 @@ func resetAllCmd(cmd *cobra.Command, args []string) (err error) {
// XXX: this is totally unsafe.
// it's only suitable for testnets.
func resetPrivValidator(cmd *cobra.Command, args []string) (err error) {
config, err = ParseConfig()
config, err = ParseConfig(cmd)
if err != nil {
return err
}

View File

@@ -29,12 +29,25 @@ func registerFlagsRootCmd(cmd *cobra.Command) {
// ParseConfig retrieves the default environment configuration,
// sets up the Tendermint root and ensures that the root exists
func ParseConfig() (*cfg.Config, error) {
func ParseConfig(cmd *cobra.Command) (*cfg.Config, error) {
conf := cfg.DefaultConfig()
err := viper.Unmarshal(conf)
if err != nil {
return nil, err
}
var home string
if os.Getenv("TMHOME") != "" {
home = os.Getenv("TMHOME")
} else {
home, err = cmd.Flags().GetString(cli.HomeFlag)
if err != nil {
return nil, err
}
}
conf.RootDir = home
conf.SetRoot(conf.RootDir)
cfg.EnsureRoot(conf.RootDir)
if err := conf.ValidateBasic(); err != nil {
@@ -52,7 +65,7 @@ var RootCmd = &cobra.Command{
return nil
}
config, err = ParseConfig()
config, err = ParseConfig(cmd)
if err != nil {
return err
}