summaryrefslogtreecommitdiffstats
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
parent80bae750cd8ec44aa879b22fb1fdcc41036cbff6 (diff)
downloadpacman-686e8eaeb5dfe74f28c5f1b25bb0a7f555ff2e6d.tar.gz
pacman-686e8eaeb5dfe74f28c5f1b25bb0a7f555ff2e6d.tar.xz
more work to backport pacman_sync from pacman 2.9.5
-rw-r--r--lib/libalpm/sync.c108
-rw-r--r--lib/libalpm/sync.h8
-rw-r--r--src/pacman/sync.c98
3 files changed, 169 insertions, 45 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);
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 667dc4f4..51e0dd3d 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -26,14 +26,22 @@
#include "trans.h"
#include "alpm.h"
+typedef struct __syncpkg_t { /* ORE: not used for now */
+ pmpkg_t *pkg;
+ pmdb_t *db;
+} pmsyncpkg_t;
+
typedef struct __pmsync_t {
unsigned char type;
pmpkg_t *lpkg;
pmpkg_t *spkg;
+ pmdb_t *dbs; /* ORE: not used for now */
} pmsync_t;
pmsync_t *sync_new(int type, pmpkg_t *lpkg, pmpkg_t *spkg);
+PMList *sync_load_archive(char *archive);
+
/*int sync_findpkg(char *name, PMList *dbs, pmsyncpkg_t **sync);
pmsyncpkg_t *find_pkginsync(char *needle, PMList *haystack);
PMList *rm_pkginsync(char *needle, PMList *haystack);*/
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 976ceaa8..6ef50bbb 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -170,11 +170,12 @@ static int sync_synctree(list_t *syncs)
list_t *files = NULL;
char *mtime = NULL;
char newmtime[16] = "";
- char lastupdate[16] = "";
+ char *lastupdate;
sync_t *sync = (sync_t *)i->data;
/* get the lastupdate time */
- if(alpm_db_getlastupdate(sync->db, lastupdate) == -1) {
+ lastupdate = alpm_db_getinfo(sync->db, PM_DB_LASTUPDATE);
+ if(lastupdate == NULL) {
vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename);
}
mtime = lastupdate;
@@ -364,16 +365,16 @@ int pacman_sync(list_t *targets)
int confirm = 0;
int retval = 0;
list_t *final = NULL;
- list_t *i, *j;
- PM_LIST *lp, *data;
+ list_t *i;
+ PM_LIST *data;
char *root;
char ldir[PATH_MAX];
int varcache = 1;
- int done = 0;
- int count = 0;
- sync_t *current = NULL;
- list_t *processed = NULL;
- list_t *files = NULL;
+ int done;
+ int count;
+ sync_t *current;
+ list_t *processed;
+ list_t *files;
if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
ERR(NL, "error: no usable package repositories configured.");
@@ -426,6 +427,8 @@ int pacman_sync(list_t *targets)
}
if(pmo_s_upgrade) {
+ PM_LIST *lp;
+
alpm_logaction("starting full system upgrade");
if(alpm_sync_sysupgrade(&data) == -1) {
@@ -488,16 +491,16 @@ int pacman_sync(list_t *targets)
data = NULL;
}
+ list_display("targets:", targets);
+
/* and add targets to it
*/
for(i = targets; i; i = i->next) {
char *targ = i->data;
-
- printf("TARGET=%s\n", targ);
-
if(alpm_trans_addtarget(targ) == -1) {
if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
PM_GRP *grp;
+ list_t *j;
/* target not found: check if it's a group */
for(j = pmc_syncs; j && !grp; j = j->next) {
sync_t *sync = j->data;
@@ -544,6 +547,7 @@ int pacman_sync(list_t *targets)
/* list targets */
if(!pmo_s_printuris) {
+ PM_LIST *lp;
list_t *list = NULL;
char *str;
unsigned long totalsize = 0;
@@ -567,22 +571,28 @@ int pacman_sync(list_t *targets)
FREELIST(list);
FREE(str);
}*/
- /* ORE
- for(i = final; i; i = i->next) {
- MALLOC(str, strlen(s->pkg->name)+strlen(s->pkg->version)+2);
- sprintf(str, "%s-%s", s->pkg->name, s->pkg->version);
+ for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) {
+ char *pkgname, *pkgver;
+ PM_PKG *pkg = alpm_list_getdata(lp);
+
+ pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
+ pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
+
+ MALLOC(str, strlen(pkgname)+strlen(pkgver)+2);
+ sprintf(str, "%s-%s", pkgname, pkgver);
list = list_add(list, str);
- totalsize += s->pkg->size;
- }*/
+
+ totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
+ }
mb = (double)(totalsize / 1048576.0);
/* round up to 0.1 */
if(mb < 0.1) {
mb = 0.1;
}
- printf("\nTargets: ");
+ MSG(NL, "\nTargets: ");
str = buildstring(list);
indentprint(str, 9);
- printf("\n\nTotal Package Size: %.1f MB\n", mb);
+ MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
FREELIST(list);
FREE(str);
}
@@ -593,7 +603,8 @@ int pacman_sync(list_t *targets)
MSG(NL, "\nBeginning download...\n");
confirm = 1;
} else {
- confirm = yesno("\nProceed with download? [Y/n] ");
+ MSG(NL, "\n");
+ confirm = yesno("Proceed with download? [Y/n] ");
}
} else {
/* don't get any confirmation if we're called from makepkg */
@@ -604,7 +615,8 @@ int pacman_sync(list_t *targets)
MSG(NL, "\nBeginning upgrade process...\n");
confirm = 1;
} else {
- confirm = yesno("\nProceed with upgrade? [Y/n] ");
+ MSG(NL, "\n");
+ confirm = yesno("Proceed with upgrade? [Y/n] ");
}
}
}
@@ -613,27 +625,56 @@ int pacman_sync(list_t *targets)
goto cleanup;
}
- /* ORE
- group sync records by repository and download */
-
+ /* group sync records by repository and download */
alpm_get_option(PM_OPT_ROOT, (long *)&root);
snprintf(ldir, PATH_MAX, "%s"CACHEDIR, root);
-
+ done = 0;
+ count = 0;
+ processed = NULL;
+ current = NULL;
while(!done) {
+ PM_LIST *lp;
+ printf("in while\n");
if(current) {
processed = list_add(processed, current);
current = NULL;
}
- for(i = final; i; i = i->next) {
+ for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) {
+ PM_PKG *sync = alpm_list_getdata(lp);
if(current == NULL) {
+ PM_DB *dbs = alpm_pkg_getinfo(sync, PM_PKG_SYNCDB);
/* we're starting on a new repository */
+ if(!list_is_ptrin(dbs, processed)) {
+ /* ORE
+ current = dbs;*/
+ current = NULL;
+ }
}
/*if(current && !strcmp(current->treename, sync->dbs->sync->treename)) {
+ struct stat buf;
+ char path[PATH_MAX];
+
+ if(pmo_s_printuris) {
+ snprintf(path, PATH_MAX, "%s-%s%s", sync->pkg->name, sync->pkg->version, PKGEXT);
+ files = list_add(files, strdup(path));
+ } else {
+ snprintf(path, PATH_MAX, "%s/%s-%s%s",
+ ldir, sync->pkg->name, sync->pkg->version, PKGEXT);
+ if(stat(path, &buf)) {
+ // file is not in the cache dir, so add it to the list //
+ snprintf(path, PATH_MAX, "%s-%s%s", sync->pkg->name, sync->pkg->version, PKGEXT);
+ files = list_add(files, strdup(path));
+ } else {
+ vprint(" %s-%s%s is already in the cache\n", sync->pkg->name, sync->pkg->version, PKGEXT);
+ count++;
+ }
+ }
}*/
}
if(files) {
if(pmo_s_printuris) {
+ list_t *j;
server_t *server = (server_t*)current->servers->data;
for(j = files; j; j = j->next) {
if(!strcmp(server->protocol, "file")) {
@@ -708,11 +749,10 @@ int pacman_sync(list_t *targets)
if(strcmp(md5sum1, md5sum2) != 0) {
retval = 1;
- ERR(NL, "error: archive %s is corrupted\n", pkgname);
+ ERR(NL, "archive %s is corrupted\n", pkgname);
}
FREE(md5sum2);
-
}
if(retval) {
goto cleanup;