32 #include "xbps_api_impl.h"
39 static const struct state states[] = {
40 {
"unpacked", XBPS_PKG_STATE_UNPACKED },
41 {
"installed", XBPS_PKG_STATE_INSTALLED },
42 {
"broken", XBPS_PKG_STATE_BROKEN },
43 {
"half-removed", XBPS_PKG_STATE_HALF_REMOVED },
44 {
"not-installed", XBPS_PKG_STATE_NOT_INSTALLED },
56 set_new_state(prop_dictionary_t dict,
pkg_state_t state)
58 const struct state *stp;
60 assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
62 for (stp = states; stp->string != NULL; stp++)
63 if (state == stp->number)
66 if (stp->string == NULL)
69 if (!prop_dictionary_set_cstring_nocopy(dict,
"state", stp->string))
76 get_state(prop_dictionary_t dict)
78 const struct state *stp;
79 const char *state_str;
81 assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
83 if (!prop_dictionary_get_cstring_nocopy(dict,
87 for (stp = states; stp->string != NULL; stp++)
88 if (strcmp(state_str, stp->string) == 0)
99 prop_dictionary_t pkgd;
101 assert(pkgname != NULL);
102 assert(state != NULL);
108 *state = get_state(pkgd);
118 assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
119 assert(state != NULL);
121 if ((*state = get_state(dict)) == 0)
130 assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
132 return set_new_state(dict, state);
136 set_pkg_objs(prop_dictionary_t pkgd,
const char *name,
const char *version)
140 if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgname", name))
143 if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version))
147 assert(pkgver != NULL);
149 if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgver", pkgver)) {
164 prop_dictionary_t pkgd;
167 assert(pkgname != NULL);
171 pkgd = prop_dictionary_create();
175 if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0) {
176 prop_object_release(pkgd);
179 if ((rv = set_new_state(pkgd, state)) != 0) {
180 prop_object_release(pkgd);
183 if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
184 prop_object_release(pkgd);
188 if ((rv = set_new_state(pkgd, state)) != 0)
191 if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
192 pkgd, pkgname)) != 0)