summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-02-05 09:27:26 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-02-05 09:27:26 +0000
commit325e3b6b98ee4ca217b153157936b77dc570bb57 (patch)
tree3a1f892f1e46c129be6370e9e44960e9be3e08ea /lib/libalpm
parentc432d525064dc9fd96bd32ade922740defd0c766 (diff)
downloadpacman-325e3b6b98ee4ca217b153157936b77dc570bb57.tar.xz
added a pmconflict_t structure to handle file conflicts
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.c37
-rw-r--r--lib/libalpm/alpm.h21
-rw-r--r--lib/libalpm/conflict.c27
-rw-r--r--lib/libalpm/conflict.h9
4 files changed, 80 insertions, 14 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 2ec59b2a..9336bc4c 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -1,7 +1,7 @@
/*
* alpm.c
*
- * Copyright (c) 2002 by Judd Vinet <jvinet@zeroflux.org>
+ * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,6 +43,7 @@
#include "db.h"
#include "cache.h"
#include "deps.h"
+#include "conflict.h"
#include "backup.h"
#include "add.h"
#include "remove.h"
@@ -415,6 +416,7 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
if(pkg->origin == PKG_FROM_CACHE) {
switch(parm) {
/* Desc entry */
+ /* not needed: the cache is loaded with DESC by default
case PM_PKG_NAME:
case PM_PKG_VERSION:
case PM_PKG_DESC:
@@ -433,7 +435,7 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
db_read(pkg->data, target, INFRQ_DESC, pkg);
}
- break;
+ break;*/
/* Depends entry */
/* not needed: the cache is loaded with DEPENDS by default
case PM_PKG_DEPENDS:
@@ -806,6 +808,37 @@ void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm)
}
/** @} */
+/** @defgroup alpm_dep File Conflicts Functions
+ * @brief Functions to get informations about a libalpm file conflict
+ * @{
+ */
+
+/** Get informations about a file conflict.
+ * @param db conflict pointer
+ * @param parm name of the info to get
+ * @return a void* on success (the value), NULL on error
+ */
+void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm)
+{
+ void *data;
+
+ /* Sanity checks */
+ ASSERT(conflict != NULL, return(NULL));
+
+ switch(parm) {
+ case PM_CONFLICT_TARGET: data = conflict->target; break;
+ case PM_CONFLICT_TYPE: data = (void *)(int)conflict->type; break;
+ case PM_CONFLICT_FILE: data = conflict->file; break;
+ case PM_CONFLICT_CTARGET: data = conflict->ctarget; break;
+ default:
+ data = NULL;
+ break;
+ }
+
+ return(data);
+}
+/** @} */
+
/** @defgroup alpm_log Logging Functions
* @brief Functions to log using libalpm
* @{
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index fb764446..47318ada 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -49,6 +49,7 @@ typedef struct __pmgrp_t PM_GRP;
typedef struct __pmsyncpkg_t PM_SYNCPKG;
typedef struct __pmtrans_t PM_TRANS;
typedef struct __pmdepmissing_t PM_DEPMISS;
+typedef struct __pmconflict_t PM_CONFLICT;
/*
* Library
@@ -268,7 +269,7 @@ int alpm_trans_commit(PM_LIST **data);
int alpm_trans_release(void);
/*
- * Dependencies
+ * Dependencies and conflicts
*/
enum {
@@ -294,6 +295,24 @@ enum {
void *alpm_dep_getinfo(PM_DEPMISS *miss, unsigned char parm);
/*
+ * File conflicts
+ */
+
+enum {
+ PM_CONFLICT_TYPE_TARGET = 1,
+ PM_CONFLICT_TYPE_FILE
+};
+/* Info parameters */
+enum {
+ PM_CONFLICT_TARGET = 1,
+ PM_CONFLICT_TYPE,
+ PM_CONFLICT_FILE,
+ PM_CONFLICT_CTARGET
+};
+
+void *alpm_conflict_getinfo(PM_CONFLICT *conflict, unsigned char parm);
+
+/*
* Helpers
*/
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index dc5dbdb9..5836a9d6 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -34,7 +34,7 @@
#include "deps.h"
#include "conflict.h"
-/* Returns a PMList* of missing_t pointers.
+/* Returns a PMList* of pmdepmissing_t pointers.
*
* conflicts are always name only
*/
@@ -194,18 +194,20 @@ PMList *db_find_conflicts(pmdb_t *db, PMList *targets, char *root, PMList **skip
if(strcmp(p1->name, p2->name)) {
for(k = p1->files; k; k = k->next) {
filestr = k->data;
- if(!strcmp(filestr, "._install") || !strcmp(filestr, ".INSTALL")) {
+ if(filestr[strlen(filestr)-1] == '/') {
+ /* this filename has a trailing '/', so it's a directory -- skip it. */
continue;
}
- if(rindex(filestr, '/') == filestr+strlen(filestr)-1) {
- /* this filename has a trailing '/', so it's a directory -- skip it. */
+ if(!strcmp(filestr, "._install") || !strcmp(filestr, ".INSTALL")) {
continue;
}
if(pm_list_is_strin(filestr, p2->files)) {
- MALLOC(str, 512);
- snprintf(str, 512, "%s: exists in \"%s\" (target) and \"%s\" (target)",
- filestr, p1->name, p2->name);
- conflicts = pm_list_add(conflicts, str);
+ pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
+ conflict->type = PM_CONFLICT_TYPE_TARGET;
+ STRNCPY(conflict->target, p1->name, PKG_NAME_LEN);
+ STRNCPY(conflict->file, filestr, CONFLICT_FILE_LEN);
+ STRNCPY(conflict->ctarget, p2->name, PKG_NAME_LEN);
+ conflicts = pm_list_add(conflicts, conflict);
}
}
}
@@ -297,9 +299,12 @@ PMList *db_find_conflicts(pmdb_t *db, PMList *targets, char *root, PMList **skip
}
donecheck:
if(!ok) {
- MALLOC(str, 512);
- snprintf(str, 512, "%s: %s: exists in filesystem", p->name, path);
- conflicts = pm_list_add(conflicts, str);
+ pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
+ conflict->type = PM_CONFLICT_TYPE_FILE;
+ STRNCPY(conflict->target, p->name, PKG_NAME_LEN);
+ STRNCPY(conflict->file, filestr, CONFLICT_FILE_LEN);
+ conflict->ctarget[0] = 0;
+ conflicts = pm_list_add(conflicts, conflict);
}
}
}
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 5d57ea8c..c8143641 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -23,6 +23,15 @@
#include "db.h"
+#define CONFLICT_FILE_LEN 512
+
+typedef struct __pmconflict_t {
+ char target[PKG_NAME_LEN];
+ unsigned char type;
+ char file[CONFLICT_FILE_LEN];
+ char ctarget[PKG_NAME_LEN];
+} pmconflict_t;
+
PMList *checkconflicts(pmdb_t *db, PMList *packages);
PMList *db_find_conflicts(pmdb_t *db, PMList *targets, char *root, PMList **skip_list);