history: Fix printing refs

The history command seems to have been broken since it was changed to
use FlatpakDecomposed, since that type only works for app or runtime
refs, resulting in errors such as:
$ flatpak history
error: appstream2/x86_64 is not application or runtime

Fix this by making the logic a bit smarter, and don't let any one
invalid ref entry prevent the whole command from working.

Fixes #4332

(cherry picked from commit 7b6dba8803)
This commit is contained in:
Phaedrus Leeds
2021-10-27 18:56:25 -07:00
committed by Simon McVittie
parent 486ff371e2
commit 9c354072e8
3 changed files with 26 additions and 17 deletions

View File

@@ -217,35 +217,43 @@ print_history (GPtrArray *dirs,
strcmp (columns[k].name, "arch") == 0 ||
strcmp (columns[k].name, "branch") == 0)
{
g_autoptr(FlatpakDecomposed) ref = NULL;
g_autofree char *ref_str = get_field (j, "REF", error);
g_autofree char *ref_str = NULL;
g_autofree char *value = NULL;
ref_str = get_field (j, "REF", error);
if (*error)
return FALSE;
if (ref_str && ref_str[0])
{
ref = flatpak_decomposed_new_from_ref (ref_str, error);
if (ref == NULL)
return FALSE;
}
if (ref_str && ref_str[0] &&
!is_flatpak_ref (ref_str) &&
g_strcmp0 (ref_str, OSTREE_REPO_METADATA_REF) != 0)
g_warning ("Unknown ref in history: %s", ref_str);
if (strcmp (columns[k].name, "ref") == 0)
flatpak_table_printer_add_column (printer, ref_str);
else
value = g_strdup (ref_str);
else if (strcmp (columns[k].name, "arch") == 0)
{
g_autofree char *value = NULL;
if (ref)
if (ref_str != NULL)
value = flatpak_get_arch_for_ref (ref_str);
}
else if (ref_str && ref_str[0] &&
(g_str_has_prefix (ref_str, "app/") ||
g_str_has_prefix (ref_str, "runtime/")))
{
g_autoptr(FlatpakDecomposed) ref = NULL;
ref = flatpak_decomposed_new_from_ref (ref_str, NULL);
if (ref == NULL)
g_warning ("Invalid ref in history: %s", ref_str);
else
{
if (strcmp (columns[k].name, "application") == 0)
value = flatpak_decomposed_dup_id (ref);
else if (strcmp (columns[k].name, "arch") == 0)
value = flatpak_decomposed_dup_arch (ref);
else
value = flatpak_decomposed_dup_branch (ref);
}
flatpak_table_printer_add_column (printer, value);
}
flatpak_table_printer_add_column (printer, value);
}
else if (strcmp (columns[k].name, "installation") == 0)
{

View File

@@ -43,6 +43,7 @@ char * flatpak_make_valid_id_prefix (const char *orig_id);
gboolean flatpak_id_has_subref_suffix (const char *id,
gssize id_len);
gboolean is_flatpak_ref (const char *ref);
char * flatpak_get_arch_for_ref (const char *ref);
const char *flatpak_get_compat_arch_reverse (const char *compat_arch);

View File

@@ -3162,7 +3162,7 @@ flatpak_repo_save_digested_summary_delta (OstreeRepo *repo,
}
static gboolean
gboolean
is_flatpak_ref (const char *ref)
{
return