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.c283
1 files changed, 133 insertions, 150 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 951ee94c..532a6672 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,15 +167,11 @@ 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));
- }
-
if(!config->cleanmethod) {
/* default to KeepInstalled if user did not specify */
config->cleanmethod = PM_CLEAN_KEEPINST;
@@ -191,22 +185,31 @@ static int sync_cleancache(int level)
if(config->cleanmethod & PM_CLEAN_KEEPCUR) {
printf(_(" All current sync database packages\n"));
}
- if(!yesno(_("Do you want to remove all other packages from cache?"))) {
- return 0;
- }
- printf(_("removing old packages from cache...\n"));
- } else {
- if(!noyes(_("Do you want to remove ALL files from cache?"))) {
- return 0;
- }
- printf(_("removing all files from cache...\n"));
}
+ printf("\n");
for(i = cachedirs; i; i = alpm_list_next(i)) {
- const char *cachedir = alpm_list_getdata(i);
- DIR *dir = opendir(cachedir);
+ const char *cachedir = i->data;
+ DIR *dir;
struct dirent *ent;
+ printf(_("Cache directory: %s\n"), (const char *)i->data);
+
+ if(level == 1) {
+ if(!yesno(_("Do you want to remove all other packages from cache?"))) {
+ printf("\n");
+ continue;
+ }
+ printf(_("removing old packages from cache...\n"));
+ } else {
+ if(!noyes(_("Do you want to remove ALL files from cache?"))) {
+ printf("\n");
+ continue;
+ }
+ printf(_("removing all files from cache...\n"));
+ }
+
+ dir = opendir(cachedir);
if(dir == NULL) {
pm_printf(ALPM_LOG_ERROR,
_("could not access cache directory %s\n"), cachedir);
@@ -226,19 +229,30 @@ static int sync_cleancache(int level)
continue;
}
- /* skip signature files - they are removed with their package file */
- if(fnmatch("*.sig", ent->d_name, 0) == 0) {
- continue;
- }
-
- /* skip package database within the cache directory */
- if(fnmatch("*.db*", ent->d_name, 0) == 0) {
- continue;
- }
-
- /* skip source packages within the cache directory */
- if(fnmatch("*.src.tar*", ent->d_name, 0) == 0) {
- continue;
+ if (level <= 1) {
+ static const char * const glob_skips[] = {
+ /* skip signature files - they are removed with their package file */
+ "*.sig",
+ /* skip package database within the cache directory */
+ "*.db*",
+ /* skip source packages within the cache directory */
+ "*.src.tar.*",
+ /* skip package deltas, we aren't smart enough to clean these yet */
+ "*.delta",
+ /* skip any partial downloads */
+ "*.part"
+ };
+ size_t j;
+
+ for(j = 0; j < sizeof(glob_skips) / sizeof(glob_skips[0]); j++) {
+ if(fnmatch(glob_skips[j], ent->d_name, 0) == 0) {
+ delete = 0;
+ break;
+ }
+ }
+ if(delete == 0) {
+ continue;
+ }
}
/* build the full filepath */
@@ -276,7 +290,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) {
@@ -301,6 +315,7 @@ static int sync_cleancache(int level)
}
}
closedir(dir);
+ printf("\n");
}
return ret;
@@ -309,12 +324,12 @@ static int sync_cleancache(int level)
static int sync_synctree(int level, alpm_list_t *syncs)
{
alpm_list_t *i;
- int success = 0, ret;
+ unsigned int success = 0;
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);
+ int ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) {
pm_printf(ALPM_LOG_ERROR, _("failed to update %s (%s)\n"),
alpm_db_get_name(db), alpm_strerror(alpm_errno(config->handle)));
@@ -358,10 +373,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 +391,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 +437,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 +461,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 +493,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 +509,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 +540,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 +555,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 +585,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),
@@ -587,30 +608,10 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
return 0;
}
-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);
-
- for(i = config->syncfirst; i; i = alpm_list_next(i)) {
- char *pkgname = alpm_list_getdata(i);
- alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
- if(pkg == NULL) {
- continue;
- }
-
- if(alpm_sync_newversion(pkg, syncdbs)) {
- res = alpm_list_add(res, strdup(pkgname));
- }
- }
-
- return res;
-}
-
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 +625,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 +641,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 +653,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 +678,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 +689,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 +697,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 +718,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 +743,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 +764,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 +774,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 +805,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 +825,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 +874,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 +898,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;
@@ -921,7 +936,6 @@ int pacman_sync(alpm_list_t *targets)
}
ret += sync_cleancache(config->op_s_clean);
- printf("\n");
ret += sync_cleandb_all();
if(trans_release() == -1) {
@@ -935,7 +949,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 */
@@ -983,38 +997,7 @@ int pacman_sync(alpm_list_t *targets)
}
}
- alpm_list_t *targs = alpm_list_strdup(targets);
- if(!config->op_s_downloadonly && !config->print) {
- /* check for newer versions of packages to be upgraded first */
- alpm_list_t *packages = syncfirst();
- if(packages) {
- /* Do not ask user if all the -S targets are SyncFirst packages, see FS#15810 */
- alpm_list_t *tmp = NULL;
- 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);
- if(yesno(_(":: Do you want to cancel the current operation\n"
- ":: and upgrade these packages now?"))) {
- FREELIST(targs);
- targs = packages;
- config->flags = 0;
- config->op_s_upgrade = 0;
- } else {
- FREELIST(packages);
- }
- printf("\n");
- } else {
- pm_printf(ALPM_LOG_DEBUG, "skipping SyncFirst dialog\n");
- FREELIST(packages);
- }
- }
- }
-
- int ret = sync_trans(targs);
- FREELIST(targs);
-
- return ret;
+ return sync_trans(targets);
}
/* vim: set ts=2 sw=2 noet: */