From 697aecf693af5cd16586435799af7240182a9950 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 12 Aug 2009 07:57:46 +0200 Subject: [PATCH] lib/findpkg.c: share some code. --HG-- extra : convert_revision : c466c6c986821623cebaed2a0eade9cc8658d6f0 --- lib/findpkg.c | 53 ++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/findpkg.c b/lib/findpkg.c index d1e180a02f..5cdce2f327 100644 --- a/lib/findpkg.c +++ b/lib/findpkg.c @@ -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))