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

fix: daemon: avoid prompting to remove chain when noninteractive #11582

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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