From 441f147f057ab94eb243d075a0fa536a5635032d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 5 Mar 2015 21:23:58 +0100 Subject: [PATCH] Fix reinstallation of pkgs in repolock mode. At the time we've been searching for the pkg in a repo, no repos were registered resulting in EINVAL. While here, if there's no declared repos return ENOENT instead. --- include/xbps_api_impl.h | 2 ++ lib/rpool.c | 28 +++++++++++++++++++ lib/transaction_ops.c | 6 +++-- tests/xbps/libxbps/shell/update_repolock.sh | 30 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index a9fb07cd..7c3d5b43 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -151,5 +151,7 @@ xbps_dictionary_t HIDDEN xbps_archive_get_dictionary(struct archive *, const char HIDDEN *vpkg_user_conf(struct xbps_handle *, const char *); xbps_array_t HIDDEN xbps_get_pkg_fulldeptree(struct xbps_handle *, const char *, bool); +struct xbps_repo HIDDEN *xbps_regget_repo(struct xbps_handle *, + const char *); #endif /* !_XBPS_API_IMPL_H_ */ diff --git a/lib/rpool.c b/lib/rpool.c index 5f64719e..e2c8a53c 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -79,6 +79,34 @@ xbps_rpool_sync(struct xbps_handle *xhp, const char *uri) return 0; } +struct xbps_repo HIDDEN * +xbps_regget_repo(struct xbps_handle *xhp, const char *url) +{ + struct xbps_repo *repo; + const char *repouri; + + if (SIMPLEQ_EMPTY(&rpool_queue)) { + /* iterate until we have a match */ + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { + xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); + if (strcmp(repouri, url)) + continue; + + repo = xbps_repo_open(xhp, repouri, false); + if (!repo) + return NULL; + + SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries); + xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri); + } + } + SIMPLEQ_FOREACH(repo, &rpool_queue, entries) + if (strcmp(url, repo->uri) == 0) + return repo; + + return NULL; +} + struct xbps_repo * xbps_rpool_get_repo(const char *url) { diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 93f8874d..121f0d52 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -108,8 +108,10 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall, /* find update from repo */ xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, "repository", &repoloc); assert(repoloc); - if ((repo = xbps_rpool_get_repo(repoloc)) == NULL) - return EINVAL; + if ((repo = xbps_regget_repo(xhp, repoloc)) == NULL) { + /* not found */ + return ENOENT; + } pkg_repod = xbps_repo_get_pkg(repo, pkg); } else { /* find update from rpool */ diff --git a/tests/xbps/libxbps/shell/update_repolock.sh b/tests/xbps/libxbps/shell/update_repolock.sh index ea3c6721..82bf86e7 100644 --- a/tests/xbps/libxbps/shell/update_repolock.sh +++ b/tests/xbps/libxbps/shell/update_repolock.sh @@ -46,6 +46,36 @@ update_repolock_body() { atf_check_equal "$out" "$(readlink -f repo2)" } +atf_test_case reinstall_repolock + +reinstall_repolock_head() { + atf_set "descr" "Tests for pkg reinstall: pkg is in repository locked mode" +} + +reinstall_repolock_body() { + mkdir -p repo pkg_A + cd repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + # install A-1.0_1 from repository "repo" + xbps-install -r root --repository=repo -yvd A-1.0_1 + atf_check_equal $? 0 + # A-1.0_1 is now locked + xbps-pkgdb -r root -m repolock A + atf_check_equal $? 0 + out=$(xbps-query -r root -p repository A) + atf_check_equal "$out" "$(readlink -f repo)" + # reinstall A-1.0_1 while repolocked + xbps-install -r root --repository=repo -yvfd A-1.0_1 + atf_check_equal $? 0 + out=$(xbps-query -r root -p pkgver A) + atf_check_equal $out A-1.0_1 +} + atf_init_test_cases() { atf_add_test_case update_repolock + atf_add_test_case reinstall_repolock }