[gnome-software/1225-do-not-allow-distro-upgrades-if-release-art-is-missing: 121/121] gs-plugin-fedora-pkgdb-collections: Do not rely on gs-plugin-rewrite-resource with background downlo




commit d6b4cb1e375e252ba974792e8cb1d306182c7157
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 5 13:01:46 2021 +0200

    gs-plugin-fedora-pkgdb-collections: Do not rely on gs-plugin-rewrite-resource with background download
    
    The gs-plugin-rewrite-resource plugin may eventually be dropped, thus
    download the background from the Internet on its own, to not rely
    on it.

 .../gs-plugin-fedora-pkgdb-collections.c           | 41 +++++++++++++++++++---
 1 file changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index b92b975dc..a7f2d69d4 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -218,7 +218,36 @@ gs_plugin_refresh (GsPlugin *plugin,
 }
 
 static gchar *
-_get_upgrade_css_background (guint version)
+_download_upgrade_background (GsPlugin *plugin,
+                             const gchar *uri,
+                             GCancellable *cancellable)
+{
+       g_autofree gchar *cachefn = NULL;
+
+       /* get cache location */
+       cachefn = gs_utils_get_cache_filename ("cssresource", uri,
+                                              GS_UTILS_CACHE_FLAG_WRITEABLE |
+                                              GS_UTILS_CACHE_FLAG_USE_HASH |
+                                              GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY,
+                                              NULL);
+       if (cachefn == NULL)
+               return NULL;
+
+       /* already exists */
+       if (g_file_test (cachefn, G_FILE_TEST_EXISTS))
+               return g_steal_pointer (&cachefn);
+
+       /* download */
+       if (!gs_plugin_download_file (plugin, NULL, uri, cachefn, cancellable, NULL))
+               return NULL;
+
+       return g_steal_pointer (&cachefn);
+}
+
+static gchar *
+_get_upgrade_css_background (GsPlugin *plugin,
+                            guint version,
+                            GCancellable *cancellable)
 {
        g_autoptr(GSettings) settings = NULL;
        g_autofree gchar *filename1 = NULL;
@@ -248,7 +277,9 @@ _get_upgrade_css_background (guint version)
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
                        filename1 = g_strdup_printf (uri, version, version, version);
 #pragma GCC diagnostic pop
-                       return g_strdup_printf ("url('%s')", filename1);
+                       filename2 = _download_upgrade_background (plugin, filename1, cancellable);
+                       if (filename2)
+                               return g_strdup_printf ("url('%s')", filename2);
                }
        }
 
@@ -277,7 +308,7 @@ _sort_items_cb (gconstpointer a, gconstpointer b)
 }
 
 static GsApp *
-_create_upgrade_from_info (GsPlugin *plugin, PkgdbItem *item)
+_create_upgrade_from_info (GsPlugin *plugin, PkgdbItem *item, GCancellable *cancellable)
 {
        GsApp *app;
        g_autofree gchar *app_id = NULL;
@@ -326,7 +357,7 @@ _create_upgrade_from_info (GsPlugin *plugin, PkgdbItem *item)
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
 
        /* use a fancy background if possible */
-       background = _get_upgrade_css_background (item->version);
+       background = _get_upgrade_css_background (plugin, item->version, cancellable);
        if (background != NULL) {
                css = g_strdup_printf ("background: %s;"
                                       "background-position: top;"
@@ -525,7 +556,7 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
                PkgdbItem *item = g_ptr_array_index (priv->distros, i);
                if (_is_valid_upgrade (plugin, item)) {
                        g_autoptr(GsApp) app = NULL;
-                       app = _create_upgrade_from_info (plugin, item);
+                       app = _create_upgrade_from_info (plugin, item, cancellable);
                        gs_app_list_add (list, app);
                }
        }


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