From 10a9eb2155ffffd5e8c7ad4d8f76f32627b6c102 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Wed, 20 Sep 2023 09:33:53 -0700 Subject: [PATCH] Address review comments --- cmd/lotus/daemon.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index dd61c9f8a1f..0fccc94a263 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -279,7 +279,27 @@ var DaemonCmd = &cli.Command{ willImportChain = true } - if cctx.Bool("remove-existing-chain") || willImportChain { + willRemoveChain := cctx.Bool("remove-existing-chain") + if willImportChain && !willRemoveChain { + // 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): ") + userInput, err := reader.ReadString('\n') + if err != nil { + return xerrors.Errorf("reading user input: %w", err) + } + userInput = strings.ToLower(strings.TrimSpace(userInput)) + + if userInput == "yes" { + willRemoveChain = true + } else if userInput == "no" { + willRemoveChain = false + } else { + return fmt.Errorf("Invalid input. Please answer with 'yes' or 'no'.") + } + } + + if willRemoveChain { lr, err := repo.NewFS(cctx.String("repo")) if err != nil { return xerrors.Errorf("error opening fs repo: %w", err)