diff options
Diffstat (limited to 'snag/src/download_db.c')
| -rw-r--r-- | snag/src/download_db.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/snag/src/download_db.c b/snag/src/download_db.c index 6261627..c1e2e1b 100644 --- a/snag/src/download_db.c +++ b/snag/src/download_db.c @@ -9,7 +9,7 @@ #include <errno.h> // note: fixed location of download database for now -const char download_db_path[] = "../downloads"; +const char download_db_path[] = "./var/snag/downloads"; // libcrpyto context EVP_MD_CTX *mdctx = NULL; @@ -18,7 +18,7 @@ const EVP_MD *md = NULL; // curl context CURL *curl = NULL; -static size_t curl_write_cb(char* ptr, size_t size, size_t nmemb, void* usrdata) +static size_t download_write_callback(char* ptr, size_t size, size_t nmemb, void* usrdata) { // write the curl data to the file in usr data size_t written = fwrite(ptr, size, nmemb, (FILE *)usrdata); @@ -56,6 +56,9 @@ bool download_package(package_info_t* pkg) { EVP_DigestInit_ex(mdctx, md, NULL); // open file for writing + // note(jqj): extension is fixed to tar gz until the switch out download + // attrs for the swenu api download command which will specify + // more information char* download_path = vastrcat(download_db_path, "/", pkg->attrs.id, "-", pkg->attrs.version, ".tar.gz"); FILE* download_file = fopen(download_path, "wb"); if (download_file == NULL) die("failed open download file for writing (%s): %s", download_path, strerror(errno)); @@ -64,10 +67,11 @@ bool download_package(package_info_t* pkg) { // callback writes to the file and feeds the hash curl_easy_setopt(curl, CURLOPT_URL, pkg->attrs.source_url); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_cb); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, download_file); CURLcode result = curl_easy_perform(curl); if(result != CURLE_OK) { + // todo(jqj): handle better, maybe try again print("failed to download package with curl: %s", curl_easy_strerror(result)); return false; } |
