From bc0f90764ed39509ab01f38184f0bbb9dbc6a073 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 7 Jul 2017 18:40:55 +0100 Subject: [PATCH] common/dir: Fix error handling for flatpak_dir_lookup_repo_metadata() It can return FALSE with an error set, or FALSE without one set, which indicates the key was not found. Signed-off-by: Philip Withnall --- app/flatpak-builtins-ls-remote.c | 10 ++++++++-- common/flatpak-dir.c | 22 +++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/flatpak-builtins-ls-remote.c b/app/flatpak-builtins-ls-remote.c index 84222185..e77c6fb4 100644 --- a/app/flatpak-builtins-ls-remote.c +++ b/app/flatpak-builtins-ls-remote.c @@ -68,6 +68,7 @@ flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr const char *opt_arches[] = {NULL, NULL}; g_autoptr(GVariant) refdata = NULL; g_autoptr(GHashTable) pref_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr(GError) local_error = NULL; context = g_option_context_new (_(" REMOTE - Show available runtimes and applications")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); @@ -97,9 +98,14 @@ flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr if (opt_show_details) { - if (!flatpak_dir_lookup_repo_metadata (dir, repository, cancellable, error, + if (!flatpak_dir_lookup_repo_metadata (dir, repository, cancellable, &local_error, "xa.cache", "v", &refdata)) - return FALSE; + { + if (local_error == NULL) + flatpak_fail (&local_error, _("No ref information available in repository")); + g_propagate_error (error, g_steal_pointer (&local_error)); + return FALSE; + } } if (opt_arch != NULL) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 967b42aa..81aed154 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -2458,7 +2458,9 @@ oci_pull_progress_cb (guint64 total_size, guint64 pulled_size, /* Look up a piece of per-repository metadata. Previously, this was stored in * the summary file; now it’s stored the commit metadata of a special branch. - * Differentiate based on whether the collection ID is set for the remote. */ + * Differentiate based on whether the collection ID is set for the remote. + * Returns %FALSE on error or if @key doesn’t exist (in which case, no error is + * set). */ gboolean flatpak_dir_lookup_repo_metadata (FlatpakDir *self, const char *remote_name, @@ -8681,12 +8683,15 @@ flatpak_dir_fetch_remote_title (FlatpakDir *self, GError **error) { g_autofree char *title = NULL; + g_autoptr(GError) local_error = NULL; - if (!flatpak_dir_lookup_repo_metadata (self, remote, cancellable, error, + if (!flatpak_dir_lookup_repo_metadata (self, remote, cancellable, &local_error, "xa.title", "s", &title)) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - _("Remote title not set")); + if (local_error == NULL) + g_set_error_literal (&local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + _("Remote title not set")); + g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } @@ -8700,12 +8705,15 @@ flatpak_dir_fetch_remote_default_branch (FlatpakDir *self, GError **error) { g_autofree char *default_branch = NULL; + g_autoptr(GError) local_error = NULL; - if (!flatpak_dir_lookup_repo_metadata (self, remote, cancellable, error, + if (!flatpak_dir_lookup_repo_metadata (self, remote, cancellable, &local_error, "xa.default-branch", "s", &default_branch)) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - _("Remote default-branch not set")); + if (local_error == NULL) + g_set_error_literal (&local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + _("Remote default-branch not set")); + g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; }