40#include "xbps_api_impl.h"
73 if (access(xhp->
rootdir, W_OK) == -1 && errno != ENOENT) {
75 "failed to check whether the rootdir is writable: "
82 "failed to create lockfile path: %s\n", strerror(errno));
85 prev_umask = umask(022);
88 if (access(xhp->
metadir, R_OK|X_OK) == -1) {
89 if (errno != ENOENT) {
92 "failed to check access to metadir: %s: %s\n",
98 "failed to create metadir: %s: %s\n",
103 xhp->lock_fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0664);
104 if (xhp->lock_fd == -1) {
106 "failed to create lock file: %s: %s\n", path,
111 if (flock(xhp->lock_fd, LOCK_EX|LOCK_NB) == -1) {
112 if (errno != EWOULDBLOCK)
117 if (flock(xhp->lock_fd, LOCK_EX) == -1) {
122 path, strerror(errno));
131 if (xhp->lock_fd == -1)
140 xbps_object_iterator_t iter;
144 if (!xbps_dictionary_count(xhp->
pkgdb))
147 if (xhp->vpkgd == NULL) {
148 xhp->vpkgd = xbps_dictionary_create();
159 iter = xbps_dictionary_iterator(xhp->
pkgdb);
166 while ((obj = xbps_object_iterator_next(iter))) {
167 xbps_array_t provides;
168 xbps_dictionary_t pkgd;
169 const char *pkgver = NULL;
170 const char *pkgname = NULL;
173 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
174 provides = xbps_dictionary_get(pkgd,
"provides");
175 cnt = xbps_array_count(provides);
179 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
180 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname);
183 for (
unsigned int i = 0; i < cnt; i++) {
184 char vpkgname[XBPS_NAME_SIZE];
185 const char *vpkg = NULL;
186 xbps_dictionary_t providers;
189 xbps_array_get_cstring_nocopy(provides, i, &vpkg);
195 providers = xbps_dictionary_get(xhp->vpkgd, vpkgname);
197 providers = xbps_dictionary_create();
203 if (!xbps_dictionary_set(xhp->vpkgd, vpkgname, providers)) {
206 xbps_object_release(providers);
212 if (!xbps_dictionary_set_cstring(providers, vpkg, pkgname)) {
216 xbps_object_release(providers);
220 xbps_object_release(providers);
225 xbps_object_iterator_release(iter);
232 xbps_object_iterator_t iter;
236 if (!xbps_dictionary_count(xhp->
pkgdb))
243 iter = xbps_dictionary_iterator(xhp->
pkgdb);
246 while ((obj = xbps_object_iterator_next(iter))) {
247 xbps_dictionary_t pkgd;
249 char pkgname[XBPS_NAME_SIZE] = {0};
251 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
252 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
259 if (!xbps_dictionary_set_cstring(pkgd,
"pkgname", pkgname)) {
264 xbps_object_iterator_release(iter);
282 if ((rv = xbps_pkgdb_conversion(xhp)) != 0)
292 if ((rv = pkgdb_map_names(xhp)) != 0) {
296 if ((rv = pkgdb_map_vpkgs(xhp)) != 0) {
309 xbps_dictionary_t pkgdb_storage;
311 static int cached_rv;
314 if (cached_rv && !flush)
317 if (xhp->
pkgdb && flush) {
318 pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist);
319 if (pkgdb_storage == NULL ||
320 !xbps_dictionary_equals(xhp->
pkgdb, pkgdb_storage)) {
322 prev_umask = umask(022);
330 xbps_object_release(pkgdb_storage);
332 xbps_object_release(xhp->
pkgdb);
340 if ((xhp->
pkgdb = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist)) == NULL) {
346 xhp->
pkgdb = xbps_dictionary_create();
350 cached_rv = rv = errno;
363 xbps_object_release(xhp->
pkgdb);
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);
382 xbps_object_release(allkeys);
388 int (*fn)(
struct xbps_handle *, xbps_object_t,
const char *,
void *,
bool *),
391 xbps_array_t allkeys;
395 if ((r = xbps_pkgdb_init(xhp)) != 0)
396 return r > 0 ? -r : r;
398 allkeys = xbps_dictionary_all_keys(xhp->
pkgdb);
403 xbps_object_release(allkeys);
410 xbps_dictionary_t pkgd;
412 if (xbps_pkgdb_init(xhp) != 0)
415 pkgd = xbps_find_pkg_in_dict(xhp->
pkgdb, pkg);
424 if (xbps_pkgdb_init(xhp) != 0)
427 return xbps_find_virtualpkg_in_dict(xhp, xhp->
pkgdb, vpkg);
434 xbps_object_iterator_t iter;
435 xbps_dictionary_t vpkg_cache;
437 if (xhp->pkgdb_revdeps)
440 xhp->pkgdb_revdeps = xbps_dictionary_create();
441 assert(xhp->pkgdb_revdeps);
443 vpkg_cache = xbps_dictionary_create();
446 iter = xbps_dictionary_iterator(xhp->
pkgdb);
449 while ((obj = xbps_object_iterator_next(iter))) {
450 xbps_array_t rundeps;
451 xbps_dictionary_t pkgd;
452 const char *pkgver = NULL;
454 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
455 rundeps = xbps_dictionary_get(pkgd,
"run_depends");
456 if (!xbps_array_count(rundeps))
459 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
460 for (
unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
462 const char *pkgdep = NULL, *v;
463 char curpkgname[XBPS_NAME_SIZE];
466 xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
477 if (!xbps_dictionary_get_cstring_nocopy(vpkg_cache, curpkgname, &v)) {
478 const char *vpkgname = vpkg_user_conf(xhp, curpkgname);
485 if (!xbps_dictionary_set_cstring_nocopy(vpkg_cache, curpkgname, v)) {
491 pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
494 pkg = xbps_array_create();
497 xbps_array_add_cstring_nocopy(pkg, pkgver);
498 xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
501 xbps_object_release(pkg);
504 xbps_object_iterator_release(iter);
505 xbps_object_release(vpkg_cache);
511 xbps_dictionary_t pkgd;
512 const char *pkgver = NULL;
513 char pkgname[XBPS_NAME_SIZE];
518 generate_full_revdeps_tree(xhp);
519 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
523 return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
529 return xbps_get_pkg_fulldeptree(xhp, pkg,
false);
535 xbps_dictionary_t pkgd;
536 const char *pkgver = NULL;
537 char pkgname[XBPS_NAME_SIZE], plist[PATH_MAX];
546 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
550 snprintf(plist,
sizeof(plist)-1,
"%s/.%s-files.plist", xhp->
metadir, pkgname);
char rootdir[XBPS_MAXPATH]
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,...)