Skip to content

Commit

Permalink
Remove kv_dump from the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris committed Nov 11, 2023
1 parent 8b3648f commit 3b845a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions fwdctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anyhow = "1.0.66"
env_logger = "0.10.0"
log = "0.4.17"
tokio = { version = "1.33.0", features = ["full"] }
futures-util = "0.3.29"

[dev-dependencies]
assert_cmd = "2.0.7"
Expand Down
25 changes: 20 additions & 5 deletions fwdctl/src/dump.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use std::borrow::Cow;

use clap::Args;
use firewood::{
db::{Db, DbConfig, WalConfig},
v2::api::{self},
v2::api::{self, Db as _},
};
use futures_util::StreamExt;
use log;
use tokio::task::block_in_place;

#[derive(Debug, Args)]
pub struct Options {
Expand All @@ -28,7 +30,20 @@ pub async fn run(opts: &Options) -> Result<(), api::Error> {
.wal(WalConfig::builder().max_revisions(10).build());

let db = Db::new(opts.db.clone(), &cfg.build()).await?;
Ok(block_in_place(|| {
db.kv_dump(&mut std::io::stdout().lock())
})?)
let latest_hash = db.root_hash().await?;
let latest_rev = db.revision(latest_hash).await?;
let mut stream = latest_rev.stream::<Vec<_>>(None)?;
loop {
match stream.next().await {
None => break,
Some(Ok((key, value))) => {
println!("'{}': '{}'", u8_to_string(&key), u8_to_string(&value))
}
Some(Err(e)) => return Err(e),
}
}
Ok(())
}
fn u8_to_string(data: &[u8]) -> Cow<'_, str> {
String::from_utf8_lossy(data)
}
2 changes: 1 addition & 1 deletion fwdctl/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn fwdctl_dump() -> Result<()> {
.args([tmpdb::path()])
.assert()
.success()
.stdout(predicate::str::is_empty().not());
.stdout(predicate::str::contains("2023"));

fwdctl_delete_db().map_err(|e| anyhow!(e))?;

Expand Down

0 comments on commit 3b845a5

Please sign in to comment.