[tracker] The XMP extractor was using a wrong URI
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] The XMP extractor was using a wrong URI
- Date: Thu, 16 Apr 2009 11:36:02 -0400 (EDT)
commit a4eb2632cdde0f7c480314e747e81a2793fbc991
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Apr 16 14:40:49 2009 +0200
The XMP extractor was using a wrong URI
The XMP extractor must find the file for which it plays a sidekick XMP.
Then use that file's URI instead of using its own URI.
---
src/tracker-extract/tracker-extract-xmp.c | 71 +++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/src/tracker-extract/tracker-extract-xmp.c b/src/tracker-extract/tracker-extract-xmp.c
index e5fcc78..241280d 100644
--- a/src/tracker-extract/tracker-extract-xmp.c
+++ b/src/tracker-extract/tracker-extract-xmp.c
@@ -20,6 +20,7 @@
#include "config.h"
#include <glib.h>
+#include <gio/gio.h>
#include <libtracker-common/tracker-statement-list.h>
@@ -34,6 +35,65 @@ static TrackerExtractData data[] = {
{ NULL, NULL }
};
+/* This function is used to find the URI for a file.xmp file. The point here is
+ * that the URI for file.xmp is not file:///file.xmp but instead for example
+ * file:///file.jpeg or file:///file.png. The reason is that file.xmp is a
+ * sidekick, and a sidekick doesn't describe itself, it describes another file. */
+
+static gchar *
+find_orig_uri (const gchar *xmp_filename)
+{
+ GFile *file = g_file_new_for_path (xmp_filename);
+ GFile *dir = g_file_get_parent (file);
+ GFileEnumerator *iter;
+ GFileInfo *orig_info;
+ gchar *compare_part, *found_file = NULL;
+ guint len;
+
+ orig_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ compare_part = g_utf8_strup (g_file_info_get_name (orig_info), -1);
+
+ len = g_utf8_strlen (compare_part, -1);
+
+ iter = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ if (iter) {
+ GFileInfo *info;
+
+ while ((info = g_file_enumerator_next_file (iter, NULL, NULL)) && !found_file) {
+ gchar *compare_with;
+ const gchar *filename;
+
+ filename = g_file_info_get_name (orig_info);
+ compare_with = g_utf8_strup (filename, -1);
+
+ /* Don't compare the ".xmp" with ".jpeg" and don't match the same file */
+
+ if (g_strncasecmp (compare_part, compare_with, len - 4) == 0 &&
+ g_strcmp0 (compare_part, compare_with) != 0) {
+ GFile *found = g_file_get_child (dir, filename);
+ found_file = g_file_get_uri (found);
+ g_object_unref (found);
+ }
+
+ g_free (compare_with);
+ g_object_unref (info);
+ }
+
+ g_object_unref (iter);
+ }
+
+ g_object_unref (orig_info);
+ g_object_unref (file);
+ g_object_unref (dir);
+ g_free (compare_part);
+
+ return found_file;
+}
+
static void
extract_xmp (const gchar *uri,
GPtrArray *metadata)
@@ -44,10 +104,13 @@ extract_xmp (const gchar *uri,
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
if (g_file_get_contents (filename, &contents, &length, &error)) {
- /* URI is very very wrong here. The URI is location://filename.xmp whereas
- * the metadata is about location://filename.jpeg (in case it's a sidecar
- * for filename.jpeg) */
- tracker_read_xmp (contents, length, uri, metadata);
+ gchar *orig_uri = find_orig_uri (filename);
+
+ /* If no orig file is found for the sidekick, we use the sidekick to
+ * describe itself instead, falling back to uri */
+ tracker_read_xmp (contents, length, orig_uri ? orig_uri : uri, metadata);
+
+ g_free (orig_uri);
}
g_free (filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]