mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 01:41:52 -05:00
Add new CleanMethod option.
As it was already mentioned several times, the new -Sc behavior in 3.1 is great, but only when the package cache is not shared. This option has two possible values : KeepInstalled and KeepCurrent With KeepCurrent, -Sc will clean packages that are no longer available in any sync db, rather than packages that are no longer in the local db. The resulting behavior should be better for shared cache. Ref : http://www.archlinux.org/pipermail/pacman-dev/2008-February/011140.html Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
5af076f09f
commit
3d10d460df
@ -244,6 +244,9 @@ Sync Options[[SO]]
|
|||||||
packages that are no longer installed; use two to remove all packages
|
packages that are no longer installed; use two to remove all packages
|
||||||
from the cache. In both cases, you will have a yes or no option to
|
from the cache. In both cases, you will have a yes or no option to
|
||||||
remove packages and/or unused downloaded databases.
|
remove packages and/or unused downloaded databases.
|
||||||
|
+
|
||||||
|
If you use a network shared cache, see the 'CleanMethod' option in
|
||||||
|
linkman:pacman.conf[5].
|
||||||
|
|
||||||
*-g, \--groups*::
|
*-g, \--groups*::
|
||||||
Display all the members for each package group specified. If no group
|
Display all the members for each package group specified. If no group
|
||||||
|
@ -119,6 +119,15 @@ Options
|
|||||||
These files refer to files in the package archive, so do not include the
|
These files refer to files in the package archive, so do not include the
|
||||||
leading slash (the RootDir) when specifying them.
|
leading slash (the RootDir) when specifying them.
|
||||||
|
|
||||||
|
*CleanMethod =* KeepInstalled | KeepCurrent::
|
||||||
|
If set to `KeepInstalled` (the default), the '-Sc' operation will clean
|
||||||
|
packages that are no longer installed (not present in the local database).
|
||||||
|
If set to `KeepCurrent`, '-Sc' will clean outdated packages (not present in
|
||||||
|
any sync database).
|
||||||
|
The second behavior is useful when the package cache is shared among
|
||||||
|
multiple machines, where the local databases are usually different, but the
|
||||||
|
sync databases in use could be the same.
|
||||||
|
|
||||||
*UseSyslog*::
|
*UseSyslog*::
|
||||||
Log action messages through syslog(). This will insert log entries into
|
Log action messages through syslog(). This will insert log entries into
|
||||||
``/var/log/messages'' or equivalent.
|
``/var/log/messages'' or equivalent.
|
||||||
|
@ -65,9 +65,10 @@ typedef struct __config_t {
|
|||||||
unsigned short chomp; /* I Love Candy! */
|
unsigned short chomp; /* I Love Candy! */
|
||||||
unsigned short usecolor; /* enable colorful output */
|
unsigned short usecolor; /* enable colorful output */
|
||||||
unsigned short showsize; /* show individual package sizes */
|
unsigned short showsize; /* show individual package sizes */
|
||||||
unsigned short totaldownload; /* When downloading, display the amount
|
/* When downloading, display the amount downloaded, rate, ETA, and percent
|
||||||
downloaded, rate, ETA, and percent
|
* downloaded of the total download list */
|
||||||
downloaded of the total download list */
|
unsigned short totaldownload;
|
||||||
|
unsigned short cleanmethod; /* select -Sc behavior */
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
/* Operations */
|
/* Operations */
|
||||||
@ -80,6 +81,12 @@ enum {
|
|||||||
PM_OP_DEPTEST
|
PM_OP_DEPTEST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* clean method */
|
||||||
|
enum {
|
||||||
|
PM_CLEAN_KEEPINST = 0, /* default */
|
||||||
|
PM_CLEAN_KEEPCUR
|
||||||
|
};
|
||||||
|
|
||||||
/* global config variable */
|
/* global config variable */
|
||||||
extern config_t *config;
|
extern config_t *config;
|
||||||
|
|
||||||
|
@ -692,6 +692,16 @@ static int _parseconfig(const char *file, const char *givensection,
|
|||||||
} else if (strcmp(key, "XferCommand") == 0) {
|
} else if (strcmp(key, "XferCommand") == 0) {
|
||||||
alpm_option_set_xfercommand(ptr);
|
alpm_option_set_xfercommand(ptr);
|
||||||
pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", ptr);
|
pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", ptr);
|
||||||
|
} else if (strcmp(key, "CleanMethod") == 0) {
|
||||||
|
if (strcmp(ptr, "KeepInstalled") == 0) {
|
||||||
|
config->cleanmethod = PM_CLEAN_KEEPINST;
|
||||||
|
} else if (strcmp(ptr, "KeepCurrent") == 0) {
|
||||||
|
config->cleanmethod = PM_CLEAN_KEEPCUR;
|
||||||
|
} else {
|
||||||
|
pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"), ptr);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
pm_printf(PM_LOG_DEBUG, "config: cleanmethod: %s\n", ptr);
|
||||||
} else {
|
} else {
|
||||||
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"),
|
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"),
|
||||||
file, linenum, key);
|
file, linenum, key);
|
||||||
|
@ -133,13 +133,23 @@ static int sync_cleancache(int level)
|
|||||||
/* incomplete cleanup */
|
/* incomplete cleanup */
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
/* Let's vastly improve the way this is done. Before, we went by package
|
/* Open up each package and see if it should be deleted,
|
||||||
* name. Instead, let's only keep packages we have installed. Open up each
|
* depending on the clean method used */
|
||||||
* package and see if it has an entry in the local DB; if not, delete it.
|
|
||||||
*/
|
|
||||||
printf(_("Cache directory: %s\n"), cachedir);
|
printf(_("Cache directory: %s\n"), cachedir);
|
||||||
if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) {
|
switch(config->cleanmethod) {
|
||||||
return(0);
|
case PM_CLEAN_KEEPINST:
|
||||||
|
if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PM_CLEAN_KEEPCUR:
|
||||||
|
if(!yesno(1, _("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(_("removing old packages from cache... "));
|
printf(_("removing old packages from cache... "));
|
||||||
|
|
||||||
@ -153,13 +163,16 @@ static int sync_cleancache(int level)
|
|||||||
/* step through the directory one file at a time */
|
/* step through the directory one file at a time */
|
||||||
while((ent = readdir(dir)) != NULL) {
|
while((ent = readdir(dir)) != NULL) {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
pmpkg_t *localpkg = NULL, *dbpkg = NULL;
|
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, "..")) {
|
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* build the full filepath */
|
/* build the full filepath */
|
||||||
snprintf(path, PATH_MAX, "%s/%s", cachedir, ent->d_name);
|
snprintf(path, PATH_MAX, "%s%s", cachedir, ent->d_name);
|
||||||
|
|
||||||
/* attempt to load the package, skip file on failures as we may have
|
/* attempt to load the package, skip file on failures as we may have
|
||||||
* files here that aren't valid packages. we also don't need a full
|
* files here that aren't valid packages. we also don't need a full
|
||||||
@ -167,19 +180,39 @@ static int sync_cleancache(int level)
|
|||||||
if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) {
|
if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* check if this package is in the local DB */
|
switch(config->cleanmethod) {
|
||||||
dbpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg));
|
case PM_CLEAN_KEEPINST:
|
||||||
if(dbpkg == NULL) {
|
/* check if this package is in the local DB */
|
||||||
/* delete package, not present in local DB */
|
pkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg));
|
||||||
unlink(path);
|
if(pkg != NULL && alpm_pkg_vercmp(alpm_pkg_get_version(localpkg),
|
||||||
} else if(alpm_pkg_vercmp(alpm_pkg_get_version(localpkg),
|
alpm_pkg_get_version(pkg)) == 0) {
|
||||||
alpm_pkg_get_version(dbpkg)) != 0) {
|
/* package was found in local DB and version matches, keep it */
|
||||||
/* delete package, it was found but version differs */
|
delete = 0;
|
||||||
unlink(path);
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
/* else version was the same, so keep the package */
|
|
||||||
/* free the local file package */
|
/* free the local file package */
|
||||||
alpm_pkg_free(localpkg);
|
alpm_pkg_free(localpkg);
|
||||||
|
|
||||||
|
if(delete) {
|
||||||
|
unlink(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf(_("done.\n"));
|
printf(_("done.\n"));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user