Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add reverse dependency, it is slower than is pkg_install but at leat it doesn't cheat with a awfull +REQUIRED_BY
Baptiste Daroussin committed 15 years ago
commit 750de67caa79b7759b4a42615fdd7c5a8373417c
parent df670b8
5 files changed +33 -0
modified libpkg/pkg.c
@@ -50,6 +50,13 @@ pkg_origin(struct pkg *pkg)
}

int
+
pkg_rdep(struct pkg *pkg, struct pkg *rdep)
+
{
+
	pkg_reset(rdep);
+
	return (pkgdb_cache_rdep(pkg, rdep));
+
}
+

+
int
pkg_dep(struct pkg *pkg, struct pkg *dep)
{
	pkg_reset(dep);
modified libpkg/pkg.h
@@ -50,6 +50,7 @@ const char *pkg_comment(struct pkg *);
const char *pkg_desc(struct pkg *);
const char *pkg_origin(struct pkg *);
int pkg_dep(struct pkg *, struct pkg *);
+
int pkg_rdep(struct pkg *, struct pkg *);

typedef enum pkg_formats { TAR, TGZ, TBZ, TXZ } pkg_formats;
int pkg_create(char *, pkg_formats, const char *, const char *);
modified libpkg/pkgdb_cache.c
@@ -174,6 +174,22 @@ pkgdb_cache_dep(struct pkg *pkg, struct pkg *dep)
	return (ret);
}

+
int
+
pkgdb_cache_rdep(struct pkg *pkg, struct pkg *rdep) {
+
	struct pkg dep;
+

+
	while ((rdep->name = pkgdb_cache_vget(pkg->pdb->cdb, PKGDB_NAME, pkg->irdep)) != NULL) {
+
		rdep->idx = pkg->irdep++;
+
		rdep->pdb = pkg->pdb;
+
		while (pkgdb_cache_dep(rdep, &dep) == 0) {
+
			if (strcmp(dep.name, pkg->name) == 0)
+
				return (0);
+
		}
+
		rdep->idep = 0;
+
	}
+
	return (-1);
+
}
+

static int
pkgdb_cache_rebuild(struct pkgdb *db, const char *pkg_dbdir, const char *cache_path)
{
modified libpkg/pkgdb_cache.h
@@ -11,6 +11,7 @@ const char *pkgdb_cache_getattr(struct pkg *, const char *);
/* query */
int pkgdb_cache_init(struct pkgdb *);
int pkgdb_cache_dep(struct pkg *, struct pkg *);
+
int pkgdb_cache_rdep(struct pkg *, struct pkg *);
int pkgdb_cache_query(struct pkgdb *, struct pkg *);
void pkgdb_cache_free(struct pkgdb *);

modified pkg/info.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <pkg.h>
#include <pkgdb.h>
+
#include <string.h>

#include "info.h"

@@ -65,6 +66,13 @@ cmd_info(int argc, char **argv)
				printf("%s-%s\n", pkg_name(&dep), pkg_version(&pkg));
			}

+
			printf("\n");
+
		} else if (opt & INFO_PRINT_RDEP) {
+
			printf("%s-%s is required by:\n", pkg_name(&pkg), pkg_version(&pkg));
+
			while (pkg_rdep(&pkg, &dep) == 0) {
+
				printf("%s-%s\n", pkg_name(&dep), pkg_version(&dep));
+
			}
+
			printf("\n");
		} else {
			printf("%s-%s: %s\n", pkg_name(&pkg), pkg_version(&pkg), pkg_comment(&pkg));
		}