[nautilus/sam/tracker-3] Bundle Tracker Miners inside Flatpak
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/sam/tracker-3] Bundle Tracker Miners inside Flatpak
- Date: Sat, 1 Aug 2020 15:27:04 +0000 (UTC)
commit 523fe20471926adaa3a144dcd16e62041a6dc8c0
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Aug 1 17:25:27 2020 +0200
Bundle Tracker Miners inside Flatpak
This means the Nautilus flatpak will be able to use Tracker to index the
filesystem on systems which don't have Tracker 3 available on the host.
build-aux/flatpak/org.gnome.Nautilus.json | 6 +-
build-aux/flatpak/org.gnome.Nautilus.yml | 8 +-
build-aux/flatpak/org.gnome.NautilusMaster.yml | 9 +-
data/meson.build | 1 +
meson.build | 2 +-
src/nautilus-batch-rename-utilities.c | 5 +-
src/nautilus-search-engine-tracker.c | 6 +-
src/nautilus-tag-manager.c | 68 +++++++-------
src/nautilus-tracker-utilities.c | 117 +++++++++++++++++++++++++
src/nautilus-tracker-utilities.h | 6 +-
10 files changed, 179 insertions(+), 49 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Nautilus.json b/build-aux/flatpak/org.gnome.Nautilus.json
index ea2aa553a..773c1dd8e 100644
--- a/build-aux/flatpak/org.gnome.Nautilus.json
+++ b/build-aux/flatpak/org.gnome.Nautilus.json
@@ -14,8 +14,6 @@
"--socket=x11",
"--socket=wayland",
"--talk-name=org.gnome.OnlineAccounts",
- "--talk-name=org.freedesktop.Tracker3.Miner.Files",
- "--talk-name=org.freedesktop.Tracker3.Miner.Extract",
"--filesystem=host",
"--talk-name=org.gtk.vfs",
"--talk-name=org.gtk.vfs.*",
@@ -24,7 +22,9 @@
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf",
- "--env=TRACKER_SPARQL_BACKEND=bus"
+ "--add-policy=Tracker3.dbus:org.freedesktop.Tracker3.Miner.Files=tracker:FileSystem;tracker:Documents",
+ "--own-name=org.gnome.Nautilus.Tracker3.Miner.Files",
+ "--own-name=org.gnome.Nautilus.Tracker3.Miner.Extract"
],
"modules": [
{
diff --git a/build-aux/flatpak/org.gnome.Nautilus.yml b/build-aux/flatpak/org.gnome.Nautilus.yml
index 93a098db0..dba69dc75 100644
--- a/build-aux/flatpak/org.gnome.Nautilus.yml
+++ b/build-aux/flatpak/org.gnome.Nautilus.yml
@@ -13,8 +13,6 @@ finish-args:
- "--socket=x11"
- "--socket=wayland"
- "--talk-name=org.gnome.OnlineAccounts"
-- "--talk-name=org.freedesktop.Tracker3.Miner.Files"
-- "--talk-name=org.freedesktop.Tracker3.Miner.Extract"
- "--filesystem=host"
- "--talk-name=org.gtk.vfs"
- "--talk-name=org.gtk.vfs.*"
@@ -23,7 +21,11 @@ finish-args:
- "--filesystem=~/.config/dconf:ro"
- "--talk-name=ca.desrt.dconf"
- "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
-- "--env=TRACKER_SPARQL_BACKEND=bus"
+# Access to host Tracker Miners
+- "--add-policy=Tracker3.dbus:org.freedesktop.Tracker3.Miner.Files=tracker:FileSystem;tracker:Documents"
+# Internal Tracker Miners, for when host doesn't have a suitable filesystem indexer
+- "--own-name=org.gnome.Nautilus.Tracker3.Miner.Files"
+- "--own-name=org.gnome.Nautilus.Tracker3.Miner.Extract"
modules:
- name: exiv2
config-opts:
diff --git a/build-aux/flatpak/org.gnome.NautilusMaster.yml b/build-aux/flatpak/org.gnome.NautilusMaster.yml
index 8215d3dec..7dd5cec19 100644
--- a/build-aux/flatpak/org.gnome.NautilusMaster.yml
+++ b/build-aux/flatpak/org.gnome.NautilusMaster.yml
@@ -13,8 +13,6 @@ finish-args:
- "--socket=x11"
- "--socket=wayland"
- "--talk-name=org.gnome.OnlineAccounts"
-- "--talk-name=org.freedesktop.Tracker3.Miner.Files"
-- "--talk-name=org.freedesktop.Tracker3.Miner.Extract"
- "--filesystem=host"
- "--talk-name=org.gtk.vfs"
- "--talk-name=org.gtk.vfs.*"
@@ -23,7 +21,11 @@ finish-args:
- "--filesystem=~/.config/dconf:ro"
- "--talk-name=ca.desrt.dconf"
- "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
-- "--env=TRACKER_SPARQL_BACKEND=bus"
+# Access to host Tracker Miners
+- "--add-policy=Tracker3.dbus:org.freedesktop.Tracker3.Miner.Files=tracker:FileSystem;tracker:Documents"
+# Internal Tracker Miners, for when host doesn't have a suitable filesystem indexer
+- "--own-name=org.gnome.Nautilus.Tracker3.Miner.Files"
+- "--own-name=org.gnome.Nautilus.Tracker3.Miner.Extract"
modules:
- name: exiv2
config-opts:
@@ -85,4 +87,5 @@ modules:
sources:
- type: git
url: https://gitlab.gnome.org/GNOME/nautilus.git
+ branch: sam/tracker-3
diff --git a/data/meson.build b/data/meson.build
index e51ed50b1..9a4e2ff52 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -139,3 +139,4 @@ if appstream_util.found()
endif
subdir('ontology')
+subdir('tracker')
diff --git a/meson.build b/meson.build
index def669735..73f571073 100644
--- a/meson.build
+++ b/meson.build
@@ -6,7 +6,7 @@ project('nautilus', 'c',
# * Update GTK-based codes over src/gtk/gtk-code-generator.sh
version: '3.37.3',
- meson_version: '>= 0.47.0',
+ meson_version: '>= 0.49.0',
license: 'GPL3+'
)
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index b31506f5f..2746cb083 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -19,6 +19,7 @@
#include "nautilus-batch-rename-dialog.h"
#include "nautilus-batch-rename-utilities.h"
#include "nautilus-file.h"
+#include "nautilus-tracker-utilities.h"
#include <glib.h>
#include <gtk/gtk.h>
@@ -63,8 +64,6 @@ enum
ALBUM_NAME_INDEX,
} QueryMetadata;
-#define TRACKER_MINER_FS_BUSNAME "org.freedesktop.Tracker3.Miner.Files"
-
static void on_cursor_callback (GObject *object,
GAsyncResult *result,
gpointer user_data);
@@ -1119,7 +1118,7 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
g_string_append (query, "} ORDER BY ASC(nie:contentCreated(?file))");
- connection = tracker_sparql_connection_bus_new (TRACKER_MINER_FS_BUSNAME, NULL, NULL, &error);
+ connection = nautilus_tracker_get_miner_fs_connection (&error);
if (!connection)
{
if (error)
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 6e5d2a2cc..70a323991 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -25,6 +25,7 @@
#include "nautilus-search-engine-private.h"
#include "nautilus-search-hit.h"
#include "nautilus-search-provider.h"
+#include "nautilus-tracker-utilities.h"
#define DEBUG_FLAG NAUTILUS_DEBUG_SEARCH
#include "nautilus-debug.h"
@@ -55,8 +56,6 @@ enum
LAST_PROP
};
-#define TRACKER_MINER_FS_BUSNAME "org.freedesktop.Tracker3.Miner.Files"
-
static void nautilus_search_provider_init (NautilusSearchProviderInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngineTracker,
@@ -567,8 +566,7 @@ nautilus_search_engine_tracker_init (NautilusSearchEngineTracker *engine)
engine->hits_pending = g_queue_new ();
- engine->connection = tracker_sparql_connection_bus_new (TRACKER_MINER_FS_BUSNAME, NULL, NULL, &error);
-
+ engine->connection = nautilus_tracker_get_miner_fs_connection (&error);
if (error)
{
g_warning ("Could not establish a connection to Tracker: %s", error->message);
diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c
index d2385dc8c..17f877f8f 100644
--- a/src/nautilus-tag-manager.c
+++ b/src/nautilus-tag-manager.c
@@ -21,6 +21,7 @@
#include "nautilus-file.h"
#include "nautilus-file-undo-operations.h"
#include "nautilus-file-undo-manager.h"
+#include "nautilus-tracker-utilities.h"
#define DEBUG_FLAG NAUTILUS_DEBUG_TAG_MANAGER
#include "nautilus-debug.h"
@@ -35,6 +36,7 @@ struct _NautilusTagManager
gboolean tracker_ok;
TrackerSparqlConnection *local;
TrackerSparqlConnection *miner_fs;
+ const gchar *miner_fs_busname;
TrackerNotifier *notifier;
TrackerSparqlStatement *query_starred_files;
@@ -81,14 +83,12 @@ enum
LAST_SIGNAL
};
-#define TRACKER_MINER_FS_BUSNAME "org.freedesktop.Tracker3.Miner.Files"
-
#define QUERY_STARRED_FILES \
"SELECT ?file_url ?content_id " \
"{ " \
" ?content_urn a nautilus:FileReference ; " \
" nautilus:starred true . " \
- " SERVICE <dbus:" TRACKER_MINER_FS_BUSNAME "> { " \
+ " SERVICE <dbus:%s> { " \
" ?content_urn nie:isStoredAs ?file_url . " \
" BIND (tracker:id (?content_urn) AS ?content_id) " \
" } " \
@@ -97,7 +97,7 @@ enum
#define QUERY_UPDATED_FILE_URL \
"SELECT ?file_url EXISTS { ?content_urn nautilus:starred true } AS ?starred" \
"{ " \
- " SERVICE <dbus:" TRACKER_MINER_FS_BUSNAME "> { " \
+ " SERVICE <dbus:%s> { " \
" ?content_urn nie:isStoredAs ?file_url . " \
" FILTER (tracker:id(?content_urn) = ~id) " \
" }" \
@@ -433,14 +433,15 @@ nautilus_tag_manager_delete_tag (NautilusTagManager *self,
GList *selection,
GString *query)
{
- g_string_append (query,
- "DELETE { "
- " ?content_urn a nautilus:FileReference ; "
- " nautilus:starred true . "
- "} "
- "WHERE { "
- " SERVICE <dbus:" TRACKER_MINER_FS_BUSNAME "> { "
- " ?content_urn nie:isStoredAs ?file_url . ");
+ g_string_append_printf (query,
+ "DELETE { "
+ " ?content_urn a nautilus:FileReference ; "
+ " nautilus:starred true . "
+ "} "
+ "WHERE { "
+ " SERVICE <dbus:%s> { "
+ " ?content_urn nie:isStoredAs ?file_url . ",
+ self->miner_fs_busname);
query = add_selection_filter (selection, query);
@@ -454,13 +455,14 @@ nautilus_tag_manager_insert_tag (NautilusTagManager *self,
GList *selection,
GString *query)
{
- g_string_append (query,
- "INSERT { "
- " ?content_urn a nautilus:FileReference . "
- " ?content_urn nautilus:starred true . "
- "} WHERE { "
- " SERVICE <dbus:" TRACKER_MINER_FS_BUSNAME "> { "
- " ?content_urn nie:isStoredAs ?file_url . ");
+ g_string_append_printf (query,
+ "INSERT { "
+ " ?content_urn a nautilus:FileReference . "
+ " ?content_urn nautilus:starred true . "
+ "} WHERE { "
+ " SERVICE <dbus:%s> { "
+ " ?content_urn nie:isStoredAs ?file_url . ",
+ self->miner_fs_busname);
query = add_selection_filter (selection, query);
@@ -571,11 +573,13 @@ nautilus_tag_manager_get_file_ids_for_urls (NautilusTagManager *self,
{
GString *query;
- query = g_string_new ("SELECT ?file_url ?content_id "
- "WHERE { "
- " SERVICE <dbus:" TRACKER_MINER_FS_BUSNAME "> { "
- " ?content_urn nie:isStoredAs ?file_url . "
- " BIND (tracker:id (?content_urn) AS ?content_id) ");
+ query = g_string_new ("");
+ g_string_append_printf (query, "SELECT ?file_url ?content_id "
+ "WHERE { "
+ " SERVICE <dbus:%s> { "
+ " ?content_urn nie:isStoredAs ?file_url . "
+ " BIND (tracker:id (?content_urn) AS ?content_id) ",
+ self->miner_fs_busname);
query = add_selection_filter (selection, query);
@@ -891,6 +895,7 @@ setup_tracker_connections (NautilusTagManager *self,
GError **error)
{
const gchar *datadir;
+ gchar *query_with_busname;
g_autofree gchar *store_path = NULL;
g_autofree gchar *ontology_path = NULL;
g_autoptr (GFile) store = NULL;
@@ -925,31 +930,32 @@ setup_tracker_connections (NautilusTagManager *self,
}
/* Connect to Tracker filesystem index to follow file renames. */
- self->miner_fs = tracker_sparql_connection_bus_new (TRACKER_MINER_FS_BUSNAME,
- NULL,
- NULL,
- error);
-
+ self->miner_fs = nautilus_tracker_get_miner_fs_connection (error);
if (*error)
{
return FALSE;
}
+ self->miner_fs_busname = nautilus_tracker_get_miner_fs_busname (NULL);
/* Prepare reusable queries. */
+ query_with_busname = g_strdup_printf (QUERY_UPDATED_FILE_URL, self->miner_fs_busname);
self->query_updated_file_url = tracker_sparql_connection_query_statement (self->local,
- QUERY_UPDATED_FILE_URL,
+ query_with_busname,
cancellable,
error);
+ g_free (query_with_busname);
if (*error)
{
return FALSE;
}
+ query_with_busname = g_strdup_printf (QUERY_STARRED_FILES, self->miner_fs_busname);
self->query_starred_files = tracker_sparql_connection_query_statement (self->local,
- QUERY_STARRED_FILES,
+ query_with_busname,
cancellable,
error);
+ g_free (query_with_busname);
if (*error)
{
diff --git a/src/nautilus-tracker-utilities.c b/src/nautilus-tracker-utilities.c
index b220df4bd..cb6feeef2 100644
--- a/src/nautilus-tracker-utilities.c
+++ b/src/nautilus-tracker-utilities.c
@@ -18,12 +18,129 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
+#include "config.h"
#include "nautilus-tracker-utilities.h"
#include "nautilus-global-preferences.h"
#define TRACKER_KEY_RECURSIVE_DIRECTORIES "index-recursive-directories"
#define TRACKER_KEY_SINGLE_DIRECTORIES "index-single-directories"
+/* Shared global connection to Tracker Miner FS */
+static const gchar *tracker_miner_fs_busname = NULL;
+static TrackerSparqlConnection *tracker_miner_fs_connection = NULL;
+static GError *tracker_miner_fs_error = NULL;
+
+static gboolean
+get_host_tracker_miner_fs (GError **error)
+{
+ const gchar *busname = "org.freedesktop.Tracker3.Miner.Files";
+
+ g_message ("Connecting to %s", busname);
+ tracker_miner_fs_connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
+ if (*error)
+ {
+ g_warning ("Unable to create connection for session-wide Tracker indexer: %s", (*error)->message);
+ return FALSE;
+ }
+
+ tracker_miner_fs_busname = busname;
+ return TRUE;
+}
+
+static gboolean
+start_local_tracker_miner_fs (GError **error)
+{
+ const gchar *busname = APPLICATION_ID ".Tracker3.Miner.Files";
+
+ g_message ("Starting %s", busname);
+ tracker_miner_fs_connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
+ if (*error)
+ {
+ g_critical ("Could not start local Tracker indexer at %s: %s", busname, (*error)->message);
+ return FALSE;
+ }
+
+ tracker_miner_fs_busname = busname;
+ return TRUE;
+}
+
+static gboolean
+inside_flatpak (void)
+{
+ return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
+}
+
+static void
+setup_tracker_miner_fs_connection (void)
+{
+ static gsize tried_tracker_init = FALSE;
+
+ if (g_once_init_enter (&tried_tracker_init))
+ {
+ gboolean success;
+
+ success = get_host_tracker_miner_fs (&tracker_miner_fs_error);
+
+ if (!success && inside_flatpak ())
+ {
+ g_clear_error (&tracker_miner_fs_error);
+ success = start_local_tracker_miner_fs (&tracker_miner_fs_error);
+ }
+
+ g_once_init_leave (&tried_tracker_init, TRUE);
+ }
+}
+
+/**
+ * nautilus_tracker_get_miner_fs_connection:
+ * @error: return location for a #GError
+ *
+ * This function returns a global singleton #TrackerSparqlConnection, or %NULL
+ * if we couldn't connect to Tracker Miner FS.
+ *
+ * The first time you call it, this function will block while trying to connect.
+ * This may take some time if starting Tracker Miners from a Flatpak bundle.
+ *
+ * Returns: a #TrackerSparqlConnection, or %NULL
+ */
+TrackerSparqlConnection *
+nautilus_tracker_get_miner_fs_connection (GError **error)
+{
+ setup_tracker_miner_fs_connection ();
+
+ if (tracker_miner_fs_error && error)
+ {
+ *error = g_error_copy (tracker_miner_fs_error);
+ }
+
+ return tracker_miner_fs_connection;
+}
+
+/**
+ * nautilus_tracker_get_miner_fs_busname:
+ * @error: return location for a #GError
+ *
+ * This function returns a DBus name that can be used to talk to
+ * tracker-miner-fs, or %NULL if there is no Tracker Miner FS available.
+ *
+ * The first time you call it, this function will block while trying to connect.
+ * This may take some time if starting Tracker Miners from a Flatpak bundle.
+ *
+ * Returns: a string
+ */
+const gchar *
+nautilus_tracker_get_miner_fs_busname (GError **error)
+{
+ setup_tracker_miner_fs_connection ();
+
+ if (tracker_miner_fs_error && error)
+ {
+ *error = g_error_copy (tracker_miner_fs_error);
+ }
+
+ return tracker_miner_fs_busname;
+}
+
static GFile *
location_from_tracker_dir (const gchar *value)
{
diff --git a/src/nautilus-tracker-utilities.h b/src/nautilus-tracker-utilities.h
index f509c3005..d4b2eba0c 100644
--- a/src/nautilus-tracker-utilities.h
+++ b/src/nautilus-tracker-utilities.h
@@ -22,5 +22,9 @@
#pragma once
#include <gio/gio.h>
+#include <libtracker-sparql/tracker-sparql.h>
-gboolean nautilus_tracker_directory_is_tracked (GFile *directory);
+TrackerSparqlConnection * nautilus_tracker_get_miner_fs_connection (GError **error);
+const gchar * nautilus_tracker_get_miner_fs_busname (GError **error);
+
+gboolean nautilus_tracker_directory_is_tracked (GFile *directory);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]