X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fpkg_hash.c;h=4de4bdfb11cd7da6a06658b99213c66f5ea90b58;hp=f5c049507848e31748624079e69e7522ceb9abb8;hb=853fa7f4398f9813c7a2449532ae756f663f8bf2;hpb=9396bd4a4c84bde6b55ac3c47c90b4804e51adaf diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c index f5c0495..4de4bdf 100644 --- a/libopkg/pkg_hash.c +++ b/libopkg/pkg_hash.c @@ -79,7 +79,7 @@ int dist_hash_add_from_file(const char *lists_dir, pkg_src_t * dist) sprintf_alloc(&list_file, "%s/%s", lists_dir, subname); if (file_exists(list_file)) { - if (pkg_hash_add_from_file(list_file, dist, NULL, 0)) { + if (pkg_hash_add_from_file(list_file, dist, NULL, 0, 0)) { free(list_file); return -1; } @@ -95,7 +95,7 @@ int dist_hash_add_from_file(const char *lists_dir, pkg_src_t * dist) int pkg_hash_add_from_file(const char *file_name, - pkg_src_t * src, pkg_dest_t * dest, int is_status_file) + pkg_src_t * src, pkg_dest_t * dest, int is_status_file, int state_flags) { pkg_t *pkg; FILE *fp; @@ -121,6 +121,7 @@ pkg_hash_add_from_file(const char *file_name, pkg = pkg_new(); pkg->src = src; pkg->dest = dest; + pkg->state_flag |= state_flags; ret = parse_from_stream_nomalloc(pkg_parse_line, pkg, fp, 0, &buf, len); @@ -141,6 +142,13 @@ pkg_hash_add_from_file(const char *file_name, continue; } + if (!(pkg->state_flag & SF_NEED_DETAIL)) { + //opkg_msg(DEBUG, "Package %s is unrelated, ignoring.\n", pkg->name); + pkg_deinit(pkg); + free(pkg); + continue; + } + if (!pkg_get_architecture(pkg) || !pkg_get_arch_priority(pkg)) { char *version_str = pkg_version_str_alloc(pkg); opkg_msg(NOTICE, "Package %s version %s has no " @@ -166,7 +174,7 @@ pkg_hash_add_from_file(const char *file_name, /* * Load in feed files from the cached "src" and/or "src/gz" locations. */ -int pkg_hash_load_feeds(void) +int pkg_hash_load_feeds(int state_flags) { pkg_src_list_elt_t *iter; pkg_src_t *src, *subdist; @@ -185,7 +193,7 @@ int pkg_hash_load_feeds(void) sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name); if (file_exists(list_file)) { - if (pkg_hash_add_from_file(list_file, src, NULL, 0)) { + if (pkg_hash_add_from_file(list_file, src, NULL, 0, state_flags)) { free(list_file); return -1; } @@ -213,7 +221,7 @@ int pkg_hash_load_status_files(void) if (file_exists(dest->status_file_name)) { if (pkg_hash_add_from_file - (dest->status_file_name, NULL, dest, 1)) + (dest->status_file_name, NULL, dest, 1, SF_NEED_DETAIL)) return -1; } } @@ -221,9 +229,44 @@ int pkg_hash_load_status_files(void) return 0; } -static abstract_pkg_t *abstract_pkg_fetch_by_name(const char *pkg_name) +static void +pkg_hash_load_package_details_helper(const char *pkg_name, void *entry, void *data) { - return (abstract_pkg_t *) hash_table_get(&conf->pkg_hash, pkg_name); + int *count = data; + abstract_pkg_t *ab_pkg = (abstract_pkg_t *) entry; + + if (ab_pkg->state_flag & SF_NEED_DETAIL) { + if (ab_pkg->state_flag & SF_MARKED) { + opkg_msg(DEBUG, "skipping already seen flagged abpkg %s\n", + ab_pkg->name); + return; + } + + opkg_msg(DEBUG, "found yet incomplete flagged abpkg %s\n", + ab_pkg->name); + + (*count)++; + ab_pkg->state_flag |= SF_MARKED; + } +} + +int pkg_hash_load_package_details(void) +{ + int n_need_detail; + + while (1) { + pkg_hash_load_feeds(0); + + n_need_detail = 0; + hash_table_foreach(&conf->pkg_hash, pkg_hash_load_package_details_helper, &n_need_detail); + + if (n_need_detail > 0) + opkg_msg(DEBUG, "Found %d packages requiring details, reloading feeds\n", n_need_detail); + else + break; + } + + return 0; } pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,