Skip to content

Commit

Permalink
feat: set cache directory (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadim authored Nov 11, 2024
1 parent 26929a3 commit aa8a092
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions crates/rattler_cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ pub mod validation;
mod consts;
pub use consts::{PACKAGE_CACHE_DIR, REPODATA_CACHE_DIR};

/// Returns the default cache directory used by rattler.
/// Determines the default cache directory for rattler.
/// It first checks the environment variable `RATTLER_CACHE_DIR`.
/// If not set, it falls back to the standard cache directory provided by `dirs::cache_dir()/rattler/cache`.
pub fn default_cache_dir() -> anyhow::Result<PathBuf> {
Ok(dirs::cache_dir()
.ok_or_else(|| anyhow::anyhow!("could not determine cache directory for current platform"))?
.join("rattler/cache"))
std::env::var("RATTLER_CACHE_DIR")
.map(PathBuf::from)
.or_else(|_| {
dirs::cache_dir()
.ok_or_else(|| {
anyhow::anyhow!("could not determine cache directory for current platform")
})
// Append `rattler/cache` to the cache directory
.map(|mut p| {
p.push("rattler");
p.push("cache");
p
})
})
}

0 comments on commit aa8a092

Please sign in to comment.