tracker r2522 - in trunk: . src/libtracker-data src/tracker-indexer
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2522 - in trunk: . src/libtracker-data src/tracker-indexer
- Date: Tue, 18 Nov 2008 18:44:42 +0000 (UTC)
Author: ifrade
Date: Tue Nov 18 18:44:42 2008
New Revision: 2522
URL: http://svn.gnome.org/viewvc/tracker?rev=2522&view=rev
Log:
Fixing metadata handling when moving files
Modified:
trunk/ChangeLog
trunk/src/libtracker-data/tracker-data-metadata.c
trunk/src/libtracker-data/tracker-data-metadata.h
trunk/src/tracker-indexer/tracker-indexer.c
Modified: trunk/src/libtracker-data/tracker-data-metadata.c
==============================================================================
--- trunk/src/libtracker-data/tracker-data-metadata.c (original)
+++ trunk/src/libtracker-data/tracker-data-metadata.c Tue Nov 18 18:44:42 2008
@@ -206,3 +206,23 @@
(GHFunc) func,
user_data);
}
+
+/**
+ * tracker_data_metadata_foreach_remove:
+ * @metadata: A #TrackerDataMetadata.
+ * @func: The function to call with each metadata.
+ * @user_data: user data to pass to the function.
+ *
+ * Calls a function for each element in @metadata and remove the element
+ * if @func returns %TRUE.
+ **/
+void
+tracker_data_metadata_foreach_remove (TrackerDataMetadata *metadata,
+ TrackerDataMetadataRemove func,
+ gpointer user_data)
+{
+ g_hash_table_foreach_remove (metadata->table,
+ (GHRFunc) func,
+ user_data);
+}
+
Modified: trunk/src/libtracker-data/tracker-data-metadata.h
==============================================================================
--- trunk/src/libtracker-data/tracker-data-metadata.h (original)
+++ trunk/src/libtracker-data/tracker-data-metadata.h Tue Nov 18 18:44:42 2008
@@ -31,22 +31,29 @@
typedef void (* TrackerDataMetadataForeach) (TrackerField *field,
gpointer value,
gpointer user_data);
+typedef gboolean (* TrackerDataMetadataRemove) (TrackerField *field,
+ gpointer value,
+ gpointer user_data);
+
+TrackerDataMetadata * tracker_data_metadata_new (void);
+void tracker_data_metadata_free (TrackerDataMetadata *metadata);
+void tracker_data_metadata_insert (TrackerDataMetadata *metadata,
+ const gchar *field_name,
+ gchar *value);
+void tracker_data_metadata_insert_values (TrackerDataMetadata *metadata,
+ const gchar *field_name,
+ GList *list);
+G_CONST_RETURN gchar *tracker_data_metadata_lookup (TrackerDataMetadata *metadata,
+ const gchar *field_name);
+G_CONST_RETURN GList *tracker_data_metadata_lookup_values (TrackerDataMetadata *metadata,
+ const gchar *field_name);
+void tracker_data_metadata_foreach (TrackerDataMetadata *metadata,
+ TrackerDataMetadataForeach func,
+ gpointer user_data);
+void tracker_data_metadata_foreach_remove (TrackerDataMetadata *metadata,
+ TrackerDataMetadataRemove func,
+ gpointer user_data);
-TrackerDataMetadata * tracker_data_metadata_new (void);
-void tracker_data_metadata_free (TrackerDataMetadata *metadata);
-void tracker_data_metadata_insert (TrackerDataMetadata *metadata,
- const gchar *field_name,
- gchar *value);
-void tracker_data_metadata_insert_values (TrackerDataMetadata *metadata,
- const gchar *field_name,
- GList *list);
-G_CONST_RETURN gchar *tracker_data_metadata_lookup (TrackerDataMetadata *metadata,
- const gchar *field_name);
-G_CONST_RETURN GList *tracker_data_metadata_lookup_values (TrackerDataMetadata *metadata,
- const gchar *field_name);
-void tracker_data_metadata_foreach (TrackerDataMetadata *metadata,
- TrackerDataMetadataForeach func,
- gpointer user_data);
G_END_DECLS
#endif /* __TRACKER_DATA_METADATA_H__*/
Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c (original)
+++ trunk/src/tracker-indexer/tracker-indexer.c Tue Nov 18 18:44:42 2008
@@ -94,6 +94,12 @@
#define TRACKER_INDEXER_ERROR "tracker-indexer-error-domain"
#define TRACKER_INDEXER_ERROR_CODE 0
+/* Properties that change in move event */
+#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"
+
typedef struct PathInfo PathInfo;
typedef struct MetadataForeachData MetadataForeachData;
typedef struct MetadataRequest MetadataRequest;
@@ -1383,6 +1389,17 @@
}
}
+static gboolean
+filter_invalid_after_move_properties (TrackerField *field,
+ gpointer value,
+ gpointer user_data)
+{
+ return g_strcmp0 (tracker_field_get_name (field), METADATA_FILE_NAME_DELIMITED)
+ && g_strcmp0 (tracker_field_get_name (field), METADATA_FILE_NAME)
+ && g_strcmp0 (tracker_field_get_name (field), METADATA_FILE_PATH)
+ && g_strcmp0 (tracker_field_get_name (field), METADATA_FILE_EXT);
+}
+
static void
item_move (TrackerIndexer *indexer,
PathInfo *info,
@@ -1390,8 +1407,9 @@
const gchar *basename)
{
TrackerService *service;
- TrackerDataMetadata *metadata;
+ TrackerDataMetadata *old_metadata, *new_metadata;
gchar *service_type;
+ gchar *new_path, *new_name, *ext;
guint32 id;
service_type = tracker_indexer_module_file_get_service_type (info->module,
@@ -1428,12 +1446,37 @@
info->other_file->path);
/*
- * Using DB directly: get old (embedded) metadata, unindex,
- * index the new metadata
+ * Updating what changes in move event (Path related properties)
*/
- metadata = tracker_data_query_embedded_metadata (service, id);
- unindex_metadata (indexer, id, service, metadata);
- index_metadata (indexer, id, service, metadata);
+ old_metadata = tracker_data_query_embedded_metadata (service, id);
+
+ tracker_data_metadata_foreach_remove (old_metadata,
+ filter_invalid_after_move_properties,
+ NULL);
+
+ unindex_metadata (indexer, id, service, old_metadata);
+
+
+ new_metadata = tracker_data_metadata_new ();
+
+ tracker_file_get_path_and_name (info->other_file->path, &new_path, &new_name);
+ tracker_data_metadata_insert (new_metadata, METADATA_FILE_PATH, new_path);
+ tracker_data_metadata_insert (new_metadata, METADATA_FILE_NAME, new_name);
+ tracker_data_metadata_insert (new_metadata,
+ METADATA_FILE_NAME_DELIMITED,
+ g_strdup (info->other_file->path));
+
+ ext = strrchr (info->other_file->path, '.');
+ if (ext) {
+ tracker_data_metadata_insert (new_metadata, METADATA_FILE_EXT, g_strdup (ext + 1));
+ }
+
+
+ index_metadata (indexer, id, service, new_metadata);
+
+ /* tracker_data_metadata_free frees the values */
+ tracker_data_metadata_free (old_metadata);
+ tracker_data_metadata_free (new_metadata);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]