From 9da8ddfcc46c3d4722d62d2f81d8794020109e90 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 5 Mar 2023 16:02:08 +0000 Subject: [PATCH] archive: Improve importing filelists from JSON We no longer build a completely filelist object that is being destroyed very quickly again. The paths are being sent directly to the package. Signed-off-by: Michael Tremer --- src/libpakfire/archive.c | 59 ++++-------------------- src/libpakfire/include/pakfire/package.h | 3 ++ src/libpakfire/package.c | 2 +- 3 files changed, 12 insertions(+), 52 deletions(-) diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index df1e5ddf..ba80619a 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -992,14 +992,11 @@ int pakfire_archive_check_digest(struct pakfire_archive* archive, return r; } -static int pakfire_archive_make_filelist_from_json(struct pakfire_archive* archive, - struct pakfire_filelist** filelist) { +static int pakfire_archive_import_filelist_from_json( + struct pakfire_archive* archive, struct pakfire_package* package) { struct json_object* array = NULL; int r; - struct pakfire_filelist* list = NULL; - struct pakfire_file* file = NULL; - // Fetch the array with the filelist array = pakfire_archive_metadata_get_object(archive, "filelist", NULL); if (!array) { @@ -1014,11 +1011,6 @@ static int pakfire_archive_make_filelist_from_json(struct pakfire_archive* archi if (!length) return 0; - // Create a new filelist object - r = pakfire_filelist_create(&list, archive->pakfire); - if (r) - goto ERROR; - // Walk through all items in this array for (unsigned int i = 0; i < length; i++) { struct json_object* item = json_object_array_get_idx(array, i); @@ -1030,43 +1022,18 @@ static int pakfire_archive_make_filelist_from_json(struct pakfire_archive* archi if (!path) continue; - // Create a new file object - r = pakfire_file_create(&file, archive->pakfire); + // Append the file to the package + r = pakfire_package_append_file(package, path); if (r) - goto ERROR; - - // Set path - r = pakfire_file_set_path(file, path); - if (r) { - pakfire_file_unref(file); - goto ERROR; - } - - // Append the file to the filelist - r = pakfire_filelist_add(list, file); - if (r) { - pakfire_file_unref(file); - goto ERROR; - } - - // Cleanup - pakfire_file_unref(file); + return r; } - // Reference the filelist - *filelist = pakfire_filelist_ref(list); - -ERROR: - if (list) - pakfire_filelist_unref(list); - - return r; + return 0; } static int pakfire_archive_make_package_from_json(struct pakfire_archive* archive, struct pakfire_repo* repo, struct pakfire_package** package) { struct pakfire_package* pkg = NULL; - struct pakfire_filelist* filelist = NULL; int r; // Calculate digest @@ -1269,26 +1236,16 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv } } - // Fetch the filelist - r = pakfire_archive_make_filelist_from_json(archive, &filelist); + // Import the filelist + r = pakfire_archive_import_filelist_from_json(archive, pkg); if (r) goto ERROR; - // Store the filelist - if (filelist) { - r = pakfire_package_set_filelist(pkg, filelist); - if (r) - goto ERROR; - } - // Success! *package = pkg; r = 0; ERROR: - if (filelist) - pakfire_filelist_unref(filelist); - return r; } diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 73b9c80a..a24c8487 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -149,6 +149,9 @@ char* pakfire_package_join_evr(const char* e, const char* v, const char* r); int pakfire_package_is_installed(struct pakfire_package* pkg); +// Filelist +int pakfire_package_append_file(struct pakfire_package* pkg, const char* path); + // Dependencies int pakfire_package_add_dep(struct pakfire_package* pkg, const enum pakfire_package_key key, const char* dep); diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 619bedbb..da6bbd84 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -1527,7 +1527,7 @@ ERROR: return NULL; } -static int pakfire_package_append_file(struct pakfire_package* pkg, const char* path) { +int pakfire_package_append_file(struct pakfire_package* pkg, const char* path) { // Fetch repodata struct pakfire_repo* repo = pakfire_package_get_repo(pkg); if (!repo) { -- 2.47.3