From 13283ab6db44646ea4947734744e36b4b27835a8 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Thu, 16 Jan 2025 17:39:05 +0100 Subject: [PATCH] utils: Rename the appstream file when re-saving it on install The as_utils_install_metadata_file() can install the .xml* data re-saved, with added origin reference. When it does so, and the original file was compressed, then the file name extension does not reflect the file content anymore (it's a pure XML after re-saving, not a compressed XML data). That can confuse the Appstream data readers, thus rename the file to be .xml, to avoid this problem. --- src/as-utils.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/as-utils.c b/src/as-utils.c index 958e536b..c335e324 100644 --- a/src/as-utils.c +++ b/src/as-utils.c @@ -2487,13 +2487,37 @@ as_utils_install_metadata_file_internal (const gchar *filename, /* update the origin for XML files */ if (origin != NULL && !is_yaml) { g_autoptr(AsMetadata) mdata = as_metadata_new (); + g_autofree gchar *new_dest = NULL; + gboolean renamed = FALSE; as_metadata_set_locale (mdata, "ALL"); as_metadata_set_format_style (mdata, AS_FORMAT_STYLE_CATALOG); if (!as_metadata_parse_file (mdata, file_dest, AS_FORMAT_KIND_XML, error)) return FALSE; as_metadata_set_origin (mdata, origin); + if (!g_str_has_suffix (path_dest, ".xml")) { + g_autofree gchar *basename_new = g_strdup_printf ("%s.xml", origin); + /* it's an XML file now, name it properly */ + g_unlink (path_dest); + g_clear_pointer (&path_dest, g_free); + path_dest = g_build_filename (path_parent, basename_new, NULL); + renamed = TRUE; + } if (!as_metadata_save_catalog (mdata, path_dest, AS_FORMAT_KIND_XML, error)) return FALSE; + if (renamed) { + g_clear_object (&file_dest); + file_dest = g_file_new_for_path (path_dest); + /* explicitly set permissions on the renamed file */ + if (!g_file_set_attribute_uint32 (file_dest, + G_FILE_ATTRIBUTE_UNIX_MODE, + 0644, + G_FILE_QUERY_INFO_NONE, + NULL, + &tmp_error)) { + g_debug ("Error setting renamed file permissions: %s", tmp_error->message); + g_clear_error (&tmp_error); + } + } } g_chmod (path_dest, 0755);