diff --git a/crates/uv-cache/src/lib.rs b/crates/uv-cache/src/lib.rs index 17a5497a5..b4a139106 100644 --- a/crates/uv-cache/src/lib.rs +++ b/crates/uv-cache/src/lib.rs @@ -445,10 +445,23 @@ impl Cache { // We have to put this below the gitignore. Otherwise, if the build backend uses the rust // ignore crate it will walk up to the top level .gitignore and ignore its python source // files. - fs_err::OpenOptions::new().create(true).write(true).open( - root.join(CacheBucket::SourceDistributions.to_str()) - .join(".git"), - )?; + let phony_git = root + .join(CacheBucket::SourceDistributions.to_str()) + .join(".git"); + match fs_err::OpenOptions::new() + .create(true) + .write(true) + .open(&phony_git) + { + Ok(_) => {} + // Handle read-only caches including sandboxed environments. + Err(err) if err.kind() == io::ErrorKind::ReadOnlyFilesystem => { + if !phony_git.exists() { + return Err(err); + } + } + Err(err) => return Err(err), + } Ok(()) }