Return negative error code from opkg_download(), not curl error codes.
[oweals/opkg-lede.git] / libopkg / opkg.c
index 383dfb5893d9b31a4d8dd33b6274946584fc896a..fdb2fe38284170f19277f5af6a6523719db77bf7 100644 (file)
    General Public License for more details.
  */
 
-#include <config.h>
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
 #include <fnmatch.h>
 
 #include "opkg.h"
 #include "opkg_conf.h"
-#include "args.h"
 
 #include "opkg_install.h"
 #include "opkg_configure.h"
@@ -115,15 +117,9 @@ curl_progress_cb(struct _curl_cb_data *cb_data, double t,  /* dltotal */
 int
 opkg_new()
 {
-       args_t args;
-
-       args_init(&args);
-
-       if (opkg_conf_init(&args))
+       if (opkg_conf_init())
                goto err0;
 
-       args_deinit(&args);
-
        if (pkg_hash_load_feeds())
                goto err1;
 
@@ -306,6 +302,7 @@ opkg_install_package(const char *package_name,
                }
                free(unresolved);
                pkg_vec_free(deps);
+               opkg_message(ERROR, "\n");
                return -1;
        }
 
@@ -704,6 +701,20 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback,
        return result;
 }
 
+static int
+pkg_compare_names_and_version(const void *a0, const void *b0)
+{
+       const pkg_t *a = *(const pkg_t **)a0;
+       const pkg_t *b = *(const pkg_t **)b0;
+       int ret;
+
+       ret = strcmp(a->name, b->name);
+
+       if (ret == 0)
+               ret = pkg_compare_versions(a, b);
+
+       return ret;
+}
 
 int
 opkg_list_packages(opkg_package_callback_t callback, void *user_data)
@@ -715,6 +726,9 @@ opkg_list_packages(opkg_package_callback_t callback, void *user_data)
 
        all = pkg_vec_alloc();
        pkg_hash_fetch_available(all);
+
+       pkg_vec_sort(all, pkg_compare_names_and_version);
+
        for (i = 0; i < all->len; i++) {
                pkg_t *pkg;
 
@@ -802,11 +816,8 @@ opkg_find_package(const char *name, const char *ver, const char *arch,
        return pkg;
 }
 
-#ifdef HAVE_CURL
-#include <curl/curl.h>
-#endif
 /**
- * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status. 
+ * @brief Check the accessibility of repositories.
  * @return return how many repositories cannot access. 0 means all okay. 
  */
 int
@@ -817,7 +828,6 @@ opkg_repository_accessibility_check(void)
        str_list_t *src;
        int repositories = 0;
        int ret = 0;
-       int err;
        char *repo_ptr;
        char *stmp;
        char *host, *end;
@@ -848,24 +858,17 @@ opkg_repository_accessibility_check(void)
                free(repo_ptr);
                repositories++;
        }
+
        while (repositories > 0) {
                iter1 = str_list_pop(src);
                repositories--;
 
-               err = opkg_download(iter1->data, "/dev/null", NULL, NULL);
-#ifdef HAVE_CURL
-               if (!(err == CURLE_OK ||
-                     err == CURLE_HTTP_RETURNED_ERROR ||
-                     err == CURLE_FILE_COULDNT_READ_FILE ||
-                     err == CURLE_REMOTE_FILE_NOT_FOUND ||
-                     err == CURLE_TFTP_NOTFOUND)) {
-#else
-               if (!(err == 0)) {
-#endif
+               if (opkg_download(iter1->data, "/dev/null", NULL, NULL))
                        ret++;
-               }
                str_list_elt_deinit(iter1);
        }
+
        free(src);
+
        return ret;
 }