[tracker/miner-fs-refactor: 26/75] libtracker-miner: Add default policies to TrackerIndexingTree filters
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-refactor: 26/75] libtracker-miner: Add default policies to TrackerIndexingTree filters
- Date: Tue, 4 Oct 2011 10:56:01 +0000 (UTC)
commit 4b44f0d3fabe6b541b8276d1bd7ac07c8cd1cc46
Author: Carlos Garnacho <carlos lanedo com>
Date: Thu Sep 8 17:31:57 2011 +0200
libtracker-miner: Add default policies to TrackerIndexingTree filters
An "accept" policy means a file is accepted unless it matches a filter,
meanwhile a "deny" policy means files are rejected unless they match a
filter. The default policy is "accept"
src/libtracker-miner/tracker-indexing-tree.c | 70 ++++++++++++++++++++++++--
src/libtracker-miner/tracker-indexing-tree.h | 6 ++
src/libtracker-miner/tracker-miner-enums.h | 5 ++
3 files changed, 77 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-indexing-tree.c b/src/libtracker-miner/tracker-indexing-tree.c
index bec57ca..d928133 100644
--- a/src/libtracker-miner/tracker-indexing-tree.c
+++ b/src/libtracker-miner/tracker-indexing-tree.c
@@ -53,6 +53,7 @@ struct _TrackerIndexingTreePrivate
{
GNode *config_tree;
GList *filter_patterns;
+ TrackerFilterPolicy policies[TRACKER_FILTER_PARENT_DIRECTORY + 1];
guint filter_hidden : 1;
};
@@ -226,6 +227,7 @@ tracker_indexing_tree_init (TrackerIndexingTree *tree)
TrackerIndexingTreePrivate *priv;
NodeData *data;
GFile *root;
+ gint i;
priv = tree->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree,
TRACKER_TYPE_INDEXING_TREE,
@@ -237,6 +239,10 @@ tracker_indexing_tree_init (TrackerIndexingTree *tree)
priv->config_tree = g_node_new (data);
g_object_unref (root);
+
+ for (i = TRACKER_FILTER_FILE; i <= TRACKER_FILTER_PARENT_DIRECTORY; i++) {
+ priv->policies[i] = TRACKER_FILTER_POLICY_ACCEPT;
+ }
}
/**
@@ -559,6 +565,32 @@ parent_or_equals (GFile *file1,
g_file_has_prefix (file1, file2));
}
+static gboolean
+indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
+ TrackerFilterType filter,
+ GFile *file)
+{
+ TrackerIndexingTreePrivate *priv;
+
+ priv = tree->priv;
+
+ if (tracker_indexing_tree_file_matches_filter (tree, filter, file)) {
+ if (priv->policies[filter] == TRACKER_FILTER_POLICY_ACCEPT) {
+ /* Filter blocks otherwise accepted
+ * (by the default policy) file
+ */
+ return TRUE;
+ }
+ } else {
+ if (priv->policies[filter] == TRACKER_FILTER_POLICY_DENY) {
+ /* No match, and the default policy denies it */
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/**
* tracker_indexing_tree_file_is_indexable:
* @tree: a #TrackerIndexingTree
@@ -599,7 +631,7 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
- if (tracker_indexing_tree_file_matches_filter (tree, filter, file)) {
+ if (indexing_tree_file_is_filtered (tree, filter, file)) {
return FALSE;
}
@@ -650,9 +682,9 @@ tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
}
while (children) {
- if (tracker_indexing_tree_file_matches_filter (tree,
- TRACKER_FILTER_PARENT_DIRECTORY,
- children->data)) {
+ if (indexing_tree_file_is_filtered (tree,
+ TRACKER_FILTER_PARENT_DIRECTORY,
+ children->data)) {
return FALSE;
}
@@ -687,6 +719,36 @@ tracker_indexing_tree_set_filter_hidden (TrackerIndexingTree *tree,
g_object_notify (G_OBJECT (tree), "filter-hidden");
}
+void
+tracker_indexing_tree_set_default_policy (TrackerIndexingTree *tree,
+ TrackerFilterType filter,
+ TrackerFilterPolicy policy)
+{
+ TrackerIndexingTreePrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_INDEXING_TREE (tree));
+ g_return_if_fail (filter >= TRACKER_FILTER_FILE && filter <= TRACKER_FILTER_PARENT_DIRECTORY);
+
+ priv = tree->priv;
+ priv->policies[filter] = policy;
+}
+
+TrackerFilterPolicy
+tracker_indexing_tree_get_default_policy (TrackerIndexingTree *tree,
+ TrackerFilterType filter)
+{
+ TrackerIndexingTreePrivate *priv;
+
+ g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (tree),
+ TRACKER_FILTER_POLICY_DENY);
+ g_return_val_if_fail (filter >= TRACKER_FILTER_FILE &&
+ filter <= TRACKER_FILTER_PARENT_DIRECTORY,
+ TRACKER_FILTER_POLICY_DENY);
+
+ priv = tree->priv;
+ return priv->policies[filter];
+}
+
/**
* tracker_indexing_tree_get_root:
* @tree: a #TrackerIndexingtree
diff --git a/src/libtracker-miner/tracker-indexing-tree.h b/src/libtracker-miner/tracker-indexing-tree.h
index 9465a75..5c2ef9c 100644
--- a/src/libtracker-miner/tracker-indexing-tree.h
+++ b/src/libtracker-miner/tracker-indexing-tree.h
@@ -87,6 +87,12 @@ gboolean tracker_indexing_tree_get_filter_hidden (TrackerIndexingTree *tree
void tracker_indexing_tree_set_filter_hidden (TrackerIndexingTree *tree,
gboolean filter_hidden);
+TrackerFilterPolicy tracker_indexing_tree_get_default_policy (TrackerIndexingTree *tree,
+ TrackerFilterType filter);
+void tracker_indexing_tree_set_default_policy (TrackerIndexingTree *tree,
+ TrackerFilterType filter,
+ TrackerFilterPolicy policy);
+
GFile * tracker_indexing_tree_get_root (TrackerIndexingTree *tree,
GFile *file,
TrackerDirectoryFlags *directory_flags);
diff --git a/src/libtracker-miner/tracker-miner-enums.h b/src/libtracker-miner/tracker-miner-enums.h
index a7e098f..0f14adf 100644
--- a/src/libtracker-miner/tracker-miner-enums.h
+++ b/src/libtracker-miner/tracker-miner-enums.h
@@ -38,6 +38,11 @@ typedef enum {
TRACKER_FILTER_PARENT_DIRECTORY
} TrackerFilterType;
+typedef enum {
+ TRACKER_FILTER_POLICY_DENY,
+ TRACKER_FILTER_POLICY_ACCEPT
+} TrackerFilterPolicy;
+
G_END_DECLS
#endif /* __TRACKER_MINER_ENUMS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]