[tracker/cuesheets: 14/22] tracker-extract: Add 'postupdate' field



commit fe7dd4d893b275bbc4c26ee3d65f58c6aee76611
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Wed Sep 14 17:56:58 2011 +0100

    tracker-extract: Add 'postupdate' field
    
    Normally in Tracker the nfo:FileDataObject resource representing a file
    and the nie:InformationElement subclasses representing its contents are
    one and the same.
    
    If a file contains more than one logical resource, the extractor needs
    to create these separately and link them to the file resource using
    nie:isStoredAs - this cannot be done until the file resource has been
    inserted in the store, because it is difficult to know how to refer to
    the file object. The 'postupdate' field provides a way to do this.

 .../libtracker-extract-sections.txt                |    1 +
 src/libtracker-extract/tracker-extract-client.c    |   23 ++++++++++----
 src/libtracker-extract/tracker-extract-info.c      |   24 +++++++++++++++
 src/libtracker-extract/tracker-extract-info.h      |   31 ++++++++++---------
 src/miners/fs/tracker-miner-files.c                |   21 ++++++++++---
 src/tracker-extract/tracker-controller.c           |   30 ++++++++++++++++--
 src/tracker-extract/tracker-extract.c              |   18 +++++++++--
 tests/functional-tests/common/utils/helpers.py     |    2 +-
 8 files changed, 115 insertions(+), 35 deletions(-)
---
diff --git a/docs/reference/libtracker-extract/libtracker-extract-sections.txt b/docs/reference/libtracker-extract/libtracker-extract-sections.txt
index d10d62f..3b731da 100644
--- a/docs/reference/libtracker-extract/libtracker-extract-sections.txt
+++ b/docs/reference/libtracker-extract/libtracker-extract-sections.txt
@@ -56,6 +56,7 @@ tracker_extract_info_new
 tracker_extract_info_ref
 tracker_extract_info_unref
 tracker_extract_info_get_preupdate_builder
+tracker_extract_info_get_postupdate_builder
 tracker_extract_info_get_metadata_builder
 tracker_extract_info_get_where_clause
 tracker_extract_info_set_where_clause
diff --git a/src/libtracker-extract/tracker-extract-client.c b/src/libtracker-extract/tracker-extract-client.c
index a59f5ac..b54b398 100644
--- a/src/libtracker-extract/tracker-extract-client.c
+++ b/src/libtracker-extract/tracker-extract-client.c
@@ -251,11 +251,11 @@ get_metadata_fast_cb (void     *buffer,
 	if (G_UNLIKELY (error)) {
 		g_simple_async_result_set_from_error (data->res, error);
 	} else {
-		const gchar *preupdate, *sparql, *where, *end;
+		const gchar *preupdate, *postupdate, *sparql, *where, *end;
 		TrackerSparqlBuilder *builder;
 		gsize len;
 
-		preupdate = sparql = where = NULL;
+		preupdate = postupdate = sparql = where = NULL;
 		end = (gchar *) buffer + buffer_size;
 
 		if (buffer) {
@@ -263,12 +263,16 @@ get_metadata_fast_cb (void     *buffer,
 			len = strlen (preupdate);
 
 			if (preupdate + len < end) {
-				buffer_size -= len;
-				sparql = preupdate + len + 1;
-				len = strlen (sparql);
+				postupdate = preupdate + len + 1;
+				len = strlen (postupdate);
 
-				if (sparql + len < end) {
-					where = sparql + len + 1;
+				if (postupdate + len < end) {
+					sparql = postupdate + len + 1;
+					len = strlen (sparql);
+
+					if (sparql + len < end) {
+						where = sparql + len + 1;
+					}
 				}
 			}
 		}
@@ -282,6 +286,11 @@ get_metadata_fast_cb (void     *buffer,
 			tracker_sparql_builder_prepend (builder, preupdate);
 		}
 
+		if (postupdate) {
+			builder = tracker_extract_info_get_postupdate_builder (data->info);
+			tracker_sparql_builder_prepend (builder, postupdate);
+		}
+
 		if (sparql) {
 			builder = tracker_extract_info_get_metadata_builder (data->info);
 			tracker_sparql_builder_prepend (builder, sparql);
diff --git a/src/libtracker-extract/tracker-extract-info.c b/src/libtracker-extract/tracker-extract-info.c
index 528e795..518be29 100644
--- a/src/libtracker-extract/tracker-extract-info.c
+++ b/src/libtracker-extract/tracker-extract-info.c
@@ -38,6 +38,7 @@
 struct _TrackerExtractInfo
 {
 	TrackerSparqlBuilder *preupdate;
+	TrackerSparqlBuilder *postupdate;
 	TrackerSparqlBuilder *metadata;
 	gchar *where_clause;
 
@@ -78,6 +79,7 @@ tracker_extract_info_new (GFile       *file,
 	info->graph = g_strdup (graph);
 
 	info->preupdate = tracker_sparql_builder_new_update ();
+	info->postupdate = tracker_sparql_builder_new_update ();
 	info->metadata = tracker_sparql_builder_new_embedded_insert ();
 
 	info->ref_count = 1;
@@ -125,6 +127,7 @@ tracker_extract_info_unref (TrackerExtractInfo *info)
 		g_free (info->graph);
 
 		g_object_unref (info->preupdate);
+		g_object_unref (info->postupdate);
 		g_object_unref (info->metadata);
 		g_free (info->where_clause);
 
@@ -213,6 +216,27 @@ tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info)
 }
 
 /**
+ * tracker_extract_info_get_postupdate_builder:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns a #TrackerSparqlBuilder containing separate
+ * updates for resources that are contained within the file
+ * and need to refer to it.
+ *
+ * Returns: (transfer none): #TrackerSparqlBuilder for
+ * resources that need inserting after the file resource.
+ *
+ * Since: 0.12.1
+ **/
+TrackerSparqlBuilder *
+tracker_extract_info_get_postupdate_builder (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->postupdate;
+}
+
+/**
  * tracker_extract_info_get_metadata_builder:
  * @info: a #TrackerExtractInfo
  *
diff --git a/src/libtracker-extract/tracker-extract-info.h b/src/libtracker-extract/tracker-extract-info.h
index beff56a..f54b113 100644
--- a/src/libtracker-extract/tracker-extract-info.h
+++ b/src/libtracker-extract/tracker-extract-info.h
@@ -33,21 +33,22 @@ G_BEGIN_DECLS
 
 typedef struct _TrackerExtractInfo TrackerExtractInfo;
 
-GType                 tracker_extract_info_get_type              (void) G_GNUC_CONST;
-
-TrackerExtractInfo *  tracker_extract_info_new                   (GFile              *file,
-                                                                  const gchar        *mimetype,
-                                                                  const gchar        *graph);
-TrackerExtractInfo *  tracker_extract_info_ref                   (TrackerExtractInfo *info);
-void                  tracker_extract_info_unref                 (TrackerExtractInfo *info);
-GFile *               tracker_extract_info_get_file              (TrackerExtractInfo *info);
-const gchar *         tracker_extract_info_get_mimetype          (TrackerExtractInfo *info);
-const gchar *         tracker_extract_info_get_graph             (TrackerExtractInfo *info);
-TrackerSparqlBuilder *tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info);
-TrackerSparqlBuilder *tracker_extract_info_get_metadata_builder  (TrackerExtractInfo *info);
-const gchar *         tracker_extract_info_get_where_clause      (TrackerExtractInfo *info);
-void                  tracker_extract_info_set_where_clause      (TrackerExtractInfo *info,
-                                                                  const gchar        *where);
+GType                 tracker_extract_info_get_type               (void) G_GNUC_CONST;
+
+TrackerExtractInfo *  tracker_extract_info_new                    (GFile              *file,
+                                                                   const gchar        *mimetype,
+                                                                   const gchar        *graph);
+TrackerExtractInfo *  tracker_extract_info_ref                    (TrackerExtractInfo *info);
+void                  tracker_extract_info_unref                  (TrackerExtractInfo *info);
+GFile *               tracker_extract_info_get_file               (TrackerExtractInfo *info);
+const gchar *         tracker_extract_info_get_mimetype           (TrackerExtractInfo *info);
+const gchar *         tracker_extract_info_get_graph              (TrackerExtractInfo *info);
+TrackerSparqlBuilder *tracker_extract_info_get_preupdate_builder  (TrackerExtractInfo *info);
+TrackerSparqlBuilder *tracker_extract_info_get_postupdate_builder (TrackerExtractInfo *info);
+TrackerSparqlBuilder *tracker_extract_info_get_metadata_builder   (TrackerExtractInfo *info);
+const gchar *         tracker_extract_info_get_where_clause       (TrackerExtractInfo *info);
+void                  tracker_extract_info_set_where_clause       (TrackerExtractInfo *info,
+                                                                   const gchar        *where);
 
 G_END_DECLS
 
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 90b6ae5..344746e 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1938,6 +1938,7 @@ process_file_data_free (ProcessFileData *data)
 static void
 sparql_builder_finish (ProcessFileData *data,
                        const gchar     *preupdate,
+                       const gchar     *postupdate,
                        const gchar     *sparql,
                        const gchar     *where)
 {
@@ -1976,6 +1977,11 @@ sparql_builder_finish (ProcessFileData *data,
 		tracker_sparql_builder_prepend (data->sparql, preupdate);
 	}
 
+    /* Append postupdate */
+    if (postupdate && *postupdate) {
+        tracker_sparql_builder_append (data->sparql, postupdate);
+    }
+
 	uuid = g_object_get_qdata (G_OBJECT (data->file),
 	                           data->miner->private->quark_mount_point_uuid);
 
@@ -2022,7 +2028,7 @@ extractor_get_failsafe_metadata_cb (GObject      *object,
 	ProcessFileData *data = user_data;
 	TrackerMinerFiles *miner = data->miner;
 	TrackerMinerFilesPrivate *priv = miner->private;
-	const gchar *preupdate, *sparql, *where;
+	const gchar *preupdate, *postupdate, *sparql, *where;
 	TrackerExtractInfo *info;
 	GError *error = NULL;
 	gchar *uri;
@@ -2046,13 +2052,16 @@ extractor_get_failsafe_metadata_cb (GObject      *object,
 		builder = tracker_extract_info_get_preupdate_builder (info);
 		preupdate = tracker_sparql_builder_get_result (builder);
 
+		builder = tracker_extract_info_get_postupdate_builder (info);
+		postupdate = tracker_sparql_builder_get_result (builder);
+
 		builder = tracker_extract_info_get_metadata_builder (info);
 		sparql = tracker_sparql_builder_get_result (builder);
 
 		where = tracker_extract_info_get_where_clause (info);
 	}
 
-	sparql_builder_finish (data, preupdate, sparql, where);
+	sparql_builder_finish (data, preupdate, postupdate, sparql, where);
 
 	/* Notify success even if the extraction failed
 	 * again, so we get the essential data in the store.
@@ -2138,7 +2147,7 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 	TrackerMinerFilesPrivate *priv;
 	TrackerMinerFiles *miner;
 	ProcessFileData *data = user_data;
-	TrackerSparqlBuilder *preupdate, *sparql;
+	TrackerSparqlBuilder *preupdate, *postupdate, *sparql;
 	const gchar *where;
 	TrackerExtractInfo *info;
 	GError *error = NULL;
@@ -2168,7 +2177,7 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 			priv->failed_extraction_queue = g_list_prepend (priv->failed_extraction_queue, data);
 			g_free (uri);
 		} else {
-			sparql_builder_finish (data, NULL, NULL, NULL);
+			sparql_builder_finish (data, NULL, NULL, NULL, NULL);
 
 			/* Something bad happened, notify about the error */
 			tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error);
@@ -2178,11 +2187,13 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 		g_error_free (error);
 	} else {
 		preupdate = tracker_extract_info_get_preupdate_builder (info);
+		postupdate = tracker_extract_info_get_postupdate_builder (info);
 		sparql = tracker_extract_info_get_metadata_builder (info);
 		where = tracker_extract_info_get_where_clause (info);
 
 		sparql_builder_finish (data,
 		                       tracker_sparql_builder_get_result (preupdate),
+		                       tracker_sparql_builder_get_result (postupdate),
 		                       tracker_sparql_builder_get_result (sparql),
 		                       where);
 
@@ -2303,7 +2314,7 @@ process_file_cb (GObject      *object,
 	} else {
 		/* Otherwise, don't request embedded metadata extraction. */
 		g_debug ("Avoiding embedded metadata request for uri '%s'", uri);
-		sparql_builder_finish (data, NULL, NULL, NULL);
+		sparql_builder_finish (data, NULL, NULL, NULL, NULL);
 		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL);
 
 		priv->extraction_queue = g_list_remove (priv->extraction_queue, data);
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index 552391e..a52ecbe 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -95,6 +95,7 @@ static const gchar *introspection_xml =
 	"      <arg type='s' name='mime' direction='in' />"
 	"      <arg type='s' name='graph' direction='in' />"
 	"      <arg type='s' name='preupdate' direction='out' />"
+	"      <arg type='s' name='postupdate' direction='out' />"
 	"      <arg type='s' name='embedded' direction='out' />"
 	"      <arg type='s' name='where' direction='out' />"
 	"    </method>"
@@ -442,12 +443,15 @@ get_metadata_cb (GObject      *object,
 	info = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
 
 	if (info) {
-		const gchar *preupdate, *statements, *where;
+		const gchar *preupdate, *postupdate, *statements, *where;
 		TrackerSparqlBuilder *builder;
 
 		builder = tracker_extract_info_get_preupdate_builder (info);
 		preupdate = tracker_sparql_builder_get_result (builder);
 
+		builder = tracker_extract_info_get_postupdate_builder (info);
+		postupdate = tracker_sparql_builder_get_result (builder);
+
 		builder = tracker_extract_info_get_metadata_builder (info);
 		statements = tracker_sparql_builder_get_result (builder);
 
@@ -455,13 +459,14 @@ get_metadata_cb (GObject      *object,
 
 		if (statements && *statements) {
 			g_dbus_method_invocation_return_value (data->invocation,
-			                                       g_variant_new ("(sss)",
+			                                       g_variant_new ("(ssss)",
 			                                                      preupdate ? preupdate : "",
+			                                                      postupdate ? postupdate : "",
 			                                                      statements,
 			                                                      where ? where : ""));
 		} else {
 			g_dbus_method_invocation_return_value (data->invocation,
-			                                       g_variant_new ("(sss)", "", "", ""));
+			                                       g_variant_new ("(ssss)", "", "", "", ""));
 		}
 
 		tracker_dbus_request_end (data->request, NULL);
@@ -556,7 +561,7 @@ get_metadata_fast_cb (GObject      *object,
 		GOutputStream *unix_output_stream;
 		GOutputStream *buffered_output_stream;
 		GDataOutputStream *data_output_stream;
-		const gchar *preupdate, *statements, *where;
+		const gchar *preupdate, *postupdate, *statements, *where;
 		TrackerSparqlBuilder *builder;
 		GError *error = NULL;
 
@@ -575,6 +580,9 @@ get_metadata_fast_cb (GObject      *object,
 		builder = tracker_extract_info_get_preupdate_builder (info);
 		preupdate = tracker_sparql_builder_get_result (builder);
 
+		builder = tracker_extract_info_get_postupdate_builder (info);
+		postupdate = tracker_sparql_builder_get_result (builder);
+
 		builder = tracker_extract_info_get_metadata_builder (info);
 		statements = tracker_sparql_builder_get_result (builder);
 
@@ -595,6 +603,20 @@ get_metadata_fast_cb (GObject      *object,
 
 			if (!error) {
 				g_data_output_stream_put_string (data_output_stream,
+				                                 postupdate ? postupdate : "",
+				                                 NULL,
+				                                 &error);
+			}
+
+			if (!error) {
+				g_data_output_stream_put_byte (data_output_stream,
+				                               0,
+				                               NULL,
+				                               &error);
+			}
+
+			if (!error) {
+				g_data_output_stream_put_string (data_output_stream,
 				                                 statements,
 				                                 NULL,
 				                                 &error);
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index cff290a..4c70037 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -524,10 +524,10 @@ static gboolean
 get_metadata (TrackerExtractTask *task)
 {
 	TrackerExtractInfo *info;
-	TrackerSparqlBuilder *preupdate, *statements;
+	TrackerSparqlBuilder *preupdate, *postupdate, *statements;
 	gchar *where = NULL;
 
-	preupdate = statements = NULL;
+	preupdate = postupdate = statements = NULL;
 
 #ifdef THREAD_ENABLE_TRACE
 	g_debug ("Thread:%p --> File:'%s' - Extracted",
@@ -559,6 +559,10 @@ get_metadata (TrackerExtractTask *task)
 			g_object_unref (preupdate);
 		}
 
+		if (postupdate) {
+			g_object_unref (postupdate);
+		}
+
 		if (statements) {
 			g_object_unref (statements);
 		}
@@ -796,7 +800,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 	while (task->cur_module && task->cur_func) {
 		if (!filter_module (object, task->cur_module) &&
 		    get_file_metadata (task, &info)) {
-			const gchar *preupdate_str, *statements_str, *where;
+			const gchar *preupdate_str, *postupdate_str, *statements_str, *where;
 			TrackerSparqlBuilder *builder;
 
 			no_modules = FALSE;
@@ -814,6 +818,12 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 				preupdate_str = tracker_sparql_builder_get_result (builder);
 			}
 
+			builder = tracker_extract_info_get_postupdate_builder (info);
+
+			if (tracker_sparql_builder_get_length (builder) > 0) {
+				postupdate_str = tracker_sparql_builder_get_result (builder);
+			}
+
 			where = tracker_extract_info_get_where_clause (info);
 
 			g_print ("\n");
@@ -824,6 +834,8 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 			         statements_str ? statements_str : "");
 			g_print ("SPARQL where clause:\n--\n%s--\n\n",
 			         where ? where : "");
+			g_print ("SPARQL post-update:\n--\n%s--\n\n",
+			         postupdate_str ? postupdate_str : "");
 
 			tracker_extract_info_unref (info);
 			break;
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index ca652a9..af356ce 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -393,7 +393,7 @@ class ExtractorHelper (Helper):
         """
         metadata = {}
         try:
-            preupdate, embedded, where = self.extractor.GetMetadata (filename, mime, "")
+            preupdate, postupdate, embedded, where = self.extractor.GetMetadata (filename, mime, "")
             extras = self.__process_where_part (where)
             for attribute_value in self.__process_lines (embedded):
                 att, value = attribute_value.split (" ", 1)



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