[tracker/tracker-0.10] libtracker-data, tests, tracker-control: Handle journal errors



commit a549c1586a91017f2d50ae0beb35941f078ce94e
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Apr 21 13:40:31 2011 +0200

    libtracker-data, tests, tracker-control: Handle journal errors

 src/libtracker-data/tracker-data-backup.c     |   22 +++-
 src/libtracker-data/tracker-data-manager.c    |   50 +++++-
 src/libtracker-data/tracker-data-update.c     |   70 +++++++--
 src/libtracker-data/tracker-db-journal.c      |  215 ++++++++++++++++++-------
 src/libtracker-data/tracker-db-journal.h      |   20 ++-
 src/libtracker-data/tracker-db-manager.c      |    8 +-
 src/tracker-control/tracker-control-general.c |    4 +-
 tests/libtracker-data/tracker-db-journal.c    |   35 +++--
 8 files changed, 323 insertions(+), 101 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index c46c350..8bf0844 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -337,6 +337,7 @@ tracker_data_backup_restore (GFile                *journal,
 		gchar **argv;
 		gint exit_status;
 		guint select_cache_size, update_cache_size;
+		GError *n_error = NULL;
 
 		flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
 
@@ -378,7 +379,18 @@ tracker_data_backup_restore (GFile                *journal,
 		g_strfreev (argv);
 
 		tracker_db_manager_init_locations ();
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &n_error);
+
+		if (n_error) {
+			if (!info->error) {
+				g_propagate_error (&info->error, n_error);
+			} else {
+				g_warning ("Ignored error while initializing journal during backup (another higher priority error already took place): %s",
+				           n_error->message ? n_error->message : "No error given");
+				g_error_free (n_error);
+			}
+			n_error = NULL;
+		}
 
 		if (info->error) {
 			tracker_db_manager_restore_from_temp ();
@@ -386,7 +398,13 @@ tracker_data_backup_restore (GFile                *journal,
 			tracker_db_manager_remove_temp ();
 		}
 
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (&n_error);
+
+		if (n_error) {
+			g_warning ("Ignored error while shuting down journal during backup: %s",
+			           n_error->message ? n_error->message : "No error given");
+			g_error_free (n_error);
+		}
 
 		tracker_data_manager_init (flags, test_schemas, &is_first, TRUE,
 		                           select_cache_size, update_cache_size,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 108d841..2f83173 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3556,7 +3556,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 	iface = tracker_db_manager_get_db_interface ();
 
 	if (journal_check && is_first_time_index) {
-		if (tracker_db_journal_reader_init (NULL)) {
+		/* Call may fail without notice */
+		if (tracker_db_journal_reader_init (NULL, NULL)) {
 			if (tracker_db_journal_reader_next (NULL)) {
 				/* journal with at least one valid transaction
 				   is required to trigger journal replay */
@@ -3580,7 +3581,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 	if (read_journal) {
 		in_journal_replay = TRUE;
 
-		tracker_db_journal_reader_ontology_init (NULL);
+		tracker_db_journal_reader_ontology_init (NULL, &internal_error);
+
+		if (internal_error) {
+			g_propagate_error (error, internal_error);
+
+			return FALSE;
+		}
 
 		/* Load ontology IDs from journal into memory */
 		load_ontology_ids_from_journal (&uri_id_map, &max_id);
@@ -3594,7 +3601,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		if (!read_journal) {
 			/* Truncate journal as it does not even contain a single valid transaction
 			 * or is explicitly ignored (journal_check == FALSE, only for test cases) */
-			tracker_db_journal_init (NULL, TRUE);
+			tracker_db_journal_init (NULL, TRUE, &internal_error);
+
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+
+				return FALSE;
+			}
 		}
 
 		/* load ontology from files into memory (max_id starts at zero: first-time) */
@@ -3710,7 +3723,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		check_ontology = FALSE;
 	} else {
 		if (!read_only) {
-			tracker_db_journal_init (NULL, FALSE);
+			tracker_db_journal_init (NULL, FALSE, &internal_error);
+
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+
+				return FALSE;
+			}
 
 			/* Load ontology from database into memory */
 			db_get_static_data (iface);
@@ -4112,7 +4131,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 			if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR, TRACKER_DB_NO_SPACE)) {
 				tracker_db_manager_remove_all (FALSE);
 				tracker_db_manager_shutdown ();
-				tracker_db_journal_shutdown ();
+				/* Call may fail without notice, we're in error handling already */
+				tracker_db_journal_shutdown (NULL);
 			}
 
 			g_hash_table_unref (uri_id_map);
@@ -4123,7 +4143,14 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		in_journal_replay = FALSE;
 
 		/* open journal for writing */
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &internal_error);
+
+		if (internal_error) {
+			g_hash_table_unref (uri_id_map);
+			g_propagate_error (error, internal_error);
+
+			return FALSE;
+		}
 
 		g_hash_table_unref (uri_id_map);
 	}
@@ -4170,10 +4197,19 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 void
 tracker_data_manager_shutdown (void)
 {
+	GError *error = NULL;
+
 	g_return_if_fail (initialized == TRUE);
 
 	/* Make sure we shutdown all other modules we depend on */
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+
+	if (error) {
+		/* TODO: propagate error */
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+
 	tracker_db_manager_shutdown ();
 	tracker_ontologies_shutdown ();
 	if (!reloading) {
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index dfbec66..7560e06 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2960,7 +2960,15 @@ tracker_data_begin_transaction (GError **error)
 
 	if (!in_journal_replay) {
 		if (in_ontology_transaction) {
-			tracker_db_journal_start_ontology_transaction (resource_time);
+			GError *n_error = NULL;
+			tracker_db_journal_start_ontology_transaction (resource_time, &n_error);
+
+			if (n_error) {
+				tracker_db_interface_end_db_transaction (iface, NULL);
+				g_propagate_error (error, n_error);
+				return;
+			}
+
 		} else {
 			tracker_db_journal_start_transaction (resource_time);
 		}
@@ -3012,22 +3020,34 @@ tracker_data_commit_transaction (GError **error)
 		return;
 	}
 
-	get_transaction_modseq ();
-	if (has_persistent && !in_ontology_transaction) {
-		transaction_modseq++;
-	}
-
 	if (!in_journal_replay) {
 		if (has_persistent || in_ontology_transaction) {
-			tracker_db_journal_commit_db_transaction ();
+			tracker_db_journal_commit_db_transaction (&actual_error);
 		} else {
 			/* If we only had transient properties, then we must not write
 			 * anything to the journal. So we roll it back, but only the
 			 * journal's part. */
-			tracker_db_journal_rollback_transaction ();
+			tracker_db_journal_rollback_transaction (&actual_error);
+		}
+
+		if (actual_error) {
+
+			/* Can't write in journal anymore; quite a serious problem, not sure
+			 * if rollback of transaction in the sqlite database is what must be
+			 * done here (behaviour change while adding error reporting to the
+			 * journal) */
+
+			tracker_data_rollback_transaction ();
+			g_propagate_error (error, actual_error);
+			return;
 		}
 	}
 
+	get_transaction_modseq ();
+	if (has_persistent && !in_ontology_transaction) {
+		transaction_modseq++;
+	}
+
 	resource_time = 0;
 	in_transaction = FALSE;
 	in_ontology_transaction = FALSE;
@@ -3091,7 +3111,13 @@ tracker_data_rollback_transaction (void)
 	tracker_db_interface_execute_query (iface, NULL, "PRAGMA cache_size = %d", TRACKER_DB_CACHE_SIZE_DEFAULT);
 
 	if (!in_journal_replay) {
-		tracker_db_journal_rollback_transaction ();
+		tracker_db_journal_rollback_transaction (&ignorable);
+
+		if (ignorable) {
+			/* Not sure if this is also ignorable: it's the close() of the
+			 * journal file failing. */
+			g_error_free (ignorable);
+		}
 
 		if (rollback_callbacks) {
 			guint n;
@@ -3183,10 +3209,17 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 	TrackerProperty *rdf_type = NULL;
 	gint last_operation_type = 0;
 	const gchar *uri;
+	GError *n_error = NULL;
+
 
 	rdf_type = tracker_ontologies_get_rdf_type ();
 
-	tracker_db_journal_reader_init (NULL);
+	tracker_db_journal_reader_init (NULL, &n_error);
+	if (n_error) {
+		/* This is fatal */
+		g_propagate_error (error, n_error);
+		return;
+	}
 
 	while (tracker_db_journal_reader_next (&journal_error)) {
 		TrackerDBJournalEntryType type;
@@ -3439,15 +3472,28 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 		}
 	}
 
+
 	if (journal_error) {
+		GError *n_error = NULL;
 		gsize size;
 
 		size = tracker_db_journal_reader_get_size_of_correct ();
 		tracker_db_journal_reader_shutdown ();
 
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &n_error);
+		if (n_error) {
+			/* This is fatal */
+			g_propagate_error (error, n_error);
+			return;
+		}
 		tracker_db_journal_truncate (size);
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (&n_error);
+
+		if (n_error) {
+			/* This is fatal */
+			g_propagate_error (error, n_error);
+			return;
+		}
 
 		g_clear_error (&journal_error);
 	} else {
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 842d64f..d59e4b4 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -119,7 +119,7 @@ static JournalWriter ontology_writer = {0};
 static TransactionFormat current_transaction_format;
 
 #if GLIB_CHECK_VERSION (2, 24, 2)
-static gboolean tracker_db_journal_rotate (void);
+static gboolean tracker_db_journal_rotate (GError **error);
 #endif /* GLib check */
 
 static gboolean
@@ -428,7 +428,9 @@ tracker_db_journal_error_quark (void)
 }
 
 static gboolean
-db_journal_init_file (JournalWriter *jwriter, gboolean truncate)
+db_journal_init_file (JournalWriter  *jwriter,
+                      gboolean        truncate,
+                      GError        **error)
 {
 	struct stat st;
 	int flags;
@@ -454,9 +456,9 @@ db_journal_init_file (JournalWriter *jwriter, gboolean truncate)
 	jwriter->journal = g_open (jwriter->journal_filename, flags, mode);
 
 	if (jwriter->journal == -1) {
-		g_critical ("Could not open journal for writing, %s", 
-		            g_strerror (errno));
-
+		g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+		             "Could not open journal for writing, %s",
+		             g_strerror (errno));
 		g_free (jwriter->journal_filename);
 		jwriter->journal_filename = NULL;
 		return FALSE;
@@ -503,22 +505,28 @@ db_journal_init_file (JournalWriter *jwriter, gboolean truncate)
 }
 
 static gboolean
-db_journal_writer_init (JournalWriter *jwriter,
-                        gboolean       truncate,
-                        gboolean       global_writer,
-                        const gchar   *filename)
+db_journal_writer_init (JournalWriter  *jwriter,
+                        gboolean        truncate,
+                        gboolean        global_writer,
+                        const gchar    *filename,
+                        GError        **error)
 {
 	gchar *directory;
 	gint mode;
+	GError *n_error = NULL;
+	gboolean ret;
 
 	directory = g_path_get_dirname (filename);
 	if (g_strcmp0 (directory, ".")) {
 		mode = S_IRWXU | S_IRWXG | S_IRWXO;
 		if (g_mkdir_with_parents (directory, mode)) {
-			g_critical ("tracker data directory does not exist and "
-			            "could not be created: %s",
-			            g_strerror (errno));
+
+			g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+			             "tracker data directory does not exist and "
+			             "could not be created: %s",
+			             g_strerror (errno));
 			g_free (directory);
+
 			return FALSE;
 		}
 	}
@@ -526,16 +534,24 @@ db_journal_writer_init (JournalWriter *jwriter,
 
 	jwriter->journal_filename = g_strdup (filename);
 
-	return db_journal_init_file (jwriter, truncate);
+	ret = db_journal_init_file (jwriter, truncate, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
+	return ret;
 }
 
 gboolean
-tracker_db_journal_init (const gchar *filename,
-                         gboolean     truncate)
+tracker_db_journal_init (const gchar  *filename,
+                         gboolean      truncate,
+                         GError      **error)
 {
 	gboolean ret;
 	const gchar *filename_use;
 	gchar *filename_free = NULL;
+	GError *n_error = NULL;
 
 	g_return_val_if_fail (writer.journal == 0, FALSE);
 
@@ -551,17 +567,23 @@ tracker_db_journal_init (const gchar *filename,
 		filename_use = filename;
 	}
 
-	ret = db_journal_writer_init (&writer, truncate, TRUE, filename_use);
+	ret = db_journal_writer_init (&writer, truncate, TRUE, filename_use, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
 	g_free (filename_free);
 
 	return ret;
 }
 
 static gboolean
-db_journal_ontology_init (void)
+db_journal_ontology_init (GError **error)
 {
 	gboolean ret;
 	gchar *filename;
+	GError *n_error = NULL;
 
 	g_return_val_if_fail (ontology_writer.journal == 0, FALSE);
 
@@ -571,14 +593,20 @@ db_journal_ontology_init (void)
 	                             TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME,
 	                             NULL);
 
-	ret = db_journal_writer_init (&ontology_writer, FALSE, FALSE, filename);
+	ret = db_journal_writer_init (&ontology_writer, FALSE, FALSE, filename, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
 	g_free (filename);
 
 	return ret;
 }
 
 static gboolean
-db_journal_writer_shutdown (JournalWriter *jwriter)
+db_journal_writer_shutdown (JournalWriter  *jwriter,
+                            GError        **error)
 {
 	g_free (jwriter->journal_filename);
 	jwriter->journal_filename = NULL;
@@ -588,8 +616,9 @@ db_journal_writer_shutdown (JournalWriter *jwriter)
 	}
 
 	if (close (jwriter->journal) != 0) {
-		g_warning ("Could not close journal, %s", 
-		           g_strerror (errno));
+		g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+		             "Could not close journal, %s",
+		             g_strerror (errno));
 		return FALSE;
 	}
 
@@ -599,9 +628,18 @@ db_journal_writer_shutdown (JournalWriter *jwriter)
 }
 
 gboolean
-tracker_db_journal_shutdown (void)
+tracker_db_journal_shutdown (GError **error)
 {
-	return db_journal_writer_shutdown (&writer);
+	GError *n_error = NULL;
+	gboolean ret;
+
+	ret = db_journal_writer_shutdown (&writer, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
+	return ret;
 }
 
 gsize
@@ -665,9 +703,17 @@ tracker_db_journal_start_transaction (time_t time)
 }
 
 gboolean
-tracker_db_journal_start_ontology_transaction (time_t time)
+tracker_db_journal_start_ontology_transaction (time_t   time,
+                                               GError **error)
 {
-	if (!db_journal_ontology_init ()) {
+	GError *n_error = NULL;
+
+	if (!db_journal_ontology_init (&n_error)) {
+
+		if (n_error) {
+			g_propagate_error (error, n_error);
+		}
+
 		return FALSE;
 	}
 
@@ -1051,8 +1097,10 @@ tracker_db_journal_append_resource (gint         s_id,
 }
 
 gboolean
-tracker_db_journal_rollback_transaction (void)
+tracker_db_journal_rollback_transaction (GError **error)
 {
+	GError *n_error = NULL;
+
 	g_return_val_if_fail (writer.journal > 0, FALSE);
 	g_return_val_if_fail (current_transaction_format != TRANSACTION_FORMAT_NONE, FALSE);
 
@@ -1060,7 +1108,11 @@ tracker_db_journal_rollback_transaction (void)
 
 	if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
 		cur_block_kill (&ontology_writer);
-		db_journal_writer_shutdown (&ontology_writer);
+		db_journal_writer_shutdown (&ontology_writer, &n_error);
+	}
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
 	}
 
 	current_transaction_format = TRANSACTION_FORMAT_NONE;
@@ -1077,7 +1129,8 @@ tracker_db_journal_truncate (gsize new_size)
 }
 
 static gboolean
-db_journal_writer_commit_db_transaction (JournalWriter *jwriter)
+db_journal_writer_commit_db_transaction (JournalWriter  *jwriter,
+                                         GError        **error)
 {
 	guint32 crc;
 	guint begin_pos;
@@ -1111,7 +1164,9 @@ db_journal_writer_commit_db_transaction (JournalWriter *jwriter)
 	cur_setnum (jwriter->cur_block, &begin_pos, crc);
 
 	if (!write_all_data (jwriter->journal, jwriter->cur_block, jwriter->cur_block_len)) {
-		g_critical ("Could not write to journal, %s", g_strerror (errno));
+		g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+		             "Could not write to journal, %s",
+		             g_strerror (errno));
 		return FALSE;
 	}
 
@@ -1125,30 +1180,39 @@ db_journal_writer_commit_db_transaction (JournalWriter *jwriter)
 }
 
 gboolean
-tracker_db_journal_commit_db_transaction (void)
+tracker_db_journal_commit_db_transaction (GError **error)
 {
 	gboolean ret;
+	GError *n_error = NULL;
+	GError *nn_error = NULL;
 
 	g_return_val_if_fail (current_transaction_format != TRANSACTION_FORMAT_NONE, FALSE);
 
 	if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
-		ret = db_journal_writer_commit_db_transaction (&ontology_writer);
-		db_journal_writer_shutdown (&ontology_writer);
+		ret = db_journal_writer_commit_db_transaction (&ontology_writer, &n_error);
+		db_journal_writer_shutdown (&ontology_writer, &nn_error);
 	} else {
-		ret = db_journal_writer_commit_db_transaction (&writer);
+		ret = db_journal_writer_commit_db_transaction (&writer, &n_error);
 
 #if GLIB_CHECK_VERSION (2, 24, 2)
 		if (ret) {
 			if (rotating_settings.do_rotating && (writer.cur_size > rotating_settings.chunk_size)) {
-				if (!tracker_db_journal_rotate ()) {
-					g_critical ("Could not rotate journal, %s", g_strerror (errno));
-					ret = FALSE;
-				}
+				ret = tracker_db_journal_rotate (&n_error);
 			}
 		}
 #endif /* GLib check */
 	}
 
+	/* Only report the first error here */
+	if (n_error) {
+		g_propagate_error (error, n_error);
+		if (nn_error) {
+			g_error_free (nn_error);
+		}
+	} else if (nn_error) {
+		g_propagate_error (error, nn_error);
+	}
+
 	current_transaction_format = TRANSACTION_FORMAT_NONE;
 
 	return ret;
@@ -1279,13 +1343,14 @@ db_journal_reader_init_file (JournalReader  *jreader,
 }
 
 static gboolean
-db_journal_reader_init (JournalReader *jreader,
-                        gboolean global_reader,
-                        const gchar *filename)
+db_journal_reader_init (JournalReader  *jreader,
+                        gboolean        global_reader,
+                        const gchar    *filename,
+                        GError        **error)
 {
-	GError *error = NULL;
 	gchar *filename_used;
 	gchar *filename_open;
+	GError *n_error = NULL;
 
 	g_return_val_if_fail (jreader->file == NULL, FALSE);
 
@@ -1311,15 +1376,18 @@ db_journal_reader_init (JournalReader *jreader,
 
 	jreader->type = TRACKER_DB_JOURNAL_START;
 
-	if (!db_journal_reader_init_file (jreader, filename_open, &error)) {
-		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
-		    !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
-			/* do not warn if the file does not exist, just return FALSE */
-			g_warning ("Could not create TrackerDBJournalReader for file '%s', %s",
-				   jreader->filename,
-				   error->message ? error->message : "no error given");
+	if (!db_journal_reader_init_file (jreader, filename_open, &n_error)) {
+		if (!g_error_matches (n_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
+		    !g_error_matches (n_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
+			/* Do not set error if the file does not exist, just return FALSE */
+
+			g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+			             "Could not create TrackerDBJournalReader for file '%s', %s",
+			             jreader->filename,
+			             n_error->message ? n_error->message : "no error given");
 		}
-		g_error_free (error);
+
+		g_error_free (n_error);
 		g_free (filename_open);
 		g_free (jreader->filename);
 		jreader->filename = NULL;
@@ -1334,15 +1402,28 @@ db_journal_reader_init (JournalReader *jreader,
 }
 
 gboolean
-tracker_db_journal_reader_init (const gchar *filename)
+tracker_db_journal_reader_init (const gchar  *filename,
+                                GError      **error)
 {
-	return db_journal_reader_init (&reader, TRUE, filename);
+	gboolean ret;
+	GError *n_error = NULL;
+
+	ret = db_journal_reader_init (&reader, TRUE, filename, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
+	return ret;
 }
 
 gboolean
-tracker_db_journal_reader_ontology_init (const gchar *filename) {
+tracker_db_journal_reader_ontology_init (const gchar  *filename,
+                                         GError      **error)
+{
 	gchar *filename_used;
 	gboolean result;
+	GError *n_error = NULL;
 
 	/* Used mostly for testing */
 	if (G_UNLIKELY (filename)) {
@@ -1355,10 +1436,14 @@ tracker_db_journal_reader_ontology_init (const gchar *filename) {
 		                                  NULL);
 	}
 
-	result = tracker_db_journal_reader_init (filename_used);
+	result = tracker_db_journal_reader_init (filename_used, &n_error);
 
 	g_free (filename_used);
 
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
 	return result;
 }
 
@@ -1772,8 +1857,9 @@ tracker_db_journal_reader_verify_last (const gchar  *filename,
 	guint32 entry_size_check;
 	gboolean success = FALSE;
 	JournalReader jreader = { 0 };
+	GError *n_error = NULL;
 
-	if (db_journal_reader_init (&jreader, FALSE, filename)) {
+	if (db_journal_reader_init (&jreader, FALSE, filename, &n_error)) {
 
 		if (jreader.end != jreader.current) {
 			entry_size_check = read_uint32 (jreader.end - 4);
@@ -1793,6 +1879,10 @@ tracker_db_journal_reader_verify_last (const gchar  *filename,
 		}
 	}
 
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
 	return success;
 }
 
@@ -1971,7 +2061,7 @@ on_chunk_copied_delete (GObject      *source_object,
 }
 
 static gboolean
-tracker_db_journal_rotate (void)
+tracker_db_journal_rotate (GError **error)
 {
 	GFile *source, *destination;
 	GFile *dest_dir;
@@ -1982,6 +2072,8 @@ tracker_db_journal_rotate (void)
 	GOutputStream *ostream, *cstream;
 	static gint max = 0;
 	static gboolean needs_move;
+	GError *n_error = NULL;
+	gboolean ret;
 
 	if (max == 0) {
 		gchar *directory;
@@ -2020,8 +2112,9 @@ tracker_db_journal_rotate (void)
 	tracker_db_journal_fsync ();
 
 	if (close (writer.journal) != 0) {
-		g_warning ("Could not close journal, %s", 
-		           g_strerror (errno));
+		g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+		             "Could not close journal, %s",
+		             g_strerror (errno));
 		return FALSE;
 	}
 
@@ -2060,6 +2153,12 @@ tracker_db_journal_rotate (void)
 
 	g_free (fullpath);
 
-	return db_journal_init_file (&writer, TRUE);
+	ret = db_journal_init_file (&writer, TRUE, &n_error);
+
+	if (n_error) {
+		g_propagate_error (error, n_error);
+	}
+
+	return ret;
 }
 #endif /* GLib check */
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index 7f3e1a5..d8d5096 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -51,9 +51,10 @@ GQuark       tracker_db_journal_error_quark                  (void);
 /*
  * Writer API
  */
-gboolean     tracker_db_journal_init                         (const gchar *filename,
-                                                              gboolean     truncate);
-gboolean     tracker_db_journal_shutdown                     (void);
+gboolean     tracker_db_journal_init                         (const gchar  *filename,
+                                                              gboolean      truncate,
+                                                              GError      **error);
+gboolean     tracker_db_journal_shutdown                     (GError      **error);
 
 const gchar* tracker_db_journal_get_filename                 (void);
 gsize        tracker_db_journal_get_size                     (void);
@@ -67,7 +68,8 @@ void         tracker_db_journal_get_rotating                 (gboolean    *do_ro
                                                               gchar      **rotate_to);
 
 gboolean     tracker_db_journal_start_transaction            (time_t       time);
-gboolean     tracker_db_journal_start_ontology_transaction   (time_t       time);
+gboolean     tracker_db_journal_start_ontology_transaction   (time_t       time,
+                                                              GError     **error);
 
 gboolean     tracker_db_journal_append_delete_statement      (gint         g_id,
                                                               gint         s_id,
@@ -96,8 +98,8 @@ gboolean     tracker_db_journal_append_update_statement_id   (gint         g_id,
 gboolean     tracker_db_journal_append_resource              (gint         s_id,
                                                               const gchar *uri);
 
-gboolean     tracker_db_journal_rollback_transaction         (void);
-gboolean     tracker_db_journal_commit_db_transaction           (void);
+gboolean     tracker_db_journal_rollback_transaction         (GError **error);
+gboolean     tracker_db_journal_commit_db_transaction        (GError **error);
 
 gboolean     tracker_db_journal_fsync                        (void);
 gboolean     tracker_db_journal_truncate                     (gsize new_size);
@@ -105,8 +107,10 @@ gboolean     tracker_db_journal_truncate                     (gsize new_size);
 /*
  * Reader API
  */
-gboolean     tracker_db_journal_reader_init                  (const gchar  *filename);
-gboolean     tracker_db_journal_reader_ontology_init         (const gchar  *filename);
+gboolean     tracker_db_journal_reader_init                  (const gchar   *filename,
+                                                              GError       **error);
+gboolean     tracker_db_journal_reader_ontology_init         (const gchar  *filename,
+                                                              GError       **error);
 gboolean     tracker_db_journal_reader_shutdown              (void);
 TrackerDBJournalEntryType
              tracker_db_journal_reader_get_type              (void);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index c931cd4..3427eb6 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -392,6 +392,7 @@ db_manager_remove_journal (void)
 	gboolean do_rotate = FALSE;
 	const gchar *dirs[3] = { NULL, NULL, NULL };
 	guint i;
+	GError *error = NULL;
 
 	/* We duplicate the path here because later we shutdown the
 	 * journal which frees this data. We want to survive that.
@@ -406,7 +407,12 @@ db_manager_remove_journal (void)
 	directory = g_path_get_dirname (path);
 
 	tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+
+	if (error) {
+		g_message ("%s", error->message);
+		g_error_free (error);
+	}
 
 	dirs[0] = directory;
 	dirs[1] = do_rotate ? rotate_to : NULL;
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index 2ef09c6..7f548d4 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -437,11 +437,11 @@ tracker_control_general_run (void)
 			return EXIT_FAILURE;
 		}
 
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, NULL);
 
 		tracker_db_manager_remove_all (hard_reset);
 		tracker_db_manager_shutdown ();
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (NULL);
 
 		/* Unset log handler */
 		g_log_remove_handler (NULL, log_handler_id);
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index 02ef306..2729625 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -26,21 +26,26 @@
 static void
 test_init_and_shutdown (void)
 {
+	GError *error = NULL;
 	gboolean result;
 
 	/* check double init/shutdown */
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	result = tracker_db_journal_init (NULL, FALSE);
+	result = tracker_db_journal_init (NULL, FALSE, &error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
-	result = tracker_db_journal_shutdown ();
+	result = tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	result = tracker_db_journal_init (NULL, FALSE);
+	result = tracker_db_journal_init (NULL, FALSE, &error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
-	result = tracker_db_journal_shutdown ();
+	result = tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 }
 
@@ -51,12 +56,14 @@ test_write_functions (void)
 	const gchar *filename;
 	gsize initial_size, actual_size;
 	gboolean result;
+	GError *error = NULL;
 
 	path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
 	g_unlink (path);
 
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	tracker_db_journal_init (path, FALSE);
+	tracker_db_journal_init (path, FALSE, &error);
+	g_assert_no_error (error);
 
 	filename = tracker_db_journal_get_filename ();
 	g_assert (filename != NULL);
@@ -76,7 +83,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_delete_statement (0, 10, 11, "test");
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_rollback_transaction ();
+	result = tracker_db_journal_rollback_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 	actual_size = tracker_db_journal_get_size ();
 	g_assert_cmpint (initial_size, ==, actual_size);
@@ -92,7 +100,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_delete_statement_id (0, 12, 13, 14);
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 	actual_size = tracker_db_journal_get_size ();
 	g_assert_cmpint (initial_size, !=, actual_size);
@@ -106,7 +115,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_insert_statement (0, 15, 16, "test");
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	/* Test insert id */
@@ -120,14 +130,16 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_insert_statement_id (0, 17, 18, 19);
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	/* Test fsync */
 	result = tracker_db_journal_fsync ();
 	g_assert_cmpint (result, ==, TRUE);
 
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 
 	g_free (path);
 }
@@ -147,7 +159,8 @@ test_read_functions (void)
 	/* NOTE: we don't unlink here so we can use the data from the write tests */
 
 	/* Create an iterator */
-	result = tracker_db_journal_reader_init (path);
+	result = tracker_db_journal_reader_init (path, &error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	type = tracker_db_journal_reader_get_type ();



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