Skip to content

Commit

Permalink
fix: Don't query the default cache directory when a custom one is set (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>
  • Loading branch information
chenxiaolong authored Sep 30, 2024
1 parent 70a5fd5 commit a37bec4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/core/src/backend/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>) -> RusticResult<Self> {
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());
Expand Down

0 comments on commit a37bec4

Please sign in to comment.