From a99838a1151ee0c8423a7c3d32789a7c03adbf41 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 3 Dec 2022 12:53:47 +0000 Subject: [PATCH] Make sure all input archives are unmapped before persisting the output archive --- compiler/rustc_codegen_ssa/src/back/archive.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 8274caa42bcfc..58558fb8c4ba2 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -290,11 +290,17 @@ impl<'a> ArArchiveBuilder<'a> { false, )?; + let any_entries = !entries.is_empty(); + drop(entries); + // Drop src_archives to unmap all input archives, which is necessary if we want to write the + // 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))?; - Ok(!entries.is_empty()) + Ok(any_entries) } }