Skip to content

Commit

Permalink
CLI option force purge chain from filesystem (#855)
Browse files Browse the repository at this point in the history
* Add option to force remove db from filesysten

--force-purge-chain-db-from-filesystem can be used anywhere on command line as opposed to purge-chain which is a sub-command and use a complete different set of arguments
  • Loading branch information
simonsso authored Apr 12, 2024
1 parent f475e1c commit 880effb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ pub struct Cli {
#[arg(long)]
pub no_hardware_benchmarks: bool,

/// Purge chain from storage, for that time when purge-chain subcommand cannot be used
#[arg(long)]
pub force_purge_chain_db_from_filesystem: bool,

/// Relay chain arguments
#[arg(raw = true)]
pub relaychain_args: Vec<String>,
Expand Down
18 changes: 17 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sc_cli::{
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_runtime::traits::AccountIdConversion;
use std::net::SocketAddr;
use std::{fs, net::SocketAddr};
// default to Nodle parachain id
const DEFAULT_PARA_ID: u32 = 2026;

Expand Down Expand Up @@ -248,6 +248,22 @@ pub fn run() -> Result<()> {
.map(|e| e.para_id)
.ok_or("Could not find parachain ID in chain-spec.")?;

if cli.force_purge_chain_db_from_filesystem {
let db_path =
config.database.path().and_then(|p| p.parent()).ok_or_else(|| {
sc_cli::Error::Input("Cannot purge custom database implementation".into())
})?;
match fs::remove_dir_all(&db_path) {

Check warning on line 256 in node/src/command.rs

View workflow job for this annotation

GitHub Actions / lints

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> node/src/command.rs:256:31 | 256 | match fs::remove_dir_all(&db_path) { | ^^^^^^^^ help: change this to: `db_path` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
Ok(_) => {
log::warn!("🧯 Removed {:?}", &db_path);
}
Err(ref err) if err.kind() == std::io::ErrorKind::NotFound => {
log::error!("🧯 {:?} did not exist.", &db_path);
}
Err(err) => return Result::Err(err.into()),
}
};

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()]
Expand Down

0 comments on commit 880effb

Please sign in to comment.