From a37bec49f66610afbf505867896f85e685a41b9a Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Mon, 30 Sep 2024 11:40:43 -0400 Subject: [PATCH] fix: Don't query the default cache directory when a custom one is set (#285) The default cache directory is now only queried if no explicit cache path is given. This is necessary to prevent errors on platforms where the default cache directory does not exist, like Android. Signed-off-by: Andrew Gunnerson --- crates/core/src/backend/cache.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/core/src/backend/cache.rs b/crates/core/src/backend/cache.rs index 69f0eb86..d00d9699 100644 --- a/crates/core/src/backend/cache.rs +++ b/crates/core/src/backend/cache.rs @@ -237,11 +237,13 @@ impl Cache { /// [`CacheBackendErrorKind::NoCacheDirectory`]: crate::error::CacheBackendErrorKind::NoCacheDirectory /// [`CacheBackendErrorKind::FromIoError`]: crate::error::CacheBackendErrorKind::FromIoError pub fn new(id: RepositoryId, path: Option) -> RusticResult { - let mut path = path.unwrap_or({ + let mut path = if let Some(p) = path { + p + } else { let mut dir = cache_dir().ok_or_else(|| CacheBackendErrorKind::NoCacheDirectory)?; dir.push("rustic"); dir - }); + }; fs::create_dir_all(&path).map_err(CacheBackendErrorKind::FromIoError)?; cachedir::ensure_tag(&path).map_err(CacheBackendErrorKind::FromIoError)?; path.push(id.to_hex());