Skip to content

Commit ffe19a9

Browse files
authored
Merge pull request #1581 from input-output-hk/ensemble/1572/client-cli-optional-existence-check
Accept existing but empty `db` dir for `client-cli` cardano-db download
2 parents 57ab7b1 + 19f6b28 commit ffe19a9

File tree

7 files changed

+313
-185
lines changed

7 files changed

+313
-185
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-cli"
3-
version = "0.7.4"
3+
version = "0.7.5"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/commands/cardano_db/download.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
commands::client_builder,
1515
configuration::ConfigParameters,
1616
utils::{
17-
CardanoDbUnpacker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver,
17+
CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver,
1818
ProgressOutputType, ProgressPrinter,
1919
},
2020
};
@@ -131,11 +131,13 @@ impl CardanoDbDownloadCommand {
131131
fn check_local_disk_info(
132132
step_number: u16,
133133
progress_printer: &ProgressPrinter,
134-
db_dir: &PathBuf,
134+
db_dir: &Path,
135135
cardano_db: &Snapshot,
136136
) -> MithrilResult<()> {
137137
progress_printer.report_step(step_number, "Checking local disk info…")?;
138-
if let Err(e) = CardanoDbUnpacker::check_prerequisites(
138+
139+
CardanoDbDownloadChecker::ensure_dir_exist(db_dir)?;
140+
if let Err(e) = CardanoDbDownloadChecker::check_prerequisites(
139141
db_dir,
140142
cardano_db.size,
141143
cardano_db.compression_algorithm.unwrap_or_default(),
@@ -144,13 +146,6 @@ impl CardanoDbDownloadCommand {
144146
.report_step(step_number, &CardanoDbUtils::check_disk_space_error(e)?)?;
145147
}
146148

147-
std::fs::create_dir_all(db_dir).with_context(|| {
148-
format!(
149-
"Download: could not create target directory '{}'.",
150-
db_dir.display()
151-
)
152-
})?;
153-
154149
Ok(())
155150
}
156151

mithril-client-cli/src/utils/cardano_db.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use futures::Future;
33
use indicatif::{MultiProgress, ProgressBar};
44
use std::time::Duration;
55

6-
use super::CardanoDbUnpackerError;
6+
use super::CardanoDbDownloadCheckerError;
77
use mithril_client::{MithrilError, MithrilResult};
88

99
/// Utility functions for to the CardanoDb commands
@@ -12,11 +12,11 @@ pub struct CardanoDbUtils;
1212
impl CardanoDbUtils {
1313
/// Handle the error return by `check_prerequisites`
1414
pub fn check_disk_space_error(error: MithrilError) -> MithrilResult<String> {
15-
if let Some(CardanoDbUnpackerError::NotEnoughSpace {
15+
if let Some(CardanoDbDownloadCheckerError::NotEnoughSpace {
1616
left_space: _,
1717
pathdir: _,
1818
archive_size: _,
19-
}) = error.downcast_ref::<CardanoDbUnpackerError>()
19+
}) = error.downcast_ref::<CardanoDbDownloadCheckerError>()
2020
{
2121
Ok(format!("Warning: {}", error))
2222
} else {
@@ -51,7 +51,7 @@ mod test {
5151

5252
#[test]
5353
fn check_disk_space_error_should_return_warning_message_if_error_is_not_enough_space() {
54-
let not_enough_space_error = CardanoDbUnpackerError::NotEnoughSpace {
54+
let not_enough_space_error = CardanoDbDownloadCheckerError::NotEnoughSpace {
5555
left_space: 1_f64,
5656
pathdir: PathBuf::new(),
5757
archive_size: 2_f64,
@@ -66,15 +66,15 @@ mod test {
6666

6767
#[test]
6868
fn check_disk_space_error_should_return_error_if_error_is_not_error_not_enough_space() {
69-
let error = CardanoDbUnpackerError::UnpackDirectoryAlreadyExists(PathBuf::new());
69+
let error = CardanoDbDownloadCheckerError::UnpackDirectoryNotEmpty(PathBuf::new());
7070

7171
let error = CardanoDbUtils::check_disk_space_error(anyhow!(error))
7272
.expect_err("check_disk_space_error should fail");
7373

7474
assert!(
7575
matches!(
76-
error.downcast_ref::<CardanoDbUnpackerError>(),
77-
Some(CardanoDbUnpackerError::UnpackDirectoryAlreadyExists(_))
76+
error.downcast_ref::<CardanoDbDownloadCheckerError>(),
77+
Some(CardanoDbDownloadCheckerError::UnpackDirectoryNotEmpty(_))
7878
),
7979
"Unexpected error: {:?}",
8080
error

0 commit comments

Comments
 (0)