Skip to content

Commit

Permalink
fix: daemon: avoid prompting to remove chain when noninteractive (#11582
Browse files Browse the repository at this point in the history
)

1. Let the user specify `--remove-existing-chain=false` to avoid the
   prompt and fail if there's an existing chain.
2. Only prompt when interactive. Otherwise, _don't_ remove the chain
   by-default.
  • Loading branch information
Stebalien authored Jan 18, 2024
1 parent 2cd6aea commit 3685cb5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ var DaemonCmd = &cli.Command{
return xerrors.Errorf("enabling runtime metrics: %w", err)
}

interactive := cctx.Bool("interactive")

if cctx.Bool("manage-fdlimit") {
if _, _, err := ulimit.ManageFdLimit(); err != nil {
log.Errorf("setting file descriptor limit: %s", err)
Expand Down Expand Up @@ -299,8 +301,8 @@ var DaemonCmd = &cli.Command{
willImportChain = true
}

willRemoveChain := cctx.Bool("remove-existing-chain")
if willImportChain && !willRemoveChain {
var willRemoveChain bool
if interactive && willImportChain && !cctx.IsSet("remove-existing-chain") {
// Confirm with the user about the intention to remove chain data.
reader := bufio.NewReader(os.Stdin)
fmt.Print("Importing chain or snapshot will by default delete existing local chain data. Do you want to proceed and delete? (yes/no): ")
Expand All @@ -309,14 +311,16 @@ var DaemonCmd = &cli.Command{
return xerrors.Errorf("reading user input: %w", err)
}
userInput = strings.ToLower(strings.TrimSpace(userInput))

if userInput == "yes" {
switch userInput {
case "yes":
willRemoveChain = true
} else if userInput == "no" {
case "no":
willRemoveChain = false
} else {
default:
return fmt.Errorf("invalid input. please answer with 'yes' or 'no'")
}
} else {
willRemoveChain = cctx.Bool("remove-existing-chain")
}

if willRemoveChain {
Expand Down

0 comments on commit 3685cb5

Please sign in to comment.