Read the contents of lists files coming from 'dist' entries
[oweals/opkg-lede.git] / libopkg / pkg_hash.c
index b7f1573d36a15cc89eeec9911fc657a30673fac7..2a76be886bff273a12eafdce8cca2bb246174daa 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 
 #include "hash_table.h"
+#include "release.h"
 #include "pkg.h"
 #include "opkg_message.h"
 #include "pkg_vec.h"
@@ -69,6 +70,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)
@@ -131,7 +158,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");
@@ -139,6 +166,40 @@ 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)) {