index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Anatol Pomozov <anatol.pomozov@gmail.com> | 2020-03-08 13:33:32 -0700 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2020-05-09 11:58:21 +1000 |
commit | fe8e13341bdeae4a59c0270a632c29e71ae9deda (patch) | |
tree | 2e40d6b786ec2fe8bd5b878d09f2fa627c0190a8 /src | |
parent | cffda331adca0aedd7c1fc17d739c27fc8041a20 (diff) |
-rw-r--r-- | src/pacman/conf.c | 56 | ||||
-rw-r--r-- | src/pacman/conf.h | 2 |
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 = ""; @@ -405,6 +407,32 @@ int config_set_arch(const char *arch) } /** + * 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 * @param storage location to store the derived signature level; any existing @@ -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; |