X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg.c;h=dbb82fbb1c2c4b74045368d9153a1fa054c6c8d3;hp=87c3244f2652849ba0041bdb4284cd38fcb24472;hb=cd113c7ea9d8883d9cdc4c3e4ea4f87531737183;hpb=0a4946b3e913a2affe5fd342aa88e2533d06356e diff --git a/libopkg/opkg.c b/libopkg/opkg.c index 87c3244..dbb82fb 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -112,14 +112,20 @@ curl_progress_cb(struct _curl_cb_data *cb_data, double t, /* dltotal */ } +static struct opkg_conf saved_conf; /*** Public API ***/ int opkg_new() { + saved_conf = *conf; + if (opkg_conf_init()) goto err0; + if (opkg_conf_load()) + goto err0; + if (pkg_hash_load_feeds()) goto err1; @@ -147,20 +153,9 @@ opkg_free(void) int opkg_re_read_config_files(void) { - pkg_hash_deinit(); - pkg_hash_init(); - - if (pkg_hash_load_feeds()) - goto err; - - if (pkg_hash_load_status_files()) - goto err; - - return 0; - -err: - pkg_hash_deinit(); - return -1; + opkg_free(); + *conf = saved_conf; + return opkg_new(); } void @@ -347,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) { @@ -597,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; } @@ -664,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 { @@ -682,7 +636,6 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback, } } free(sig_file_name); - free(list_file_name); free(url); } #else @@ -690,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); @@ -775,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; @@ -812,12 +767,13 @@ 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; } /** @@ -867,7 +823,7 @@ opkg_repository_accessibility_check(void) iter1 = str_list_pop(src); repositories--; - if (opkg_download(iter1->data, "/dev/null", NULL, NULL)) + if (opkg_download(iter1->data, "/dev/null", NULL, NULL, 0)) ret++; str_list_elt_deinit(iter1); }