Skip to content

Commit 7d35403

Browse files
committed
fixup! fix(util): preserve file permissions on unix during write_atomic
1 parent c0148a4 commit 7d35403

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

crates/cargo-util/src/paths.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Res
221221
// umask so that the new file has the same permissions as the old file.
222222
#[cfg(unix)]
223223
if let Some(perms) = perms {
224-
tmp.as_file().set_permissions(perms).unwrap();
224+
tmp.as_file().set_permissions(perms)?;
225225
}
226226

227227
tmp.persist(path)?;
@@ -867,9 +867,11 @@ mod tests {
867867
libc::S_IRWXU | libc::S_IRGRP | libc::S_IWGRP | libc::S_IROTH,
868868
));
869869

870-
let tmp = tempfile::Builder::new()
871-
.permissions(original_perms.clone())
872-
.tempfile()
870+
let tmp = tempfile::Builder::new().tempfile().unwrap();
871+
872+
// need to set the permissions after creating the file to avoid umask
873+
tmp.as_file()
874+
.set_permissions(original_perms.clone())
873875
.unwrap();
874876

875877
// after this call, the file at `tmp.path()` will not be the same as the file held by `tmp`

0 commit comments

Comments
 (0)