Skip to content

Commit 67a76e6

Browse files
committed
Don't ignore failed pre-install/post-install scripts/lua files in pkg-register(8) (#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
1 parent 6c55d7b commit 67a76e6

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

libpkg/pkg_add.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,10 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
13571357
if (retcode != EPKG_OK)
13581358
goto cleanup;
13591359
if ((flags & PKG_ADD_NOSCRIPT) == 0) {
1360-
pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, (local != NULL));
1361-
pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, (local != NULL));
1360+
if ((retcode = pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, (local != NULL))) != EPKG_OK)
1361+
goto cleanup;
1362+
if ((retcode = pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, (local != NULL))) != EPKG_OK)
1363+
goto cleanup;
13621364
}
13631365

13641366
/*

libpkg/pkg_ports.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
12141214

12151215
if (!testing) {
12161216
/* Execute pre-install scripts */
1217-
pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false);
1218-
pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false);
1217+
if ((rc = pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false)) != EPKG_OK)
1218+
goto cleanup;
1219+
if ((rc = pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false)) != EPKG_OK)
1220+
goto cleanup;
12191221

12201222
if (input_path != NULL) {
12211223
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,
12291231
}
12301232

12311233
/* Execute post-install scripts */
1232-
pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false);
1233-
pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false);
1234+
if ((rc = pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false)) != EPKG_OK)
1235+
goto cleanup;
1236+
if ((rc = pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false)) != EPKG_OK)
1237+
goto cleanup;
12341238
}
12351239

12361240
if (rc == EPKG_OK) {

tests/frontend/install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests_init \
66
metalog \
77
reinstall \
88
pre_script_fail \
9-
post_script_ignored \
9+
post_script_fail \
1010
install_missing_dep
1111

1212
test_setup()
@@ -150,7 +150,7 @@ EOF
150150
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
151151
}
152152

153-
post_script_ignored_body()
153+
post_script_fail_body()
154154
{
155155
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
156156
cat << EOF >> test.ucl
@@ -167,7 +167,7 @@ EOF
167167

168168
atf_check -o ignore \
169169
-e inline:"${PROGNAME}: POST-INSTALL script failed\n" \
170-
-s exit:0 \
170+
-s exit:3 \
171171
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
172172
}
173173

tests/frontend/lua.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pkg: lua script failed\n"
221221
mkdir -p ${TMPDIR}/target
222222
atf_check \
223223
-e inline:"${ERR}" \
224-
-s exit:0 \
224+
-s exit:3 \
225225
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg
226226
}
227227

0 commit comments

Comments
 (0)