rattler_cache/
lib.rs

1#[cfg(not(target_arch = "wasm32"))]
2use std::path::PathBuf;
3
4#[cfg(not(target_arch = "wasm32"))]
5pub mod package_cache;
6#[cfg(not(target_arch = "wasm32"))]
7pub mod run_exports_cache;
8
9#[cfg(not(target_arch = "wasm32"))]
10pub mod validation;
11
12mod consts;
13pub use consts::{PACKAGE_CACHE_DIR, REPODATA_CACHE_DIR, RUN_EXPORTS_CACHE_DIR};
14
15/// Determines the default cache directory for rattler.
16/// It first checks the environment variable `RATTLER_CACHE_DIR`.
17/// If not set, it falls back to the standard cache directory provided by `dirs::cache_dir()/rattler/cache`.
18#[cfg(not(target_arch = "wasm32"))]
19pub fn default_cache_dir() -> anyhow::Result<PathBuf> {
20    std::env::var("RATTLER_CACHE_DIR")
21        .map(PathBuf::from)
22        .or_else(|_| {
23            dirs::cache_dir()
24                .ok_or_else(|| {
25                    anyhow::anyhow!("could not determine cache directory for current platform")
26                })
27                // Append `rattler/cache` to the cache directory
28                .map(|mut p| {
29                    p.push("rattler");
30                    p.push("cache");
31                    p
32                })
33        })
34}