createrepo: Add --cut-dirs and --location-prefix options
authorTomas Mlcoch <tmlcoch@redhat.com>
Fri, 22 May 2015 13:34:33 +0000 (15:34 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Fri, 22 May 2015 13:42:49 +0000 (15:42 +0200)
src/cmd_parser.c
src/cmd_parser.h
src/createrepo_c.c
src/dumper_thread.c
src/dumper_thread.h

index 6756615fe6e49bf1f47fccbfbd9e0764e982a32a..4fc14d2185190bc0f8c2f1845c156462fab60091 100644 (file)
@@ -49,6 +49,8 @@ struct CmdOptions _cmd_options = {
         .md_max_age           = 0,
         .cachedir             = NULL,
         .local_sqlite         = DEFAULT_LOCAL_SQLITE,
+        .cut_dirs             = 0,
+        .location_prefix      = NULL,
 
         .deltas               = FALSE,
         .oldpackagedirs       = NULL,
@@ -166,6 +168,11 @@ static GOptionEntry cmd_entries[] =
       "This option could lead to a higher memory consumption "
       "if TMPDIR is set to /tmp or not set at all, because then the /tmp is "
       "used and /tmp dir is often a ramdisk.", NULL },
+    { "cut-dirs", 0, 0, G_OPTION_ARG_INT, &(_cmd_options.cut_dirs),
+      "Ignore NUM of directory components in location_href during repodata "
+      "generation", "NUM" },
+    { "location-prefix", 0, 0, G_OPTION_ARG_FILENAME, &(_cmd_options.location_prefix),
+      "Append this prefix before location_href in output repodata", "PREFIX" },
     { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL },
 };
 
@@ -481,6 +488,13 @@ check_arguments(struct CmdOptions *options,
         x++;
     }
 
+    // Check cut_dirs
+    if (options->cut_dirs < 0) {
+        g_set_error(err, ERR_DOMAIN, CRE_BADARG,
+                    "--cur-dirs value must be possitive integer");
+        return FALSE;
+    }
+
     return TRUE;
 }
 
index 7dc36d7cd5454371fb4ec6be85f20b3b4aba834a..6aabdb54f43512239f6be4e754f0efcf47729c44 100644 (file)
@@ -96,6 +96,11 @@ struct CmdOptions {
                                      temporary files.
                                      For situations when sqlite has a trouble
                                      to gen DBs on NFS mounts. */
+    gint cut_dirs;              /*!< Ignore *num* of directory components
+                                     during repodata generation in location
+                                     href value. */
+    gchar *location_prefix;     /*!< Append this prefix into location_href
+                                     during repodata generation. */
 
     /* Items filled by check_arguments() */
 
index ab39c65bf1d0ac3ed735964ddc91c8af292e9678..69a92eecdf93a53774fae5430647a4805066041e 100644 (file)
@@ -822,6 +822,8 @@ main(int argc, char **argv)
     user_data.max_delta_rpm_size= cmd_options->max_delta_rpm_size;
     user_data.mutex_deltatargetpackages = g_mutex_new();
     user_data.deltatargetpackages = NULL;
+    user_data.cut_dirs          = cmd_options->cut_dirs;
+    user_data.location_prefix   = cmd_options->location_prefix;
 
     g_debug("Thread pool user data ready");
 
index 4ebc1bfbf8dd77afc3532db644c0b9f2aec29687..dd167d7cfaf5d12bbb5fbd827e08fa155644cbf1 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "checksum.h"
+#include "cleanup.h"
 #include "deltarpms.h"
 #include "dumper_thread.h"
 #include "error.h"
@@ -309,8 +310,22 @@ cr_dumper_thread(gpointer data, gpointer user_data)
 
     // get location_href without leading part of path (path to repo)
     // including '/' char
-    const char *location_href = task->full_path + udata->repodir_name_len;
-    const char *location_base = udata->location_base;
+    const gchar *location_base = udata->location_base;
+    _cleanup_free_ gchar *location_href = NULL;
+    location_href = g_strdup(task->full_path + udata->repodir_name_len);
+
+    // User requested modification of the location href
+    if (udata->cut_dirs) {
+        gchar *tmp = location_href;
+        location_href = g_strdup(cr_cut_dirs(location_href, udata->cut_dirs));
+        g_free(tmp);
+    }
+
+    if (udata->location_prefix) {
+        gchar *tmp = location_href;
+        location_href = g_build_filename(udata->location_prefix, tmp, NULL);
+        g_free(tmp);
+    }
 
     // If --cachedir is used, load signatures and hdrid from packages too
     if (udata->checksum_cachedir)
@@ -350,8 +365,8 @@ cr_dumper_thread(gpointer data, gpointer user_data)
                 // We have usable old data, but we have to set proper locations
                 // WARNING! This two lines destructively modifies content of
                 // packages in old metadata.
-                md->location_href = (char *) location_href;
-                md->location_base = (char *) location_base;
+                md->location_href = location_href;
+                md->location_base = location_base;
             }
         }
     }
index 5b797783d89e262c94ecb3911d0823d8decf0b4c..e1ae7158da8898b80ec97445d3eb924eb57b99a3 100644 (file)
@@ -87,6 +87,12 @@ struct UserData {
                                     // deltarpm against
     GMutex *mutex_deltatargetpackages; // Mutex
     GSList *deltatargetpackages;    // List of cr_DeltaTargetPackages
+
+    // Location href modifiers
+    gint cut_dirs;                  // Ignore *num* of directory components
+                                    // in location href path
+    gchar *location_prefix;         // Append this prefix into location_href
+                                    // during repodata generation
 };