40#include "xbps_api_impl.h"
74 "failed to create lockfile path: %s\n", strerror(errno));
77 prev_umask = umask(022);
81 "failed to create metadir: %s: %s\n",
85 xhp->lock_fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0664);
86 if (xhp->lock_fd == -1) {
88 "failed to lock package database: %s\n", strerror(errno));
92 if (flock(xhp->lock_fd, LOCK_EX|LOCK_NB) == -1) {
93 if (errno != EWOULDBLOCK)
98 if (flock(xhp->lock_fd, LOCK_EX) == -1) {
103 path, strerror(errno));
112 if (xhp->lock_fd == -1)
121 xbps_object_iterator_t iter;
125 if (!xbps_dictionary_count(xhp->
pkgdb))
128 if (xhp->vpkgd == NULL) {
129 xhp->vpkgd = xbps_dictionary_create();
140 iter = xbps_dictionary_iterator(xhp->
pkgdb);
147 while ((obj = xbps_object_iterator_next(iter))) {
148 xbps_array_t provides;
149 xbps_dictionary_t pkgd;
150 const char *pkgver = NULL;
151 const char *pkgname = NULL;
154 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
155 provides = xbps_dictionary_get(pkgd,
"provides");
156 cnt = xbps_array_count(provides);
160 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
161 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname);
164 for (
unsigned int i = 0; i < cnt; i++) {
165 char vpkgname[XBPS_NAME_SIZE];
166 const char *vpkg = NULL;
167 xbps_dictionary_t providers;
170 xbps_array_get_cstring_nocopy(provides, i, &vpkg);
176 providers = xbps_dictionary_get(xhp->vpkgd, vpkgname);
178 providers = xbps_dictionary_create();
184 if (!xbps_dictionary_set(xhp->vpkgd, vpkgname, providers)) {
187 xbps_object_release(providers);
193 if (!xbps_dictionary_set_cstring(providers, vpkg, pkgname)) {
197 xbps_object_release(providers);
201 xbps_object_release(providers);
206 xbps_object_iterator_release(iter);
213 xbps_object_iterator_t iter;
217 if (!xbps_dictionary_count(xhp->
pkgdb))
224 iter = xbps_dictionary_iterator(xhp->
pkgdb);
227 while ((obj = xbps_object_iterator_next(iter))) {
228 xbps_dictionary_t pkgd;
230 char pkgname[XBPS_NAME_SIZE] = {0};
232 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
233 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
240 if (!xbps_dictionary_set_cstring(pkgd,
"pkgname", pkgname)) {
245 xbps_object_iterator_release(iter);
263 if ((rv = xbps_pkgdb_conversion(xhp)) != 0)
273 if ((rv = pkgdb_map_names(xhp)) != 0) {
277 if ((rv = pkgdb_map_vpkgs(xhp)) != 0) {
290 xbps_dictionary_t pkgdb_storage;
292 static int cached_rv;
295 if (cached_rv && !flush)
298 if (xhp->
pkgdb && flush) {
299 pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist);
300 if (pkgdb_storage == NULL ||
301 !xbps_dictionary_equals(xhp->
pkgdb, pkgdb_storage)) {
303 prev_umask = umask(022);
311 xbps_object_release(pkgdb_storage);
313 xbps_object_release(xhp->
pkgdb);
321 if ((xhp->
pkgdb = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist)) == NULL) {
327 xhp->
pkgdb = xbps_dictionary_create();
331 cached_rv = rv = errno;
344 xbps_object_release(xhp->
pkgdb);
350 int (*fn)(
struct xbps_handle *, xbps_object_t,
const char *,
void *,
bool *),
353 xbps_array_t allkeys;
357 if ((r = xbps_pkgdb_init(xhp)) != 0)
358 return r > 0 ? -r : r;
360 allkeys = xbps_dictionary_all_keys(xhp->
pkgdb);
363 xbps_object_release(allkeys);
369 int (*fn)(
struct xbps_handle *, xbps_object_t,
const char *,
void *,
bool *),
372 xbps_array_t allkeys;
376 if ((r = xbps_pkgdb_init(xhp)) != 0)
377 return r > 0 ? -r : r;
379 allkeys = xbps_dictionary_all_keys(xhp->
pkgdb);
384 xbps_object_release(allkeys);
391 xbps_dictionary_t pkgd;
393 if (xbps_pkgdb_init(xhp) != 0)
396 pkgd = xbps_find_pkg_in_dict(xhp->
pkgdb, pkg);
405 if (xbps_pkgdb_init(xhp) != 0)
408 return xbps_find_virtualpkg_in_dict(xhp, xhp->
pkgdb, vpkg);
415 xbps_object_iterator_t iter;
416 xbps_dictionary_t vpkg_cache;
418 if (xhp->pkgdb_revdeps)
421 xhp->pkgdb_revdeps = xbps_dictionary_create();
422 assert(xhp->pkgdb_revdeps);
424 vpkg_cache = xbps_dictionary_create();
427 iter = xbps_dictionary_iterator(xhp->
pkgdb);
430 while ((obj = xbps_object_iterator_next(iter))) {
431 xbps_array_t rundeps;
432 xbps_dictionary_t pkgd;
433 const char *pkgver = NULL;
435 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
436 rundeps = xbps_dictionary_get(pkgd,
"run_depends");
437 if (!xbps_array_count(rundeps))
440 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
441 for (
unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
443 const char *pkgdep = NULL, *v;
444 char curpkgname[XBPS_NAME_SIZE];
447 xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
458 if (!xbps_dictionary_get_cstring_nocopy(vpkg_cache, curpkgname, &v)) {
459 const char *vpkgname = vpkg_user_conf(xhp, curpkgname);
466 if (!xbps_dictionary_set_cstring_nocopy(vpkg_cache, curpkgname, v)) {
472 pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
475 pkg = xbps_array_create();
478 xbps_array_add_cstring_nocopy(pkg, pkgver);
479 xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
482 xbps_object_release(pkg);
485 xbps_object_iterator_release(iter);
486 xbps_object_release(vpkg_cache);
492 xbps_dictionary_t pkgd;
493 const char *pkgver = NULL;
494 char pkgname[XBPS_NAME_SIZE];
499 generate_full_revdeps_tree(xhp);
500 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
504 return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
510 return xbps_get_pkg_fulldeptree(xhp, pkg,
false);
516 xbps_dictionary_t pkgd;
517 const char *pkgver = NULL;
518 char pkgname[XBPS_NAME_SIZE], plist[PATH_MAX];
527 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
531 snprintf(plist,
sizeof(plist)-1,
"%s/.%s-files.plist", xhp->
metadir, pkgname);
char metadir[XBPS_MAXPATH]
Generic XBPS structure handler for initialization.
#define xbps_error_oom()
Log out of memory condition.
int xbps_error_errno(int r, const char *fmt,...)
Prints formatted log message to stderr and returns error.
void xbps_error_printf(const char *fmt,...)
Prints error messages to stderr.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
void xbps_warn_printf(const char *fmt,...)
Prints warning messages to stderr.
xbps_array_t xbps_pkgdb_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg)
int xbps_pkgdb_foreach_cb_multi(struct xbps_handle *xhp, int(*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *), void *arg)
xbps_dictionary_t xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
void xbps_pkgdb_unlock(struct xbps_handle *xhp)
xbps_dictionary_t xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *vpkg)
int xbps_pkgdb_foreach_cb(struct xbps_handle *xhp, int(*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *), void *arg)
xbps_array_t xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
int xbps_pkgdb_lock(struct xbps_handle *xhp)
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
bool xbps_match_string_in_array(xbps_array_t array, const char *val)
int xbps_array_foreach_cb_multi(struct xbps_handle *xhp, xbps_array_t array, xbps_dictionary_t dict, int(*fn)(struct xbps_handle *, xbps_object_t obj, const char *, void *arg, bool *done), void *arg)
int xbps_array_foreach_cb(struct xbps_handle *xhp, xbps_array_t array, xbps_dictionary_t dict, int(*fn)(struct xbps_handle *, xbps_object_t obj, const char *, void *arg, bool *done), void *arg)
xbps_dictionary_t xbps_plist_dictionary_from_file(const char *path)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
int xbps_mkpath(const char *path, mode_t mode)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern)
ssize_t xbps_path_join(char *dst, size_t len,...)