libopkg: allow passing common package state flags to pkg_hash_add_from_file()
[oweals/opkg-lede.git] / libopkg / pkg_hash.c
index a8809a3025d3cc20f0e0d241f36c28d0c463a7bc..8c31aa99f0f8a26ac248c4d7ddb8e7324fcce62b 100644 (file)
@@ -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,8 +142,7 @@ pkg_hash_add_from_file(const char *file_name,
                        continue;
                }
 
-               if (!pkg_get_string(pkg, PKG_ARCHITECTURE) ||
-                   !pkg_get_int(pkg, PKG_ARCH_PRIORITY)) {
+               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 "
                                 "valid architecture, ignoring.\n",
@@ -186,7 +186,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, 0)) {
                                free(list_file);
                                return -1;
                        }
@@ -214,7 +214,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;
                }
        }
@@ -222,11 +222,6 @@ int pkg_hash_load_status_files(void)
        return 0;
 }
 
-static abstract_pkg_t *abstract_pkg_fetch_by_name(const char *pkg_name)
-{
-       return (abstract_pkg_t *) hash_table_get(&conf->pkg_hash, pkg_name);
-}
-
 pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                                                  int (*constraint_fcn) (pkg_t *
                                                                         pkg,
@@ -319,11 +314,11 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                        /* count packages matching max arch priority and keep track of last one */
                        for (j = 0; j < vec->len; j++) {
                                pkg_t *maybe = vec->pkgs[j];
-                               arch_priority = pkg_get_int(maybe, PKG_ARCH_PRIORITY);
+                               arch_priority = pkg_get_arch_priority(maybe);
 
                                opkg_msg(DEBUG,
                                         "%s arch=%s arch_priority=%d version=%s.\n",
-                                        maybe->name, pkg_get_string(maybe, PKG_ARCHITECTURE),
+                                        maybe->name, pkg_get_architecture(maybe),
                                         arch_priority, pkg_get_string(maybe, PKG_VERSION));
                                /* We make sure not to add the same package twice. Need to search for the reason why
                                   they show up twice sometimes. */
@@ -393,7 +388,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                int prio = 0;
                for (i = 0; i < matching_pkgs->len; i++) {
                        pkg_t *matching = matching_pkgs->pkgs[i];
-                       arch_priority = pkg_get_int(matching, PKG_ARCH_PRIORITY);
+                       arch_priority = pkg_get_arch_priority(matching);
                        if (arch_priority > prio) {
                                priorized_matching = matching;
                                prio = arch_priority;
@@ -411,7 +406,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                        pkg_t *matching = matching_pkgs->pkgs[i];
                        opkg_msg(INFO, "%s %s %s\n",
                                 matching->name, pkg_get_string(matching, PKG_VERSION),
-                                pkg_get_string(matching, PKG_ARCHITECTURE));
+                                pkg_get_architecture(matching));
                }
        }
 
@@ -437,7 +432,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
        if (priorized_matching) {
                opkg_msg(INFO, "Using priorized matching %s %s %s.\n",
                         priorized_matching->name, pkg_get_string(priorized_matching, PKG_VERSION),
-                        pkg_get_string(priorized_matching, PKG_ARCHITECTURE));
+                        pkg_get_architecture(priorized_matching));
                return priorized_matching;
        }
        if (nmatching > 1) {
@@ -448,7 +443,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
        if (latest_matching) {
                opkg_msg(INFO, "Using latest matching %s %s %s.\n",
                         latest_matching->name, pkg_get_string(latest_matching, PKG_VERSION),
-                        pkg_get_string(latest_matching, PKG_ARCHITECTURE));
+                        pkg_get_architecture(latest_matching));
                return latest_matching;
        }
        return NULL;