]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
build: Refactor copying packages after the build
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 17:02:29 +0000 (17:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 17:02:29 +0000 (17:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index 8b8bcbdb21446f8f282bdec502ea5935797589cf..8c9f9e56befa6b2c8be253e74b646372a75f2925 100644 (file)
@@ -2298,26 +2298,27 @@ static int pakfire_build_post_check(struct pakfire_build* build) {
 }
 
 static int pakfire_build_copy_package(struct pakfire_ctx* ctx,
-               struct pakfire_package* pkg, void* p) {
+               struct pakfire_package* pkg, void* data) {
        struct pakfire_archive* archive = NULL;
+       const char* target = data;
        char path[PATH_MAX];
        int r;
 
-       const char* target = (const char*)p;
-
+       // Check inputs
        if (!target)
                return -EINVAL;
 
+       // Fetch NEVRA
+       const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
+
        // Fetch the package filename
        const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
-       if (!filename) {
-               r = 1;
-               goto ERROR;
-       }
+       if (!filename)
+               return -EINVAL;
 
        // Format the destination path
        r = pakfire_string_format(path, "%s/%s", target, filename);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Open the archive
@@ -2328,9 +2329,11 @@ static int pakfire_build_copy_package(struct pakfire_ctx* ctx,
        }
 
        // Copy it to its destination
-       r = pakfire_archive_copy(archive, path);
-       if (r)
+       r = pakfire_archive_link_or_copy(archive, path);
+       if (r < 0) {
+               ERROR(ctx, "Could not write %s to %s: %s\n", nevra, path, strerror(-r));
                goto ERROR;
+       }
 
 ERROR:
        if (archive)
@@ -2348,12 +2351,11 @@ static int pakfire_build_copy_packages(struct pakfire_build* build) {
        // Fetch local repository
        local = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
 
-#if 0
        // Copy all packages to the target path
        if (*build->target) {
-               r = pakfire_packagelist_walk(build->packages,
+               r = pakfire_repo_walk_packages(build->repo,
                                pakfire_build_copy_package, build->target, 0);
-               if (r)
+               if (r < 0)
                        goto ERROR;
        }
 
@@ -2361,13 +2363,12 @@ static int pakfire_build_copy_packages(struct pakfire_build* build) {
        if (local) {
                const char* path = pakfire_repo_get_path(local);
                if (path) {
-                       r = pakfire_packagelist_walk(build->packages,
-                                       pakfire_build_copy_package, (void*)path, 0);
-                       if (r)
+                       r = pakfire_repo_walk_packages(build->repo,
+                                       pakfire_build_copy_package, (char*)path, 0);
+                       if (r < 0)
                                goto ERROR;
                }
        }
-#endif
 
 ERROR:
        if (local)