- updated sync feature

- added 2 new transaction events
This commit is contained in:
Aurelien Foret 2005-04-13 19:59:04 +00:00
parent 45c7e10afc
commit e115a5829e
4 changed files with 117 additions and 141 deletions

View File

@ -220,6 +220,8 @@ enum {
PM_TRANS_EVT_FILECONFLICTS_DONE, PM_TRANS_EVT_FILECONFLICTS_DONE,
PM_TRANS_EVT_RESOLVEDEPS_START, PM_TRANS_EVT_RESOLVEDEPS_START,
PM_TRANS_EVT_RESOLVEDEPS_DONE, PM_TRANS_EVT_RESOLVEDEPS_DONE,
PM_TRANS_EVT_INTERCONFLICTS_START,
PM_TRANS_EVT_INTERCONFLICTS_DONE,
PM_TRANS_EVT_ADD_START, PM_TRANS_EVT_ADD_START,
PM_TRANS_EVT_ADD_DONE, PM_TRANS_EVT_ADD_DONE,
PM_TRANS_EVT_REMOVE_START, PM_TRANS_EVT_REMOVE_START,

View File

@ -311,21 +311,16 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
return(0); return(0);
} }
for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
list = pm_list_add(list, sync->spkg);
}
/* Resolve targets dependencies */
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
list = pm_list_add(list, sync->spkg); list = pm_list_add(list, sync->spkg);
} }
trail = pm_list_new(); trail = pm_list_new();
/* Resolve targets dependencies */
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "resolving targets dependencies");
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
pmpkg_t *spkg = sync->spkg; pmpkg_t *spkg = sync->spkg;
@ -338,7 +333,6 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
if called from makepkg, reason should be set to REASON_DEPEND if called from makepkg, reason should be set to REASON_DEPEND
spkg->reason = PM_PKG_REASON_EXPLICIT;*/ spkg->reason = PM_PKG_REASON_EXPLICIT;*/
} }
for(i = list; i; i = i->next) { for(i = list; i; i = i->next) {
pmpkg_t *spkg = i->data; pmpkg_t *spkg = i->data;
if(!find_pkginsync(spkg->name, trans->packages)) { if(!find_pkginsync(spkg->name, trans->packages)) {
@ -346,40 +340,42 @@ int sync_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data)
trans->packages = pm_list_add(trans->packages, sync); trans->packages = pm_list_add(trans->packages, sync);
} }
} }
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
/* 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);
if(deps) {
int errorout = 0;
_alpm_log(PM_LOG_FLOW1, "looking for unresolvable dependencies");
for(i = deps; i; i = i->next) {
pmdepmissing_t *miss = i->data;
if(miss->type == PM_DEP_TYPE_DEPEND || miss->type == PM_DEP_TYPE_REQUIRED) {
if(!errorout) {
errorout = 1;
}
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
FREELIST(deps);
FREELIST(*data);
RET_ERR(PM_ERR_MEMORY, -1);
}
*miss = *(pmdepmissing_t *)i->data;
*data = pm_list_add(*data, miss);
}
}
if(errorout) {
FREELIST(deps);
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
}
/* ORE
no unresolvable deps, so look for conflicts */
_alpm_log(PM_LOG_FLOW1, "looking for conflicts");
}
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
FREELISTPTR(list); FREELISTPTR(list);
FREELISTPTR(trail); FREELISTPTR(trail);
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
}
/* ORE
check for inter-conflicts and whatnot */
_alpm_log(PM_LOG_FLOW1, "looking for inter-conflicts");
deps = checkdeps(db, PM_TRANS_TYPE_UPGRADE, list);
if(deps) {
int errorout = 0;
for(i = deps; i; i = i->next) {
pmdepmissing_t *miss = i->data;
if(miss->type == PM_DEP_TYPE_DEPEND || miss->type == PM_DEP_TYPE_REQUIRED) {
if(!errorout) {
errorout = 1;
}
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
FREELIST(deps);
FREELIST(*data);
RET_ERR(PM_ERR_MEMORY, -1);
}
*miss = *(pmdepmissing_t *)i->data;
*data = pm_list_add(*data, miss);
}
}
if(errorout) {
FREELIST(deps);
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
}
/* ORE
then look for conflicts */
} }
/* ORE /* ORE

View File

@ -366,14 +366,10 @@ int pacman_sync(list_t *targets)
int retval = 0; int retval = 0;
list_t *final = NULL; list_t *final = NULL;
list_t *i; list_t *i;
PM_LIST *data; PM_LIST *packages, *data;
char *root; char *root;
char ldir[PATH_MAX]; char ldir[PATH_MAX];
int varcache = 1; int varcache = 1;
int done;
int count;
sync_t *current = NULL;
list_t *processed = NULL;
list_t *files = NULL; list_t *files = NULL;
if(pmc_syncs == NULL || !list_count(pmc_syncs)) { if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
@ -549,11 +545,11 @@ int pacman_sync(list_t *targets)
/* list targets */ /* list targets */
if(!pmo_s_printuris) { if(!pmo_s_printuris) {
PM_LIST *packages, *lp;
list_t *list = NULL; list_t *list = NULL;
char *str; char *str;
unsigned long totalsize = 0; unsigned long totalsize = 0;
double mb; double mb;
PM_LIST *lp;
/* ORE /* ORE
for(i = rmtargs; i; i = i->next) { for(i = rmtargs; i; i = i->next) {
list = list_add(list, strdup(i->data)); list = list_add(list, strdup(i->data));
@ -603,130 +599,108 @@ int pacman_sync(list_t *targets)
MSG(NL, "\nTotal Package Size: %.1f MB\n", mb); MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
FREELIST(list); FREELIST(list);
FREE(str); FREE(str);
}
/* get confirmation */ /* get confirmation */
if(pmo_s_downloadonly) { if(pmo_s_downloadonly) {
if(pmo_noconfirm) {
MSG(NL, "\nBeginning download...\n");
confirm = 1;
} else {
MSG(NL, "\n");
confirm = yesno("Proceed with download? [Y/n] ");
}
} else {
/* don't get any confirmation if we're called from makepkg */
if(pmo_d_resolve || pmo_s_printuris) {
confirm = 1;
} else {
if(pmo_noconfirm) { if(pmo_noconfirm) {
MSG(NL, "\nBeginning upgrade process...\n"); MSG(NL, "\nBeginning download...\n");
confirm = 1; confirm = 1;
} else { } else {
MSG(NL, "\n"); MSG(NL, "\n");
confirm = yesno("Proceed with upgrade? [Y/n] "); confirm = yesno("Proceed with download? [Y/n] ");
}
} else {
/* don't get any confirmation if we're called from makepkg */
if(pmo_d_resolve) {
confirm = 1;
} else {
if(pmo_noconfirm) {
MSG(NL, "\nBeginning upgrade process...\n");
confirm = 1;
} else {
MSG(NL, "\n");
confirm = yesno("Proceed with upgrade? [Y/n] ");
}
} }
} }
} if(!confirm) {
if(!confirm) { retval = 1;
retval = 1; goto cleanup;
goto cleanup; }
} }
/* group sync records by repository and download */ /* group sync records by repository and download */
alpm_get_option(PM_OPT_ROOT, (long *)&root); alpm_get_option(PM_OPT_ROOT, (long *)&root);
snprintf(ldir, PATH_MAX, "%s"CACHEDIR, root); snprintf(ldir, PATH_MAX, "%s" CACHEDIR, root);
done = 0; for(i = pmc_syncs; i; i = i->next) {
count = 0;
processed = NULL;
current = NULL;
while(!done) {
PM_LIST *lp; PM_LIST *lp;
printf("in while\n"); sync_t *current = i->data;
if(current) {
processed = list_add(processed, current); for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
current = NULL; PM_SYNCPKG *sync = alpm_list_getdata(lp);
} PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_SYNCPKG);
for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) { PM_DB *dbs = alpm_pkg_getinfo(spkg, PM_PKG_DB);
PM_PKG *sync = alpm_list_getdata(lp);
if(current == NULL) { if(current->db == dbs) {
PM_DB *dbs = alpm_pkg_getinfo(sync, PM_PKG_DB);
/* 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; struct stat buf;
char path[PATH_MAX]; char path[PATH_MAX];
char *pkgname, *pkgver;
pkgname = alpm_pkg_getinfo(spkg, PM_PKG_NAME);
pkgver = alpm_pkg_getinfo(spkg, PM_PKG_VERSION);
if(pmo_s_printuris) { if(pmo_s_printuris) {
snprintf(path, PATH_MAX, "%s-%s%s", sync->pkg->name, sync->pkg->version, PKGEXT); server_t *server = (server_t*)current->servers->data;
files = list_add(files, strdup(path)); snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
if(!strcmp(server->protocol, "file")) {
MSG(NL, "%s://%s%s\n", server->protocol, server->path, path);
} else {
MSG(NL, "%s://%s%s%s\n", server->protocol,
server->server, server->path, path);
}
} else { } else {
snprintf(path, PATH_MAX, "%s/%s-%s%s", snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, pkgname, pkgver);
ldir, sync->pkg->name, sync->pkg->version, PKGEXT);
if(stat(path, &buf)) { if(stat(path, &buf)) {
// file is not in the cache dir, so add it to the list // /* 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); snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
files = list_add(files, strdup(path)); files = list_add(files, strdup(path));
} else { } else {
vprint(" %s-%s%s is already in the cache\n", sync->pkg->name, sync->pkg->version, PKGEXT); vprint(" %s-%s" PM_EXT_PKG " is already in the cache\n", pkgname, pkgver);
count++;
} }
} }
}*/ }
} }
if(files) { if(files) {
if(pmo_s_printuris) { struct stat buf;
list_t *j; MSG(NL, "\n:: Retrieving packages from %s...\n", current->treename);
server_t *server = (server_t*)current->servers->data; fflush(stdout);
for(j = files; j; j = j->next) { if(stat(ldir, &buf)) {
if(!strcmp(server->protocol, "file")) { /* no cache directory.... try creating it */
MSG(NL, "%s://%s%s\n", server->protocol, server->path, MSG(NL, "warning: no %s cache exists. creating...", ldir);
(char *)j->data); alpm_logaction("warning: no %s cache exists. creating...", ldir);
} else { if(makepath(ldir)) {
MSG(NL, "%s://%s%s%s\n", server->protocol, /* couldn't mkdir the cache directory, so fall back to /tmp and unlink
server->server, server->path, (char *)j->data); * the package afterwards.
} */
} MSG(NL, "warning: couldn't create package cache, using /tmp instead");
} else { alpm_logaction("warning: couldn't create package cache, using /tmp instead");
struct stat buf; snprintf(ldir, PATH_MAX, "/tmp");
varcache = 0;
MSG(NL, "\n:: Retrieving packages from %s...\n", current->treename);
fflush(stdout);
if(stat(ldir, &buf)) {
/* no cache directory.... try creating it */
MSG(NL, "warning: no %s cache exists. creating...", ldir);
alpm_logaction("warning: no %s cache exists. creating...", ldir);
if(makepath(ldir)) {
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
* the package afterwards.
*/
MSG(NL, "warning: couldn't create package cache, using /tmp instead");
alpm_logaction("warning: couldn't create package cache, using /tmp instead");
snprintf(ldir, PATH_MAX, "/tmp");
varcache = 0;
}
}
if(downloadfiles(current->servers, ldir, files)) {
ERR(NL, "failed to retrieve some files from %s\n", current->treename);
retval = 1;
goto cleanup;
} }
} }
if(downloadfiles(current->servers, ldir, files)) {
count += list_count(files); ERR(NL, "failed to retrieve some files from %s\n", current->treename);
retval = 1;
goto cleanup;
}
FREELIST(files); FREELIST(files);
} }
if(count == list_count(final)) {
done = 1;
}
} }
printf("\n"); if(pmo_s_printuris) {
goto cleanup;
}
MSG(NL, "\n");
/* Check integrity of files */ /* Check integrity of files */
MSG(NL, "checking package integrity... "); MSG(NL, "checking package integrity... ");
@ -735,7 +709,7 @@ int pacman_sync(list_t *targets)
char /*str[PATH_MAX],*/ pkgname[PATH_MAX] = "dummy"; char /*str[PATH_MAX],*/ pkgname[PATH_MAX] = "dummy";
char *md5sum1, *md5sum2; char *md5sum1, *md5sum2;
snprintf(pkgname, PATH_MAX, "%s-%s"PM_EXT_PKG, "", ""); snprintf(pkgname, PATH_MAX, "%s-%s" PM_EXT_PKG, "", "");
md5sum1 = NULL; md5sum1 = NULL;
/* ORE /* ORE

View File

@ -50,9 +50,13 @@ void cb_trans(unsigned short event, void *data1, void *data2)
case PM_TRANS_EVT_RESOLVEDEPS_START: case PM_TRANS_EVT_RESOLVEDEPS_START:
MSG(NL, "resolving dependencies... "); MSG(NL, "resolving dependencies... ");
break; break;
case PM_TRANS_EVT_INTERCONFLICTS_START:
MSG(NL, "looking inter-conflicts... ");
break;
case PM_TRANS_EVT_CHECKDEPS_DONE: case PM_TRANS_EVT_CHECKDEPS_DONE:
case PM_TRANS_EVT_FILECONFLICTS_DONE: case PM_TRANS_EVT_FILECONFLICTS_DONE:
case PM_TRANS_EVT_RESOLVEDEPS_DONE: case PM_TRANS_EVT_RESOLVEDEPS_DONE:
case PM_TRANS_EVT_INTERCONFLICTS_DONE:
MSG(CL, "done.\n"); MSG(CL, "done.\n");
break; break;
case PM_TRANS_EVT_ADD_START: case PM_TRANS_EVT_ADD_START: