createrepo_c support --compress-type param
authorTomas Mlcoch <tmlcoch@redhat.com>
Wed, 27 Jun 2012 08:52:12 +0000 (10:52 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Wed, 27 Jun 2012 08:56:08 +0000 (10:56 +0200)
doc/createrepo_c.8.gz
src/cmd_parser.c
src/cmd_parser.h
src/createrepo_c.c

index 773e1e9..ecb185d 100644 (file)
Binary files a/doc/createrepo_c.8.gz and b/doc/createrepo_c.8.gz differ
index ed6b7f9..301ab9b 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <string.h>
 #include "cmd_parser.h"
+#include "compression_wrapper.h"
 #include "misc.h"
 
 
 #define DEFAULT_UNIQUE_MD_FILENAMES     TRUE
 
 
-struct CmdOptions _cmd_options = {   .changelog_limit = DEFAULT_CHANGELOG_LIMIT,
-                    .checksum = NULL,
-                    .workers =  DEFAULT_WORKERS,
-                    .unique_md_filenames = DEFAULT_UNIQUE_MD_FILENAMES };
+struct CmdOptions _cmd_options = {
+        .changelog_limit     = DEFAULT_CHANGELOG_LIMIT,
+        .checksum            = NULL,
+        .workers             = DEFAULT_WORKERS,
+        .unique_md_filenames = DEFAULT_UNIQUE_MD_FILENAMES,
+        .checksum_type       = PKG_CHECKSUM_SHA256,
+        .compression_type    = UNKNOWN_COMPRESSION
+    };
 
 
 
@@ -91,6 +96,8 @@ static GOptionEntry cmd_entries[] =
       "Number of workers to spawn to read rpms.", NULL },
     { "xz", 0, 0, G_OPTION_ARG_NONE, &(_cmd_options.xz_compression),
       "Use xz for repodata compression.", NULL },
+    { "compress-type", 0, 0, G_OPTION_ARG_STRING, &(_cmd_options.compress_type),
+      "Which compression type to use.", "<compress_type>" },
     { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
 };
 
@@ -157,11 +164,24 @@ gboolean check_arguments(struct CmdOptions *options)
             return FALSE;
         }
         g_string_free(checksum_str, TRUE);
-    } else {
-        options->checksum = g_strdup("sha256");
-        options->checksum_type = PKG_CHECKSUM_SHA256;
     }
 
+    // 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 = GZ_COMPRESSION;
+        } else if (!strcmp(compress_str->str, "bz2")) {
+            options->compression_type = BZ2_COMPRESSION;
+        } else if (!strcmp(compress_str->str, "xz")) {
+            options->compression_type = XZ_COMPRESSION;
+        } else {
+            g_string_free(compress_str, TRUE);
+            g_critical("Unknown/Unsupported compression type \"%s\"", options->compress_type);
+            return FALSE;
+        }
+        g_string_free(compress_str, TRUE);
+    }
 
     int x;
 
@@ -250,6 +270,7 @@ void free_options(struct CmdOptions *options)
     g_free(options->outputdir);
     g_free(options->pkglist);
     g_free(options->checksum);
+    g_free(options->compress_type);
     g_free(options->groupfile);
     g_free(options->groupfile_fullpath);
 
index 5bf2124..87353ed 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <glib.h>
 #include "constants.h"
+#include "compression_wrapper.h"
 
 
 /**
@@ -49,6 +50,7 @@ struct CmdOptions {
     gboolean database;          /*!< create sqlite database metadata - Not implemented yet!!! :( */
     gboolean no_database;       /*!< do not create database - Implemented ;) */
     char *checksum;             /*!< type of checksum */
+    char *compress_type;        /*!< which compression type to use */
     gboolean skip_symlinks;     /*!< ignore symlinks of packages */
     int changelog_limit;        /*!< number of changelog messages in other.(xml|sqlite) */
     gboolean unique_md_filenames;       /*!< include the file checksums in the filenames */
@@ -63,6 +65,7 @@ struct CmdOptions {
     GSList *include_pkgs;       /*!< list of packages to include (build from includepkg options and pkglist file) */
     GSList *l_update_md_paths;  /*!< list of repos from update_md_paths (remote repos are downloaded) */
     ChecksumType checksum_type; /*!< checksum type */
+    CompressionType compression_type; /*!< compression type */
 
 };
 
index 0fb53fe..8233cc8 100644 (file)
@@ -50,9 +50,9 @@ struct UserData {
     DbFilelistsStatements fil_statements;
     DbOtherStatements oth_statements;
     int changelog_limit;
-    char *location_base;
+    const char *location_base;
     int repodir_name_len;
-    char *checksum_type_str;
+    const char *checksum_type_str;
     ChecksumType checksum_type;
     gboolean quiet;
     gboolean verbose;
@@ -137,9 +137,9 @@ void dumper_thread(gpointer data, gpointer user_data) {
     struct PoolTask *task = (struct PoolTask *) data;
 
     // get location_href without leading part of path (path to repo) including '/' char
-    char *location_href = (gchar *) task->full_path + udata->repodir_name_len;
+    const char *location_href = task->full_path + udata->repodir_name_len;
 
-    char *location_base = udata->location_base;
+    const char *location_base = udata->location_base;
 
     // Get stat info about file
     struct stat stat_buf;
@@ -179,8 +179,8 @@ void dumper_thread(gpointer data, gpointer user_data) {
 
         if (old_used) {
             // We have usable old data, but we have to set locations (href and base)
-            md->location_href = location_href;
-            md->location_base = location_base;
+            md->location_href = (char *) location_href;
+            md->location_base = (char *) location_base;
         }
     }
 
@@ -418,17 +418,27 @@ int main(int argc, char **argv) {
     }
 
 
-    // Create and open new compressed files
+    // Setup compression types
 
     const char *sqlite_compression_suffix = NULL;
     CompressionType sqlite_compression = BZ2_COMPRESSION;
     CompressionType groupfile_compression = GZ_COMPRESSION;
+
+    if (cmd_options->compression_type != UNKNOWN_COMPRESSION) {
+        sqlite_compression    = cmd_options->compression_type;
+        groupfile_compression = cmd_options->compression_type;
+    }
+
     if (cmd_options->xz_compression) {
-        sqlite_compression = XZ_COMPRESSION;
+        sqlite_compression    = XZ_COMPRESSION;
         groupfile_compression = XZ_COMPRESSION;
     }
+
     sqlite_compression_suffix = get_suffix(sqlite_compression);
 
+
+    // Create and open new compressed files
+
     CW_FILE *pri_cw_file;
     CW_FILE *fil_cw_file;
     CW_FILE *oth_cw_file;
@@ -510,7 +520,7 @@ int main(int argc, char **argv) {
     user_data.oth_statements    = oth_statements;
     user_data.changelog_limit   = cmd_options->changelog_limit;
     user_data.location_base     = cmd_options->location_base;
-    user_data.checksum_type_str = cmd_options->checksum;
+    user_data.checksum_type_str = get_checksum_name_str(cmd_options->checksum_type);
     user_data.checksum_type     = cmd_options->checksum_type;
     user_data.quiet             = cmd_options->quiet;
     user_data.verbose           = cmd_options->verbose;