]> git.ipfire.org Git - pakfire.git/commitdiff
build: Copy the result to the local repository and target
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 16:44:18 +0000 (16:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 16:44:18 +0000 (16:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index ae4f5c882b2cab3022ec8660e76a4819b4b9b7f4..6e304717bc1bf5b0bc524ae1c34fa95f5cd85e5c 100644 (file)
@@ -1270,9 +1270,95 @@ static int pakfire_build_post_check(struct pakfire_build* build) {
        if (r)
                return r;
 
+#if 0
+       // Perform install test
+       r = pakfire_build_install_test(build);
+       if (r)
+               return r;
+#endif
+
        return 0;
 }
 
+static int pakfire_build_copy_package(struct pakfire* pakfire,
+               struct pakfire_package* pkg, void* p) {
+       struct pakfire_archive* archive = NULL;
+       char path[PATH_MAX];
+       int r;
+
+       const char* target = (const char*)p;
+
+       if (!target) {
+               errno = EINVAL;
+               return 1;
+       }
+
+       // Fetch the package filename
+       const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
+       if (!filename) {
+               r = 1;
+               goto ERROR;
+       }
+
+       // Format the destination path
+       r = pakfire_string_format(path, "%s/%s", target, filename);
+       if (r)
+               goto ERROR;
+
+       // Open the archive
+       archive = pakfire_package_get_archive(pkg);
+       if (!archive) {
+               r = 1;
+               goto ERROR;
+       }
+
+       // Copy it to its destination
+       r = pakfire_archive_copy(archive, path);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (archive)
+               pakfire_archive_unref(archive);
+
+       return r;
+}
+
+static int pakfire_build_copy_packages(struct pakfire_build* build) {
+       struct pakfire_repo* local = NULL;
+       int r = 0;
+
+       DEBUG(build->pakfire, "Copying built packages\n");
+
+       // Fetch local repository
+       local = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
+
+       // Copy all packages to the target path
+       if (*build->target) {
+               r = pakfire_packagelist_walk(build->packages,
+                       pakfire_build_copy_package, build->target);
+               if (r)
+                       goto ERROR;
+       }
+
+       // If we have a local repository, we copy all packages to it
+       if (local) {
+               const char* path = pakfire_repo_get_path(local);
+               if (path) {
+                       r = pakfire_packagelist_walk(build->packages,
+                               pakfire_build_copy_package, (void*)path);
+                       if (r)
+                               goto ERROR;
+               }
+       }
+
+ERROR:
+       if (local)
+               pakfire_repo_unref(local);
+
+       return r;
+}
+
 PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
        struct pakfire_archive* archive = NULL;
        struct pakfire_package* package = NULL;
@@ -1349,6 +1435,11 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        if (r)
                goto ERROR;
 
+       // Copy packages to their destination
+       r = pakfire_build_copy_packages(build);
+       if (r)
+               goto ERROR;
+
 ERROR:
        if (makefile)
                pakfire_parser_unref(makefile);