diff options
author | Dan McGee <dan@archlinux.org> | 2012-01-11 15:39:52 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-01-18 22:10:06 -0600 |
commit | b3612e9cc198f198b3806efa461bf6fc04dd4502 (patch) | |
tree | 85d6018836a02c4ed4cb1211d3ec73d34a2259c9 /src | |
parent | 6e8ca48cbb22c328deab56b1740be04ea7ddba6e (diff) | |
download | pacman-b3612e9cc198f198b3806efa461bf6fc04dd4502.tar.xz |
Allow UseDelta option to specify a delta ratio
Rework the frontend and backend to allow passing a ratio value in for
UseDelta rather than having a hardcoded #define-d 0.7 value always used.
This is useful for those with fast connections, who would likely benefit
from tuning this ratio to lower values; it is also useful for general
testing purposes.
The libalpm API changes for this, but we do support the old config file
format with a no-value 'UseDelta' option; in this case we simply use the
old default of 0.7.
We clamp the ratio values to a sane range between 0.0 and 2.0, allowing
ratios above 1.0 for testing purposes.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/conf.c | 19 | ||||
-rw-r--r-- | src/pacman/conf.h | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 7ba2791c..e1bff189 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -52,6 +52,7 @@ config_t *config_new(void) newconfig->op = PM_OP_MAIN; newconfig->logmask = ALPM_LOG_ERROR | ALPM_LOG_WARNING; newconfig->configfile = strdup(CONFFILE); + newconfig->deltaratio = 0.0; if(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) { newconfig->siglevel = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL | ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; @@ -397,8 +398,8 @@ static int _parse_options(const char *key, char *value, config->verbosepkglists = 1; pm_printf(ALPM_LOG_DEBUG, "config: verbosepkglists\n"); } else if(strcmp(key, "UseDelta") == 0) { - config->usedelta = 1; - pm_printf(ALPM_LOG_DEBUG, "config: usedelta\n"); + config->deltaratio = 0.7; + pm_printf(ALPM_LOG_DEBUG, "config: usedelta (default 0.7)\n"); } else if(strcmp(key, "TotalDownload") == 0) { config->totaldownload = 1; pm_printf(ALPM_LOG_DEBUG, "config: totaldownload\n"); @@ -429,6 +430,18 @@ static int _parse_options(const char *key, char *value, if(!config->arch) { config_set_arch(value); } + } else if(strcmp(key, "UseDelta") == 0) { + double ratio; + char *endptr; + ratio = strtod(value, &endptr); + if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: invalid value for '%s' : '%s'\n"), + file, linenum, "UseDelta", value); + return 1; + } + config->deltaratio = ratio; + pm_printf(ALPM_LOG_DEBUG, "config: usedelta = %f\n", ratio); } else if(strcmp(key, "DBPath") == 0) { /* don't overwrite a path specified on the command line */ if(!config->dbpath) { @@ -605,7 +618,7 @@ static int setup_libalpm(void) alpm_option_set_arch(handle, config->arch); alpm_option_set_checkspace(handle, config->checkspace); alpm_option_set_usesyslog(handle, config->usesyslog); - alpm_option_set_usedelta(handle, config->usedelta); + alpm_option_set_deltaratio(handle, config->deltaratio); alpm_option_set_ignorepkgs(handle, config->ignorepkg); alpm_option_set_ignoregroups(handle, config->ignoregrp); diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 325fbb64..481132fa 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -34,7 +34,7 @@ typedef struct __config_t { unsigned short print; unsigned short checkspace; unsigned short usesyslog; - unsigned short usedelta; + double deltaratio; char *arch; char *print_format; /* unfortunately, we have to keep track of paths both here and in the library |