From b5a2505c049fe316e3e2e081d4c9628be42b51c8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 19 Apr 2022 18:17:13 +0200 Subject: [PATCH] Add unpack tests & fix typos #102 --- mithril-network/mithril-client/README.md | 2 +- .../mithril-client/src/aggregator.rs | 57 +++++++++++++++---- .../mithril-client/src/aggregator_fake.rs | 6 +- mithril-network/mithril-client/src/client.rs | 2 +- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/mithril-network/mithril-client/README.md b/mithril-network/mithril-client/README.md index b75e9c34245..c09eb4ae7a4 100644 --- a/mithril-network/mithril-client/README.md +++ b/mithril-network/mithril-client/README.md @@ -12,7 +12,7 @@ **Install Rust** - Install a [correctly configured](https://www.rust-lang.org/learn/get-started) Rust toolchain (version 1.58.0+). -- Instal Rust [Clippy](https://github.com/rust-lang/rust-clippy) component. +- Install Rust [Clippy](https://github.com/rust-lang/rust-clippy) component. ## Download source code: diff --git a/mithril-network/mithril-client/src/aggregator.rs b/mithril-network/mithril-client/src/aggregator.rs index 4955ba3da2e..c4a9957486d 100644 --- a/mithril-network/mithril-client/src/aggregator.rs +++ b/mithril-network/mithril-client/src/aggregator.rs @@ -28,8 +28,8 @@ pub trait AggregatorHandler { /// Download snapshot async fn download_snapshot(&self, digest: String, location: String) -> Result; - /// Unarchive snapshot - async fn unarchive_snapshot(&self, digest: String) -> Result; + /// Unpack snapshot + async fn unpack_snapshot(&self, digest: String) -> Result; } /// AggregatorHTTPClient is a http client for an aggregator @@ -116,7 +116,7 @@ impl AggregatorHandler for AggregatorHTTPClient { bytes_downloaded, bytes_total ); - io::stdout().flush().ok().expect("Could not flush stdout"); + io::stdout().flush().expect("Could not flush stdout"); } Ok(local_path.into_os_string().into_string().unwrap()) } @@ -127,19 +127,15 @@ impl AggregatorHandler for AggregatorHTTPClient { } } - /// Unarchive snapshot - async fn unarchive_snapshot(&self, digest: String) -> Result { + /// Unpack snapshot + async fn unpack_snapshot(&self, digest: String) -> Result { debug!("Restore snapshot {}", digest); println!("Restoring..."); let local_path = archive_file_path(digest, self.config.network.clone())?; let snapshot_file_tar_gz = fs::File::open(local_path.clone()) .map_err(|e| format!("can't open snapshot file: {}", e))?; let snapshot_file_tar = GzDecoder::new(snapshot_file_tar_gz); - let unarchive_dir_path = local_path - .clone() - .parent() - .unwrap() - .join(path::Path::new("db")); + let unarchive_dir_path = local_path.parent().unwrap().join(path::Path::new("db")); let mut snapshot_archive = Archive::new(snapshot_file_tar); snapshot_archive .unpack(&unarchive_dir_path) @@ -161,6 +157,8 @@ fn archive_file_path(digest: String, network: String) -> Result Result { - unimplemented!("Unarchive snapshot {}", digest); + /// Unpack snapshot + async fn unpack_snapshot(&self, digest: String) -> Result { + unimplemented!("Unpack snapshot {}", digest); } } diff --git a/mithril-network/mithril-client/src/client.rs b/mithril-network/mithril-client/src/client.rs index baaef16e86b..524e43f475c 100644 --- a/mithril-network/mithril-client/src/client.rs +++ b/mithril-network/mithril-client/src/client.rs @@ -102,7 +102,7 @@ where debug!("Restore snapshot {}", digest); match &self.aggregator_handler { Some(aggregator_handler) => { - match aggregator_handler.unarchive_snapshot(digest.clone()).await { + match aggregator_handler.unpack_snapshot(digest.clone()).await { Ok(to) => Ok(to), Err(err) => Err(err), }