authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-30 18:18:25+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-30 18:21:38+02:00
log8306826d53bf6dd0c5ea5ea27963374b31aa6dd1
tree382f0ca9e0612bb8d173928a4f61e7663b5a1de3
parent5bc99dd7e8c037aa6c5f46d779fba99163d1da36

Map ENOTCAPABLE into error.AccessDenied instead of error.NotCapable

This is direct result of review comments left by andrewrk and daurnimator. It makes sense to map `ENOTCAPABLE` into a more generic `error.AccessDenied`.

6 files changed, 69 insertions(+), 114 deletions(-)

lib/std/child_process.zig-1
......@@ -364,7 +364,6 @@ pub const ChildProcess = struct {
364364 error.FileTooBig => unreachable,
365365 error.DeviceBusy => unreachable,
366366 error.FileLocksNotSupported => unreachable,
367 error.NotCapable => unreachable, // until WASI comes up with multi-processing (if ever)
368367 else => |e| return e,
369368 }
370369 else
lib/std/elf.zig+1-1
......@@ -551,7 +551,7 @@ fn preadNoEof(file: std.fs.File, buf: []u8, offset: u64) !void {
551551 error.InputOutput => return error.FileSystem,
552552 error.Unexpected => return error.Unexpected,
553553 error.WouldBlock => return error.Unexpected,
554 error.NotCapable => unreachable, // NotCapable mainly pertains WASI target so it's a bug if we hit it here
554 error.AccessDenied => return error.Unexpected,
555555 };
556556 if (len == 0) return error.UnexpectedEndOfFile;
557557 i += len;
lib/std/fs.zig+3-18
......@@ -264,13 +264,7 @@ pub const Dir = struct {
264264 pub const Kind = File.Kind;
265265 };
266266
267 const IteratorError = error{
268 AccessDenied,
269
270 /// WASI-only. This error occurs when the underlying `Dir` file descriptor does
271 /// not hold the required rights to call `fd_readdir` on it.
272 NotCapable,
273 } || os.UnexpectedError;
267 const IteratorError = error{AccessDenied} || os.UnexpectedError;
274268
275269 pub const Iterator = switch (builtin.os.tag) {
276270 .macosx, .ios, .freebsd, .netbsd, .dragonfly => struct {
......@@ -541,7 +535,7 @@ pub const Dir = struct {
541535 w.EFAULT => unreachable,
542536 w.ENOTDIR => unreachable,
543537 w.EINVAL => unreachable,
544 w.ENOTCAPABLE => return error.NotCapable,
538 w.ENOTCAPABLE => return error.AccessDenied,
545539 else => |err| return os.unexpectedErrno(err),
546540 }
547541 if (bufused == 0) return null;
......@@ -628,7 +622,6 @@ pub const Dir = struct {
628622 InvalidUtf8,
629623 BadPathName,
630624 DeviceBusy,
631 NotCapable,
632625 } || os.UnexpectedError;
633626
634627 pub fn close(self: *Dir) void {
......@@ -1113,7 +1106,7 @@ pub const Dir = struct {
11131106 }
11141107 }
11151108
1116 pub const DeleteFileError = os.UnlinkatError;
1109 pub const DeleteFileError = os.UnlinkError;
11171110
11181111 /// Delete a file name and possibly the file it refers to, based on an open directory handle.
11191112 /// Asserts that the path parameter has no null bytes.
......@@ -1155,7 +1148,6 @@ pub const Dir = struct {
11551148 ReadOnlyFileSystem,
11561149 InvalidUtf8,
11571150 BadPathName,
1158 NotCapable,
11591151 Unexpected,
11601152 };
11611153
......@@ -1258,7 +1250,6 @@ pub const Dir = struct {
12581250 /// On Windows, file paths cannot contain these characters:
12591251 /// '/', '*', '?', '"', '<', '>', '|'
12601252 BadPathName,
1261 NotCapable,
12621253 } || os.UnexpectedError;
12631254
12641255 /// Whether `full_path` describes a symlink, file, or directory, this function
......@@ -1272,7 +1263,6 @@ pub const Dir = struct {
12721263 if (self.deleteFile(sub_path)) {
12731264 return;
12741265 } else |err| switch (err) {
1275 error.DirNotEmpty => unreachable,
12761266 error.FileNotFound => return,
12771267 error.IsDir => {},
12781268 error.AccessDenied => got_access_denied = true,
......@@ -1287,7 +1277,6 @@ pub const Dir = struct {
12871277 error.FileBusy,
12881278 error.BadPathName,
12891279 error.Unexpected,
1290 error.NotCapable,
12911280 => |e| return e,
12921281 }
12931282 var dir = self.openDir(sub_path, .{ .iterate = true }) catch |err| switch (err) {
......@@ -1313,7 +1302,6 @@ pub const Dir = struct {
13131302 error.InvalidUtf8,
13141303 error.BadPathName,
13151304 error.DeviceBusy,
1316 error.NotCapable,
13171305 => |e| return e,
13181306 };
13191307 var cleanup_dir_parent: ?Dir = null;
......@@ -1342,7 +1330,6 @@ pub const Dir = struct {
13421330
13431331 // Impossible because we do not pass any path separators.
13441332 error.NotDir => unreachable,
1345 error.DirNotEmpty => unreachable,
13461333
13471334 error.IsDir => {},
13481335 error.AccessDenied => got_access_denied = true,
......@@ -1356,7 +1343,6 @@ pub const Dir = struct {
13561343 error.FileBusy,
13571344 error.BadPathName,
13581345 error.Unexpected,
1359 error.NotCapable,
13601346 => |e| return e,
13611347 }
13621348
......@@ -1383,7 +1369,6 @@ pub const Dir = struct {
13831369 error.InvalidUtf8,
13841370 error.BadPathName,
13851371 error.DeviceBusy,
1386 error.NotCapable,
13871372 => |e| return e,
13881373 };
13891374 if (cleanup_dir_parent) |*d| d.close();
lib/std/os.zig+64-87
......@@ -301,9 +301,9 @@ pub const ReadError = error{
301301 /// and reading from the file descriptor would block.
302302 WouldBlock,
303303
304 /// WASI-only. This error occurs when the file descriptor does
304 /// In WASI, this error occurs when the file descriptor does
305305 /// not hold the required rights to read from it.
306 NotCapable,
306 AccessDenied,
307307} || UnexpectedError;
308308
309309/// Returns the number of bytes that were read, which can be less than
......@@ -339,7 +339,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
339339 wasi.ENOMEM => return error.SystemResources,
340340 wasi.ECONNRESET => return error.ConnectionResetByPeer,
341341 wasi.ETIMEDOUT => return error.ConnectionTimedOut,
342 wasi.ENOTCAPABLE => return error.NotCapable,
342 wasi.ENOTCAPABLE => return error.AccessDenied,
343343 else => |err| return unexpectedErrno(err),
344344 }
345345 }
......@@ -407,7 +407,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
407407 wasi.EISDIR => return error.IsDir,
408408 wasi.ENOBUFS => return error.SystemResources,
409409 wasi.ENOMEM => return error.SystemResources,
410 wasi.ENOTCAPABLE => return error.NotCapable,
410 wasi.ENOTCAPABLE => return error.AccessDenied,
411411 else => |err| return unexpectedErrno(err),
412412 }
413413 }
......@@ -472,7 +472,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
472472 wasi.ENXIO => return error.Unseekable,
473473 wasi.ESPIPE => return error.Unseekable,
474474 wasi.EOVERFLOW => return error.Unseekable,
475 wasi.ENOTCAPABLE => return error.NotCapable,
475 wasi.ENOTCAPABLE => return error.AccessDenied,
476476 else => |err| return unexpectedErrno(err),
477477 }
478478 }
......@@ -507,12 +507,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
507507pub const TruncateError = error{
508508 FileTooBig,
509509 InputOutput,
510 CannotTruncate,
511510 FileBusy,
512511
513 /// WASI-only. This error occurs when the file descriptor does
512 /// In WASI, this error occurs when the file descriptor does
514513 /// not hold the required rights to call `ftruncate` on it.
515 NotCapable,
514 AccessDenied,
516515} || UnexpectedError;
517516
518517pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
......@@ -533,7 +532,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
533532 switch (rc) {
534533 .SUCCESS => return,
535534 .INVALID_HANDLE => unreachable, // Handle not open for writing
536 .ACCESS_DENIED => return error.CannotTruncate,
535 .ACCESS_DENIED => return error.AccessDenied,
537536 else => return windows.unexpectedStatus(rc),
538537 }
539538 }
......@@ -543,11 +542,11 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
543542 wasi.EINTR => unreachable,
544543 wasi.EFBIG => return error.FileTooBig,
545544 wasi.EIO => return error.InputOutput,
546 wasi.EPERM => return error.CannotTruncate,
545 wasi.EPERM => return error.AccessDenied,
547546 wasi.ETXTBSY => return error.FileBusy,
548547 wasi.EBADF => unreachable, // Handle not open for writing
549548 wasi.EINVAL => unreachable, // Handle not open for writing
550 wasi.ENOTCAPABLE => return error.NotCapable,
549 wasi.ENOTCAPABLE => return error.AccessDenied,
551550 else => |err| return unexpectedErrno(err),
552551 }
553552 }
......@@ -566,7 +565,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
566565 EINTR => continue,
567566 EFBIG => return error.FileTooBig,
568567 EIO => return error.InputOutput,
569 EPERM => return error.CannotTruncate,
568 EPERM => return error.AccessDenied,
570569 ETXTBSY => return error.FileBusy,
571570 EBADF => unreachable, // Handle not open for writing
572571 EINVAL => unreachable, // Handle not open for writing
......@@ -616,7 +615,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
616615 wasi.ENXIO => return error.Unseekable,
617616 wasi.ESPIPE => return error.Unseekable,
618617 wasi.EOVERFLOW => return error.Unseekable,
619 wasi.ENOTCAPABLE => return error.NotCapable,
618 wasi.ENOTCAPABLE => return error.AccessDenied,
620619 else => |err| return unexpectedErrno(err),
621620 }
622621 }
......@@ -654,6 +653,9 @@ pub const WriteError = error{
654653 FileTooBig,
655654 InputOutput,
656655 NoSpaceLeft,
656
657 /// In WASI, this error may occur when the file descriptor does
658 /// not hold the required rights to write to it.
657659 AccessDenied,
658660 BrokenPipe,
659661 SystemResources,
......@@ -662,10 +664,6 @@ pub const WriteError = error{
662664 /// This error occurs when no global event loop is configured,
663665 /// and reading from the file descriptor would block.
664666 WouldBlock,
665
666 /// WASI-only. This error occurs when the file descriptor does
667 /// not hold the required rights to write to it.
668 NotCapable,
669667} || UnexpectedError;
670668
671669/// Write to a file descriptor.
......@@ -714,7 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
714712 wasi.ENOSPC => return error.NoSpaceLeft,
715713 wasi.EPERM => return error.AccessDenied,
716714 wasi.EPIPE => return error.BrokenPipe,
717 wasi.ENOTCAPABLE => return error.NotCapable,
715 wasi.ENOTCAPABLE => return error.AccessDenied,
718716 else => |err| return unexpectedErrno(err),
719717 }
720718 }
......@@ -792,7 +790,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
792790 wasi.ENOSPC => return error.NoSpaceLeft,
793791 wasi.EPERM => return error.AccessDenied,
794792 wasi.EPIPE => return error.BrokenPipe,
795 wasi.ENOTCAPABLE => return error.NotCapable,
793 wasi.ENOTCAPABLE => return error.AccessDenied,
796794 else => |err| return unexpectedErrno(err),
797795 }
798796 }
......@@ -875,7 +873,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
875873 wasi.ENXIO => return error.Unseekable,
876874 wasi.ESPIPE => return error.Unseekable,
877875 wasi.EOVERFLOW => return error.Unseekable,
878 wasi.ENOTCAPABLE => return error.NotCapable,
876 wasi.ENOTCAPABLE => return error.AccessDenied,
879877 else => |err| return unexpectedErrno(err),
880878 }
881879 }
......@@ -969,7 +967,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
969967 wasi.ENXIO => return error.Unseekable,
970968 wasi.ESPIPE => return error.Unseekable,
971969 wasi.EOVERFLOW => return error.Unseekable,
972 wasi.ENOTCAPABLE => return error.NotCapable,
970 wasi.ENOTCAPABLE => return error.AccessDenied,
973971 else => |err| return unexpectedErrno(err),
974972 }
975973 }
......@@ -1005,6 +1003,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
10051003}
10061004
10071005pub const OpenError = error{
1006 /// In WASI, this error may occur when the file descriptor does
1007 /// not hold the required rights to open a new resource relative to it.
10081008 AccessDenied,
10091009 SymLinkLoop,
10101010 ProcessFdQuotaExceeded,
......@@ -1041,10 +1041,6 @@ pub const OpenError = error{
10411041
10421042 /// The underlying filesystem does not support file locks
10431043 FileLocksNotSupported,
1044
1045 /// WASI-only. This error occurs when the file descriptor does
1046 /// not hold the required rights to open a new resource relative to it.
1047 NotCapable,
10481044} || UnexpectedError;
10491045
10501046/// Open and possibly create a file. Keeps trying if it gets interrupted.
......@@ -1138,7 +1134,7 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags
11381134 wasi.EPERM => return error.AccessDenied,
11391135 wasi.EEXIST => return error.PathAlreadyExists,
11401136 wasi.EBUSY => return error.DeviceBusy,
1141 wasi.ENOTCAPABLE => return error.NotCapable,
1137 wasi.ENOTCAPABLE => return error.AccessDenied,
11421138 else => |err| return unexpectedErrno(err),
11431139 }
11441140 }
......@@ -1525,6 +1521,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
15251521}
15261522
15271523pub const SymLinkError = error{
1524 /// In WASI, this error may occur when the file descriptor does
1525 /// not hold the required rights to create a new symbolic link relative to it.
15281526 AccessDenied,
15291527 DiskQuota,
15301528 PathAlreadyExists,
......@@ -1589,19 +1587,13 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
15891587 }
15901588}
15911589
1592pub const SymLinkAtError = error{
1593 /// WASI-only. This error occurs when the file descriptor does
1594 /// not hold the required rights to create a new symbolic link relative to it.
1595 NotCapable,
1596} || SymLinkError;
1597
15981590/// Similar to `symlink`, however, creates a symbolic link named `sym_link_path` which contains the string
15991591/// `target_path` **relative** to `newdirfd` directory handle.
16001592/// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent
16011593/// one; the latter case is known as a dangling link.
16021594/// If `sym_link_path` exists, it will not be overwritten.
16031595/// See also `symlinkatWasi`, `symlinkatZ` and `symlinkatW`.
1604pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void {
1596pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
16051597 if (builtin.os.tag == .wasi) {
16061598 return symlinkatWasi(target_path, newdirfd, sym_link_path);
16071599 }
......@@ -1619,7 +1611,7 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
16191611
16201612/// WASI-only. The same as `symlinkat` but targeting WASI.
16211613/// See also `symlinkat`.
1622pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void {
1614pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
16231615 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {
16241616 wasi.ESUCCESS => {},
16251617 wasi.EFAULT => unreachable,
......@@ -1636,20 +1628,20 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c
16361628 wasi.ENOMEM => return error.SystemResources,
16371629 wasi.ENOSPC => return error.NoSpaceLeft,
16381630 wasi.EROFS => return error.ReadOnlyFileSystem,
1639 wasi.ENOTCAPABLE => return error.NotCapable,
1631 wasi.ENOTCAPABLE => return error.AccessDenied,
16401632 else => |err| return unexpectedErrno(err),
16411633 }
16421634}
16431635
16441636/// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded.
16451637/// See also `symlinkat`.
1646pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkAtError!void {
1638pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkError!void {
16471639 @compileError("TODO implement on Windows");
16481640}
16491641
16501642/// The same as `symlinkat` except the parameters are null-terminated pointers.
16511643/// See also `symlinkat`.
1652pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkAtError!void {
1644pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
16531645 if (builtin.os.tag == .windows) {
16541646 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
16551647 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
......@@ -1677,6 +1669,9 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
16771669
16781670pub const UnlinkError = error{
16791671 FileNotFound,
1672
1673 /// In WASI, this error may occur when the file descriptor does
1674 /// not hold the required rights to unlink a resource by path relative to it.
16801675 AccessDenied,
16811676 FileBusy,
16821677 FileSystem,
......@@ -1739,10 +1734,6 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
17391734pub const UnlinkatError = UnlinkError || error{
17401735 /// When passing `AT_REMOVEDIR`, this error occurs when the named directory is not empty.
17411736 DirNotEmpty,
1742
1743 /// WASI-only. This error occurs when the file descriptor does
1744 /// not hold the required rights to unlink a resource by path relative to it.
1745 NotCapable,
17461737};
17471738
17481739/// Delete a file name and possibly the file it refers to, based on an open directory handle.
......@@ -1784,7 +1775,7 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
17841775 wasi.ENOMEM => return error.SystemResources,
17851776 wasi.EROFS => return error.ReadOnlyFileSystem,
17861777 wasi.ENOTEMPTY => return error.DirNotEmpty,
1787 wasi.ENOTCAPABLE => return error.NotCapable,
1778 wasi.ENOTCAPABLE => return error.AccessDenied,
17881779
17891780 wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component
17901781 wasi.EBADF => unreachable, // always a race condition
......@@ -1887,6 +1878,8 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
18871878}
18881879
18891880const RenameError = error{
1881 /// In WASI, this error may occur when the file descriptor does
1882 /// not hold the required rights to rename a resource by path relative to it.
18901883 AccessDenied,
18911884 FileBusy,
18921885 DiskQuota,
......@@ -1963,19 +1956,13 @@ pub fn renameW(old_path: [*:0]const u16, new_path: [*:0]const u16) RenameError!v
19631956 return windows.MoveFileExW(old_path, new_path, flags);
19641957}
19651958
1966pub const RenameatError = error{
1967 /// WASI-only. This error occurs when the file descriptor does
1968 /// not hold the required rights to rename a resource by path relative to it.
1969 NotCapable,
1970} || RenameError;
1971
19721959/// Change the name or location of a file based on an open directory handle.
19731960pub fn renameat(
19741961 old_dir_fd: fd_t,
19751962 old_path: []const u8,
19761963 new_dir_fd: fd_t,
19771964 new_path: []const u8,
1978) RenameatError!void {
1965) RenameError!void {
19791966 if (builtin.os.tag == .windows) {
19801967 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
19811968 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
......@@ -1991,7 +1978,7 @@ pub fn renameat(
19911978
19921979/// WASI-only. Same as `renameat` expect targeting WASI.
19931980/// See also `renameat`.
1994pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameatError!void {
1981pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {
19951982 switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {
19961983 wasi.ESUCCESS => return,
19971984 wasi.EACCES => return error.AccessDenied,
......@@ -2012,7 +1999,7 @@ pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, ne
20121999 wasi.ENOTEMPTY => return error.PathAlreadyExists,
20132000 wasi.EROFS => return error.ReadOnlyFileSystem,
20142001 wasi.EXDEV => return error.RenameAcrossMountPoints,
2015 wasi.ENOTCAPABLE => return error.NotCapable,
2002 wasi.ENOTCAPABLE => return error.AccessDenied,
20162003 else => |err| return unexpectedErrno(err),
20172004 }
20182005}
......@@ -2023,7 +2010,7 @@ pub fn renameatZ(
20232010 old_path: [*:0]const u8,
20242011 new_dir_fd: fd_t,
20252012 new_path: [*:0]const u8,
2026) RenameatError!void {
2013) RenameError!void {
20272014 if (builtin.os.tag == .windows) {
20282015 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
20292016 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
......@@ -2062,7 +2049,7 @@ pub fn renameatW(
20622049 new_dir_fd: fd_t,
20632050 new_path_w: []const u16,
20642051 ReplaceIfExists: windows.BOOLEAN,
2065) RenameatError!void {
2052) RenameError!void {
20662053 const src_fd = windows.OpenFile(old_path_w, .{
20672054 .dir = old_dir_fd,
20682055 .access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE | windows.DELETE,
......@@ -2111,13 +2098,7 @@ pub fn renameatW(
21112098 }
21122099}
21132100
2114pub const MakeDirAtError = error{
2115 /// WASI-only. This error occurs when the file descriptor does
2116 /// not hold the required rights to create a new directory relative to it.
2117 NotCapable,
2118} || MakeDirError;
2119
2120pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void {
2101pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
21212102 if (builtin.os.tag == .windows) {
21222103 const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path);
21232104 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
......@@ -2131,7 +2112,7 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError
21312112
21322113pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
21332114
2134pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void {
2115pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
21352116 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
21362117 wasi.ESUCCESS => return,
21372118 wasi.EACCES => return error.AccessDenied,
......@@ -2148,12 +2129,12 @@ pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtE
21482129 wasi.ENOSPC => return error.NoSpaceLeft,
21492130 wasi.ENOTDIR => return error.NotDir,
21502131 wasi.EROFS => return error.ReadOnlyFileSystem,
2151 wasi.ENOTCAPABLE => return error.NotCapable,
2132 wasi.ENOTCAPABLE => return error.AccessDenied,
21522133 else => |err| return unexpectedErrno(err),
21532134 }
21542135}
21552136
2156pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtError!void {
2137pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
21572138 if (builtin.os.tag == .windows) {
21582139 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);
21592140 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
......@@ -2178,12 +2159,14 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtE
21782159 }
21792160}
21802161
2181pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirAtError!void {
2162pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirError!void {
21822163 const sub_dir_handle = try windows.CreateDirectoryW(dir_fd, sub_path_w, null);
21832164 windows.CloseHandle(sub_dir_handle);
21842165}
21852166
21862167pub const MakeDirError = error{
2168 /// In WASI, this error may occur when the file descriptor does
2169 /// not hold the required rights to create a new directory relative to it.
21872170 AccessDenied,
21882171 DiskQuota,
21892172 PathAlreadyExists,
......@@ -2363,6 +2346,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void {
23632346}
23642347
23652348pub const ReadLinkError = error{
2349 /// In WASI, this error may occur when the file descriptor does
2350 /// not hold the required rights to read value of a symbolic link relative to it.
23662351 AccessDenied,
23672352 FileSystem,
23682353 SymLinkLoop,
......@@ -2416,16 +2401,10 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
24162401 }
24172402}
24182403
2419pub const ReadLinkAtError = error{
2420 /// WASI-only. This error occurs when the file descriptor does
2421 /// not hold the required rights to read value of a symbolic link relative to it.
2422 NotCapable,
2423} || ReadLinkError;
2424
24252404/// Similar to `readlink` except reads value of a symbolink link **relative** to `dirfd` directory handle.
24262405/// The return value is a slice of `out_buffer` from index 0.
24272406/// See also `readlinkatWasi`, `realinkatZ` and `realinkatW`.
2428pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 {
2407pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
24292408 if (builtin.os.tag == .wasi) {
24302409 return readlinkatWasi(dirfd, file_path, out_buffer);
24312410 }
......@@ -2441,7 +2420,7 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
24412420
24422421/// WASI-only. Same as `readlinkat` but targets WASI.
24432422/// See also `readlinkat`.
2444pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 {
2423pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
24452424 var bufused: usize = undefined;
24462425 switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {
24472426 wasi.ESUCCESS => return out_buffer[0..bufused],
......@@ -2454,20 +2433,20 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read
24542433 wasi.ENOENT => return error.FileNotFound,
24552434 wasi.ENOMEM => return error.SystemResources,
24562435 wasi.ENOTDIR => return error.NotDir,
2457 wasi.ENOTCAPABLE => return error.NotCapable,
2436 wasi.ENOTCAPABLE => return error.AccessDenied,
24582437 else => |err| return unexpectedErrno(err),
24592438 }
24602439}
24612440
24622441/// Windows-only. Same as `readlinkat` except `file_path` is null-terminated, WTF16 encoded.
24632442/// See also `readlinkat`.
2464pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkAtError![]u8 {
2443pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 {
24652444 @compileError("TODO implement on Windows");
24662445}
24672446
24682447/// Same as `readlinkat` except `file_path` is null-terminated.
24692448/// See also `readlinkat`.
2470pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkAtError![]u8 {
2449pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
24712450 if (builtin.os.tag == .windows) {
24722451 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
24732452 return readlinkatW(dirfd, file_path_w.span().ptr, out_buffer);
......@@ -3132,11 +3111,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 {
31323111
31333112pub const FStatError = error{
31343113 SystemResources,
3135 AccessDenied,
31363114
3137 /// WASI-only. This error occurs when the file descriptor does
3115 /// In WASI, this error may occur when the file descriptor does
31383116 /// not hold the required rights to get its filestat information.
3139 NotCapable,
3117 AccessDenied,
31403118} || UnexpectedError;
31413119
31423120/// Return information about a file descriptor.
......@@ -3149,7 +3127,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
31493127 wasi.EBADF => unreachable, // Always a race condition.
31503128 wasi.ENOMEM => return error.SystemResources,
31513129 wasi.EACCES => return error.AccessDenied,
3152 wasi.ENOTCAPABLE => return error.NotCapable,
3130 wasi.ENOTCAPABLE => return error.AccessDenied,
31533131 else => |err| return unexpectedErrno(err),
31543132 }
31553133 }
......@@ -3200,7 +3178,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S
32003178 wasi.ENAMETOOLONG => return error.NameTooLong,
32013179 wasi.ENOENT => return error.FileNotFound,
32023180 wasi.ENOTDIR => return error.FileNotFound,
3203 wasi.ENOTCAPABLE => return error.NotCapable,
3181 wasi.ENOTCAPABLE => return error.AccessDenied,
32043182 else => |err| return unexpectedErrno(err),
32053183 }
32063184}
......@@ -3709,9 +3687,9 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
37093687pub const SeekError = error{
37103688 Unseekable,
37113689
3712 /// WASI-only. This error occurs when the file descriptor does
3690 /// In WASI, this error may occur when the file descriptor does
37133691 /// not hold the required rights to seek on it.
3714 NotCapable,
3692 AccessDenied,
37153693} || UnexpectedError;
37163694
37173695/// Repositions read/write file offset relative to the beginning.
......@@ -3740,7 +3718,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
37403718 wasi.EOVERFLOW => return error.Unseekable,
37413719 wasi.ESPIPE => return error.Unseekable,
37423720 wasi.ENXIO => return error.Unseekable,
3743 wasi.ENOTCAPABLE => return error.NotCapable,
3721 wasi.ENOTCAPABLE => return error.AccessDenied,
37443722 else => |err| return unexpectedErrno(err),
37453723 }
37463724 }
......@@ -3782,7 +3760,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
37823760 wasi.EOVERFLOW => return error.Unseekable,
37833761 wasi.ESPIPE => return error.Unseekable,
37843762 wasi.ENXIO => return error.Unseekable,
3785 wasi.ENOTCAPABLE => return error.NotCapable,
3763 wasi.ENOTCAPABLE => return error.AccessDenied,
37863764 else => |err| return unexpectedErrno(err),
37873765 }
37883766 }
......@@ -3823,7 +3801,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
38233801 wasi.EOVERFLOW => return error.Unseekable,
38243802 wasi.ESPIPE => return error.Unseekable,
38253803 wasi.ENXIO => return error.Unseekable,
3826 wasi.ENOTCAPABLE => return error.NotCapable,
3804 wasi.ENOTCAPABLE => return error.AccessDenied,
38273805 else => |err| return unexpectedErrno(err),
38283806 }
38293807 }
......@@ -3864,7 +3842,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
38643842 wasi.EOVERFLOW => return error.Unseekable,
38653843 wasi.ESPIPE => return error.Unseekable,
38663844 wasi.ENXIO => return error.Unseekable,
3867 wasi.ENOTCAPABLE => return error.NotCapable,
3845 wasi.ENOTCAPABLE => return error.AccessDenied,
38683846 else => |err| return unexpectedErrno(err),
38693847 }
38703848 }
......@@ -4012,7 +3990,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
40123990 if (builtin.os.tag == .linux and !builtin.link_libc) {
40133991 const fd = openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0) catch |err| switch (err) {
40143992 error.FileLocksNotSupported => unreachable,
4015 error.NotCapable => unreachable, // WASI only
40163993 else => |e| return e,
40173994 };
40183995 defer close(fd);
lib/std/zig/system.zig+1-4
......@@ -499,7 +499,6 @@ pub const NativeTargetInfo = struct {
499499 error.PipeBusy => unreachable,
500500 error.FileLocksNotSupported => unreachable,
501501 error.WouldBlock => unreachable,
502 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
503502
504503 error.IsDir,
505504 error.NotDir,
......@@ -791,7 +790,6 @@ pub const NativeTargetInfo = struct {
791790 var it = mem.tokenize(rpath_list, ":");
792791 while (it.next()) |rpath| {
793792 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
794 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
795793 error.NameTooLong => unreachable,
796794 error.InvalidUtf8 => unreachable,
797795 error.BadPathName => unreachable,
......@@ -819,7 +817,6 @@ pub const NativeTargetInfo = struct {
819817 &link_buf,
820818 ) catch |err| switch (err) {
821819 error.NameTooLong => unreachable,
822 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
823820
824821 error.AccessDenied,
825822 error.FileNotFound,
......@@ -854,7 +851,6 @@ pub const NativeTargetInfo = struct {
854851 const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
855852 error.OperationAborted => unreachable, // Windows-only
856853 error.WouldBlock => unreachable, // Did not request blocking mode
857 error.NotCapable => unreachable, // WASI only, and we don't support it here yet
858854 error.SystemResources => return error.SystemResources,
859855 error.IsDir => return error.UnableToReadElfFile,
860856 error.BrokenPipe => return error.UnableToReadElfFile,
......@@ -863,6 +859,7 @@ pub const NativeTargetInfo = struct {
863859 error.ConnectionTimedOut => return error.UnableToReadElfFile,
864860 error.Unexpected => return error.Unexpected,
865861 error.InputOutput => return error.FileSystem,
862 error.AccessDenied => return error.Unexpected,
866863 };
867864 if (len == 0) return error.UnexpectedEndOfFile;
868865 i += len;
src-self-hosted/stage2.zig-3
......@@ -163,7 +163,6 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
163163 error.OutOfMemory => return .OutOfMemory,
164164 error.Unexpected => return .Unexpected,
165165 error.InputOutput => return .FileSystem,
166 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
167166 };
168167 return .None;
169168}
......@@ -607,7 +606,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [
607606 error.NotDir => return .NotDir,
608607 error.DeviceBusy => return .DeviceBusy,
609608 error.FileLocksNotSupported => unreachable,
610 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
611609 };
612610 stage1_libc.initFromStage2(libc);
613611 return .None;
......@@ -651,7 +649,6 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file:
651649 error.AccessDenied => return .AccessDenied,
652650 error.Unexpected => return .Unexpected,
653651 error.InputOutput => return .FileSystem,
654 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
655652 };
656653 return .None;
657654}