libopkg: clarify messages and errors related to downloads
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index a1b83416bffde9382e78c5be66ee071226d57269..3f86462b9a7729b8d00c9bea38d5d633dac2a3ad 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "config.h"
 
+#include <sys/wait.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <libgen.h>
@@ -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;
@@ -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;
       }
@@ -227,7 +230,7 @@ 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);
+           err = opkg_download(src, cache_location, cb, data, 0);
            if (err) {
               (void) unlink(cache_location);
               goto out2;
@@ -334,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;
 }
@@ -342,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;