071-use_gzipped_pkg_list.patch 3.2 KB

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