authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 11:18:16-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 11:18:16-08:00
log212968c574ada30dd593dddf6d5c0cfd962459e0
tree5f64e1ba76b4f5f75e5beae8f305791a29dd5867
parentc0809c9b68ad33b9963ff3da1a6ad53ca2c8b6f3

std.Io.Threaded: handle missing atime from statx


1 files changed, 20 insertions(+), 10 deletions(-)

lib/std/Io/Threaded.zig+20-10
...@@ -1934,7 +1934,7 @@ fn dirStatFileLinux(...@@ -1934,7 +1934,7 @@ fn dirStatFileLinux(
1934 try current_thread.beginSyscall();1934 try current_thread.beginSyscall();
1935 while (true) {1935 while (true) {
1936 var statx = std.mem.zeroes(linux.Statx);1936 var statx = std.mem.zeroes(linux.Statx);
1937 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_mask, &statx))) {1937 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_request, &statx))) {
1938 .SUCCESS => {1938 .SUCCESS => {
1939 current_thread.endSyscall();1939 current_thread.endSyscall();
1940 return statFromLinux(&statx);1940 return statFromLinux(&statx);
...@@ -2169,7 +2169,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {...@@ -2169,7 +2169,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
2169 try current_thread.beginSyscall();2169 try current_thread.beginSyscall();
2170 while (true) {2170 while (true) {
2171 var statx = std.mem.zeroes(linux.Statx);2171 var statx = std.mem.zeroes(linux.Statx);
2172 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_mask, &statx))) {2172 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_request, &statx))) {
2173 .SUCCESS => {2173 .SUCCESS => {
2174 current_thread.endSyscall();2174 current_thread.endSyscall();
2175 return statFromLinux(&statx);2175 return statFromLinux(&statx);
...@@ -11101,7 +11101,7 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {...@@ -11101,7 +11101,7 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
11101 };11101 };
11102}11102}
1110311103
11104const linux_statx_mask: std.os.linux.STATX = .{11104const linux_statx_request: std.os.linux.STATX = .{
11105 .TYPE = true,11105 .TYPE = true,
11106 .MODE = true,11106 .MODE = true,
11107 .ATIME = true,11107 .ATIME = true,
...@@ -11112,14 +11112,22 @@ const linux_statx_mask: std.os.linux.STATX = .{...@@ -11112,14 +11112,22 @@ const linux_statx_mask: std.os.linux.STATX = .{
11112 .NLINK = true,11112 .NLINK = true,
11113};11113};
1111411114
11115const linux_statx_check: std.os.linux.STATX = .{
11116 .TYPE = true,
11117 .MODE = true,
11118 .ATIME = false,
11119 .MTIME = true,
11120 .CTIME = true,
11121 .INO = true,
11122 .SIZE = true,
11123 .NLINK = true,
11124};
11125
11115fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {11126fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
11116 const actual_mask_int: u32 = @bitCast(stx.mask);11127 const actual_mask_int: u32 = @bitCast(stx.mask);
11117 const wanted_mask_int: u32 = @bitCast(linux_statx_mask);11128 const wanted_mask_int: u32 = @bitCast(linux_statx_check);
11118 if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;11129 if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;
1111911130
11120 const atime = stx.atime;
11121 const mtime = stx.mtime;
11122 const ctime = stx.ctime;
11123 return .{11131 return .{
11124 .inode = stx.ino,11132 .inode = stx.ino,
11125 .nlink = stx.nlink,11133 .nlink = stx.nlink,
...@@ -11135,9 +11143,11 @@ fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {...@@ -11135,9 +11143,11 @@ fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
11135 std.os.linux.S.IFSOCK => .unix_domain_socket,11143 std.os.linux.S.IFSOCK => .unix_domain_socket,
11136 else => .unknown,11144 else => .unknown,
11137 },11145 },
11138 .atime = .{ .nanoseconds = @intCast(@as(i128, atime.sec) * std.time.ns_per_s + atime.nsec) },11146 .atime = if (!stx.mask.ATIME) null else .{
11139 .mtime = .{ .nanoseconds = @intCast(@as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec) },11147 .nanoseconds = @intCast(@as(i128, stx.atime.sec) * std.time.ns_per_s + stx.atime.nsec),
11140 .ctime = .{ .nanoseconds = @intCast(@as(i128, ctime.sec) * std.time.ns_per_s + ctime.nsec) },11148 },
11149 .mtime = .{ .nanoseconds = @intCast(@as(i128, stx.mtime.sec) * std.time.ns_per_s + stx.mtime.nsec) },
11150 .ctime = .{ .nanoseconds = @intCast(@as(i128, stx.ctime.sec) * std.time.ns_per_s + stx.ctime.nsec) },
11141 };11151 };
11142}11152}
1114311153