[tracker/libtracker-miner] More clean ups to libtracker-miner
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-miner] More clean ups to libtracker-miner
- Date: Tue, 4 Aug 2009 14:59:38 +0000 (UTC)
commit 3c60e53135c85bed9ebbd8e41374ca870ac41095
Author: Martyn Russell <martyn imendio com>
Date: Tue Aug 4 15:58:32 2009 +0100
More clean ups to libtracker-miner
Removed tracker-utils.[ch]
Clean ups to code in tracker-crawler.[ch] and tracker-monitor.[ch]
removed unused stuff
Added directory for loop machinery to tracker-processor.c
Added more useful test cases to tracker-miner-test
src/libtracker-miner/Makefile.am | 4 +-
src/libtracker-miner/tracker-crawler.c | 592 +-----------------------------
src/libtracker-miner/tracker-crawler.h | 22 +-
src/libtracker-miner/tracker-main.c | 114 +++----
src/libtracker-miner/tracker-monitor.c | 2 +-
src/libtracker-miner/tracker-monitor.h | 14 +-
src/libtracker-miner/tracker-processor.c | 405 ++++++++++++++-------
src/libtracker-miner/tracker-processor.h | 38 +-
src/libtracker-miner/tracker-utils.c | 44 ---
src/libtracker-miner/tracker-utils.h | 28 --
10 files changed, 368 insertions(+), 895 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 8908b58..fc42315 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -37,9 +37,7 @@ libtracker_miner_la_SOURCES = \
tracker-monitor.c \
tracker-monitor.h \
tracker-processor.c \
- tracker-processor.h \
- tracker-utils.c \
- tracker-utils.h
+ tracker-processor.h
libtracker_minerinclude_HEADERS = \
tracker-miner.h \
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index aa4849e..cb6e58c 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -34,7 +34,6 @@
#include "tracker-dbus.h"
#include "tracker-monitor.h"
#include "tracker-marshal.h"
-#include "tracker-utils.h"
#define TRACKER_CRAWLER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_CRAWLER, TrackerCrawlerPrivate))
@@ -50,7 +49,7 @@
*/
#define FILES_GROUP_SIZE 100
-struct _TrackerCrawlerPrivate {
+struct TrackerCrawlerPrivate {
/* Found data */
GQueue *directories;
GQueue *files;
@@ -60,37 +59,6 @@ struct _TrackerCrawlerPrivate {
gboolean recurse;
- /* Actual paths that exist which we are crawling:
- *
- * - 'Paths' are non-recursive.
- * - 'Recurse Paths' are recursive.
- * - 'Special Paths' are recursive but not in module config.
- */
-#ifdef FIX
- GSList *paths;
- GSList *paths_current;
- gboolean paths_are_done;
-
- GSList *recurse_paths;
- GSList *recurse_paths_current;
- gboolean recurse_paths_are_done;
-
- GSList *special_paths;
- GSList *special_paths_current;
- gboolean special_paths_are_done;
-
- /* Ignore/Index patterns */
- GList *ignored_directory_patterns;
- GList *ignored_file_patterns;
- GList *index_file_patterns;
- GList *ignored_directories_with_content;
-
- /* Legacy NoWatchDirectoryRoots */
- GSList *no_watch_directory_roots;
- GSList *watch_directory_roots;
- GSList *crawl_directory_roots;
-#endif
-
/* Statistics */
GTimer *timer;
guint enumerations;
@@ -113,8 +81,8 @@ enum {
};
typedef struct {
- GFile *child;
- gboolean is_dir;
+ GFile *child;
+ gboolean is_dir;
} EnumeratorChildData;
typedef struct {
@@ -131,7 +99,7 @@ static void file_enumerate_children (TrackerCrawler *crawler,
static guint signals[LAST_SIGNAL] = { 0, };
-G_DEFINE_TYPE(TrackerCrawler, tracker_crawler, G_TYPE_OBJECT)
+G_DEFINE_TYPE (TrackerCrawler, tracker_crawler, G_TYPE_OBJECT)
static void
tracker_crawler_class_init (TrackerCrawlerClass *klass)
@@ -203,45 +171,6 @@ tracker_crawler_finalize (GObject *object)
g_timer_destroy (priv->timer);
}
-#ifdef FIX
- g_slist_foreach (priv->no_watch_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->no_watch_directory_roots);
-
- g_slist_foreach (priv->watch_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->watch_directory_roots);
-
- g_slist_foreach (priv->crawl_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->crawl_directory_roots);
-
- if (priv->index_file_patterns) {
- g_list_free (priv->index_file_patterns);
- }
-
- if (priv->ignored_directory_patterns) {
- g_list_free (priv->ignored_directory_patterns);
- }
-
- if (priv->ignored_file_patterns) {
- g_list_free (priv->ignored_file_patterns);
- }
-
- if (priv->ignored_directories_with_content) {
- g_list_free (priv->ignored_directories_with_content);
- }
-
- /* Don't free the 'current_' variant of these, they are just
- * place holders so we know our status.
- */
- g_slist_foreach (priv->paths, (GFunc) g_free, NULL);
- g_slist_free (priv->paths);
-
- g_slist_foreach (priv->recurse_paths, (GFunc) g_free, NULL);
- g_slist_free (priv->recurse_paths);
-
- g_slist_foreach (priv->special_paths, (GFunc) g_free, NULL);
- g_slist_free (priv->special_paths);
-#endif
-
if (priv->idle_id) {
g_source_remove (priv->idle_id);
}
@@ -277,123 +206,6 @@ tracker_crawler_new (void)
return crawler;
}
-/*
- * Functions
- */
-
-#ifdef FIX
-
-static gboolean
-is_path_ignored (TrackerCrawler *crawler,
- const gchar *path,
- gboolean is_directory)
-{
- GList *l;
- gchar *basename;
- gboolean ignore;
-
- if (tracker_is_empty_string (path)) {
- return TRUE;
- }
-
- if (!g_utf8_validate (path, -1, NULL)) {
- g_message ("Ignoring path:'%s', not valid UTF-8", path);
- return TRUE;
- }
-
- if (is_directory) {
- GSList *sl;
-
- /* Most common things to ignore */
- if (strcmp (path, "/dev") == 0 ||
- strcmp (path, "/lib") == 0 ||
- strcmp (path, "/proc") == 0 ||
- strcmp (path, "/sys") == 0) {
- return TRUE;
- }
-
- if (g_str_has_prefix (path, g_get_tmp_dir ())) {
- return TRUE;
- }
-
- /* Check ignored directories in config */
- for (sl = crawler->private->no_watch_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- return TRUE;
- }
- }
- }
-
- /* Check basename against pattern matches */
- basename = g_path_get_basename (path);
- ignore = TRUE;
-
- if (!basename) {
- goto done;
- }
-
- /* Test ignore types */
- if (is_directory) {
- GSList *sl;
-
- /* If directory begins with ".", check it isn't one of
- * the top level directories to watch/crawl if it
- * isn't we ignore it. If it is, we don't.
- */
- if (basename[0] == '.') {
- for (sl = crawler->private->watch_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- ignore = FALSE;
- goto done;
- }
- }
-
- for (sl = crawler->private->crawl_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- ignore = FALSE;
- goto done;
- }
- }
-
- goto done;
- }
-
- /* Check module directory ignore patterns */
- for (l = crawler->private->ignored_directory_patterns; l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
- } else {
- if (basename[0] == '.') {
- goto done;
- }
-
- /* Check module file ignore patterns */
- for (l = crawler->private->ignored_file_patterns; l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-
- /* Check module file match patterns */
- for (l = crawler->private->index_file_patterns; l; l = l->next) {
- if (!g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
- }
-
- ignore = FALSE;
-
-done:
- g_free (basename);
-
- return ignore;
-}
-
-#endif
-
static void
add_file (TrackerCrawler *crawler,
GFile *file)
@@ -531,89 +343,6 @@ process_func (gpointer data)
return TRUE;
}
-#ifdef FIX
- /* Process next path in list */
- if (!priv->paths_are_done) {
- /* This is done so we don't go over the list again
- * when we get to the end and the current item = NULL.
- */
- priv->paths_are_done = TRUE;
-
- if (!priv->paths_current) {
- priv->paths_current = priv->paths;
- }
- } else {
- if (priv->paths_current) {
- priv->paths_current = priv->paths_current->next;
- }
- }
-
- if (priv->paths_current) {
- g_message (" Searching directory:'%s'",
- (gchar*) priv->paths_current->data);
-
- file = g_file_new_for_path (priv->paths_current->data);
- add_directory (crawler, file);
- g_object_unref (file);
-
- return TRUE;
- }
-
- /* Process next recursive path in list */
- if (!priv->recurse_paths_are_done) {
- /* This is done so we don't go over the list again
- * when we get to the end and the current item = NULL.
- */
- priv->recurse_paths_are_done = TRUE;
-
- if (!priv->recurse_paths_current) {
- priv->recurse_paths_current = priv->recurse_paths;
- }
- } else {
- if (priv->recurse_paths_current) {
- priv->recurse_paths_current = priv->recurse_paths_current->next;
- }
- }
-
- if (priv->recurse_paths_current) {
- g_message (" Searching directory:'%s' (recursively)",
- (gchar *) priv->recurse_paths_current->data);
-
- file = g_file_new_for_path (priv->recurse_paths_current->data);
- add_directory (crawler, file);
- g_object_unref (file);
-
- return TRUE;
- }
-
- /* Process next special path in list */
- if (!priv->special_paths_are_done) {
- /* This is done so we don't go over the list again
- * when we get to the end and the current item = NULL.
- */
- priv->special_paths_are_done = TRUE;
-
- if (!priv->special_paths_current) {
- priv->special_paths_current = priv->special_paths;
- }
- } else {
- if (priv->special_paths_current) {
- priv->special_paths_current = priv->special_paths_current->next;
- }
- }
-
- if (priv->special_paths_current) {
- g_message (" Searching directory:'%s' (special)",
- (gchar *) priv->special_paths_current->data);
-
- file = g_file_new_for_path (priv->special_paths_current->data);
- add_directory (crawler, file);
- g_object_unref (file);
-
- return TRUE;
- }
-#endif
-
priv->idle_id = 0;
priv->is_finished = TRUE;
@@ -701,7 +430,7 @@ enumerator_data_process (EnumeratorData *ed)
g_hash_table_iter_init (&iter, ed->children);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cd)) {
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &cd)) {
if (cd->is_dir) {
add_directory (crawler, cd->child, FALSE);
} else {
@@ -725,7 +454,7 @@ file_enumerator_close_cb (GObject *enumerator,
gpointer user_data)
{
TrackerCrawler *crawler;
- GError *error = NULL;
+ GError *error = NULL;
crawler = TRACKER_CRAWLER (user_data);
crawler->private->enumerations--;
@@ -745,13 +474,13 @@ file_enumerate_next_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- TrackerCrawler *crawler;
- EnumeratorData *ed;
+ TrackerCrawler *crawler;
+ EnumeratorData *ed;
GFileEnumerator *enumerator;
- GFile *parent, *child;
- GFileInfo *info;
- GList *files, *l;
- GError *error = NULL;
+ GFile *parent, *child;
+ GFileInfo *info;
+ GList *files, *l;
+ GError *error = NULL;
enumerator = G_FILE_ENUMERATOR (object);
@@ -797,7 +526,7 @@ file_enumerate_next_cb (GObject *object,
child_name = g_file_info_get_name (info);
child = g_file_get_child (parent, child_name);
- is_dir = (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);
+ is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
enumerator_data_add_child (ed, child_name, child, is_dir);
@@ -828,14 +557,14 @@ file_enumerate_children_cb (GObject *file,
GAsyncResult *result,
gpointer user_data)
{
- TrackerCrawler *crawler;
- EnumeratorData *ed;
+ TrackerCrawler *crawler;
+ EnumeratorData *ed;
GFileEnumerator *enumerator;
- GFile *parent;
- GError *error = NULL;
+ GFile *parent;
+ GError *error = NULL;
parent = G_FILE (file);
- ed = (EnumeratorData *) user_data;
+ ed = (EnumeratorData*) user_data;
crawler = ed->crawler;
enumerator = g_file_enumerate_children_finish (parent, result, &error);
@@ -879,81 +608,6 @@ file_enumerate_children (TrackerCrawler *crawler,
ed);
}
-#ifdef FIX
-
-static GSList *
-prune_none_existing_gslist_paths (TrackerCrawler *crawler,
- GSList *paths,
- const gchar *path_type)
-{
- TrackerCrawlerPrivate *priv;
- GSList *new_paths = NULL;
-
- priv = crawler->private;
-
- if (paths) {
- GSList *l;
- GFile *file;
- gchar *path;
- gboolean exists;
-
- /* Check the currently set recurse paths are real */
- for (l = paths; l; l = l->next) {
- path = l->data;
-
- /* Check location exists before we do anything */
- file = g_file_new_for_path (path);
- exists = g_file_query_exists (file, NULL);
-
- if (exists) {
- g_message (" Directory:'%s' added to list to crawl exists %s%s%s",
- path,
- path_type ? "(" : "",
- path_type ? path_type : "",
- path_type ? ")" : "");
- new_paths = g_slist_prepend (new_paths, g_strdup (path));
- } else {
- g_message (" Directory:'%s' does not exist",
- path);
- }
-
- g_object_unref (file);
- }
-
- new_paths = g_slist_reverse (new_paths);
- }
-
- return new_paths;
-}
-
-static GSList *
-prune_none_existing_glist_paths (TrackerCrawler *crawler,
- GList *paths,
- const gchar *path_type)
-{
- GSList *temporary_paths;
- GSList *new_paths;
- GList *l;
-
- /* The only difference with this function is that it takes a
- * GList instead of a GSList.
- */
-
- temporary_paths = NULL;
-
- for (l = paths; l; l = l->next) {
- temporary_paths = g_slist_prepend (temporary_paths, l->data);
- }
-
- temporary_paths = g_slist_reverse (temporary_paths);
- new_paths = prune_none_existing_gslist_paths (crawler, temporary_paths, path_type);
- g_slist_free (temporary_paths);
-
- return new_paths;
-}
-
-#endif
-
gboolean
tracker_crawler_start (TrackerCrawler *crawler,
const gchar *path,
@@ -991,86 +645,6 @@ tracker_crawler_start (TrackerCrawler *crawler,
recurse ? "recursively" : "non-recursively",
path);
-#ifdef FIX
- if (priv->use_module_paths) {
- GSList *new_paths;
- GList *recurse_paths;
- GList *paths;
-
- g_message (" Using module paths");
-
- recurse_paths = tracker_module_config_get_monitor_recurse_directories ("files");
- paths = tracker_module_config_get_monitor_directories ("files");
-
- if (recurse_paths || paths) {
- /* First we do non-recursive directories */
- new_paths = prune_none_existing_glist_paths (crawler, paths, NULL);
- g_slist_foreach (priv->paths, (GFunc) g_free, NULL);
- g_slist_free (priv->paths);
- priv->paths = new_paths;
-
- /* Second we do recursive directories */
- new_paths = prune_none_existing_glist_paths (crawler, recurse_paths, "recursively");
- g_slist_foreach (priv->recurse_paths, (GFunc) g_free, NULL);
- g_slist_free (priv->recurse_paths);
- priv->recurse_paths = new_paths;
- } else {
- g_message (" No directories from module config");
- }
-
- g_list_free (paths);
- g_list_free (recurse_paths);
- } else {
- GSList *new_paths;
-
- g_message (" Not using module config paths, using special paths added");
-
- new_paths = prune_none_existing_gslist_paths (crawler, priv->special_paths, "special");
- g_slist_foreach (priv->special_paths, (GFunc) g_free, NULL);
- g_slist_free (priv->special_paths);
- priv->special_paths = new_paths;
- }
-
- if (!priv->paths && !priv->recurse_paths && !priv->special_paths) {
- g_message (" No directories that actually exist to iterate, doing nothing");
- return FALSE;
- }
-
- /* Filter duplicates */
- l = priv->paths;
- priv->paths = tracker_path_list_filter_duplicates (priv->paths, ".");
- g_slist_foreach (l, (GFunc) g_free, NULL);
- g_slist_free (l);
-
- l = priv->recurse_paths;
- priv->recurse_paths = tracker_path_list_filter_duplicates (priv->recurse_paths, ".");
- g_slist_foreach (l, (GFunc) g_free, NULL);
- g_slist_free (l);
-
- l = priv->special_paths;
- priv->special_paths = tracker_path_list_filter_duplicates (priv->special_paths, ".");
- g_slist_foreach (l, (GFunc) g_free, NULL);
- g_slist_free (l);
-
- /* Set up legacy NoWatchDirectoryRoots so we don't have to get
- * them from the config for EVERY file we traverse.
- */
- g_slist_foreach (priv->no_watch_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->no_watch_directory_roots);
- l = tracker_config_get_no_watch_directory_roots (priv->config);
- priv->no_watch_directory_roots = tracker_gslist_copy_with_string_data (l);
-
- g_slist_foreach (priv->watch_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->watch_directory_roots);
- l = tracker_config_get_watch_directory_roots (priv->config);
- priv->watch_directory_roots = tracker_gslist_copy_with_string_data (l);
-
- g_slist_foreach (priv->crawl_directory_roots, (GFunc) g_free, NULL);
- g_slist_free (priv->crawl_directory_roots);
- l = tracker_config_get_crawl_directory_roots (priv->config);
- priv->crawl_directory_roots = tracker_gslist_copy_with_string_data (l);
-#endif
-
/* Time the event */
if (priv->timer) {
g_timer_destroy (priv->timer);
@@ -1088,13 +662,6 @@ tracker_crawler_start (TrackerCrawler *crawler,
priv->files_found = 0;
priv->files_ignored = 0;
-#ifdef FIX
- /* Reset paths which have been iterated */
- priv->paths_are_done = FALSE;
- priv->recurse_paths_are_done = FALSE;
- priv->special_paths_are_done = FALSE;
-#endif
-
/* Set idle handler to process directories and files found */
priv->idle_id = g_idle_add (process_func, crawler);
@@ -1114,8 +681,7 @@ tracker_crawler_stop (TrackerCrawler *crawler)
priv = crawler->private;
-
- g_message (" %s crawling files in %4.4f seconds",
+ g_message ("%s crawling files in %4.4f seconds",
priv->is_finished ? "Finished" : "Stopped",
g_timer_elapsed (priv->timer, NULL));
g_message (" Found %d directories, ignored %d directories",
@@ -1143,123 +709,3 @@ tracker_crawler_stop (TrackerCrawler *crawler)
priv->files_found,
priv->files_ignored);
}
-
-#ifdef FIX
-
-/* This function is a convenience for the monitor module so we can
- * just ask it to crawl another path which we didn't know about
- * before.
- */
-void
-tracker_crawler_add_unexpected_path (TrackerCrawler *crawler,
- const gchar *path)
-{
- TrackerCrawlerPrivate *priv;
- GFile *file;
-
- g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
- g_return_if_fail (path != NULL);
-
- priv = crawler->private;
-
- /* This check should be fine, the reason being, that if we
- * call this, it is because we have received a monitor event
- * in the first place. This means we must already have been
- * started at some point.
- */
- g_return_if_fail (priv->was_started);
-
- /* FIXME: Should we check paths_are_done to see if we
- * need to actually call add_directory()?
- */
- file = g_file_new_for_path (path);
- add_directory (crawler, file);
- g_object_unref (file);
-
- /* FIXME: Should we reset the stats? */
- if (!priv->idle_id) {
- /* Time the event */
- if (priv->timer) {
- g_timer_destroy (priv->timer);
- }
-
- priv->timer = g_timer_new ();
-
- /* Set as running now */
- priv->is_running = TRUE;
- priv->is_finished = FALSE;
-
- /* Set idle handler to process directories and files found */
- priv->idle_id = g_idle_add (process_func, crawler);
- }
-}
-
-/* This is a convenience function to add extra locations because
- * sometimes we want to add locations like the MMC or others to the
- * "Files" module, for example.
- */
-void
-tracker_crawler_special_paths_add (TrackerCrawler *crawler,
- const gchar *path)
-{
- TrackerCrawlerPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
- g_return_if_fail (path != NULL);
-
- priv = crawler->private;
-
- g_return_if_fail (!priv->is_running);
-
- priv->special_paths = g_slist_append (priv->special_paths, g_strdup (path));
-}
-
-void
-tracker_crawler_special_paths_clear (TrackerCrawler *crawler)
-{
- TrackerCrawlerPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
-
- priv = crawler->private;
-
- g_return_if_fail (!priv->is_running);
-
- g_slist_foreach (priv->special_paths, (GFunc) g_free, NULL);
- g_slist_free (priv->special_paths);
- priv->special_paths = NULL;
-}
-
-void
-tracker_crawler_use_module_paths (TrackerCrawler *crawler,
- gboolean use_module_paths)
-{
- TrackerCrawlerPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
-
- priv = crawler->private;
-
- g_return_if_fail (priv->is_running == FALSE);
-
- priv->use_module_paths = use_module_paths;
-}
-
-gboolean
-tracker_crawler_is_path_ignored (TrackerCrawler *crawler,
- const gchar *path,
- gboolean is_directory)
-{
- g_return_val_if_fail (TRACKER_IS_CRAWLER (crawler), TRUE);
-
- /* We have an internal function here we call. The reason for
- * this is that it is expensive to type check the Crawler
- * object for EVERY file we process. Internally, we don't do
- * that. Externally we do. Externally this is used by the
- * processor when we get new monitor events to know if we
- * should be sending new files to the indexer.
- */
- return is_path_ignored (crawler, path, is_directory);
-}
-
-#endif
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index dc43dbf..6096988 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -32,25 +32,25 @@ G_BEGIN_DECLS
#define TRACKER_IS_CRAWLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_CRAWLER))
#define TRACKER_CRAWLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_CRAWLER, TrackerCrawlerClass))
-typedef struct _TrackerCrawler TrackerCrawler;
-typedef struct _TrackerCrawlerClass TrackerCrawlerClass;
-typedef struct _TrackerCrawlerPrivate TrackerCrawlerPrivate;
+typedef struct TrackerCrawler TrackerCrawler;
+typedef struct TrackerCrawlerClass TrackerCrawlerClass;
+typedef struct TrackerCrawlerPrivate TrackerCrawlerPrivate;
-struct _TrackerCrawler {
+struct TrackerCrawler {
GObject parent;
TrackerCrawlerPrivate *private;
};
-struct _TrackerCrawlerClass {
+struct TrackerCrawlerClass {
GObjectClass parent;
};
-GType tracker_crawler_get_type (void);
-TrackerCrawler *tracker_crawler_new (void);
-gboolean tracker_crawler_start (TrackerCrawler *crawler,
- const gchar *path,
- gboolean recurse);
-void tracker_crawler_stop (TrackerCrawler *crawler);
+GType tracker_crawler_get_type (void);
+TrackerCrawler *tracker_crawler_new (void);
+gboolean tracker_crawler_start (TrackerCrawler *crawler,
+ const gchar *path,
+ gboolean recurse);
+void tracker_crawler_stop (TrackerCrawler *crawler);
G_END_DECLS
diff --git a/src/libtracker-miner/tracker-main.c b/src/libtracker-miner/tracker-main.c
index 7729721..7c89a1e 100644
--- a/src/libtracker-miner/tracker-main.c
+++ b/src/libtracker-miner/tracker-main.c
@@ -28,7 +28,7 @@
#include "tracker-miner-test.h"
static void
-on_miner_terminated (TrackerMiner *miner,
+miner_terminated_cb (TrackerMiner *miner,
gpointer user_data)
{
GMainLoop *main_loop = user_data;
@@ -37,8 +37,10 @@ on_miner_terminated (TrackerMiner *miner,
}
static gboolean
-on_miner_start (TrackerMiner *miner)
+miner_start_cb (gpointer user_data)
{
+ TrackerMiner *miner = user_data;
+
g_message ("Starting miner");
tracker_miner_start (miner);
@@ -46,11 +48,10 @@ on_miner_start (TrackerMiner *miner)
}
static gboolean
-check_dir_cb (TrackerProcessor *processor,
- GFile *file,
- gpointer user_data)
+check_directory_cb (TrackerProcessor *processor,
+ GFile *file,
+ gpointer user_data)
{
- GSList *sl;
gchar *path;
gchar *basename;
gboolean should_process;
@@ -81,14 +82,6 @@ check_dir_cb (TrackerProcessor *processor,
}
/* Check ignored directories in config */
-#ifdef FIX
- for (sl = crawler->private->no_watch_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- goto done;
- }
- }
-#endif
-
basename = g_file_get_basename (file);
if (!basename) {
@@ -100,33 +93,10 @@ check_dir_cb (TrackerProcessor *processor,
* isn't we ignore it. If it is, we don't.
*/
if (basename[0] == '.') {
-#ifdef FIX
- for (sl = crawler->private->watch_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- should_process = TRUE;
- goto done;
- }
- }
-
- for (sl = crawler->private->crawl_directory_roots; sl; sl = sl->next) {
- if (strcmp (sl->data, path) == 0) {
- should_process = TRUE;
- goto done;
- }
- }
-#endif
goto done;
}
/* Check module directory ignore patterns */
-#ifdef FIX
- for (l = crawler->private->ignored_directory_patterns; l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-#endif
-
should_process = TRUE;
done:
@@ -141,7 +111,6 @@ check_file_cb (TrackerProcessor *processor,
GFile *file,
gpointer user_data)
{
- GList *l;
gchar *path;
gchar *basename;
gboolean should_process;
@@ -166,22 +135,6 @@ check_file_cb (TrackerProcessor *processor,
goto done;
}
-#ifdef FIX
- /* Check module file ignore patterns */
- for (l = crawler->private->ignored_file_patterns; l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-
- /* Check module file match patterns */
- for (l = crawler->private->index_file_patterns; l; l = l->next) {
- if (!g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-#endif
-
should_process = TRUE;
done:
@@ -196,17 +149,17 @@ process_file_cb (TrackerProcessor *processor,
GFile *file,
gpointer user_data)
{
- gchar *path;
+ /* gchar *path; */
- path = g_file_get_path (file);
- g_print ("** PROCESSING FILE:'%s'\n", path);
- g_free (path);
+ /* path = g_file_get_path (file); */
+ /* g_print ("** PROCESSING FILE:'%s'\n", path); */
+ /* g_free (path); */
}
static gboolean
-monitor_dir_cb (TrackerProcessor *processor,
- GFile *file,
- gpointer user_data)
+monitor_directory_cb (TrackerProcessor *processor,
+ GFile *file,
+ gpointer user_data)
{
return TRUE;
}
@@ -230,26 +183,51 @@ main (int argc, char *argv[])
g_signal_connect (TRACKER_PROCESSOR (miner), "check-file",
G_CALLBACK (check_file_cb),
NULL);
- g_signal_connect (TRACKER_PROCESSOR (miner), "check-dir",
- G_CALLBACK (check_dir_cb),
+ g_signal_connect (TRACKER_PROCESSOR (miner), "check-directory",
+ G_CALLBACK (check_directory_cb),
NULL);
g_signal_connect (TRACKER_PROCESSOR (miner), "process-file",
G_CALLBACK (process_file_cb),
NULL);
- g_signal_connect (TRACKER_PROCESSOR (miner), "monitor-dir",
- G_CALLBACK (monitor_dir_cb),
+ g_signal_connect (TRACKER_PROCESSOR (miner), "monitor-directory",
+ G_CALLBACK (monitor_directory_cb),
NULL);
tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
g_get_home_dir (),
FALSE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_tmp_dir (),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_current_dir (),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD),
+ FALSE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
+ TRUE);
+ tracker_processor_add_directory (TRACKER_PROCESSOR (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
+ TRUE);
g_signal_connect (miner, "terminated",
- G_CALLBACK (on_miner_terminated), main_loop);
-
- g_timeout_add_seconds (1, (GSourceFunc) on_miner_start, miner);
+ G_CALLBACK (miner_terminated_cb),
+ main_loop);
+ g_timeout_add_seconds (1, miner_start_cb, miner);
g_main_loop_run (main_loop);
+ g_object_unref (main_loop);
return EXIT_SUCCESS;
}
diff --git a/src/libtracker-miner/tracker-monitor.c b/src/libtracker-miner/tracker-monitor.c
index 7d273d9..d9dfa23 100644
--- a/src/libtracker-miner/tracker-monitor.c
+++ b/src/libtracker-miner/tracker-monitor.c
@@ -50,7 +50,7 @@
*/
#undef PAUSE_ON_IO
-struct _TrackerMonitorPrivate {
+struct TrackerMonitorPrivate {
GHashTable *monitors;
gboolean enabled;
diff --git a/src/libtracker-miner/tracker-monitor.h b/src/libtracker-miner/tracker-monitor.h
index af5b2b0..4132179 100644
--- a/src/libtracker-miner/tracker-monitor.h
+++ b/src/libtracker-miner/tracker-monitor.h
@@ -34,17 +34,17 @@ G_BEGIN_DECLS
#define TRACKER_IS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_MONITOR))
#define TRACKER_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_MONITOR, TrackerMonitorClass))
-typedef struct _TrackerMonitor TrackerMonitor;
-typedef struct _TrackerMonitorClass TrackerMonitorClass;
-typedef struct _TrackerMonitorPrivate TrackerMonitorPrivate;
+typedef struct TrackerMonitor TrackerMonitor;
+typedef struct TrackerMonitorClass TrackerMonitorClass;
+typedef struct TrackerMonitorPrivate TrackerMonitorPrivate;
-struct _TrackerMonitor {
- GObject parent;
+struct TrackerMonitor {
+ GObject parent;
TrackerMonitorPrivate *private;
};
-struct _TrackerMonitorClass {
- GObjectClass parent;
+struct TrackerMonitorClass {
+ GObjectClass parent;
};
GType tracker_monitor_get_type (void);
diff --git a/src/libtracker-miner/tracker-processor.c b/src/libtracker-miner/tracker-processor.c
index 86145b2..dd135fb 100644
--- a/src/libtracker-miner/tracker-processor.c
+++ b/src/libtracker-miner/tracker-processor.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2008, Nokia
+ * Copyright (C) 2009, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -51,7 +51,9 @@ struct TrackerProcessorPrivate {
GQueue *items_deleted;
GQueue *items_moved;
- GArray *dirs;
+ GList *directories;
+ GList *current_directory;
+
GList *devices;
GList *current_device;
@@ -61,7 +63,7 @@ struct TrackerProcessorPrivate {
gboolean been_started;
gboolean interrupted;
- gboolean finished_files;
+ gboolean finished_directories;
gboolean finished_devices;
gboolean finished_sending;
gboolean finished_indexer;
@@ -81,51 +83,59 @@ struct TrackerProcessorPrivate {
typedef struct {
gchar *path;
gboolean recurse;
-} DirData;
+} DirectoryData;
enum {
CHECK_FILE,
- CHECK_DIR,
+ CHECK_DIRECTORY,
PROCESS_FILE,
- MONITOR_DIR,
+ MONITOR_DIRECTORY,
FINISHED,
LAST_SIGNAL
};
-static void processor_finalize (GObject *object);
-static gboolean processor_defaults (TrackerProcessor *processor,
- GFile *file);
-static void processor_started (TrackerMiner *miner);
-static void monitor_item_created_cb (TrackerMonitor *monitor,
- GFile *file,
- gboolean is_directory,
- gpointer user_data);
-static void monitor_item_updated_cb (TrackerMonitor *monitor,
- GFile *file,
- gboolean is_directory,
- gpointer user_data);
-static void monitor_item_deleted_cb (TrackerMonitor *monitor,
- GFile *file,
- gboolean is_directory,
- gpointer user_data);
-static void monitor_item_moved_cb (TrackerMonitor *monitor,
- GFile *file,
- GFile *other_file,
- gboolean is_directory,
- gboolean is_source_monitored,
- gpointer user_data);
-static gboolean crawler_process_file_cb (TrackerCrawler *crawler,
- GFile *file,
- gpointer user_data);
-static gboolean crawler_process_directory_cb (TrackerCrawler *crawler,
- GFile *file,
- gpointer user_data);
-static void crawler_finished_cb (TrackerCrawler *crawler,
- guint directories_found,
- guint directories_ignored,
- guint files_found,
- guint files_ignored,
- gpointer user_data);
+static void processor_finalize (GObject *object);
+static gboolean processor_defaults (TrackerProcessor *processor,
+ GFile *file);
+static void miner_started (TrackerMiner *miner);
+static DirectoryData *directory_data_new (const gchar *path,
+ gboolean recurse);
+static void directory_data_free (DirectoryData *dd);
+static void monitor_item_created_cb (TrackerMonitor *monitor,
+ GFile *file,
+ gboolean is_directory,
+ gpointer user_data);
+static void monitor_item_updated_cb (TrackerMonitor *monitor,
+ GFile *file,
+ gboolean is_directory,
+ gpointer user_data);
+static void monitor_item_deleted_cb (TrackerMonitor *monitor,
+ GFile *file,
+ gboolean is_directory,
+ gpointer user_data);
+static void monitor_item_moved_cb (TrackerMonitor *monitor,
+ GFile *file,
+ GFile *other_file,
+ gboolean is_directory,
+ gboolean is_source_monitored,
+ gpointer user_data);
+static gboolean crawler_process_file_cb (TrackerCrawler *crawler,
+ GFile *file,
+ gpointer user_data);
+static gboolean crawler_process_directory_cb (TrackerCrawler *crawler,
+ GFile *file,
+ gpointer user_data);
+static void crawler_finished_cb (TrackerCrawler *crawler,
+ guint directories_found,
+ guint directories_ignored,
+ guint files_found,
+ guint files_ignored,
+ gpointer user_data);
+static void process_continue (TrackerProcessor *processor);
+static void process_next (TrackerProcessor *processor);
+static void process_directories_next (TrackerProcessor *processor);
+static void process_directories_start (TrackerProcessor *processor);
+static void process_directories_stop (TrackerProcessor *processor);
static guint signals[LAST_SIGNAL] = { 0, };
@@ -141,18 +151,18 @@ tracker_processor_class_init (TrackerProcessorClass *klass)
object_class->finalize = processor_finalize;
if (0) {
- processor_class->check_file = processor_defaults;
- processor_class->check_dir = processor_defaults;
- processor_class->monitor_dir = processor_defaults;
+ processor_class->check_file = processor_defaults;
+ processor_class->check_directory = processor_defaults;
+ processor_class->monitor_directory = processor_defaults;
}
- miner_class->started = processor_started;
+ miner_class->started = miner_started;
+
/*
miner_class->stopped = miner_crawler_stopped;
miner_class->paused = miner_crawler_paused;
miner_class->resumed = miner_crawler_resumed;
*/
-
signals[CHECK_FILE] =
g_signal_new ("check-file",
@@ -162,11 +172,11 @@ tracker_processor_class_init (TrackerProcessorClass *klass)
NULL, NULL,
tracker_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1, G_TYPE_FILE);
- signals[CHECK_DIR] =
- g_signal_new ("check-dir",
+ signals[CHECK_DIRECTORY] =
+ g_signal_new ("check-directory",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (TrackerProcessorClass, check_dir),
+ G_STRUCT_OFFSET (TrackerProcessorClass, check_directory),
NULL, NULL,
tracker_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1, G_TYPE_FILE);
@@ -178,22 +188,27 @@ tracker_processor_class_init (TrackerProcessorClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_FILE);
- signals[MONITOR_DIR] =
- g_signal_new ("monitor-dir",
+ signals[MONITOR_DIRECTORY] =
+ g_signal_new ("monitor-directory",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (TrackerProcessorClass, monitor_dir),
+ G_STRUCT_OFFSET (TrackerProcessorClass, monitor_directory),
NULL, NULL,
tracker_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1, G_TYPE_FILE);
signals[FINISHED] =
g_signal_new ("finished",
- G_OBJECT_CLASS_TYPE (object_class),
+ G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TrackerProcessorClass, finished),
NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ tracker_marshal_VOID__UINT_UINT_UINT_UINT,
+ G_TYPE_NONE,
+ 4,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_UINT);
g_type_class_add_private (object_class, sizeof (TrackerProcessorPrivate));
}
@@ -216,8 +231,6 @@ tracker_processor_init (TrackerProcessor *object)
priv->items_deleted = g_queue_new ();
priv->items_moved = g_queue_new ();
- priv->dirs = g_array_new (FALSE, TRUE, sizeof (DirData));
-
/* Set up the crawlers now we have config and hal */
priv->crawler = tracker_crawler_new ();
@@ -311,17 +324,9 @@ processor_finalize (GObject *object)
g_object_unref (priv->monitor);
}
- if (priv->dirs) {
- gint i;
-
- for (i = 0; i < priv->dirs->len; i++) {
- DirData dd;
-
- dd = g_array_index (priv->dirs, DirData, i);
- g_free (dd.path);
- }
-
- g_array_free (priv->dirs, TRUE);
+ if (priv->directories) {
+ g_list_foreach (priv->directories, (GFunc) directory_data_free, NULL);
+ g_list_free (priv->directories);
}
g_queue_foreach (priv->items_moved, (GFunc) g_object_unref, NULL);
@@ -354,10 +359,9 @@ processor_defaults (TrackerProcessor *processor,
}
static void
-processor_started (TrackerMiner *miner)
+miner_started (TrackerMiner *miner)
{
TrackerProcessor *processor;
- gint i;
processor = TRACKER_PROCESSOR (miner);
@@ -365,31 +369,37 @@ processor_started (TrackerMiner *miner)
processor->private->interrupted = FALSE;
- processor->private->finished_files = FALSE;
+ processor->private->finished_directories = FALSE;
processor->private->finished_devices = FALSE;
processor->private->finished_sending = FALSE;
processor->private->finished_indexer = FALSE;
- /* Go through dirs and crawl */
- if (!processor->private->dirs) {
- g_message ("No directories set up for processor to handle, doing nothing");
- return;
- }
+ process_next (processor);
+}
- for (i = 0; i < processor->private->dirs->len; i++) {
- DirData dd;
-
- dd = g_array_index (processor->private->dirs, DirData, i);
+static DirectoryData *
+directory_data_new (const gchar *path,
+ gboolean recurse)
+{
+ DirectoryData *dd;
- tracker_crawler_start (processor->private->crawler,
- dd.path,
- dd.recurse);
- }
+ dd = g_slice_new (DirectoryData);
+ dd->path = g_strdup (path);
+ dd->recurse = recurse;
-#if 0
- process_next (processor);
-#endif
+ return dd;
+}
+
+static void
+directory_data_free (DirectoryData *dd)
+{
+ if (!dd) {
+ return;
+ }
+
+ g_free (dd->path);
+ g_slice_free (DirectoryData, dd);
}
static gboolean
@@ -476,6 +486,14 @@ monitor_item_created_cb (TrackerMonitor *monitor,
if (should_process) {
if (is_directory) {
+ gboolean add_monitor = TRUE;
+
+ g_signal_emit (processor, signals[MONITOR_DIRECTORY], 0, file, &add_monitor);
+
+ if (add_monitor) {
+ tracker_monitor_add (processor->private->monitor, file);
+ }
+
#ifdef FIX
tracker_crawler_add_unexpected_path (processor->private->crawler, path);
#endif
@@ -565,9 +583,10 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
if (!is_source_monitored) {
gchar *path;
- /* If the source is not monitored, we need to crawl it. */
path = g_file_get_path (other_file);
+
#ifdef FIX
+ /* If the source is not monitored, we need to crawl it. */
tracker_crawler_add_unexpected_path (processor->private->crawler, path);
#endif
g_free (path);
@@ -599,12 +618,20 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
g_object_ref (other_file));
item_queue_handlers_set_up (processor);
- }
-
- /* If this is a directory we need to crawl it */
+ } else {
+ gboolean add_monitor = TRUE;
+
+ g_signal_emit (processor, signals[MONITOR_DIRECTORY], 0, file, &add_monitor);
+
+ if (add_monitor) {
+ tracker_monitor_add (processor->private->monitor, file);
+ }
+
#ifdef FIX
- tracker_crawler_add_unexpected_path (processor->private->crawler, other_path);
+ /* If this is a directory we need to crawl it */
+ tracker_crawler_add_unexpected_path (processor->private->crawler, other_path);
#endif
+ }
} else if (!should_process_other) {
/* Delete old file */
g_queue_push_tail (processor->private->items_deleted, g_object_ref (file));
@@ -656,7 +683,7 @@ crawler_process_directory_cb (TrackerCrawler *crawler,
processor = user_data;
- g_signal_emit (processor, signals[CHECK_DIR], 0, file, &should_process);
+ g_signal_emit (processor, signals[CHECK_DIRECTORY], 0, file, &should_process);
if (should_process) {
/* FIXME: Do we add directories to the queue? */
@@ -666,7 +693,7 @@ crawler_process_directory_cb (TrackerCrawler *crawler,
item_queue_handlers_set_up (processor);
}
- g_signal_emit (processor, signals[MONITOR_DIR], 0, file, &add_monitor);
+ g_signal_emit (processor, signals[MONITOR_DIRECTORY], 0, file, &add_monitor);
/* Should we add? */
if (add_monitor) {
@@ -700,71 +727,172 @@ crawler_finished_cb (TrackerCrawler *crawler,
processor->private->total_files_ignored += files_ignored;
/* Proceed to next thing to process */
- /* process_continue (processor); */
+ process_continue (processor);
}
-TrackerProcessor *
-tracker_processor_new (TrackerStorage *storage)
+static void
+process_continue (TrackerProcessor *processor)
{
- TrackerProcessor *processor;
- TrackerProcessorPrivate *priv;
+ if (!processor->private->finished_directories) {
+ process_directories_next (processor);
+ return;
+ }
-#ifdef HAVE_HAL
- g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL);
-#endif /* HAVE_HAL */
+#if 0
+ if (!processor->private->finished_devices) {
+ process_device_next (processor);
+ return;
+ }
+#endif
- /* tracker_status_init (NULL, tracker_power_new ()); */
- tracker_module_config_init ();
+ /* Nothing to do */
+}
- /* tracker_status_set_and_signal (TRACKER_STATUS_INITIALIZING); */
+static void
+process_next (TrackerProcessor *processor)
+{
+ static gboolean shown_totals = FALSE;
- processor = g_object_new (TRACKER_TYPE_PROCESSOR, NULL);
- priv = processor->private;
+ if (!processor->private->finished_directories) {
+ process_directories_start (processor);
+ return;
+ }
-#ifdef HAVE_HAL
- /* Set up hal */
- priv->hal = g_object_ref (storage);
+#if 0
+ if (!processor->private->finished_devices) {
+ process_devices_start (processor);
+ return;
+ }
+#endif
+
+ /* Only do this the first time, otherwise the results are
+ * likely to be inaccurate. Devices can be added or removed so
+ * we can't assume stats are correct.
+ */
+ if (!shown_totals) {
+ shown_totals = TRUE;
+
+ g_message ("--------------------------------------------------");
+ g_message ("Total directories : %d (%d ignored)",
+ processor->private->total_directories_found,
+ processor->private->total_directories_ignored);
+ g_message ("Total files : %d (%d ignored)",
+ processor->private->total_files_found,
+ processor->private->total_files_ignored);
+ g_message ("Total monitors : %d",
+ tracker_monitor_get_count (processor->private->monitor));
+ g_message ("--------------------------------------------------\n");
+ }
- priv->devices = tracker_storage_get_removable_device_roots (priv->hal);
+ /* Now we have finished crawling, we enable monitor events */
+ g_message ("Enabling monitor events");
+ tracker_monitor_set_enabled (processor->private->monitor, TRUE);
+}
-#endif /* HAVE_HAL */
+static void
+process_directories_next (TrackerProcessor *processor)
+{
+ DirectoryData *dd;
+ /* Don't recursively iterate the modules */
+ if (!processor->private->current_directory) {
+ if (!processor->private->finished_directories) {
+ processor->private->current_directory = processor->private->directories;
+ }
+ } else {
+ processor->private->current_directory = processor->private->current_directory->next;
+ }
-#if 0
- /* Set up the indexer and signalling to know when we are
- * finished.
- */
+ /* If we have no further modules to iterate */
+ if (!processor->private->current_directory) {
+ process_directories_stop (processor);
+ process_next (processor);
+ return;
+ }
- g_signal_connect (priv->indexer, "started",
- G_CALLBACK (indexer_started_cb),
- processor);
- g_signal_connect (priv->indexer, "finished",
- G_CALLBACK (indexer_finished_cb),
- processor);
-#endif
+ dd = processor->private->current_directory->data;
- return processor;
+ tracker_crawler_start (processor->private->crawler,
+ dd->path,
+ dd->recurse);
}
-void
-tracker_processor_stop (TrackerProcessor *processor)
+static void
+process_directories_start (TrackerProcessor *processor)
{
-#if 0
- g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
+ g_message ("Processor is starting to iterating directories");
- if (!processor->private->been_started) {
+ /* Go through dirs and crawl */
+ if (!processor->private->directories) {
+ g_message ("No directories set up for processor to handle, doing nothing");
+ return;
+ }
+
+ if (processor->private->timer) {
+ g_timer_destroy (processor->private->timer);
+ }
+
+ processor->private->timer = g_timer_new ();
+
+ processor->private->finished_directories = FALSE;
+
+ processor->private->directories_found = 0;
+ processor->private->directories_ignored = 0;
+ processor->private->files_found = 0;
+ processor->private->files_ignored = 0;
+
+ process_directories_next (processor);
+}
+
+static void
+process_directories_stop (TrackerProcessor *processor)
+{
+ if (processor->private->finished_directories) {
return;
}
- processor->private->interrupted = TRUE;
+ g_message ("--------------------------------------------------");
+ g_message ("Processor has %s iterating files",
+ processor->private->interrupted ? "been stopped while" : "finished");
+
+ processor->private->finished_directories = TRUE;
+
+ if (processor->private->interrupted) {
+ if (processor->private->crawler) {
+ tracker_crawler_stop (processor->private->crawler);
+ }
- process_files_stop (processor);
- process_devices_stop (processor);
+ if (processor->private->timer) {
+ g_timer_destroy (processor->private->timer);
+ processor->private->timer = NULL;
+ }
+ } else {
+ gdouble elapsed;
- /* Queues? */
+ if (processor->private->timer) {
+ g_timer_stop (processor->private->timer);
+ elapsed = g_timer_elapsed (processor->private->timer, NULL);
+ } else {
+ elapsed = 0;
+ }
+
+ g_message ("FS time taken : %4.4f seconds",
+ elapsed);
+ g_message ("FS directories: %d (%d ignored)",
+ processor->private->directories_found,
+ processor->private->directories_ignored);
+ g_message ("FS files : %d (%d ignored)",
+ processor->private->files_found,
+ processor->private->files_ignored);
+ }
- process_finish (processor);
-#endif
+ g_message ("--------------------------------------------------\n");
+
+ g_signal_emit (processor, signals[FINISHED], 0,
+ processor->private->total_directories_found,
+ processor->private->total_directories_ignored,
+ processor->private->total_files_found,
+ processor->private->total_files_ignored);
}
void
@@ -772,13 +900,12 @@ tracker_processor_add_directory (TrackerProcessor *processor,
const gchar *path,
gboolean recurse)
{
- DirData dd;
-
g_return_if_fail (TRACKER_IS_PROCESSOR (processor));
g_return_if_fail (path != NULL);
- dd.path = g_strdup (path);
- dd.recurse = recurse;
+ /* WHAT HAPPENS IF WE ADD DURING OPERATION ? */
- g_array_append_val (processor->private->dirs, dd);
+ processor->private->directories =
+ g_list_append (processor->private->directories,
+ directory_data_new (path, recurse));
}
diff --git a/src/libtracker-miner/tracker-processor.h b/src/libtracker-miner/tracker-processor.h
index fd3a6db..db74367 100644
--- a/src/libtracker-miner/tracker-processor.h
+++ b/src/libtracker-miner/tracker-processor.h
@@ -42,33 +42,29 @@ typedef struct TrackerProcessorClass TrackerProcessorClass;
typedef struct TrackerProcessorPrivate TrackerProcessorPrivate;
struct TrackerProcessor {
- TrackerMiner parent_instance;
+ TrackerMiner parent;
TrackerProcessorPrivate *private;
};
struct TrackerProcessorClass {
- TrackerMinerClass parent_class;
-
- gboolean (* check_file) (TrackerProcessor *processor,
- GFile *file);
- gboolean (* check_dir) (TrackerProcessor *processor,
- GFile *file);
- void (* process_file) (TrackerProcessor *processor,
- GFile *file);
- gboolean (* monitor_dir) (TrackerProcessor *processor,
- GFile *file);
-
- void (* finished) (TrackerProcessor *processor);
+ TrackerMinerClass parent;
+
+ gboolean (* check_file) (TrackerProcessor *processor,
+ GFile *file);
+ gboolean (* check_directory) (TrackerProcessor *processor,
+ GFile *file);
+ void (* process_file) (TrackerProcessor *processor,
+ GFile *file);
+ gboolean (* monitor_directory) (TrackerProcessor *processor,
+ GFile *file);
+
+ void (* finished) (TrackerProcessor *processor);
};
-GType tracker_processor_get_type (void) G_GNUC_CONST;
-
-TrackerProcessor *tracker_processor_new (TrackerStorage *storage);
-
-void tracker_processor_stop (TrackerProcessor *processor);
-void tracker_processor_add_directory (TrackerProcessor *processor,
- const gchar *path,
- gboolean recurse);
+GType tracker_processor_get_type (void) G_GNUC_CONST;
+void tracker_processor_add_directory (TrackerProcessor *processor,
+ const gchar *path,
+ gboolean recurse);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]