[tracker-miners/wip/carlosg/timeouts-and-stuff: 3/4] libtracker-miner: Handle race conditions between crawler/monitor better



commit 2aa4f81932275562d63b5555d12c244330289961
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 2 16:46:56 2020 +0200

    libtracker-miner: Handle race conditions between crawler/monitor better
    
    At the time of monitoring a folder, we first crawl its contents and then
    add a monitor. This has a brief window in which a file might be added at
    the right time that crawling is too late, but the monitor wasn't added
    yet.
    
    Invert the order here, so we first set up the monitor and then crawl the
    file. There is still a race condition in that the file might be now
    reported twice (once via crawling, once caught by the monitor). Those
    should be already coalesced by the upper layers, so it is preferable to
    have the race condition on this side.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/110

 src/libtracker-miner/tracker-file-notifier.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 5fd0dd0ae..415ef0e78 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -252,22 +252,9 @@ crawler_check_directory_contents_cb (TrackerCrawler *crawler,
                                                                     parent, children);
        }
 
-       if (process) {
-               TrackerDirectoryFlags parent_flags;
-               gboolean add_monitor;
-
-               tracker_indexing_tree_get_root (priv->indexing_tree,
-                                               parent, &parent_flags);
-
-               add_monitor = (parent_flags & TRACKER_DIRECTORY_FLAG_MONITOR) != 0;
-
-               if (add_monitor) {
-                       tracker_monitor_add (priv->monitor, parent);
-               } else {
-                       tracker_monitor_remove (priv->monitor, parent);
-               }
-       } else {
+       if (!process) {
                priv->current_index_root->current_dir_content_filtered = TRUE;
+               tracker_monitor_remove (priv->monitor, parent);
        }
 
        return process;
@@ -529,9 +516,17 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
                return FALSE;
 
        while (!g_queue_is_empty (priv->current_index_root->pending_dirs)) {
+               TrackerDirectoryFlags flags;
+
                directory = g_queue_pop_head (priv->current_index_root->pending_dirs);
                priv->current_index_root->current_dir = directory;
 
+               tracker_indexing_tree_get_root (priv->indexing_tree,
+                                               directory, &flags);
+
+               if ((flags & TRACKER_DIRECTORY_FLAG_MONITOR) != 0)
+                       tracker_monitor_add (priv->monitor, directory);
+
                /* Begin crawling the directory non-recursively.
                 *
                 *  - We receive ::check-file, ::check-directory and ::check-directory-contents signals
@@ -548,6 +543,7 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
                        return TRUE;
                }
 
+               tracker_monitor_remove (priv->monitor, directory);
                g_object_unref (directory);
        }
 


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