summaryrefslogtreecommitdiffstats
path: root/src/pacman/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/sync.c')
-rw-r--r--src/pacman/sync.c216
1 files changed, 107 insertions, 109 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 12f67df2..a2ef616d 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -93,18 +93,21 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
if(rmrf(path)) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove repository directory\n"));
+ closedir(dir);
return(1);
}
}
-
}
+ closedir(dir);
return(0);
}
static int sync_cleandb_all(void) {
- const char *dbpath = alpm_option_get_dbpath();
+ const char *dbpath;
char newdbpath[PATH_MAX];
+ int ret = 0;
+ dbpath = alpm_option_get_dbpath();
printf(_("Database directory: %s\n"), dbpath);
if(!yesno(_("Do you want to remove unused repositories?"))) {
return(0);
@@ -112,28 +115,26 @@ static int sync_cleandb_all(void) {
/* 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);
+ ret += sync_cleandb(dbpath, 0);
sprintf(newdbpath, "%s%s", dbpath, "sync/");
- sync_cleandb(newdbpath, 1);
+ ret += sync_cleandb(newdbpath, 1);
printf(_("Database directory cleaned up\n"));
- return(0);
+ return(ret);
}
static int sync_cleancache(int level)
{
- /* 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);
+ alpm_list_t *i;
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
+ int ret = 0;
+
+ for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ printf(_("Cache directory: %s\n"), (char*)alpm_list_getdata(i));
+ }
if(level == 1) {
- /* incomplete cleanup */
- DIR *dir;
- struct dirent *ent;
- /* Open up each package and see if it should be deleted,
- * depending on the clean method used */
- printf(_("Cache directory: %s\n"), cachedir);
switch(config->cleanmethod) {
case PM_CLEAN_KEEPINST:
if(!yesno(_("Do you want to remove uninstalled packages from cache?"))) {
@@ -150,11 +151,23 @@ static int sync_cleancache(int level)
return(1);
}
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"));
+ }
+
+ for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ const char *cachedir = alpm_list_getdata(i);
+ DIR *dir = opendir(cachedir);
+ struct dirent *ent;
- dir = opendir(cachedir);
if(dir == NULL) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("could not access cache directory\n"));
- return(1);
+ pm_fprintf(stderr, PM_LOG_ERROR,
+ _("could not access cache directory %s\n"), cachedir);
+ ret++;
+ continue;
}
rewinddir(dir);
@@ -163,7 +176,6 @@ static int sync_cleancache(int level)
char path[PATH_MAX];
int delete = 1;
pmpkg_t *localpkg = NULL, *pkg = NULL;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
alpm_list_t *j;
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
@@ -172,11 +184,20 @@ static int sync_cleancache(int level)
/* build the full filepath */
snprintf(path, PATH_MAX, "%s%s", cachedir, ent->d_name);
+ /* short circuit for removing all packages from cache */
+ if(level > 1) {
+ unlink(path);
+ continue;
+ }
+
/* attempt to load the package, prompt removal on failures as we may have
* 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) {
if(yesno(_("File %s does not seem to be a valid package, remove it?"), path)) {
+ if(localpkg) {
+ alpm_pkg_free(localpkg);
+ }
unlink(path);
}
continue;
@@ -215,26 +236,10 @@ static int sync_cleancache(int level)
unlink(path);
}
}
- } else {
- /* full cleanup */
- printf(_("Cache directory: %s\n"), cachedir);
- if(!noyes(_("Do you want to remove ALL files from cache?"))) {
- return(0);
- }
- printf(_("removing all files from cache...\n"));
-
- if(rmrf(cachedir)) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("could not remove cache directory\n"));
- return(1);
- }
-
- if(makepath(cachedir)) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("could not create new cache directory\n"));
- return(1);
- }
+ closedir(dir);
}
- return(0);
+ return(ret);
}
static int sync_synctree(int level, alpm_list_t *syncs)
@@ -242,7 +247,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_list_t *i;
int success = 0, ret;
- if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
+ if(trans_init(0) == -1) {
return(0);
}
@@ -548,89 +553,68 @@ static alpm_list_t *syncfirst() {
return(res);
}
+static int process_target(char *target)
+{
+ /* process targets */
+ char *targstring = strdup(target);
+ char *targname = strchr(targstring, '/');
+ char *dbname = NULL;
+ int ret = 0;
+ if(targname) {
+ *targname = '\0';
+ targname++;
+ dbname = targstring;
+ ret = alpm_sync_dbtarget(dbname,targname);
+ } else {
+ targname = targstring;
+ ret = alpm_sync_target(targname);
+ }
+
+ if(ret == -1) {
+ if(pm_errno == PM_ERR_TRANS_DUP_TARGET
+ || pm_errno == PM_ERR_PKG_IGNORED) {
+ /* just skip duplicate or ignored targets */
+ pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), target);
+ } else {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target,
+ alpm_strerrorlast());
+ ret = 1;
+ }
+ }
+
+ free(targstring);
+ return(ret);
+}
+
static int sync_trans(alpm_list_t *targets)
{
int retval = 0;
alpm_list_t *data = NULL;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
alpm_list_t *packages = NULL;
+ alpm_list_t *i;
/* Step 1: create a new transaction... */
- if(trans_init(PM_TRANS_TYPE_SYNC, config->flags) == -1) {
+ if(trans_init(config->flags) == -1) {
return(1);
}
+ /* process targets */
+ for(i = targets; i; i = alpm_list_next(i)) {
+ char *targ = alpm_list_getdata(i);
+ if(process_target(targ) == 1) {
+ retval = 1;
+ goto cleanup;
+ }
+ }
+
if(config->op_s_upgrade) {
printf(_(":: Starting full system upgrade...\n"));
alpm_logaction("starting full system upgrade\n");
- if(alpm_trans_sysupgrade(config->op_s_upgrade >= 2) == -1) {
+ if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
retval = 1;
goto cleanup;
}
- } else {
- alpm_list_t *i;
-
- /* process targets */
- for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
- if(alpm_trans_addtarget(targ) == -1) {
- pmgrp_t *grp = NULL;
- int found = 0;
- alpm_list_t *j;
-
- if(pm_errno == PM_ERR_TRANS_DUP_TARGET || pm_errno == PM_ERR_PKG_IGNORED) {
- /* just skip duplicate or ignored targets */
- pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
- continue;
- }
- if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- targ, alpm_strerrorlast());
- retval = 1;
- goto cleanup;
- }
- /* target not found: check if it's a group */
- printf(_("%s package not found, searching for group...\n"), targ);
- for(j = sync_dbs; j; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
- grp = alpm_db_readgrp(db, targ);
- if(grp) {
- alpm_list_t *k, *pkgnames = NULL;
-
- found++;
- printf(_(":: group %s (including ignored packages):\n"), targ);
- /* remove dupe entries in case a package exists in multiple repos */
- alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
- alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
- for(k = pkgs; k; k = alpm_list_next(k)) {
- pkgnames = alpm_list_add(pkgnames,
- (char*)alpm_pkg_get_name(k->data));
- }
- list_display(" ", pkgnames);
- if(yesno(_(":: Install whole content?"))) {
- for(k = pkgnames; k; k = alpm_list_next(k)) {
- targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
- }
- } else {
- for(k = pkgnames; k; k = alpm_list_next(k)) {
- char *pkgname = alpm_list_getdata(k);
- if(yesno(_(":: Install %s from group %s?"), pkgname, targ)) {
- targets = alpm_list_add(targets, strdup(pkgname));
- }
- }
- }
- alpm_list_free(pkgnames);
- alpm_list_free(pkgs);
- }
- }
- if(!found) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in sync db\n"), targ);
- retval = 1;
- goto cleanup;
- }
- }
- }
}
/* Step 2: "compute" the transaction based on targets and flags */
@@ -639,6 +623,12 @@ static int sync_trans(alpm_list_t *targets)
alpm_strerrorlast());
switch(pm_errno) {
alpm_list_t *i;
+ case PM_ERR_PKG_INVALID_ARCH:
+ for(i = data; i; i = alpm_list_next(i)) {
+ char *pkg = alpm_list_getdata(i);
+ printf(_(":: package %s does not have a valid architecture\n"), pkg);
+ }
+ break;
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
@@ -650,10 +640,17 @@ static int sync_trans(alpm_list_t *targets)
}
break;
case PM_ERR_CONFLICTING_DEPS:
- for(i = data; i; i = alpm_list_next(i)) {
+ for(i = data; i; i = alpm_list_next(i)) {
pmconflict_t *conflict = alpm_list_getdata(i);
- printf(_(":: %s: conflicts with %s\n"),
- alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
+ const char *package1 = alpm_conflict_get_package1(conflict);
+ const char *package2 = alpm_conflict_get_package2(conflict);
+ const char *reason = alpm_conflict_get_reason(conflict);
+ /* only print reason if it contains new information */
+ if(!strcmp(package1, reason) || !strcmp(package2, reason)) {
+ printf(_(":: %s and %s are in conflict\n"), package1, package2);
+ } else {
+ printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
+ }
}
break;
default:
@@ -663,7 +660,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- packages = alpm_trans_get_pkgs();
+ packages = alpm_trans_get_add();
if(packages == NULL) {
/* nothing to do: just exit without complaining */
printf(_(" local database is up to date\n"));
@@ -691,7 +688,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- display_synctargets(packages);
+ display_targets(alpm_trans_get_remove(), 0);
+ display_targets(alpm_trans_get_add(), 1);
printf("\n");
int confirm;
@@ -768,7 +766,7 @@ int pacman_sync(alpm_list_t *targets)
if(config->op_s_clean) {
int ret = 0;
- if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
+ if(trans_init(0) == -1) {
return(1);
}