Skip to content

Commit 9d99e92

Browse files
committed
Add --reset-digests-cache param to client
Also enhance client cache creation errors message
1 parent 0cdf44b commit 9d99e92

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

mithril-client/src/commands/restore.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{error::Error, path::Path, sync::Arc};
1+
use std::{error::Error, fs, path::Path, sync::Arc};
22

33
use clap::Parser;
44
use config::{builder::DefaultState, ConfigBuilder};
@@ -23,9 +23,15 @@ pub struct RestoreCommand {
2323
#[clap(long)]
2424
json: bool,
2525

26-
/// Disable immutables digest cache.
26+
/// Disable immutables digests cache.
2727
#[clap(long)]
28-
disable_digest_cache: bool,
28+
disable_digests_cache: bool,
29+
30+
/// If set the existing immutables digests cache will be reset.
31+
///
32+
/// Will be ignored if set in conjunction with `--disable-digests-cache`.
33+
#[clap(long)]
34+
reset_digests_cache: bool,
2935

3036
/// Digest of the snapshot to download. Use the `list` command to get that information.
3137
digest: String,
@@ -55,7 +61,11 @@ impl RestoreCommand {
5561

5662
let digester = Box::new(CardanoImmutableDigester::new(
5763
Path::new(&unpacked_path).into(),
58-
build_digester_cache_provider(self.disable_digest_cache, &config)?,
64+
build_digester_cache_provider(
65+
self.disable_digests_cache,
66+
self.reset_digests_cache,
67+
&config,
68+
)?,
5969
slog_scope::logger(),
6070
));
6171
let output = runtime
@@ -86,25 +96,43 @@ docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind
8696
}
8797

8898
fn build_digester_cache_provider(
89-
disable_digest_cache: bool,
99+
disable_digests_cache: bool,
100+
reset_digests_cache: bool,
90101
config: &Config,
91102
) -> Result<Arc<dyn ImmutableFileDigestCacheProvider>, Box<dyn Error>> {
92-
if disable_digest_cache {
103+
if disable_digests_cache {
93104
return Ok(Arc::new(MemoryImmutableFileDigestCacheProvider::default()));
94105
}
95106

96107
match ProjectDirs::from("io", "iohk", "mithril") {
97108
None => {
98-
warn!("Could not get cache directory for immutables digests");
109+
warn!("Could not get cache directory, disabling immutables digests cache");
99110
Ok(Arc::new(MemoryImmutableFileDigestCacheProvider::default()))
100111
}
101112
Some(project_dirs) => {
102113
let cache_dir: &Path = project_dirs.cache_dir();
103114
if !cache_dir.exists() {
104-
std::fs::create_dir_all(cache_dir)?;
115+
fs::create_dir_all(cache_dir).map_err(|e| {
116+
format!(
117+
"Failure when creation cache directory `{}`: {}",
118+
cache_dir.display(),
119+
e
120+
)
121+
})?;
105122
}
106123

107124
let cache_file = cache_dir.join(format!("immutables_digests_{}.json", config.network));
125+
126+
if reset_digests_cache {
127+
fs::remove_file(&cache_file).map_err(|e| {
128+
format!(
129+
"Failure when resetting digests cache file `{}`: {}",
130+
cache_file.display(),
131+
e
132+
)
133+
})?;
134+
}
135+
108136
info!(
109137
"Storing/Getting immutables digests cache from: {}",
110138
cache_file.display()

mithril-test-lab/mithril-end-to-end/src/mithril/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Client {
4545
vec![
4646
"restore".to_string(),
4747
// Disable immutable digests cache as they will changes between two e2e executions
48-
"--disable-digest-cache".to_string(),
48+
"--disable-digests-cache".to_string(),
4949
digest,
5050
]
5151
}

0 commit comments

Comments
 (0)