[tracker/initable-db-iface] Squash with previous, error handling



commit 13ef28d352d9a44864c03e41183836b7d795a747
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Feb 3 13:58:55 2011 +0100

    Squash with previous, error handling

 src/libtracker-data/tracker-db-manager.c   |   76 +++++++++++++++++----------
 src/libtracker-direct/tracker-direct.vala  |   12 +----
 src/libtracker-sparql/tracker-backend.vala |    1 +
 3 files changed, 51 insertions(+), 38 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index bdeee4c..1a73266 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -839,32 +839,37 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 	                                    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 +877,42 @@ 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 {
+				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);
+				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 +926,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) */
 
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index cc3e51f..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,15 +30,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 			select_cache_size = env_cache_size.to_int();
 		}
 
-		try {
-			// I don't really know why we are hiding the real error by wrapping
-			// it in a Sparql.Error.INTERNAL here ...
-			if (!Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null)) {
-				throw new Sparql.Error.INTERNAL ("Unable to initialize database");
-			}
-		} catch (Tracker.DBInterfaceError e) {
-			throw new Sparql.Error.INTERNAL ("Unable to initialize database: %s", e.message);
-		}
+		Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null);
 
 		initialized = true;
 	}
diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala
index 94edf0b..1e9587e 100644
--- a/src/libtracker-sparql/tracker-backend.vala
+++ b/src/libtracker-sparql/tracker-backend.vala
@@ -35,6 +35,7 @@ class Tracker.Sparql.Backend : Connection {
 		BUS
 	}
 
+	[CCode (has_target = false)]
 	private delegate Tracker.Sparql.Connection? ModuleInitFunc () throws GLib.Error;
 
 	public Backend (bool direct_only = false) throws Sparql.Error



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