From 8e7fefd6f11da751b58c88655053b8a122421c4b Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Wed, 31 Oct 2012 00:04:33 +0100 Subject: [PATCH] Fix file indexing Initialize Tracker miner manager in module initialization and wrap miner calls within become_root()/unbecome_root(). --- etc/afpd/spotlight_module.c | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/etc/afpd/spotlight_module.c b/etc/afpd/spotlight_module.c index 52e4e8c4..7e6556f9 100644 --- a/etc/afpd/spotlight_module.c +++ b/etc/afpd/spotlight_module.c @@ -33,6 +33,7 @@ #define MAX_SL_RESULTS 20 static TrackerSparqlConnection *connection; +static TrackerMinerManager *manager; char *tracker_to_unix_path(const char *uri) { @@ -71,6 +72,7 @@ static int sl_mod_init(void *p) become_root(); connection = tracker_sparql_connection_get(NULL, &error); + manager = tracker_miner_manager_new_full(FALSE, &error); unbecome_root(); if (!connection) { @@ -80,6 +82,12 @@ static int sl_mod_init(void *p) EC_FAIL; } + if (!manager) { + LOG(log_error, logtype_sl, "Couldn't connect to Tracker miner"); + g_clear_error(&error); + EC_FAIL; + } + EC_CLEANUP: EC_EXIT; } @@ -347,33 +355,29 @@ EC_CLEANUP: static int sl_mod_index_file(const void *p) { #ifdef HAVE_TRACKER_MINER - /* hangs in tracker_miner_manager_new_full() for whatever reason... */ - return 0; - EC_INIT; const char *f = p; if (!f) goto EC_CLEANUP; - TrackerMinerManager *manager; GError *error = NULL; - GFile *file; + GFile *file = NULL; - if ((manager = tracker_miner_manager_new_full(FALSE, &error)) == NULL) { - LOG(log_error, logtype_sl, "sl_mod_index_file(\"%s\"): couldn't connect to Tracker miner", f); - } else { - file = g_file_new_for_commandline_arg(f); - tracker_miner_manager_index_file(manager, file, &error); - if (error) - LOG(log_error, logtype_sl, "sl_mod_index_file(\"%s\"): indexing failed", f); - else - LOG(log_debug, logtype_sl, "sl_mod_index_file(\"%s\"): indexing file was successful", f); - g_object_unref(manager); - g_object_unref(file); - } + file = g_file_new_for_commandline_arg(f); + + become_root(); + tracker_miner_manager_index_file(manager, file, &error); + unbecome_root(); + + if (error) + LOG(log_error, logtype_sl, "sl_mod_index_file(\"%s\"): indexing failed", f); + else + LOG(log_debug, logtype_sl, "sl_mod_index_file(\"%s\"): indexing file was successful", f); EC_CLEANUP: + if (file) + g_object_unref(file); EC_EXIT; #else return 0; -- 2.39.2