#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#ifdef CYGWIN
#include <limits.h>
#endif
#include <libtar.h>
#include <zlib.h>
#include "log.h"
#include "util.h"
#include "error.h"
#include "list.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "deps.h"
#include "trans.h"
#include "sync.h"
#include "rpmvercmp.h"
#include "handle.h"
extern pmhandle_t *handle;
pmsyncpkg_t *sync_new(int type, pmpkg_t *spkg, void *data)
{
pmsyncpkg_t *sync;
if((sync = (pmsyncpkg_t *)malloc(sizeof(pmsyncpkg_t))) == NULL) {
return(NULL);
}
sync->type = type;
sync->pkg = spkg;
sync->data = data;
return(sync);
}
void sync_free(pmsyncpkg_t *sync)
{
if(sync == NULL) {
return;
}
if(sync->type == PM_SYNC_TYPE_REPLACE) {
FREELISTPKGS(sync->data);
} else {
FREEPKG(sync->data);
}
free(sync);
}
static pmsyncpkg_t* find_pkginsync(char *needle, PMList *haystack)
{
PMList *i;
pmsyncpkg_t *sync = NULL;
int found = 0;
for(i = haystack; i && !found; i = i->next) {
sync = i->data;
if(sync && !strcmp(sync->pkg->name, needle)) {
found = 1;
}
}
if(!found) {
sync = NULL;
}
return(sync);
}
PMList *sync_load_dbarchive(char *archive)
{
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;
}
tar_close(tar);
return(lp);
error:
if(tar) {
tar_close(tar);
}
if(dir) {
closedir(dir);
}
return(NULL);
}
int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
{
PMList *i, *j, *k;
for(i = dbs_sync; i; i = i->next) {
for(j = db_get_pkgcache(i->data); j; j = j->next) {
pmpkg_t *spkg = j->data;
|