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 {
317317 uid: uid_t,
318318 gid: gid_t,
319319 rdev: dev_t,
320 __pad1: [2]u32, // -1 because our dev_t is u64 (kernel dev_t is really u32).
320 __pad1: [2]u32,
321321 size: off_t,
322322 atim: i32,
323 atim_nsec: u32,
323 atim_nsec: i32,
324324 mtim: i32,
325 mtim_nsec: u32,
325 mtim_nsec: i32,
326326 ctim: i32,
327 ctim_nsec: u32,
327 ctim_nsec: i32,
328328 blksize: blksize_t,
329329 __pad3: u32,
330330 blocks: blkcnt_t,
lib/std/posix/test.zig+21-5
......@@ -395,11 +395,27 @@ test "fstatat" {
395395 // now repeat but using `fstatat` instead
396396 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 a
399 // result, comparing the two structures is doomed to fail.
400 if (builtin.cpu.arch == .s390x and builtin.os.tag == .linux) return error.SkipZigTest;
401
402 try expectEqual(stat, statat);
398 try expectEqual(stat.dev, statat.dev);
399 try expectEqual(stat.ino, statat.ino);
400 try expectEqual(stat.nlink, statat.nlink);
401 try expectEqual(stat.mode, statat.mode);
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 }
403419}
404420
405421test "readlinkat" {