[tracker-miners/sam/index-location: 12/21] Add IndexLocation method call to replace IndexFile[ForProcess]
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-location: 12/21] Add IndexLocation method call to replace IndexFile[ForProcess]
- Date: Thu, 9 Jul 2020 23:04:46 +0000 (UTC)
commit 9aed401e49eec9278876f593642e12815f785a7c
Author: Sam Thursfield <sam afuera me uk>
Date: Thu Jul 9 02:07:53 2020 +0200
Add IndexLocation method call to replace IndexFile[ForProcess]
The new method call takes a flags parameter, allowing more control
over its behaviour in Tracker 3.
src/libtracker-miners-common/tracker-enums.h | 6 ++
src/miners/fs/tracker-miner-files-index.c | 91 ++++++++++++++++++----------
src/miners/fs/tracker-miner-files-index.xml | 16 ++---
src/tracker/tracker-miner-manager.c | 17 +++---
4 files changed, 81 insertions(+), 49 deletions(-)
---
diff --git a/src/libtracker-miners-common/tracker-enums.h b/src/libtracker-miners-common/tracker-enums.h
index d54b97b90..311d6813e 100644
--- a/src/libtracker-miners-common/tracker-enums.h
+++ b/src/libtracker-miners-common/tracker-enums.h
@@ -33,6 +33,12 @@ typedef enum {
TRACKER_SERIALIZATION_FORMAT_JSON_LD,
} TrackerSerializationFormat;
+typedef enum {
+ TRACKER_INDEX_LOCATION_FLAG_FOR_PROCESS = 1 << 0,
+ TRACKER_INDEX_LOCATION_FLAG_AWAIT_MINER_FS = 1 << 1,
+ TRACKER_INDEX_LOCATION_FLAG_AWAIT_EXTRACT = 1 << 2,
+} TrackerIndexLocationFlags;
+
G_END_DECLS
#endif /* __TRACKER_ENUMS_H__ */
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index a6b940b8c..bc1138823 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -20,6 +20,8 @@
#include "config-miners.h"
#include <libtracker-miners-common/tracker-dbus.h>
+#include <libtracker-miners-common/tracker-enums.h>
+#include <libtracker-miners-common/tracker-miners-enum-types.h>
#include <libtracker-sparql/tracker-sparql.h>
#include <libtracker-miner/tracker-miner.h>
@@ -30,11 +32,9 @@
static const gchar introspection_xml[] =
"<node>"
" <interface name='org.freedesktop.Tracker3.Miner.Files.Index'>"
- " <method name='IndexFile'>"
- " <arg type='s' name='file_uri' direction='in' />"
- " </method>"
- " <method name='IndexFileForProcess'>"
- " <arg type='s' name='file_uri' direction='in' />"
+ " <method name='IndexLocation'>"
+ " <arg type='s' name='uri' direction='in' />"
+ " <arg type='as' name='flags' direction='in' />"
" </method>"
" </interface>"
"</node>";
@@ -87,6 +87,7 @@ G_DEFINE_TYPE_WITH_PRIVATE(TrackerMinerFilesIndex, tracker_miner_files_index, G_
GQuark tracker_miner_index_error_quark (void);
typedef enum {
+ TRACKER_MINER_INDEX_ERROR_UNKNOWN_FLAG,
TRACKER_MINER_INDEX_ERROR_FILE_NOT_FOUND,
TRACKER_MINER_INDEX_ERROR_DIRECTORIES_ONLY,
TRACKER_MINER_INDEX_ERROR_NOT_ELIGIBLE,
@@ -95,6 +96,7 @@ typedef enum {
static const GDBusErrorEntry tracker_miner_index_error_entries[] =
{
+ {TRACKER_MINER_INDEX_ERROR_UNKNOWN_FLAG,
"org.freedesktop.Tracker.Miner.Files.Index.Error.UnknownFlag"},
{TRACKER_MINER_INDEX_ERROR_FILE_NOT_FOUND,
"org.freedesktop.Tracker.Miner.Files.Index.Error.FileNotFound"},
{TRACKER_MINER_INDEX_ERROR_DIRECTORIES_ONLY,
"org.freedesktop.Tracker.Miner.Files.Index.Error.DirectoriesOnly"},
{TRACKER_MINER_INDEX_ERROR_NOT_ELIGIBLE,
"org.freedesktop.Tracker.Miner.Files.Index.Error.NotEligible"},
@@ -199,27 +201,70 @@ index_finalize (GObject *object)
g_object_unref (priv->files_miner);
}
+static TrackerIndexLocationFlags
+parse_index_location_flags (const gchar **flags_strv,
+ GError **error)
+{
+ TrackerIndexLocationFlags flags = 0;
+ GFlagsClass *type_class;
+ GFlagsValue *value;
+ const gchar *flag_string;
+
+ type_class = g_type_class_ref (TRACKER_TYPE_INDEX_LOCATION_FLAGS);
+
+ for (flag_string = *flags_strv; flag_string; flag_string ++) {
+ value = g_flags_get_value_by_nick (type_class, flag_string);
+
+ if (value == NULL) {
+ g_set_error (error,
+ TRACKER_MINER_INDEX_ERROR,
+ TRACKER_MINER_INDEX_ERROR_UNKNOWN_FLAG,
+ "Unknown flag %s",
+ flag_string);
+ break;
+ }
+
+ flags |= value->value;
+ }
+
+ g_type_class_unref (type_class);
+
+ return flags;
+}
+
static void
-handle_method_call_index_file (TrackerMinerFilesIndex *miner,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- gboolean watch_source)
+handle_method_call_index_location (TrackerMinerFilesIndex *miner,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters)
{
TrackerMinerFilesIndexPrivate *priv;
TrackerDBusRequest *request;
- GFile *file;
+ g_autoptr(GFile) file = NULL;
GFileInfo *file_info;
gboolean is_dir;
gboolean do_checks = FALSE;
- GError *internal_error;
+ g_autoptr(GError) internal_error = NULL;
const gchar *file_uri;
+ g_autofree const gchar **flags_strv = NULL;
+ TrackerIndexLocationFlags flags;
+ gboolean watch_source;
priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (miner);
- g_variant_get (parameters, "(&s)", &file_uri);
+ g_variant_get (parameters, "(&s^a&s)", &file_uri, &flags_strv);
tracker_gdbus_async_return_if_fail (file_uri != NULL, invocation);
+ flags = parse_index_location_flags (flags_strv, &internal_error);
+
+ if (internal_error != NULL) {
+ g_dbus_method_invocation_return_gerror (invocation, internal_error);
+
+ return;
+ }
+
+ watch_source = flags & TRACKER_INDEX_LOCATION_FLAG_FOR_PROCESS;
+
request = tracker_g_dbus_request_begin (invocation, "%s(uri:'%s')", __FUNCTION__, file_uri);
file = g_file_new_for_uri (file_uri);
@@ -236,10 +281,6 @@ handle_method_call_index_file (TrackerMinerFilesIndex *miner,
tracker_dbus_request_end (request, internal_error);
g_dbus_method_invocation_return_gerror (invocation, internal_error);
- g_error_free (internal_error);
-
- g_object_unref (file);
-
return;
}
@@ -255,10 +296,6 @@ handle_method_call_index_file (TrackerMinerFilesIndex *miner,
tracker_dbus_request_end (request, internal_error);
g_dbus_method_invocation_return_gerror (invocation, internal_error);
- g_error_free (internal_error);
-
- g_object_unref (file);
-
return;
}
#endif /* REQUIRE_LOCATION_IN_CONFIG */
@@ -306,14 +343,10 @@ handle_method_call_index_file (TrackerMinerFilesIndex *miner,
if (watch_source) {
internal_error = g_error_new_literal (TRACKER_MINER_INDEX_ERROR,
TRACKER_MINER_INDEX_ERROR_DIRECTORIES_ONLY,
- "Only directories can be processed using
IndexFileForProcess");
+ "Only directories can be processed in
`for-process` mode");
tracker_dbus_request_end (request, internal_error);
g_dbus_method_invocation_return_gerror (invocation, internal_error);
- g_error_free (internal_error);
-
- g_object_unref (file);
-
return;
} else {
tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner),
@@ -323,8 +356,6 @@ handle_method_call_index_file (TrackerMinerFilesIndex *miner,
tracker_dbus_request_end (request, NULL);
g_dbus_method_invocation_return_value (invocation, NULL);
-
- g_object_unref (file);
}
static void
@@ -342,10 +373,8 @@ handle_method_call (GDBusConnection *connection,
tracker_gdbus_async_return_if_fail (miner != NULL, invocation);
tracker_gdbus_async_return_if_fail (TRACKER_IS_MINER_FILES_INDEX (miner), invocation);
- if (g_strcmp0 (method_name, "IndexFile") == 0) {
- handle_method_call_index_file (miner, invocation, parameters, FALSE);
- } else if (g_strcmp0 (method_name, "IndexFileForProcess") == 0) {
- handle_method_call_index_file (miner, invocation, parameters, TRUE);
+ if (g_strcmp0 (method_name, "IndexLocation") == 0) {
+ handle_method_call_index_location (miner, invocation, parameters);
} else {
g_assert_not_reached ();
}
diff --git a/src/miners/fs/tracker-miner-files-index.xml b/src/miners/fs/tracker-miner-files-index.xml
index 47d91d24c..cd33f7433 100644
--- a/src/miners/fs/tracker-miner-files-index.xml
+++ b/src/miners/fs/tracker-miner-files-index.xml
@@ -2,17 +2,11 @@
<node name="/">
<interface name="org.freedesktop.Tracker3.Miner.Files.Index">
- <method name="ReindexMimeTypes">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
- <arg type="as" name="mime_types" direction="in" />
- </method>
- <method name="IndexFile">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
- <arg type="s" name="file_uri" direction="in" />
- </method>
- <method name="IndexFileForProcess">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
- <arg type="s" name="file_uri" direction="in" />
+ <method name='IndexLocation'>"
+ <arg type='s' name='uri' direction='in' />"
+ <arg type='as' name='flags' direction='in'>"
+ <doc:doc><doc:summary>Allowed values: for-process, await-miner-fs,
await-extract</doc:summary></doc:doc>
+ </arg>
</method>
</interface>
</node>
diff --git a/src/tracker/tracker-miner-manager.c b/src/tracker/tracker-miner-manager.c
index b2b69a16a..3e8574102 100644
--- a/src/tracker/tracker-miner-manager.c
+++ b/src/tracker/tracker-miner-manager.c
@@ -47,9 +47,6 @@
#define DISPLAY_NAME_KEY "DisplayName"
#define DESCRIPTION_KEY "Comment"
-#define METHOD_INDEX_FILE "IndexFile"
-#define METHOD_INDEX_FILE_FOR_PROCESS "IndexFileForProcess"
-
typedef struct TrackerMinerManagerPrivate TrackerMinerManagerPrivate;
typedef struct MinerData MinerData;
@@ -1545,7 +1542,8 @@ tracker_indexing_task_run (GTask *task,
gchar *uri;
GVariant *v;
GError *error = NULL;
- const gchar *method_name;
+ const gchar **flags;
+ const gchar *flags_for_process[] = {"for-process", NULL};
priv = tracker_miner_manager_get_instance_private (manager);
@@ -1553,15 +1551,20 @@ tracker_indexing_task_run (GTask *task,
tracker_indexing_status_start_watching (data->status, manager, 0, &error);
- method_name = data->for_process ? METHOD_INDEX_FILE_FOR_PROCESS : METHOD_INDEX_FILE;
uri = g_file_get_uri (data->root);
+ if (data->for_process) {
+ flags = flags_for_process;
+ } else {
+ flags = NULL;
+ }
+
v = g_dbus_connection_call_sync (priv->connection,
"org.freedesktop.Tracker3.Miner.Files",
"/org/freedesktop/Tracker3/Miner/Files/Index",
"org.freedesktop.Tracker3.Miner.Files.Index",
- method_name,
- g_variant_new ("(s)", uri),
+ "IndexLocation",
+ g_variant_new ("(sas)", uri, flags),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]