Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Re-solve upgrade conflicts.
Vsevolod Stakhov committed 12 years ago
commit 1662a8adb19c9bd18603c56b8fdc396a584c3c6c
parent 69d9856
2 files changed +57 -32
modified libpkg/pkg_jobs.c
@@ -186,9 +186,33 @@ MAKE_JOBS_ITER_FUNC(upgrade)
#undef MAKE_JOBS_ITER_FUNC

static void
-
pkg_jobs_add_req(struct pkg_jobs *j, const char *origin, struct pkg *pkg, bool add, int priority)
+
pkg_jobs_add_req(struct pkg_jobs *j, const char *origin, struct pkg *pkg,
+
		bool add, int priority)
{
-
	struct pkg_job_request *req;
+
	struct pkg_job_request *req, *test, **head;
+
	bool replace = false;
+

+
	if (add)
+
		head = &j->request_add;
+
	else
+
		head = &j->request_delete;
+

+
	HASH_FIND(hh, *head, origin, strlen(origin), test);
+

+
	if (test != NULL) {
+
		if (test->priority < priority)
+
			replace = true;
+

+
		pkg_debug(1, "the request already has package with origin %s, we want "
+
				"to %s it by priority (%s) vs (%s)", origin,
+
				replace ? "replace" : "keep",
+
				test->priority, priority);
+
		if (replace) {
+
			test->pkg = pkg;
+
			test->priority = priority;
+
		}
+
		return;
+
	}

	req = calloc(1, sizeof (struct pkg_job_request));
	if (req == NULL) {
@@ -198,10 +222,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, const char *origin, struct pkg *pkg, bool a
	req->pkg = pkg;
	req->priority = priority;

-
	if (add)
-
		HASH_ADD_KEYPTR(hh, j->request_add, origin, strlen(origin), req);
-
	else
-
		HASH_ADD_KEYPTR(hh, j->request_delete, origin, strlen(origin), req);
+
	HASH_ADD_KEYPTR(hh, *head, origin, strlen(origin), req);
}

/**
modified pkg/upgrade.c
@@ -51,13 +51,13 @@ exec_upgrade(int argc, char **argv)
	int retcode;
	int updcode;
	int ch;
-
	bool yes;
+
	bool yes, yes_arg;
	bool dry_run = false;
	bool auto_update;
	nbactions = nbdone = 0;
	pkg_flags f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;

-
	pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
+
	pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes_arg);
	pkg_config_bool(PKG_CONFIG_REPO_AUTOUPDATE, &auto_update);


@@ -149,34 +149,38 @@ exec_upgrade(int argc, char **argv)
	if (pkg_jobs_solve(jobs) != EPKG_OK)
		goto cleanup;

-
	if ((nbactions = pkg_jobs_count(jobs)) == 0) {
-
		if (!quiet)
-
			printf("Nothing to do\n");
-
		retcode = EXIT_SUCCESS;
-
		goto cleanup;
-
	}
-

-
	if (!quiet || dry_run) {
-
		print_jobs_summary(jobs,
-
		    "Upgrades have been requested for the following %d "
-
		    "packages (%d packages in the universe):\n\n", nbactions, pkg_jobs_total(jobs));
-

-
		if (!yes && !dry_run)
-
			yes = query_yesno("\nProceed with upgrading "
-
			          "packages [y/N]: ");
-
		if (dry_run)
-
			yes = false;
-
	}
+
	while ((nbactions = pkg_jobs_count(jobs)) > 0) {
+
		/* print a summary before applying the jobs */
+
		yes = yes_arg;
+
		if (!quiet || dry_run) {
+
			print_jobs_summary(jobs,
+
				"Upgrades have been requested for the following %d "
+
				"packages (%d packages in the universe):\n\n", nbactions, pkg_jobs_total(jobs));
+

+
			if (!yes && !dry_run)
+
				yes = query_yesno("\nProceed with upgrading "
+
						"packages [y/N]: ");
+
			if (dry_run)
+
				yes = false;
+
		}

-
	if (yes && pkg_jobs_apply(jobs) != EPKG_OK)
-
		goto cleanup;
+
		if (yes) {
+
			retcode = pkg_jobs_apply(jobs);
+
			if (retcode == EPKG_CONFLICT) {
+
				continue;
+
			}
+
			else if (retcode != EPKG_OK)
+
				goto cleanup;
+
		}

-
	if (messages != NULL) {
-
		sbuf_finish(messages);
-
		printf("%s", sbuf_data(messages));
+
		if (messages != NULL) {
+
			sbuf_finish(messages);
+
			printf("%s", sbuf_data(messages));
+
		}
+
		break;
	}

-
	retcode = EXIT_SUCCESS;
+
	retcode = EX_OK;

cleanup:
	pkg_jobs_free(jobs);