[pacman-dev] [PATCH 1/5] Make pmfileconflict_t type public

Dan McGee dan at archlinux.org
Thu Jun 16 13:01:33 EDT 2011


This removes the need to write accessor methods for every type we have,
and simplifies the API. Any type that doesn't need magic* can be
converted in this fashion to make it easier for frontend applications to
use, as well as make it less of a pain to introduce new such structs in
the future.

* "magic" meaning something like pmpkg_t where values can be lazy loaded.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 lib/libalpm/alpm.h     |   36 +++++++++++++++++++-----------------
 lib/libalpm/conflict.c |   24 ------------------------
 lib/libalpm/conflict.h |    7 -------
 src/pacman/sync.c      |    9 +++------
 src/pacman/upgrade.c   |    9 +++------
 5 files changed, 25 insertions(+), 60 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index bfc01e5..4c44a36 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -50,7 +50,7 @@ extern "C" {
  */
 
 /**
- * Install reasons
+ * Install reasons.
  * Why the package was installed.
  */
 typedef enum _pmpkgreason_t {
@@ -61,6 +61,16 @@ typedef enum _pmpkgreason_t {
 } pmpkgreason_t;
 
 /**
+ * File conflict type.
+ * Whether the conflict results from a file existing on the filesystem, or with
+ * another target in the transaction.
+ */
+typedef enum _pmfileconflicttype_t {
+	PM_FILECONFLICT_TARGET = 1,
+	PM_FILECONFLICT_FILESYSTEM
+} pmfileconflicttype_t;
+
+/**
  * GPG signature verification options
  */
 typedef enum _pgp_verify_t {
@@ -83,7 +93,14 @@ typedef struct __pmtrans_t pmtrans_t;
 typedef struct __pmdepend_t pmdepend_t;
 typedef struct __pmdepmissing_t pmdepmissing_t;
 typedef struct __pmconflict_t pmconflict_t;
-typedef struct __pmfileconflict_t pmfileconflict_t;
+
+/** File conflict */
+typedef struct _pmfileconflict_t {
+	char *target;
+	pmfileconflicttype_t type;
+	char *file;
+	char *ctarget;
+} pmfileconflict_t;
 
 /*
  * Logging facilities
@@ -944,21 +961,6 @@ char *alpm_dep_compute_string(const pmdepend_t *dep);
 
 /** @} */
 
-/** @addtogroup alpm_api_fileconflicts File Conflicts Functions
- * Functions to manipulate file conflict information.
- * @{
- */
-
-typedef enum _pmfileconflicttype_t {
-	PM_FILECONFLICT_TARGET = 1,
-	PM_FILECONFLICT_FILESYSTEM
-} pmfileconflicttype_t;
-
-const char *alpm_fileconflict_get_target(pmfileconflict_t *conflict);
-pmfileconflicttype_t alpm_fileconflict_get_type(pmfileconflict_t *conflict);
-const char *alpm_fileconflict_get_file(pmfileconflict_t *conflict);
-const char *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict);
-
 /** @} */
 
 /*
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index a6bbe09..d9a0b7c 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -565,28 +565,4 @@ const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
 	return conflict->reason;
 }
 
-const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
-{
-	ASSERT(conflict != NULL, return NULL);
-	return conflict->target;
-}
-
-pmfileconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conflict)
-{
-	ASSERT(conflict != NULL, return -1);
-	return conflict->type;
-}
-
-const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict)
-{
-	ASSERT(conflict != NULL, return NULL);
-	return conflict->file;
-}
-
-const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict)
-{
-	ASSERT(conflict != NULL, return NULL);
-	return conflict->ctarget;
-}
-
 /* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 7a3784a..a9d3e27 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -30,13 +30,6 @@ struct __pmconflict_t {
 	char *reason;
 };
 
-struct __pmfileconflict_t {
-	char *target;
-	pmfileconflicttype_t type;
-	char *file;
-	char *ctarget;
-};
-
 pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
 void _alpm_conflict_free(pmconflict_t *conflict);
 alpm_list_t *_alpm_innerconflicts(pmhandle_t *handle, alpm_list_t *packages);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 37b9d6e..2c21d57 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -849,17 +849,14 @@ static int sync_trans(alpm_list_t *targets)
 			case PM_ERR_FILE_CONFLICTS:
 				for(i = data; i; i = alpm_list_next(i)) {
 					pmfileconflict_t *conflict = alpm_list_getdata(i);
-					switch(alpm_fileconflict_get_type(conflict)) {
+					switch(conflict->type) {
 						case PM_FILECONFLICT_TARGET:
 							printf(_("%s exists in both '%s' and '%s'\n"),
-									alpm_fileconflict_get_file(conflict),
-									alpm_fileconflict_get_target(conflict),
-									alpm_fileconflict_get_ctarget(conflict));
+									conflict->file, conflict->target, conflict->ctarget);
 							break;
 						case PM_FILECONFLICT_FILESYSTEM:
 							printf(_("%s: %s exists in filesystem\n"),
-									alpm_fileconflict_get_target(conflict),
-									alpm_fileconflict_get_file(conflict));
+									conflict->target, conflict->file);
 							break;
 					}
 				}
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index c046645..37cf700 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -173,17 +173,14 @@ int pacman_upgrade(alpm_list_t *targets)
 			case PM_ERR_FILE_CONFLICTS:
 				for(i = data; i; i = alpm_list_next(i)) {
 					pmfileconflict_t *conflict = alpm_list_getdata(i);
-					switch(alpm_fileconflict_get_type(conflict)) {
+					switch(conflict->type) {
 						case PM_FILECONFLICT_TARGET:
 							printf(_("%s exists in both '%s' and '%s'\n"),
-									alpm_fileconflict_get_file(conflict),
-									alpm_fileconflict_get_target(conflict),
-									alpm_fileconflict_get_ctarget(conflict));
+									conflict->file, conflict->target, conflict->ctarget);
 							break;
 						case PM_FILECONFLICT_FILESYSTEM:
 							printf(_("%s: %s exists in filesystem\n"),
-									alpm_fileconflict_get_target(conflict),
-									alpm_fileconflict_get_file(conflict));
+									conflict->target, conflict->file);
 							break;
 					}
 				}
-- 
1.7.5.4



More information about the pacman-dev mailing list