Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-04-16 22:15:50 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-04-16 22:15:50 +0000
commit36087bb392e0f045039cd9d51188d9eb7fe4d98b (patch)
tree471425bb5620c5ff9f77b699ca4491554d4726fb /lib
parent29a712e3939ff359cdaa8574be2c76d6f71a0c78 (diff)
- reworked pmsyncpkg_t structure
- got ride of uneeded handle external references
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/sync.c108
-rw-r--r--lib/libalpm/sync.h17
2 files changed, 59 insertions, 66 deletions
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 41a0b918..d4029435 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -40,9 +40,13 @@
#include "rpmvercmp.h"
#include "handle.h"
+/* ORE
+set CACHEDIR as a library option? */
+#define PM_CACHEDIR "var/cache/pacman/pkg"
+
extern pmhandle_t *handle;
-pmsyncpkg_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg)
+pmsyncpkg_t *sync_new(int type, pmpkg_t *spkg, void *data)
{
pmsyncpkg_t *sync;
@@ -51,9 +55,13 @@ pmsyncpkg_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg)
}
sync->type = type;
- sync->lpkg = lpkg;
- sync->spkg = spkg;
- sync->replaces = NULL;
+ sync->pkg = spkg;
+
+ if(sync->type == PM_SYNC_TYPE_REPLACE) {
+ sync->data = pm_list_add(NULL, data);
+ } else {
+ sync->data = data;
+ }
return(sync);
}
@@ -61,7 +69,9 @@ pmsyncpkg_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg)
void sync_free(pmsyncpkg_t *sync)
{
if(sync) {
- FREELISTPTR(sync->replaces);
+ if(sync->type == PM_SYNC_TYPE_REPLACE) {
+ FREELISTPTR(sync->data);
+ }
free(sync);
}
}
@@ -77,7 +87,7 @@ static pmsyncpkg_t* find_pkginsync(char *needle, PMList *haystack)
for(i = haystack; i && !found; i = i->next) {
sync = i->data;
- if(sync && !strcmp(sync->spkg->name, needle)) {
+ if(sync && !strcmp(sync->pkg->name, needle)) {
found = 1;
}
}
@@ -91,7 +101,7 @@ static pmsyncpkg_t* find_pkginsync(char *needle, PMList *haystack)
/* It returns a PMList of packages extracted from the given archive
* (the archive must have been generated by gensync)
*/
-PMList *sync_load_archive(char *archive)
+PMList *sync_load_dbarchive(char *archive)
{
PMList *lp = NULL;
DIR *dir = NULL;
@@ -125,39 +135,32 @@ error:
return(NULL);
}
-int sync_sysupgrade(PMList **data)
+int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
{
PMList *i, *j, *k;
- PMList *targets = NULL;
-
- *data = NULL;
/* check for "recommended" package replacements */
- for(i = handle->dbs_sync; i; i = i->next) {
+ for(i = dbs_sync; i; i = i->next) {
PMList *j;
-
for(j = db_get_pkgcache(i->data); j; j = j->next) {
pmpkg_t *spkg = j->data;
-
for(k = spkg->replaces; k; k = k->next) {
PMList *m;
-
- for(m = db_get_pkgcache(handle->db_local); m; m = m->next) {
+ for(m = db_get_pkgcache(db_local); m; m = m->next) {
pmpkg_t *lpkg = m->data;
-
if(!strcmp(k->data, lpkg->name)) {
if(pm_list_is_strin(lpkg->name, handle->ignorepkg)) {
_alpm_log(PM_LOG_WARNING, "%s-%s: ignoring package upgrade (to be replaced by %s-%s)",
lpkg->name, lpkg->version, spkg->name, spkg->version);
} else {
- pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_REPLACE, lpkg, spkg);
+ pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_REPLACE, spkg, lpkg);
if(sync == NULL) {
pm_errno = PM_ERR_MEMORY;
goto error;
}
_alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)",
lpkg->name, lpkg->version, spkg->name, spkg->version);
- targets = pm_list_add(targets, sync);
+ trans->packages = pm_list_add(trans->packages, sync);
}
}
}
@@ -166,14 +169,13 @@ int sync_sysupgrade(PMList **data)
}
/* match installed packages with the sync dbs and compare versions */
- for(i = db_get_pkgcache(handle->db_local); i; i = i->next) {
+ for(i = db_get_pkgcache(db_local); i; i = i->next) {
int cmp;
pmpkg_t *local = i->data;
pmpkg_t *spkg = NULL;
pmsyncpkg_t *sync;
- for(j = handle->dbs_sync; !spkg && j; j = j->next) {
-
+ for(j = dbs_sync; !spkg && j; j = j->next) {
for(k = db_get_pkgcache(j->data); !spkg && k; k = k->next) {
pmpkg_t *sp = k->data;
if(!strcmp(local->name, sp->name)) {
@@ -199,27 +201,24 @@ int sync_sysupgrade(PMList **data)
_alpm_log(PM_LOG_FLOW1, "%s-%s: ignoring package upgrade (%s)",
local->name, local->version, spkg->version);
} else {
- sync = sync_new(PM_SYNC_TYPE_UPGRADE, local, spkg);
+ sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, local);
if(sync == NULL) {
pm_errno = PM_ERR_MEMORY;
goto error;
}
_alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)",
local->name, local->version, local->version, spkg->version);
- targets = pm_list_add(targets, sync);
+ trans->packages = pm_list_add(trans->packages, sync);
}
}
- *data = targets;
-
return(0);
error:
- FREELIST(targets);
return(-1);
}
-int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
+int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *name)
{
char targline[(PKG_NAME_LEN-1)+1+(DB_TREENAME_LEN-1)+1];
char *targ;
@@ -229,14 +228,10 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
pmsyncpkg_t *sync;
int cmp;
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- if(trans->flags & PM_TRANS_FLAG_SYSUPG) {
- RET_ERR(PM_ERR_XXX, -1);
- }
-
strncpy(targline, name, (PKG_NAME_LEN-1)+1+(DB_TREENAME_LEN-1)+1);
targ = strchr(targline, '/');
if(targ) {
@@ -262,7 +257,7 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
- local = db_get_pkgfromcache(db, name);
+ local = db_get_pkgfromcache(db_local, name);
if(local) {
cmp = alpm_pkg_vercmp(local->version, spkg->version);
if(cmp > 0) {
@@ -284,7 +279,7 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
/* add the package to the transaction */
if(!find_pkginsync(spkg->name, trans->packages)) {
- sync = sync_new(PM_SYNC_TYPE_UPGRADE, local, spkg);
+ sync = sync_new(PM_SYNC_TYPE_UPGRADE, spkg, local);
if(sync == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
@@ -294,14 +289,14 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
return(0);
}
-int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
+int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **data)
{
PMList *deps = NULL;
PMList *list = NULL;
PMList *trail = NULL;
PMList *i;
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(data != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
@@ -314,7 +309,7 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
- list = pm_list_add(list, sync->spkg);
+ list = pm_list_add(list, sync->pkg);
}
trail = pm_list_new();
@@ -323,9 +318,9 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
_alpm_log(PM_LOG_FLOW1, "resolving targets dependencies");
for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
- pmpkg_t *spkg = sync->spkg;
+ pmpkg_t *spkg = sync->pkg;
_alpm_log(PM_LOG_FLOW1, "resolving dependencies for package %s", spkg->name);
- if(resolvedeps(handle->db_local, handle->dbs_sync, spkg, list, trail) == -1) {
+ if(resolvedeps(db_local, dbs_sync, spkg, list, trail) == -1) {
/* pm_errno is set by resolvedeps */
goto error;
}
@@ -336,7 +331,7 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
for(i = list; i; i = i->next) {
pmpkg_t *spkg = i->data;
if(!find_pkginsync(spkg->name, trans->packages)) {
- pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_DEPEND, NULL, spkg);
+ pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_DEPEND, spkg, NULL);
trans->packages = pm_list_add(trans->packages, sync);
}
}
@@ -345,7 +340,7 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
/* ORE
check for inter-conflicts and whatnot */
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
- deps = checkdeps(db, PM_TRANS_TYPE_UPGRADE, list);
+ deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list);
if(deps) {
int errorout = 0;
_alpm_log(PM_LOG_FLOW1, "looking for unresolvable dependencies");
@@ -399,9 +394,9 @@ error:
return(-1);
}
-int sync_commit(pmdb_t *db, pmtrans_t *trans)
+int sync_commit(pmtrans_t *trans, pmdb_t *db)
{
- PMList *i, *j = NULL;
+ PMList *i;
PMList *data;
pmtrans_t *tr;
char ldir[PATH_MAX];
@@ -409,11 +404,7 @@ int sync_commit(pmdb_t *db, pmtrans_t *trans)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- /* ORE
- set CACHEDIR as a library option? */
-#define PM_CACHEDIR "var/cache/pacman/pkg"
snprintf(ldir, PATH_MAX, "%s" PM_CACHEDIR, handle->root);
-#undef CACHEDIR
/* remove any conflicting packages (WITHOUT dep checks) */
/* ORE - alpm does not handle removal of conflicting pkgs for now */
@@ -424,15 +415,17 @@ int sync_commit(pmdb_t *db, pmtrans_t *trans)
if(tr == NULL) {
goto error;
}
- for(i = trans->packages; i; i = i->next) {
+ /*for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
- for(j = sync->replaces; j; j = j->next) {
- pmpkg_t *pkg = j->data;
+ if(sync->type == PM_SYNC_TYPE_REPLACE) {
+ pmpkg_t *pkg = sync->lpkg;
if(trans_addtarget(tr, pkg->name)) {
goto error;
}
}
}
+ trans_prepare(tr, &data);
+ trans_commit(tr);*/
trans_free(tr);
/* install targets */
@@ -443,11 +436,13 @@ int sync_commit(pmdb_t *db, pmtrans_t *trans)
}
for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
- pmpkg_t *spkg = sync->spkg;
- char str[PATH_MAX];
- snprintf(str, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, spkg->name, spkg->version);
- if(trans_addtarget(tr, str) == -1) {
- goto error;
+ if(sync->type != PM_SYNC_TYPE_REPLACE) {
+ pmpkg_t *spkg = sync->pkg;
+ char str[PATH_MAX];
+ snprintf(str, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, spkg->name, spkg->version);
+ if(trans_addtarget(tr, str) == -1) {
+ goto error;
+ }
}
}
if(trans_prepare(tr, &data) == -1) {
@@ -462,6 +457,7 @@ int sync_commit(pmdb_t *db, pmtrans_t *trans)
for(i = trans->packages; i; i = i->next) {
/*syncpkg_t *sync = (syncpkg_t*)i->data;
if(sync->replaces) {
+ PMList *j;
pkginfo_t *new = db_scan(db, sync->pkg->name, INFRQ_DEPENDS);
for(j = sync->replaces; j; j = j->next) {
pkginfo_t *old = (pkginfo_t*)j->data;
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 7c839736..d5e5a02f 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -24,25 +24,22 @@
#include "db.h"
#include "package.h"
#include "trans.h"
-#include "alpm.h"
typedef struct __pmsyncpkg_t {
unsigned char type;
- pmpkg_t *lpkg;
- pmpkg_t *spkg;
- PMList *replaces;
+ pmpkg_t *pkg;
+ void *data;
} pmsyncpkg_t;
-pmsyncpkg_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg);
+pmsyncpkg_t *sync_new(int type, pmpkg_t *spkg, void *data);
void sync_free(pmsyncpkg_t *sync);
PMList *sync_load_archive(char *archive);
-int sync_sysupgrade(pmlist_t **data);
-
-int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name);
-int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data);
-int sync_commit(pmdb_t *db, pmtrans_t *trans);
+int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db, PMList *dbs_sync);
+int sync_addtarget(pmtrans_t *trans, pmdb_t *db, PMList *dbs_sync, char *name);
+int sync_prepare(pmtrans_t *trans, pmdb_t *db, PMList *dbs_sync, PMList **data);
+int sync_commit(pmtrans_t *trans, pmdb_t *db);
#endif /* _ALPM_SYNC_H */