File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,21 @@ pub(crate) struct ArtifactCache {
3636
3737impl ArtifactCache {
3838 pub ( crate ) fn new ( cache_dir : PathBuf ) -> Result < Self > {
39- Ok ( Self { cache_dir } )
39+ let cache = Self { cache_dir } ;
40+ cache. ensure_cache_exists ( ) ?;
41+ Ok ( cache)
4042 }
4143
4244 pub ( crate ) fn purge ( & self ) -> Result < ( ) > {
4345 fs:: remove_dir_all ( & self . cache_dir ) ?;
46+ self . ensure_cache_exists ( ) ?;
47+ Ok ( ( ) )
48+ }
49+
50+ fn ensure_cache_exists ( & self ) -> Result < ( ) > {
51+ if !self . cache_dir . exists ( ) {
52+ fs:: create_dir_all ( & self . cache_dir ) ?;
53+ }
4454 Ok ( ( ) )
4555 }
4656
@@ -168,6 +178,7 @@ impl ArtifactCache {
168178 return Ok ( ( ) ) ;
169179 }
170180
181+ self . ensure_cache_exists ( ) ?;
171182 fs:: rename ( cache_dir, target_dir) . context ( "could not move cache directory to target" ) ?;
172183 Ok ( ( ) )
173184 }
@@ -182,6 +193,7 @@ impl ArtifactCache {
182193 if cache_dir. exists ( ) {
183194 fs:: remove_dir_all ( & cache_dir) ?;
184195 }
196+ self . ensure_cache_exists ( ) ?;
185197
186198 debug ! ( ?target_dir, ?cache_dir, "saving artifact cache" ) ;
187199 fs:: rename ( & target_dir, & cache_dir) . context ( "could not move target directory to cache" ) ?;
You can’t perform that action at this time.
0 commit comments