authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-02-26 20:22:11-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-27 15:59:50-08:00
logae7f3fc360ce2f72611b5ef6abc6f21d31f82870
tree63f0dd22c004da965440985d22c08395f2eed32c
parent30bf8d7147a337444df51926199b70dc152a8283

Eliminate `error.InvalidHandle` from OpenError and RealPathError

InvalidHandle in OpenError is no longer a possible error on any platform. In the past it was able to be returned in `openOptionsFromFlagsWasi`, but the implementation was changed in 7680c5330cbc9141b9a5444e30c512b6068ab50d to make it no longer possible. InvalidHandle in RealPathError was a holdover from before d5312d53a066092ba9efd687e25b29a87eb6290c, which made realpath a compile error on WASI. However, InvalidHandle was also a possible error in the FreeBSD fallback implementation added in 537624734c4db9e0cdbdc0ebce57375d17172a70. This commit changes the FreeBSD fallback implementation to return FileNotFound instead of InvalidHandle which matches how EBADF is handled in all the other `realpath` implementations (including the FreeBSD non-fallback implementation). Closes #19084

5 files changed, 1 insertions(+), 19 deletions(-)

lib/std/child_process.zig-1
......@@ -519,7 +519,6 @@ pub const ChildProcess = struct {
519519 error.DeviceBusy => unreachable,
520520 error.FileLocksNotSupported => unreachable,
521521 error.BadPathName => unreachable, // Windows-only
522 error.InvalidHandle => unreachable, // WASI-only
523522 error.WouldBlock => unreachable,
524523 error.NetworkNotFound => unreachable, // Windows-only
525524 else => |e| return e,
lib/std/fs.zig-1
......@@ -526,7 +526,6 @@ pub const SelfExePathError = error{
526526 PipeBusy,
527527 NotLink,
528528 PathAlreadyExists,
529 InvalidHandle,
530529
531530 /// On Windows, `\\server` or `\\server\share` was not found.
532531 NetworkNotFound,
lib/std/fs/Dir.zig-6
......@@ -742,7 +742,6 @@ pub fn walk(self: Dir, allocator: Allocator) !Walker {
742742pub const OpenError = error{
743743 FileNotFound,
744744 NotDir,
745 InvalidHandle,
746745 AccessDenied,
747746 SymLinkLoop,
748747 ProcessFdQuotaExceeded,
......@@ -1847,7 +1846,6 @@ pub fn readFileAllocOptions(
18471846}
18481847
18491848pub const DeleteTreeError = error{
1850 InvalidHandle,
18511849 AccessDenied,
18521850 FileTooBig,
18531851 SymLinkLoop,
......@@ -1930,7 +1928,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {
19301928 break :handle_entry;
19311929 },
19321930
1933 error.InvalidHandle,
19341931 error.AccessDenied,
19351932 error.SymLinkLoop,
19361933 error.ProcessFdQuotaExceeded,
......@@ -2026,7 +2023,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {
20262023 continue :process_stack;
20272024 },
20282025
2029 error.InvalidHandle,
20302026 error.AccessDenied,
20312027 error.SymLinkLoop,
20322028 error.ProcessFdQuotaExceeded,
......@@ -2132,7 +2128,6 @@ fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint
21322128 continue :dir_it;
21332129 },
21342130
2135 error.InvalidHandle,
21362131 error.AccessDenied,
21372132 error.SymLinkLoop,
21382133 error.ProcessFdQuotaExceeded,
......@@ -2231,7 +2226,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File
22312226 return null;
22322227 },
22332228
2234 error.InvalidHandle,
22352229 error.AccessDenied,
22362230 error.SymLinkLoop,
22372231 error.ProcessFdQuotaExceeded,
lib/std/os.zig+1-8
......@@ -1573,9 +1573,6 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
15731573}
15741574
15751575pub const OpenError = error{
1576 /// In WASI, this error may occur when the provided file handle is invalid.
1577 InvalidHandle,
1578
15791576 /// In WASI, this error may occur when the file descriptor does
15801577 /// not hold the required rights to open a new resource relative to it.
15811578 AccessDenied,
......@@ -5543,9 +5540,6 @@ pub const RealPathError = error{
55435540 SharingViolation,
55445541 PipeBusy,
55455542
5546 /// On WASI, the current CWD may not be associated with an absolute path.
5547 InvalidHandle,
5548
55495543 /// Windows-only; file paths provided by the user must be valid WTF-8.
55505544 /// https://simonsapin.github.io/wtf-8/
55515545 InvalidWtf8,
......@@ -5613,7 +5607,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
56135607 error.FileLocksNotSupported => unreachable,
56145608 error.WouldBlock => unreachable,
56155609 error.FileBusy => unreachable, // not asking for write permissions
5616 error.InvalidHandle => unreachable, // WASI-only
56175610 error.InvalidUtf8 => unreachable, // WASI-only
56185611 else => |e| return e,
56195612 };
......@@ -5797,7 +5790,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
57975790 }
57985791 i += @as(usize, @intCast(kf.structsize));
57995792 }
5800 return error.InvalidHandle;
5793 return error.FileNotFound;
58015794 }
58025795 },
58035796 .dragonfly => {
lib/std/zig/system.zig-3
......@@ -739,7 +739,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
739739
740740 error.FileNotFound,
741741 error.NotDir,
742 error.InvalidHandle,
743742 error.AccessDenied,
744743 error.NoDevice,
745744 => return error.GLibCNotFound,
......@@ -775,7 +774,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
775774 error.PathAlreadyExists => unreachable, // read-only
776775 error.DeviceBusy => unreachable, // read-only
777776 error.FileBusy => unreachable, // read-only
778 error.InvalidHandle => unreachable, // should not be in the error set
779777 error.WouldBlock => unreachable, // not using O_NONBLOCK
780778 error.NoDevice => unreachable, // not asking for a special device
781779
......@@ -1012,7 +1010,6 @@ fn detectAbiAndDynamicLinker(
10121010
10131011 error.IsDir,
10141012 error.NotDir,
1015 error.InvalidHandle,
10161013 error.AccessDenied,
10171014 error.NoDevice,
10181015 error.FileNotFound,