fix: propagate unwatch() errors if backend.remove_watch can fail
This commit is contained in:
parent
f107b97214
commit
505b9efeb8
2 changed files with 10 additions and 3 deletions
|
|
@ -175,11 +175,18 @@ pub fn Create(comptime variant: Variant) type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const UnwatchReturnType = @typeInfo(@TypeOf(Backend.remove_watch)).@"fn".return_type orelse void;
|
||||||
|
pub const UnwatchError = switch (@typeInfo(UnwatchReturnType)) {
|
||||||
|
.error_union => |info| info.error_set,
|
||||||
|
.void => error{},
|
||||||
|
else => @compileError("invalid remove_watch return type: " ++ @typeName(UnwatchReturnType)),
|
||||||
|
};
|
||||||
|
|
||||||
/// Stop watching a previously watched path. Has no effect if `path`
|
/// Stop watching a previously watched path. Has no effect if `path`
|
||||||
/// was never watched. Does not unwatch subdirectories that were
|
/// was never watched. Does not unwatch subdirectories that were
|
||||||
/// added automatically as a result of watching `path`.
|
/// added automatically as a result of watching `path`.
|
||||||
pub fn unwatch(self: *@This(), path: []const u8) void {
|
pub fn unwatch(self: *@This(), path: []const u8) UnwatchError!void {
|
||||||
self.interceptor.backend.remove_watch(self.allocator, path);
|
return self.interceptor.backend.remove_watch(self.allocator, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read pending events from the backend fd and deliver them to the handler.
|
/// Read pending events from the backend fd and deliver them to the handler.
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ fn testUnwatch(comptime Watcher: type, allocator: std.mem.Allocator) !void {
|
||||||
try drainEvents(Watcher, &watcher);
|
try drainEvents(Watcher, &watcher);
|
||||||
try std.testing.expect(th.hasChange(file1, .created, .file));
|
try std.testing.expect(th.hasChange(file1, .created, .file));
|
||||||
|
|
||||||
watcher.unwatch(tmp);
|
watcher.unwatch(tmp) catch return error.TestUnexpectedResult;
|
||||||
const count_before = th.events.items.len;
|
const count_before = th.events.items.len;
|
||||||
|
|
||||||
const file2 = try std.fs.path.join(allocator, &.{ tmp, "after_unwatch.txt" });
|
const file2 = try std.fs.path.join(allocator, &.{ tmp, "after_unwatch.txt" });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue