@@ -266,15 +266,20 @@ const Os = switch (builtin.os.tag) {
266
266
lpCompletionRoutine : windows.LPOVERLAPPED_COMPLETION_ROUTINE ,
267
267
) callconv (windows .WINAPI ) windows .BOOL ;
268
268
269
- fn readChanges (self : * @This ()) void {
269
+ fn readChanges (self : * @This ()) ! void {
270
270
const notify_filter =
271
271
windows .FILE_NOTIFY_CHANGE_CREATION |
272
272
windows .FILE_NOTIFY_CHANGE_DIR_NAME |
273
273
windows .FILE_NOTIFY_CHANGE_FILE_NAME |
274
274
windows .FILE_NOTIFY_CHANGE_LAST_WRITE |
275
275
windows .FILE_NOTIFY_CHANGE_SIZE ;
276
276
const r = ReadDirectoryChangesW (self .handle , @ptrCast (& self .buffer ), self .buffer .len , 0 , notify_filter , null , & self .overlapped , null );
277
- assert (r != 0 );
277
+ if (r == 0 ) {
278
+ switch (windows .GetLastError ()) {
279
+ .INVALID_FUNCTION = > return error .ReadDirectoryChangesUnsupported ,
280
+ else = > | err | return windows .unexpectedError (err ),
281
+ }
282
+ }
278
283
}
279
284
280
285
fn getWaitHandle (self : @This ()) windows.HANDLE {
@@ -340,7 +345,7 @@ const Os = switch (builtin.os.tag) {
340
345
offset += notify .NextEntryOffset ;
341
346
}
342
347
343
- dir .readChanges ();
348
+ try dir .readChanges ();
344
349
return any_dirty ;
345
350
}
346
351
@@ -408,18 +413,22 @@ const Os = switch (builtin.os.tag) {
408
413
// directory on the file system.
409
414
// In such case, we must revert adding this directory, but keep
410
415
// the additions to the step set.
411
- const dh_gop = try w .os .handle_table .getOrPut (gpa , dir_handle );
416
+ const dh_gop = w .os .handle_table .getOrPut (gpa , dir_handle ) catch | err | {
417
+ windows .CloseHandle (dir_handle );
418
+ return err ;
419
+ };
412
420
if (dh_gop .found_existing ) {
413
421
_ = w .dir_table .pop ();
414
422
} else {
415
423
assert (dh_gop .index == gop .index );
416
424
dh_gop .value_ptr .* = .{};
417
425
const dir = try Os .Directory .init (gpa , dir_handle );
426
+ errdefer dir .deinit (gpa );
427
+ try dir .readChanges ();
418
428
try w .os .handle_extra .insert (gpa , dh_gop .index , .{
419
429
.dir = dir ,
420
430
.wait_handle = dir .getWaitHandle (),
421
431
});
422
- dir .readChanges ();
423
432
}
424
433
break :rs & w .os .handle_table .values ()[dh_gop .index ];
425
434
}
0 commit comments