From 1371aac8280c8281d7b79926fc7b8d8e38cda3ab Mon Sep 17 00:00:00 2001 From: forever2k38 Date: Sun, 6 Sep 2026 22:35:45 +0200 Subject: feat: initial builds! --- src/download.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/download.c') 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; +} -- cgit v1.3