Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Split request in jobs, add cudf parser.
Vsevolod Stakhov committed 12 years ago
commit 8d462a51204be71188375716f7bba990388a4242
parent c1799c2
4 files changed +107 -10
modified libpkg/pkg.h.in
@@ -1160,6 +1160,12 @@ int pkg_jobs_apply(struct pkg_jobs *jobs);
int pkg_jobs_cudf_emit_file(struct pkg_jobs *, pkg_jobs_t , FILE *, struct pkgdb *);

/**
+
 * Parse the output of an external CUDF solver
+
 * @return error code
+
 */
+
int pkg_jobs_cudf_parse_output(struct pkg_jobs *j, FILE *f);
+

+
/**
 * Solve a SAT problem
 * @return true if a problem is solvable
 */
modified libpkg/pkg_cudf.c
@@ -33,6 +33,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+
#define _WITH_GETLINE
+
#include <stdio.h>

#include "pkg.h"
#include "private/event.h"
@@ -104,7 +106,18 @@ cudf_emit_request_packages(const char *op, struct pkg_jobs *j, FILE *f)

	if (fprintf(f, "%s: ", op) < 0)
		return (EPKG_FATAL);
-
	HASH_ITER(hh, j->request, req, tmp) {
+
	HASH_ITER(hh, j->request_add, req, tmp) {
+
		pkg_get(req->pkg, PKG_ORIGIN, &origin);
+
		if (fprintf(f, "%s%c", origin,
+
				(req->hh.hh_next == NULL) ?
+
						'\n' : ',') < 0) {
+
			return (EPKG_FATAL);
+
		}
+
	}
+

+
	if (fprintf(f, "remove: ") < 0)
+
		return (EPKG_FATAL);
+
	HASH_ITER(hh, j->request_delete, req, tmp) {
		pkg_get(req->pkg, PKG_ORIGIN, &origin);
		if (fprintf(f, "%s%c", origin,
				(req->hh.hh_next == NULL) ?
@@ -138,12 +151,9 @@ pkg_jobs_cudf_emit_file(struct pkg_jobs *j, pkg_jobs_t t, FILE *f, struct pkgdb
	switch (t) {
	case PKG_JOBS_FETCH:
	case PKG_JOBS_INSTALL:
-
		if (cudf_emit_request_packages("install", j, f) != EPKG_OK)
-
			return (EPKG_FATAL);
-
		break;
	case PKG_JOBS_DEINSTALL:
	case PKG_JOBS_AUTOREMOVE:
-
		if (cudf_emit_request_packages("remove", j, f) != EPKG_OK)
+
		if (cudf_emit_request_packages("install", j, f) != EPKG_OK)
			return (EPKG_FATAL);
		break;
	case PKG_JOBS_UPGRADE:
@@ -153,3 +163,64 @@ pkg_jobs_cudf_emit_file(struct pkg_jobs *j, pkg_jobs_t t, FILE *f, struct pkgdb
	}
	return (EPKG_OK);
}
+

+
int
+
pkg_jobs_cudf_parse_output(struct pkg_jobs __unused *j, FILE *f)
+
{
+
	char *line = NULL, *param, *value;
+
	size_t linecap = 0;
+
	ssize_t linelen;
+
	struct {
+
		char *origin;
+
		bool was_installed;
+
		bool installed;
+
		char *version;
+
	} cur_pkg = { NULL, false, false, NULL };
+

+
	while ((linelen = getline(&line, &linecap, f)) > 0) {
+
		value = line;
+
		param = strsep(&value, ": \t");
+
		if (strcmp(param, "package") == 0) {
+
			if (cur_pkg.origin != NULL) {
+
				/* XXX: Add pkg */
+

+
			}
+
			cur_pkg.origin = strdup(value);
+
			cur_pkg.was_installed = false;
+
			cur_pkg.installed = false;
+
			cur_pkg.version = NULL;
+
		}
+
		else if (strcmp(param, "version") == 0) {
+
			if (cur_pkg.origin == NULL) {
+
				free(line);
+
				return (EPKG_FATAL);
+
			}
+
			cur_pkg.version = strdup(value);
+
		}
+
		else if (strcmp(param, "installed") == 0) {
+
			if (cur_pkg.origin == NULL) {
+
				free(line);
+
				return (EPKG_FATAL);
+
			}
+
			if (strcmp(value, "true"))
+
				cur_pkg.installed = true;
+
		}
+
		else if (strcmp(param, "was-installed") == 0) {
+
			if (cur_pkg.origin == NULL) {
+
				free(line);
+
				return (EPKG_FATAL);
+
			}
+
			if (strcmp(value, "true"))
+
				cur_pkg.was_installed = true;
+
		}
+
	}
+

+
	if (cur_pkg.origin != NULL) {
+
		/* XXX: add pkg */
+
	}
+

+
	if (line != NULL)
+
		free(line);
+

+
	return (EPKG_OK);
+
}
modified libpkg/pkg_jobs.c
@@ -158,6 +158,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, const char *origin, struct pkg *pkg, bool a
		HASH_ADD_KEYPTR(hh, j->request_delete, origin, strlen(origin), req);
}

+

static int
populate_local_rdeps(struct pkg_jobs *j, struct pkg *p)
{
modified libpkg/pkg_solve.c
@@ -452,7 +452,7 @@ pkg_solve_jobs_to_sat(struct pkg_jobs *j)
	}

	/* Add requests */
-
	HASH_ITER(hh, j->request, jreq, jtmp) {
+
	HASH_ITER(hh, j->request_add, jreq, jtmp) {
		rule = NULL;
		it = NULL;
		var = NULL;
@@ -466,10 +466,29 @@ pkg_solve_jobs_to_sat(struct pkg_jobs *j)
		if (it == NULL)
			goto err;

-
		if (j->type == PKG_JOBS_DEINSTALL ||
-
				j->type == PKG_JOBS_AUTOREMOVE) {
-
			it->inverse = true;
-
		}
+
		rule = pkg_solve_rule_new();
+
		if (rule == NULL)
+
			goto err;
+

+
		/* Requests are unary rules */
+
		LL_PREPEND(rule->items, it);
+
		LL_PREPEND(problem->rules, rule);
+
	}
+
	HASH_ITER(hh, j->request_delete, jreq, jtmp) {
+
		rule = NULL;
+
		it = NULL;
+
		var = NULL;
+

+
		var = pkg_solve_variable_new(jreq->pkg);
+
		if (var == NULL)
+
			goto err;
+

+
		HASH_ADD_KEYPTR(hh, problem->variables, var->origin, strlen(var->origin), var);
+
		it = pkg_solve_item_new(var);
+
		if (it == NULL)
+
			goto err;
+

+
		it->inverse = true;
		rule = pkg_solve_rule_new();
		if (rule == NULL)
			goto err;