]> git.ipfire.org Git - pakfire.git/commitdiff
package: Refactor reading the filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Oct 2022 10:30:24 +0000 (10:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Oct 2022 10:30:24 +0000 (10:30 +0000)
The old approach never returned any results. This one finally works.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c

index 6092a4db45b6af47a0cd7f32f004701f4f82cf5d..29db983794ad657fd0aa69b0c1de81f240ead9e6 100644 (file)
@@ -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;
 }