#include "download.h" #include "lib/logging/logging.h" #include #include bool download_file(const char *url, const char *dest) { CURL *curl = curl_easy_init(); if (curl) { FILE *fp = fopen(dest, "wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nullptr); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); auto res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); if (res == CURLE_OK) { LOG(md, bts::Info, "download_file result: {}. url: {} dest: {}", true, std::string(url), std::string(dest)); return true; } remove(dest); } LOG(md, bts::Info, "download_file result: {}. url: {} dest: {}", false, std::string(url), std::string(dest)); return false; }