[gnome-software/wip/mak/swcatalog: 2/2] Migrate path for external-appstream user data




commit 2d03a5fd3522649edcc5a314e6a6777385ae0114
Author: Matthias Klumpp <matthias tenstral net>
Date:   Fri Feb 25 21:10:40 2022 +0100

    Migrate path for external-appstream user data

 data/org.gnome.software.gschema.xml |  4 ++--
 doc/api/gnome-software-docs.xml     |  6 +++---
 plugins/core/gs-plugin-appstream.c  | 38 +++++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index bf43208d9..7eacb116d 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -133,11 +133,11 @@
     </key>
     <key name="external-appstream-urls" type="as">
       <default>[]</default>
-      <summary>A list of URLs pointing to appstream files that will be downloaded into an app-info 
folder</summary>
+      <summary>A list of URLs pointing to appstream files that will be downloaded into an swcatalog 
folder</summary>
     </key>
     <key name="external-appstream-system-wide" type="b">
       <default>false</default>
-      <summary>Install the AppStream files to a system-wide location for all users. If false, files are 
installed in non-standard $XDG_DATA_HOME/app-info/xmls directory</summary>
+      <summary>Install the AppStream files to a system-wide location for all users. If false, files are 
installed in non-standard $XDG_DATA_HOME/swcatalog/xml directory</summary>
     </key>
     <key name="packaging-format-preference" type="as">
       <default>['']</default>
diff --git a/doc/api/gnome-software-docs.xml b/doc/api/gnome-software-docs.xml
index e20808f3f..f1b0640cd 100644
--- a/doc/api/gnome-software-docs.xml
+++ b/doc/api/gnome-software-docs.xml
@@ -549,9 +549,9 @@ gs_plugin_example_refine_finish (GsPlugin *plugin,
           icons are going to be loaded, and you can re-use a lot of the existing
           code in the <code>appstream</code> plugin.
           To do this you just save an AppStream-format XML file in either
-          <filename>/usr/share/app-info/xmls/</filename>,
-          <filename>/var/cache/app-info/xmls/</filename> or
-          <filename>~/.local/share/app-info/xmls/</filename>.
+          <filename>/usr/share/swcatalog/xml/</filename>,
+          <filename>/var/cache/swcatalog/xml/</filename> or
+          <filename>~/.local/share/swcatalog/xml/</filename>.
           GNOME Software will immediately notice any new files, or changes to
           existing files as it has set up the various inotify watches.
         </para>
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 6d37abb9c..e832af745 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -10,6 +10,8 @@
 #include <config.h>
 
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <errno.h>
 #include <gnome-software.h>
 #include <xmlb.h>
 
@@ -714,8 +716,40 @@ gs_plugin_appstream_check_silo (GsPluginAppstream  *self,
 
 #ifdef ENABLE_EXTERNAL_APPSTREAM
                /* check for the corresponding setting */
-               if (!g_settings_get_boolean (self->settings, "external-appstream-system-wide"))
-                       gs_add_appstream_catalog_location (parent_appstream, g_get_user_data_dir ());
+               if (!g_settings_get_boolean (self->settings, "external-appstream-system-wide")) {
+                       g_autofree gchar *user_catalog_path = NULL;
+                       g_autofree gchar *user_catalog_old_path = NULL;
+
+                       /* migrate data paths */
+                       user_catalog_path = g_build_filename (g_get_user_data_dir (), "swcatalog", NULL);
+                       user_catalog_old_path = g_build_filename (g_get_user_data_dir (), "app-info", NULL);
+                       if (g_file_test (user_catalog_old_path, G_FILE_TEST_IS_DIR) &&
+                           !g_file_test (user_catalog_path, G_FILE_TEST_IS_DIR)) {
+                               g_debug ("Migrating external AppStream user location.");
+                               if (g_rename (user_catalog_old_path, user_catalog_path) == 0) {
+                                       g_autofree gchar *user_catalog_xml_path = NULL;
+                                       g_autofree gchar *user_catalog_xml_old_path = NULL;
+
+                                       user_catalog_xml_path = g_build_filename (user_catalog_path, "xml", 
NULL);
+                                       user_catalog_xml_old_path = g_build_filename (user_catalog_path, 
"xmls", NULL);
+                                       if (g_file_test (user_catalog_xml_old_path, G_FILE_TEST_IS_DIR)) {
+                                               if (g_rename (user_catalog_xml_old_path, 
user_catalog_xml_path) != 0)
+                                                       g_warning ("Unable to migrate external XML data 
location from '%s' to '%s': %s",
+                                                               user_catalog_xml_old_path, 
user_catalog_xml_path, g_strerror (errno));
+                                       }
+                               } else {
+                                       g_warning ("Unable to migrate external data location from '%s' to 
'%s': %s",
+                                                  user_catalog_old_path, user_catalog_path, g_strerror 
(errno));
+                               }
+
+                       }
+
+                       /* add modern locations only */
+                       g_ptr_array_add (parent_appstream,
+                                       g_build_filename (user_catalog_path, "xml", NULL));
+                       g_ptr_array_add (parent_appstream,
+                                       g_build_filename (user_catalog_path, "yaml", NULL));
+               }
 #endif
 
                /* Add the normal system directories if the installation prefix


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