Skip to content

Commit 96bab77

Browse files
committed
Rename to `purge-db-force and skip in non-interactive mode
1 parent 2173514 commit 96bab77

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

beacon_node/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@ pub fn cli_app() -> Command {
911911
.display_order(0)
912912
)
913913
.arg(
914-
Arg::new("purge-db-auto")
915-
.long("purge-db-auto")
914+
Arg::new("purge-db-force")
915+
.long("purge-db-force")
916916
.action(ArgAction::SetTrue)
917917
.help_heading(FLAG_HEADER)
918918
.help("If present, the chain database will be deleted without confirmation. Use with caution.")

beacon_node/src/config.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use slog::{info, warn, Logger};
2222
use std::cmp::max;
2323
use std::fmt::Debug;
2424
use std::fs;
25+
use std::io::IsTerminal;
2526
use std::net::Ipv6Addr;
2627
use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs};
2728
use 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
}

book/src/help_bn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Flags:
567567
--purge-db
568568
If present, the chain database will be deleted. Requires manual
569569
confirmation.
570-
--purge-db-auto
570+
--purge-db-force
571571
If present, the chain database will be deleted without confirmation.
572572
Use with caution.
573573
--reconstruct-historic-states

0 commit comments

Comments
 (0)