]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Remove the shell convenience function
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 17:23:38 +0000 (17:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 17:23:38 +0000 (17:23 +0000)
This is not very flexible.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/shell.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/libpakfire/libpakfire.sym

index 98cf983529d5d1225b7ee670f519606feb185f5b..d5e7fe42747cb6de0f83fd0a0f95971645a08a64 100644 (file)
@@ -75,12 +75,13 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 
 int cli_shell(void* data, int argc, char* argv[]) {
        struct pakfire* pakfire = NULL;
+       struct pakfire_build* build = NULL;
        int r;
 
        struct cli_config* cli_config = data;
 
        struct config config = {
-               .flags        = 0,
+               .flags        = PAKFIRE_BUILD_INTERACTIVE,
                .packages     = {},
                .num_packages = 0,
        };
@@ -95,12 +96,26 @@ int cli_shell(void* data, int argc, char* argv[]) {
        if (r)
                goto ERROR;
 
-       // Run the shell
-       r = pakfire_shell(pakfire, config.packages, config.flags);
-       if (r)
+       // Setup the build environment
+       r = pakfire_build_create(&build, pakfire, NULL, config.flags);
+       if (r) {
+               fprintf(stderr, "Could not setup the build environment: %m\n");
                goto ERROR;
+       }
+
+       // Install any additional packages
+       if (config.num_packages) {
+               r = pakfire_build_install(build, config.packages);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Run shell
+       r = pakfire_build_shell(build);
 
 ERROR:
+       if (build)
+               pakfire_build_unref(build);
        if (pakfire)
                pakfire_unref(pakfire);
 
index aed747ceea0cf7b3ff73f2a85ceebbab81c1d88b..68330efc5d698af77693dcb7f566b37b41b91ba0 100644 (file)
@@ -233,21 +233,6 @@ static int pakfire_build_enable_repos(struct pakfire_build* build) {
        return pakfire_repo_walk(build->pakfire, __pakfire_build_setup_repo, build);
 }
 
-/*
-       Drops the user into a shell
-*/
-static int pakfire_build_shell(struct pakfire_build* build) {
-       int r;
-
-       // Export local repository if running in interactive mode
-       r = pakfire_build_enable_repos(build);
-       if (r)
-               return r;
-
-       // Run shell
-       return pakfire_jail_shell(build->jail);
-}
-
 static int pakfire_build_read_script(struct pakfire_build* build,
                const char* filename, char** buffer, size_t* length) {
        char path[PATH_MAX];
@@ -2427,7 +2412,7 @@ ERROR:
        return r;
 }
 
-static int pakfire_build_install(struct pakfire_build* build, const char** packages) {
+PAKFIRE_EXPORT int pakfire_build_install(struct pakfire_build* build, const char** packages) {
        struct pakfire_transaction* transaction = NULL;
        char* problems = NULL;
        int r;
@@ -2466,46 +2451,21 @@ ERROR:
 }
 
 /*
-       This is a convenience function that sets up a build environment and
-       then drops the user into an interactive shell.
+       Drops the user into a shell
 */
-PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire, const char** packages, int flags) {
-       struct pakfire_build* build = NULL;
+PAKFIRE_EXPORT int pakfire_build_shell(struct pakfire_build* build) {
        int r;
 
-       // Fetch the context
-       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
-
-       // Shells are always interactive
-       flags |= PAKFIRE_BUILD_INTERACTIVE;
-
-       // Create a new build environment
-       r = pakfire_build_create(&build, pakfire, NULL, flags);
-       if (r) {
-               CTX_ERROR(ctx, "Could not create build: %m\n");
-               goto ERROR;
-       }
-
        // Initialize the build environment
        r = pakfire_build_init(build);
        if (r)
-               goto ERROR;
+               return r;
 
-       // Install any additional packages
-       if (packages) {
-               r = pakfire_build_install(build, packages);
-               if (r)
-                       goto ERROR;
-       }
+       // Export local repository if running in interactive mode
+       r = pakfire_build_enable_repos(build);
+       if (r)
+               return r;
 
        // Run shell
-       r = pakfire_build_shell(build);
-
-ERROR:
-       if (build)
-               pakfire_build_unref(build);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
-
-       return r;
+       return pakfire_jail_shell(build->jail);
 }
index 858b7582945a62574ebbe07578ab259e5aafa94d..5e44305948edb966c4c2b994eb16c485d0f17291 100644 (file)
@@ -48,6 +48,8 @@ void pakfire_build_set_log_callback(struct pakfire_build* build,
 int pakfire_build_set_ccache_path(struct pakfire_build* build, const char* path);
 int pakfire_build_set_target(struct pakfire_build* build, const char* target);
 
+int pakfire_build_shell(struct pakfire_build* build);
+
 int pakfire_build_exec(struct pakfire_build* build, const char* path);
 
 int pakfire_build_mkimage(struct pakfire_build* build,
@@ -55,6 +57,6 @@ int pakfire_build_mkimage(struct pakfire_build* build,
 
 int pakfire_build_clean(struct pakfire* pakfire, int flags);
 
-int pakfire_shell(struct pakfire* pakfire, const char** packages, int flags);
+int pakfire_build_install(struct pakfire_build* build, const char** packages);
 
 #endif /* PAKFIRE_BUILD_H */
index 4005c808a59dfd263119aaa030ae44a278ea2a99..ce27d9210dd711cefccf2776ccf02579f541b798 100644 (file)
@@ -77,12 +77,13 @@ global:
        # build
        pakfire_build_create;
        pakfire_build_exec;
+       pakfire_build_install;
        pakfire_build_mkimage;
        pakfire_build_ref;
+       pakfire_build_shell;
        pakfire_build_set_ccache_path;
        pakfire_build_set_target;
        pakfire_build_unref;
-       pakfire_shell;
 
        # buildservice
        pakfire_buildservice_create;