[glib/wip/mount-watcher] inotify: plumb "interesting" through



commit e315af30aeb58ce9770f7628855cb4ece4af0327
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 15 16:38:22 2015 -0500

    inotify: plumb "interesting" through

 gio/inotify/inotify-helper.c |   24 ++++++++++++++----------
 gio/inotify/inotify-kernel.c |    6 +++---
 gio/inotify/inotify-kernel.h |    2 +-
 gio/inotify/inotify-path.c   |   29 ++++++++++++++++++-----------
 gio/inotify/inotify-path.h   |    2 +-
 5 files changed, 37 insertions(+), 26 deletions(-)
---
diff --git a/gio/inotify/inotify-helper.c b/gio/inotify/inotify-helper.c
index 9e52f60..06f5fab 100644
--- a/gio/inotify/inotify-helper.c
+++ b/gio/inotify/inotify-helper.c
@@ -39,9 +39,9 @@
 static gboolean ih_debug_enabled = FALSE;
 #define IH_W if (ih_debug_enabled) g_warning 
 
-static void ih_event_callback (ik_event_t  *event,
-                              inotify_sub *sub,
-                              gboolean     file_event);
+static gboolean ih_event_callback (ik_event_t  *event,
+                                   inotify_sub *sub,
+                                   gboolean     file_event);
 static void ih_not_missing_callback (inotify_sub *sub);
 
 /* We share this lock with inotify-kernel.c and inotify-missing.c
@@ -151,11 +151,13 @@ _ih_fullpath_from_event (ik_event_t *event,
    return fullpath;
 }
 
-static void
+static gboolean
 ih_event_callback (ik_event_t  *event,
                    inotify_sub *sub,
                    gboolean     file_event)
 {
+  gboolean interesting;
+
   g_assert (!file_event); /* XXX hardlink support */
 
   if (event->mask & IN_MOVE)
@@ -166,8 +168,8 @@ ih_event_callback (ik_event_t  *event,
       if (event->pair && event->pair->wd == event->wd)
         {
           /* this is a rename */
-          g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_RENAMED,
-                                              event->name, event->pair->name, NULL, event->timestamp);
+          interesting = g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_RENAMED,
+                                                            event->name, event->pair->name, NULL, 
event->timestamp);
         }
       else
         {
@@ -187,8 +189,8 @@ ih_event_callback (ik_event_t  *event,
             other = NULL;
 
           /* this is either an incoming or outgoing move */
-          g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
-                                              event->name, NULL, other, event->timestamp);
+          interesting = g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags 
(event->mask),
+                                                            event->name, NULL, other, event->timestamp);
 
           if (other)
             g_object_unref (other);
@@ -196,8 +198,8 @@ ih_event_callback (ik_event_t  *event,
     }
   else
     /* unpaired event -- no 'other' field */
-    g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
-                                        event->name, NULL, NULL, event->timestamp);
+    interesting = g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
+                                                      event->name, NULL, NULL, event->timestamp);
 
   if (event->mask & IN_CREATE)
     {
@@ -230,6 +232,8 @@ ih_event_callback (ik_event_t  *event,
         g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT,
                                             event->name, NULL, NULL, event->timestamp);
     }
+
+  return interesting;
 }
 
 static void
diff --git a/gio/inotify/inotify-kernel.c b/gio/inotify/inotify-kernel.c
index 305b5c8..2ea1609 100644
--- a/gio/inotify/inotify-kernel.c
+++ b/gio/inotify/inotify-kernel.c
@@ -163,7 +163,7 @@ ik_source_dispatch (GSource     *source,
                     gpointer     user_data)
 {
   InotifyKernelSource *iks = (InotifyKernelSource *) source;
-  void (*user_callback) (ik_event_t *event) = (void *) func;
+  gboolean (*user_callback) (ik_event_t *event) = (void *) func;
   gint64 now = g_source_get_time (source);
 
   now = g_source_get_time (source);
@@ -216,7 +216,7 @@ ik_source_dispatch (GSource     *source,
 }
 
 static InotifyKernelSource *
-ik_source_new (void (* callback) (ik_event_t *event))
+ik_source_new (gboolean (* callback) (ik_event_t *event))
 {
   static GSourceFuncs source_funcs = {
     NULL, NULL,
@@ -247,7 +247,7 @@ ik_source_new (void (* callback) (ik_event_t *event))
 }
 
 gboolean
-_ik_startup (void (*cb)(ik_event_t *event))
+_ik_startup (gboolean (*cb)(ik_event_t *event))
 {
   if (g_once_init_enter (&inotify_source))
     g_once_init_leave (&inotify_source, ik_source_new (cb));
diff --git a/gio/inotify/inotify-kernel.h b/gio/inotify/inotify-kernel.h
index 26ab19d..25ede29 100644
--- a/gio/inotify/inotify-kernel.h
+++ b/gio/inotify/inotify-kernel.h
@@ -40,7 +40,7 @@ typedef struct ik_event_s {
   gint64 timestamp; /* monotonic time that this was created */
 } ik_event_t;
 
-gboolean _ik_startup (void (*cb) (ik_event_t *event));
+gboolean _ik_startup (gboolean (*cb) (ik_event_t *event));
 
 ik_event_t *_ik_event_new_dummy (const char *name,
                                 gint32      wd,
diff --git a/gio/inotify/inotify-path.c b/gio/inotify/inotify-path.c
index 830f514..c27ed4a 100644
--- a/gio/inotify/inotify-path.c
+++ b/gio/inotify/inotify-path.c
@@ -100,13 +100,13 @@ static GHashTable * wd_file_hash = NULL;
 static ip_watched_dir_t *ip_watched_dir_new  (const char       *path,
                                              int               wd);
 static void              ip_watched_dir_free (ip_watched_dir_t *dir);
-static void              ip_event_callback   (ik_event_t       *event);
+static gboolean          ip_event_callback   (ik_event_t       *event);
 
 
-static void (*event_callback)(ik_event_t *event, inotify_sub *sub, gboolean file_event);
+static gboolean (*event_callback)(ik_event_t *event, inotify_sub *sub, gboolean file_event);
 
 gboolean
-_ip_startup (void (*cb)(ik_event_t *event, inotify_sub *sub, gboolean file_event))
+_ip_startup (gboolean (*cb)(ik_event_t *event, inotify_sub *sub, gboolean file_event))
 {
   static gboolean initialized = FALSE;
   static gboolean result = FALSE;
@@ -436,15 +436,17 @@ ip_wd_delete (gpointer data,
   ip_watched_dir_free (dir);
 }
 
-static void
+static gboolean
 ip_event_dispatch (GList      *dir_list, 
                    GList      *file_list,
                    ik_event_t *event)
 {
+  gboolean interesting = FALSE;
+
   GList *l;
   
   if (!event)
-    return;
+    return FALSE;
 
   for (l = dir_list; l; l = l->next)
     {
@@ -487,7 +489,7 @@ ip_event_dispatch (GList      *dir_list,
           * the filename doesn't match
           */
          
-         event_callback (event, sub, FALSE);
+         interesting |= event_callback (event, sub, FALSE);
 
           if (sub->hardlinks)
             {
@@ -516,14 +518,17 @@ ip_event_dispatch (GList      *dir_list,
         {
          inotify_sub *sub = subl->data;
 
-         event_callback (event, sub, TRUE);
+         interesting |= event_callback (event, sub, TRUE);
         }
     }
+
+  return interesting;
 }
 
-static void
+static gboolean
 ip_event_callback (ik_event_t *event)
 {
+  gboolean interesting = FALSE;
   GList* dir_list = NULL;
   GList *file_list = NULL;
 
@@ -531,14 +536,14 @@ ip_event_callback (ik_event_t *event)
   if (event->mask & IN_IGNORED)
     {
       _ik_event_free (event);
-      return;
+      return TRUE;
     }
 
   dir_list = g_hash_table_lookup (wd_dir_hash, GINT_TO_POINTER (event->wd));
   file_list = g_hash_table_lookup (wd_file_hash, GINT_TO_POINTER (event->wd));
 
   if (event->mask & IP_INOTIFY_DIR_MASK)
-    ip_event_dispatch (dir_list, file_list, event);
+    interesting |= ip_event_dispatch (dir_list, file_list, event);
 
   /* Only deliver paired events if the wds are separate */
   if (event->pair && event->pair->wd != event->wd)
@@ -547,7 +552,7 @@ ip_event_callback (ik_event_t *event)
       file_list = g_hash_table_lookup (wd_file_hash, GINT_TO_POINTER (event->pair->wd));
 
       if (event->pair->mask & IP_INOTIFY_DIR_MASK)
-        ip_event_dispatch (dir_list, file_list, event->pair);
+        interesting |= ip_event_dispatch (dir_list, file_list, event->pair);
     }
 
   /* We have to manage the missing list
@@ -565,6 +570,8 @@ ip_event_callback (ik_event_t *event)
     }
   
   _ik_event_free (event);
+
+  return interesting;
 }
 
 const char *
diff --git a/gio/inotify/inotify-path.h b/gio/inotify/inotify-path.h
index e985149..1793ff7 100644
--- a/gio/inotify/inotify-path.h
+++ b/gio/inotify/inotify-path.h
@@ -25,7 +25,7 @@
 #include "inotify-kernel.h"
 #include "inotify-sub.h"
 
-gboolean     _ip_startup (void (*event_cb)(ik_event_t *event, inotify_sub *sub, gboolean file_event));
+gboolean     _ip_startup (gboolean (*event_cb)(ik_event_t *event, inotify_sub *sub, gboolean file_event));
 gboolean     _ip_start_watching (inotify_sub *sub);
 gboolean     _ip_stop_watching  (inotify_sub *sub);
 const char * _ip_get_path_for_wd (gint32 wd);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]