[gnome-software/wip/mak/swcatalog] Find AppStream metadata in every possible location




commit 0d6309816501fefb92be749e776e7d738132e458
Author: Matthias Klumpp <matthias tenstral net>
Date:   Fri Feb 25 03:02:15 2022 +0100

    Find AppStream metadata in every possible location
    
    AppStream Metadata can currently be found in:
    Modern:
     MetaInfo data:
      /usr/share/metainfo
     Catalog Data:
      /usr/share/swcatalog/(xml|yaml)
      /var/(lib|cache)/swcatalog/(xml|yaml)
    
    Legacy:
     MetaInfo Data:
      /usr/share/appdata
     Catalog Data:
      /usr/share/app-info/(xml|xmls|yaml)
      /var/(lib|cache)/app-info/(xml|xmls|yaml)
    
    With this patch, we search them all, and don't monitor any locations
    that have a compatibility symlink.

 contrib/org.gnome.SoftwareDevel.json |   4 ++
 data/assets/meson.build              |   4 +-
 lib/gs-external-appstream-utils.c    |   6 +--
 plugins/core/gs-plugin-appstream.c   | 100 ++++++++++++++++++++++-------------
 4 files changed, 71 insertions(+), 43 deletions(-)
---
diff --git a/contrib/org.gnome.SoftwareDevel.json b/contrib/org.gnome.SoftwareDevel.json
index 4f7e0f90b..98973f2ae 100644
--- a/contrib/org.gnome.SoftwareDevel.json
+++ b/contrib/org.gnome.SoftwareDevel.json
@@ -25,7 +25,11 @@
         "--filesystem=/var/lib/flatpak",
         "--env=FLATPAK_SYSTEM_DIR=/var/lib/flatpak",
         "--filesystem=xdg-data/flatpak",
+        "--filesystem=/usr/share/metainfo:ro",
         "--filesystem=/usr/share/appdata:ro",
+        "--filesystem=/usr/share/swcatalog:ro",
+        "--filesystem=/var/lib/swcatalog:ro",
+        "--filesystem=/var/cache/swcatalog:ro",
         "--filesystem=/usr/share/app-info:ro",
         "--filesystem=/var/lib/app-info:ro",
         "--filesystem=/var/cache/app-info:ro"
diff --git a/data/assets/meson.build b/data/assets/meson.build
index 2f0ed4b51..956875fc2 100644
--- a/data/assets/meson.build
+++ b/data/assets/meson.build
@@ -1,11 +1,11 @@
 if get_option('default_featured_apps')
   install_data('org.gnome.Software.Featured.xml',
-    install_dir : join_paths(get_option('datadir'), 'app-info', 'xmls'),
+    install_dir : join_paths(get_option('datadir'), 'swcatalog', 'xml'),
   )
 endif
 
 if get_option('hardcoded_popular')
   install_data('org.gnome.Software.Popular.xml',
-    install_dir : join_paths(get_option('datadir'), 'app-info', 'xmls'),
+    install_dir : join_paths(get_option('datadir'), 'swcatalog', 'xml'),
   )
 endif
diff --git a/lib/gs-external-appstream-utils.c b/lib/gs-external-appstream-utils.c
index 23462c0db..4d9b5eee1 100644
--- a/lib/gs-external-appstream-utils.c
+++ b/lib/gs-external-appstream-utils.c
@@ -14,7 +14,7 @@
 
 #include "gs-external-appstream-utils.h"
 
-#define APPSTREAM_SYSTEM_DIR LOCALSTATEDIR "/cache/app-info/xmls"
+#define APPSTREAM_SYSTEM_DIR LOCALSTATEDIR "/cache/swcatalog/xml"
 
 gchar *
 gs_external_appstream_utils_get_file_cache_path (const gchar *file_name)
@@ -228,8 +228,8 @@ gs_external_appstream_refresh_user (GsPlugin      *plugin,
 
        /* check age */
        fullpath = g_build_filename (g_get_user_data_dir (),
-                                    "app-info",
-                                    "xmls",
+                                    "swcatalog",
+                                    "xml",
                                     basename,
                                     NULL);
        file = g_file_new_for_path (fullpath);
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index cde6a5c2c..6d37abb9c 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -584,6 +584,51 @@ gs_plugin_appstream_load_appstream (GsPluginAppstream  *self,
        return TRUE;
 }
 
+static void
+gs_add_appstream_catalog_location (GPtrArray *locations, const gchar *root)
+{
+       g_autofree gchar *catalog_path = NULL;
+       g_autofree gchar *catalog_legacy_path = NULL;
+       gboolean ignore_legacy_path = FALSE;
+
+       catalog_path = g_build_filename (root, "swcatalog", NULL);
+       catalog_legacy_path = g_build_filename (root, "app-info", NULL);
+
+       /* ignore compatibility symlink if one exists, so we don't scan the same location twice */
+       if (g_file_test (catalog_legacy_path, G_FILE_TEST_IS_SYMLINK)) {
+               g_autofree gchar *link_target = g_file_read_link (catalog_legacy_path, NULL);
+               if (link_target != NULL) {
+                       if (g_strcmp0 (link_target, catalog_path) == 0) {
+                               ignore_legacy_path = TRUE;
+                               g_debug ("Ignoring legacy AppStream catalog location '%s'.", 
catalog_legacy_path);
+                       }
+               }
+       }
+
+       g_ptr_array_add (locations,
+                        g_build_filename (catalog_path, "xml", NULL));
+       g_ptr_array_add (locations,
+                        g_build_filename (catalog_path, "yaml", NULL));
+
+       if (!ignore_legacy_path) {
+               g_ptr_array_add (locations,
+                                g_build_filename (catalog_legacy_path, "xml", NULL));
+               g_ptr_array_add (locations,
+                                g_build_filename (catalog_legacy_path, "xmls", NULL));
+               g_ptr_array_add (locations,
+                                g_build_filename (catalog_legacy_path, "yaml", NULL));
+       }
+}
+
+static void
+gs_add_appstream_metainfo_location (GPtrArray *locations, const gchar *root)
+{
+       g_ptr_array_add (locations,
+                        g_build_filename (root, "metainfo", NULL));
+       g_ptr_array_add (locations,
+                        g_build_filename (root, "appdata", NULL));
+}
+
 static gboolean
 gs_plugin_appstream_check_silo (GsPluginAppstream  *self,
                                 GCancellable       *cancellable,
@@ -655,31 +700,22 @@ gs_plugin_appstream_check_silo (GsPluginAppstream  *self,
                xb_builder_source_add_fixup (source, fixup2);
                xb_builder_import_source (builder, source);
        } else {
+               g_autofree gchar *state_cache_dir = NULL;
+               g_autofree gchar *state_lib_dir = NULL;
+
                /* add search paths */
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (DATADIR, "app-info", "xmls", NULL));
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (DATADIR, "app-info", "yaml", NULL));
-               g_ptr_array_add (parent_appdata,
-                                g_build_filename (DATADIR, "appdata", NULL));
-               g_ptr_array_add (parent_appdata,
-                                g_build_filename (DATADIR, "metainfo", NULL));
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (LOCALSTATEDIR, "cache", "app-info", "xmls", NULL));
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (LOCALSTATEDIR, "cache", "app-info", "yaml", NULL));
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (LOCALSTATEDIR, "lib", "app-info", "xmls", NULL));
-               g_ptr_array_add (parent_appstream,
-                                g_build_filename (LOCALSTATEDIR, "lib", "app-info", "yaml", NULL));
+               gs_add_appstream_catalog_location (parent_appstream, DATADIR);
+               gs_add_appstream_metainfo_location (parent_appdata, DATADIR);
+
+               state_cache_dir = g_build_filename (LOCALSTATEDIR, "cache", NULL);
+               gs_add_appstream_catalog_location (parent_appstream, state_cache_dir);
+               state_lib_dir = g_build_filename (LOCALSTATEDIR, "lib", NULL);
+               gs_add_appstream_catalog_location (parent_appstream, state_lib_dir);
+
 #ifdef ENABLE_EXTERNAL_APPSTREAM
                /* check for the corresponding setting */
-               if (!g_settings_get_boolean (self->settings, "external-appstream-system-wide")) {
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename (g_get_user_data_dir (), "app-info", "xmls", NULL));
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename (g_get_user_data_dir (), "app-info", "yaml", NULL));
-               }
+               if (!g_settings_get_boolean (self->settings, "external-appstream-system-wide"))
+                       gs_add_appstream_catalog_location (parent_appstream, g_get_user_data_dir ());
 #endif
 
                /* Add the normal system directories if the installation prefix
@@ -687,24 +723,12 @@ gs_plugin_appstream_check_silo (GsPluginAppstream  *self,
                 * development builds. It’s useful to still list the system apps
                 * during development. */
                if (g_strcmp0 (DATADIR, "/usr/share") != 0) {
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/usr/share", "app-info", "xmls", NULL));
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/usr/share", "app-info", "yaml", NULL));
-                       g_ptr_array_add (parent_appdata,
-                                        g_build_filename ("/usr/share", "appdata", NULL));
-                       g_ptr_array_add (parent_appdata,
-                                        g_build_filename ("/usr/share", "metainfo", NULL));
+                       gs_add_appstream_catalog_location (parent_appstream, "/usr/share");
+                       gs_add_appstream_metainfo_location (parent_appdata, "/usr/share");
                }
                if (g_strcmp0 (LOCALSTATEDIR, "/var") != 0) {
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/var", "cache", "app-info", "xmls", NULL));
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/var", "cache", "app-info", "yaml", NULL));
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/var", "lib", "app-info", "xmls", NULL));
-                       g_ptr_array_add (parent_appstream,
-                                        g_build_filename ("/var", "lib", "app-info", "yaml", NULL));
+                       gs_add_appstream_catalog_location (parent_appstream, "/var/cache");
+                       gs_add_appstream_catalog_location (parent_appstream, "/var/lib");
                }
 
                /* import all files */


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