GInotifyDirectoryMonitor *inotify_monitor;
const gchar *dirname = NULL;
inotify_sub *sub = NULL;
- gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
+ gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
+ gboolean pair_moves;
klass = G_INOTIFY_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_INOTIFY_DIRECTORY_MONITOR));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
ret_ih_startup = _ih_startup();
g_assert (ret_ih_startup);
- sub = _ih_sub_new (dirname, NULL, inotify_monitor);
+ pair_moves = G_LOCAL_DIRECTORY_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED;
+
+ sub = _ih_sub_new (dirname, NULL, pair_moves, inotify_monitor);
/* FIXME: what to do about errors here? we can't return NULL or another
* kind of error and an assertion is probably too hard */
g_assert (sub != NULL);
gchar *filename;
gchar *dirname;
inotify_sub *sub;
+ gboolean pair_moves;
};
static gboolean g_inotify_file_monitor_cancel (GFileMonitor* monitor);
GInotifyFileMonitor *inotify_monitor;
const gchar *filename = NULL;
inotify_sub *sub = NULL;
+ gboolean pair_moves;
gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
klass = G_INOTIFY_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_INOTIFY_FILE_MONITOR));
ret_ih_startup = _ih_startup();
g_assert (ret_ih_startup);
- sub = _ih_sub_new (inotify_monitor->dirname, inotify_monitor->filename, inotify_monitor);
+ pair_moves = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED;
+
+ sub = _ih_sub_new (inotify_monitor->dirname,
+ inotify_monitor->filename,
+ pair_moves,
+ inotify_monitor);
/* FIXME: what to do about errors here? we can't return NULL or another
* kind of error and an assertion is probably too hard */
return TRUE;
}
+static char *
+_ih_fullpath_from_event (ik_event_t *event, char *dirname)
+{
+ char *fullpath;
+
+ if (event->name)
+ fullpath = g_strdup_printf ("%s/%s", dirname, event->name);
+ else
+ fullpath = g_strdup_printf ("%s/", dirname);
+
+ return fullpath;
+}
+
+
+static gboolean
+ih_event_is_paired_move (ik_event_t *event)
+{
+ if (event->pair)
+ {
+ ik_event_t *paired = event->pair;
+ /* intofiy(7): IN_MOVE == IN_MOVED_FROM | IN_MOVED_TO */
+ return (event->mask | paired->mask) & IN_MOVE;
+ }
+
+ return FALSE;
+}
static void
ih_event_callback (ik_event_t *event,
GFileMonitorEvent eflags;
GFile* parent;
GFile* child;
+ GFile* other;
eflags = ih_mask_to_EventFlags (event->mask);
parent = g_file_new_for_path (sub->dirname);
- if (event->name)
- fullpath = g_strdup_printf ("%s/%s", sub->dirname, event->name);
- else
- fullpath = g_strdup_printf ("%s/", sub->dirname);
-
+ fullpath = _ih_fullpath_from_event (event, sub->dirname);
child = g_file_new_for_path (fullpath);
g_free (fullpath);
+ if (ih_event_is_paired_move (event) && sub->pair_moves)
+ {
+ char *parent_dir = _ip_get_path_for_wd (event->pair->wd);
+ fullpath = _ih_fullpath_from_event (event->pair, parent_dir);
+ other = g_file_new_for_path (fullpath);
+ g_free (fullpath);
+ eflags = G_FILE_MONITOR_EVENT_MOVED;
+ event->pair = NULL; /* prevents the paired event to be emitted as well */
+ }
+ else
+ other = NULL;
+
g_file_monitor_emit_event (G_FILE_MONITOR (sub->user_data),
- child, NULL, eflags);
+ child, other, eflags);
g_object_unref (child);
g_object_unref (parent);
+ if (other)
+ g_object_unref (other);
}
static void
#include <sys/inotify.h>
/* Timings for pairing MOVED_TO / MOVED_FROM events */
-#define PROCESS_EVENTS_TIME 1000 /* milliseconds (1 hz) */
+#define PROCESS_EVENTS_TIME 1000 /* 1 millisecond (1 hz) */
#define DEFAULT_HOLD_UNTIL_TIME 0 /* 0 millisecond */
-#define MOVE_HOLD_UNTIL_TIME 0 /* 0 milliseconds */
+#define MOVE_HOLD_UNTIL_TIME 500 /* 500 microseconds or 0.5 milliseconds */
static int inotify_instance_fd = -1;
static GQueue *events_to_process = NULL;
_ik_event_free (event);
}
+
+const char *
+_ip_get_path_for_wd (gint32 wd)
+{
+ GList *dir_list;
+ ip_watched_dir_t *dir;
+
+ g_assert (wd >= 0);
+ dir_list = g_hash_table_lookup (wd_dir_hash, GINT_TO_POINTER (wd));
+ if (dir_list)
+ {
+ dir = dir_list->data;
+ if (dir)
+ return dir->path;
+ }
+
+ return NULL;
+}
#include "inotify-kernel.h"
#include "inotify-sub.h"
-gboolean _ip_startup (void (*event_cb)(ik_event_t *event, inotify_sub *sub));
-gboolean _ip_start_watching (inotify_sub *sub);
-gboolean _ip_stop_watching (inotify_sub *sub);
-
+gboolean _ip_startup (void (*event_cb)(ik_event_t *event, inotify_sub *sub));
+gboolean _ip_start_watching (inotify_sub *sub);
+gboolean _ip_stop_watching (inotify_sub *sub);
+const char * _ip_get_path_for_wd (gint32 wd);
#endif
inotify_sub*
_ih_sub_new (const gchar *dirname,
- const gchar *filename,
+ const gchar *filename,
+ gboolean pair_moves,
gpointer user_data)
{
inotify_sub *sub = NULL;
sub = g_new0 (inotify_sub, 1);
sub->dirname = dup_dirname (dirname);
sub->filename = g_strdup (filename);
+ sub->pair_moves = pair_moves;
sub->user_data = user_data;
-
+
IS_W ("new subscription for %s being setup\n", sub->dirname);
return sub;
gchar* filename;
gboolean cancelled;
gpointer user_data;
+ gboolean pair_moves;
} inotify_sub;
-inotify_sub* _ih_sub_new (const gchar* dirname, const gchar* filename, gpointer user_data);
+inotify_sub* _ih_sub_new (const gchar* dirname, const gchar* filename, gboolean pair_moves, gpointer user_data);
void _ih_sub_free (inotify_sub* sub);
#endif /* __INOTIFY_SUB_H */