commit dd98188ce06c09c666414e45ab54a4fd260b0d59 (tree)
parent a7c9d11b289b2140430f2666968bddb02a6f1a1f
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sat, 27 Dec 2025 10:52:17 -0800
std.Io.Threaded: mostly implement fileSetTimestamps for Windows
it's still missing the case of setting to now (which was also not
implemented before)
Diffstat:
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
@@ -6046,11 +6046,34 @@ fn fileSetTimestamps(
if (is_windows) {
try current_thread.checkCancel();
- const atime_ft = windows.nanoSecondsToFileTime(options.access_time);
- const mtime_ft = windows.nanoSecondsToFileTime(options.modify_time);
+ var access_time_buffer: windows.FILETIME = undefined;
+ var modify_time_buffer: windows.FILETIME = undefined;
+ var system_time_buffer: windows.LARGE_INTEGER = undefined;
+
+ if (options.access_timestamp == .now or options.modify_timestamp == .now) {
+ system_time_buffer = windows.ntdll.RtlGetSystemTimePrecise();
+ }
+
+ const access_ptr = switch (options.access_timestamp) {
+ .unchanged => null,
+ .now => @panic("TODO do SystemTimeToFileTime logic here"),
+ .new => |ts| p: {
+ access_time_buffer = windows.nanoSecondsToFileTime(ts);
+ break :p &access_time_buffer;
+ },
+ };
+
+ const modify_ptr = switch (options.modify_timestamp) {
+ .unchanged => null,
+ .now => @panic("TODO do SystemTimeToFileTime logic here"),
+ .new => |ts| p: {
+ modify_time_buffer = windows.nanoSecondsToFileTime(ts);
+ break :p &modify_time_buffer;
+ },
+ };
// https://github.com/ziglang/zig/issues/1840
- const rc = windows.kernel32.SetFileTime(file.handle, null, &atime_ft, &mtime_ft);
+ const rc = windows.kernel32.SetFileTime(file.handle, null, access_ptr, modify_ptr);
if (rc == 0) {
switch (windows.GetLastError()) {
else => |err| return windows.unexpectedError(err),
@@ -6060,8 +6083,8 @@ fn fileSetTimestamps(
}
if (native_os == .wasi and !builtin.link_libc) {
- const atim = timestampToPosix(options.access_time.nanoseconds).toTimestamp();
- const mtim = timestampToPosix(options.modify_time.nanoseconds).toTimestamp();
+ const atim = timestampToPosix(options.access_timestamp.nanoseconds).toTimestamp();
+ const mtim = timestampToPosix(options.modify_timestamp.nanoseconds).toTimestamp();
try current_thread.beginSyscall();
while (true) switch (std.os.wasi.fd_filestat_set_times(file.handle, atim, mtim, .{
.ATIM = true,