[tracker/libtracker-miner] TrackerMinerFS: Remove directory and children from all processing queues.



commit ed09b923c318f2011502ff721da294fba7f768fc
Author: Carlos Garnacho <carlos lanedo com>
Date:   Mon Aug 31 14:35:46 2009 +0200

    TrackerMinerFS: Remove directory and children from all processing queues.
    
    Now tracker_miner_fs_remove_directory() also removes any child from processing
    queues, and cancels the ongoing process_file() call if necessary.

 src/libtracker-miner/tracker-miner-fs.c |   49 +++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 3324537..13b61fe 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -60,6 +60,7 @@ struct TrackerMinerFSPrivate {
 	guint           crawl_directories_id;
 	guint		item_queues_handler_id;
 
+	GFile          *current_file;
 	GCancellable   *cancellable;
 
 	/* Status */
@@ -478,6 +479,11 @@ item_add_or_update_cb (TrackerMinerFS       *fs,
 		fs->private->cancellable = NULL;
 	}
 
+	if (fs->private->current_file) {
+		g_object_unref (fs->private->current_file);
+		fs->private->current_file = NULL;
+	}
+
 	g_object_unref (sparql);
 	g_free (uri);
 
@@ -508,6 +514,8 @@ item_add_or_update (TrackerMinerFS *fs,
 	if (!processing) {
 		g_object_unref (sparql);
 		return TRUE;
+	} else {
+		fs->private->current_file = g_object_ref (file);
 	}
 
 	return FALSE;
@@ -1361,16 +1369,41 @@ tracker_miner_fs_add_directory (TrackerMinerFS *fs,
 	crawl_directories_start (fs);
 }
 
+static void
+check_files_removal (GQueue *queue,
+		     GFile  *parent)
+{
+	GList *l;
+
+	l = queue->head;
+
+	while (l) {
+		GFile *file = l->data;
+		GList *link = l;
+
+		l = l->next;
+
+		if (g_file_equal (file, parent) ||
+		    g_file_has_prefix (file, parent)) {
+			g_queue_delete_link (queue, link);
+			g_object_unref (file);
+		}
+	}
+}
+
 gboolean
 tracker_miner_fs_remove_directory (TrackerMinerFS *fs,
 				   GFile          *file)
 {
+	TrackerMinerFSPrivate *priv;
 	gboolean return_val = FALSE;
 	GList *dirs;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), FALSE);
 	g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
+	priv = fs->private;
+
 	if (fs->private->current_directory) {
 		GFile *current_file;
 
@@ -1400,5 +1433,21 @@ tracker_miner_fs_remove_directory (TrackerMinerFS *fs,
 		}
 	}
 
+	/* Remove anything contained in the removed directory
+	 * from all relevant processing queues.
+	 */
+	check_files_removal (priv->items_updated, file);
+	check_files_removal (priv->items_created, file);
+
+	if (priv->current_file &&
+	    priv->cancellable &&
+	    (g_file_equal (priv->current_file, file) ||
+	     g_file_has_prefix (priv->current_file, file))) {
+		/* Cancel processing if currently processed file is
+		 * inside the removed directory.
+		 */
+		g_cancellable_cancel (priv->cancellable);
+	}
+
 	return return_val;
 }



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