libxbps: simplify pkgdb_get_pkgd and find_pkg_dict_installed internals.

There's no need to prop_dictionary_copy the returned dictionary to
later have to free it again, just return directly the dictionary and
avoid the free(3)s.
This commit is contained in:
Juan RP
2012-06-16 09:02:07 +02:00
parent 068cab8d20
commit 974b2fe8ad
19 changed files with 28 additions and 96 deletions

View File

@@ -103,16 +103,11 @@ xbps_configure_pkg(struct xbps_handle *xhp,
}
if (state == XBPS_PKG_STATE_INSTALLED) {
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0) {
prop_object_release(pkgd);
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0)
return 0;
}
} else if (state != XBPS_PKG_STATE_UNPACKED) {
prop_object_release(pkgd);
} else if (state != XBPS_PKG_STATE_UNPACKED)
return EINVAL;
}
}
prop_object_release(pkgd);
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",

View File

@@ -59,7 +59,6 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
"installed pkg %s", repopkgver, pkgver);
assert(buf != NULL);
prop_array_add_cstring(trans_cflicts, buf);
prop_object_release(pkgd);
free(buf);
continue;
}

View File

@@ -137,9 +137,6 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
goto out;
}
out:
if (pkgd != NULL)
prop_object_release(pkgd);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
rv, pkgname, version,

View File

@@ -107,7 +107,6 @@ xbps_pkg_state_installed(struct xbps_handle *xhp,
return ENOENT;
*state = get_state(pkgd);
prop_object_release(pkgd);
if (*state == 0)
return EINVAL;
@@ -203,11 +202,8 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
if (pkgd == NULL) {
newpkg = true;
pkgd = prop_dictionary_create();
rv = set_pkg_objs(pkgd, pkgname, version);
if (rv != 0) {
prop_object_release(pkgd);
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0)
return rv;
}
}
if ((rv = set_new_state(pkgd, state)) != 0) {
if (newpkg)
@@ -223,8 +219,6 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
pkgd, pkgname)) != 0)
return rv;
prop_object_release(pkgd);
}
}

View File

@@ -169,25 +169,16 @@ xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern)
else
pkgd = xbps_find_pkg_in_array_by_name(xhp, xhp->pkgdb, pkg, NULL);
if (pkgd != NULL)
return prop_dictionary_copy(pkgd);
return NULL;
return pkgd;
}
prop_dictionary_t
xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver)
{
prop_dictionary_t pkgd = NULL;
if (xbps_pkgdb_init(xhp) != 0)
return NULL;
pkgd = xbps_find_pkg_in_array_by_pkgver(xhp, xhp->pkgdb, pkgver, NULL);
if (pkgd != NULL)
return prop_dictionary_copy(pkgd);
return NULL;
return xbps_find_pkg_in_array_by_pkgver(xhp, xhp->pkgdb, pkgver, NULL);
}
bool

View File

@@ -294,7 +294,6 @@ xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
"pkgname", &savedpkgname);
plistf = xbps_xasprintf("%s/metadata/%s/%s",
xhp->metadir, savedpkgname, plist);
prop_object_release(pkgd);
if (plistf == NULL)
return NULL;
}

View File

@@ -342,7 +342,7 @@ find_pkgd_installed(struct xbps_handle *xhp,
bool bypattern,
bool virtual)
{
prop_dictionary_t pkgd, rpkgd = NULL;
prop_dictionary_t pkgd = NULL;
pkg_state_t state = 0;
int rv;
@@ -376,20 +376,20 @@ find_pkgd_installed(struct xbps_handle *xhp,
return NULL;
if (xbps_pkg_state_dictionary(pkgd, &state) != 0)
return rpkgd;
return NULL;
switch (state) {
case XBPS_PKG_STATE_INSTALLED:
case XBPS_PKG_STATE_UNPACKED:
rpkgd = prop_dictionary_copy(pkgd);
break;
return pkgd;
/* NOTREACHED */
default:
/* not fully installed */
errno = ENOENT;
break;
}
return rpkgd;
return NULL;
}
prop_dictionary_t

View File

@@ -245,11 +245,8 @@ find_repo_deps(struct xbps_handle *xhp,
"pkgver", &pkgver_q);
/* Check its state */
rv = xbps_pkg_state_dictionary(tmpd, &state);
if (rv != 0) {
prop_object_release(tmpd);
if ((rv = xbps_pkg_state_dictionary(tmpd, &state)) != 0)
break;
}
if (xbps_match_virtual_pkg_in_dict(tmpd,reqpkg,true)) {
/*
* Check if required dependency is a virtual
@@ -259,7 +256,6 @@ find_repo_deps(struct xbps_handle *xhp,
xbps_dbg_printf_append(xhp,
"[virtual] satisfied by "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
}
rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
@@ -294,12 +290,10 @@ find_repo_deps(struct xbps_handle *xhp,
xbps_dbg_printf_append(xhp,
"installed "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
}
} else {
/* error matching pkgpattern */
prop_object_release(tmpd);
xbps_dbg_printf(xhp, "failed to match "
"pattern %s with %s\n", reqpkg, pkgver_q);
break;

View File

@@ -135,9 +135,11 @@ xbps_rpool_release(struct xbps_handle *xhp)
for (i = 0; i < prop_array_count(xhp->repo_pool); i++) {
d = prop_array_get(xhp->repo_pool, i);
idx = prop_dictionary_get(d, "index");
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf(xhp, "[rpool] unregistered repository '%s'\n",
uri);
if (xhp->flags & XBPS_FLAG_DEBUG) {
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf(xhp, "[rpool] unregistered "
"repository '%s'\n", uri);
}
prop_object_release(idx);
prop_object_release(d);
}

View File

@@ -121,7 +121,6 @@ transaction_find_pkg(struct xbps_handle *xhp,
*/
prop_dictionary_get_cstring_nocopy(pkg_pkgdb,
"version", &instver);
prop_object_release(pkg_pkgdb);
if (xbps_cmpver(repover, instver) <= 0) {
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
"(installed: %s-%s) from repository `%s'\n",
@@ -279,11 +278,8 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp,
pkgd = xbps_pkgdb_get_pkgd(xhp, pkg, bypattern);
if (pkgd) {
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
prop_object_release(pkgd);
if (xbps_pkg_state_dictionary(pkgd, &state) != 0)
return EINVAL;
}
prop_object_release(pkgd);
if ((state == XBPS_PKG_STATE_INSTALLED) && !reinstall) {
/* error out if pkg installed and no reinstall */
return EEXIST;
@@ -315,7 +311,7 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
* Prepare transaction dictionary and missing deps array.
*/
if ((rv = xbps_transaction_init(xhp)) != 0)
goto out;
return rv;
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (!recursive)
@@ -324,19 +320,14 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
* If recursive is set, find out which packages would be orphans
* if the supplied package were already removed.
*/
orphans_pkg = prop_array_create();
if (orphans_pkg == NULL) {
rv = ENOMEM;
goto out;
}
if ((orphans_pkg = prop_array_create()) == NULL)
return ENOMEM;
prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
prop_object_release(orphans_pkg);
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) {
rv = EINVAL;
goto out;
}
if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
return EINVAL;
count = prop_array_count(orphans);
while (count--) {
@@ -364,9 +355,6 @@ rmpkg:
(prop_array_count(reqby) > 0))
rv = EEXIST;
out:
prop_object_release(pkgd);
return rv;
}

View File

@@ -95,7 +95,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
xbps_dbg_printf(xhp,
"replaced and new package "
"are equal (%s)\n", pkgname);
prop_object_release(instd);
continue;
}
instd_reqby = prop_dictionary_get(instd, "requiredby");
@@ -181,7 +180,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
if (xbps_mkpath(dname, 0755) == -1) {
if (errno != EEXIST) {
free(buf);
prop_object_release(instd);
prop_object_iterator_release(iter);
return errno;
}
@@ -190,7 +188,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
free(buf);
free(dirc);
prop_object_release(filesd);
prop_object_release(instd);
prop_object_iterator_release(iter);
return errno;
}
@@ -205,7 +202,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
prop_dictionary_set_cstring_nocopy(instd,
"transaction", "remove");
if (!xbps_add_obj_to_array(transd_unsorted, instd)) {
prop_object_release(instd);
prop_object_iterator_release(iter);
return EINVAL;
}

View File

@@ -83,15 +83,10 @@ xbps_check_is_installed_pkg_by_pattern(struct xbps_handle *xhp,
* Check that package state is fully installed, not
* unpacked or something else.
*/
if (xbps_pkg_state_dictionary(dict, &state) != 0) {
prop_object_release(dict);
if (xbps_pkg_state_dictionary(dict, &state) != 0)
return -1; /* error */
}
if (state != XBPS_PKG_STATE_INSTALLED) {
prop_object_release(dict);
if (state != XBPS_PKG_STATE_INSTALLED)
return 0; /* not fully installed */
}
prop_object_release(dict);
return 1;
}
@@ -108,7 +103,6 @@ xbps_check_is_installed_pkg_by_name(struct xbps_handle *xhp,
((pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false)) == NULL))
return false;
prop_object_release(pkgd);
return true;
}