libopkg: drop support for Release files
[oweals/opkg-lede.git] / libopkg / pkg_hash.c
index 2a76be886bff273a12eafdce8cca2bb246174daa..c6d7158032cb8a860171cebc796e44f566e1c672 100644 (file)
 #include <stdio.h>
 
 #include "hash_table.h"
-#include "release.h"
 #include "pkg.h"
 #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)
@@ -105,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;
@@ -119,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);
@@ -148,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;
 }
 
@@ -166,40 +183,6 @@ pkg_hash_load_feeds(void)
        lists_dir = conf->restrict_to_default_dest ?
                conf->default_dest->lists_dir : conf->lists_dir;
 
-       for (iter = void_list_first(&conf->dist_src_list); iter;
-                       iter = void_list_next(&conf->dist_src_list, iter)) {
-
-               src = (pkg_src_t *)iter->data;
-
-               sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name);
-
-               if (file_exists(list_file)) {
-                       int i;
-                       release_t *release = release_new();
-                       if(release_init_from_file(release, list_file)) {
-                               free(list_file);
-                               return -1;
-                       }
-
-                       unsigned int ncomp;
-                       const char **comps = release_comps(release, &ncomp);
-                       subdist = (pkg_src_t *) xmalloc(sizeof(pkg_src_t));
-                       memcpy(subdist, src, sizeof(pkg_src_t));
-
-                       for(i = 0; i < ncomp; i++){
-                               subdist->name = NULL;
-                               sprintf_alloc(&subdist->name, "%s-%s", src->name, comps[i]);
-                               if (dist_hash_add_from_file(lists_dir, subdist)) {
-                                       free(subdist->name); free(subdist);
-                                       free(list_file);
-                                       return -1;
-                               }
-                       }
-                       free(subdist->name); free(subdist);
-               }
-               free(list_file);
-       }
-
        for (iter = void_list_first(&conf->pkg_src_list); iter;
                        iter = void_list_next(&conf->pkg_src_list, iter)) {