lib/findpkg.c: share some code.

--HG--
extra : convert_revision : c466c6c986821623cebaed2a0eade9cc8658d6f0
This commit is contained in:
Juan RP 2009-08-12 07:57:46 +02:00
parent 5ace634ade
commit 697aecf693
1 changed files with 27 additions and 26 deletions

View File

@ -34,6 +34,8 @@
static prop_dictionary_t pkg_props;
static bool pkg_props_initialized;
static int set_pkg_state(prop_dictionary_t, const char *);
static int
create_pkg_props_dictionary(void)
{
@ -244,7 +246,6 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
struct repository_data *rdata;
const char *repoloc, *repover, *instver;
int rv = 0;
pkg_state_t state = 0;
assert(pkgname != NULL);
assert(instpkg != NULL);
@ -310,20 +311,9 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
* Always set "not-installed" package state. Will be overwritten
* to its correct state later.
*/
rv = xbps_set_pkg_state_dictionary(pkgrd, XBPS_PKG_STATE_NOT_INSTALLED);
if (rv != 0)
if ((rv = set_pkg_state(pkgrd, pkgname)) != 0)
goto out;
/*
* Overwrite package state in dictionary if it was unpacked
* previously.
*/
rv = xbps_get_pkg_state_installed(pkgname, &state);
if (rv == 0) {
if ((rv = xbps_set_pkg_state_dictionary(pkgrd, state)) != 0)
goto out;
}
prop_dictionary_set_cstring_nocopy(pkgrd, "trans-action", "update");
if (!prop_array_add(unsorted, pkgrd))
@ -336,6 +326,29 @@ out:
return rv;
}
static int
set_pkg_state(prop_dictionary_t pkgd, const char *pkgname)
{
pkg_state_t state = 0;
int rv = 0;
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_NOT_INSTALLED);
if (rv != 0)
return rv;
/*
* Overwrite package state in dictionary if it was unpacked
* previously.
*/
rv = xbps_get_pkg_state_installed(pkgname, &state);
if (rv == 0) {
if ((rv = xbps_set_pkg_state_dictionary(pkgd, state)) != 0)
return rv;
}
return rv;
}
int
xbps_prepare_pkg(const char *pkgname)
{
@ -344,7 +357,6 @@ xbps_prepare_pkg(const char *pkgname)
struct repository_data *rdata;
const char *repoloc;
int rv = 0;
pkg_state_t state = 0;
assert(pkgname != NULL);
@ -430,20 +442,9 @@ xbps_prepare_pkg(const char *pkgname)
* Always set "not-installed" package state. Will be overwritten
* to its correct state later.
*/
rv = xbps_set_pkg_state_dictionary(pkgrd, XBPS_PKG_STATE_NOT_INSTALLED);
if (rv != 0)
if ((rv = set_pkg_state(pkgrd, pkgname)) != 0)
goto out;
/*
* Overwrite package state in dictionary if it was unpacked
* previously.
*/
rv = xbps_get_pkg_state_installed(pkgname, &state);
if (rv == 0) {
if ((rv = xbps_set_pkg_state_dictionary(pkgrd, state)) != 0)
goto out;
}
prop_dictionary_set_cstring_nocopy(pkgrd, "trans-action", "install");
if (!prop_array_add(pkgs_array, pkgrd))