transaction_ops: in update, check if curpkg has been previously added.

This commit is contained in:
Juan RP 2012-07-04 11:56:01 +02:00
parent e879c71a02
commit 94238302f2
2 changed files with 34 additions and 35 deletions

View File

@ -56,8 +56,8 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120620" #define XBPS_API_VERSION "20120704"
#define XBPS_VERSION "0.16.1" #define XBPS_VERSION "0.16.2"
/** /**
* @def XBPS_RELVER * @def XBPS_RELVER

View File

@ -66,7 +66,7 @@ transaction_find_pkg(struct xbps_handle *xhp,
{ {
prop_dictionary_t pkg_pkgdb, pkg_repod; prop_dictionary_t pkg_pkgdb, pkg_repod;
prop_array_t unsorted; prop_array_t unsorted;
const char *pkgname, *repoloc, *repover, *instver, *reason; const char *pkgname, *repoloc, *repover, *repopkgver, *instver, *reason;
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -91,28 +91,26 @@ transaction_find_pkg(struct xbps_handle *xhp,
pkg_repod = xbps_rpool_find_pkg_exact(xhp, pkg); pkg_repod = xbps_rpool_find_pkg_exact(xhp, pkg);
if (pkg_repod == NULL) { if (pkg_repod == NULL) {
/* not found */ /* not found */
rv = errno; return errno;
goto out;
} }
} else { } else {
if (((pkg_repod = xbps_rpool_find_pkg(xhp, pkg, bypattern, best)) == NULL) && if (((pkg_repod = xbps_rpool_find_pkg(xhp, pkg, bypattern, best)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg_conf(xhp, pkg, bypattern)) == NULL) && ((pkg_repod = xbps_rpool_find_virtualpkg_conf(xhp, pkg, bypattern)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg(xhp, pkg, bypattern)) == NULL)) { ((pkg_repod = xbps_rpool_find_virtualpkg(xhp, pkg, bypattern)) == NULL)) {
/* not found */ /* not found */
rv = errno; return errno;
goto out;
} }
} }
} else { } else {
pkg_repod = xbps_rpool_find_pkg(xhp, pkg, false, true); pkg_repod = xbps_rpool_find_pkg(xhp, pkg, false, true);
if (pkg_repod == NULL) { if (pkg_repod == NULL) {
/* not found */ /* not found */
rv = errno; return errno;
goto out;
} }
} }
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover); prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover);
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
if (action == TRANS_UPDATE) { if (action == TRANS_UPDATE) {
@ -125,39 +123,54 @@ transaction_find_pkg(struct xbps_handle *xhp,
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' " xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
"(installed: %s-%s) from repository `%s'\n", "(installed: %s-%s) from repository `%s'\n",
pkgname, repover, pkgname, instver, repoloc); pkgname, repover, pkgname, instver, repoloc);
rv = EEXIST; return EEXIST;
goto out;
} }
} }
/* /*
* Prepare transaction dictionary. * Prepare transaction dictionary.
*/ */
if ((rv = xbps_transaction_init(xhp)) != 0) if ((rv = xbps_transaction_init(xhp)) != 0)
goto out; return rv;
/* /*
* Find out if package has matched conflicts. * Find out if package has matched conflicts.
*/ */
xbps_pkg_find_conflicts(xhp, pkg_repod); xbps_pkg_find_conflicts(xhp, pkg_repod);
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (unsorted == NULL)
return EINVAL;
/*
* Find out if package being updated matches the one already
* in transaction, in that case ignore it.
*/
if (action == TRANS_UPDATE) {
if (xbps_find_pkg_in_array_by_pkgver(xhp,
unsorted, repopkgver, NULL)) {
xbps_dbg_printf(xhp, "[update] `%s' already queued in "
"transaction.\n", repopkgver);
return EEXIST;
}
}
/* /*
* Prepare required package dependencies and add them into the * Prepare required package dependencies and add them into the
* "unsorted" array in transaction dictionary. * "unsorted" array in transaction dictionary.
*/ */
if ((rv = xbps_repository_find_pkg_deps(xhp, pkg_repod)) != 0) if ((rv = xbps_repository_find_pkg_deps(xhp, pkg_repod)) != 0)
goto out; return rv;
/* /*
* Set package state in dictionary with same state than the * Set package state in dictionary with same state than the
* package currently uses, otherwise not-installed. * package currently uses, otherwise not-installed.
*/ */
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) { if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
if (rv != ENOENT) if (rv != ENOENT)
goto out; return rv;
/* Package not installed, don't error out */ /* Package not installed, don't error out */
state = XBPS_PKG_STATE_NOT_INSTALLED; state = XBPS_PKG_STATE_NOT_INSTALLED;
} }
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0)
goto out; return rv;
if (state == XBPS_PKG_STATE_UNPACKED) if (state == XBPS_PKG_STATE_UNPACKED)
reason = "configure"; reason = "configure";
@ -170,33 +183,19 @@ transaction_find_pkg(struct xbps_handle *xhp,
* or "update". * or "update".
*/ */
if (!prop_dictionary_set_cstring_nocopy(pkg_repod, if (!prop_dictionary_set_cstring_nocopy(pkg_repod,
"transaction", reason)) { "transaction", reason))
rv = EINVAL; return EINVAL;
goto out;
}
/*
* Add required package dictionary into the unsorted array.
*/
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (unsorted == NULL) {
rv = EINVAL;
goto out;
}
/* /*
* Add the pkg dictionary from repository's index dictionary into * Add the pkg dictionary from repository's index dictionary into
* the "unsorted" array in transaction dictionary. * the "unsorted" array in transaction dictionary.
*/ */
if (!prop_array_add(unsorted, pkg_repod)) { if (!prop_array_add(unsorted, pkg_repod))
rv = errno; return errno;
goto out;
}
xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n", xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n",
pkgname, repover, repoloc); pkgname, repover, repoloc);
out:
if (pkg_repod != NULL)
prop_object_release(pkg_repod);
return rv; return rv;
} }