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...@@ -221,13 +221,13 @@ pub fn readPositional(file: File, io: Io, buffer: []u8, offset: u64) ReadPositio
221221
222pub const WriteStreamingError = error{} || Io.UnexpectedError || Io.Cancelable;222pub const WriteStreamingError = error{} || Io.UnexpectedError || Io.Cancelable;
223223
224pub fn write(file: File, io: Io, buffer: []const u8) WriteStreamingError!usize {224pub fn writeStreaming(file: File, io: Io, buffer: [][]const u8) WriteStreamingError!usize {
225 return @errorCast(file.pwrite(io, buffer, -1));225 return file.fileWriteStreaming(io, buffer);
226}226}
227227
228pub const WritePositionalError = WriteStreamingError || error{Unseekable};228pub 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 {
231 return io.vtable.fileWritePositional(io.userdata, file, buffer, offset);231 return io.vtable.fileWritePositional(io.userdata, file, buffer, offset);
232}232}
233233
lib/std/Io/Threaded.zig+4-4
...@@ -2120,18 +2120,18 @@ pub fn dirOpenFileWtf16(...@@ -2120,18 +2120,18 @@ pub fn dirOpenFileWtf16(
2120 .BAD_NETWORK_NAME => return error.NetworkNotFound, // \\server was found but \\server\share wasn't2120 .BAD_NETWORK_NAME => return error.NetworkNotFound, // \\server was found but \\server\share wasn't
2121 .NO_MEDIA_IN_DEVICE => return error.NoDevice,2121 .NO_MEDIA_IN_DEVICE => return error.NoDevice,
2122 .INVALID_PARAMETER => |err| return w.statusBug(err),2122 .INVALID_PARAMETER => |err| return w.statusBug(err),
2123 .SHARING_VIOLATION => return error.AccessDenied,2123 .SHARING_VIOLATION => {
2124 .ACCESS_DENIED => {
2125 // This occurs if the file attempting to be opened is a running2124 // This occurs if the file attempting to be opened is a running
2126 // executable. However, there's a kernel bug: the error may be2125 // executable. However, there's a kernel bug: the error may be
2127 // incorrectly returned for an indeterminate amount of time2126 // incorrectly returned for an indeterminate amount of time
2128 // after an executable file is closed. Here we work around the2127 // after an executable file is closed. Here we work around the
2129 // kernel bug with retry attempts.2128 // kernel bug with retry attempts.
2130 if (attempt - max_attempts == 0) return error.AccessDenied;2129 if (attempt - max_attempts == 0) return error.SharingViolation;
2131 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);2130 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);
2132 attempt += 1;2131 attempt += 1;
2133 continue;2132 continue;
2134 },2133 },
2134 .ACCESS_DENIED => return error.AccessDenied,
2135 .PIPE_BUSY => return error.PipeBusy,2135 .PIPE_BUSY => return error.PipeBusy,
2136 .PIPE_NOT_AVAILABLE => return error.NoDevice,2136 .PIPE_NOT_AVAILABLE => return error.NoDevice,
2137 .OBJECT_PATH_SYNTAX_BAD => |err| return w.statusBug(err),2137 .OBJECT_PATH_SYNTAX_BAD => |err| return w.statusBug(err),
...@@ -2146,7 +2146,7 @@ pub fn dirOpenFileWtf16(...@@ -2146,7 +2146,7 @@ pub fn dirOpenFileWtf16(
2146 // finished with the deletion operation, and so this CreateFile2146 // finished with the deletion operation, and so this CreateFile
2147 // call has failed. Here, we simulate the kernel bug being2147 // call has failed. Here, we simulate the kernel bug being
2148 // fixed by sleeping and retrying until the error goes away.2148 // 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;
2150 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);2150 _ = w.kernel32.SleepEx((@as(u32, 1) << attempt) >> 1, w.TRUE);
2151 attempt += 1;2151 attempt += 1;
2152 continue;2152 continue;