[tracker] libtracker-miner: Fixes NB#161449, on overwrite the original resource must be deleted



commit cb0c4c59e60294a455be8f4263dc1fafdc27527c
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Jun 8 19:36:59 2010 +0200

    libtracker-miner: Fixes NB#161449, on overwrite the original resource must be deleted

 src/libtracker-miner/tracker-miner-fs.c |   33 ++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 141b27a..a585565 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -64,6 +64,7 @@ typedef struct {
 	gchar *parent_urn;
 	GCancellable *cancellable;
 	TrackerSparqlBuilder *builder;
+	gboolean update;
 } ProcessData;
 
 typedef struct {
@@ -561,10 +562,11 @@ tracker_miner_fs_init (TrackerMinerFS *object)
 
 static ProcessData *
 process_data_new (GFile                *file,
-		  const gchar          *urn,
-		  const gchar          *parent_urn,
+                  const gchar          *urn,
+                  const gchar          *parent_urn,
                   GCancellable         *cancellable,
-                  TrackerSparqlBuilder *builder)
+                  TrackerSparqlBuilder *builder,
+                  gboolean              update)
 {
 	ProcessData *data;
 
@@ -572,6 +574,7 @@ process_data_new (GFile                *file,
 	data->file = g_object_ref (file);
 	data->urn = g_strdup (urn);
 	data->parent_urn = g_strdup (parent_urn);
+	data->update = update;
 
 	if (cancellable) {
 		data->cancellable = g_object_ref (cancellable);
@@ -1361,8 +1364,13 @@ 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->update) {
+			full_sparql = g_strdup_printf ("DELETE { ?res a rdfs:Resource } WHERE { ?res nie:url \"%s\" } %s",
+			                               uri, tracker_sparql_builder_get_result (data->builder));
+		} else {
+			full_sparql = g_strdup_printf ("DROP GRAPH <%s> %s",
+			                               uri, tracker_sparql_builder_get_result (data->builder));
+		}
 
 		tracker_miner_execute_batch_update (TRACKER_MINER (fs),
 		                                    full_sparql,
@@ -1377,7 +1385,8 @@ item_add_or_update_cb (TrackerMinerFS *fs,
 
 static gboolean
 item_add_or_update (TrackerMinerFS *fs,
-                    GFile          *file)
+                    GFile          *file,
+                    gboolean        update)
 {
 	TrackerMinerFSPrivate *priv;
 	TrackerSparqlBuilder *sparql;
@@ -1426,7 +1435,7 @@ item_add_or_update (TrackerMinerFS *fs,
 
 	urn = iri_cache_lookup (fs, file);
 
-	data = process_data_new (file, urn, parent_urn, cancellable, sparql);
+	data = process_data_new (file, urn, parent_urn, cancellable, sparql, update);
 	priv->processing_pool = g_list_prepend (priv->processing_pool, data);
 
 	if (do_process_file (fs, data)) {
@@ -1495,7 +1504,7 @@ item_remove (TrackerMinerFS *fs,
 	                        "}",
 	                        uri);
 
-	data = process_data_new (file, NULL, NULL, NULL, NULL);
+	data = process_data_new (file, NULL, NULL, NULL, NULL, FALSE);
 	fs->private->processing_pool = g_list_prepend (fs->private->processing_pool, data);
 
 	tracker_miner_execute_batch_update (TRACKER_MINER (fs),
@@ -1740,7 +1749,7 @@ item_move (TrackerMinerFS *fs,
 			tracker_miner_fs_directory_add_internal (fs, file);
 			retval = TRUE;
 		} else {
-			retval = item_add_or_update (fs, file);
+			retval = item_add_or_update (fs, file, FALSE);
 		}
 
 		g_free (source_uri);
@@ -1805,7 +1814,7 @@ item_move (TrackerMinerFS *fs,
 
 	g_main_loop_unref (move_data.main_loop);
 
-	data = process_data_new (file, NULL, NULL, NULL, NULL);
+	data = process_data_new (file, NULL, NULL, NULL, NULL, FALSE);
 	fs->private->processing_pool = g_list_prepend (fs->private->processing_pool, data);
 
 	tracker_miner_execute_batch_update (TRACKER_MINER (fs),
@@ -2144,8 +2153,10 @@ item_queue_handlers_cb (gpointer user_data)
 		keep_processing = item_remove (fs, file);
 		break;
 	case QUEUE_CREATED:
+		keep_processing = item_add_or_update (fs, file, FALSE);
+		break;
 	case QUEUE_UPDATED:
-		keep_processing = item_add_or_update (fs, file);
+		keep_processing = item_add_or_update (fs, file, TRUE);
 		break;
 	case QUEUE_IGNORE_NEXT_UPDATE:
 		keep_processing = item_ignore_next_update (fs, file, source_file);



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