[tracker/miner-fs-refactor: 52/74] libtracker-miner: Remove TrackerFile
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-refactor: 52/74] libtracker-miner: Remove TrackerFile
- Date: Tue, 4 Oct 2011 10:54:49 +0000 (UTC)
commit 1d93d57a99ac10ce2f287508541bd72cae8c3373
Author: Carlos Garnacho <carlos lanedo com>
Date: Fri Sep 30 16:51:59 2011 +0200
libtracker-miner: Remove TrackerFile
Instead, weak refs to GFiles are kept to manage the actual nodes
in a TrackerFileSystem tree, this also eases TrackerFile vs GFile
situations.
src/libtracker-miner/tracker-file-notifier.c | 174 +++++++++------------
src/libtracker-miner/tracker-file-system.c | 220 ++++++++++++++++++-------
src/libtracker-miner/tracker-file-system.h | 42 ++---
3 files changed, 250 insertions(+), 186 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index d95eb91..dffbf12 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -178,33 +178,31 @@ crawler_check_directory_contents_cb (TrackerCrawler *crawler,
}
static gboolean
-file_notifier_traverse_tree_foreach (TrackerFile *file,
- gpointer user_data)
+file_notifier_traverse_tree_foreach (GFile *file,
+ gpointer user_data)
{
TrackerFileNotifier *notifier;
TrackerFileNotifierPrivate *priv;
const gchar *store_mtime, *disk_mtime;
- GFile *f;
notifier = user_data;
priv = notifier->priv;
store_mtime = tracker_file_system_get_property (priv->file_system, file,
- quark_property_store_mtime);
+ quark_property_store_mtime);
disk_mtime = tracker_file_system_get_property (priv->file_system, file,
quark_property_filesystem_mtime);
- f = tracker_file_system_resolve_file (priv->file_system, file);
if (store_mtime && !disk_mtime) {
/* In store but not in disk, delete */
- g_signal_emit (notifier, signals[FILE_DELETED], 0, f);
+ g_signal_emit (notifier, signals[FILE_DELETED], 0, file);
} else if (disk_mtime && !store_mtime) {
/* In disk but not in store, create */
- g_signal_emit (notifier, signals[FILE_CREATED], 0, f);
+ g_signal_emit (notifier, signals[FILE_CREATED], 0, file);
} else if (store_mtime && disk_mtime &&
strcmp (store_mtime, disk_mtime) != 0) {
/* Mtime changed, update */
- g_signal_emit (notifier, signals[FILE_UPDATED], 0, f, FALSE);
+ g_signal_emit (notifier, signals[FILE_UPDATED], 0, file, FALSE);
} else if (!store_mtime && !disk_mtime) {
/* what are we doing with such file? shouldn't happen */
g_assert_not_reached ();
@@ -243,7 +241,9 @@ file_notifier_traverse_tree (TrackerFileNotifier *notifier)
typedef struct {
TrackerFileNotifier *notifier;
GNode *cur_parent_node;
- TrackerFile *cur_parent;
+
+ /* Canonical copy from priv->file_system */
+ GFile *cur_parent;
} DirectoryCrawledData;
static gboolean
@@ -253,7 +253,6 @@ file_notifier_add_node_foreach (GNode *node,
DirectoryCrawledData *data = user_data;
TrackerFileNotifierPrivate *priv;
GFileInfo *file_info;
- TrackerFile *f;
GFile *file;
priv = data->notifier->priv;
@@ -269,10 +268,11 @@ file_notifier_add_node_foreach (GNode *node,
data->cur_parent = NULL;
}
- f = tracker_file_system_get_file (priv->file_system,
- file,
- G_FILE_TYPE_UNKNOWN,
- data->cur_parent);
+ /* Intern file in filesystem */
+ file = tracker_file_system_get_file (priv->file_system,
+ file,
+ G_FILE_TYPE_UNKNOWN,
+ data->cur_parent);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -297,7 +297,7 @@ file_notifier_add_node_foreach (GNode *node,
t.tm_min,
t.tm_sec);
- tracker_file_system_set_property (priv->file_system, f,
+ tracker_file_system_set_property (priv->file_system, file,
quark_property_filesystem_mtime,
time_str);
g_object_unref (file_info);
@@ -362,26 +362,26 @@ sparql_query_cb (GObject *object,
}
while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
- TrackerFile *file;
+ GFile *file, *canonical;
const gchar *mtime, *iri;
- GFile *f;
- f = g_file_new_for_uri (tracker_sparql_cursor_get_string (cursor, 0, NULL));
- file = tracker_file_system_get_file (priv->file_system, f,
- G_FILE_TYPE_UNKNOWN,
- NULL);
+ file = g_file_new_for_uri (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ canonical = tracker_file_system_get_file (priv->file_system,
+ file,
+ G_FILE_TYPE_UNKNOWN,
+ NULL);
iri = tracker_sparql_cursor_get_string (cursor, 1, NULL);
- tracker_file_system_set_property (priv->file_system, file,
+ tracker_file_system_set_property (priv->file_system, canonical,
quark_property_iri,
g_strdup (iri));
mtime = tracker_sparql_cursor_get_string (cursor, 2, NULL);
- tracker_file_system_set_property (priv->file_system, file,
+ tracker_file_system_set_property (priv->file_system, canonical,
quark_property_store_mtime,
g_strdup (mtime));
- g_object_unref (f);
+ g_object_unref (file);
}
/* Mark the directory root as queried */
@@ -419,9 +419,7 @@ crawl_directories_start (TrackerFileNotifier *notifier)
}
while (priv->pending_index_roots) {
- directory = tracker_file_system_resolve_file (priv->file_system,
- priv->pending_index_roots->data);
-
+ directory = priv->pending_index_roots->data;
tracker_indexing_tree_get_root (priv->indexing_tree,
directory,
&flags);
@@ -496,7 +494,7 @@ crawler_finished_cb (TrackerCrawler *crawler,
g_timer_elapsed (priv->timer, NULL));
if (!was_interrupted) {
- TrackerFile *directory;
+ GFile *directory;
directory = priv->pending_index_roots->data;
@@ -523,8 +521,8 @@ monitor_item_created_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv = notifier->priv;
- TrackerFile *canonical;
GFileType file_type;
+ GFile *canonical;
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
@@ -566,28 +564,24 @@ monitor_item_created_cb (TrackerMonitor *monitor,
file, &flags);
if (flags & TRACKER_DIRECTORY_FLAG_RECURSE) {
- TrackerFile *f;
-
- f = tracker_file_system_get_file (priv->file_system,
- file,
- G_FILE_TYPE_DIRECTORY,
- NULL);
+ file = tracker_file_system_get_file (priv->file_system,
+ file,
+ G_FILE_TYPE_DIRECTORY,
+ NULL);
priv->pending_index_roots =
- g_list_append (priv->pending_index_roots, f);
+ g_list_append (priv->pending_index_roots, file);
crawl_directories_start (notifier);
return;
}
}
+ /* Fetch the interned copy */
canonical = tracker_file_system_get_file (priv->file_system,
file, file_type, NULL);
- /* Fetch the unique copy */
- file = tracker_file_system_resolve_file (priv->file_system, canonical);
-
- g_signal_emit (notifier, signals[FILE_CREATED], 0, file);
+ g_signal_emit (notifier, signals[FILE_CREATED], 0, canonical);
}
static void
@@ -598,24 +592,21 @@ monitor_item_updated_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv = notifier->priv;
- TrackerFile *canonical;
GFileType file_type;
+ GFile *canonical;
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) {
/* File should not be indexed */
- return ;
+ return;
}
+ /* Fetch the interned copy */
canonical = tracker_file_system_get_file (priv->file_system,
file, file_type, NULL);
-
- /* Fetch the unique copy */
- file = tracker_file_system_resolve_file (priv->file_system, canonical);
-
- g_signal_emit (notifier, signals[FILE_UPDATED], 0, file, FALSE);
+ g_signal_emit (notifier, signals[FILE_UPDATED], 0, canonical, FALSE);
}
static void
@@ -626,7 +617,7 @@ monitor_item_attribute_updated_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv = notifier->priv;
- TrackerFile *canonical;
+ GFile *canonical;
GFileType file_type;
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
@@ -634,16 +625,13 @@ monitor_item_attribute_updated_cb (TrackerMonitor *monitor,
if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) {
/* File should not be indexed */
- return ;
+ return;
}
+ /* Fetch the interned copy */
canonical = tracker_file_system_get_file (priv->file_system,
file, file_type, NULL);
-
- /* Fetch the unique copy */
- file = tracker_file_system_resolve_file (priv->file_system, canonical);
-
- g_signal_emit (notifier, signals[FILE_UPDATED], 0, file, TRUE);
+ g_signal_emit (notifier, signals[FILE_UPDATED], 0, canonical, TRUE);
}
static void
@@ -654,7 +642,7 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv = notifier->priv;
- TrackerFile *canonical;
+ GFile *canonical;
GFileType file_type;
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
@@ -683,29 +671,25 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
* wasn't being monitored if being ignored
*/
if (!indexable) {
- TrackerFile *f;
-
/* New file was triggering a directory content
* filter, reindex parent directory altogether
*/
- f = tracker_file_system_get_file (priv->file_system,
- file,
- G_FILE_TYPE_DIRECTORY,
- NULL);
+ file = tracker_file_system_get_file (priv->file_system,
+ file,
+ G_FILE_TYPE_DIRECTORY,
+ NULL);
priv->pending_index_roots =
- g_list_append (priv->pending_index_roots, f);
+ g_list_append (priv->pending_index_roots, file);
crawl_directories_start (notifier);
return;
}
}
+ /* Fetch the interned copy */
canonical = tracker_file_system_get_file (priv->file_system,
file, file_type, NULL);
- /* Fetch the unique copy */
- file = tracker_file_system_resolve_file (priv->file_system, canonical);
-
- g_signal_emit (notifier, signals[FILE_DELETED], 0, file);
+ g_signal_emit (notifier, signals[FILE_DELETED], 0, canonical);
}
static void
@@ -724,18 +708,16 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
if (!is_source_monitored) {
if (is_directory) {
- TrackerFile *f;
-
/* Remove monitors if any */
tracker_monitor_remove_recursively (priv->monitor, file);
/* If should recurse, crawl other_file, as content is "new" */
- f = tracker_file_system_get_file (priv->file_system,
- other_file,
- G_FILE_TYPE_DIRECTORY,
- NULL);
+ file = tracker_file_system_get_file (priv->file_system,
+ other_file,
+ G_FILE_TYPE_DIRECTORY,
+ NULL);
priv->pending_index_roots =
- g_list_append (priv->pending_index_roots, f);
+ g_list_append (priv->pending_index_roots, file);
crawl_directories_start (notifier);
}
@@ -780,15 +762,13 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
if (!is_directory || !dest_is_recursive) {
g_signal_emit (notifier, signals[FILE_CREATED], 0, other_file);
} else if (is_directory) {
- TrackerFile *f;
-
/* Crawl dest directory */
- f = tracker_file_system_get_file (priv->file_system,
- other_file,
- G_FILE_TYPE_DIRECTORY,
- NULL);
+ other_file = tracker_file_system_get_file (priv->file_system,
+ other_file,
+ G_FILE_TYPE_DIRECTORY,
+ NULL);
priv->pending_index_roots =
- g_list_append (priv->pending_index_roots, f);
+ g_list_append (priv->pending_index_roots, other_file);
crawl_directories_start (notifier);
}
@@ -826,15 +806,13 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
*/
/* FIXME: it doesn't */
} else if (!source_is_recursive && dest_is_recursive) {
- TrackerFile *f;
-
/* crawl the folder */
- f = tracker_file_system_get_file (priv->file_system,
- other_file,
- G_FILE_TYPE_DIRECTORY,
- NULL);
+ file = tracker_file_system_get_file (priv->file_system,
+ other_file,
+ G_FILE_TYPE_DIRECTORY,
+ NULL);
priv->pending_index_roots =
- g_list_append (priv->pending_index_roots, f);
+ g_list_append (priv->pending_index_roots, file);
crawl_directories_start (notifier);
}
@@ -855,20 +833,18 @@ indexing_tree_directory_added (TrackerIndexingTree *indexing_tree,
TrackerFileNotifierPrivate *priv = notifier->priv;
gboolean start_crawler = FALSE;
TrackerDirectoryFlags flags;
- TrackerFile *file;
tracker_indexing_tree_get_root (indexing_tree, directory, &flags);
- file = tracker_file_system_get_file (priv->file_system, directory,
- G_FILE_TYPE_DIRECTORY, NULL);
-
+ directory = tracker_file_system_get_file (priv->file_system, directory,
+ G_FILE_TYPE_DIRECTORY, NULL);
if (!priv->stopped &&
!priv->pending_index_roots) {
start_crawler = TRUE;
}
priv->pending_index_roots = g_list_append (priv->pending_index_roots,
- file);
+ directory);
if (start_crawler) {
crawl_directories_start (notifier);
}
@@ -1044,17 +1020,17 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
tracker_file_system_register_property (priv->file_system,
quark_property_crawled, NULL);
tracker_file_system_register_property (priv->file_system,
- quark_property_queried, NULL);
+ 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);
+ quark_property_store_mtime,
+ g_free);
tracker_file_system_register_property (priv->file_system,
- quark_property_filesystem_mtime,
- g_free);
+ quark_property_filesystem_mtime,
+ g_free);
priv->timer = g_timer_new ();
priv->stopped = TRUE;
@@ -1103,8 +1079,8 @@ tracker_file_notifier_new (TrackerIndexingTree *indexing_tree)
g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (indexing_tree), NULL);
return g_object_new (TRACKER_TYPE_FILE_NOTIFIER,
- "indexing-tree", indexing_tree,
- NULL);
+ "indexing-tree", indexing_tree,
+ NULL);
}
gboolean
diff --git a/src/libtracker-miner/tracker-file-system.c b/src/libtracker-miner/tracker-file-system.c
index 8008fc4..6a359e7 100644
--- a/src/libtracker-miner/tracker-file-system.c
+++ b/src/libtracker-miner/tracker-file-system.c
@@ -42,11 +42,15 @@ struct _FileNodeData {
GFile *file;
gchar *uri_suffix;
GArray *properties;
- guint ref_count;
guint shallow : 1;
guint file_type : 4;
};
+static GQuark quark_file_node = 0;
+
+static void file_weak_ref_notify (gpointer user_data,
+ GObject *prev_location);
+
G_DEFINE_TYPE (TrackerFileSystem, tracker_file_system, G_TYPE_OBJECT)
/*
@@ -58,9 +62,45 @@ G_DEFINE_TYPE (TrackerFileSystem, tracker_file_system, G_TYPE_OBJECT)
*/
+static void
+file_node_data_free (FileNodeData *data,
+ GNode *node)
+{
+ if (data->shallow) {
+ /* Shallow nodes own the reference to the file */
+ g_object_unref (data->file);
+ } else if (node) {
+ g_object_weak_unref (G_OBJECT (data->file),
+ file_weak_ref_notify,
+ node);
+ }
+
+ g_free (data->uri_suffix);
+ g_array_free (data->properties, TRUE);
+
+ g_slice_free (FileNodeData, data);
+}
+
+static void
+file_weak_ref_notify (gpointer user_data,
+ GObject *prev_location)
+{
+ FileNodeData *data;
+ GNode *node;
+
+ node = user_data;
+ data = node->data;
+
+ g_assert (data->file == (GFile *) prev_location);
+
+ /* Delete node tree here */
+ file_node_data_free (data, NULL);
+}
+
static FileNodeData *
file_node_data_new (GFile *file,
- GFileType file_type)
+ GFileType file_type,
+ GNode *node)
{
FileNodeData *data;
@@ -68,7 +108,14 @@ file_node_data_new (GFile *file,
data->file = g_object_ref (file);
data->file_type = file_type;
data->properties = g_array_new (FALSE, TRUE, sizeof (FileNodeProperty));
- data->ref_count = 1;
+
+ /* We use weak refs to keep track of files */
+ g_object_weak_ref (G_OBJECT (data->file), file_weak_ref_notify, node);
+ g_object_set_qdata (G_OBJECT (data->file),
+ quark_file_node, node);
+
+ g_assert (node->data == NULL);
+ node->data = data;
return data;
}
@@ -84,21 +131,10 @@ file_node_data_root_new (void)
data->properties = g_array_new (FALSE, TRUE, sizeof (FileNodeProperty));
data->file_type = G_FILE_TYPE_DIRECTORY;
data->shallow = TRUE;
- data->ref_count = 1;
return data;
}
-static void
-file_node_data_free (FileNodeData *data)
-{
- g_object_unref (data->file);
- g_free (data->uri_suffix);
- g_array_free (data->properties, TRUE);
-
- g_slice_free (FileNodeData, data);
-}
-
static gboolean
file_node_data_equal_or_child (GNode *node,
gchar *uri_suffix,
@@ -227,8 +263,8 @@ static gboolean
file_tree_free_node_foreach (GNode *node,
gpointer user_data)
{
- file_node_data_free (node->data);
- return TRUE;
+ file_node_data_free (node->data, node);
+ return FALSE;
}
/* TrackerFileSystem implementation */
@@ -259,6 +295,9 @@ tracker_file_system_class_init (TrackerFileSystemClass *klass)
g_type_class_add_private (object_class,
sizeof (TrackerFileSystemPrivate));
+
+ quark_file_node =
+ g_quark_from_static_string ("tracker-quark-file-node");
}
static void
tracker_file_system_init (TrackerFileSystem *file_system)
@@ -312,11 +351,29 @@ reparent_child_nodes (GNode *node,
}
}
-TrackerFile *
+static GNode *
+file_system_get_node (TrackerFileSystem *file_system,
+ GFile *file)
+{
+ TrackerFileSystemPrivate *priv;
+ GNode *node;
+
+ node = g_object_get_qdata (G_OBJECT (file), quark_file_node);
+
+ if (!node) {
+ priv = file_system->priv;
+ node = file_tree_lookup (priv->file_tree, file,
+ NULL, NULL);
+ }
+
+ return node;
+}
+
+GFile *
tracker_file_system_get_file (TrackerFileSystem *file_system,
GFile *file,
- GFileType file_type,
- TrackerFile *parent)
+ GFileType file_type,
+ GFile *parent)
{
TrackerFileSystemPrivate *priv;
FileNodeData *data;
@@ -333,7 +390,7 @@ tracker_file_system_get_file (TrackerFileSystem *file_system,
FileNodeData *parent_data;
GNode *child;
- parent_node = (GNode *) parent;
+ parent_node = file_system_get_node (file_system, parent);
parent_data = parent_node->data;
/* Find child node, if any */
@@ -376,12 +433,12 @@ tracker_file_system_get_file (TrackerFileSystem *file_system,
if (!node) {
g_assert (parent_node != NULL);
+ node = g_node_new (NULL);
+
/* Parent was found, add file as child */
- data = file_node_data_new (file, file_type);
+ data = file_node_data_new (file, file_type, node);
data->uri_suffix = uri_suffix;
- node = g_node_new (data);
-
/* Reparent any previously created child to it,
* that would currently be a child of parent_node
*/
@@ -389,48 +446,59 @@ tracker_file_system_get_file (TrackerFileSystem *file_system,
g_node_append (parent_node, node);
} else {
- /* Increment reference count of node if found */
data = node->data;
- g_atomic_int_inc (&data->ref_count);
-
g_free (uri_suffix);
}
- return (TrackerFile *) node;
+ return data->file;
}
-TrackerFile *
+GFile *
tracker_file_system_peek_file (TrackerFileSystem *file_system,
- GFile *file)
+ GFile *file)
{
- TrackerFileSystemPrivate *priv;
GNode *node;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (TRACKER_IS_FILE_SYSTEM (file_system), NULL);
- priv = file_system->priv;
- node = file_tree_lookup (priv->file_tree, file, NULL, NULL);
+ node = file_system_get_node (file_system, file);
+
+ if (node) {
+ FileNodeData *data;
+
+ data = node->data;
+ return data->file;
+ }
- return (TrackerFile *) node;
+ return NULL;
}
-TrackerFile *
-tracker_file_system_ref_file (TrackerFileSystem *file_system,
- TrackerFile *file)
+GFile *
+tracker_file_system_peek_parent (TrackerFileSystem *file_system,
+ GFile *file)
{
- FileNodeData *data;
+ GNode *node;
- g_return_val_if_fail (TRACKER_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (file != NULL, NULL);
+ g_return_val_if_fail (TRACKER_IS_FILE_SYSTEM (file_system), NULL);
- data = ((GNode *) file)->data;
+ node = file_system_get_node (file_system, file);
+
+ if (node) {
+ FileNodeData *parent_data;
+ GNode *parent;
- g_atomic_int_inc (&data->ref_count);
+ parent = node->parent;
+ parent_data = parent->data;
- return file;
+ return parent_data->file;
+ }
+
+ return NULL;
}
+#if 0
void
tracker_file_system_unref_file (TrackerFileSystem *file_system,
TrackerFile *file)
@@ -451,39 +519,58 @@ tracker_file_system_unref_file (TrackerFileSystem *file_system,
g_node_destroy (node);
}
}
+#endif
+typedef struct {
+ TrackerFileSystemTraverseFunc func;
+ gpointer user_data;
+} TraverseData;
-GFile *
-tracker_file_system_resolve_file (TrackerFileSystem *file_system,
- TrackerFile *file)
+static gboolean
+traverse_filesystem_func (GNode *node,
+ gpointer user_data)
{
- FileNodeData *data;
+ TraverseData *data = user_data;
+ FileNodeData *node_data;
+ gboolean retval;
- g_return_val_if_fail (file != NULL, NULL);
+ node_data = node->data;
+ retval = data->func (node_data->file, data->user_data);
- data = ((GNode *) file)->data;
- return data->file;
+ return retval;
}
void
tracker_file_system_traverse (TrackerFileSystem *file_system,
- TrackerFile *root,
- GTraverseType order,
- TrackerFileSystemTraverseFunc func,
- gpointer user_data)
+ GFile *root,
+ GTraverseType order,
+ TrackerFileSystemTraverseFunc func,
+ gpointer user_data)
{
TrackerFileSystemPrivate *priv;
+ TraverseData data;
+ GNode *node;
g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
g_return_if_fail (func != NULL);
priv = file_system->priv;
- g_node_traverse ((root) ? (GNode *) root : priv->file_tree,
+
+ if (root) {
+ node = file_system_get_node (file_system, root);
+ } else {
+ node = priv->file_tree;
+ }
+
+ data.func = func;
+ data.user_data = user_data;
+
+ g_node_traverse (node,
order,
G_TRAVERSE_ALL,
-1,
- (GNodeTraverseFunc) func,
- user_data);
+ traverse_filesystem_func,
+ &data);
}
void
@@ -532,7 +619,7 @@ search_property_node (gconstpointer key,
void
tracker_file_system_set_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop,
gpointer prop_data)
{
@@ -540,6 +627,7 @@ tracker_file_system_set_property (TrackerFileSystem *file_system,
FileNodeProperty property, *match;
GDestroyNotify destroy_notify;
FileNodeData *data;
+ GNode *node;
g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
g_return_if_fail (file != NULL);
@@ -556,10 +644,12 @@ tracker_file_system_set_property (TrackerFileSystem *file_system,
return;
}
- data = ((GNode *) file)->data;
+ node = file_system_get_node (file_system, file);
+ g_return_if_fail (node != NULL);
- property.prop_quark = prop;
+ data = node->data;
+ property.prop_quark = prop;
match = bsearch (&property, data->properties->data,
data->properties->len, sizeof (FileNodeProperty),
search_property_node);
@@ -596,18 +686,21 @@ tracker_file_system_set_property (TrackerFileSystem *file_system,
gpointer
tracker_file_system_get_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop)
{
FileNodeData *data;
FileNodeProperty property, *match;
+ GNode *node;
g_return_val_if_fail (TRACKER_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (prop > 0, NULL);
- data = ((GNode *) file)->data;
+ node = file_system_get_node (file_system, file);
+ g_return_val_if_fail (node != NULL, NULL);
+ data = node->data;
property.prop_quark = prop;
match = bsearch (&property, data->properties->data,
@@ -619,13 +712,14 @@ tracker_file_system_get_property (TrackerFileSystem *file_system,
void
tracker_file_system_unset_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop)
{
TrackerFileSystemPrivate *priv;
FileNodeData *data;
FileNodeProperty property, *match;
GDestroyNotify destroy_notify;
+ GNode *node;
guint index;
g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
@@ -643,8 +737,10 @@ tracker_file_system_unset_property (TrackerFileSystem *file_system,
g_quark_to_string (prop));
}
- data = ((GNode *) file)->data;
+ node = file_system_get_node (file_system, file);
+ g_return_if_fail (node != NULL);
+ data = node->data;
property.prop_quark = prop;
match = bsearch (&property, data->properties->data,
diff --git a/src/libtracker-miner/tracker-file-system.h b/src/libtracker-miner/tracker-file-system.h
index 70df3e1..d247d8c 100644
--- a/src/libtracker-miner/tracker-file-system.h
+++ b/src/libtracker-miner/tracker-file-system.h
@@ -39,7 +39,6 @@ G_BEGIN_DECLS
typedef struct _TrackerFileSystem TrackerFileSystem;
typedef struct _TrackerFileSystemClass TrackerFileSystemClass;
-typedef struct _TrackerFile TrackerFile;
struct _TrackerFileSystem {
GObject parent_instance;
@@ -50,34 +49,27 @@ struct _TrackerFileSystemClass {
GObjectClass parent_class;
};
-typedef gboolean (* TrackerFileSystemTraverseFunc) (TrackerFile *file,
- gpointer user_data);
+typedef gboolean (* TrackerFileSystemTraverseFunc) (GFile *file,
+ gpointer user_data);
GType tracker_file_system_get_type (void) G_GNUC_CONST;
TrackerFileSystem * tracker_file_system_new (void);
-/* GFile -> TrackerFile */
-TrackerFile * tracker_file_system_get_file (TrackerFileSystem *file_system,
- GFile *file,
- GFileType file_type,
- TrackerFile *parent);
-TrackerFile * tracker_file_system_ref_file (TrackerFileSystem *file_system,
- TrackerFile *file);
-void tracker_file_system_unref_file (TrackerFileSystem *file_system,
- TrackerFile *file);
-TrackerFile * tracker_file_system_peek_file (TrackerFileSystem *file_system,
- GFile *file);
+GFile * tracker_file_system_get_file (TrackerFileSystem *file_system,
+ GFile *file,
+ GFileType file_type,
+ GFile *parent);
+GFile * tracker_file_system_peek_file (TrackerFileSystem *file_system,
+ GFile *file);
+GFile * tracker_file_system_peek_parent (TrackerFileSystem *file_system,
+ GFile *file);
void tracker_file_system_traverse (TrackerFileSystem *file_system,
- TrackerFile *root,
- GTraverseType order,
- TrackerFileSystemTraverseFunc func,
- gpointer user_data);
-
-/* TrackerFile -> GFile */
-GFile * tracker_file_system_resolve_file (TrackerFileSystem *file_system,
- TrackerFile *file);
+ GFile *root,
+ GTraverseType order,
+ TrackerFileSystemTraverseFunc func,
+ gpointer user_data);
/* properties */
void tracker_file_system_register_property (TrackerFileSystem *file_system,
@@ -85,14 +77,14 @@ void tracker_file_system_register_property (TrackerFileSystem *file_system,
GDestroyNotify destroy_notify);
void tracker_file_system_set_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop,
gpointer prop_data);
gpointer tracker_file_system_get_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop);
void tracker_file_system_unset_property (TrackerFileSystem *file_system,
- TrackerFile *file,
+ GFile *file,
GQuark prop);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]