[tracker/initable-db-iface-rebased: 3/3] libtracker-bus, -direct, -sparql: Error handling, get_direct



commit 8147b2936364195795ed2bccb1c5514e99985e31
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Feb 3 11:13:11 2011 +0100

    libtracker-bus, -direct, -sparql: Error handling, get_direct
    
    This makes the connection.get_direct and connection.get APIs work
    right.
    
    Fixes NB#222182.

 src/libtracker-bus/tracker-bus.vala        |   10 +--
 src/libtracker-data/tracker-db-manager.c   |   90 ++++++++++++++++++----------
 src/libtracker-direct/tracker-direct.vala  |   16 ++----
 src/libtracker-sparql/tracker-backend.vala |    3 +-
 4 files changed, 69 insertions(+), 50 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index e17c9fc..b0b3137 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -347,11 +347,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 	}
 }
 
-public Tracker.Sparql.Connection? module_init () {
-	try {
-		Tracker.Sparql.Connection plugin = new Tracker.Bus.Connection ();
-		return plugin;
-	} catch {
-		return null;
-	}
+public Tracker.Sparql.Connection? module_init () throws GLib.Error {
+	Tracker.Sparql.Connection plugin = new Tracker.Bus.Connection ();
+	return plugin;
 }
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index bdeee4c..0c80583 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -702,7 +702,7 @@ db_recreate_all (GError **error)
 		if (internal_error) {
 			guint y;
 
-			for (y = 0; y < i - 1; y++) {
+			for (y = 1; y < i; y++) {
 				g_object_unref (dbs[y].iface);
 				dbs[y].iface = NULL;
 			}
@@ -833,38 +833,44 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 	                             "tracker",
 	                             NULL);
 
+	g_free (in_use_filename);
 	in_use_filename = g_build_filename (g_get_user_data_dir (),
 	                                    "tracker",
 	                                    "data",
 	                                    IN_USE_FILENAME,
 	                                    NULL);
 
-	/* Make sure the directories exist */
-	g_message ("Checking database directories exist");
+	/* Don't do need_reindex checks for readonly (direct-access) */
+	if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
 
-	g_mkdir_with_parents (data_dir, 00755);
-	g_mkdir_with_parents (user_data_dir, 00755);
-	g_mkdir_with_parents (sys_tmp_dir, 00755);
+		/* Make sure the directories exist */
+		g_message ("Checking database directories exist");
 
-	g_message ("Checking database version");
+		g_mkdir_with_parents (data_dir, 00755);
+		g_mkdir_with_parents (user_data_dir, 00755);
+		g_mkdir_with_parents (sys_tmp_dir, 00755);
 
-	version = db_get_version ();
+		g_message ("Checking database version");
 
-	if (version < TRACKER_DB_VERSION_NOW) {
-		g_message ("  A reindex will be forced");
-		need_reindex = TRUE;
-	}
+		version = db_get_version ();
+
+		if (version < TRACKER_DB_VERSION_NOW) {
+			g_message ("  A reindex will be forced");
+			need_reindex = TRUE;
+		}
+
+		if (need_reindex) {
+			tracker_db_manager_create_version_file ();
+		}
 
-	if (need_reindex) {
-		tracker_db_manager_create_version_file ();
 	}
 
 	g_message ("Checking database files exist");
 
 	for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
 		/* Fill absolute path for the database */
-		dir = location_to_directory (dbs[i].location);
 
+		dir = location_to_directory (dbs[i].location);
 		g_free (dbs[i].abs_filename);
 		dbs[i].abs_filename = g_build_filename (dir, dbs[i].file, NULL);
 
@@ -872,28 +878,50 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 		 * missing, we reindex.
 		 */
 
-		/* No need to check for other files not existing (for
-		 * reindex) if one is already missing.
-		 */
-		if (need_reindex) {
-			continue;
+		if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
+			/* No need to check for other files not existing (for
+			 * reindex) if one is already missing.
+			 */
+			if (need_reindex) {
+				continue;
+			}
 		}
 
 		if (!g_file_test (dbs[i].abs_filename, G_FILE_TEST_EXISTS)) {
-			g_message ("Could not find database file:'%s'", dbs[i].abs_filename);
-			g_message ("One or more database files are missing, a reindex will be forced");
-			need_reindex = TRUE;
+			if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
+				g_message ("Could not find database file:'%s'", dbs[i].abs_filename);
+				g_message ("One or more database files are missing, a reindex will be forced");
+				need_reindex = TRUE;
+			} else {
+				guint y;
+
+				g_set_error (error,
+				             TRACKER_DB_INTERFACE_ERROR,
+				             TRACKER_DB_OPEN_ERROR,
+				             "Could not find database file:'%s'. One or more database files are missing", dbs[i].abs_filename);
+
+				for (y = 1; y <= i; y++) {
+					g_free (dbs[y].abs_filename);
+					dbs[y].abs_filename = NULL;
+				}
+
+				return FALSE;
+			}
 		}
 	}
 
 	locations_initialized = TRUE;
 
-	/* If we are just initializing to remove the databases,
-	 * return here.
-	 */
-	if ((flags & TRACKER_DB_MANAGER_REMOVE_ALL) != 0) {
-		initialized = TRUE;
-		return TRUE;
+	/* Don't do remove-dbs for readonly (direct-access) */
+	if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
+
+		/* If we are just initializing to remove the databases,
+		 * return here.
+		 */
+		if ((flags & TRACKER_DB_MANAGER_REMOVE_ALL) != 0) {
+			initialized = TRUE;
+			return TRUE;
+		}
 	}
 
 	/* Set general database options */
@@ -907,6 +935,7 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 	 * other things like the nfs lock file.
 	 */
 	if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX || need_reindex) {
+
 		if (flags & TRACKER_DB_MANAGER_READONLY) {
 			/* no reindexing supported in read-only mode (direct access) */
 
@@ -991,13 +1020,12 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 				if (internal_error) {
 					guint y;
 
-					for (y = 0; y < i - 1; y++) {
+					for (y = 1; y < i; y++) {
 						g_object_unref (dbs[y].iface);
 						dbs[y].iface = NULL;
 					}
 
 					g_propagate_error (error, internal_error);
-
 					return FALSE;
 				}
 
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index 4551e45..d6493e8 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -21,7 +21,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 	// only single connection is currently supported per process
 	static bool initialized;
 
-	public Connection () throws Sparql.Error
+	public Connection () throws GLib.Error
 	requires (!initialized) {
 		uint select_cache_size = 100;
 		string env_cache_size = Environment.get_variable ("TRACKER_SPARQL_CACHE_SIZE");
@@ -30,9 +30,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 			select_cache_size = env_cache_size.to_int();
 		}
 
-		if (!Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null)) {
-			throw new Sparql.Error.INTERNAL ("Unable to initialize database");
-		}
+		Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null);
 
 		initialized = true;
 	}
@@ -108,11 +106,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 	}
 }
 
-public Tracker.Sparql.Connection? module_init () {
-	try {
-		Tracker.Sparql.Connection plugin = new Tracker.Direct.Connection ();
-		return plugin;
-	} catch (Tracker.Sparql.Error e) {
-		return null;
-	}
+public Tracker.Sparql.Connection? module_init () throws GLib.Error {
+	Tracker.Sparql.Connection plugin = new Tracker.Direct.Connection ();
+	return plugin;
 }
diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala
index 6ecbb5f..8eb832c 100644
--- a/src/libtracker-sparql/tracker-backend.vala
+++ b/src/libtracker-sparql/tracker-backend.vala
@@ -35,7 +35,8 @@ class Tracker.Sparql.Backend : Connection {
 		BUS
 	}
 
-	private delegate Tracker.Sparql.Connection? ModuleInitFunc ();
+	[CCode (has_target = false)]
+	private delegate Tracker.Sparql.Connection? ModuleInitFunc () throws GLib.Error;
 
 	public Backend (bool direct_only = false) throws Sparql.Error
 	requires (Module.supported ()) {



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