Skip to content

Commit ce655de

Browse files
committed
feat(client-cli): implement unpack of Cardano node distribution
1 parent 9e1f5a6 commit ce655de

File tree

8 files changed

+511
-1
lines changed

8 files changed

+511
-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: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use clap::{Parser, ValueEnum};
1010
use mithril_client::MithrilResult;
1111

1212
use crate::utils::{
13-
GitHubReleaseRetriever, HttpDownloader, ReqwestGitHubApiClient, ReqwestHttpDownloader,
13+
ArchiveUnpacker, GitHubReleaseRetriever, HttpDownloader, ReqwestGitHubApiClient,
14+
ReqwestHttpDownloader,
1415
};
1516

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

82+
Self::unpack_cardano_node_distribution(&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+
8190
Ok(())
8291
}
8392

@@ -118,6 +127,19 @@ impl SnapshotConverterCommand {
118127

119128
Ok(archive_path)
120129
}
130+
131+
fn unpack_cardano_node_distribution(
132+
archive_path: &Path,
133+
target_dir: &Path,
134+
) -> MithrilResult<()> {
135+
ArchiveUnpacker::default()
136+
.unpack(archive_path, target_dir)
137+
.with_context(|| {
138+
format!("Failed to unpack distribution: {}", archive_path.display())
139+
})?;
140+
141+
Ok(())
142+
}
121143
}
122144

123145
#[cfg(test)]
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)