@@ -22,6 +22,7 @@ use slog::{info, warn, Logger};
2222use std:: cmp:: max;
2323use std:: fmt:: Debug ;
2424use std:: fs;
25+ use std:: io:: IsTerminal ;
2526use std:: net:: Ipv6Addr ;
2627use std:: net:: { IpAddr , Ipv4Addr , ToSocketAddrs } ;
2728use std:: num:: NonZeroU16 ;
@@ -54,32 +55,42 @@ pub fn get_config<E: EthSpec>(
5455
5556 // If necessary, remove any existing database and configuration
5657 if client_config. data_dir ( ) . exists ( ) {
57- if cli_args. get_flag ( "purge-db-auto " ) {
58+ if cli_args. get_flag ( "purge-db-force " ) {
5859 let chain_db = client_config. get_db_path ( ) ;
5960 let freezer_db = client_config. get_freezer_db_path ( ) ;
6061 let blobs_db = client_config. get_blobs_db_path ( ) ;
6162 purge_db ( chain_db, freezer_db, blobs_db) ?;
6263 } else if cli_args. get_flag ( "purge-db" ) {
63- let stdin_inputs = cfg ! ( windows) || cli_args. get_flag ( STDIN_INPUTS_FLAG ) ;
64- eprintln ! (
65- "You are about to delete the chain database. This is irreversable \
66- and you will need to resync the chain."
67- ) ;
68- eprintln ! (
69- "Type 'confirm' to delete the database. Any other input will leave \
70- the database intact and Lighthouse will exit."
71- ) ;
72- let confirmation = read_input_from_user ( stdin_inputs) ?;
73-
74- if confirmation == PURGE_DB_CONFIRMATION {
75- eprintln ! ( "Database was deleted." ) ;
76- let chain_db = client_config. get_db_path ( ) ;
77- let freezer_db = client_config. get_freezer_db_path ( ) ;
78- let blobs_db = client_config. get_blobs_db_path ( ) ;
79- purge_db ( chain_db, freezer_db, blobs_db) ?;
64+ if std:: io:: stdin ( ) . is_terminal ( ) {
65+ let stdin_inputs = cfg ! ( windows) || cli_args. get_flag ( STDIN_INPUTS_FLAG ) ;
66+ eprintln ! (
67+ "You are about to delete the chain database. This is irreversable \
68+ and you will need to resync the chain."
69+ ) ;
70+ eprintln ! (
71+ "Type 'confirm' to delete the database. Any other input will leave \
72+ the database intact and Lighthouse will exit."
73+ ) ;
74+ let confirmation = read_input_from_user ( stdin_inputs) ?;
75+
76+ if confirmation == PURGE_DB_CONFIRMATION {
77+ eprintln ! ( "Database was deleted." ) ;
78+ let chain_db = client_config. get_db_path ( ) ;
79+ let freezer_db = client_config. get_freezer_db_path ( ) ;
80+ let blobs_db = client_config. get_blobs_db_path ( ) ;
81+ purge_db ( chain_db, freezer_db, blobs_db) ?;
82+ } else {
83+ eprintln ! ( "Database was not deleted. Lighthouse will now close." ) ;
84+ std:: process:: exit ( 1 ) ;
85+ }
8086 } else {
81- eprintln ! ( "Database was not deleted. Lighthouse will now close." ) ;
82- std:: process:: exit ( 1 ) ;
87+ warn ! (
88+ log,
89+ "The `--purge-db` flag was passed, but Lighthouse is not running \
90+ interactively. The database was not purged. Use `--purge-db-force` \
91+ or `lighthouse db purge` to purge the database without requiring \
92+ confirmation."
93+ ) ;
8394 }
8495 }
8596 }
0 commit comments