]> git.ipfire.org Git - pakfire.git/commitdiff
build: Set default target
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:23:18 +0000 (16:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:23:18 +0000 (16:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index addfc69633cd4ad629b1ddbfc91a7c150a02f915..ea0c36f15ae36ea5aa92de6e604b7fbe61b130f2 100644 (file)
@@ -52,6 +52,8 @@ struct pakfire_build {
        uuid_t id;
        char _id[UUID_STR_LEN];
 
+       char target[PATH_MAX];
+
        // cgroup
        struct pakfire_cgroup* cgroup;
 
@@ -822,6 +824,32 @@ static int pakfire_build_parse_id(struct pakfire_build* build, const char* id) {
        return 0;
 }
 
+/*
+       Sets the default target
+*/
+static int pakfire_build_set_default_target(struct pakfire_build* build) {
+       // Look for the "local" repository
+       struct pakfire_repo* repo = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
+       if (repo) {
+               const char* target = pakfire_repo_get_path(repo);
+               if (target)
+                       pakfire_string_set(build->target, target);
+
+               pakfire_repo_unref(repo);
+       }
+
+       // Default to the current working directory
+       if (!*build->target) {
+               char* cwd = getcwd(build->target, sizeof(build->target));
+               if (!cwd) {
+                       ERROR(build->pakfire, "getcwd() failed: %m\n");
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 /*
        Sets up a new cgroup for this build
 */
@@ -895,6 +923,11 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
        if (r)
                goto ERROR;
 
+       // Set target
+       r = pakfire_build_set_default_target(b);
+       if (r)
+               goto ERROR;
+
        // Create cgroup
        r = pakfire_build_setup_cgroup(b);
        if (r)