[gnome-photos/sam/tracker2-domain] Switch to private instances of the Tracker 2.x daemons




commit fb31e2a8686a05b879ac2b3259acbfb8de230663
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue Sep 1 13:48:20 2020 +0200

    Switch to private instances of the Tracker 2.x daemons
    
    GNOME 3.38 is switching to Tracker 3.x by default [1]. However, Photos
    is not ready to switch this cycle.
    
    It's desirable to avoid having two sets of Tracker daemons indexing
    the same content as much as possible. One option is to start private
    instances of the Tracker 2.x daemons tied to the lifetime of the GNOME
    Photos application. Distributions can disable Tracker 2.x by default,
    and it will only be activated when needed by Photos.
    
    This also allows the Photos Flatpak to run Tracker 2.x daemons inside
    the sandbox, ensuring it works on systems which don't have Tracker 2.x
    available.
    
    Based on code written by Yi-Soo An.
    
    [1] https://gitlab.gnome.org/GNOME/Initiatives/-/issues/17
    
    https://gitlab.gnome.org/GNOME/gnome-photos/-/merge_requests/146

 data/meson.build                                   | 29 ++++++++++
 ....gnome.Photos.Tracker1.Miner.Extract.service.in |  8 +++
 ...rg.gnome.Photos.Tracker1.Miner.Files.service.in |  8 +++
 data/org.gnome.Photos.Tracker1.service.in          |  3 ++
 data/org.gnome.Photos.rule.in                      | 39 ++++++++++++++
 flatpak/org.gnome.Photos.json                      |  9 +---
 meson.build                                        |  1 +
 meson_post_install.py                              | 14 +++++
 src/photos-application.c                           | 62 ++++++++++++++--------
 src/photos-indexing-notification.c                 |  4 +-
 src/photos-tracker-change-monitor.c                |  2 +-
 src/photos-tracker-import-controller.c             |  2 +-
 src/photos-tracker-queue.c                         |  2 +
 13 files changed, 150 insertions(+), 33 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 534ef3e0..f51a4511 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -45,6 +45,35 @@ configure_file(
   install_dir: dbus_services_dir,
 )
 
+tracker_domain_conf = configuration_data()
+tracker_domain_conf.set('libexecdir', photos_libexecdir)
+
+domain_ontology_rule = photos_namespace + '.rule'
+
+configure_file(
+  input: domain_ontology_rule + '.in',
+  output: domain_ontology_rule,
+  configuration: tracker_domain_conf,
+  install: true,
+  install_dir: join_paths(photos_datadir, 'tracker', 'domain-ontologies'),
+)
+
+tracker_domain_services = [
+  'Tracker1',
+  'Tracker1.Miner.Extract',
+  'Tracker1.Miner.Files'
+]
+
+foreach service: tracker_domain_services
+  configure_file(
+    input: '@0@.@1  service in'.format(photos_namespace, service),
+    output: '@0@.@1@.service'.format(photos_namespace, service),
+    configuration: tracker_domain_conf,
+    install: true,
+    install_dir: dbus_services_dir,
+  )
+endforeach
+
 install_data(
   photos_namespace + '.search-provider.ini',
   install_dir: join_paths(photos_datadir, 'gnome-shell', 'search-providers'),
diff --git a/data/org.gnome.Photos.Tracker1.Miner.Extract.service.in 
b/data/org.gnome.Photos.Tracker1.Miner.Extract.service.in
new file mode 100644
index 00000000..4f2272e5
--- /dev/null
+++ b/data/org.gnome.Photos.Tracker1.Miner.Extract.service.in
@@ -0,0 +1,8 @@
+[D-BUS Service]
+Name=org.gnome.Photos.Tracker1.Miner.Extract
+Exec=@libexecdir@/tracker-extract --domain-ontology org.gnome.Photos
+
+# Miner details needed for tracker-control
+Path=/org/freedesktop/Tracker1/Miner/Extract
+NameSuffix=Miner.Extract
+DisplayName=Extractor
diff --git a/data/org.gnome.Photos.Tracker1.Miner.Files.service.in 
b/data/org.gnome.Photos.Tracker1.Miner.Files.service.in
new file mode 100644
index 00000000..3bf53ec8
--- /dev/null
+++ b/data/org.gnome.Photos.Tracker1.Miner.Files.service.in
@@ -0,0 +1,8 @@
+[D-BUS Service]
+Name=org.gnome.Photos.Tracker1.Miner.Files
+Exec=@libexecdir@/tracker-miner-fs --initial-sleep=0 --domain-ontology org.gnome.Photos
+
+# Miner details needed for tracker-control
+Path=/org/freedesktop/Tracker1/Miner/Files
+NameSuffix=Miner.Files
+DisplayName=File System
diff --git a/data/org.gnome.Photos.Tracker1.service.in b/data/org.gnome.Photos.Tracker1.service.in
new file mode 100644
index 00000000..7966e630
--- /dev/null
+++ b/data/org.gnome.Photos.Tracker1.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Photos.Tracker1
+Exec=@libexecdir@/tracker-store --domain-ontology org.gnome.Photos
diff --git a/data/org.gnome.Photos.rule.in b/data/org.gnome.Photos.rule.in
new file mode 100644
index 00000000..3d9c2bb3
--- /dev/null
+++ b/data/org.gnome.Photos.rule.in
@@ -0,0 +1,39 @@
+[DomainOntology]
+# All locations accept
+# 1) Paths relative from a variable, the variables
+#    may be: HOME, XDG_CACHE_HOME, XDG_DATA_HOME, XDG_RUNTIME_DIR,
+#    XDG_DESKTOP_DIR, XDG_DOCUMENTS_DIR, XDG_DOWNLOAD_DIR,
+#    XDG_MUSIC_DIR, XDG_PICTURES_DIR, XDG_PUBLICSHARE_DIR,
+#    XDG_VIDEOS_DIR.
+#
+#    eg. $XDG_CACHE_HOME/...
+#
+# 2) URIs
+#
+#    eg. file:///var/...
+#
+
+# Location for the Tracker database (not optional)
+CacheLocation=$XDG_CACHE_HOME/tracker
+
+# Location for the data journal, used in data recovery
+# situations (optional)
+JournalLocation=$XDG_DATA_HOME/tracker/data
+
+# Name of the ontology to use, must be one located in
+# $(sharedir)/tracker/ontologies
+OntologyName=nepomuk
+
+# DBus name for the owner (not optional). Tracker will use
+# the domain as the prefix of the DBus name for all the
+# services related to this domain ontology.
+#
+# eg. org.gnome.Photos
+Domain=org.gnome.Photos
+
+# Miners that the domain ontology will require. This is
+# purely a hint (mainly for libtracker-control), and not
+# any sort of white list. Anything else knowing about this
+# domain ontology may still perform updates, miners and
+# non-miners.
+Miners=Miner.Files;Miner.Extract
diff --git a/flatpak/org.gnome.Photos.json b/flatpak/org.gnome.Photos.json
index 633e4b0a..4d3ac2a8 100644
--- a/flatpak/org.gnome.Photos.json
+++ b/flatpak/org.gnome.Photos.json
@@ -251,7 +251,7 @@
         {
             "name": "tracker",
             "buildsystem": "meson",
-            "cleanup": [ "/bin", "/etc", "/lib/girepository-1.0", "/libexec", "/share/dbus-1", 
"/share/gir-1.0" ],
+            "cleanup": [ "/bin", "/etc", "/lib/girepository-1.0", "/share/dbus-1", "/share/gir-1.0" ],
             "config-opts": [ "-Dbash_completion=no", "-Ddocs=false", "-Dsystemd_user_services=no" ],
             "sources": [
                 {
@@ -276,18 +276,13 @@
             "name": "tracker-miners",
             "buildsystem": "meson",
             "cleanup": [ "/etc",
-                         "/lib",
-                         "/libexec",
                          "/share/dbus-1/services/org.freedesktop.Tracker1.Miner.Extract.service",
                          "/share/dbus-1/services/org.freedesktop.Tracker1.Writeback.service",
                          "/share/tracker/miners/org.freedesktop.Tracker1.Miner.Applications.service",
                          "/share/tracker/miners/org.freedesktop.Tracker1.Miner.Extract.service",
                          "/share/tracker/miners/org.freedesktop.Tracker1.Miner.RSS.service",
-                         "/share/tracker-miners",
-                         "/share/glib-2.0/schemas/org.freedesktop.Tracker.Extract.gschema.xml",
                          "/share/glib-2.0/schemas/org.freedesktop.Tracker.Writeback.gschema.xml" ],
-            "config-opts": [ "-Dextract=false",
-                             "-Dgeneric_media_extractor=none",
+            "config-opts": [ "-Dextract=true",
                              "-Dminer_fs=true",
                              "-Dminer_rss=false",
                              "-Dsystemd_user_services=no",
diff --git a/meson.build b/meson.build
index 66f77e0b..0d0ed1a2 100644
--- a/meson.build
+++ b/meson.build
@@ -211,4 +211,5 @@ run_target(script_name, command: [find_program(script_name + '.sh'), source_root
 meson.add_install_script(
   'meson_post_install.py',
   photos_datadir,
+  dbus_services_dir,
 )
diff --git a/meson_post_install.py b/meson_post_install.py
index 15a1bc17..298a390e 100644
--- a/meson_post_install.py
+++ b/meson_post_install.py
@@ -28,3 +28,17 @@ if not destdir:
     schemadir = os.path.join(datadir, 'glib-2.0', 'schemas')
     print('Compiling gsettings schemas...')
     subprocess.call(['glib-compile-schemas', schemadir])
+
+dbusservicesdir = sys.argv[2]
+trackerdir = os.path.join(datadir, 'tracker', 'miners')
+
+miners = ["org.gnome.Photos.Tracker1.Miner.Extract.service", "org.gnome.Photos.Tracker1.Miner.Files.service"]
+
+os.makedirs(trackerdir, exist_ok=True)
+for miner in miners:
+    dst = os.path.join(trackerdir, miner)
+    src = os.path.join(dbusservicesdir, miner)
+    try:
+        os.symlink(src, dst)
+    except FileExistsError:
+        pass
diff --git a/src/photos-application.c b/src/photos-application.c
index 167beb19..f7b4b56e 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -127,6 +127,7 @@ struct _PhotosApplication
   PhotosSearchProvider *search_provider;
   PhotosSelectionController *sel_cntrlr;
   PhotosThumbnailFactory *factory;
+  TrackerMinerManager *miner_manager;
   TrackerExtractPriority *extract_priority;
   gboolean empty_results;
   gboolean main_window_deleted;
@@ -173,6 +174,7 @@ static const gchar *DESKTOP_KEY_PICTURE_OPTIONS = "picture-options";
 static const gchar *DESKTOP_KEY_COLOR_SHADING_TYPE = "color-shading-type";
 static const gchar *DESKTOP_KEY_PRIMARY_COLOR = "primary-color";
 static const gchar *DESKTOP_KEY_SECONDARY_COLOR = "secondary-color";
+static const gchar *MINER_FILES = "org.gnome.Photos.Tracker1.Miner.Files";
 
 typedef struct _PhotosApplicationCreateData PhotosApplicationCreateData;
 typedef struct _PhotosApplicationImportData PhotosApplicationImportData;
@@ -195,7 +197,6 @@ struct _PhotosApplicationImportData
   GFile *import_sub_dir;
   GList *files;
   PhotosBaseItem *collection;
-  TrackerMinerManager *manager;
   gchar *collection_urn;
   gint64 ctime_latest;
 };
@@ -248,7 +249,6 @@ photos_application_create_data_free (PhotosApplicationCreateData *data)
 
 static PhotosApplicationImportData *
 photos_application_import_data_new (PhotosApplication *application,
-                                    TrackerMinerManager *manager,
                                     GList *files,
                                     gint64 ctime_latest)
 {
@@ -257,7 +257,6 @@ photos_application_import_data_new (PhotosApplication *application,
   data = g_slice_new0 (PhotosApplicationImportData);
   g_application_hold (G_APPLICATION (application));
   data->application = application;
-  data->manager = g_object_ref (manager);
   data->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
   data->ctime_latest = ctime_latest;
   return data;
@@ -278,7 +277,6 @@ photos_application_import_data_free (PhotosApplicationImportData *data)
   g_clear_object (&data->destination);
   g_clear_object (&data->import_sub_dir);
   g_list_free_full (data->files, g_object_unref);
-  g_clear_object (&data->manager);
   g_free (data->collection_urn);
   g_slice_free (PhotosApplicationImportData, data);
 }
@@ -830,7 +828,7 @@ photos_application_create_window (PhotosApplication *self)
   g_application_hold (G_APPLICATION (self));
   tracker_extract_priority_proxy_new_for_bus (G_BUS_TYPE_SESSION,
                                               G_DBUS_PROXY_FLAGS_NONE,
-                                              "org.freedesktop.Tracker1.Miner.Extract",
+                                              "org.gnome.Photos.Tracker1.Miner.Extract",
                                               "/org/freedesktop/Tracker1/Extract/Priority",
                                               self->create_window_cancellable,
                                               photos_application_tracker_extract_priority,
@@ -1323,7 +1321,6 @@ photos_application_import_file_copy (GObject *source_object, GAsyncResult *res,
   PhotosApplication *self = data->application;
   g_autoptr (GFile) destination = NULL;
   GFile *source = G_FILE (source_object);
-  TrackerMinerManager *manager = data->manager;
 
   {
     g_autoptr (GError) error = NULL;
@@ -1364,7 +1361,7 @@ photos_application_import_file_copy (GObject *source_object, GAsyncResult *res,
 
       g_application_hold (G_APPLICATION (self));
       g_application_mark_busy (G_APPLICATION (self));
-      tracker_miner_manager_index_file_for_process_async (manager,
+      tracker_miner_manager_index_file_for_process_async (self->miner_manager,
                                                           destination,
                                                           NULL,
                                                           photos_application_import_index_file,
@@ -1519,7 +1516,6 @@ photos_application_import (PhotosApplication *self)
   GtkWidget *dialog;
   g_autoptr (PhotosApplicationImportData) data = NULL;
   PhotosSource *source;
-  TrackerMinerManager *manager = NULL; /* TODO: use g_autoptr */
   gint64 ctime_latest = -1;
 
   source = PHOTOS_SOURCE (photos_base_manager_get_active_object (self->state->src_mngr));
@@ -1533,17 +1529,11 @@ photos_application_import (PhotosApplication *self)
   selection = photos_selection_controller_get_selection (self->sel_cntrlr);
   g_return_if_fail (selection != NULL);
 
-  {
-    g_autoptr (GError) error = NULL;
-
-    manager = tracker_miner_manager_new_full (FALSE, &error);
-    if (error != NULL)
-      {
-        g_warning ("Unable to create a TrackerMinerManager, importing from attached devices won't work: %s",
-                   error->message);
-        goto out;
-      }
-  }
+  if (self->miner_manager == NULL)
+    {
+      g_warning ("No TrackerMinerManager, importing from attached devices won't work");
+      goto out;
+    }
 
   for (l = selection; l != NULL; l = l->next)
     {
@@ -1572,14 +1562,13 @@ photos_application_import (PhotosApplication *self)
   dialog = photos_import_dialog_new (GTK_WINDOW (self->main_window), ctime_latest);
   gtk_widget_show_all (dialog);
 
-  data = photos_application_import_data_new (self, manager, files, ctime_latest);
+  data = photos_application_import_data_new (self, files, ctime_latest);
   g_signal_connect (dialog,
                     "response",
                     G_CALLBACK (photos_application_import_response),
                     g_steal_pointer (&data));
 
  out:
-  g_clear_object (&manager);
   g_list_free_full (files, g_object_unref);
 }
 
@@ -2245,7 +2234,35 @@ photos_application_share_current (PhotosApplication *self)
 static void
 photos_application_start_miners (PhotosApplication *self)
 {
-  photos_application_create_online_miners (self);
+  {
+    g_autoptr (GError) error = NULL;
+
+    self->miner_manager = tracker_miner_manager_new_full (TRUE, &error);
+    if (error != NULL)
+      g_warning ("Unable to create a TrackerMinerManager: %s", error->message);
+  }
+
+  if (self->miner_manager != NULL)
+    {
+      GSList *available = NULL;
+      GSList *miner_files = NULL;
+
+      available = tracker_miner_manager_get_available (self->miner_manager);
+      miner_files = g_slist_find_custom (available, MINER_FILES, (GCompareFunc) strcmp);
+      if (miner_files == NULL)
+        {
+          g_warning ("Unable to find miner %s", MINER_FILES);
+        }
+      else
+        {
+          if (!tracker_miner_manager_is_active (self->miner_manager, MINER_FILES))
+            g_warning ("Unable to activate miner %s", MINER_FILES);
+        }
+
+      g_slist_free_full (available, g_free);
+    }
+
+ photos_application_create_online_miners (self);
 }
 
 
@@ -3003,6 +3020,7 @@ photos_application_dispose (GObject *object)
   g_clear_object (&self->sel_cntrlr);
   g_clear_object (&self->factory);
   g_clear_object (&self->extract_priority);
+  g_clear_object (&self->miner_manager);
 
   if (self->state != NULL)
     {
diff --git a/src/photos-indexing-notification.c b/src/photos-indexing-notification.c
index 7b2ea7dd..72394983 100644
--- a/src/photos-indexing-notification.c
+++ b/src/photos-indexing-notification.c
@@ -56,7 +56,7 @@ enum
   REMOTE_MINER_TIMEOUT = 10 /* s */
 };
 
-static const gchar *MINER_FILES = "org.freedesktop.Tracker1.Miner.Files";
+static const gchar *MINER_FILES = "org.gnome.Photos.Tracker1.Miner.Files";
 
 
 static void
@@ -242,7 +242,7 @@ photos_indexing_notification_init (PhotosIndexingNotification *self)
   {
     g_autoptr (GError) error = NULL;
 
-    self->manager = tracker_miner_manager_new_full (FALSE, &error);
+    self->manager = tracker_miner_manager_new_full (TRUE, &error);
     if (error != NULL)
       {
         g_warning ("Unable to create a TrackerMinerManager, indexing progress notification won't work: %s",
diff --git a/src/photos-tracker-change-monitor.c b/src/photos-tracker-change-monitor.c
index 2e9810aa..44c9ffe7 100644
--- a/src/photos-tracker-change-monitor.c
+++ b/src/photos-tracker-change-monitor.c
@@ -434,7 +434,7 @@ photos_tracker_change_monitor_initable_init (GInitable *initable, GCancellable *
 
   self->resource_service = tracker_resources_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                                      G_DBUS_PROXY_FLAGS_NONE,
-                                                                     "org.freedesktop.Tracker1",
+                                                                     "org.gnome.Photos.Tracker1",
                                                                      "/org/freedesktop/Tracker1/Resources",
                                                                      cancellable,
                                                                      error);
diff --git a/src/photos-tracker-import-controller.c b/src/photos-tracker-import-controller.c
index 085ace3a..9f130714 100644
--- a/src/photos-tracker-import-controller.c
+++ b/src/photos-tracker-import-controller.c
@@ -424,7 +424,7 @@ photos_tracker_import_controller_init (PhotosTrackerImportController *self)
   {
     g_autoptr (GError) error = NULL;
 
-    self->manager = tracker_miner_manager_new_full (FALSE, &error);
+    self->manager = tracker_miner_manager_new_full (TRUE, &error);
     if (error != NULL)
       g_warning ("Unable to create a TrackerMinerManager, indexing attached devices won't work: %s", 
error->message);
   }
diff --git a/src/photos-tracker-queue.c b/src/photos-tracker-queue.c
index 6ac829cd..76d25d5d 100644
--- a/src/photos-tracker-queue.c
+++ b/src/photos-tracker-queue.c
@@ -290,6 +290,8 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
 
   g_assert_no_error (self->initialization_error);
 
+  tracker_sparql_connection_set_domain ("org.gnome.Photos");
+
   self->connection = tracker_sparql_connection_get (cancellable, &self->initialization_error);
   if (G_UNLIKELY (self->initialization_error != NULL))
     goto out;


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