[tracker/initable-db-iface-rebased: 1/3] libtracker-data, tracker-store, tracker-control, tests: Make db iface initable
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/initable-db-iface-rebased: 1/3] libtracker-data, tracker-store, tracker-control, tests: Make db iface initable
- Date: Thu, 3 Feb 2011 13:41:25 +0000 (UTC)
commit 0f80a796b657d12796c127055158c2bd25b0bdde
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Feb 2 16:51:26 2011 +0100
libtracker-data, tracker-store, tracker-control, tests: Make db iface initable
src/libtracker-data/libtracker-data.vapi | 5 +-
src/libtracker-data/tracker-data-backup.c | 15 +-
src/libtracker-data/tracker-data-manager.c | 75 ++++---
src/libtracker-data/tracker-data-manager.h | 26 ++-
src/libtracker-data/tracker-db-interface-sqlite.c | 119 +++++++----
src/libtracker-data/tracker-db-interface-sqlite.h | 6 +-
src/libtracker-data/tracker-db-interface.h | 3 +-
src/libtracker-data/tracker-db-manager.c | 240 +++++++++++++++-----
src/libtracker-data/tracker-db-manager.h | 17 +-
src/tracker-control/tracker-control-general.c | 7 +-
src/tracker-store/tracker-locale-change.c | 10 +-
src/tracker-store/tracker-main.vala | 21 +-
tests/libtracker-data/tracker-backup-test.c | 9 +-
.../libtracker-data/tracker-ontology-change-test.c | 8 +-
tests/libtracker-data/tracker-ontology-test.c | 13 +-
tests/libtracker-data/tracker-sparql-blank-test.c | 5 +-
tests/libtracker-data/tracker-sparql-test.c | 4 +-
tests/libtracker-fts/tracker-fts-test.c | 4 +-
utils/tracker-sql/tracker-sql.c | 24 +-
19 files changed, 421 insertions(+), 190 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index cc213ea..9f431a3 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -31,7 +31,8 @@ namespace Tracker {
public errordomain DBInterfaceError {
QUERY_ERROR,
CORRUPT,
- INTERRUPTED
+ INTERRUPTED,
+ OPEN_ERROR
}
[CCode (cprefix = "TRACKER_DB_STATEMENT_CACHE_TYPE_", cheader_filename = "libtracker-data/tracker-db-interface.h")]
@@ -194,7 +195,7 @@ namespace Tracker {
[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
namespace Data.Manager {
- public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status);
+ public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws DBInterfaceError;
public void shutdown ();
}
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 4b3ea8b..18b9adc 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -322,6 +322,7 @@ tracker_data_backup_restore (GFile *journal,
GError **error)
{
BackupSaveInfo *info;
+ GError *internal_error = NULL;
info = g_new0 (BackupSaveInfo, 1);
info->destination = g_file_new_for_path (tracker_db_journal_get_filename ());
@@ -390,12 +391,16 @@ tracker_data_backup_restore (GFile *journal,
tracker_data_manager_init (flags, test_schemas, &is_first, TRUE,
select_cache_size, update_cache_size,
busy_callback, busy_user_data,
- "Restoring backup");
+ "Restoring backup", &internal_error);
- /* Re-set the DB version file, so that its mtime changes. The mtime of this
- * file will change only when the whole DB is recreated (after a hard reset
- * or after a backup restoration). */
- tracker_db_manager_create_version_file ();
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ } else {
+ /* Re-set the DB version file, so that its mtime changes. The mtime of this
+ * file will change only when the whole DB is recreated (after a hard reset
+ * or after a backup restoration). */
+ tracker_db_manager_create_version_file ();
+ }
} else {
g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR, 0,
"Backup file doesn't exist");
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 86e8c08..02e04ab 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3138,15 +3138,17 @@ tracker_data_manager_recreate_indexes (TrackerBusyCallback busy_callback,
}
gboolean
-tracker_data_manager_reload (TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation)
+tracker_data_manager_reload (TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error)
{
TrackerDBManagerFlags flags;
guint select_cache_size;
guint update_cache_size;
gboolean is_first;
gboolean status;
+ GError *internal_error = NULL;
g_message ("Reloading data manager...");
/* Shutdown data manager... */
@@ -3164,10 +3166,16 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback,
update_cache_size,
busy_callback,
busy_user_data,
- busy_operation);
+ busy_operation,
+ &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ }
g_message (" %s reloading data manager",
status ? "Succeeded" : "Failed");
+
return status;
}
@@ -3202,15 +3210,16 @@ load_ontologies_gvdb (GError **error)
}
gboolean
-tracker_data_manager_init (TrackerDBManagerFlags flags,
- const gchar **test_schemas,
- gboolean *first_time,
- gboolean journal_check,
- guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation)
+tracker_data_manager_init (TrackerDBManagerFlags flags,
+ const gchar **test_schemas,
+ gboolean *first_time,
+ gboolean journal_check,
+ guint select_cache_size,
+ guint update_cache_size,
+ TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error)
{
TrackerDBInterface *iface;
gboolean is_first_time_index, read_journal, check_ontology;
@@ -3223,6 +3232,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
gboolean read_only;
GHashTable *uri_id_map = NULL;
gchar *busy_status;
+ GError *internal_error = NULL;
read_only = (flags & TRACKER_DB_MANAGER_READONLY) ? TRUE : FALSE;
@@ -3249,7 +3259,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
update_cache_size,
busy_callback,
busy_user_data,
- busy_operation)) {
+ busy_operation,
+ &internal_error)) {
+
+ g_propagate_error (error, internal_error);
+
return FALSE;
}
@@ -3438,7 +3452,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
guint p;
GPtrArray *seen_classes;
GPtrArray *seen_properties;
- GError *error = NULL;
+ GError *n_error = NULL;
seen_classes = g_ptr_array_new ();
seen_properties = g_ptr_array_new ();
@@ -3471,13 +3485,13 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
* for all the ontology files in ontologies_dir whether the last-modified
* has changed since we dealt with the file last time. */
- stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
+ stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &n_error,
"SELECT Resource.Uri, \"rdfs:Resource\".\"nao:lastModified\" FROM \"tracker:Ontology\" "
"INNER JOIN Resource ON Resource.ID = \"tracker:Ontology\".ID "
"INNER JOIN \"rdfs:Resource\" ON \"tracker:Ontology\".ID = \"rdfs:Resource\".ID");
if (stmt) {
- cursor = tracker_db_statement_start_cursor (stmt, &error);
+ cursor = tracker_db_statement_start_cursor (stmt, &n_error);
g_object_unref (stmt);
} else {
cursor = NULL;
@@ -3489,7 +3503,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
NULL);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL, &n_error)) {
const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
/* It's stored as an int in the db anyway. This is caused by
* string_to_gvalue in tracker-data-update.c */
@@ -3502,9 +3516,9 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_object_unref (cursor);
}
- if (error) {
- g_warning ("%s", error->message);
- g_clear_error (&error);
+ if (n_error) {
+ g_warning ("%s", n_error->message);
+ g_clear_error (&n_error);
}
for (l = ontos; l; l = l->next) {
@@ -3587,7 +3601,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
update_cache_size,
busy_callback,
busy_user_data,
- busy_operation);
+ busy_operation,
+ error);
}
if (ontology_error) {
@@ -3646,7 +3661,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
update_cache_size,
busy_callback,
busy_user_data,
- busy_operation);
+ busy_operation,
+ error);
}
if (ontology_error) {
@@ -3660,7 +3676,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (update_nao) {
/* Update the nao:lastModified in the database */
- stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &error,
+ stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &n_error,
"UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
"WHERE \"rdfs:Resource\".ID = "
"(SELECT Resource.ID FROM Resource INNER JOIN \"rdfs:Resource\" "
@@ -3670,13 +3686,13 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (stmt) {
tracker_db_statement_bind_int (stmt, 0, last_mod);
tracker_db_statement_bind_text (stmt, 1, ontology_uri);
- tracker_db_statement_execute (stmt, &error);
+ tracker_db_statement_execute (stmt, &n_error);
g_object_unref (stmt);
}
- if (error) {
- g_critical ("%s", error->message);
- g_clear_error (&error);
+ if (n_error) {
+ g_critical ("%s", n_error->message);
+ g_clear_error (&n_error);
}
}
@@ -3729,7 +3745,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
update_cache_size,
busy_callback,
busy_user_data,
- busy_operation);
+ busy_operation,
+ error);
}
if (ontology_error) {
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 30f97c9..71c40b1 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -45,19 +45,21 @@ typedef enum {
} TrackerDataOntologyError;
GQuark tracker_data_ontology_error_quark (void);
-gboolean tracker_data_manager_init (TrackerDBManagerFlags flags,
- const gchar **test_schema,
- gboolean *first_time,
- gboolean journal_check,
- guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation);
+gboolean tracker_data_manager_init (TrackerDBManagerFlags flags,
+ const gchar **test_schema,
+ gboolean *first_time,
+ gboolean journal_check,
+ guint select_cache_size,
+ guint update_cache_size,
+ TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error);
void tracker_data_manager_shutdown (void);
-gboolean tracker_data_manager_reload (TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation);
+gboolean tracker_data_manager_reload (TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index ebc9845..6cfab09 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -114,21 +114,22 @@ struct TrackerDBStatementClass {
GObjectClass parent_class;
};
-static TrackerDBStatement *tracker_db_statement_sqlite_new (TrackerDBInterface *db_interface,
- sqlite3_stmt *sqlite_stmt);
-static void tracker_db_statement_sqlite_reset (TrackerDBStatement *stmt);
-static TrackerDBCursor *tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
- TrackerDBStatement *ref_stmt,
- TrackerPropertyType *types,
- gint n_types,
- const gchar **variable_names,
- gint n_variable_names,
- gboolean threadsafe);
-static gboolean tracker_db_cursor_get_boolean (TrackerSparqlCursor *cursor,
- guint column);
-static gboolean db_cursor_iter_next (TrackerDBCursor *cursor,
- GCancellable *cancellable,
- GError **error);
+static void tracker_db_interface_initable_iface_init (GInitableIface *iface);
+static TrackerDBStatement *tracker_db_statement_sqlite_new (TrackerDBInterface *db_interface,
+ sqlite3_stmt *sqlite_stmt);
+static void tracker_db_statement_sqlite_reset (TrackerDBStatement *stmt);
+static TrackerDBCursor *tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
+ TrackerDBStatement *ref_stmt,
+ TrackerPropertyType *types,
+ gint n_types,
+ const gchar **variable_names,
+ gint n_variable_names,
+ gboolean threadsafe);
+static gboolean tracker_db_cursor_get_boolean (TrackerSparqlCursor *cursor,
+ guint column);
+static gboolean db_cursor_iter_next (TrackerDBCursor *cursor,
+ GCancellable *cancellable,
+ GError **error);
enum {
PROP_0,
@@ -136,7 +137,9 @@ enum {
PROP_RO
};
-G_DEFINE_TYPE (TrackerDBInterface, tracker_db_interface, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_CODE (TrackerDBInterface, tracker_db_interface, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ tracker_db_interface_initable_iface_init));
G_DEFINE_TYPE (TrackerDBStatement, tracker_db_statement, G_TYPE_OBJECT)
@@ -544,7 +547,8 @@ tracker_locale_notify_cb (TrackerLocaleID id,
}
static void
-open_database (TrackerDBInterface *db_interface)
+open_database (TrackerDBInterface *db_interface,
+ GError **error)
{
int mode;
@@ -557,7 +561,11 @@ open_database (TrackerDBInterface *db_interface)
}
if (sqlite3_open_v2 (db_interface->filename, &db_interface->db, mode | SQLITE_OPEN_NOMUTEX, NULL) != SQLITE_OK) {
- g_critical ("Could not open sqlite3 database:'%s'", db_interface->filename);
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_OPEN_ERROR,
+ "Could not open sqlite3 database:'%s'", db_interface->filename);
+ return;
} else {
g_message ("Opened sqlite3 database:'%s'", db_interface->filename);
}
@@ -605,22 +613,30 @@ open_database (TrackerDBInterface *db_interface)
sqlite3_busy_timeout (db_interface->db, 100000);
}
-static GObject *
-tracker_db_interface_sqlite_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+static gboolean
+tracker_db_interface_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
- GObject *object;
TrackerDBInterface *db_iface;
+ GError *internal_error = NULL;
- object = (* G_OBJECT_CLASS (tracker_db_interface_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
- db_iface = TRACKER_DB_INTERFACE (object);
+ db_iface = TRACKER_DB_INTERFACE (initable);
- open_database (db_iface);
+ open_database (db_iface, &internal_error);
- return object;
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+tracker_db_interface_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = tracker_db_interface_initable_init;
}
static void
@@ -778,7 +794,6 @@ tracker_db_interface_class_init (TrackerDBInterfaceClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- object_class->constructor = tracker_db_interface_sqlite_constructor;
object_class->set_property = tracker_db_interface_sqlite_set_property;
object_class->get_property = tracker_db_interface_sqlite_get_property;
object_class->finalize = tracker_db_interface_sqlite_finalize;
@@ -1165,20 +1180,46 @@ tracker_db_interface_execute_vquery (TrackerDBInterface *db_interface,
}
TrackerDBInterface *
-tracker_db_interface_sqlite_new (const gchar *filename)
+tracker_db_interface_sqlite_new (const gchar *filename,
+ GError **error)
{
- return g_object_new (TRACKER_TYPE_DB_INTERFACE,
- "filename", filename,
- NULL);
+ TrackerDBInterface *object;
+ GError *internal_error = NULL;
+
+ object = g_initable_new (TRACKER_TYPE_DB_INTERFACE,
+ NULL,
+ &internal_error,
+ "filename", filename,
+ NULL);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return NULL;
+ }
+
+ return object;
}
TrackerDBInterface *
-tracker_db_interface_sqlite_new_ro (const gchar *filename)
-{
- return g_object_new (TRACKER_TYPE_DB_INTERFACE,
- "filename", filename,
- "read-only", TRUE,
- NULL);
+tracker_db_interface_sqlite_new_ro (const gchar *filename,
+ GError **error)
+{
+ TrackerDBInterface *object;
+ GError *internal_error = NULL;
+
+ object = g_initable_new (TRACKER_TYPE_DB_INTERFACE,
+ NULL,
+ &internal_error,
+ "filename", filename,
+ "read-only", TRUE,
+ NULL);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return NULL;
+ }
+
+ return object;
}
gint64
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 3259728..e58ebc6 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -32,8 +32,10 @@ G_BEGIN_DECLS
#define TRACKER_COLLATION_NAME "TRACKER"
-TrackerDBInterface *tracker_db_interface_sqlite_new (const gchar *filename);
-TrackerDBInterface *tracker_db_interface_sqlite_new_ro (const gchar *filename);
+TrackerDBInterface *tracker_db_interface_sqlite_new (const gchar *filename,
+ GError **error);
+TrackerDBInterface *tracker_db_interface_sqlite_new_ro (const gchar *filename,
+ GError **error);
gint64 tracker_db_interface_sqlite_get_last_insert_id (TrackerDBInterface *interface);
void tracker_db_interface_sqlite_enable_shared_cache (void);
void tracker_db_interface_sqlite_fts_init (TrackerDBInterface *interface,
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index a636bcd..b081902 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -63,7 +63,8 @@ typedef void (*TrackerBusyCallback) (const gchar *status,
typedef enum {
TRACKER_DB_QUERY_ERROR,
TRACKER_DB_CORRUPT,
- TRACKER_DB_INTERRUPTED
+ TRACKER_DB_INTERRUPTED,
+ TRACKER_DB_OPEN_ERROR
} TrackerDBInterfaceError;
typedef enum {
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 8b0baab..bdeee4c 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -138,13 +138,16 @@ static TrackerDBDefinition dbs[] = {
0 },
};
-static gboolean db_exec_no_reply (TrackerDBInterface *iface,
- const gchar *query,
- ...);
-static TrackerDBInterface *db_interface_create (TrackerDB db);
-static TrackerDBInterface *tracker_db_manager_get_db_interfaces (gint num, ...);
-static TrackerDBInterface *tracker_db_manager_get_db_interfaces_ro (gint num, ...);
-static void db_remove_locale_file (void);
+static gboolean db_exec_no_reply (TrackerDBInterface *iface,
+ const gchar *query,
+ ...);
+static TrackerDBInterface *db_interface_create (TrackerDB db,
+ GError **error);
+static TrackerDBInterface *tracker_db_manager_get_db_interfaces (GError **error,
+ gint num, ...);
+static TrackerDBInterface *tracker_db_manager_get_db_interfaces_ro (GError **error,
+ gint num, ...);
+static void db_remove_locale_file (void);
static gboolean initialized;
static gboolean locations_initialized;
@@ -271,11 +274,13 @@ db_type_to_string (TrackerDB db)
}
static TrackerDBInterface *
-db_interface_get (TrackerDB type,
- gboolean *create)
+db_interface_get (TrackerDB type,
+ gboolean *create,
+ GError **error)
{
TrackerDBInterface *iface;
- const gchar *path;
+ const gchar *path;
+ GError *internal_error = NULL;
path = dbs[type].abs_filename;
@@ -290,7 +295,13 @@ db_interface_get (TrackerDB type,
path,
db_type_to_string (type));
- iface = tracker_db_interface_sqlite_new (path);
+ iface = tracker_db_interface_sqlite_new (path,
+ &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return NULL;
+ }
db_set_params (iface,
dbs[type].cache_size,
@@ -300,25 +311,40 @@ db_interface_get (TrackerDB type,
}
static TrackerDBInterface *
-db_interface_get_metadata (void)
+db_interface_get_metadata (GError **error)
{
TrackerDBInterface *iface;
- gboolean create;
+ gboolean create;
+ GError *internal_error = NULL;
- iface = db_interface_get (TRACKER_DB_METADATA, &create);
+ iface = db_interface_get (TRACKER_DB_METADATA, &create, &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return NULL;
+ }
return iface;
}
static TrackerDBInterface *
-db_interface_create (TrackerDB db)
+db_interface_create (TrackerDB db,
+ GError **error)
{
+ TrackerDBInterface *iface;
+ GError *internal_error = NULL;
+
switch (db) {
case TRACKER_DB_UNKNOWN:
return NULL;
case TRACKER_DB_METADATA:
- return db_interface_get_metadata ();
+ iface = db_interface_get_metadata (&internal_error);
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return NULL;
+ }
+ return iface;
default:
g_critical ("This TrackerDB type:%d->'%s' has no interface set up yet!!",
@@ -654,10 +680,11 @@ tracker_db_get_type (void)
}
static void
-db_recreate_all (void)
+db_recreate_all (GError **error)
{
guint i;
gchar *locale;
+ GError *internal_error = NULL;
/* We call an internal version of this function here
* because at the time 'initialized' = FALSE and that
@@ -671,7 +698,19 @@ db_recreate_all (void)
g_message ("Creating database files, this may take a few moments...");
for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
- dbs[i].iface = db_interface_create (i);
+ dbs[i].iface = db_interface_create (i, &internal_error);
+ if (internal_error) {
+ guint y;
+
+ for (y = 0; y < i - 1; y++) {
+ g_object_unref (dbs[y].iface);
+ dbs[y].iface = NULL;
+ }
+
+ g_propagate_error (error, internal_error);
+
+ return;
+ }
}
/* We don't close the dbs in the same loop as before
@@ -718,25 +757,27 @@ tracker_db_manager_init_locations (void)
}
gboolean
-tracker_db_manager_init (TrackerDBManagerFlags flags,
- gboolean *first_time,
- gboolean shared_cache,
- guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation)
+tracker_db_manager_init (TrackerDBManagerFlags flags,
+ gboolean *first_time,
+ gboolean shared_cache,
+ guint select_cache_size,
+ guint update_cache_size,
+ TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error)
{
- GType etype;
- TrackerDBVersion version;
- gchar *filename;
- const gchar *dir;
- const gchar *env_path;
- gboolean need_reindex;
- guint i;
- int in_use_file;
- gboolean loaded = FALSE;
+ GType etype;
+ TrackerDBVersion version;
+ gchar *filename;
+ const gchar *dir;
+ const gchar *env_path;
+ gboolean need_reindex;
+ guint i;
+ int in_use_file;
+ gboolean loaded = FALSE;
TrackerDBInterface *resources_iface;
+ GError *internal_error = NULL;
/* First set defaults for return values */
if (first_time) {
@@ -868,6 +909,12 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX || need_reindex) {
if (flags & TRACKER_DB_MANAGER_READONLY) {
/* no reindexing supported in read-only mode (direct access) */
+
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_OPEN_ERROR,
+ "No reindexing supported in read-only mode (direct access)");
+
return FALSE;
}
@@ -876,13 +923,24 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
}
if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
+
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_OPEN_ERROR,
+ "Filesystem has not enough space");
+
return FALSE;
}
/* Clear the first-index stamp file */
tracker_db_manager_set_first_index_done (FALSE);
- db_recreate_all ();
+ db_recreate_all (&internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
+ }
/* Load databases */
g_message ("Loading databases files...");
@@ -913,7 +971,6 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
for (i = 1; i < G_N_ELEMENTS (dbs) && !must_recreate; i++) {
struct stat st;
- GError *error = NULL;
TrackerDBStatement *stmt;
gchar *busy_status;
@@ -929,7 +986,21 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
continue;
}
- dbs[i].iface = db_interface_create (i);
+ dbs[i].iface = db_interface_create (i, &internal_error);
+
+ if (internal_error) {
+ guint y;
+
+ for (y = 0; y < i - 1; y++) {
+ g_object_unref (dbs[y].iface);
+ dbs[y].iface = NULL;
+ }
+
+ g_propagate_error (error, internal_error);
+
+ return FALSE;
+ }
+
dbs[i].mtime = tracker_file_get_mtime (dbs[i].abs_filename);
loaded = TRUE;
@@ -944,17 +1015,19 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
busy_user_data);
g_free (busy_status);
- stmt = tracker_db_interface_create_statement (dbs[i].iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, &error,
+ stmt = tracker_db_interface_create_statement (dbs[i].iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
+ &internal_error,
"PRAGMA integrity_check(1)");
- if (error != NULL) {
- if (error->domain == TRACKER_DB_INTERFACE_ERROR &&
- error->code == TRACKER_DB_QUERY_ERROR) {
+ if (internal_error != NULL) {
+ if (internal_error->domain == TRACKER_DB_INTERFACE_ERROR &&
+ internal_error->code == TRACKER_DB_QUERY_ERROR) {
must_recreate = TRUE;
} else {
- g_critical ("%s", error->message);
+ g_critical ("%s", internal_error->message);
}
- g_error_free (error);
+ g_error_free (internal_error);
+ internal_error = NULL;
} else {
TrackerDBCursor *cursor = NULL;
@@ -995,10 +1068,22 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
}
if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
+
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_OPEN_ERROR,
+ "Filesystem has not enough space");
+
+ return FALSE;
+ }
+
+ db_recreate_all (&internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
return FALSE;
}
- db_recreate_all ();
loaded = FALSE;
}
@@ -1025,15 +1110,21 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
initialized = TRUE;
if (flags & TRACKER_DB_MANAGER_READONLY) {
- resources_iface = tracker_db_manager_get_db_interfaces_ro (1,
+ resources_iface = tracker_db_manager_get_db_interfaces_ro (&internal_error, 1,
TRACKER_DB_METADATA);
/* libtracker-direct does not use per-thread interfaces */
global_iface = resources_iface;
} else {
- resources_iface = tracker_db_manager_get_db_interfaces (1,
+ resources_iface = tracker_db_manager_get_db_interfaces (&internal_error, 1,
TRACKER_DB_METADATA);
}
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ initialized = FALSE;
+ return FALSE;
+ }
+
tracker_db_interface_set_max_stmt_cache_size (resources_iface,
TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
select_cache_size);
@@ -1424,11 +1515,13 @@ tracker_db_manager_get_file (TrackerDB db)
* returns: (caller-owns): a database connection
**/
static TrackerDBInterface *
-tracker_db_manager_get_db_interfaces (gint num, ...)
+tracker_db_manager_get_db_interfaces (GError **error,
+ gint num, ...)
{
- gint n_args;
- va_list args;
+ gint n_args;
+ va_list args;
TrackerDBInterface *connection = NULL;
+ GError *internal_error = NULL;
g_return_val_if_fail (initialized != FALSE, NULL);
@@ -1437,7 +1530,14 @@ tracker_db_manager_get_db_interfaces (gint num, ...)
TrackerDB db = va_arg (args, TrackerDB);
if (!connection) {
- connection = tracker_db_interface_sqlite_new (dbs[db].abs_filename);
+ connection = tracker_db_interface_sqlite_new (dbs[db].abs_filename,
+ &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ connection = NULL;
+ goto end_on_error;
+ }
db_set_params (connection,
dbs[db].cache_size,
@@ -1451,17 +1551,22 @@ tracker_db_manager_get_db_interfaces (gint num, ...)
}
}
+
+ end_on_error:
+
va_end (args);
return connection;
}
static TrackerDBInterface *
-tracker_db_manager_get_db_interfaces_ro (gint num, ...)
+tracker_db_manager_get_db_interfaces_ro (GError **error,
+ gint num, ...)
{
- gint n_args;
- va_list args;
+ gint n_args;
+ va_list args;
TrackerDBInterface *connection = NULL;
+ GError *internal_error = NULL;
g_return_val_if_fail (initialized != FALSE, NULL);
@@ -1470,7 +1575,15 @@ tracker_db_manager_get_db_interfaces_ro (gint num, ...)
TrackerDB db = va_arg (args, TrackerDB);
if (!connection) {
- connection = tracker_db_interface_sqlite_new_ro (dbs[db].abs_filename);
+ connection = tracker_db_interface_sqlite_new_ro (dbs[db].abs_filename,
+ &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ connection = NULL;
+ goto end_on_error;
+ }
+
db_set_params (connection,
dbs[db].cache_size,
dbs[db].page_size);
@@ -1480,19 +1593,19 @@ tracker_db_manager_get_db_interfaces_ro (gint num, ...)
dbs[db].abs_filename,
dbs[db].name);
}
-
}
+
+ end_on_error:
+
va_end (args);
return connection;
}
-
/**
* tracker_db_manager_get_db_interface:
- * @db: the database file wanted
*
- * Request a database connection to the database file @db.
+ * Request a database connection to the database
*
* The caller must NOT g_object_unref the result
*
@@ -1501,6 +1614,7 @@ tracker_db_manager_get_db_interfaces_ro (gint num, ...)
TrackerDBInterface *
tracker_db_manager_get_db_interface (void)
{
+ GError *internal_error = NULL;
TrackerDBInterface *interface;
g_return_val_if_fail (initialized != FALSE, NULL);
@@ -1514,9 +1628,15 @@ tracker_db_manager_get_db_interface (void)
/* Ensure the interface is there */
if (!interface) {
- interface = tracker_db_manager_get_db_interfaces (1,
+ interface = tracker_db_manager_get_db_interfaces (&internal_error, 1,
TRACKER_DB_METADATA);
+ if (internal_error) {
+ g_critical ("Error opening database: %s", internal_error->message);
+ g_error_free (internal_error);
+ return NULL;
+ }
+
tracker_db_interface_sqlite_fts_init (interface, FALSE);
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 630c80a..4b196cc 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -50,14 +50,15 @@ typedef enum {
} TrackerDBManagerFlags;
GType tracker_db_get_type (void) G_GNUC_CONST;
-gboolean tracker_db_manager_init (TrackerDBManagerFlags flags,
- gboolean *first_time,
- gboolean shared_cache,
- guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation);
+gboolean tracker_db_manager_init (TrackerDBManagerFlags flags,
+ gboolean *first_time,
+ gboolean shared_cache,
+ guint select_cache_size,
+ guint update_cache_size,
+ TrackerBusyCallback busy_callback,
+ gpointer busy_user_data,
+ const gchar *busy_operation,
+ GError **error);
void tracker_db_manager_shutdown (void);
void tracker_db_manager_remove_all (gboolean rm_journal);
void tracker_db_manager_optimize (void);
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index 72c9cb0..cc40fda 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -419,7 +419,12 @@ tracker_control_general_run (void)
100,
NULL,
NULL,
- NULL)) {
+ NULL,
+ &error)) {
+
+ g_message ("Error initializing database: %s", error->message);
+ g_free (error);
+
return EXIT_FAILURE;
}
diff --git a/src/tracker-store/tracker-locale-change.c b/src/tracker-store/tracker-locale-change.c
index b98fc95..0236643 100644
--- a/src/tracker-store/tracker-locale-change.c
+++ b/src/tracker-store/tracker-locale-change.c
@@ -53,6 +53,7 @@ locale_change_process_cb (GObject *source,
gpointer busy_user_data;
GDestroyNotify busy_destroy_notify;
TrackerLocaleChangeContext *ctxt = user_data;
+ GError *error = NULL;
notifier = TRACKER_STATUS (tracker_dbus_get_object (TRACKER_TYPE_STATUS));
@@ -64,7 +65,14 @@ locale_change_process_cb (GObject *source,
/* Reload! This will regenerate indexes with the new locale */
tracker_data_manager_reload (busy_callback,
busy_user_data,
- "Changing locale");
+ "Changing locale",
+ &error);
+
+ if (error) {
+ g_critical ("Error reloading database for locale change: %s",
+ error->message);
+ g_error_free (error);
+ }
busy_destroy_notify (busy_user_data);
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 7c01ce5..f4bff34 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -290,19 +290,20 @@ License which can be viewed at:
bool is_first_time_index;
- if (!Tracker.Data.Manager.init (flags,
- null,
- out is_first_time_index,
- true,
- select_cache_size,
- update_cache_size,
- busy_callback,
- "Initializing")) {
-
+ try {
+ Tracker.Data.Manager.init (flags,
+ null,
+ out is_first_time_index,
+ true,
+ select_cache_size,
+ update_cache_size,
+ busy_callback,
+ "Initializing");
+ } catch (Tracker.DBInterfaceError e) {
+ critical ("Cannot initialize database: %s", e.message);
return 1;
}
-
db_config = null;
notifier = null;
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index f9fd51b..36e4888 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -112,7 +112,9 @@ test_backup_and_restore_helper (gboolean journal)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
(const gchar **) test_schemas,
- NULL, FALSE, 100, 100, NULL, NULL, NULL);
+ NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
/* load data set */
data_filename = g_strconcat (data_prefix, ".data", NULL);
@@ -168,7 +170,10 @@ test_backup_and_restore_helper (gboolean journal)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
(const gchar **) test_schemas,
- NULL, FALSE, 100, 100, NULL, NULL, NULL);
+ NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
+
check_content_in_db (0, 0);
tracker_data_backup_restore (backup_file, (const gchar **) test_schemas, NULL, NULL, &error);
diff --git a/tests/libtracker-data/tracker-ontology-change-test.c b/tests/libtracker-data/tracker-ontology-change-test.c
index 5cc37ea..2fd935d 100644
--- a/tests/libtracker-data/tracker-ontology-change-test.c
+++ b/tests/libtracker-data/tracker-ontology-change-test.c
@@ -229,7 +229,9 @@ test_ontology_change (void)
g_chmod (ontology_file, 0666);
tracker_data_manager_init (0, (const gchar **) test_schemas,
- NULL, FALSE, 100, 100, NULL, NULL, NULL);
+ NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
if (g_file_get_contents (update, &queries, NULL, NULL)) {
gchar *query = strtok (queries, "\n");
@@ -270,7 +272,9 @@ test_ontology_change (void)
delete_db (FALSE);
tracker_data_manager_init (0, (const gchar **) test_schemas,
- NULL, TRUE, 100, 100, NULL, NULL, NULL);
+ NULL, TRUE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
for (i = 0; change_tests[i].test_name != NULL; i++) {
gchar *query_filename;
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index cb0fe13..8910465 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -172,6 +172,8 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
static void
test_ontology_init (void)
{
+ GError *error = NULL;
+
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
/* first-time initialization */
@@ -183,7 +185,10 @@ test_ontology_init (void)
100,
NULL,
NULL,
- NULL);
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
tracker_data_manager_shutdown ();
@@ -198,7 +203,10 @@ test_ontology_init (void)
100,
NULL,
NULL,
- NULL);
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
tracker_data_manager_shutdown ();
}
@@ -233,6 +241,7 @@ test_query (gconstpointer test_data)
100,
NULL,
NULL,
+ NULL,
NULL);
/* load data set */
diff --git a/tests/libtracker-data/tracker-sparql-blank-test.c b/tests/libtracker-data/tracker-sparql-blank-test.c
index afbd5ea..c20f8a7 100644
--- a/tests/libtracker-data/tracker-sparql-blank-test.c
+++ b/tests/libtracker-data/tracker-sparql-blank-test.c
@@ -50,7 +50,10 @@ test_blank (void)
100,
NULL,
NULL,
- NULL);
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
/* perform update in transaction */
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index d97ed96..bd0933c 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -235,7 +235,9 @@ test_sparql_query (gconstpointer test_data)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
test_schemas,
- NULL, FALSE, 100, 100, NULL, NULL, NULL);
+ NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
/* data_path = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL); */
diff --git a/tests/libtracker-fts/tracker-fts-test.c b/tests/libtracker-fts/tracker-fts-test.c
index b7eefee..a54e45a 100644
--- a/tests/libtracker-fts/tracker-fts-test.c
+++ b/tests/libtracker-fts/tracker-fts-test.c
@@ -74,7 +74,9 @@ test_sparql_query (gconstpointer test_data)
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
test_schemas,
- NULL, FALSE, 100, 100, NULL, NULL, NULL);
+ NULL, FALSE, 100, 100, NULL, NULL, NULL, &error);
+
+ g_assert_no_error (error);
/* load data / perform updates */
diff --git a/utils/tracker-sql/tracker-sql.c b/utils/tracker-sql/tracker-sql.c
index fb89e6b..f7c0dee 100644
--- a/utils/tracker-sql/tracker-sql.c
+++ b/utils/tracker-sql/tracker-sql.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2010, Nokia
*
@@ -132,16 +131,19 @@ main (int argc, char **argv)
gint n_rows = 0;
if (!tracker_data_manager_init (0,
- NULL,
- &first_time,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL)) {
- g_printerr ("%s\n",
- _("Failed to initialize data manager"));
+ NULL,
+ &first_time,
+ FALSE,
+ 100,
+ 100,
+ NULL,
+ NULL,
+ NULL,
+ &error)) {
+ g_printerr ("%s: %s\n",
+ _("Failed to initialize data manager"),
+ error->message);
+ g_error_free (error);
return EXIT_FAILURE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]