From: Tomas Mlcoch Date: Wed, 7 Oct 2015 14:45:01 +0000 (+0200) Subject: Add --general-compress-type option (RhBug 1253850) X-Git-Tag: upstream/0.10.0~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0240c8ecee1bde3523f33705daea8c0ddce8893a;p=services%2Fcreaterepo_c.git Add --general-compress-type option (RhBug 1253850) Createrepo_c behaviour is (in most cases) backward compatible with classical createrepo. Classical createrepo doesn't provide a possibility to compress primary, filelists and other xml metadata by different compress algorithm than GZ. To be able to enable this feature in createrepo_c, a new option --general-compress-type was added. Behaviour of this option is basically same as --compress-type except that the specified compress type is used also for the main xml files (primary, filelists, other). This option has priority over the existing options --compress-type and --xz. --- diff --git a/src/cmd_parser.c b/src/cmd_parser.c index 1bc7a2e..bec7605 100644 --- a/src/cmd_parser.c +++ b/src/cmd_parser.c @@ -27,6 +27,7 @@ #include "error.h" #include "compression_wrapper.h" #include "misc.h" +#include "cleanup.h" #define ERR_DOMAIN CREATEREPO_C_ERROR @@ -38,28 +39,29 @@ #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, }; @@ -142,6 +144,9 @@ static GOptionEntry cmd_entries[] = "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), @@ -227,6 +232,36 @@ struct CmdOptions *parse_arguments(int *argc, char ***argv, GError **err) 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, ... @@ -341,21 +376,20 @@ check_arguments(struct CmdOptions *options, // 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; diff --git a/src/cmd_parser.h b/src/cmd_parser.h index 71d43cb..d0d9a27 100644 --- a/src/cmd_parser.h +++ b/src/cmd_parser.h @@ -51,6 +51,8 @@ struct CmdOptions { gboolean no_database; /*!< do not create database */ char *checksum; /*!< type of checksum */ char *compress_type; /*!< which compression type to use */ + char *general_compress_type;/*!< which compression type to use (even for + primary, filelists and other xml) */ gboolean skip_symlinks; /*!< ignore symlinks of packages */ gint changelog_limit; /*!< number of changelog messages in other.(xml|sqlite) */ @@ -117,6 +119,7 @@ struct CmdOptions { cr_ChecksumType checksum_type; /*!< checksum type */ cr_ChecksumType repomd_checksum_type; /*!< checksum type */ cr_CompressionType compression_type; /*!< compression type */ + cr_CompressionType general_compression_type; /*!< compression type */ gint64 md_max_age; /*!< Max age of files in repodata/. Older files will be removed during --update. diff --git a/src/createrepo_c.c b/src/createrepo_c.c index 7b31bab..bfd9777 100644 --- a/src/createrepo_c.c +++ b/src/createrepo_c.c @@ -612,8 +612,10 @@ main(int argc, char **argv) // 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; @@ -630,6 +632,14 @@ main(int argc, char **argv) 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); @@ -650,13 +660,13 @@ main(int argc, char **argv) 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); @@ -673,7 +683,7 @@ main(int argc, char **argv) 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); @@ -692,7 +702,7 @@ main(int argc, char **argv) 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);