[gnome-software] trivial: Ensure we use the plugin cache when returning flatpak sources
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Ensure we use the plugin cache when returning flatpak sources
- Date: Tue, 11 Jul 2017 16:11:49 +0000 (UTC)
commit 76ac062877664767492fc6b75aab99cb8dcf6273
Author: Richard Hughes <richard hughsie com>
Date: Tue Jul 11 13:59:04 2017 +0100
trivial: Ensure we use the plugin cache when returning flatpak sources
plugins/flatpak/gs-flatpak-utils.c | 141 +++++++++++++++++++++++++++++
plugins/flatpak/gs-flatpak-utils.h | 4 +
plugins/flatpak/gs-flatpak.c | 173 +++++++-----------------------------
3 files changed, 176 insertions(+), 142 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-utils.c b/plugins/flatpak/gs-flatpak-utils.c
index 897f2f2..9ea6f1a 100644
--- a/plugins/flatpak/gs-flatpak-utils.c
+++ b/plugins/flatpak/gs-flatpak-utils.c
@@ -63,3 +63,144 @@ gs_flatpak_error_convert (GError **perror)
}
error->domain = GS_PLUGIN_ERROR;
}
+
+GsApp *
+gs_flatpak_app_new_from_remote (FlatpakRemote *xremote)
+{
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *url = NULL;
+ g_autoptr(GsApp) app = NULL;
+
+ app = gs_app_new (flatpak_remote_get_name (xremote));
+ gs_app_set_kind (app, AS_APP_KIND_SOURCE);
+ gs_app_set_state (app, flatpak_remote_get_disabled (xremote) ?
+ AS_APP_STATE_AVAILABLE : AS_APP_STATE_INSTALLED);
+ gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
+ gs_app_set_name (app, GS_APP_QUALITY_LOWEST,
+ flatpak_remote_get_name (xremote));
+
+ /* title */
+ title = flatpak_remote_get_title (xremote);
+ if (title != NULL)
+ gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, title);
+
+ /* url */
+ url = flatpak_remote_get_url (xremote);
+ if (url != NULL)
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
+
+ /* success */
+ return g_steal_pointer (&app);
+}
+
+GsApp *
+gs_flatpak_app_new_from_repo_file (GFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gchar *tmp;
+ g_autofree gchar *filename = NULL;
+ g_autofree gchar *repo_comment = NULL;
+ g_autofree gchar *repo_default_branch = NULL;
+ g_autofree gchar *repo_description = NULL;
+ g_autofree gchar *repo_gpgkey = NULL;
+ g_autofree gchar *repo_homepage = NULL;
+ g_autofree gchar *repo_icon = NULL;
+ g_autofree gchar *repo_id = NULL;
+ g_autofree gchar *repo_title = NULL;
+ g_autofree gchar *repo_url = NULL;
+ g_autoptr(GError) error_local = NULL;
+ g_autoptr(GKeyFile) kf = NULL;
+ g_autoptr(GsApp) app = NULL;
+
+ /* read the file */
+ kf = g_key_file_new ();
+ filename = g_file_get_path (file);
+ if (!g_key_file_load_from_file (kf, filename,
+ G_KEY_FILE_NONE,
+ &error_local)) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "failed to load flatpakrepo: %s",
+ error_local->message);
+ return NULL;
+ }
+
+ /* get the ID from the basename */
+ repo_id = g_file_get_basename (file);
+ tmp = g_strrstr (repo_id, ".");
+ if (tmp != NULL)
+ *tmp = '\0';
+
+ /* create source */
+ repo_title = g_key_file_get_string (kf, "Flatpak Repo", "Title", NULL);
+ repo_url = g_key_file_get_string (kf, "Flatpak Repo", "Url", NULL);
+ repo_gpgkey = g_key_file_get_string (kf, "Flatpak Repo", "GPGKey", NULL);
+ if (repo_title == NULL || repo_url == NULL || repo_gpgkey == NULL ||
+ repo_title[0] == '\0' || repo_url[0] == '\0' || repo_gpgkey[0] == '\0') {
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "not enough data in file, "
+ "expected Title, Url, GPGKey");
+ return NULL;
+ }
+
+ /* check version */
+ if (g_key_file_has_key (kf, "Flatpak Repo", "Version", NULL)) {
+ guint64 ver = g_key_file_get_uint64 (kf, "Flatpak Repo", "Version", NULL);
+ if (ver != 1) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "unsupported version %" G_GUINT64_FORMAT, ver);
+ return NULL;
+ }
+ }
+
+ /* user specified a URL */
+ if (g_str_has_prefix (repo_gpgkey, "http://") ||
+ g_str_has_prefix (repo_gpgkey, "https://")) {
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "Base64 encoded GPGKey required, not URL");
+ return NULL;
+ }
+
+ /* create source */
+ app = gs_app_new (repo_id);
+ gs_app_set_flatpak_file_type (app, "flatpakrepo");
+ gs_app_set_kind (app, AS_APP_KIND_SOURCE);
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL, repo_title);
+ gs_app_set_metadata (app, "flatpak::gpg-key", repo_gpgkey);
+ gs_app_set_metadata (app, "flatpak::url", repo_url);
+ gs_app_set_origin_hostname (app, repo_url);
+
+ /* optional data */
+ repo_homepage = g_key_file_get_string (kf, "Flatpak Repo", "Homepage", NULL);
+ if (repo_homepage != NULL)
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, repo_homepage);
+ repo_comment = g_key_file_get_string (kf, "Flatpak Repo", "Comment", NULL);
+ if (repo_comment != NULL)
+ gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, repo_comment);
+ repo_description = g_key_file_get_string (kf, "Flatpak Repo", "Description", NULL);
+ if (repo_description != NULL)
+ gs_app_set_description (app, GS_APP_QUALITY_NORMAL, repo_description);
+ repo_default_branch = g_key_file_get_string (kf, "Flatpak Repo", "DefaultBranch", NULL);
+ if (repo_default_branch != NULL)
+ gs_app_set_branch (app, repo_default_branch);
+ repo_icon = g_key_file_get_string (kf, "Flatpak Repo", "Icon", NULL);
+ if (repo_icon != NULL) {
+ g_autoptr(AsIcon) ic = as_icon_new ();
+ as_icon_set_kind (ic, AS_ICON_KIND_REMOTE);
+ as_icon_set_url (ic, repo_icon);
+ gs_app_add_icon (app, ic);
+ }
+
+ /* success */
+ return g_steal_pointer (&app);
+}
diff --git a/plugins/flatpak/gs-flatpak-utils.h b/plugins/flatpak/gs-flatpak-utils.h
index 653ccce..fd77ab1 100644
--- a/plugins/flatpak/gs-flatpak-utils.h
+++ b/plugins/flatpak/gs-flatpak-utils.h
@@ -44,6 +44,10 @@ G_BEGIN_DECLS
#define gs_app_set_flatpak_ref_display(app,val) gs_app_set_metadata(app,"flatpak::ref-display",val)
void gs_flatpak_error_convert (GError **perror);
+GsApp *gs_flatpak_app_new_from_remote (FlatpakRemote *xremote);
+GsApp *gs_flatpak_app_new_from_repo_file (GFile *file,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 4db884f..ba70911 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -165,6 +165,27 @@ gs_flatpak_create_app (GsFlatpak *self, FlatpakRef *xref)
return g_steal_pointer (&app);
}
+static GsApp *
+gs_flatpak_create_source (GsFlatpak *self, FlatpakRemote *xremote)
+{
+ GsApp *app_cached;
+ g_autoptr(GsApp) app = NULL;
+
+ /* create a temp GsApp */
+ app = gs_flatpak_app_new_from_remote (xremote);
+ gs_app_set_scope (app, self->scope);
+ gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
+
+ /* we already have one, returned the ref'd cached copy */
+ app_cached = gs_plugin_cache_lookup (self->plugin, gs_app_get_unique_id (app));
+ if (app_cached != NULL)
+ return app_cached;
+
+ /* no existing match, just steal the temp object */
+ gs_plugin_cache_add (self->plugin, NULL, app);
+ return g_steal_pointer (&app);
+}
+
static void
gs_plugin_flatpak_changed_cb (GFileMonitor *monitor,
GFile *child,
@@ -842,34 +863,14 @@ gs_flatpak_add_sources (GsFlatpak *self, GsAppList *list,
for (i = 0; i < xremotes->len; i++) {
FlatpakRemote *xremote = g_ptr_array_index (xremotes, i);
g_autoptr(GsApp) app = NULL;
- g_autofree gchar *url = NULL;
- g_autofree gchar *title = NULL;;
/* apps installed from bundles add their own remote that only
* can be used for updating that app only -- so hide them */
if (flatpak_remote_get_noenumerate (xremote))
continue;
- /* create both enabled and disabled and filter in the UI */
- app = gs_app_new (flatpak_remote_get_name (xremote));
- gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
- gs_app_set_kind (app, AS_APP_KIND_SOURCE);
- gs_app_set_state (app, flatpak_remote_get_disabled (xremote) ?
- AS_APP_STATE_AVAILABLE : AS_APP_STATE_INSTALLED);
- gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
- gs_app_set_name (app,
- GS_APP_QUALITY_LOWEST,
- flatpak_remote_get_name (xremote));
-
- /* title */
- title = flatpak_remote_get_title (xremote);
- if (title != NULL)
- gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, title);
-
- /* url */
- url = flatpak_remote_get_url (xremote);
- if (url != NULL)
- gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
+ /* create app */
+ app = gs_flatpak_create_source (self, xremote);
gs_app_list_add (list, app);
/* add related apps, i.e. what was installed from there */
@@ -2445,121 +2446,6 @@ install_runtime_for_app (GsFlatpak *self,
return TRUE;
}
-static GsApp *
-gs_flatpak_create_app_from_repo_file (GsFlatpak *self,
- GFile *file,
- GCancellable *cancellable,
- GError **error)
-{
- gchar *tmp;
- g_autofree gchar *filename = NULL;
- g_autofree gchar *repo_comment = NULL;
- g_autofree gchar *repo_default_branch = NULL;
- g_autofree gchar *repo_description = NULL;
- g_autofree gchar *repo_gpgkey = NULL;
- g_autofree gchar *repo_homepage = NULL;
- g_autofree gchar *repo_icon = NULL;
- g_autofree gchar *repo_id = NULL;
- g_autofree gchar *repo_title = NULL;
- g_autofree gchar *repo_url = NULL;
- g_autoptr(GError) error_local = NULL;
- g_autoptr(GKeyFile) kf = NULL;
- g_autoptr(GsApp) app = NULL;
-
- /* read the file */
- kf = g_key_file_new ();
- filename = g_file_get_path (file);
- if (!g_key_file_load_from_file (kf, filename,
- G_KEY_FILE_NONE,
- &error_local)) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "failed to load flatpakrepo: %s",
- error_local->message);
- return NULL;
- }
-
- /* get the ID from the basename */
- repo_id = g_file_get_basename (file);
- tmp = g_strrstr (repo_id, ".");
- if (tmp != NULL)
- *tmp = '\0';
-
- /* create source */
- repo_title = g_key_file_get_string (kf, "Flatpak Repo", "Title", NULL);
- repo_url = g_key_file_get_string (kf, "Flatpak Repo", "Url", NULL);
- repo_gpgkey = g_key_file_get_string (kf, "Flatpak Repo", "GPGKey", NULL);
- if (repo_title == NULL || repo_url == NULL || repo_gpgkey == NULL ||
- repo_title[0] == '\0' || repo_url[0] == '\0' || repo_gpgkey[0] == '\0') {
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "not enough data in file, "
- "expected Title, Url, GPGKey");
- return NULL;
- }
-
- /* check version */
- if (g_key_file_has_key (kf, "Flatpak Repo", "Version", NULL)) {
- guint64 ver = g_key_file_get_uint64 (kf, "Flatpak Repo", "Version", NULL);
- if (ver != 1) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "unsupported version %" G_GUINT64_FORMAT, ver);
- return NULL;
- }
- }
-
- /* user specified a URL */
- if (g_str_has_prefix (repo_gpgkey, "http://") ||
- g_str_has_prefix (repo_gpgkey, "https://")) {
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "Base64 encoded GPGKey required, not URL");
- return NULL;
- }
-
- /* create source */
- app = gs_app_new (repo_id);
- gs_app_set_flatpak_file_type (app, "flatpakrepo");
- gs_app_set_kind (app, AS_APP_KIND_SOURCE);
- gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
- gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
- gs_app_set_name (app, GS_APP_QUALITY_NORMAL, repo_title);
- gs_app_set_metadata (app, "flatpak::gpg-key", repo_gpgkey);
- gs_app_set_metadata (app, "flatpak::url", repo_url);
- gs_app_set_origin_hostname (app, repo_url);
- gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
-
- /* optional data */
- repo_homepage = g_key_file_get_string (kf, "Flatpak Repo", "Homepage", NULL);
- if (repo_homepage != NULL)
- gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, repo_homepage);
- repo_comment = g_key_file_get_string (kf, "Flatpak Repo", "Comment", NULL);
- if (repo_comment != NULL)
- gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, repo_comment);
- repo_description = g_key_file_get_string (kf, "Flatpak Repo", "Description", NULL);
- if (repo_description != NULL)
- gs_app_set_description (app, GS_APP_QUALITY_NORMAL, repo_description);
- repo_default_branch = g_key_file_get_string (kf, "Flatpak Repo", "DefaultBranch", NULL);
- if (repo_default_branch != NULL)
- gs_app_set_branch (app, repo_default_branch);
- repo_icon = g_key_file_get_string (kf, "Flatpak Repo", "Icon", NULL);
- if (repo_icon != NULL) {
- g_autoptr(AsIcon) ic = as_icon_new ();
- as_icon_set_kind (ic, AS_ICON_KIND_REMOTE);
- as_icon_set_url (ic, repo_icon);
- gs_app_add_icon (app, ic);
- }
- gs_app_set_flatpak_object_id (app, gs_flatpak_get_id (self));
-
- /* success */
- return g_steal_pointer (&app);
-}
-
gboolean
gs_flatpak_app_install (GsFlatpak *self,
GsApp *app,
@@ -2646,16 +2532,17 @@ gs_flatpak_app_install (GsFlatpak *self,
/* get GsApp for local file */
file = g_file_new_for_path (cache_fn);
- app_src = gs_flatpak_create_app_from_repo_file (self,
- file,
- cancellable,
- error);
+ app_src = gs_flatpak_app_new_from_repo_file (file,
+ cancellable,
+ error);
if (app_src == NULL) {
g_prefix_error (error,
"cannot create source from %s: ",
cache_fn);
return FALSE;
}
+ gs_app_set_flatpak_object_id (app, gs_flatpak_get_id (self));
+ gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
/* install the flatpakrepo */
if (!gs_flatpak_app_install_source (self,
@@ -3044,9 +2931,11 @@ gs_flatpak_file_to_app_repo (GsFlatpak *self,
g_autoptr(FlatpakRemote) xremote = NULL;
/* create app */
- app = gs_flatpak_create_app_from_repo_file (self, file, cancellable, error);
+ app = gs_flatpak_app_new_from_repo_file (file, cancellable, error);
if (app == NULL)
return FALSE;
+ gs_app_set_flatpak_object_id (app, gs_flatpak_get_id (self));
+ gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
/* check to see if the repo ID already exists */
xremote = flatpak_installation_get_remote_by_name (self->installation,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]