authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 10:52:17-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 10:52:17-08:00
logdd98188ce06c09c666414e45ab54a4fd260b0d59
treedcffc4c933601128df5e1b5c2475ce2ae9be699c
parenta7c9d11b289b2140430f2666968bddb02a6f1a1f

std.Io.Threaded: mostly implement fileSetTimestamps for Windows

it's still missing the case of setting to now (which was also not implemented before)

1 files changed, 28 insertions(+), 5 deletions(-)

lib/std/Io/Threaded.zig+28-5
...@@ -6046,11 +6046,34 @@ fn fileSetTimestamps(...@@ -6046,11 +6046,34 @@ fn fileSetTimestamps(
6046 if (is_windows) {6046 if (is_windows) {
6047 try current_thread.checkCancel();6047 try current_thread.checkCancel();
60486048
6049 const atime_ft = windows.nanoSecondsToFileTime(options.access_time);6049 var access_time_buffer: windows.FILETIME = undefined;
6050 const mtime_ft = windows.nanoSecondsToFileTime(options.modify_time);6050 var modify_time_buffer: windows.FILETIME = undefined;
6051 var system_time_buffer: windows.LARGE_INTEGER = undefined;
6052
6053 if (options.access_timestamp == .now or options.modify_timestamp == .now) {
6054 system_time_buffer = windows.ntdll.RtlGetSystemTimePrecise();
6055 }
6056
6057 const access_ptr = switch (options.access_timestamp) {
6058 .unchanged => null,
6059 .now => @panic("TODO do SystemTimeToFileTime logic here"),
6060 .new => |ts| p: {
6061 access_time_buffer = windows.nanoSecondsToFileTime(ts);
6062 break :p &access_time_buffer;
6063 },
6064 };
6065
6066 const modify_ptr = switch (options.modify_timestamp) {
6067 .unchanged => null,
6068 .now => @panic("TODO do SystemTimeToFileTime logic here"),
6069 .new => |ts| p: {
6070 modify_time_buffer = windows.nanoSecondsToFileTime(ts);
6071 break :p &modify_time_buffer;
6072 },
6073 };
60516074
6052 // https://github.com/ziglang/zig/issues/18406075 // https://github.com/ziglang/zig/issues/1840
6053 const rc = windows.kernel32.SetFileTime(file.handle, null, &atime_ft, &mtime_ft);6076 const rc = windows.kernel32.SetFileTime(file.handle, null, access_ptr, modify_ptr);
6054 if (rc == 0) {6077 if (rc == 0) {
6055 switch (windows.GetLastError()) {6078 switch (windows.GetLastError()) {
6056 else => |err| return windows.unexpectedError(err),6079 else => |err| return windows.unexpectedError(err),
...@@ -6060,8 +6083,8 @@ fn fileSetTimestamps(...@@ -6060,8 +6083,8 @@ fn fileSetTimestamps(
6060 }6083 }
60616084
6062 if (native_os == .wasi and !builtin.link_libc) {6085 if (native_os == .wasi and !builtin.link_libc) {
6063 const atim = timestampToPosix(options.access_time.nanoseconds).toTimestamp();6086 const atim = timestampToPosix(options.access_timestamp.nanoseconds).toTimestamp();
6064 const mtim = timestampToPosix(options.modify_time.nanoseconds).toTimestamp();6087 const mtim = timestampToPosix(options.modify_timestamp.nanoseconds).toTimestamp();
6065 try current_thread.beginSyscall();6088 try current_thread.beginSyscall();
6066 while (true) switch (std.os.wasi.fd_filestat_set_times(file.handle, atim, mtim, .{6089 while (true) switch (std.os.wasi.fd_filestat_set_times(file.handle, atim, mtim, .{
6067 .ATIM = true,6090 .ATIM = true,