summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2020-03-08 21:33:32 +0100
committerAllan McRae <allan@archlinux.org>2020-05-09 03:58:21 +0200
commitfe8e13341bdeae4a59c0270a632c29e71ae9deda (patch)
tree2e40d6b786ec2fe8bd5b878d09f2fa627c0190a8 /src
parentcffda331adca0aedd7c1fc17d739c27fc8041a20 (diff)
downloadpacman-fe8e13341bdeae4a59c0270a632c29e71ae9deda.tar.gz
pacman-fe8e13341bdeae4a59c0270a632c29e71ae9deda.tar.xz
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 <anatol.pomozov@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.c56
-rw-r--r--src/pacman/conf.h2
2 files changed, 58 insertions, 0 deletions
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;