[tracker: 15/21] prefix "unsupported inverse functional property change" error with line and column numbers




commit 92eafb5c5f7d2a21df6427f575e8d17437703055
Author: Abanoub Ghadban <abanoub gdb gmail com>
Date:   Thu Aug 19 19:35:36 2021 +0200

    prefix "unsupported inverse functional property change" error with line and column numbers
    
    Note: Tracker doesn't support adding any new inverse functional property, converting normal property to 
inverse functional property or converting inverse functional property into normal property.
    Added a check for any new inverse functional property inside tracker_data_ontology_load_statement().
    Updated the check for any deleted inverse functional property inside 
tracker_data_ontology_process_changes_post_db() to be prefixed by the line and column numbers where the 
property is defined.

 src/libtracker-data/tracker-data-manager.c | 54 ++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 98915b787..2dbc891da 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -684,6 +684,31 @@ check_max_cardinality_change_is_allowed (TrackerDataManager  *manager,
        }
 }
 
+static void
+ensure_inverse_functional_property (TrackerDataManager  *manager,
+                                    const gchar         *property_uri,
+                                    GError             **error)
+{
+       TrackerDBCursor *cursor;
+       gchar *query;
+
+       query = g_strdup_printf ("ASK { <%s> a nrl:InverseFunctionalProperty }", property_uri);
+       cursor = tracker_data_query_sparql_cursor (manager, query, NULL);
+       g_free (query);
+
+       if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL)) {
+               if (!tracker_db_cursor_get_int (cursor, 0)) {
+                       handle_unsupported_ontology_change (manager,
+                                                           NULL, -1, -1,
+                                                           property_uri,
+                                                           "nrl:InverseFunctionalProperty", "-", "-",
+                                                           error);
+               }
+
+               g_object_unref (cursor);
+       }
+}
+
 static void
 fix_indexed_on_db (TrackerDataManager  *manager,
                    const gchar         *database,
@@ -885,6 +910,27 @@ tracker_data_ontology_load_statement (TrackerDataManager  *manager,
                                goto out;
                        }
 
+                       if (in_update) {
+                               GError *err = NULL;
+
+                               if (tracker_property_get_is_new (property)) {
+                                       const gchar* property_uri = tracker_property_get_uri (property);
+
+                                       g_set_error (&err,
+                                                    TRACKER_SPARQL_ERROR,
+                                                    TRACKER_SPARQL_ERROR_UNSUPPORTED,
+                                                    "Unsupported adding the new inverse functional property: 
%s",
+                                                    property_uri);
+                               } else {
+                                       ensure_inverse_functional_property (manager, subject, &err);
+                               }
+
+                               if (err) {
+                                       g_propagate_prefixed_error (error, err, "%s: ", object_location);
+                                       goto out;
+                               }
+                       }
+
                        tracker_property_set_is_inverse_functional_property (property, TRUE);
                } else if (g_strcmp0 (object, TRACKER_PREFIX_NRL "Namespace") == 0) {
                        TrackerNamespace *namespace;
@@ -1767,10 +1813,14 @@ tracker_data_ontology_process_changes_post_db (TrackerDataManager  *manager,
 
                        if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
                                if (tracker_sparql_cursor_get_boolean (cursor, 0) != in_onto) {
+                                       const gchar *ontology_path = tracker_property_get_ontology_path 
(property);
+                                       goffset line_no = tracker_property_get_definition_line_no (property);
+                                       goffset column_no = tracker_property_get_definition_column_no 
(property);
+
                                        handle_unsupported_ontology_change (manager,
                                                                            ontology_path,
-                                                                           -1,
-                                                                           -1,
+                                                                           line_no,
+                                                                           column_no,
                                                                            subject,
                                                                            "nrl:InverseFunctionalProperty", 
"-", "-",
                                                                            &n_error);


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