Commit 74d20884 authored by Carlos Garnacho's avatar Carlos Garnacho Committed by Martyn Russell

libtracker-miner: Make filesystem properties registration global

This is so GDestroyNotify for set properties is available at the
time of destructing a file node.
parent 97956265
......@@ -1124,10 +1124,21 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
/* Initialize property quarks */
quark_property_crawled = g_quark_from_static_string ("tracker-property-crawled");
tracker_file_system_register_property (quark_property_crawled, NULL);
quark_property_queried = g_quark_from_static_string ("tracker-property-queried");
tracker_file_system_register_property (quark_property_queried, NULL);
quark_property_iri = g_quark_from_static_string ("tracker-property-iri");
tracker_file_system_register_property (quark_property_iri, g_free);
quark_property_store_mtime = g_quark_from_static_string ("tracker-property-store-mtime");
tracker_file_system_register_property (quark_property_store_mtime,
g_free);
quark_property_filesystem_mtime = g_quark_from_static_string ("tracker-property-filesystem-mtime");
tracker_file_system_register_property (quark_property_filesystem_mtime,
g_free);
}
static void
......@@ -1154,22 +1165,6 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
/* Initialize filesystem and register properties */
priv->file_system = tracker_file_system_new ();
/* booleans */
tracker_file_system_register_property (priv->file_system,
quark_property_crawled, NULL);
tracker_file_system_register_property (priv->file_system,
quark_property_queried, NULL);
/* strings */
tracker_file_system_register_property (priv->file_system,
quark_property_iri, g_free);
tracker_file_system_register_property (priv->file_system,
quark_property_store_mtime,
g_free);
tracker_file_system_register_property (priv->file_system,
quark_property_filesystem_mtime,
g_free);
priv->timer = g_timer_new ();
priv->stopped = TRUE;
......
......@@ -28,9 +28,10 @@ typedef struct _TrackerFileSystemPrivate TrackerFileSystemPrivate;
typedef struct _FileNodeProperty FileNodeProperty;
typedef struct _FileNodeData FileNodeData;
static GHashTable *properties = NULL;
struct _TrackerFileSystemPrivate {
GNode *file_tree;
GHashTable *properties;
};
struct _FileNodeProperty {
......@@ -66,6 +67,8 @@ static void
file_node_data_free (FileNodeData *data,
GNode *node)
{
guint i;
if (data->shallow) {
/* Shallow nodes own the reference to the file */
g_object_unref (data->file);
......@@ -76,8 +79,23 @@ file_node_data_free (FileNodeData *data,
}
g_free (data->uri_suffix);
g_array_free (data->properties, TRUE);
for (i = 0; i < data->properties->len; i++) {
FileNodeProperty *property;
GDestroyNotify destroy_notify;
property = &g_array_index (data->properties,
FileNodeProperty, i);
destroy_notify = g_hash_table_lookup (properties,
GUINT_TO_POINTER (property->prop_quark));
if (destroy_notify) {
(destroy_notify) (property->value);
}
}
g_array_free (data->properties, TRUE);
g_slice_free (FileNodeData, data);
}
......@@ -554,28 +572,22 @@ tracker_file_system_traverse (TrackerFileSystem *file_system,
}
void
tracker_file_system_register_property (TrackerFileSystem *file_system,
GQuark prop,
tracker_file_system_register_property (GQuark prop,
GDestroyNotify destroy_notify)
{
TrackerFileSystemPrivate *priv;
g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
g_return_if_fail (prop != 0);
priv = file_system->priv;
if (!priv->properties) {
priv->properties = g_hash_table_new (NULL, NULL);
if (!properties) {
properties = g_hash_table_new (NULL, NULL);
}
if (g_hash_table_lookup (priv->properties, GUINT_TO_POINTER (prop))) {
if (g_hash_table_lookup (properties, GUINT_TO_POINTER (prop))) {
g_warning ("FileSystem: property '%s' has been already registered",
g_quark_to_string (prop));
return;
}
g_hash_table_insert (priv->properties,
g_hash_table_insert (properties,
GUINT_TO_POINTER (prop),
destroy_notify);
}
......@@ -615,8 +627,8 @@ tracker_file_system_set_property (TrackerFileSystem *file_system,
priv = file_system->priv;
if (!priv->properties ||
!g_hash_table_lookup_extended (priv->properties,
if (!properties ||
!g_hash_table_lookup_extended (properties,
GUINT_TO_POINTER (prop),
NULL, (gpointer *) &destroy_notify)) {
g_warning ("FileSystem: property '%s' is not registered",
......@@ -708,8 +720,8 @@ tracker_file_system_unset_property (TrackerFileSystem *file_system,
priv = file_system->priv;
if (!priv->properties ||
!g_hash_table_lookup_extended (priv->properties,
if (!properties ||
!g_hash_table_lookup_extended (properties,
GUINT_TO_POINTER (prop),
NULL,
(gpointer *) &destroy_notify)) {
......
......@@ -72,8 +72,7 @@ void tracker_file_system_traverse (TrackerFileSystem
gpointer user_data);
/* properties */
void tracker_file_system_register_property (TrackerFileSystem *file_system,
GQuark prop,
void tracker_file_system_register_property (GQuark prop,
GDestroyNotify destroy_notify);
void tracker_file_system_set_property (TrackerFileSystem *file_system,
......
......@@ -189,12 +189,10 @@ test_file_system_properties (TestCommonContext *fixture,
GFile *file, *f;
property1_quark = g_quark_from_string ("file-system-test-property1");
tracker_file_system_register_property (fixture->file_system,
property1_quark,
tracker_file_system_register_property (property1_quark,
NULL);
property2_quark = g_quark_from_string ("file-system-test-property2");
tracker_file_system_register_property (fixture->file_system,
property2_quark,
tracker_file_system_register_property (property2_quark,
NULL);
f = g_file_new_for_uri ("file:///aaa/");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment