Merge pull request #11277 from filecoin-project/0919_jie_flip_flags
Feat: Lotus Daemon CLI: Auto remove existing chain if importing chain file or snapshot
This commit is contained in:
commit
c11a5bce59
@ -1,6 +1,7 @@
|
|||||||
# Lotus changelog
|
# Lotus changelog
|
||||||
|
|
||||||
# UNRELEASED
|
# UNRELEASED
|
||||||
|
- chore: Auto remove local chain data when importing chain file or snapshot ([filecoin-project/lotus#11277](https://github.com/filecoin-project/lotus/pull/11277))
|
||||||
|
|
||||||
## New features
|
## New features
|
||||||
- feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100))
|
- feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100))
|
||||||
|
@ -269,7 +269,37 @@ var DaemonCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cctx.Bool("remove-existing-chain") {
|
chainfile := cctx.String("import-chain")
|
||||||
|
snapshot := cctx.String("import-snapshot")
|
||||||
|
willImportChain := false
|
||||||
|
if chainfile != "" || snapshot != "" {
|
||||||
|
if chainfile != "" && snapshot != "" {
|
||||||
|
return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'")
|
||||||
|
}
|
||||||
|
willImportChain = true
|
||||||
|
}
|
||||||
|
|
||||||
|
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"))
|
lr, err := repo.NewFS(cctx.String("repo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("error opening fs repo: %w", err)
|
return xerrors.Errorf("error opening fs repo: %w", err)
|
||||||
@ -289,12 +319,7 @@ var DaemonCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chainfile := cctx.String("import-chain")
|
if willImportChain {
|
||||||
snapshot := cctx.String("import-snapshot")
|
|
||||||
if chainfile != "" || snapshot != "" {
|
|
||||||
if chainfile != "" && snapshot != "" {
|
|
||||||
return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'")
|
|
||||||
}
|
|
||||||
var issnapshot bool
|
var issnapshot bool
|
||||||
if chainfile == "" {
|
if chainfile == "" {
|
||||||
chainfile = snapshot
|
chainfile = snapshot
|
||||||
|
Loading…
Reference in New Issue
Block a user