Skip to content

Commit 77fec9a

Browse files
committed
feat(client-cli): implement unpack of Cardano node distribution
1 parent e60cd61 commit 77fec9a

File tree

8 files changed

+499
-1
lines changed

8 files changed

+499
-1
lines changed

Cargo.lock

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-client-cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ chrono = { workspace = true }
3131
clap = { workspace = true }
3232
cli-table = "0.5.0"
3333
config = { workspace = true }
34+
flate2 = "1.1.1"
3435
fs2 = "0.4.3"
3536
futures = "0.3.31"
3637
human_bytes = { version = "0.4.3", features = ["fast"] }
@@ -54,8 +55,10 @@ slog = { workspace = true, features = [
5455
slog-async = { workspace = true }
5556
slog-bunyan = { workspace = true }
5657
slog-term = { workspace = true }
58+
tar = "0.4.44"
5759
thiserror = { workspace = true }
5860
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
61+
zip = "4.0.0"
5962

6063
[dev-dependencies]
6164
mithril-common = { path = "../mithril-common", features = ["test_tools"] }

mithril-client-cli/src/commands/tools/snapshot_converter.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use clap::{Parser, ValueEnum};
99
use mithril_client::MithrilResult;
1010

1111
use crate::utils::{
12-
GitHubReleaseRetriever, HttpDownloader, ReqwestGitHubApiClient, ReqwestHttpDownloader,
12+
ArchiveUnpacker, GitHubReleaseRetriever, HttpDownloader, ReqwestGitHubApiClient,
13+
ReqwestHttpDownloader,
1314
};
1415

1516
const GITHUB_ORGANIZATION: &str = "IntersectMBO";
@@ -77,6 +78,15 @@ impl SnapshotConverterCommand {
7778
"Failed to download 'snapshot-converter' binary from Cardano node distribution"
7879
})?;
7980

81+
ArchiveUnpacker::default()
82+
.unpack(&archive_path, &distribution_temp_dir)
83+
.with_context(|| {
84+
format!(
85+
"Failed to unpack 'snapshot-converter' binary to directory: {}",
86+
distribution_temp_dir.display()
87+
)
88+
})?;
89+
8090
Ok(())
8191
}
8292

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
mod tar_gz_unpacker;
2+
mod unpacker;
3+
mod zip_unpacker;
4+
5+
pub use unpacker::*;
6+
7+
use mithril_client::MithrilResult;
8+
use std::path::Path;
9+
10+
#[cfg_attr(test, mockall::automock)]
11+
pub trait ArchiveFormat {
12+
fn supports(&self, archive_path: &Path) -> bool;
13+
14+
fn unpack(&self, archive_path: &Path, unpack_dir: &Path) -> MithrilResult<()>;
15+
}

0 commit comments

Comments
 (0)