[tracker-miners/sam/index-location: 8/8] Add IndexLocation method call to replace IndexFile[ForProcess]



commit 7190c46610e98543dc8cadea9aa6096f22354cfd
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.
    
    The equivalent of the IndexFileForProcess method is now to call
    `IndexLocation(uri, ['watch-for-caller'])`. As before, this
    enables two things: the location is watched for changes while
    the calling process is connected to the bus, and the location
    is un-indexed if the calling process disconnected from the bus.

 src/libtracker-miners-common/tracker-enums.h  |   7 +
 src/miners/fs/tracker-miner-files-index.c     | 227 +++++++++++++----------
 src/miners/fs/tracker-miner-files-index.xml   |  16 +-
 src/tracker/tracker-index.c                   |   2 +-
 src/tracker/tracker-miner-manager.c           | 255 ++++++++++----------------
 src/tracker/tracker-miner-manager.h           |  40 ++--
 src/tracker/tracker-reset.c                   |   2 +-
 tests/functional-tests/extractor-decorator.py |   2 +-
 tests/functional-tests/miner-basic.py         |   2 +-
 tests/functional-tests/minerhelper.py         |   4 +-
 10 files changed, 263 insertions(+), 294 deletions(-)
---
diff --git a/src/libtracker-miners-common/tracker-enums.h b/src/libtracker-miners-common/tracker-enums.h
index d54b97b90..708e81b2b 100644
--- a/src/libtracker-miners-common/tracker-enums.h
+++ b/src/libtracker-miners-common/tracker-enums.h
@@ -33,6 +33,13 @@ typedef enum {
        TRACKER_SERIALIZATION_FORMAT_JSON_LD,
 } TrackerSerializationFormat;
 
+typedef enum {
+       TRACKER_INDEX_LOCATION_FLAGS_NONE = 0,
+       TRACKER_INDEX_LOCATION_WATCH_FOR_CALLER = 1 << 0,
+       TRACKER_INDEX_LOCATION_AWAIT_MINER_FS = 1 << 1,
+       TRACKER_INDEX_LOCATION_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 82a2c0473..66a64bbee 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,29 +32,13 @@
 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>";
 
-/* If defined, then a file provided to be indexed MUST be a child in
- * an configured path. if undefined, any file can be indexed, however
- * it is up to applications to maintain files outside the configured
- * locations.
- */
-#undef REQUIRE_LOCATION_IN_CONFIG
-
-typedef struct {
-       TrackerDBusRequest *request;
-       GDBusMethodInvocation *invocation;
-       TrackerSparqlConnection *connection;
-       TrackerMinerFiles *miner_files;
-} MimeTypesData;
-
 typedef struct {
        TrackerMinerFiles *files_miner;
        TrackerMinerFilesPeerListener *peer_listener;
@@ -87,6 +73,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 +82,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 +187,132 @@ 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;
+
+       type_class = g_type_class_ref (TRACKER_TYPE_INDEX_LOCATION_FLAGS);
+
+       while (*flags_strv) {
+               const gchar *flag_string = *flags_strv;
+
+               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;
+
+               flags_strv ++;
+       }
+
+       g_type_class_unref (type_class);
+
+       return flags;
+}
+
+/* Returns TRUE if 'directory' is currently indexed by Tracker */
+static gboolean
+directory_is_configured_for_indexing (TrackerIndexingTree *indexing_tree,
+                                      GFile               *directory)
+{
+       GFile *root;
+       TrackerDirectoryFlags flags;
+
+       root = tracker_indexing_tree_get_root (indexing_tree, directory, &flags);
+
+       if (root) {
+               if (flags & TRACKER_DIRECTORY_FLAG_RECURSE) {
+                       return TRUE;
+               } else if (g_file_equal (root, directory) && g_file_has_parent (directory, root)) {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 static void
-handle_method_call_index_file (TrackerMinerFilesIndex *miner,
-                               GDBusMethodInvocation  *invocation,
-                               GVariant               *parameters,
-                               gboolean                watch_source)
+index_directory (TrackerMinerFilesIndex *miner,
+                 GFile                  *directory,
+                 GDBusMethodInvocation  *invocation,
+                 gboolean                watch_for_caller)
+{
+       TrackerMinerFilesIndexPrivate *priv;
+       TrackerIndexingTree *indexing_tree;
+       gboolean is_watched, needs_watch = FALSE;
+
+       priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (miner);
+
+       indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (priv->files_miner));
+
+       if (directory_is_configured_for_indexing (indexing_tree, directory)) {
+               tracker_indexing_tree_notify_update (indexing_tree, directory, TRUE);
+               needs_watch = FALSE;
+       } else {
+               tracker_indexing_tree_add (indexing_tree, directory,
+                                              TRACKER_DIRECTORY_FLAG_RECURSE |
+                                              TRACKER_DIRECTORY_FLAG_PRIORITY |
+                                              TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
+                                              TRACKER_DIRECTORY_FLAG_MONITOR);
+               needs_watch = TRUE;
+       }
+
+       /* If the directory had already subscribers, we want to add all
+        * further watches, so the directory survives as long as there's
+        * watchers.
+        */
+       is_watched = tracker_miner_files_peer_listener_is_file_watched (priv->peer_listener, directory);
+
+       if (watch_for_caller && (is_watched || needs_watch)) {
+               tracker_miner_files_peer_listener_add_watch (priv->peer_listener,
+                                                                g_dbus_method_invocation_get_sender 
(invocation),
+                                                                directory);
+       }
+}
+
+static void
+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_for_caller;
 
        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_for_caller = flags & TRACKER_INDEX_LOCATION_WATCH_FOR_CALLER;
+
        request = tracker_g_dbus_request_begin (invocation, "%s(uri:'%s')", __FUNCTION__, file_uri);
 
        file = g_file_new_for_uri (file_uri);
@@ -236,81 +329,31 @@ 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;
        }
 
        is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
        g_object_unref (file_info);
 
-#ifdef REQUIRE_LOCATION_IN_CONFIG
-       do_checks = TRUE;
-       if (!tracker_miner_files_is_file_eligible (priv->files_miner, file)) {
-               internal_error = g_error_new_literal (TRACKER_MINER_INDEX_ERROR,
-                                                     TRACKER_MINER_INDEX_ERROR_NOT_ELIGIBLE,
-                                                     "File is not eligible to be indexed");
-               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 */
-
        if (is_dir) {
-               TrackerIndexingTree *indexing_tree;
-               TrackerDirectoryFlags flags;
-               gboolean is_watched, needs_watch = FALSE;
-               GFile *root;
-
-               indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (priv->files_miner));
-               root = tracker_indexing_tree_get_root (indexing_tree, file, &flags);
-
-               /* If the directory had already subscribers, we want to add all
-                * further watches, so the directory survives as long as there's
-                * watchers.
-                */
-               is_watched = tracker_miner_files_peer_listener_is_file_watched (priv->peer_listener, file);
-
-               /* Check whether the requested dir is not over a (recursively)
-                * watched directory already, in that case we don't add the
-                * directory (nor add a watch if we're positive it comes from
-                * config).
-                */
-               if (!root ||
-                   (!(flags & TRACKER_DIRECTORY_FLAG_RECURSE) &&
-                    !g_file_equal (root, file) &&
-                    !g_file_has_parent (file, root))) {
-                       tracker_indexing_tree_add (indexing_tree, file,
-                                                  TRACKER_DIRECTORY_FLAG_RECURSE |
-                                                  TRACKER_DIRECTORY_FLAG_PRIORITY |
-                                                  TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
-                                                  TRACKER_DIRECTORY_FLAG_MONITOR);
-                       needs_watch = TRUE;
+               index_directory (miner, file, invocation, watch_for_caller);
+       } else {
+               if (watch_for_caller) {
+                       internal_error = g_error_new_literal (TRACKER_MINER_INDEX_ERROR,
+                                                             TRACKER_MINER_INDEX_ERROR_DIRECTORIES_ONLY,
+                                                             "Only directories can be processed in 
`watch-for-caller` mode");
+                       tracker_dbus_request_end (request, internal_error);
+                       g_dbus_method_invocation_return_gerror (invocation, internal_error);
+
+                       return;
                } else {
-                       tracker_indexing_tree_notify_update (indexing_tree, file, TRUE);
+                       tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner),
+                                                    file, G_PRIORITY_HIGH, FALSE);
                }
-
-               if (watch_source && (is_watched || needs_watch)) {
-                       tracker_miner_files_peer_listener_add_watch (priv->peer_listener,
-                                                                    g_dbus_method_invocation_get_sender 
(invocation),
-                                                                    file);
-               }
-       } else {
-               tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner),
-                                            file, G_PRIORITY_HIGH, do_checks);
        }
 
        tracker_dbus_request_end (request, NULL);
        g_dbus_method_invocation_return_value (invocation, NULL);
-
-       g_object_unref (file);
 }
 
 static void
@@ -328,10 +371,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..2c453c622 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: watch-for-caller, await-miner-fs, 
await-extract</doc:summary></doc:doc>
+      </arg>
     </method>
   </interface>
 </node>
diff --git a/src/tracker/tracker-index.c b/src/tracker/tracker-index.c
index f0ff904fe..414c048f5 100644
--- a/src/tracker/tracker-index.c
+++ b/src/tracker/tracker-index.c
@@ -70,7 +70,7 @@ index_or_reindex_file (void)
                GFile *file;
 
                file = g_file_new_for_commandline_arg (*p);
-               tracker_miner_manager_index_file (manager, file, NULL, &error);
+               tracker_miner_manager_index_location (manager, file, TRACKER_INDEX_LOCATION_FLAGS_NONE, NULL, 
&error);
 
                if (error) {
                        g_printerr ("%s: %s\n",
diff --git a/src/tracker/tracker-miner-manager.c b/src/tracker/tracker-miner-manager.c
index b021492b4..2d9b21e1b 100644
--- a/src/tracker/tracker-miner-manager.c
+++ b/src/tracker/tracker-miner-manager.c
@@ -24,6 +24,7 @@
 #include <string.h>
 
 #include <libtracker-miners-common/tracker-dbus.h>
+#include <libtracker-miners-common/tracker-enums.h>
 #include <libtracker-miners-common/tracker-type-utils.h>
 #include <libtracker-miners-common/tracker-domain-ontology.h>
 
@@ -47,9 +48,6 @@
 #define DISPLAY_NAME_KEY "DisplayName"
 #define DESCRIPTION_KEY "Comment"
 
-#define METHOD_INDEX_FILE "IndexFile"
-#define METHOD_INDEX_FILE_FOR_PROCESS "IndexFileForProcess"
-
 #define TRACKER_MINER_DBUS_INTERFACE "org.freedesktop.Tracker3.Miner"
 
 typedef struct TrackerMinerManagerPrivate TrackerMinerManagerPrivate;
@@ -81,6 +79,11 @@ struct TrackerMinerManagerPrivate {
        TrackerDomainOntology *domain_ontology;
 };
 
+typedef struct {
+       GFile *location;
+       TrackerIndexLocationFlags flags;
+} IndexLocationTaskData;
+
 static void miner_manager_initable_iface_init (GInitableIface         *iface);
 static void miner_manager_set_property        (GObject             *object,
                                                guint                param_id,
@@ -1406,15 +1409,40 @@ tracker_miner_manager_error_quark (void)
        return error_quark;
 }
 
+static gchar **
+index_location_flags_to_strv (TrackerIndexLocationFlags flags)
+{
+       GFlagsClass *typeclass;
+       GPtrArray *flags_array;
+       int i;
+
+       typeclass = g_type_class_ref (TRACKER_TYPE_INDEX_LOCATION_FLAGS);
+       flags_array = g_ptr_array_new ();
+
+       for (i = 0; i < typeclass->n_values; i++) {
+               GFlagsValue *value;
+
+               value = &typeclass->values[i];
+
+               if (flags & (value->value)) {
+                       g_ptr_array_add (flags_array, (char *)value->value_nick);
+               }
+       }
+
+       g_type_class_unref (typeclass);
+       return (gchar **) g_ptr_array_free (flags_array, FALSE);
+}
+
 static gboolean
-miner_manager_index_file_sync (TrackerMinerManager *manager,
-                               const gchar         *method_name,
-                               GFile               *file,
-                               GCancellable        *cancellable,
-                               GError             **error)
+miner_manager_index_location_sync (TrackerMinerManager       *manager,
+                                   GFile                     *file,
+                                   TrackerIndexLocationFlags  flags,
+                                   GCancellable               *cancellable,
+                                   GError                    **error)
 {
        TrackerMinerManagerPrivate *priv;
        gchar *uri;
+       gchar **flags_strv;
        GVariant *v;
        GError *new_error = NULL;
 
@@ -1438,13 +1466,14 @@ miner_manager_index_file_sync (TrackerMinerManager *manager,
        priv = tracker_miner_manager_get_instance_private (manager);
 
        uri = g_file_get_uri (file);
+       flags_strv = index_location_flags_to_strv (flags);
 
        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_strv),
                                         NULL,
                                         G_DBUS_CALL_FLAGS_NONE,
                                         -1,
@@ -1452,6 +1481,7 @@ miner_manager_index_file_sync (TrackerMinerManager *manager,
                                         &new_error);
 
        g_free (uri);
+       g_free (flags_strv);
 
        if (new_error) {
                g_propagate_error (error, new_error);
@@ -1463,115 +1493,38 @@ miner_manager_index_file_sync (TrackerMinerManager *manager,
        return TRUE;
 }
 
-static void
-miner_manager_index_file_thread (GTask *task,
-                                 gpointer source_object,
-                                 gpointer task_data,
-                                 GCancellable *cancellable)
+static IndexLocationTaskData *
+index_location_task_data_new (GFile                     *location,
+                              TrackerIndexLocationFlags  flags)
 {
-       TrackerMinerManager *manager = source_object;
-       GFile *file = task_data;
-       GError *error = NULL;
+       IndexLocationTaskData *data;
 
-       miner_manager_index_file_sync (manager, METHOD_INDEX_FILE,
-                                      file, cancellable, &error);
-       if (error != NULL) {
-               g_task_return_error (task, error);
-       } else {
-               g_task_return_boolean (task, TRUE);
-       }
-}
+       data = g_slice_new0 (IndexLocationTaskData);
+       data->location = g_object_ref (location);
+       data->flags = flags;
 
-/**
- * tracker_miner_manager_index_file:
- * @manager: a #TrackerMinerManager
- * @file: a URL valid in GIO of a file to give to the miner for processing
- * @cancellable: (allow-none): a #GCancellable, or %NULL
- * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
- *
- * Tells the filesystem miner to start indexing the @file.
- *
- * On failure @error will be set.
- *
- * Returns: %TRUE on success, otherwise %FALSE.
- *
- * Since: 2.0
- **/
-gboolean
-tracker_miner_manager_index_file (TrackerMinerManager  *manager,
-                                  GFile                *file,
-                                  GCancellable         *cancellable,
-                                  GError              **error)
-{
-       g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
-       g_return_val_if_fail (G_IS_FILE (file), FALSE);
-       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
-
-       return miner_manager_index_file_sync (manager, METHOD_INDEX_FILE,
-                                             file, cancellable, error);
+       return data;
 }
 
-/**
- * tracker_miner_manager_index_file_async:
- * @manager: a #TrackerMinerManager
- * @file: a URL valid in GIO of a file to give to the miner for processing
- * @cancellable: (allow-none): a #GCancellable, or %NULL
- * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
- * @user_data: the data to pass to the callback function
- *
- * Tells the filesystem miner to start indexing the @file. Once the message has been sent,
- * @callback will be called. You can then call tracker_miner_manager_index_file_finish()
- * to get the result.
- *
- * Since: 0.16
- **/
-void
-tracker_miner_manager_index_file_async (TrackerMinerManager *manager,
-                                        GFile               *file,
-                                        GCancellable        *cancellable,
-                                        GAsyncReadyCallback  callback,
-                                        gpointer             user_data)
-{
-       GTask *task = g_task_new (manager, cancellable, callback, user_data);
-       g_task_set_task_data (task, g_object_ref (file), (GDestroyNotify) g_object_unref);
-       g_task_run_in_thread (task, miner_manager_index_file_thread);
-       g_object_unref (task);
-}
-
-/**
- * tracker_miner_manager_index_file_finish:
- * @manager: a #TrackerMinerManager
- * @result: a #GAsyncResult
- * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
- *
- * Finishes a request to index a file. See tracker_miner_manager_index_file_async()
- *
- * On failure @error will be set.
- *
- * Returns: %TRUE on success, otherwise %FALSE.
- *
- * Since: 0.16
- **/
-gboolean
-tracker_miner_manager_index_file_finish (TrackerMinerManager *manager,
-                                         GAsyncResult        *result,
-                                         GError             **error)
+static void
+index_location_task_data_free (IndexLocationTaskData *data)
 {
-       return g_task_propagate_boolean (G_TASK (result), error);
+       g_object_unref (data->location);
+       g_slice_free (IndexLocationTaskData, data);
 }
 
 static void
-miner_manager_index_file_for_process_thread (GTask        *task,
-                                             gpointer      source_object,
-                                             gpointer      task_data,
-                                             GCancellable *cancellable)
+miner_manager_index_location_thread (GTask        *task,
+                                     gpointer      source_object,
+                                     gpointer      task_data,
+                                     GCancellable *cancellable)
 {
        TrackerMinerManager *manager = source_object;
-       GFile *file = task_data;
+       IndexLocationTaskData *data = task_data;
        GError *error = NULL;
 
-       miner_manager_index_file_sync (manager, METHOD_INDEX_FILE_FOR_PROCESS,
-                                      file, cancellable, &error);
+       miner_manager_index_location_sync (manager, data->location, data->flags,
+                                          cancellable, &error);
        if (error != NULL) {
                g_task_return_error (task, error);
        } else {
@@ -1579,101 +1532,83 @@ miner_manager_index_file_for_process_thread (GTask        *task,
        }
 }
 
+
 /**
- * tracker_miner_manager_index_file_for_process:
+ * tracker_miner_manager_index_location:
  * @manager: a #TrackerMinerManager
- * @file: a URL valid in GIO of a file to give to the miner for processing
+ * @location: a #GFile instance of a file or directory
+ * @flags: values from #TrackerIndexLocationFlags
  * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
  *
- * This function operates exactly the same way as
- * tracker_miner_manager_index_file() with the exception that if the
- * calling process dies, the indexing is cancelled. This API is useful
- * for cases where the calling process wants to tie the indexing
- * operation closely to its own lifetime.
+ * Tells the filesystem miner to start indexing the @file.
  *
  * On failure @error will be set.
  *
  * Returns: %TRUE on success, otherwise %FALSE.
  *
- * Since: 1.10
+ * Since: 2.0
  **/
 gboolean
-tracker_miner_manager_index_file_for_process (TrackerMinerManager  *manager,
-                                              GFile                *file,
-                                              GCancellable         *cancellable,
-                                              GError              **error)
+tracker_miner_manager_index_location (TrackerMinerManager        *manager,
+                                      GFile                      *location,
+                                      TrackerIndexLocationFlags   flags,
+                                      GCancellable               *cancellable,
+                                      GError                    **error)
 {
-       g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
-       g_return_val_if_fail (G_IS_FILE (file), FALSE);
-       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
-       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
-       return miner_manager_index_file_sync (manager, METHOD_INDEX_FILE_FOR_PROCESS,
-                                             file, cancellable, error);
+       return miner_manager_index_location_sync (manager, location, flags, cancellable, error);
 }
 
 /**
- * tracker_miner_manager_index_file_for_process_async:
+ * tracker_miner_manager_index_location_async:
  * @manager: a #TrackerMinerManager
- * @file: a URL valid in GIO of a file to give to the miner for processing
+ * @location: a #GFile instance of a file or directory
+ * @flags: values from #TrackerIndexLocationFlags
  * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
  * @user_data: the data to pass to the callback function
  *
- * This function operates exactly the same way as
- * tracker_miner_manager_index_file() with the exception that if the
- * calling process dies, the indexing is cancelled. This API is useful
- * for cases where the calling process wants to tie the indexing
- * operation closely to its own lifetime.
- *
- * When the operation is finished, @callback will be called. You can
- * then call tracker_miner_manager_index_file_for_process_finish() to
- * get the result of the operation.
+ * Tells the filesystem miner to start indexing the @location. Once the message has been sent,
+ * @callback will be called. You can then call tracker_miner_manager_index_location_finish()
+ * to get the result.
  *
- * Since: 1.10
+ * Since: 0.16
  **/
 void
-tracker_miner_manager_index_file_for_process_async (TrackerMinerManager *manager,
-                                                    GFile               *file,
-                                                    GCancellable        *cancellable,
-                                                    GAsyncReadyCallback  callback,
-                                                    gpointer             user_data)
+tracker_miner_manager_index_location_async (TrackerMinerManager        *manager,
+                                            GFile                      *location,
+                                            TrackerIndexLocationFlags   flags,
+                                            GCancellable               *cancellable,
+                                            GAsyncReadyCallback         callback,
+                                            gpointer                    user_data)
 {
-       GTask *task;
-
-       g_return_if_fail (TRACKER_IS_MINER_MANAGER (manager));
-       g_return_if_fail (G_IS_FILE (file));
-       g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+       IndexLocationTaskData *data;
+       g_autoptr (GTask) task;
 
+       data = index_location_task_data_new (location, flags);
        task = g_task_new (manager, cancellable, callback, user_data);
-       g_task_set_task_data (task, g_object_ref (file), (GDestroyNotify) g_object_unref);
-       g_task_run_in_thread (task, miner_manager_index_file_for_process_thread);
-       g_object_unref (task);
+       g_task_set_task_data (task, data, (GDestroyNotify) index_location_task_data_free);
+       g_task_run_in_thread (task, miner_manager_index_location_thread);
 }
 
 /**
- * tracker_miner_manager_index_file_for_process_finish:
+ * tracker_miner_manager_index_location_finish:
  * @manager: a #TrackerMinerManager
  * @result: a #GAsyncResult
  * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
  *
- * Finishes a request to index a file. See tracker_miner_manager_index_file_for_process_async()
+ * Finishes a request to index a file. See tracker_miner_manager_index_location_async()
  *
  * On failure @error will be set.
  *
  * Returns: %TRUE on success, otherwise %FALSE.
  *
- * Since: 1.10
+ * Since: 0.16
  **/
 gboolean
-tracker_miner_manager_index_file_for_process_finish (TrackerMinerManager  *manager,
-                                                     GAsyncResult         *result,
-                                                     GError              **error)
+tracker_miner_manager_index_location_finish (TrackerMinerManager *manager,
+                                             GAsyncResult        *result,
+                                             GError             **error)
 {
-       g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
-       g_return_val_if_fail (g_task_is_valid (result, manager), FALSE);;
-       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
        return g_task_propagate_boolean (G_TASK (result), error);
 }
diff --git a/src/tracker/tracker-miner-manager.h b/src/tracker/tracker-miner-manager.h
index de77b48e0..8167d01ce 100644
--- a/src/tracker/tracker-miner-manager.h
+++ b/src/tracker/tracker-miner-manager.h
@@ -26,6 +26,8 @@
 
 #include <gio/gio.h>
 
+#include <libtracker-miners-common/tracker-miners-enum-types.h>
+
 G_BEGIN_DECLS
 
 #define TRACKER_TYPE_MINER_MANAGER         (tracker_miner_manager_get_type())
@@ -128,30 +130,20 @@ const gchar *        tracker_miner_manager_get_display_name   (TrackerMinerManag
 const gchar *        tracker_miner_manager_get_description    (TrackerMinerManager  *manager,
                                                                const gchar          *miner);
 
-gboolean             tracker_miner_manager_index_file          (TrackerMinerManager  *manager,
-                                                                GFile                *file,
-                                                                GCancellable         *cancellable,
-                                                                GError              **error);
-void                 tracker_miner_manager_index_file_async    (TrackerMinerManager  *manager,
-                                                                GFile                *file,
-                                                                GCancellable         *cancellable,
-                                                                GAsyncReadyCallback   callback,
-                                                                gpointer              user_data);
-gboolean             tracker_miner_manager_index_file_finish   (TrackerMinerManager  *manager,
-                                                                GAsyncResult         *result,
-                                                                GError              **error);
-gboolean             tracker_miner_manager_index_file_for_process        (TrackerMinerManager  *manager,
-                                                                          GFile                *file,
-                                                                          GCancellable         *cancellable,
-                                                                          GError              **error);
-void                 tracker_miner_manager_index_file_for_process_async  (TrackerMinerManager  *manager,
-                                                                          GFile                *file,
-                                                                          GCancellable         *cancellable,
-                                                                          GAsyncReadyCallback   callback,
-                                                                          gpointer              user_data);
-gboolean             tracker_miner_manager_index_file_for_process_finish (TrackerMinerManager  *manager,
-                                                                          GAsyncResult         *result,
-                                                                          GError              **error);
+gboolean tracker_miner_manager_index_location        (TrackerMinerManager       *manager,
+                                                      GFile                     *location,
+                                                      TrackerIndexLocationFlags  flags,
+                                                      GCancellable               *cancellable,
+                                                      GError                    **error);
+void     tracker_miner_manager_index_location_async  (TrackerMinerManager       *manager,
+                                                      GFile                     *location,
+                                                      TrackerIndexLocationFlags  flags,
+                                                      GCancellable              *cancellable,
+                                                      GAsyncReadyCallback        callback,
+                                                      gpointer                   user_data);
+gboolean tracker_miner_manager_index_location_finish (TrackerMinerManager       *manager,
+                                                      GAsyncResult              *result,
+                                                      GError                   **error);
 
 G_END_DECLS
 
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 8329a69ad..e4056f73a 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -117,7 +117,7 @@ delete_info_recursively (GFile *file)
 
        /* Request reindexing of this data, it was previously in the store. */
        miner_manager = tracker_miner_manager_new_full (FALSE, NULL);
-       tracker_miner_manager_index_file (miner_manager, file, NULL, &error);
+       tracker_miner_manager_index_location (miner_manager, file, TRACKER_INDEX_LOCATION_FLAGS_NONE, NULL, 
&error);
        g_object_unref (miner_manager);
 
        if (error)
diff --git a/tests/functional-tests/extractor-decorator.py b/tests/functional-tests/extractor-decorator.py
index 41c8eec17..e44b6ad9c 100755
--- a/tests/functional-tests/extractor-decorator.py
+++ b/tests/functional-tests/extractor-decorator.py
@@ -66,7 +66,7 @@ class ExtractorDecoratorTest(fixtures.TrackerMinerTest):
             # deleted, so we should see the nie:title property change.
             with self.tracker.await_insert(fixtures.AUDIO_GRAPH, f'nie:title "{VALID_FILE_TITLE}"',
                                            timeout=cfg.AWAIT_TIMEOUT):
-                miner_fs.index_file(file_uri)
+                miner_fs.index_location(file_uri, [])
 
             title_result = store.query('SELECT ?title { <%s> nie:interpretedAs/nie:title ?title }' % 
file_uri)
             assert len(title_result) == 1
diff --git a/tests/functional-tests/miner-basic.py b/tests/functional-tests/miner-basic.py
index 33f7afbd3..dfbb55322 100755
--- a/tests/functional-tests/miner-basic.py
+++ b/tests/functional-tests/miner-basic.py
@@ -368,7 +368,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
             # indirectly by the new file)
             with open(document, 'w') as f:
                 f.write(DEFAULT_TEXT)
-            self.miner_fs.index_file(directory_uri)
+            self.miner_fs.index_location(directory_uri, [])
 
         new_urn = self.__get_file_urn(directory)
         # Ensure that children remain consistent, old and new ones
diff --git a/tests/functional-tests/minerhelper.py b/tests/functional-tests/minerhelper.py
index 0df14a3d6..a0e13e91f 100644
--- a/tests/functional-tests/minerhelper.py
+++ b/tests/functional-tests/minerhelper.py
@@ -138,5 +138,5 @@ class MinerFsHelper ():
             self._target_wakeup_count = None
             GLib.source_remove(timeout_id)
 
-    def index_file(self, uri):
-        return self.index.IndexFile('(s)', uri)
+    def index_location(self, uri, flags=None):
+        return self.index.IndexLocation('(sas)', uri, flags or [])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]