| author | |
| committer | |
| log | 9a3adeea6ef0eb30e75e732148e0a2b93d0d0c99 |
| tree | 0b4c647651ff5e8881d29ec60242e4ba35340e4c |
| parent | 0f21d3d4d1a5cbb5254dbf55304347f4d5c3e9c5 |
When calling NtCreateFile with a UNC path, if either `\\server` or `\\server\share` are not found, then the statuses `BAD_NETWORK_PATH` or `BAD_NETWORK_NAME` are returned (respectively).
These statuses are not translated into `error.FileNotFound` because they convey more information than the typical FileNotFound error. For example, if you were trying to call `Dir.makePath` with an absolute UNC path like `\\MyServer\MyShare\a\b\c\d`, then knowing that `\\MyServer\MyShare` was not found allows for returning after trying to create the first directory instead of then trying to create `a\b\c`, `a\b`, etc. when it's already known that they will all fail in the same way.6 files changed, 48 insertions(+), 0 deletions(-)
lib/std/child_process.zig+2| ... | ... | @@ -508,6 +508,7 @@ pub const ChildProcess = struct { |
| 508 | 508 | error.BadPathName => unreachable, // Windows-only |
| 509 | 509 | error.InvalidHandle => unreachable, // WASI-only |
| 510 | 510 | error.WouldBlock => unreachable, |
| 511 | error.NetworkNotFound => unreachable, // Windows-only | |
| 511 | 512 | else => |e| return e, |
| 512 | 513 | } |
| 513 | 514 | else |
| ... | ... | @@ -659,6 +660,7 @@ pub const ChildProcess = struct { |
| 659 | 660 | error.AccessDenied => unreachable, // not possible for "NUL" |
| 660 | 661 | error.NameTooLong => unreachable, // not possible for "NUL" |
| 661 | 662 | error.WouldBlock => unreachable, // not possible for "NUL" |
| 663 | error.NetworkNotFound => unreachable, // not possible for "NUL" | |
| 662 | 664 | else => |e| return e, |
| 663 | 665 | } |
| 664 | 666 | else |
lib/std/fs.zig+15| ... | ... | @@ -1099,6 +1099,8 @@ pub const Dir = struct { |
| 1099 | 1099 | InvalidUtf8, |
| 1100 | 1100 | BadPathName, |
| 1101 | 1101 | DeviceBusy, |
| 1102 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 1103 | NetworkNotFound, | |
| 1102 | 1104 | } || os.UnexpectedError; |
| 1103 | 1105 | |
| 1104 | 1106 | pub fn close(self: *Dir) void { |
| ... | ... | @@ -1890,6 +1892,8 @@ pub const Dir = struct { |
| 1890 | 1892 | ReadOnlyFileSystem, |
| 1891 | 1893 | InvalidUtf8, |
| 1892 | 1894 | BadPathName, |
| 1895 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 1896 | NetworkNotFound, | |
| 1893 | 1897 | Unexpected, |
| 1894 | 1898 | }; |
| 1895 | 1899 | |
| ... | ... | @@ -2112,6 +2116,9 @@ pub const Dir = struct { |
| 2112 | 2116 | /// On Windows, file paths cannot contain these characters: |
| 2113 | 2117 | /// '/', '*', '?', '"', '<', '>', '|' |
| 2114 | 2118 | BadPathName, |
| 2119 | ||
| 2120 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 2121 | NetworkNotFound, | |
| 2115 | 2122 | } || os.UnexpectedError; |
| 2116 | 2123 | |
| 2117 | 2124 | /// Whether `full_path` describes a symlink, file, or directory, this function |
| ... | ... | @@ -2168,6 +2175,7 @@ pub const Dir = struct { |
| 2168 | 2175 | error.Unexpected, |
| 2169 | 2176 | error.InvalidUtf8, |
| 2170 | 2177 | error.BadPathName, |
| 2178 | error.NetworkNotFound, | |
| 2171 | 2179 | error.DeviceBusy, |
| 2172 | 2180 | => |e| return e, |
| 2173 | 2181 | }; |
| ... | ... | @@ -2204,6 +2212,7 @@ pub const Dir = struct { |
| 2204 | 2212 | error.FileSystem, |
| 2205 | 2213 | error.FileBusy, |
| 2206 | 2214 | error.BadPathName, |
| 2215 | error.NetworkNotFound, | |
| 2207 | 2216 | error.Unexpected, |
| 2208 | 2217 | => |e| return e, |
| 2209 | 2218 | } |
| ... | ... | @@ -2257,6 +2266,7 @@ pub const Dir = struct { |
| 2257 | 2266 | error.Unexpected, |
| 2258 | 2267 | error.InvalidUtf8, |
| 2259 | 2268 | error.BadPathName, |
| 2269 | error.NetworkNotFound, | |
| 2260 | 2270 | error.DeviceBusy, |
| 2261 | 2271 | => |e| return e, |
| 2262 | 2272 | }; |
| ... | ... | @@ -2283,6 +2293,7 @@ pub const Dir = struct { |
| 2283 | 2293 | error.FileSystem, |
| 2284 | 2294 | error.FileBusy, |
| 2285 | 2295 | error.BadPathName, |
| 2296 | error.NetworkNotFound, | |
| 2286 | 2297 | error.Unexpected, |
| 2287 | 2298 | => |e| return e, |
| 2288 | 2299 | } |
| ... | ... | @@ -2353,6 +2364,7 @@ pub const Dir = struct { |
| 2353 | 2364 | error.Unexpected, |
| 2354 | 2365 | error.InvalidUtf8, |
| 2355 | 2366 | error.BadPathName, |
| 2367 | error.NetworkNotFound, | |
| 2356 | 2368 | error.DeviceBusy, |
| 2357 | 2369 | => |e| return e, |
| 2358 | 2370 | }; |
| ... | ... | @@ -2386,6 +2398,7 @@ pub const Dir = struct { |
| 2386 | 2398 | error.FileSystem, |
| 2387 | 2399 | error.FileBusy, |
| 2388 | 2400 | error.BadPathName, |
| 2401 | error.NetworkNotFound, | |
| 2389 | 2402 | error.Unexpected, |
| 2390 | 2403 | => |e| return e, |
| 2391 | 2404 | } |
| ... | ... | @@ -2446,6 +2459,7 @@ pub const Dir = struct { |
| 2446 | 2459 | error.InvalidUtf8, |
| 2447 | 2460 | error.BadPathName, |
| 2448 | 2461 | error.DeviceBusy, |
| 2462 | error.NetworkNotFound, | |
| 2449 | 2463 | => |e| return e, |
| 2450 | 2464 | }; |
| 2451 | 2465 | } else { |
| ... | ... | @@ -2469,6 +2483,7 @@ pub const Dir = struct { |
| 2469 | 2483 | error.FileSystem, |
| 2470 | 2484 | error.FileBusy, |
| 2471 | 2485 | error.BadPathName, |
| 2486 | error.NetworkNotFound, | |
| 2472 | 2487 | error.Unexpected, |
| 2473 | 2488 | => |e| return e, |
| 2474 | 2489 | } |
lib/std/fs/file.zig+2| ... | ... | @@ -73,6 +73,8 @@ pub const File = struct { |
| 73 | 73 | /// '/', '*', '?', '"', '<', '>', '|' |
| 74 | 74 | BadPathName, |
| 75 | 75 | Unexpected, |
| 76 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 77 | NetworkNotFound, | |
| 76 | 78 | } || os.OpenError || os.FlockError; |
| 77 | 79 | |
| 78 | 80 | pub const OpenMode = enum { |
lib/std/os.zig+15| ... | ... | @@ -1463,6 +1463,9 @@ pub const OpenError = error{ |
| 1463 | 1463 | BadPathName, |
| 1464 | 1464 | InvalidUtf8, |
| 1465 | 1465 | |
| 1466 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 1467 | NetworkNotFound, | |
| 1468 | ||
| 1466 | 1469 | /// One of these three things: |
| 1467 | 1470 | /// * pathname refers to an executable image which is currently being |
| 1468 | 1471 | /// executed and write access was requested. |
| ... | ... | @@ -2307,6 +2310,9 @@ pub const UnlinkError = error{ |
| 2307 | 2310 | /// On Windows, file paths cannot contain these characters: |
| 2308 | 2311 | /// '/', '*', '?', '"', '<', '>', '|' |
| 2309 | 2312 | BadPathName, |
| 2313 | ||
| 2314 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 2315 | NetworkNotFound, | |
| 2310 | 2316 | } || UnexpectedError; |
| 2311 | 2317 | |
| 2312 | 2318 | /// Delete a name and possibly the file it refers to. |
| ... | ... | @@ -2472,6 +2478,8 @@ pub const RenameError = error{ |
| 2472 | 2478 | NoDevice, |
| 2473 | 2479 | SharingViolation, |
| 2474 | 2480 | PipeBusy, |
| 2481 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 2482 | NetworkNotFound, | |
| 2475 | 2483 | } || UnexpectedError; |
| 2476 | 2484 | |
| 2477 | 2485 | /// Change the name or location of a file. |
| ... | ... | @@ -2777,6 +2785,8 @@ pub const MakeDirError = error{ |
| 2777 | 2785 | InvalidUtf8, |
| 2778 | 2786 | BadPathName, |
| 2779 | 2787 | NoDevice, |
| 2788 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 2789 | NetworkNotFound, | |
| 2780 | 2790 | } || UnexpectedError; |
| 2781 | 2791 | |
| 2782 | 2792 | /// Create a directory. |
| ... | ... | @@ -2850,6 +2860,8 @@ pub const DeleteDirError = error{ |
| 2850 | 2860 | ReadOnlyFileSystem, |
| 2851 | 2861 | InvalidUtf8, |
| 2852 | 2862 | BadPathName, |
| 2863 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 2864 | NetworkNotFound, | |
| 2853 | 2865 | } || UnexpectedError; |
| 2854 | 2866 | |
| 2855 | 2867 | /// Deletes an empty directory. |
| ... | ... | @@ -5067,6 +5079,9 @@ pub const RealPathError = error{ |
| 5067 | 5079 | /// On Windows, file paths must be valid Unicode. |
| 5068 | 5080 | InvalidUtf8, |
| 5069 | 5081 | |
| 5082 | /// On Windows, `\\server` or `\\server\share` was not found. | |
| 5083 | NetworkNotFound, | |
| 5084 | ||
| 5070 | 5085 | PathAlreadyExists, |
| 5071 | 5086 | } || UnexpectedError; |
| 5072 | 5087 |
lib/std/os/windows.zig+11| ... | ... | @@ -46,6 +46,7 @@ pub const OpenError = error{ |
| 46 | 46 | Unexpected, |
| 47 | 47 | NameTooLong, |
| 48 | 48 | WouldBlock, |
| 49 | NetworkNotFound, | |
| 49 | 50 | }; |
| 50 | 51 | |
| 51 | 52 | pub const OpenFileOptions = struct { |
| ... | ... | @@ -130,6 +131,8 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN |
| 130 | 131 | .OBJECT_NAME_INVALID => unreachable, |
| 131 | 132 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, |
| 132 | 133 | .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, |
| 134 | .BAD_NETWORK_PATH => return error.NetworkNotFound, // \\server was not found | |
| 135 | .BAD_NETWORK_NAME => return error.NetworkNotFound, // \\server was found but \\server\share wasn't | |
| 133 | 136 | .NO_MEDIA_IN_DEVICE => return error.NoDevice, |
| 134 | 137 | .INVALID_PARAMETER => unreachable, |
| 135 | 138 | .SHARING_VIOLATION => return error.AccessDenied, |
| ... | ... | @@ -700,6 +703,7 @@ pub const CreateSymbolicLinkError = error{ |
| 700 | 703 | FileNotFound, |
| 701 | 704 | NameTooLong, |
| 702 | 705 | NoDevice, |
| 706 | NetworkNotFound, | |
| 703 | 707 | Unexpected, |
| 704 | 708 | }; |
| 705 | 709 | |
| ... | ... | @@ -812,6 +816,9 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin |
| 812 | 816 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, |
| 813 | 817 | .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, |
| 814 | 818 | .NO_MEDIA_IN_DEVICE => return error.FileNotFound, |
| 819 | // TODO: Should BAD_NETWORK_* be translated to a different error? | |
| 820 | .BAD_NETWORK_PATH => return error.FileNotFound, // \\server was not found | |
| 821 | .BAD_NETWORK_NAME => return error.FileNotFound, // \\server was found but \\server\share wasn't | |
| 815 | 822 | .INVALID_PARAMETER => unreachable, |
| 816 | 823 | .SHARING_VIOLATION => return error.AccessDenied, |
| 817 | 824 | .ACCESS_DENIED => return error.AccessDenied, |
| ... | ... | @@ -873,6 +880,7 @@ pub const DeleteFileError = error{ |
| 873 | 880 | NotDir, |
| 874 | 881 | IsDir, |
| 875 | 882 | DirNotEmpty, |
| 883 | NetworkNotFound, | |
| 876 | 884 | }; |
| 877 | 885 | |
| 878 | 886 | pub const DeleteFileOptions = struct { |
| ... | ... | @@ -931,6 +939,8 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil |
| 931 | 939 | .OBJECT_NAME_INVALID => unreachable, |
| 932 | 940 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, |
| 933 | 941 | .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, |
| 942 | .BAD_NETWORK_PATH => return error.NetworkNotFound, // \\server was not found | |
| 943 | .BAD_NETWORK_NAME => return error.NetworkNotFound, // \\server was found but \\server\share wasn't | |
| 934 | 944 | .INVALID_PARAMETER => unreachable, |
| 935 | 945 | .FILE_IS_A_DIRECTORY => return error.IsDir, |
| 936 | 946 | .NOT_A_DIRECTORY => return error.NotDir, |
| ... | ... | @@ -1207,6 +1217,7 @@ pub fn GetFinalPathNameByHandle( |
| 1207 | 1217 | error.PipeBusy => unreachable, |
| 1208 | 1218 | error.PathAlreadyExists => unreachable, |
| 1209 | 1219 | error.WouldBlock => unreachable, |
| 1220 | error.NetworkNotFound => unreachable, | |
| 1210 | 1221 | else => |e| return e, |
| 1211 | 1222 | }; |
| 1212 | 1223 | defer CloseHandle(mgmt_handle); |
lib/std/zig/system/NativeTargetInfo.zig+3| ... | ... | @@ -338,6 +338,7 @@ fn detectAbiAndDynamicLinker( |
| 338 | 338 | error.AccessDenied, |
| 339 | 339 | error.NoDevice, |
| 340 | 340 | error.FileNotFound, |
| 341 | error.NetworkNotFound, | |
| 341 | 342 | error.FileTooBig, |
| 342 | 343 | error.Unexpected, |
| 343 | 344 | => |e| { |
| ... | ... | @@ -401,6 +402,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { |
| 401 | 402 | error.InvalidUtf8 => unreachable, |
| 402 | 403 | error.BadPathName => unreachable, |
| 403 | 404 | error.DeviceBusy => unreachable, |
| 405 | error.NetworkNotFound => unreachable, // Windows-only | |
| 404 | 406 | |
| 405 | 407 | error.FileNotFound, |
| 406 | 408 | error.NotDir, |
| ... | ... | @@ -432,6 +434,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { |
| 432 | 434 | error.BadPathName => unreachable, // Windows only |
| 433 | 435 | error.PipeBusy => unreachable, // Windows-only |
| 434 | 436 | error.SharingViolation => unreachable, // Windows-only |
| 437 | error.NetworkNotFound => unreachable, // Windows-only | |
| 435 | 438 | error.FileLocksNotSupported => unreachable, // No lock requested. |
| 436 | 439 | error.NoSpaceLeft => unreachable, // read-only |
| 437 | 440 | error.PathAlreadyExists => unreachable, // read-only |