X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libopkg%2Fpkg_hash.c;h=62e6f0acdda5212ff816eeb1da37d5bbab9c2c54;hb=51e968e4ddffd4acd7c71e4976e1254a590f2217;hp=976ec96e28a979e0e9096bf920aa3268306e0d35;hpb=f032fb5b8c7c73531257331dc1b5489147ca0c85;p=oweals%2Fopkg-lede.git diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c index 976ec96..62e6f0a 100644 --- a/libopkg/pkg_hash.c +++ b/libopkg/pkg_hash.c @@ -113,43 +113,53 @@ static char *pkg_get_default_arch(opkg_conf_t *conf) int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, pkg_src_t *src, pkg_dest_t *dest, int is_status_file) { - hash_table_t *hash = &conf->pkg_hash; - char **raw; - char **raw_start; - pkg_t *pkg; - - raw = raw_start = read_raw_pkgs_from_file(file_name); - if (!raw) - return -ENOMEM; - - while(*raw){ /* don't worry, we'll increment raw in the parsing function */ - pkg = pkg_new(); - if (!pkg) - return -ENOMEM; - - if (pkg_parse_raw(pkg, &raw, src, dest) == 0) { - if (!pkg->architecture) { - char *version_str = pkg_version_str_alloc(pkg); - pkg->architecture = pkg_get_default_arch(conf); - opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n", - pkg->name, version_str, pkg->architecture); - free(version_str); - } - hash_insert_pkg(hash, pkg, is_status_file,conf); - } else { - pkg_deinit (pkg); - free(pkg); - } - } + hash_table_t *hash = &conf->pkg_hash; + pkg_t *pkg; + FILE *fp; + char *buf; + const size_t len = 4096; + int ret = 0; + + fp = fopen(file_name, "r"); + if (fp == NULL) { + fprintf(stderr, "%s: fopen(%s): %s\n", + __FUNCTION__, file_name, strerror(errno)); + return -1; + } - /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up - memory after read_raw_pkgs_from_file */ - raw = raw_start; - while (*raw) { - free(*raw++); - } - free(raw_start); - return 0; + buf = xmalloc(len); + + do { + pkg = pkg_new(); + pkg->src = src; + pkg->dest = dest; + + ret = pkg_parse_from_stream_nomalloc(pkg, fp, PFM_ALL, + &buf, len); + if (ret) { + pkg_deinit (pkg); + free(pkg); + if (ret == -1) + break; + continue; + } + + if (!pkg->architecture) { + char *version_str = pkg_version_str_alloc(pkg); + pkg->architecture = pkg_get_default_arch(conf); + opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n", + pkg->name, version_str, pkg->architecture); + free(version_str); + } + + hash_insert_pkg(hash, pkg, is_status_file, conf); + + } while (!feof(fp)); + + free(buf); + fclose(fp); + + return ret; } abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name) @@ -315,7 +325,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk } - if (matching_apkgs->len > 1 && conf->verbosity > 1) { + if (conf->verbosity >= OPKG_NOTICE && matching_apkgs->len > 1) { opkg_message(conf, OPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n", __FUNCTION__, apkg->name, matching_pkgs->len); for (i = 0; i < matching_pkgs->len; i++) {