From 843fa80361e3737b57176f2074ecf20c7a2ec934 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 27 Oct 2022 10:30:24 +0000 Subject: [PATCH] package: Refactor reading the filelist The old approach never returned any results. This one finally works. Signed-off-by: Michael Tremer --- src/libpakfire/package.c | 84 +++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 6092a4db4..29db98379 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -1374,37 +1374,80 @@ PAKFIRE_EXPORT struct pakfire_archive* pakfire_package_get_archive(struct pakfir return archive; } -static int pakfire_package_fetch_filelist(struct pakfire_package* pkg, struct pakfire_filelist* filelist) { +struct pakfire_package_filelist_search { + struct pakfire* pakfire; + struct pakfire_filelist* filelist; + int r; +}; + +static int __pakfire_package_fetch_filelist(void* data, Solvable* s, Repodata* repodata, + Repokey* key, struct s_KeyValue* kv) { + struct pakfire_package_filelist_search* search = (struct pakfire_package_filelist_search*)data; + struct pakfire_file* file = NULL; - Dataiterator di; - int r = 0; + int r; - pakfire_package_internalize_repo(pkg); + // Skip any results of the wrong type + if (key->type != REPOKEY_TYPE_DIRSTRARRAY) + return 0; - Solvable* s = get_solvable(pkg); + // Fetch the path + const char* path = repodata_dir2str(repodata, kv->id, kv->str); + if (!path) { + r = 1; + goto ERROR; + } - dataiterator_init(&di, s->repo->pool, s->repo, pkg->id, - SOLVABLE_FILELIST, NULL, SEARCH_FILES | SEARCH_COMPLETE_FILELIST); + // Create a new file entry + r = pakfire_file_create(&file, search->pakfire); + if (r) + goto ERROR; - while (dataiterator_step(&di)) { - r = pakfire_file_create(&file, pkg->pakfire); - if (r) - goto ERROR; + // Set path + r = pakfire_file_set_path(file, path); + if (r) + goto ERROR; - pakfire_file_set_path(file, di.kv.str); + // Append the file to the filelist + r = pakfire_filelist_append(search->filelist, file); + if (r) + goto ERROR; + +ERROR: + // Store the error code + search->r = r; - // Append to filelist - pakfire_filelist_append(filelist, file); + if (file) pakfire_file_unref(file); - } -ERROR: - dataiterator_free(&di); + return r; +} + +static int pakfire_package_fetch_filelist(struct pakfire_package* pkg, struct pakfire_filelist* filelist) { + struct pakfire_package_filelist_search search = { + .pakfire = pkg->pakfire, + .filelist = filelist, + .r = 0, + }; - // Sort the list + pakfire_package_internalize_repo(pkg); + + Solvable* s = get_solvable(pkg); + + Repodata* repodata = repo_last_repodata(s->repo); + + // Search for all files + repodata_search(repodata, pkg->id, SOLVABLE_FILELIST, SEARCH_FILES, + __pakfire_package_fetch_filelist, &search); + + // Break on any error + if (search.r) + return search.r; + + // Sort the result pakfire_filelist_sort(filelist); - return r; + return search.r; } PAKFIRE_EXPORT struct pakfire_filelist* pakfire_package_get_filelist(struct pakfire_package* pkg) { @@ -1454,6 +1497,9 @@ static int pakfire_package_append_file(struct pakfire_package* pkg, const char* pakfire_repo_unref(repo); + // This package has changed + pakfire_package_has_changed(pkg); + return 0; } -- 2.39.5