From 95b00a51e915c76465060de6af41f7e8061099c3 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 4 Sep 2024 10:10:29 +0100 Subject: [PATCH] fix: create temp folder with looser perms --- cmd/osmosisd/cmd/root.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/osmosisd/cmd/root.go b/cmd/osmosisd/cmd/root.go index 8dcb5eaa7a6..0eb73339033 100644 --- a/cmd/osmosisd/cmd/root.go +++ b/cmd/osmosisd/cmd/root.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "math/rand" "net/http" "os" "path/filepath" @@ -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 @@ -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: