From 04a7e4ec45ccd4ce71432e131eb3dbd241de36ab Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 20 May 2019 17:28:35 +0900 Subject: [PATCH] pepper-inotify: provide a path information to inotify event Change-Id: I14f001668c885e81dbf4dffc2217c15fe1f7cbaf --- src/lib/inotify/pepper-inotify-internal.h | 1 + src/lib/inotify/pepper-inotify.c | 24 ++++++++++++++++------- src/lib/inotify/pepper-inotify.h | 3 +++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/inotify/pepper-inotify-internal.h b/src/lib/inotify/pepper-inotify-internal.h index 56f3f83..3ebc3a6 100644 --- a/src/lib/inotify/pepper-inotify-internal.h +++ b/src/lib/inotify/pepper-inotify-internal.h @@ -34,6 +34,7 @@ struct pepper_inotify_event pepper_inotify_t *inotify; char *name; + char *path; pepper_bool_t is_dir; }; diff --git a/src/lib/inotify/pepper-inotify.c b/src/lib/inotify/pepper-inotify.c index 6960dd0..56ff285 100644 --- a/src/lib/inotify/pepper-inotify.c +++ b/src/lib/inotify/pepper-inotify.c @@ -39,18 +39,19 @@ #include static void -_inotify_event_post(pepper_inotify_t *inotify, pepper_inotify_event_type_t type, const char *name, pepper_bool_t is_dir) +_inotify_event_post(pepper_inotify_watch_t *watch, pepper_inotify_event_type_t type, const char *name, pepper_bool_t is_dir) { pepper_inotify_event_t ev; - PEPPER_CHECK(inotify->callback.cb, return, "Current inotify has no callback"); + PEPPER_CHECK(watch->inotify->callback.cb, return, "Current inotify has no callback"); - ev.inotify = inotify; + ev.inotify = watch->inotify; ev.name = (char *)name; ev.is_dir = is_dir; + ev.path = watch->path; - inotify->callback.cb(type, &ev, inotify->callback.data); + watch->inotify->callback.cb(type, &ev, watch->inotify->callback.data); } static void @@ -59,15 +60,15 @@ _inotify_event_process(struct inotify_event *ev, pepper_inotify_watch_t *watch) if (!ev->len) return; if (ev->mask & IN_CREATE) { - _inotify_event_post(watch->inotify, PEPPER_INOTIFY_EVENT_TYPE_CREATE, + _inotify_event_post(watch, PEPPER_INOTIFY_EVENT_TYPE_CREATE, ev->name, (ev->mask & IN_ISDIR) ? PEPPER_TRUE : PEPPER_FALSE); } else if (ev->mask & IN_DELETE) { - _inotify_event_post(watch->inotify, PEPPER_INOTIFY_EVENT_TYPE_REMOVE, + _inotify_event_post(watch, PEPPER_INOTIFY_EVENT_TYPE_REMOVE, ev->name, (ev->mask & IN_ISDIR) ? PEPPER_TRUE : PEPPER_FALSE); } else if (ev->mask & IN_MODIFY) { - _inotify_event_post(watch->inotify, PEPPER_INOTIFY_EVENT_TYPE_MODIFY, + _inotify_event_post(watch, PEPPER_INOTIFY_EVENT_TYPE_MODIFY, ev->name, (ev->mask & IN_ISDIR) ? PEPPER_TRUE : PEPPER_FALSE); } } @@ -111,6 +112,15 @@ pepper_inotify_event_name_get(pepper_inotify_event_t *ev) return ev->name; } +PEPPER_API char * +pepper_inotify_event_path_get(pepper_inotify_event_t *ev) +{ + PEPPER_CHECK(ev, return PEPPER_INOTIFY_EVENT_TYPE_NONE, + "Invalid inotify event\n"); + + return ev->path; +} + PEPPER_API pepper_bool_t pepper_inotify_event_is_directory(pepper_inotify_event_t *ev) { diff --git a/src/lib/inotify/pepper-inotify.h b/src/lib/inotify/pepper-inotify.h index 36364fb..b66a3f6 100644 --- a/src/lib/inotify/pepper-inotify.h +++ b/src/lib/inotify/pepper-inotify.h @@ -62,6 +62,9 @@ pepper_inotify_event_type_get(pepper_inotify_event_t *ev); PEPPER_API char * pepper_inotify_event_name_get(pepper_inotify_event_t *ev); +PEPPER_API char * +pepper_inotify_event_path_get(pepper_inotify_event_t *ev); + PEPPER_API pepper_bool_t pepper_inotify_event_is_directory(pepper_inotify_event_t *ev); -- 2.34.1