From 4d03145b5831a712bb6fab9d9b65040a9982955a Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Wed, 1 Mar 2023 12:51:39 +0100 Subject: [PATCH] pkg-register ignores failed pre-install/post-install scripts (#2073) When a package is registered through pkg-register(8) the return codes of pre-install and post-install scripts and lua files are ignored. Now they are respected as with pkg-add(8). This fixes #2073 --- libpkg/pkg_add.c | 6 ++++-- libpkg/pkg_ports.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libpkg/pkg_add.c b/libpkg/pkg_add.c index a14f63eea2..f6432ae3d9 100644 --- a/libpkg/pkg_add.c +++ b/libpkg/pkg_add.c @@ -1357,8 +1357,10 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags, if (retcode != EPKG_OK) goto cleanup; if ((flags & PKG_ADD_NOSCRIPT) == 0) { - pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, (local != NULL)); - pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, (local != NULL)); + if ((retcode = pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, (local != NULL))) != EPKG_OK) + goto cleanup; + if ((retcode = pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, (local != NULL))) != EPKG_OK) + goto cleanup; } /* diff --git a/libpkg/pkg_ports.c b/libpkg/pkg_ports.c index 60e93cb54d..080c2e72fb 100644 --- a/libpkg/pkg_ports.c +++ b/libpkg/pkg_ports.c @@ -1214,8 +1214,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path, if (!testing) { /* Execute pre-install scripts */ - pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false); - pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false); + if ((rc = pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false)) != EPKG_OK) + goto cleanup; + if ((rc = pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false)) != EPKG_OK) + goto cleanup; if (input_path != NULL) { pkg_register_cleanup_callback(pkg_rollback_cb, pkg); @@ -1229,8 +1231,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path, } /* Execute post-install scripts */ - pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false); - pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false); + if ((rc = pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false)) != EPKG_OK) + goto cleanup; + if ((rc = pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false)) != EPKG_OK) + goto cleanup; } if (rc == EPKG_OK) {