From fe8e13341bdeae4a59c0270a632c29e71ae9deda Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Sun, 8 Mar 2020 13:33:32 -0700 Subject: Add config option to specify amount of parallel download streams It includes pacman.conf new 'ParallelDownloads' option that specifies how many concurrent downloads cURL starts in parallel. Add alpm_option_set_parallel_downloads() ALPM function that allows to set this config option programmatically. Signed-off-by: Anatol Pomozov Signed-off-by: Allan McRae --- src/pacman/conf.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/conf.h | 2 ++ 2 files changed, 58 insertions(+) (limited to 'src') diff --git a/src/pacman/conf.c b/src/pacman/conf.c index becbd03e..7390d741 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -114,6 +114,8 @@ config_t *config_new(void) newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT; } + /* by default use 1 download stream */ + newconfig->parallel_downloads = 1; newconfig->colstr.colon = ":: "; newconfig->colstr.title = ""; newconfig->colstr.repo = ""; @@ -404,6 +406,32 @@ int config_set_arch(const char *arch) return 0; } +/** + * Parse a string into long number. The input string has to be non-empty + * and represent a number that fits long type. + * @param value the string to parse + * @param result pointer to long where the final result will be stored. + * This result is modified if the input string parsed successfully. + * @return 0 in case if value parsed successfully, 1 otherwise. + */ +static int parse_number(char *value, long *result) { + char *endptr; + long val; + int invalid; + + errno = 0; /* To distinguish success/failure after call */ + val = strtol(value, &endptr, 10); + invalid = (errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) + || (*endptr != '\0') + || (endptr == value); + + if(!invalid) { + *result = val; + } + + return invalid; +} + /** * Parse a signature verification level line. * @param values the list of parsed option values @@ -683,6 +711,33 @@ static int _parse_options(const char *key, char *value, return 1; } FREELIST(values); + } else if(strcmp(key, "ParallelDownloads") == 0) { + long number; + int err; + + err = parse_number(value, &number); + if(err) { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: invalid value for '%s' : '%s'\n"), + file, linenum, "ParallelDownloads", value); + return 1; + } + + if(number < 1) { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: value for '%s' has to be positive : '%s'\n"), + file, linenum, "ParallelDownloads", value); + return 1; + } + + if(number > INT_MAX) { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: value for '%s' is too large : '%s'\n"), + file, linenum, "ParallelDownloads", value); + return 1; + } + + config->parallel_downloads = number; } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -851,6 +906,7 @@ static int setup_libalpm(void) alpm_option_set_noextracts(handle, config->noextract); alpm_option_set_disable_dl_timeout(handle, config->disable_dl_timeout); + alpm_option_set_parallel_downloads(handle, config->parallel_downloads); for(i = config->assumeinstalled; i; i = i->next) { char *entry = i->data; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index e1df24b7..b8a451ad 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -116,6 +116,8 @@ typedef struct __config_t { /* When downloading, display the amount downloaded, rate, ETA, and percent * downloaded of the total download list */ unsigned short totaldownload; + /* number of parallel download streams */ + unsigned int parallel_downloads; /* select -Sc behavior */ unsigned short cleanmethod; alpm_list_t *holdpkg; -- cgit v1.2.3-54-g00ecf