[tracker: 4/18] tracker-control: Avoid usage of TrackerCrawler
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker: 4/18] tracker-control: Avoid usage of TrackerCrawler
- Date: Thu, 20 Feb 2014 12:09:01 +0000 (UTC)
commit 33faab071c8c02eb5dc0eab6f8757238d84293cd
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Feb 19 21:31:12 2014 +0100
tracker-control: Avoid usage of TrackerCrawler
This can be easily replaced by a helper function that iterates
over a directory.
src/tracker-control/tracker-control-general.c | 81 ++++++++++---------------
1 files changed, 31 insertions(+), 50 deletions(-)
---
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index a808bfd..c05594a 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -189,45 +189,44 @@ log_handler (const gchar *domain,
}
}
-static gboolean
-crawler_check_file_cb (TrackerCrawler *crawler,
- GFile *file,
- gpointer user_data)
+static void
+delete_file (GFile *file,
+ gpointer user_data)
{
- const gchar **suffix;
- gchar *path;
- gboolean should_remove;
-
- suffix = user_data;
- path = g_file_get_path (file);
-
- if (suffix) {
- should_remove = g_str_has_suffix (path, *suffix);
- } else {
- should_remove = TRUE;
- }
-
- if (!should_remove) {
- g_free (path);
- return FALSE;
- }
+ if (g_file_delete (file, NULL, NULL)) {
+ gchar *path;
- /* Remove file */
- if (g_unlink (path) == 0) {
+ path = g_file_get_path (file);
g_print (" %s\n", path);
+ g_free (path);
}
-
- g_free (path);
-
- return should_remove;
}
static void
-crawler_finished_cb (TrackerCrawler *crawler,
- gboolean was_interrupted,
- gpointer user_data)
+directory_foreach (GFile *file,
+ gchar *suffix,
+ GFunc func,
+ gpointer user_data)
{
- g_main_loop_quit (user_data);
+ GFileEnumerator *enumerator;
+ GFileInfo *info;
+ GFile *child;
+
+ enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+
+ if (!suffix || g_str_has_suffix (g_file_info_get_name (info), suffix)) {
+ child = g_file_enumerator_get_child (enumerator, info);
+ (func) (child, user_data);
+ g_object_unref (child);
+ }
+
+ g_object_unref (info);
+ }
+
+ g_object_unref (enumerator);
}
typedef struct {
@@ -1058,26 +1057,11 @@ tracker_control_general_run (void)
}
if (remove_config) {
- GMainLoop *main_loop;
GFile *file;
- TrackerCrawler *crawler;
- const gchar *suffix = ".cfg";
const gchar *home_conf_dir;
gchar *path;
GSList *all, *l;
- crawler = tracker_crawler_new ();
- main_loop = g_main_loop_new (NULL, FALSE);
-
- g_signal_connect (crawler, "check-file",
- G_CALLBACK (crawler_check_file_cb),
- &suffix);
- g_signal_connect (crawler, "finished",
- G_CALLBACK (crawler_finished_cb),
- main_loop);
-
- /* Go through service files */
-
/* Check the default XDG_DATA_HOME location */
home_conf_dir = g_getenv ("XDG_CONFIG_HOME");
@@ -1097,12 +1081,9 @@ tracker_control_general_run (void)
g_print ("%s\n", _("Removing configuration files…"));
- tracker_crawler_start (crawler, file, FALSE);
+ directory_foreach (file, ".cfg", (GFunc) delete_file, NULL);
g_object_unref (file);
- g_main_loop_run (main_loop);
- g_object_unref (crawler);
-
g_print ("%s\n", _("Resetting existing configuration…"));
all = tracker_gsettings_get_all (NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]