opkg: add downloading, configuring and installing state changes
[oweals/opkg-lede.git] / opkg_download.c
index 63702508fd99413397a34070a1c63105f83a1822..2bdbb00cae92537c75ca2a5df3ab96b4788c1160 100644 (file)
@@ -42,7 +42,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 +60,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 +172,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 +201,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 +209,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 +224,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;
 }