summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbanoub Ghadban <abanoub.gdb@gmail.com>2021-08-05 13:33:47 +0200
committerAbanoub Ghadban <abanoub.gdb@gmail.com>2021-08-10 11:51:15 +0200
commit2b9832714109e0476ee5e662c139316f662fd996 (patch)
tree8a7f43e11f4155d13ccf0c3c0ba7fb4511e4fbd7
parent255123acfafadf5f23c5322264d375ca2ece37b2 (diff)
downloadtracker-2b9832714109e0476ee5e662c139316f662fd996.tar.gz
propagate errors that happen while updating an existing db schema
If an error happens while updating the existing ontologies, all changes that applied on the db schema will be rolled back and an error will propagate to the connection method. The old behavior was showing warnings, applying some changes and discarding other changes.
-rw-r--r--src/libtracker-data/tracker-data-manager.c127
1 files changed, 50 insertions, 77 deletions
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 6d3892b8e..c3645357e 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1819,19 +1819,21 @@ load_ontology_file (TrackerDataManager *manager,
static TrackerOntology*
get_ontology_from_file (TrackerDataManager *manager,
- GFile *file)
+ GFile *file,
+ GError **error)
{
const gchar *subject, *predicate, *object;
TrackerTurtleReader *reader;
- GError *error = NULL;
+ GError *internal_error = NULL;
GHashTable *ontology_uris;
TrackerOntology *ret = NULL;
- reader = tracker_turtle_reader_new_for_file (file, &error);
+ reader = tracker_turtle_reader_new_for_file (file, &internal_error);
- if (error) {
- g_critical ("Turtle parse error: %s", error->message);
- g_error_free (error);
+ if (internal_error) {
+ g_propagate_prefixed_error (error, internal_error,
+ "Turtle parse error: %s",
+ internal_error->message);
return NULL;
}
@@ -1842,7 +1844,7 @@ get_ontology_from_file (TrackerDataManager *manager,
while (tracker_turtle_reader_next (reader,
&subject, &predicate, &object,
- NULL, NULL, &error)) {
+ NULL, NULL, &internal_error)) {
if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
if (g_strcmp0 (object, TRACKER_PREFIX_NRL "Ontology") == 0) {
TrackerOntology *ontology;
@@ -1859,21 +1861,21 @@ get_ontology_from_file (TrackerDataManager *manager,
} else if (g_strcmp0 (predicate, NRL_LAST_MODIFIED) == 0) {
TrackerOntology *ontology;
GDateTime *datetime;
- GError *error = NULL;
+ GError *parsing_error;
ontology = g_hash_table_lookup (ontology_uris, subject);
if (ontology == NULL) {
gchar *uri = g_file_get_uri (file);
g_critical ("%s: Unknown ontology %s", uri, subject);
g_free (uri);
- return NULL;
+ continue;
}
- datetime = tracker_date_new_from_iso8601 (object, NULL);
+ datetime = tracker_date_new_from_iso8601 (object, &parsing_error);
if (!datetime) {
- g_critical ("%s: error parsing nrl:lastModified: %s",
- subject, error->message);
- g_error_free (error);
+ g_propagate_prefixed_error (error, parsing_error,
+ "%s: error parsing nrl:lastModified: %s",
+ subject, parsing_error->message);
return NULL;
}
@@ -1891,15 +1893,19 @@ get_ontology_from_file (TrackerDataManager *manager,
g_hash_table_unref (ontology_uris);
g_object_unref (reader);
- if (error) {
- g_critical ("Turtle parse error: %s", error->message);
- g_error_free (error);
+ if (internal_error) {
+ g_propagate_prefixed_error (error, internal_error,
+ "Turtle parse error: %s",
+ internal_error->message);
+ return NULL;
}
if (ret == NULL) {
gchar *uri = g_file_get_uri (file);
- g_critical ("Ontology file has no nrl:lastModified header: %s", uri);
+ g_propagate_prefixed_error (error, internal_error,
+ "Ontology file has no nrl:lastModified header: %s", uri);
g_free (uri);
+ return NULL;
}
return ret;
@@ -4060,16 +4066,14 @@ tracker_data_manager_initable_init (GInitable *initable,
gint last_mod;
/* Parse a TrackerOntology from ontology_file */
- ontology = get_ontology_from_file (manager, ontology_file);
+ ontology = get_ontology_from_file (manager, ontology_file, &internal_error);
- if (!ontology) {
- /* TODO: cope with full custom .ontology files: deal with this
- * error gracefully. App devs might install wrong ontology files
- * and we shouldn't critical() due to this. */
+ if (internal_error) {
gchar *uri = g_file_get_uri (ontology_file);
- g_critical ("Can't get ontology from file: %s", uri);
+ g_propagate_prefixed_error (error, internal_error,
+ "Can't get ontology from file: %s", uri);
g_free (uri);
- continue;
+ return FALSE;
}
ontology_uri = tracker_ontology_get_uri (ontology);
@@ -4128,34 +4132,17 @@ tracker_data_manager_initable_init (GInitable *initable,
seen_properties,
&ontology_error);
- if (g_error_matches (ontology_error,
- TRACKER_DATA_ONTOLOGY_ERROR,
- TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE)) {
- g_warning ("%s", ontology_error->message);
- g_error_free (ontology_error);
+ if (ontology_error) {
+ g_propagate_error (error, ontology_error);
g_clear_pointer (&seen_classes, g_ptr_array_unref);
g_clear_pointer (&seen_properties, g_ptr_array_unref);
- tracker_data_ontology_import_finished (manager);
-
- /* as we're processing an ontology change,
- transaction is guaranteed to be started */
- tracker_data_rollback_transaction (manager->data_update);
- if (ontos_table) {
- g_hash_table_unref (ontos_table);
- }
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
- g_object_unref (manager->ontology_location);
-
- goto skip_ontology_check;
- }
-
- if (ontology_error) {
- g_critical ("Fatal error dealing with ontology changes: %s", ontology_error->message);
- g_error_free (ontology_error);
+
+ goto rollback_db_changes;
}
to_reload = g_list_prepend (to_reload, l->data);
@@ -4185,28 +4172,17 @@ tracker_data_manager_initable_init (GInitable *initable,
seen_properties,
&ontology_error);
- if (g_error_matches (ontology_error,
- TRACKER_DATA_ONTOLOGY_ERROR,
- TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE)) {
- g_warning ("%s", ontology_error->message);
- g_error_free (ontology_error);
+ if (ontology_error) {
+ g_propagate_error (error, ontology_error);
g_clear_pointer (&seen_classes, g_ptr_array_unref);
g_clear_pointer (&seen_properties, g_ptr_array_unref);
- tracker_data_ontology_import_finished (manager);
-
- /* as we're processing an ontology change,
- transaction is guaranteed to be started */
- tracker_data_rollback_transaction (manager->data_update);
- if (ontos_table) {
- g_hash_table_unref (ontos_table);
- }
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
-
- goto skip_ontology_check;
+
+ goto rollback_db_changes;
}
if (ontology_error) {
@@ -4303,28 +4279,17 @@ tracker_data_manager_initable_init (GInitable *initable,
}
}
- if (g_error_matches (ontology_error,
- TRACKER_DATA_ONTOLOGY_ERROR,
- TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE)) {
- g_warning ("%s", ontology_error->message);
- g_error_free (ontology_error);
+ if (ontology_error) {
+ g_propagate_error (error, ontology_error);
g_clear_pointer (&seen_classes, g_ptr_array_unref);
g_clear_pointer (&seen_properties, g_ptr_array_unref);
- tracker_data_ontology_import_finished (manager);
-
- /* as we're processing an ontology change,
- transaction is guaranteed to be started */
- tracker_data_rollback_transaction (manager->data_update);
- if (ontos_table) {
- g_hash_table_unref (ontos_table);
- }
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
-
- goto skip_ontology_check;
+
+ goto rollback_db_changes;
}
if (ontology_error) {
@@ -4363,8 +4328,6 @@ tracker_data_manager_initable_init (GInitable *initable,
}
-
-skip_ontology_check:
if (!read_only && is_create) {
tracker_db_manager_set_current_locale (manager->db_manager);
tracker_db_manager_tokenizer_update (manager->db_manager);
@@ -4400,6 +4363,16 @@ skip_ontology_check:
return TRUE;
+rollback_db_changes:
+ tracker_data_ontology_import_finished (manager);
+ tracker_data_rollback_transaction (manager->data_update);
+
+ if (ontos_table) {
+ g_hash_table_unref (ontos_table);
+ }
+
+ return FALSE;
+
rollback_newly_created_db:
tracker_data_rollback_transaction (manager->data_update);
tracker_db_manager_rollback_db_creation (manager->db_manager, NULL);