diff --git a/crates/rattler_cache/src/lib.rs b/crates/rattler_cache/src/lib.rs index a6995f46a..753b867a1 100644 --- a/crates/rattler_cache/src/lib.rs +++ b/crates/rattler_cache/src/lib.rs @@ -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 { - 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 + }) + }) } diff --git a/crates/rattler_shell/Cargo.toml b/crates/rattler_shell/Cargo.toml index 2a484d19c..40543a167 100644 --- a/crates/rattler_shell/Cargo.toml +++ b/crates/rattler_shell/Cargo.toml @@ -13,6 +13,7 @@ readme.workspace = true [dependencies] enum_dispatch = { workspace = true } indexmap = { workspace = true } +fs-err = { workspace = true } itertools = { workspace = true } rattler_conda_types = { path="../rattler_conda_types", version = "0.29.0", default-features = false } serde_json = { workspace = true, features = ["preserve_order"] } diff --git a/crates/rattler_shell/src/activation.rs b/crates/rattler_shell/src/activation.rs index cc12d0b96..d5e200f16 100644 --- a/crates/rattler_shell/src/activation.rs +++ b/crates/rattler_shell/src/activation.rs @@ -3,10 +3,10 @@ //! This crate provides helper functions to activate and deactivate virtual //! environments. +use fs_err as fs; use std::{ collections::HashMap, ffi::OsStr, - fs, path::{Path, PathBuf}, process::ExitStatus, }; diff --git a/crates/rattler_shell/src/run/mod.rs b/crates/rattler_shell/src/run/mod.rs index 03d4e688b..d925b6d79 100644 --- a/crates/rattler_shell/src/run/mod.rs +++ b/crates/rattler_shell/src/run/mod.rs @@ -58,7 +58,7 @@ pub fn run_in_environment( let file = tempfile::Builder::new() .suffix(&format!(".{}", shell.extension())) .tempfile()?; - std::fs::write(file.path(), shell_script.contents()?)?; + fs_err::write(file.path(), shell_script.contents()?)?; match shell { ShellEnum::Bash(_) => Ok(Command::new(shell.executable()).arg(file.path()).output()?),