Skip to content

Commit

Permalink
Extract groupfile (re)compression so it can be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura authored and Conan-Kudo committed Jul 24, 2023
1 parent 60ee8dc commit 669870f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
20 changes: 1 addition & 19 deletions src/createrepo_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,25 +847,7 @@ main(int argc, char **argv)

// Groupfile specified as argument
if (cmd_options->groupfile_fullpath) {
gchar *compressed_path;
cr_CompressionType old_type = cr_detect_compression(cmd_options->groupfile_fullpath, &tmp_err);
if (tmp_err) {
compressed_path = g_strconcat(tmp_out_repo, cr_get_filename(cmd_options->groupfile_fullpath), compression_suffix, NULL);
g_debug("Unable to detect compression type of %s, using %s for groupfile.", cmd_options->groupfile_fullpath, compressed_path);
g_clear_error(&tmp_err);
} else if (old_type == CR_CW_NO_COMPRESSION) {
compressed_path = g_strconcat(tmp_out_repo, cr_get_filename(cmd_options->groupfile_fullpath), compression_suffix, NULL);
} else {
// strip compression suffix
_cleanup_free_ gchar *tmp_file = g_strndup(cmd_options->groupfile_fullpath, strlen(cmd_options->groupfile_fullpath) - strlen(cr_compression_suffix(old_type)));
compressed_path = g_strconcat(tmp_out_repo, cr_get_filename(tmp_file), compression_suffix, NULL);
}
if (cr_compress_file(cmd_options->groupfile_fullpath, compressed_path, compression, NULL, NULL, &tmp_err) != CRE_OK) {
g_critical("Cannot compress file: %s: %s", cmd_options->groupfile_fullpath,
(tmp_err ? tmp_err->message : "Unknown error"));
g_clear_error(&tmp_err);
exit(EXIT_FAILURE);
}
gchar *compressed_path = cr_compress_groupfile(cmd_options->groupfile_fullpath, tmp_out_repo, compression);
cr_Metadatum *new_groupfile_metadatum = g_malloc0(sizeof(cr_Metadatum));
new_groupfile_metadatum->name = compressed_path;
new_groupfile_metadatum->type = g_strdup("group");
Expand Down
28 changes: 28 additions & 0 deletions src/load_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,31 @@ cr_metadata_locate_and_load_xml(cr_Metadata *md,

return ret;
}

gchar *
cr_compress_groupfile(const char *groupfile, const char *dest_dir, cr_CompressionType compression)
{
const char *compression_suffix = cr_compression_suffix(compression);
GError *tmp_err = NULL;
gchar *compressed_path;
cr_CompressionType old_type = cr_detect_compression(groupfile, &tmp_err);
if (tmp_err) {
compressed_path = g_strconcat(dest_dir, cr_get_filename(groupfile), compression_suffix, NULL);
g_debug("Unable to detect compression type of %s, using %s for groupfile.", groupfile, compressed_path);
g_clear_error(&tmp_err);
} else if (old_type == CR_CW_NO_COMPRESSION) {
compressed_path = g_strconcat(dest_dir, cr_get_filename(groupfile), compression_suffix, NULL);
} else {
// strip compression suffix
gchar *tmp_file = g_strndup(groupfile, strlen(groupfile) - strlen(cr_compression_suffix(old_type)));
compressed_path = g_strconcat(dest_dir, cr_get_filename(tmp_file), compression_suffix, NULL);
g_free(tmp_file);
}
if (cr_compress_file(groupfile, compressed_path, compression, NULL, 0, &tmp_err) != CRE_OK) {
g_critical("Cannot compress file: %s: %s", groupfile,
(tmp_err ? tmp_err->message : "Unknown error"));
g_clear_error(&tmp_err);
exit(EXIT_FAILURE);
}
return compressed_path;
}
11 changes: 11 additions & 0 deletions src/metadata_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ cr_metadata_load_modulemd(ModulemdModuleIndex **moduleindex,
gchar *path_to_md,
GError **err);

/** Compress groupfile into dest_dir with specified compression.
* @param groupfile Path to local groupfile, it can be already compressed by
* some compression.
* @param dest_dir Path to directory where the compressed groupfile should be stored.
* @return Path to the new compressed groupfile. Has to be freed by the caller.
*/
gchar *
cr_compress_groupfile(const char *groupfile,
const char *dest_dir,
cr_CompressionType compression);


#endif /* WITH_LIBMODULEMD */

Expand Down

0 comments on commit 669870f

Please sign in to comment.