#include "error.h"
#include "compression_wrapper.h"
#include "misc.h"
+#include "cleanup.h"
#define ERR_DOMAIN CREATEREPO_C_ERROR
#define DEFAULT_LOCAL_SQLITE FALSE
struct CmdOptions _cmd_options = {
- .changelog_limit = DEFAULT_CHANGELOG_LIMIT,
- .checksum = NULL,
- .workers = DEFAULT_WORKERS,
- .unique_md_filenames = DEFAULT_UNIQUE_MD_FILENAMES,
- .checksum_type = CR_CHECKSUM_SHA256,
- .retain_old = 0,
- .compression_type = CR_CW_UNKNOWN_COMPRESSION,
- .ignore_lock = DEFAULT_IGNORE_LOCK,
- .md_max_age = G_GINT64_CONSTANT(0),
- .cachedir = NULL,
- .local_sqlite = DEFAULT_LOCAL_SQLITE,
- .cut_dirs = 0,
- .location_prefix = NULL,
- .repomd_checksum = NULL,
-
- .deltas = FALSE,
- .oldpackagedirs = NULL,
- .num_deltas = 1,
- .max_delta_rpm_size = CR_DEFAULT_MAX_DELTA_RPM_SIZE,
-
- .checksum_cachedir = NULL,
- .repomd_checksum_type = CR_CHECKSUM_SHA256,
+ .changelog_limit = DEFAULT_CHANGELOG_LIMIT,
+ .checksum = NULL,
+ .workers = DEFAULT_WORKERS,
+ .unique_md_filenames = DEFAULT_UNIQUE_MD_FILENAMES,
+ .checksum_type = CR_CHECKSUM_SHA256,
+ .retain_old = 0,
+ .compression_type = CR_CW_UNKNOWN_COMPRESSION,
+ .general_compression_type = CR_CW_UNKNOWN_COMPRESSION,
+ .ignore_lock = DEFAULT_IGNORE_LOCK,
+ .md_max_age = G_GINT64_CONSTANT(0),
+ .cachedir = NULL,
+ .local_sqlite = DEFAULT_LOCAL_SQLITE,
+ .cut_dirs = 0,
+ .location_prefix = NULL,
+ .repomd_checksum = NULL,
+
+ .deltas = FALSE,
+ .oldpackagedirs = NULL,
+ .num_deltas = 1,
+ .max_delta_rpm_size = CR_DEFAULT_MAX_DELTA_RPM_SIZE,
+
+ .checksum_cachedir = NULL,
+ .repomd_checksum_type = CR_CHECKSUM_SHA256,
};
"Use xz for repodata compression.", NULL },
{ "compress-type", 0, 0, G_OPTION_ARG_STRING, &(_cmd_options.compress_type),
"Which compression type to use.", "COMPRESSION_TYPE" },
+ { "general-compress-type", 0, 0, G_OPTION_ARG_STRING, &(_cmd_options.general_compress_type),
+ "Which compression type to use (even for primary, filelists and other xml).",
+ "COMPRESSION_TYPE" },
{ "keep-all-metadata", 0, 0, G_OPTION_ARG_NONE, &(_cmd_options.keep_all_metadata),
"Keep groupfile and updateinfo from source repo during update.", NULL },
{ "compatibility", 0, 0, G_OPTION_ARG_NONE, &(_cmd_options.compatibility),
return &(_cmd_options);
}
+/** Convert string to compression type set an error if failed.
+ * @param type_str String with compression type (e.g. "gz")
+ * @param type Pointer to cr_CompressionType variable
+ * @param err Err that will be set in case of error
+ */
+static gboolean
+check_and_set_compression_type(const char *type_str,
+ cr_CompressionType *type,
+ GError **err)
+{
+ assert(!err || *err == NULL);
+
+ _cleanup_string_free_ GString *compress_str = NULL;
+ compress_str = g_string_ascii_down(g_string_new(type_str));
+
+ if (!strcmp(compress_str->str, "gz")) {
+ *type = CR_CW_GZ_COMPRESSION;
+ } else if (!strcmp(compress_str->str, "bz2")) {
+ *type = CR_CW_BZ2_COMPRESSION;
+ } else if (!strcmp(compress_str->str, "xz")) {
+ *type = CR_CW_XZ_COMPRESSION;
+ } else {
+ g_set_error(err, ERR_DOMAIN, CRE_BADARG,
+ "Unknown/Unsupported compression type \"%s\"", type_str);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/** Convert a time period to seconds (gint64 value)
* Format: "[0-9]+[mhd]?"
* Units: m - minutes, h - hours, d - days, ...
// Check and set compression type
if (options->compress_type) {
- GString *compress_str = g_string_ascii_down(g_string_new(options->compress_type));
- if (!strcmp(compress_str->str, "gz")) {
- options->compression_type = CR_CW_GZ_COMPRESSION;
- } else if (!strcmp(compress_str->str, "bz2")) {
- options->compression_type = CR_CW_BZ2_COMPRESSION;
- } else if (!strcmp(compress_str->str, "xz")) {
- options->compression_type = CR_CW_XZ_COMPRESSION;
- } else {
- g_string_free(compress_str, TRUE);
- g_set_error(err, ERR_DOMAIN, CRE_BADARG,
- "Unknown/Unsupported compression type \"%s\"",
- options->compress_type);
+ if (!check_and_set_compression_type(options->compress_type,
+ &(options->compression_type),
+ err)) {
+ return FALSE;
+ }
+ }
+
+ // Check and set general compression type
+ if (options->general_compress_type) {
+ if (!check_and_set_compression_type(options->general_compress_type,
+ &(options->general_compression_type),
+ err)) {
return FALSE;
}
- g_string_free(compress_str, TRUE);
}
int x;
// Setup compression types
+ const char *xml_compression_suffix = NULL;
const char *sqlite_compression_suffix = NULL;
const char *prestodelta_compression_suffix = NULL;
+ cr_CompressionType xml_compression = CR_CW_GZ_COMPRESSION;
cr_CompressionType sqlite_compression = CR_CW_BZ2_COMPRESSION;
cr_CompressionType groupfile_compression = CR_CW_GZ_COMPRESSION;
cr_CompressionType prestodelta_compression = CR_CW_GZ_COMPRESSION;
prestodelta_compression = CR_CW_GZ_COMPRESSION;
}
+ if (cmd_options->general_compression_type) {
+ xml_compression = cmd_options->general_compression_type;
+ sqlite_compression = cmd_options->general_compression_type;
+ groupfile_compression = cmd_options->general_compression_type;
+ prestodelta_compression = cmd_options->general_compression_type;
+ }
+
+ xml_compression_suffix = cr_compression_suffix(xml_compression);
sqlite_compression_suffix = cr_compression_suffix(sqlite_compression);
prestodelta_compression_suffix = cr_compression_suffix(prestodelta_compression);
g_message("Temporary output repo path: %s", tmp_out_repo);
g_debug("Creating .xml.gz files");
- pri_xml_filename = g_strconcat(tmp_out_repo, "/primary.xml.gz", NULL);
- fil_xml_filename = g_strconcat(tmp_out_repo, "/filelists.xml.gz", NULL);
- oth_xml_filename = g_strconcat(tmp_out_repo, "/other.xml.gz", NULL);
+ pri_xml_filename = g_strconcat(tmp_out_repo, "/primary.xml", xml_compression_suffix, NULL);
+ fil_xml_filename = g_strconcat(tmp_out_repo, "/filelists.xml", xml_compression_suffix, NULL);
+ oth_xml_filename = g_strconcat(tmp_out_repo, "/other.xml", xml_compression_suffix, NULL);
pri_stat = cr_contentstat_new(cmd_options->repomd_checksum_type, NULL);
pri_cr_file = cr_xmlfile_sopen_primary(pri_xml_filename,
- CR_CW_GZ_COMPRESSION,
+ xml_compression,
pri_stat,
&tmp_err);
assert(pri_cr_file || tmp_err);
fil_stat = cr_contentstat_new(cmd_options->repomd_checksum_type, NULL);
fil_cr_file = cr_xmlfile_sopen_filelists(fil_xml_filename,
- CR_CW_GZ_COMPRESSION,
+ xml_compression,
fil_stat,
&tmp_err);
assert(fil_cr_file || tmp_err);
oth_stat = cr_contentstat_new(cmd_options->repomd_checksum_type, NULL);
oth_cr_file = cr_xmlfile_sopen_other(oth_xml_filename,
- CR_CW_GZ_COMPRESSION,
+ xml_compression,
oth_stat,
&tmp_err);
assert(oth_cr_file || tmp_err);