1
- use std:: { error:: Error , path:: Path , sync:: Arc } ;
1
+ use std:: { error:: Error , fs , path:: Path , sync:: Arc } ;
2
2
3
3
use clap:: Parser ;
4
4
use config:: { builder:: DefaultState , ConfigBuilder } ;
@@ -23,9 +23,15 @@ pub struct RestoreCommand {
23
23
#[ clap( long) ]
24
24
json : bool ,
25
25
26
- /// Disable immutables digest cache.
26
+ /// Disable immutables digests cache.
27
27
#[ 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 ,
29
35
30
36
/// Digest of the snapshot to download. Use the `list` command to get that information.
31
37
digest : String ,
@@ -55,7 +61,11 @@ impl RestoreCommand {
55
61
56
62
let digester = Box :: new ( CardanoImmutableDigester :: new (
57
63
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
+ ) ?,
59
69
slog_scope:: logger ( ) ,
60
70
) ) ;
61
71
let output = runtime
@@ -86,25 +96,43 @@ docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind
86
96
}
87
97
88
98
fn build_digester_cache_provider (
89
- disable_digest_cache : bool ,
99
+ disable_digests_cache : bool ,
100
+ reset_digests_cache : bool ,
90
101
config : & Config ,
91
102
) -> Result < Arc < dyn ImmutableFileDigestCacheProvider > , Box < dyn Error > > {
92
- if disable_digest_cache {
103
+ if disable_digests_cache {
93
104
return Ok ( Arc :: new ( MemoryImmutableFileDigestCacheProvider :: default ( ) ) ) ;
94
105
}
95
106
96
107
match ProjectDirs :: from ( "io" , "iohk" , "mithril" ) {
97
108
None => {
98
- warn ! ( "Could not get cache directory for immutables digests" ) ;
109
+ warn ! ( "Could not get cache directory, disabling immutables digests cache " ) ;
99
110
Ok ( Arc :: new ( MemoryImmutableFileDigestCacheProvider :: default ( ) ) )
100
111
}
101
112
Some ( project_dirs) => {
102
113
let cache_dir: & Path = project_dirs. cache_dir ( ) ;
103
114
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
+ } ) ?;
105
122
}
106
123
107
124
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
+
108
136
info ! (
109
137
"Storing/Getting immutables digests cache from: {}" ,
110
138
cache_file. display( )
0 commit comments