[pacman-dev] libalpm data structures
Nagy Gabor
ngaba at bibl.u-szeged.hu
Sun Oct 21 15:33:42 EDT 2007
> 2. We have pmconflict_t. Nice. So we
> don't need pmdeptype_t (in pmdepmissing_t). As we discussed with
> Xavier, pmconflict_t should be a symmetric structure:
> {target,ctarget} set [<=> alpm_strcmp ordered (target, ctarget) pair]
> instead of (target,ctarget) ordered pair) <- this is a
> pmconflict_t-helper-function problem only. Future plans:
Well, I overlooked something. pmconflict_t is reserved for
file-conflicts only, and pmdepmissing_t is used for conflicts?! (UGLY)
So here is a little patch which renames pmconflict_t to pmfileconflict_t
and alpm_conflict_* to alpm_fileconflict_*. pmconflicttype_t was removed
from pmfileconflict_t structure, because type can be determined with
(ctarget == "").
Bye, ngaba
----------------------
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 880bbeb..a40075a 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -52,7 +52,7 @@ typedef struct __pmtrans_t pmtrans_t;
typedef struct __pmsyncpkg_t pmsyncpkg_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;
typedef struct __pmgraph_t pmgraph_t;
/*
@@ -389,10 +389,10 @@ typedef enum _pmconflicttype_t {
PM_CONFLICT_TYPE_FILE
} pmconflicttype_t;
-const char *alpm_conflict_get_target(pmconflict_t *conflict);
-pmconflicttype_t alpm_conflict_get_type(pmconflict_t *conflict);
-const char *alpm_conflict_get_file(pmconflict_t *conflict);
-const char *alpm_conflict_get_ctarget(pmconflict_t *conflict);
+const char *alpm_fileconflict_get_target(pmfileconflict_t *conflict);
+pmconflicttype_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);
/*
* Helpers
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index d09c996..2aea8ff 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -230,22 +230,20 @@ static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
return(ret);
}
-/* Adds pmconflict_t to a conflicts list. Pass the conflicts list, type (either
+/* Adds pmfileconflict_t to a conflicts list. Pass the conflicts list, type (either
* PM_CONFLICT_TYPE_TARGET or PM_CONFLICT_TYPE_FILE), a file string, and either
* two package names or one package name and NULL. This is a wrapper for former
* functionality that was done inline.
*/
-static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
- pmconflicttype_t type, const char *filestr,
+static alpm_list_t *add_fileconflict(alpm_list_t *conflicts, const char *filestr,
const char* name1, const char* name2)
{
- pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
+ pmfileconflict_t *conflict = malloc(sizeof(pmfileconflict_t));
if(conflict == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"),
- sizeof(pmconflict_t));
+ sizeof(pmfileconflict_t));
return(conflicts);
}
- conflict->type = type;
strncpy(conflict->target, name1, PKG_NAME_LEN);
strncpy(conflict->file, filestr, CONFLICT_FILE_LEN);
if(name2) {
@@ -303,8 +301,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
if(tmpfiles) {
for(k = tmpfiles; k; k = k->next) {
snprintf(path, PATH_MAX, "%s%s", root, (char *)k->data);
- conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_TARGET, path,
- alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
+ conflicts = add_fileconflict(conflicts, path, alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
}
alpm_list_free_inner(tmpfiles, &free);
alpm_list_free(tmpfiles);
@@ -402,8 +399,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
}
if(!resolved_conflict) {
_alpm_log(PM_LOG_DEBUG, "file found in conflict: %s\n", path);
- conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE,
- path, p1->name, NULL);
+ conflicts = add_fileconflict(conflicts, path, p1->name, NULL);
}
}
}
@@ -414,7 +410,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
return(conflicts);
}
-const char SYMEXPORT *alpm_conflict_get_target(pmconflict_t *conflict)
+const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;
@@ -425,7 +421,7 @@ const char SYMEXPORT *alpm_conflict_get_target(pmconflict_t *conflict)
return conflict->target;
}
-pmconflicttype_t SYMEXPORT alpm_conflict_get_type(pmconflict_t *conflict)
+pmconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;
@@ -433,10 +429,10 @@ pmconflicttype_t SYMEXPORT alpm_conflict_get_type(pmconflict_t *conflict)
ASSERT(handle != NULL, return(-1));
ASSERT(conflict != NULL, return(-1));
- return conflict->type;
+ if(conflict->ctarget[0] == '\0') return (PM_CONFLICT_TYPE_FILE); else return(PM_CONFLICT_TYPE_TARGET);
}
-const char SYMEXPORT *alpm_conflict_get_file(pmconflict_t *conflict)
+const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;
@@ -447,7 +443,7 @@ const char SYMEXPORT *alpm_conflict_get_file(pmconflict_t *conflict)
return conflict->file;
}
-const char SYMEXPORT *alpm_conflict_get_ctarget(pmconflict_t *conflict)
+const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 8928de8..955fc38 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -27,9 +27,8 @@
#define CONFLICT_FILE_LEN 512
-struct __pmconflict_t {
+struct __pmfileconflict_t {
char target[PKG_NAME_LEN];
- pmconflicttype_t type;
char file[CONFLICT_FILE_LEN];
char ctarget[PKG_NAME_LEN];
};
diff --git a/src/pacman/add.c b/src/pacman/add.c
index 0b59a23..d430bf6 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -169,18 +169,18 @@ int pacman_add(alpm_list_t *targets)
break;
case PM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
- pmconflict_t *conflict = alpm_list_getdata(i);
- switch(alpm_conflict_get_type(conflict)) {
+ pmfileconflict_t *conflict = alpm_list_getdata(i);
+ switch(alpm_fileconflict_get_type(conflict)) {
case PM_CONFLICT_TYPE_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
- alpm_conflict_get_file(conflict),
- alpm_conflict_get_target(conflict),
- alpm_conflict_get_ctarget(conflict));
+ alpm_fileconflict_get_file(conflict),
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_ctarget(conflict));
break;
case PM_CONFLICT_TYPE_FILE:
printf(_("%s: %s exists in filesystem\n"),
- alpm_conflict_get_target(conflict),
- alpm_conflict_get_file(conflict));
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_file(conflict));
break;
}
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index bf6eed1..0feff97 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -632,18 +632,18 @@ int sync_trans(alpm_list_t *targets, int sync_only)
alpm_list_t *i;
case PM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
- pmconflict_t *conflict = alpm_list_getdata(i);
- switch(alpm_conflict_get_type(conflict)) {
+ pmfileconflict_t *conflict = alpm_list_getdata(i);
+ switch(alpm_fileconflict_get_type(conflict)) {
case PM_CONFLICT_TYPE_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
- alpm_conflict_get_file(conflict),
- alpm_conflict_get_target(conflict),
- alpm_conflict_get_ctarget(conflict));
+ alpm_fileconflict_get_file(conflict),
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_ctarget(conflict));
break;
case PM_CONFLICT_TYPE_FILE:
printf(_("%s: %s exists in filesystem\n"),
- alpm_conflict_get_target(conflict),
- alpm_conflict_get_file(conflict));
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_file(conflict));
break;
}
}
More information about the pacman-dev
mailing list