Commit a699d678b2

Ali Chraghi <63465728+AliChraghi@users.noreply.github.com>
2021-11-20 21:49:22
add `NotLink` error (#9877)
Closes #9872 Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
1 parent 3fefdc1
Changed files (2)
lib
lib/std/zig/system.zig
@@ -614,6 +614,7 @@ pub const NativeTargetInfo = struct {
             error.FileSystem => return error.FileSystem,
             error.SymLinkLoop => return error.SymLinkLoop,
             error.NameTooLong => unreachable,
+            error.NotLink => return error.GnuLibCVersionUnavailable,
             error.FileNotFound => return error.GnuLibCVersionUnavailable,
             error.SystemResources => return error.SystemResources,
             error.NotDir => return error.GnuLibCVersionUnavailable,
@@ -892,6 +893,7 @@ pub const NativeTargetInfo = struct {
 
                             error.AccessDenied,
                             error.FileNotFound,
+                            error.NotLink,
                             error.NotDir,
                             => continue,
 
lib/std/os.zig
@@ -2674,6 +2674,7 @@ pub const ReadLinkError = error{
     NameTooLong,
     FileNotFound,
     SystemResources,
+    NotLink,
     NotDir,
     InvalidUtf8,
     BadPathName,
@@ -2715,7 +2716,7 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
         .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
         .ACCES => return error.AccessDenied,
         .FAULT => unreachable,
-        .INVAL => unreachable,
+        .INVAL => return error.NotLink,
         .IO => return error.FileSystem,
         .LOOP => return error.SymLinkLoop,
         .NAMETOOLONG => return error.NameTooLong,
@@ -2751,7 +2752,7 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read
         .SUCCESS => return out_buffer[0..bufused],
         .ACCES => return error.AccessDenied,
         .FAULT => unreachable,
-        .INVAL => unreachable,
+        .INVAL => return error.NotLink,
         .IO => return error.FileSystem,
         .LOOP => return error.SymLinkLoop,
         .NAMETOOLONG => return error.NameTooLong,
@@ -2781,7 +2782,7 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
         .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
         .ACCES => return error.AccessDenied,
         .FAULT => unreachable,
-        .INVAL => unreachable,
+        .INVAL => return error.NotLink,
         .IO => return error.FileSystem,
         .LOOP => return error.SymLinkLoop,
         .NAMETOOLONG => return error.NameTooLong,
@@ -4758,6 +4759,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
             const target = readlinkZ(std.meta.assumeSentinel(proc_path.ptr, 0), out_buffer) catch |err| {
                 switch (err) {
                     error.UnsupportedReparsePointType => unreachable, // Windows only,
+                    error.NotLink => unreachable,
                     else => |e| return e,
                 }
             };
@@ -4769,6 +4771,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
 
             const target = readlinkZ(proc_path, out_buffer) catch |err| switch (err) {
                 error.UnsupportedReparsePointType => unreachable,
+                error.NotLink => unreachable,
                 else => |e| return e,
             };
             return target;