opkg: disable gpgme header if gpgme disabled from configure
[oweals/opkg-lede.git] / opkg_download.c
index 63702508fd99413397a34070a1c63105f83a1822..2c2bc57422550bd21c8fa00c7bfc97957662f04f 100644 (file)
 */
 
 #include <curl/curl.h>
+#ifdef HAVE_GPGME
 #include <gpgme.h>
+#endif
 
 #include "opkg.h"
 #include "opkg_download.h"
 #include "opkg_message.h"
+#include "opkg_state.h"
 
 #include "sprintf_alloc.h"
 #include "xsystem.h"
@@ -42,7 +45,7 @@ curl_progress_func (char* url,
                    double ulnow)
 {
     int i;
-    int p = d*100/t;
+    int p = (t) ? d*100/t : 0;
 
 #ifdef OPKG_LIB
     if (opkg_cb_download_progress)
@@ -60,6 +63,12 @@ curl_progress_func (char* url,
     }
 #endif
 
+    /* skip progress bar if we haven't done started yet
+     * this prevents drawing the progress bar if we receive an error such as
+     * file not found */
+    if (t == 0)
+       return 0;
+
     printf ("\r%3d%% |", p);
     for (i = 1; i < 73; i++)
     {
@@ -166,7 +175,12 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
        curl_easy_cleanup (curl);
        fclose (file);
        if (res)
+       {
+           long error_code;
+           curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
+           opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, error_code);
            return res;
+       }
 
     }
     else
@@ -190,6 +204,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
 {
     int err;
     char *url;
+    char *pkgid;
 
     if (pkg->src == NULL) {
        opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
@@ -197,6 +212,10 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
        return -1;
     }
 
+    sprintf_alloc (&pkgid, "%s;%s;%s;", pkg->name, pkg->version, pkg->architecture);
+    opkg_set_current_state (OPKG_STATE_DOWNLOADING_PKG, pkgid);
+    free (pkgid);
+
     sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
 
     /* XXX: BUG: The pkg->filename might be something like
@@ -208,6 +227,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
     err = opkg_download(conf, url, pkg->local_filename);
     free(url);
 
+    opkg_set_current_state (OPKG_STATE_NONE, NULL);
     return err;
 }
 
@@ -279,6 +299,7 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
 int
 opkg_verify_file (char *text_file, char *sig_file)
 {
+#ifdef HAVE_GPGME
     int status = -1;
     gpgme_ctx_t ctx;
     gpgme_data_t sig, text;
@@ -318,4 +339,8 @@ opkg_verify_file (char *text_file, char *sig_file)
     gpgme_release (ctx);
 
     return status;
+#else
+    printf ("Signature check skipped because GPG support was not enabled in this build\n");
+    return 0;
+#endif
 }