tracker r2145 - in branches/indexer-split: . src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2145 - in branches/indexer-split: . src/trackerd
- Date: Fri, 22 Aug 2008 15:28:45 +0000 (UTC)
Author: mr
Date: Fri Aug 22 15:28:45 2008
New Revision: 2145
URL: http://svn.gnome.org/viewvc/tracker?rev=2145&view=rev
Log:
* src/trackerd/tracker-monitor.c: Handle situations where the
source or target are not monitored and emit the appropriate
signals up the stack.
* src/trackerd/tracker-processor.c: Check the source AND the
target to see if they should be ignored or not when we get MOVE
monitor events. If both are ignored, we do nothing, if source is
ignored we create the new file in the database, if target is
ignored we delete the old file in the database, if both are valid
we do a simple move in the database. I say simple, it isn't that
simple. :)
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/trackerd/tracker-monitor.c
branches/indexer-split/src/trackerd/tracker-processor.c
Modified: branches/indexer-split/src/trackerd/tracker-monitor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-monitor.c (original)
+++ branches/indexer-split/src/trackerd/tracker-monitor.c Fri Aug 22 15:28:45 2008
@@ -91,6 +91,10 @@
#ifdef USE_LIBINOTIFY
GHashTable *event_pairs;
+ GHashTable *event_time_by_cookie;
+ GHashTable *event_type_by_cookie;
+
+ guint event_check_timeout_id;
#endif /* USE_LIBINOTIFY */
};
@@ -251,6 +255,16 @@
g_direct_equal,
NULL,
g_object_unref);
+ priv->event_time_by_cookie =
+ g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ NULL);
+ priv->event_type_by_cookie =
+ g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ NULL);
#endif /* USE_LIBINOTIFY */
all_modules = tracker_module_config_get_modules ();
@@ -377,6 +391,12 @@
g_hash_table_unref (priv->black_list_count);
#ifdef USE_LIBINOTIFY
+ if (priv->event_check_timeout_id) {
+ g_source_remove (priv->event_check_timeout_id);
+ }
+
+ g_hash_table_unref (priv->event_type_by_cookie);
+ g_hash_table_unref (priv->event_time_by_cookie);
g_hash_table_unref (priv->event_pairs);
#endif /* USE_LIBINOTIFY */
@@ -821,6 +841,107 @@
return g_string_free (s, FALSE);
}
+static gboolean
+libinotify_event_check_timeout_cb (gpointer data)
+{
+ TrackerMonitor *monitor;
+ GTimeVal t;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ monitor = data;
+
+ g_debug ("Checking for event pairs which have timed out...");
+
+ g_get_current_time (&t);
+
+ g_hash_table_iter_init (&iter, monitor->private->event_time_by_cookie);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ glong seconds;
+ glong seconds_then;
+ guint32 event_type;
+ GFile *file;
+ const gchar *module_name;
+ gboolean is_directory;
+ gpointer p;
+
+ seconds_then = GPOINTER_TO_SIZE (value);
+
+ seconds = t.tv_sec;
+ seconds -= seconds_then;
+
+ g_debug ("Comparing now:%ld to then:%ld, diff:%ld",
+ t.tv_sec,
+ seconds_then,
+ seconds);
+
+ if (seconds < 2) {
+ continue;
+ }
+
+ file = g_hash_table_lookup (monitor->private->event_pairs, key);
+ p = g_hash_table_lookup (monitor->private->event_type_by_cookie, key);
+ event_type = GPOINTER_TO_UINT (p);
+
+ /* We didn't receive an event pair for this
+ * cookie, so we just generate the CREATE or
+ * DELETE event for the file we know about.
+ */
+ g_debug ("Event:%d with cookie:%d has timed out (%ld seconds have elapsed)",
+ event_type,
+ GPOINTER_TO_UINT (key),
+ seconds);
+
+ module_name = get_module_name_from_gfile (monitor,
+ file,
+ &is_directory);
+
+ switch (event_type) {
+ case IN_MOVE_SELF:
+ case IN_MOVED_FROM:
+ case IN_DELETE:
+ case IN_DELETE_SELF:
+ /* So we new the source, but not the
+ * target location for the event.
+ */
+ g_signal_emit (monitor,
+ signals[ITEM_DELETED], 0,
+ module_name,
+ file,
+ is_directory);
+ break;
+
+ case IN_CREATE:
+ case IN_MOVED_TO:
+ /* So we new the target, but not the
+ * source location for the event.
+ */
+ g_signal_emit (monitor,
+ signals[ITEM_CREATED], 0,
+ module_name,
+ file,
+ is_directory);
+ break;
+ }
+
+ /* Clean up */
+ g_hash_table_remove (monitor->private->event_pairs, key);
+ g_hash_table_remove (monitor->private->event_time_by_cookie, key);
+ g_hash_table_remove (monitor->private->event_type_by_cookie, key);
+
+ /* Reset the iter, so we start from the top */
+ g_hash_table_iter_init (&iter, monitor->private->event_time_by_cookie);
+ }
+
+ if (g_hash_table_size (monitor->private->event_time_by_cookie) < 1) {
+ g_debug ("No more events to pair, removing timeout");
+ monitor->private->event_check_timeout_id = 0;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
libinotify_monitor_event_cb (INotifyHandle *handle,
const char *monitor_name,
@@ -942,17 +1063,36 @@
other_file = g_hash_table_lookup (monitor->private->event_pairs,
GINT_TO_POINTER (cookie));
if (!other_file) {
+ GTimeVal t;
+
+ g_get_current_time (&t);
g_hash_table_insert (monitor->private->event_pairs,
- GINT_TO_POINTER (cookie),
+ GUINT_TO_POINTER (cookie),
g_object_ref (file));
+ g_hash_table_insert (monitor->private->event_time_by_cookie,
+ GUINT_TO_POINTER (cookie),
+ GSIZE_TO_POINTER (t.tv_sec));
+ g_hash_table_insert (monitor->private->event_type_by_cookie,
+ GUINT_TO_POINTER (cookie),
+ GUINT_TO_POINTER (event_type));
} else {
gchar *other_path;
other_path = g_file_get_path (other_file);
- g_message ("!!!!!!! File:'%s' moved from '%s'\n\n",
- other_path, str1);
g_free (other_path);
}
+
+ /* Add a check for old cookies we didn't
+ * receive the follow up pair event for.
+ */
+ if (!monitor->private->event_check_timeout_id) {
+ g_debug ("Setting up event pair timeout check");
+
+ monitor->private->event_check_timeout_id =
+ g_timeout_add_seconds (2,
+ libinotify_event_check_timeout_cb,
+ monitor);
+ }
}
switch (event_type) {
@@ -985,7 +1125,6 @@
file,
is_directory);
} else if (other_file) {
- g_message ("!!!!!!! Emitting signal\n\n");
g_signal_emit (monitor,
signals[ITEM_MOVED], 0,
module_name,
@@ -993,7 +1132,11 @@
other_file,
is_directory);
g_hash_table_remove (monitor->private->event_pairs,
- GINT_TO_POINTER (cookie));
+ GUINT_TO_POINTER (cookie));
+ g_hash_table_remove (monitor->private->event_time_by_cookie,
+ GUINT_TO_POINTER (cookie));
+ g_hash_table_remove (monitor->private->event_type_by_cookie,
+ GUINT_TO_POINTER (cookie));
}
break;
@@ -1010,7 +1153,6 @@
file,
is_directory);
} else if (other_file) {
- g_message ("!!!!!!! Emitting signal\n\n");
g_signal_emit (monitor,
signals[ITEM_MOVED], 0,
module_name,
@@ -1018,7 +1160,11 @@
other_file,
is_directory);
g_hash_table_remove (monitor->private->event_pairs,
- GINT_TO_POINTER (cookie));
+ GUINT_TO_POINTER (cookie));
+ g_hash_table_remove (monitor->private->event_time_by_cookie,
+ GUINT_TO_POINTER (cookie));
+ g_hash_table_remove (monitor->private->event_type_by_cookie,
+ GUINT_TO_POINTER (cookie));
}
break;
Modified: branches/indexer-split/src/trackerd/tracker-processor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-processor.c (original)
+++ branches/indexer-split/src/trackerd/tracker-processor.c Fri Aug 22 15:28:45 2008
@@ -1213,34 +1213,43 @@
GQueue *queue;
gchar *path;
gchar *other_path;
- gboolean ignored;
+ gboolean path_ignored;
+ gboolean other_path_ignored;
path = g_file_get_path (file);
other_path = g_file_get_path (other_file);
crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
-#if 0
- /* FIXME: How do we do this? Surely if other_file is ignored we delete it? */
- ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
-#else
- ignored = FALSE;
-#endif
+ path_ignored = tracker_crawler_is_path_ignored (crawler, path, is_directory);
+ other_path_ignored = tracker_crawler_is_path_ignored (crawler, other_path, is_directory);
- g_debug ("%s:'%s'->'%s' (move monitor event or user request)",
- ignored ? "Ignored" : "Found ",
+ g_debug ("%s:'%s'->'%s':%s (move monitor event or user request)",
+ path_ignored ? "Ignored" : "Found ",
path,
- other_path);
+ other_path,
+ other_path_ignored ? "Ignored" : " Found");
+ g_free (other_path);
g_free (path);
-
- if (ignored) {
+
+ if (path_ignored && other_path_ignored) {
+ /* Do nothing */
return;
+ } else if (path_ignored) {
+ /* Check new file */
+ queue = g_hash_table_lookup (processor->private->items_created_queues, module_name);
+ g_queue_push_tail (queue, g_object_ref (other_file));
+ } else if (other_path_ignored) {
+ /* Delete old file */
+ queue = g_hash_table_lookup (processor->private->items_deleted_queues, module_name);
+ g_queue_push_tail (queue, g_object_ref (file));
+ } else {
+ /* Move old file to new file */
+ queue = g_hash_table_lookup (processor->private->items_moved_queues, module_name);
+ g_queue_push_tail (queue, g_object_ref (file));
+ g_queue_push_tail (queue, g_object_ref (other_file));
}
- queue = g_hash_table_lookup (processor->private->items_moved_queues, module_name);
- g_queue_push_tail (queue, g_object_ref (file));
- g_queue_push_tail (queue, g_object_ref (other_file));
-
item_queue_handlers_set_up (processor);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]