summaryrefslogtreecommitdiff
path: root/src/pacman/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/sync.c')
-rw-r--r--src/pacman/sync.c164
1 files changed, 91 insertions, 73 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 951ee94c..5165dca1 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -18,8 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -68,7 +66,7 @@ static int sync_cleandb(const char *dbpath, int keep_used)
return 1;
}
- syncdbs = alpm_option_get_syncdbs(config->handle);
+ syncdbs = alpm_get_syncdbs(config->handle);
rewinddir(dir);
/* step through the directory one file at a time */
@@ -118,7 +116,7 @@ static int sync_cleandb(const char *dbpath, int keep_used)
if(keep_used) {
alpm_list_t *i;
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
found = !strcmp(dbname, alpm_db_get_name(db));
}
}
@@ -169,13 +167,13 @@ static int sync_cleandb_all(void)
static int sync_cleancache(int level)
{
alpm_list_t *i;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle);
- alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_list_t *sync_dbs = alpm_get_syncdbs(config->handle);
+ alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *cachedirs = alpm_option_get_cachedirs(config->handle);
int ret = 0;
for(i = cachedirs; i; i = alpm_list_next(i)) {
- printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
+ printf(_("Cache directory: %s\n"), (const char *)i->data);
}
if(!config->cleanmethod) {
@@ -203,7 +201,7 @@ static int sync_cleancache(int level)
}
for(i = cachedirs; i; i = alpm_list_next(i)) {
- const char *cachedir = alpm_list_getdata(i);
+ const char *cachedir = i->data;
DIR *dir = opendir(cachedir);
struct dirent *ent;
@@ -276,7 +274,7 @@ static int sync_cleancache(int level)
alpm_list_t *j;
/* check if this package is in a sync DB */
for(j = sync_dbs; j && delete; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
pkg = alpm_db_get_pkg(db, local_name);
if(pkg != NULL && alpm_pkg_vercmp(local_version,
alpm_pkg_get_version(pkg)) == 0) {
@@ -312,7 +310,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
int success = 0, ret;
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) {
@@ -358,10 +356,11 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *i, *j, *ret;
int freelist;
int found = 0;
- alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_db_t *db_local = alpm_get_localdb(config->handle);
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
+ unsigned short cols;
/* if we have a targets list, search for packages matching it */
if(targets) {
ret = alpm_db_search(db, targets);
@@ -375,39 +374,40 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
} else {
found = 1;
}
+ cols = getcols(fileno(stdout));
for(j = ret; j; j = alpm_list_next(j)) {
alpm_list_t *grp;
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
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));
+ fputs(alpm_pkg_get_name(pkg), stdout);
}
if(!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_list_t *k;
- printf(" (");
+ fputs(" (", stdout);
for(k = grp; k; k = alpm_list_next(k)) {
- const char *group = alpm_list_getdata(k);
- printf("%s", group);
+ const char *group = k->data;
+ fputs(group, stdout);
if(alpm_list_next(k)) {
/* only print a spacer if there are more groups */
- printf(" ");
+ putchar(' ');
}
}
- printf(")");
+ putchar(')');
}
print_installed(db_local, pkg);
/* we need a newline and initial indent first */
- printf("\n ");
- indentprint(alpm_pkg_get_desc(pkg), 4);
+ fputs("\n ", stdout);
+ indentprint(alpm_pkg_get_desc(pkg), 4, cols);
}
- printf("\n");
+ fputc('\n', stdout);
}
/* we only want to free if the list was a search list */
if(freelist) {
@@ -420,23 +420,23 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
{
- alpm_list_t *i, *j, *k;
+ alpm_list_t *i, *j, *k, *s = NULL;
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *grpname = alpm_list_getdata(i);
+ const char *grpname = i->data;
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
- alpm_group_t *grp = alpm_db_readgroup(db, grpname);
+ alpm_db_t *db = j->data;
+ alpm_group_t *grp = alpm_db_get_group(db, grpname);
if(grp) {
/* get names of packages in group */
for(k = grp->packages; k; k = alpm_list_next(k)) {
if(!config->quiet) {
printf("%s %s\n", grpname,
- alpm_pkg_get_name(alpm_list_getdata(k)));
+ alpm_pkg_get_name(k->data));
} else {
- printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
+ printf("%s\n", alpm_pkg_get_name(k->data));
}
}
}
@@ -444,22 +444,26 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_groupcache(db); j; j = alpm_list_next(j)) {
- alpm_group_t *grp = alpm_list_getdata(j);
+ alpm_group_t *grp = j->data;
if(level > 1) {
for(k = grp->packages; k; k = alpm_list_next(k)) {
printf("%s %s\n", grp->name,
- alpm_pkg_get_name(alpm_list_getdata(k)));
+ alpm_pkg_get_name(k->data));
}
} else {
/* print grp names only, no package names */
- printf("%s\n", grp->name);
+ if(!alpm_list_find_str (s, grp->name)) {
+ s = alpm_list_add (s, grp->name);
+ printf("%s\n", grp->name);
+ }
}
}
}
+ alpm_list_free(s);
}
return 0;
@@ -472,7 +476,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *target = alpm_list_getdata(i);
+ const char *target = i->data;
char *name = strdup(target);
char *repo, *pkgstr;
int foundpkg = 0, founddb = 0;
@@ -488,14 +492,14 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
if(repo && strcmp(repo, alpm_db_get_name(db)) != 0) {
continue;
}
founddb = 1;
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- alpm_pkg_t *pkg = alpm_list_getdata(k);
+ alpm_pkg_t *pkg = k->data;
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
dump_pkg_full(pkg, config->op_s_info > 1);
@@ -519,10 +523,10 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
dump_pkg_full(pkg, config->op_s_info > 1);
}
}
@@ -534,15 +538,15 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
{
alpm_list_t *i, *j, *ls = NULL;
- alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_db_t *db_local = alpm_get_localdb(config->handle);
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *repo = alpm_list_getdata(i);
+ const char *repo = i->data;
alpm_db_t *db = NULL;
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *d = alpm_list_getdata(j);
+ alpm_db_t *d = j->data;
if(strcmp(repo, alpm_db_get_name(d)) == 0) {
db = d;
@@ -564,10 +568,10 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
}
for(i = ls; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
if(!config->quiet) {
printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
@@ -589,11 +593,11 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
static alpm_list_t *syncfirst(void) {
alpm_list_t *i, *res = NULL;
- alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
- alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle);
+ alpm_db_t *db_local = alpm_get_localdb(config->handle);
+ alpm_list_t *syncdbs = alpm_get_syncdbs(config->handle);
for(i = config->syncfirst; i; i = alpm_list_next(i)) {
- char *pkgname = alpm_list_getdata(i);
+ const char *pkgname = i->data;
alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
if(pkg == NULL) {
continue;
@@ -610,7 +614,7 @@ static alpm_list_t *syncfirst(void) {
static alpm_db_t *get_db(const char *dbname)
{
alpm_list_t *i;
- for(i = alpm_option_get_syncdbs(config->handle); i; i = i->next) {
+ for(i = alpm_get_syncdbs(config->handle); i; i = i->next) {
alpm_db_t *db = i->data;
if(strcmp(alpm_db_get_name(db), dbname) == 0) {
return db;
@@ -624,7 +628,7 @@ static int process_pkg(alpm_pkg_t *pkg)
int ret = alpm_add_pkg(config->handle, pkg);
if(ret == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
if(err == ALPM_ERR_TRANS_DUP_TARGET
|| err == ALPM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
@@ -640,7 +644,7 @@ static int process_pkg(alpm_pkg_t *pkg)
return 0;
}
-static int process_group(alpm_list_t *dbs, const char *group)
+static int process_group(alpm_list_t *dbs, const char *group, int error)
{
int ret = 0;
alpm_list_t *i;
@@ -652,6 +656,12 @@ static int process_group(alpm_list_t *dbs, const char *group)
return 1;
}
+ if(error) {
+ /* we already know another target errored. there is no reason to prompt the
+ * user here; we already validated the group name so just move on since we
+ * won't actually be installing anything anyway. */
+ goto cleanup;
+ }
if(config->print == 0) {
printf(_(":: There are %d members in group %s:\n"), count,
@@ -671,7 +681,7 @@ static int process_group(alpm_list_t *dbs, const char *group)
for(i = pkgs; i; i = alpm_list_next(i)) {
if(array[n++] == 0)
continue;
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -682,7 +692,7 @@ static int process_group(alpm_list_t *dbs, const char *group)
free(array);
} else {
for(i = pkgs; i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -690,12 +700,14 @@ static int process_group(alpm_list_t *dbs, const char *group)
}
}
}
+
cleanup:
alpm_list_free(pkgs);
return ret;
}
-static int process_targname(alpm_list_t *dblist, const char *targname)
+static int process_targname(alpm_list_t *dblist, const char *targname,
+ int error)
{
alpm_pkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname);
@@ -709,20 +721,20 @@ static int process_targname(alpm_list_t *dblist, const char *targname)
return process_pkg(pkg);
}
/* fallback on group */
- return process_group(dblist, targname);
+ return process_group(dblist, targname, error);
}
-static int process_target(const char *target)
+static int process_target(const char *target, int error)
{
/* process targets */
char *targstring = strdup(target);
char *targname = strchr(targstring, '/');
- char *dbname = NULL;
int ret = 0;
- alpm_list_t *dblist = NULL;
+ alpm_list_t *dblist;
if(targname && targname != targstring) {
- alpm_db_t *db = NULL;
+ alpm_db_t *db;
+ const char *dbname;
*targname = '\0';
targname++;
@@ -734,14 +746,15 @@ static int process_target(const char *target)
ret = 1;
goto cleanup;
}
- dblist = alpm_list_add(dblist, db);
- ret = process_targname(dblist, targname);
+ dblist = alpm_list_add(NULL, db);
+ ret = process_targname(dblist, targname, error);
alpm_list_free(dblist);
} else {
targname = targstring;
- dblist = alpm_option_get_syncdbs(config->handle);
- ret = process_targname(dblist, targname);
+ dblist = alpm_get_syncdbs(config->handle);
+ ret = process_targname(dblist, targname, error);
}
+
cleanup:
free(targstring);
if(ret && access(target, R_OK) == 0) {
@@ -754,6 +767,7 @@ cleanup:
static int sync_trans(alpm_list_t *targets)
{
+ int retval = 0;
alpm_list_t *i;
/* Step 1: create a new transaction... */
@@ -763,13 +777,17 @@ static int sync_trans(alpm_list_t *targets)
/* process targets */
for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
- if(process_target(targ) == 1) {
- trans_release();
- return 1;
+ const char *targ = i->data;
+ if(process_target(targ, retval) == 1) {
+ retval = 1;
}
}
+ if(retval) {
+ trans_release();
+ return retval;
+ }
+
if(config->op_s_upgrade) {
printf(_(":: Starting full system upgrade...\n"));
alpm_logaction(config->handle, "starting full system upgrade\n");
@@ -790,19 +808,19 @@ int sync_prepare_execute(void)
/* Step 2: "compute" the transaction based on targets and flags */
if(alpm_trans_prepare(config->handle, &data) == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerror(err));
switch(err) {
case ALPM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
- char *pkg = alpm_list_getdata(i);
+ const char *pkg = i->data;
printf(_(":: package %s does not have a valid architecture\n"), pkg);
}
break;
case ALPM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = alpm_list_getdata(i);
+ alpm_depmissing_t *miss = i->data;
char *depstring = alpm_dep_compute_string(miss->depend);
printf(_(":: %s: requires %s\n"), miss->target, depstring);
free(depstring);
@@ -810,7 +828,7 @@ int sync_prepare_execute(void)
break;
case ALPM_ERR_CONFLICTING_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_conflict_t *conflict = alpm_list_getdata(i);
+ alpm_conflict_t *conflict = i->data;
/* only print reason if it contains new information */
if(conflict->reason->mod == ALPM_DEP_MOD_ANY) {
printf(_(":: %s and %s are in conflict\n"),
@@ -859,13 +877,13 @@ int sync_prepare_execute(void)
}
if(alpm_trans_commit(config->handle, &data) == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerror(err));
switch(err) {
case ALPM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_fileconflict_t *conflict = alpm_list_getdata(i);
+ alpm_fileconflict_t *conflict = i->data;
switch(conflict->type) {
case ALPM_FILECONFLICT_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
@@ -883,7 +901,7 @@ int sync_prepare_execute(void)
case ALPM_ERR_PKG_INVALID_SIG:
case ALPM_ERR_DLT_INVALID:
for(i = data; i; i = alpm_list_next(i)) {
- const char *filename = alpm_list_getdata(i);
+ const char *filename = i->data;
printf(_("%s is invalid or corrupted\n"), filename);
}
break;
@@ -935,7 +953,7 @@ int pacman_sync(alpm_list_t *targets)
return 1;
}
- sync_dbs = alpm_option_get_syncdbs(config->handle);
+ sync_dbs = alpm_get_syncdbs(config->handle);
if(config->op_s_sync) {
/* grab a fresh package list */
@@ -993,7 +1011,7 @@ int pacman_sync(alpm_list_t *targets)
if(config->op_s_upgrade || (tmp = alpm_list_diff(targets, packages, (alpm_list_fn_cmp)strcmp))) {
alpm_list_free(tmp);
printf(_(":: The following packages should be upgraded first :\n"));
- list_display(" ", packages);
+ list_display(" ", packages, getcols(fileno(stdout)));
if(yesno(_(":: Do you want to cancel the current operation\n"
":: and upgrade these packages now?"))) {
FREELIST(targs);