Skip to content

Commit

Permalink
linux/inotify: fix reporting on nested subdirectories which lack pare…
Browse files Browse the repository at this point in the history
…nt marks
  • Loading branch information
Will committed Feb 1, 2025
1 parent 8c0d98d commit f4aaf62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions devel/include/detail/wtr/watcher/adapter/linux/inotify/watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,21 @@ inline auto do_ev_recv = [](auto const& cb, sysres& sr) -> result
else if (msk & IN_Q_OVERFLOW)
send_msg(result::w_sys_q_overflow, dmhit->second.c_str(), cb);
else if (is_real_event(msk)) {
auto [ev, next] = parse_ev(dmhit->second, in_ev, in_ev_tail);
auto parsed = parse_ev(dmhit->second, in_ev, in_ev_tail);
if (msk & IN_ISDIR && msk & IN_CREATE)
do_mark(ev.path_name.c_str(), sr.ke.fd, sr.ke.dm, cb);
cb(ev);
in_ev_next = next;
// In case of nested subdirectories which were
// created before we had an opportunity to mark
// the parent, walk the newly created directory
// tree, marking and reporting on the children.
walkdir_do(parsed.ev.path_name.c_str(), [&](auto dir) {
do_mark(dir, sr.ke.fd, sr.ke.dm, cb);
cb({dir, parsed.ev.effect_type, parsed.ev.path_type});
});
else
// Or, in the case of any other kind of file,
// no need to descend or mark things.
cb(parsed.ev);
in_ev_next = parsed.next;
}
in_ev = in_ev_next;
}
Expand Down
18 changes: 14 additions & 4 deletions include/wtr/watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1621,11 +1621,21 @@ inline auto do_ev_recv = [](auto const& cb, sysres& sr) -> result
else if (msk & IN_Q_OVERFLOW)
send_msg(result::w_sys_q_overflow, dmhit->second.c_str(), cb);
else if (is_real_event(msk)) {
auto [ev, next] = parse_ev(dmhit->second, in_ev, in_ev_tail);
auto parsed = parse_ev(dmhit->second, in_ev, in_ev_tail);
if (msk & IN_ISDIR && msk & IN_CREATE)
do_mark(ev.path_name.c_str(), sr.ke.fd, sr.ke.dm, cb);
cb(ev);
in_ev_next = next;
// In case of nested subdirectories which were
// created before we had an opportunity to mark
// the parent, walk the newly created directory
// tree, marking and reporting on the children.
walkdir_do(parsed.ev.path_name.c_str(), [&](auto dir) {
do_mark(dir, sr.ke.fd, sr.ke.dm, cb);
cb({dir, parsed.ev.effect_type, parsed.ev.path_type});
});
else
// Or, in the case of any other kind of file,
// no need to descend or mark things.
cb(parsed.ev);
in_ev_next = parsed.next;
}
in_ev = in_ev_next;
}
Expand Down

0 comments on commit f4aaf62

Please sign in to comment.