[gnome-photos/sam/tracker2-domain: 17/17] Start private Tracker 2.x daemons in all cases




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

    Start private Tracker 2.x daemons in all cases
    
    GNOME is switching to Tracker 3.x by default (see
    https://gitlab.gnome.org/GNOME/Initiatives/-/issues/17) however Photos
    is not ready to switch this cycle.
    
    We want to avoid having two Tracker daemons indexing the same content
    as much as possible. This commit means that Photos will start private
    instances of Tracker 2.x daemons, and the daemons will be tied to the
    lifetime of the Photos app. Distros can disable Tracker 2.x by default
    and it will only activate 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 a patch by Yi-Soo An <yisooan gmail com>.

 data/create-miner-symlinks.sh                      |  6 ++
 data/meson.build                                   | 33 +++++++++++
 ....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                      | 10 +---
 src/photos-application.c                           | 66 ++++++++++++++--------
 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 +
 12 files changed, 150 insertions(+), 33 deletions(-)
---
diff --git a/data/create-miner-symlinks.sh b/data/create-miner-symlinks.sh
new file mode 100755
index 00000000..6c81a969
--- /dev/null
+++ b/data/create-miner-symlinks.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+mkdir -p $MESON_INSTALL_DESTDIR_PREFIX/share/tracker/miners/
+for miner in org.gnome.Photos.Tracker1.Miner.Files org.gnome.Photos.Tracker1.Miner.Extract; do
+    ln -sf $MESON_INSTALL_PREFIX/share/dbus-1/services/$miner.service 
$MESON_INSTALL_DESTDIR_PREFIX/share/tracker/miners/
+done
diff --git a/data/meson.build b/data/meson.build
index 7898b0cc..ad7ef461 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -45,6 +45,37 @@ configure_file(
   install_dir: dbus_service_dir,
 )
 
+domain_ontologies_dir = join_paths(photos_datadir, 'tracker', 'domain-ontologies')
+dbus_services_dir = get_option('datadir') / 'dbus-1' / 'services'
+
+domain_conf = configuration_data()
+domain_conf.set('datadir', photos_datadir)
+domain_conf.set('prefix', get_option('prefix'))
+
+configure_file(
+  input: photos_namespace + '.rule.in',
+  output: photos_namespace + '.rule',
+  configuration: domain_conf,
+  install: true,
+  install_dir: domain_ontologies_dir,
+)
+
+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: 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'),
@@ -54,3 +85,5 @@ install_data(
   photos_namespace.to_lower() + '.gschema.xml',
   install_dir: join_paths(photos_datadir, 'glib-2.0', 'schemas'),
 )
+
+meson.add_install_script('create-miner-symlinks.sh')
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..085d9506
--- /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=@prefix@/libexec/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..5db708b3
--- /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=@prefix@/libexec/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..99d15783
--- /dev/null
+++ b/data/org.gnome.Photos.Tracker1.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Photos.Tracker1
+Exec=@prefix@/libexec/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 5d16689c..44557e6d 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,14 @@
             "name": "tracker-miners",
             "buildsystem": "meson",
             "cleanup": [ "/etc",
-                         "/lib",
-                         "/libexec",
+                         "/libexec/tracker-writeback",
                          "/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_apps=false",
                              "-Dminer_fs=true",
                              "-Dminer_rss=false",
diff --git a/src/photos-application.c b/src/photos-application.c
index cb114fda..faf6d04e 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;
@@ -195,7 +196,6 @@ struct _PhotosApplicationImportData
   GFile *import_sub_dir;
   GList *files;
   PhotosBaseItem *collection;
-  TrackerMinerManager *manager;
   gchar *collection_urn;
   gint64 ctime_latest;
 };
@@ -248,7 +248,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 +256,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 +276,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);
 }
@@ -693,7 +690,7 @@ photos_application_gom_miner (GObject *source_object, GAsyncResult *res, gpointe
 
 
 static void
-photos_application_create_miners (PhotosApplication *self)
+photos_application_create_online_miners (PhotosApplication *self)
 {
   GIOExtensionPoint *extension_point;
   GList *extensions;
@@ -800,6 +797,7 @@ photos_application_create_window (PhotosApplication *self)
   gboolean gegl_sanity_checked;
   gboolean gexiv2_initialized;
   gboolean gexiv2_registered_namespace;
+  g_autoptr (GError) error = NULL;
 
   if (self->main_window != NULL)
     return TRUE;
@@ -830,12 +828,18 @@ 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,
                                               self);
 
+  self->miner_manager = tracker_miner_manager_new_full (TRUE, &error);
+  if (error)
+    {
+      g_warning ("Unable to create Miner Manager: %s", error->message);
+    }
+
   photos_application_start_miners (self);
   return TRUE;
 }
@@ -1323,7 +1327,7 @@ 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;
+  TrackerMinerManager *manager = self->miner_manager;
 
   {
     g_autoptr (GError) error = NULL;
@@ -1519,7 +1523,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 +1536,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)
+    {
+      g_warning ("No TrackerMinerManager, importing from attached devices won't work");
+      goto out;
+    }
 
   for (l = selection; l != NULL; l = l->next)
     {
@@ -1572,14 +1569,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 +2241,32 @@ photos_application_share_current (PhotosApplication *self)
 static void
 photos_application_start_miners (PhotosApplication *self)
 {
-  photos_application_create_miners (self);
+  if (self->miner_manager)
+    {
+      GSList *available, *photos_miner_files;
+      const gchar *photos_miner_files_name = "org.gnome.Photos.Tracker1.Miner.Files";
+
+      /* This autostarts the miners */
+      available = tracker_miner_manager_get_running (self->miner_manager);
+
+      photos_miner_files = g_slist_find_custom (available, photos_miner_files_name, (GCompareFunc) strcmp);
+
+      if (photos_miner_files)
+        {
+          gboolean active;
+
+          active = tracker_miner_manager_is_active (self->miner_manager, photos_miner_files_name);
+
+          if (!active)
+            g_warning ("%s is inactive", photos_miner_files_name);
+        }
+      else
+        g_warning ("Miner %s was not found", photos_miner_files_name);
+
+      g_slist_free_full (available, g_free);
+    }
+
+ photos_application_create_online_miners (self);
 }
 
 
@@ -3003,6 +3024,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]