mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-04 04:39:20 +02:00
inotify: plumb "interesting" through
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
static gboolean ih_debug_enabled = FALSE;
|
static gboolean ih_debug_enabled = FALSE;
|
||||||
#define IH_W if (ih_debug_enabled) g_warning
|
#define IH_W if (ih_debug_enabled) g_warning
|
||||||
|
|
||||||
static void ih_event_callback (ik_event_t *event,
|
static gboolean ih_event_callback (ik_event_t *event,
|
||||||
inotify_sub *sub,
|
inotify_sub *sub,
|
||||||
gboolean file_event);
|
gboolean file_event);
|
||||||
static void ih_not_missing_callback (inotify_sub *sub);
|
static void ih_not_missing_callback (inotify_sub *sub);
|
||||||
@@ -151,11 +151,13 @@ _ih_fullpath_from_event (ik_event_t *event,
|
|||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
ih_event_callback (ik_event_t *event,
|
ih_event_callback (ik_event_t *event,
|
||||||
inotify_sub *sub,
|
inotify_sub *sub,
|
||||||
gboolean file_event)
|
gboolean file_event)
|
||||||
{
|
{
|
||||||
|
gboolean interesting;
|
||||||
|
|
||||||
g_assert (!file_event); /* XXX hardlink support */
|
g_assert (!file_event); /* XXX hardlink support */
|
||||||
|
|
||||||
if (event->mask & IN_MOVE)
|
if (event->mask & IN_MOVE)
|
||||||
@@ -166,7 +168,7 @@ ih_event_callback (ik_event_t *event,
|
|||||||
if (event->pair && event->pair->wd == event->wd)
|
if (event->pair && event->pair->wd == event->wd)
|
||||||
{
|
{
|
||||||
/* this is a rename */
|
/* this is a rename */
|
||||||
g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_RENAMED,
|
interesting = g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_RENAMED,
|
||||||
event->name, event->pair->name, NULL, event->timestamp);
|
event->name, event->pair->name, NULL, event->timestamp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -187,7 +189,7 @@ ih_event_callback (ik_event_t *event,
|
|||||||
other = NULL;
|
other = NULL;
|
||||||
|
|
||||||
/* this is either an incoming or outgoing move */
|
/* this is either an incoming or outgoing move */
|
||||||
g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
interesting = g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
||||||
event->name, NULL, other, event->timestamp);
|
event->name, NULL, other, event->timestamp);
|
||||||
|
|
||||||
if (other)
|
if (other)
|
||||||
@@ -196,7 +198,7 @@ ih_event_callback (ik_event_t *event,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* unpaired event -- no 'other' field */
|
/* unpaired event -- no 'other' field */
|
||||||
g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
interesting = g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
||||||
event->name, NULL, NULL, event->timestamp);
|
event->name, NULL, NULL, event->timestamp);
|
||||||
|
|
||||||
if (event->mask & IN_CREATE)
|
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,
|
g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT,
|
||||||
event->name, NULL, NULL, event->timestamp);
|
event->name, NULL, NULL, event->timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return interesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -163,7 +163,7 @@ ik_source_dispatch (GSource *source,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
InotifyKernelSource *iks = (InotifyKernelSource *) source;
|
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);
|
gint64 now = g_source_get_time (source);
|
||||||
|
|
||||||
now = g_source_get_time (source);
|
now = g_source_get_time (source);
|
||||||
@@ -216,7 +216,7 @@ ik_source_dispatch (GSource *source,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static InotifyKernelSource *
|
static InotifyKernelSource *
|
||||||
ik_source_new (void (* callback) (ik_event_t *event))
|
ik_source_new (gboolean (* callback) (ik_event_t *event))
|
||||||
{
|
{
|
||||||
static GSourceFuncs source_funcs = {
|
static GSourceFuncs source_funcs = {
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
@@ -247,7 +247,7 @@ ik_source_new (void (* callback) (ik_event_t *event))
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_ik_startup (void (*cb)(ik_event_t *event))
|
_ik_startup (gboolean (*cb)(ik_event_t *event))
|
||||||
{
|
{
|
||||||
if (g_once_init_enter (&inotify_source))
|
if (g_once_init_enter (&inotify_source))
|
||||||
g_once_init_leave (&inotify_source, ik_source_new (cb));
|
g_once_init_leave (&inotify_source, ik_source_new (cb));
|
||||||
|
@@ -40,7 +40,7 @@ typedef struct ik_event_s {
|
|||||||
gint64 timestamp; /* monotonic time that this was created */
|
gint64 timestamp; /* monotonic time that this was created */
|
||||||
} ik_event_t;
|
} 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,
|
ik_event_t *_ik_event_new_dummy (const char *name,
|
||||||
gint32 wd,
|
gint32 wd,
|
||||||
|
@@ -100,13 +100,13 @@ static GHashTable * wd_file_hash = NULL;
|
|||||||
static ip_watched_dir_t *ip_watched_dir_new (const char *path,
|
static ip_watched_dir_t *ip_watched_dir_new (const char *path,
|
||||||
int wd);
|
int wd);
|
||||||
static void ip_watched_dir_free (ip_watched_dir_t *dir);
|
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
|
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 initialized = FALSE;
|
||||||
static gboolean result = FALSE;
|
static gboolean result = FALSE;
|
||||||
@@ -436,15 +436,17 @@ ip_wd_delete (gpointer data,
|
|||||||
ip_watched_dir_free (dir);
|
ip_watched_dir_free (dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
ip_event_dispatch (GList *dir_list,
|
ip_event_dispatch (GList *dir_list,
|
||||||
GList *file_list,
|
GList *file_list,
|
||||||
ik_event_t *event)
|
ik_event_t *event)
|
||||||
{
|
{
|
||||||
|
gboolean interesting = FALSE;
|
||||||
|
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
if (!event)
|
if (!event)
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
for (l = dir_list; l; l = l->next)
|
for (l = dir_list; l; l = l->next)
|
||||||
{
|
{
|
||||||
@@ -487,7 +489,7 @@ ip_event_dispatch (GList *dir_list,
|
|||||||
* the filename doesn't match
|
* the filename doesn't match
|
||||||
*/
|
*/
|
||||||
|
|
||||||
event_callback (event, sub, FALSE);
|
interesting |= event_callback (event, sub, FALSE);
|
||||||
|
|
||||||
if (sub->hardlinks)
|
if (sub->hardlinks)
|
||||||
{
|
{
|
||||||
@@ -516,14 +518,17 @@ ip_event_dispatch (GList *dir_list,
|
|||||||
{
|
{
|
||||||
inotify_sub *sub = subl->data;
|
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)
|
ip_event_callback (ik_event_t *event)
|
||||||
{
|
{
|
||||||
|
gboolean interesting = FALSE;
|
||||||
GList* dir_list = NULL;
|
GList* dir_list = NULL;
|
||||||
GList *file_list = NULL;
|
GList *file_list = NULL;
|
||||||
|
|
||||||
@@ -531,14 +536,14 @@ ip_event_callback (ik_event_t *event)
|
|||||||
if (event->mask & IN_IGNORED)
|
if (event->mask & IN_IGNORED)
|
||||||
{
|
{
|
||||||
_ik_event_free (event);
|
_ik_event_free (event);
|
||||||
return;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir_list = g_hash_table_lookup (wd_dir_hash, GINT_TO_POINTER (event->wd));
|
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));
|
file_list = g_hash_table_lookup (wd_file_hash, GINT_TO_POINTER (event->wd));
|
||||||
|
|
||||||
if (event->mask & IP_INOTIFY_DIR_MASK)
|
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 */
|
/* Only deliver paired events if the wds are separate */
|
||||||
if (event->pair && event->pair->wd != event->wd)
|
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));
|
file_list = g_hash_table_lookup (wd_file_hash, GINT_TO_POINTER (event->pair->wd));
|
||||||
|
|
||||||
if (event->pair->mask & IP_INOTIFY_DIR_MASK)
|
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
|
/* We have to manage the missing list
|
||||||
@@ -565,6 +570,8 @@ ip_event_callback (ik_event_t *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ik_event_free (event);
|
_ik_event_free (event);
|
||||||
|
|
||||||
|
return interesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
#include "inotify-kernel.h"
|
#include "inotify-kernel.h"
|
||||||
#include "inotify-sub.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_start_watching (inotify_sub *sub);
|
||||||
gboolean _ip_stop_watching (inotify_sub *sub);
|
gboolean _ip_stop_watching (inotify_sub *sub);
|
||||||
const char * _ip_get_path_for_wd (gint32 wd);
|
const char * _ip_get_path_for_wd (gint32 wd);
|
||||||
|
Reference in New Issue
Block a user