[tracker-miners/sam/index-location: 19/21] Implement 'await-miner-fs' flag
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-location: 19/21] Implement 'await-miner-fs' flag
- Date: Thu, 9 Jul 2020 23:05:22 +0000 (UTC)
commit 9727fb6266e76c4224b801c713aabf933d30feeb
Author: Sam Thursfield <sam afuera me uk>
Date: Wed Jul 8 00:56:48 2020 +0200
Implement 'await-miner-fs' flag
src/miners/fs/tracker-miner-files-index.c | 77 ++++++++++++++++++++++++++++---
tests/functional-tests/miner-on-demand.py | 7 ++-
2 files changed, 76 insertions(+), 8 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 53b3fde03..1103a1562 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -40,11 +40,10 @@ static const gchar introspection_xml[] =
"</node>";
typedef struct {
+ GFile *file;
TrackerDBusRequest *request;
GDBusMethodInvocation *invocation;
- TrackerSparqlConnection *connection;
- TrackerMinerFiles *miner_files;
-} MimeTypesData;
+} AwaitMinerFsData;
typedef struct {
TrackerMinerFiles *files_miner;
@@ -108,6 +107,30 @@ tracker_miner_index_error_quark (void)
return (GQuark) quark_volatile;
}
+static AwaitMinerFsData *
+await_miner_fs_data_new (GFile *file,
+ TrackerDBusRequest *request,
+ GDBusMethodInvocation *invocation)
+{
+ AwaitMinerFsData *data;
+
+ data = g_slice_new0 (AwaitMinerFsData);
+ data->file = g_object_ref (file);
+ data->request = g_object_ref (request);
+ data->invocation = g_object_ref (invocation);
+
+ return data;
+}
+
+static void
+await_miner_fs_data_free (AwaitMinerFsData *data)
+{
+ g_object_unref (data->file);
+ g_object_unref (data->request);
+ g_object_unref (data->invocation);
+ g_slice_free (AwaitMinerFsData, data);
+}
+
static void
tracker_miner_files_index_class_init (TrackerMinerFilesIndexClass *klass)
{
@@ -285,6 +308,30 @@ index_directory (TrackerMinerFilesIndex *miner,
}
}
+static void
+await_miner_fs_files_processed_cb (TrackerMinerFS *miner_fs,
+ const gchar *uri,
+ gboolean success,
+ const gchar *message,
+ gpointer user_data)
+{
+ AwaitMinerFsData *data = user_data;
+ GFile *processed_file;
+
+ processed_file = g_file_new_for_uri (uri);
+
+ if (g_file_equal (data->file, processed_file)) {
+ /* We got the file, so the IndexLocation DBus method call can now return */
+
+ g_signal_handlers_disconnect_by_data (miner_fs, data);
+
+ tracker_dbus_request_end (data->request, NULL);
+
+ /* FIXME: return an error if success = FALSE ... */
+ g_dbus_method_invocation_return_value (data->invocation, NULL);
+ }
+}
+
static void
handle_method_call_index_location (TrackerMinerFilesIndex *miner,
GDBusMethodInvocation *invocation,
@@ -315,8 +362,6 @@ handle_method_call_index_location (TrackerMinerFilesIndex *miner,
return;
}
- watch_for_caller = flags & TRACKER_INDEX_LOCATION_FLAG_WATCH_FOR_CALLER;
-
request = tracker_g_dbus_request_begin (invocation, "%s(uri:'%s')", __FUNCTION__, file_uri);
file = g_file_new_for_uri (file_uri);
@@ -336,9 +381,23 @@ handle_method_call_index_location (TrackerMinerFilesIndex *miner,
return;
}
+ watch_for_caller = flags & TRACKER_INDEX_LOCATION_FLAG_WATCH_FOR_CALLER;
+
is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
g_object_unref (file_info);
+ if (flags & TRACKER_INDEX_LOCATION_FLAG_AWAIT_MINER_FS) {
+ AwaitMinerFsData *data;
+
+ data = await_miner_fs_data_new (file, request, invocation);
+ g_signal_connect_data (TRACKER_MINER_FS (priv->files_miner),
+ "file-processed",
+ G_CALLBACK (await_miner_fs_files_processed_cb),
+ data,
+ (GClosureNotify) await_miner_fs_data_free,
+ 0);
+ }
+
if (is_dir) {
index_directory (miner, file, invocation, watch_for_caller);
} else {
@@ -356,8 +415,12 @@ handle_method_call_index_location (TrackerMinerFilesIndex *miner,
}
}
- tracker_dbus_request_end (request, NULL);
- g_dbus_method_invocation_return_value (invocation, NULL);
+ if (flags & TRACKER_INDEX_LOCATION_FLAG_AWAIT_MINER_FS) {
+ /* DBus request will return in await_miner_fs_files_processed_cb */
+ } else {
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
}
static void
diff --git a/tests/functional-tests/miner-on-demand.py b/tests/functional-tests/miner-on-demand.py
index 95d9a38c6..75e2bc569 100755
--- a/tests/functional-tests/miner-on-demand.py
+++ b/tests/functional-tests/miner-on-demand.py
@@ -114,7 +114,12 @@ class MinerOnDemandTest(fixtures.TrackerMinerTest):
]
with self.miner_fs.await_files_processed(expected):
- self.miner_fs.index_location(testdir.as_uri())
+ self.miner_fs.index_location(testdir.as_uri(), ['await-miner-fs'])
+
+ def test_index_location_invalid_flag(self):
+ testdir = pathlib.Path(self.workdir).joinpath('test-not-monitored')
+ self.miner_fs.index_location(testdir.as_uri(), ['invalid-flag-which-should-trigger-an-error'])
+
if __name__ == "__main__":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]