| ... | @@ -105,41 +105,53 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN | ... | @@ -105,41 +105,53 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN |
| 105 | // If we're not following symlinks, we need to ensure we don't pass in any synchronization flags such as FILE_SYNCHRONOUS_IO_NONALERT. | 105 | // If we're not following symlinks, we need to ensure we don't pass in any synchronization flags such as FILE_SYNCHRONOUS_IO_NONALERT. |
| 106 | const flags: ULONG = if (options.follow_symlinks) file_or_dir_flag | blocking_flag else file_or_dir_flag | FILE_OPEN_REPARSE_POINT; | 106 | const flags: ULONG = if (options.follow_symlinks) file_or_dir_flag | blocking_flag else file_or_dir_flag | FILE_OPEN_REPARSE_POINT; |
| 107 | | 107 | |
| 108 | const rc = ntdll.NtCreateFile( | 108 | while (true) { |
| 109 | &result, | 109 | const rc = ntdll.NtCreateFile( |
| 110 | options.access_mask, | 110 | &result, |
| 111 | &attr, | 111 | options.access_mask, |
| 112 | &io, | 112 | &attr, |
| 113 | null, | 113 | &io, |
| 114 | FILE_ATTRIBUTE_NORMAL, | 114 | null, |
| 115 | options.share_access, | 115 | FILE_ATTRIBUTE_NORMAL, |
| 116 | options.creation, | 116 | options.share_access, |
| 117 | flags, | 117 | options.creation, |
| 118 | null, | 118 | flags, |
| 119 | 0, | 119 | null, |
| 120 | ); | 120 | 0, |
| 121 | switch (rc) { | 121 | ); |
| 122 | .SUCCESS => { | 122 | switch (rc) { |
| 123 | if (std.io.is_async and options.io_mode == .evented) { | 123 | .SUCCESS => { |
| 124 | _ = CreateIoCompletionPort(result, std.event.Loop.instance.?.os_data.io_port, undefined, undefined) catch undefined; | 124 | if (std.io.is_async and options.io_mode == .evented) { |
| 125 | } | 125 | _ = CreateIoCompletionPort(result, std.event.Loop.instance.?.os_data.io_port, undefined, undefined) catch undefined; |
| 126 | return result; | 126 | } |
| 127 | }, | 127 | return result; |
| 128 | .OBJECT_NAME_INVALID => unreachable, | 128 | }, |
| 129 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, | 129 | .OBJECT_NAME_INVALID => unreachable, |
| 130 | .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, | 130 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, |
| 131 | .NO_MEDIA_IN_DEVICE => return error.NoDevice, | 131 | .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, |
| 132 | .INVALID_PARAMETER => unreachable, | 132 | .NO_MEDIA_IN_DEVICE => return error.NoDevice, |
| 133 | .SHARING_VIOLATION => return error.AccessDenied, | 133 | .INVALID_PARAMETER => unreachable, |
| 134 | .ACCESS_DENIED => return error.AccessDenied, | 134 | .SHARING_VIOLATION => return error.AccessDenied, |
| 135 | .PIPE_BUSY => return error.PipeBusy, | 135 | .ACCESS_DENIED => return error.AccessDenied, |
| 136 | .OBJECT_PATH_SYNTAX_BAD => unreachable, | 136 | .PIPE_BUSY => return error.PipeBusy, |
| 137 | .OBJECT_NAME_COLLISION => return error.PathAlreadyExists, | 137 | .OBJECT_PATH_SYNTAX_BAD => unreachable, |
| 138 | .FILE_IS_A_DIRECTORY => return error.IsDir, | 138 | .OBJECT_NAME_COLLISION => return error.PathAlreadyExists, |
| 139 | .NOT_A_DIRECTORY => return error.NotDir, | 139 | .FILE_IS_A_DIRECTORY => return error.IsDir, |
| 140 | .USER_MAPPED_FILE => return error.AccessDenied, | 140 | .NOT_A_DIRECTORY => return error.NotDir, |
| 141 | .INVALID_HANDLE => unreachable, | 141 | .USER_MAPPED_FILE => return error.AccessDenied, |
| 142 | else => return unexpectedStatus(rc), | 142 | .INVALID_HANDLE => unreachable, |
| | 143 | .DELETE_PENDING => { |
| | 144 | // This error means that there *was* a file in this location on |
| | 145 | // the file system, but it was deleted. However, the OS is not |
| | 146 | // finished with the deletion operation, and so this CreateFile |
| | 147 | // call has failed. There is not really a sane way to handle |
| | 148 | // this other than retrying the creation after the OS finishes |
| | 149 | // the deletion. |
| | 150 | std.time.sleep(std.time.ns_per_ms); |
| | 151 | continue; |
| | 152 | }, |
| | 153 | else => return unexpectedStatus(rc), |
| | 154 | } |
| 143 | } | 155 | } |
| 144 | } | 156 | } |
| 145 | | 157 | |