Skip to content

Commit 1f99b96

Browse files
ifreundbapt
authored andcommitted
libpkg: fix --register-only with empty packages
Currently we end up calling archive_read_next_header() in populate_config_file_contents() even when there are no files in the package. This results in the following libarchive error: pkg: archive_read_next_header(): INTERNAL ERROR: Function 'archive_read_next_header' invoked with archive structure in state 'eof', should be in state 'header/data' This commit fixes the error and adds a test to prevent regression. Sponsored by: The FreeBSD Foundation
1 parent eaa2efc commit 1f99b96

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

libpkg/pkg_add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
16641664
pkg_delete_dirs(db, pkg, NULL);
16651665
goto cleanup;
16661666
}
1667-
} else if (flags & PKG_ADD_REGISTER_ONLY) {
1667+
} else if (flags & PKG_ADD_REGISTER_ONLY && nfiles > 0) {
16681668
/* Need to populate config file contents so they can be stored in
16691669
the database */
16701670
retcode = populate_config_file_contents(a, ae, pkg);

tests/frontend/install.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tests_init \
99
post_script_ignored \
1010
install_missing_dep \
1111
install_register_only \
12+
install_register_only_empty \
1213
install_autoremove \
1314
install_autoremove_flag \
1415
install_suggest_clear_automatic \
@@ -267,6 +268,46 @@ EOF
267268
test -d dir
268269
}
269270

271+
install_register_only_empty_body()
272+
{
273+
test_setup
274+
275+
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "${TMPDIR}"
276+
277+
mkdir repoconf
278+
cat << EOF > repoconf/repo.conf
279+
repo: {
280+
url: file:///$TMPDIR/repo,
281+
enabled: true
282+
}
283+
EOF
284+
285+
mkdir repo
286+
287+
atf_check \
288+
-o empty \
289+
-e empty \
290+
-s exit:0 \
291+
pkg create -M test.ucl -o repo
292+
293+
atf_check \
294+
-o ignore \
295+
-e empty \
296+
-s exit:0 \
297+
pkg repo repo
298+
299+
export REPOS_DIR="${TMPDIR}/repoconf"
300+
atf_check \
301+
-o ignore \
302+
-s exit:0 \
303+
pkg install -r repo -y --register-only test
304+
305+
atf_check \
306+
-o inline:"0\n" \
307+
-e empty \
308+
pkg query "%a" test
309+
}
310+
270311
install_autoremove_body() {
271312
# Pre-register: olddep (automatic), master depends on olddep
272313
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "olddep" "olddep" "1"

0 commit comments

Comments
 (0)