]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Improve importing filelists from JSON
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Mar 2023 16:02:08 +0000 (16:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Mar 2023 16:02:08 +0000 (16:02 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/archive.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/package.c

index df1e5ddf72e27b90ccc4984930ca323f1f0024e8..ba80619aaad8283c977b06dc9274cb96a2ad1309 100644 (file)
@@ -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;
 }
 
index 73b9c80af7036fe77637553c77f446ac97e8d479..a24c84876d09ff9fd80050332a1e16ec4a00c62e 100644 (file)
@@ -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);
index 619bedbb16996c80457d40802ca7cedc7a40794a..da6bbd84acbc5a98122df812d8aa762f0e9a02fa 100644 (file)
@@ -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) {