authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-06 13:47:39+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-06 13:47:39+01:00
log281dabaa880a8099b0fff752c8e1f4bdd5eec423
tree366e50e1236804bd792c9fd7373ada7bf4eaca9d
parent205f8214d8ddbc0d2bc0c7ba75e10688e260acfa

Compilation: unconditionally close open file handles for writable dance


2 files changed, 8 insertions(+), 3 deletions(-)

src/Compilation.zig+8-2
......@@ -2295,10 +2295,16 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
22952295 defer comp.gpa.free(o_sub_path);
22962296
22972297 // Work around windows `AccessDenied` if any files within this directory are open
2298 // by doing the makeExecutable/makeWritable dance.
2298 // by closing and reopening the file handles.
22992299 const need_writable_dance = builtin.os.tag == .windows and comp.bin_file.file != null;
23002300 if (need_writable_dance) {
2301 try comp.bin_file.makeExecutable();
2301 // We cannot just call `makeExecutable` as it makes a false assumption that we have a
2302 // file handle open only when linking an executable file. This used to be true when
2303 // our linkers were incapable of emitting relocatables and static archive. Now that
2304 // they are capable, we need to unconditionally close the file handle and re-open it
2305 // in the follow up call to `makeWritable`.
2306 comp.bin_file.file.?.close();
2307 comp.bin_file.file = null;
23022308 }
23032309
23042310 try comp.bin_file.renameTmpIntoCache(comp.local_cache_directory, tmp_dir_sub_path, o_sub_path);
src/link/Elf.zig-1
......@@ -943,7 +943,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
943943
944944 if (self.isObject() and self.zig_object_index == null) {
945945 // TODO this will become -r route I guess. For now, just copy the object file.
946 assert(self.base.file == null); // TODO uncomment once we implement -r
947946 const the_object_path = blk: {
948947 if (self.base.options.objects.len != 0) {
949948 break :blk self.base.options.objects[0].path;