Skip to content

Commit 8588608

Browse files
karthiknadigCopilot
andcommitted
fix: preserve requested Conda cache prefixes (PR #490)
Add Windows regression coverage for equivalent separator styles while ensuring cache hits return the caller's requested prefix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 82feff9 commit 8588608

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

crates/pet-conda/src/lib.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ impl Conda {
182182
.get(&cache_key)
183183
.filter(|cached| &cached.fingerprint == fingerprint)
184184
{
185-
return Some(cached.details.clone());
185+
let mut details = cached.details.clone();
186+
details.environment.prefix = Some(path.to_path_buf());
187+
return Some(details);
186188
}
187189
}
188190

@@ -596,4 +598,41 @@ mod tests {
596598

597599
fs::remove_dir_all(prefix).unwrap();
598600
}
601+
602+
#[cfg(windows)]
603+
#[test]
604+
fn environment_info_cache_normalizes_windows_keys() {
605+
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
606+
607+
let prefix = std::env::temp_dir().join(format!(
608+
"pet-conda-environment-cache-case-{}-{}",
609+
std::process::id(),
610+
NEXT_ID.fetch_add(1, Ordering::Relaxed)
611+
));
612+
let conda_meta = prefix.join("conda-meta");
613+
fs::create_dir_all(&conda_meta).unwrap();
614+
fs::write(conda_meta.join("history"), "history").unwrap();
615+
616+
let alternate_separators = PathBuf::from(prefix.to_string_lossy().replace('\\', "/"));
617+
let environment = EnvironmentApi::new();
618+
let locator = Conda::from(&environment);
619+
let loads = AtomicUsize::new(0);
620+
621+
locator
622+
.get_or_load_environment_details(&prefix, || {
623+
loads.fetch_add(1, Ordering::Relaxed);
624+
Some(test_details(&prefix, 1))
625+
})
626+
.unwrap();
627+
let cached = locator
628+
.get_or_load_environment_details(&alternate_separators, || {
629+
panic!("equivalent Windows paths should reuse the cache")
630+
})
631+
.unwrap();
632+
633+
assert_eq!(loads.load(Ordering::Relaxed), 1);
634+
assert_eq!(cached.environment.prefix, Some(alternate_separators));
635+
636+
fs::remove_dir_all(prefix).unwrap();
637+
}
599638
}

0 commit comments

Comments
 (0)