[tracker/merge: 5/5] tracker-miner-fs: Do not delete metadata from other sources on update



commit 966ff5c076b00ae3e1120fa9645444ef171a612b
Author: Jürg Billeter <j bitron ch>
Date:   Wed Jun 9 14:59:00 2010 +0200

    tracker-miner-fs: Do not delete metadata from other sources on update
    
    When a file is updated, only delete statements that have been inserted
    by the miner instead of relying on the inflexible tracker:isAnnotation.
    
    Fixes NB#173164.

 src/libtracker-client/tracker-sparql-builder.vala |   10 ++++++++++
 src/libtracker-miner/tracker-miner-fs.c           |   12 ++++++++++--
 src/libtracker-miner/tracker-miner-fs.h           |    2 ++
 src/miners/fs/tracker-miner-applications.c        |    8 ++++----
 src/miners/fs/tracker-miner-files.c               |    4 ++--
 5 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-client/tracker-sparql-builder.vala b/src/libtracker-client/tracker-sparql-builder.vala
index 60c3aab..b5fa989 100644
--- a/src/libtracker-client/tracker-sparql-builder.vala
+++ b/src/libtracker-client/tracker-sparql-builder.vala
@@ -72,6 +72,16 @@ public class Tracker.SparqlBuilder : Object {
 			str.append ("INSERT {\n");
 	}
 
+	public void insert_silent_open (string? graph)
+		requires (state == State.UPDATE)
+	{
+		states += State.INSERT;
+		if (graph != null)
+			str.append ("INSERT SILENT INTO <%s> {\n".printf (graph));
+		else
+			str.append ("INSERT SILENT {\n");
+	}
+
 	public void insert_close ()
 		requires (state == State.INSERT || state == State.OBJECT)
 	{
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 9269f1f..88403a6 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1362,8 +1362,16 @@ item_add_or_update_cb (TrackerMinerFS *fs,
 
 		g_debug ("Adding item '%s'", uri);
 
-		full_sparql = g_strdup_printf ("DROP GRAPH <%s> %s",
-		                               uri, tracker_sparql_builder_get_result (data->builder));
+		if (data->urn) {
+			/* update, delete all statements inserted by miner
+			   except for rdf:type statements as they could cause implicit deletion of user data */
+			full_sparql = g_strdup_printf ("DELETE { <%s> ?p ?o } WHERE { GRAPH <%s> { <%s> ?p ?o FILTER (?p != rdf:type) } } %s",
+			                               data->urn, TRACKER_MINER_FS_GRAPH_URN,
+			                               data->urn, tracker_sparql_builder_get_result (data->builder));
+		} else {
+			/* new file */
+			full_sparql = g_strdup (tracker_sparql_builder_get_result (data->builder));
+		}
 
 		tracker_miner_execute_batch_update (TRACKER_MINER (fs),
 		                                    full_sparql,
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 5105e1e..7eda517 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -33,6 +33,8 @@
 
 G_BEGIN_DECLS
 
+#define TRACKER_MINER_FS_GRAPH_URN "urn:uuid:472ed0cc-40ff-4e37-9c0c-062d78656540"
+
 #define TRACKER_TYPE_MINER_FS         (tracker_miner_fs_get_type())
 #define TRACKER_MINER_FS(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_FS, TrackerMinerFS))
 #define TRACKER_MINER_FS_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_MINER_FS, TrackerMinerFSClass))
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index 1e4b694..62f1bd7 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -254,7 +254,7 @@ miner_applications_process_file_cb (gpointer user_data)
 		gchar *icon = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Icon", NULL);
 
 		uri = canonical_uri;
-		tracker_sparql_builder_insert_open (sparql, uri);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 		tracker_sparql_builder_subject_iri (sparql, uri);
 
 		tracker_sparql_builder_predicate (sparql, "a");
@@ -284,7 +284,7 @@ miner_applications_process_file_cb (gpointer user_data)
 
 	} else if (name && g_ascii_strcasecmp (type, "Application") == 0) {
 		uri = g_file_get_uri (data->file);
-		tracker_sparql_builder_insert_open (sparql, uri);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
 		tracker_sparql_builder_subject_iri (sparql, APPLICATION_DATASOURCE_URN);
 		tracker_sparql_builder_predicate (sparql, "a");
@@ -303,7 +303,7 @@ miner_applications_process_file_cb (gpointer user_data)
 	} else if (name && g_str_has_suffix (type, "Applet")) {
 		/* The URI of the InformationElement should be a UUID URN */
 		uri = g_file_get_uri (data->file);
-		tracker_sparql_builder_insert_open (sparql, uri);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
 		tracker_sparql_builder_subject_iri (sparql, APPLET_DATASOURCE_URN);
 		tracker_sparql_builder_predicate (sparql, "a");
@@ -320,7 +320,7 @@ miner_applications_process_file_cb (gpointer user_data)
 	} else {
 		/* Invalid type, all valid types are already listed above */
 		uri = g_file_get_uri (data->file);
-		tracker_sparql_builder_insert_open (sparql, uri);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
 		tracker_sparql_builder_subject_iri (sparql, APPLICATION_DATASOURCE_URN);
 		tracker_sparql_builder_predicate (sparql, "a");
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index a65202d..4f09b55 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1607,7 +1607,7 @@ process_file_cb (GObject      *object,
 	mime_type = g_file_info_get_content_type (file_info);
 	urn = miner_files_get_file_urn (TRACKER_MINER_FILES (data->miner), file, &is_iri);
 
-	tracker_sparql_builder_insert_open (sparql, uri);
+	tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
 	if (is_iri) {
 		tracker_sparql_builder_subject_iri (sparql, urn);
@@ -1738,7 +1738,7 @@ miner_files_ignore_next_update_file (TrackerMinerFS       *fs,
 	 * should NEVER be marked as tracker:writeback in the ontology! (else you break
 	 * the tracker-writeback feature) */
 
-	tracker_sparql_builder_insert_open (sparql, uri);
+	tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
 	tracker_sparql_builder_subject_variable (sparql, "urn");
 	tracker_sparql_builder_predicate (sparql, "a");



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