[tracker/subtree-crawling: 1/4] libtracker-miner: Make crawler take a maximum recursion depth
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/subtree-crawling: 1/4] libtracker-miner: Make crawler take a maximum recursion depth
- Date: Sun, 23 Mar 2014 00:36:34 +0000 (UTC)
commit cc56e0c5b116f55456f87b4d8dac08205d22918c
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Mar 22 23:09:11 2014 +0100
libtracker-miner: Make crawler take a maximum recursion depth
TrackerCrawler gets now the maximum depth to recurse into as a parameter
to tracker_crawler_start(), this can be used to divide crawling into
units bigger than individual folders. A value of -1 can be passed
to have it recurse with no restrictions as with the previous recurse=TRUE
argument.
src/libtracker-miner/tracker-crawler.c | 35 +++++++++---------------
src/libtracker-miner/tracker-crawler.h | 2 +-
src/libtracker-miner/tracker-file-notifier.c | 2 +-
tests/libtracker-miner/tracker-crawler-test.c | 14 +++++-----
4 files changed, 22 insertions(+), 31 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 0978996..d4a1dba 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -55,7 +55,7 @@ struct DirectoryProcessingData {
struct DirectoryRootInfo {
GFile *directory;
GNode *tree;
- guint recurse : 1;
+ gint max_depth;
GQueue *directory_processing_queue;
@@ -79,8 +79,6 @@ struct TrackerCrawlerPrivate {
gchar *file_attributes;
- gboolean recurse;
-
/* Statistics */
GTimer *timer;
@@ -370,9 +368,9 @@ directory_processing_data_add_child (DirectoryProcessingData *data,
}
static DirectoryRootInfo *
-directory_root_info_new (GFile *file,
- gboolean recurse,
- gchar *file_attributes)
+directory_root_info_new (GFile *file,
+ gint max_depth,
+ gchar *file_attributes)
{
DirectoryRootInfo *info;
DirectoryProcessingData *dir_info;
@@ -380,7 +378,7 @@ directory_root_info_new (GFile *file,
info = g_slice_new0 (DirectoryRootInfo);
info->directory = g_object_ref (file);
- info->recurse = recurse;
+ info->max_depth = max_depth;
info->directory_processing_queue = g_queue_new ();
info->tree = g_node_new (g_object_ref (file));
@@ -461,19 +459,13 @@ process_func (gpointer data)
}
if (dir_data) {
- /* One directory inside the tree hierarchy is being inspected */
- if (!dir_data->was_inspected) {
- gboolean iterate;
+ gint depth = g_node_depth (dir_data->node) - 1;
+ gboolean iterate;
- if (G_NODE_IS_ROOT (dir_data->node)) {
- iterate = check_directory (crawler, info, dir_data->node->data);
- } else {
- /* Directory has been already checked in the block below, so
- * so obey the settings for the current directory root.
- */
- iterate = info->recurse;
- }
+ 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;
/* Crawler may have been already stopped while we were waiting for the
@@ -511,7 +503,7 @@ process_func (gpointer data)
g_object_ref (child_data->child));
}
- if (info->recurse && priv->is_running &&
+ if (iterate && priv->is_running &&
child_node && child_data->is_dir) {
DirectoryProcessingData *child_dir_data;
@@ -839,7 +831,7 @@ file_enumerate_children (TrackerCrawler *crawler,
gboolean
tracker_crawler_start (TrackerCrawler *crawler,
GFile *file,
- gboolean recurse)
+ gint max_depth)
{
TrackerCrawlerPrivate *priv;
DirectoryRootInfo *info;
@@ -857,7 +849,6 @@ tracker_crawler_start (TrackerCrawler *crawler,
}
priv->was_started = TRUE;
- priv->recurse = recurse;
/* Time the event */
if (priv->timer) {
@@ -874,7 +865,7 @@ tracker_crawler_start (TrackerCrawler *crawler,
priv->is_running = TRUE;
priv->is_finished = FALSE;
- info = directory_root_info_new (file, recurse, priv->file_attributes);
+ info = directory_root_info_new (file, max_depth, priv->file_attributes);
g_queue_push_tail (priv->directories, info);
process_func_start (crawler);
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 1bae0f6..669343f 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -73,7 +73,7 @@ GType tracker_crawler_get_type (void);
TrackerCrawler *tracker_crawler_new (void);
gboolean tracker_crawler_start (TrackerCrawler *crawler,
GFile *file,
- gboolean recurse);
+ gint max_depth);
void tracker_crawler_stop (TrackerCrawler *crawler);
void tracker_crawler_pause (TrackerCrawler *crawler);
void tracker_crawler_resume (TrackerCrawler *crawler);
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 96b8c1a..fdfda92 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -596,7 +596,7 @@ crawl_directories_start (TrackerFileNotifier *notifier)
if ((flags & TRACKER_DIRECTORY_FLAG_IGNORE) == 0 &&
tracker_crawler_start (priv->crawler,
directory,
- (flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0)) {
+ (flags & TRACKER_DIRECTORY_FLAG_RECURSE) ? -1 : 1)) {
gchar *uri;
sparql_file_query_start (notifier, directory,
diff --git a/tests/libtracker-miner/tracker-crawler-test.c b/tests/libtracker-miner/tracker-crawler-test.c
index 69a9630..4f44ede 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, TRUE);
+ started = tracker_crawler_start (crawler, file, -1);
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, TRUE);
+ started = tracker_crawler_start (crawler, file, -1);
g_assert_cmpint (started, ==, 1);
@@ -175,7 +175,7 @@ test_crawler_crawl_nonexisting (void)
crawler = tracker_crawler_new ();
file = g_file_new_for_path (TEST_DATA_DIR "-idontexist");
- started = tracker_crawler_start (crawler, file, TRUE);
+ started = tracker_crawler_start (crawler, file, -1);
g_assert_cmpint (started, ==, 0);
@@ -200,7 +200,7 @@ test_crawler_crawl_recursive (void)
file = g_file_new_for_path (TEST_DATA_DIR);
- tracker_crawler_start (crawler, file, TRUE);
+ tracker_crawler_start (crawler, file, -1);
g_main_loop_run (test.main_loop);
@@ -232,7 +232,7 @@ test_crawler_crawl_non_recursive (void)
file = g_file_new_for_path (TEST_DATA_DIR);
- tracker_crawler_start (crawler, file, FALSE);
+ tracker_crawler_start (crawler, file, 1);
g_main_loop_run (test.main_loop);
@@ -270,7 +270,7 @@ test_crawler_crawl_n_signals (void)
file = g_file_new_for_path (TEST_DATA_DIR);
- tracker_crawler_start (crawler, file, TRUE);
+ tracker_crawler_start (crawler, file, -1);
g_main_loop_run (test.main_loop);
@@ -308,7 +308,7 @@ test_crawler_crawl_n_signals_non_recursive (void)
file = g_file_new_for_path (TEST_DATA_DIR);
- tracker_crawler_start (crawler, file, FALSE);
+ tracker_crawler_start (crawler, file, 1);
g_main_loop_run (test.main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]