[tracker] tracker-extract: Fix --force-module for commandline extraction



commit ea380384fca9c37cd6b8d301b80dc1bdcef69514
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Aug 2 13:43:17 2011 +0200

    tracker-extract: Fix --force-module for commandline extraction
    
    This only works with --file, and the forced module must be one of those
    that typically handle the file (i.e. mp3/gstreamer/gupnp-dlna for mp3
    files)

 src/tracker-extract/tracker-extract.c |   46 ++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 7f14870..8d55735 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -75,6 +75,8 @@ typedef struct {
 	gboolean force_internal_extractors;
 	gboolean disable_summary_on_finalize;
 
+	gchar *force_module;
+
 	gint unhandled_count;
 } TrackerExtractPrivate;
 
@@ -229,6 +231,7 @@ tracker_extract_new (gboolean     disable_shutdown,
 
 	priv->disable_shutdown = disable_shutdown;
 	priv->force_internal_extractors = force_internal_extractors;
+	priv->force_module = g_strdup (force_module);
 
 	return object;
 }
@@ -695,6 +698,46 @@ tracker_extract_file (TrackerExtract      *extract,
 	}
 }
 
+static gboolean
+filter_module (TrackerExtract *extract,
+               GModule        *module)
+{
+	TrackerExtractPrivate *priv;
+	gchar *module_basename, *filter_name;
+	gboolean filter;
+
+	priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
+
+	if (!priv->force_module) {
+		return FALSE;
+	}
+
+	/* Module name is the full path to it */
+	module_basename = g_path_get_basename (g_module_name (module));
+
+	if (g_str_has_prefix (priv->force_module, "lib") &&
+	    g_str_has_suffix (priv->force_module, "." G_MODULE_SUFFIX)) {
+		filter_name = g_strdup (priv->force_module);
+	} else {
+		filter_name = g_strdup_printf ("libextract-%s.so",
+		                               priv->force_module);
+	}
+
+	g_print ("Comparing %s -> %s\n", module_basename, filter_name);
+
+	filter = strcmp (module_basename, filter_name) != 0;
+
+	if (filter) {
+		g_debug ("Module '%s' has been filtered due to --force-module",
+		         g_module_name (module));
+	}
+
+	g_free (module_basename);
+	g_free (filter_name);
+
+	return filter;
+}
+
 void
 tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                                          const gchar    *uri,
@@ -722,7 +765,8 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 	task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers, &task->cur_func, NULL);
 
 	while (task->cur_module && task->cur_func) {
-		if (get_file_metadata (task, &preupdate, &statements, &where)) {
+		if (!filter_module (object, task->cur_module) &&
+		    get_file_metadata (task, &preupdate, &statements, &where)) {
 			const gchar *preupdate_str, *statements_str;
 
 			preupdate_str = statements_str = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]