[tracker] libtracker-miner: Keep a monitor on root index tree files on deletion
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-miner: Keep a monitor on root index tree files on deletion
- Date: Mon, 6 Jul 2015 08:42:54 +0000 (UTC)
commit 0ca8361f1627a036684277f5a07d7cca33554af4
Author: Philip Withnall <philip withnall collabora co uk>
Date: Thu Jun 4 13:01:11 2015 +0100
libtracker-miner: Keep a monitor on root index tree files on deletion
If Tracker is running with some index-recursive-directories set (for
example, ~/Music), and one of those directories is moved, then the file
monitor watching for its existence is deleted. This means that if it is
then moved back to the location listed in index-recursive-directories,
its renewed existence is not detected, and its contents are not
re-indexed.
Fix this by keeping a monitor around on a directory if that directory is
listed as an index tree root, even if the directory is deleted.
https://bugzilla.gnome.org/show_bug.cgi?id=750394
src/libtracker-miner/tracker-file-notifier.c | 9 +++++
src/libtracker-miner/tracker-monitor.c | 46 +++++++++++++++++++------
src/libtracker-miner/tracker-monitor.h | 2 +
3 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 5abe9d3..088b982 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1079,6 +1079,15 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
+ /* Remove monitors if any */
+ if (is_directory &&
+ tracker_indexing_tree_file_is_root (priv->indexing_tree, file)) {
+ tracker_monitor_remove_children_recursively (priv->monitor,
+ file);
+ } else if (is_directory) {
+ tracker_monitor_remove_recursively (priv->monitor, file);
+ }
+
if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) {
/* File was not indexed */
diff --git a/src/libtracker-miner/tracker-monitor.c b/src/libtracker-miner/tracker-monitor.c
index b0a47cf..a0fdba7 100644
--- a/src/libtracker-miner/tracker-monitor.c
+++ b/src/libtracker-miner/tracker-monitor.c
@@ -712,11 +712,6 @@ emit_signal_for_event (TrackerMonitor *monitor,
g_debug ("Emitting ITEM_DELETED for (%s) '%s'",
event_data->is_directory ? "DIRECTORY" : "FILE",
event_data->file_uri);
- /* Remove monitors recursively */
- if (event_data->is_directory) {
- tracker_monitor_remove_recursively (monitor,
- event_data->file);
- }
g_signal_emit (monitor,
signals[ITEM_DELETED], 0,
event_data->file,
@@ -1594,9 +1589,22 @@ tracker_monitor_remove (TrackerMonitor *monitor,
return removed;
}
-gboolean
-tracker_monitor_remove_recursively (TrackerMonitor *monitor,
- GFile *file)
+/* If @is_strict is %TRUE, return %TRUE iff @file is a child of @prefix.
+ * If @is_strict is %FALSE, additionally return %TRUE if @file equals @prefix.
+ */
+static gboolean
+file_has_maybe_strict_prefix (GFile *file,
+ GFile *prefix,
+ gboolean is_strict)
+{
+ return (g_file_has_prefix (file, prefix) ||
+ (!is_strict && g_file_equal (file, prefix)));
+}
+
+static gboolean
+remove_recursively (TrackerMonitor *monitor,
+ GFile *file,
+ gboolean remove_top_level)
{
GHashTableIter iter;
gpointer iter_file, iter_file_monitor;
@@ -1608,8 +1616,8 @@ tracker_monitor_remove_recursively (TrackerMonitor *monitor,
g_hash_table_iter_init (&iter, monitor->priv->monitors);
while (g_hash_table_iter_next (&iter, &iter_file, &iter_file_monitor)) {
- if (!g_file_has_prefix (iter_file, file) &&
- !g_file_equal (iter_file, file)) {
+ if (!file_has_maybe_strict_prefix (iter_file, file,
+ !remove_top_level)) {
continue;
}
@@ -1618,7 +1626,9 @@ tracker_monitor_remove_recursively (TrackerMonitor *monitor,
}
uri = g_file_get_uri (file);
- g_debug ("Removed all monitors recursively for path:'%s', total monitors:%d",
+ g_debug ("Removed all monitors %srecursively for path:'%s', "
+ "total monitors:%d",
+ !remove_top_level ? "(except top level) " : "",
uri, g_hash_table_size (monitor->priv->monitors));
g_free (uri);
@@ -1631,6 +1641,20 @@ tracker_monitor_remove_recursively (TrackerMonitor *monitor,
return FALSE;
}
+gboolean
+tracker_monitor_remove_recursively (TrackerMonitor *monitor,
+ GFile *file)
+{
+ return remove_recursively (monitor, file, TRUE);
+}
+
+gboolean
+tracker_monitor_remove_children_recursively (TrackerMonitor *monitor,
+ GFile *file)
+{
+ return remove_recursively (monitor, file, FALSE);
+}
+
static gboolean
monitor_cancel_recursively (TrackerMonitor *monitor,
GFile *file)
diff --git a/src/libtracker-miner/tracker-monitor.h b/src/libtracker-miner/tracker-monitor.h
index 132a530..5673ba0 100644
--- a/src/libtracker-miner/tracker-monitor.h
+++ b/src/libtracker-miner/tracker-monitor.h
@@ -66,6 +66,8 @@ gboolean tracker_monitor_remove (TrackerMonitor *monitor,
GFile *file);
gboolean tracker_monitor_remove_recursively (TrackerMonitor *monitor,
GFile *file);
+gboolean tracker_monitor_remove_children_recursively (TrackerMonitor *monitor,
+ GFile *file);
gboolean tracker_monitor_move (TrackerMonitor *monitor,
GFile *old_file,
GFile *new_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]