From: Tomas Mlcoch Date: Fri, 22 May 2015 13:34:33 +0000 (+0200) Subject: createrepo: Add --cut-dirs and --location-prefix options X-Git-Tag: upstream/0.10.0~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c98fe13c89822f3b2c7b44a3a2c9a1aed6cec4c;p=services%2Fcreaterepo_c.git createrepo: Add --cut-dirs and --location-prefix options --- diff --git a/src/cmd_parser.c b/src/cmd_parser.c index 6756615..4fc14d2 100644 --- a/src/cmd_parser.c +++ b/src/cmd_parser.c @@ -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; } diff --git a/src/cmd_parser.h b/src/cmd_parser.h index 7dc36d7..6aabdb5 100644 --- a/src/cmd_parser.h +++ b/src/cmd_parser.h @@ -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() */ diff --git a/src/createrepo_c.c b/src/createrepo_c.c index ab39c65..69a92ee 100644 --- a/src/createrepo_c.c +++ b/src/createrepo_c.c @@ -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"); diff --git a/src/dumper_thread.c b/src/dumper_thread.c index 4ebc1bf..dd167d7 100644 --- a/src/dumper_thread.c +++ b/src/dumper_thread.c @@ -27,6 +27,7 @@ #include #include #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; } } } diff --git a/src/dumper_thread.h b/src/dumper_thread.h index 5b79778..e1ae715 100644 --- a/src/dumper_thread.h +++ b/src/dumper_thread.h @@ -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 };