[tracker] libtracker-miner: Remove TrackerCrawler max_depth argument



commit ef421db6c8938cd1a1a07727c31a4ef60caf45be
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Sep 26 16:06:45 2017 +0200

    libtracker-miner: Remove TrackerCrawler max_depth argument
    
    It was always called with depth=1 (return just direct children of the
    given folder), so make this the default. Admittedly, the "crawler" name
    is a bit of an stretch now.
    
    The TrackerCrawler tests have also been removed the recursive tests,
    since that's not possible anymore.

 src/libtracker-miner/tracker-crawler.c        |   37 +----------
 src/libtracker-miner/tracker-crawler.h        |    4 +-
 src/libtracker-miner/tracker-file-notifier.c  |    7 +--
 tests/libtracker-miner/tracker-crawler-test.c |   82 ++-----------------------
 4 files changed, 12 insertions(+), 118 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 78367e4..93b1ab1 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -69,7 +69,6 @@ struct DirectoryProcessingData {
 struct DirectoryRootInfo {
        GFile *directory;
        GNode *tree;
-       gint max_depth;
 
        GQueue *directory_processing_queue;
 
@@ -107,8 +106,6 @@ struct TrackerCrawlerPrivate {
        gboolean        is_finished;
        gboolean        is_paused;
        gboolean        was_started;
-
-       gint            max_depth;
 };
 
 enum {
@@ -248,7 +245,6 @@ tracker_crawler_init (TrackerCrawler *object)
 
        priv = object->priv;
 
-       priv->max_depth = -1;
        priv->directories = g_queue_new ();
 }
 
@@ -474,7 +470,6 @@ directory_processing_data_add_child (DirectoryProcessingData *data,
 
 static DirectoryRootInfo *
 directory_root_info_new (GFile                 *file,
-                         gint                   max_depth,
                          gchar                 *file_attributes,
                          TrackerDirectoryFlags  flags)
 {
@@ -485,7 +480,6 @@ directory_root_info_new (GFile                 *file,
        info = g_slice_new0 (DirectoryRootInfo);
 
        info->directory = g_object_ref (file);
-       info->max_depth = max_depth;
        info->directory_processing_queue = g_queue_new ();
 
        info->tree = g_node_new (g_object_ref (file));
@@ -612,11 +606,6 @@ process_next (TrackerCrawler *crawler)
        }
 
        if (dir_data) {
-               gint depth = g_node_depth (dir_data->node) - 1;
-               gboolean iterate;
-
-               iterate = (info->max_depth >= 0) ? depth < info->max_depth : TRUE;
-
                /* One directory inside the tree hierarchy is being inspected */
                if (!dir_data->was_inspected) {
                        dir_data->was_inspected = TRUE;
@@ -624,7 +613,7 @@ process_next (TrackerCrawler *crawler)
                        /* Crawler may have been already stopped while we were waiting for the
                         *  check_directory return value, and thus we should check if it's
                         *  running before going on with the iteration */
-                       if (priv->is_running && iterate) {
+                       if (priv->is_running && G_NODE_IS_ROOT (dir_data->node)) {
                                /* Directory contents haven't been inspected yet,
                                 * stop this idle function while it's being iterated
                                 */
@@ -656,7 +645,7 @@ process_next (TrackerCrawler *crawler)
                                                                  g_object_ref (child_data->child));
                        }
 
-                       if (iterate && priv->is_running &&
+                       if (G_NODE_IS_ROOT (dir_data->node) && priv->is_running &&
                            child_node && child_data->is_dir) {
                                DirectoryProcessingData *child_dir_data;
 
@@ -1029,8 +1018,7 @@ data_provider_begin (TrackerCrawler          *crawler,
 gboolean
 tracker_crawler_start (TrackerCrawler        *crawler,
                        GFile                 *file,
-                       TrackerDirectoryFlags  flags,
-                       gint                   max_depth)
+                       TrackerDirectoryFlags  flags)
 {
        TrackerCrawlerPrivate *priv;
        DirectoryProcessingData *dir_data;
@@ -1075,9 +1063,8 @@ tracker_crawler_start (TrackerCrawler        *crawler,
        /* Set as running now */
        priv->is_running = TRUE;
        priv->is_finished = FALSE;
-       priv->max_depth = max_depth;
 
-       info = directory_root_info_new (file, max_depth, priv->file_attributes, flags);
+       info = directory_root_info_new (file, priv->file_attributes, flags);
 
        if (!check_directory (crawler, info, file)) {
                directory_root_info_free (info);
@@ -1232,22 +1219,6 @@ tracker_crawler_get_file_attributes (TrackerCrawler *crawler)
 }
 
 /**
- * tracker_crawler_get_max_depth:
- * @crawler: a #TrackerCrawler
- *
- * Returns the max depth that @crawler got passed on tracker_crawler_start
- *
- * Returns: the max depth
- **/
-
-gint
-tracker_crawler_get_max_depth (TrackerCrawler *crawler)
-{
-       g_return_val_if_fail (TRACKER_IS_CRAWLER (crawler), 0);
-       return crawler->priv->max_depth;
-}
-
-/**
  * tracker_crawler_get_file_info:
  * @crawler: a #TrackerCrawler
  * @file: a #GFile returned by @crawler
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 1395e3a..3d61e55 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -75,8 +75,7 @@ GType           tracker_crawler_get_type     (void);
 TrackerCrawler *tracker_crawler_new          (TrackerDataProvider *data_provider);
 gboolean        tracker_crawler_start        (TrackerCrawler *crawler,
                                               GFile          *file,
-                                              TrackerDirectoryFlags flags,
-                                             gint            max_depth);
+                                              TrackerDirectoryFlags flags);
 void            tracker_crawler_stop         (TrackerCrawler *crawler);
 void            tracker_crawler_pause        (TrackerCrawler *crawler);
 void            tracker_crawler_resume       (TrackerCrawler *crawler);
@@ -89,7 +88,6 @@ const gchar *   tracker_crawler_get_file_attributes (TrackerCrawler *crawler);
 
 GFileInfo *     tracker_crawler_get_file_info       (TrackerCrawler *crawler,
                                                     GFile          *file);
-gint            tracker_crawler_get_max_depth       (TrackerCrawler *crawler);
 
 G_END_DECLS
 
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 3afcc50..f4da056 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -664,8 +664,7 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
 
        if (!tracker_crawler_start (priv->crawler,
                                    directory,
-                                   priv->current_index_root->flags,
-                                   depth)) {
+                                   priv->current_index_root->flags)) {
                sparql_files_query_start (notifier, &directory, 1, depth);
        }
 
@@ -1038,7 +1037,7 @@ crawler_finished_cb (TrackerCrawler *crawler,
        TrackerFileNotifier *notifier = user_data;
        TrackerFileNotifierPrivate *priv = notifier->priv;
        GFile *directory;
-       gint max_depth = -1;
+       gint max_depth = 1;
 
        g_assert (priv->current_index_root != NULL);
 
@@ -1047,8 +1046,6 @@ crawler_finished_cb (TrackerCrawler *crawler,
                return;
        }
 
-       max_depth = tracker_crawler_get_max_depth (crawler);
-
        directory = priv->current_index_root->current_dir;
 
        if (priv->current_index_root->query_files->len > 0 &&
diff --git a/tests/libtracker-miner/tracker-crawler-test.c b/tests/libtracker-miner/tracker-crawler-test.c
index 4739f39..45295a8 100644
--- a/tests/libtracker-miner/tracker-crawler-test.c
+++ b/tests/libtracker-miner/tracker-crawler-test.c
@@ -126,7 +126,7 @@ test_crawler_crawl (void)
 
        file = g_file_new_for_path (TEST_DATA_DIR);
 
-       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, -1);
+       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE);
 
        g_assert_cmpint (started, ==, 1);
 
@@ -153,7 +153,7 @@ test_crawler_crawl_interrupted (void)
 
        file = g_file_new_for_path (TEST_DATA_DIR);
 
-       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, -1);
+       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE);
 
        g_assert_cmpint (started, ==, 1);
 
@@ -175,7 +175,7 @@ test_crawler_crawl_nonexisting (void)
        crawler = tracker_crawler_new (NULL);
        file = g_file_new_for_path (TEST_DATA_DIR "-idontexist");
 
-       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, -1);
+       started = tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE);
 
        g_assert_cmpint (started, ==, 0);
 
@@ -184,38 +184,6 @@ test_crawler_crawl_nonexisting (void)
 }
 
 static void
-test_crawler_crawl_recursive (void)
-{
-       TrackerCrawler *crawler;
-       CrawlerTest test = { 0 };
-       GFile *file;
-
-       test.main_loop = g_main_loop_new (NULL, FALSE);
-
-       crawler = tracker_crawler_new (NULL);
-       g_signal_connect (crawler, "finished",
-                         G_CALLBACK (crawler_finished_cb), &test);
-       g_signal_connect (crawler, "directory-crawled",
-                         G_CALLBACK (crawler_directory_crawled_cb), &test);
-
-       file = g_file_new_for_path (TEST_DATA_DIR);
-
-       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, -1);
-
-       g_main_loop_run (test.main_loop);
-
-       /* There are 4 directories and 5 (2 hidden) files */
-       g_assert_cmpint (test.directories_found, ==, 4);
-       g_assert_cmpint (test.directories_ignored, ==, 0);
-       g_assert_cmpint (test.files_found, ==, 5);
-       g_assert_cmpint (test.files_ignored, ==, 0);
-
-       g_main_loop_unref (test.main_loop);
-       g_object_unref (crawler);
-       g_object_unref (file);
-}
-
-static void
 test_crawler_crawl_non_recursive (void)
 {
        TrackerCrawler *crawler;
@@ -232,7 +200,7 @@ test_crawler_crawl_non_recursive (void)
 
        file = g_file_new_for_path (TEST_DATA_DIR);
 
-       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, 1);
+       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE);
 
        g_main_loop_run (test.main_loop);
 
@@ -248,42 +216,6 @@ test_crawler_crawl_non_recursive (void)
 }
 
 static void
-test_crawler_crawl_n_signals (void)
-{
-       TrackerCrawler *crawler;
-       CrawlerTest test = { 0 };
-       GFile *file;
-
-       test.main_loop = g_main_loop_new (NULL, FALSE);
-
-       crawler = tracker_crawler_new (NULL);
-       g_signal_connect (crawler, "finished",
-                         G_CALLBACK (crawler_finished_cb), &test);
-       g_signal_connect (crawler, "directory-crawled",
-                         G_CALLBACK (crawler_directory_crawled_cb), &test);
-       g_signal_connect (crawler, "check-directory",
-                         G_CALLBACK (crawler_check_directory_cb), &test);
-       g_signal_connect (crawler, "check-directory-contents",
-                         G_CALLBACK (crawler_check_directory_contents_cb), &test);
-       g_signal_connect (crawler, "check-file",
-                         G_CALLBACK (crawler_check_file_cb), &test);
-
-       file = g_file_new_for_path (TEST_DATA_DIR);
-
-       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, -1);
-
-       g_main_loop_run (test.main_loop);
-
-       g_assert_cmpint (test.directories_found, ==, test.n_check_directory);
-       g_assert_cmpint (test.directories_found, ==, test.n_check_directory_contents);
-       g_assert_cmpint (test.files_found, ==, test.n_check_file);
-
-       g_main_loop_unref (test.main_loop);
-       g_object_unref (crawler);
-       g_object_unref (file);
-}
-
-static void
 test_crawler_crawl_n_signals_non_recursive (void)
 {
        TrackerCrawler *crawler;
@@ -308,7 +240,7 @@ test_crawler_crawl_n_signals_non_recursive (void)
 
        file = g_file_new_for_path (TEST_DATA_DIR);
 
-       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE, 1);
+       tracker_crawler_start (crawler, file, TRACKER_DIRECTORY_FLAG_NONE);
 
        g_main_loop_run (test.main_loop);
 
@@ -336,13 +268,9 @@ main (int    argc,
        g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-nonexisting",
                         test_crawler_crawl_nonexisting);
 
-       g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-recursive",
-                        test_crawler_crawl_recursive);
        g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-non-recursive",
                         test_crawler_crawl_non_recursive);
 
-       g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-n-signals",
-                        test_crawler_crawl_n_signals);
        g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-n-signals-non-recursive",
                         test_crawler_crawl_n_signals_non_recursive);
 


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