X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_download.c;h=3f86462b9a7729b8d00c9bea38d5d633dac2a3ad;hp=16502d1b91634322f736e0f274ab54b8520402da;hb=a79c1af5c0d3908a3ad30806530c754b42cf80e2;hpb=a28f22ee5c9f868c733572048bbbb1217957507b diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 16502d1..3f86462 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -19,6 +19,7 @@ #include "config.h" +#include #include #include #include @@ -82,7 +83,7 @@ str_starts_with(const char *str, const char *prefix) int opkg_download(const char *src, const char *dest_file_name, - curl_progress_func cb, void *data) + curl_progress_func cb, void *data, const short hide_error) { int err = 0; @@ -90,7 +91,7 @@ opkg_download(const char *src, const char *dest_file_name, char *src_base = basename(src_basec); char *tmp_file_location; - opkg_msg(NOTICE,"Downloading %s.\n", src); + opkg_msg(NOTICE,"Downloading %s\n", src); if (str_starts_with(src, "file:")) { const char *file_src = src + 5; @@ -142,7 +143,7 @@ opkg_download(const char *src, const char *dest_file_name, { long error_code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code); - opkg_msg(ERROR, "Failed to download %s: %s.\n", + opkg_msg(hide_error?DEBUG2:ERROR, "Failed to download %s: %s.\n", src, curl_easy_strerror(res)); free(tmp_file_location); return -1; @@ -174,6 +175,8 @@ opkg_download(const char *src, const char *dest_file_name, if (res) { opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res); + if (res == 4) + opkg_msg(ERROR, "Check your network settings and connectivity.\n\n"); free(tmp_file_location); return -1; } @@ -196,7 +199,7 @@ opkg_download_cache(const char *src, const char *dest_file_name, int err = 0; if (!conf->cache || str_starts_with(src, "file:")) { - err = opkg_download(src, dest_file_name, cb, data); + err = opkg_download(src, dest_file_name, cb, data, 0); goto out1; } @@ -215,10 +218,23 @@ opkg_download_cache(const char *src, const char *dest_file_name, if (file_exists(cache_location)) opkg_msg(NOTICE, "Copying %s.\n", cache_location); else { - err = opkg_download(src, cache_location, cb, data); - if (err) { - (void) unlink(cache_location); - goto out2; + /* cache file with funky name not found, try simple name */ + free(cache_name); + char *filename = strrchr(dest_file_name,'/'); + if (filename) + cache_name = xstrdup(filename+1); // strip leading '/' + else + cache_name = xstrdup(dest_file_name); + free(cache_location); + sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); + if (file_exists(cache_location)) + opkg_msg(NOTICE, "Copying %s.\n", cache_location); + else { + err = opkg_download(src, cache_location, cb, data, 0); + if (err) { + (void) unlink(cache_location); + goto out2; + } } } @@ -287,7 +303,7 @@ opkg_prepare_url_for_install(const char *url, char **namep) char *file_base = basename(file_basec); sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base); - err = opkg_download(url, tmp_file, NULL, NULL); + err = opkg_download(url, tmp_file, NULL, NULL, 0); if (err) return err; @@ -321,7 +337,7 @@ opkg_prepare_url_for_install(const char *url, char **namep) hash_insert_pkg(pkg, 1); if (namep) { - *namep = pkg->name; + *namep = xstrdup(pkg->name); } return 0; } @@ -329,7 +345,28 @@ opkg_prepare_url_for_install(const char *url, char **namep) int opkg_verify_file (char *text_file, char *sig_file) { -#if defined HAVE_GPGME +#if defined HAVE_USIGN + int status = -1; + int pid; + + if (conf->check_signature == 0 ) + return 0; + + pid = fork(); + if (pid < 0) + return -1; + + if (!pid) { + execl("/usr/sbin/opkg-key", "opkg-key", "verify", sig_file, text_file, NULL); + exit(255); + } + + waitpid(pid, &status, 0); + if (!WIFEXITED(status) || WEXITSTATUS(status)) + return -1; + + return 0; +#elif defined HAVE_GPGME if (conf->check_signature == 0 ) return 0; int status = -1;