Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Schreiner <schreiner@suse.de>2016-04-07 01:38:41 +0300
committerFrank Schreiner <schreiner@suse.de>2016-04-07 01:49:39 +0300
commitf170796c64ce163ac83a28fa76e1f828261827bd (patch)
tree2e468090baedb31be7616e41e6c364a8324a12c6
parent1f808e464bbc7cd03459fd0326736261a9a570d5 (diff)
optimized memory usage
-rw-r--r--src/createrepo_c.c3
-rw-r--r--src/dumper_thread.c41
-rw-r--r--src/package.c2
-rw-r--r--src/package.h2
4 files changed, 23 insertions, 25 deletions
diff --git a/src/createrepo_c.c b/src/createrepo_c.c
index 7f028ec..31864fe 100644
--- a/src/createrepo_c.c
+++ b/src/createrepo_c.c
@@ -826,6 +826,7 @@ main(int argc, char **argv)
user_data.fil_db = fil_db;
user_data.oth_db = oth_db;
user_data.changelog_limit = cmd_options->changelog_limit;
+ user_data.location_base = cmd_options->location_base;
user_data.checksum_type_str = cr_checksum_name_str(cmd_options->checksum_type);
user_data.checksum_type = cmd_options->checksum_type;
user_data.checksum_cachedir = cmd_options->checksum_cachedir;
@@ -852,8 +853,6 @@ main(int argc, char **argv)
user_data.cut_dirs = cmd_options->cut_dirs;
user_data.location_prefix = cmd_options->location_prefix;
- user_data.location_base = cmd_options->location_base;
-
g_debug("Thread pool user data ready");
// Start pool
diff --git a/src/dumper_thread.c b/src/dumper_thread.c
index e887ffb..e1e6193 100644
--- a/src/dumper_thread.c
+++ b/src/dumper_thread.c
@@ -34,7 +34,6 @@
#include "misc.h"
#include "parsepkg.h"
#include "xml_dump.h"
-#include "package.h"
#define MAX_TASK_BUFFER_LEN 20
#define CACHEDCHKSUM_BUFFER_LEN 2048
@@ -44,6 +43,7 @@ struct BufferedTask {
struct cr_XmlStruct res; // XML for primary, filelists and other
cr_Package *pkg; // Package structure
char *location_href; // location_href path
+ char *location_base; // location_base path
int pkg_from_md; // If true - package structure if from
// old metadata and must not be freed!
// If false - package is from file and
@@ -222,7 +222,7 @@ exit:
return checksum;
}
-int prepare_split_media_baseurl(int media_id,const char *location_base,cr_Package *pkg)
+gchar * prepare_split_media_baseurl(int media_id,const char *location_base,cr_Package *pkg)
{
// default location_base "media:" in split mode
if (!location_base)
@@ -234,13 +234,10 @@ int prepare_split_media_baseurl(int media_id,const char *location_base,cr_Packag
strcpy(t_location_base, location_base);
if (lb_length > 3 && g_strcmp0(location_base + lb_length - 3, "://") == 0)
lb_length -= 2;
- sprintf(t_location_base + lb_length, "#%d", media_id);
-
- pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, t_location_base);
- g_free(t_location_base);
+ sprintf(t_location_base + lb_length, "#%d", media_id);
- return 0;
+ return t_location_base;
}
static cr_Package *
@@ -266,15 +263,17 @@ load_rpm(const char *fullpath,
if (!pkg)
goto errexit;
+ pkg->location_href = cr_safe_string_chunk_insert(pkg->chunk, location_href);
if (!media_id) {
pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, location_base);
} else {
// calculate location_base
- prepare_split_media_baseurl(media_id, location_base, pkg);
+ gchar *t_location_base = prepare_split_media_baseurl(media_id, location_base, pkg);
+ pkg->location_base = cr_safe_string_chunk_insert(pkg->chunk, t_location_base);
+ g_free(t_location_base);
}
- pkg->location_href = cr_safe_string_chunk_insert(pkg->chunk, location_href);
// Get checksum type string
pkg->checksum_type = cr_safe_string_chunk_insert(pkg->chunk,
@@ -341,10 +340,12 @@ cr_dumper_thread(gpointer data, gpointer user_data)
// get location_href without leading part of path (path to repo)
// including '/' char
- const gchar *location_base = udata->location_base;
_cleanup_free_ gchar *location_href = NULL;
location_href = g_strdup(task->full_path + udata->repodir_name_len);
+ _cleanup_free_ gchar *location_base = NULL;
+ location_base = g_strdup(udata->location_base);
+
// User requested modification of the location href
if (udata->cut_dirs) {
gchar *tmp = location_href;
@@ -431,11 +432,11 @@ cr_dumper_thread(gpointer data, gpointer user_data)
} else {
// Just gen XML from old loaded metadata
if ( task->media_id ) {
- // need chunk to store location_base foreach package
- if ( ! md->chunk )
- md->chunk = g_string_chunk_new (PACKAGE_CHUNK_SIZE);
-
- prepare_split_media_baseurl(task->media_id, location_base, md);
+ _cleanup_free_ gchar *t_location_base;
+ t_location_base = prepare_split_media_baseurl(task->media_id, location_base, md);
+ g_free(location_base);
+ location_base = g_strdup(t_location_base);
+ md->location_base = location_base;
}
pkg = md;
res = cr_xml_dump(md, &tmp_err);
@@ -492,11 +493,11 @@ cr_dumper_thread(gpointer data, gpointer user_data)
if (pkg == md) {
// We MUST store location_href for reused packages who goes to the buffer
- // We don't need to store location_base because it is allocated in
- // user_data during this function calls.
-
buf_task->location_href = g_strdup(location_href);
buf_task->pkg->location_href = buf_task->location_href;
+
+ buf_task->location_base = g_strdup(location_base);
+ buf_task->pkg->location_base = buf_task->location_base;
}
g_queue_insert_sorted(udata->buffer, buf_task, buf_task_sort_func, NULL);
@@ -518,8 +519,6 @@ cr_dumper_thread(gpointer data, gpointer user_data)
// Clean up
if (pkg != md)
cr_package_free(pkg);
- else
- g_string_chunk_free(md->chunk);
g_free(res.primary);
g_free(res.filelists);
g_free(res.other);
@@ -568,7 +567,7 @@ task_cleanup:
if (!buf_task->pkg_from_md)
cr_package_free(buf_task->pkg);
else
- g_string_chunk_free(buf_task->pkg->chunk);
+ g_free(buf_task->location_base);
g_free(buf_task->res.primary);
g_free(buf_task->res.filelists);
g_free(buf_task->res.other);
diff --git a/src/package.c b/src/package.c
index 30d5cb6..c026c32 100644
--- a/src/package.c
+++ b/src/package.c
@@ -22,6 +22,8 @@
#include "package.h"
#include "misc.h"
+#define PACKAGE_CHUNK_SIZE 2048
+
cr_Dependency *
cr_dependency_new(void)
{
diff --git a/src/package.h b/src/package.h
index fc1324a..be061ad 100644
--- a/src/package.h
+++ b/src/package.h
@@ -28,8 +28,6 @@ extern "C" {
#include <glib.h>
-#define PACKAGE_CHUNK_SIZE 2048
-
/** \defgroup package Package representation.
* \addtogroup package
* @{