Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/xbps-install/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,20 @@ print_trans_colmode(struct transaction *trans, unsigned int cols)

while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
bool dload = false;
bool replaced = false;

pkgver = pkgname = ipkgver = ver = iver = NULL;
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
xbps_dictionary_get_uint64(obj, "filename-size", &dlsize);
xbps_dictionary_get_bool(obj, "download", &dload);
xbps_dictionary_get_bool(obj, "replaced", &replaced);

ttype = xbps_transaction_pkg_type(obj);
tract = ttype2str(obj);
if (replaced) {
tract = "replaced";
}
if (trans->xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
tract = "download";
}
Expand Down
8 changes: 6 additions & 2 deletions lib/transaction_check_replaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)

/*
* Find the installed package that matches the pattern
* to be replaced.
* to be replaced. Also check if the package would be
* installed in the transaction.
*/
if (((instd = xbps_pkgdb_get_pkg(xhp, pattern)) == NULL) &&
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL))
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL) &&
((instd = xbps_find_pkg_in_array(pkgs, pattern, XBPS_TRANS_INSTALL)) == NULL))
continue;

if (!xbps_dictionary_get_cstring_nocopy(instd, "pkgver", &curpkgver)) {
Expand Down Expand Up @@ -142,6 +144,7 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_object_iterator_release(iter);
return false;
}
xbps_verbose_printf("Package `%s' will be replaced by `%s'\n", curpkgver, pkgver);
xbps_dbg_printf(
"Package `%s' in transaction will be "
"replaced by `%s', matched with `%s'\n",
Expand Down Expand Up @@ -174,6 +177,7 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_object_iterator_release(iter);
return false;
}
xbps_verbose_printf("Package `%s' will be replaced by `%s'\n", curpkgver, pkgver);
xbps_dbg_printf(
"Package `%s' will be replaced by `%s', "
"matched with `%s'\n", curpkgver, pkgver, pattern);
Expand Down
13 changes: 12 additions & 1 deletion lib/transaction_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
xbps_trans_type_t ttype;
const char *pkgver = NULL, *pkgname = NULL;
int rv = 0;
bool update;
bool update, replaced;

setlocale(LC_ALL, "");

Expand Down Expand Up @@ -232,6 +232,11 @@ xbps_transaction_commit(struct xbps_handle *xhp)
}

if ((pkgdb_pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
replaced = false;
xbps_dictionary_get_bool(obj, "replaced", &replaced);
if (replaced) {
continue;
}
rv = ENOENT;
xbps_dbg_printf("[trans] cannot find %s in pkgdb: %s\n",
pkgname, strerror(rv));
Expand Down Expand Up @@ -302,6 +307,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)

while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);

ttype = xbps_transaction_pkg_type(obj);
if (ttype == XBPS_TRANS_REMOVE) {
Expand All @@ -310,6 +316,11 @@ xbps_transaction_commit(struct xbps_handle *xhp)
*/
update = false;
xbps_dictionary_get_bool(obj, "remove-and-update", &update);
replaced = false;
xbps_dictionary_get_bool(obj, "replaced", &replaced);
if (((pkgdb_pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) && replaced) {
continue;
}
rv = xbps_remove_pkg(xhp, pkgver, update);
if (rv != 0) {
xbps_dbg_printf("[trans] failed to "
Expand Down
27 changes: 27 additions & 0 deletions tests/xbps/libxbps/shell/replace_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,32 @@ replace_transitional_pkg_automatically_installed3_body() {
atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) ""
}

atf_test_case replace_transitional_pkg_during_install

replace_transitional_pkg_during_install_head() {
atf_set "descr" "Tests for package replace: install a transitional package and replace it during the transaction"
}

replace_transitional_pkg_during_install_body() {
mkdir some_repo root
mkdir -p pkg_A/usr/bin empty
echo "A-1.0_1" > pkg_A/usr/bin/foo
cd some_repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" --replaces "B>=0" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.0_1 -s "A pkg - transitional dummy package" --dependencies="A>=0" ../empty
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B
atf_check_equal $? 0
result=$(xbps-query -r root -l | wc -l)
atf_check_equal $result 1
atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed
atf_check_equal $(xbps-query -C xbps.d -r root -p state B) ""
}

atf_test_case replace_automatically_installed_dep

replace_automatically_installed_dep_head() {
Expand Down Expand Up @@ -600,6 +626,7 @@ atf_init_test_cases() {
atf_add_test_case replace_transitional_pkg_automatically_installed
atf_add_test_case replace_transitional_pkg_automatically_installed2
atf_add_test_case replace_transitional_pkg_automatically_installed3
atf_add_test_case replace_transitional_pkg_during_install
atf_add_test_case replace_automatically_installed_dep
atf_add_test_case replace_automatically_installed_dep2
atf_add_test_case replace_automatically_installed_dep3
Expand Down
Loading