fix(linux): prevent double delete notification on directories
This commit is contained in:
parent
d66fd9348a
commit
240f3f148f
1 changed files with 16 additions and 3 deletions
|
|
@ -233,6 +233,14 @@ const INotifyBackend = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_watch_for_path(self: *const @This(), path: []const u8) bool {
|
||||||
|
var it = self.watches.iterator();
|
||||||
|
while (it.next()) |entry| {
|
||||||
|
if (std.mem.eql(u8, entry.value_ptr.*, path)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_read_ready(self: *@This(), allocator: std.mem.Allocator) (std.posix.ReadError || error{ NoSpaceLeft, OutOfMemory, HandlerFailed })!void {
|
fn handle_read_ready(self: *@This(), allocator: std.mem.Allocator) (std.posix.ReadError || error{ NoSpaceLeft, OutOfMemory, HandlerFailed })!void {
|
||||||
const InotifyEvent = extern struct {
|
const InotifyEvent = extern struct {
|
||||||
wd: i32,
|
wd: i32,
|
||||||
|
|
@ -314,9 +322,14 @@ const INotifyBackend = struct {
|
||||||
} else {
|
} else {
|
||||||
const event_type: EventType = if (ev.mask & IN.CREATE != 0)
|
const event_type: EventType = if (ev.mask & IN.CREATE != 0)
|
||||||
if (ev.mask & IN.ISDIR != 0) .dir_created else .created
|
if (ev.mask & IN.ISDIR != 0) .dir_created else .created
|
||||||
else if (ev.mask & (IN.DELETE | IN.DELETE_SELF) != 0)
|
else if (ev.mask & (IN.DELETE | IN.DELETE_SELF) != 0) blk: {
|
||||||
.deleted
|
// Suppress IN_DELETE|IN_ISDIR for subdirs that have their
|
||||||
else if (ev.mask & (IN.MODIFY | IN.CLOSE_WRITE) != 0)
|
// own watch: IN_DELETE_SELF on that watch will fire the
|
||||||
|
// same path without duplication.
|
||||||
|
if (ev.mask & IN.ISDIR != 0 and self.has_watch_for_path(full_path))
|
||||||
|
continue;
|
||||||
|
break :blk .deleted;
|
||||||
|
} else if (ev.mask & (IN.MODIFY | IN.CLOSE_WRITE) != 0)
|
||||||
.modified
|
.modified
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue