2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* sync.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2005-10-06 03:28:30 -04:00
|
|
|
#ifdef CYGWIN
|
|
|
|
#include <limits.h> /* PATH_MAX */
|
|
|
|
#endif
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
/* pacman */
|
|
|
|
#include "util.h"
|
2005-03-19 04:00:40 -05:00
|
|
|
#include "log.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "download.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
2005-04-02 15:25:24 -05:00
|
|
|
#include "trans.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "sync.h"
|
|
|
|
#include "pacman.h"
|
2005-10-28 08:20:40 -04:00
|
|
|
#include "conf.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-10-29 03:00:56 -04:00
|
|
|
extern config_t *config;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
extern PM_DB *db_local;
|
|
|
|
extern list_t *pmc_syncs;
|
|
|
|
|
|
|
|
extern int maxcols;
|
|
|
|
|
|
|
|
static int sync_cleancache(int level)
|
|
|
|
{
|
2005-10-10 12:03:17 -04:00
|
|
|
char *root, *cachedir;
|
|
|
|
char dirpath[PATH_MAX];
|
2005-03-16 16:32:46 -05:00
|
|
|
|
|
|
|
alpm_get_option(PM_OPT_ROOT, (long *)&root);
|
2005-10-10 12:03:17 -04:00
|
|
|
alpm_get_option(PM_OPT_CACHEDIR, (long *)&cachedir);
|
|
|
|
|
|
|
|
snprintf(dirpath, PATH_MAX, "%s%s", root, cachedir);
|
2005-03-16 16:32:46 -05:00
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
if(level == 1) {
|
|
|
|
/* incomplete cleanup: we keep latest packages and partial downloads */
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
|
|
|
list_t *cache = NULL;
|
|
|
|
list_t *clean = NULL;
|
|
|
|
list_t *i, *j;
|
|
|
|
|
|
|
|
MSG(NL, "removing old packages from cache... ");
|
|
|
|
dir = opendir(dirpath);
|
|
|
|
if(dir == NULL) {
|
|
|
|
ERR(NL, "could not access cache directory\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
rewinddir(dir);
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
|
|
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
|
|
|
|
continue;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
cache = list_add(cache, strdup(ent->d_name));
|
|
|
|
}
|
|
|
|
closedir(dir);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
for(i = cache; i; i = i->next) {
|
|
|
|
char *str = i->data;
|
|
|
|
char name[256], version[64];
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
if(strstr(str, PM_EXT_PKG) == NULL) {
|
|
|
|
clean = list_add(clean, strdup(str));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* we keep partially downloaded files */
|
|
|
|
if(strstr(str, PM_EXT_PKG ".part")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(split_pkgname(str, name, version) != 0) {
|
|
|
|
clean = list_add(clean, strdup(str));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(j = i->next; j; j = j->next) {
|
|
|
|
char *s = j->data;
|
|
|
|
char n[256], v[64];
|
|
|
|
|
|
|
|
if(strstr(s, PM_EXT_PKG) == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
if(strstr(s, PM_EXT_PKG ".part")) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
if(split_pkgname(s, n, v) != 0) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
if(!strcmp(name, n)) {
|
|
|
|
char *ptr = (alpm_pkg_vercmp(version, v) < 0) ? str : s;
|
|
|
|
if(!list_is_strin(ptr, clean)) {
|
|
|
|
clean = list_add(clean, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
}
|
|
|
|
FREELIST(cache);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
for(i = clean; i; i = i->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2005-10-10 12:03:17 -04:00
|
|
|
snprintf(path, PATH_MAX, "%s/%s", dirpath, (char *)i->data);
|
2005-05-09 05:14:10 -04:00
|
|
|
unlink(path);
|
|
|
|
}
|
|
|
|
FREELIST(clean);
|
|
|
|
} else {
|
|
|
|
/* full cleanup */
|
|
|
|
MSG(NL, "removing all packages from cache... ");
|
2005-10-10 12:03:17 -04:00
|
|
|
|
|
|
|
if(rmrf(dirpath)) {
|
2005-05-09 05:14:10 -04:00
|
|
|
ERR(NL, "could not remove cache directory\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2005-10-10 12:03:17 -04:00
|
|
|
if(makepath(dirpath)) {
|
2005-05-09 05:14:10 -04:00
|
|
|
ERR(NL, "could not create new cache directory\n");
|
|
|
|
return(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MSG(CL, "done.\n");
|
|
|
|
return(0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-01-17 16:30:02 -05:00
|
|
|
static int sync_synctree(int level, list_t *syncs)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2005-03-16 16:21:06 -05:00
|
|
|
char *root, *dbpath;
|
2005-03-20 04:22:03 -05:00
|
|
|
char path[PATH_MAX];
|
2005-03-14 20:51:43 -05:00
|
|
|
list_t *i;
|
2005-03-20 04:22:03 -05:00
|
|
|
int success = 0, ret;
|
2005-03-16 16:21:06 -05:00
|
|
|
|
|
|
|
alpm_get_option(PM_OPT_ROOT, (long *)&root);
|
|
|
|
alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
for(i = syncs; i; i = i->next) {
|
2005-03-16 16:21:06 -05:00
|
|
|
list_t *files = NULL;
|
2005-03-20 04:22:03 -05:00
|
|
|
char newmtime[16] = "";
|
2006-02-14 13:29:26 -05:00
|
|
|
char *lastupdate = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
sync_t *sync = (sync_t *)i->data;
|
|
|
|
|
2006-02-14 13:29:26 -05:00
|
|
|
if(level < 2) {
|
|
|
|
/* get the lastupdate time */
|
|
|
|
lastupdate = alpm_db_getinfo(sync->db, PM_DB_LASTUPDATE);
|
|
|
|
if(strlen(lastupdate) == 0) {
|
|
|
|
vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename);
|
|
|
|
}
|
2005-03-20 04:22:03 -05:00
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* build a one-element list */
|
2005-05-09 05:14:10 -04:00
|
|
|
snprintf(path, PATH_MAX, "%s" PM_EXT_DB, sync->treename);
|
2005-03-14 20:51:43 -05:00
|
|
|
files = list_add(files, strdup(path));
|
|
|
|
|
2005-03-16 16:21:06 -05:00
|
|
|
snprintf(path, PATH_MAX, "%s%s", root, dbpath);
|
|
|
|
|
2006-01-02 15:48:40 -05:00
|
|
|
ret = downloadfiles_forreal(sync->servers, path, files, lastupdate, newmtime);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREELIST(files);
|
2005-03-20 04:22:03 -05:00
|
|
|
if(ret > 0) {
|
2005-04-06 17:03:09 -04:00
|
|
|
ERR(NL, "failed to synchronize %s\n", sync->treename);
|
2005-03-20 04:22:03 -05:00
|
|
|
success--;
|
|
|
|
} else if(ret < 0) {
|
2005-05-09 05:14:10 -04:00
|
|
|
MSG(NL, " %s is up to date\n", sync->treename);
|
2005-03-20 04:22:03 -05:00
|
|
|
} else {
|
2006-01-13 16:51:05 -05:00
|
|
|
if(strlen(newmtime)) {
|
|
|
|
vprint("sync: new mtime for %s: %s\n", sync->treename, newmtime);
|
|
|
|
}
|
2005-05-09 05:14:10 -04:00
|
|
|
snprintf(path, PATH_MAX, "%s%s/%s" PM_EXT_DB, root, dbpath, sync->treename);
|
2005-03-20 04:22:03 -05:00
|
|
|
if(alpm_db_update(sync->db, path, newmtime) == -1) {
|
2005-12-31 12:36:45 -05:00
|
|
|
if(pm_errno != PM_ERR_DB_UPTODATE) {
|
2006-01-13 16:51:05 -05:00
|
|
|
ERR(NL, "failed to update %s (%s)\n", sync->treename, alpm_strerror(pm_errno));
|
2005-12-31 12:36:45 -05:00
|
|
|
success--;
|
2006-01-04 18:52:26 -05:00
|
|
|
} else if(!strlen(newmtime)){
|
2005-12-31 12:36:45 -05:00
|
|
|
MSG(NL, ":: %s is up to date\n", sync->treename);
|
|
|
|
}
|
2005-03-20 04:22:03 -05:00
|
|
|
}
|
|
|
|
/* remove the .tar.gz */
|
|
|
|
unlink(path);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-20 04:22:03 -05:00
|
|
|
return(success);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sync_search(list_t *syncs, list_t *targets)
|
|
|
|
{
|
|
|
|
list_t *i;
|
|
|
|
|
|
|
|
for(i = syncs; i; i = i->next) {
|
|
|
|
sync_t *sync = i->data;
|
|
|
|
if(targets) {
|
2005-10-07 19:29:49 -04:00
|
|
|
if(db_search(sync->db, sync->treename, targets)) {
|
|
|
|
return(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PM_LIST *lp;
|
|
|
|
|
|
|
|
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_PKG *pkg = alpm_list_getdata(lp);
|
|
|
|
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "%s/%s %s\n ", sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
2005-03-14 20:51:43 -05:00
|
|
|
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-01-17 16:27:01 -05:00
|
|
|
static int sync_group(int level, list_t *syncs, list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
list_t *i, *j;
|
|
|
|
|
|
|
|
if(targets) {
|
|
|
|
for(i = targets; i; i = i->next) {
|
|
|
|
for(j = syncs; j; j = j->next) {
|
|
|
|
sync_t *sync = j->data;
|
|
|
|
PM_GRP *grp = alpm_db_readgrp(sync->db, i->data);
|
|
|
|
|
|
|
|
if(grp) {
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "%s/%s\n", sync->treename, (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
2005-03-14 20:51:43 -05:00
|
|
|
PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(j = syncs; j; j = j->next) {
|
|
|
|
sync_t *sync = j->data;
|
|
|
|
PM_LIST *lp;
|
|
|
|
|
2005-12-31 12:59:28 -05:00
|
|
|
for(lp = alpm_db_getgrpcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
PM_GRP *grp = alpm_list_getdata(lp);
|
|
|
|
|
2006-01-13 16:27:25 -05:00
|
|
|
MSG(NL, "%s/%s\n", sync->treename, (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
2006-01-17 16:27:01 -05:00
|
|
|
if(level > 1) {
|
2005-12-31 12:59:28 -05:00
|
|
|
PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sync_info(list_t *syncs, list_t *targets)
|
|
|
|
{
|
|
|
|
list_t *i, *j;
|
|
|
|
|
|
|
|
if(targets) {
|
|
|
|
for(i = targets; i; i = i->next) {
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
for(j = syncs; j && !found; j = j->next) {
|
|
|
|
sync_t *sync = j->data;
|
|
|
|
PM_LIST *lp;
|
|
|
|
|
|
|
|
for(lp = alpm_db_getpkgcache(sync->db); !found && lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_PKG *pkg = alpm_list_getdata(lp);
|
|
|
|
|
|
|
|
if(!strcmp(alpm_pkg_getinfo(pkg, PM_PKG_NAME), i->data)) {
|
|
|
|
dump_pkg_sync(pkg, sync->treename);
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found) {
|
2005-04-06 17:03:09 -04:00
|
|
|
ERR(NL, "package \"%s\" was not found.\n", (char *)i->data);
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(j = syncs; j; j = j->next) {
|
|
|
|
sync_t *sync = j->data;
|
|
|
|
PM_LIST *lp;
|
|
|
|
|
|
|
|
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
|
|
|
dump_pkg_sync(alpm_list_getdata(lp), sync->treename);
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sync_list(list_t *syncs, list_t *targets)
|
|
|
|
{
|
2005-05-09 05:14:10 -04:00
|
|
|
list_t *i;
|
|
|
|
list_t *ls = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets) {
|
|
|
|
for(i = targets; i; i = i->next) {
|
|
|
|
list_t *j;
|
|
|
|
sync_t *sync = NULL;
|
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
for(j = syncs; j && !sync; j = j->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
sync_t *s = j->data;
|
|
|
|
|
|
|
|
if(strcmp(i->data, s->treename) == 0) {
|
2005-05-09 05:14:10 -04:00
|
|
|
sync = s;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sync == NULL) {
|
2005-04-06 17:03:09 -04:00
|
|
|
ERR(NL, "repository \"%s\" was not found.\n", (char *)i->data);
|
2006-01-05 16:29:36 -05:00
|
|
|
FREELISTPTR(ls);
|
2005-03-14 20:51:43 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
ls = list_add(ls, sync);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
2005-05-09 05:14:10 -04:00
|
|
|
ls = syncs;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
for(i = ls; i; i = i->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
PM_LIST *lp;
|
|
|
|
sync_t *sync = i->data;
|
|
|
|
|
|
|
|
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_PKG *pkg = alpm_list_getdata(lp);
|
|
|
|
|
2005-04-06 17:03:09 -04:00
|
|
|
MSG(NL, "%s %s %s\n", (char *)sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(targets) {
|
2006-01-05 16:29:36 -05:00
|
|
|
FREELISTPTR(ls);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pacman_sync(list_t *targets)
|
|
|
|
{
|
2005-03-30 17:32:43 -05:00
|
|
|
int confirm = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
int retval = 0;
|
2005-04-02 18:21:10 -05:00
|
|
|
list_t *i;
|
2005-04-13 17:05:08 -04:00
|
|
|
PM_LIST *packages, *data, *lp;
|
2005-10-10 12:03:17 -04:00
|
|
|
char *root, *cachedir;
|
2005-03-14 20:51:43 -05:00
|
|
|
char ldir[PATH_MAX];
|
|
|
|
int varcache = 1;
|
2005-04-06 17:03:09 -04:00
|
|
|
list_t *files = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
|
2005-04-06 17:03:09 -04:00
|
|
|
ERR(NL, "no usable package repositories configured.\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_clean) {
|
|
|
|
return(sync_cleancache(config->op_s_clean));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* open the database(s) */
|
|
|
|
for(i = pmc_syncs; i; i = i->next) {
|
|
|
|
sync_t *sync = i->data;
|
2005-03-29 16:09:54 -05:00
|
|
|
sync->db = alpm_db_register(sync->treename);
|
|
|
|
if(sync->db == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_sync) {
|
2005-03-20 04:22:03 -05:00
|
|
|
/* grab a fresh package list */
|
|
|
|
MSG(NL, ":: Synchronizing package databases...\n");
|
|
|
|
alpm_logaction("synchronizing package lists");
|
2006-01-17 16:30:02 -05:00
|
|
|
if(sync_synctree(config->op_s_sync, pmc_syncs)) {
|
2005-04-06 17:03:09 -04:00
|
|
|
return(1);
|
|
|
|
}
|
2005-03-20 04:22:03 -05:00
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_search) {
|
2005-03-14 20:51:43 -05:00
|
|
|
return(sync_search(pmc_syncs, targets));
|
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->group) {
|
2006-01-17 16:27:01 -05:00
|
|
|
return(sync_group(config->group, pmc_syncs, targets));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_info) {
|
2005-03-14 20:51:43 -05:00
|
|
|
return(sync_info(pmc_syncs, targets));
|
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_q_list) {
|
2005-03-14 20:51:43 -05:00
|
|
|
return(sync_list(pmc_syncs, targets));
|
|
|
|
}
|
|
|
|
|
2005-03-30 17:32:43 -05:00
|
|
|
/* Step 1: create a new transaction...
|
|
|
|
*/
|
2005-10-28 08:20:40 -04:00
|
|
|
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
2005-03-30 17:32:43 -05:00
|
|
|
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
|
2006-01-26 15:46:48 -05:00
|
|
|
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
|
|
|
MSG(NL, " if you're sure a package manager is not already running,\n"
|
|
|
|
" you can remove %s\n", PM_LOCK);
|
|
|
|
}
|
|
|
|
return(1);
|
2005-03-30 17:32:43 -05:00
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_upgrade) {
|
2005-05-09 05:14:10 -04:00
|
|
|
MSG(NL, ":: Starting local database upgrade...\n");
|
2005-03-23 15:07:45 -05:00
|
|
|
alpm_logaction("starting full system upgrade");
|
2005-04-16 18:24:13 -04:00
|
|
|
if(alpm_trans_sysupgrade() == -1) {
|
2005-03-30 17:32:43 -05:00
|
|
|
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
2005-04-06 17:03:09 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if pacman itself is one of the packages to upgrade. If so, we
|
|
|
|
* we should upgrade ourselves first and then re-exec as the new version.
|
|
|
|
*
|
|
|
|
* this can prevent some of the "syntax error" problems users can have
|
|
|
|
* when sysupgrade'ing with an older version of pacman.
|
|
|
|
*/
|
2005-04-16 18:24:13 -04:00
|
|
|
data = alpm_trans_getinfo(PM_TRANS_PACKAGES);
|
2005-03-14 20:51:43 -05:00
|
|
|
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
2005-04-06 17:03:09 -04:00
|
|
|
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
2005-04-16 18:24:13 -04:00
|
|
|
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
2006-01-06 09:00:03 -05:00
|
|
|
if(!strcmp("pacman", alpm_pkg_getinfo(spkg, PM_PKG_NAME)) && alpm_list_count(data) > 1) {
|
2005-03-30 17:32:43 -05:00
|
|
|
MSG(NL, "\n:: pacman has detected a newer version of the \"pacman\" package.\n");
|
|
|
|
MSG(NL, ":: It is recommended that you allow pacman to upgrade itself\n");
|
|
|
|
MSG(NL, ":: first, then you can re-run the operation with the newer version.\n");
|
|
|
|
MSG(NL, "::\n");
|
2006-01-06 09:00:03 -05:00
|
|
|
if(yesno(":: Upgrade pacman first? [Y/n] ")) {
|
|
|
|
if(alpm_trans_release() == -1) {
|
|
|
|
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
|
|
|
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
|
2006-01-26 15:46:48 -05:00
|
|
|
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
|
|
|
MSG(NL, " if you're sure a package manager is not already running,\n"
|
|
|
|
" you can remove %s\n", PM_LOCK);
|
|
|
|
}
|
|
|
|
return(1);
|
2006-01-06 09:00:03 -05:00
|
|
|
}
|
|
|
|
if(alpm_trans_addtarget("pacman") == -1) {
|
|
|
|
ERR(NL, "could not add target '%s': %s\n", (char *)i->data, alpm_strerror(pm_errno));
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 18:24:13 -04:00
|
|
|
} else {
|
|
|
|
/* process targets */
|
|
|
|
for(i = targets; i; i = i->next) {
|
|
|
|
char *targ = i->data;
|
|
|
|
if(alpm_trans_addtarget(targ) == -1) {
|
2005-04-08 15:21:28 -04:00
|
|
|
PM_GRP *grp = NULL;
|
2005-04-02 18:21:10 -05:00
|
|
|
list_t *j;
|
2005-12-31 12:07:32 -05:00
|
|
|
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
|
|
|
|
/* just ignore duplicate targets */
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-16 18:24:13 -04:00
|
|
|
if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
|
|
|
|
ERR(NL, "could not add target '%s': %s\n", (char *)i->data, alpm_strerror(pm_errno));
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
/* target not found: check if it's a group */
|
|
|
|
for(j = pmc_syncs; j && !grp; j = j->next) {
|
|
|
|
sync_t *sync = j->data;
|
|
|
|
grp = alpm_db_readgrp(sync->db, targ);
|
|
|
|
if(grp) {
|
2005-10-20 16:34:31 -04:00
|
|
|
PM_LIST *pmpkgs;
|
|
|
|
list_t *k, *pkgs;
|
2005-03-14 20:51:43 -05:00
|
|
|
MSG(NL, ":: group %s:\n", targ);
|
2005-10-20 16:34:31 -04:00
|
|
|
pmpkgs = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
|
|
|
|
/* remove dupe entries in case a package exists in multiple repos */
|
|
|
|
/* (the dupe function takes a PM_LIST* and returns a list_t*) */
|
|
|
|
pkgs = PM_LIST_remove_dupes(pmpkgs);
|
|
|
|
list_display(" ", pkgs);
|
2005-04-06 17:03:09 -04:00
|
|
|
if(yesno(":: Install whole content? [Y/n] ")) {
|
2005-10-20 16:34:31 -04:00
|
|
|
for(k = pkgs; k; k = k->next) {
|
|
|
|
targets = list_add(targets, strdup(k->data));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
2005-10-20 16:34:31 -04:00
|
|
|
for(k = pkgs; k; k = k->next) {
|
|
|
|
char *pkgname = k->data;
|
2005-03-14 20:51:43 -05:00
|
|
|
if(yesno(":: Install %s from group %s? [Y/n] ", pkgname, targ)) {
|
|
|
|
targets = list_add(targets, strdup(pkgname));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-20 16:34:31 -04:00
|
|
|
FREELIST(pkgs);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(grp == NULL) {
|
2005-04-16 18:24:13 -04:00
|
|
|
ERR(NL, "could not add target '%s': not found in sync db\n", targ);
|
2005-04-06 17:03:09 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-17 16:19:40 -05:00
|
|
|
/* Step 2: "compute" the transaction based on targets and flags
|
|
|
|
*/
|
2005-03-14 20:51:43 -05:00
|
|
|
if(alpm_trans_prepare(&data) == -1) {
|
|
|
|
ERR(NL, "failed to prepare transaction (%s)\n", alpm_strerror(pm_errno));
|
2006-01-06 18:14:21 -05:00
|
|
|
switch(pm_errno) {
|
|
|
|
case PM_ERR_UNSATISFIED_DEPS:
|
|
|
|
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_DEPMISS *miss = alpm_list_getdata(lp);
|
2006-01-17 16:19:40 -05:00
|
|
|
MSG(NL, ":: %s: %s %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
2006-01-26 15:46:48 -05:00
|
|
|
(int)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? "requires" : "is required by",
|
2006-01-17 16:19:40 -05:00
|
|
|
alpm_dep_getinfo(miss, PM_DEP_NAME));
|
2006-01-06 18:14:21 -05:00
|
|
|
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
2006-01-07 12:50:20 -05:00
|
|
|
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
2006-01-06 18:14:21 -05:00
|
|
|
case PM_DEP_MOD_GE: MSG(CL, ">=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
|
|
|
case PM_DEP_MOD_LE: MSG(CL, "<=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
|
|
|
}
|
|
|
|
MSG(CL, "\n");
|
|
|
|
}
|
|
|
|
alpm_list_free(data);
|
|
|
|
break;
|
|
|
|
case PM_ERR_CONFLICTING_DEPS:
|
|
|
|
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_DEPMISS *miss = alpm_list_getdata(lp);
|
|
|
|
MSG(NL, ":: %s: conflicts with %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
|
|
|
alpm_dep_getinfo(miss, PM_DEP_NAME));
|
|
|
|
}
|
|
|
|
alpm_list_free(data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-04-06 17:03:09 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-01-05 16:29:36 -05:00
|
|
|
packages = alpm_trans_getinfo(PM_TRANS_PACKAGES);
|
|
|
|
if(packages == NULL) {
|
2006-01-06 09:00:03 -05:00
|
|
|
/* nothing to do: just exit without complaining */
|
2006-01-05 16:29:36 -05:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2005-04-13 17:05:08 -04:00
|
|
|
/* list targets and get confirmation */
|
2005-10-28 08:20:40 -04:00
|
|
|
if(!config->op_s_printuris) {
|
2006-01-05 16:29:36 -05:00
|
|
|
list_t *list_install = NULL;
|
|
|
|
list_t *list_remove = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
char *str;
|
|
|
|
unsigned long totalsize = 0;
|
|
|
|
double mb;
|
2005-04-13 17:05:08 -04:00
|
|
|
|
2005-04-20 16:49:39 -04:00
|
|
|
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
2006-01-13 15:47:13 -05:00
|
|
|
PM_PKG *pkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
|
|
|
char *pkgname, *pkgver;
|
|
|
|
|
2005-04-20 16:49:39 -04:00
|
|
|
if((int)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
|
|
|
|
PM_LIST *j, *data;
|
|
|
|
data = alpm_sync_getinfo(sync, PM_SYNC_DATA);
|
|
|
|
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
|
|
|
|
PM_PKG *p = alpm_list_getdata(j);
|
2005-04-23 13:16:50 -04:00
|
|
|
char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME);
|
2006-01-05 16:29:36 -05:00
|
|
|
if(!list_is_strin(pkgname, list_remove)) {
|
2006-01-06 09:00:03 -05:00
|
|
|
list_remove = list_add(list_remove, strdup(pkgname));
|
2005-04-23 13:16:50 -04:00
|
|
|
}
|
2005-04-20 16:49:39 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-01-13 15:47:13 -05:00
|
|
|
|
|
|
|
pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
|
|
|
|
pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
|
|
|
|
totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
|
|
|
|
|
|
|
|
asprintf(&str, "%s-%s", pkgname, pkgver);
|
|
|
|
list_install = list_add(list_install, str);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-01-05 16:29:36 -05:00
|
|
|
if(list_remove) {
|
2006-01-06 09:00:03 -05:00
|
|
|
MSG(NL, "\nRemove: ");
|
2006-01-05 16:29:36 -05:00
|
|
|
str = buildstring(list_remove);
|
2005-03-14 20:51:43 -05:00
|
|
|
indentprint(str, 9);
|
2006-01-06 09:00:03 -05:00
|
|
|
MSG(CL, "\n");
|
|
|
|
FREELIST(list_remove);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREE(str);
|
2005-04-06 17:03:09 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
mb = (double)(totalsize / 1048576.0);
|
|
|
|
/* round up to 0.1 */
|
|
|
|
if(mb < 0.1) {
|
|
|
|
mb = 0.1;
|
|
|
|
}
|
2005-04-02 18:21:10 -05:00
|
|
|
MSG(NL, "\nTargets: ");
|
2006-01-05 16:29:36 -05:00
|
|
|
str = buildstring(list_install);
|
2005-03-14 20:51:43 -05:00
|
|
|
indentprint(str, 9);
|
2006-01-07 12:50:20 -05:00
|
|
|
MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
|
2006-01-05 16:29:36 -05:00
|
|
|
FREELIST(list_install);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREE(str);
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_downloadonly) {
|
|
|
|
if(config->noconfirm) {
|
2005-04-13 15:59:04 -04:00
|
|
|
MSG(NL, "\nBeginning download...\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
confirm = 1;
|
|
|
|
} else {
|
2005-04-02 18:21:10 -05:00
|
|
|
MSG(NL, "\n");
|
2005-04-13 15:59:04 -04:00
|
|
|
confirm = yesno("Proceed with download? [Y/n] ");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* don't get any confirmation if we're called from makepkg */
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_d_resolve) {
|
2005-04-13 15:59:04 -04:00
|
|
|
confirm = 1;
|
|
|
|
} else {
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->noconfirm) {
|
2005-04-13 15:59:04 -04:00
|
|
|
MSG(NL, "\nBeginning upgrade process...\n");
|
|
|
|
confirm = 1;
|
|
|
|
} else {
|
|
|
|
MSG(NL, "\n");
|
|
|
|
confirm = yesno("Proceed with upgrade? [Y/n] ");
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
if(!confirm) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-04-02 18:21:10 -05:00
|
|
|
/* group sync records by repository and download */
|
2005-03-16 16:32:46 -05:00
|
|
|
alpm_get_option(PM_OPT_ROOT, (long *)&root);
|
2005-10-10 12:03:17 -04:00
|
|
|
alpm_get_option(PM_OPT_CACHEDIR, (long *)&cachedir);
|
|
|
|
snprintf(ldir, PATH_MAX, "%s%s", root, cachedir);
|
2005-04-13 17:05:08 -04:00
|
|
|
|
2005-04-13 15:59:04 -04:00
|
|
|
for(i = pmc_syncs; i; i = i->next) {
|
|
|
|
sync_t *current = i->data;
|
|
|
|
|
|
|
|
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
2005-04-16 18:24:13 -04:00
|
|
|
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
|
|
|
PM_DB *dbs = alpm_pkg_getinfo(spkg, PM_PKG_DATA);
|
2005-04-13 15:59:04 -04:00
|
|
|
|
|
|
|
if(current->db == dbs) {
|
2005-04-02 18:21:10 -05:00
|
|
|
char path[PATH_MAX];
|
2005-04-13 15:59:04 -04:00
|
|
|
char *pkgname, *pkgver;
|
|
|
|
|
|
|
|
pkgname = alpm_pkg_getinfo(spkg, PM_PKG_NAME);
|
|
|
|
pkgver = alpm_pkg_getinfo(spkg, PM_PKG_VERSION);
|
2005-04-02 18:21:10 -05:00
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_printuris) {
|
2005-04-13 15:59:04 -04:00
|
|
|
server_t *server = (server_t*)current->servers->data;
|
|
|
|
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);
|
|
|
|
}
|
2005-04-02 18:21:10 -05:00
|
|
|
} else {
|
2006-01-05 16:29:36 -05:00
|
|
|
struct stat buf;
|
2005-04-13 15:59:04 -04:00
|
|
|
snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, pkgname, pkgver);
|
2005-04-02 18:21:10 -05:00
|
|
|
if(stat(path, &buf)) {
|
2005-04-13 15:59:04 -04:00
|
|
|
/* file is not in the cache dir, so add it to the list */
|
|
|
|
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
|
2005-04-02 18:21:10 -05:00
|
|
|
files = list_add(files, strdup(path));
|
|
|
|
} else {
|
2005-04-13 15:59:04 -04:00
|
|
|
vprint(" %s-%s" PM_EXT_PKG " is already in the cache\n", pkgname, pkgver);
|
2005-04-02 18:21:10 -05:00
|
|
|
}
|
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(files) {
|
2005-04-13 15:59:04 -04:00
|
|
|
struct stat buf;
|
|
|
|
MSG(NL, "\n:: Retrieving packages from %s...\n", current->treename);
|
|
|
|
fflush(stdout);
|
|
|
|
if(stat(ldir, &buf)) {
|
|
|
|
/* no cache directory.... try creating it */
|
2006-02-14 13:43:51 -05:00
|
|
|
WARN(NL, "no %s cache exists. creating...\n", ldir);
|
2005-04-13 15:59:04 -04:00
|
|
|
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.
|
|
|
|
*/
|
2006-02-14 13:43:51 -05:00
|
|
|
WARN(NL, "couldn't create package cache, using /tmp instead");
|
2005-04-13 15:59:04 -04:00
|
|
|
alpm_logaction("warning: couldn't create package cache, using /tmp instead");
|
|
|
|
snprintf(ldir, PATH_MAX, "/tmp");
|
2006-01-05 16:02:08 -05:00
|
|
|
if(alpm_set_option(PM_OPT_CACHEDIR, (long)ldir) == -1) {
|
|
|
|
ERR(NL, "failed to set option CACHEDIR (%s)\n", alpm_strerror(pm_errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
varcache = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
if(downloadfiles(current->servers, ldir, files)) {
|
|
|
|
ERR(NL, "failed to retrieve some files from %s\n", current->treename);
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
FREELIST(files);
|
|
|
|
}
|
|
|
|
}
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_printuris) {
|
2005-04-13 15:59:04 -04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
MSG(NL, "\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
/* Check integrity of files */
|
2005-10-08 19:42:15 -04:00
|
|
|
MSG(NL, "checking package integrity... ");
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-04-13 17:05:08 -04:00
|
|
|
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
|
|
|
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
2005-04-16 18:24:13 -04:00
|
|
|
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
2006-02-05 04:58:16 -05:00
|
|
|
if(alpm_pkg_checkmd5sum(spkg) == -1) {
|
|
|
|
if(pm_errno == PM_ERR_PKG_INVALID) {
|
|
|
|
ERR(NL, "archive %s is corrupted\n", alpm_pkg_getinfo(spkg, PM_PKG_NAME));
|
|
|
|
} else {
|
|
|
|
ERR(NL, "could not get checksum for package %s (%s)\n",
|
|
|
|
alpm_pkg_getinfo(spkg, PM_PKG_NAME), alpm_strerror(pm_errno));
|
|
|
|
}
|
2005-03-30 17:32:43 -05:00
|
|
|
retval = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2005-03-30 17:32:43 -05:00
|
|
|
if(retval) {
|
2005-03-14 20:51:43 -05:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
MSG(CL, "done.\n");
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_downloadonly) {
|
2005-04-13 17:05:08 -04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2006-01-17 16:19:40 -05:00
|
|
|
/* Step 3: actually perform the installation
|
|
|
|
*/
|
2006-01-07 13:42:44 -05:00
|
|
|
if(alpm_trans_commit(&data) == -1) {
|
2005-04-13 17:05:08 -04:00
|
|
|
ERR(NL, "failed to commit transaction (%s)\n", alpm_strerror(pm_errno));
|
2006-01-07 13:42:44 -05:00
|
|
|
switch(pm_errno) {
|
|
|
|
case PM_ERR_FILE_CONFLICTS:
|
|
|
|
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
2006-02-05 04:34:49 -05:00
|
|
|
PM_CONFLICT *conflict = alpm_list_getdata(i);
|
|
|
|
switch((int)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
|
|
|
|
case PM_CONFLICT_TYPE_TARGET:
|
|
|
|
MSG(NL, "%s exists in \"%s\" (target) and \"%s\" (target)",
|
|
|
|
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE),
|
|
|
|
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
|
|
|
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_CTARGET));
|
|
|
|
break;
|
|
|
|
case PM_CONFLICT_TYPE_FILE:
|
|
|
|
MSG(NL, "%s: %s exists in filesystem",
|
|
|
|
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
|
|
|
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE));
|
|
|
|
break;
|
|
|
|
}
|
2006-01-07 13:42:44 -05:00
|
|
|
}
|
|
|
|
alpm_list_free(data);
|
|
|
|
MSG(NL, "\nerrors occurred, no packages were upgraded.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-04-13 17:05:08 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(!varcache && !config->op_s_downloadonly) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* delete packages */
|
|
|
|
for(i = files; i; i = i->next) {
|
|
|
|
unlink(i->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 15:46:48 -05:00
|
|
|
/* Step 4: release transaction resources
|
|
|
|
*/
|
2005-03-14 20:51:43 -05:00
|
|
|
cleanup:
|
2006-01-26 15:46:48 -05:00
|
|
|
if(alpm_trans_release() == -1) {
|
|
|
|
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
|
2006-01-27 14:02:24 -05:00
|
|
|
retval = 1;
|
2006-01-26 15:46:48 -05:00
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|