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 <withnall@endlessm.com>
tingping/wmclass
Philip Withnall 2017-07-07 18:40:55 +01:00 committed by Alexander Larsson
parent bc46274ae4
commit bc0f90764e
2 changed files with 23 additions and 9 deletions

View File

@ -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)

View File

@ -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 its 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 doesnt 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;
}