xbps_pkgdb_update: if pkgdb cannot be internalized, create it to simplify code.

This commit is contained in:
Juan RP 2012-11-11 10:03:14 +01:00
parent df0d5d7330
commit f81d8ac1f0
2 changed files with 15 additions and 40 deletions

View File

@ -162,64 +162,36 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
pkg_state_t state)
{
prop_dictionary_t pkgd;
bool newpkg = false;
int rv;
int rv = 0;
assert(pkgname != NULL);
if (xhp->pkgdb == NULL) {
xhp->pkgdb = prop_array_create();
if (xhp->pkgdb == NULL)
return ENOMEM;
pkgd = prop_dictionary_create();
if (pkgd == NULL) {
prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
return ENOMEM;
}
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0) {
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return rv;
}
if ((rv = set_new_state(pkgd, state)) != 0) {
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return rv;
}
if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return EINVAL;
}
} else {
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) {
newpkg = true;
pkgd = prop_dictionary_create();
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0)
return rv;
}
if ((rv = set_new_state(pkgd, state)) != 0) {
if (newpkg)
if (pkgd == NULL)
return ENOMEM;
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0) {
prop_object_release(pkgd);
return rv;
}
if ((rv = set_new_state(pkgd, state)) != 0) {
prop_object_release(pkgd);
return rv;
}
if (newpkg) {
if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
prop_object_release(pkgd);
return EINVAL;
}
} else {
if ((rv = set_new_state(pkgd, state)) != 0)
return rv;
if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
pkgd, pkgname)) != 0)
return rv;
}
}
return rv;
}

View File

@ -106,9 +106,12 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
cached_rv = 0;
}
/* update copy in memory */
if ((xhp->pkgdb = prop_array_internalize_from_zfile(plist)) == NULL)
cached_rv = rv = errno;
if ((xhp->pkgdb = prop_array_internalize_from_zfile(plist)) == NULL) {
if (errno == ENOENT)
xhp->pkgdb = prop_array_create();
cached_rv = rv = errno;
}
free(plist);
return rv;