aboutsummaryrefslogtreecommitdiff
path: root/src/download.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/download.c')
-rw-r--r--src/download.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/download.c b/src/download.c
index bb8365c..351a36b 100644
--- a/src/download.c
+++ b/src/download.c
@@ -1,5 +1,9 @@
+#include "package.h"
+
#include "curl/curl.h"
#include "stdio.h"
+#include "stdlib.h"
+#include "string.h"
static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream) {
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
@@ -11,6 +15,9 @@ int pow_download_file(char *path, char *url) {
FILE *pagefile;
CURL *curl = curl_easy_init();
+ printf("%s", path);
+ printf("%s", url);
+
if (!curl) {
printf("failed to init curl\n");
@@ -18,13 +25,16 @@ int pow_download_file(char *path, char *url) {
}
curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
pagefile = fopen(path, "wb");
if (!pagefile) {
+ printf("failed to open file to download\n");
+
curl_easy_cleanup(curl);
return 1;
@@ -32,9 +42,22 @@ int pow_download_file(char *path, char *url) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, pagefile);
- int result = curl_easy_perform(curl);
+ CURLcode result = curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
fclose(pagefile);
return result;
}
+
+int pow_download_source(pow_package_source *src, const char *prefix) {
+ size_t len = strlen(prefix) + strlen(src->out) + 2;
+ char *full_path = malloc(len);
+
+ snprintf(full_path, len, "%s/%s", prefix, src->out);
+
+ pow_download_file(full_path, src->in);
+
+ return 0;
+}