summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/sync.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-04-03 01:21:10 +0200
committerAurelien Foret <aurelien@archlinux.org>2005-04-03 01:21:10 +0200
commit686e8eaeb5dfe74f28c5f1b25bb0a7f555ff2e6d (patch)
treef09e15ce9834cc1c02abeca205db461ef73c1703 /lib/libalpm/sync.c
parent80bae750cd8ec44aa879b22fb1fdcc41036cbff6 (diff)
downloadpacman-686e8eaeb5dfe74f28c5f1b25bb0a7f555ff2e6d.tar.gz
pacman-686e8eaeb5dfe74f28c5f1b25bb0a7f555ff2e6d.tar.xz
more work to backport pacman_sync from pacman 2.9.5
Diffstat (limited to 'lib/libalpm/sync.c')
-rw-r--r--lib/libalpm/sync.c108
1 files changed, 92 insertions, 16 deletions
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 8e839b0c..03ccb915 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -22,7 +22,10 @@
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
+#include <fcntl.h>
#include <string.h>
+#include <libtar.h>
+#include <zlib.h>
/* pacman */
#include "log.h"
#include "util.h"
@@ -54,9 +57,41 @@ pmsync_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg)
return(sync);
}
-int sync_parsedb(char *archive)
+/* 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)
{
- return(0);
+ PMList *lp = NULL;
+ DIR *dir = NULL;
+ TAR *tar = NULL;
+ tartype_t gztype = {
+ (openfunc_t)_alpm_gzopen_frontend,
+ (closefunc_t)gzclose,
+ (readfunc_t)gzread,
+ (writefunc_t)gzwrite
+ };
+
+ if(tar_open(&tar, archive, &gztype, O_RDONLY, 0, TAR_GNU) == -1) {
+ pm_errno = PM_ERR_NOT_A_FILE;
+ goto error;
+ }
+
+ /* readdir tmp_dir */
+ /* for each subdir, parse %s/desc and %s/depends */
+
+ tar_close(tar);
+
+ return(lp);
+
+error:
+ if(tar) {
+ tar_close(tar);
+ }
+ if(dir) {
+ closedir(dir);
+ }
+ return(NULL);
}
int sync_sysupgrade(PMList **data)
@@ -85,12 +120,12 @@ int sync_sysupgrade(PMList **data)
lpkg->name, lpkg->version, spkg->name, spkg->version);
} else {
pmsync_t *sync = sync_new(PM_SYSUPG_REPLACE, lpkg, spkg);
-
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);
}
}
@@ -110,7 +145,6 @@ int sync_sysupgrade(PMList **data)
for(k = db_get_pkgcache(j->data); !spkg && k; k = k->next) {
pmpkg_t *sp = k->data;
-
if(!strcmp(local->name, sp->name)) {
spkg = sp;
}
@@ -139,6 +173,8 @@ int sync_sysupgrade(PMList **data)
pm_errno = PM_ERR_MEMORY;
goto error;
}
+ _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (upgrade: %s => %s)",
+ local->name, local->version, local->version, spkg->version);
targets = pm_list_add(targets, sync);
}
}
@@ -174,24 +210,23 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
for(j = dbs_sync; j && !sync; j = j->next) {
pmdb_t *dbs = j->data;
if(strcmp(dbs->treename, targline) == 0) {
- sync = alpm_db_readpkg(dbs, targ);
+ sync = db_scan(dbs, targ, INFRQ_DESC|INFRQ_DEPENDS);
}
}
} else {
targ = targline;
for(j = dbs_sync; j && !sync; j = j->next) {
pmdb_t *dbs = j->data;
- sync = alpm_db_readpkg(dbs, targ);
+ sync = db_scan(dbs, targ, INFRQ_DESC|INFRQ_DEPENDS);
}
}
-
if(sync == NULL) {
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
/* if not a sysupgrade, compare versions and determine if it is necessary */
if(!trans->flags & PM_TRANS_FLAG_SYSUPG) {
- local = alpm_db_readpkg(db, name);
+ local = db_get_pkgfromcache(db, name);
if(local) {
cmp = alpm_pkg_vercmp(local->version, sync->version);
if(cmp > 0) {
@@ -200,6 +235,7 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
if(!yesno(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] ", lpkgname, lpkgver)) {
}*/
_alpm_log(PM_LOG_WARNING, "%s-%s: local version is newer -- skipping");
+ FREE(sync);
return(0);
} else if(cmp == 0) {
/* versions are identical */
@@ -207,6 +243,7 @@ int sync_addtarget(pmdb_t *db, PMList *dbs_sync, pmtrans_t *trans, char *name)
if(!yesno(":: %s-%s: is up to date. Upgrade anyway? [Y/n] ", lpkgname, lpkgver)) {
}*/
_alpm_log(PM_LOG_WARNING, "%s-%s: is up to date -- skipping");
+ FREE(sync);
return(0);
}
}
@@ -220,17 +257,54 @@ 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)
{
- PMList *i;
- PMList *trail = NULL;
PMList *list = NULL;
+ PMList *trail = NULL;
+ PMList *i;
+
+ if(trans->packages == NULL) {
+ return(0);
+ }
/* Resolve targets dependencies */
- for(i = trans->packages; i; i = i->next) {
- pmpkg_t *sync = i->data;
- if(resolvedeps(handle->db_local, handle->dbs_sync, sync, list, trail) == -1) {
- /* pm_errno is set by resolvedeps */
- goto error;
+ if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
+ TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
+
+ list = pm_list_new();
+ trail = pm_list_new();
+
+ for(i = trans->packages; i; i = i->next) {
+ pmpkg_t *sync = i->data;
+ _alpm_log(PM_LOG_FLOW1, "resolving dependencies for package %s", sync->name);
+ if(resolvedeps(handle->db_local, handle->dbs_sync, sync, list, trail) == -1) {
+ /* pm_errno is set by resolvedeps */
+ goto error;
+ }
+ /* ORE
+ if called from makepkg, reason should be set to REASON_DEPEND */
+ sync->reason = PM_PKG_REASON_EXPLICIT;
}
+ FREELISTPTR(trail);
+
+ for(i = list; i; i = i->next) {
+ pmpkg_t *sync = i->data;
+ if(sync == NULL) {
+ continue;
+ }
+ if(!pkg_isin(sync, trans->packages)) {
+ pmpkg_t *pkg = db_scan(sync->data, sync->name, INFRQ_DESC|INFRQ_DEPENDS);
+ if(pkg == NULL) {
+ _alpm_log(PM_LOG_ERROR, "could not find package \"%s\" in repository %s",
+ sync->name, ((pmdb_t *)sync->data)->treename);
+ pm_errno = PM_ERR_PKG_NOT_FOUND;
+ goto error;
+ }
+ pkg->reason = PM_PKG_REASON_DEPEND;
+ trans->packages = pm_list_add(trans->packages, pkg);
+ }
+ }
+ FREELISTPTR(list);
+
+ TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
}
/* ORE
@@ -250,6 +324,8 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
return(0);
error:
+ FREELISTPTR(list);
+ FREELISTPTR(trail);
return(-1);
}