diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-07-15 10:07:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 10:07:25 -0400 |
commit | 07dc44efdc5c2fbc2b34c969e623d3b0bc0df15a (patch) | |
tree | 1f41c27e50baeee149b59b8c3d37a9c72cbd0ded /src/download.c | |
parent | 70cd78cdef69237ba3c511b9e091715ec6d093e5 (diff) | |
download | stasis-07dc44efdc5c2fbc2b34c969e623d3b0bc0df15a.tar.gz |
Unit tests (#12)
* Change return value of conda_setup_headless() from void to int
* Replace exit() with return;
* Return early if unpacking the micromamba binary fails
* Exit program when pointer to INIFILE is NULL.
* Validation function cannot otherwise proceed
* The way the logic is set up I've decided to duplicate the installation code for now until I find time to revise it
* The only meaningful difference between a "fresh start" and reusing the conda installation is a rmtree().
* Exposes STASIS_DOWNLOAD_TIMEOUT environment variable
* Sets the connection timeout for libcurl to 30, instead of 300.
* Export ini_section_create() function
* Add download() tests
* Add conda_*() tests
* Add boilerplate source file for test framework
* Fixes segfault reported by @GeorgeJCleary (#10)
* The key is now an array index. When key is -1, the env variable is not defined.
* Free resources only when continue on error is disabled (#11)
* Fix segfault due to premature shutdown/cleanup
* If conda_setup_headless cannot succeed, die
* Set STASIS_SYSCONFDIR for tests
Diffstat (limited to 'src/download.c')
-rw-r--r-- | src/download.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/download.c b/src/download.c index 1623560..f83adda 100644 --- a/src/download.c +++ b/src/download.c @@ -3,6 +3,7 @@ // #include <string.h> +#include <stdlib.h> #include "download.h" size_t download_writer(void *fp, size_t size, size_t nmemb, void *stream) { @@ -18,6 +19,8 @@ long download(char *url, const char *filename, char **errmsg) { FILE *fp; char user_agent[20]; sprintf(user_agent, "stasis/%s", VERSION); + long timeout = 30L; + char *timeout_str = getenv("STASIS_DOWNLOAD_TIMEOUT"); curl_global_init(CURL_GLOBAL_ALL); c = curl_easy_init(); @@ -27,11 +30,18 @@ long download(char *url, const char *filename, char **errmsg) { if (!fp) { return -1; } + curl_easy_setopt(c, CURLOPT_VERBOSE, 0L); curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(c, CURLOPT_USERAGENT, user_agent); curl_easy_setopt(c, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(c, CURLOPT_WRITEDATA, fp); + + if (timeout_str) { + timeout = strtol(timeout_str, NULL, 10); + } + curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, timeout); + curl_code = curl_easy_perform(c); if (curl_code != CURLE_OK) { if (errmsg) { |