Skip to content

Commit 09588f1

Browse files
committed
ensure if target directory exists
1 parent a15fc75 commit 09588f1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/docbuilder/caching.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ pub(crate) struct ArtifactCache {
3636

3737
impl 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")?;

0 commit comments

Comments
 (0)