From a82d7c20631b90de2f2298d351353041ac41650d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 10 Aug 2022 23:02:04 -0700 Subject: [PATCH] std: add missing error to windows.WriteFile I encountered this error today when testing the self-hosted compiler on Windows. --- lib/std/os.zig | 4 ++++ lib/std/os/windows.zig | 4 ++++ src/link.zig | 1 + src/main.zig | 1 + 4 files changed, 10 insertions(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index 1192c72629..2836ddf9c9 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -953,6 +953,10 @@ pub const WriteError = error{ OperationAborted, NotOpenForWriting, + /// The process cannot access the file because another process has locked + /// a portion of the file. Windows-only. + LockViolation, + /// This error occurs when no global event loop is configured, /// and reading from the file descriptor would block. WouldBlock, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 3e42ee5f2d..c79ccb5113 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -517,6 +517,9 @@ pub const WriteFileError = error{ OperationAborted, BrokenPipe, NotOpenForWriting, + /// The process cannot access the file because another process has locked + /// a portion of the file. + LockViolation, Unexpected, }; @@ -597,6 +600,7 @@ pub fn WriteFile( .IO_PENDING => unreachable, .BROKEN_PIPE => return error.BrokenPipe, .INVALID_HANDLE => return error.NotOpenForWriting, + .LOCK_VIOLATION => return error.LockViolation, else => |err| return unexpectedError(err), } } diff --git a/src/link.zig b/src/link.zig index a69dcc4c6e..14ae142a3f 100644 --- a/src/link.zig +++ b/src/link.zig @@ -435,6 +435,7 @@ pub const File = struct { EmitFail, NameTooLong, CurrentWorkingDirectoryUnlinked, + LockViolation, }; /// Called from within the CodeGen to lower a local variable instantion as an unnamed diff --git a/src/main.zig b/src/main.zig index c103cddcd4..971fe19e36 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4227,6 +4227,7 @@ const FmtError = error{ NotOpenForWriting, UnsupportedEncoding, ConnectionResetByPeer, + LockViolation, } || fs.File.OpenError; fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void {