Skip to content

Commit 8843631

Browse files
authored
Merge pull request #24709 from rootbeer/24380-fstatat-race-fix
2 parents 63c5329 + cf47d28 commit 8843631

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lib/std/os/linux/mips.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

405421
test "readlinkat" {

0 commit comments

Comments
 (0)