Skip to content
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

cmd/geth: make it possible to autopilot removedb #28725

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 32 additions & 9 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ import (
)

var (
removeStateDataFlag = &cli.BoolFlag{
Name: "remove.state",
Usage: "If set, selects the state data for removal",
}
removeChainDataFlag = &cli.BoolFlag{
Name: "remove.chain",
Usage: "If set, selects the state data for removal",
}

removedbCommand = &cli.Command{
Action: removeDB,
Name: "removedb",
Usage: "Remove blockchain and state databases",
Action: removeDB,
Name: "removedb",
Usage: "Remove blockchain and state databases. If arguments are provided, " +
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
"they are interpreted as comma-separated answers to questions.",
ArgsUsage: "",
Flags: utils.DatabaseFlags,
Flags: flags.Merge(utils.DatabaseFlags,
[]cli.Flag{removeStateDataFlag, removeChainDataFlag}),
Description: `
Remove blockchain and state databases`,
}
Expand Down Expand Up @@ -211,11 +222,11 @@ func removeDB(ctx *cli.Context) error {
}
// Delete state data
statePaths := []string{rootDir, filepath.Join(ancientDir, rawdb.StateFreezerName)}
confirmAndRemoveDB(statePaths, "state data")
confirmAndRemoveDB(statePaths, "state data", ctx, removeStateDataFlag.Name)

// Delete ancient chain
chainPaths := []string{filepath.Join(ancientDir, rawdb.ChainFreezerName)}
confirmAndRemoveDB(chainPaths, "ancient chain")
confirmAndRemoveDB(chainPaths, "ancient chain", ctx, removeChainDataFlag.Name)
return nil
}

Expand All @@ -238,14 +249,26 @@ func removeFolder(dir string) {

// confirmAndRemoveDB prompts the user for a last confirmation and removes the
// list of folders if accepted.
func confirmAndRemoveDB(paths []string, kind string) {
func confirmAndRemoveDB(paths []string, kind string, ctx *cli.Context, removeFlagName string) {
var (
confirm bool
err error
)
msg := fmt.Sprintf("Location(s) of '%s': \n", kind)
for _, path := range paths {
msg += fmt.Sprintf("\t- %s\n", path)
}
fmt.Println(msg)

confirm, err := prompt.Stdin.PromptConfirm(fmt.Sprintf("Remove '%s'?", kind))
if ctx.IsSet(removeFlagName) {
confirm = ctx.Bool(removeFlagName)
if confirm {
fmt.Printf("Remove '%s'? [y/n] y\n", kind)
} else {
fmt.Printf("Remove '%s'? [y/n] n\n", kind)
}
} else {
confirm, err = prompt.Stdin.PromptConfirm(fmt.Sprintf("Remove '%s'?", kind))
}
switch {
case err != nil:
utils.Fatalf("%v", err)
Expand Down