authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-28 11:04:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:52-07:00
log6c794ce7bceeefceeee43a5514e633162ee946a9
treeb8ee83006257c812be04f8ac658e0c525c7c52e0
parent9f986419bd0409c0b6b7630f0c7222b4137ead4f

std.Io.Threaded.dirOpenFileWtf16: SHARING_VIOLATION

is the error code that needs the kernel bug workaround, not ACCESS_DENIED.

2 files changed, 7 insertions(+), 7 deletions(-)

lib/std/Io/File.zig+3-3
......@@ -221,13 +221,13 @@ pub fn readPositional(file: File, io: Io, buffer: []u8, offset: u64) ReadPositio
221221
222222pub const WriteStreamingError = error{} || Io.UnexpectedError || Io.Cancelable;
223223
224pub fn write(file: File, io: Io, buffer: []const u8) WriteStreamingError!usize {
225 return @errorCast(file.pwrite(io, buffer, -1));
224pub fn writeStreaming(file: File, io: Io, buffer: [][]const u8) WriteStreamingError!usize {
225 return file.fileWriteStreaming(io, buffer);
226226}
227227
228228pub const WritePositionalError = WriteStreamingError || error{Unseekable};
229229
230pub fn writePositional(file: File, io: Io, buffer: []const u8, offset: u64) WritePositionalError!usize {
230pub fn writePositional(file: File, io: Io, buffer: [][]const u8, offset: u64) WritePositionalError!usize {
231231 return io.vtable.fileWritePositional(io.userdata, file, buffer, offset);
232232}
233233
lib/std/Io/Threaded.zig+4-4
......@@ -2120,18 +2120,18 @@ pub fn dirOpenFileWtf16(
21202120 .BAD_NETWORK_NAME => return error.NetworkNotFound, // \\server was found but \\server\share wasn't
21212121 .NO_MEDIA_IN_DEVICE => return error.NoDevice,
21222122 .INVALID_PARAMETER => |err| return w.statusBug(err),
2123 .SHARING_VIOLATION => return error.AccessDenied,
2124 .ACCESS_DENIED => {
2123 .SHARING_VIOLATION => {
21252124 // This occurs if the file attempting to be opened is a running
21262125 // executable. However, there's a kernel bug: the error may be
21272126 // incorrectly returned for an indeterminate amount of time
21282127 // after an executable file is closed. Here we work around the
21292128 // kernel bug with retry attempts.
2130 if (attempt - max_attempts == 0) return error.AccessDenied;
2129 if (attempt - max_attempts == 0) return error.SharingViolation;
21312130 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);
21322131 attempt += 1;
21332132 continue;
21342133 },
2134 .ACCESS_DENIED => return error.AccessDenied,
21352135 .PIPE_BUSY => return error.PipeBusy,
21362136 .PIPE_NOT_AVAILABLE => return error.NoDevice,
21372137 .OBJECT_PATH_SYNTAX_BAD => |err| return w.statusBug(err),
......@@ -2146,7 +2146,7 @@ pub fn dirOpenFileWtf16(
21462146 // finished with the deletion operation, and so this CreateFile
21472147 // call has failed. Here, we simulate the kernel bug being
21482148 // fixed by sleeping and retrying until the error goes away.
2149 if (attempt - max_attempts == 0) return error.AccessDenied;
2149 if (attempt - max_attempts == 0) return error.SharingViolation;
21502150 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);
21512151 attempt += 1;
21522152 continue;