示例#1
0
文件: depends.c 项目: joyent/pkgin
int
show_direct_depends(const char *pkgarg)
{
	char		*pkgname, query[BUFSIZ];
	Pkglist		*pdp, *mapplist;
	Plisthead	*deptreehead;

	if (SLIST_EMPTY(&r_plisthead)) {
		printf("%s\n", MSG_EMPTY_AVAIL_PKGLIST);
		return EXIT_FAILURE;
	}

	if ((pkgname = unique_pkg(pkgarg, REMOTE_PKG)) == NULL) {
		fprintf(stderr, MSG_PKG_NOT_AVAIL, pkgarg);
		return EXIT_FAILURE;
	}

	deptreehead = init_head();

	snprintf(query, BUFSIZ, EXACT_DIRECT_DEPS, pkgname);

	if (pkgindb_doquery(query, pdb_rec_depends, deptreehead) == PDB_OK) {
		printf(MSG_DIRECT_DEPS_FOR, pkgname);
		SLIST_FOREACH(pdp, deptreehead, next) {
			if (package_version && 
				(mapplist = map_pkg_to_dep(&r_plisthead,
							   pdp->depend))
				!= NULL)
				printf("\t%s\n", mapplist->full);
			else
				printf("\t%s\n", pdp->depend);
		}
		free_pkglist(&deptreehead, DEPTREE);
	}
示例#2
0
/**
 * sqlite callback
 * DIRECT_DEPS or REVERSE_DEPS result, feeds a Pkglist SLIST
 * Plisthead is the head of Pkglist
 */
int
pdb_rec_depends(void *param, int argc, char **argv, char **colname)
{
	Pkglist		*deptree, *pdp, *pkg_map;
	Plisthead	*pdphead = (Plisthead *)param, *plisthead;

	if (argv == NULL)
		return PDB_ERR;

	/* check if dependency is already recorded, do not insert on list  */
	SLIST_FOREACH(pdp, pdphead, next)
		if (strcmp(DEPS_PKGNAME, pdp->name) == 0) {
			TRACE(" < dependency %s already recorded\n", pdp->name);
			/* proceed to next result */
			return PDB_OK;
		}

	deptree = malloc_pkglist(DEPTREE);
	XSTRDUP(deptree->depend, DEPS_FULLPKG);

	/* unresolved pkgname because of complex dependency glob */
	if (non_trivial_glob(DEPS_FULLPKG)) {
		/* check wether we're getting local or remote dependencies */
		if (strncmp(colname[0], "LOCAL_", 6) == 0)
			plisthead = &l_plisthead;
		else
			plisthead = &r_plisthead;

		/* map corresponding pkgname */
		if ((pkg_map = map_pkg_to_dep(plisthead, deptree->depend)) != NULL)
			XSTRDUP(deptree->name, pkg_map->name);
		else
			/* some dependencies just don't match anything */
			XSTRDUP(deptree->name, DEPS_PKGNAME);
	} else
		/* case handled by get_pkgname_from_depend() */
		XSTRDUP(deptree->name, DEPS_PKGNAME);

	deptree->computed = 0;
	deptree->level = 0;
	/* used in LOCAL_REVERSE_DEPS / autoremove.c */
	if (argc > 2 && PKG_KEEP != NULL)
		deptree->keep = 1;
	else
		deptree->keep = 0;

	SLIST_INSERT_HEAD(pdphead, deptree, next);

	return PDB_OK;
}