32#include "xbps_api_impl.h"
39static 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 },
56set_new_state(xbps_dictionary_t dict,
pkg_state_t state)
58 const struct state *stp;
60 assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
62 for (stp = states; stp->string != NULL; stp++)
63 if (state == stp->number)
66 if (stp->string == NULL)
69 if (!xbps_dictionary_set_cstring_nocopy(dict,
"state", stp->string))
76get_state(xbps_dictionary_t dict)
78 const struct state *stp;
79 const char *state_str;
81 assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
83 if (!xbps_dictionary_get_cstring_nocopy(dict,
87 for (stp = states; stp->string != NULL; stp++)
88 if (strcmp(state_str, stp->string) == 0)
99 xbps_dictionary_t pkgd;
101 assert(pkgver != NULL);
102 assert(state != NULL);
108 *state = get_state(pkgd);
118 assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
119 assert(state != NULL);
121 if ((*state = get_state(dict)) == 0)
130 assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
132 return set_new_state(dict, state);
140 xbps_dictionary_t pkgd;
141 char pkgname[XBPS_NAME_SIZE];
144 assert(pkgver != NULL);
148 pkgd = xbps_dictionary_create();
152 if (!xbps_dictionary_set_cstring_nocopy(pkgd,
154 xbps_object_release(pkgd);
157 if ((rv = set_new_state(pkgd, state)) != 0) {
158 xbps_object_release(pkgd);
164 if (!xbps_dictionary_set(xhp->
pkgdb, pkgname, pkgd)) {
165 xbps_object_release(pkgd);
168 xbps_object_release(pkgd);
170 if ((rv = set_new_state(pkgd, state)) != 0)
176 if (!xbps_dictionary_set(xhp->
pkgdb, pkgname, pkgd)) {
Generic XBPS structure handler for initialization.
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
int xbps_pkg_state_installed(struct xbps_handle *xhp, const char *pkgver, pkg_state_t *state)
int xbps_set_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t state)
int xbps_set_pkg_state_installed(struct xbps_handle *xhp, const char *pkgver, pkg_state_t state)
int xbps_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t *state)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)