Skip to content

Commit deab5c9

Browse files
committed
Do not use statx. Do not use unreachable.
1 parent cd19959 commit deab5c9

File tree

3 files changed

+0
-57
lines changed

3 files changed

+0
-57
lines changed

lib/std/fs/Dir.zig

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,31 +2722,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
27222722
const st = try std.os.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
27232723
return Stat.fromWasi(st);
27242724
}
2725-
if (native_os == .linux) {
2726-
const sub_path_c = try posix.toPosixPath(sub_path);
2727-
var stx = std.mem.zeroes(linux.Statx);
2728-
2729-
const rc = linux.statx(
2730-
self.fd,
2731-
&sub_path_c,
2732-
linux.AT.NO_AUTOMOUNT,
2733-
linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME,
2734-
&stx,
2735-
);
27362725

2737-
return switch (linux.E.init(rc)) {
2738-
.SUCCESS => Stat.fromLinux(stx),
2739-
.ACCES => error.AccessDenied,
2740-
.BADF => unreachable,
2741-
.FAULT => unreachable,
2742-
.INVAL => unreachable,
2743-
.LOOP => error.SymLinkLoop,
2744-
.NAMETOOLONG => unreachable, // Handled by posix.toPosixPath() above.
2745-
.NOENT, .NOTDIR => error.FileNotFound,
2746-
.NOMEM => error.SystemResources,
2747-
else => |err| posix.unexpectedErrno(err),
2748-
};
2749-
}
27502726
const st = try posix.fstatat(self.fd, sub_path, 0);
27512727
return Stat.fromPosix(st);
27522728
}

lib/std/fs/File.zig

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,37 +1060,6 @@ pub fn metadata(self: File) MetadataError!Metadata {
10601060
.creation_time = windows.fromSysTime(info.BasicInformation.CreationTime),
10611061
};
10621062
},
1063-
.linux => blk: {
1064-
var stx = std.mem.zeroes(linux.Statx);
1065-
1066-
// We are gathering information for Metadata, which is meant to contain all the
1067-
// native OS information about the file, so use all known flags.
1068-
const rc = linux.statx(
1069-
self.handle,
1070-
"",
1071-
linux.AT.EMPTY_PATH,
1072-
linux.STATX_BASIC_STATS | linux.STATX_BTIME,
1073-
&stx,
1074-
);
1075-
1076-
switch (linux.E.init(rc)) {
1077-
.SUCCESS => {},
1078-
.ACCES => unreachable,
1079-
.BADF => unreachable,
1080-
.FAULT => unreachable,
1081-
.INVAL => unreachable,
1082-
.LOOP => unreachable,
1083-
.NAMETOOLONG => unreachable,
1084-
.NOENT => unreachable,
1085-
.NOMEM => return error.SystemResources,
1086-
.NOTDIR => unreachable,
1087-
else => |err| return posix.unexpectedErrno(err),
1088-
}
1089-
1090-
break :blk .{
1091-
.statx = stx,
1092-
};
1093-
},
10941063
.wasi => .{ .stat = try std.os.fstat_wasi(self.handle) },
10951064
else => .{ .stat = try posix.fstat(self.handle) },
10961065
},

lib/std/posix.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,8 +4408,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
44084408
var stat = mem.zeroes(Stat);
44094409
switch (errno(fstat_sym(fd, &stat))) {
44104410
.SUCCESS => return stat,
4411-
.INVAL => unreachable,
4412-
.BADF => unreachable, // Always a race condition.
44134411
.NOMEM => return error.SystemResources,
44144412
.ACCES => return error.AccessDenied,
44154413
else => |err| return unexpectedErrno(err),

0 commit comments

Comments
 (0)