tracker r2005 - in branches/indexer-split: . src/tracker-indexer src/tracker-indexer/modules



Author: carlosg
Date: Tue Aug  5 15:01:26 2008
New Revision: 2005
URL: http://svn.gnome.org/viewvc/tracker?rev=2005&view=rev

Log:
2008-08-05  Carlos Garnacho  <carlos imendio com>

        * src/tracker-indexer/Makefile.am:
        * src/tracker-indexer/tracker-metadata-utils.[ch]: Added files,
        generic utility functions for extracting metadata from a file.
        * src/tracker-indexer/modules/files.c: Use these functions to get
        metadata from files.


Added:
   branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
   branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h
Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/tracker-indexer/Makefile.am
   branches/indexer-split/src/tracker-indexer/modules/files.c

Modified: branches/indexer-split/src/tracker-indexer/Makefile.am
==============================================================================
--- branches/indexer-split/src/tracker-indexer/Makefile.am	(original)
+++ branches/indexer-split/src/tracker-indexer/Makefile.am	Tue Aug  5 15:01:26 2008
@@ -29,6 +29,8 @@
 	tracker-marshal-main.c						\
 	tracker-metadata.c						\
 	tracker-metadata.h						\
+	tracker-metadata-utils.c					\
+	tracker-metadata-utils.h					\
 	tracker-module.h
 
 tracker_indexer_LDADD =							\

Modified: branches/indexer-split/src/tracker-indexer/modules/files.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/modules/files.c	(original)
+++ branches/indexer-split/src/tracker-indexer/modules/files.c	Tue Aug  5 15:01:26 2008
@@ -26,9 +26,9 @@
 
 #include <libtracker-common/tracker-config.h>
 #include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-type-utils.h>
 #include <libtracker-common/tracker-os-dependant.h>
 #include <libtracker-common/tracker-ontology.h>
+#include <tracker-indexer/tracker-metadata-utils.h>
 #include <tracker-indexer/tracker-module.h>
 
 #define METADATA_FILE_NAME_DELIMITED "File:NameDelimited"
@@ -61,87 +61,6 @@
         return service_type;
 }
 
-static void
-tracker_metadata_get_embedded (const char      *path,
-			       const char      *mimetype,
-                               TrackerMetadata *metadata)
-{
-	gboolean success;
-	gchar **argv, *output, **values, *service_type;
-	gint i;
-
-	service_type = tracker_ontology_get_service_type_for_mime (mimetype);
-
-	if (!service_type) {
-		return;
-	}
-
-	if (!tracker_ontology_service_type_has_metadata (service_type)) {
-		g_free (service_type);
-		return;
-	}
-
-        g_free (service_type);
-
-	/* we extract metadata out of process using pipes */
-	argv = g_new0 (gchar *, 4);
-	argv[0] = g_strdup ("tracker-extract");
-	argv[1] = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
-	argv[2] = g_strdup (mimetype);
-
-	if (!argv[1] || !argv[2]) {
-		g_critical ("path or mime could not be converted to locale format");
-		g_strfreev (argv);
-		return;
-	}
-
-	success = tracker_spawn (argv, 10, &output, NULL);
-	g_strfreev (argv);
-
-	if (!success || !output)
-		return;
-
-	/* parse returned stdout and extract keys and associated metadata values */
-
-	values = g_strsplit_set (output, ";", -1);
-
-	for (i = 0; values[i]; i++) {
-		char *meta_data, *sep;
-		const char *name, *value;
-		char *utf_value;
-
-		meta_data = g_strstrip (values[i]);
-		sep = strchr (meta_data, '=');
-
-		if (!sep)
-			continue;
-
-		/* zero out the separator, so we get
-		 * NULL-terminated name and value
-		 */
-		sep[0] = '\0';
-		name = meta_data;
-		value = sep + 1;
-
-		if (!name || !value)
-			continue;
-
-		if (!g_utf8_validate (value, -1, NULL)) {
-			utf_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
-		} else {
-			utf_value = g_strdup (value);
-		}
-
-		if (!utf_value)
-			continue;
-
-                tracker_metadata_insert (metadata, name, utf_value);
-	}
-
-	g_strfreev (values);
-	g_free (output);
-}
-
 static gboolean
 check_exclude_file (const gchar *path)
 {
@@ -212,10 +131,6 @@
 tracker_module_file_get_metadata (TrackerFile *file)
 {
 	const gchar *path;
-        TrackerMetadata *metadata;
-	struct stat st;
-	const gchar *ext;
-	gchar *mimetype;
 
 	path = file->path;
 
@@ -223,45 +138,7 @@
                 return NULL;
         }
 
-	if (g_lstat (path, &st) < 0) {
-                return NULL;
-        }
-
-        metadata = tracker_metadata_new ();
-	ext = strrchr (path, '.');
-
-	if (ext) {
-		tracker_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
-	}
-
-	mimetype = tracker_file_get_mime_type (path);
-
-        tracker_metadata_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (path));
-	tracker_metadata_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (path));
-	tracker_metadata_insert (metadata, METADATA_FILE_NAME_DELIMITED,
-                                 g_filename_to_utf8 (path, -1, NULL, NULL, NULL));
-	tracker_metadata_insert (metadata, METADATA_FILE_MIMETYPE, mimetype);
-
-	if (S_ISLNK (st.st_mode)) {
-		gchar *link_path;
-
-		link_path = g_file_read_link (path, NULL);
-		tracker_metadata_insert (metadata, METADATA_FILE_LINK,
-                                         g_filename_to_utf8 (link_path, -1, NULL, NULL, NULL));
-		g_free (link_path);
-	}
-
-	/* FIXME: These should be dealt directly as integer/times/whatever, not strings */
-	tracker_metadata_insert (metadata, METADATA_FILE_SIZE,
-                                 tracker_uint_to_string (st.st_size));
-	tracker_metadata_insert (metadata, METADATA_FILE_MODIFIED,
-                                 tracker_uint_to_string (st.st_mtime));
-	tracker_metadata_insert (metadata, METADATA_FILE_ACCESSED,
-                                 tracker_uint_to_string (st.st_atime));
-
-	tracker_metadata_get_embedded (path, mimetype, metadata);
-
-	return metadata;
+        return tracker_metadata_utils_get_data (path);
 }
 
 static gchar *

Added: branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c	Tue Aug  5 15:01:26 2008
@@ -0,0 +1,167 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-os-dependant.h>
+#include <libtracker-common/tracker-ontology.h>
+#include <string.h>
+#include "tracker-metadata-utils.h"
+
+#define METADATA_FILE_NAME_DELIMITED "File:NameDelimited"
+#define METADATA_FILE_EXT            "File:Ext"
+#define METADATA_FILE_PATH           "File:Path"
+#define METADATA_FILE_NAME           "File:Name"
+#define METADATA_FILE_LINK           "File:Link"
+#define METADATA_FILE_MIMETYPE       "File:Mime"
+#define METADATA_FILE_SIZE           "File:Size"
+#define METADATA_FILE_MODIFIED       "File:Modified"
+#define METADATA_FILE_ACCESSED       "File:Accessed"
+
+static void
+tracker_metadata_utils_get_embedded (const char      *path,
+				     const char      *mimetype,
+				     TrackerMetadata *metadata)
+{
+	gboolean success;
+	gchar **argv, *output, **values, *service_type;
+	gint i;
+
+	service_type = tracker_ontology_get_service_type_for_mime (mimetype);
+
+	if (!service_type) {
+		return;
+	}
+
+	if (!tracker_ontology_service_type_has_metadata (service_type)) {
+		g_free (service_type);
+		return;
+	}
+
+        g_free (service_type);
+
+	/* we extract metadata out of process using pipes */
+	argv = g_new0 (gchar *, 4);
+	argv[0] = g_strdup ("tracker-extract");
+	argv[1] = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
+	argv[2] = g_strdup (mimetype);
+
+	if (!argv[1] || !argv[2]) {
+		g_critical ("path or mime could not be converted to locale format");
+		g_strfreev (argv);
+		return;
+	}
+
+	success = tracker_spawn (argv, 10, &output, NULL);
+	g_strfreev (argv);
+
+	if (!success || !output)
+		return;
+
+	/* parse returned stdout and extract keys and associated metadata values */
+
+	values = g_strsplit_set (output, ";", -1);
+
+	for (i = 0; values[i]; i++) {
+		char *meta_data, *sep;
+		const char *name, *value;
+		char *utf_value;
+
+		meta_data = g_strstrip (values[i]);
+		sep = strchr (meta_data, '=');
+
+		if (!sep)
+			continue;
+
+		/* zero out the separator, so we get
+		 * NULL-terminated name and value
+		 */
+		sep[0] = '\0';
+		name = meta_data;
+		value = sep + 1;
+
+		if (!name || !value)
+			continue;
+
+		if (!g_utf8_validate (value, -1, NULL)) {
+			utf_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+		} else {
+			utf_value = g_strdup (value);
+		}
+
+		if (!utf_value)
+			continue;
+
+                tracker_metadata_insert (metadata, name, utf_value);
+	}
+
+	g_strfreev (values);
+	g_free (output);
+}
+
+TrackerMetadata *
+tracker_metadata_utils_get_data (const gchar *path)
+{
+        TrackerMetadata *metadata;
+	struct stat st;
+	const gchar *ext;
+	gchar *mimetype;
+
+	if (g_lstat (path, &st) < 0) {
+                return NULL;
+        }
+
+        metadata = tracker_metadata_new ();
+	ext = strrchr (path, '.');
+
+	if (ext) {
+		tracker_metadata_insert (metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
+	}
+
+	mimetype = tracker_file_get_mime_type (path);
+
+        tracker_metadata_insert (metadata, METADATA_FILE_NAME, g_filename_display_basename (path));
+	tracker_metadata_insert (metadata, METADATA_FILE_PATH, g_path_get_dirname (path));
+	tracker_metadata_insert (metadata, METADATA_FILE_NAME_DELIMITED,
+                                 g_filename_to_utf8 (path, -1, NULL, NULL, NULL));
+	tracker_metadata_insert (metadata, METADATA_FILE_MIMETYPE, mimetype);
+
+	if (S_ISLNK (st.st_mode)) {
+		gchar *link_path;
+
+		link_path = g_file_read_link (path, NULL);
+		tracker_metadata_insert (metadata, METADATA_FILE_LINK,
+                                         g_filename_to_utf8 (link_path, -1, NULL, NULL, NULL));
+		g_free (link_path);
+	}
+
+	/* FIXME: These should be dealt directly as integer/times/whatever, not strings */
+	tracker_metadata_insert (metadata, METADATA_FILE_SIZE,
+                                 tracker_uint_to_string (st.st_size));
+	tracker_metadata_insert (metadata, METADATA_FILE_MODIFIED,
+                                 tracker_uint_to_string (st.st_mtime));
+	tracker_metadata_insert (metadata, METADATA_FILE_ACCESSED,
+                                 tracker_uint_to_string (st.st_atime));
+
+	tracker_metadata_utils_get_embedded (path, mimetype, metadata);
+
+        return metadata;
+}

Added: branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.h	Tue Aug  5 15:01:26 2008
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_METADATA_UTILS_H__
+#define __TRACKER_METADATA_UTILS_H__
+
+#include "tracker-metadata.h"
+
+G_BEGIN_DECLS
+
+TrackerMetadata * tracker_metadata_utils_get_data (const gchar *file);
+
+G_END_DECLS
+
+#endif /* __TRACKER_METADATA_UTILS_H__ */



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