40#include "xbps_api_impl.h"
73 if (access(xhp->
rootdir, W_OK) == -1 && errno != ENOENT) {
75 "failed to check whether the roodir is wriable: "
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) == -1) {
115 path, strerror(errno));
124 if (xhp->lock_fd == -1)
133 xbps_object_iterator_t iter;
137 if (!xbps_dictionary_count(xhp->
pkgdb))
140 if (xhp->vpkgd == NULL) {
141 xhp->vpkgd = xbps_dictionary_create();
152 iter = xbps_dictionary_iterator(xhp->
pkgdb);
159 while ((obj = xbps_object_iterator_next(iter))) {
160 xbps_array_t provides;
161 xbps_dictionary_t pkgd;
162 const char *pkgver = NULL;
163 const char *pkgname = NULL;
166 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
167 provides = xbps_dictionary_get(pkgd,
"provides");
168 cnt = xbps_array_count(provides);
172 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
173 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname);
176 for (
unsigned int i = 0; i < cnt; i++) {
177 char vpkgname[XBPS_NAME_SIZE];
178 const char *vpkg = NULL;
179 xbps_dictionary_t providers;
182 xbps_array_get_cstring_nocopy(provides, i, &vpkg);
188 providers = xbps_dictionary_get(xhp->vpkgd, vpkgname);
190 providers = xbps_dictionary_create();
196 if (!xbps_dictionary_set(xhp->vpkgd, vpkgname, providers)) {
199 xbps_object_release(providers);
205 if (!xbps_dictionary_set_cstring(providers, vpkg, pkgname)) {
209 xbps_object_release(providers);
213 xbps_object_release(providers);
218 xbps_object_iterator_release(iter);
225 xbps_object_iterator_t iter;
229 if (!xbps_dictionary_count(xhp->
pkgdb))
236 iter = xbps_dictionary_iterator(xhp->
pkgdb);
239 while ((obj = xbps_object_iterator_next(iter))) {
240 xbps_dictionary_t pkgd;
242 char pkgname[XBPS_NAME_SIZE] = {0};
244 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
245 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver)) {
252 if (!xbps_dictionary_set_cstring(pkgd,
"pkgname", pkgname)) {
257 xbps_object_iterator_release(iter);
275 if ((rv = xbps_pkgdb_conversion(xhp)) != 0)
285 if ((rv = pkgdb_map_names(xhp)) != 0) {
289 if ((rv = pkgdb_map_vpkgs(xhp)) != 0) {
302 xbps_dictionary_t pkgdb_storage;
304 static int cached_rv;
307 if (cached_rv && !flush)
310 if (xhp->
pkgdb && flush) {
311 pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist);
312 if (pkgdb_storage == NULL ||
313 !xbps_dictionary_equals(xhp->
pkgdb, pkgdb_storage)) {
315 prev_umask = umask(022);
323 xbps_object_release(pkgdb_storage);
325 xbps_object_release(xhp->
pkgdb);
333 if ((xhp->
pkgdb = xbps_dictionary_internalize_from_file(xhp->
pkgdb_plist)) == NULL) {
339 xhp->
pkgdb = xbps_dictionary_create();
343 cached_rv = rv = errno;
356 xbps_object_release(xhp->
pkgdb);
362 int (*fn)(
struct xbps_handle *, xbps_object_t,
const char *,
void *,
bool *),
365 xbps_array_t allkeys;
369 if ((r = xbps_pkgdb_init(xhp)) != 0)
370 return r > 0 ? -r : r;
372 allkeys = xbps_dictionary_all_keys(xhp->
pkgdb);
375 xbps_object_release(allkeys);
381 int (*fn)(
struct xbps_handle *, xbps_object_t,
const char *,
void *,
bool *),
384 xbps_array_t allkeys;
388 if ((r = xbps_pkgdb_init(xhp)) != 0)
389 return r > 0 ? -r : r;
391 allkeys = xbps_dictionary_all_keys(xhp->
pkgdb);
396 xbps_object_release(allkeys);
403 xbps_dictionary_t pkgd;
405 if (xbps_pkgdb_init(xhp) != 0)
408 pkgd = xbps_find_pkg_in_dict(xhp->
pkgdb, pkg);
417 if (xbps_pkgdb_init(xhp) != 0)
420 return xbps_find_virtualpkg_in_dict(xhp, xhp->
pkgdb, vpkg);
427 xbps_object_iterator_t iter;
428 xbps_dictionary_t vpkg_cache;
430 if (xhp->pkgdb_revdeps)
433 xhp->pkgdb_revdeps = xbps_dictionary_create();
434 assert(xhp->pkgdb_revdeps);
436 vpkg_cache = xbps_dictionary_create();
439 iter = xbps_dictionary_iterator(xhp->
pkgdb);
442 while ((obj = xbps_object_iterator_next(iter))) {
443 xbps_array_t rundeps;
444 xbps_dictionary_t pkgd;
445 const char *pkgver = NULL;
447 pkgd = xbps_dictionary_get_keysym(xhp->
pkgdb, obj);
448 rundeps = xbps_dictionary_get(pkgd,
"run_depends");
449 if (!xbps_array_count(rundeps))
452 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
453 for (
unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
455 const char *pkgdep = NULL, *v;
456 char curpkgname[XBPS_NAME_SIZE];
459 xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
470 if (!xbps_dictionary_get_cstring_nocopy(vpkg_cache, curpkgname, &v)) {
471 const char *vpkgname = vpkg_user_conf(xhp, curpkgname);
478 if (!xbps_dictionary_set_cstring_nocopy(vpkg_cache, curpkgname, v)) {
484 pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
487 pkg = xbps_array_create();
490 xbps_array_add_cstring_nocopy(pkg, pkgver);
491 xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
494 xbps_object_release(pkg);
497 xbps_object_iterator_release(iter);
498 xbps_object_release(vpkg_cache);
504 xbps_dictionary_t pkgd;
505 const char *pkgver = NULL;
506 char pkgname[XBPS_NAME_SIZE];
511 generate_full_revdeps_tree(xhp);
512 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
516 return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
522 return xbps_get_pkg_fulldeptree(xhp, pkg,
false);
528 xbps_dictionary_t pkgd;
529 const char *pkgver = NULL;
530 char pkgname[XBPS_NAME_SIZE], plist[PATH_MAX];
539 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
543 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_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
void void xbps_error_printf(const char *fmt,...)
Prints error 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,...)