2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* sync.c
|
2007-06-02 12:34:01 -04:00
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2007 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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-10-23 00:33:47 -04:00
|
|
|
#include <limits.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2008-02-19 09:47:05 -05:00
|
|
|
#include <sys/stat.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-19 04:28:44 -05:00
|
|
|
#include <alpm_list.h>
|
2006-11-14 02:58:42 -05:00
|
|
|
#include <download.h> /* downloadLastErrString */
|
2007-02-21 03:16:26 -05:00
|
|
|
/* TODO remove above download.h inclusion once we abstract more, and also
|
|
|
|
* remove it from Makefile.am on the pacman side */
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2007-04-25 02:21:12 -04:00
|
|
|
#include "pacman.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
|
|
|
#include "package.h"
|
2007-04-25 20:02:07 -04:00
|
|
|
#include "callback.h"
|
2005-10-28 08:20:40 -04:00
|
|
|
#include "conf.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-09-25 23:07:36 -04:00
|
|
|
extern pmdb_t *db_local;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-12-05 17:47:54 -05:00
|
|
|
/* if keep_used != 0, then the dirnames which match an used syncdb
|
|
|
|
* will be kept */
|
|
|
|
static int sync_cleandb(const char *dbpath, int keep_used) {
|
2007-11-17 16:52:03 -05:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
|
|
|
|
|
|
|
dir = opendir(dbpath);
|
|
|
|
if(dir == NULL) {
|
|
|
|
fprintf(stderr, _("error: could not access database directory\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rewinddir(dir);
|
|
|
|
/* step through the directory one file at a time */
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
|
|
char path[PATH_MAX];
|
2008-02-19 09:47:05 -05:00
|
|
|
struct stat buf;
|
2007-11-17 16:52:03 -05:00
|
|
|
alpm_list_t *syncdbs = NULL, *i;
|
|
|
|
int found = 0;
|
|
|
|
char *dname = ent->d_name;
|
|
|
|
|
|
|
|
if(!strcmp(dname, ".") || !strcmp(dname, "..")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* skip the local and sync directories */
|
|
|
|
if(!strcmp(dname, "sync") || !strcmp(dname, "local")) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-19 09:47:05 -05:00
|
|
|
|
|
|
|
/* build the full path */
|
|
|
|
snprintf(path, PATH_MAX, "%s%s", dbpath, ent->d_name);
|
|
|
|
/* skip entries that are not dirs (lock file, etc.) */
|
|
|
|
stat(path, &buf);
|
|
|
|
if(!S_ISDIR(buf.st_mode)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-12-05 17:47:54 -05:00
|
|
|
if(keep_used) {
|
|
|
|
syncdbs = alpm_option_get_syncdbs();
|
|
|
|
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
|
|
|
found = !strcmp(dname, alpm_db_get_name(db));
|
|
|
|
}
|
2007-11-17 16:52:03 -05:00
|
|
|
}
|
|
|
|
/* We have a directory that doesn't match any syncdb.
|
|
|
|
* Ask the user if he wants to remove it. */
|
|
|
|
if(!found) {
|
|
|
|
if(!yesno(_("Do you want to remove %s? [Y/n] "), path)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rmrf(path)) {
|
|
|
|
fprintf(stderr, _("error: could not remove repository directory\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sync_cleandb_all(void) {
|
|
|
|
const char *dbpath = alpm_option_get_dbpath();
|
|
|
|
char newdbpath[PATH_MAX];
|
|
|
|
|
|
|
|
printf(_("Database directory: %s\n"), dbpath);
|
|
|
|
if(!yesno(_("Do you want to remove unused repositories? [Y/n] "))) {
|
|
|
|
return(0);
|
|
|
|
}
|
2007-12-05 17:47:54 -05:00
|
|
|
/* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
|
|
|
|
* so we will clean everything in dbpath/ (except dbpath/local/ and dbpath/sync/,
|
|
|
|
* and only the unused sync dbs in dbpath/sync/ */
|
|
|
|
sync_cleandb(dbpath, 0);
|
2007-11-17 16:52:03 -05:00
|
|
|
|
|
|
|
sprintf(newdbpath, "%s%s", dbpath, "sync/");
|
2007-12-05 17:47:54 -05:00
|
|
|
sync_cleandb(newdbpath, 1);
|
2007-11-17 16:52:03 -05:00
|
|
|
|
|
|
|
printf(_("Database directory cleaned up\n"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
static int sync_cleancache(int level)
|
|
|
|
{
|
2007-06-04 14:50:16 -04:00
|
|
|
/* TODO for now, just mess with the first cache directory */
|
|
|
|
alpm_list_t* cachedirs = alpm_option_get_cachedirs();
|
|
|
|
const char *cachedir = alpm_list_getdata(cachedirs);
|
2005-03-16 16:32:46 -05:00
|
|
|
|
2005-05-09 05:14:10 -04:00
|
|
|
if(level == 1) {
|
2007-06-17 23:25:07 -04:00
|
|
|
/* incomplete cleanup */
|
2007-09-25 23:07:36 -04:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
|
|
|
/* Let's vastly improve the way this is done. Before, we went by package
|
|
|
|
* name. Instead, let's only keep packages we have installed. Open up each
|
|
|
|
* package and see if it has an entry in the local DB; if not, delete it.
|
|
|
|
*/
|
|
|
|
printf(_("Cache directory: %s\n"), cachedir);
|
2007-11-17 17:35:22 -05:00
|
|
|
if(!yesno(_("Do you want to remove uninstalled packages from cache? [Y/n] "))) {
|
2007-09-25 23:07:36 -04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
printf(_("removing old packages from cache... "));
|
|
|
|
|
|
|
|
dir = opendir(cachedir);
|
|
|
|
if(dir == NULL) {
|
|
|
|
fprintf(stderr, _("error: could not access cache directory\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rewinddir(dir);
|
|
|
|
/* step through the directory one file at a time */
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
pmpkg_t *localpkg = NULL, *dbpkg = NULL;
|
|
|
|
|
|
|
|
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* build the full filepath */
|
|
|
|
snprintf(path, PATH_MAX, "%s/%s", cachedir, ent->d_name);
|
|
|
|
|
|
|
|
/* attempt to load the package, skip file on failures as we may have
|
2007-09-28 00:39:37 -04:00
|
|
|
* files here that aren't valid packages. we also don't need a full
|
|
|
|
* load of the package, just the metadata. */
|
|
|
|
if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) {
|
2007-09-25 23:07:36 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* check if this package is in the local DB */
|
|
|
|
dbpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg));
|
|
|
|
if(dbpkg == NULL) {
|
|
|
|
/* delete package, not present in local DB */
|
|
|
|
unlink(path);
|
|
|
|
} else if(alpm_pkg_vercmp(alpm_pkg_get_version(localpkg),
|
|
|
|
alpm_pkg_get_version(dbpkg)) != 0) {
|
|
|
|
/* delete package, it was found but version differs */
|
|
|
|
unlink(path);
|
|
|
|
}
|
|
|
|
/* else version was the same, so keep the package */
|
|
|
|
/* free the local file package */
|
|
|
|
alpm_pkg_free(localpkg);
|
|
|
|
}
|
|
|
|
printf(_("done.\n"));
|
2005-05-09 05:14:10 -04:00
|
|
|
} else {
|
|
|
|
/* full cleanup */
|
2007-09-25 23:07:36 -04:00
|
|
|
printf(_("Cache directory: %s\n"), cachedir);
|
|
|
|
if(!yesno(_("Do you want to remove ALL packages from cache? [Y/n] "))) {
|
2006-10-15 15:34:52 -04:00
|
|
|
return(0);
|
2007-09-25 23:07:36 -04:00
|
|
|
}
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_("removing all packages from cache... "));
|
2005-10-10 12:03:17 -04:00
|
|
|
|
2007-05-31 02:51:28 -04:00
|
|
|
if(rmrf(cachedir)) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: could not remove cache directory\n"));
|
2005-05-09 05:14:10 -04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-05-31 02:51:28 -04:00
|
|
|
if(makepath(cachedir)) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: could not create new cache directory\n"));
|
2005-05-09 05:14:10 -04:00
|
|
|
return(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-06-17 23:25:07 -04:00
|
|
|
printf(_("done.\n"));
|
2005-05-09 05:14:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2008-02-19 14:32:48 -05:00
|
|
|
static int sync_trans_init(pmtransflag_t flags) {
|
|
|
|
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, flags, cb_trans_evt,
|
|
|
|
cb_trans_conv, cb_trans_progress) == -1) {
|
|
|
|
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
|
|
|
|
alpm_strerrorlast());
|
|
|
|
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
|
|
|
printf(_(" if you're sure a package manager is not already\n"
|
|
|
|
" running, you can remove %s.\n"), alpm_option_get_lockfile());
|
|
|
|
}
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sync_trans_release() {
|
|
|
|
if(alpm_trans_release() == -1) {
|
|
|
|
fprintf(stderr, _("error: failed to release transaction (%s)\n"),
|
|
|
|
alpm_strerrorlast());
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
2007-01-19 04:28:44 -05:00
|
|
|
static int sync_synctree(int level, alpm_list_t *syncs)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i;
|
2005-03-20 04:22:03 -05:00
|
|
|
int success = 0, ret;
|
2005-03-16 16:21:06 -05:00
|
|
|
|
2008-01-28 13:49:27 -05:00
|
|
|
if(sync_trans_init(0) == -1) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = syncs; i; i = alpm_list_next(i)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
ret = alpm_db_update((level < 2 ? 0 : 1), db);
|
2006-10-31 01:41:42 -05:00
|
|
|
if(ret < 0) {
|
2006-10-15 15:34:52 -04:00
|
|
|
if(pm_errno == PM_ERR_DB_SYNC) {
|
2006-11-14 02:58:42 -05:00
|
|
|
/* use libdownload error */
|
2007-01-18 11:52:57 -05:00
|
|
|
/* TODO breaking abstraction barrier here?
|
|
|
|
* pacman -> libalpm -> libdownload
|
|
|
|
*
|
|
|
|
* Yes. This will be here until we add a nice pacman "pm_errstr" or
|
|
|
|
* something, OR add all libdownload error codes into the pm_error enum
|
|
|
|
*/
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: failed to synchronize %s: %s\n"),
|
|
|
|
alpm_db_get_name(db), downloadLastErrString);
|
2006-10-15 15:34:52 -04:00
|
|
|
} else {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: failed to update %s (%s)\n"),
|
2007-09-08 12:41:45 -04:00
|
|
|
alpm_db_get_name(db), alpm_strerrorlast());
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2006-10-31 01:41:42 -05:00
|
|
|
} else if(ret == 1) {
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_(" %s is up to date\n"), alpm_db_get_name(db));
|
2006-11-02 22:56:02 -05:00
|
|
|
success++;
|
2006-11-01 21:29:10 -05:00
|
|
|
} else {
|
|
|
|
success++;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:49:27 -05:00
|
|
|
if(sync_trans_release() == -1) {
|
|
|
|
return(0);
|
|
|
|
}
|
2006-11-01 21:29:10 -05:00
|
|
|
/* We should always succeed if at least one DB was upgraded - we may possibly
|
|
|
|
* fail later with unresolved deps, but that should be rare, and would be
|
|
|
|
* expected
|
|
|
|
*/
|
2008-01-28 13:49:27 -05:00
|
|
|
if(!success) {
|
|
|
|
fprintf(stderr, _("error: failed to synchronize any databases\n"));
|
|
|
|
}
|
2006-11-01 21:29:10 -05:00
|
|
|
return(success > 0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
/* search the sync dbs for a matching package */
|
2007-01-19 04:28:44 -05:00
|
|
|
static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i, *j, *ret;
|
2007-04-26 14:27:13 -04:00
|
|
|
int freelist;
|
2007-08-09 03:36:20 -04:00
|
|
|
int found = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = syncs; i; i = alpm_list_next(i)) {
|
2007-04-26 14:27:13 -04:00
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
|
|
|
/* if we have a targets list, search for packages matching it */
|
2005-03-14 20:51:43 -05:00
|
|
|
if(targets) {
|
2007-02-11 23:45:21 -05:00
|
|
|
ret = alpm_db_search(db, targets);
|
2007-04-26 14:27:13 -04:00
|
|
|
freelist = 1;
|
|
|
|
} else {
|
|
|
|
ret = alpm_db_getpkgcache(db);
|
|
|
|
freelist = 0;
|
|
|
|
}
|
|
|
|
if(ret == NULL) {
|
|
|
|
continue;
|
2007-08-09 03:36:20 -04:00
|
|
|
} else {
|
|
|
|
found = 1;
|
2007-04-26 14:27:13 -04:00
|
|
|
}
|
|
|
|
for(j = ret; j; j = alpm_list_next(j)) {
|
|
|
|
/* print repo/name (group) info about each package in our list */
|
|
|
|
char *group = NULL;
|
|
|
|
alpm_list_t *grp;
|
|
|
|
pmpkg_t *pkg = alpm_list_getdata(j);
|
|
|
|
|
2007-11-07 02:05:33 -05:00
|
|
|
if (!config->quiet) {
|
|
|
|
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
|
|
|
|
alpm_pkg_get_version(pkg));
|
|
|
|
} else {
|
|
|
|
printf("%s", alpm_pkg_get_name(pkg));
|
|
|
|
}
|
2007-06-01 11:00:39 -04:00
|
|
|
|
|
|
|
/* print the package size with the output if ShowSize option set */
|
2007-06-04 12:51:23 -04:00
|
|
|
if(config->showsize) {
|
2007-05-14 01:21:42 -04:00
|
|
|
/* Convert byte size to MB */
|
|
|
|
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
|
|
|
|
|
2007-06-01 11:00:39 -04:00
|
|
|
printf(" [%.2f MB]", mbsize);
|
2007-05-14 01:21:42 -04:00
|
|
|
}
|
2007-04-26 14:27:13 -04:00
|
|
|
|
2007-11-07 02:05:33 -05:00
|
|
|
if (!config->quiet) {
|
|
|
|
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
2007-04-26 14:27:13 -04:00
|
|
|
group = alpm_list_getdata(grp);
|
2007-08-24 05:47:40 -04:00
|
|
|
printf(" (%s)", (char *)alpm_list_getdata(grp));
|
2007-11-07 02:05:33 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-11-07 02:05:33 -05:00
|
|
|
/* we need a newline and initial indent first */
|
|
|
|
printf("\n ");
|
|
|
|
indentprint(alpm_pkg_get_desc(pkg), 4);
|
|
|
|
}
|
2007-04-26 14:27:13 -04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
/* we only want to free if the list was a search list */
|
|
|
|
if(freelist) {
|
|
|
|
alpm_list_free(ret);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-09 03:36:20 -04:00
|
|
|
return(!found);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i, *j;
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
if(targets) {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
2007-01-22 20:34:58 -05:00
|
|
|
char *grpname = alpm_list_getdata(i);
|
2007-01-19 04:28:44 -05:00
|
|
|
for(j = syncs; j; j = alpm_list_next(j)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(j);
|
2007-01-22 20:34:58 -05:00
|
|
|
pmgrp_t *grp = alpm_db_readgrp(db, grpname);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(grp) {
|
2007-02-01 01:35:30 -05:00
|
|
|
/* TODO this should be a lot cleaner, why two outputs? */
|
2007-04-26 15:28:54 -04:00
|
|
|
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
2007-02-26 03:43:02 -05:00
|
|
|
list_display(" ", alpm_grp_get_pkgs(grp));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = syncs; i; i = alpm_list_next(i)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(j = alpm_db_getgrpcache(db); j; j = alpm_list_next(j)) {
|
|
|
|
pmgrp_t *grp = alpm_list_getdata(j);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-04-26 15:28:54 -04:00
|
|
|
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
2006-10-15 15:34:52 -04:00
|
|
|
if(grp && level > 1) {
|
2007-02-26 03:43:02 -05:00
|
|
|
list_display(" ", alpm_grp_get_pkgs(grp));
|
2005-12-31 12:59:28 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i, *j, *k;
|
2007-05-31 01:12:17 -04:00
|
|
|
int ret = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets) {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
2007-02-15 20:58:51 -05:00
|
|
|
pmdb_t *db = NULL;
|
|
|
|
int foundpkg = 0;
|
|
|
|
|
|
|
|
char target[512]; /* TODO is this enough space? */
|
|
|
|
char *repo = NULL, *pkgstr = NULL;
|
|
|
|
|
|
|
|
strncpy(target, i->data, 512);
|
|
|
|
pkgstr = strchr(target, '/');
|
|
|
|
if(pkgstr) {
|
|
|
|
repo = target;
|
|
|
|
*pkgstr = '\0';
|
|
|
|
++pkgstr;
|
|
|
|
|
|
|
|
for(j = syncs; j; j = alpm_list_next(j)) {
|
|
|
|
db = alpm_list_getdata(j);
|
|
|
|
if(strcmp(repo, alpm_db_get_name(db)) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
db = NULL;
|
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-02-15 20:58:51 -05:00
|
|
|
if(!db) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: repository '%s' does not exist\n"), repo);
|
2007-02-15 20:58:51 -05:00
|
|
|
return(1);
|
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-02-15 20:58:51 -05:00
|
|
|
for(k = alpm_db_getpkgcache(db); k; k = alpm_list_next(k)) {
|
2007-01-19 04:28:44 -05:00
|
|
|
pmpkg_t *pkg = alpm_list_getdata(k);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-02-15 20:58:51 -05:00
|
|
|
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
|
2007-01-19 04:28:44 -05:00
|
|
|
dump_pkg_sync(pkg, alpm_db_get_name(db));
|
2007-02-15 20:58:51 -05:00
|
|
|
foundpkg = 1;
|
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-02-15 20:58:51 -05:00
|
|
|
if(!foundpkg) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: package '%s' was not found in repository '%s'\n"), pkgstr, repo);
|
2007-05-31 01:12:17 -04:00
|
|
|
ret++;
|
2007-02-15 20:58:51 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pkgstr = target;
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-02-15 20:58:51 -05:00
|
|
|
for(j = syncs; j; j = alpm_list_next(j)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(j);
|
|
|
|
|
|
|
|
for(k = alpm_db_getpkgcache(db); k; k = alpm_list_next(k)) {
|
|
|
|
pmpkg_t *pkg = alpm_list_getdata(k);
|
|
|
|
|
|
|
|
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
|
|
|
|
dump_pkg_sync(pkg, alpm_db_get_name(db));
|
|
|
|
foundpkg = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!foundpkg) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: package '%s' was not found\n"), pkgstr);
|
2007-05-31 01:12:17 -04:00
|
|
|
ret++;
|
2007-02-15 20:58:51 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = syncs; i; i = alpm_list_next(i)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
|
|
|
|
dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-31 01:12:17 -04:00
|
|
|
return(ret);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i, *j, *ls = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets) {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
|
|
|
const char *repo = alpm_list_getdata(i);
|
|
|
|
pmdb_t *db = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(j = syncs; j; j = alpm_list_next(j)) {
|
|
|
|
pmdb_t *d = alpm_list_getdata(j);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
if(strcmp(repo, alpm_db_get_name(d)) == 0) {
|
|
|
|
db = d;
|
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
if(db == NULL) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: repository \"%s\" was not found.\n"),repo);
|
2007-01-24 03:51:50 -05:00
|
|
|
alpm_list_free(ls);
|
2005-03-14 20:51:43 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
ls = alpm_list_add(ls, db);
|
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
|
|
|
}
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = ls; i; i = alpm_list_next(i)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(i);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
|
|
|
|
pmpkg_t *pkg = alpm_list_getdata(j);
|
2007-11-07 02:05:33 -05:00
|
|
|
if (!config->quiet) {
|
|
|
|
printf("%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
|
|
|
|
alpm_pkg_get_version(pkg));
|
|
|
|
} else {
|
|
|
|
printf("%s\n", alpm_pkg_get_name(pkg));
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(targets) {
|
2007-01-24 03:51:50 -05:00
|
|
|
alpm_list_free(ls);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:49:27 -05:00
|
|
|
static int sync_trans(alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2007-10-03 22:02:36 -04:00
|
|
|
alpm_list_t *data = NULL;
|
|
|
|
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
|
2007-06-13 00:34:43 -04:00
|
|
|
|
2007-04-26 15:28:54 -04:00
|
|
|
/* Step 1: create a new transaction... */
|
2008-02-19 14:32:48 -05:00
|
|
|
if(sync_trans_init(config->flags) == -1) {
|
2006-01-26 15:46:48 -05:00
|
|
|
return(1);
|
2005-03-30 17:32:43 -05:00
|
|
|
}
|
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_upgrade) {
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *pkgs, *i;
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_(":: Starting full system upgrade...\n"));
|
2007-11-04 14:53:34 -05:00
|
|
|
alpm_logaction("starting full system upgrade\n");
|
2005-04-16 18:24:13 -04:00
|
|
|
if(alpm_trans_sysupgrade() == -1) {
|
2007-09-08 12:41:45 -04:00
|
|
|
fprintf(stderr, _("error: %s\n"), alpm_strerrorlast());
|
2005-04-06 17:03:09 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-12-09 21:57:54 -05:00
|
|
|
if(!(alpm_trans_get_flags() & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS))) {
|
|
|
|
/* check if pacman itself is one of the packages to upgrade.
|
|
|
|
* this can prevent some of the "syntax error" problems users can have
|
|
|
|
* when sysupgrade'ing with an older version of pacman.
|
|
|
|
*/
|
|
|
|
pkgs = alpm_trans_get_pkgs();
|
|
|
|
for(i = pkgs; i; i = alpm_list_next(i)) {
|
|
|
|
pmsyncpkg_t *sync = alpm_list_getdata(i);
|
|
|
|
pmpkg_t *spkg = alpm_sync_get_pkg(sync);
|
|
|
|
/* TODO pacman name should probably not be hardcoded. In addition, we
|
|
|
|
* have problems on an -Syu if pacman has to pull in deps, so recommend
|
|
|
|
* an '-S pacman' operation */
|
|
|
|
if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0) {
|
|
|
|
printf("\n");
|
2008-01-27 09:59:35 -05:00
|
|
|
printf(_(":: pacman has detected a newer version of itself.\n"));
|
|
|
|
if(yesno(_(":: Do you want to cancel the current operation\n"
|
|
|
|
":: and install the new pacman version now? [Y/n] "))) {
|
2008-02-19 14:32:48 -05:00
|
|
|
if(sync_trans_release() == -1) {
|
|
|
|
return(1);
|
2007-12-09 21:57:54 -05:00
|
|
|
}
|
2008-02-19 14:32:48 -05:00
|
|
|
if(sync_trans_init(0) == -1) {
|
2007-12-09 21:57:54 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if(alpm_trans_addtarget("pacman") == -1) {
|
|
|
|
fprintf(stderr, _("error: pacman: %s\n"), alpm_strerrorlast());
|
2008-02-19 14:32:48 -05:00
|
|
|
return(1);
|
2007-12-09 21:57:54 -05:00
|
|
|
}
|
|
|
|
break;
|
2006-01-06 09:00:03 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 18:24:13 -04:00
|
|
|
} else {
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *i;
|
|
|
|
|
2005-04-16 18:24:13 -04:00
|
|
|
/* process targets */
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
|
|
|
char *targ = alpm_list_getdata(i);
|
2005-04-16 18:24:13 -04:00
|
|
|
if(alpm_trans_addtarget(targ) == -1) {
|
2006-11-20 04:10:23 -05:00
|
|
|
pmgrp_t *grp = NULL;
|
2006-10-15 15:34:52 -04:00
|
|
|
int found=0;
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_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) {
|
2007-11-09 03:16:08 -05:00
|
|
|
fprintf(stderr, _("error: '%s': %s\n"),
|
2008-02-02 19:12:33 -05:00
|
|
|
targ, alpm_strerrorlast());
|
2005-04-16 18:24:13 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
/* target not found: check if it's a group */
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2007-10-03 22:02:36 -04:00
|
|
|
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
2007-01-19 04:28:44 -05:00
|
|
|
pmdb_t *db = alpm_list_getdata(j);
|
|
|
|
grp = alpm_db_readgrp(db, targ);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(grp) {
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *k;
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
found++;
|
2007-12-15 11:01:52 -05:00
|
|
|
printf(_(":: group %s (including ignored packages):\n"), targ);
|
2005-10-20 16:34:31 -04:00
|
|
|
/* remove dupe entries in case a package exists in multiple repos */
|
2007-06-05 17:34:33 -04:00
|
|
|
const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
|
|
|
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
2005-10-20 16:34:31 -04:00
|
|
|
list_display(" ", pkgs);
|
2006-05-14 22:19:57 -04:00
|
|
|
if(yesno(_(":: Install whole content? [Y/n] "))) {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(k = pkgs; k; k = alpm_list_next(k)) {
|
|
|
|
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
2007-01-19 04:28:44 -05:00
|
|
|
for(k = pkgs; k; k = alpm_list_next(k)) {
|
|
|
|
char *pkgname = alpm_list_getdata(k);
|
2006-05-14 22:19:57 -04:00
|
|
|
if(yesno(_(":: Install %s from group %s? [Y/n] "), pkgname, targ)) {
|
2007-01-19 04:28:44 -05:00
|
|
|
targets = alpm_list_add(targets, strdup(pkgname));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-24 03:51:50 -05:00
|
|
|
alpm_list_free(pkgs);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 15:34:52 -04:00
|
|
|
if(!found) {
|
2008-01-05 13:45:07 -05:00
|
|
|
/* targ not found in sync db, searching for providers... */
|
|
|
|
alpm_list_t *prov = NULL;
|
|
|
|
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
|
|
|
pmdb_t *db = alpm_list_getdata(j);
|
|
|
|
prov = alpm_list_join(prov, alpm_db_whatprovides(db, targ));
|
|
|
|
}
|
|
|
|
if(prov != NULL) {
|
|
|
|
if(alpm_list_count(prov) == 1) {
|
|
|
|
const char *pname = NULL;
|
|
|
|
pmpkg_t *pkg = alpm_list_getdata(prov);
|
|
|
|
pname = alpm_pkg_get_name(pkg);
|
|
|
|
alpm_list_free(prov);
|
|
|
|
printf(_("Warning: %s provides %s\n"), pname, targ);
|
|
|
|
targets = alpm_list_add(targets, strdup(pname));
|
|
|
|
} else {
|
|
|
|
alpm_list_t *k;
|
|
|
|
fprintf(stderr, _("error: several packages provide %s, please specify one :\n"), targ);
|
|
|
|
for(k = prov; k; k = alpm_list_next(k)) {
|
|
|
|
pmpkg_t *pkg = alpm_list_getdata(k);
|
|
|
|
printf("%s ", alpm_pkg_get_name(pkg));
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
alpm_list_free(prov);
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, _("error: '%s': not found in sync db\n"), targ);
|
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 15:28:54 -04: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) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
|
2007-09-08 12:41:45 -04:00
|
|
|
alpm_strerrorlast());
|
2006-01-06 18:14:21 -05:00
|
|
|
switch(pm_errno) {
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *i;
|
2006-01-06 18:14:21 -05:00
|
|
|
case PM_ERR_UNSATISFIED_DEPS:
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
|
|
|
pmdepmissing_t *miss = alpm_list_getdata(i);
|
2007-07-16 08:08:48 -04:00
|
|
|
pmdepend_t *dep = alpm_miss_get_dep(miss);
|
2007-10-24 20:31:28 -04:00
|
|
|
char *depstring = alpm_dep_get_string(dep);
|
2007-07-16 08:08:48 -04:00
|
|
|
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
|
2007-10-24 20:31:28 -04:00
|
|
|
depstring);
|
|
|
|
free(depstring);
|
2006-01-06 18:14:21 -05:00
|
|
|
}
|
2007-06-13 00:31:01 -04:00
|
|
|
break;
|
2006-01-06 18:14:21 -05:00
|
|
|
case PM_ERR_CONFLICTING_DEPS:
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
2007-11-18 08:25:43 -05:00
|
|
|
pmconflict_t *conflict = alpm_list_getdata(i);
|
Fix several memleaks, mostly related to errors handling.
* The frontend calls alpm_trans_prepare(&data), and in case of errors,
receive the missing dependencies / conflicts / etc in the data pointer.
It apparently needs to free this structure totally with :
alpm_list_free_inner(data, free)
alpm_list_free(data)
So I added alpm_list_free_inner(data, free) in
pacman/{sync.c,remove.c,add,c}
* in _alpm_sync_prepare, the deps and asked lists were not freed in case
of errors (unresolvable conflicts).
Besides the code for handling this case was duplicated.
* in _alpm_remove_commit, free was used instead of alpm_list_free for
newfiles.
* newline fix in pacman/sync.c
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-21 13:51:46 -05:00
|
|
|
printf(_(":: %s: conflicts with %s\n"),
|
2007-11-18 08:25:43 -05:00
|
|
|
alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
|
2006-01-06 18:14:21 -05:00
|
|
|
}
|
2007-06-13 00:31:01 -04:00
|
|
|
break;
|
2006-01-06 18:14:21 -05:00
|
|
|
default:
|
2007-06-13 00:31:01 -04:00
|
|
|
break;
|
2006-01-06 18:14:21 -05:00
|
|
|
}
|
2005-04-06 17:03:09 -04:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *packages = alpm_trans_get_pkgs();
|
2006-01-05 16:29:36 -05:00
|
|
|
if(packages == NULL) {
|
2006-01-06 09:00:03 -05:00
|
|
|
/* nothing to do: just exit without complaining */
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_(" local database is up to date\n"));
|
2006-01-05 16:29:36 -05:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
|
2007-06-13 00:34:43 -04:00
|
|
|
int confirm;
|
|
|
|
|
2007-10-19 13:17:54 -04:00
|
|
|
display_targets(packages, db_local);
|
2007-04-26 15:28:54 -04:00
|
|
|
printf("\n");
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->op_s_downloadonly) {
|
|
|
|
if(config->noconfirm) {
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_("Beginning download...\n"));
|
2005-03-14 20:51:43 -05:00
|
|
|
confirm = 1;
|
|
|
|
} else {
|
2006-05-14 22:19:57 -04:00
|
|
|
confirm = yesno(_("Proceed with download? [Y/n] "));
|
2005-04-13 15:59:04 -04:00
|
|
|
}
|
|
|
|
} else {
|
2007-07-15 12:44:18 -04:00
|
|
|
if(config->noconfirm) {
|
|
|
|
printf(_("Beginning upgrade process...\n"));
|
2005-04-13 15:59:04 -04:00
|
|
|
confirm = 1;
|
|
|
|
} else {
|
2007-07-15 12:44:18 -04:00
|
|
|
confirm = yesno(_("Proceed with installation? [Y/n] "));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
if(!confirm) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-01-03 03:05:13 -05:00
|
|
|
}/* else 'print uris' requested. We're done at this point */
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-04-26 15:28:54 -04:00
|
|
|
/* Step 3: actually perform the installation */
|
2007-01-03 03:05:13 -05:00
|
|
|
if(alpm_trans_commit(&data) == -1) {
|
2007-04-26 16:23:59 -04:00
|
|
|
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
|
2007-09-08 12:41:45 -04:00
|
|
|
alpm_strerrorlast());
|
2007-01-03 03:05:13 -05:00
|
|
|
switch(pm_errno) {
|
2007-06-13 00:34:43 -04:00
|
|
|
alpm_list_t *i;
|
2007-04-26 15:28:54 -04:00
|
|
|
case PM_ERR_FILE_CONFLICTS:
|
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
2007-11-18 04:29:55 -05:00
|
|
|
pmfileconflict_t *conflict = alpm_list_getdata(i);
|
|
|
|
switch(alpm_fileconflict_get_type(conflict)) {
|
|
|
|
case PM_FILECONFLICT_TARGET:
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_("%s exists in both '%s' and '%s'\n"),
|
2007-11-18 04:29:55 -05:00
|
|
|
alpm_fileconflict_get_file(conflict),
|
|
|
|
alpm_fileconflict_get_target(conflict),
|
|
|
|
alpm_fileconflict_get_ctarget(conflict));
|
2007-04-26 15:28:54 -04:00
|
|
|
break;
|
2007-11-18 04:29:55 -05:00
|
|
|
case PM_FILECONFLICT_FILESYSTEM:
|
2007-04-26 15:28:54 -04:00
|
|
|
printf(_("%s: %s exists in filesystem\n"),
|
2007-11-18 04:29:55 -05:00
|
|
|
alpm_fileconflict_get_target(conflict),
|
|
|
|
alpm_fileconflict_get_file(conflict));
|
2007-04-26 15:28:54 -04:00
|
|
|
break;
|
|
|
|
}
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-04-26 15:28:54 -04:00
|
|
|
break;
|
|
|
|
case PM_ERR_PKG_CORRUPTED:
|
|
|
|
for(i = data; i; i = alpm_list_next(i)) {
|
|
|
|
printf("%s", (char*)alpm_list_getdata(i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-01-07 13:42:44 -05:00
|
|
|
}
|
2007-04-26 15:28:54 -04:00
|
|
|
/* TODO: stderr? */
|
|
|
|
printf(_("Errors occurred, no packages were upgraded.\n"));
|
2007-01-03 03:05:13 -05:00
|
|
|
retval = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-04-26 15:28:54 -04:00
|
|
|
/* Step 4: release transaction resources */
|
2005-03-14 20:51:43 -05:00
|
|
|
cleanup:
|
2006-11-14 02:58:42 -05:00
|
|
|
if(data) {
|
2007-12-08 03:58:49 -05:00
|
|
|
FREELIST(data);
|
2006-11-14 02:58:42 -05:00
|
|
|
}
|
2008-02-19 14:32:48 -05:00
|
|
|
if(sync_trans_release() == -1) {
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-03 22:02:36 -04:00
|
|
|
int pacman_sync(alpm_list_t *targets)
|
|
|
|
{
|
|
|
|
alpm_list_t *sync_dbs = NULL;
|
|
|
|
|
|
|
|
/* clean the cache */
|
|
|
|
if(config->op_s_clean) {
|
2008-02-19 15:57:40 -05:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if(sync_trans_init(0) == -1) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += sync_cleancache(config->op_s_clean);
|
2007-11-17 16:52:03 -05:00
|
|
|
ret += sync_cleandb_all();
|
2008-02-19 15:57:40 -05:00
|
|
|
|
|
|
|
if(sync_trans_release() == -1) {
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
2007-11-17 16:52:03 -05:00
|
|
|
return(ret);
|
2007-10-03 22:02:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure we have at least one valid sync db set up */
|
|
|
|
sync_dbs = alpm_option_get_syncdbs();
|
|
|
|
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
|
|
|
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:49:27 -05:00
|
|
|
if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade
|
|
|
|
|| config->op_s_search || config->group
|
|
|
|
|| config->op_s_info || config->op_q_list)) {
|
2007-10-03 22:02:36 -04:00
|
|
|
/* don't proceed here unless we have an operation that doesn't require
|
|
|
|
* a target list */
|
|
|
|
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:49:27 -05:00
|
|
|
if(config->op_s_sync) {
|
|
|
|
/* grab a fresh package list */
|
|
|
|
printf(_(":: Synchronizing package databases...\n"));
|
|
|
|
alpm_logaction("synchronizing package lists\n");
|
|
|
|
if(!sync_synctree(config->op_s_sync, sync_dbs)) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
config->op_s_sync = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-03 22:02:36 -04:00
|
|
|
if(needs_transaction()) {
|
2008-01-28 13:49:27 -05:00
|
|
|
if(sync_trans(targets) == 1) {
|
2007-10-03 22:02:36 -04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for a package */
|
|
|
|
if(config->op_s_search) {
|
|
|
|
return(sync_search(sync_dbs, targets));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for groups */
|
|
|
|
if(config->group) {
|
|
|
|
return(sync_group(config->group, sync_dbs, targets));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get package info */
|
|
|
|
if(config->op_s_info) {
|
|
|
|
return(sync_info(sync_dbs, targets));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a listing of files in sync DBs */
|
|
|
|
if(config->op_q_list) {
|
|
|
|
return(sync_list(sync_dbs, targets));
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|