about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-17 16:27:58 +0000
committerbors <bors@rust-lang.org>2024-04-17 16:27:58 +0000
commitc45dee5efd0c042e9d1e24559ebd0d6424d8aa70 (patch)
tree947e3082200a6e830e620f94c3506e4c641f988d /compiler/rustc_codegen_ssa/src
parent00ed4edb44ccc76d8cc992ef9f9f4634ea6d0e82 (diff)
parentabbe0d0e478eee3a599fe363e622d63967f4c4a0 (diff)
downloadrust-c45dee5efd0c042e9d1e24559ebd0d6424d8aa70.tar.gz
rust-c45dee5efd0c042e9d1e24559ebd0d6424d8aa70.zip
Auto merge of #124084 - matthiaskrgr:rollup-h42psbx, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #116957 (meta: notify #t-rustdoc Zulip stream on backport nominations)
 - #122201 (Document overrides of `clone_from()` in core/std)
 - #122723 (Use same file permissions for ar_archive_writer as the LLVM archive writer)
 - #124030 (interpret: pass MemoryKind to adjust_alloc_base_pointer)
 - #124037 (Don't ascend into parent bodies when collecting stmts for possible return suggestion)
 - #124049 (Stabilize `const_io_structs`)
 - #124062 (Add another expression to weird-exprs.rs)
 - #124066 (Don't error on subtyping of equal types)
 - #124073 (Remove libc from rust_get_test_int uses)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/archive.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs
index d336973d2b9..c99118f5156 100644
--- a/compiler/rustc_codegen_ssa/src/back/archive.rs
+++ b/compiler/rustc_codegen_ssa/src/back/archive.rs
@@ -13,7 +13,7 @@ use object::read::macho::FatArch;
 use tempfile::Builder as TempFileBuilder;
 
 use std::error::Error;
-use std::fs::File;
+use std::fs::{self, File};
 use std::io::{self, Write};
 use std::path::{Path, PathBuf};
 
@@ -280,12 +280,21 @@ impl<'a> ArArchiveBuilder<'a> {
         // This prevents programs (including rustc) from attempting to read a partial archive.
         // It also enables writing an archive with the same filename as a dependency on Windows as
         // required by a test.
-        let mut archive_tmpfile = TempFileBuilder::new()
+        // The tempfile crate currently uses 0o600 as mode for the temporary files and directories
+        // it creates. We need it to be the default mode for back compat reasons however. (See
+        // #107495) To handle this we are telling tempfile to create a temporary directory instead
+        // and then inside this directory create a file using File::create.
+        let archive_tmpdir = TempFileBuilder::new()
             .suffix(".temp-archive")
-            .tempfile_in(output.parent().unwrap_or_else(|| Path::new("")))
-            .map_err(|err| io_error_context("couldn't create a temp file", err))?;
+            .tempdir_in(output.parent().unwrap_or_else(|| Path::new("")))
+            .map_err(|err| {
+                io_error_context("couldn't create a directory for the temp file", err)
+            })?;
+        let archive_tmpfile_path = archive_tmpdir.path().join("tmp.a");
+        let mut archive_tmpfile = File::create_new(&archive_tmpfile_path)
+            .map_err(|err| io_error_context("couldn't create the temp file", err))?;
 
-        write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?;
+        write_archive_to_stream(&mut archive_tmpfile, &entries, archive_kind, false)?;
 
         let any_entries = !entries.is_empty();
         drop(entries);
@@ -293,9 +302,11 @@ impl<'a> ArArchiveBuilder<'a> {
         // output archive to the same location as an input archive on Windows.
         drop(self.src_archives);
 
-        archive_tmpfile
-            .persist(output)
-            .map_err(|err| io_error_context("failed to rename archive file", err.error))?;
+        fs::rename(archive_tmpfile_path, output)
+            .map_err(|err| io_error_context("failed to rename archive file", err))?;
+        archive_tmpdir
+            .close()
+            .map_err(|err| io_error_context("failed to remove temporary directory", err))?;
 
         Ok(any_entries)
     }