aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-05-19 01:04:35 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-05-19 01:04:35 +0800
commit36a4ba32485fb6605ea23f03896ae8d7c4cc44ae (patch)
treed47e1ae83ea49beeea26bd143589c4e8476a0a2b /cmd/geth
parentfe41bd6fe854248d9937ba24e58baeaf672cf94e (diff)
downloaddexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar.gz
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar.bz2
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar.lz
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar.xz
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.tar.zst
dexon-36a4ba32485fb6605ea23f03896ae8d7c4cc44ae.zip
Add user confirmation for removedb
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/main.go45
1 files changed, 40 insertions, 5 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index b10347781..7db175eb9 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -549,13 +549,22 @@ func exportchain(ctx *cli.Context) {
}
func removeDb(ctx *cli.Context) {
- fmt.Println("Removing chain and state databases...")
- start := time.Now()
+ confirm, err := readConfirm("Remove local databases?")
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
- os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
- os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "state"))
+ if confirm {
+ 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) {
@@ -682,6 +691,32 @@ func hashish(x string) bool {
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) {
if liner.TerminalSupported() {
lr := liner.NewLiner()