libopkg: drop support for Release files
[oweals/opkg-lede.git] / libopkg / pkg_hash.c
index b7f1573d36a15cc89eeec9911fc657a30673fac7..c6d7158032cb8a860171cebc796e44f566e1c672 100644 (file)
 #include "opkg_message.h"
 #include "pkg_vec.h"
 #include "pkg_hash.h"
+#include "parse_util.h"
 #include "pkg_parse.h"
 #include "opkg_utils.h"
 #include "sprintf_alloc.h"
 #include "file_util.h"
 #include "libbb/libbb.h"
+#include "libbb/gzip.h"
 
 void
 pkg_hash_init(void)
@@ -69,6 +71,32 @@ pkg_hash_deinit(void)
        hash_table_deinit(&conf->pkg_hash);
 }
 
+int
+dist_hash_add_from_file(const char *lists_dir, pkg_src_t *dist)
+{
+       nv_pair_list_elt_t *l;
+       char *list_file, *subname;
+
+       list_for_each_entry(l , &conf->arch_list.head, node) {
+               nv_pair_t *nv = (nv_pair_t *)l->data;
+               sprintf_alloc(&subname, "%s-%s", dist->name, nv->name);
+               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)) {
+                               free(list_file);
+                               return -1;
+                       }
+                       pkg_src_list_append (&conf->pkg_src_list, subname, dist->value, "__dummy__", 0);
+               }
+
+               free(list_file);
+       }
+
+       return 0;
+}
+
+
 int
 pkg_hash_add_from_file(const char *file_name,
                        pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
@@ -78,8 +106,15 @@ pkg_hash_add_from_file(const char *file_name,
        char *buf;
        const size_t len = 4096;
        int ret = 0;
+       struct gzip_handle zh;
+
+       if (src && src->gzip) {
+               fp = gzip_fdopen(&zh, file_name);
+       }
+       else {
+               fp = fopen(file_name, "r");
+       }
 
-       fp = fopen(file_name, "r");
        if (fp == NULL) {
                opkg_perror(ERROR, "Failed to open %s", file_name);
                return -1;
@@ -92,8 +127,14 @@ pkg_hash_add_from_file(const char *file_name,
                pkg->src = src;
                pkg->dest = dest;
 
-               ret = pkg_parse_from_stream_nomalloc(pkg, fp, 0,
+               ret = parse_from_stream_nomalloc(pkg_parse_line, pkg, fp, 0,
                                &buf, len);
+
+               if (pkg->name == NULL) {
+                       /* probably just a blank line */
+                       ret = 1;
+               }
+
                if (ret) {
                        pkg_deinit (pkg);
                        free(pkg);
@@ -121,6 +162,9 @@ pkg_hash_add_from_file(const char *file_name,
        free(buf);
        fclose(fp);
 
+       if (src && src->gzip)
+               gzip_close(&zh);
+
        return ret;
 }
 
@@ -131,7 +175,7 @@ int
 pkg_hash_load_feeds(void)
 {
        pkg_src_list_elt_t *iter;
-       pkg_src_t *src;
+       pkg_src_t *src, *subdist;
        char *list_file, *lists_dir;
 
        opkg_msg(INFO, "\n");