Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/pixi_command_dispatcher/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod dependencies;
pub mod pin_compatible;
mod work_dir_key;

use std::hash::{DefaultHasher, Hash, Hasher};
use std::hash::{Hash, Hasher};

use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
pub use build_environment::BuildEnvironment;
Expand Down Expand Up @@ -231,7 +231,7 @@ fn pretty_url_name(url: &Url) -> String {
host.to_string()
} else {
// Final fallback: use a hash of the URL to avoid invalid path characters
let mut hasher = DefaultHasher::new();
let mut hasher = Xxh3::new();
url.as_str().hash(&mut hasher);
URL_SAFE_NO_PAD.encode(hasher.finish().to_ne_bytes())
}
Expand Down
5 changes: 3 additions & 2 deletions crates/pixi_command_dispatcher/src/cache/backend_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ use serde::{Deserialize, Serialize};
use std::collections::{BTreeSet, BinaryHeap};
use std::{
collections::BTreeMap,
hash::{DefaultHasher, Hash, Hasher},
hash::{Hash, Hasher},
path::{Path, PathBuf},
sync::Arc,
};
use thiserror::Error;
use xxhash_rust::xxh3::Xxh3;

// Re-export WriteResult with the correct type
pub type WriteResult = CommonWriteResult<BuildBackendMetadataCacheEntry>;
Expand Down Expand Up @@ -113,7 +114,7 @@ impl MetadataCacheKey<BuildBackendMetadataCache> for BuildBackendMetadataCacheKe
/// Computes a unique semi-human-readable string representation of the key.
/// This is what is used as the cache file name.
fn key(&self) -> CacheKeyString<BuildBackendMetadataCache> {
let mut hasher = DefaultHasher::new();
let mut hasher = Xxh3::new();
self.channel_urls.hash(&mut hasher);
// Hash the cutoffs as configured, like the prefix of the backend
// environment does, so a relative cutoff such as `14d` does not
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tracing = { workspace = true }
url = { workspace = true }
urlencoding = { version = "2.1.3" }
which = { workspace = true }
xxhash-rust = { workspace = true, features = ["xxh3"] }

[dev-dependencies]
fs-err = { workspace = true }
Expand Down
13 changes: 11 additions & 2 deletions crates/pixi_git/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use rattler_networking::LazyClient;
/// can be checked out locally.
use std::{
borrow::Cow,
hash::{DefaultHasher, Hash, Hasher},
hash::{Hash, Hasher},
path::{Path, PathBuf},
sync::Arc,
};
use tracing::instrument;
use xxhash_rust::xxh3::Xxh3;

use crate::{
GitError, GitUrl, Reporter,
Expand Down Expand Up @@ -287,7 +288,7 @@ impl Fetch {
}

pub fn cache_digest(url: &RepositoryUrl) -> String {
let mut hasher = DefaultHasher::new();
let mut hasher = Xxh3::new();
url.hash(&mut hasher);
let hash = hasher.finish();
format!("{hash:x}")
Expand Down Expand Up @@ -316,6 +317,14 @@ mod tests {
out
}

// The digest names a directory on disk, so it must not change between
// builds.
#[test]
fn cache_digest_is_stable() {
let url = RepositoryUrl::new(&"https://github.com/prefix-dev/pixi".parse().unwrap());
assert_eq!(cache_digest(&url), "218bc8dbef9a0fe8");
}

#[test]
fn env_unset_is_none() {
with_env(None, || assert_eq!(lfs_enabled_from_env(), None));
Expand Down
17 changes: 15 additions & 2 deletions crates/pixi_utils/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::hash::{DefaultHasher, Hash, Hasher};
use std::hash::{Hash, Hasher};

use rattler_conda_types::{MatchSpec, Subdir};
use xxhash_rust::xxh3::Xxh3;

/// Hash identifying a cached `pixi exec` environment by its specs, channels
/// and platform. The executed command is intentionally not part of the hash.
Expand Down Expand Up @@ -37,7 +38,7 @@ impl EnvironmentHash {
/// Directory name for the cached environment: `{prefix}-{hash}` when a
/// prefix is given, otherwise just `{hash}`.
pub fn name(&self, prefix: Option<&str>) -> String {
let mut hasher = DefaultHasher::new();
let mut hasher = Xxh3::new();
self.hash(&mut hasher);
let hash = hasher.finish();
match prefix {
Expand Down Expand Up @@ -73,6 +74,18 @@ mod tests {
);
}

// The name is a directory on disk, so it must not change between builds.
#[test]
fn name_is_stable() {
let h = EnvironmentHash::new(
vec![spec("python")],
vec!["conda-forge".into()],
Subdir::Linux64,
false,
);
assert_eq!(h.name(Some("python")), "python-5a7a16265bfee075");
}

#[test]
fn name_has_no_prefix_when_caller_passes_none() {
let h = EnvironmentHash::new(vec![spec("foo")], vec![], Subdir::Linux64, false);
Expand Down
Loading