From b80191fdcd3df13905c2c900709c81753df501dd Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Wed, 7 Feb 2018 13:34:25 -0800 Subject: [PATCH] app: Print a warning if xa.metadata doesn't exist All flatpaks built using version 0.9.4 or newer should have the xa.metadata field in the commit metadata, so warn if it doesn't exist. This commit changes the info command to print a warning rather than nothing and changes the info-remote command to print a warning rather than error out. Closes: #1351 Approved by: alexlarsson --- app/flatpak-builtins-info-remote.c | 19 +++++++++++-------- app/flatpak-builtins-info.c | 4 ++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/flatpak-builtins-info-remote.c b/app/flatpak-builtins-info-remote.c index f3ecce4e..d81530a4 100644 --- a/app/flatpak-builtins-info-remote.c +++ b/app/flatpak-builtins-info-remote.c @@ -174,7 +174,13 @@ flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, G commit_metadata = g_variant_get_child_value (commit_v, 0); g_variant_lookup (commit_metadata, "xa.metadata", "&s", &xa_metadata); if (xa_metadata == NULL) - return flatpak_fail (error, "Commit has no metadata"); + g_printerr (_("Warning: Commit has no flatpak metadata\n")); + else + { + metakey = g_key_file_new (); + if (!g_key_file_load_from_data (metakey, xa_metadata, -1, 0, error)) + return FALSE; + } #ifdef FLATPAK_ENABLE_P2P g_variant_lookup (commit_metadata, "ostree.collection-binding", "&s", &collection_id); @@ -186,10 +192,6 @@ flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, G if (g_variant_lookup (commit_metadata, "xa.download-size", "t", &download_size)) download_size = GUINT64_FROM_BE (download_size); - metakey = g_key_file_new (); - if (!g_key_file_load_from_data (metakey, xa_metadata, -1, 0, error)) - return FALSE; - parts = g_strsplit (ref, "/", 0); formatted_installed_size = g_format_size (installed_size); formatted_download_size = g_format_size (download_size); @@ -207,7 +209,7 @@ flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, G g_print ("%s%s%s %s\n", on, _("Parent:"), off, parent ? parent : "-"); g_print ("%s%s%s %s\n", on, _("Download size:"), off, formatted_download_size); g_print ("%s%s%s %s\n", on, _("Installed size:"), off, formatted_installed_size); - if (strcmp (parts[0], "app") == 0) + if (strcmp (parts[0], "app") == 0 && metakey != NULL) { g_autofree char *runtime = NULL; runtime = g_key_file_get_string (metakey, "Application", "runtime", error); @@ -287,8 +289,9 @@ flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, G c_m = g_variant_get_child_value (c_v, 0); g_variant_lookup (c_m, "xa.metadata", "&s", &xa_metadata); if (xa_metadata == NULL) - return flatpak_fail (error, "Commit %s has no metadata", c); - g_print ("%s", xa_metadata); + g_printerr (_("Warning: Commit %s has no flatpak metadata\n"), c); + else + g_print ("%s", xa_metadata); } g_free (c); diff --git a/app/flatpak-builtins-info.c b/app/flatpak-builtins-info.c index d611a232..2367adaf 100644 --- a/app/flatpak-builtins-info.c +++ b/app/flatpak-builtins-info.c @@ -181,6 +181,7 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError * const gchar *body = NULL; g_autofree char *parent = NULL; const char *latest; + const char *xa_metadata = NULL; const char *collection_id = NULL; latest = flatpak_dir_read_latest (dir, origin, ref, NULL, NULL, NULL); @@ -196,6 +197,9 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError * formatted_timestamp = format_timestamp (timestamp); commit_metadata = g_variant_get_child_value (commit_v, 0); + g_variant_lookup (commit_metadata, "xa.metadata", "&s", &xa_metadata); + if (xa_metadata == NULL) + g_printerr (_("Warning: Commit has no flatpak metadata\n")); #ifdef FLATPAK_ENABLE_P2P g_variant_lookup (commit_metadata, "ostree.collection-binding", "&s", &collection_id);