libxbps: make sure to not add dups in transaction for remove.

This commit is contained in:
Juan RP
2014-10-19 11:22:17 +02:00
parent fb868454b2
commit 231582e671
5 changed files with 32 additions and 14 deletions

View File

@ -198,7 +198,7 @@ bool HIDDEN xbps_transaction_shlibs(struct xbps_handle *, xbps_array_t, xbps_arr
*/ */
int HIDDEN xbps_transaction_init(struct xbps_handle *); int HIDDEN xbps_transaction_init(struct xbps_handle *);
int HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, xbps_dictionary_t, pkg_state_t); int HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, xbps_dictionary_t);
/** /**
* @private * @private

View File

@ -330,7 +330,7 @@ find_repo_deps(struct xbps_handle *xhp,
* Package is on repo, add it into the transaction dictionary. * Package is on repo, add it into the transaction dictionary.
*/ */
xbps_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); xbps_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
rv = xbps_transaction_store(xhp, unsorted, curpkgd, state); rv = xbps_transaction_store(xhp, unsorted, curpkgd);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf(xhp, "xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); xbps_dbg_printf(xhp, "xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv));
break; break;
@ -359,7 +359,7 @@ find_repo_deps(struct xbps_handle *xhp,
* Package is on repo, add it into the transaction dictionary. * Package is on repo, add it into the transaction dictionary.
*/ */
xbps_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); xbps_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
rv = xbps_transaction_store(xhp, unsorted, curpkgd, state); rv = xbps_transaction_store(xhp, unsorted, curpkgd);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf(xhp, "xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); xbps_dbg_printf(xhp, "xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv));
break; break;

View File

@ -197,7 +197,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
free(pkgname); free(pkgname);
return EINVAL; return EINVAL;
} }
if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod, state)) != 0) { if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod)) != 0) {
free(pkgname); free(pkgname);
return rv; return rv;
} }
@ -310,7 +310,8 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
obj = xbps_array_get(orphans, count); obj = xbps_array_get(orphans, count);
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_set_cstring_nocopy(obj, "transaction", "remove"); xbps_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
xbps_array_add(pkgs, obj); if ((rv = xbps_transaction_store(xhp, pkgs, obj)) != 0)
return EINVAL;
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver); xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
} }
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname); reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
@ -331,7 +332,8 @@ rmpkg:
*/ */
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
xbps_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove"); xbps_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
xbps_array_add(pkgs, pkgd); if ((rv = xbps_transaction_store(xhp, pkgs, pkgd)) != 0)
return EINVAL;
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver); xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver); reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver);
/* /*

View File

@ -32,22 +32,15 @@
int HIDDEN int HIDDEN
xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
xbps_dictionary_t pkgd, pkg_state_t pstate) xbps_dictionary_t pkgd)
{ {
xbps_array_t replaces; xbps_array_t replaces;
const char *pkgver; const char *pkgver;
char *pkgname, *self_replaced; char *pkgname, *self_replaced;
int rv;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
if (xbps_find_pkg_in_array(pkgs, pkgver, NULL)) if (xbps_find_pkg_in_array(pkgs, pkgver, NULL))
return 0; return 0;
/*
* Overwrite package state in dictionary with same state than the
* package currently uses, otherwise not-installed.
*/
if ((rv = xbps_set_pkg_state_dictionary(pkgd, pstate)) != 0)
return rv;
/* /*
* Add required objects into package dep's dictionary. * Add required objects into package dep's dictionary.
*/ */

View File

@ -136,9 +136,32 @@ remove_readonly_files_body() {
atf_check_equal $rv 0 atf_check_equal $rv 0
} }
atf_test_case remove_dups
remove_dups_head() {
atf_set "descr" "Tests for package removal: remove pkg multiple times"
}
remove_dups_body() {
mkdir some_repo
mkdir -p pkg_A/usr/bin
cd some_repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
xbps-rindex -a *.xbps
atf_check_equal $? 0
cd ..
xbps-install -r root -C null.conf --repository=$PWD/some_repo -yv A
atf_check_equal $? 0
out=$(xbps-remove -r root -yvn A A A|wc -l)
atf_check_equal $out 1
}
atf_init_test_cases() { atf_init_test_cases() {
atf_add_test_case keep_base_symlinks atf_add_test_case keep_base_symlinks
atf_add_test_case remove_readonly_files atf_add_test_case remove_readonly_files
atf_add_test_case remove_symlinks atf_add_test_case remove_symlinks
atf_add_test_case remove_symlinks_from_root atf_add_test_case remove_symlinks_from_root
atf_add_test_case remove_dups
} }