Skip to content

Commit

Permalink
utils: Rename the appstream file when re-saving it on install
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcrha committed Jan 16, 2025
1 parent 530cadc commit 13283ab
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/as-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 13283ab

Please sign in to comment.