34#include "xbps_api_impl.h"
37pkgdb038(
struct xbps_handle *xhp,
const char *opkgdb_plist)
39 xbps_dictionary_t pkgdb, opkgdb;
40 xbps_object_iterator_t iter;
57 pkgdb = xbps_dictionary_create();
63 iter = xbps_dictionary_iterator(opkgdb);
66 while ((obj = xbps_object_iterator_next(iter))) {
67 xbps_dictionary_t pkgd, pkgfilesd, pkgmetad;
68 xbps_object_iterator_t iter2;
70 const char *pkgname, *repo;
73 pkgname = xbps_dictionary_keysym_cstring_nocopy(obj);
74 pkgd = xbps_dictionary_get_keysym(opkgdb, obj);
79 if (xbps_dictionary_get_cstring_nocopy(pkgd,
"repository-origin", &repo)) {
80 xbps_dictionary_set_cstring(pkgd,
"repository", repo);
81 xbps_dictionary_remove(pkgd,
"repository-origin");
86 if (!xbps_dictionary_set(pkgdb, pkgname, pkgd)) {
87 xbps_dbg_printf(
"%s: failed to copy %s pkgd "
88 "for pkgdb conversion\n", __func__, pkgname);
97 if (pkgmetad == NULL) {
99 xbps_dbg_printf(
"%s: cannot open %s: %s\n",
100 __func__, pkgmeta, strerror(errno));
103 pkgfilesd = xbps_dictionary_create();
106 iter2 = xbps_dictionary_iterator(pkgmetad);
109 while ((obj2 = xbps_object_iterator_next(iter2))) {
110 xbps_object_t curobj;
111 const char *key, *excluded[] = {
112 "conf_files",
"dirs",
"files",
"links"
116 key = xbps_dictionary_keysym_cstring_nocopy(obj2);
117 curobj = xbps_dictionary_get_keysym(pkgmetad, obj2);
118 for (uint8_t i = 0; i < __arraycount(excluded); i++) {
119 if (strcmp(excluded[i], key) == 0) {
125 assert(xbps_object_type(curobj) == XBPS_TYPE_ARRAY);
126 if (xbps_array_count(curobj))
127 xbps_dictionary_set(pkgfilesd, key, curobj);
131 if (!xbps_dictionary_set(pkgd, key, curobj)) {
132 xbps_dbg_printf(
"%s: failed to copy %s "
133 "pkgd for pkgdb conversion\n", pkgname, key);
134 xbps_object_iterator_release(iter2);
135 xbps_object_release(pkgmetad);
141 xbps_object_iterator_release(iter2);
145 if (xbps_dictionary_count(pkgfilesd)) {
146 char *pkgfiles, *sha256;
149 if (!xbps_dictionary_externalize_to_file(pkgfilesd, pkgfiles)) {
150 xbps_dbg_printf(
"%s: failed to "
151 "externalize %s: %s\n", __func__, pkgfiles, strerror(errno));
155 xbps_dbg_printf(
"%s: externalized %s successfully\n", __func__, pkgfiles);
159 sha256 = xbps_file_hash(pkgfiles);
161 xbps_dictionary_set_cstring(pkgd,
"metafile-sha256", sha256);
166 xbps_dictionary_remove(pkgd,
"metafile-sha256");
168 xbps_object_release(pkgfilesd);
169 xbps_object_release(pkgmetad);
175 if (!xbps_dictionary_externalize_to_file(pkgdb, xhp->
pkgdb_plist)) {
176 xbps_dbg_printf(
"%s: failed to externalize %s: "
177 "%s!\n", __func__, xhp->
pkgdb_plist, strerror(errno));
183 xbps_object_iterator_release(iter);
185 xbps_object_release(pkgdb);
187 xbps_object_release(opkgdb);
207 if (access(opkgdb, R_OK) == 0) {
212 xbps_set_cb_state(xhp, XBPS_STATE_PKGDB, 0, NULL, NULL);
213 if ((rv = pkgdb038(xhp, opkgdb)) == 0) {
214 xbps_set_cb_state(xhp, XBPS_STATE_PKGDB_DONE, 0, NULL, NULL);
char metadir[XBPS_MAXPATH+sizeof(XBPS_META_PATH)]
Generic XBPS structure handler for initialization.
void xbps_end(struct xbps_handle *xhp)
xbps_dictionary_t xbps_plist_dictionary_from_file(const char *path)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf