[tracker] Reindex files of a specified MIME type
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Reindex files of a specified MIME type
- Date: Mon, 25 Jan 2010 17:18:37 +0000 (UTC)
commit 8877ba163ab4d13eda8891b95740df350f8d6e66
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Jan 25 18:01:16 2010 +0100
Reindex files of a specified MIME type
This feature is useful when installing a 3th party extractor
src/libtracker-miner/tracker-miner-fs.c | 36 ++++++
src/libtracker-miner/tracker-miner-fs.h | 2 +
src/tracker-miner-fs/tracker-main.c | 11 ++-
src/tracker-miner-fs/tracker-miner-files-reindex.c | 133 ++++++++++++++++++--
src/tracker-miner-fs/tracker-miner-files-reindex.h | 4 +-
5 files changed, 174 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index cddba6a..a49b723 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2163,6 +2163,42 @@ tracker_miner_fs_add_directory (TrackerMinerFS *fs,
crawl_directories_start (fs);
}
+/**
+ * tracker_miner_fs_add_file:
+ * @fs: a #TrackerMinerFS
+ * @file: #GFile for the file to inspect
+ *
+ * Tells the filesystem miner to inspect a file.
+ **/
+void
+tracker_miner_fs_add_file (TrackerMinerFS *fs,
+ GFile *file)
+{
+ gboolean should_process;
+ gchar *path;
+
+ g_return_if_fail (TRACKER_IS_MINER_FS (fs));
+ g_return_if_fail (G_IS_FILE (file));
+
+ should_process = should_check_file (fs, file, FALSE);
+
+ path = g_file_get_path (file);
+
+ g_debug ("%s:'%s' (FILE) (requested by application)",
+ should_process ? "Found " : "Ignored",
+ path);
+
+ if (should_process) {
+ g_queue_push_tail (fs->private->items_updated,
+ g_object_ref (file));
+
+ item_queue_handlers_set_up (fs);
+ }
+
+ g_free (path);
+}
+
+
static void
check_files_removal (GQueue *queue,
GFile *parent)
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 5e36e8e..557b17f 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -104,6 +104,8 @@ gdouble tracker_miner_fs_get_throttle (TrackerMinerFS *fs);
void tracker_miner_fs_notify_file (TrackerMinerFS *fs,
GFile *file,
const GError *error);
+void tracker_miner_fs_add_file (TrackerMinerFS *fs,
+ GFile *file);
G_END_DECLS
diff --git a/src/tracker-miner-fs/tracker-main.c b/src/tracker-miner-fs/tracker-main.c
index 3c91078..20d4373 100644
--- a/src/tracker-miner-fs/tracker-main.c
+++ b/src/tracker-miner-fs/tracker-main.c
@@ -317,10 +317,14 @@ main (gint argc, gchar *argv[])
return EXIT_FAILURE;
}
- object = tracker_miner_files_reindex_new ();
+ miner_files = tracker_miner_files_new (config);
+
+ object = tracker_miner_files_reindex_new (miner_files);
if (!object) {
+ g_object_unref (miner_files);
g_object_unref (config);
+ tracker_dbus_shutdown ();
tracker_log_shutdown ();
return EXIT_FAILURE;
@@ -328,8 +332,10 @@ main (gint argc, gchar *argv[])
/* Make Tracker available for introspection */
if (!tracker_dbus_register_objects (object)) {
+ g_object_unref (miner_files);
g_object_unref (object);
g_object_unref (config);
+ tracker_dbus_shutdown ();
tracker_log_shutdown ();
return EXIT_FAILURE;
@@ -344,7 +350,6 @@ main (gint argc, gchar *argv[])
NULL);
/* Create miner for files */
- miner_files = tracker_miner_files_new (config);
miners = g_slist_append (miners, miner_files);
g_signal_connect (miner_files, "finished",
@@ -364,6 +369,8 @@ main (gint argc, gchar *argv[])
g_slist_foreach (miners, (GFunc) g_object_unref, NULL);
g_slist_free (miners);
+ tracker_dbus_shutdown ();
+
tracker_log_shutdown ();
g_print ("\nOK\n\n");
diff --git a/src/tracker-miner-fs/tracker-miner-files-reindex.c b/src/tracker-miner-fs/tracker-miner-files-reindex.c
index d92eb20..d9118fd 100644
--- a/src/tracker-miner-fs/tracker-miner-files-reindex.c
+++ b/src/tracker-miner-fs/tracker-miner-files-reindex.c
@@ -31,8 +31,30 @@ typedef struct {
guint request_id;
DBusGMethodInvocation *context;
TrackerClient *client;
+ TrackerMinerFiles *miner_files;
} MimeTypesData;
+typedef struct {
+ TrackerMinerFiles *files_miner;
+} TrackerMinerFilesReindexPrivate;
+
+enum {
+ PROP_0,
+ PROP_FILES_MINER
+};
+
+#define TRACKER_MINER_FILES_REINDEX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_FILES_REINDEX, TrackerMinerFilesReindexPrivate))
+
+static void reindex_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void reindex_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void reindex_finalize (GObject *object);
+
G_DEFINE_TYPE(TrackerMinerFilesReindex, tracker_miner_files_reindex, G_TYPE_OBJECT)
static void
@@ -41,6 +63,68 @@ tracker_miner_files_reindex_class_init (TrackerMinerFilesReindexClass *klass)
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = reindex_finalize;
+ object_class->set_property = reindex_set_property;
+ object_class->get_property = reindex_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_FILES_MINER,
+ g_param_spec_object ("files_miner",
+ "files_miner",
+ "The FS Miner",
+ TRACKER_TYPE_MINER_FILES,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_type_class_add_private (klass, sizeof (TrackerMinerFilesReindexPrivate));
+}
+
+static void
+reindex_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerFilesReindexPrivate *priv;
+
+ priv = TRACKER_MINER_FILES_REINDEX_GET_PRIVATE (object);
+
+ switch (param_id) {
+ case PROP_FILES_MINER:
+ priv->files_miner = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+
+static void
+reindex_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerFilesReindexPrivate *priv;
+
+ priv = TRACKER_MINER_FILES_REINDEX_GET_PRIVATE (object);
+
+ switch (param_id) {
+ case PROP_FILES_MINER:
+ g_value_set_object (value, priv->files_miner);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+reindex_finalize (GObject *object)
+{
+ TrackerMinerFilesReindexPrivate *priv = TRACKER_MINER_FILES_REINDEX_GET_PRIVATE (object);
+ g_object_unref (priv->files_miner);
}
static void
@@ -51,12 +135,14 @@ tracker_miner_files_reindex_init (TrackerMinerFilesReindex *object)
static MimeTypesData *
mime_types_data_new (guint request_id,
DBusGMethodInvocation *context,
- TrackerClient *client)
+ TrackerClient *client,
+ TrackerMinerFiles *miner_files)
{
MimeTypesData *mtd;
mtd = g_slice_new0 (MimeTypesData);
+ mtd->miner_files = g_object_ref (miner_files);
mtd->request_id = request_id;
mtd->context = context;
mtd->client = g_object_ref (client);
@@ -71,6 +157,7 @@ mime_types_data_destroy (gpointer data)
mtd = data;
+ g_object_unref (mtd->miner_files);
g_object_unref (mtd->client);
g_slice_free (MimeTypesData, mtd);
@@ -82,21 +169,42 @@ mime_types_cb (GPtrArray *result,
gpointer user_data)
{
MimeTypesData *mtd = user_data;
+ guint i;
+
+ if (!error) {
+ tracker_dbus_request_comment (mtd->request_id, mtd->context,
+ "Found %d files that will need reindexing",
+ result ? result->len : 0);
+
+ for (i = 0; i < result->len; i++) {
+ GStrv *row = g_ptr_array_index (result, i);
+
+ if (row && row[0]) {
+ const gchar *url = (const gchar *) row[0];
+ GFile *file = g_file_new_for_uri (url);
+ tracker_miner_fs_add_file (TRACKER_MINER_FS (mtd->miner_files), file);
+ g_object_unref (file);
+ }
+ }
- tracker_dbus_request_comment (mtd->request_id, mtd->context,
- "Found %d files that will need reindexing",
- result ? result->len : 0);
+ tracker_dbus_request_success (mtd->request_id, mtd->context);
+ dbus_g_method_return (mtd->context);
+
+ } else {
+ tracker_dbus_request_success (mtd->request_id, mtd->context);
+ dbus_g_method_return_error (mtd->context, error);
+ }
- tracker_dbus_request_success (mtd->request_id, mtd->context);
- dbus_g_method_return (mtd->context);
mime_types_data_destroy (user_data);
}
TrackerMinerFilesReindex *
-tracker_miner_files_reindex_new (void)
+tracker_miner_files_reindex_new (TrackerMinerFiles *miner_files)
{
- return g_object_new (TRACKER_TYPE_MINER_FILES_REINDEX, NULL);
+ return g_object_new (TRACKER_TYPE_MINER_FILES_REINDEX,
+ "files-miner", miner_files,
+ NULL);
}
void
@@ -105,6 +213,7 @@ tracker_miner_files_reindex_mime_types (TrackerMinerFilesReindex *object,
DBusGMethodInvocation *context,
GError **error)
{
+ TrackerMinerFilesReindexPrivate *priv;
GString *query;
TrackerClient *client;
guint request_id;
@@ -153,11 +262,17 @@ tracker_miner_files_reindex_mime_types (TrackerMinerFilesReindex *object,
g_string_append (query, ") }");
+ priv = TRACKER_MINER_FILES_REINDEX_GET_PRIVATE (object);
+
/* FIXME: save last call id */
tracker_resources_sparql_query_async (client,
query->str,
mime_types_cb,
- mime_types_data_new (request_id, context, client));
+ mime_types_data_new (request_id,
+ context,
+ client,
+ priv->files_miner));
+
g_string_free (query, TRUE);
g_object_unref (client);
}
diff --git a/src/tracker-miner-fs/tracker-miner-files-reindex.h b/src/tracker-miner-fs/tracker-miner-files-reindex.h
index c0281fa..f95868f 100644
--- a/src/tracker-miner-fs/tracker-miner-files-reindex.h
+++ b/src/tracker-miner-fs/tracker-miner-files-reindex.h
@@ -26,6 +26,8 @@
#define TRACKER_MINER_FILES_REINDEX_PATH "/org/freedesktop/Tracker1/Miner/Files/Reindex"
#define TRACKER_MINER_FILES_REINDEX_INTERFACE "org.freedesktop.Tracker1.Miner.Files.Reindex"
+#include <tracker-miner-fs/tracker-miner-files.h>
+
G_BEGIN_DECLS
#define TRACKER_TYPE_MINER_FILES_REINDEX (tracker_miner_files_reindex_get_type ())
@@ -47,7 +49,7 @@ struct TrackerMinerFilesReindexClass {
};
GType tracker_miner_files_reindex_get_type (void);
-TrackerMinerFilesReindex *tracker_miner_files_reindex_new (void);
+TrackerMinerFilesReindex *tracker_miner_files_reindex_new (TrackerMinerFiles *miner_files);
void tracker_miner_files_reindex_mime_types (TrackerMinerFilesReindex *object,
gchar **mime_types,
DBusGMethodInvocation *context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]