tracker r2109 - in branches/indexer-split: . src/libtracker-db src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2109 - in branches/indexer-split: . src/libtracker-db src/trackerd
- Date: Wed, 20 Aug 2008 11:47:24 +0000 (UTC)
Author: mr
Date: Wed Aug 20 11:47:24 2008
New Revision: 2109
URL: http://svn.gnome.org/viewvc/tracker?rev=2109&view=rev
Log:
* src/libtracker-db/tracker-db-index.c: Don't try to open the
index and flush if the cache size is < 1. This should fix a
warning we were seeing about not being able to open the cache on
startup and shutdown.
* src/trackerd/tracker-marshal.list:
* src/trackerd/tracker-monitor.c: Add support for libinotify to
know about MOVE events.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-db/tracker-db-index.c
branches/indexer-split/src/trackerd/tracker-marshal.list
branches/indexer-split/src/trackerd/tracker-monitor.c
branches/indexer-split/src/trackerd/tracker-processor.c
branches/indexer-split/src/trackerd/tracker-processor.h
Modified: branches/indexer-split/src/libtracker-db/tracker-db-index.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-index.c (original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-index.c Wed Aug 20 11:47:24 2008
@@ -840,24 +840,26 @@
g_mutex_lock (priv->mutex);
- if (!priv->index) {
- g_debug ("Index was not open for flush, opening first...");
- g_mutex_unlock (priv->mutex);
- tracker_db_index_open (index);
- g_mutex_lock (priv->mutex);
- }
-
size = g_hash_table_size (priv->cache);
- if (priv->index && size > 0) {
- g_debug ("Flushing index with %d items in cache", size);
+ if (size > 0) {
+ if (!priv->index) {
+ g_debug ("Index was not open for flush, opening first...");
+ g_mutex_unlock (priv->mutex);
+ tracker_db_index_open (index);
+ g_mutex_lock (priv->mutex);
+ }
- g_hash_table_foreach_remove (priv->cache,
- cache_flush_foreach,
- priv->index);
- } else {
- g_warning ("Could not open index, cache was not flushed");
- size = 0;
+ if (priv->index) {
+ g_debug ("Flushing index with %d items in cache", size);
+
+ g_hash_table_foreach_remove (priv->cache,
+ cache_flush_foreach,
+ priv->index);
+ } else {
+ g_warning ("Could not open index, cache was not flushed");
+ size = 0;
+ }
}
g_mutex_unlock (priv->mutex);
Modified: branches/indexer-split/src/trackerd/tracker-marshal.list
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-marshal.list (original)
+++ branches/indexer-split/src/trackerd/tracker-marshal.list Wed Aug 20 11:47:24 2008
@@ -3,6 +3,7 @@
VOID:STRING,STRING,STRING
VOID:STRING,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN
VOID:STRING,OBJECT,BOOLEAN
+VOID:STRING,OBJECT,OBJECT,BOOLEAN
VOID:STRING,OBJECT
# XESAM signals -- HitsRemoved, HitsModified
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 Wed Aug 20 11:47:24 2008
@@ -88,12 +88,17 @@
/* Timeout id for pausing when we get IO */
guint unpause_timeout_id;
+
+#ifdef USE_LIBINOTIFY
+ GHashTable *event_pairs;
+#endif /* USE_LIBINOTIFY */
};
enum {
ITEM_CREATED,
ITEM_UPDATED,
ITEM_DELETED,
+ ITEM_MOVED,
LAST_SIGNAL
};
@@ -102,18 +107,24 @@
PROP_ENABLED
};
-static void tracker_monitor_finalize (GObject *object);
-static void tracker_monitor_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void tracker_monitor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static gboolean black_list_check_items_cb (gpointer data);
-static void black_list_print_all (TrackerMonitor *monitor);
-static guint get_inotify_limit (void);
+static void tracker_monitor_finalize (GObject *object);
+static void tracker_monitor_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void tracker_monitor_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static gboolean black_list_check_items_cb (gpointer data);
+static void black_list_print_all (TrackerMonitor *monitor);
+static guint get_inotify_limit (void);
+
+#ifdef USE_LIBINOTIFY
+static INotifyHandle *libinotify_monitor_directory (TrackerMonitor *monitor,
+ GFile *file);
+static void libinotify_monitor_cancel (gpointer data);
+#endif /* USE_LIBINOTIFY */
static guint signals[LAST_SIGNAL] = { 0, };
@@ -166,6 +177,19 @@
G_TYPE_STRING,
G_TYPE_OBJECT,
G_TYPE_BOOLEAN);
+ signals[ITEM_MOVED] =
+ g_signal_new ("item-moved",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ tracker_marshal_VOID__STRING_OBJECT_OBJECT_BOOLEAN,
+ G_TYPE_NONE,
+ 4,
+ G_TYPE_STRING,
+ G_TYPE_OBJECT,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN);
g_object_class_install_property (object_class,
PROP_ENABLED,
@@ -218,17 +242,36 @@
g_object_unref,
NULL);
+#ifdef USE_LIBINOTIFY
+ /* We have a hash table with cookies so we can pair up move
+ * events.
+ */
+ priv->event_pairs =
+ g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ g_object_unref);
+#endif /* USE_LIBINOTIFY */
+
all_modules = tracker_module_config_get_modules ();
for (l = all_modules; l; l = l->next) {
GHashTable *monitors;
/* Create monitors table for this module */
+#ifdef USE_LIBINOTIFY
+ monitors =
+ g_hash_table_new_full (g_file_hash,
+ (GEqualFunc) g_file_equal,
+ (GDestroyNotify) g_object_unref,
+ (GDestroyNotify) libinotify_monitor_cancel);
+#else /* USE_LIBINOTIFY */
monitors =
g_hash_table_new_full (g_file_hash,
(GEqualFunc) g_file_equal,
(GDestroyNotify) g_object_unref,
(GDestroyNotify) g_file_monitor_cancel);
+#endif /* USE_LIBINOTIFY */
g_hash_table_insert (priv->modules, g_strdup (l->data), monitors);
}
@@ -332,6 +375,10 @@
g_hash_table_unref (priv->black_list_timestamps);
g_hash_table_unref (priv->black_list_count);
+
+#ifdef USE_LIBINOTIFY
+ g_hash_table_unref (priv->event_pairs);
+#endif /* USE_LIBINOTIFY */
if (priv->black_list_timeout_id) {
g_source_remove (priv->black_list_timeout_id);
@@ -650,29 +697,6 @@
}
}
-static const gchar *
-monitor_event_to_string (GFileMonitorEvent event_type)
-{
- switch (event_type) {
- case G_FILE_MONITOR_EVENT_CHANGED:
- return "G_FILE_MONITOR_EVENT_CHANGED";
- case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
- return "G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT";
- case G_FILE_MONITOR_EVENT_DELETED:
- return "G_FILE_MONITOR_EVENT_DELETED";
- case G_FILE_MONITOR_EVENT_CREATED:
- return "G_FILE_MONITOR_EVENT_CREATED";
- case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
- return "G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED";
- case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
- return "G_FILE_MONITOR_EVENT_PRE_UNMOUNT";
- case G_FILE_MONITOR_EVENT_UNMOUNTED:
- return "G_FILE_MONITOR_EVENT_UNMOUNTED";
- }
-
- return "unknown";
-}
-
static void
indexer_pause_cb (DBusGProxy *proxy,
GError *error,
@@ -718,6 +742,379 @@
return FALSE;
}
+#ifdef USE_LIBINOTIFY
+
+static gchar *
+libinotify_monitor_event_to_string (guint32 event_type)
+{
+ GString *s;
+
+ s = g_string_new ("");
+
+ if (event_type & IN_ACCESS) {
+ s = g_string_append (s, "IN_ACCESS | ");
+ }
+ if (event_type & IN_MODIFY) {
+ s = g_string_append (s, "IN_MODIFY | ");
+ }
+ if (event_type & IN_ATTRIB) {
+ s = g_string_append (s, "IN_ATTRIB | ");
+ }
+ if (event_type & IN_CLOSE_WRITE) {
+ s = g_string_append (s, "IN_CLOSE_WRITE | ");
+ }
+ if (event_type & IN_CLOSE_NOWRITE) {
+ s = g_string_append (s, "IN_CLOSE_NOWRITE | ");
+ }
+ if (event_type & IN_OPEN) {
+ s = g_string_append (s, "IN_OPEN | ");
+ }
+ if (event_type & IN_MOVED_FROM) {
+ s = g_string_append (s, "IN_MOVED_FROM | ");
+ }
+ if (event_type & IN_MOVED_TO) {
+ s = g_string_append (s, "IN_MOVED_TO | ");
+ }
+ if (event_type & IN_CREATE) {
+ s = g_string_append (s, "IN_CREATE | ");
+ }
+ if (event_type & IN_DELETE) {
+ s = g_string_append (s, "IN_DELETE | ");
+ }
+ if (event_type & IN_DELETE_SELF) {
+ s = g_string_append (s, "IN_DELETE_SELF | ");
+ }
+ if (event_type & IN_MOVE_SELF) {
+ s = g_string_append (s, "IN_MOVE_SELF | ");
+ }
+ if (event_type & IN_UNMOUNT) {
+ s = g_string_append (s, "IN_UNMOUNT | ");
+ }
+ if (event_type & IN_Q_OVERFLOW) {
+ s = g_string_append (s, "IN_Q_OVERFLOW | ");
+ }
+ if (event_type & IN_IGNORED) {
+ s = g_string_append (s, "IN_IGNORED | ");
+ }
+
+ /* helper events */
+ if (event_type & IN_CLOSE) {
+ s = g_string_append (s, "IN_CLOSE* | ");
+ }
+ if (event_type & IN_MOVE) {
+ s = g_string_append (s, "IN_MOVE* | ");
+ }
+
+ /* special flags */
+ if (event_type & IN_MASK_ADD) {
+ s = g_string_append (s, "IN_MASK_ADD^ | ");
+ }
+ if (event_type & IN_ISDIR) {
+ s = g_string_append (s, "IN_ISDIR^ | ");
+ }
+ if (event_type & IN_ONESHOT) {
+ s = g_string_append (s, "IN_ONESHOT^ | ");
+ }
+
+ s->str[s->len - 3] = '\0';
+
+ return g_string_free (s, FALSE);
+}
+
+static void
+libinotify_monitor_event_cb (INotifyHandle *handle,
+ const char *monitor_name,
+ const char *filename,
+ guint32 event_type,
+ guint32 cookie,
+ gpointer user_data)
+{
+ TrackerMonitor *monitor;
+ GFile *file;
+ GFile *other_file;
+ const gchar *module_name;
+ gchar *str1;
+ gchar *str2;
+ gboolean is_directory;
+ gchar *event_type_str;
+
+ monitor = user_data;
+
+ switch (event_type) {
+ case IN_Q_OVERFLOW:
+ case IN_OPEN:
+ case IN_CLOSE_NOWRITE:
+ case IN_ACCESS:
+ case IN_IGNORED:
+ /* Return, otherwise we spam with messages for every
+ * file we open and look at.
+ */
+ return;
+ default:
+ break;
+ }
+
+ if (G_UNLIKELY (!monitor->private->enabled)) {
+ g_debug ("Silently dropping monitor event, monitor disabled for now");
+ return;
+ }
+
+ if (monitor_name) {
+ str1 = g_build_filename (monitor_name, filename, NULL);
+ file = g_file_new_for_path (str1);
+ } else {
+ str1 = NULL;
+ file = g_file_new_for_path (filename);
+ }
+
+ other_file = NULL;
+
+ module_name = get_module_name_from_gfile (monitor,
+ file,
+ &is_directory);
+ if (!module_name) {
+ g_free (str1);
+ g_object_unref (file);
+ return;
+ }
+
+ if (!str1) {
+ str1 = g_file_get_path (file);
+ }
+
+ /* This doesn't outright black list a file, it purely adds
+ * each file to the hash table so we have a count for every
+ * path we get an event for. If the count is too high, we
+ * then don't propagate the event up.
+ */
+ switch (event_type) {
+ case IN_MOVE_SELF:
+ case IN_MOVED_FROM:
+ case IN_MOVED_TO:
+ /* If the event is a move type, we don't increment the
+ * black list count to avoid missing the second event
+ * to pair the two up.
+ */
+ break;
+
+ default:
+ black_list_file_increment (monitor, file);
+ break;
+ }
+
+ if (other_file) {
+ str2 = g_file_get_path (other_file);
+ } else {
+ str2 = NULL;
+ }
+
+ event_type_str = libinotify_monitor_event_to_string (event_type);
+ g_message ("Received monitor event:%d->'%s' for file:'%s' (cookie:%d)",
+ event_type,
+ event_type_str,
+ str1 ? str1 : "",
+ cookie);
+ g_free (event_type_str);
+
+ if (!black_list_file_check (monitor, file)) {
+ if (monitor->private->unpause_timeout_id != 0) {
+ g_source_remove (monitor->private->unpause_timeout_id);
+ } else {
+ g_message ("Pausing indexing because we are "
+ "receiving monitor events");
+
+ tracker_status_set_is_paused_for_io (TRUE);
+
+ org_freedesktop_Tracker_Indexer_pause_async (tracker_dbus_indexer_get_proxy (),
+ indexer_pause_cb,
+ NULL);
+ }
+
+ monitor->private->unpause_timeout_id =
+ g_timeout_add_seconds (PAUSE_FOR_IO_SECONDS,
+ unpause_cb,
+ monitor);
+
+ if (cookie > 0) {
+ /* First check if we already have a file in
+ * the event pairs hash table.
+ */
+ other_file = g_hash_table_lookup (monitor->private->event_pairs,
+ GINT_TO_POINTER (cookie));
+ if (!other_file) {
+ g_hash_table_insert (monitor->private->event_pairs,
+ GINT_TO_POINTER (cookie),
+ g_object_ref (file));
+ } 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);
+ }
+ }
+
+ switch (event_type) {
+ case IN_MODIFY:
+ if (!monitor->private->use_changed_event) {
+ /* Do nothing */
+ break;
+ }
+
+ case IN_CLOSE_WRITE:
+ case IN_ATTRIB:
+ g_signal_emit (monitor,
+ signals[ITEM_UPDATED], 0,
+ module_name,
+ file,
+ is_directory);
+ break;
+
+ case IN_MOVE_SELF:
+ case IN_MOVED_FROM:
+ case IN_DELETE:
+ case IN_DELETE_SELF:
+ /* FIXME: What if we don't monitor the other
+ * location?
+ */
+ if (cookie == 0) {
+ g_signal_emit (monitor,
+ signals[ITEM_DELETED], 0,
+ module_name,
+ file,
+ is_directory);
+ } else if (other_file) {
+ g_message ("!!!!!!! Emitting signal\n\n");
+ g_signal_emit (monitor,
+ signals[ITEM_MOVED], 0,
+ module_name,
+ file,
+ other_file,
+ is_directory);
+ g_hash_table_remove (monitor->private->event_pairs,
+ GINT_TO_POINTER (cookie));
+ }
+
+ break;
+
+ case IN_CREATE:
+ case IN_MOVED_TO:
+ /* FIXME: What if we don't monitor the other
+ * location?
+ */
+ if (cookie == 0) {
+ g_signal_emit (monitor,
+ signals[ITEM_CREATED], 0,
+ module_name,
+ file,
+ is_directory);
+ } else if (other_file) {
+ g_message ("!!!!!!! Emitting signal\n\n");
+ g_signal_emit (monitor,
+ signals[ITEM_MOVED], 0,
+ module_name,
+ file,
+ other_file,
+ is_directory);
+ g_hash_table_remove (monitor->private->event_pairs,
+ GINT_TO_POINTER (cookie));
+ }
+
+ break;
+
+ case IN_UNMOUNT:
+ g_signal_emit (monitor,
+ signals[ITEM_DELETED], 0,
+ module_name,
+ file,
+ is_directory);
+ break;
+
+ case IN_Q_OVERFLOW:
+ case IN_OPEN:
+ case IN_CLOSE_NOWRITE:
+ case IN_ACCESS:
+ case IN_IGNORED:
+ /* Do nothing */
+ break;
+ }
+ } else {
+ g_message ("Not propagating event, file is black listed");
+ }
+
+ g_free (str1);
+ g_free (str2);
+ g_object_unref (file);
+}
+
+static INotifyHandle *
+libinotify_monitor_directory (TrackerMonitor *monitor,
+ GFile *file)
+{
+ INotifyHandle *handle;
+ gchar *path;
+ guint32 mask;
+ unsigned long flags;
+ gboolean is_directory;
+
+ is_directory = TRUE;
+ flags = 0;
+ mask = IN_ALL_EVENTS;
+
+ /* For files */
+ if (is_directory) {
+ flags &= ~IN_FLAG_FILE_BASED;
+ } else {
+ flags |= IN_FLAG_FILE_BASED;
+ }
+
+ path = g_file_get_path (file);
+ handle = inotify_monitor_add (path,
+ mask,
+ flags,
+ libinotify_monitor_event_cb,
+ monitor);
+ g_free (path);
+
+ if (!handle) {
+ return NULL;
+ }
+
+ return handle;
+}
+
+static void
+libinotify_monitor_cancel (gpointer data)
+{
+ inotify_monitor_remove (data);
+}
+
+#else /* USE_LIBINOTIFY */
+
+static const gchar *
+monitor_event_to_string (GFileMonitorEvent event_type)
+{
+ switch (event_type) {
+ case G_FILE_MONITOR_EVENT_CHANGED:
+ return "G_FILE_MONITOR_EVENT_CHANGED";
+ case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
+ return "G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT";
+ case G_FILE_MONITOR_EVENT_DELETED:
+ return "G_FILE_MONITOR_EVENT_DELETED";
+ case G_FILE_MONITOR_EVENT_CREATED:
+ return "G_FILE_MONITOR_EVENT_CREATED";
+ case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
+ return "G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED";
+ case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
+ return "G_FILE_MONITOR_EVENT_PRE_UNMOUNT";
+ case G_FILE_MONITOR_EVENT_UNMOUNTED:
+ return "G_FILE_MONITOR_EVENT_UNMOUNTED";
+ }
+
+ return "unknown";
+}
+
static void
monitor_event_cb (GFileMonitor *file_monitor,
GFile *file,
@@ -837,6 +1234,7 @@
g_free (str2);
}
+#endif /* USE_LIBINOTIFY */
TrackerMonitor *
tracker_monitor_new (TrackerConfig *config)
@@ -879,7 +1277,11 @@
const gchar *module_name,
GFile *file)
{
+#ifdef USE_LIBINOTIFY
+ INotifyHandle *file_monitor;
+#else /* USE_LIBINOTIFY */
GFileMonitor *file_monitor;
+#endif /* USE_LIBINOTIFY */
GHashTable *monitors;
GSList *ignored_roots;
GSList *l;
@@ -938,6 +1340,22 @@
*
* Also, we assume ALL paths passed are directories.
*/
+#ifdef USE_LIBINOTIFY
+ file_monitor = libinotify_monitor_directory (monitor, file);
+
+ if (!file_monitor) {
+ g_warning ("Could not add monitor for path:'%s', %s",
+ path,
+ error->message);
+ g_free (path);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_hash_table_insert (monitors,
+ g_object_ref (file),
+ file_monitor);
+#else /* USE_LIBINOTIFY */
file_monitor = g_file_monitor_directory (file,
G_FILE_MONITOR_WATCH_MOUNTS,
NULL,
@@ -959,6 +1377,7 @@
g_hash_table_insert (monitors,
g_object_ref (file),
file_monitor);
+#endif /* USE_LIBINOTIFY */
g_debug ("Added monitor for module:'%s', path:'%s', total monitors:%d",
module_name,
@@ -1105,142 +1524,3 @@
return monitor->private->monitors_ignored;
}
-
-#ifdef USE_LIBINOTIFY
-
-static gchar *
-get_events (guint32 event_type)
-{
- GString *s;
-
- s = g_string_new ("");
-
- if (event_type & IN_ACCESS) {
- s = g_string_append (s, "IN_ACCESS | ");
- }
- if (event_type & IN_MODIFY) {
- s = g_string_append (s, "IN_MODIFY | ");
- }
- if (event_type & IN_ATTRIB) {
- s = g_string_append (s, "IN_ATTRIB | ");
- }
- if (event_type & IN_CLOSE_WRITE) {
- s = g_string_append (s, "IN_CLOSE_WRITE | ");
- }
- if (event_type & IN_CLOSE_NOWRITE) {
- s = g_string_append (s, "IN_CLOSE_NOWRITE | ");
- }
- if (event_type & IN_OPEN) {
- s = g_string_append (s, "IN_OPEN | ");
- }
- if (event_type & IN_MOVED_FROM) {
- s = g_string_append (s, "IN_MOVED_FROM | ");
- }
- if (event_type & IN_MOVED_TO) {
- s = g_string_append (s, "IN_MOVED_TO | ");
- }
- if (event_type & IN_CREATE) {
- s = g_string_append (s, "IN_CREATE | ");
- }
- if (event_type & IN_DELETE) {
- s = g_string_append (s, "IN_DELETE | ");
- }
- if (event_type & IN_DELETE_SELF) {
- s = g_string_append (s, "IN_DELETE_SELF | ");
- }
- if (event_type & IN_MOVE_SELF) {
- s = g_string_append (s, "IN_MOVE_SELF | ");
- }
- if (event_type & IN_UNMOUNT) {
- s = g_string_append (s, "IN_UNMOUNT | ");
- }
- if (event_type & IN_Q_OVERFLOW) {
- s = g_string_append (s, "IN_Q_OVERFLOW | ");
- }
- if (event_type & IN_IGNORED) {
- s = g_string_append (s, "IN_IGNORED | ");
- }
-
- /* helper events */
- if (event_type & IN_CLOSE) {
- s = g_string_append (s, "IN_CLOSE* | ");
- }
- if (event_type & IN_MOVE) {
- s = g_string_append (s, "IN_MOVE* | ");
- }
-
- /* special flags */
- if (event_type & IN_MASK_ADD) {
- s = g_string_append (s, "IN_MASK_ADD^ | ");
- }
- if (event_type & IN_ISDIR) {
- s = g_string_append (s, "IN_ISDIR^ | ");
- }
- if (event_type & IN_ONESHOT) {
- s = g_string_append (s, "IN_ONESHOT^ | ");
- }
-
- s->len -= 3;
-
- return g_string_free (s, FALSE);
-}
-
-static void
-callback (INotifyHandle *handle,
- const char *monitor_name,
- const char *filename,
- guint32 event_type,
- guint32 cookie,
- gpointer user_data)
-{
- gchar *event_type_str = get_events (event_type);
-
- g_message ("Received monitor event:%d->'%s' for file:'%s'",
- event_type,
- event_type_str,
- filename ? filename : "");
-
- g_free (event_type_str);
-}
-
-void start (const gchar *path);
-
-void
-start (const gchar *path)
-{
- INotifyHandle **handle;
- guint32 mask;
- unsigned long flags;
- gboolean is_directory;
- static gint i = 0;
- static gint count = 0;
-
- if (!inotify_is_available ()) {
- return;
- }
-
- handle = g_new (INotifyHandle *, 1);
-
- is_directory = TRUE;
- flags = 0;
- mask = IN_ALL_EVENTS;
-
- /* For files */
- if (is_directory) {
- flags &= ~IN_FLAG_FILE_BASED;
- } else {
- flags |= IN_FLAG_FILE_BASED;
- }
-
- g_message ("Addeding monitor for path:'%s'", path);
- handle[i] = inotify_monitor_add (path, mask, flags, callback, NULL);
-
- if (handle[i] == NULL) {
- g_warning ("failed to add monitor for path:'%s'", path);
- } else {
- count++;
- i++;
- }
-}
-
-#endif /* USE_LIBINOTIFY */
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 Wed Aug 20 11:47:24 2008
@@ -51,7 +51,8 @@
SENT_TYPE_NONE,
SENT_TYPE_CREATED,
SENT_TYPE_UPDATED,
- SENT_TYPE_DELETED
+ SENT_TYPE_DELETED,
+ SENT_TYPE_MOVED
} SentType;
struct TrackerProcessorPrivate {
@@ -70,6 +71,7 @@
GHashTable *items_created_queues;
GHashTable *items_updated_queues;
GHashTable *items_deleted_queues;
+ GHashTable *items_moved_queues;
SentType sent_type;
GStrv sent_items;
@@ -130,6 +132,12 @@
GFile *file,
gboolean is_directory,
gpointer user_data);
+static void monitor_item_moved_cb (TrackerMonitor *monitor,
+ const gchar *module_name,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory,
+ gpointer user_data);
static void crawler_processing_file_cb (TrackerCrawler *crawler,
const gchar *module_name,
GFile *file,
@@ -219,6 +227,11 @@
g_str_equal,
g_free,
item_queue_destroy_notify);
+ priv->items_moved_queues =
+ g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ item_queue_destroy_notify);
for (l = priv->modules; l; l = l->next) {
/* Create queues for this module */
@@ -231,6 +244,9 @@
g_hash_table_insert (priv->items_deleted_queues,
g_strdup (l->data),
g_queue_new ());
+ g_hash_table_insert (priv->items_moved_queues,
+ g_strdup (l->data),
+ g_queue_new ());
}
}
@@ -250,6 +266,10 @@
priv->item_queues_handler_id = 0;
}
+ if (priv->items_moved_queues) {
+ g_hash_table_unref (priv->items_moved_queues);
+ }
+
if (priv->items_deleted_queues) {
g_hash_table_unref (priv->items_deleted_queues);
}
@@ -285,6 +305,9 @@
g_signal_handlers_disconnect_by_func (priv->monitor,
G_CALLBACK (monitor_item_created_cb),
object);
+ g_signal_handlers_disconnect_by_func (priv->monitor,
+ G_CALLBACK (monitor_item_moved_cb),
+ object);
g_object_unref (priv->monitor);
#ifdef HAVE_HAL
@@ -523,6 +546,10 @@
queue = g_hash_table_lookup (processor->private->items_deleted_queues,
processor->private->sent_module_name);
break;
+ case SENT_TYPE_MOVED:
+ queue = g_hash_table_lookup (processor->private->items_moved_queues,
+ processor->private->sent_module_name);
+ break;
}
item_queue_readd_items (queue, processor->private->sent_items);
@@ -595,7 +622,7 @@
return TRUE;
}
- /* Process the created items first */
+ /* Process the created items next */
queue = get_next_queue_with_data (processor->private->modules,
processor->private->items_created_queues,
&module_name);
@@ -620,7 +647,7 @@
return TRUE;
}
- /* Process the updated items first */
+ /* Process the updated items next */
queue = get_next_queue_with_data (processor->private->modules,
processor->private->items_updated_queues,
&module_name);
@@ -645,6 +672,43 @@
return TRUE;
}
+ /* Process the moved items last */
+ queue = get_next_queue_with_data (processor->private->modules,
+ processor->private->items_moved_queues,
+ &module_name);
+
+ if (queue) {
+ const gchar *source;
+ const gchar *target;
+
+ files = tracker_dbus_queue_gfile_to_strv (queue, 2);
+
+ if (files) {
+ source = files[0];
+ target = files[1];
+ } else {
+ source = NULL;
+ target = NULL;
+ }
+
+ g_message ("Queue for module:'%s' moved items processed, sending first %d to the indexer",
+ module_name,
+ g_strv_length (files));
+
+ processor->private->sent_type = SENT_TYPE_MOVED;
+ processor->private->sent_module_name = module_name;
+ processor->private->sent_items = files;
+
+ org_freedesktop_Tracker_Indexer_file_move_async (processor->private->indexer_proxy,
+ module_name,
+ source,
+ target,
+ item_queue_processed_cb,
+ processor);
+
+ return TRUE;
+ }
+
g_message ("No items in any queues to process, doing nothing");
processor->private->item_queues_handler_id = 0;
@@ -1130,6 +1194,48 @@
}
static void
+processor_files_move (TrackerProcessor *processor,
+ const gchar *module_name,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory)
+{
+ TrackerCrawler *crawler;
+ GQueue *queue;
+ gchar *path;
+ gchar *other_path;
+ gboolean 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
+
+ g_debug ("%s:'%s'->'%s' (move monitor event or user request)",
+ ignored ? "Ignored" : "Found ",
+ path,
+ other_path);
+
+ g_free (path);
+
+ if (ignored) {
+ return;
+ }
+
+ 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);
+}
+
+static void
monitor_item_created_cb (TrackerMonitor *monitor,
const gchar *module_name,
GFile *file,
@@ -1160,6 +1266,17 @@
}
static void
+monitor_item_moved_cb (TrackerMonitor *monitor,
+ const gchar *module_name,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory,
+ gpointer user_data)
+{
+ processor_files_move (user_data, module_name, file, other_file, is_directory);
+}
+
+static void
crawler_processing_file_cb (TrackerCrawler *crawler,
const gchar *module_name,
GFile *file,
@@ -1344,6 +1461,9 @@
g_signal_connect (priv->monitor, "item-deleted",
G_CALLBACK (monitor_item_deleted_cb),
processor);
+ g_signal_connect (priv->monitor, "item-moved",
+ G_CALLBACK (monitor_item_moved_cb),
+ processor);
/* Set up the indexer proxy and signalling to know when we are
* finished.
@@ -1480,6 +1600,21 @@
processor_files_delete (processor, module_name, file, is_directory);
}
+void
+tracker_processor_files_move (TrackerProcessor *processor,
+ const gchar *module_name,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory)
+{
+ g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+ g_return_if_fail (module_name != NULL);
+ g_return_if_fail (G_IS_FILE (file));
+ g_return_if_fail (G_IS_FILE (other_file));
+
+ processor_files_move (processor, module_name, file, other_file, is_directory);
+}
+
guint
tracker_processor_get_directories_found (TrackerProcessor *processor)
{
Modified: branches/indexer-split/src/trackerd/tracker-processor.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-processor.h (original)
+++ branches/indexer-split/src/trackerd/tracker-processor.h Wed Aug 20 11:47:24 2008
@@ -71,6 +71,11 @@
const gchar *module_name,
GFile *file,
gboolean is_directory);
+void tracker_processor_files_move (TrackerProcessor *processor,
+ const gchar *module_name,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory);
/* Statistics */
guint tracker_processor_get_directories_found (TrackerProcessor *processor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]