Commit ee3f0700 authored by Carlos Garnacho's avatar Carlos Garnacho

miners: Take over the deletion of previous properties from TrackerMinerFS

Performing the deletion inside libtracker-miner takes some assumptions we
shouldn't be doing in a generic library, such as the graph we're deleting
from. It makes more sense to make miners responsible of deleting their
older properties prior to a file update.

Applications/user guides miners could be more specific as to which
properties they're deleting, we'll rely on those not stepping over other
miners' toes at the moment.

https://bugzilla.gnome.org/show_bug.cgi?id=758341
parent 2f13932b
......@@ -1373,55 +1373,19 @@ item_add_or_update_continue (TrackerMinerFS *fs,
if (ctxt->urn) {
gboolean attribute_update_only;
/* The SPARQL builder will already contain the necessary
* DELETE statements for the properties being updated */
attribute_update_only = GPOINTER_TO_INT (g_object_steal_qdata (G_OBJECT (file), fs->priv->quark_attribute_updated));
g_debug ("Updating item '%s' with urn '%s'%s",
uri,
ctxt->urn,
attribute_update_only ? " (attributes only)" : "");
if (!attribute_update_only) {
gchar *full_sparql;
/* Update, delete all statements inserted by miner except:
* - rdf:type statements as they could cause implicit deletion of user data
* - nie:contentCreated so it persists across updates
*
* Additionally, delete also nie:url as it might have been set by 3rd parties,
* and it's used to know whether a file is known to tracker or not.
*/
full_sparql = g_strdup_printf ("DELETE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" } "
"} "
"WHERE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" FILTER (?p != rdf:type && ?p != nie:contentCreated)"
" } "
"} "
"DELETE {"
" <%s> nie:url ?o"
"} WHERE {"
" <%s> nie:url ?o"
"}"
"%s",
TRACKER_OWN_GRAPH_URN, ctxt->urn,
TRACKER_OWN_GRAPH_URN, ctxt->urn,
ctxt->urn, ctxt->urn,
tracker_sparql_builder_get_result (ctxt->builder));
sparql_task = tracker_sparql_task_new_take_sparql_str (file, full_sparql);
} else {
/* Do not drop graph if only updating attributes, the SPARQL builder
* will already contain the necessary DELETE statements for the properties
* being updated */
sparql_task = tracker_sparql_task_new_with_sparql (file, ctxt->builder);
}
} else {
g_debug ("Creating new item '%s'", uri);
sparql_task = tracker_sparql_task_new_with_sparql (file, ctxt->builder);
}
sparql_task = tracker_sparql_task_new_with_sparql (file, ctxt->builder);
}
if (sparql_task) {
......
......@@ -741,7 +741,8 @@ process_desktop_file (ProcessApplicationData *data,
}
}
if (sparql && uri) {
if (uri) {
gchar *delete_properties_sparql;
gchar *desktop_file_uri;
tracker_sparql_builder_predicate (sparql, "a");
......@@ -864,6 +865,33 @@ process_desktop_file (ProcessApplicationData *data,
g_free (desktop_file_uri);
/* Prepend a delete statement to delete previous properties from
* the miner, if any.
*/
delete_properties_sparql =
g_strdup_printf ("DELETE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" } "
"} "
"WHERE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" FILTER (?p != rdf:type && ?p != nie:contentCreated)"
" } "
"} "
"DELETE {"
" <%s> nie:url ?o"
"} WHERE {"
" <%s> nie:url ?o"
"}",
TRACKER_OWN_GRAPH_URN, uri,
TRACKER_OWN_GRAPH_URN, uri,
uri, uri);
tracker_sparql_builder_prepend (sparql, delete_properties_sparql);
g_free (delete_properties_sparql);
}
if (file_info) {
......
......@@ -2136,6 +2136,41 @@ process_file_cb (GObject *object,
data->mime_type = g_strdup (mime_type);
if (is_iri) {
gchar *delete_properties_sparql;
/* Update: delete all statements inserted by miner except:
* - rdf:type statements as they could cause implicit deletion of user data
* - nie:contentCreated so it persists across updates
*
* Additionally, delete also nie:url as it might have been set by 3rd parties,
* and it's used to know whether a file is known to tracker or not.
*/
delete_properties_sparql =
g_strdup_printf ("DELETE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" } "
"} "
"WHERE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" FILTER (?p != rdf:type && ?p != nie:contentCreated)"
" } "
"} "
"DELETE {"
" <%s> nie:url ?o"
"} WHERE {"
" <%s> nie:url ?o"
"}",
TRACKER_OWN_GRAPH_URN, urn,
TRACKER_OWN_GRAPH_URN, urn,
urn, urn);
tracker_sparql_builder_prepend (sparql, delete_properties_sparql);
g_free (delete_properties_sparql);
}
tracker_sparql_builder_insert_silent_open (sparql, NULL);
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
......
......@@ -437,7 +437,33 @@ process_item (ProcessUserguideData *data,
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
if (is_iri) {
gchar *delete_properties_sparql;
delete_properties_sparql =
g_strdup_printf ("DELETE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" } "
"} "
"WHERE {"
" GRAPH <%s> {"
" <%s> ?p ?o"
" FILTER (?p != rdf:type && ?p != nie:contentCreated)"
" } "
"} "
"DELETE {"
" <%s> nie:url ?o"
"} WHERE {"
" <%s> nie:url ?o"
"}",
TRACKER_OWN_GRAPH_URN, urn,
TRACKER_OWN_GRAPH_URN, urn,
urn, urn);
tracker_sparql_builder_prepend (sparql, delete_properties_sparql);
tracker_sparql_builder_subject_iri (sparql, urn);
g_free (delete_properties_sparql);
} else {
tracker_sparql_builder_subject (sparql, urn);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment