tracker r1762 - in branches/xesam-support: . data filters/application src src/libtracker src/libtracker-common src/libtracker-db src/text-filters src/tracker-indexer src/tracker-indexer/modules src/trackerd tests tests/common tests/libtracker-db tests/scripts tests/trackerd tests/trackerd/xesam



Author: pvanhoof
Date: Wed Jun 25 09:38:42 2008
New Revision: 1762
URL: http://svn.gnome.org/viewvc/tracker?rev=1762&view=rev

Log:
2008-06-25  Philip Van Hoof  <pvanhoof gnome org>

        * svn merge -r 1733:1761 ../indexer-split



Added:
   branches/xesam-support/src/tracker-indexer/modules/evolution.c
      - copied unchanged from r1761, /branches/indexer-split/src/tracker-indexer/modules/evolution.c
   branches/xesam-support/src/tracker-indexer/tracker-module.h
      - copied unchanged from r1761, /branches/indexer-split/src/tracker-indexer/tracker-module.h
   branches/xesam-support/tests/libtracker-db/
      - copied from r1761, /branches/indexer-split/tests/libtracker-db/
Removed:
   branches/xesam-support/src/text-filters/
Modified:
   branches/xesam-support/ChangeLog
   branches/xesam-support/README
   branches/xesam-support/configure.ac
   branches/xesam-support/data/sqlite-stored-procs.sql
   branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation-template_filter
   branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation_filter
   branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet-template_filter
   branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet_filter
   branches/xesam-support/filters/application/vnd.oasis.opendocument.text-template_filter
   branches/xesam-support/filters/application/vnd.oasis.opendocument.text_filter
   branches/xesam-support/filters/application/vnd.stardivision.writer_filter
   branches/xesam-support/filters/application/vnd.sun.xml.calc.template_filter
   branches/xesam-support/filters/application/vnd.sun.xml.calc_filter
   branches/xesam-support/filters/application/vnd.sun.xml.draw_filter
   branches/xesam-support/filters/application/vnd.sun.xml.impress.template_filter
   branches/xesam-support/filters/application/vnd.sun.xml.impress_filter
   branches/xesam-support/filters/application/vnd.sun.xml.writer.template_filter
   branches/xesam-support/filters/application/vnd.sun.xml.writer_filter
   branches/xesam-support/src/Makefile.am
   branches/xesam-support/src/libtracker-common/Makefile.am
   branches/xesam-support/src/libtracker-common/tracker-config.c
   branches/xesam-support/src/libtracker-common/tracker-log.c
   branches/xesam-support/src/libtracker-db/tracker-db-interface-sqlite.c
   branches/xesam-support/src/libtracker-db/tracker-db-manager.c
   branches/xesam-support/src/libtracker-db/tracker-db-manager.h
   branches/xesam-support/src/libtracker/tracker.c
   branches/xesam-support/src/tracker-indexer/Makefile.am
   branches/xesam-support/src/tracker-indexer/modules/Makefile.am
   branches/xesam-support/src/tracker-indexer/modules/applications.c
   branches/xesam-support/src/tracker-indexer/modules/dummy.c
   branches/xesam-support/src/tracker-indexer/modules/files.c
   branches/xesam-support/src/tracker-indexer/tracker-index.c
   branches/xesam-support/src/tracker-indexer/tracker-index.h
   branches/xesam-support/src/tracker-indexer/tracker-indexer-module.c
   branches/xesam-support/src/tracker-indexer/tracker-indexer-module.h
   branches/xesam-support/src/tracker-indexer/tracker-indexer.c
   branches/xesam-support/src/tracker-indexer/tracker-main.c
   branches/xesam-support/src/trackerd/tracker-crawler.c
   branches/xesam-support/src/trackerd/tracker-db.c
   branches/xesam-support/src/trackerd/tracker-main.c
   branches/xesam-support/src/trackerd/tracker-monitor.c
   branches/xesam-support/src/trackerd/tracker-monitor.h
   branches/xesam-support/src/trackerd/tracker-xesam-manager.c
   branches/xesam-support/tests/Makefile.am
   branches/xesam-support/tests/common/Makefile.am
   branches/xesam-support/tests/scripts/Makefile.am
   branches/xesam-support/tests/trackerd/Makefile.am
   branches/xesam-support/tests/trackerd/xesam/Makefile.am

Modified: branches/xesam-support/README
==============================================================================
--- branches/xesam-support/README	(original)
+++ branches/xesam-support/README	Wed Jun 25 09:38:42 2008
@@ -167,6 +167,7 @@
   * w3m
   * wv 1.0.2
   * poppler (pdftotext)
+  * odt2txt 0.4 (indexing OpenOffice/ODF documents)
   * libvorbis
   * libpng
   * libexif

Modified: branches/xesam-support/configure.ac
==============================================================================
--- branches/xesam-support/configure.ac	(original)
+++ branches/xesam-support/configure.ac	Wed Jun 25 09:38:42 2008
@@ -722,8 +722,6 @@
 	thumbnailers/image/Makefile
 	src/Makefile
 	src/qdbm/Makefile
-	src/text-filters/Makefile
-	src/text-filters/ooo_converter/Makefile
 	src/tracker-extract/Makefile
 	src/tracker-thumbnailer/Makefile
 	src/libstemmer/Makefile
@@ -745,6 +743,7 @@
 	tests/libtracker-common/Makefile
 	tests/trackerd/Makefile
 	tests/trackerd/xesam/Makefile
+	tests/libtracker-db/Makefile
 	tests/scripts/dummy_data_start.sh
 	tests/scripts/dummy_data_stop.sh
 	tests/scripts/Makefile

Modified: branches/xesam-support/data/sqlite-stored-procs.sql
==============================================================================
--- branches/xesam-support/data/sqlite-stored-procs.sql	(original)
+++ branches/xesam-support/data/sqlite-stored-procs.sql	Wed Jun 25 09:38:42 2008
@@ -25,7 +25,6 @@
 GetNewID SELECT OptionValue FROM Options WHERE OptionKey = 'Sequence';
 UpdateNewID UPDATE Options set OptionValue = ? WHERE OptionKey = 'Sequence';
 CreateEvent INSERT INTO Events (ID, ServiceID, EventType) VALUES (?,?,?); 
-DeleteHandledEvents DELETE FROM cache.Events WHERE BeingHandled = 1;
 GetEvents SELECT ID, ServiceID, EventType FROM Events WHERE BeingHandled = 1;
 SetEventsBeingHandled UPDATE Events SET BeingHandled = 1;
 

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation-template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation-template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation-template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.presentation_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet-template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet-template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet-template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.spreadsheet_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.text-template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.text-template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.text-template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.oasis.opendocument.text_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.oasis.opendocument.text_filter	(original)
+++ branches/xesam-support/filters/application/vnd.oasis.opendocument.text_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.stardivision.writer_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.stardivision.writer_filter	(original)
+++ branches/xesam-support/filters/application/vnd.stardivision.writer_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.calc.template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.calc.template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.calc.template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.calc_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.calc_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.calc_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.draw_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.draw_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.draw_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.impress.template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.impress.template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.impress.template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.impress_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.impress_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.impress_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.writer.template_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.writer.template_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.writer.template_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/filters/application/vnd.sun.xml.writer_filter
==============================================================================
--- branches/xesam-support/filters/application/vnd.sun.xml.writer_filter	(original)
+++ branches/xesam-support/filters/application/vnd.sun.xml.writer_filter	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-nice -n19 unzip -p "$1" content.xml | o3totxt
+nice -n19 odt2txt "$1"

Modified: branches/xesam-support/src/Makefile.am
==============================================================================
--- branches/xesam-support/src/Makefile.am	(original)
+++ branches/xesam-support/src/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -22,7 +22,6 @@
 	libstemmer				\
 	xdgmime					\
 	$(qdbm_dir)				\
-	text-filters				\
 	libtracker-common 			\
 	libtracker-db				\
 	trackerd				\
@@ -33,4 +32,4 @@
 	$(libtrackergtk_dir)			\
 	$(tracker_gui_dir)			\
 	$(trackerapplet_dir) 			\
-	$(tracker_preferences_dir)
\ No newline at end of file
+	$(tracker_preferences_dir)

Modified: branches/xesam-support/src/libtracker-common/Makefile.am
==============================================================================
--- branches/xesam-support/src/libtracker-common/Makefile.am	(original)
+++ branches/xesam-support/src/libtracker-common/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -6,6 +6,7 @@
 	$(DBUS_CFLAGS)				\
 	$(UNAC_CFLAGS)				\
 	$(PANGO_CFLAGS)				\
+	$(GIO_CFLAGS)				\
 	$(GLIB2_CFLAGS)
 
 noinst_LTLIBRARIES = libtracker-common.la
@@ -61,5 +62,6 @@
 	$(DBUS_LIBS)				\
 	$(UNAC_LIBS)				\
 	$(PANGO_LIBS)				\
+	$(GIO_LIBS)				\
 	$(GLIB2_LIBS)
 

Modified: branches/xesam-support/src/libtracker-common/tracker-config.c
==============================================================================
--- branches/xesam-support/src/libtracker-common/tracker-config.c	(original)
+++ branches/xesam-support/src/libtracker-common/tracker-config.c	Wed Jun 25 09:38:42 2008
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 
 #include <glib.h>
+#include <gio/gio.h>
 
 #include "tracker-language.h"
 #include "tracker-config.h"
@@ -115,6 +116,9 @@
 typedef struct _TrackerConfigPriv TrackerConfigPriv;
 
 struct _TrackerConfigPriv {
+	GFile        *file;
+	GFileMonitor *monitor;
+
 	/* General */
 	gint	  verbosity;
 	gint	  initial_sleep;
@@ -172,8 +176,8 @@
 				 guint	       param_id,
 				 const GValue *value,
 				 GParamSpec   *pspec);
+static void config_load         (TrackerConfig *config);
 
-/* GObject properties */
 enum {
 	PROP_0,
 
@@ -577,6 +581,14 @@
 	g_free (priv->language);
 	g_free (priv->email_client);
 
+	if (priv->monitor) {
+		g_object_unref (priv->monitor);
+	}
+
+	if (priv->file) {
+		g_object_unref (priv->file);
+	}
+
 	(G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
 }
 
@@ -1369,8 +1381,39 @@
 }
 
 static void
+config_changed_cb (GFileMonitor     *monitor,
+		   GFile            *file,
+		   GFile            *other_file,
+		   GFileMonitorEvent event_type,
+		   gpointer          user_data)  
+{
+	TrackerConfig *config;
+	gchar         *filename;
+
+	config = TRACKER_CONFIG (user_data);
+
+	/* Do we recreate if the file is deleted? */
+
+	switch (event_type) {
+	case G_FILE_MONITOR_EVENT_CHANGED:
+	case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
+		filename = g_file_get_path (file);
+		g_message ("Config file changed:'%s', reloading settings...", 
+			   filename); 
+		g_free (filename);
+
+		config_load (config);
+		break;
+
+	default:
+		break;
+	}
+}
+
+static void
 config_load (TrackerConfig *config)
 {
+	TrackerConfigPriv *priv;
 	GKeyFile *key_file;
 	GError	 *error = NULL;
 	gchar	 *filename;
@@ -1389,6 +1432,27 @@
 	filename = g_build_filename (directory, "tracker.cfg", NULL);
 	g_free (directory);
 
+	priv = GET_PRIV (config);
+
+	/* Add file monitoring for changes */
+	if (!priv->file) {
+		priv->file = g_file_new_for_path (filename);
+	}
+
+	if (!priv->monitor) {
+		g_message ("Setting up monitor for changes to config file:'%s'", 
+			   filename);
+
+		priv->monitor = g_file_monitor_file (priv->file,
+						     G_FILE_MONITOR_NONE,
+						     NULL,
+						     NULL);
+		
+		g_signal_connect (priv->monitor, "changed",
+				  G_CALLBACK (config_changed_cb), 
+				  config);
+	}
+
 	/* Load options */
 	g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &error);
 	if (error) {

Modified: branches/xesam-support/src/libtracker-common/tracker-log.c
==============================================================================
--- branches/xesam-support/src/libtracker-common/tracker-log.c	(original)
+++ branches/xesam-support/src/libtracker-common/tracker-log.c	Wed Jun 25 09:38:42 2008
@@ -45,16 +45,18 @@
 static guint log_handler_id;
 
 static inline void
-log_output (const char *message)
+log_output (const gchar    *domain,
+	    GLogLevelFlags  log_level,
+	    const gchar    *message)
 {
-	FILE		*fd;
-	time_t	  	 now;
-	gchar	 	 time_str[64];
-	gchar            usec_str[20];
-	gchar		*output;
-	struct tm	*local_time;
-	GTimeVal	 current_time;
-	static size_t    size = 0;
+	FILE          *fd;
+	time_t         now;
+	gchar          time_str[64];
+	gchar         *output;
+	struct tm     *local_time;
+	GTimeVal       current_time;
+	static size_t  size = 0;
+	const gchar   *log_level_str;
 
 	g_return_if_fail (log != NULL);
 	g_return_if_fail (message != NULL && message[0] != '\0');
@@ -81,11 +83,30 @@
 	now = time ((time_t *) NULL);
 	local_time = localtime (&now);
 	strftime (time_str, 64, "%d %b %Y, %H:%M:%S:", local_time);
-	g_sprintf (usec_str, "%03ld", current_time.tv_usec / 1000); 
 
-	output = g_strdup_printf ("%s%s - %s", 
+	switch (log_level) {
+	case G_LOG_LEVEL_WARNING:
+		log_level_str = "-Warning **";
+		break;
+
+	case G_LOG_LEVEL_CRITICAL:
+		log_level_str = "-Critical **";
+		break;
+
+	case G_LOG_LEVEL_ERROR:
+		log_level_str = "-Error **";
+		break;
+
+	default:
+		log_level_str = NULL;
+		break;
+	}
+
+	output = g_strdup_printf ("%s%s %s%s: %s", 
+				  log_level_str ? "\n" : "",
 				  time_str, 
-				  usec_str, 
+				  domain,
+				  log_level_str ? log_level_str : "",
 				  message);
 
 	size += g_fprintf (fd, "%s\n", output);
@@ -108,7 +129,7 @@
 		return;
 	}
 
-	log_output (message);
+	log_output (domain, log_level, message);
 
 	/* now show the message through stdout/stderr as usual */
 	g_log_default_handler (domain, log_level, message, user_data);
@@ -121,7 +142,7 @@
 	g_return_if_fail (filename != NULL);
 
 	if (log != NULL) {
-		g_warning ("Logger already initialized (%s)", log->filename);
+		g_warning ("Log already initialized");
 		return;
 	}
 
@@ -130,8 +151,12 @@
 	log->mutex = g_mutex_new ();
 	log->verbosity = verbosity;
 
-	log_handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,
-					    tracker_log_handler, log);
+	log_handler_id = g_log_set_handler (NULL, 
+					    G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,
+					    tracker_log_handler, 
+					    log);
+
+	g_log_set_default_handler (tracker_log_handler, log);
 }
 
 void

Modified: branches/xesam-support/src/libtracker-db/tracker-db-interface-sqlite.c
==============================================================================
--- branches/xesam-support/src/libtracker-db/tracker-db-interface-sqlite.c	(original)
+++ branches/xesam-support/src/libtracker-db/tracker-db-interface-sqlite.c	Wed Jun 25 09:38:42 2008
@@ -516,18 +516,27 @@
 	TrackerDBInterfaceSqlitePrivate *priv;
 	TrackerDBResultSet *result_set;
 	sqlite3_stmt *stmt;
+        int retval;
 
 	priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (db_interface);
 
-	sqlite3_prepare_v2 (priv->db, query, -1, &stmt, NULL);
+	retval = sqlite3_prepare_v2 (priv->db, query, -1, &stmt, NULL);
 
-	if (!stmt) {
+        if (retval != SQLITE_OK) {
 		g_set_error (error,
 			     TRACKER_DB_INTERFACE_ERROR,
 			     TRACKER_DB_QUERY_ERROR,
 			     sqlite3_errmsg (priv->db));
 		return NULL;
-	}
+	} else if (stmt == NULL) {
+		g_set_error (error,
+			     TRACKER_DB_INTERFACE_ERROR,
+			     TRACKER_DB_QUERY_ERROR,
+			     "Could not prepare SQL statement:'%s'",
+                             query);
+
+		return NULL;
+        }
 
 	result_set = create_result_set_from_stmt (TRACKER_DB_INTERFACE_SQLITE (db_interface), stmt, error);
 	sqlite3_finalize (stmt);

Modified: branches/xesam-support/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/xesam-support/src/libtracker-db/tracker-db-manager.c	(original)
+++ branches/xesam-support/src/libtracker-db/tracker-db-manager.c	Wed Jun 25 09:38:42 2008
@@ -58,6 +58,7 @@
         gint                cache_size;
         gint                page_size;
         gboolean            add_functions;
+        gboolean            attached;
 } TrackerDBDefinition;
 
 static TrackerDBDefinition dbs[] = {
@@ -69,6 +70,7 @@
           NULL,
           32, 
           TRACKER_DB_PAGE_SIZE_DEFAULT, 
+          FALSE,
           FALSE },
         { TRACKER_DB_CACHE, 
           TRACKER_DB_LOCATION_SYS_TMP_DIR,
@@ -78,6 +80,7 @@
           NULL, 
           128,                          
           TRACKER_DB_PAGE_SIZE_DONT_SET, 
+          FALSE,
           FALSE },
         { TRACKER_DB_FILE_METADATA,
           TRACKER_DB_LOCATION_DATA_DIR,
@@ -87,7 +90,8 @@
           NULL,
           512,                          
           TRACKER_DB_PAGE_SIZE_DEFAULT, 
-          TRUE },
+          TRUE,
+          FALSE },
         { TRACKER_DB_FILE_CONTENTS,
           TRACKER_DB_LOCATION_DATA_DIR,
 	  NULL,
@@ -96,6 +100,7 @@
           NULL,
           1024,
           TRACKER_DB_PAGE_SIZE_DEFAULT,
+          FALSE,
           FALSE },
         { TRACKER_DB_EMAIL_METADATA,
           TRACKER_DB_LOCATION_DATA_DIR,
@@ -114,6 +119,7 @@
           NULL,
           512,
           TRACKER_DB_PAGE_SIZE_DEFAULT,
+          FALSE,
           FALSE },
         { TRACKER_DB_XESAM,
           TRACKER_DB_LOCATION_DATA_DIR,
@@ -123,7 +129,8 @@
           NULL,
           512,
           TRACKER_DB_PAGE_SIZE_DEFAULT,
-          TRUE },
+          TRUE,
+          FALSE },
 };
 
 static gboolean            db_exec_no_reply    (TrackerDBInterface *iface,
@@ -180,7 +187,8 @@
 	       const gchar        *delimiter)
 {
 	gchar *path, *content, **queries;
-	gint i;
+	gint   count;
+	gint   i;
 
 	path = g_build_filename (sql_dir, file, NULL);
 
@@ -196,11 +204,29 @@
 
 	queries = g_strsplit (content, delimiter, -1);
 
-	for (i = 0; queries[i]; i++) {
-		tracker_db_interface_execute_query (iface, NULL, queries[i]);
+	for (i = 0, count = 0; queries[i]; i++) {
+		GError *error = NULL;
+		gchar  *sql;
+
+		/* Skip white space, including control characters */
+		for (sql = queries[i]; sql && g_ascii_isspace (sql[0]); sql++);
+		
+		if (!sql || sql[0] == '\0') {
+			continue;
+		}
+
+		tracker_db_interface_execute_query (iface, &error, sql);
+
+		if (error) {
+			g_warning ("Error loading query:'%s' #%d, %s", file, i, error->message);
+			g_error_free (error);
+			continue;
+		}
+
+		count++;
 	}
 
-	g_message ("  Loaded SQL file:'%s'", file);
+	g_message ("  Loaded SQL file:'%s' (%d queries)", file, count);
 
 	g_strfreev (queries);
 	g_free (content);
@@ -1387,7 +1413,8 @@
 db_set_params (TrackerDBInterface *iface,
 	       gint                cache_size,
 	       gint                page_size,
-	       gboolean            add_functions)
+	       gboolean            add_functions,
+	       gboolean            created)
 {
 	tracker_db_interface_execute_query (iface, NULL, "PRAGMA synchronous = NORMAL;");
 	tracker_db_interface_execute_query (iface, NULL, "PRAGMA count_changes = 0;");
@@ -1412,27 +1439,29 @@
 			g_critical ("Collation sequence failed");
 		}
 
-		/* Create user defined functions that can be used in sql */
-		tracker_db_interface_sqlite_create_function (iface, 
-							     "FormatDate", 
-							     function_date_to_str, 
-							     1);
-		tracker_db_interface_sqlite_create_function (iface, 
-							     "GetServiceName", 
-							     function_get_service_name, 
-							     1);
-		tracker_db_interface_sqlite_create_function (iface, 
-							     "GetServiceTypeID", 
-							     function_get_service_type, 
-							     1);
-		tracker_db_interface_sqlite_create_function (iface, 
-							     "GetMaxServiceTypeID", 
-							     function_get_max_service_type, 
-							     1);
-		tracker_db_interface_sqlite_create_function (iface, 
-							     "REGEXP",
-							     function_regexp,
-							     2);
+		if (created) {
+			/* Create user defined functions that can be used in sql */
+			tracker_db_interface_sqlite_create_function (iface, 
+								     "FormatDate", 
+								     function_date_to_str, 
+								     1);
+			tracker_db_interface_sqlite_create_function (iface, 
+								     "GetServiceName", 
+								     function_get_service_name, 
+								     1);
+			tracker_db_interface_sqlite_create_function (iface, 
+								     "GetServiceTypeID", 
+								     function_get_service_type, 
+								     1);
+			tracker_db_interface_sqlite_create_function (iface, 
+								     "GetMaxServiceTypeID", 
+								     function_get_max_service_type, 
+								     1);
+			tracker_db_interface_sqlite_create_function (iface, 
+								     "REGEXP",
+								     function_regexp,
+								     2);
+		}
 	}
 }
 
@@ -1676,30 +1705,39 @@
 		 * are loaded into the right file instead of the
 		 * first one we create.
 		 */
-		if (attach_iface) {
-			g_message ("  Attaching");
+		if (attach_iface && dbs[type].attached) {
+			g_message ("  Already attached '%s' as '%s'", 
+				   dbs[type].abs_filename,
+				   dbs[type].name);
+		}
+
+		if (attach_iface && !dbs[type].attached) {
+
+			g_message ("  Attaching '%s' as '%s'", 
+				   dbs[type].abs_filename,
+				   dbs[type].name);
+
 			db_exec_no_reply (attach_iface, 
-					  "ATTACH '%s' as %s",
+					  "ATTACH '%s' as '%s'",
 					  dbs[type].abs_filename,
 					  dbs[type].name);
-		} else {
+
+			dbs[type].attached = TRUE;
+		} else if (!attach_iface) {
 			attach_iface = iface;
 		}
 	} else {
 		iface = tracker_db_interface_sqlite_new (path);
 		tracker_db_interface_set_procedure_table (iface, 
 							  prepared_queries);
-
-		/* FIXME: Shouldn't we do this for common/cache dbs too? */
-		if (type != TRACKER_DB_COMMON &&
-		    type != TRACKER_DB_CACHE) {
-			db_set_params (iface,
-				       dbs[type].cache_size,
-				       dbs[type].page_size,
-				       dbs[type].add_functions);
-		}
 	}
 
+	db_set_params (iface,
+		       dbs[type].cache_size,
+		       dbs[type].page_size,
+		       dbs[type].add_functions,
+		       *create);
+
 	return iface;
 }
 
@@ -2026,7 +2064,7 @@
 		}
 	}
 	
-	g_object_unref (result_set);	
+	g_object_unref (result_set);
 
 	return TRUE;
 }
@@ -2036,7 +2074,6 @@
 {
 	TrackerDBInterface *iface;
 	gboolean            create;
-	guint               i;
 
 	iface = db_interface_get (TRACKER_DB_XESAM, &create);
 
@@ -2063,19 +2100,6 @@
 		tracker_db_interface_end_transaction (iface);
 	}
 
-	/* Xesam's DB connection depends on all interfaces being attached. 
-	 * The current initialization code does not guarantee that all are
-	 * at this point indeed already attached. */
-
-	for (i = 0; i < G_N_ELEMENTS (dbs); i++) {
-		gboolean            dummy;
-		TrackerDBInterface *dependency_iface;
-
-		dependency_iface = db_interface_get (dbs[i].db, &dummy);
-		g_object_unref (dependency_iface);
-		/* If it was not yet created, we have a problem */
-		g_assert (!dummy);
-	}
 
 	/* Load static xesam data */
 	db_get_static_xesam_data (attach_iface);
@@ -2154,18 +2178,17 @@
 }
 
 void
-tracker_db_manager_init (gboolean  attach_all_dbs,
-			 gboolean  force_reindex,
-			 gboolean *first_time_index)
+tracker_db_manager_init (TrackerDBManagerFlags  flags,
+			 gboolean              *first_time)
 {
-	GType        etype;
-	gchar       *filename;
-	const gchar *dir;
-	gboolean     need_reindex;
-	guint        i;
+	GType               etype;
+	gchar              *filename;
+	const gchar        *dir;
+	gboolean            need_reindex;
+	guint               i;
 
-	if (first_time_index) {
-		*first_time_index = FALSE;
+	if (first_time) {
+		*first_time = FALSE;
 	}
 
         if (initialized) {
@@ -2256,9 +2279,9 @@
 	 * NOT the paths, note, that these paths are also used for
 	 * other things like the nfs lock file.
 	 */
-	if (force_reindex || need_reindex) {
-		if (first_time_index) {
-			*first_time_index = TRUE;
+	if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX || need_reindex) {
+		if (first_time) {
+			*first_time = TRUE;
 		}
 
 		g_message ("Removing database files for reindex");
@@ -2303,15 +2326,17 @@
 		 * each time we start up, this is meant to be a per-run
 		 * thing.
 		 */
-		g_message ("Removing cache database:'%s'", 
-			   dbs[TRACKER_DB_CACHE].abs_filename);
-		g_unlink (dbs[TRACKER_DB_CACHE].abs_filename);
+		if (flags & TRACKER_DB_MANAGER_REMOVE_CACHE) {
+			g_message ("Removing cache database:'%s'", 
+				   dbs[TRACKER_DB_CACHE].abs_filename);
+			g_unlink (dbs[TRACKER_DB_CACHE].abs_filename);
+		}
 
 		/* Make sure we initialize all other modules we depend on */
 		tracker_ontology_init ();
 	}
 
-	attach_all = attach_all_dbs;
+	attach_all = flags & TRACKER_DB_MANAGER_ATTACH_ALL;
 
 	/* Load databases */
 	g_message ("Loading databases files...");
@@ -2320,11 +2345,36 @@
 		dbs[i].iface = db_interface_create (i);
 	}
 
+	if (attach_all) {
+		TrackerDBInterface *dummy;
+
+		dummy = db_interface_get_common ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_cache ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_file_contents ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_file_metadata ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_email_metadata ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_email_metadata ();
+		g_object_unref (dummy);
+
+		dummy = db_interface_get_xesam ();
+		g_object_unref (dummy);
+	}
+
 	initialized = TRUE;
 }
 
 void
-tracker_db_manager_shutdown (void) 
+tracker_db_manager_shutdown (gboolean remove_tmp) 
 {
         guint i;
 
@@ -2348,8 +2398,10 @@
 	prepared_queries = NULL;
 
 	/* Remove directory in tmp */
-	g_message ("Removing directory:'%s'", sys_tmp_dir);
-	tracker_path_remove (sys_tmp_dir);
+	if (remove_tmp) {
+		g_message ("Removing directory:'%s'", sys_tmp_dir);
+		tracker_path_remove (sys_tmp_dir);
+	}
 
 	g_free (data_dir);
 	g_free (user_data_dir);
@@ -2386,6 +2438,45 @@
 }
 
 TrackerDBInterface *
+tracker_db_manager_get_db_interfaces (gint num, ...)
+{
+	gint                n_args;
+	va_list             args;
+	TrackerDBInterface *connection = NULL;
+
+	va_start (args, num);
+	for (n_args = 1; n_args <= num; n_args++) {
+		TrackerDB db = va_arg (args, TrackerDB);
+
+		if (!connection) {
+			connection = tracker_db_interface_sqlite_new (dbs[db].abs_filename);
+			tracker_db_interface_set_procedure_table (connection, 
+								  prepared_queries);
+
+			/* You could set specific cache and page sizes for the
+			 * indexer's INSERT connection here. */
+
+			db_set_params (connection,
+				       dbs[db].cache_size,
+				       dbs[db].page_size,
+				       TRUE,
+				       FALSE);
+
+		} else {
+			db_exec_no_reply (connection, 
+					  "ATTACH '%s' as '%s'",
+					  dbs[db].abs_filename,
+					  dbs[db].name);
+		}
+
+	}
+	va_end (args);
+
+	return connection;
+}
+
+
+TrackerDBInterface *
 tracker_db_manager_get_db_interface (TrackerDB db)
 {
 	g_return_val_if_fail (initialized != FALSE, NULL);

Modified: branches/xesam-support/src/libtracker-db/tracker-db-manager.h
==============================================================================
--- branches/xesam-support/src/libtracker-db/tracker-db-manager.h	(original)
+++ branches/xesam-support/src/libtracker-db/tracker-db-manager.h	Wed Jun 25 09:38:42 2008
@@ -39,23 +39,30 @@
 	TRACKER_DB_XESAM,
 } TrackerDB;
 
+typedef enum {
+	TRACKER_DB_MANAGER_ATTACH_ALL    = 1 << 0,
+	TRACKER_DB_MANAGER_FORCE_REINDEX = 1 << 1,
+	TRACKER_DB_MANAGER_REMOVE_CACHE  = 1 << 2,
+} TrackerDBManagerFlags;
+
 GType        tracker_db_get_type                            (void) G_GNUC_CONST;
 
-void         tracker_db_manager_init                        (gboolean            attach_all_dbs,
-							     gboolean            force_reindex,
-							     gboolean           *first_time_index);
-void         tracker_db_manager_shutdown                    (void);
+void         tracker_db_manager_init                        (TrackerDBManagerFlags  flags,
+							     gboolean              *first_time);
+void         tracker_db_manager_shutdown                    (gboolean remove_tmp);
 
 void         tracker_db_manager_close_all                   (void);
 
-const gchar *tracker_db_manager_get_file                    (TrackerDB           db);
+const gchar *tracker_db_manager_get_file                    (TrackerDB              db);
+TrackerDBInterface *
+             tracker_db_manager_get_db_interface            (TrackerDB              db);
 TrackerDBInterface *
-             tracker_db_manager_get_db_interface            (TrackerDB           db);
+             tracker_db_manager_get_db_interfaces           (gint num, ...);
 TrackerDBInterface *
-             tracker_db_manager_get_db_interface_by_service (const gchar        *service, 
-							     gboolean            content);
+             tracker_db_manager_get_db_interface_by_service (const gchar           *service, 
+							     gboolean               content);
 TrackerDBInterface *
-             tracker_db_manager_get_db_interface_content    (TrackerDBInterface *iface);
+             tracker_db_manager_get_db_interface_content    (TrackerDBInterface    *iface);
 
 G_END_DECLS
 

Modified: branches/xesam-support/src/libtracker/tracker.c
==============================================================================
--- branches/xesam-support/src/libtracker/tracker.c	(original)
+++ branches/xesam-support/src/libtracker/tracker.c	Wed Jun 25 09:38:42 2008
@@ -1488,5 +1488,45 @@
 	}
 }
 
+void
+tracker_search_metadata_by_text_and_mime_async (TrackerClient *client, const char *query, const char **mimes, TrackerArrayReply callback, gpointer user_data)
+{
+	ArrayCallBackStruct *callback_struct;
 
+	callback_struct = g_new (ArrayCallBackStruct, 1);
+	callback_struct->callback = callback;
+	callback_struct->data = user_data;	
+
+	client->last_pending_call = org_freedesktop_Tracker_Files_search_by_text_and_mime_async  (client->proxy_files, query,(const char **) mimes,  tracker_array_reply, callback_struct);
+	
+}
+
+
+void
+tracker_search_metadata_by_text_and_mime_and_location_async (TrackerClient *client, const char *query, const char **mimes, const char *location, TrackerArrayReply callback, gpointer user_data)
+{
+	ArrayCallBackStruct *callback_struct;
+
+	callback_struct = g_new (ArrayCallBackStruct, 1);
+	callback_struct->callback = callback;
+	callback_struct->data = user_data;	
+
+	client->last_pending_call = org_freedesktop_Tracker_Files_search_by_text_and_mime_and_location_async (client->proxy_files, query, (const char **)mimes, location,  tracker_array_reply, callback_struct);
+	
+}
+
+
+
+void
+tracker_search_metadata_by_text_and_location_async (TrackerClient *client, const char *query, const char *location, TrackerArrayReply callback, gpointer user_data)
+{
+	ArrayCallBackStruct *callback_struct;
+
+	callback_struct = g_new (ArrayCallBackStruct, 1);
+	callback_struct->callback = callback;
+	callback_struct->data = user_data;	
+
+	client->last_pending_call = org_freedesktop_Tracker_Files_search_by_text_and_location_async (client->proxy_files, query, location,  tracker_array_reply, callback_struct);
+	
+}
 

Modified: branches/xesam-support/src/tracker-indexer/Makefile.am
==============================================================================
--- branches/xesam-support/src/tracker-indexer/Makefile.am	(original)
+++ branches/xesam-support/src/tracker-indexer/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -5,10 +5,12 @@
 	-DLIBDIR=\""$(libdir)"\"					\
 	-DLOCALEDIR=\""$(localedir)"\" 					\
 	-DINDEXER_MODULES_DIR=\""$(libdir)"/tracker/indexer-modules\"	\
-	-DG_LOG_DOMAIN=\"Tracker-Indexer\"				\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
 	-I$(top_srcdir)/src						\
 	$(DBUS_CFLAGS)							\
 	$(GMODULE_CFLAGS)						\
+	$(GTHREAD_LIBS)							\
+	$(GIO_LIBS)							\
 	$(GLIB2_CFLAGS)
 
 bin_PROGRAMS = tracker-indexer
@@ -28,7 +30,8 @@
 	tracker-indexer-module.h					\
 	tracker-main.c							\
 	tracker-metadata.c						\
-	tracker-metadata.h
+	tracker-metadata.h						\
+	tracker-module.h
 
 tracker_indexer_LDADD =							\
 	$(top_builddir)/src/libtracker-db/libtracker-db.la 		\
@@ -39,6 +42,7 @@
 	$(DBUS_LIBS)							\
 	$(GMODULE_LIBS)							\
 	$(GTHREAD_LIBS)							\
+	$(GIO_LIBS)							\
 	$(GLIB2_LIBS)							\
 	-lz								\
 	-lm

Modified: branches/xesam-support/src/tracker-indexer/modules/Makefile.am
==============================================================================
--- branches/xesam-support/src/tracker-indexer/modules/Makefile.am	(original)
+++ branches/xesam-support/src/tracker-indexer/modules/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -6,20 +6,26 @@
 	-DLIBDIR=\""$(libdir)"\"					\
 	-DLOCALEDIR=\""$(localedir)"\" 					\
 	-DINDEXER_MODULES_DIR=\"$(indexer_modulesdir)\"			\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
+	-D_GNU_SOURCE							\
 	-I$(top_srcdir)/src						\
 	$(GMODULE_CFLAGS)						\
-	$(GLIB2_CFLAGS)
+	$(GIO_LIBS)							\
+	$(GLIB2_CFLAGS)							\
+	$(GMIME_CFLAGS)
 
 indexer_modules_LTLIBRARIES = 						\
 	libtracker-indexer-applications.la				\
 	libtracker-indexer-files.la					\
-	libtracker-indexer-gaim-conversations.la
+	libtracker-indexer-gaim-conversations.la			\
+	libtracker-indexer-evolution.la
 
 # Applications module
 libtracker_indexer_applications_la_SOURCES = applications.c
 libtracker_indexer_applications_la_LDFLAGS = $(module_flags)
 libtracker_indexer_applications_la_LIBADD = 				\
 	$(GMODULE_LIBS)							\
+	$(GIO_LIBS)							\
 	$(GLIB2_LIBS)
 
 # Files module
@@ -29,6 +35,7 @@
 	$(top_builddir)/src/libtracker-db/libtracker-db.la		\
 	$(top_builddir)/src/xdgmime/libxdgmime.la			\
 	$(GMODULE_LIBS)							\
+	$(GIO_LIBS)							\
 	$(GLIB2_LIBS)
 
 # Instant messaging module
@@ -36,4 +43,13 @@
 libtracker_indexer_gaim_conversations_la_LDFLAGS = $(module_flags)
 libtracker_indexer_gaim_conversations_la_LIBADD = 			\
 	$(GMODULE_LIBS)							\
+	$(GIO_LIBS)							\
 	$(GLIB2_LIBS)
+
+# Evolution
+libtracker_indexer_evolution_la_SOURCES = evolution.c
+libtracker_indexer_evolution_la_LDFLAGS = $(module_flags)
+libtracker_indexer_evolution_la_LIBADD = 				\
+	$(GMODULE_LIBS)							\
+	$(GLIB2_LIBS)							\
+	$(GMIME_LIBS)

Modified: branches/xesam-support/src/tracker-indexer/modules/applications.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/modules/applications.c	(original)
+++ branches/xesam-support/src/tracker-indexer/modules/applications.c	Wed Jun 25 09:38:42 2008
@@ -19,6 +19,7 @@
 
 #include <stdlib.h>
 #include <glib.h>
+#include <tracker-indexer/tracker-module.h>
 
 #define GROUP_DESKTOP_ENTRY "Desktop Entry"
 #define KEY_TYPE            "Type"
@@ -112,20 +113,20 @@
 }
 
 GHashTable *
-tracker_module_get_file_metadata (const gchar *file)
+tracker_module_file_get_metadata (TrackerFile *file)
 {
 	GHashTable *metadata;
 	GKeyFile *key_file;
 	gchar *type, *filename;
 
 	/* Check we're dealing with a desktop file */
-	if (!g_str_has_suffix (file, ".desktop")) {
+	if (!g_str_has_suffix (file->path, ".desktop")) {
 		return NULL;
 	}
 
 	key_file = g_key_file_new ();
 
-	if (!g_key_file_load_from_file (key_file, file, G_KEY_FILE_NONE, NULL)) {
+	if (!g_key_file_load_from_file (key_file, file->path, G_KEY_FILE_NONE, NULL)) {
 		g_key_file_free (key_file);
 		return NULL;
 	}
@@ -157,7 +158,7 @@
 
 	/* FIXME: mimetypes list and categories? */
 
-	filename = g_filename_display_basename (file);
+	filename = g_filename_display_basename (file->path);
 	g_hash_table_insert (metadata, METADATA_FILE_NAME, filename);
 
 	g_key_file_free (key_file);

Modified: branches/xesam-support/src/tracker-indexer/modules/dummy.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/modules/dummy.c	(original)
+++ branches/xesam-support/src/tracker-indexer/modules/dummy.c	Wed Jun 25 09:38:42 2008
@@ -29,13 +29,68 @@
 gchar **
 tracker_module_get_directories (void)
 {
-	/* Return directories/files to scan */
+	/* Return directories/files (a NULL-ended array of gchar*) to scan */
 	return NULL;
 }
 
+gpointer
+tracker_module_file_get_data (const gchar *path)
+{
+        /* Implementing this function is optional.
+         *
+         * Return here private, module specific data for path.
+         * Given this data is attached to the file until it isn't
+         * needed anymore. This is usually used for files that
+         * contain sets of data that should be considered as separate
+         * entities (for example, mboxes), so the module can internally
+         * keep the state. Also see tracker_module_file_iter_contents().
+         */
+        return NULL;
+}
+
+void
+tracker_module_file_free_data (gpointer file_data)
+{
+        /* Implementing this function is optional
+         *
+         * Free the data created previously
+         * through tracker_module_file_get_data()
+         */
+}
+
 GHashTable *
-tracker_module_get_file_metadata (const gchar *file)
+tracker_module_file_get_metadata (TrackerFile *file)
 {
-	/* Return a hashtable filled with metadata for the file */
+	/* Return a hashtable filled with metadata for file, given the
+         * current state. Also see tracker_module_file_iter_contents()
+         */
 	return NULL;
 }
+
+gchar *
+tracker_module_file_get_text (TrackerFile *file)
+{
+        /* Implementing this function is optional
+         *
+         * Return here full text for file, given the current state,
+         * also see tracker_module_file_iter_contents()
+         */
+        return NULL;
+}
+
+gboolean
+tracker_module_file_iter_contents (TrackerFile *file)
+{
+        /* Implementing this function is optional
+         *
+         * This function is meant to iterate the internal state,
+         * so it points to the next entity inside the file.
+         * In case there is such next entity, this function must
+         * return TRUE, else, returning FALSE will make the indexer
+         * think it is done with this file and move on to the next one.
+         *
+         * What an "entity" is considered is left to the module
+         * implementation.
+         */
+        return FALSE;
+}

Modified: branches/xesam-support/src/tracker-indexer/modules/files.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/modules/files.c	(original)
+++ branches/xesam-support/src/tracker-indexer/modules/files.c	Wed Jun 25 09:38:42 2008
@@ -29,6 +29,7 @@
 #include <libtracker-common/tracker-type-utils.h>
 #include <libtracker-common/tracker-os-dependant.h>
 #include <libtracker-common/tracker-ontology.h>
+#include <tracker-indexer/tracker-module.h>
 
 #define METADATA_FILE_NAME_DELIMITED "File:NameDelimited"
 #define METADATA_FILE_EXT            "File:Ext"
@@ -243,39 +244,42 @@
 }
 
 GHashTable *
-tracker_module_get_file_metadata (const gchar *file)
+tracker_module_file_get_metadata (TrackerFile *file)
 {
+	const gchar *path;
 	GHashTable *metadata;
 	struct stat st;
 	const gchar *ext;
 	gchar *mimetype;
 
-	if (check_exclude_file (file)) {
+	path = file->path;
+
+	if (check_exclude_file (path)) {
 		return NULL;
 	}
 
-	g_lstat (file, &st);
+	g_lstat (path, &st);
 	metadata = g_hash_table_new_full (g_str_hash, g_str_equal,
 					  NULL,
 					  (GDestroyNotify) g_free);
-	ext = strrchr (file, '.');
+	ext = strrchr (path, '.');
 
 	if (ext) {
 		g_hash_table_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
 	}
 
-	mimetype = tracker_file_get_mime_type (file);
+	mimetype = tracker_file_get_mime_type (path);
 
-	g_hash_table_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (file));
-	g_hash_table_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (file));
+	g_hash_table_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (path));
+	g_hash_table_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (path));
 	g_hash_table_insert (metadata, METADATA_FILE_NAME_DELIMITED,
-			     g_filename_to_utf8 (file, -1, NULL, NULL, NULL));
+			     g_filename_to_utf8 (path, -1, NULL, NULL, NULL));
 	g_hash_table_insert (metadata, METADATA_FILE_MIMETYPE, mimetype);
 
 	if (S_ISLNK (st.st_mode)) {
 		gchar *link_path;
 
-		link_path = g_file_read_link (file, NULL);
+		link_path = g_file_read_link (path, NULL);
 		g_hash_table_insert (metadata, METADATA_FILE_LINK,
 				     g_filename_to_utf8 (link_path, -1, NULL, NULL, NULL));
 		g_free (link_path);
@@ -289,12 +293,12 @@
 	g_hash_table_insert (metadata, METADATA_FILE_ACCESSED,
 			     tracker_uint_to_string (st.st_atime));
 
-	tracker_metadata_get_embedded (file, mimetype, metadata);
+	tracker_metadata_get_embedded (path, mimetype, metadata);
 
 	return metadata;
 }
 
-gchar *
+static gchar *
 tracker_metadata_call_text_filter (const gchar *path,
 				   const gchar *mime)
 {
@@ -335,12 +339,12 @@
 }
 
 gchar *
-tracker_module_get_file_text (const gchar *file)
+tracker_module_file_get_text (TrackerFile *file)
 {
 	gchar *mimetype, *service_type;
 	gchar *text = NULL;
 
-	mimetype = tracker_file_get_mime_type (file);
+	mimetype = tracker_file_get_mime_type (file->path);
 	service_type = tracker_ontology_get_service_type_for_mime (mimetype);
 
 	/* No need to filter text based files - index them directly */
@@ -349,14 +353,14 @@
              strcmp (service_type, "Development") == 0)) {
 		GMappedFile *mapped_file;
 
-		mapped_file = g_mapped_file_new (file, FALSE, NULL);
+		mapped_file = g_mapped_file_new (file->path, FALSE, NULL);
 
 		if (mapped_file) {
 			text = g_strdup (g_mapped_file_get_contents (mapped_file));
 			g_mapped_file_free (mapped_file);
 		}
 	} else {
-		text = tracker_metadata_call_text_filter (file, mimetype);
+		text = tracker_metadata_call_text_filter (file->path, mimetype);
 	}
 
 	g_free (mimetype);

Modified: branches/xesam-support/src/tracker-indexer/tracker-index.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-index.c	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-index.c	Wed Jun 25 09:38:42 2008
@@ -155,10 +155,15 @@
 	return TRUE;
 }
 
-void
+guint
 tracker_index_flush (TrackerIndex *index)
 {
-	g_message ("Flushing index");
+	guint size;
+
+	size = g_hash_table_size (index->cache);
+	g_message ("Flushing index with %d items", size);
 
 	g_hash_table_foreach_remove (index->cache, cache_flush_foreach, index->index);
+
+	return size;
 }

Modified: branches/xesam-support/src/tracker-indexer/tracker-index.h
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-index.h	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-index.h	Wed Jun 25 09:38:42 2008
@@ -38,7 +38,7 @@
 				       gint          service_type,
 				       gint          weight);
 
-void           tracker_index_flush    (TrackerIndex *index);
+guint          tracker_index_flush    (TrackerIndex *index);
 
 
 G_END_DECLS

Modified: branches/xesam-support/src/tracker-indexer/tracker-indexer-module.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-indexer-module.c	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-indexer-module.c	Wed Jun 25 09:38:42 2008
@@ -23,11 +23,6 @@
 
 #include "tracker-indexer-module.h"
 
-typedef const gchar * (* TrackerIndexerModuleGetName) (void);
-typedef gchar **      (* TrackerIndexerModuleGetDirectories) (void);
-typedef GHashTable *  (* TrackerIndexerModuleGetData) (const gchar *path);
-typedef gchar *       (* TrackerIndexerModuleGetText) (const gchar *path);
-
 GModule *
 tracker_indexer_module_load (const gchar *module_name)
 {
@@ -56,7 +51,7 @@
 G_CONST_RETURN gchar *
 tracker_indexer_module_get_name (GModule *module)
 {
-	TrackerIndexerModuleGetName func;
+	TrackerModuleGetNameFunc func;
 
 	if (g_module_symbol (module, "tracker_module_get_name", (gpointer *) &func)) {
 		return (func) ();
@@ -68,7 +63,7 @@
 gchar **
 tracker_indexer_module_get_directories (GModule *module)
 {
-	TrackerIndexerModuleGetDirectories func;
+	TrackerModuleGetDirectoriesFunc func;
 
 	if (g_module_symbol (module, "tracker_module_get_directories", (gpointer *) &func)) {
 		return (func) ();
@@ -80,7 +75,7 @@
 gchar **
 tracker_indexer_module_get_ignore_directories (GModule *module)
 {
-	TrackerIndexerModuleGetDirectories func;
+	TrackerModuleGetDirectoriesFunc func;
 
 	if (g_module_symbol (module, "tracker_module_get_ignore_directories", (gpointer *) &func)) {
 		return (func) ();
@@ -89,13 +84,45 @@
 	return NULL;
 }
 
+TrackerFile *
+tracker_indexer_module_file_new (GModule     *module,
+				 const gchar *path)
+{
+	TrackerModuleFileGetDataFunc func;
+	TrackerFile *file = NULL;
+
+	file = g_slice_new0 (TrackerFile);
+	file->path = g_strdup (path);
+
+	if (g_module_symbol (module, "tracker_module_file_get_data", (gpointer *) &func)) {
+		file->data = (func) (path);
+	}
+
+	return file;
+}
+
+void
+tracker_indexer_module_file_free (GModule     *module,
+				  TrackerFile *file)
+{
+	TrackerModuleFileFreeDataFunc func;
+
+	if (file->data &&
+	    g_module_symbol (module, "tracker_module_file_free_data", (gpointer *) &func)) {
+		(func) (file->data);
+	}
+
+	g_free (file->path);
+	g_slice_free (TrackerFile, file);
+}
+
 GHashTable *
-tracker_indexer_module_get_file_metadata (GModule     *module,
-					  const gchar *file)
+tracker_indexer_module_file_get_metadata (GModule     *module,
+					  TrackerFile *file)
 {
-	TrackerIndexerModuleGetData func;
+	TrackerModuleFileGetMetadataFunc func;
 
-	if (g_module_symbol (module, "tracker_module_get_file_metadata", (gpointer *) &func)) {
+	if (g_module_symbol (module, "tracker_module_file_get_metadata", (gpointer *) &func)) {
 		return (func) (file);
         }
 
@@ -103,14 +130,27 @@
 }
 
 gchar *
-tracker_indexer_module_get_text (GModule     *module,
-				 const gchar *file)
+tracker_indexer_module_file_get_text (GModule     *module,
+				      TrackerFile *file)
 {
-	TrackerIndexerModuleGetText func;
+	TrackerModuleFileGetText func;
 
-	if (g_module_symbol (module, "tracker_module_get_file_text", (gpointer *) &func)) {
+	if (g_module_symbol (module, "tracker_module_file_get_text", (gpointer *) &func)) {
 		return (func) (file);
         }
 
 	return NULL;
 }
+
+gboolean
+tracker_indexer_module_file_iter_contents (GModule     *module,
+					   TrackerFile *file)
+{
+	TrackerModuleFileIterContents func;
+
+	if (file->data && g_module_symbol (module, "tracker_module_file_iter_contents", (gpointer *) &func)) {
+		return (func) (file);
+	}
+
+	return FALSE;
+}

Modified: branches/xesam-support/src/tracker-indexer/tracker-indexer-module.h
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-indexer-module.h	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-indexer-module.h	Wed Jun 25 09:38:42 2008
@@ -23,6 +23,7 @@
 #define __TRACKER_INDEXER_MODULE_H__
 
 #include <glib.h>
+#include "tracker-module.h"
 
 G_BEGIN_DECLS
 
@@ -32,10 +33,18 @@
 gchar **                tracker_indexer_module_get_directories        (GModule     *module);
 gchar **                tracker_indexer_module_get_ignore_directories (GModule     *module);
 
-GHashTable *            tracker_indexer_module_get_file_metadata      (GModule     *module,
-								       const gchar *file);
-gchar *                 tracker_indexer_module_get_text               (GModule     *module,
-								       const gchar *file);
+TrackerFile *           tracker_indexer_module_file_new               (GModule     *module,
+								       const gchar *path);
+void                    tracker_indexer_module_file_free              (GModule     *module,
+								       TrackerFile *file);
+
+GHashTable *            tracker_indexer_module_file_get_metadata      (GModule     *module,
+								       TrackerFile *file);
+gchar *                 tracker_indexer_module_file_get_text          (GModule     *module,
+								       TrackerFile *file);
+
+gboolean                tracker_indexer_module_file_iter_contents     (GModule     *module,
+								       TrackerFile *file);
 
 G_END_DECLS
 

Modified: branches/xesam-support/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-indexer.c	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-indexer.c	Wed Jun 25 09:38:42 2008
@@ -61,9 +61,13 @@
 #include "tracker-indexer-module.h"
 #include "tracker-indexer-db.h"
 #include "tracker-index.h"
+#include "tracker-module.h"
 
 #define TRACKER_INDEXER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_INDEXER, TrackerIndexerPrivate))
 
+/* Flush every 'x' seconds */
+#define FLUSH_FREQUENCY 10
+
 typedef struct TrackerIndexerPrivate TrackerIndexerPrivate;
 typedef struct PathInfo PathInfo;
 typedef struct MetadataForeachData MetadataForeachData;
@@ -82,16 +86,21 @@
 	TrackerDBInterface *metadata;
 	TrackerDBInterface *contents;
 	TrackerDBInterface *common;
+	TrackerDBInterface *cache;
 
 	TrackerConfig *config;
 	TrackerLanguage *language;
 
+	GTimer *timer;
+	guint   items_indexed;
+
 	guint idle_id;
+	guint flush_id;
 };
 
 struct PathInfo {
 	GModule *module;
-	gchar *path;
+	TrackerFile *file;
 };
 
 struct MetadataForeachData {
@@ -127,7 +136,7 @@
 
 	info = g_slice_new (PathInfo);
 	info->module = module;
-	info->path = g_strdup (path);
+	info->file = tracker_indexer_module_file_new (module, path);
 
 	return info;
 }
@@ -135,10 +144,44 @@
 static void
 path_info_free (PathInfo *info)
 {
-	g_free (info->path);
+	tracker_indexer_module_file_free (info->module, info->file);
 	g_slice_free (PathInfo, info);
 }
 
+static gboolean
+schedule_flush_cb (gpointer data)
+{
+	TrackerIndexer        *indexer;
+	TrackerIndexerPrivate *priv;
+
+	indexer = TRACKER_INDEXER (data);
+	priv = TRACKER_INDEXER_GET_PRIVATE (indexer);
+
+	priv->flush_id = 0;
+
+	priv->items_indexed += tracker_index_flush (priv->index);
+
+	return FALSE;
+}
+
+static void
+schedule_flush (TrackerIndexer *indexer,
+		gboolean        immediately)
+{
+	TrackerIndexerPrivate *priv;
+
+        priv = TRACKER_INDEXER_GET_PRIVATE (indexer);
+
+	if (immediately) {
+		priv->items_indexed += tracker_index_flush (priv->index);
+		return;
+	}
+
+	priv->flush_id = g_timeout_add_seconds (FLUSH_FREQUENCY, 
+						schedule_flush_cb, 
+						indexer);
+}
+
 static void
 tracker_indexer_finalize (GObject *object)
 {
@@ -146,6 +189,18 @@
 
 	priv = TRACKER_INDEXER_GET_PRIVATE (object);
 
+	/* Important! Make sure we flush if we are scheduled to do so,
+	 * and do that first.
+	 */
+	if (priv->flush_id) {
+		g_source_remove (priv->flush_id);
+		schedule_flush (TRACKER_INDEXER (object), TRUE);
+	}	
+
+	if (priv->timer) {
+		g_timer_destroy (priv->timer);
+	}
+
 	g_free (priv->db_dir);
 
 	g_queue_foreach (priv->dir_queue, (GFunc) path_info_free, NULL);
@@ -286,10 +341,13 @@
 	priv->index = tracker_index_new (index_file,
 					 tracker_config_get_max_bucket_count (priv->config));
 
+	priv->cache = tracker_db_manager_get_db_interface (TRACKER_DB_CACHE);
 	priv->common = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
-	priv->metadata = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_METADATA);
+	priv->metadata = tracker_db_manager_get_db_interfaces (3, TRACKER_DB_COMMON, TRACKER_DB_CACHE, TRACKER_DB_FILE_METADATA);
 	priv->contents = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_CONTENTS);
 
+	priv->timer = g_timer_new ();
+
 	tracker_indexer_set_running (indexer, TRUE, NULL);
 
 	g_free (index_file);
@@ -325,7 +383,7 @@
 
 	if (ignore_dirs) {
 		for (i = 0; ignore_dirs[i]; i++) {
-			if (strcmp (info->path, ignore_dirs[i]) == 0) {
+			if (strcmp (info->file->path, ignore_dirs[i]) == 0) {
 				ignore = TRUE;
 				break;
 			}
@@ -335,7 +393,7 @@
 	if (!ignore) {
 		g_queue_push_tail (priv->dir_queue, info);
 	} else {
-		g_message ("Ignoring directory:'%s'", info->path);
+		g_message ("Ignoring directory:'%s'", info->file->path);
 		path_info_free (info);
 	}
 
@@ -403,19 +461,20 @@
 
 	g_hash_table_foreach (metadata, index_metadata_foreach, &data);
 
-	/* FIXME: flushing after adding each metadata set, not ideal */
-	tracker_index_flush (priv->index);
+	if (!priv->flush_id) {
+		schedule_flush (indexer, FALSE);
+	}
 }
 
-static void
+static gboolean
 process_file (TrackerIndexer *indexer,
 	      PathInfo       *info)
 {
 	GHashTable *metadata;
 
-	g_message ("Processing file:'%s'", info->path);
+	g_message ("Processing file:'%s'", info->file->path);
 
-	metadata = tracker_indexer_module_get_file_metadata (info->module, info->path);
+	metadata = tracker_indexer_module_file_get_metadata (info->module, info->file);
 
 	if (metadata) {
 		TrackerService *service;
@@ -429,28 +488,43 @@
 		service = tracker_ontology_get_service_type_by_name (service_type);
 		id = tracker_db_get_new_service_id (priv->common);
 
-		if (tracker_db_create_service (priv->metadata, id, service, info->path, metadata)) {
+		/* Begin of transaction point X */
+
+		/* If you ever need to remove this transaction, because it gets
+		 * wrapped into a larger one, that's fine IF you indeed have a
+		 * larger one in place that spans cache,common and the selected
+		 * metadata database file */
+
+		tracker_db_interface_start_transaction (priv->metadata);
+
+		if (tracker_db_create_service (priv->metadata, id, service, info->file->path, metadata)) {
 			gchar *text;
 			guint32 eid;
 
-			eid = tracker_db_get_new_event_id (priv->common);
+			eid = tracker_db_get_new_event_id (priv->metadata);
 
-			tracker_db_create_event (priv->common, eid, id, "Create");
+			tracker_db_create_event (priv->metadata, eid, id, "Create");
 
-			tracker_db_increment_stats (priv->common, service);
+			tracker_db_increment_stats (priv->metadata, service);
 
 			index_metadata (indexer, id, service, metadata);
 
-			text = tracker_indexer_module_get_text (info->module, info->path);
+			text = tracker_indexer_module_file_get_text (info->module, info->file);
 
 			if (text) {
 				tracker_db_set_text (priv->contents, id, text);
 				g_free (text);
 			}
 		}
+		
+		tracker_db_interface_end_transaction (priv->metadata); 
+		
+		/* End of transaction point X */
 
 		g_hash_table_destroy (metadata);
 	}
+
+	return !tracker_indexer_module_file_iter_contents (info->module, info->file);
 }
 
 static void
@@ -461,9 +535,9 @@
 	const gchar *name;
 	GDir *dir;
 
-	g_message ("Processing directory:'%s'", info->path);
+	g_message ("Processing directory:'%s'", info->file->path);
 
-	dir = g_dir_open (info->path, 0, NULL);
+	dir = g_dir_open (info->file->path, 0, NULL);
 
 	if (!dir) {
 		return;
@@ -473,7 +547,7 @@
 		PathInfo *new_info;
 		gchar *path;
 
-		path = g_build_filename (info->path, name, NULL);
+		path = g_build_filename (info->file->path, name, NULL);
 
 		new_info = path_info_new (info->module, path);
 		tracker_indexer_add_file (indexer, new_info);
@@ -533,10 +607,12 @@
 	indexer = (TrackerIndexer *) data;
 	priv = TRACKER_INDEXER_GET_PRIVATE (indexer);
 
-	if ((path = g_queue_pop_head (priv->file_process_queue)) != NULL) {
+	if ((path = g_queue_peek_head (priv->file_process_queue)) != NULL) {
 		/* Process file */
-		process_file (indexer, path);
-		path_info_free (path);
+		if (process_file (indexer, path)) {
+			path = g_queue_pop_head (priv->file_process_queue);
+			path_info_free (path);
+		}
 	} else if ((path = g_queue_pop_head (priv->dir_queue)) != NULL) {
 		/* Process directory contents */
 		process_directory (indexer, path, TRUE);
@@ -550,7 +626,16 @@
 		}
 
 		if (!priv->current_module) {
+			/* Flush remaining items */
+			schedule_flush (indexer, TRUE);
+
 			/* No more modules to query, we're done */
+			g_timer_stop (priv->timer);
+
+			g_message ("Indexer finished in %4.4f seconds, %d items indexed in total",
+				   g_timer_elapsed (priv->timer, NULL),
+				   priv->items_indexed);
+
 			g_signal_emit (indexer, signals[FINISHED], 0);
 			return FALSE;
 		}

Modified: branches/xesam-support/src/tracker-indexer/tracker-main.c
==============================================================================
--- branches/xesam-support/src/tracker-indexer/tracker-main.c	(original)
+++ branches/xesam-support/src/tracker-indexer/tracker-main.c	Wed Jun 25 09:38:42 2008
@@ -148,7 +148,7 @@
 	sys_tmp_dir = g_build_filename (g_get_tmp_dir (), filename, NULL);
 	g_free (filename);
 
-	tracker_db_manager_init (FALSE, FALSE, NULL);
+	tracker_db_manager_init (0, NULL);
 
 	g_free (data_dir);
 	g_free (user_data_dir);
@@ -160,7 +160,7 @@
 {
 	g_message ("Shutting down...\n");
 
-	tracker_db_manager_shutdown ();
+	tracker_db_manager_shutdown (FALSE);
 }
 
 gint

Modified: branches/xesam-support/src/trackerd/tracker-crawler.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-crawler.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-crawler.c	Wed Jun 25 09:38:42 2008
@@ -673,12 +673,14 @@
 	if (priv->enumerations == 0) {
 		g_timer_stop (priv->timer);
 
-		g_message ("%s crawling files in %4.4f seconds, %d found, %d ignored, %d monitors", 
+		g_message ("%s crawling files in %4.4f seconds, %d found, %d ignored, "
+			   "%d monitors, %d monitors ignored", 
 			   priv->running ? "Finished" : "Stopped",
 			   g_timer_elapsed (priv->timer, NULL),
 			   priv->files_found,
 			   priv->files_ignored,
-			   tracker_monitor_get_count ());
+			   tracker_monitor_get_count (),
+			   tracker_monitor_get_ignored ());
 
 		priv->running = FALSE;
 	}

Modified: branches/xesam-support/src/trackerd/tracker-db.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-db.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-db.c	Wed Jun 25 09:38:42 2008
@@ -2694,9 +2694,7 @@
 {
 	g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
 
-	db_exec_proc_no_reply (iface, 
-			       "DeleteHandledEvents", 
-			       NULL);
+	tracker_db_exec (iface, "DELETE FROM Events WHERE BeingHandled = 1");
 }
 
 /* Deprecated */

Modified: branches/xesam-support/src/trackerd/tracker-main.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-main.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-main.c	Wed Jun 25 09:38:42 2008
@@ -666,10 +666,11 @@
 gint
 main (gint argc, gchar *argv[])
 {
-	GOptionContext *context = NULL;
-	GOptionGroup   *group;
-	GError         *error = NULL;
-	GSList         *l;
+	GOptionContext        *context = NULL;
+	GOptionGroup          *group;
+	GError                *error = NULL;
+	GSList                *l;
+	TrackerDBManagerFlags  flags;
 
         g_type_init ();
         
@@ -800,7 +801,15 @@
 	sanity_check_option_values ();
 
 	tracker_nfs_lock_init (tracker_config_get_nfs_locking (tracker->config));
-	tracker_db_manager_init (TRUE, reindex, &tracker->first_time_index); 
+
+	flags = TRACKER_DB_MANAGER_ATTACH_ALL |
+		TRACKER_DB_MANAGER_REMOVE_CACHE;
+
+	if (reindex) {
+		flags |= TRACKER_DB_MANAGER_FORCE_REINDEX;
+	}
+
+	tracker_db_manager_init (flags, &tracker->first_time_index);
 	tracker_db_init ();
 	tracker_xesam_manager_init ();
 	tracker_email_start_email_watching (tracker_config_get_email_client (tracker->config));
@@ -881,7 +890,7 @@
 	tracker_email_end_email_watching ();
 	tracker_dbus_shutdown ();
 	tracker_xesam_manager_shutdown ();
-	tracker_db_manager_shutdown ();
+	tracker_db_manager_shutdown (TRUE);
 	tracker_db_shutdown ();
 	tracker_monitor_shutdown ();
 	tracker_nfs_lock_shutdown ();

Modified: branches/xesam-support/src/trackerd/tracker-monitor.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-monitor.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-monitor.c	Wed Jun 25 09:38:42 2008
@@ -29,15 +29,6 @@
 
 /* #define TESTING  */
 
-/* This is the default inotify limit - 500 to allow some monitors for
- * other applications. 
- *
- * FIXME: Should we try reading
- * /proc/sys/fs/inotify/max_user_watches when there is a possiblity
- * that we don't even use inotify?
- */
-#define MAX_MONITORS                 (guint) ((2 ^ 13) - 500)   
-
 #define FILES_QUEUE_PROCESS_INTERVAL 2000
 #define FILES_QUEUE_PROCESS_MAX      5000
 
@@ -47,6 +38,39 @@
 static GAsyncQueue   *files_updated;
 static GAsyncQueue   *files_deleted;
 static guint          files_queue_handlers_id;
+static GType          monitor_backend; 
+static guint          monitor_limit;
+static gboolean       monitor_limit_warned;
+static guint          monitors_ignored;
+
+static guint
+monitor_get_inotify_limit (void)
+{
+	GError      *error = NULL;
+	const gchar *filename;
+	gchar       *contents = NULL;
+	guint        limit;
+	
+	filename = "/proc/sys/fs/inotify/max_user_watches";
+	
+	if (!g_file_get_contents (filename,
+				  &contents, 
+				  NULL, 
+				  &error)) {
+		g_warning ("Couldn't get INotify monitor limit from:'%s', %s", 
+			   filename,
+			   error ? error->message : "no error given");
+		g_clear_error (&error);
+		
+		/* Setting limit to an arbitary limit */
+		limit = 8192;
+	} else {
+		limit = atoi (contents);
+		g_free (contents);
+	}
+
+	return limit;
+}
 
 gboolean 
 tracker_monitor_init (TrackerConfig *_config) 
@@ -76,6 +100,91 @@
 		files_deleted = g_async_queue_new ();
 	}
 
+	/* For the first monitor we get the type and find out if we
+	 * are using inotify, FAM, polling, etc.
+	 */
+	if (monitor_backend == 0) {
+		GFile        *file;
+		GFileMonitor *monitor;
+		const gchar  *name;
+
+		file = g_file_new_for_path (g_get_home_dir ());
+		monitor = g_file_monitor_directory (file,
+						    G_FILE_MONITOR_WATCH_MOUNTS,
+						    NULL,
+						    NULL);
+
+		monitor_backend = G_OBJECT_TYPE (monitor);
+
+		/* We use the name because the type itself is actually
+		 * private and not available publically. Note this is
+		 * subject to change, but unlikely of course.
+		 */
+		name = g_type_name (monitor_backend);
+		if (name) {
+			/* Set limits based on backend... */
+			if (strcmp (name, "GInotifyDirectoryMonitor") == 0) {
+				/* Using inotify */
+				g_message ("Monitor backend is INotify");
+
+				/* Setting limit based on kernel
+				 * settings in /proc...
+				 */
+				monitor_limit = monitor_get_inotify_limit ();
+
+				/* We don't use 100% of the monitors, we allow other
+				 * applications to have at least 500 or so to use
+				 * between them selves. This only
+				 * applies to inotify because it is a
+				 * user shared resource.
+				 */
+				monitor_limit -= 500;
+
+				/* Make sure we don't end up with a
+				 * negative maximum.
+				 */
+				monitor_limit = MAX (monitor_limit, 0);
+			}
+			else if (strcmp (name, "GFamDirectoryMonitor") == 0) {
+				/* Using Fam */
+				g_message ("Monitor backend is Fam");
+
+				/* Setting limit to an arbitary limit
+				 * based on testing 
+				 */
+				monitor_limit = 400;
+			}
+			else if (strcmp (name, "GFenDirectoryMonitor") == 0) {
+				/* Using Fen, what is this? */
+				g_message ("Monitor backend is Fen");
+
+				/* Guessing limit... */
+				monitor_limit = 8192;
+			}
+			else if (strcmp (name, "GWin32DirectoryMonitor") == 0) {
+				/* Using Windows */
+				g_message ("Monitor backend is Windows");
+
+				/* Guessing limit... */
+				monitor_limit = 8192;
+			}
+			else {
+				/* Unknown */
+				g_warning ("Monitor backend:'%s' is unknown, we have no limits "
+					   "in place because we don't know what we are dealing with!", 
+					   name);
+
+				/* Guessing limit... */
+				monitor_limit = 100;
+			}
+		}
+
+		g_message ("Monitor limit is %d", monitor_limit);
+
+		g_file_monitor_cancel (monitor);
+		g_object_unref (file);
+	}
+
 	return TRUE;
 }
 
@@ -84,6 +193,11 @@
 {
 	gchar *str;
 
+	monitors_ignored = 0;
+	monitor_limit_warned = FALSE;
+	monitor_limit = 0;
+	monitor_backend = 0;
+
 	if (files_queue_handlers_id) {
 		g_source_remove (files_queue_handlers_id);
 		files_queue_handlers_id = 0;
@@ -331,10 +445,16 @@
 	}
 
 	/* Cap the number of monitors */
-	if (g_hash_table_size (monitors) >= MAX_MONITORS) {
-		g_warning ("The maximum number of monitors to set (%d) "
-			   "has been reached, not adding any new ones",
-			   MAX_MONITORS);
+	if (g_hash_table_size (monitors) >= monitor_limit) {
+		monitors_ignored++;
+
+		if (!monitor_limit_warned) {
+			g_warning ("The maximum number of monitors to set (%d) "
+				   "has been reached, not adding any new ones",
+				   monitor_limit);
+			monitor_limit_warned = TRUE;
+		}
+
 		return FALSE;
 	}
 
@@ -361,6 +481,7 @@
 					    NULL,
 					    &error);
 
+	
 	if (error) {
 		g_warning ("Could not add monitor for path:'%s', %s", 
 			   path, 
@@ -403,6 +524,9 @@
 		return TRUE;
 	}
 
+	/* We reset this because now it is possible we have limit - 1 */
+	monitor_limit_warned = FALSE;
+
 	g_hash_table_remove (monitors, file);
 
 	path = g_file_get_path (file);
@@ -441,9 +565,14 @@
 	return watched;
 }
 
-gint
+guint
 tracker_monitor_get_count (void)
 {
 	return g_hash_table_size (monitors);
 }
 
+guint
+tracker_monitor_get_ignored (void)
+{
+	return monitors_ignored;
+}

Modified: branches/xesam-support/src/trackerd/tracker-monitor.h
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-monitor.h	(original)
+++ branches/xesam-support/src/trackerd/tracker-monitor.h	Wed Jun 25 09:38:42 2008
@@ -35,7 +35,8 @@
 					       gboolean       delete_subdirs);
 gboolean tracker_monitor_is_watched           (GFile         *file);
 gboolean tracker_monitor_is_watched_by_string (const gchar   *path);
-gint     tracker_monitor_get_count            (void);
+guint    tracker_monitor_get_count            (void);
+guint    tracker_monitor_get_ignored          (void);
 
 G_END_DECLS
 

Modified: branches/xesam-support/src/trackerd/tracker-xesam-manager.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-manager.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-manager.c	Wed Jun 25 09:38:42 2008
@@ -264,6 +264,7 @@
 	gboolean            reason_to_live = FALSE;
 
 	iface = tracker_db_manager_get_db_interface (TRACKER_DB_XESAM);
+
 	g_return_val_if_fail (iface != NULL, FALSE);
 
 	sessions = g_hash_table_get_values (xesam_sessions);

Modified: branches/xesam-support/tests/Makefile.am
==============================================================================
--- branches/xesam-support/tests/Makefile.am	(original)
+++ branches/xesam-support/tests/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,3 @@
 include $(top_srcdir)/Makefile.decl
 
-SUBDIRS = common libtracker-common trackerd scripts
+SUBDIRS = common libtracker-common trackerd scripts libtracker-db

Modified: branches/xesam-support/tests/common/Makefile.am
==============================================================================
--- branches/xesam-support/tests/common/Makefile.am	(original)
+++ branches/xesam-support/tests/common/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 noinst_LTLIBRARIES = libtracker-testcommon.la
 
 INCLUDES = $(GLIB2_CFLAGS)

Modified: branches/xesam-support/tests/scripts/Makefile.am
==============================================================================
--- branches/xesam-support/tests/scripts/Makefile.am	(original)
+++ branches/xesam-support/tests/scripts/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -1 +1,3 @@
+include $(top_srcdir)/Makefile.decl
+
 noinst_SCRIPTS = dummy_data_start.sh dummy_data_stop.sh

Modified: branches/xesam-support/tests/trackerd/Makefile.am
==============================================================================
--- branches/xesam-support/tests/trackerd/Makefile.am	(original)
+++ branches/xesam-support/tests/trackerd/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -21,6 +21,7 @@
 
 tracker_xesam_SOURCES = \
 	tracker-xesam-test.c \
+	tracker-xesam-test.h \
 	tracker-xesam-session-test.c \
 	tracker-xesam-session-test.h \
 	tracker-xesam-hit-test.c \

Modified: branches/xesam-support/tests/trackerd/xesam/Makefile.am
==============================================================================
--- branches/xesam-support/tests/trackerd/xesam/Makefile.am	(original)
+++ branches/xesam-support/tests/trackerd/xesam/Makefile.am	Wed Jun 25 09:38:42 2008
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 if HAVE_XESAM_GLIB
 
 noinst_LTLIBRARIES = libxesamhelper.la



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