summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-29 19:10:05 +0100
committerDan McGee <dan@archlinux.org>2011-01-31 16:38:14 +0100
commit09f9f2433173477c0b0d269203e0f40df0907aa9 (patch)
treeeae68479fe1d80f20b84eb3c01a8def30aeee441 /src
parent986edb8bd4308b73ef225a554f13a07c232ead91 (diff)
downloadpacman-09f9f2433173477c0b0d269203e0f40df0907aa9.tar.gz
pacman-09f9f2433173477c0b0d269203e0f40df0907aa9.tar.xz
Allow both cleanmethod values to be specified at the same time
No reason to disallow this- it allows keeping even more packages around in the cache. Test cases included for this case and to ensure the default behavior is preserved. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.h4
-rw-r--r--src/pacman/pacman.c22
-rw-r--r--src/pacman/sync.c76
3 files changed, 54 insertions, 48 deletions
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index ff7a9c79..92c379fc 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -111,8 +111,8 @@ enum {
/* clean method */
enum {
- PM_CLEAN_KEEPINST = 0, /* default */
- PM_CLEAN_KEEPCUR
+ PM_CLEAN_KEEPINST = 1,
+ PM_CLEAN_KEEPCUR = (1 << 1)
};
/* global config variable */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 45500cfb..21d02107 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -792,6 +792,18 @@ static void option_add_syncfirst(const char *name) {
config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
}
+/* helper for being used with setrepeatingoption */
+static void option_add_cleanmethod(const char *value) {
+ if (strcmp(value, "KeepInstalled") == 0) {
+ config->cleanmethod |= PM_CLEAN_KEEPINST;
+ } else if (strcmp(value, "KeepCurrent") == 0) {
+ config->cleanmethod |= PM_CLEAN_KEEPCUR;
+ } else {
+ pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
+ value);
+ }
+}
+
/** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
* settings. Refactored out of the parseconfig code since all of them did
* the exact same thing and duplicated code.
@@ -1008,15 +1020,7 @@ static int _parse_options(char *key, char *value)
alpm_option_set_fetchcb(download_with_xfercommand);
pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", value);
} else if (strcmp(key, "CleanMethod") == 0) {
- if (strcmp(value, "KeepInstalled") == 0) {
- config->cleanmethod = PM_CLEAN_KEEPINST;
- } else if (strcmp(value, "KeepCurrent") == 0) {
- config->cleanmethod = PM_CLEAN_KEEPCUR;
- } else {
- pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"), value);
- return(1);
- }
- pm_printf(PM_LOG_DEBUG, "config: cleanmethod: %s\n", value);
+ setrepeatingoption(value, "CleanMethod", option_add_cleanmethod);
} else {
pm_printf(PM_LOG_ERROR, _("directive '%s' with a value not recognized\n"), key);
return(1);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 2e68c8da..26f6f824 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -151,21 +151,21 @@ static int sync_cleancache(int level)
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;
+ }
+
if(level == 1) {
- switch(config->cleanmethod) {
- case PM_CLEAN_KEEPINST:
- if(!yesno(_("Do you want to remove uninstalled packages from cache?"))) {
- return(0);
- }
- break;
- case PM_CLEAN_KEEPCUR:
- if(!yesno(_("Do you want to remove outdated packages from cache?"))) {
- return(0);
- }
- break;
- default:
- /* this should not happen : the config parsing doesn't set any other value */
- return(1);
+ printf(_("Packages to keep:\n"));
+ if(config->cleanmethod & PM_CLEAN_KEEPINST) {
+ printf(_(" All locally installed packages\n"));
+ }
+ 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 {
@@ -193,6 +193,7 @@ static int sync_cleancache(int level)
char path[PATH_MAX];
int delete = 1;
pmpkg_t *localpkg = NULL, *pkg = NULL;
+ const char *local_name, *local_version;
alpm_list_t *j;
if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
@@ -219,32 +220,33 @@ static int sync_cleancache(int level)
}
continue;
}
- switch(config->cleanmethod) {
- case PM_CLEAN_KEEPINST:
- /* check if this package is in the local DB */
- pkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg));
- if(pkg != NULL && alpm_pkg_vercmp(alpm_pkg_get_version(localpkg),
+ local_name = alpm_pkg_get_name(localpkg);
+ local_version = alpm_pkg_get_version(localpkg);
+
+ if(config->cleanmethod & PM_CLEAN_KEEPINST) {
+ /* check if this package is in the local DB */
+ pkg = alpm_db_get_pkg(db_local, local_name);
+ if(pkg != NULL && alpm_pkg_vercmp(local_version,
+ alpm_pkg_get_version(pkg)) == 0) {
+ /* package was found in local DB and version matches, keep it */
+ pm_printf(PM_LOG_DEBUG, "pkg %s-%s found in local db\n",
+ local_name, local_version);
+ delete = 0;
+ }
+ }
+ if(config->cleanmethod & PM_CLEAN_KEEPCUR) {
+ /* check if this package is in a sync DB */
+ for(j = sync_dbs; j && delete; j = alpm_list_next(j)) {
+ pmdb_t *db = alpm_list_getdata(j);
+ pkg = alpm_db_get_pkg(db, local_name);
+ if(pkg != NULL && alpm_pkg_vercmp(local_version,
alpm_pkg_get_version(pkg)) == 0) {
- /* package was found in local DB and version matches, keep it */
+ /* package was found in a sync DB and version matches, keep it */
+ pm_printf(PM_LOG_DEBUG, "pkg %s-%s found in sync db\n",
+ local_name, local_version);
delete = 0;
}
- break;
- case PM_CLEAN_KEEPCUR:
- /* check if this package is in a sync DB */
- for(j = sync_dbs; j && delete; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
- pkg = alpm_db_get_pkg(db, alpm_pkg_get_name(localpkg));
- if(pkg != NULL && alpm_pkg_vercmp(alpm_pkg_get_version(localpkg),
- alpm_pkg_get_version(pkg)) == 0) {
- /* package was found in a sync DB and version matches, keep it */
- delete = 0;
- }
- }
- break;
- default:
- /* this should not happen : the config parsing doesn't set any other value */
- delete = 0;
- break;
+ }
}
/* free the local file package */
alpm_pkg_free(localpkg);