From 085bebc454abd1e80f8546aa0df5992bc1286a5a Mon Sep 17 00:00:00 2001 From: "Sam H. Smith" Date: Tue, 20 Sep 2022 23:32:54 +0200 Subject: [PATCH] [fix]: #2571: Better Kura Inspector UX. Signed-off-by: Sam H. Smith --- tools/kura_inspector/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/kura_inspector/src/main.rs b/tools/kura_inspector/src/main.rs index cad9eda95dd..ea915bc7aa7 100644 --- a/tools/kura_inspector/src/main.rs +++ b/tools/kura_inspector/src/main.rs @@ -67,11 +67,26 @@ fn main() { clippy::expect_fun_call )] fn print_blockchain(block_store_path: &Path, from_height: u64, block_count: u64) { - let block_store = StdFileBlockStore::new(block_store_path); + let mut block_store_path: std::borrow::Cow<'_, Path> = block_store_path.into(); + + if let Some(os_str_file_name) = block_store_path.file_name() { + let file_name_str = os_str_file_name.to_str().unwrap_or(""); + if file_name_str == "blocks.data" || file_name_str == "blocks.index" { + block_store_path.to_mut().pop(); + } + } + + let block_store = StdFileBlockStore::new(&block_store_path); let index_count = block_store .read_index_count() .expect("Failed to read index count from block store {block_store_path:?}."); + + if index_count == 0 { + println!("The block store is empty."); + return; + } + assert!( index_count != 0, "Index count is zero. This could be because there are no blocks in the store: {:?}",