e102868d36b4298316839d74cc66eb6dbbe2197e
[openwrt/staging/dedeckeh.git] / package / system / opkg / patches / 071-use_gzipped_pkg_list.patch
1 --- a/libopkg/opkg.c
2 +++ b/libopkg/opkg.c
3 @@ -592,49 +592,8 @@ opkg_update_package_lists(opkg_progress_
4 src->gzip ? "Packages.gz" : "Packages");
5
6 sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
7 - if (src->gzip) {
8 - FILE *in, *out;
9 - struct _curl_cb_data cb_data;
10 - char *tmp_file_name = NULL;
11 -
12 - sprintf_alloc(&tmp_file_name, "%s/%s.gz", tmp,
13 - src->name);
14 -
15 - opkg_msg(INFO, "Downloading %s to %s...\n", url,
16 - tmp_file_name);
17 -
18 - cb_data.cb = progress_callback;
19 - cb_data.progress_data = &pdata;
20 - cb_data.user_data = user_data;
21 - cb_data.start_range =
22 - 100 * sources_done / sources_list_count;
23 - cb_data.finish_range =
24 - 100 * (sources_done + 1) / sources_list_count;
25 -
26 - err = opkg_download(url, tmp_file_name,
27 - (curl_progress_func) curl_progress_cb,
28 - &cb_data, 0);
29
30 - if (err == 0) {
31 - opkg_msg(INFO, "Inflating %s...\n",
32 - tmp_file_name);
33 - in = fopen(tmp_file_name, "r");
34 - out = fopen(list_file_name, "w");
35 - if (in && out)
36 - unzip(in, out);
37 - else
38 - err = 1;
39 - if (in)
40 - fclose(in);
41 - if (out)
42 - fclose(out);
43 - unlink(tmp_file_name);
44 - }
45 - free(tmp_file_name);
46 - } else
47 - err = opkg_download(url, list_file_name, NULL, NULL, 0);
48 -
49 - if (err) {
50 + if (opkg_download(url, list_file_name, NULL, NULL, 0)) {
51 opkg_msg(ERROR, "Couldn't retrieve %s\n", url);
52 result = -1;
53 }
54 --- a/libopkg/opkg_cmd.c
55 +++ b/libopkg/opkg_cmd.c
56 @@ -162,30 +162,7 @@ opkg_update_cmd(int argc, char **argv)
57 sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
58
59 sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
60 - if (src->gzip) {
61 - char *tmp_file_name;
62 - FILE *in, *out;
63 -
64 - sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
65 - err = opkg_download(url, tmp_file_name, NULL, NULL, 0);
66 - if (err == 0) {
67 - opkg_msg(NOTICE, "Inflating %s.\n", url);
68 - in = fopen (tmp_file_name, "r");
69 - out = fopen (list_file_name, "w");
70 - if (in && out)
71 - unzip (in, out);
72 - else
73 - err = 1;
74 - if (in)
75 - fclose (in);
76 - if (out)
77 - fclose (out);
78 - unlink (tmp_file_name);
79 - }
80 - free(tmp_file_name);
81 - } else
82 - err = opkg_download(url, list_file_name, NULL, NULL, 0);
83 - if (err) {
84 + if (opkg_download(url, list_file_name, NULL, NULL, 0)) {
85 failures++;
86 } else {
87 opkg_msg(NOTICE, "Updated list of available packages in %s.\n",
88 --- a/libopkg/pkg_hash.c
89 +++ b/libopkg/pkg_hash.c
90 @@ -29,6 +29,7 @@
91 #include "sprintf_alloc.h"
92 #include "file_util.h"
93 #include "libbb/libbb.h"
94 +#include "libbb/gzip.h"
95
96 void
97 pkg_hash_init(void)
98 @@ -106,8 +107,15 @@ pkg_hash_add_from_file(const char *file_
99 char *buf;
100 const size_t len = 4096;
101 int ret = 0;
102 + struct gzip_handle zh;
103 +
104 + if (src && src->gzip) {
105 + fp = gzip_fdopen(&zh, file_name);
106 + }
107 + else {
108 + fp = fopen(file_name, "r");
109 + }
110
111 - fp = fopen(file_name, "r");
112 if (fp == NULL) {
113 opkg_perror(ERROR, "Failed to open %s", file_name);
114 return -1;
115 @@ -155,6 +163,9 @@ pkg_hash_add_from_file(const char *file_
116 free(buf);
117 fclose(fp);
118
119 + if (src && src->gzip)
120 + gzip_close(&zh);
121 +
122 return ret;
123 }
124