From 3f36f7cd1ecdbe68b9c2ef1719acccfe47f25aa8 Mon Sep 17 00:00:00 2001 From: Harish Marri Date: Fri, 20 Sep 2024 21:50:47 +0530 Subject: [PATCH] fix temp directories issue --- cmd/omniflixhubd/cmd/root.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/omniflixhubd/cmd/root.go b/cmd/omniflixhubd/cmd/root.go index 42492b9..79ceb94 100644 --- a/cmd/omniflixhubd/cmd/root.go +++ b/cmd/omniflixhubd/cmd/root.go @@ -2,9 +2,9 @@ package cmd import ( "errors" + "fmt" "io" "os" - "path/filepath" "github.com/cosmos/cosmos-sdk/baseapp" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -73,6 +73,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { if err := tempApp.Close(); err != nil { panic(err) } + if tempDir != app.DefaultNodeHome { + os.RemoveAll(tempDir) + } }() initClientCtx := client.Context{}. @@ -179,7 +182,10 @@ func addModuleInitFlags(startCmd *cobra.Command) { } func tempDir() string { - dir := filepath.Join(os.TempDir(), "."+app.Name+"-temp") + dir, err := os.MkdirTemp("", "."+app.Name+"-temp") + if err != nil { + panic(fmt.Sprintf("failed creating temp directory: %s", err.Error())) + } defer os.RemoveAll(dir) return dir