tracker r2608 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2608 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- Date: Fri, 28 Nov 2008 11:39:12 +0000 (UTC)
Author: pvanhoof
Date: Fri Nov 28 11:39:12 2008
New Revision: 2608
URL: http://svn.gnome.org/viewvc/tracker?rev=2608&view=rev
Log:
2008-11-28 Philip Van Hoof <philip codeminded be>
* src/tracker-indexer/tracker-removable-device.c
* src/tracker-indexer/tracker-indexer.c
* src/libtracker-data/tracker-turtle.c: Implementing add, remove, move
events for Turtle (untested)
Modified:
branches/turtle/ChangeLog
branches/turtle/src/libtracker-data/tracker-turtle.c
branches/turtle/src/tracker-indexer/tracker-indexer.c
branches/turtle/src/tracker-indexer/tracker-removable-device.c
Modified: branches/turtle/src/libtracker-data/tracker-turtle.c
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-turtle.c (original)
+++ branches/turtle/src/libtracker-data/tracker-turtle.c Fri Nov 28 11:39:12 2008
@@ -392,7 +392,7 @@
commit_turtle_parse_info_optimizer (info);
raptor_serialize_end (info->serializer);
- raptor_free_serializer(info->serializer);
+ raptor_free_serializer (info->serializer);
fclose (target_file);
g_slice_free (TurtleOptimizerInfo, info);
Modified: branches/turtle/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/turtle/src/tracker-indexer/tracker-indexer.c (original)
+++ branches/turtle/src/tracker-indexer/tracker-indexer.c Fri Nov 28 11:39:12 2008
@@ -1513,6 +1513,7 @@
gchar *new_path, *new_name, *ext;
GFile *file, *other_file;
gchar *path, *other_path;
+ gchar *mount_point = NULL;
guint32 id;
service = get_service_for_file (info->other_module_file, info->module);
@@ -1541,6 +1542,27 @@
tracker_data_update_move_service (service, path, other_path);
+ if (tracker_hal_path_is_on_removable_device (indexer->private->hal,
+ path,
+ &mount_point,
+ NULL) &&
+ tracker_hal_path_is_on_removable_device (indexer->private->hal,
+ other_path,
+ NULL,
+ NULL) ) {
+
+ tracker_removable_device_add_move (indexer,
+ mount_point,
+ path,
+ other_path);
+ } else {
+ tracker_removable_device_add_removal (indexer,
+ mount_point,
+ path);
+ }
+
+ g_free (mount_point);
+
/*
* Updating what changes in move event (Path related properties)
*/
Modified: branches/turtle/src/tracker-indexer/tracker-removable-device.c
==============================================================================
--- branches/turtle/src/tracker-indexer/tracker-removable-device.c (original)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.c Fri Nov 28 11:39:12 2008
@@ -78,9 +78,14 @@
gchar *rdf_type;
} TurtleStorerInfo;
+typedef enum {
+ REMOVAL,
+ REPLACE,
+ MOVE
+} StorerTask;
static void
-commit_turtle_parse_info_storer (TurtleStorerInfo *info, gboolean may_flush, gboolean is_removal)
+commit_turtle_parse_info_storer (TurtleStorerInfo *info, gboolean may_flush, StorerTask task, gchar *destination)
{
if (info->last_subject) {
@@ -88,13 +93,25 @@
* the database api becomes sane and uses URIs everywhere, the
* '+ 7' means that we cut away the 'file://' prefix. */
- if (!is_removal)
+ switch (task) {
+ case REMOVAL:
+ tracker_data_delete_service (info->last_subject + 7,
+ info->rdf_type);
+ break;
+ case MOVE:
+ tracker_data_delete_service (info->last_subject + 7,
+ info->rdf_type);
+ tracker_data_replace_service (destination + 7,
+ info->rdf_type,
+ info->metadata);
+ break;
+ default:
+ case REPLACE:
tracker_data_replace_service (info->last_subject + 7,
info->rdf_type,
info->metadata);
- else
- tracker_data_delete_service (info->last_subject + 7,
- info->rdf_type);
+ break;
+ }
info->amount++;
@@ -132,7 +149,7 @@
if (!info->last_subject || strcmp (subject, info->last_subject) != 0) {
/* Commit previous subject */
- commit_turtle_parse_info_storer (info, TRUE, FALSE);
+ commit_turtle_parse_info_storer (info, TRUE, REPLACE, NULL);
/* Install next subject */
info->last_subject = g_strdup (subject);
@@ -180,7 +197,7 @@
* field will be cleared for the next subject to be set
* ready first next process loop. */
- commit_turtle_parse_info_storer (info, FALSE, TRUE);
+ commit_turtle_parse_info_storer (info, FALSE, REMOVAL, NULL);
}
else
if (triple->object && strcmp (key, triple->object) == 0 &&
@@ -209,7 +226,16 @@
}
}
}
+ else
+ if (triple->object && strcmp (key, triple->object) != 0 &&
+ triple->predicate && strcmp (key, triple->predicate) == 0)
+ {
+ gchar *object;
+ /* <URI> <:> <to-URI> - is a move of the subject */
+ object = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->object);
+ commit_turtle_parse_info_storer (info, FALSE, MOVE, object);
+ }
g_free (key);
}
@@ -270,8 +296,10 @@
tracker_turtle_process (file, consume_triple_storer, info);
- /* Commit final subject (or loop doesn't handle the very last) */
- commit_turtle_parse_info_storer (info, FALSE, FALSE);
+ /* Commit final subject (our loop doesn't handle the very last)
+ * It can't be a REMOVAL nor MOVE as those happen immediately. */
+
+ commit_turtle_parse_info_storer (info, FALSE, REPLACE, NULL);
/* We will (always) be left in open state, so we commit the
@@ -290,8 +318,67 @@
}
+typedef struct {
+ raptor_serializer *serializer;
+ gchar *about_uri;
+} AddMetadataInfo;
+
+static void
+set_metadata (gpointer key, gpointer value, gpointer user_data)
+{
+ raptor_statement *statement;
+ AddMetadataInfo *item = user_data;
+ const gchar *about_uri = item->about_uri;
+ raptor_serializer *serializer = item->serializer;
+
+ statement = g_new0 (raptor_statement, 1);
+
+ statement->subject = (void *) raptor_new_uri (about_uri);
+ statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->predicate = (void *) raptor_new_uri (key);
+ statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->object = (unsigned char *) g_strdup (value);
+ statement->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+
+ raptor_serialize_statement (serializer,
+ statement);
+
+ raptor_free_uri ((raptor_uri *) statement->subject);
+ raptor_free_uri ((raptor_uri *) statement->predicate);
+ g_free ((unsigned char *) statement->object);
+
+ g_free (statement);
+}
+
+
/* TODO URI branch: path -> uri */
+static void
+foreach_in_metadata_set_metadata (TrackerField *field,
+ gpointer value,
+ gpointer user_data)
+{
+ AddMetadataInfo *info = user_data;
+ gchar *parsed_value;
+ gint throttle;
+
+
+ if (!tracker_field_get_multiple_values (field)) {
+ set_metadata (field, value, user_data);
+ } else {
+ GList *list;
+
+ list = value;
+
+ while (list) {
+ set_metadata (field, list->data, user_data);
+ list = list->next;
+ }
+ }
+
+}
void
tracker_removable_device_add_metadata (TrackerIndexer *indexer,
const gchar *mount_point,
@@ -299,9 +386,44 @@
TrackerDataMetadata *metadata)
{
#ifdef HAVE_RAPTOR
+ AddMetadataInfo *info = g_slice_new (AddMetadataInfo);
+ gchar *file;
+ FILE *target_file;
+ raptor_uri *suri;
- /* Implement adding metadata */
+ file = g_build_filename (mount_point, ".cache",
+ "metadata", "metadata.ttl", NULL);
+
+ target_file = fopen (file, "a");
+ /* Similar to a+ */
+ if (!target_file)
+ target_file = fopen (file, "w");
+
+ if (!target_file) {
+ g_free (target_file);
+ g_free (file);
+ return;
+ }
+
+ info->serializer = raptor_new_serializer ("turtle");
+ info->about_uri = g_strdup_printf ("file://%s", path);
+
+ suri = raptor_new_uri ("/");
+ raptor_serialize_start_to_file_handle (info->serializer,
+ suri, target_file);
+
+ tracker_data_metadata_foreach (metadata,
+ foreach_in_metadata_set_metadata,
+ info);
+
+ g_free (info->about_uri);
+ raptor_serialize_end (info->serializer);
+ raptor_free_serializer (info->serializer);
+ fclose (target_file);
+ raptor_free_uri (suri);
+
+ g_slice_free (AddMetadataInfo, info);
#endif /* HAVE_RAPTOR */
}
@@ -313,8 +435,59 @@
const gchar *path)
{
#ifdef HAVE_RAPTOR
+ gchar *file, *about_uri;
+ FILE *target_file;
+ raptor_uri *suri;
+ raptor_statement *statement;
+ raptor_serializer *serializer;
+
+ file = g_build_filename (mount_point, ".cache",
+ "metadata", "metadata.ttl", NULL);
+
+ target_file = fopen (file, "a");
+ /* Similar to a+ */
+ if (!target_file)
+ target_file = fopen (file, "w");
+
+ if (!target_file) {
+ g_free (target_file);
+ g_free (file);
+ return;
+ }
+
+ serializer = raptor_new_serializer ("turtle");
+ about_uri = g_strdup_printf ("file://%s", path);
+
+ suri = raptor_new_uri ("/");
+
+ raptor_serialize_start_to_file_handle (serializer,
+ suri, target_file);
+
+ statement = g_new0 (raptor_statement, 1);
+
+ statement->subject = (void *) raptor_new_uri (about_uri);
+ statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->predicate = (void *) raptor_new_uri (NULL);
+ statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->object = (void *) raptor_new_uri (NULL);
+ statement->object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
- /* Implement adding metadata */
+ raptor_serialize_statement (serializer,
+ statement);
+
+ raptor_free_uri ((raptor_uri *) statement->subject);
+ raptor_free_uri ((raptor_uri *) statement->predicate);
+ g_free ((unsigned char *) statement->object);
+
+ g_free (statement);
+
+ g_free (about_uri);
+ raptor_serialize_end (serializer);
+ raptor_free_serializer (serializer);
+ fclose (target_file);
+ raptor_free_uri (suri);
#endif /* HAVE_RAPTOR */
}
@@ -328,8 +501,62 @@
const gchar *to_path)
{
#ifdef HAVE_RAPTOR
+ gchar *file, *about_uri, *to_uri;
+ FILE *target_file;
+ raptor_uri *suri;
+ raptor_statement *statement;
+ raptor_serializer *serializer;
+
+ file = g_build_filename (mount_point, ".cache",
+ "metadata", "metadata.ttl", NULL);
+
+ target_file = fopen (file, "a");
+ /* Similar to a+ */
+ if (!target_file)
+ target_file = fopen (file, "w");
+
+ if (!target_file) {
+ g_free (target_file);
+ g_free (file);
+ return;
+ }
+
+ serializer = raptor_new_serializer ("turtle");
+ about_uri = g_strdup_printf ("file://%s", from_path);
+ to_uri = g_strdup_printf ("file://%s", to_path);
+
+ suri = raptor_new_uri ("/");
+
+ raptor_serialize_start_to_file_handle (serializer,
+ suri, target_file);
+
+ statement = g_new0 (raptor_statement, 1);
+
+ statement->subject = (void *) raptor_new_uri (about_uri);
+ statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->predicate = (void *) raptor_new_uri (NULL);
+ statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ statement->object = (void *) raptor_new_uri (to_uri);
+ statement->object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+
+ raptor_serialize_statement (serializer,
+ statement);
+
+ raptor_free_uri ((raptor_uri *) statement->subject);
+ raptor_free_uri ((raptor_uri *) statement->predicate);
+ g_free ((unsigned char *) statement->object);
+
+ g_free (statement);
+
+ g_free (about_uri);
+ g_free (to_uri);
+ raptor_serialize_end (serializer);
+ raptor_free_serializer (serializer);
+ fclose (target_file);
+ raptor_free_uri (suri);
- /* Implement adding metadata */
#endif /* HAVE_RAPTOR */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]