Skip to content

Commit

Permalink
fix: multiple temp directories on command executions (#3349)
Browse files Browse the repository at this point in the history
* remove temp dir when it's not needed anymore

* added changelog
  • Loading branch information
bermuell authored Sep 20, 2024
1 parent 420ac1e commit bff43d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3349-multiple-temp-dirs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix creation of multiple temp directories
([\#3349](https://github.com/cosmos/gaia/pull/3349))
6 changes: 5 additions & 1 deletion cmd/gaiad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -80,6 +81,9 @@ func NewRootCmd() *cobra.Command {
if err := tempApplication.Close(); err != nil {
panic(err)
}
if tempDir != gaia.DefaultNodeHome {
os.RemoveAll(tempDir)
}
}()

initClientCtx := client.Context{}.
Expand Down Expand Up @@ -437,7 +441,7 @@ func (a appCreator) appExport(
var tempDir = func() string {
dir, err := os.MkdirTemp("", ".gaia")
if err != nil {
dir = gaia.DefaultNodeHome
panic(fmt.Sprintf("failed creating temp directory: %s", err.Error()))
}
defer os.RemoveAll(dir)

Expand Down

0 comments on commit bff43d3

Please sign in to comment.