[tracker/journal-err-reporting] libtracker-data: Unfinished: Add error reporting to journal code
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/journal-err-reporting] libtracker-data: Unfinished: Add error reporting to journal code
- Date: Thu, 21 Apr 2011 11:41:15 +0000 (UTC)
commit d9d7a6fa4a5d8e5554848cad38b14c74527bea8d
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Apr 21 13:40:31 2011 +0200
libtracker-data: Unfinished: Add error reporting to journal code
src/libtracker-data/tracker-db-journal.c | 215 ++++++++++++++++++++++--------
src/libtracker-data/tracker-db-journal.h | 20 ++-
2 files changed, 169 insertions(+), 66 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 842d64f..e0fb512 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]