[tracker-miners/wip/carlosg/speed-track: 29/40] libtracker-miner: Pass GFileInfo to TrackerIndexingTree checks
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/speed-track: 29/40] libtracker-miner: Pass GFileInfo to TrackerIndexingTree checks
- Date: Sun, 18 Oct 2020 20:58:43 +0000 (UTC)
commit 6094a3d1a684b232767b768cb5ba05932af9d484
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Oct 17 13:33:28 2020 +0200
libtracker-miner: Pass GFileInfo to TrackerIndexingTree checks
We most often (except from monitor events) have a GFileInfo to pass on
to the TrackerIndexingTree. This will allow unifying some file queries
being done.
src/libtracker-miner/tracker-file-notifier.c | 70 ++++++++++++----------
src/libtracker-miner/tracker-indexing-tree.c | 38 +++++-------
src/libtracker-miner/tracker-indexing-tree.h | 2 +-
src/libtracker-miner/tracker-miner-fs.c | 16 +----
src/miners/fs/tracker-main.c | 15 +++--
.../libtracker-miner/tracker-indexing-tree-test.c | 8 +--
6 files changed, 69 insertions(+), 80 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 7dc495b05..626553408 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -200,20 +200,21 @@ root_data_free (RootData *data)
/* Crawler signal handlers */
static gboolean
check_file (TrackerFileNotifier *notifier,
- GFile *file)
+ GFile *file,
+ GFileInfo *info)
{
TrackerFileNotifierPrivate *priv;
priv = tracker_file_notifier_get_instance_private (notifier);
return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- file,
- G_FILE_TYPE_REGULAR);
+ file, info);
}
static gboolean
check_directory (TrackerFileNotifier *notifier,
- GFile *directory)
+ GFile *directory,
+ GFileInfo *info)
{
TrackerFileNotifierPrivate *priv;
@@ -230,8 +231,7 @@ check_directory (TrackerFileNotifier *notifier,
}
return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- directory,
- G_FILE_TYPE_DIRECTORY);
+ directory, info);
}
static gboolean
@@ -848,6 +848,19 @@ notifier_queue_root (TrackerFileNotifier *notifier,
notifier_check_next_root (notifier);
}
+static GFileInfo *
+create_shallow_file_info (GFile *file,
+ gboolean is_directory)
+{
+ GFileInfo *file_info;
+
+ file_info = g_file_info_new ();
+ g_file_info_set_file_type (file_info,
+ is_directory ?
+ G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR);
+ return file_info;
+}
+
/* Monitor signal handlers */
static void
monitor_item_created_cb (TrackerMonitor *monitor,
@@ -857,14 +870,12 @@ monitor_item_created_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv;
- GFileType file_type;
gboolean indexable;
priv = tracker_file_notifier_get_instance_private (notifier);
- file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
indexable = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- file, file_type);
+ file, NULL);
if (!is_directory) {
gboolean parent_indexable;
@@ -929,13 +940,11 @@ monitor_item_updated_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv;
- GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier);
- 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, NULL)) {
/* File should not be indexed */
return;
}
@@ -951,13 +960,11 @@ monitor_item_attribute_updated_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv;
- GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier);
- 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, NULL)) {
/* File should not be indexed */
return;
}
@@ -973,10 +980,8 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
{
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv;
- GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier);
- file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
/* Remove monitors if any */
if (is_directory &&
@@ -1019,7 +1024,7 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
}
if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- file, file_type)) {
+ file, NULL)) {
/* File was not indexed */
return ;
}
@@ -1076,7 +1081,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
/* else, file, do nothing */
} else {
gboolean should_process, should_process_other;
- GFileType file_type;
+ GFileInfo *file_info;
GFile *check_file;
if (is_directory) {
@@ -1085,18 +1090,17 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
check_file = g_file_get_parent (file);
}
- file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
+ file_info = create_shallow_file_info (file, is_directory);
/* If the (parent) directory is in
* the filesystem, file is stored
*/
should_process = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- file,
- file_type);
+ file, file_info);
should_process_other = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- other_file,
- file_type);
+ other_file, file_info);
g_object_unref (check_file);
+ g_object_unref (file_info);
/* Ref those so they are safe to use after signal emission */
g_object_ref (file);
@@ -1281,17 +1285,19 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree,
TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv;
TrackerDirectoryFlags flags;
+ GFileInfo *child_info;
GFileType child_type;
priv = tracker_file_notifier_get_instance_private (notifier);
- child_type = g_file_query_file_type (child,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL);
-
- if (child_type == G_FILE_TYPE_UNKNOWN)
+ child_info = g_file_query_info (child,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+ if (!child_info)
return;
+ child_type = g_file_info_get_file_type (child_info);
tracker_indexing_tree_get_root (indexing_tree, child, &flags);
if (child_type == G_FILE_TYPE_DIRECTORY &&
@@ -1300,7 +1306,7 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree,
notifier_queue_root (notifier, child, flags, FALSE);
} else if (tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
- child, child_type)) {
+ child, child_info)) {
g_signal_emit (notifier, signals[FILE_UPDATED], 0, child, FALSE,
child_type == G_FILE_TYPE_DIRECTORY);
}
@@ -1392,12 +1398,12 @@ crawler_check_func (TrackerCrawler *crawler,
TrackerFileNotifier *notifier = user_data;
if (flags & TRACKER_CRAWLER_CHECK_FILE) {
- if (!check_file (notifier, file))
+ if (!check_file (notifier, file, file_info))
return FALSE;
}
if (flags & TRACKER_CRAWLER_CHECK_DIRECTORY) {
- if (!check_directory (notifier, file))
+ if (!check_directory (notifier, file, file_info))
return FALSE;
}
diff --git a/src/libtracker-miner/tracker-indexing-tree.c b/src/libtracker-miner/tracker-indexing-tree.c
index b74e28ff9..62ea105bb 100644
--- a/src/libtracker-miner/tracker-indexing-tree.c
+++ b/src/libtracker-miner/tracker-indexing-tree.c
@@ -830,13 +830,13 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
* tracker_indexing_tree_file_is_indexable:
* @tree: a #TrackerIndexingTree
* @file: a #GFile
- * @file_type: a #GFileType
+ * @file_info: a #GFileInfo
*
* returns %TRUE if @file should be indexed according to the
* parameters given through tracker_indexing_tree_add() and
* tracker_indexing_tree_add_filter().
*
- * If @file_type is #G_FILE_TYPE_UNKNOWN, file type will be queried to the
+ * If @file_info is %NULL, it will be queried to the
* file system.
*
* Returns: %TRUE if @file should be indexed.
@@ -844,11 +844,12 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
gboolean
tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file,
- GFileType file_type)
+ GFileInfo *info)
{
TrackerFilterType filter;
TrackerDirectoryFlags config_flags;
GFile *config_file;
+ GFileType file_type;
g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (tree), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
@@ -859,28 +860,21 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
return FALSE;
}
- /* Don't check file type if _NO_STAT is given in flags */
- if (file_type == G_FILE_TYPE_UNKNOWN &&
- (config_flags & TRACKER_DIRECTORY_FLAG_NO_STAT) != 0) {
- GFileQueryInfoFlags file_flags;
-
- file_flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
-
- file_type = g_file_query_file_type (file, file_flags, NULL);
+ if (info == NULL) {
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+ }
- filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
- TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
+ file_type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN;
- if (indexing_tree_file_is_filtered (tree, filter, file)) {
- return FALSE;
- }
- } else if (file_type != G_FILE_TYPE_UNKNOWN) {
- filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
- TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
+ filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
+ TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
- if (indexing_tree_file_is_filtered (tree, filter, file)) {
- return FALSE;
- }
+ if (indexing_tree_file_is_filtered (tree, filter, file)) {
+ return FALSE;
}
/* FIXME: Shouldn't we only do this for file_type == G_FILE_TYPE_DIRECTORY ? */
diff --git a/src/libtracker-miner/tracker-indexing-tree.h b/src/libtracker-miner/tracker-indexing-tree.h
index aa2112893..359c83bd6 100644
--- a/src/libtracker-miner/tracker-indexing-tree.h
+++ b/src/libtracker-miner/tracker-indexing-tree.h
@@ -104,7 +104,7 @@ gboolean tracker_indexing_tree_file_matches_filter (TrackerIndexingTree *tree
gboolean tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file,
- GFileType file_type);
+ GFileInfo *info);
gboolean tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
GFile *parent,
GList *children);
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 82566d915..d368d5532 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1940,18 +1940,6 @@ item_queue_handlers_set_up (TrackerMinerFS *fs)
fs);
}
-static gboolean
-should_check_file (TrackerMinerFS *fs,
- GFile *file,
- gboolean is_dir)
-{
- GFileType file_type;
-
- file_type = (is_dir) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
- return tracker_indexing_tree_file_is_indexable (fs->priv->indexing_tree,
- file, file_type);
-}
-
static gint
miner_fs_get_queue_priority (TrackerMinerFS *fs,
GFile *file)
@@ -2303,7 +2291,9 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
g_return_if_fail (G_IS_FILE (file));
if (check_parents) {
- should_process = should_check_file (fs, file, FALSE);
+ should_process =
+ tracker_indexing_tree_file_is_indexable (fs->priv->indexing_tree,
+ file, NULL);
}
uri = g_file_get_uri (file);
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index f5e00a7dd..077a6dbe3 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -611,7 +611,6 @@ check_eligible (void)
if (info) {
is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
- g_object_unref (info);
} else {
/* Assume not a dir */
is_dir = FALSE;
@@ -634,8 +633,10 @@ check_eligible (void)
ontology,
NULL,
NULL);
- if (!sparql_conn)
+ if (!sparql_conn) {
+ g_object_unref (info);
return EXIT_FAILURE;
+ }
/* Create new TrackerMinerFiles object */
config = tracker_config_new ();
@@ -644,16 +645,14 @@ check_eligible (void)
g_object_unref (config);
if (!miner_files) {
+ g_object_unref (info);
g_object_unref (sparql_conn);
return EXIT_FAILURE;
}
indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (miner_files));
- indexable = tracker_indexing_tree_file_is_indexable (indexing_tree, file,
- is_dir ?
- G_FILE_TYPE_DIRECTORY :
- G_FILE_TYPE_REGULAR);
+ indexable = tracker_indexing_tree_file_is_indexable (indexing_tree, file, info);
if (!indexable) {
if (is_dir &&
@@ -739,6 +738,7 @@ check_eligible (void)
g_object_unref (config);
g_object_unref (file);
g_object_unref (miner_files);
+ g_object_unref (info);
tracker_domain_ontology_unref (domain_ontology);
return (indexable && parents_indexable) ? EXIT_SUCCESS : EXIT_FAILURE;
@@ -894,8 +894,7 @@ update_indexed_files_from_proxy (TrackerMinerFiles *miner,
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
if (!tracker_indexing_tree_file_is_indexable (indexing_tree,
- file,
- G_FILE_TYPE_DIRECTORY)) {
+ file, file_info)) {
tracker_indexing_tree_add (indexing_tree,
file,
TRACKER_DIRECTORY_FLAG_RECURSE |
diff --git a/tests/libtracker-miner/tracker-indexing-tree-test.c
b/tests/libtracker-miner/tracker-indexing-tree-test.c
index b61179f1b..24f1bf6cf 100644
--- a/tests/libtracker-miner/tracker-indexing-tree-test.c
+++ b/tests/libtracker-miner/tracker-indexing-tree-test.c
@@ -60,12 +60,12 @@ typedef struct {
#define ASSERT_INDEXABLE(fixture, id) \
g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \
- fixture->test_dir[id], \
- G_FILE_TYPE_DIRECTORY) == TRUE)
+ fixture->test_dir[id], \
+ NULL) == TRUE)
#define ASSERT_NOT_INDEXABLE(fixture, id) \
g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \
- fixture->test_dir[id], \
- G_FILE_TYPE_DIRECTORY) == FALSE)
+ fixture->test_dir[id], \
+ NULL) == FALSE)
#define test_add(path,fun) \
g_test_add (path, \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]