[tracker] tracker-miner-fs: Improved feature to update indexed paths in realtime
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] tracker-miner-fs: Improved feature to update indexed paths in realtime
- Date: Tue, 9 Feb 2010 23:11:10 +0000 (UTC)
commit 90409dfeb2ff648329f175741d51c979aeb8cad1
Author: Martyn Russell <martyn lanedo com>
Date: Wed Feb 10 00:08:15 2010 +0100
tracker-miner-fs: Improved feature to update indexed paths in realtime
This does several things:
- Avoids the TrackerConfig for the object notify if the list data
hasn't actually changed.
- Allow tracker_keyfile_object_load_string_list() to return the list
instead of use it with g_object_set().
- Don't load defaults into config everytime we reload, only
initially.
- Directories are removed from list of dirs when indexed, so we now
keep a list of config specified directories to index so we have a
real list to compare to when the config updates (previously the
old list was NULL if indexing was complete leading to a reindex of
ALL locations because the list was different).
- Don't notify about the index-{recursive|single}-directories twice.
This happened because we loaded the config into the GObject and
then did post processing on the &DESKTOP and other special values
which re-set the value in TrackerConfig.
src/libtracker-common/tracker-keyfile-object.c | 31 ++++---
src/libtracker-common/tracker-keyfile-object.h | 101 ++++++++++----------
src/tracker-miner-fs/tracker-config.c | 109 +++++++++++++++++-----
src/tracker-miner-fs/tracker-miner-files.c | 117 +++++++++++++++---------
4 files changed, 227 insertions(+), 131 deletions(-)
---
diff --git a/src/libtracker-common/tracker-keyfile-object.c b/src/libtracker-common/tracker-keyfile-object.c
index 1098c2e..25ec528 100644
--- a/src/libtracker-common/tracker-keyfile-object.c
+++ b/src/libtracker-common/tracker-keyfile-object.c
@@ -195,10 +195,10 @@ tracker_keyfile_object_load_boolean (gpointer object,
void
tracker_keyfile_object_load_string (gpointer object,
- const gchar *property,
+ const gchar *property,
GKeyFile *key_file,
- const gchar *group,
- const gchar *key)
+ const gchar *group,
+ const gchar *key)
{
GError *error = NULL;
gchar *value;
@@ -222,12 +222,13 @@ tracker_keyfile_object_load_string (gpointer object,
}
void
-tracker_keyfile_object_load_string_list (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key,
- gboolean is_directory_list)
+tracker_keyfile_object_load_string_list (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key,
+ gboolean is_directory_list,
+ GSList **return_instead)
{
GSList *l;
gchar **value;
@@ -260,11 +261,15 @@ tracker_keyfile_object_load_string_list (gpointer object,
}
g_strfreev (value);
- g_object_set (G_OBJECT (object), property, l, NULL);
+ if (G_LIKELY (!return_instead)) {
+ g_object_set (G_OBJECT (object), property, l, NULL);
- /* List is copied internally */
- g_slist_foreach (l, (GFunc) g_free, NULL);
- g_slist_free (l);
+ /* List is copied internally */
+ g_slist_foreach (l, (GFunc) g_free, NULL);
+ g_slist_free (l);
+ } else {
+ *return_instead = l;
+ }
}
void
diff --git a/src/libtracker-common/tracker-keyfile-object.h b/src/libtracker-common/tracker-keyfile-object.h
index 96885ba..6ad6b11 100644
--- a/src/libtracker-common/tracker-keyfile-object.h
+++ b/src/libtracker-common/tracker-keyfile-object.h
@@ -28,56 +28,57 @@ G_BEGIN_DECLS
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
-const gchar *tracker_keyfile_object_blurb (gpointer object,
- const gchar *property);
-gboolean tracker_keyfile_object_default_boolean (gpointer object,
- const gchar *property);
-gint tracker_keyfile_object_default_int (gpointer object,
- const gchar *property);
-gboolean tracker_keyfile_object_validate_int (gpointer object,
- const gchar *property,
- gint value);
-void tracker_keyfile_object_load_int (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_load_boolean (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_load_string (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_load_string_list (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key,
- gboolean is_directory_list);
-void tracker_keyfile_object_save_int (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_save_boolean (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_save_string (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
-void tracker_keyfile_object_save_string_list (gpointer object,
- const gchar *property,
- GKeyFile *key_file,
- const gchar *group,
- const gchar *key);
+const gchar *tracker_keyfile_object_blurb (gpointer object,
+ const gchar *property);
+gboolean tracker_keyfile_object_default_boolean (gpointer object,
+ const gchar *property);
+gint tracker_keyfile_object_default_int (gpointer object,
+ const gchar *property);
+gboolean tracker_keyfile_object_validate_int (gpointer object,
+ const gchar *property,
+ gint value);
+void tracker_keyfile_object_load_int (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_load_boolean (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_load_string (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_load_string_list (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key,
+ gboolean is_directory_list,
+ GSList **return_instead);
+void tracker_keyfile_object_save_int (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_save_boolean (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_save_string (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
+void tracker_keyfile_object_save_string_list (gpointer object,
+ const gchar *property,
+ GKeyFile *key_file,
+ const gchar *group,
+ const gchar *key);
G_END_DECLS
diff --git a/src/tracker-miner-fs/tracker-config.c b/src/tracker-miner-fs/tracker-config.c
index 4161e3e..34e3cb7 100644
--- a/src/tracker-miner-fs/tracker-config.c
+++ b/src/tracker-miner-fs/tracker-config.c
@@ -99,7 +99,8 @@ static void config_get_property (GObject *object,
static void config_finalize (GObject *object);
static void config_constructed (GObject *object);
static void config_changed (TrackerConfigFile *file);
-static void config_load (TrackerConfig *config);
+static void config_load (TrackerConfig *config,
+ gboolean use_defaults);
static gboolean config_save (TrackerConfig *config);
static void config_create_with_defaults (TrackerConfig *config,
GKeyFile *key_file,
@@ -518,14 +519,14 @@ config_constructed (GObject *object)
{
(G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
- config_load (TRACKER_CONFIG (object));
+ config_load (TRACKER_CONFIG (object), TRUE);
}
static void
config_changed (TrackerConfigFile *file)
{
/* Reload config */
- config_load (TRACKER_CONFIG (file));
+ config_load (TRACKER_CONFIG (file), FALSE);
}
static void
@@ -805,13 +806,17 @@ config_set_ignored_directory_conveniences (TrackerConfig *config)
}
static void
-config_load (TrackerConfig *config)
+config_load (TrackerConfig *config,
+ gboolean use_defaults)
{
TrackerConfigFile *file;
gint i;
file = TRACKER_CONFIG_FILE (config);
- config_create_with_defaults (config, file->key_file, FALSE);
+
+ if (use_defaults) {
+ config_create_with_defaults (config, file->key_file, FALSE);
+ }
if (!file->file_exists) {
tracker_config_file_save (file);
@@ -844,26 +849,34 @@ config_load (TrackerConfig *config)
break;
case G_TYPE_POINTER: {
- GSList *dirs, *l;
+ GSList *new_dirs, *old_dirs, *l;
gboolean check_for_duplicates = FALSE;
+ gboolean equal;
is_directory_list = TRUE;
- tracker_keyfile_object_load_string_list (G_OBJECT (file),
- conversions[i].property,
- file->key_file,
- conversions[i].group,
- conversions[i].key,
- is_directory_list);
-
if (strcmp (conversions[i].property, "index-recursive-directories") != 0 &&
strcmp (conversions[i].property, "index-single-directories") != 0) {
- continue;
+ tracker_keyfile_object_load_string_list (G_OBJECT (file),
+ conversions[i].property,
+ file->key_file,
+ conversions[i].group,
+ conversions[i].key,
+ is_directory_list,
+ NULL);
+ continue;
}
- g_object_get (config, conversions[i].property, &dirs, NULL);
+ tracker_keyfile_object_load_string_list (G_OBJECT (file),
+ conversions[i].property,
+ file->key_file,
+ conversions[i].group,
+ conversions[i].key,
+ is_directory_list,
+ &new_dirs);
+ g_object_get (config, conversions[i].property, &old_dirs, NULL);
- for (l = dirs; l; l = l->next) {
+ for (l = new_dirs; l; l = l->next) {
const gchar *path_to_use;
/* Must be a special dir */
@@ -897,12 +910,21 @@ config_load (TrackerConfig *config)
if (check_for_duplicates) {
GSList *filtered;
- filtered = tracker_path_list_filter_duplicates (dirs, ".");
- g_object_set (config, conversions[i].property, filtered, NULL);
+ filtered = tracker_path_list_filter_duplicates (new_dirs, ".");
+ g_slist_foreach (new_dirs, (GFunc) g_free, NULL);
+ g_slist_free (new_dirs);
- g_slist_foreach (filtered, (GFunc) g_free, NULL);
- g_slist_free (filtered);
- }
+ new_dirs = filtered;
+ }
+
+ equal = tracker_gslist_with_string_data_equal (new_dirs, old_dirs);
+
+ if (!equal) {
+ g_object_set (config, conversions[i].property, new_dirs, NULL);
+ }
+
+ g_slist_foreach (new_dirs, (GFunc) g_free, NULL);
+ g_slist_free (new_dirs);
break;
}
@@ -1407,7 +1429,8 @@ tracker_config_set_index_recursive_directories (TrackerConfig *config,
GSList *roots)
{
TrackerConfigPrivate *priv;
- GSList *l;
+ GSList *l;
+ gboolean equal;
g_return_if_fail (TRACKER_IS_CONFIG (config));
@@ -1415,6 +1438,8 @@ tracker_config_set_index_recursive_directories (TrackerConfig *config,
l = priv->index_recursive_directories;
+ equal = tracker_gslist_with_string_data_equal (roots, l);
+
if (!roots) {
priv->index_recursive_directories = NULL;
} else {
@@ -1425,6 +1450,10 @@ tracker_config_set_index_recursive_directories (TrackerConfig *config,
g_slist_foreach (l, (GFunc) g_free, NULL);
g_slist_free (l);
+ if (equal) {
+ return;
+ }
+
g_object_notify (G_OBJECT (config), "index-recursive-directories");
}
@@ -1433,7 +1462,8 @@ tracker_config_set_index_single_directories (TrackerConfig *config,
GSList *roots)
{
TrackerConfigPrivate *priv;
- GSList *l;
+ GSList *l;
+ gboolean equal;
g_return_if_fail (TRACKER_IS_CONFIG (config));
@@ -1441,6 +1471,8 @@ tracker_config_set_index_single_directories (TrackerConfig *config,
l = priv->index_single_directories;
+ equal = tracker_gslist_with_string_data_equal (roots, l);
+
if (!roots) {
priv->index_single_directories = NULL;
} else {
@@ -1451,6 +1483,10 @@ tracker_config_set_index_single_directories (TrackerConfig *config,
g_slist_foreach (l, (GFunc) g_free, NULL);
g_slist_free (l);
+ if (equal) {
+ return;
+ }
+
g_object_notify (G_OBJECT (config), "index-single-directories");
}
@@ -1459,7 +1495,8 @@ tracker_config_set_ignored_directories (TrackerConfig *config,
GSList *roots)
{
TrackerConfigPrivate *priv;
- GSList *l;
+ GSList *l;
+ gboolean equal;
g_return_if_fail (TRACKER_IS_CONFIG (config));
@@ -1467,6 +1504,8 @@ tracker_config_set_ignored_directories (TrackerConfig *config,
l = priv->ignored_directories;
+ equal = tracker_gslist_with_string_data_equal (roots, l);
+
if (!roots) {
priv->ignored_directories = NULL;
} else {
@@ -1477,6 +1516,10 @@ tracker_config_set_ignored_directories (TrackerConfig *config,
g_slist_foreach (l, (GFunc) g_free, NULL);
g_slist_free (l);
+ if (equal) {
+ return;
+ }
+
/* Re-set up the GPatternSpec list */
config_set_ignored_directory_conveniences (config);
@@ -1488,7 +1531,8 @@ tracker_config_set_ignored_directories_with_content (TrackerConfig *config,
GSList *roots)
{
TrackerConfigPrivate *priv;
- GSList *l;
+ GSList *l;
+ gboolean equal;
g_return_if_fail (TRACKER_IS_CONFIG (config));
@@ -1496,6 +1540,8 @@ tracker_config_set_ignored_directories_with_content (TrackerConfig *config,
l = priv->ignored_directories_with_content;
+ equal = tracker_gslist_with_string_data_equal (roots, l);
+
if (!roots) {
priv->ignored_directories_with_content = NULL;
} else {
@@ -1506,6 +1552,10 @@ tracker_config_set_ignored_directories_with_content (TrackerConfig *config,
g_slist_foreach (l, (GFunc) g_free, NULL);
g_slist_free (l);
+ if (equal) {
+ return;
+ }
+
g_object_notify (G_OBJECT (config), "ignored-directories-with-content");
}
@@ -1514,7 +1564,8 @@ tracker_config_set_ignored_files (TrackerConfig *config,
GSList *files)
{
TrackerConfigPrivate *priv;
- GSList *l;
+ GSList *l;
+ gboolean equal;
g_return_if_fail (TRACKER_IS_CONFIG (config));
@@ -1522,6 +1573,8 @@ tracker_config_set_ignored_files (TrackerConfig *config,
l = priv->ignored_files;
+ equal = tracker_gslist_with_string_data_equal (files, l);
+
if (!files) {
priv->ignored_files = NULL;
} else {
@@ -1532,6 +1585,10 @@ tracker_config_set_ignored_files (TrackerConfig *config,
g_slist_foreach (l, (GFunc) g_free, NULL);
g_slist_free (l);
+ if (equal) {
+ return;
+ }
+
/* Re-set up the GPatternSpec list */
config_set_ignored_file_conveniences (config);
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 920d608..ff69a6f 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -64,6 +64,9 @@ struct TrackerMinerFilesPrivate {
GVolumeMonitor *volume_monitor;
+ GSList *index_recursive_directories;
+ GSList *index_single_directories;
+
guint disk_space_check_id;
guint disk_space_pause_cookie;
@@ -277,6 +280,16 @@ miner_files_finalize (GObject *object)
disk_space_check_stop (TRACKER_MINER_FILES (object));
+ if (priv->index_recursive_directories) {
+ g_slist_foreach (priv->index_recursive_directories, (GFunc) g_free, NULL);
+ g_slist_free (priv->index_recursive_directories);
+ }
+
+ if (priv->index_single_directories) {
+ g_slist_foreach (priv->index_single_directories, (GFunc) g_free, NULL);
+ g_slist_free (priv->index_single_directories);
+ }
+
#ifdef HAVE_HAL
g_object_unref (priv->power);
g_object_unref (priv->storage);
@@ -321,6 +334,9 @@ miner_files_constructed (GObject *object)
/* Fill in directories to inspect */
dirs = tracker_config_get_index_single_directories (mf->private->config);
+ /* Copy in case of config changes */
+ mf->private->index_single_directories = tracker_gslist_copy_with_string_data (dirs);
+
for (; dirs; dirs = dirs->next) {
GFile *file;
@@ -361,6 +377,9 @@ miner_files_constructed (GObject *object)
dirs = tracker_config_get_index_recursive_directories (mf->private->config);
+ /* Copy in case of config changes */
+ mf->private->index_recursive_directories = tracker_gslist_copy_with_string_data (dirs);
+
for (; dirs; dirs = dirs->next) {
GFile *file;
@@ -953,70 +972,50 @@ low_disk_space_limit_cb (GObject *gobject,
static void
update_directories_from_new_config (TrackerMinerFS *mf,
- TrackerConfig *config,
+ GSList *new_dirs,
+ GSList *old_dirs,
gboolean recurse)
{
- GList *old_dirs, *l;
- GSList *new_dirs, *sl;
+ GSList *sl;
- old_dirs = tracker_miner_fs_get_directories (TRACKER_MINER_FS (mf), recurse);
-
- if (recurse) {
- new_dirs = tracker_config_get_index_recursive_directories (config);
- } else {
- new_dirs = tracker_config_get_index_single_directories (config);
- }
+ g_message ("Updating %s directories changed from configuration",
+ recurse ? "recursive" : "single");
/* First remove all directories removed from the config */
- for (l = old_dirs; l; l = l->next) {
- gchar *path;
+ for (sl = old_dirs; sl; sl = sl->next) {
+ const gchar *path;
- path = g_file_get_path (l->data);
+ path = sl->data;
/* If we are not still in the list, remove the dir */
if (!tracker_string_in_gslist (path, new_dirs)) {
- tracker_miner_fs_directory_remove (TRACKER_MINER_FS (mf),
- l->data);
- }
+ GFile *file;
+
+ g_message (" Removing directory:'%s'", path);
- g_free (path);
+ file = g_file_new_for_path (path);
+ tracker_miner_fs_directory_remove (TRACKER_MINER_FS (mf), file);
+ g_object_unref (file);
+ }
}
/* Second add directories which are new */
for (sl = new_dirs; sl; sl = sl->next) {
const gchar *path;
- gboolean found;
path = sl->data;
- found = FALSE;
-
- for (l = old_dirs; l && !found; l = l->next) {
- GFile *old_file;
- gchar *old_path;
- old_file = l->data;
- old_path = g_file_get_path (old_file);
-
- if (strcmp (old_path, path) == 0) {
- found = TRUE;
- }
-
- g_free (old_path);
- }
-
- if (!found) {
+ /* If we are now in the list, add the dir */
+ if (!tracker_string_in_gslist (path, old_dirs)) {
GFile *file;
+ g_message (" Adding directory:'%s'", path);
+
file = g_file_new_for_path (path);
- tracker_miner_fs_directory_add (TRACKER_MINER_FS (mf),
- file,
- recurse);
+ tracker_miner_fs_directory_add (TRACKER_MINER_FS (mf), file, recurse);
g_object_unref (file);
}
}
-
- g_list_foreach (old_dirs, (GFunc) g_object_unref, NULL);
- g_list_free (old_dirs);
}
static void
@@ -1024,9 +1023,26 @@ index_recursive_directories_cb (GObject *gobject,
GParamSpec *arg1,
gpointer user_data)
{
+ TrackerMinerFilesPrivate *private;
+ GSList *new_dirs, *old_dirs;
+
+ private = TRACKER_MINER_FILES_GET_PRIVATE (user_data);
+
+ new_dirs = tracker_config_get_index_recursive_directories (private->config);
+ old_dirs = private->index_recursive_directories;
+
update_directories_from_new_config (TRACKER_MINER_FS (user_data),
- TRACKER_CONFIG (gobject),
+ new_dirs,
+ old_dirs,
TRUE);
+
+ /* Re-set the stored config in case it changes again */
+ if (private->index_recursive_directories) {
+ g_slist_foreach (private->index_recursive_directories, (GFunc) g_free, NULL);
+ g_slist_free (private->index_recursive_directories);
+ }
+
+ private->index_recursive_directories = tracker_gslist_copy_with_string_data (new_dirs);
}
static void
@@ -1034,9 +1050,26 @@ index_single_directories_cb (GObject *gobject,
GParamSpec *arg1,
gpointer user_data)
{
+ TrackerMinerFilesPrivate *private;
+ GSList *new_dirs, *old_dirs;
+
+ private = TRACKER_MINER_FILES_GET_PRIVATE (user_data);
+
+ new_dirs = tracker_config_get_index_single_directories (private->config);
+ old_dirs = private->index_single_directories;
+
update_directories_from_new_config (TRACKER_MINER_FS (user_data),
- TRACKER_CONFIG (gobject),
+ new_dirs,
+ old_dirs,
FALSE);
+
+ /* Re-set the stored config in case it changes again */
+ if (private->index_single_directories) {
+ g_slist_foreach (private->index_single_directories, (GFunc) g_free, NULL);
+ g_slist_free (private->index_single_directories);
+ }
+
+ private->index_single_directories = tracker_gslist_copy_with_string_data (new_dirs);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]