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)
/* 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
......@@ -840,6 +840,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,
......@@ -849,14 +862,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;
......@@ -921,13 +932,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;
}
......@@ -943,13 +952,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;
}
......@@ -965,10 +972,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 &&
......@@ -1011,7 +1016,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 ;
}
......@@ -1068,7 +1073,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) {
......@@ -1077,18 +1082,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);
......@@ -1273,17 +1277,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 &&
......@@ -1292,7 +1298,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);
}
......@@ -1384,12 +1390,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;
}
......
......@@ -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 ? */
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 |
......
......@@ -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, \
......
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