authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-07 16:36:52+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-07 16:36:52+02:00
log8843631f7ecfe0a7756a2f1f0bc99a24b57c2fcc
treea07e3a2d22e61650a16e9f1862673a515d4393a2
parent63c5329156b0c77ada4dcba6086d75f31d5353f7
parentcf47d283d101e5d8e0d1ca7ec427d40efc40f358
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24709 from rootbeer/24380-fstatat-race-fix


2 files changed, 25 insertions(+), 9 deletions(-)

lib/std/os/linux/mips.zig+4-4
...@@ -317,14 +317,14 @@ pub const Stat = extern struct {...@@ -317,14 +317,14 @@ pub const Stat = extern struct {
317 uid: uid_t,317 uid: uid_t,
318 gid: gid_t,318 gid: gid_t,
319 rdev: dev_t,319 rdev: dev_t,
320 __pad1: [2]u32, // -1 because our dev_t is u64 (kernel dev_t is really u32).320 __pad1: [2]u32,
321 size: off_t,321 size: off_t,
322 atim: i32,322 atim: i32,
323 atim_nsec: u32,323 atim_nsec: i32,
324 mtim: i32,324 mtim: i32,
325 mtim_nsec: u32,325 mtim_nsec: i32,
326 ctim: i32,326 ctim: i32,
327 ctim_nsec: u32,327 ctim_nsec: i32,
328 blksize: blksize_t,328 blksize: blksize_t,
329 __pad3: u32,329 __pad3: u32,
330 blocks: blkcnt_t,330 blocks: blkcnt_t,
lib/std/posix/test.zig+21-5
...@@ -395,11 +395,27 @@ test "fstatat" {...@@ -395,11 +395,27 @@ test "fstatat" {
395 // now repeat but using `fstatat` instead395 // now repeat but using `fstatat` instead
396 const statat = try posix.fstatat(tmp.dir.fd, "file.txt", posix.AT.SYMLINK_NOFOLLOW);396 const statat = try posix.fstatat(tmp.dir.fd, "file.txt", posix.AT.SYMLINK_NOFOLLOW);
397397
398 // s390x-linux does not have nanosecond precision for fstat(), but it does for fstatat(). As a398 try expectEqual(stat.dev, statat.dev);
399 // result, comparing the two structures is doomed to fail.399 try expectEqual(stat.ino, statat.ino);
400 if (builtin.cpu.arch == .s390x and builtin.os.tag == .linux) return error.SkipZigTest;400 try expectEqual(stat.nlink, statat.nlink);
401401 try expectEqual(stat.mode, statat.mode);
402 try expectEqual(stat, statat);402 try expectEqual(stat.uid, statat.uid);
403 try expectEqual(stat.gid, statat.gid);
404 try expectEqual(stat.rdev, statat.rdev);
405 try expectEqual(stat.size, statat.size);
406 try expectEqual(stat.blksize, statat.blksize);
407
408 // The stat.blocks/statat.blocks count is managed by the filesystem and may
409 // change if the file is stored in a journal or "inline".
410 // try expectEqual(stat.blocks, statat.blocks);
411
412 // s390x-linux does not have nanosecond precision for fstat(), but it does for
413 // fstatat(). As a result, comparing the timestamps isn't worth the effort
414 if (!(builtin.cpu.arch == .s390x and builtin.os.tag == .linux)) {
415 try expectEqual(stat.atime(), statat.atime());
416 try expectEqual(stat.mtime(), statat.mtime());
417 try expectEqual(stat.ctime(), statat.ctime());
418 }
403}419}
404420
405test "readlinkat" {421test "readlinkat" {