Skip to content

Commit

Permalink
backport: Fix unsafe-reset-all for working with default home (#9103) …
Browse files Browse the repository at this point in the history
…(#9113)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
  • Loading branch information
tnasu and cmwaters committed Jul 19, 2023
1 parent 14dfc96 commit 56d15db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/ostracon/commands/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
17 changes: 15 additions & 2 deletions cmd/ostracon/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ func registerFlagsRootCmd(cmd *cobra.Command) {

// ParseConfig retrieves the default environment configuration,
// sets up the Ostracon 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 {
Expand All @@ -51,7 +64,7 @@ var RootCmd = &cobra.Command{
return nil
}

config, err = ParseConfig()
config, err = ParseConfig(cmd)
if err != nil {
return err
}
Expand Down

0 comments on commit 56d15db

Please sign in to comment.