tracker r2709 - branches/turtle/src/trackerd



Author: ifrade
Date: Tue Dec 16 14:21:37 2008
New Revision: 2709
URL: http://svn.gnome.org/viewvc/tracker?rev=2709&view=rev

Log:
Moved backup code to functions. Reordered those functions to group the backup related stuff

Modified:
   branches/turtle/src/trackerd/tracker-main.c

Modified: branches/turtle/src/trackerd/tracker-main.c
==============================================================================
--- branches/turtle/src/trackerd/tracker-main.c	(original)
+++ branches/turtle/src/trackerd/tracker-main.c	Tue Dec 16 14:21:37 2008
@@ -640,6 +640,102 @@
 	}
 }
 
+static const gchar *
+get_ttl_backup_filename (void) 
+{
+
+	TrackerMainPrivate *private;
+
+	private = g_static_private_get (&private_key);
+
+	return private->ttl_backup_file;
+}
+
+static void
+backup_user_metadata (TrackerConfig *config, TrackerLanguage *language)
+{
+	TrackerDBIndex		   *file_index;
+	TrackerDBIndex		   *email_index;
+	gboolean                    is_first_time_index;
+
+	g_message ("Saving metadata in %s", get_ttl_backup_filename ());
+	
+	/*
+	 *  Init the DB stack to get the user metadata
+	 */
+	tracker_db_manager_init (0, &is_first_time_index, TRUE);
+
+	/*
+	 * If some database is missing or the dbs dont exists, we dont need
+	 * to backup anything.
+	 */
+	if (is_first_time_index) {
+		tracker_db_manager_shutdown ();
+		return;
+	}
+	
+	tracker_db_index_manager_init (0,
+				       tracker_config_get_min_bucket_count (config),
+				       tracker_config_get_max_bucket_count (config));
+	
+	file_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+	email_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
+	
+	tracker_data_manager_init (config, language, file_index, email_index);
+	
+	/* Actual save of the metadata */
+	tracker_backup_save (get_ttl_backup_filename ());
+	
+	/* Shutdown the DB stack */
+	tracker_data_manager_shutdown ();
+	tracker_db_index_manager_shutdown ();
+	tracker_db_manager_shutdown ();
+}
+
+/*
+ * TODO: Ugly hack counting signals because the indexer is sending two "Finished" signals
+ *  and only the second really mean "finished processing modules".
+ *
+ * Saving the last backup file to help with debugging.
+ */
+static void
+crawling_finished_cb (TrackerProcessor *processor, gpointer user_data)
+{
+	gulong *callback_id = user_data;
+	GError *error;
+	static gint counter = 0;
+	
+	counter += 1;
+
+	if (counter >= 2) {
+		gchar *rebackup;
+
+		g_debug ("Uninstalling initial crawling callback");
+		g_signal_handler_disconnect (processor, *callback_id);
+
+		org_freedesktop_Tracker_Indexer_restore_backup (tracker_dbus_indexer_get_proxy (), 
+								get_ttl_backup_filename (),
+								&error);
+		rebackup = g_strdup_printf ("%s.old",
+					    get_ttl_backup_filename ());
+		g_rename (get_ttl_backup_filename (), rebackup);
+		g_free (rebackup);
+	} else {
+		g_debug ("%d finished signal", counter);
+	}
+}
+
+static void
+backup_restore_on_crawling_finished (TrackerProcessor *processor)
+{
+	gulong                      restore_cb_id;
+
+	g_debug ("Setting callback for crawling finish detection");
+	restore_cb_id = g_signal_connect (processor, "finished", 
+					  G_CALLBACK (crawling_finished_cb), 
+					  &restore_cb_id);
+}
+
 #ifdef HAVE_HAL
 
 static void
@@ -763,51 +859,6 @@
 	return FALSE;
 }
 
-static const gchar *
-get_ttl_backup_filename (void) 
-{
-
-	TrackerMainPrivate *private;
-
-	private = g_static_private_get (&private_key);
-
-	return private->ttl_backup_file;
-}
-
-
-/*
- * TODO: Ugly hack counting signals because the indexer is sending two "Finished" signals
- *  and only the second really mean "finished processing modules".
- *
- * Saving the last backup file to help with debugging.
- */
-static void
-crawling_finished_cb (TrackerProcessor *processor, gpointer user_data)
-{
-	gulong *callback_id = user_data;
-	GError *error;
-	static gint counter = 0;
-	
-	counter += 1;
-
-	if (counter >= 2) {
-		gchar *rebackup;
-
-		g_debug ("Uninstalling initial crawling callback");
-		g_signal_handler_disconnect (processor, *callback_id);
-
-		org_freedesktop_Tracker_Indexer_restore_backup (tracker_dbus_indexer_get_proxy (), 
-								get_ttl_backup_filename (),
-								&error);
-		rebackup = g_strdup_printf ("%s.old",
-					    get_ttl_backup_filename ());
-		g_rename (get_ttl_backup_filename (), rebackup);
-		g_free (rebackup);
-	} else {
-		g_debug ("%d finished signal", counter);
-	}
-}
-
 gint
 main (gint argc, gchar *argv[])
 {
@@ -825,7 +876,6 @@
 	TrackerDBManagerFlags	    flags = 0;
 	TrackerDBIndexManagerFlags  index_flags = 0;
 	gboolean		    is_first_time_index;
-	gulong                      restore_cb_id;
 
 	g_type_init ();
 
@@ -983,28 +1033,7 @@
 	index_flags |= TRACKER_DB_INDEX_MANAGER_READONLY;
 
 	if (force_reindex) {
-
-		g_message ("Saving metadata in %s", get_ttl_backup_filename ());
-
-		/* Init the DB stack */
-		tracker_db_manager_init (0, &is_first_time_index, TRUE);
-
-		tracker_db_index_manager_init (0,
-					       tracker_config_get_min_bucket_count (config),
-					       tracker_config_get_max_bucket_count (config));
-		
-		file_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
-		email_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
-		
-		tracker_data_manager_init (config, language, file_index, email_index);
-		
-		tracker_backup_save (get_ttl_backup_filename ());
-
-		/* Shutdown the DB stack */
-		tracker_data_manager_shutdown ();
-		
-		tracker_db_index_manager_shutdown ();
-		tracker_db_manager_shutdown ();
+		backup_user_metadata (config, language);
 
 		flags |= TRACKER_DB_MANAGER_FORCE_REINDEX;
 		index_flags |= TRACKER_DB_INDEX_MANAGER_FORCE_REINDEX;
@@ -1122,12 +1151,9 @@
 		tracker_status_set_and_signal (TRACKER_STATUS_IDLE);
 	}
 
-	if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX
-	    || g_file_test (get_ttl_backup_filename, G_FILE_TEST_EXISTS)) {
-		g_debug ("Setting callback for crawling finish detection");
-		restore_cb_id = g_signal_connect (private->processor, "finished", 
-						  G_CALLBACK (crawling_finished_cb), 
-						  &restore_cb_id);
+	if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX ||
+	    g_file_test (get_ttl_backup_filename (), G_FILE_TEST_EXISTS)) {
+		backup_restore_on_crawling_finished (private->processor);
 	}
 
 	if (tracker_status_get_is_running ()) {



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