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

This commit is contained in:
Alex Rønne Petersen 2025-08-07 16:36:52 +02:00 committed by GitHub
commit 8843631f7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 8 deletions

View file

@ -317,14 +317,14 @@ pub const Stat = extern struct {
uid: uid_t, uid: uid_t,
gid: gid_t, gid: gid_t,
rdev: dev_t, rdev: dev_t,
__pad1: [2]u32, // -1 because our dev_t is u64 (kernel dev_t is really u32). __pad1: [2]u32,
size: off_t, size: off_t,
atim: i32, atim: i32,
atim_nsec: u32, atim_nsec: i32,
mtim: i32, mtim: i32,
mtim_nsec: u32, mtim_nsec: i32,
ctim: i32, ctim: i32,
ctim_nsec: u32, ctim_nsec: i32,
blksize: blksize_t, blksize: blksize_t,
__pad3: u32, __pad3: u32,
blocks: blkcnt_t, blocks: blkcnt_t,

View file

@ -395,11 +395,27 @@ test "fstatat" {
// now repeat but using `fstatat` instead // now repeat but using `fstatat` instead
const statat = try posix.fstatat(tmp.dir.fd, "file.txt", posix.AT.SYMLINK_NOFOLLOW); const statat = try posix.fstatat(tmp.dir.fd, "file.txt", posix.AT.SYMLINK_NOFOLLOW);
// s390x-linux does not have nanosecond precision for fstat(), but it does for fstatat(). As a try expectEqual(stat.dev, statat.dev);
// result, comparing the two structures is doomed to fail. try expectEqual(stat.ino, statat.ino);
if (builtin.cpu.arch == .s390x and builtin.os.tag == .linux) return error.SkipZigTest; try expectEqual(stat.nlink, statat.nlink);
try expectEqual(stat.mode, statat.mode);
try expectEqual(stat.uid, statat.uid);
try expectEqual(stat.gid, statat.gid);
try expectEqual(stat.rdev, statat.rdev);
try expectEqual(stat.size, statat.size);
try expectEqual(stat.blksize, statat.blksize);
try expectEqual(stat, statat); // The stat.blocks/statat.blocks count is managed by the filesystem and may
// change if the file is stored in a journal or "inline".
// try expectEqual(stat.blocks, statat.blocks);
// s390x-linux does not have nanosecond precision for fstat(), but it does for
// fstatat(). As a result, comparing the timestamps isn't worth the effort
if (!(builtin.cpu.arch == .s390x and builtin.os.tag == .linux)) {
try expectEqual(stat.atime(), statat.atime());
try expectEqual(stat.mtime(), statat.mtime());
try expectEqual(stat.ctime(), statat.ctime());
}
} }
test "readlinkat" { test "readlinkat" {