[tracker-miners/sam/index-file-sync: 6/18] miners/fs: Send file-processed signal when a file is ignored by config



commit 616580a35ff054610a49987d37c9e887ba031437
Author: Sam Thursfield <sam afuera me uk>
Date:   Sat Mar 21 16:39:31 2020 +0100

    miners/fs: Send file-processed signal when a file is ignored by config
    
    Internally, this adds a ::file-ignored-during-crawl to
    TrackerFileNotifier. The miner-fs uses this to emit file-processed
    for files and directories that have been ignored at crawl time.
    
    This allows tools like `tracker index` to inform the user about the
    status of their request to index a file.

 src/libtracker-miner/tracker-file-notifier.c | 37 +++++++++++++++++++++++-----
 src/libtracker-miner/tracker-file-notifier.h |  3 +++
 src/libtracker-miner/tracker-miner-fs.c      | 16 ++++++++++++
 3 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 81dc129b2..58dc35298 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -46,6 +46,7 @@ enum {
        FILE_UPDATED,
        FILE_DELETED,
        FILE_MOVED,
+       FILE_IGNORED_DURING_CRAWL,
        DIRECTORY_STARTED,
        DIRECTORY_FINISHED,
        FINISHED,
@@ -196,12 +197,19 @@ crawler_check_file_cb (TrackerCrawler *crawler,
                        gpointer        user_data)
 {
        TrackerFileNotifierPrivate *priv;
+       gboolean use;
 
        priv = tracker_file_notifier_get_instance_private (user_data);
 
-       return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
-                                                       file,
-                                                       G_FILE_TYPE_REGULAR);
+       use = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
+                                                      file,
+                                                      G_FILE_TYPE_REGULAR);
+
+       if (!use) {
+               g_signal_emit (TRACKER_FILE_NOTIFIER (user_data), signals[FILE_IGNORED_DURING_CRAWL], 0, 
file);
+       }
+
+       return use;
 }
 
 static gboolean
@@ -211,6 +219,7 @@ crawler_check_directory_cb (TrackerCrawler *crawler,
 {
        TrackerFileNotifierPrivate *priv;
        GFile *root, *canonical;
+       gboolean use;
 
        priv = tracker_file_notifier_get_instance_private (user_data);
        g_assert (priv->current_index_root != NULL);
@@ -227,9 +236,15 @@ crawler_check_directory_cb (TrackerCrawler *crawler,
                return FALSE;
        }
 
-       return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
-                                                       directory,
-                                                       G_FILE_TYPE_DIRECTORY);
+       use = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
+                                                      directory,
+                                                      G_FILE_TYPE_DIRECTORY);
+
+       if (!use) {
+               g_signal_emit (TRACKER_FILE_NOTIFIER (user_data), signals[FILE_IGNORED_DURING_CRAWL], 0, 
directory);
+       }
+
+       return use;
 }
 
 static gboolean
@@ -1876,6 +1891,16 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
                              NULL,
                              G_TYPE_NONE,
                              2, G_TYPE_FILE, G_TYPE_FILE);
+       signals[FILE_IGNORED_DURING_CRAWL] =
+               g_signal_new ("file-ignored-during-crawl",
+                             G_TYPE_FROM_CLASS (klass),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (TrackerFileNotifierClass,
+                                              file_ignored_during_crawl),
+                             NULL, NULL,
+                             NULL,
+                             G_TYPE_NONE,
+                             1, G_TYPE_FILE);
        signals[DIRECTORY_STARTED] =
                g_signal_new ("directory-started",
                              G_TYPE_FROM_CLASS (klass),
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index 592dfee2c..4c988660e 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -61,6 +61,9 @@ struct _TrackerFileNotifierClass {
                               GFile               *from,
                               GFile               *to);
 
+       void (* file_ignored_during_crawl)   (TrackerFileNotifier *notifier,
+                                             GFile               *file);
+
        /* Directory notifications */
        void (* directory_started)  (TrackerFileNotifier *notifier,
                                     GFile               *directory);
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 68ac0c036..26145b0cc 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -252,6 +252,9 @@ static void           file_notifier_file_moved            (TrackerFileNotifier
                                                            GFile                *source,
                                                            GFile                *dest,
                                                            gpointer              user_data);
+static void           file_notifier_file_ignored_during_crawl (TrackerFileNotifier  *notifier,
+                                                               GFile                *file,
+                                                               gpointer              user_data);
 static void           file_notifier_directory_started     (TrackerFileNotifier *notifier,
                                                            GFile               *directory,
                                                            gpointer             user_data);
@@ -614,6 +617,9 @@ miner_fs_initable_init (GInitable     *initable,
        g_signal_connect (priv->file_notifier, "file-moved",
                          G_CALLBACK (file_notifier_file_moved),
                          initable);
+       g_signal_connect (priv->file_notifier, "file-ignored-during-crawl",
+                         G_CALLBACK (file_notifier_file_ignored_during_crawl),
+                         initable);
        g_signal_connect (priv->file_notifier, "directory-started",
                          G_CALLBACK (file_notifier_directory_started),
                          initable);
@@ -2151,6 +2157,16 @@ file_notifier_file_moved (TrackerFileNotifier *notifier,
        miner_fs_queue_event (fs, event, miner_fs_get_queue_priority (fs, source));
 }
 
+static void
+file_notifier_file_ignored_during_crawl (TrackerFileNotifier *notifier,
+                                         GFile               *file,
+                                         gpointer             user_data)
+{
+       TrackerMinerFS *fs = user_data;
+
+       tracker_miner_file_processed (TRACKER_MINER (fs), file, FALSE, "ignored by configuration");
+}
+
 static void
 file_notifier_directory_started (TrackerFileNotifier *notifier,
                                  GFile               *directory,


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