2009-11-26 07:52:50 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2009-11-26 07:52:50 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2015-07-19 15:17:09 +05:30
|
|
|
#include <sys/types.h>
|
2014-02-23 12:53:14 +05:30
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2012-01-20 16:47:27 +05:30
|
|
|
/**
|
|
|
|
* @file lib/pkgdb.c
|
|
|
|
* @brief Package database handling routines
|
|
|
|
* @defgroup pkgdb Package database handling functions
|
|
|
|
*
|
|
|
|
* Functions to manipulate the main package database plist file (pkgdb).
|
|
|
|
*
|
|
|
|
* The following image shown below shows the proplib structure used
|
|
|
|
* by the main package database plist:
|
|
|
|
*
|
2013-09-25 14:45:04 +05:30
|
|
|
* @image html images/xbps_pkgdb_dictionary.png
|
2012-01-20 16:47:27 +05:30
|
|
|
*
|
|
|
|
* Legend:
|
2013-09-25 14:45:04 +05:30
|
|
|
* - <b>Salmon filled box</b>: \a pkgdb plist internalized.
|
2012-01-20 16:47:27 +05:30
|
|
|
* - <b>White filled box</b>: mandatory objects.
|
|
|
|
* - <b>Grey filled box</b>: optional objects.
|
|
|
|
* - <b>Green filled box</b>: possible value set in the object, only one
|
|
|
|
* of them is set.
|
|
|
|
*
|
|
|
|
* Text inside of white boxes are the key associated with the object, its
|
|
|
|
* data type is specified on its edge, i.e array, bool, integer, string,
|
|
|
|
* dictionary.
|
|
|
|
*/
|
2019-06-23 14:35:03 +05:30
|
|
|
static int pkgdb_fd = -1;
|
2020-02-21 13:38:22 +05:30
|
|
|
static bool pkgdb_map_names_done = false;
|
2014-03-04 19:07:10 +05:30
|
|
|
|
2014-02-23 12:53:14 +05:30
|
|
|
int
|
|
|
|
xbps_pkgdb_lock(struct xbps_handle *xhp)
|
|
|
|
{
|
2015-07-19 15:17:09 +05:30
|
|
|
mode_t prev_umask;
|
2017-02-27 22:32:39 +05:30
|
|
|
int rv = 0;
|
2014-02-23 12:53:14 +05:30
|
|
|
/*
|
2014-03-04 19:07:10 +05:30
|
|
|
* Use a mandatory file lock to only allow one writer to pkgdb,
|
|
|
|
* other writers will block.
|
2014-02-23 12:53:14 +05:30
|
|
|
*/
|
2017-02-27 22:32:39 +05:30
|
|
|
prev_umask = umask(022);
|
2014-03-04 19:07:10 +05:30
|
|
|
xhp->pkgdb_plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
|
|
|
if (xbps_pkgdb_init(xhp) == ENOENT) {
|
|
|
|
/* if metadir does not exist, create it */
|
|
|
|
if (access(xhp->metadir, R_OK|X_OK) == -1) {
|
2017-02-27 22:32:39 +05:30
|
|
|
if (errno != ENOENT) {
|
|
|
|
rv = errno;
|
|
|
|
goto ret;
|
|
|
|
}
|
2014-03-04 19:07:10 +05:30
|
|
|
if (xbps_mkpath(xhp->metadir, 0755) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] failed to create metadir "
|
|
|
|
"%s: %s\n", xhp->metadir, strerror(rv));
|
2017-02-27 22:32:39 +05:30
|
|
|
goto ret;
|
2014-03-04 19:07:10 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if pkgdb is unexistent, create it with an empty dictionary */
|
|
|
|
xhp->pkgdb = xbps_dictionary_create();
|
2014-10-24 13:45:41 +05:30
|
|
|
if (!xbps_dictionary_externalize_to_file(xhp->pkgdb, xhp->pkgdb_plist)) {
|
2014-03-04 19:07:10 +05:30
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] failed to create pkgdb "
|
|
|
|
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
2017-02-27 22:32:39 +05:30
|
|
|
goto ret;
|
2014-03-04 19:07:10 +05:30
|
|
|
}
|
|
|
|
}
|
2015-07-19 15:17:09 +05:30
|
|
|
|
2015-04-16 00:32:38 +05:30
|
|
|
if ((pkgdb_fd = open(xhp->pkgdb_plist, O_CREAT|O_RDWR|O_CLOEXEC, 0664)) == -1) {
|
2014-02-23 12:53:14 +05:30
|
|
|
rv = errno;
|
2014-03-04 19:07:10 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] cannot open pkgdb for locking "
|
|
|
|
"%s: %s\n", xhp->pkgdb_plist, strerror(rv));
|
|
|
|
free(xhp->pkgdb_plist);
|
2017-02-27 22:32:39 +05:30
|
|
|
goto ret;
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
2015-07-19 15:17:09 +05:30
|
|
|
|
2019-06-13 20:34:32 +05:30
|
|
|
/*
|
|
|
|
* If we've acquired the file lock, then pkgdb is writable.
|
|
|
|
*/
|
2014-03-04 19:07:10 +05:30
|
|
|
if (lockf(pkgdb_fd, F_TLOCK, 0) == -1) {
|
2014-02-23 12:53:14 +05:30
|
|
|
rv = errno;
|
2014-03-04 19:07:10 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] cannot lock pkgdb: %s\n", strerror(rv));
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
2019-06-13 20:34:32 +05:30
|
|
|
/*
|
|
|
|
* Check if rootdir is writable.
|
|
|
|
*/
|
|
|
|
if (access(xhp->rootdir, W_OK) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] rootdir %s: %s\n", xhp->rootdir, strerror(rv));
|
|
|
|
}
|
2017-02-27 22:32:39 +05:30
|
|
|
|
|
|
|
ret:
|
|
|
|
umask(prev_umask);
|
|
|
|
return rv;
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_pkgdb_unlock(struct xbps_handle *xhp)
|
|
|
|
{
|
2019-06-22 22:17:13 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: pkgdb_fd %d\n", __func__, pkgdb_fd);
|
|
|
|
|
2015-01-10 23:41:31 +05:30
|
|
|
if (pkgdb_fd != -1) {
|
|
|
|
if (lockf(pkgdb_fd, F_ULOCK, 0) == -1)
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] failed to unlock pkgdb: %s\n", strerror(errno));
|
2014-03-04 19:07:10 +05:30
|
|
|
|
2015-01-10 23:41:31 +05:30
|
|
|
(void)close(pkgdb_fd);
|
|
|
|
pkgdb_fd = -1;
|
|
|
|
}
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
|
|
|
|
2014-11-04 15:47:27 +05:30
|
|
|
static int
|
|
|
|
pkgdb_map_vpkgs(struct xbps_handle *xhp)
|
|
|
|
{
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (!xbps_dictionary_count(xhp->pkgdb))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (xhp->vpkgd == NULL) {
|
|
|
|
xhp->vpkgd = xbps_dictionary_create();
|
|
|
|
assert(xhp->vpkgd);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* This maps all pkgs that have virtualpkgs in pkgdb.
|
|
|
|
*/
|
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
|
|
|
assert(iter);
|
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
xbps_array_t provides;
|
|
|
|
xbps_dictionary_t pkgd;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *pkgver = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
|
|
|
unsigned int cnt;
|
2014-11-04 15:47:27 +05:30
|
|
|
|
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
provides = xbps_dictionary_get(pkgd, "provides");
|
2020-02-21 13:38:22 +05:30
|
|
|
cnt = xbps_array_count(provides);
|
|
|
|
if (!cnt)
|
2014-11-04 15:47:27 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
|
|
|
rv = EINVAL;
|
2020-02-21 13:38:22 +05:30
|
|
|
goto out;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
for (unsigned int i = 0; i < cnt; i++) {
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *vpkg = NULL;
|
2014-11-04 15:47:27 +05:30
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(provides, i, &vpkg);
|
|
|
|
if (!xbps_dictionary_set_cstring(xhp->vpkgd, vpkg, pkgname)) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: set_cstring vpkg "
|
|
|
|
"%s pkgname %s\n", __func__, vpkg, pkgname);
|
|
|
|
rv = EINVAL;
|
2020-02-21 13:38:22 +05:30
|
|
|
goto out;
|
2014-11-04 15:47:27 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] added vpkg %s for %s\n", vpkg, pkgname);
|
2014-11-04 15:47:27 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
|
|
|
out:
|
|
|
|
xbps_object_iterator_release(iter);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pkgdb_map_names(struct xbps_handle *xhp)
|
|
|
|
{
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (pkgdb_map_names_done || !xbps_dictionary_count(xhp->pkgdb))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This maps all pkgs in pkgdb to have the "pkgname" string property.
|
|
|
|
* This way we do it once and not multiple times.
|
|
|
|
*/
|
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
|
|
|
assert(iter);
|
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
xbps_dictionary_t pkgd;
|
|
|
|
const char *pkgver;
|
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
|
|
|
|
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
|
|
|
rv = EINVAL;
|
2020-02-09 00:01:29 +05:30
|
|
|
break;
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
|
|
|
if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-04 15:47:27 +05:30
|
|
|
}
|
|
|
|
xbps_object_iterator_release(iter);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!rv) {
|
|
|
|
pkgdb_map_names_done = true;
|
|
|
|
}
|
2014-11-04 15:47:27 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
int HIDDEN
|
2012-01-20 15:40:52 +05:30
|
|
|
xbps_pkgdb_init(struct xbps_handle *xhp)
|
2009-11-26 07:52:50 +05:30
|
|
|
{
|
2011-12-24 05:35:26 +05:30
|
|
|
int rv;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
assert(xhp);
|
|
|
|
|
|
|
|
if (xhp->pkgdb)
|
|
|
|
return 0;
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xhp->pkgdb_plist)
|
2014-03-04 19:29:58 +05:30
|
|
|
xhp->pkgdb_plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2015-01-10 23:56:37 +05:30
|
|
|
#if 0
|
2014-09-11 03:42:12 +05:30
|
|
|
if ((rv = xbps_pkgdb_conversion(xhp)) != 0)
|
|
|
|
return rv;
|
2015-01-10 23:56:37 +05:30
|
|
|
#endif
|
2014-09-11 03:42:12 +05:30
|
|
|
|
|
|
|
|
2015-01-11 00:12:09 +05:30
|
|
|
if ((rv = xbps_pkgdb_update(xhp, false, true)) != 0) {
|
2011-12-24 05:35:26 +05:30
|
|
|
if (rv != ENOENT)
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] cannot internalize "
|
2020-02-21 13:38:22 +05:30
|
|
|
"pkgdb dictionary: %s\n", strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if ((rv = pkgdb_map_names(xhp)) != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] pkgdb_map_names %s\n", strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
2014-11-04 15:47:27 +05:30
|
|
|
if ((rv = pkgdb_map_vpkgs(xhp)) != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] pkgdb_map_vpkgs %s\n", strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
2015-10-30 16:54:46 +05:30
|
|
|
assert(xhp->pkgdb);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] initialized ok.\n");
|
2011-12-24 05:35:26 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-11 00:12:09 +05:30
|
|
|
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
|
2011-12-24 05:35:26 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgdb_storage;
|
2017-02-27 22:54:46 +05:30
|
|
|
mode_t prev_umask;
|
2012-06-15 19:03:11 +05:30
|
|
|
static int cached_rv;
|
2011-12-24 05:35:26 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2012-06-15 19:03:11 +05:30
|
|
|
if (cached_rv && !flush)
|
|
|
|
return cached_rv;
|
|
|
|
|
2019-06-22 22:17:13 +05:30
|
|
|
if (xhp->pkgdb && flush) {
|
2014-12-31 13:21:45 +05:30
|
|
|
pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist);
|
2012-10-26 14:35:17 +05:30
|
|
|
if (pkgdb_storage == NULL ||
|
2013-06-20 13:56:12 +05:30
|
|
|
!xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) {
|
2012-10-26 13:55:14 +05:30
|
|
|
/* flush dictionary to storage */
|
2017-02-27 22:54:46 +05:30
|
|
|
prev_umask = umask(022);
|
|
|
|
if (!xbps_dictionary_externalize_to_file(xhp->pkgdb, xhp->pkgdb_plist)) {
|
|
|
|
umask(prev_umask);
|
2012-10-26 13:55:14 +05:30
|
|
|
return errno;
|
2017-02-27 22:54:46 +05:30
|
|
|
}
|
|
|
|
umask(prev_umask);
|
2011-12-24 05:35:26 +05:30
|
|
|
}
|
2012-10-26 14:35:17 +05:30
|
|
|
if (pkgdb_storage)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(pkgdb_storage);
|
2012-10-26 14:35:17 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(xhp->pkgdb);
|
2012-01-20 15:40:52 +05:30
|
|
|
xhp->pkgdb = NULL;
|
2012-06-15 19:03:11 +05:30
|
|
|
cached_rv = 0;
|
2011-01-19 00:48:27 +05:30
|
|
|
}
|
2015-01-11 00:12:09 +05:30
|
|
|
if (!update)
|
|
|
|
return rv;
|
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
/* update copy in memory */
|
2014-12-31 13:21:45 +05:30
|
|
|
if ((xhp->pkgdb = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist)) == NULL) {
|
2015-05-22 15:48:54 +05:30
|
|
|
rv = errno;
|
|
|
|
if (!rv)
|
|
|
|
rv = EINVAL;
|
|
|
|
|
|
|
|
if (rv == ENOENT)
|
2013-06-20 13:56:12 +05:30
|
|
|
xhp->pkgdb = xbps_dictionary_create();
|
2013-01-15 17:44:30 +05:30
|
|
|
else
|
2015-05-22 15:48:54 +05:30
|
|
|
xbps_error_printf("cannot access to pkgdb: %s\n", strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2012-11-11 14:33:14 +05:30
|
|
|
cached_rv = rv = errno;
|
|
|
|
}
|
2011-01-19 00:48:27 +05:30
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
return rv;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
void HIDDEN
|
2012-01-20 15:40:52 +05:30
|
|
|
xbps_pkgdb_release(struct xbps_handle *xhp)
|
2009-11-26 07:52:50 +05:30
|
|
|
{
|
2019-06-22 22:17:13 +05:30
|
|
|
assert(xhp);
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_pkgdb_unlock(xhp);
|
2019-06-22 22:17:13 +05:30
|
|
|
if (xhp->pkgdb)
|
|
|
|
xbps_object_release(xhp->pkgdb);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "[pkgdb] released ok.\n");
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2011-12-22 18:55:27 +05:30
|
|
|
|
2011-12-23 12:46:25 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_pkgdb_foreach_cb(struct xbps_handle *xhp,
|
2013-07-27 13:17:16 +05:30
|
|
|
int (*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *),
|
|
|
|
void *arg)
|
2011-12-23 12:46:25 +05:30
|
|
|
{
|
2013-07-27 13:17:16 +05:30
|
|
|
xbps_array_t allkeys;
|
2013-03-05 08:38:42 +05:30
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
2013-07-27 13:17:16 +05:30
|
|
|
allkeys = xbps_dictionary_all_keys(xhp->pkgdb);
|
|
|
|
assert(allkeys);
|
|
|
|
rv = xbps_array_foreach_cb(xhp, allkeys, xhp->pkgdb, fn, arg);
|
|
|
|
xbps_object_release(allkeys);
|
2013-03-05 08:38:42 +05:30
|
|
|
return rv;
|
2011-12-23 12:46:25 +05:30
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2013-09-17 20:00:13 +05:30
|
|
|
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_array_t allkeys;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
allkeys = xbps_dictionary_all_keys(xhp->pkgdb);
|
|
|
|
assert(allkeys);
|
|
|
|
rv = xbps_array_foreach_cb_multi(xhp, allkeys, xhp->pkgdb, fn, arg);
|
|
|
|
xbps_object_release(allkeys);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
|
2011-12-24 05:35:26 +05:30
|
|
|
{
|
2012-01-20 15:40:52 +05:30
|
|
|
if (xbps_pkgdb_init(xhp) != 0)
|
2011-12-24 05:35:26 +05:30
|
|
|
return NULL;
|
|
|
|
|
2013-03-05 08:38:42 +05:30
|
|
|
return xbps_find_pkg_in_dict(xhp->pkgdb, pkg);
|
2011-12-24 05:35:26 +05:30
|
|
|
}
|
2011-12-24 20:39:30 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *vpkg)
|
2012-11-20 02:16:54 +05:30
|
|
|
{
|
|
|
|
if (xbps_pkgdb_init(xhp) != 0)
|
|
|
|
return NULL;
|
|
|
|
|
2013-03-05 08:38:42 +05:30
|
|
|
return xbps_find_virtualpkg_in_dict(xhp, xhp->pkgdb, vpkg);
|
2012-11-20 02:16:54 +05:30
|
|
|
}
|
|
|
|
|
2012-12-15 12:03:49 +05:30
|
|
|
static void
|
|
|
|
generate_full_revdeps_tree(struct xbps_handle *xhp)
|
2012-11-30 22:10:52 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2012-11-30 22:10:52 +05:30
|
|
|
|
2012-12-15 12:03:49 +05:30
|
|
|
if (xhp->pkgdb_revdeps)
|
|
|
|
return;
|
2012-11-30 22:10:52 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xhp->pkgdb_revdeps = xbps_dictionary_create();
|
2014-11-04 15:47:27 +05:30
|
|
|
assert(xhp->pkgdb_revdeps);
|
2012-11-30 22:10:52 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
2012-11-30 22:10:52 +05:30
|
|
|
assert(iter);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
2014-11-04 15:47:27 +05:30
|
|
|
xbps_array_t rundeps;
|
|
|
|
xbps_dictionary_t pkgd;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *pkgver = NULL;
|
2014-11-04 15:47:27 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
rundeps = xbps_dictionary_get(pkgd, "run_depends");
|
|
|
|
if (!xbps_array_count(rundeps))
|
2012-11-30 22:10:52 +05:30
|
|
|
continue;
|
|
|
|
|
2015-01-10 10:13:35 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
|
2014-11-04 15:47:27 +05:30
|
|
|
xbps_array_t pkg;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *pkgdep = NULL, *vpkgname = NULL;
|
2020-02-09 00:01:29 +05:30
|
|
|
char *v, curpkgname[XBPS_NAME_SIZE];
|
2014-11-04 15:47:27 +05:30
|
|
|
bool alloc = false;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
|
2020-02-09 00:01:29 +05:30
|
|
|
if ((!xbps_pkgpattern_name(curpkgname, sizeof(curpkgname), pkgdep)) &&
|
|
|
|
(!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))) {
|
|
|
|
abort();
|
|
|
|
}
|
2016-03-24 14:53:20 +05:30
|
|
|
vpkgname = vpkg_user_conf(xhp, curpkgname, false);
|
2020-02-09 00:01:29 +05:30
|
|
|
if (vpkgname == NULL) {
|
|
|
|
v = strdup(curpkgname);
|
|
|
|
} else {
|
|
|
|
v = strdup(vpkgname);
|
|
|
|
}
|
2012-12-15 12:03:49 +05:30
|
|
|
|
2020-02-09 00:01:29 +05:30
|
|
|
pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
|
2012-12-15 12:03:49 +05:30
|
|
|
if (pkg == NULL) {
|
|
|
|
alloc = true;
|
2013-06-20 13:56:12 +05:30
|
|
|
pkg = xbps_array_create();
|
2012-12-15 12:03:49 +05:30
|
|
|
}
|
2013-03-10 13:28:37 +05:30
|
|
|
if (!xbps_match_string_in_array(pkg, pkgver)) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add_cstring_nocopy(pkg, pkgver);
|
2020-02-09 00:01:29 +05:30
|
|
|
xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
|
2013-03-10 13:28:37 +05:30
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
free(v);
|
2012-12-15 12:03:49 +05:30
|
|
|
if (alloc)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(pkg);
|
2012-11-30 22:10:52 +05:30
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2012-12-15 12:03:49 +05:30
|
|
|
}
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t
|
2012-12-15 12:03:49 +05:30
|
|
|
xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *pkgver = NULL;
|
2020-02-09 00:01:29 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE];
|
2012-12-15 12:03:49 +05:30
|
|
|
|
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
generate_full_revdeps_tree(xhp);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
2014-10-07 11:27:38 +05:30
|
|
|
return NULL;
|
|
|
|
|
2020-02-09 00:01:29 +05:30
|
|
|
return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
|
2012-11-30 22:10:52 +05:30
|
|
|
}
|
|
|
|
|
2014-11-20 13:53:51 +05:30
|
|
|
xbps_array_t
|
|
|
|
xbps_pkgdb_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg)
|
|
|
|
{
|
|
|
|
return xbps_get_pkg_fulldeptree(xhp, pkg, false);
|
|
|
|
}
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t
|
2014-09-11 03:42:12 +05:30
|
|
|
xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
2012-11-30 22:10:52 +05:30
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *pkgver = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE], plist[PATH_MAX];
|
2013-12-08 12:37:10 +05:30
|
|
|
|
|
|
|
if (pkg == NULL)
|
|
|
|
return NULL;
|
2012-11-30 22:10:52 +05:30
|
|
|
|
|
|
|
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
|
|
|
|
if (pkgd == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-12-08 12:37:10 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
|
|
|
return NULL;
|
2013-12-08 12:37:10 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
snprintf(plist, sizeof(plist)-1, "%s/.%s-files.plist", xhp->metadir, pkgname);
|
|
|
|
return xbps_plist_dictionary_from_file(xhp, plist);
|
2012-11-30 22:10:52 +05:30
|
|
|
}
|