2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2014-08-19 16:44:37 +05:30
|
|
|
* Copyright (c) 2009-2014 Juan Romero Pardines.
|
2012-11-02 19:34:25 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
2014-08-19 16:44:37 +05:30
|
|
|
#include "queue.h"
|
|
|
|
|
|
|
|
struct pkgdep {
|
|
|
|
SLIST_ENTRY(pkgdep) pkgdep_entries;
|
|
|
|
const char *pkg;
|
|
|
|
xbps_array_t rdeps;
|
|
|
|
};
|
|
|
|
|
|
|
|
static SLIST_HEAD(pkgdep_head, pkgdep) pkgdep_list =
|
|
|
|
SLIST_HEAD_INITIALIZER(pkgdep_list);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-10-29 14:16:54 +05:30
|
|
|
static xbps_dictionary_t pkgdep_pvmap;
|
|
|
|
|
2013-03-05 08:38:42 +05:30
|
|
|
static void
|
2014-08-19 16:44:37 +05:30
|
|
|
print_rdeps(struct xbps_handle *xhp, xbps_array_t rdeps, bool full, bool repo)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t currdeps;
|
|
|
|
xbps_dictionary_t pkgd;
|
2014-08-19 16:44:37 +05:30
|
|
|
const char *curdep;
|
2013-03-05 08:38:42 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
2014-08-19 16:44:37 +05:30
|
|
|
struct pkgdep *pd;
|
|
|
|
const char *pkgver;
|
|
|
|
bool virtual = false, found = false;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
|
|
|
|
if (!full) {
|
|
|
|
printf("%s\n", curdep);
|
2013-03-05 08:38:42 +05:30
|
|
|
continue;
|
2014-08-19 16:44:37 +05:30
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
if (repo) {
|
2014-08-23 12:17:38 +05:30
|
|
|
if ((pkgd = xbps_rpool_get_pkg(xhp, curdep)) == NULL) {
|
2014-08-19 16:44:37 +05:30
|
|
|
pkgd = xbps_rpool_get_virtualpkg(xhp, curdep);
|
2014-08-23 12:17:38 +05:30
|
|
|
virtual = true;
|
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
} else {
|
2014-08-19 16:44:37 +05:30
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, curdep)) == NULL) {
|
|
|
|
pkgd = xbps_pkgdb_get_virtualpkg(xhp, curdep);
|
|
|
|
virtual = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(pkgd);
|
|
|
|
currdeps = xbps_dictionary_get(pkgd, "run_depends");
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
assert(pkgver);
|
|
|
|
if (virtual) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = xbps_pkgpattern_name(curdep)) == NULL)
|
|
|
|
p = xbps_pkg_name(curdep);
|
|
|
|
|
|
|
|
assert(p);
|
2014-10-29 14:16:54 +05:30
|
|
|
if (pkgdep_pvmap == NULL)
|
|
|
|
pkgdep_pvmap = xbps_dictionary_create();
|
|
|
|
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkgdep_pvmap, p, pkgver);
|
2014-08-19 16:44:37 +05:30
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
/* uniquify dependencies, sorting will be done later */
|
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
|
2014-10-29 14:16:54 +05:30
|
|
|
if (strcmp(pd->pkg, pkgver) == 0) {
|
2014-08-19 16:44:37 +05:30
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
2014-08-19 16:44:37 +05:30
|
|
|
if (!found) {
|
|
|
|
pd = malloc(sizeof(*pd));
|
|
|
|
assert(pd);
|
2014-10-29 14:16:54 +05:30
|
|
|
pd->pkg = pkgver;
|
2014-08-19 16:44:37 +05:30
|
|
|
pd->rdeps = xbps_array_copy(currdeps);
|
|
|
|
SLIST_INSERT_HEAD(&pkgdep_list, pd, pkgdep_entries);
|
2014-08-23 12:17:38 +05:30
|
|
|
//printf("Added %s into the slist\n", pd->pkg);
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
2014-08-19 16:44:37 +05:30
|
|
|
if (xbps_array_count(currdeps))
|
|
|
|
print_rdeps(xhp, currdeps, full, repo);
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-08-19 16:44:37 +05:30
|
|
|
static xbps_array_t
|
|
|
|
sort_rdeps(void)
|
2013-03-05 08:38:42 +05:30
|
|
|
{
|
2014-08-19 16:44:37 +05:30
|
|
|
struct pkgdep *pd;
|
|
|
|
xbps_array_t result;
|
|
|
|
unsigned int ndeps = 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-08-19 16:44:37 +05:30
|
|
|
result = xbps_array_create();
|
|
|
|
assert(result);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-08-19 16:44:37 +05:30
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
|
|
|
|
if (!pd->rdeps) {
|
|
|
|
xbps_array_add_cstring_nocopy(result, pd->pkg);
|
|
|
|
SLIST_REMOVE(&pkgdep_list, pd, pkgdep, pkgdep_entries);
|
2012-11-30 22:10:52 +05:30
|
|
|
}
|
2014-08-19 16:44:37 +05:30
|
|
|
ndeps++;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2014-08-19 16:44:37 +05:30
|
|
|
while (xbps_array_count(result) < ndeps) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
|
|
|
|
unsigned int i = 0, mdeps = 0, rdeps = 0;
|
|
|
|
|
|
|
|
rdeps = xbps_array_count(pd->rdeps);
|
|
|
|
for (i = 0; i < rdeps; i++) {
|
|
|
|
const char *pkgdep;
|
|
|
|
char *pkgname;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(pd->rdeps, i, &pkgdep);
|
2014-10-29 14:16:54 +05:30
|
|
|
if ((pkgname = xbps_pkgpattern_name(pkgdep)) == NULL)
|
2014-08-19 16:44:37 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgdep);
|
|
|
|
|
2014-10-29 14:16:54 +05:30
|
|
|
assert(pkgname);
|
|
|
|
if (xbps_match_pkgname_in_array(result, pkgname)) {
|
2014-08-19 16:44:37 +05:30
|
|
|
mdeps++;
|
2014-10-29 14:16:54 +05:30
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xbps_dictionary_get(pkgdep_pvmap, pkgname)) {
|
|
|
|
mdeps++;
|
|
|
|
free(pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//printf("%s: missing dep %s\n", pd->pkg, pkgdep);
|
2014-08-19 16:44:37 +05:30
|
|
|
free(pkgname);
|
|
|
|
}
|
|
|
|
if (mdeps == rdeps) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-23 12:17:38 +05:30
|
|
|
/*
|
|
|
|
printf("%s ndeps: %u result: %u rdeps: %u mdeps: %u\n",
|
|
|
|
pd->pkg, ndeps, xbps_array_count(result), rdeps, mdeps);
|
|
|
|
*/
|
2014-08-19 16:44:37 +05:30
|
|
|
}
|
|
|
|
if (found && !xbps_match_string_in_array(result, pd->pkg)) {
|
|
|
|
xbps_array_add_cstring_nocopy(result, pd->pkg);
|
|
|
|
SLIST_REMOVE(&pkgdep_list, pd, pkgdep, pkgdep_entries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-08-19 16:44:37 +05:30
|
|
|
show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool repomode, bool full)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2014-08-19 16:44:37 +05:30
|
|
|
xbps_array_t rdeps, res;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-08-19 16:44:37 +05:30
|
|
|
if (repomode) {
|
|
|
|
if (((pkgd = xbps_rpool_get_pkg(xhp, pkgname)) == NULL) &&
|
|
|
|
((pkgd = xbps_rpool_get_virtualpkg(xhp, pkgname)) == NULL))
|
|
|
|
return errno;
|
|
|
|
} else {
|
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL)
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
if ((rdeps = xbps_dictionary_get(pkgd, "run_depends")))
|
|
|
|
print_rdeps(xhp, rdeps, full, repomode);
|
|
|
|
if (full) {
|
|
|
|
res = sort_rdeps();
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(res); i++) {
|
|
|
|
const char *pkgdep;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(res, i, &pkgdep);
|
|
|
|
printf("%s\n", pkgdep);
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2012-11-21 07:22:36 +05:30
|
|
|
|
|
|
|
int
|
2014-08-19 16:44:37 +05:30
|
|
|
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg, bool repomode)
|
2012-11-21 07:22:36 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t revdeps;
|
2014-08-19 16:44:37 +05:30
|
|
|
const char *pkgdep;
|
2013-06-14 11:43:51 +05:30
|
|
|
|
2014-08-19 16:44:37 +05:30
|
|
|
if (repomode)
|
|
|
|
revdeps = xbps_rpool_get_pkg_revdeps(xhp, pkg);
|
2014-08-19 20:29:25 +05:30
|
|
|
else
|
|
|
|
revdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkg);
|
2014-08-19 16:44:37 +05:30
|
|
|
|
|
|
|
if (revdeps == NULL)
|
|
|
|
return ENOENT;
|
2013-06-14 11:43:51 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(revdeps); i++) {
|
2014-08-19 16:44:37 +05:30
|
|
|
xbps_array_get_cstring_nocopy(revdeps, i, &pkgdep);
|
|
|
|
printf("%s\n", pkgdep);
|
2013-06-11 19:48:40 +05:30
|
|
|
}
|
2014-08-19 16:44:37 +05:30
|
|
|
return 0;
|
2012-11-21 07:22:36 +05:30
|
|
|
}
|