[tracker/external-crawler: 17/31] libtracker-miner: Added FileEnumerator unit test



commit ef73c59184dd6499fb8346ba24ff8b6ca082aca4
Author: Martyn Russell <martyn lanedo com>
Date:   Thu May 15 14:25:12 2014 +0100

    libtracker-miner: Added FileEnumerator unit test

 src/libtracker-miner/Makefile.am                   |   15 +-
 src/libtracker-miner/tracker-crawler.c             |  272 +++++++++-----------
 src/libtracker-miner/tracker-crawler.h             |    4 +-
 src/libtracker-miner/tracker-file-enumerator.c     |    1 -
 src/libtracker-miner/tracker-file-notifier.c       |   60 ++---
 src/libtracker-miner/tracker-file-notifier.h       |    3 +-
 src/libtracker-miner/tracker-miner-fs.c            |   63 ++---
 tests/libtracker-miner/Makefile.am                 |    1 +
 tests/libtracker-miner/tracker-crawler-test.c      |   14 +-
 .../tracker-file-enumerator-test.c                 |   77 ++++++
 10 files changed, 275 insertions(+), 235 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 2837c39..be1eaea 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -31,8 +31,8 @@ libtracker_minerdir = $(libdir)/tracker-$(TRACKER_API_VERSION)
 libtracker_minerincludedir=$(includedir)/tracker-$(TRACKER_API_VERSION)/libtracker-miner/
 
 private_sources =                                     \
-       tracker-enumerator.c                           \
-       tracker-enumerator.h                           \
+       tracker-crawler.c                              \
+       tracker-crawler.h                              \
        tracker-file-enumerator.c                      \
        tracker-file-enumerator.h                      \
        tracker-file-notifier.h                        \
@@ -59,11 +59,15 @@ endif
 miner_sources =                                       \
        $(libtracker_miner_monitor_sources)            \
        $(libtracker_miner_monitor_headers)            \
+       tracker-enumerator.c                           \
+       tracker-enumerator.h                           \
        tracker-decorator.c                            \
        tracker-decorator.h                            \
        tracker-decorator-internal.h                   \
        tracker-decorator-fs.c                         \
        tracker-decorator-fs.h                         \
+       tracker-indexing-tree.c                        \
+       tracker-indexing-tree.h                        \
        tracker-miner-dbus.h                           \
        tracker-miner-enum-types.c                     \
        tracker-miner-enum-types.h                     \
@@ -78,11 +82,10 @@ libtracker_miner_private_la_SOURCES =                  \
        $(private_sources)
 
 libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES =    \
-       $(miner_sources)                               \
-       tracker-indexing-tree.c                        \
-       tracker-indexing-tree.h
+       $(miner_sources)
 
 libtracker_minerinclude_HEADERS =                      \
+       tracker-enumerator.h                           \
        tracker-decorator.h                            \
        tracker-decorator-fs.h                         \
        tracker-indexing-tree.h                        \
@@ -100,7 +103,7 @@ if !ENABLE_GCOV
 # Using enable_gcov instead of have_unit_test because when doing a release
 #  we disable gcov but NOT the unit tests
 libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS +=    \
-       -export-symbols-regex 
'^tracker_(miner|indexing_tree|directory_flags|filter_type|filter_policy|network_type|decorator)_.*'
+       -export-symbols-regex 
'^tracker_(enumerator|miner|indexing_tree|directory_flags|filter_type|filter_policy|network_type|decorator)_.*'
 endif
 
 libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD =     \
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 20d29dc..31d926a 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "tracker-crawler.h"
+#include "tracker-file-enumerator.h"
 #include "tracker-utils.h"
 
 #define TRACKER_CRAWLER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_CRAWLER, 
TrackerCrawlerPrivate))
@@ -67,6 +68,8 @@ struct DirectoryRootInfo {
 };
 
 struct TrackerCrawlerPrivate {
+       TrackerEnumerator *enumerator;
+
        /* Directories to crawl */
        GQueue         *directories;
 
@@ -89,6 +92,14 @@ struct TrackerCrawlerPrivate {
        gboolean        was_started;
 };
 
+typedef struct {
+       TrackerCrawler *crawler;
+       DirectoryRootInfo  *root_info;
+       DirectoryProcessingData *dir_info;
+       GFile *dir_file;
+       GCancellable *cancellable;
+} EnumeratorData;
+
 enum {
        CHECK_DIRECTORY,
        CHECK_FILE,
@@ -98,22 +109,25 @@ enum {
        LAST_SIGNAL
 };
 
-typedef struct {
-       TrackerCrawler *crawler;
-       DirectoryRootInfo  *root_info;
-       DirectoryProcessingData *dir_info;
-       GFile *dir_file;
-       GCancellable *cancellable;
-} EnumeratorData;
+enum {
+       PROP_0,
+       PROP_ENUMERATOR
+};
 
-static void     crawler_finalize        (GObject         *object);
-static gboolean check_defaults          (TrackerCrawler  *crawler,
-                                         GFile           *file);
-static gboolean check_contents_defaults (TrackerCrawler  *crawler,
-                                         GFile           *file,
-                                         GList           *contents);
-static void     file_enumerate_next     (GFileEnumerator *enumerator,
-                                         EnumeratorData  *ed);
+static void     crawler_get_property     (GObject         *object,
+                                          guint            prop_id,
+                                          GValue          *value,
+                                          GParamSpec      *pspec);
+static void     crawler_set_property     (GObject         *object,
+                                          guint            prop_id,
+                                          const GValue    *value,
+                                          GParamSpec      *pspec);
+static void     crawler_finalize         (GObject         *object);
+static gboolean check_defaults           (TrackerCrawler  *crawler,
+                                          GFile           *file);
+static gboolean check_contents_defaults  (TrackerCrawler  *crawler,
+                                          GFile           *file,
+                                          GList           *contents);
 static void     file_enumerate_children  (TrackerCrawler          *crawler,
                                          DirectoryRootInfo       *info,
                                          DirectoryProcessingData *dir_data);
@@ -132,6 +146,8 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        TrackerCrawlerClass *crawler_class = TRACKER_CRAWLER_CLASS (klass);
 
+       object_class->set_property = crawler_set_property;
+       object_class->get_property = crawler_get_property;
        object_class->finalize = crawler_finalize;
 
        crawler_class->check_directory = check_defaults;
@@ -195,6 +211,15 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
                              G_TYPE_NONE,
                              1, G_TYPE_BOOLEAN);
 
+       g_object_class_install_property (object_class,
+                                        PROP_ENUMERATOR,
+                                        g_param_spec_object ("enumerator",
+                                                             "Enumerator",
+                                                             "Enumerator to use to crawl structures 
populating data, e.g. like GFileEnumerator",
+                                                             TRACKER_TYPE_ENUMERATOR,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+
        g_type_class_add_private (object_class, sizeof (TrackerCrawlerPrivate));
 
        file_info_quark = g_quark_from_static_string ("tracker-crawler-file-info");
@@ -213,6 +238,46 @@ tracker_crawler_init (TrackerCrawler *object)
 }
 
 static void
+crawler_set_property (GObject      *object,
+                      guint         prop_id,
+                      const GValue *value,
+                      GParamSpec   *pspec)
+{
+       TrackerCrawlerPrivate *priv;
+
+       priv = TRACKER_CRAWLER (object)->priv;
+
+       switch (prop_id) {
+       case PROP_ENUMERATOR:
+               priv->enumerator = g_value_dup_object (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+crawler_get_property (GObject    *object,
+                      guint       prop_id,
+                      GValue     *value,
+                      GParamSpec *pspec)
+{
+       TrackerCrawlerPrivate *priv;
+
+       priv = TRACKER_CRAWLER (object)->priv;
+
+       switch (prop_id) {
+       case PROP_ENUMERATOR:
+               g_value_set_object (value, priv->enumerator);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
 crawler_finalize (GObject *object)
 {
        TrackerCrawlerPrivate *priv;
@@ -253,13 +318,16 @@ check_contents_defaults (TrackerCrawler  *crawler,
 }
 
 TrackerCrawler *
-tracker_crawler_new (void)
+tracker_crawler_new (TrackerEnumerator *enumerator)
 {
-       TrackerCrawler *crawler;
-
-       crawler = g_object_new (TRACKER_TYPE_CRAWLER, NULL);
+       if (!enumerator) {
+               /* Default to the file enumerator if none is passed */
+               enumerator = tracker_file_enumerator_new ();
+       }
 
-       return crawler;
+       return g_object_new (TRACKER_TYPE_CRAWLER,
+                            "enumerator", enumerator,
+                            NULL);
 }
 
 static gboolean
@@ -638,86 +706,52 @@ enumerator_data_free (EnumeratorData *ed)
 }
 
 static void
-file_enumerator_close_cb (GObject      *enumerator,
-                          GAsyncResult *result,
-                          gpointer      user_data)
-{
-       TrackerCrawler *crawler;
-       GError *error = NULL;
-
-       crawler = TRACKER_CRAWLER (user_data);
-
-       if (!g_file_enumerator_close_finish (G_FILE_ENUMERATOR (enumerator),
-                                            result,
-                                            &error)) {
-               g_warning ("Couldn't close GFileEnumerator (%p): %s", enumerator,
-                          (error) ? error->message : "No reason");
-
-               g_clear_error (&error);
-       }
-
-       /* Processing of directory is now finished,
-        * continue with queued files/directories.
-        */
-       process_func_start (crawler);
-}
-
-static void
-file_enumerate_next_cb (GObject      *object,
-                        GAsyncResult *result,
-                        gpointer      user_data)
+file_enumerate_children_cb (GObject      *object,
+                            GAsyncResult *result,
+                            gpointer      user_data)
 {
        TrackerCrawler *crawler;
+       TrackerEnumerator *enumerator;
+       GSList *l;
        EnumeratorData *ed;
-       GFileEnumerator *enumerator;
-       GFile *parent, *child;
-       GFileInfo *info;
-       GList *files, *l;
+       GFile *parent;
        GError *error = NULL;
+       GSList *files = NULL;
        gboolean cancelled;
 
-       enumerator = G_FILE_ENUMERATOR (object);
-
-       ed = user_data;
+       ed = (EnumeratorData*) user_data;
        crawler = ed->crawler;
        cancelled = g_cancellable_is_cancelled (ed->cancellable);
+       parent = ed->dir_info->node->data;
+       enumerator = TRACKER_ENUMERATOR (object);
 
-       files = g_file_enumerator_next_files_finish (enumerator,
-                                                    result,
-                                                    &error);
+       files = tracker_enumerator_start_finish (enumerator, result, &error);
 
-       if (error || !files || !crawler->priv->is_running) {
+       if (!files) {
                if (error && !cancelled) {
-                       g_critical ("Could not crawl through directory: %s", error->message);
-                       g_error_free (error);
-               }
+                       gchar *path;
 
-               /* No more files or we are stopping anyway, so clean
-                * up and close all file enumerators.
-                */
-               if (files) {
-                       g_list_foreach (files, (GFunc) g_object_unref, NULL);
-                       g_list_free (files);
-               }
+                       path = g_file_get_path (parent);
 
-               if (!cancelled) {
-                       enumerator_data_process (ed);
+                       g_warning ("Could not open directory '%s': %s",
+                                  path, error->message);
+
+                       g_error_free (error);
+                       g_free (path);
                }
 
                enumerator_data_free (ed);
-               g_file_enumerator_close_async (enumerator,
-                                              G_PRIORITY_DEFAULT,
-                                              NULL,
-                                              file_enumerator_close_cb,
-                                              crawler);
-               g_object_unref (enumerator);
-
+               process_func_start (crawler);
                return;
        }
 
-       parent = ed->dir_info->node->data;
+       if (!cancelled) {
+               enumerator_data_process (ed);
+       }
 
        for (l = files; l; l = l->next) {
+               GFileInfo *info;
+               GFile *child;
                const gchar *child_name;
                gboolean is_dir;
 
@@ -730,9 +764,9 @@ file_enumerate_next_cb (GObject      *object,
                if (crawler->priv->file_attributes) {
                        /* Store the file info for future retrieval */
                        g_object_set_qdata_full (G_OBJECT (child),
-                                                file_info_quark,
-                                                g_object_ref (info),
-                                                (GDestroyNotify) g_object_unref);
+                                                file_info_quark,
+                                                g_object_ref (info),
+                                                (GDestroyNotify) g_object_unref);
                }
 
                directory_processing_data_add_child (ed->dir_info, child, is_dir);
@@ -741,62 +775,8 @@ file_enumerate_next_cb (GObject      *object,
                g_object_unref (info);
        }
 
-       g_list_free (files);
-
-       /* Get next files */
-       file_enumerate_next (enumerator, ed);
-}
-
-static void
-file_enumerate_next (GFileEnumerator *enumerator,
-                     EnumeratorData  *ed)
-{
-       g_file_enumerator_next_files_async (enumerator,
-                                           FILES_GROUP_SIZE,
-                                           G_PRIORITY_DEFAULT,
-                                           ed->cancellable,
-                                           file_enumerate_next_cb,
-                                           ed);
-}
-
-static void
-file_enumerate_children_cb (GObject      *file,
-                            GAsyncResult *result,
-                            gpointer      user_data)
-{
-       TrackerCrawler *crawler;
-       EnumeratorData *ed;
-       GFileEnumerator *enumerator;
-       GFile *parent;
-       GError *error = NULL;
-       gboolean cancelled;
-
-       parent = G_FILE (file);
-       ed = (EnumeratorData*) user_data;
-       crawler = ed->crawler;
-       cancelled = g_cancellable_is_cancelled (ed->cancellable);
-       enumerator = g_file_enumerate_children_finish (parent, result, &error);
-
-       if (!enumerator) {
-               if (error && !cancelled) {
-                       gchar *path;
-
-                       path = g_file_get_path (parent);
-
-                       g_warning ("Could not open directory '%s': %s",
-                                  path, error->message);
-
-                       g_error_free (error);
-                       g_free (path);
-               }
-
-               enumerator_data_free (ed);
-               process_func_start (crawler);
-               return;
-       }
-
-       /* Start traversing the directory's files */
-       file_enumerate_next (enumerator, ed);
+       g_slist_free (files);
+       process_func_start (crawler);
 }
 
 static void
@@ -817,14 +797,14 @@ file_enumerate_children (TrackerCrawler          *crawler,
                attrs = g_strdup (FILE_ATTRIBUTES);
        }
 
-       g_file_enumerate_children_async (ed->dir_file,
-                                        attrs,
-                                        G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                        G_PRIORITY_LOW,
-                                        ed->cancellable,
-                                        file_enumerate_children_cb,
-                                        ed);
-
+       tracker_enumerator_start_async (crawler->priv->enumerator,
+                                       ed->dir_file,
+                                       attrs,
+                                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                       G_PRIORITY_LOW,
+                                       ed->cancellable,
+                                       file_enumerate_children_cb,
+                                       ed);
        g_free (attrs);
 }
 
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 669343f..5ec992e 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -27,6 +27,8 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#include "tracker-enumerator.h"
+
 G_BEGIN_DECLS
 
 #define TRACKER_TYPE_CRAWLER            (tracker_crawler_get_type ())
@@ -70,7 +72,7 @@ struct TrackerCrawlerClass {
 };
 
 GType           tracker_crawler_get_type     (void);
-TrackerCrawler *tracker_crawler_new          (void);
+TrackerCrawler *tracker_crawler_new          (TrackerEnumerator *enumerator);
 gboolean        tracker_crawler_start        (TrackerCrawler *crawler,
                                               GFile          *file,
                                              gint            max_depth);
diff --git a/src/libtracker-miner/tracker-file-enumerator.c b/src/libtracker-miner/tracker-file-enumerator.c
index 43b055f..c285b6a 100644
--- a/src/libtracker-miner/tracker-file-enumerator.c
+++ b/src/libtracker-miner/tracker-file-enumerator.c
@@ -58,7 +58,6 @@ tracker_file_enumerator_init (TrackerFileEnumerator *fe)
 {
 }
 
-
 static StartData *
 start_data_new (GFile               *dir,
                 const gchar         *attributes,
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index c52811a..b57d1f6 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -38,7 +38,7 @@ static GQuark quark_property_filesystem_mtime = 0;
 enum {
        PROP_0,
        PROP_INDEXING_TREE,
-       PROP_EXTERNAL_CRAWLER
+       PROP_ENUMERATOR
 };
 
 enum {
@@ -75,8 +75,7 @@ typedef struct {
 
        TrackerCrawler *crawler;
        TrackerMonitor *monitor;
-
-       gboolean external_crawler;
+       TrackerEnumerator *enumerator;
 
        GTimer *timer;
 
@@ -117,8 +116,8 @@ tracker_file_notifier_set_property (GObject      *object,
                tracker_monitor_set_indexing_tree (priv->monitor,
                                                   priv->indexing_tree);
                break;
-       case PROP_EXTERNAL_CRAWLER:
-               priv->external_crawler = g_value_get_boolean (value);
+       case PROP_ENUMERATOR:
+               priv->enumerator = g_value_dup_object (value);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -140,8 +139,8 @@ tracker_file_notifier_get_property (GObject    *object,
        case PROP_INDEXING_TREE:
                g_value_set_object (value, priv->indexing_tree);
                break;
-       case PROP_EXTERNAL_CRAWLER:
-               g_value_set_boolean (value, priv->external_crawler);
+       case PROP_ENUMERATOR:
+               g_value_set_object (value, priv->enumerator);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -388,12 +387,7 @@ file_notifier_add_node_foreach (GNode    *node,
                data->cur_parent = NULL;
        }
 
-       if (priv->external_crawler) {
-               g_signal_emit (data->notifier, signals[QUERY_INFO], 0, file, &file_info);
-               g_warning ("TRACKER_FILE_NOTIFIER --> QUERY INFO, file:%p, info:%p", file, file_info);
-       } else {
-               file_info = tracker_crawler_get_file_info (priv->crawler, file);
-       }
+       file_info = tracker_crawler_get_file_info (priv->crawler, file);
 
        if (file_info) {
                GFileType file_type;
@@ -453,8 +447,6 @@ crawler_directory_crawled_cb (TrackerCrawler *crawler,
        notifier = data.notifier = user_data;
        priv = notifier->priv;
 
-       /* FIXME: Add a call into this periodically when we have external crawlers */
-
        g_node_traverse (tree,
                         G_PRE_ORDER,
                         G_TRAVERSE_ALL,
@@ -573,9 +565,6 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
        gboolean recurse, retval = FALSE;
        GFile *directory;
 
-       if (priv->external_crawler)
-               return TRUE;
-
        if (!priv->current_index_root)
                return FALSE;
 
@@ -861,7 +850,6 @@ crawler_finished_cb (TrackerCrawler *crawler,
 
        directory = g_queue_peek_head (priv->current_index_root->pending_dirs);
 
-       /* FIXME: Do we need some logic here for external crawlers ? */
        if (priv->current_index_root->query_files->len > 0 &&
            (directory == priv->current_index_root->root ||
             tracker_file_system_get_property (priv->file_system,
@@ -1311,10 +1299,7 @@ indexing_tree_directory_removed (TrackerIndexingTree *indexing_tree,
        if (priv->current_index_root &&
            directory == priv->current_index_root->root) {
                /* Directory being currently processed */
-               if (!priv->external_crawler) {
-                       tracker_crawler_stop (priv->crawler);
-               }
-
+               tracker_crawler_stop (priv->crawler);
                g_cancellable_cancel (priv->cancellable);
 
                root_data_free (priv->current_index_root);
@@ -1324,9 +1309,8 @@ indexing_tree_directory_removed (TrackerIndexingTree *indexing_tree,
        }
 
        /* Remove monitors if any */
-       if (!priv->external_crawler) {
-               tracker_monitor_remove_recursively (priv->monitor, directory);
-       }
+       /* FIXME: How do we handle this with 3rd party enumerators? */
+       tracker_monitor_remove_recursively (priv->monitor, directory);
 
        /* Remove all files from cache */
        tracker_file_system_forget_files (priv->file_system, directory,
@@ -1466,13 +1450,13 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
-                                        PROP_EXTERNAL_CRAWLER,
-                                        g_param_spec_boolean ("external-crawler",
-                                                              "External crawler",
-                                                              "Set to TRUE when we don't use the 
TrackerCrawler but feed files by the API",
-                                                              FALSE,
-                                                              G_PARAM_READWRITE |
-                                                              G_PARAM_CONSTRUCT_ONLY));
+                                        PROP_ENUMERATOR,
+                                        g_param_spec_object ("enumerator",
+                                                             "Enumerator",
+                                                             "Enumerator to use to crawl structures 
populating data, e.g. like GFileEnumerator",
+                                                             TRACKER_TYPE_ENUMERATOR,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
 
        g_type_class_add_private (object_class,
                                  sizeof (TrackerFileNotifierClass));
@@ -1519,7 +1503,7 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
        priv->stopped = TRUE;
 
        /* Set up crawler */
-       priv->crawler = tracker_crawler_new ();
+       priv->crawler = tracker_crawler_new (priv->enumerator);
        tracker_crawler_set_file_attributes (priv->crawler,
                                             G_FILE_ATTRIBUTE_TIME_MODIFIED ","
                                             G_FILE_ATTRIBUTE_STANDARD_TYPE);
@@ -1562,13 +1546,13 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
 
 TrackerFileNotifier *
 tracker_file_notifier_new (TrackerIndexingTree *indexing_tree,
-                           gboolean             external_crawler)
+                           TrackerEnumerator   *enumerator)
 {
        g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (indexing_tree), NULL);
 
        return g_object_new (TRACKER_TYPE_FILE_NOTIFIER,
                             "indexing-tree", indexing_tree,
-                            "external-crawler", external_crawler,
+                            "enumerator", enumerator,
                             NULL);
 }
 
@@ -1604,9 +1588,7 @@ tracker_file_notifier_stop (TrackerFileNotifier *notifier)
        priv = notifier->priv;
 
        if (!priv->stopped) {
-               if (!priv->external_crawler) {
-                       tracker_crawler_stop (priv->crawler);
-               }
+               tracker_crawler_stop (priv->crawler);
 
                g_cancellable_cancel (priv->cancellable);
                priv->stopped = TRUE;
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index 57bafce..5af8760 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -28,6 +28,7 @@
 
 #include <gio/gio.h>
 #include "tracker-indexing-tree.h"
+#include "tracker-enumerator.h"
 #include "tracker-miner-fs.h"
 
 G_BEGIN_DECLS
@@ -79,7 +80,7 @@ GType         tracker_file_notifier_get_type     (void) G_GNUC_CONST;
 
 TrackerFileNotifier *
               tracker_file_notifier_new          (TrackerIndexingTree     *indexing_tree,
-                                                  gboolean                 external_crawler);
+                                                  TrackerEnumerator       *enumerator);
 
 gboolean      tracker_file_notifier_start        (TrackerFileNotifier     *notifier);
 void          tracker_file_notifier_stop         (TrackerFileNotifier     *notifier);
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 6c2c95d..0d1709b 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -167,6 +167,7 @@ struct _TrackerMinerFSPrivate {
        GFile *root;
        TrackerIndexingTree *indexing_tree;
        TrackerFileNotifier *file_notifier;
+       TrackerEnumerator *enumerator;
 
        /* Sparql insertion tasks */
        TrackerTaskPool *task_pool;
@@ -181,9 +182,6 @@ struct _TrackerMinerFSPrivate {
 
        /* Properties */
        gdouble throttle;
-       guint external_crawler : 1; /* TRUE if we're being feed files
-                                    * instead of discovering them
-                                    * ourselves */
        guint mtime_checking : 1;   /* TRUE if mtime checks should be done
                                     * during initial crawling. */
        guint initial_crawling : 1; /* TRUE if initial crawling should be
@@ -250,7 +248,7 @@ enum {
        PROP_ROOT,
        PROP_WAIT_POOL_LIMIT,
        PROP_READY_POOL_LIMIT,
-       PROP_EXTERNAL_CRAWLER,
+       PROP_ENUMERATOR,
        PROP_MTIME_CHECKING,
        PROP_INITIAL_CRAWLING
 };
@@ -377,12 +375,12 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
                                                            1, G_MAXUINT, DEFAULT_READY_POOL_LIMIT,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
        g_object_class_install_property (object_class,
-                                        PROP_EXTERNAL_CRAWLER,
-                                        g_param_spec_boolean ("external-crawler",
-                                                              "External crawler",
-                                                              "Set to TRUE when we don't use the 
TrackerCrawler but feed files by the API",
-                                                              FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+                                        PROP_ENUMERATOR,
+                                        g_param_spec_object ("enumerator",
+                                                             "Enumerator",
+                                                             "Enumerator to use to crawl structures 
populating data, e.g. like GFileEnumerator",
+                                                             TRACKER_TYPE_ENUMERATOR,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_MTIME_CHECKING,
                                         g_param_spec_boolean ("mtime-checking",
@@ -667,7 +665,7 @@ miner_fs_initable_init (GInitable     *initable,
 
        /* Create the file notifier */
        priv->file_notifier = tracker_file_notifier_new (priv->indexing_tree,
-                                                        priv->external_crawler);
+                                                        priv->enumerator);
 
        if (!priv->file_notifier) {
                g_set_error (error,
@@ -821,8 +819,8 @@ fs_set_property (GObject      *object,
                                                     fs->priv->sparql_buffer_limit);
                }
                break;
-       case PROP_EXTERNAL_CRAWLER:
-               fs->priv->external_crawler = g_value_get_boolean (value);
+       case PROP_ENUMERATOR:
+               fs->priv->enumerator = g_value_dup_object (value);
                break;
        case PROP_MTIME_CHECKING:
                fs->priv->mtime_checking = g_value_get_boolean (value);
@@ -862,8 +860,8 @@ fs_get_property (GObject    *object,
        case PROP_MTIME_CHECKING:
                g_value_set_boolean (value, fs->priv->mtime_checking);
                break;
-       case PROP_EXTERNAL_CRAWLER:
-               g_value_set_boolean (value, fs->priv->external_crawler);
+       case PROP_ENUMERATOR:
+               g_value_set_object (value, fs->priv->enumerator);
                break;
        case PROP_INITIAL_CRAWLING:
                g_value_set_boolean (value, fs->priv->initial_crawling);
@@ -3030,12 +3028,12 @@ tracker_miner_fs_directory_add (TrackerMinerFS *fs,
                flags |= TRACKER_DIRECTORY_FLAG_RECURSE;
        }
 
-       if (!fs->priv->external_crawler) {
+       if (!fs->priv->enumerator) {
                flags |= TRACKER_DIRECTORY_FLAG_MONITOR;
+       }
 
-               if (fs->priv->mtime_checking) {
-                       flags |= TRACKER_DIRECTORY_FLAG_CHECK_MTIME;
-               }
+       if (fs->priv->mtime_checking) {
+               flags |= TRACKER_DIRECTORY_FLAG_CHECK_MTIME;
        }
 
        tracker_indexing_tree_add (fs->priv->indexing_tree,
@@ -3468,12 +3466,11 @@ tracker_miner_fs_check_directory_with_priority (TrackerMinerFS *fs,
                        return;
                }
 
-               if (fs->priv->external_crawler) {
-                       flags = TRACKER_DIRECTORY_FLAG_RECURSE;
-               } else {
-                       flags = TRACKER_DIRECTORY_FLAG_RECURSE |
-                               TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
-                               TRACKER_DIRECTORY_FLAG_MONITOR;
+               flags = TRACKER_DIRECTORY_FLAG_RECURSE |
+                       TRACKER_DIRECTORY_FLAG_CHECK_MTIME;
+
+               if (!fs->priv->enumerator) {
+                       flags |= TRACKER_DIRECTORY_FLAG_MONITOR;
                }
 
                /* Priorities run from positive to negative */
@@ -3852,7 +3849,7 @@ tracker_miner_fs_force_mtime_checking (TrackerMinerFS *fs,
        g_return_if_fail (TRACKER_IS_MINER_FS (fs));
        g_return_if_fail (G_IS_FILE (directory));
 
-       if (fs->priv->external_crawler) {
+       if (fs->priv->enumerator) {
                /* Essentially, this is a not doing anything special */
                flags = TRACKER_DIRECTORY_FLAG_RECURSE;
        } else {
@@ -3931,14 +3928,12 @@ tracker_miner_fs_add_directory_without_parent (TrackerMinerFS *fs,
        g_return_if_fail (TRACKER_IS_MINER_FS (fs));
        g_return_if_fail (G_IS_FILE (file));
 
-       if (fs->priv->external_crawler) {
-               flags = TRACKER_DIRECTORY_FLAG_RECURSE |
-                       TRACKER_DIRECTORY_FLAG_PRESERVE;
-       } else {
-               flags = TRACKER_DIRECTORY_FLAG_RECURSE |
-                       TRACKER_DIRECTORY_FLAG_PRESERVE |
-                       TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
-                       TRACKER_DIRECTORY_FLAG_MONITOR;
+       flags = TRACKER_DIRECTORY_FLAG_RECURSE |
+               TRACKER_DIRECTORY_FLAG_PRESERVE |
+               TRACKER_DIRECTORY_FLAG_CHECK_MTIME;
+
+       if (!fs->priv->enumerator) {
+               flags |= TRACKER_DIRECTORY_FLAG_MONITOR;
        }
 
        tracker_indexing_tree_add (fs->priv->indexing_tree,
diff --git a/tests/libtracker-miner/Makefile.am b/tests/libtracker-miner/Makefile.am
index cebb7e2..979a0ad 100644
--- a/tests/libtracker-miner/Makefile.am
+++ b/tests/libtracker-miner/Makefile.am
@@ -16,6 +16,7 @@ noinst_PROGRAMS += $(test_programs)
 
 test_programs = \
        tracker-crawler-test                           \
+       tracker-file-enumerator-test                   \
        tracker-file-notifier-test                     \
        tracker-file-system-test                       \
        tracker-thumbnailer-test                       \
diff --git a/tests/libtracker-miner/tracker-crawler-test.c b/tests/libtracker-miner/tracker-crawler-test.c
index 4f44ede..894d896 100644
--- a/tests/libtracker-miner/tracker-crawler-test.c
+++ b/tests/libtracker-miner/tracker-crawler-test.c
@@ -120,7 +120,7 @@ test_crawler_crawl (void)
 
        test.main_loop = g_main_loop_new (NULL, FALSE);
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
 
@@ -147,7 +147,7 @@ test_crawler_crawl_interrupted (void)
        gboolean started;
        GFile *file;
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
 
@@ -172,7 +172,7 @@ test_crawler_crawl_nonexisting (void)
        GFile *file;
        gboolean started;
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        file = g_file_new_for_path (TEST_DATA_DIR "-idontexist");
 
        started = tracker_crawler_start (crawler, file, -1);
@@ -192,7 +192,7 @@ test_crawler_crawl_recursive (void)
 
        test.main_loop = g_main_loop_new (NULL, FALSE);
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
        g_signal_connect (crawler, "directory-crawled",
@@ -224,7 +224,7 @@ test_crawler_crawl_non_recursive (void)
 
        test.main_loop = g_main_loop_new (NULL, FALSE);
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
        g_signal_connect (crawler, "directory-crawled",
@@ -256,7 +256,7 @@ test_crawler_crawl_n_signals (void)
 
        test.main_loop = g_main_loop_new (NULL, FALSE);
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
        g_signal_connect (crawler, "directory-crawled",
@@ -294,7 +294,7 @@ test_crawler_crawl_n_signals_non_recursive (void)
 
        test.main_loop = g_main_loop_new (NULL, FALSE);
 
-       crawler = tracker_crawler_new ();
+       crawler = tracker_crawler_new (NULL);
        g_signal_connect (crawler, "finished",
                          G_CALLBACK (crawler_finished_cb), &test);
        g_signal_connect (crawler, "directory-crawled",
diff --git a/tests/libtracker-miner/tracker-file-enumerator-test.c 
b/tests/libtracker-miner/tracker-file-enumerator-test.c
new file mode 100644
index 0000000..2665064
--- /dev/null
+++ b/tests/libtracker-miner/tracker-file-enumerator-test.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2014, Softathome <contact softathome com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <locale.h>
+
+#include <libtracker-miner/tracker-file-enumerator.h>
+
+static void
+test_enumerator_crawl (void)
+{
+       TrackerEnumerator *enumerator;
+       GFile *dir;
+       GSList *files, *l;
+       GError *error = NULL;
+       const gchar *path;
+
+       setlocale (LC_ALL, "");
+
+       enumerator = tracker_file_enumerator_new ();
+       g_assert (enumerator != NULL);
+
+       /* FIXME: Use better tmp data structure */
+       path = "/tmp";
+       dir = g_file_new_for_path (path);
+       g_print ("'%s'\n", path);
+
+       files = tracker_enumerator_start (enumerator,
+                                         dir,
+                                         G_FILE_ATTRIBUTE_STANDARD_NAME "," \
+                                         G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                         G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                         NULL,
+                                         &error);
+       g_assert_no_error (error);
+       g_assert (files != NULL);
+       g_assert (g_slist_length (files) > 0);
+
+       for (l = files; l; l = l->next) {
+               GFileInfo *info = l->data;
+
+               g_print ("-> '%s'\n", g_file_info_get_name (info));
+       }
+
+       g_object_unref (dir);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_message ("Testing file enumerator");
+
+       g_test_add_func ("/libtracker-miner/tracker-enumerator/crawl",
+                        test_enumerator_crawl);
+
+       return g_test_run ();
+}


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