-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Feat: Lotus Daemon CLI: Auto remove existing chain if importing chain file or snapshot #11277
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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): ") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (just a bit more clear, there isn't really a default since we're forcing users to specify) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, however we couldn't differentiate between
That's why we have to ask for the user's input... |
||||||
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" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably want to handle case-sensitivity here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
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) | ||||||
|
@@ -289,12 +319,7 @@ var DaemonCmd = &cli.Command{ | |||||
} | ||||||
} | ||||||
|
||||||
chainfile := cctx.String("import-chain") | ||||||
snapshot := cctx.String("import-snapshot") | ||||||
if chainfile != "" || snapshot != "" { | ||||||
if chainfile != "" && snapshot != "" { | ||||||
return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'") | ||||||
} | ||||||
if willImportChain { | ||||||
var issnapshot bool | ||||||
if chainfile == "" { | ||||||
chainfile = snapshot | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for including this! It needs to be moved up to the
UNRELEASED
section, thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed