Delete full db directory with purge-chain subcommand (#1786)

Closes #1767 

Until now the `purge-chain` command would only remove the `full`
subfolder of the db folder. However there is also the `parachains` db
that currently remains and can cause problems on node restart.

Example wiht old code:
```
polkadot purge-chain --database paritydb --base-path /tmp/some-folder
Are you sure to remove "/tmp/some-folder/chains/polkadot/paritydb/full"? [y/N]: y
"/tmp/some-folder/chains/polkadot/paritydb/full" removed.
```
In this case `/tmp/some-folder/chains/polkadot/paritydb/parachains`
would remain and might cause problem on node restart because of version
conflicts as described in #1767. After this PR the whole
`/tmp/some-folder/chains/polkadot/paritydb` folder will be deleted.
This commit is contained in:
Sebastian Kunert
2023-10-05 18:44:03 +02:00
committed by GitHub
parent 51c0c24213
commit d21113c13f
2 changed files with 1 additions and 5 deletions
-4
View File
@@ -57,7 +57,6 @@ async fn purge_chain_rocksdb_works() {
assert!(cmd.wait().unwrap().success());
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(tmpdir.path().join("chains/rococo_dev/db/full").exists());
assert!(tmpdir.path().join("chains/rococo_dev/db/full/parachains").exists());
// Purge chain
let status = Command::new(cargo_bin("polkadot"))
@@ -102,7 +101,6 @@ async fn purge_chain_paritydb_works() {
assert!(cmd.wait().unwrap().success());
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/full").exists());
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/parachains").exists());
// Purge chain
let status = Command::new(cargo_bin("polkadot"))
@@ -118,8 +116,6 @@ async fn purge_chain_paritydb_works() {
// Make sure that the chain folder exists, but `db/full` is deleted.
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(!tmpdir.path().join("chains/rococo_dev/paritydb/full").exists());
// Parachains removal requires calling "purge-chain --parachains".
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/parachains").exists());
})
.await;
}
@@ -48,7 +48,7 @@ pub struct PurgeChainCmd {
impl PurgeChainCmd {
/// Run the purge command
pub fn run(&self, database_config: DatabaseSource) -> error::Result<()> {
let db_path = database_config.path().ok_or_else(|| {
let db_path = database_config.path().and_then(|p| p.parent()).ok_or_else(|| {
error::Error::Input("Cannot purge custom database implementation".into())
})?;