Commit e8c5aecc authored by Carlos Garnacho's avatar Carlos Garnacho

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.
parent ac2f9051
...@@ -200,20 +200,21 @@ root_data_free (RootData *data) ...@@ -200,20 +200,21 @@ root_data_free (RootData *data)
/* Crawler signal handlers */ /* Crawler signal handlers */
static gboolean static gboolean
check_file (TrackerFileNotifier *notifier, check_file (TrackerFileNotifier *notifier,
GFile *file) GFile *file,
GFileInfo *info)
{ {
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
priv = tracker_file_notifier_get_instance_private (notifier); priv = tracker_file_notifier_get_instance_private (notifier);
return tracker_indexing_tree_file_is_indexable (priv->indexing_tree, return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file, info);
G_FILE_TYPE_REGULAR);
} }
static gboolean static gboolean
check_directory (TrackerFileNotifier *notifier, check_directory (TrackerFileNotifier *notifier,
GFile *directory) GFile *directory,
GFileInfo *info)
{ {
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
...@@ -230,8 +231,7 @@ check_directory (TrackerFileNotifier *notifier, ...@@ -230,8 +231,7 @@ check_directory (TrackerFileNotifier *notifier,
} }
return tracker_indexing_tree_file_is_indexable (priv->indexing_tree, return tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
directory, directory, info);
G_FILE_TYPE_DIRECTORY);
} }
static gboolean static gboolean
...@@ -840,6 +840,19 @@ notifier_queue_root (TrackerFileNotifier *notifier, ...@@ -840,6 +840,19 @@ notifier_queue_root (TrackerFileNotifier *notifier,
notifier_check_next_root (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 */ /* Monitor signal handlers */
static void static void
monitor_item_created_cb (TrackerMonitor *monitor, monitor_item_created_cb (TrackerMonitor *monitor,
...@@ -849,14 +862,12 @@ monitor_item_created_cb (TrackerMonitor *monitor, ...@@ -849,14 +862,12 @@ monitor_item_created_cb (TrackerMonitor *monitor,
{ {
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
GFileType file_type;
gboolean indexable; gboolean indexable;
priv = tracker_file_notifier_get_instance_private (notifier); 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, indexable = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type); file, NULL);
if (!is_directory) { if (!is_directory) {
gboolean parent_indexable; gboolean parent_indexable;
...@@ -921,13 +932,11 @@ monitor_item_updated_cb (TrackerMonitor *monitor, ...@@ -921,13 +932,11 @@ monitor_item_updated_cb (TrackerMonitor *monitor,
{ {
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier); 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, if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) { file, NULL)) {
/* File should not be indexed */ /* File should not be indexed */
return; return;
} }
...@@ -943,13 +952,11 @@ monitor_item_attribute_updated_cb (TrackerMonitor *monitor, ...@@ -943,13 +952,11 @@ monitor_item_attribute_updated_cb (TrackerMonitor *monitor,
{ {
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier); 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, if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) { file, NULL)) {
/* File should not be indexed */ /* File should not be indexed */
return; return;
} }
...@@ -965,10 +972,8 @@ monitor_item_deleted_cb (TrackerMonitor *monitor, ...@@ -965,10 +972,8 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
{ {
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
GFileType file_type;
priv = tracker_file_notifier_get_instance_private (notifier); priv = tracker_file_notifier_get_instance_private (notifier);
file_type = (is_directory) ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR;
/* Remove monitors if any */ /* Remove monitors if any */
if (is_directory && if (is_directory &&
...@@ -1011,7 +1016,7 @@ monitor_item_deleted_cb (TrackerMonitor *monitor, ...@@ -1011,7 +1016,7 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
} }
if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree, if (!tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file_type)) { file, NULL)) {
/* File was not indexed */ /* File was not indexed */
return ; return ;
} }
...@@ -1068,7 +1073,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor, ...@@ -1068,7 +1073,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
/* else, file, do nothing */ /* else, file, do nothing */
} else { } else {
gboolean should_process, should_process_other; gboolean should_process, should_process_other;
GFileType file_type; GFileInfo *file_info;
GFile *check_file; GFile *check_file;
if (is_directory) { if (is_directory) {
...@@ -1077,18 +1082,17 @@ monitor_item_moved_cb (TrackerMonitor *monitor, ...@@ -1077,18 +1082,17 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
check_file = g_file_get_parent (file); 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 /* If the (parent) directory is in
* the filesystem, file is stored * the filesystem, file is stored
*/ */
should_process = tracker_indexing_tree_file_is_indexable (priv->indexing_tree, should_process = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
file, file, file_info);
file_type);
should_process_other = tracker_indexing_tree_file_is_indexable (priv->indexing_tree, should_process_other = tracker_indexing_tree_file_is_indexable (priv->indexing_tree,
other_file, other_file, file_info);
file_type);
g_object_unref (check_file); g_object_unref (check_file);
g_object_unref (file_info);
/* Ref those so they are safe to use after signal emission */ /* Ref those so they are safe to use after signal emission */
g_object_ref (file); g_object_ref (file);
...@@ -1273,17 +1277,19 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree, ...@@ -1273,17 +1277,19 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree,
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
TrackerFileNotifierPrivate *priv; TrackerFileNotifierPrivate *priv;
TrackerDirectoryFlags flags; TrackerDirectoryFlags flags;
GFileInfo *child_info;
GFileType child_type; GFileType child_type;
priv = tracker_file_notifier_get_instance_private (notifier); priv = tracker_file_notifier_get_instance_private (notifier);
child_type = g_file_query_file_type (child, child_info = g_file_query_info (child,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_FILE_ATTRIBUTE_STANDARD_TYPE,
NULL); G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, NULL);
if (child_type == G_FILE_TYPE_UNKNOWN) if (!child_info)
return; return;
child_type = g_file_info_get_file_type (child_info);
tracker_indexing_tree_get_root (indexing_tree, child, &flags); tracker_indexing_tree_get_root (indexing_tree, child, &flags);
if (child_type == G_FILE_TYPE_DIRECTORY && if (child_type == G_FILE_TYPE_DIRECTORY &&
...@@ -1292,7 +1298,7 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree, ...@@ -1292,7 +1298,7 @@ indexing_tree_child_updated (TrackerIndexingTree *indexing_tree,
notifier_queue_root (notifier, child, flags, FALSE); notifier_queue_root (notifier, child, flags, FALSE);
} else if (tracker_indexing_tree_file_is_indexable (priv->indexing_tree, } 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, g_signal_emit (notifier, signals[FILE_UPDATED], 0, child, FALSE,
child_type == G_FILE_TYPE_DIRECTORY); child_type == G_FILE_TYPE_DIRECTORY);
} }
...@@ -1384,12 +1390,12 @@ crawler_check_func (TrackerCrawler *crawler, ...@@ -1384,12 +1390,12 @@ crawler_check_func (TrackerCrawler *crawler,
TrackerFileNotifier *notifier = user_data; TrackerFileNotifier *notifier = user_data;
if (flags & TRACKER_CRAWLER_CHECK_FILE) { if (flags & TRACKER_CRAWLER_CHECK_FILE) {
if (!check_file (notifier, file)) if (!check_file (notifier, file, file_info))
return FALSE; return FALSE;
} }
if (flags & TRACKER_CRAWLER_CHECK_DIRECTORY) { if (flags & TRACKER_CRAWLER_CHECK_DIRECTORY) {
if (!check_directory (notifier, file)) if (!check_directory (notifier, file, file_info))
return FALSE; return FALSE;
} }
......
...@@ -830,13 +830,13 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree, ...@@ -830,13 +830,13 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
* tracker_indexing_tree_file_is_indexable: * tracker_indexing_tree_file_is_indexable:
* @tree: a #TrackerIndexingTree * @tree: a #TrackerIndexingTree
* @file: a #GFile * @file: a #GFile
* @file_type: a #GFileType * @file_info: a #GFileInfo
* *
* returns %TRUE if @file should be indexed according to the * returns %TRUE if @file should be indexed according to the
* parameters given through tracker_indexing_tree_add() and * parameters given through tracker_indexing_tree_add() and
* tracker_indexing_tree_add_filter(). * 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. * file system.
* *
* Returns: %TRUE if @file should be indexed. * Returns: %TRUE if @file should be indexed.
...@@ -844,11 +844,12 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree, ...@@ -844,11 +844,12 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
gboolean gboolean
tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree, tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file, GFile *file,
GFileType file_type) GFileInfo *info)
{ {
TrackerFilterType filter; TrackerFilterType filter;
TrackerDirectoryFlags config_flags; TrackerDirectoryFlags config_flags;
GFile *config_file; GFile *config_file;
GFileType file_type;
g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (tree), FALSE); g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (tree), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE);
...@@ -859,28 +860,21 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree, ...@@ -859,28 +860,21 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
return FALSE; return FALSE;
} }
/* Don't check file type if _NO_STAT is given in flags */ if (info == NULL) {
if (file_type == G_FILE_TYPE_UNKNOWN && info = g_file_query_info (file,
(config_flags & TRACKER_DIRECTORY_FLAG_NO_STAT) != 0) { G_FILE_ATTRIBUTE_STANDARD_TYPE ","
GFileQueryInfoFlags file_flags; G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
file_flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS; NULL, NULL);
}
file_type = g_file_query_file_type (file, file_flags, NULL);
filter = (file_type == G_FILE_TYPE_DIRECTORY) ? file_type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN;
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
if (indexing_tree_file_is_filtered (tree, filter, file)) { filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
return FALSE; TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
}
} else if (file_type != G_FILE_TYPE_UNKNOWN) {
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
if (indexing_tree_file_is_filtered (tree, filter, file)) { if (indexing_tree_file_is_filtered (tree, filter, file)) {
return FALSE; return FALSE;
}
} }
/* FIXME: Shouldn't we only do this for file_type == G_FILE_TYPE_DIRECTORY ? */ /* FIXME: Shouldn't we only do this for file_type == G_FILE_TYPE_DIRECTORY ? */
......
...@@ -104,7 +104,7 @@ gboolean tracker_indexing_tree_file_matches_filter (TrackerIndexingTree *tree ...@@ -104,7 +104,7 @@ gboolean tracker_indexing_tree_file_matches_filter (TrackerIndexingTree *tree
gboolean tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree, gboolean tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file, GFile *file,
GFileType file_type); GFileInfo *info);
gboolean tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree, gboolean tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
GFile *parent, GFile *parent,
GList *children); GList *children);
......
...@@ -1940,18 +1940,6 @@ item_queue_handlers_set_up (TrackerMinerFS *fs) ...@@ -1940,18 +1940,6 @@ item_queue_handlers_set_up (TrackerMinerFS *fs)
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 static gint
miner_fs_get_queue_priority (TrackerMinerFS *fs, miner_fs_get_queue_priority (TrackerMinerFS *fs,
GFile *file) GFile *file)
...@@ -2303,7 +2291,9 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs, ...@@ -2303,7 +2291,9 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
g_return_if_fail (G_IS_FILE (file)); g_return_if_fail (G_IS_FILE (file));
if (check_parents) { 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); uri = g_file_get_uri (file);
......
...@@ -611,7 +611,6 @@ check_eligible (void) ...@@ -611,7 +611,6 @@ check_eligible (void)
if (info) { if (info) {
is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
g_object_unref (info);
} else { } else {
/* Assume not a dir */ /* Assume not a dir */
is_dir = FALSE; is_dir = FALSE;
...@@ -634,8 +633,10 @@ check_eligible (void) ...@@ -634,8 +633,10 @@ check_eligible (void)
ontology, ontology,
NULL, NULL,
NULL); NULL);
if (!sparql_conn) if (!sparql_conn) {
g_object_unref (info);
return EXIT_FAILURE; return EXIT_FAILURE;
}
/* Create new TrackerMinerFiles object */ /* Create new TrackerMinerFiles object */
config = tracker_config_new (); config = tracker_config_new ();
...@@ -644,16 +645,14 @@ check_eligible (void) ...@@ -644,16 +645,14 @@ check_eligible (void)
g_object_unref (config); g_object_unref (config);
if (!miner_files) { if (!miner_files) {
g_object_unref (info);
g_object_unref (sparql_conn); g_object_unref (sparql_conn);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (miner_files)); indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (miner_files));
indexable = tracker_indexing_tree_file_is_indexable (indexing_tree, file, indexable = tracker_indexing_tree_file_is_indexable (indexing_tree, file, info);
is_dir ?
G_FILE_TYPE_DIRECTORY :
G_FILE_TYPE_REGULAR);
if (!indexable) { if (!indexable) {
if (is_dir && if (is_dir &&
...@@ -739,6 +738,7 @@ check_eligible (void) ...@@ -739,6 +738,7 @@ check_eligible (void)
g_object_unref (config); g_object_unref (config);
g_object_unref (file); g_object_unref (file);
g_object_unref (miner_files); g_object_unref (miner_files);
g_object_unref (info);
tracker_domain_ontology_unref (domain_ontology); tracker_domain_ontology_unref (domain_ontology);
return (indexable && parents_indexable) ? EXIT_SUCCESS : EXIT_FAILURE; return (indexable && parents_indexable) ? EXIT_SUCCESS : EXIT_FAILURE;
...@@ -894,8 +894,7 @@ update_indexed_files_from_proxy (TrackerMinerFiles *miner, ...@@ -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 (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
if (!tracker_indexing_tree_file_is_indexable (indexing_tree, if (!tracker_indexing_tree_file_is_indexable (indexing_tree,
file, file, file_info)) {
G_FILE_TYPE_DIRECTORY)) {
tracker_indexing_tree_add (indexing_tree, tracker_indexing_tree_add (indexing_tree,
file, file,
TRACKER_DIRECTORY_FLAG_RECURSE | TRACKER_DIRECTORY_FLAG_RECURSE |
......
...@@ -60,12 +60,12 @@ typedef struct { ...@@ -60,12 +60,12 @@ typedef struct {
#define ASSERT_INDEXABLE(fixture, id) \ #define ASSERT_INDEXABLE(fixture, id) \
g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \ g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \
fixture->test_dir[id], \ fixture->test_dir[id], \
G_FILE_TYPE_DIRECTORY) == TRUE) NULL) == TRUE)
#define ASSERT_NOT_INDEXABLE(fixture, id) \ #define ASSERT_NOT_INDEXABLE(fixture, id) \
g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \ g_assert_true (tracker_indexing_tree_file_is_indexable (fixture->tree, \
fixture->test_dir[id], \ fixture->test_dir[id], \
G_FILE_TYPE_DIRECTORY) == FALSE) NULL) == FALSE)
#define test_add(path,fun) \ #define test_add(path,fun) \
g_test_add (path, \ g_test_add (path, \
......
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