rpcd: update to git head
[openwrt.git] / package / system / opkg / patches / 070-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 @@ -102,12 +102,18 @@ pkg_hash_add_from_file(const char *file_
91                         pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
92  {
93         pkg_t *pkg;
94 -       FILE *fp;
95 +       FILE *fp, *fp_c = NULL;
96         char *buf;
97         const size_t len = 4096;
98         int ret = 0;
99 +       int pid;
100  
101         fp = fopen(file_name, "r");
102 +       if (fp && src && src->gzip) {
103 +               fp_c = fp;
104 +               fp = gz_open(fp_c, &pid);
105 +       }
106 +
107         if (fp == NULL) {
108                 opkg_perror(ERROR, "Failed to open %s", file_name);
109                 return -1;
110 @@ -154,6 +160,10 @@ pkg_hash_add_from_file(const char *file_
111  
112         free(buf);
113         fclose(fp);
114 +       if (fp_c) {
115 +               fclose(fp_c);
116 +               gz_close(pid);
117 +       }
118  
119         return ret;
120  }