[tracker] tracker-extract: Propagate urn to the TrackerExtractInfo



commit 389068a3c580e2b69011d2afec699d4ada687756
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 14 01:37:16 2016 +0100

    tracker-extract: Propagate urn to the TrackerExtractInfo
    
    Now that extraction is performed after the file got initially
    inserted and has an URN, there's no reason we can't pass the
    URN to the TrackerExtractInfo. This would make URNs available
    to extract modules, which have some places where the SPARQL
    produced would be clearer.
    
    This actually opens the path for quite a cleanup, we might
    pass a single TrackerSparqlBuilder to extract modules instead
    of doing the postprocessing we currently perform.

 src/libtracker-extract/tracker-extract-info.c      |   14 +++++++++++++-
 src/libtracker-extract/tracker-extract-info.h      |    4 +++-
 src/tracker-extract/tracker-extract-decorator.c    |    1 +
 src/tracker-extract/tracker-extract.c              |   11 ++++++++---
 src/tracker-extract/tracker-extract.h              |    1 +
 .../libtracker-extract/tracker-extract-info-test.c |    5 +++--
 6 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-extract-info.c b/src/libtracker-extract/tracker-extract-info.c
index de2c594..c534695 100644
--- a/src/libtracker-extract/tracker-extract-info.c
+++ b/src/libtracker-extract/tracker-extract-info.c
@@ -47,6 +47,7 @@ struct _TrackerExtractInfo
        GFile *file;
        gchar *mimetype;
        gchar *graph;
+       gchar *urn;
 
 #ifdef HAVE_LIBMEDIAART
        MediaArtProcess *media_art_process;
@@ -73,7 +74,8 @@ G_DEFINE_BOXED_TYPE (TrackerExtractInfo, tracker_extract_info,
 TrackerExtractInfo *
 tracker_extract_info_new (GFile       *file,
                           const gchar *mimetype,
-                          const gchar *graph)
+                          const gchar *graph,
+                          const gchar *urn)
 {
        TrackerExtractInfo *info;
 
@@ -83,6 +85,7 @@ tracker_extract_info_new (GFile       *file,
        info->file = g_object_ref (file);
        info->mimetype = g_strdup (mimetype);
        info->graph = g_strdup (graph);
+       info->urn = g_strdup (urn);
 
        info->preupdate = tracker_sparql_builder_new_update ();
        info->postupdate = tracker_sparql_builder_new_update ();
@@ -137,6 +140,7 @@ tracker_extract_info_unref (TrackerExtractInfo *info)
                g_object_unref (info->file);
                g_free (info->mimetype);
                g_free (info->graph);
+               g_free (info->urn);
 
                g_object_unref (info->preupdate);
                g_object_unref (info->postupdate);
@@ -310,6 +314,14 @@ tracker_extract_info_set_where_clause (TrackerExtractInfo *info,
        info->where_clause = g_strdup (where);
 }
 
+const gchar *
+tracker_extract_info_get_urn (TrackerExtractInfo *info)
+{
+       g_return_val_if_fail (info != NULL, NULL);
+
+       return info->urn;
+}
+
 #ifdef HAVE_LIBMEDIAART
 
 /**
diff --git a/src/libtracker-extract/tracker-extract-info.h b/src/libtracker-extract/tracker-extract-info.h
index ffd1bce..857956f 100644
--- a/src/libtracker-extract/tracker-extract-info.h
+++ b/src/libtracker-extract/tracker-extract-info.h
@@ -41,12 +41,14 @@ GType                 tracker_extract_info_get_type               (void) G_GNUC_
 
 TrackerExtractInfo *  tracker_extract_info_new                    (GFile              *file,
                                                                    const gchar        *mimetype,
-                                                                   const gchar        *graph);
+                                                                   const gchar        *graph,
+                                                                   const gchar        *urn);
 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);
+const gchar *         tracker_extract_info_get_urn                (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);
diff --git a/src/tracker-extract/tracker-extract-decorator.c b/src/tracker-extract/tracker-extract-decorator.c
index 5152e9f..e011a92 100644
--- a/src/tracker-extract/tracker-extract-decorator.c
+++ b/src/tracker-extract/tracker-extract-decorator.c
@@ -311,6 +311,7 @@ decorator_next_item_cb (TrackerDecorator *decorator,
                              tracker_decorator_info_get_url (info),
                              tracker_decorator_info_get_mimetype (info),
                              TRACKER_OWN_GRAPH_URN,
+                             tracker_decorator_info_get_urn (info),
                              g_task_get_cancellable (task),
                              (GAsyncReadyCallback) get_metadata_cb, data);
 }
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index c15737c..04b3291 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -88,6 +88,7 @@ typedef struct {
        gchar *file;
        gchar *mimetype;
        gchar *graph;
+       gchar *urn;
 
        TrackerMimetypeInfo *mimetype_handlers;
 
@@ -301,7 +302,7 @@ get_file_metadata (TrackerExtractTask  *task,
        *info_out = NULL;
 
        file = g_file_new_for_uri (task->file);
-       info = tracker_extract_info_new (file, task->mimetype, task->graph);
+       info = tracker_extract_info_new (file, task->mimetype, task->graph, task->urn);
        g_object_unref (file);
 
 #ifdef HAVE_LIBMEDIAART
@@ -382,6 +383,7 @@ extract_task_new (TrackerExtract *extract,
                   const gchar    *uri,
                   const gchar    *mimetype,
                   const gchar    *graph,
+                  const gchar    *urn,
                   GCancellable   *cancellable,
                   GAsyncResult   *res,
                   GError        **error)
@@ -422,6 +424,7 @@ extract_task_new (TrackerExtract *extract,
        task->file = g_strdup (uri);
        task->mimetype = mimetype_used;
        task->graph = g_strdup (graph);
+       task->urn = g_strdup (urn);
        task->extract = extract;
 
        if (task->cancellable) {
@@ -454,6 +457,7 @@ extract_task_free (TrackerExtractTask *task)
                tracker_mimetype_info_free (task->mimetype_handlers);
        }
 
+       g_free (task->urn);
        g_free (task->graph);
        g_free (task->mimetype);
        g_free (task->file);
@@ -698,6 +702,7 @@ tracker_extract_file (TrackerExtract      *extract,
                       const gchar         *file,
                       const gchar         *mimetype,
                       const gchar         *graph,
+                      const gchar         *urn,
                       GCancellable        *cancellable,
                       GAsyncReadyCallback  cb,
                       gpointer             user_data)
@@ -718,7 +723,7 @@ tracker_extract_file (TrackerExtract      *extract,
 
        async_task = g_task_new (extract, cancellable, cb, user_data);
 
-       task = extract_task_new (extract, file, mimetype, graph,
+       task = extract_task_new (extract, file, mimetype, graph, urn,
                                 cancellable, G_ASYNC_RESULT (async_task), &error);
 
        if (error) {
@@ -772,7 +777,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 
        g_return_if_fail (uri != NULL);
 
-       task = extract_task_new (object, uri, mime, NULL, NULL, NULL, &error);
+       task = extract_task_new (object, uri, mime, NULL, "_:file", NULL, NULL, &error);
 
        if (error) {
                g_printerr ("%s, %s\n",
diff --git a/src/tracker-extract/tracker-extract.h b/src/tracker-extract/tracker-extract.h
index a527e82..704ece4 100644
--- a/src/tracker-extract/tracker-extract.h
+++ b/src/tracker-extract/tracker-extract.h
@@ -63,6 +63,7 @@ void            tracker_extract_file                    (TrackerExtract
                                                          const gchar            *file,
                                                          const gchar            *mimetype,
                                                          const gchar            *graph,
+                                                         const gchar            *urn,
                                                          GCancellable           *cancellable,
                                                          GAsyncReadyCallback     cb,
                                                          gpointer                user_data);
diff --git a/tests/libtracker-extract/tracker-extract-info-test.c 
b/tests/libtracker-extract/tracker-extract-info-test.c
index 3c968bc..d8b3b18 100644
--- a/tests/libtracker-extract/tracker-extract-info-test.c
+++ b/tests/libtracker-extract/tracker-extract-info-test.c
@@ -29,13 +29,14 @@ test_extract_info_setters (void)
 
         file = g_file_new_for_path ("./imaginary-file-2");
 
-        info = tracker_extract_info_new (file, "imaginary/mime", "test-graph");
+        info = tracker_extract_info_new (file, "imaginary/mime", "test-graph", "test-urn");
         info_ref = tracker_extract_info_ref (info);
 
         g_assert (g_file_equal (file, tracker_extract_info_get_file (info)));
 
         g_assert_cmpstr (tracker_extract_info_get_mimetype (info), ==, "imaginary/mime");
         g_assert_cmpstr (tracker_extract_info_get_graph (info), ==, "test-graph");
+        g_assert_cmpstr (tracker_extract_info_get_urn (info), ==, "test-urn");
         g_assert (tracker_extract_info_get_preupdate_builder (info));
         g_assert (tracker_extract_info_get_postupdate_builder (info));
         g_assert (tracker_extract_info_get_metadata_builder (info));
@@ -58,7 +59,7 @@ test_extract_info_empty_objects (void)
 
         file = g_file_new_for_path ("./imaginary-file");
 
-        info = tracker_extract_info_new (file, "imaginary/mime", "test-graph");
+        info = tracker_extract_info_new (file, "imaginary/mime", "test-graph", "test-urn");
         info_ref = tracker_extract_info_ref (info);
 
         tracker_extract_info_unref (info_ref);


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