524-memory_usage.patch 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. --- a/archival/libipkg/pkg.c
  2. +++ b/archival/libipkg/pkg.c
  3. @@ -224,8 +224,7 @@
  4. if (err) { return err; }
  5. rewind(control_file);
  6. - raw = read_raw_pkgs_from_stream(control_file);
  7. - pkg_parse_raw(pkg, &raw, NULL, NULL);
  8. + pkg_parse_stream(pkg, control_file, NULL, NULL);
  9. fclose(control_file);
  10. --- a/archival/libipkg/pkg_hash.c
  11. +++ b/archival/libipkg/pkg_hash.c
  12. @@ -89,20 +89,20 @@
  13. pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  14. {
  15. hash_table_t *hash = &conf->pkg_hash;
  16. - char **raw;
  17. - char **raw_start;
  18. + FILE *fp;
  19. pkg_t *pkg;
  20. - raw = raw_start = read_raw_pkgs_from_file(file_name);
  21. - if (!raw)
  22. - return -ENOMEM;
  23. + if(!(fp = fopen(file_name, "r"))){
  24. + fprintf(stderr, "can't get %s open for read\n", file_name);
  25. + return NULL;
  26. + }
  27. - while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  28. + while(!feof(fp)) { /* don't worry, we'll increment raw in the parsing function */
  29. pkg = pkg_new();
  30. if (!pkg)
  31. return -ENOMEM;
  32. - if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  33. + if (pkg_parse_stream(pkg, fp, src, dest) == 0) {
  34. if (!pkg->architecture) {
  35. char *version_str = pkg_version_str_alloc(pkg);
  36. pkg->architecture = pkg_get_default_arch(conf);
  37. @@ -116,13 +116,6 @@
  38. }
  39. }
  40. - /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  41. - memory after read_raw_pkgs_from_file */
  42. - raw = raw_start;
  43. - while (*raw) {
  44. - free(*raw++);
  45. - }
  46. - free(raw_start);
  47. return 0;
  48. }
  49. --- a/archival/libipkg/pkg_parse.c
  50. +++ b/archival/libipkg/pkg_parse.c
  51. @@ -224,6 +224,161 @@
  52. Enhances, perhaps we could generalize all of these and save some
  53. code duplication.
  54. */
  55. +int pkg_parse_stream(pkg_t *pkg, FILE *stream, pkg_src_t *src, pkg_dest_t *dest)
  56. +{
  57. + int reading_conffiles, reading_description;
  58. + int pkg_false_provides=1;
  59. + char ** lines;
  60. + char *provide=NULL;
  61. + char *buf, *scout;
  62. + int count = 0;
  63. + size_t size = 512;
  64. +
  65. + buf = malloc (size);
  66. +
  67. + pkg->src = src;
  68. + pkg->dest = dest;
  69. +
  70. + reading_conffiles = reading_description = 0;
  71. +
  72. + while (fgets(buf, size, stream)) {
  73. + while (strlen (buf) == (size - 1)
  74. + && buf[size-2] != '\n') {
  75. + size_t o = size - 1;
  76. + size *= 2;
  77. + buf = realloc (buf, size);
  78. + if (fgets (buf + o, size - o, stream) == NULL)
  79. + break;
  80. + }
  81. +
  82. + if((scout = strchr(buf, '\n')))
  83. + *scout = '\0';
  84. +
  85. + lines = &buf;
  86. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  87. + if(isGenericFieldType("Package:", *lines))
  88. + pkg->name = parseGenericFieldType("Package", *lines);
  89. + else if(isGenericFieldType("Architecture:", *lines))
  90. + pkg->architecture = parseGenericFieldType("Architecture", *lines);
  91. + else if(isGenericFieldType("Filename:", *lines))
  92. + pkg->filename = parseGenericFieldType("Filename", *lines);
  93. + else if(isGenericFieldType("Section:", *lines))
  94. + pkg->section = parseGenericFieldType("Section", *lines);
  95. + else if(isGenericFieldType("MD5sum:", *lines))
  96. + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
  97. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  98. + let's parse it either way */
  99. + else if(isGenericFieldType("MD5Sum:", *lines))
  100. + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
  101. + else if(isGenericFieldType("Size:", *lines))
  102. + pkg->size = parseGenericFieldType("Size", *lines);
  103. + else if(isGenericFieldType("Source:", *lines))
  104. + pkg->source = parseGenericFieldType("Source", *lines);
  105. + else if(isGenericFieldType("Installed-Size:", *lines))
  106. + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
  107. + else if(isGenericFieldType("Installed-Time:", *lines)) {
  108. + char *time_str = parseGenericFieldType("Installed-Time", *lines);
  109. + pkg->installed_time = strtoul(time_str, NULL, 0);
  110. + } else if(isGenericFieldType("Priority:", *lines))
  111. + pkg->priority = parseGenericFieldType("Priority", *lines);
  112. + else if(isGenericFieldType("Essential:", *lines)) {
  113. + char *essential_value;
  114. + essential_value = parseGenericFieldType("Essential", *lines);
  115. + if (strcmp(essential_value, "yes") == 0) {
  116. + pkg->essential = 1;
  117. + }
  118. + free(essential_value);
  119. + }
  120. + else if(isGenericFieldType("Status", *lines))
  121. + parseStatus(pkg, *lines);
  122. + else if(isGenericFieldType("Version", *lines))
  123. + parseVersion(pkg, *lines);
  124. + else if(isGenericFieldType("Maintainer", *lines))
  125. + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
  126. + else if(isGenericFieldType("Conffiles", *lines)){
  127. + parseConffiles(pkg, *lines);
  128. + reading_conffiles = 1;
  129. + }
  130. + else if(isGenericFieldType("Description", *lines)) {
  131. + pkg->description = parseGenericFieldType("Description", *lines);
  132. + reading_conffiles = 0;
  133. + reading_description = 1;
  134. + }
  135. +
  136. + else if(isGenericFieldType("Provides", *lines)){
  137. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  138. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  139. + if ( alterProvidesLine(*lines,provide) ){
  140. + return EINVAL;
  141. + }
  142. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  143. +/* Let's try to hack a bit here.
  144. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  145. + in alot of other places. We will remove it before writing down the status database */
  146. + pkg_false_provides=0;
  147. + free(provide);
  148. + }
  149. +
  150. + else if(isGenericFieldType("Depends", *lines))
  151. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  152. + else if(isGenericFieldType("Pre-Depends", *lines))
  153. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  154. + else if(isGenericFieldType("Recommends", *lines))
  155. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  156. + else if(isGenericFieldType("Suggests", *lines))
  157. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  158. + /* Abhaya: support for conflicts */
  159. + else if(isGenericFieldType("Conflicts", *lines))
  160. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  161. + else if(isGenericFieldType("Replaces", *lines))
  162. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  163. + else if(line_is_blank(*lines)) {
  164. + break;
  165. + }
  166. + else if(**lines == ' '){
  167. + if(reading_description) {
  168. + /* we already know it's not blank, so the rest of description */
  169. + pkg->description = realloc(pkg->description,
  170. + strlen(pkg->description)
  171. + + 1 + strlen(*lines) + 1);
  172. + strcat(pkg->description, "\n");
  173. + strcat(pkg->description, (*lines));
  174. + }
  175. + else if(reading_conffiles)
  176. + parseConffiles(pkg, *lines);
  177. + }
  178. + }
  179. +/* If the ipk has not a Provides line, we insert our false line */
  180. + if ( pkg_false_provides==1)
  181. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  182. +
  183. + free(buf);
  184. + if (pkg->name) {
  185. + return 0;
  186. + } else {
  187. + return EINVAL;
  188. + }
  189. +}
  190. +
  191. +#if 0
  192. +
  193. +/* Some random thoughts from Carl:
  194. +
  195. + This function could be considerably simplified if we just kept
  196. + an array of all the generic string-valued field names, and looped
  197. + through those looking for a match. Also, these fields could perhaps
  198. + be stored in the package as an array as well, (or, probably better,
  199. + as an nv_pair_list_t).
  200. +
  201. + Fields which require special parsing or storage, (such as Depends:
  202. + and Status:) could be handled as they are now.
  203. +*/
  204. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  205. + to a dependency list. And, since we already have
  206. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  207. + Enhances, perhaps we could generalize all of these and save some
  208. + code duplication.
  209. +*/
  210. int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  211. {
  212. int reading_conffiles, reading_description;
  213. @@ -342,6 +497,7 @@
  214. return EINVAL;
  215. }
  216. }
  217. +#endif
  218. int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  219. {
  220. --- a/archival/libipkg/pkg_parse.h
  221. +++ b/archival/libipkg/pkg_parse.h
  222. @@ -25,7 +25,10 @@
  223. char ** parseDependsString(char * raw, int * depends_count);
  224. int parseVersion(pkg_t *pkg, char *raw);
  225. void parseConffiles(pkg_t * pkg, char * raw);
  226. +#if 0
  227. int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  228. +#endif
  229. +int pkg_parse_stream(pkg_t *pkg, FILE *stream, pkg_src_t *src, pkg_dest_t *dest);
  230. int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  231. #endif