2019-09-27 04:38:18 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
|
|
|
)
|
|
|
|
|
2019-10-31 09:55:32 +00:00
|
|
|
func confirmDelete(d db.Database, path string, force bool) (db.Database, error) {
|
2019-09-27 04:38:18 +00:00
|
|
|
var clearDB bool
|
|
|
|
var err error
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2019-10-31 17:38:51 +00:00
|
|
|
if force {
|
|
|
|
clearDB = true
|
|
|
|
} else {
|
|
|
|
log.Warn("This will delete your beacon chain data base stored in your data directory. " +
|
|
|
|
"Your database backups will not be removed - do you want to proceed? (Y/N)")
|
2019-09-27 04:38:18 +00:00
|
|
|
|
2019-10-31 17:38:51 +00:00
|
|
|
for {
|
|
|
|
fmt.Print(">> ")
|
2019-09-27 04:38:18 +00:00
|
|
|
|
2019-10-31 17:38:51 +00:00
|
|
|
line, _, err := reader.ReadLine()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
trimmedLine := strings.TrimSpace(string(line))
|
|
|
|
lineInput := strings.ToUpper(trimmedLine)
|
|
|
|
if lineInput != "Y" && lineInput != "N" {
|
|
|
|
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if lineInput == "Y" {
|
|
|
|
clearDB = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
log.Info("Not deleting chain database, the db will be initialized" +
|
|
|
|
" with the current data directory.")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-09-27 04:38:18 +00:00
|
|
|
|
|
|
|
if clearDB {
|
2019-10-31 17:38:51 +00:00
|
|
|
log.Warning("Removing database")
|
2019-09-27 04:38:18 +00:00
|
|
|
if err := d.ClearDB(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
d, err = db.NewDB(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}
|