X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg.c;h=dbb82fbb1c2c4b74045368d9153a1fa054c6c8d3;hp=046b5a096d34cdf1247839efa17bc31c2f335aee;hb=cd113c7ea9d8883d9cdc4c3e4ea4f87531737183;hpb=307864afe92e3b941d66bb334b32979eac2b41ab diff --git a/libopkg/opkg.c b/libopkg/opkg.c index 046b5a0..dbb82fb 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -15,12 +15,14 @@ General Public License for more details. */ -#include +#include "config.h" + +#include +#include #include #include "opkg.h" #include "opkg_conf.h" -#include "args.h" #include "opkg_install.h" #include "opkg_configure.h" @@ -33,8 +35,6 @@ #include -args_t *args; - #define opkg_assert(expr) if (!(expr)) { \ printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\ __FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); } @@ -112,23 +112,33 @@ curl_progress_cb(struct _curl_cb_data *cb_data, double t, /* dltotal */ } +static struct opkg_conf saved_conf; /*** Public API ***/ int opkg_new() { - int err; + saved_conf = *conf; - args = xcalloc(1, sizeof(args_t)); - args_init(args); + if (opkg_conf_init()) + goto err0; - err = opkg_conf_init(args); - if (err) { - free(args); - return -1; - } + if (opkg_conf_load()) + goto err0; + + if (pkg_hash_load_feeds()) + goto err1; + + if (pkg_hash_load_status_files()) + goto err1; return 0; + +err1: + pkg_hash_deinit(); +err0: + opkg_conf_deinit(); + return -1; } void @@ -138,19 +148,14 @@ opkg_free(void) opkg_curl_cleanup(); #endif opkg_conf_deinit(); - args_deinit(args); - free(args); } int opkg_re_read_config_files(void) { - /* Unfortunately, the easiest way to re-read the config files right now is to - * throw away conf and start again */ opkg_free(); - memset(conf, '\0', sizeof(opkg_conf_t)); + *conf = saved_conf; return opkg_new(); - return 0; } void @@ -234,7 +239,7 @@ opkg_set_option(char *option, void *value) /** * @brief libopkg API: Install package * @param package_name The name of package in which is going to install - * @param progress_callback The callback function that report the status to caller. + * @param progress_callback The callback function that report the status to caller. */ int opkg_install_package(const char *package_name, @@ -292,6 +297,7 @@ opkg_install_package(const char *package_name, } free(unresolved); pkg_vec_free(deps); + opkg_message(ERROR, "\n"); return -1; } @@ -336,7 +342,7 @@ opkg_install_package(const char *package_name, err = opkg_download(url, pkg->local_filename, (curl_progress_func) curl_progress_cb, - &cb_data); + &cb_data, 0); free(url); if (err) { @@ -512,6 +518,10 @@ opkg_upgrade_all(opkg_progress_callback_t progress_callback, void *user_data) if (err) return 1; + /* write out status files and file lists */ + opkg_conf_write_status_files(); + pkg_write_changed_filelists(); + pdata.pkg = NULL; progress(pdata, 100); return 0; @@ -582,49 +592,8 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback, src->gzip ? "Packages.gz" : "Packages"); sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name); - if (src->gzip) { - FILE *in, *out; - struct _curl_cb_data cb_data; - char *tmp_file_name = NULL; - sprintf_alloc(&tmp_file_name, "%s/%s.gz", tmp, - src->name); - - opkg_msg(INFO, "Downloading %s to %s...\n", url, - tmp_file_name); - - cb_data.cb = progress_callback; - cb_data.progress_data = &pdata; - cb_data.user_data = user_data; - cb_data.start_range = - 100 * sources_done / sources_list_count; - cb_data.finish_range = - 100 * (sources_done + 1) / sources_list_count; - - err = opkg_download(url, tmp_file_name, - (curl_progress_func) curl_progress_cb, - &cb_data); - - if (err == 0) { - opkg_msg(INFO, "Inflating %s...\n", - tmp_file_name); - in = fopen(tmp_file_name, "r"); - out = fopen(list_file_name, "w"); - if (in && out) - unzip(in, out); - else - err = 1; - if (in) - fclose(in); - if (out) - fclose(out); - unlink(tmp_file_name); - } - free(tmp_file_name); - } else - err = opkg_download(url, list_file_name, NULL, NULL); - - if (err) { + if (opkg_download(url, list_file_name, NULL, NULL, 0)) { opkg_msg(ERROR, "Couldn't retrieve %s\n", url); result = -1; } @@ -649,7 +618,7 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback, /* make sure there is no existing signature file */ unlink(sig_file_name); - err = opkg_download(url, sig_file_name, NULL, NULL); + err = opkg_download(url, sig_file_name, NULL, NULL, 0); if (err) { opkg_msg(ERROR, "Couldn't retrieve %s\n", url); } else { @@ -667,7 +636,6 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback, } } free(sig_file_name); - free(list_file_name); free(url); } #else @@ -675,6 +643,7 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback, " has not been enabled in this build\n", list_file_name); #endif + free(list_file_name); sources_done++; progress(pdata, 100 * sources_done / sources_list_count); @@ -690,6 +659,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) @@ -701,6 +684,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; @@ -728,7 +714,7 @@ opkg_list_upgradable_packages(opkg_package_callback_t callback, void *user_data) head = prepare_upgrade_list(); for (node = active_list_next(head, head); node; - active_list_next(head, node)) { + node = active_list_next(head, node)) { old = list_entry(node, pkg_t, list); new = pkg_hash_fetch_best_installation_candidate_by_name(old->name); if (new == NULL) @@ -743,6 +729,7 @@ pkg_t * opkg_find_package(const char *name, const char *ver, const char *arch, const char *repo) { + int pkg_found = 0; pkg_t *pkg = NULL; pkg_vec_t *all; int i; @@ -780,20 +767,18 @@ opkg_find_package(const char *name, const char *ver, const char *arch, } /* match found */ + pkg_found = 1; break; } pkg_vec_free(all); - return pkg; + return pkg_found ? pkg : NULL; } -#ifdef HAVE_CURL -#include -#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. - * @return return how many repositories cannot access. 0 means all okay. + * @brief Check the accessibility of repositories. + * @return return how many repositories cannot access. 0 means all okay. */ int opkg_repository_accessibility_check(void) @@ -803,7 +788,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; @@ -834,24 +818,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, 0)) ret++; - } str_list_elt_deinit(iter1); } + free(src); + return ret; }