diff --git a/crates/install-wheel-rs/src/wheel.rs b/crates/install-wheel-rs/src/wheel.rs index 73151e6a5..f53bf8f6e 100644 --- a/crates/install-wheel-rs/src/wheel.rs +++ b/crates/install-wheel-rs/src/wheel.rs @@ -498,7 +498,7 @@ fn install_script( .as_bytes() .to_vec(); - let mut target = tempfile::NamedTempFile::new_in(&layout.scheme.scripts)?; + let mut target = uv_fs::tempfile_in(&layout.scheme.scripts)?; let size_and_encoded_hash = copy_and_hash(&mut start.chain(script), &mut target)?; target.persist(&script_absolute).map_err(|err| { io::Error::new( diff --git a/crates/uv-fs/src/lib.rs b/crates/uv-fs/src/lib.rs index 57866ee50..5f360fd66 100644 --- a/crates/uv-fs/src/lib.rs +++ b/crates/uv-fs/src/lib.rs @@ -101,10 +101,28 @@ pub fn replace_symlink(src: impl AsRef, dst: impl AsRef) -> std::io: } } +/// Return a [`NamedTempFile`] in the specified directory. +/// +/// Sets the permissions of the temporary file to `0o644`, to match the non-temporary file default. +/// ([`NamedTempfile`] defaults to `0o600`.) +#[cfg(unix)] +pub fn tempfile_in(path: &Path) -> std::io::Result { + use std::os::unix::fs::PermissionsExt; + tempfile::Builder::new() + .permissions(std::fs::Permissions::from_mode(0o644)) + .tempfile_in(path) +} + +/// Return a [`NamedTempFile`] in the specified directory. +#[cfg(not(unix))] +pub fn tempfile_in(path: &Path) -> std::io::Result { + tempfile::Builder::new().tempfile_in(path) +} + /// Write `data` to `path` atomically using a temporary file and atomic rename. #[cfg(feature = "tokio")] pub async fn write_atomic(path: impl AsRef, data: impl AsRef<[u8]>) -> std::io::Result<()> { - let temp_file = NamedTempFile::new_in( + let temp_file = tempfile_in( path.as_ref() .parent() .expect("Write path must have a parent"), @@ -125,7 +143,7 @@ pub async fn write_atomic(path: impl AsRef, data: impl AsRef<[u8]>) -> std /// Write `data` to `path` atomically using a temporary file and atomic rename. pub fn write_atomic_sync(path: impl AsRef, data: impl AsRef<[u8]>) -> std::io::Result<()> { - let temp_file = NamedTempFile::new_in( + let temp_file = tempfile_in( path.as_ref() .parent() .expect("Write path must have a parent"),