Skip to content

Commit fec3ff2

Browse files
fix(inotify): correct event type for symlinks (#78)
Use the correct path type for symlinks instead of always using file. This might have to be fixed for other backends as well, but i didn't test that.
1 parent d6c2dbd commit fec3ff2

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

include/wtr/watcher.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,14 @@ inline auto parse_ev = [](
14781478
using ev_et = enum ev::effect_type;
14791479
auto pathof = [&](inotify_event const* const m)
14801480
{ return known_pathof_wd_or_default(dm, m->wd) / m->name; };
1481-
auto pt = in->mask & IN_ISDIR ? ev_pt::dir : ev_pt::file;
1481+
auto calc_pt = [&](inotify_event const* const ev_ptr) -> ev_pt
1482+
{
1483+
// Return other type if pointer is null
1484+
if (! ev_ptr) return ev_pt::other;
1485+
return ev_ptr->mask & IN_ISDIR ? ev_pt::dir
1486+
: is_symlink(pathof(ev_ptr)) ? ev_pt::sym_link
1487+
: ev_pt::file;
1488+
};
14821489
auto et = in->mask & IN_CREATE ? ev_et::create
14831490
: in->mask & IN_DELETE ? ev_et::destroy
14841491
: in->mask & IN_MOVE ? ev_et::rename
@@ -1489,9 +1496,14 @@ inline auto parse_ev = [](
14891496
auto isfromto = [](auto* a, auto* b) -> bool
14901497
{ return (a->mask & IN_MOVED_FROM) && (b->mask & IN_MOVED_TO); };
14911498
auto one = [&](auto* a, auto* next) -> parsed
1492-
{ return {ev(pathof(a), et, pt), next}; };
1499+
{ return {ev(pathof(a), et, calc_pt(a)), next}; };
14931500
auto assoc = [&](auto* a, auto* b) -> parsed
1494-
{ return {ev(ev(pathof(a), et, pt), ev(pathof(b), et, pt)), peek(b, tail)}; };
1501+
{
1502+
auto pt_b = calc_pt(b);
1503+
return {
1504+
ev(ev(pathof(a), et, pt_b), ev(pathof(b), et, pt_b)),
1505+
peek(b, tail)};
1506+
};
14951507
auto next = peek(in, tail);
14961508
return ! isassoc(in, next) ? one(in, next)
14971509
: isfromto(in, next) ? assoc(in, next)

0 commit comments

Comments
 (0)