From 095deb6fea1133b9df331b241652415bcdebc571 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 6 Oct 2024 17:23:38 +0000 Subject: [PATCH] libpakfire: Remove the shell convenience function This is not very flexible. Signed-off-by: Michael Tremer --- src/cli/lib/shell.c | 23 ++++++++-- src/libpakfire/build.c | 58 ++++---------------------- src/libpakfire/include/pakfire/build.h | 4 +- src/libpakfire/libpakfire.sym | 3 +- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/src/cli/lib/shell.c b/src/cli/lib/shell.c index 98cf98352..d5e7fe427 100644 --- a/src/cli/lib/shell.c +++ b/src/cli/lib/shell.c @@ -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); diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index aed747cee..68330efc5 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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); } diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index 858b75829..5e4430594 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -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 */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 4005c808a..ce27d9210 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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; -- 2.47.2