libopkg: remove unused progress parameters from opkg_download()
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index d03e27c0e7a18b9f71da9a85e9712f99b6a86bbd..7d5bd04a8d45f06c7f3a9ee064eb24581249c755 100644 (file)
@@ -15,8 +15,6 @@
    General Public License for more details.
 */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <dirent.h>
 #include <glob.h>
 static void print_pkg(pkg_t * pkg)
 {
        char *version = pkg_version_str_alloc(pkg);
+       char *description = pkg_get_string(pkg, PKG_DESCRIPTION);
        printf("%s - %s", pkg->name, version);
        if (conf->size)
-               printf(" - %lu", pkg->size);
-       if (pkg->description)
-               printf(" - %s", pkg->description);
+               printf(" - %lu", (unsigned long) pkg_get_int(pkg, PKG_SIZE));
+       if (description)
+               printf(" - %s", description);
        printf("\n");
        free(version);
 }
@@ -131,7 +130,7 @@ static int opkg_update_cmd(int argc, char **argv)
 
                sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
                pkglist_dl_error = 0;
-               if (opkg_download(url, list_file_name, NULL, NULL, 0)) {
+               if (opkg_download(url, list_file_name, 0)) {
                        failures++;
                        pkglist_dl_error = 1;
                        opkg_msg(NOTICE,
@@ -143,7 +142,7 @@ static int opkg_update_cmd(int argc, char **argv)
                                 list_file_name);
                }
                free(url);
-#if defined(HAVE_GPGME) || defined(HAVE_OPENSSL) || defined(HAVE_USIGN)
+#if defined(HAVE_USIGN)
                if (pkglist_dl_error == 0 && conf->check_signature) {
                        /* download detached signitures to verify the package lists */
                        /* get the url for the sig file */
@@ -161,7 +160,7 @@ static int opkg_update_cmd(int argc, char **argv)
                        sprintf_alloc(&tmp_file_name, "%s/%s.sig", lists_dir,
                                      src->name);
 
-                       err = opkg_download(url, tmp_file_name, NULL, NULL, 0);
+                       err = opkg_download(url, tmp_file_name, 0);
                        if (err) {
                                failures++;
                                opkg_msg(NOTICE,
@@ -215,13 +214,19 @@ static opkg_intercept_t opkg_prep_intercepts(void)
 
        ctx = xcalloc(1, sizeof(*ctx));
        ctx->oldpath = xstrdup(getenv("PATH"));
-       sprintf_alloc(&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
+
+       sprintf_alloc(&newpath, "%s/opkg/intercept:%s", DATADIR,
+                     ctx->oldpath ? ctx->oldpath : PATH_SPEC);
+
        sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX",
-                     conf->tmp_dir);
+                     conf->tmp_dir);
 
        if (mkdtemp(ctx->statedir) == NULL) {
                opkg_perror(ERROR, "Failed to make temp dir %s", ctx->statedir);
-               free(ctx->oldpath);
+
+               if (ctx->oldpath)
+                       free(ctx->oldpath);
+
                free(ctx->statedir);
                free(newpath);
                free(ctx);
@@ -240,8 +245,13 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
        DIR *dir;
        int err = 0;
 
-       setenv("PATH", ctx->oldpath, 1);
-       free(ctx->oldpath);
+       if (ctx->oldpath) {
+               setenv("PATH", ctx->oldpath, 1);
+               free(ctx->oldpath);
+       }
+       else {
+               unsetenv("PATH");
+       }
 
        dir = opendir(ctx->statedir);
        if (dir) {
@@ -255,7 +265,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
                        sprintf_alloc(&path, "%s/%s", ctx->statedir,
                                      de->d_name);
                        if (access(path, X_OK) == 0) {
-                               const char *argv[] = { "sh", "-c", path, NULL };
+                               const char *argv[] = { "/bin/sh", "-c", path, NULL };
                                xsystem(argv);
                        }
                        free(path);
@@ -284,7 +294,6 @@ opkg_recurse_pkgs_in_order(pkg_t * pkg, pkg_vec_t * all,
                           pkg_vec_t * visited, pkg_vec_t * ordered)
 {
        int j, k, l, m;
-       int count;
        pkg_t *dep;
        compound_depend_t *compound_depend;
        depend_t **possible_satisfiers;
@@ -311,17 +320,13 @@ opkg_recurse_pkgs_in_order(pkg_t * pkg, pkg_vec_t * all,
 
        pkg_vec_insert(visited, pkg);
 
-       count = pkg->pre_depends_count + pkg->depends_count +
-           pkg->recommends_count + pkg->suggests_count;
-
        opkg_msg(DEBUG, "pkg %s.\n", pkg->name);
 
        /* Iterate over all the dependencies of pkg. For each one, find a package
           that is either installed or unpacked and satisfies this dependency.
           (there should only be one such package per dependency installed or
           unpacked). Then recurse to the dependency package */
-       for (j = 0; j < count; j++) {
-               compound_depend = &pkg->depends[j];
+       for (compound_depend = pkg_get_ptr(pkg, PKG_DEPENDS); compound_depend && compound_depend->type; compound_depend++) {
                possible_satisfiers = compound_depend->possibilities;
                for (k = 0; k < compound_depend->possibility_count; k++) {
                        abpkg = possible_satisfiers[k]->pkg;
@@ -439,14 +444,6 @@ static int opkg_install_cmd(int argc, char **argv)
        char *arg;
        int err = 0;
 
-       if (conf->force_reinstall) {
-               int saved_force_depends = conf->force_depends;
-               conf->force_depends = 1;
-               (void)opkg_remove_cmd(argc, argv);
-               conf->force_depends = saved_force_depends;
-               conf->force_reinstall = 0;
-       }
-
        signal(SIGINT, sigint_handler);
 
        /*
@@ -459,6 +456,18 @@ static int opkg_install_cmd(int argc, char **argv)
                if (opkg_prepare_url_for_install(arg, &argv[i]))
                        return -1;
        }
+
+       pkg_hash_load_package_details();
+       pkg_hash_load_status_files();
+
+       if (conf->force_reinstall) {
+               int saved_force_depends = conf->force_depends;
+               conf->force_depends = 1;
+               (void)opkg_remove_cmd(argc, argv);
+               conf->force_depends = saved_force_depends;
+               conf->force_reinstall = 0;
+       }
+
        pkg_info_preinstall_check();
 
        for (i = 0; i < argc; i++) {
@@ -553,7 +562,7 @@ static int opkg_download_cmd(int argc, char **argv)
                        opkg_msg(ERROR, "Failed to download %s.\n", pkg->name);
                } else {
                        opkg_msg(NOTICE, "Downloaded %s as %s.\n",
-                                pkg->name, pkg->local_filename);
+                                pkg->name, pkg_get_string(pkg, PKG_LOCAL_FILENAME));
                }
        }
 
@@ -566,6 +575,7 @@ static int opkg_list_find_cmd(int argc, char **argv, int use_desc)
        pkg_vec_t *available;
        pkg_t *pkg;
        char *pkg_name = NULL;
+       char *description;
 
        if (argc > 0) {
                pkg_name = argv[0];
@@ -575,10 +585,11 @@ static int opkg_list_find_cmd(int argc, char **argv, int use_desc)
        pkg_vec_sort(available, pkg_compare_names);
        for (i = 0; i < available->len; i++) {
                pkg = available->pkgs[i];
+               description = use_desc ? pkg_get_string(pkg, PKG_DESCRIPTION) : NULL;
                /* if we have package name or pattern and pkg does not match, then skip it */
                if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase) &&
-                   (!use_desc || !pkg->description
-                    || fnmatch(pkg_name, pkg->description, conf->nocase)))
+                   (!use_desc || !description
+                    || fnmatch(pkg_name, description, conf->nocase)))
                        continue;
                print_pkg(pkg);
        }
@@ -630,6 +641,7 @@ static int opkg_list_changed_conffiles_cmd(int argc, char **argv)
        pkg_t *pkg;
        char *pkg_name = NULL;
        conffile_list_elt_t *iter;
+       conffile_list_t *cl;
        conffile_t *cf;
 
        if (argc > 0) {
@@ -640,13 +652,14 @@ static int opkg_list_changed_conffiles_cmd(int argc, char **argv)
        pkg_vec_sort(available, pkg_compare_names);
        for (i = 0; i < available->len; i++) {
                pkg = available->pkgs[i];
+               cl = pkg_get_ptr(pkg, PKG_CONFFILES);
                /* if we have package name or pattern and pkg does not match, then skip it */
                if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase))
                        continue;
-               if (nv_pair_list_empty(&pkg->conffiles))
+               if (!cl || nv_pair_list_empty(cl))
                        continue;
-               for (iter = nv_pair_list_first(&pkg->conffiles); iter;
-                    iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+               for (iter = nv_pair_list_first(cl); iter;
+                    iter = nv_pair_list_next(cl, iter)) {
                        cf = (conffile_t *) iter->data;
                        if (cf->name && cf->value
                            && conffile_has_been_modified(cf))
@@ -665,7 +678,7 @@ static int opkg_list_upgradable_cmd(int argc, char **argv)
        char *old_v, *new_v;
        for (node = active_list_next(head, head); node;
             node = active_list_next(head, node)) {
-               _old_pkg = list_entry(node, pkg_t, list);
+               _old_pkg = node->pkg;
                _new_pkg =
                    pkg_hash_fetch_best_installation_candidate_by_name
                    (_old_pkg->name);
@@ -687,6 +700,7 @@ static int opkg_info_status_cmd(int argc, char **argv, int installed_only)
        pkg_vec_t *available;
        pkg_t *pkg;
        char *pkg_name = NULL;
+       conffile_list_t *cl;
 
        if (argc > 0) {
                pkg_name = argv[0];
@@ -706,10 +720,12 @@ static int opkg_info_status_cmd(int argc, char **argv, int installed_only)
 
                pkg_formatted_info(stdout, pkg);
 
-               if (conf->verbosity >= NOTICE) {
+               cl = pkg_get_ptr(pkg, PKG_CONFFILES);
+
+               if (conf->verbosity >= NOTICE && cl) {
                        conffile_list_elt_t *iter;
-                       for (iter = nv_pair_list_first(&pkg->conffiles); iter;
-                            iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+                       for (iter = nv_pair_list_first(cl); iter;
+                            iter = nv_pair_list_next(cl, iter)) {
                                conffile_t *cf = (conffile_t *) iter->data;
                                int modified = conffile_has_been_modified(cf);
                                if (cf->value)
@@ -894,7 +910,6 @@ static int opkg_files_cmd(int argc, char **argv)
 static int opkg_depends_cmd(int argc, char **argv)
 {
        int i, j, k;
-       int depends_count;
        pkg_vec_t *available_pkgs;
        compound_depend_t *cdep;
        pkg_t *pkg;
@@ -915,15 +930,9 @@ static int opkg_depends_cmd(int argc, char **argv)
                        if (fnmatch(argv[i], pkg->name, conf->nocase) != 0)
                                continue;
 
-                       depends_count = pkg->depends_count +
-                           pkg->pre_depends_count +
-                           pkg->recommends_count + pkg->suggests_count;
-
                        opkg_msg(NOTICE, "%s depends on:\n", pkg->name);
 
-                       for (k = 0; k < depends_count; k++) {
-                               cdep = &pkg->depends[k];
-
+                       for (k = 0, cdep = pkg_get_ptr(pkg, PKG_DEPENDS); cdep && cdep->type; k++, cdep++) {
                                if (cdep->type != DEPEND)
                                        continue;
 
@@ -941,13 +950,15 @@ static int opkg_depends_cmd(int argc, char **argv)
 
 static int pkg_mark_provides(pkg_t * pkg)
 {
-       int provides_count = pkg->provides_count;
-       abstract_pkg_t **provides = pkg->provides;
-       int i;
+       abstract_pkg_t **provider = pkg_get_ptr(pkg, PKG_PROVIDES);
+
        pkg->parent->state_flag |= SF_MARKED;
-       for (i = 0; i < provides_count; i++) {
-               provides[i]->state_flag |= SF_MARKED;
+
+       while (provider && *provider) {
+               (*provider)->state_flag |= SF_MARKED;
+               provider++;
        }
+
        return 0;
 }
 
@@ -965,11 +976,11 @@ opkg_what_depends_conflicts_cmd(enum depend_type what_field_type, int recursive,
                                int argc, char **argv)
 {
        depend_t *possibility;
-       compound_depend_t *cdep;
+       compound_depend_t *cdep, *deps;
        pkg_vec_t *available_pkgs;
        pkg_t *pkg;
-       int i, j, k, l;
-       int changed, count;
+       int i, j, l;
+       int changed;
        const char *rel_str = NULL;
        char *ver;
 
@@ -1019,21 +1030,21 @@ opkg_what_depends_conflicts_cmd(enum depend_type what_field_type, int recursive,
                for (j = 0; j < available_pkgs->len; j++) {
 
                        pkg = available_pkgs->pkgs[j];
+                       /*
                        count = ((what_field_type == CONFLICTS)
                                 ? pkg->conflicts_count
                                 : pkg->pre_depends_count +
                                 pkg->depends_count +
                                 pkg->recommends_count + pkg->suggests_count);
+                                */
 
                        /* skip this package if it is already marked */
                        if (pkg->parent->state_flag & SF_MARKED)
                                continue;
 
-                       for (k = 0; k < count; k++) {
-                               cdep = (what_field_type == CONFLICTS)
-                                   ? &pkg->conflicts[k]
-                                   : &pkg->depends[k];
+                       deps = pkg_get_ptr(pkg, (what_field_type == CONFLICTS) ? PKG_CONFLICTS : PKG_DEPENDS);
 
+                       for (cdep = deps; cdep && cdep->type; cdep++) {
                                if (what_field_type != cdep->type)
                                        continue;
 
@@ -1112,6 +1123,7 @@ static int
 opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc,
                                char **argv)
 {
+       abstract_pkg_t *apkg, **abpkgs;
 
        if (argc > 0) {
                pkg_vec_t *available_pkgs = pkg_vec_alloc();
@@ -1132,33 +1144,21 @@ opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc,
                        opkg_msg(NOTICE, "What %s %s\n", rel_str, target);
                        for (j = 0; j < available_pkgs->len; j++) {
                                pkg_t *pkg = available_pkgs->pkgs[j];
-                               int k;
-                               int count =
-                                   (what_field_type ==
-                                    WHATPROVIDES) ? pkg->provides_count : pkg->
-                                   replaces_count;
-                               for (k = 0; k < count; k++) {
-                                       abstract_pkg_t *apkg =
-                                           ((what_field_type == WHATPROVIDES)
-                                            ? pkg->provides[k]
-                                            : pkg->replaces[k]);
-                                       if (fnmatch
-                                           (target, apkg->name,
-                                            conf->nocase) == 0) {
-                                               opkg_msg(NOTICE, "    %s",
-                                                        pkg->name);
-                                               if ((conf->
-                                                    nocase ? strcasecmp(target,
-                                                                        apkg->
-                                                                        name) :
-                                                    strcmp(target,
-                                                           apkg->name)) != 0)
-                                                       opkg_msg(NOTICE,
-                                                                "\t%s %s\n",
-                                                                rel_str,
-                                                                apkg->name);
-                                               opkg_message(NOTICE, "\n");
-                                       }
+                               abpkgs = pkg_get_ptr(pkg, (what_field_type == WHATPROVIDES) ? PKG_PROVIDES : PKG_REPLACES);
+
+                               while (abpkgs && *abpkgs) {
+                                       apkg = *abpkgs++;
+
+                                       if (fnmatch(target, apkg->name, conf->nocase))
+                                               continue;
+
+                                       opkg_msg(NOTICE, "    %s", pkg->name);
+
+                                       if ((conf->nocase ? strcasecmp(target, apkg->name)
+                                           : strcmp(target, apkg->name)))
+                                               opkg_msg(NOTICE, "\t%s %s\n", rel_str, apkg->name);
+
+                                       opkg_message(NOTICE, "\n");
                                }
                        }
                }