Add user confirmation for removedb

This commit is contained in:
Taylor Gerring 2015-05-18 12:04:35 -05:00
parent fe41bd6fe8
commit 36a4ba3248
1 changed files with 40 additions and 5 deletions

View File

@ -549,13 +549,22 @@ func exportchain(ctx *cli.Context) {
} }
func removeDb(ctx *cli.Context) { func removeDb(ctx *cli.Context) {
fmt.Println("Removing chain and state databases...") confirm, err := readConfirm("Remove local databases?")
start := time.Now() if err != nil {
utils.Fatalf("%v", err)
}
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain")) if confirm {
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "state")) fmt.Println("Removing chain and state databases...")
start := time.Now()
fmt.Printf("Removed in %v\n", time.Since(start)) os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "state"))
fmt.Printf("Removed in %v\n", time.Since(start))
} else {
fmt.Println("Operation aborted")
}
} }
func upgradeDb(ctx *cli.Context) { func upgradeDb(ctx *cli.Context) {
@ -682,6 +691,32 @@ func hashish(x string) bool {
return err != nil return err != nil
} }
func readConfirm(prompt string) (bool, error) {
var (
input string
err error
)
prompt = prompt + " [y/N] "
if liner.TerminalSupported() {
lr := liner.NewLiner()
defer lr.Close()
input, err = lr.Prompt(prompt)
} else {
fmt.Print(prompt)
input, err = bufio.NewReader(os.Stdin).ReadString('\n')
fmt.Println()
}
if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" {
return true, nil
} else {
return false, nil
}
return false, err
}
func readPassword(prompt string, warnTerm bool) (string, error) { func readPassword(prompt string, warnTerm bool) (string, error) {
if liner.TerminalSupported() { if liner.TerminalSupported() {
lr := liner.NewLiner() lr := liner.NewLiner()