-
Notifications
You must be signed in to change notification settings - Fork 23
fix: replace emptyAppOptions with tmpAppOptions #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,9 +50,16 @@ import ( | |||||||||||||||||||||||||||||||
| "github.com/xrplevm/node/v10/app" | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type emptyAppOptions struct{} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func (ao emptyAppOptions) Get(_ string) interface{} { return nil } | ||||||||||||||||||||||||||||||||
| type tmpAppOptions struct{} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func (ao tmpAppOptions) Get(searchFlag string) interface{} { | ||||||||||||||||||||||||||||||||
| switch searchFlag { | ||||||||||||||||||||||||||||||||
| case flags.FlagHome: | ||||||||||||||||||||||||||||||||
| return tempDir(app.DefaultNodeHome) | ||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // NewRootCmd creates a new root command for a Cosmos SDK application | ||||||||||||||||||||||||||||||||
| func NewRootCmd() (*cobra.Command, sdktestutil.TestEncodingConfig) { | ||||||||||||||||||||||||||||||||
|
|
@@ -64,7 +71,7 @@ func NewRootCmd() (*cobra.Command, sdktestutil.TestEncodingConfig) { | |||||||||||||||||||||||||||||||
| dbm.NewMemDB(), | ||||||||||||||||||||||||||||||||
| nil, true, nil, | ||||||||||||||||||||||||||||||||
| 0, | ||||||||||||||||||||||||||||||||
| emptyAppOptions{}, | ||||||||||||||||||||||||||||||||
| tmpAppOptions{}, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| encodingConfig := sdktestutil.TestEncodingConfig{ | ||||||||||||||||||||||||||||||||
| InterfaceRegistry: tempApp.InterfaceRegistry(), | ||||||||||||||||||||||||||||||||
|
|
@@ -424,3 +431,13 @@ func getChainIDFromOpts(appOpts servertypes.AppOptions) (chainID string, err err | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func tempDir(defaultHome string) string { | ||||||||||||||||||||||||||||||||
| dir, err := os.MkdirTemp("", ".exrpd-tmp") | ||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||
| dir = defaultHome | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| defer os.RemoveAll(dir) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return dir | ||||||||||||||||||||||||||||||||
|
Comment on lines
+435
to
+442
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical:
🛡️ Minimal safe fix (avoid deleting on return) func tempDir(defaultHome string) string {
dir, err := os.MkdirTemp("", ".exrpd-tmp")
if err != nil {
- dir = defaultHome
+ return defaultHome
}
- defer os.RemoveAll(dir)
-
return dir
}Please move cleanup to a controlled lifecycle hook (e.g., process shutdown) instead of inside 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stabilize
FlagHomeresolution to avoid multiple temp dirs.Get(flags.FlagHome)may be called multiple times; returning a new temp dir each time can cause inconsistent home paths and temp-dir leaks. Cache the directory and switch to a pointer receiver.♻️ Suggested memoization with `sync.Once`
Also applies to: 74-74
🤖 Prompt for AI Agents