mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-30 01:28:21 -05:00
ask for confirmation during reth db drop (#4118)
This commit is contained in:
@@ -15,7 +15,10 @@ use reth_db::{
|
||||
Tables,
|
||||
};
|
||||
use reth_primitives::ChainSpec;
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
mod clear;
|
||||
mod diff;
|
||||
@@ -74,7 +77,11 @@ pub enum Subcommands {
|
||||
/// Gets the content of a table for the given key
|
||||
Get(get::Command),
|
||||
/// Deletes all database entries
|
||||
Drop,
|
||||
Drop {
|
||||
/// Bypasses the interactive confirmation and drops the database directly
|
||||
#[arg(short, long)]
|
||||
force: bool,
|
||||
},
|
||||
/// Deletes all table entries
|
||||
Clear(clear::Command),
|
||||
/// Lists current and local database versions
|
||||
@@ -178,7 +185,22 @@ impl Command {
|
||||
let tool = DbTool::new(&db, self.chain.clone())?;
|
||||
command.execute(&tool)?;
|
||||
}
|
||||
Subcommands::Drop => {
|
||||
Subcommands::Drop { force } => {
|
||||
if !force {
|
||||
// Ask for confirmation
|
||||
print!("Are you sure you want to drop the database? This cannot be undone. (y/N): ");
|
||||
// Flush the buffer to ensure the message is printed immediately
|
||||
io::stdout().flush().unwrap();
|
||||
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input).expect("Failed to read line");
|
||||
|
||||
if !input.trim().eq_ignore_ascii_case("y") {
|
||||
println!("Database drop aborted!");
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let db = open_db(&db_path, self.db.log_level)?;
|
||||
let mut tool = DbTool::new(&db, self.chain.clone())?;
|
||||
tool.drop(db_path)?;
|
||||
|
||||
Reference in New Issue
Block a user