[pacman-dev] [PATCH] Add a new reason field to pmconflict_t struct

Nagy Gabor ngaba at bibl.u-szeged.hu
Mon Aug 31 22:16:38 UTC 2009


>From 841439f2d5d8c8e750d7abe186a22f53f7f87729 Mon Sep 17 00:00:00 2001
From: Nagy Gabor <ngaba at bibl.u-szeged.hu>
Date: Mon, 31 Aug 2009 16:20:18 +0200
Subject: [PATCH] Add a new reason field to pmconflict_t struct

Sometimes "foo conflicts with bar" information is not enough, see this
thread: http://bbs.archlinux.org/viewtopic.php?id=77647. That's why I added
a new reason field to our pmconflict_t struct that stores the packager-
defined conflict that induced the fact that package1 conflicts with
package2.

I modified the front-end (in callback.c, sync.c, upgrade.c) to print this
new information as well (only if reason differs from package2).

Signed-off-by: Nagy Gabor <ngaba at bibl.u-szeged.hu>
---
 lib/libalpm/alpm.h     |    1 +
 lib/libalpm/conflict.c |   24 +++++++++++++++++++-----
 lib/libalpm/conflict.h |    3 ++-
 lib/libalpm/sync.c     |    2 +-
 src/pacman/callback.c  |   18 ++++++++++++++----
 src/pacman/sync.c      |   13 ++++++++++---
 src/pacman/upgrade.c   |   11 +++++++++--
 7 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 1f33078..86dd621 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -443,6 +443,7 @@ alpm_list_t *alpm_checkconflicts(alpm_list_t *pkglist);
 
 const char *alpm_conflict_get_package1(pmconflict_t *conflict);
 const char *alpm_conflict_get_package2(pmconflict_t *conflict);
+const char *alpm_conflict_get_reason(pmconflict_t *conflict);
 
 pmdepmod_t alpm_dep_get_mod(const pmdepend_t *dep);
 const char *alpm_dep_get_name(const pmdepend_t *dep);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 07ef73c..be97f00 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -41,7 +41,7 @@
 #include "cache.h"
 #include "deps.h"
 
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2)
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason)
 {
 	pmconflict_t *conflict;
 
@@ -51,6 +51,7 @@ pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2)
 
 	STRDUP(conflict->package1, package1, RET_ERR(PM_ERR_MEMORY, NULL));
 	STRDUP(conflict->package2, package2, RET_ERR(PM_ERR_MEMORY, NULL));
+	STRDUP(conflict->reason, reason, RET_ERR(PM_ERR_MEMORY, NULL));
 
 	return(conflict);
 }
@@ -59,6 +60,7 @@ void _alpm_conflict_free(pmconflict_t *conflict)
 {
 	FREE(conflict->package2);
 	FREE(conflict->package1);
+	FREE(conflict->reason);
 	FREE(conflict);
 }
 
@@ -69,6 +71,7 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
 
 	STRDUP(newconflict->package1, conflict->package1, RET_ERR(PM_ERR_MEMORY, NULL));
 	STRDUP(newconflict->package2, conflict->package2, RET_ERR(PM_ERR_MEMORY, NULL));
+	STRDUP(newconflict->reason, conflict->reason, RET_ERR(PM_ERR_MEMORY, NULL));
 
 	return(newconflict);
 }
@@ -122,9 +125,9 @@ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
  * @param pkg2 package causing conflict
  */
 static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
-		const char *pkg2)
+		const char *pkg2, const char *reason)
 {
-	pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2);
+	pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
 	if(conflict && !_alpm_conflict_isin(conflict, *baddeps)) {
 		*baddeps = alpm_list_add(*baddeps, conflict);
 	} else {
@@ -168,9 +171,9 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
 
 				if(does_conflict(pkg1, conflict, pkg2)) {
 					if(order >= 0) {
-						add_conflict(baddeps, pkg1name, pkg2name);
+						add_conflict(baddeps, pkg1name, pkg2name, conflict);
 					} else {
-						add_conflict(baddeps, pkg2name, pkg1name);
+						add_conflict(baddeps, pkg2name, pkg1name, conflict);
 					}
 				}
 			}
@@ -578,6 +581,17 @@ const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
 	return conflict->package2;
 }
 
+const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
+{
+	ALPM_LOG_FUNC;
+
+	/* Sanity checks */
+	ASSERT(handle != NULL, return(NULL));
+	ASSERT(conflict != NULL, return(NULL));
+
+	return conflict->reason;
+}
+
 const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
 {
 	ALPM_LOG_FUNC;
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 149c728..73a6e95 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -27,6 +27,7 @@
 struct __pmconflict_t {
 	char *package1;
 	char *package2;
+	char *reason;
 };
 
 struct __pmfileconflict_t {
@@ -36,7 +37,7 @@ struct __pmfileconflict_t {
 	char *ctarget;
 };
 
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2);
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason);
 pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
 void _alpm_conflict_free(pmconflict_t *conflict);
 int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 4763924..dda4953 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -504,7 +504,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
 			pmpkg_t *local = _alpm_db_get_pkgfromcache(db_local, conflict->package2);
 			int doremove = 0;
 			QUESTION(trans, PM_TRANS_CONV_CONFLICT_PKG, conflict->package1,
-								conflict->package2, NULL, &doremove);
+							conflict->package2, conflict->reason, &doremove);
 			if(doremove) {
 				/* append to the removes list */
 				_alpm_log(PM_LOG_DEBUG, "electing '%s' for removal\n", conflict->package2);
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 8b611f1..3df3ef5 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -259,10 +259,20 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
 					alpm_pkg_get_name(data2));
 			break;
 		case PM_TRANS_CONV_CONFLICT_PKG:
-			*response = yesno(_(":: %s conflicts with %s. Remove %s?"),
-					(char *)data1,
-					(char *)data2,
-					(char *)data2);
+			/* data parameters: package1, package2, conflict (string) */
+			/* print conflict only if it contains more information than package2 */
+			if(!strcmp(data2, data3)) {
+				*response = yesno(_(":: %s conflicts with %s. Remove %s?"),
+						(char *)data1,
+						(char *)data2,
+						(char *)data2);
+			} else {
+				*response = yesno(_(":: %s conflicts with %s (%s). Remove %s?"),
+						(char *)data1,
+						(char *)data2,
+						(char *)data3,
+						(char *)data2);
+			}
 			break;
 		case PM_TRANS_CONV_REMOVE_PKGS:
 			{
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index dc93621..3314545 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -650,10 +650,17 @@ static int sync_trans(alpm_list_t *targets)
 				}
 				break;
 			case PM_ERR_CONFLICTING_DEPS:
-			  for(i = data; i; i = alpm_list_next(i)) {
+				for(i = data; i; i = alpm_list_next(i)) {
 					pmconflict_t *conflict = alpm_list_getdata(i);
-					printf(_(":: %s: conflicts with %s\n"),
-							alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
+					const char *package1 = alpm_conflict_get_package1(conflict);
+					const char *package2 = alpm_conflict_get_package2(conflict);
+					const char *reason = alpm_conflict_get_reason(conflict);
+					/* only print reason if it contains more information than package2 */
+					if(!strcmp(package2, reason)) {
+						printf(_(":: %s: conflicts with %s\n"), package1, package2);
+					} else {
+						printf(_(":: %s: conflicts with %s (%s)\n"), package1, package2, reason);
+					}
 				}
 				break;
 			default:
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 1570f95..9c3690d 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -104,8 +104,15 @@ int pacman_upgrade(alpm_list_t *targets)
 			case PM_ERR_CONFLICTING_DEPS:
 				for(i = data; i; i = alpm_list_next(i)) {
 					pmconflict_t *conflict = alpm_list_getdata(i);
-					printf(_(":: %s: conflicts with %s\n"),
-						alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
+					const char *package1 = alpm_conflict_get_package1(conflict);
+					const char *package2 = alpm_conflict_get_package2(conflict);
+					const char *reason = alpm_conflict_get_reason(conflict);
+					/* only print reason if it contains more information than package2 */
+					if(!strcmp(package2, reason)) {
+						printf(_(":: %s: conflicts with %s\n"), package1, package2);
+					} else {
+						printf(_(":: %s: conflicts with %s (%s)\n"), package1, package2, reason);
+					}
 				}
 				break;
 			case PM_ERR_FILE_CONFLICTS:
-- 
1.6.0.3





More information about the pacman-dev mailing list