summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2018-07-15 18:01:38 +0200
committerSam Thursfield <sam@afuera.me.uk>2018-07-15 18:01:38 +0200
commit4bbbe4663b4768fee3a1fdad1fb5214623c779bf (patch)
tree5669ba4a2e5375c62fb371ccf08e386408c48eda
parentbdc3734db91a2ef649d2fb84a7c7c4c59076f5e2 (diff)
parent13cf183c43751c5a817abc63360aa85857342b82 (diff)
downloadtracker-4bbbe4663b4768fee3a1fdad1fb5214623c779bf.tar.gz
Merge branch 'sam/tracker-miner-fs-test-fixes'
See https://gitlab.gnome.org/GNOME/tracker/issues/15
-rw-r--r--src/libtracker-miner/tracker-miner-fs.c111
-rw-r--r--src/libtracker-miner/tracker-task-pool.c11
-rw-r--r--tests/libtracker-miner/tracker-miner-fs-test.c4
3 files changed, 84 insertions, 42 deletions
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 0af1a5834..e8c9de85e 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1461,10 +1461,10 @@ item_add_or_update (TrackerMinerFS *fs,
static gboolean
item_remove (TrackerMinerFS *fs,
GFile *file,
- gboolean only_children)
+ gboolean only_children,
+ GString *task_sparql)
{
gchar *uri, *sparql;
- TrackerTask *task;
guint signal_num;
uri = g_file_get_uri (file);
@@ -1476,23 +1476,16 @@ item_remove (TrackerMinerFS *fs,
fs->priv->quark_recursive_removal,
GINT_TO_POINTER (TRUE));
+ /* Call the implementation to generate a SPARQL update for the removal. */
signal_num = only_children ? REMOVE_CHILDREN : REMOVE_FILE;
g_signal_emit (fs, signals[signal_num], 0, file, &sparql);
- if (sparql) {
- task = tracker_sparql_task_new_take_sparql_str (file, sparql);
- tracker_sparql_buffer_push (fs->priv->sparql_buffer,
- task,
- G_PRIORITY_DEFAULT,
- sparql_buffer_task_finished_cb,
- fs);
- tracker_task_unref (task);
- }
-
- if (!tracker_task_pool_limit_reached (TRACKER_TASK_POOL (fs->priv->sparql_buffer))) {
- item_queue_handlers_set_up (fs);
+ if (sparql && sparql[0] != '\0') {
+ g_string_append (task_sparql, sparql);
+ g_string_append_c (task_sparql, '\n');
}
+ g_free (sparql);
g_free (uri);
return TRUE;
@@ -1500,22 +1493,23 @@ item_remove (TrackerMinerFS *fs,
static gboolean
item_move (TrackerMinerFS *fs,
- GFile *file,
- GFile *source_file)
+ GFile *dest_file,
+ GFile *source_file,
+ GString *dest_task_sparql,
+ GString *source_task_sparql)
{
gchar *uri, *source_uri, *sparql;
GFileInfo *file_info;
- TrackerTask *task;
const gchar *source_iri;
gboolean source_exists;
TrackerDirectoryFlags source_flags, flags;
gboolean recursive;
- uri = g_file_get_uri (file);
+ uri = g_file_get_uri (dest_file);
source_uri = g_file_get_uri (source_file);
/* FIXME: Should check the _NO_STAT on TrackerDirectoryFlags first! */
- file_info = g_file_query_info (file,
+ file_info = g_file_query_info (dest_file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, NULL);
@@ -1530,7 +1524,7 @@ item_move (TrackerMinerFS *fs,
if (source_exists) {
/* Destination file has gone away, ignore dest file and remove source if any */
- retval = item_remove (fs, source_file, FALSE);
+ retval = item_remove (fs, source_file, FALSE, source_task_sparql);
} else {
/* Destination file went away, and source wasn't indexed either */
retval = TRUE;
@@ -1550,7 +1544,7 @@ item_move (TrackerMinerFS *fs,
g_debug ("Source file '%s' not yet in store, indexing '%s' "
"from scratch", source_uri, uri);
- retval = item_add_or_update (fs, file, G_PRIORITY_DEFAULT, FALSE);
+ retval = item_add_or_update (fs, dest_file, G_PRIORITY_DEFAULT, FALSE);
g_free (source_uri);
g_free (uri);
@@ -1564,38 +1558,30 @@ item_move (TrackerMinerFS *fs,
uri);
tracker_indexing_tree_get_root (fs->priv->indexing_tree, source_file, &source_flags);
- tracker_indexing_tree_get_root (fs->priv->indexing_tree, file, &flags);
+ tracker_indexing_tree_get_root (fs->priv->indexing_tree, dest_file, &flags);
recursive = ((source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
(flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
/* Delete destination item from store if any */
- item_remove (fs, file, FALSE);
+ item_remove (fs, dest_file, FALSE, dest_task_sparql);
/* If the original location is recursive, but the destination location
* is not, remove all children.
*/
if (!recursive &&
(source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0)
- item_remove (fs, source_file, TRUE);
+ item_remove (fs, source_file, TRUE, source_task_sparql);
- g_signal_emit (fs, signals[MOVE_FILE], 0, file, source_file, recursive, &sparql);
+ g_signal_emit (fs, signals[MOVE_FILE], 0, dest_file, source_file, recursive, &sparql);
- if (sparql) {
- /* Add new task to processing pool */
- task = tracker_sparql_task_new_take_sparql_str (file, sparql);
- tracker_sparql_buffer_push (fs->priv->sparql_buffer,
- task,
- G_PRIORITY_DEFAULT,
- sparql_buffer_task_finished_cb,
- fs);
- tracker_task_unref (task);
- }
-
- if (!tracker_task_pool_limit_reached (TRACKER_TASK_POOL (fs->priv->sparql_buffer))) {
- item_queue_handlers_set_up (fs);
+ if (sparql && sparql[0] != '\0') {
+ /* This is treated as a task on dest_file */
+ g_string_append (dest_task_sparql, sparql);
+ g_string_append_c (dest_task_sparql, '\n');
}
+ g_free (sparql);
g_free (uri);
g_free (source_uri);
g_object_unref (file_info);
@@ -1719,6 +1705,26 @@ item_queue_get_progress (TrackerMinerFS *fs,
return (gdouble) (items_total - items_to_process) / items_total;
}
+/* Add a task to the processing pool to update stored information on 'file'.
+ *
+ * This function takes ownership of the 'sparql' string.
+ */
+static void
+push_task (TrackerMinerFS *fs,
+ GFile *file,
+ gchar *sparql)
+{
+ TrackerTask *task;
+
+ task = tracker_sparql_task_new_take_sparql_str (file, sparql);
+ tracker_sparql_buffer_push (fs->priv->sparql_buffer,
+ task,
+ G_PRIORITY_DEFAULT,
+ sparql_buffer_task_finished_cb,
+ fs);
+ tracker_task_unref (task);
+}
+
static gboolean
miner_handle_next_item (TrackerMinerFS *fs)
{
@@ -1731,6 +1737,8 @@ miner_handle_next_item (TrackerMinerFS *fs)
gboolean attributes_update = FALSE;
TrackerMinerFSEventType type;
gint priority = 0;
+ GString *task_sparql = NULL;
+ GString *source_task_sparql = NULL;
if (fs->priv->timer_stopped) {
g_timer_start (fs->priv->timer);
@@ -1867,10 +1875,13 @@ miner_handle_next_item (TrackerMinerFS *fs)
/* Handle queues */
switch (type) {
case TRACKER_MINER_FS_EVENT_MOVED:
- keep_processing = item_move (fs, file, source_file);
+ task_sparql = g_string_new ("");
+ source_task_sparql = g_string_new ("");
+ keep_processing = item_move (fs, file, source_file, task_sparql, source_task_sparql);
break;
case TRACKER_MINER_FS_EVENT_DELETED:
- keep_processing = item_remove (fs, file, FALSE);
+ task_sparql = g_string_new ("");
+ keep_processing = item_remove (fs, file, FALSE, task_sparql);
break;
case TRACKER_MINER_FS_EVENT_CREATED:
case TRACKER_MINER_FS_EVENT_UPDATED:
@@ -1914,6 +1925,26 @@ miner_handle_next_item (TrackerMinerFS *fs)
g_assert_not_reached ();
}
+ if (source_task_sparql) {
+ if (source_task_sparql->len == 0) {
+ g_string_free (source_task_sparql, TRUE);
+ } else {
+ push_task (fs, source_file, g_string_free (source_task_sparql, FALSE));
+ }
+ }
+
+ if (task_sparql) {
+ if (task_sparql->len == 0) {
+ g_string_free (task_sparql, TRUE);
+ } else {
+ push_task (fs, file, g_string_free (task_sparql, FALSE));
+ }
+ }
+
+ if (!tracker_task_pool_limit_reached (TRACKER_TASK_POOL (fs->priv->sparql_buffer))) {
+ item_queue_handlers_set_up (fs);
+ }
+
if (file) {
g_object_unref (file);
}
diff --git a/src/libtracker-miner/tracker-task-pool.c b/src/libtracker-miner/tracker-task-pool.c
index f66d4b694..c17d961be 100644
--- a/src/libtracker-miner/tracker-task-pool.c
+++ b/src/libtracker-miner/tracker-task-pool.c
@@ -218,11 +218,22 @@ tracker_task_pool_add (TrackerTaskPool *pool,
TrackerTask *task)
{
TrackerTaskPoolPrivate *priv;
+ GFile *file;
g_return_if_fail (TRACKER_IS_TASK_POOL (pool));
priv = pool->priv;
+ file = tracker_task_get_file (task);
+
+ if (g_hash_table_contains (priv->tasks, file)) {
+ /* This is bad! We use the task's associated GFile as the key for the
+ * hash table, so if there's already a value we are about to overwrite
+ * it. This suggests there's a bug in the tracker-miner-fs.c code.
+ */
+ g_warning ("Multiple update tasks for file %s", g_file_get_uri (file));
+ };
+
g_hash_table_insert (priv->tasks,
tracker_task_get_file (task),
tracker_task_ref (task));
diff --git a/tests/libtracker-miner/tracker-miner-fs-test.c b/tests/libtracker-miner/tracker-miner-fs-test.c
index 3ec5d278e..17769f37d 100644
--- a/tests/libtracker-miner/tracker-miner-fs-test.c
+++ b/tests/libtracker-miner/tracker-miner-fs-test.c
@@ -1948,7 +1948,7 @@ main (gint argc,
ADD_TEST ("/indexing-tree/recursive-indexing",
test_recursive_indexing);
ADD_TEST ("/indexing-tree/non-recursive-indexing",
- test_recursive_indexing);
+ test_non_recursive_indexing);
/* FIXME: test other directory flags */
ADD_TEST ("/indexing-tree/separate-recursive-and-non-recursive",
test_separate_recursive_and_non_recursive);
@@ -2009,7 +2009,7 @@ main (gint argc,
ADD_TEST ("event-queue/create-and-delete",
test_event_queue_create_and_delete);
ADD_TEST ("event-queue/create-and-move",
- test_event_queue_create_and_delete);
+ test_event_queue_create_and_move);
ADD_TEST ("event-queue/update-and-update",
test_event_queue_update_and_update);
ADD_TEST ("event-queue/update-and-delete",