070-use_gzipped_pkg_list.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. - sprintf_alloc(&tmp_file_name, "%s/%s.gz", tmp,
  11. - src->name);
  12. -
  13. - opkg_msg(INFO, "Downloading %s to %s...\n", url,
  14. - tmp_file_name);
  15. -
  16. - cb_data.cb = progress_callback;
  17. - cb_data.progress_data = &pdata;
  18. - cb_data.user_data = user_data;
  19. - cb_data.start_range =
  20. - 100 * sources_done / sources_list_count;
  21. - cb_data.finish_range =
  22. - 100 * (sources_done + 1) / sources_list_count;
  23. -
  24. - err = opkg_download(url, tmp_file_name,
  25. - (curl_progress_func) curl_progress_cb,
  26. - &cb_data, 0);
  27. -
  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. @@ -102,12 +102,18 @@ pkg_hash_add_from_file(const char *file_
  88. pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  89. {
  90. pkg_t *pkg;
  91. - FILE *fp;
  92. + FILE *fp, *fp_c = NULL;
  93. char *buf;
  94. const size_t len = 4096;
  95. int ret = 0;
  96. + int pid;
  97. fp = fopen(file_name, "r");
  98. + if (fp && src && src->gzip) {
  99. + fp_c = fp;
  100. + fp = gz_open(fp_c, &pid);
  101. + }
  102. +
  103. if (fp == NULL) {
  104. opkg_perror(ERROR, "Failed to open %s", file_name);
  105. return -1;
  106. @@ -154,6 +160,10 @@ pkg_hash_add_from_file(const char *file_
  107. free(buf);
  108. fclose(fp);
  109. + if (fp_c) {
  110. + fclose(fp_c);
  111. + gz_close(pid);
  112. + }
  113. return ret;
  114. }