tracker r2556 - in branches/turtle: . data/db src/libtracker-data src/libtracker-db src/tracker-indexer src/trackerd
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2556 - in branches/turtle: . data/db src/libtracker-data src/libtracker-db src/tracker-indexer src/trackerd
- Date: Tue, 25 Nov 2008 11:46:12 +0000 (UTC)
Author: ifrade
Date: Tue Nov 25 11:46:12 2008
New Revision: 2556
URL: http://svn.gnome.org/viewvc/tracker?rev=2556&view=rev
Log:
Turtle and backup things
Added:
branches/turtle/src/libtracker-data/tracker-turtle.c
branches/turtle/src/libtracker-data/tracker-turtle.h
branches/turtle/src/tracker-indexer/tracker-removable-device.c
branches/turtle/src/tracker-indexer/tracker-removable-device.h
branches/turtle/src/trackerd/tracker-backup.c
branches/turtle/src/trackerd/tracker-backup.h
Modified:
branches/turtle/ChangeLog
branches/turtle/configure.ac
branches/turtle/data/db/sqlite-stored-procs.sql
branches/turtle/src/libtracker-data/Makefile.am
branches/turtle/src/libtracker-data/tracker-data-query.c
branches/turtle/src/libtracker-data/tracker-data-query.h
branches/turtle/src/libtracker-db/tracker-db-manager.c
branches/turtle/src/tracker-indexer/Makefile.am
branches/turtle/src/trackerd/Makefile.am
branches/turtle/src/trackerd/tracker-main.c
Modified: branches/turtle/configure.ac
==============================================================================
--- branches/turtle/configure.ac (original)
+++ branches/turtle/configure.ac Tue Nov 25 11:46:12 2008
@@ -153,6 +153,15 @@
AM_CONDITIONAL(HAVE_GCONF, test "$have_gconf" = "yes")
+# Check for Raptor
+PKG_CHECK_MODULES(RAPTOR, [raptor], have_raptor=yes, have_raptor=no)
+AC_SUBST(RAPTOR_CFLAGS)
+AC_SUBST(RAPTOR_LIBS)
+
+if test x$have_raptor == "xyes"; then
+ AC_DEFINE(HAVE_RAPTOR, 1, [Raptor RDF parsers])
+fi
+
# Check we have the DBUS binding tool we need
AC_PATH_PROG(DBUSBINDINGTOOL, dbus-binding-tool)
if test -z $DBUSBINDINGTOOL; then
Modified: branches/turtle/data/db/sqlite-stored-procs.sql
==============================================================================
--- branches/turtle/data/db/sqlite-stored-procs.sql (original)
+++ branches/turtle/data/db/sqlite-stored-procs.sql Tue Nov 25 11:46:12 2008
@@ -62,6 +62,7 @@
/*
* Metadata/MIME queries
*/
+GetEmbeddedMetadataBackup SELECT S.Path || '/' || S.Name, F.MetadataID, F.MetadataDisplay From Services S, ServiceMetadata F WHERE (S.ID == F.ServiceID) AND (F.MetadataID IN (SELECT ID From MetadataTypes WHERE Embedded = 0)) UNION SELECT S.Path || '/' || S.Name, F.MetadataID, F.MetadataValue From Services S, ServiceNumericMetadata F WHERE (S.ID == F.ServiceID) AND (F.MetadataID IN (SELECT ID From MetadataTypes WHERE Embedded = 0)) UNION SELECT S.Path || '/' || S.Name, F.MetadataID, F.MetadataValue From Services S, ServiceKeywordMetadata F WHERE (S.ID == F.ServiceID) AND (F.MetadataID IN (SELECT ID From MetadataTypes WHERE Embedded = 0));
GetAllMetadata SELECT MetadataID, MetadataDisplay FROM ServiceMetadata WHERE ServiceID = ? UNION SELECT MetadataID, MetadataValue FROM ServiceKeywordMetadata WHERE ServiceID = ? UNION SELECT MetadataID, upper(MetadataValue) FROM ServiceNumericMetadata WHERE ServiceID = ?;
GetMetadata SELECT MetaDataDisplay FROM ServiceMetaData WHERE ServiceID = ? AND MetaDataID = ?;
GetMetadataAliases SELECT DISTINCT M.MetaName, M.ID FROM MetaDataTypes M, MetaDataChildren C WHERE M.ID = C.ChildID AND C.MetaDataID = ?;
Modified: branches/turtle/src/libtracker-data/Makefile.am
==============================================================================
--- branches/turtle/src/libtracker-data/Makefile.am (original)
+++ branches/turtle/src/libtracker-data/Makefile.am Tue Nov 25 11:46:12 2008
@@ -6,6 +6,7 @@
-DTRACKER_COMPILATION \
-I$(top_srcdir)/src \
$(DBUS_CFLAGS) \
+ $(RAPTOR_CFLAGS) \
$(GLIB2_CFLAGS)
libtracker_datadir = $(libdir)/tracker
@@ -21,6 +22,7 @@
tracker-data-update.c \
tracker-query-tree.c \
tracker-rdf-query.c \
+ tracker-turtle.c \
tracker-xesam-query.c
noinst_HEADERS = \
@@ -33,6 +35,7 @@
tracker-data-update.h \
tracker-query-tree.h \
tracker-rdf-query.h \
+ tracker-turtle.h \
tracker-xesam-query.h
libtracker_data_la_LDFLAGS = -version-info 0:0:0
@@ -41,4 +44,5 @@
$(top_builddir)/src/libtracker-db/libtracker-db.la \
$(DBUS_LIBS) \
$(GLIB2_LIBS) \
+ $(RAPTOR_LIBS) \
-lz
Modified: branches/turtle/src/libtracker-data/tracker-data-query.c
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-data-query.c (original)
+++ branches/turtle/src/libtracker-data/tracker-data-query.c Tue Nov 25 11:46:12 2008
@@ -385,6 +385,9 @@
return service_type_id;
}
+/*
+ * Result set with (metadataID, value) per row
+ */
static void
result_set_to_metadata (TrackerDBResultSet *result_set,
TrackerDataMetadata *metadata,
@@ -402,7 +405,7 @@
GValue transform = {0, };
GValue value = {0, };
gchar *str;
-
+
g_value_init (&transform, G_TYPE_STRING);
tracker_db_result_set_get (result_set, 0, &metadata_id, -1);
_tracker_db_result_set_get_value (result_set, 1, &value);
@@ -525,6 +528,23 @@
return metadata;
}
+TrackerDBResultSet *
+tracker_data_query_backup_metadata (TrackerService *service)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ GHashTable *results;
+
+ g_return_val_if_fail (TRACKER_IS_SERVICE (service), NULL);
+
+ iface = tracker_db_manager_get_db_interface_by_service (tracker_service_get_name (service));
+
+ result_set = tracker_data_manager_exec_proc (iface,
+ "GetEmbeddedMetadataBackup",
+ NULL);
+ return result_set;
+}
+
static gchar *
db_get_metadata (TrackerService *service,
guint service_id,
Modified: branches/turtle/src/libtracker-data/tracker-data-query.h
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-data-query.h (original)
+++ branches/turtle/src/libtracker-data/tracker-data-query.h Tue Nov 25 11:46:12 2008
@@ -54,6 +54,7 @@
guint32 service_id);
TrackerDataMetadata *tracker_data_query_non_embedded_metadata (TrackerService *service,
guint32 service_id);
+TrackerDBResultSet *tracker_data_query_backup_metadata (TrackerService *service);
gchar * tracker_data_query_parsed_metadata (TrackerService *service,
guint32 service_id);
gchar * tracker_data_query_unparsed_metadata (TrackerService *service,
Added: branches/turtle/src/libtracker-data/tracker-turtle.c
==============================================================================
--- (empty file)
+++ branches/turtle/src/libtracker-data/tracker-turtle.c Tue Nov 25 11:46:12 2008
@@ -0,0 +1,283 @@
+/* -*- 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.
+ *
+ * Author: Philip Van Hoof <philip codeminded be>
+ */
+
+#include "config.h"
+
+#include "tracker-turtle.h"
+
+#ifdef HAVE_RAPTOR
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/statvfs.h>
+
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <gmodule.h>
+
+#include <raptor.h>
+
+#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-language.h>
+#include <libtracker-common/tracker-parser.h>
+#include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-module-config.h>
+#include <libtracker-common/tracker-utils.h>
+
+#include <libtracker-db/tracker-db-manager.h>
+#include <libtracker-db/tracker-db-index-manager.h>
+#include <libtracker-db/tracker-db-interface-sqlite.h>
+
+#include <libtracker-data/tracker-data-query.h>
+#include <libtracker-data/tracker-data-update.h>
+
+typedef struct {
+ raptor_uri *uri;
+ gchar *about_uri;
+ raptor_serializer *serializer;
+} ForeachIdentifierInfo;
+
+#endif /* HAVE_RAPTOR */
+
+struct TurtleFile {
+ FILE *file;
+ raptor_uri *uri;
+ raptor_serializer *serializer;
+};
+
+static gboolean initialized = FALSE;
+
+void
+tracker_turtle_init (void)
+{
+ if (!initialized) {
+ raptor_init ();
+ initialized = TRUE;
+ }
+}
+
+void
+tracker_turtle_shutdown (void)
+{
+ if (initialized) {
+ raptor_finish ();
+ initialized = FALSE;
+ }
+}
+
+#ifdef HAVE_RAPTOR
+
+static void
+foreach_in_metadata (TrackerField *field, gpointer value, gpointer user_data)
+{
+
+ ForeachIdentifierInfo *info = user_data;
+ raptor_statement statement;
+
+ statement.subject = info->about_uri;
+ statement.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+ statement.predicate = tracker_field_get_name (field);
+ statement.predicate_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+ statement.object = value;
+ statement.object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+
+ raptor_serialize_statement (info->serializer,
+ &statement);
+}
+
+#endif /* HAVE_RAPTOR */
+
+
+
+void
+tracker_turtle_append (const gchar *turtle_file,
+ const gchar *about_uri,
+ TrackerDataMetadata *metadata)
+{
+#ifdef HAVE_RAPTOR
+ FILE *file = fopen (turtle_file, "a");
+
+ /* Similar to a+ */
+
+ if (!file)
+ file = fopen (turtle_file, "w");
+
+ if (file) {
+ ForeachIdentifierInfo *info = g_slice_new (ForeachIdentifierInfo);
+
+ info->serializer = raptor_new_serializer ("turtle");
+
+ info->uri = raptor_new_uri (turtle_file);
+ info->about_uri = g_strdup_printf ("<%s>", about_uri);
+
+ raptor_serialize_start_to_file_handle (info->serializer,
+ info->uri, file);
+
+ tracker_data_metadata_foreach (metadata,
+ foreach_in_metadata,
+ info);
+
+ g_free (info->about_uri);
+ raptor_free_uri (info->uri);
+ raptor_serialize_end (info->serializer);
+ raptor_free_serializer(info->serializer);
+ g_slice_free (ForeachIdentifierInfo, info);
+
+ fclose (file);
+ }
+
+#endif /* HAVE_RAPTOR */
+}
+
+
+typedef struct {
+ gchar *about_uri;
+ TrackerDataMetadata *metadata;
+} MetadataItem;
+
+
+
+void
+tracker_turtle_append_multiple (const gchar *turtle_file, GPtrArray *items)
+{
+#ifdef HAVE_RAPTOR
+ FILE *file = fopen (turtle_file, "a");
+
+ /* Similar to a+ */
+
+ if (!file)
+ file = fopen (turtle_file, "w");
+
+ if (file) {
+ guint cnt;
+ ForeachIdentifierInfo *info = g_slice_new (ForeachIdentifierInfo);
+
+ info->serializer = raptor_new_serializer ("turtle");
+
+ info->uri = raptor_new_uri (turtle_file);
+
+ raptor_serialize_start_to_file_handle (info->serializer,
+ info->uri, file);
+
+ for (cnt = 0; cnt < items->len; cnt++) {
+ MetadataItem *item = g_ptr_array_index (items, cnt);
+
+ info->about_uri = g_strdup_printf ("<%s>", item->about_uri);
+ tracker_data_metadata_foreach (item->metadata,
+ foreach_in_metadata,
+ info);
+ g_free (info->about_uri);
+ }
+
+ raptor_free_uri (info->uri);
+ raptor_serialize_end (info->serializer);
+ raptor_free_serializer(info->serializer);
+ g_slice_free (ForeachIdentifierInfo, info);
+
+ fclose (file);
+ }
+#endif /* HAVE_RAPTOR */
+}
+
+TurtleFile *
+tracker_turtle_open (const gchar *turtle_file)
+{
+#ifdef HAVE_RAPTOR
+ TurtleFile *turtle = NULL;
+ gchar *uri_string;
+
+ turtle = g_new0 (TurtleFile, 1);
+
+ turtle->file = fopen (turtle_file, "a");
+
+ /* Similar to a+ */
+ if (!turtle->file)
+ turtle->file = fopen (turtle_file, "w");
+
+ turtle->serializer = raptor_new_serializer ("turtle");
+
+ uri_string = raptor_uri_filename_to_uri_string (turtle_file);
+ turtle->uri = raptor_new_uri (uri_string);
+ raptor_serialize_start_to_file_handle (turtle->serializer,
+ turtle->uri, turtle->file);
+
+ g_free (uri_string);
+ return turtle;
+#else
+ return NULL;
+#endif
+}
+
+
+void
+tracker_turtle_add_triple (TurtleFile *turtle,
+ const gchar *uri,
+ TrackerField *property,
+ const gchar *value)
+{
+#ifdef HAVE_RAPTOR
+ gchar *about_uri;
+ raptor_statement statement;
+
+ if (g_str_has_prefix (uri, "file://")) {
+ about_uri = g_strdup_printf ("<%s>", uri);
+ } else {
+ about_uri = g_strdup_printf ("<file://%s>", uri);
+ }
+
+ g_debug ("turtle <%s, %s, %s>",
+ about_uri,
+ tracker_field_get_name (property),
+ value);
+
+ statement.subject = about_uri;
+ statement.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+ statement.predicate = tracker_field_get_name (property);
+ statement.predicate_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+ statement.object = value;
+ statement.object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+
+ raptor_serialize_statement (turtle->serializer,
+ &statement);
+
+ g_free (about_uri);
+
+#endif
+}
+
+
+void
+tracker_turtle_close (TurtleFile *turtle)
+{
+#ifdef HAVE_RAPTOR
+ raptor_free_uri (turtle->uri);
+ raptor_serialize_end (turtle->serializer);
+ raptor_free_serializer(turtle->serializer);
+ fclose (turtle->file);
+
+ raptor_finish ();
+#endif
+}
+
+
+
Added: branches/turtle/src/libtracker-data/tracker-turtle.h
==============================================================================
--- (empty file)
+++ branches/turtle/src/libtracker-data/tracker-turtle.h Tue Nov 25 11:46:12 2008
@@ -0,0 +1,54 @@
+/* -*- 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.
+ *
+ * Author: Philip Van Hoof <philip codeminded be>
+ */
+
+#ifndef __TRACKER_TURTLE_H__
+#define __TRACKER_TURTLE_H__
+
+#include "tracker-data-metadata.h"
+#include <stdio.h>
+
+typedef struct TurtleFile TurtleFile;
+
+/* Initialization (use in both cases) */
+void tracker_turtle_init (void);
+void tracker_turtle_shutdown (void);
+
+
+/* Instant writing access */
+void tracker_turtle_append (const gchar *turtle_file,
+ const gchar *about_uri,
+ TrackerDataMetadata *metadata);
+void tracker_turtle_append_multiple (const gchar *turtle_file,
+ GPtrArray *items);
+
+
+/* Transactions style */
+TurtleFile *tracker_turtle_open (const gchar *turtle_file);
+void tracker_turtle_add_triple (TurtleFile *turtle,
+ const gchar *uri,
+ TrackerField *property,
+ const gchar *value);
+void tracker_turtle_close (TurtleFile *turtle);
+
+
+#endif /* __TRACKER_TURTLE_H__ */
Modified: branches/turtle/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/turtle/src/libtracker-db/tracker-db-manager.c (original)
+++ branches/turtle/src/libtracker-db/tracker-db-manager.c Tue Nov 25 11:46:12 2008
@@ -2654,12 +2654,20 @@
g_free (services_dir);
g_free (sql_dir);
- if (file_iface)
+ if (file_iface) {
g_object_unref (file_iface);
- if (email_iface)
+ file_iface = NULL;
+ }
+
+ if (email_iface) {
g_object_unref (email_iface);
- if (xesam_iface)
+ email_iface = NULL;
+ }
+
+ if (xesam_iface) {
g_object_unref (xesam_iface);
+ xesam_iface = NULL;
+ }
/* Since we don't reference this enum anywhere, we do
Modified: branches/turtle/src/tracker-indexer/Makefile.am
==============================================================================
--- branches/turtle/src/tracker-indexer/Makefile.am (original)
+++ branches/turtle/src/tracker-indexer/Makefile.am Tue Nov 25 11:46:12 2008
@@ -39,7 +39,10 @@
tracker-indexer-module.c \
tracker-indexer-module.h \
tracker-main.c \
- tracker-marshal-main.c
+ tracker-marshal-main.c \
+ tracker-thumbnailer.c \
+ tracker-thumbnailer.h \
+ tracker-removable-device.c \
tracker_indexer_LDADD = \
libtracker-indexer.la \
Added: branches/turtle/src/tracker-indexer/tracker-removable-device.c
==============================================================================
--- (empty file)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.c Tue Nov 25 11:46:12 2008
@@ -0,0 +1,247 @@
+/* -*- 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.
+ *
+ * Author: Philip Van Hoof <philip codeminded be>
+ */
+
+#include "tracker-removable-device.h"
+
+#ifdef HAVE_RAPTOR
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/statvfs.h>
+
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <gmodule.h>
+
+#include <raptor.h>
+
+#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-dbus.h>
+#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-language.h>
+#include <libtracker-common/tracker-parser.h>
+#include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-module-config.h>
+#include <libtracker-common/tracker-utils.h>
+
+#include <libtracker-db/tracker-db-manager.h>
+#include <libtracker-db/tracker-db-index-manager.h>
+#include <libtracker-db/tracker-db-interface-sqlite.h>
+
+#include <libtracker-data/tracker-data-query.h>
+#include <libtracker-data/tracker-data-update.h>
+
+typedef struct {
+ const gchar *ttl_file;
+ gchar *last_subject;
+ TrackerDataMetadata *metadata;
+ gchar *base;
+ guint amount;
+ TrackerIndexer *indexer;
+ gchar *rdf_type;
+} TurtleParseInfo;
+
+static void
+commit_turtle_parse_info_data (TurtleParseInfo *info, gboolean may_flush)
+{
+
+ if (info->last_subject) {
+
+ /* We have it as a URI, database api wants Paths. Update this when
+ * the database api becomes sane and uses URIs everywhere */
+
+ tracker_data_replace_service (info->last_subject + 7,
+ info->rdf_type,
+ info->metadata);
+
+ info->amount++;
+
+ tracker_data_metadata_free (info->metadata);
+ g_free (info->last_subject);
+ g_free (info->rdf_type);
+ info->last_subject = NULL;
+ info->metadata = NULL;
+ info->rdf_type = NULL;
+ }
+
+ /* We commit per transaction of 100 here, and then we also iterate the
+ * mainloop so that the state-machine gets the opportunity to run for a
+ * moment */
+
+ if (may_flush && info->amount > 100) {
+ tracker_indexer_commit_transaction (info->indexer);
+ g_main_context_iteration (NULL, FALSE);
+ tracker_indexer_open_transaction (info->indexer);
+ info->amount = 0;
+ }
+}
+
+static void
+consume_triple (void* user_data, const raptor_statement* triple)
+{
+ TurtleParseInfo *info = user_data;
+ gchar *subject;
+
+ subject = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject);
+
+ if (!info->last_subject || strcmp (subject, info->last_subject) != 0) {
+
+ /* Commit previous subject */
+
+ commit_turtle_parse_info_data (info, TRUE);
+ info->last_subject = g_strdup (subject);
+ info->metadata = tracker_data_metadata_new ();
+ }
+
+ if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_LITERAL) {
+ gchar *predicate;
+
+ predicate = g_strdup ((const gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate));
+
+ if (strcmp (predicate, "rdf:type") == 0) {
+ g_free (info->rdf_type);
+
+ /* TODO: ontology */
+ /* Change this when Files and Emails becomes File and Email */
+
+ info->rdf_type = g_strdup_printf ("%ss", triple->object);
+ } else
+ tracker_data_metadata_insert (info->metadata,
+ predicate,
+ g_strdup (triple->object));
+
+ } else if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE) {
+ gchar *key = g_strdup_printf ("file://%s/:", info->base);
+
+ if (strcmp (key, triple->object) == 0) {
+ gchar *predicate;
+
+ predicate = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate);
+
+ tracker_data_metadata_insert (info->metadata,
+ predicate,
+ g_strdup (""));
+
+ }
+
+ g_free (key);
+ }
+
+}
+
+static void
+raptor_error (void *user_data, raptor_locator* locator, const char *message)
+{
+ TurtleParseInfo *info = user_data;
+ g_message ("RAPTOR parse error: %s for %s\n", message, info->ttl_file);
+}
+
+
+#endif /* HAVE_RAPTOR */
+
+void
+tracker_removable_device_process_ttl (TrackerIndexer *indexer, const gchar *file)
+{
+#ifdef HAVE_RAPTOR
+
+ unsigned char *uri_stringa, *uri_stringb;
+ raptor_uri *uri, *base_uri;
+ static gboolean has_init = FALSE;
+ raptor_parser *parser;
+ TurtleParseInfo *info;
+ gchar *copy_file, *ptr;
+
+ if (!has_init)
+ raptor_init();
+
+ parser = raptor_new_parser ("turtle");
+
+ info = g_slice_new0 (TurtleParseInfo);
+
+ info->ttl_file = file;
+ info->indexer = g_object_ref (indexer);
+ info->amount = 0;
+
+ raptor_set_statement_handler (parser, info, consume_triple);
+ raptor_set_fatal_error_handler (parser, info, raptor_error);
+ raptor_set_error_handler (parser, info, raptor_error);
+ raptor_set_warning_handler (parser, info, raptor_error);
+
+ copy_file = g_strdup (file);
+
+ ptr = strstr (copy_file, "/metadata/metadata.ttl");
+ if (ptr) {
+ /* .cache remains, and will be cut later, just like dummy_file is */
+ *ptr = '\0';
+ } else {
+ g_free (copy_file);
+ copy_file = g_strdup ("/home/pvanhoof/dummy_file");
+ }
+
+
+ uri_stringa = raptor_uri_filename_to_uri_string (file);
+ uri_stringb = raptor_uri_filename_to_uri_string (copy_file);
+
+ uri = raptor_new_uri (uri_stringa);
+ base_uri = raptor_new_uri (uri_stringb);
+
+ /* Take the file (dummy_file or .cache) from base */
+ ptr = strrchr (copy_file, '/');
+ if (ptr)
+ *ptr = '\0';
+
+ info->base = copy_file;
+
+ tracker_indexer_open_transaction (info->indexer);
+
+ GTimer *timer = g_timer_new ();
+ g_timer_start (timer);
+
+ raptor_parse_file (parser, uri, base_uri);
+ /* Commit final subject */
+
+ commit_turtle_parse_info_data (info, FALSE);
+
+ g_timer_stop (timer);
+ g_print ("\nTIME: %f\n", g_timer_elapsed (timer, NULL));
+
+ tracker_indexer_commit_transaction (info->indexer);
+
+ g_free (copy_file);
+ g_object_unref (info->indexer);
+ g_slice_free (TurtleParseInfo, info);
+
+ raptor_free_parser (parser);
+
+ raptor_free_uri (base_uri);
+ raptor_free_uri (uri);
+ raptor_free_memory (uri_stringa);
+ raptor_free_memory (uri_stringb);
+
+
+ /* raptor_finish(); */
+
+#endif /* HAVE_RAPTOR */
+
+}
Added: branches/turtle/src/tracker-indexer/tracker-removable-device.h
==============================================================================
--- (empty file)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.h Tue Nov 25 11:46:12 2008
@@ -0,0 +1,36 @@
+/* -*- 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.
+ *
+ * Author: Philip Van Hoof <philip codeminded be>
+ */
+
+#ifndef __TRACKER_REMOVABLE_DEVICE_H__
+#define __TRACKER_REMOVABLE_DEVICE_H__
+
+#include "tracker-indexer.h"
+#include <libtracker-data/tracker-data-metadata.h>
+
+void tracker_removable_device_process_ttl (TrackerIndexer *indexer, const gchar *file);
+
+
+#endif /* __TRACKER_REMOVABLE_DEVICE_H__ */
+
+
+
Modified: branches/turtle/src/trackerd/Makefile.am
==============================================================================
--- branches/turtle/src/trackerd/Makefile.am (original)
+++ branches/turtle/src/trackerd/Makefile.am Tue Nov 25 11:46:12 2008
@@ -29,6 +29,8 @@
libexec_PROGRAMS = trackerd
trackerd_SOURCES = \
+ tracker-backup.h \
+ tracker-backup.c \
tracker-crawler.c \
tracker-crawler.h \
tracker-daemon.c \
Added: branches/turtle/src/trackerd/tracker-backup.c
==============================================================================
--- (empty file)
+++ branches/turtle/src/trackerd/tracker-backup.c Tue Nov 25 11:46:12 2008
@@ -0,0 +1,122 @@
+#include "tracker-backup.h"
+#include <libtracker-data/tracker-data-query.h>
+#include <libtracker-data/tracker-turtle.h>
+#include <glib.h>
+
+static gchar *
+list_to_str (GList *list) {
+
+ GList *tmp;
+ GString *str;
+
+ str = g_string_new ("");
+
+ for (tmp = list; tmp != NULL; tmp = tmp->next) {
+ g_string_append (str, g_strdup ((gchar *)tmp->data));
+ g_string_append (str, "-");
+ }
+
+ return g_string_free (str, FALSE);
+}
+
+static void
+debug_tracker_data_metadata (TrackerField *field, gpointer value, gpointer user_data)
+{
+ if (tracker_field_get_multiple_values (field)) {
+ g_debug (" tracker_backup: %s = %s",
+ tracker_field_get_name (field),
+ list_to_str ((GList *)value));
+ } else {
+ g_debug (" tracker_backup: %s = %s",
+ tracker_field_get_name (field),
+ (gchar *) value);
+ }
+}
+
+static void
+debug_sophisticated_metadata (gpointer key, gpointer value, gpointer user_data)
+{
+ gchar *uri = (gchar *)key;
+ TrackerDataMetadata *metadata = (TrackerDataMetadata *)value;
+
+ g_debug (" tracker_backup : %s", uri);
+ tracker_data_metadata_foreach (metadata, debug_tracker_data_metadata, NULL);
+}
+
+/*
+ * (uri, metadataid, value)
+ */
+static void
+extended_result_set_to_turtle (TrackerDBResultSet *result_set)
+{
+ TrackerField *field;
+ gint metadata_id;
+ gboolean valid = TRUE;
+ TrackerDataMetadata *metadata;
+ TurtleFile *turtle_file;
+
+ turtle_file = tracker_turtle_open ("/home/ivan/tracker-saving-things.ttl");
+
+ while (valid) {
+ GValue transform = {0, };
+ GValue value = {0, };
+ gchar *str;
+ gchar *uri;
+
+ g_value_init (&transform, G_TYPE_STRING);
+ tracker_db_result_set_get (result_set, 0, &uri, -1);
+ tracker_db_result_set_get (result_set, 1, &metadata_id, -1);
+ _tracker_db_result_set_get_value (result_set, 2, &value);
+
+ if (g_value_transform (&value, &transform)) {
+ str = g_value_dup_string (&transform);
+
+ if (!str) {
+ str = g_strdup ("");
+ } else if (!g_utf8_validate (str, -1, NULL)) {
+ g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
+ g_free (str);
+ str = g_strdup ("");
+ }
+ } else {
+ str = g_strdup ("");
+ }
+
+ field = tracker_ontology_get_field_by_id (metadata_id);
+ if (!field) {
+ g_critical ("Field id %d in database but not in tracker-ontology",
+ metadata_id);
+ g_free (str);
+ return;
+ }
+ g_debug ("Insertion in turtle");
+ tracker_turtle_add_triple (turtle_file, uri, field, str);
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ tracker_turtle_close (turtle_file);
+}
+
+
+void
+tracker_backup_save ()
+{
+ TrackerDBResultSet *data;
+ TrackerService *service;
+ GHashTable *trash;
+
+ g_message ("***** tracker_backup: Saving metadata in turtle file *****");
+
+ service = tracker_ontology_get_service_by_name ("Files");
+ data = tracker_data_query_backup_metadata (service);
+
+ extended_result_set_to_turtle (data);
+}
+
+void
+tracker_backup_restore ()
+{
+ g_message ("***** Restoring metadata from turtle file *****");
+}
+
Added: branches/turtle/src/trackerd/tracker-backup.h
==============================================================================
--- (empty file)
+++ branches/turtle/src/trackerd/tracker-backup.h Tue Nov 25 11:46:12 2008
@@ -0,0 +1,9 @@
+#ifndef __TRACKER_BACKUP_H__
+#define __TRACKER_BACKUP_H__
+
+#include <glib.h>
+
+void tracker_backup_save (void);
+void tracker_backup_restore (void);
+
+#endif /* __TRACKER_BACKUP_H__ */
Modified: branches/turtle/src/trackerd/tracker-main.c
==============================================================================
--- branches/turtle/src/trackerd/tracker-main.c (original)
+++ branches/turtle/src/trackerd/tracker-main.c Tue Nov 25 11:46:12 2008
@@ -60,6 +60,7 @@
#include "tracker-processor.h"
#include "tracker-status.h"
#include "tracker-xesam-manager.h"
+#include "tracker-backup.h"
#ifdef G_OS_WIN32
#include <windows.h>
@@ -746,6 +747,17 @@
return FALSE;
}
+static void
+crawling_finished_cb (TrackerProcessor *processor, gpointer user_data)
+{
+ gulong *callback_id = (gulong *)user_data;
+
+ g_debug ("Uninstalling initial crawling callback");
+ g_signal_handler_disconnect (processor, *callback_id);
+
+ tracker_backup_restore ();
+}
+
gint
main (gint argc, gchar *argv[])
{
@@ -763,6 +775,7 @@
TrackerDBManagerFlags flags = 0;
TrackerDBIndexManagerFlags index_flags = 0;
gboolean is_first_time_index;
+ gulong callback_id;
g_type_init ();
@@ -785,7 +798,7 @@
/* Set timezone info */
tzset ();
-
+
/* Translators: this messagge will apper immediately after the
* usage string - Usage: COMMAND <THIS_MESSAGE>
*/
@@ -918,6 +931,28 @@
index_flags |= TRACKER_DB_INDEX_MANAGER_READONLY;
if (force_reindex) {
+ g_message ("***** Saving metadata in turtle file *****");
+
+ /* Init the DB stack */
+ tracker_db_manager_init (0, &is_first_time_index, TRUE);
+
+ tracker_db_index_manager_init (0,
+ tracker_config_get_min_bucket_count (config),
+ tracker_config_get_max_bucket_count (config));
+
+ file_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_FILE);
+ email_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_EMAIL);
+
+ tracker_data_manager_init (config, language, file_index, email_index);
+
+ tracker_backup_save ();
+
+ /* Shutdown the DB stack */
+ tracker_data_manager_shutdown ();
+
+ tracker_db_index_manager_shutdown ();
+ tracker_db_manager_shutdown ();
+
flags |= TRACKER_DB_MANAGER_FORCE_REINDEX;
index_flags |= TRACKER_DB_INDEX_MANAGER_FORCE_REINDEX;
}
@@ -1033,6 +1068,14 @@
tracker_status_set_and_signal (TRACKER_STATUS_IDLE);
}
+ if (flags & TRACKER_DB_MANAGER_FORCE_REINDEX) {
+ g_debug ("Setting callback for crawling finish detection");
+ callback_id = g_signal_connect (private->processor, "finished",
+ G_CALLBACK (crawling_finished_cb),
+ &callback_id);
+ }
+
+
if (tracker_status_get_is_running ()) {
private->main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (private->main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]