[gnome-software] Move all the external appstream functionality to the same plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move all the external appstream functionality to the same plugin
- Date: Thu, 22 Feb 2018 11:32:13 +0000 (UTC)
commit f18a81b3ce24f5c9073be4548f05c3833a1f2bf0
Author: Richard Hughes <richard hughsie com>
Date: Thu Feb 22 11:21:40 2018 +0000
Move all the external appstream functionality to the same plugin
plugins/core/gs-plugin-appstream.c | 64 ---------------------
.../gs-plugin-external-appstream.c | 66 ++++++++++++++++++----
po/POTFILES.in | 2 +-
3 files changed, 57 insertions(+), 75 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 54a84eb0..766bbe63 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -660,41 +660,6 @@ gs_plugin_add_recent (GsPlugin *plugin,
cancellable, error);
}
-static gboolean
-gs_plugin_appstream_refresh_url (GsPlugin *plugin,
- const gchar *url,
- guint cache_age,
- GCancellable *cancellable,
- GError **error)
-{
- guint file_age;
- g_autofree gchar *basename = NULL;
- g_autofree gchar *fullpath = NULL;
- g_autoptr(GFile) file = NULL;
- g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
-
- /* check age */
- basename = g_path_get_basename (url);
- fullpath = g_build_filename (g_get_user_data_dir (),
- "app-info",
- "xmls",
- basename,
- NULL);
- file = g_file_new_for_path (fullpath);
- file_age = gs_utils_get_file_age (file);
- if (file_age < cache_age) {
- g_debug ("skipping %s: cache age is older than file", fullpath);
- return TRUE;
- }
-
- /* download file */
- gs_app_set_summary_missing (app_dl,
- /* TRANSLATORS: status text when downloading */
- _("Downloading extra metadata files…"));
- return gs_plugin_download_file (plugin, app_dl, url, fullpath,
- cancellable, error);
-}
-
gboolean
gs_plugin_refresh (GsPlugin *plugin,
guint cache_age,
@@ -703,39 +668,10 @@ gs_plugin_refresh (GsPlugin *plugin,
GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
- g_auto(GStrv) appstream_urls = NULL;
/* ensure the token cache */
if (cache_age == G_MAXUINT)
as_store_load_search_cache (priv->store);
- if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
- return TRUE;
-
- /* check we want per-user */
- if (g_settings_get_boolean (priv->settings,
- "external-appstream-system-wide")) {
- g_debug ("not per-user for external appstream");
- return TRUE;
- }
- appstream_urls = g_settings_get_strv (priv->settings,
- "external-appstream-urls");
- for (guint i = 0; appstream_urls[i] != NULL; ++i) {
- g_autoptr(GError) local_error = NULL;
- if (!g_str_has_prefix (appstream_urls[i], "https")) {
- g_warning ("cannot use AppStream source %s: use https://",
- appstream_urls[i]);
- continue;
- }
- if (!gs_plugin_appstream_refresh_url (plugin,
- appstream_urls[i],
- cache_age,
- cancellable,
- &local_error)) {
- g_warning ("failed to update external AppStream file: %s",
- local_error->message);
- }
- }
-
return TRUE;
}
diff --git a/plugins/external-appstream/gs-plugin-external-appstream.c
b/plugins/external-appstream/gs-plugin-external-appstream.c
index 80b7af02..42865c7d 100644
--- a/plugins/external-appstream/gs-plugin-external-appstream.c
+++ b/plugins/external-appstream/gs-plugin-external-appstream.c
@@ -22,6 +22,7 @@
*/
#include <config.h>
+#include <glib/gi18n.h>
#include <gnome-software.h>
#include "gs-external-appstream-utils.h"
@@ -101,7 +102,7 @@ gs_plugin_external_appstream_get_modification_date (const gchar *file_path)
}
static gboolean
-gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
+gs_plugin_external_appstream_refresh_sys (GsPlugin *plugin,
const gchar *url,
guint cache_age,
GCancellable *cancellable,
@@ -209,6 +210,59 @@ gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
return file_written;
}
+static gboolean
+gs_plugin_external_appstream_refresh_user (GsPlugin *plugin,
+ const gchar *url,
+ guint cache_age,
+ GCancellable *cancellable,
+ GError **error)
+{
+ guint file_age;
+ g_autofree gchar *basename = NULL;
+ g_autofree gchar *fullpath = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
+
+ /* check age */
+ basename = g_path_get_basename (url);
+ fullpath = g_build_filename (g_get_user_data_dir (),
+ "app-info",
+ "xmls",
+ basename,
+ NULL);
+ file = g_file_new_for_path (fullpath);
+ file_age = gs_utils_get_file_age (file);
+ if (file_age < cache_age) {
+ g_debug ("skipping %s: cache age is older than file", fullpath);
+ return TRUE;
+ }
+
+ /* download file */
+ gs_app_set_summary_missing (app_dl,
+ /* TRANSLATORS: status text when downloading */
+ _("Downloading extra metadata files…"));
+ return gs_plugin_download_file (plugin, app_dl, url, fullpath,
+ cancellable, error);
+}
+
+static gboolean
+gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
+ const gchar *url,
+ guint cache_age,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (g_settings_get_strv (priv->settings, "external-appstream-urls")) {
+ return gs_plugin_external_appstream_refresh_sys (plugin, url,
+ cache_age,
+ cancellable,
+ error);
+ }
+ return gs_plugin_external_appstream_refresh_user (plugin, url, cache_age,
+ cancellable, error);
+}
+
gboolean
gs_plugin_refresh (GsPlugin *plugin,
guint cache_age,
@@ -217,22 +271,14 @@ gs_plugin_refresh (GsPlugin *plugin,
GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
- guint i;
g_auto(GStrv) appstream_urls = NULL;
if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
return TRUE;
- /* check we want system-wide */
- if (!g_settings_get_boolean (priv->settings,
- "external-appstream-system-wide")) {
- g_debug ("not system-wide for external appstream");
- return TRUE;
- }
-
appstream_urls = g_settings_get_strv (priv->settings,
"external-appstream-urls");
- for (i = 0; appstream_urls[i] != NULL; ++i) {
+ for (guint i = 0; appstream_urls[i] != NULL; ++i) {
g_autoptr(GError) local_error = NULL;
if (!g_str_has_prefix (appstream_urls[i], "https")) {
g_warning ("Not considering %s as an external "
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d9baa51c..b02354db 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -74,11 +74,11 @@ src/gs-upgrade-banner.ui
src/org.gnome.Software.desktop.in
src/org.gnome.Software.Editor.desktop.in
plugins/core/gs-desktop-common.c
-plugins/core/gs-plugin-appstream.c
plugins/core/gs-plugin-generic-updates.c
plugins/core/gs-plugin-rewrite-resource.c
plugins/epiphany/org.gnome.Software.Plugin.Epiphany.metainfo.xml.in
plugins/external-appstream/gs-install-appstream.c
+plugins/external-appstream/gs-plugin-external-appstream.c
plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
plugins/flatpak/org.gnome.Software.Plugin.Flatpak.metainfo.xml.in
plugins/flatpak/gs-flatpak.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]