diff options
author | Pavel Raiskup <praiskup@redhat.com> | 2022-08-09 17:52:27 +0300 |
---|---|---|
committer | amatej <matej.ales@seznam.cz> | 2022-11-03 18:51:36 +0300 |
commit | ef4c669881626e9d76085b0efd5d1815c9c50b1f (patch) | |
tree | b885c01922904c7977bd56afa8fb8a64b5d226ad | |
parent | d8da644c45bec1429d600c619ce4e47af5906ef8 (diff) |
Make the --update old_metadata override hack simpler
Even though we are destructively changing the recycled cr_Packages data,
we can keep the structure self-contained so the upper level logic will
automatically take care of the allocated memory.
The recycled metadata cr_Packages use one chunk per all packages
(CR_PACKAGE_SINGLE_CHUNK). That's why (pkg->chunk == NULL) and we can
re-use it for a new chunk. We just need to change the type of pkg to
!CR_PACKAGE_SINGLE_CHUNK so the cr_package_free() cleans the new
chunk.
This allows us to stop taking care of the locally allocated location_*
variables, because they are _cleanup_free_. This makes even the buffer
handling simpler.
-rw-r--r-- | src/dumper_thread.c | 31 | ||||
-rw-r--r-- | src/package.h | 2 |
2 files changed, 12 insertions, 21 deletions
diff --git a/src/dumper_thread.c b/src/dumper_thread.c index b949ffb..52bdc6f 100644 --- a/src/dumper_thread.c +++ b/src/dumper_thread.c @@ -43,8 +43,6 @@ struct BufferedTask { long id; // ID of the task 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 @@ -472,14 +470,20 @@ cr_dumper_thread(gpointer data, gpointer user_data) } if (old_used) { + // CR_PACKAGE_SINGLE_CHUNK used with the preloaded (old) + // metadata. Create a new per-package chunk. + assert (!md->chunk); + md->chunk = g_string_chunk_new(1024); + md->loadingflags &= ~CR_PACKAGE_SINGLE_CHUNK; + // 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 = location_href; - md->location_base = location_base; - // ^^^ The location_base not location_href are properly saved - // into pkg chunk this is intentional as after the metadata - // are written (dumped) none should use them again. + md->location_href = cr_safe_string_chunk_insert(md->chunk, location_href); + md->location_base = cr_safe_string_chunk_insert(md->chunk, location_base); + // ^^^ The location_base and location_href create a new data + // chunk, even though the rest of the metadata is stored in the + // global chunk (shared with all packages). } } } @@ -581,19 +585,8 @@ cr_dumper_thread(gpointer data, gpointer user_data) buf_task->id = task->id; buf_task->res = res; buf_task->pkg = pkg; - buf_task->location_href = NULL; - buf_task->location_base = NULL; buf_task->pkg_from_md = (pkg == md) ? 1 : 0; - if (pkg == md) { - // We MUST store locations for reused packages who goes to the buffer - 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); g_mutex_unlock(&(udata->mutex_buffer)); @@ -661,8 +654,6 @@ task_cleanup: g_free(buf_task->res.primary); g_free(buf_task->res.filelists); g_free(buf_task->res.other); - g_free(buf_task->location_href); - g_free(buf_task->location_base); g_free(buf_task); } else { g_mutex_unlock(&(udata->mutex_buffer)); diff --git a/src/package.h b/src/package.h index be061ad..908fb2b 100644 --- a/src/package.h +++ b/src/package.h @@ -40,7 +40,7 @@ typedef enum { CR_PACKAGE_LOADED_PRI = (1<<10), /*!< Primary metadata was loaded */ CR_PACKAGE_LOADED_FIL = (1<<11), /*!< Filelists metadata was loaded */ CR_PACKAGE_LOADED_OTH = (1<<12), /*!< Other metadata was loaded */ - CR_PACKAGE_SINGLE_CHUNK = (1<<13), /*!< Package uses single chunk */ + CR_PACKAGE_SINGLE_CHUNK = (1<<13), /*!< Package shares a single chunk with others */ } cr_PackageLoadingFlags; /** Dependency (Provides, Conflicts, Obsoletes, Requires). |