Skip to content

Commit

Permalink
fix: create temp folder with looser perms (#8670)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddyMc authored Sep 4, 2024
1 parent c633db6 commit 1bdcf05
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -355,7 +354,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
WithHomeDir(homeDir).
WithViper("OSMOSIS")

tempDir := fmt.Sprintf("%s%d", ".temp-osmosis", rand.Int())
tempDir := tempDir()
tempApp := osmosis.NewOsmosisApp(log.NewNopLogger(), cosmosdb.NewMemDB(), nil, true, map[int64]bool{}, tempDir, 5, sims.EmptyAppOptions{}, osmosis.EmptyWasmOpts, baseapp.SetChainID("osmosis-1"))

// Allows you to add extra params to your client.toml
Expand Down Expand Up @@ -473,11 +472,21 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
if err := autoCliOpts(initClientCtx, tempApp).EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
os.RemoveAll(tempDir)

return rootCmd, encodingConfig
}

// tempDir create a temporary directory to initialize the command line client
func tempDir() string {
dir, err := os.MkdirTemp("", "osmosisd")
if err != nil {
dir = osmosis.DefaultNodeHome
}
defer os.RemoveAll(dir)

return dir
}

// overwriteConfigTomlValues overwrites config.toml values. Returns error if config.toml does not exist
//
// Currently, overwrites:
Expand Down

0 comments on commit 1bdcf05

Please sign in to comment.