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 {...@@ -519,7 +519,6 @@ pub const ChildProcess = struct {
519 error.DeviceBusy => unreachable,519 error.DeviceBusy => unreachable,
520 error.FileLocksNotSupported => unreachable,520 error.FileLocksNotSupported => unreachable,
521 error.BadPathName => unreachable, // Windows-only521 error.BadPathName => unreachable, // Windows-only
522 error.InvalidHandle => unreachable, // WASI-only
523 error.WouldBlock => unreachable,522 error.WouldBlock => unreachable,
524 error.NetworkNotFound => unreachable, // Windows-only523 error.NetworkNotFound => unreachable, // Windows-only
525 else => |e| return e,524 else => |e| return e,
lib/std/fs.zig-1
...@@ -526,7 +526,6 @@ pub const SelfExePathError = error{...@@ -526,7 +526,6 @@ pub const SelfExePathError = error{
526 PipeBusy,526 PipeBusy,
527 NotLink,527 NotLink,
528 PathAlreadyExists,528 PathAlreadyExists,
529 InvalidHandle,
530529
531 /// On Windows, `\\server` or `\\server\share` was not found.530 /// On Windows, `\\server` or `\\server\share` was not found.
532 NetworkNotFound,531 NetworkNotFound,
lib/std/fs/Dir.zig-6
...@@ -742,7 +742,6 @@ pub fn walk(self: Dir, allocator: Allocator) !Walker {...@@ -742,7 +742,6 @@ pub fn walk(self: Dir, allocator: Allocator) !Walker {
742pub const OpenError = error{742pub const OpenError = error{
743 FileNotFound,743 FileNotFound,
744 NotDir,744 NotDir,
745 InvalidHandle,
746 AccessDenied,745 AccessDenied,
747 SymLinkLoop,746 SymLinkLoop,
748 ProcessFdQuotaExceeded,747 ProcessFdQuotaExceeded,
...@@ -1847,7 +1846,6 @@ pub fn readFileAllocOptions(...@@ -1847,7 +1846,6 @@ pub fn readFileAllocOptions(
1847}1846}
18481847
1849pub const DeleteTreeError = error{1848pub const DeleteTreeError = error{
1850 InvalidHandle,
1851 AccessDenied,1849 AccessDenied,
1852 FileTooBig,1850 FileTooBig,
1853 SymLinkLoop,1851 SymLinkLoop,
...@@ -1930,7 +1928,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {...@@ -1930,7 +1928,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {
1930 break :handle_entry;1928 break :handle_entry;
1931 },1929 },
19321930
1933 error.InvalidHandle,
1934 error.AccessDenied,1931 error.AccessDenied,
1935 error.SymLinkLoop,1932 error.SymLinkLoop,
1936 error.ProcessFdQuotaExceeded,1933 error.ProcessFdQuotaExceeded,
...@@ -2026,7 +2023,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {...@@ -2026,7 +2023,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void {
2026 continue :process_stack;2023 continue :process_stack;
2027 },2024 },
20282025
2029 error.InvalidHandle,
2030 error.AccessDenied,2026 error.AccessDenied,
2031 error.SymLinkLoop,2027 error.SymLinkLoop,
2032 error.ProcessFdQuotaExceeded,2028 error.ProcessFdQuotaExceeded,
...@@ -2132,7 +2128,6 @@ fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint...@@ -2132,7 +2128,6 @@ fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint
2132 continue :dir_it;2128 continue :dir_it;
2133 },2129 },
21342130
2135 error.InvalidHandle,
2136 error.AccessDenied,2131 error.AccessDenied,
2137 error.SymLinkLoop,2132 error.SymLinkLoop,
2138 error.ProcessFdQuotaExceeded,2133 error.ProcessFdQuotaExceeded,
...@@ -2231,7 +2226,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File...@@ -2231,7 +2226,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File
2231 return null;2226 return null;
2232 },2227 },
22332228
2234 error.InvalidHandle,
2235 error.AccessDenied,2229 error.AccessDenied,
2236 error.SymLinkLoop,2230 error.SymLinkLoop,
2237 error.ProcessFdQuotaExceeded,2231 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...@@ -1573,9 +1573,6 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
1573}1573}
15741574
1575pub const OpenError = error{1575pub const OpenError = error{
1576 /// In WASI, this error may occur when the provided file handle is invalid.
1577 InvalidHandle,
1578
1579 /// In WASI, this error may occur when the file descriptor does1576 /// In WASI, this error may occur when the file descriptor does
1580 /// not hold the required rights to open a new resource relative to it.1577 /// not hold the required rights to open a new resource relative to it.
1581 AccessDenied,1578 AccessDenied,
...@@ -5543,9 +5540,6 @@ pub const RealPathError = error{...@@ -5543,9 +5540,6 @@ pub const RealPathError = error{
5543 SharingViolation,5540 SharingViolation,
5544 PipeBusy,5541 PipeBusy,
55455542
5546 /// On WASI, the current CWD may not be associated with an absolute path.
5547 InvalidHandle,
5548
5549 /// Windows-only; file paths provided by the user must be valid WTF-8.5543 /// Windows-only; file paths provided by the user must be valid WTF-8.
5550 /// https://simonsapin.github.io/wtf-8/5544 /// https://simonsapin.github.io/wtf-8/
5551 InvalidWtf8,5545 InvalidWtf8,
...@@ -5613,7 +5607,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -5613,7 +5607,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
5613 error.FileLocksNotSupported => unreachable,5607 error.FileLocksNotSupported => unreachable,
5614 error.WouldBlock => unreachable,5608 error.WouldBlock => unreachable,
5615 error.FileBusy => unreachable, // not asking for write permissions5609 error.FileBusy => unreachable, // not asking for write permissions
5616 error.InvalidHandle => unreachable, // WASI-only
5617 error.InvalidUtf8 => unreachable, // WASI-only5610 error.InvalidUtf8 => unreachable, // WASI-only
5618 else => |e| return e,5611 else => |e| return e,
5619 };5612 };
...@@ -5797,7 +5790,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5797,7 +5790,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5797 }5790 }
5798 i += @as(usize, @intCast(kf.structsize));5791 i += @as(usize, @intCast(kf.structsize));
5799 }5792 }
5800 return error.InvalidHandle;5793 return error.FileNotFound;
5801 }5794 }
5802 },5795 },
5803 .dragonfly => {5796 .dragonfly => {
lib/std/zig/system.zig-3
...@@ -739,7 +739,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {...@@ -739,7 +739,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
739739
740 error.FileNotFound,740 error.FileNotFound,
741 error.NotDir,741 error.NotDir,
742 error.InvalidHandle,
743 error.AccessDenied,742 error.AccessDenied,
744 error.NoDevice,743 error.NoDevice,
745 => return error.GLibCNotFound,744 => return error.GLibCNotFound,
...@@ -775,7 +774,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {...@@ -775,7 +774,6 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
775 error.PathAlreadyExists => unreachable, // read-only774 error.PathAlreadyExists => unreachable, // read-only
776 error.DeviceBusy => unreachable, // read-only775 error.DeviceBusy => unreachable, // read-only
777 error.FileBusy => unreachable, // read-only776 error.FileBusy => unreachable, // read-only
778 error.InvalidHandle => unreachable, // should not be in the error set
779 error.WouldBlock => unreachable, // not using O_NONBLOCK777 error.WouldBlock => unreachable, // not using O_NONBLOCK
780 error.NoDevice => unreachable, // not asking for a special device778 error.NoDevice => unreachable, // not asking for a special device
781779
...@@ -1012,7 +1010,6 @@ fn detectAbiAndDynamicLinker(...@@ -1012,7 +1010,6 @@ fn detectAbiAndDynamicLinker(
10121010
1013 error.IsDir,1011 error.IsDir,
1014 error.NotDir,1012 error.NotDir,
1015 error.InvalidHandle,
1016 error.AccessDenied,1013 error.AccessDenied,
1017 error.NoDevice,1014 error.NoDevice,
1018 error.FileNotFound,1015 error.FileNotFound,