From e207f7382cf23dcf88700dead255a41c817a0863 Mon Sep 17 00:00:00 2001 From: Jack Jamison Date: Thu, 23 Jul 2026 11:45:52 -0400 Subject: clean up downloading and configure script --- snag/src/download_db.c | 10 +++++++--- snag/src/package_db.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'snag/src') 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 // 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; } diff --git a/snag/src/package_db.c b/snag/src/package_db.c index 3974120..04705e4 100644 --- a/snag/src/package_db.c +++ b/snag/src/package_db.c @@ -12,7 +12,7 @@ #define PKG_INST_CMD "./scripts/run_pkg_install.sh" // note: fixed location of package database for now -const char pkg_db[] = "../packages"; +const char pkg_db[] = "./var/snag/packages"; const size_t pkg_db_len = sizeof(pkg_db) - 1; bool load_package_info(char* pkgid, package_info_t* info) { -- cgit v1.2.3