rattler_cache/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::path::PathBuf;

pub mod package_cache;

pub mod validation;

mod consts;
pub use consts::{PACKAGE_CACHE_DIR, REPODATA_CACHE_DIR};

/// 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> {
    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
                })
        })
}