authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-07-26 14:41:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-27 09:35:29-07:00
log9a3adeea6ef0eb30e75e732148e0a2b93d0d0c99
tree0b4c647651ff5e8881d29ec60242e4ba35340e4c
parent0f21d3d4d1a5cbb5254dbf55304347f4d5c3e9c5

windows.OpenFile/DeleteFile: Add NetworkNotFound as a possible error

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 {
508508 error.BadPathName => unreachable, // Windows-only
509509 error.InvalidHandle => unreachable, // WASI-only
510510 error.WouldBlock => unreachable,
511 error.NetworkNotFound => unreachable, // Windows-only
511512 else => |e| return e,
512513 }
513514 else
......@@ -659,6 +660,7 @@ pub const ChildProcess = struct {
659660 error.AccessDenied => unreachable, // not possible for "NUL"
660661 error.NameTooLong => unreachable, // not possible for "NUL"
661662 error.WouldBlock => unreachable, // not possible for "NUL"
663 error.NetworkNotFound => unreachable, // not possible for "NUL"
662664 else => |e| return e,
663665 }
664666 else
lib/std/fs.zig+15
......@@ -1099,6 +1099,8 @@ pub const Dir = struct {
10991099 InvalidUtf8,
11001100 BadPathName,
11011101 DeviceBusy,
1102 /// On Windows, `\\server` or `\\server\share` was not found.
1103 NetworkNotFound,
11021104 } || os.UnexpectedError;
11031105
11041106 pub fn close(self: *Dir) void {
......@@ -1890,6 +1892,8 @@ pub const Dir = struct {
18901892 ReadOnlyFileSystem,
18911893 InvalidUtf8,
18921894 BadPathName,
1895 /// On Windows, `\\server` or `\\server\share` was not found.
1896 NetworkNotFound,
18931897 Unexpected,
18941898 };
18951899
......@@ -2112,6 +2116,9 @@ pub const Dir = struct {
21122116 /// On Windows, file paths cannot contain these characters:
21132117 /// '/', '*', '?', '"', '<', '>', '|'
21142118 BadPathName,
2119
2120 /// On Windows, `\\server` or `\\server\share` was not found.
2121 NetworkNotFound,
21152122 } || os.UnexpectedError;
21162123
21172124 /// Whether `full_path` describes a symlink, file, or directory, this function
......@@ -2168,6 +2175,7 @@ pub const Dir = struct {
21682175 error.Unexpected,
21692176 error.InvalidUtf8,
21702177 error.BadPathName,
2178 error.NetworkNotFound,
21712179 error.DeviceBusy,
21722180 => |e| return e,
21732181 };
......@@ -2204,6 +2212,7 @@ pub const Dir = struct {
22042212 error.FileSystem,
22052213 error.FileBusy,
22062214 error.BadPathName,
2215 error.NetworkNotFound,
22072216 error.Unexpected,
22082217 => |e| return e,
22092218 }
......@@ -2257,6 +2266,7 @@ pub const Dir = struct {
22572266 error.Unexpected,
22582267 error.InvalidUtf8,
22592268 error.BadPathName,
2269 error.NetworkNotFound,
22602270 error.DeviceBusy,
22612271 => |e| return e,
22622272 };
......@@ -2283,6 +2293,7 @@ pub const Dir = struct {
22832293 error.FileSystem,
22842294 error.FileBusy,
22852295 error.BadPathName,
2296 error.NetworkNotFound,
22862297 error.Unexpected,
22872298 => |e| return e,
22882299 }
......@@ -2353,6 +2364,7 @@ pub const Dir = struct {
23532364 error.Unexpected,
23542365 error.InvalidUtf8,
23552366 error.BadPathName,
2367 error.NetworkNotFound,
23562368 error.DeviceBusy,
23572369 => |e| return e,
23582370 };
......@@ -2386,6 +2398,7 @@ pub const Dir = struct {
23862398 error.FileSystem,
23872399 error.FileBusy,
23882400 error.BadPathName,
2401 error.NetworkNotFound,
23892402 error.Unexpected,
23902403 => |e| return e,
23912404 }
......@@ -2446,6 +2459,7 @@ pub const Dir = struct {
24462459 error.InvalidUtf8,
24472460 error.BadPathName,
24482461 error.DeviceBusy,
2462 error.NetworkNotFound,
24492463 => |e| return e,
24502464 };
24512465 } else {
......@@ -2469,6 +2483,7 @@ pub const Dir = struct {
24692483 error.FileSystem,
24702484 error.FileBusy,
24712485 error.BadPathName,
2486 error.NetworkNotFound,
24722487 error.Unexpected,
24732488 => |e| return e,
24742489 }
lib/std/fs/file.zig+2
......@@ -73,6 +73,8 @@ pub const File = struct {
7373 /// '/', '*', '?', '"', '<', '>', '|'
7474 BadPathName,
7575 Unexpected,
76 /// On Windows, `\\server` or `\\server\share` was not found.
77 NetworkNotFound,
7678 } || os.OpenError || os.FlockError;
7779
7880 pub const OpenMode = enum {
lib/std/os.zig+15
......@@ -1463,6 +1463,9 @@ pub const OpenError = error{
14631463 BadPathName,
14641464 InvalidUtf8,
14651465
1466 /// On Windows, `\\server` or `\\server\share` was not found.
1467 NetworkNotFound,
1468
14661469 /// One of these three things:
14671470 /// * pathname refers to an executable image which is currently being
14681471 /// executed and write access was requested.
......@@ -2307,6 +2310,9 @@ pub const UnlinkError = error{
23072310 /// On Windows, file paths cannot contain these characters:
23082311 /// '/', '*', '?', '"', '<', '>', '|'
23092312 BadPathName,
2313
2314 /// On Windows, `\\server` or `\\server\share` was not found.
2315 NetworkNotFound,
23102316} || UnexpectedError;
23112317
23122318/// Delete a name and possibly the file it refers to.
......@@ -2472,6 +2478,8 @@ pub const RenameError = error{
24722478 NoDevice,
24732479 SharingViolation,
24742480 PipeBusy,
2481 /// On Windows, `\\server` or `\\server\share` was not found.
2482 NetworkNotFound,
24752483} || UnexpectedError;
24762484
24772485/// Change the name or location of a file.
......@@ -2777,6 +2785,8 @@ pub const MakeDirError = error{
27772785 InvalidUtf8,
27782786 BadPathName,
27792787 NoDevice,
2788 /// On Windows, `\\server` or `\\server\share` was not found.
2789 NetworkNotFound,
27802790} || UnexpectedError;
27812791
27822792/// Create a directory.
......@@ -2850,6 +2860,8 @@ pub const DeleteDirError = error{
28502860 ReadOnlyFileSystem,
28512861 InvalidUtf8,
28522862 BadPathName,
2863 /// On Windows, `\\server` or `\\server\share` was not found.
2864 NetworkNotFound,
28532865} || UnexpectedError;
28542866
28552867/// Deletes an empty directory.
......@@ -5067,6 +5079,9 @@ pub const RealPathError = error{
50675079 /// On Windows, file paths must be valid Unicode.
50685080 InvalidUtf8,
50695081
5082 /// On Windows, `\\server` or `\\server\share` was not found.
5083 NetworkNotFound,
5084
50705085 PathAlreadyExists,
50715086} || UnexpectedError;
50725087
lib/std/os/windows.zig+11
......@@ -46,6 +46,7 @@ pub const OpenError = error{
4646 Unexpected,
4747 NameTooLong,
4848 WouldBlock,
49 NetworkNotFound,
4950};
5051
5152pub const OpenFileOptions = struct {
......@@ -130,6 +131,8 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN
130131 .OBJECT_NAME_INVALID => unreachable,
131132 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
132133 .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
133136 .NO_MEDIA_IN_DEVICE => return error.NoDevice,
134137 .INVALID_PARAMETER => unreachable,
135138 .SHARING_VIOLATION => return error.AccessDenied,
......@@ -700,6 +703,7 @@ pub const CreateSymbolicLinkError = error{
700703 FileNotFound,
701704 NameTooLong,
702705 NoDevice,
706 NetworkNotFound,
703707 Unexpected,
704708};
705709
......@@ -812,6 +816,9 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin
812816 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
813817 .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
814818 .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
815822 .INVALID_PARAMETER => unreachable,
816823 .SHARING_VIOLATION => return error.AccessDenied,
817824 .ACCESS_DENIED => return error.AccessDenied,
......@@ -873,6 +880,7 @@ pub const DeleteFileError = error{
873880 NotDir,
874881 IsDir,
875882 DirNotEmpty,
883 NetworkNotFound,
876884};
877885
878886pub const DeleteFileOptions = struct {
......@@ -931,6 +939,8 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
931939 .OBJECT_NAME_INVALID => unreachable,
932940 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
933941 .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
934944 .INVALID_PARAMETER => unreachable,
935945 .FILE_IS_A_DIRECTORY => return error.IsDir,
936946 .NOT_A_DIRECTORY => return error.NotDir,
......@@ -1207,6 +1217,7 @@ pub fn GetFinalPathNameByHandle(
12071217 error.PipeBusy => unreachable,
12081218 error.PathAlreadyExists => unreachable,
12091219 error.WouldBlock => unreachable,
1220 error.NetworkNotFound => unreachable,
12101221 else => |e| return e,
12111222 };
12121223 defer CloseHandle(mgmt_handle);
lib/std/zig/system/NativeTargetInfo.zig+3
......@@ -338,6 +338,7 @@ fn detectAbiAndDynamicLinker(
338338 error.AccessDenied,
339339 error.NoDevice,
340340 error.FileNotFound,
341 error.NetworkNotFound,
341342 error.FileTooBig,
342343 error.Unexpected,
343344 => |e| {
......@@ -401,6 +402,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
401402 error.InvalidUtf8 => unreachable,
402403 error.BadPathName => unreachable,
403404 error.DeviceBusy => unreachable,
405 error.NetworkNotFound => unreachable, // Windows-only
404406
405407 error.FileNotFound,
406408 error.NotDir,
......@@ -432,6 +434,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
432434 error.BadPathName => unreachable, // Windows only
433435 error.PipeBusy => unreachable, // Windows-only
434436 error.SharingViolation => unreachable, // Windows-only
437 error.NetworkNotFound => unreachable, // Windows-only
435438 error.FileLocksNotSupported => unreachable, // No lock requested.
436439 error.NoSpaceLeft => unreachable, // read-only
437440 error.PathAlreadyExists => unreachable, // read-only