[tracker/wip/carlosg/data-update-error-propagation: 10/11] libtracker-data: Propagate errors from tracker_data_query_rdf_type()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/data-update-error-propagation: 10/11] libtracker-data: Propagate errors from tracker_data_query_rdf_type()
- Date: Sun, 21 Feb 2021 19:31:58 +0000 (UTC)
commit a73e11c34c5b4d98bfe1195c76a47fe1c57a63c5
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Feb 21 19:30:24 2021 +0100
libtracker-data: Propagate errors from tracker_data_query_rdf_type()
Propagate any errors that might happen in this function.
src/libtracker-data/tracker-data-query.c | 29 ++++++++++++++---------------
src/libtracker-data/tracker-data-query.h | 7 ++++---
src/libtracker-data/tracker-data-update.c | 22 +++++++++++++++++-----
3 files changed, 35 insertions(+), 23 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 7ff062f58..38c8ec96f 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -34,21 +34,22 @@
#include "tracker-sparql.h"
GPtrArray*
-tracker_data_query_rdf_type (TrackerDataManager *manager,
- const gchar *graph,
- gint id)
+tracker_data_query_rdf_type (TrackerDataManager *manager,
+ const gchar *graph,
+ gint id,
+ GError **error)
{
TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
GPtrArray *ret = NULL;
- GError *error = NULL;
+ GError *inner_error = NULL;
TrackerOntologies *ontologies;
iface = tracker_data_manager_get_writable_db_interface (manager);
ontologies = tracker_data_manager_get_ontologies (manager);
- stmt = tracker_db_interface_create_vstatement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
+ stmt = tracker_db_interface_create_vstatement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&inner_error,
"SELECT (SELECT Uri FROM Resource WHERE ID =
\"rdf:type\") "
"FROM \"%s\".\"rdfs:Resource_rdf:type\" "
"WHERE ID = ?",
@@ -56,7 +57,7 @@ tracker_data_query_rdf_type (TrackerDataManager *manager,
if (stmt) {
tracker_db_statement_bind_int (stmt, 0, id);
- cursor = tracker_db_statement_start_cursor (stmt, &error);
+ cursor = tracker_db_statement_start_cursor (stmt, &inner_error);
g_object_unref (stmt);
}
@@ -67,7 +68,7 @@ tracker_data_query_rdf_type (TrackerDataManager *manager,
* function is called fairly often) */
ret = g_ptr_array_sized_new (20);
- while (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL, &inner_error)) {
const gchar *class_uri;
TrackerClass *cl;
@@ -82,14 +83,12 @@ tracker_data_query_rdf_type (TrackerDataManager *manager,
g_object_unref (cursor);
}
- if (G_UNLIKELY (error)) {
- g_critical ("Could not query RDF type: %s\n", error->message);
- g_error_free (error);
-
- if (ret) {
- g_ptr_array_free (ret, FALSE);
- ret = NULL;
- }
+ if (G_UNLIKELY (inner_error)) {
+ g_propagate_prefixed_error (error,
+ inner_error,
+ "Querying RDF type:");
+ g_clear_pointer (&ret, g_ptr_array_unref);
+ return NULL;
}
return ret;
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index 928483169..8321843cc 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -44,9 +44,10 @@ TrackerDBCursor *tracker_data_query_sparql_cursor (TrackerDataManager *mana
const gchar *query,
GError **error);
-GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *manager,
- const gchar *graph,
- gint id);
+GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *manager,
+ const gchar *graph,
+ gint id,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 1796bcc86..a5900ee7e 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2307,6 +2307,8 @@ resource_buffer_switch (TrackerData *data,
TrackerDataUpdateBufferResource *resource_buffer;
gchar *subject_dup;
gint resource_id;
+ gboolean create;
+ GPtrArray *rdf_types;
/* subject not yet in cache, retrieve or create ID */
resource_id =
@@ -2317,20 +2319,30 @@ resource_buffer_switch (TrackerData *data,
if (resource_id == 0)
return FALSE;
+ create = g_hash_table_contains (data->update_buffer.new_resources,
+ subject);
+ if (!create) {
+ rdf_types = tracker_data_query_rdf_type (data->manager,
+ graph,
+ resource_id,
+ &inner_error);
+ if (!rdf_types) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
+ }
+
resource_buffer = g_slice_new0 (TrackerDataUpdateBufferResource);
resource_buffer->id = resource_id;
subject_dup = g_strdup (subject);
resource_buffer->subject = subject_dup;
-
- resource_buffer->create =
- g_hash_table_contains (data->update_buffer.new_resources,
- resource_buffer->subject);
+ resource_buffer->create = create;
resource_buffer->fts_updated = FALSE;
if (resource_buffer->create) {
resource_buffer->types = g_ptr_array_new ();
} else {
- resource_buffer->types = tracker_data_query_rdf_type (data->manager, graph,
resource_buffer->id);
+ resource_buffer->types = rdf_types;
}
resource_buffer->predicates = g_hash_table_new_full (g_direct_hash, g_direct_equal,
g_object_unref, (GDestroyNotify) g_array_unref);
resource_buffer->tables = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) cache_table_free);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]