Add an OSX specific patch to compile busybox with Darwin, possible fix for BSDs as...
[openwrt.git] / package / busybox / patches / 911-ipkg.patch
1 # Copyright (C) 2006 OpenWrt.org
2 #
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5 #
6 # add ipkg support to busybox
7 #
8 diff -ruN busybox-1.3.1-orig/archival/Config.in busybox-1.3.1-911/archival/Config.in
9 --- busybox-1.3.1-orig/archival/Config.in 2006-12-27 05:53:54.000000000 +0100
10 +++ busybox-1.3.1-911/archival/Config.in 2006-12-28 02:41:16.000000000 +0100
11 @@ -121,6 +121,14 @@
12 gzip is used to compress files.
13 It's probably the most widely used UNIX compression program.
14
15 +config IPKG
16 + bool "ipkg"
17 + default n
18 + select MD5SUM
19 + select WGET
20 + help
21 + ipkg is the itsy package management system.
22 +
23 config RPM2CPIO
24 bool "rpm2cpio"
25 default n
26 diff -ruN busybox-1.3.1-orig/archival/dpkg.c busybox-1.3.1-911/archival/dpkg.c
27 --- busybox-1.3.1-orig/archival/dpkg.c 2006-12-27 05:53:54.000000000 +0100
28 +++ busybox-1.3.1-911/archival/dpkg.c 2006-12-27 19:41:04.000000000 +0100
29 @@ -1507,6 +1507,10 @@
30 return ar_handle->sub_archive->buffer;
31 }
32
33 +/*
34 +
35 +// moved to data_extract_all.c
36 +
37 static void data_extract_all_prefix(archive_handle_t *archive_handle)
38 {
39 char *name_ptr = archive_handle->file_header->name;
40 @@ -1519,6 +1523,8 @@
41 return;
42 }
43
44 +*/
45 +
46 static void unpack_package(deb_file_t *deb_file)
47 {
48 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
49 diff -ruN busybox-1.3.1-orig/archival/ipkg.c busybox-1.3.1-911/archival/ipkg.c
50 --- busybox-1.3.1-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
51 +++ busybox-1.3.1-911/archival/ipkg.c 2006-12-27 19:41:04.000000000 +0100
52 @@ -0,0 +1,26 @@
53 +/* ipkg.c - the itsy package management system
54 +
55 + Florina Boor
56 +
57 + Copyright (C) 2003 kernel concepts
58 +
59 + This program is free software; you can redistribute it and/or
60 + modify it under the terms of the GNU General Public License as
61 + published by the Free Software Foundation; either version 2, or (at
62 + your option) any later version.
63 +
64 + This program is distributed in the hope that it will be useful, but
65 + WITHOUT ANY WARRANTY; without even the implied warranty of
66 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67 + General Public License for more details.
68 +
69 + ipkg command line frontend using libipkg
70 +
71 +*/
72 +
73 +#include "libipkg/libipkg.h"
74 +
75 +int ipkg_main(int argc, char **argv)
76 +{
77 + return ipkg_op(argc, argv);
78 +}
79 diff -ruN busybox-1.3.1-orig/archival/Kbuild busybox-1.3.1-911/archival/Kbuild
80 --- busybox-1.3.1-orig/archival/Kbuild 2006-12-27 05:53:54.000000000 +0100
81 +++ busybox-1.3.1-911/archival/Kbuild 2006-12-27 19:51:09.000000000 +0100
82 @@ -15,6 +15,7 @@
83 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
84 lib-$(CONFIG_GUNZIP) += gunzip.o
85 lib-$(CONFIG_GZIP) += gzip.o
86 +lib-$(CONFIG_IPKG) += ipkg.o
87 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
88 lib-$(CONFIG_RPM) += rpm.o
89 lib-$(CONFIG_TAR) += tar.o
90 diff -ruN busybox-1.3.1-orig/archival/libipkg/args.c busybox-1.3.1-911/archival/libipkg/args.c
91 --- busybox-1.3.1-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
92 +++ busybox-1.3.1-911/archival/libipkg/args.c 2006-12-27 19:41:04.000000000 +0100
93 @@ -0,0 +1,242 @@
94 +/* args.c - parse command-line args
95 +
96 + Carl D. Worth
97 +
98 + Copyright 2001 University of Southern California
99 +
100 + This program is free software; you can redistribute it and/or modify
101 + it under the terms of the GNU General Public License as published by
102 + the Free Software Foundation; either version 2, or (at your option)
103 + any later version.
104 +
105 + This program is distributed in the hope that it will be useful,
106 + but WITHOUT ANY WARRANTY; without even the implied warranty of
107 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108 + GNU General Public License for more details.
109 + */
110 +
111 +#include <getopt.h>
112 +#include <stdlib.h>
113 +#include <string.h>
114 +#include <unistd.h>
115 +
116 +#include "ipkg.h"
117 +#include "ipkg_message.h"
118 +
119 +#include "args.h"
120 +#include "sprintf_alloc.h"
121 +
122 +#include "libbb.h"
123 +
124 +
125 +static void print_version(void);
126 +
127 +enum long_args_opt
128 +{
129 + ARGS_OPT_FORCE_DEFAULTS = 129,
130 + ARGS_OPT_FORCE_DEPENDS,
131 + ARGS_OPT_FORCE_OVERWRITE,
132 + ARGS_OPT_FORCE_DOWNGRADE,
133 + ARGS_OPT_FORCE_REINSTALL,
134 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
135 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
136 + ARGS_OPT_FORCE_SPACE,
137 + ARGS_OPT_NOACTION,
138 + ARGS_OPT_NODEPS,
139 + ARGS_OPT_VERBOSE_WGET,
140 + ARGS_OPT_VERBOSITY,
141 + ARGS_OPT_MULTIPLE_PROVIDERS
142 +};
143 +
144 +int args_init(args_t *args)
145 +{
146 + char *conf_file_dir;
147 +
148 + memset(args, 0, sizeof(args_t));
149 +
150 + args->dest = ARGS_DEFAULT_DEST;
151 +
152 + conf_file_dir = getenv("IPKG_CONF_DIR");
153 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
154 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
155 + }
156 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
157 + ARGS_DEFAULT_CONF_FILE_NAME);
158 +
159 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
160 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
161 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
162 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
163 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
164 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
165 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
166 + args->noaction = ARGS_DEFAULT_NOACTION;
167 + args->nodeps = ARGS_DEFAULT_NODEPS;
168 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
169 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
170 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
171 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
172 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
173 + args->multiple_providers = 0;
174 + args->nocheckfordirorfile = 0;
175 + args->noreadfeedsfile = 0;
176 +
177 + return 1;
178 +}
179 +
180 +void args_deinit(args_t *args)
181 +{
182 + free(args->conf_file);
183 + args->conf_file = NULL;
184 +}
185 +
186 +int args_parse(args_t *args, int argc, char *argv[])
187 +{
188 + int c;
189 + int option_index = 0;
190 + int parse_err = 0;
191 + static struct option long_options[] = {
192 + {"query-all", 0, 0, 'A'},
193 + {"conf-file", 1, 0, 'f'},
194 + {"conf", 1, 0, 'f'},
195 + {"dest", 1, 0, 'd'},
196 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
197 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
198 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
199 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
200 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
201 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
202 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
203 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
204 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
205 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
206 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
207 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
208 + {"recursive", 0, 0,
209 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
210 + {"force-removal-of-dependent-packages", 0, 0,
211 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
212 + {"force_removal_of_dependent_packages", 0, 0,
213 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
214 + {"force-removal-of-essential-packages", 0, 0,
215 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
216 + {"force_removal_of_essential_packages", 0, 0,
217 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
218 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
219 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
220 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
221 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
222 + {"offline", 1, 0, 'o'},
223 + {"offline-root", 1, 0, 'o'},
224 + {"test", 0, 0, ARGS_OPT_NOACTION},
225 + {"tmp-dir", 1, 0, 't'},
226 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
227 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
228 + {"verbosity", 2, 0, 'V'},
229 + {"version", 0, 0, 'v'},
230 + {0, 0, 0, 0}
231 + };
232 +
233 + while (1) {
234 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
235 + if (c == -1)
236 + break;
237 +
238 + switch (c) {
239 + case 'A':
240 + args->query_all = 1;
241 + break;
242 + case 'd':
243 + args->dest = optarg;
244 + break;
245 + case 'f':
246 + free(args->conf_file);
247 + args->conf_file = strdup(optarg);
248 + break;
249 + case 'o':
250 + args->offline_root = optarg;
251 + break;
252 + case 'n':
253 + args->noaction = 1;
254 + break;
255 + case 't':
256 + args->tmp_dir = strdup(optarg);
257 + break;
258 + case 'v':
259 + print_version();
260 + exit(0);
261 + case 'V':
262 + case ARGS_OPT_VERBOSITY:
263 + if (optarg)
264 + args->verbosity = atoi(optarg);
265 + else
266 + args->verbosity += 1;
267 + break;
268 + case ARGS_OPT_FORCE_DEFAULTS:
269 + args->force_defaults = 1;
270 + break;
271 + case ARGS_OPT_FORCE_DEPENDS:
272 + args->force_depends = 1;
273 + break;
274 + case ARGS_OPT_FORCE_OVERWRITE:
275 + args->force_overwrite = 1;
276 + break;
277 + case ARGS_OPT_FORCE_DOWNGRADE:
278 + args->force_downgrade = 1;
279 + break;
280 + case ARGS_OPT_FORCE_REINSTALL:
281 + args->force_reinstall = 1;
282 + break;
283 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
284 + args->force_removal_of_essential_packages = 1;
285 + break;
286 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
287 + args->force_removal_of_dependent_packages = 1;
288 + break;
289 + case ARGS_OPT_FORCE_SPACE:
290 + args->force_space = 1;
291 + break;
292 + case ARGS_OPT_VERBOSE_WGET:
293 + args->verbose_wget = 1;
294 + break;
295 + case ARGS_OPT_MULTIPLE_PROVIDERS:
296 + args->multiple_providers = 1;
297 + break;
298 + case ARGS_OPT_NODEPS:
299 + args->nodeps = 1;
300 + break;
301 + case ARGS_OPT_NOACTION:
302 + args->noaction = 1;
303 + break;
304 + case ':':
305 + parse_err++;
306 + break;
307 + case '?':
308 + parse_err++;
309 + break;
310 + default:
311 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
312 + }
313 + }
314 +
315 + if (parse_err) {
316 + return -parse_err;
317 + } else {
318 + return optind;
319 + }
320 +}
321 +
322 +void args_usage(char *complaint)
323 +{
324 + if (complaint) {
325 + bb_error_msg("%s\n", complaint);
326 + }
327 + print_version();
328 + bb_show_usage();
329 + exit(1);
330 +}
331 +
332 +static void print_version(void)
333 +{
334 + bb_error_msg("version %s\n", IPKG_VERSION);
335 +}
336 diff -ruN busybox-1.3.1-orig/archival/libipkg/args.h busybox-1.3.1-911/archival/libipkg/args.h
337 --- busybox-1.3.1-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
338 +++ busybox-1.3.1-911/archival/libipkg/args.h 2006-12-27 19:41:04.000000000 +0100
339 @@ -0,0 +1,72 @@
340 +/* args.h - parse command-line args
341 +
342 + Carl D. Worth
343 +
344 + Copyright 2001 University of Southern California
345 +
346 + This program is free software; you can redistribute it and/or modify
347 + it under the terms of the GNU General Public License as published by
348 + the Free Software Foundation; either version 2, or (at your option)
349 + any later version.
350 +
351 + This program is distributed in the hope that it will be useful,
352 + but WITHOUT ANY WARRANTY; without even the implied warranty of
353 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
354 + GNU General Public License for more details.
355 +*/
356 +
357 +#ifndef ARGS_H
358 +#define ARGS_H
359 +
360 +struct args
361 +{
362 + char *conf_file;
363 + char *dest;
364 + char *tmp_dir;
365 + int force_defaults;
366 + int force_depends;
367 + int force_overwrite;
368 + int force_downgrade;
369 + int force_reinstall;
370 + int force_removal_of_essential_packages;
371 + int force_removal_of_dependent_packages;
372 + int force_space;
373 + int noaction;
374 + int nodeps;
375 + int multiple_providers;
376 + int query_all;
377 + int verbose_wget;
378 + int verbosity;
379 + int nocheckfordirorfile;
380 + int noreadfeedsfile;
381 + char *offline_root;
382 + char *offline_root_pre_script_cmd;
383 + char *offline_root_post_script_cmd;
384 +};
385 +typedef struct args args_t;
386 +
387 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
388 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
389 +#define ARGS_DEFAULT_DEST NULL
390 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
391 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
392 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
393 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
394 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
395 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
396 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
397 +#define ARGS_DEFAULT_FORCE_SPACE 0
398 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
399 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
400 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
401 +#define ARGS_DEFAULT_NOACTION 0
402 +#define ARGS_DEFAULT_NODEPS 0
403 +#define ARGS_DEFAULT_VERBOSE_WGET 0
404 +#define ARGS_DEFAULT_VERBOSITY 1
405 +
406 +int args_init(args_t *args);
407 +void args_deinit(args_t *args);
408 +int args_parse(args_t *args, int argc, char *argv[]);
409 +void args_usage(char *complaint);
410 +
411 +#endif
412 diff -ruN busybox-1.3.1-orig/archival/libipkg/conffile.c busybox-1.3.1-911/archival/libipkg/conffile.c
413 --- busybox-1.3.1-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
414 +++ busybox-1.3.1-911/archival/libipkg/conffile.c 2006-12-27 19:41:04.000000000 +0100
415 @@ -0,0 +1,64 @@
416 +/* conffile.c - the itsy package management system
417 +
418 + Carl D. Worth
419 +
420 + Copyright (C) 2001 University of Southern California
421 +
422 + This program is free software; you can redistribute it and/or
423 + modify it under the terms of the GNU General Public License as
424 + published by the Free Software Foundation; either version 2, or (at
425 + your option) any later version.
426 +
427 + This program is distributed in the hope that it will be useful, but
428 + WITHOUT ANY WARRANTY; without even the implied warranty of
429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
430 + General Public License for more details.
431 +*/
432 +
433 +#include <string.h>
434 +#include <stdlib.h>
435 +
436 +#include "ipkg.h"
437 +#include "ipkg_message.h"
438 +
439 +#include "conffile.h"
440 +#include "file_util.h"
441 +#include "sprintf_alloc.h"
442 +
443 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
444 +{
445 + return nv_pair_init(conffile, file_name, md5sum);
446 +}
447 +
448 +void conffile_deinit(conffile_t *conffile)
449 +{
450 + nv_pair_deinit(conffile);
451 +}
452 +
453 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
454 +{
455 + char *md5sum;
456 + char *filename = conffile->name;
457 + char *root_filename;
458 + int ret;
459 +
460 + if (conffile->value == NULL) {
461 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
462 + return 1;
463 + }
464 +
465 + root_filename = root_filename_alloc(conf, filename);
466 +
467 + md5sum = file_md5sum_alloc(root_filename);
468 +
469 + ret = strcmp(md5sum, conffile->value);
470 + if (ret) {
471 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
472 + conffile->name, md5sum, conffile->value);
473 + }
474 +
475 + free(root_filename);
476 + free(md5sum);
477 +
478 + return ret;
479 +}
480 diff -ruN busybox-1.3.1-orig/archival/libipkg/conffile.h busybox-1.3.1-911/archival/libipkg/conffile.h
481 --- busybox-1.3.1-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
482 +++ busybox-1.3.1-911/archival/libipkg/conffile.h 2006-12-27 19:41:04.000000000 +0100
483 @@ -0,0 +1,30 @@
484 +/* conffile.h - the itsy package management system
485 +
486 + Carl D. Worth
487 +
488 + Copyright (C) 2001 University of Southern California
489 +
490 + This program is free software; you can redistribute it and/or
491 + modify it under the terms of the GNU General Public License as
492 + published by the Free Software Foundation; either version 2, or (at
493 + your option) any later version.
494 +
495 + This program is distributed in the hope that it will be useful, but
496 + WITHOUT ANY WARRANTY; without even the implied warranty of
497 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
498 + General Public License for more details.
499 +*/
500 +
501 +#ifndef CONFFILE_H
502 +#define CONFFILE_H
503 +
504 +#include "nv_pair.h"
505 +
506 +typedef struct nv_pair conffile_t;
507 +
508 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
509 +void conffile_deinit(conffile_t *conffile);
510 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
511 +
512 +#endif
513 +
514 diff -ruN busybox-1.3.1-orig/archival/libipkg/conffile_list.c busybox-1.3.1-911/archival/libipkg/conffile_list.c
515 --- busybox-1.3.1-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
516 +++ busybox-1.3.1-911/archival/libipkg/conffile_list.c 2006-12-27 19:41:04.000000000 +0100
517 @@ -0,0 +1,47 @@
518 +/* conffile_list.c - the itsy package management system
519 +
520 + Carl D. Worth
521 +
522 + Copyright (C) 2001 University of Southern California
523 +
524 + This program is free software; you can redistribute it and/or
525 + modify it under the terms of the GNU General Public License as
526 + published by the Free Software Foundation; either version 2, or (at
527 + your option) any later version.
528 +
529 + This program is distributed in the hope that it will be useful, but
530 + WITHOUT ANY WARRANTY; without even the implied warranty of
531 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
532 + General Public License for more details.
533 +*/
534 +
535 +#include "ipkg.h"
536 +
537 +#include "conffile_list.h"
538 +
539 +int conffile_list_init(conffile_list_t *list)
540 +{
541 + return nv_pair_list_init(list);
542 +}
543 +
544 +void conffile_list_deinit(conffile_list_t *list)
545 +{
546 + nv_pair_list_deinit(list);
547 +}
548 +
549 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
550 + const char *md5sum)
551 +{
552 + return nv_pair_list_append(list, file_name, md5sum);
553 +}
554 +
555 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
556 +{
557 + return nv_pair_list_push(list, data);
558 +}
559 +
560 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
561 +{
562 + return nv_pair_list_pop(list);
563 +}
564 +
565 diff -ruN busybox-1.3.1-orig/archival/libipkg/conffile_list.h busybox-1.3.1-911/archival/libipkg/conffile_list.h
566 --- busybox-1.3.1-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
567 +++ busybox-1.3.1-911/archival/libipkg/conffile_list.h 2006-12-27 19:41:04.000000000 +0100
568 @@ -0,0 +1,36 @@
569 +/* conffile_list.h - the itsy package management system
570 +
571 + Carl D. Worth
572 +
573 + Copyright (C) 2001 University of Southern California
574 +
575 + This program is free software; you can redistribute it and/or
576 + modify it under the terms of the GNU General Public License as
577 + published by the Free Software Foundation; either version 2, or (at
578 + your option) any later version.
579 +
580 + This program is distributed in the hope that it will be useful, but
581 + WITHOUT ANY WARRANTY; without even the implied warranty of
582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
583 + General Public License for more details.
584 +*/
585 +
586 +#ifndef CONFFILE_LIST_H
587 +#define CONFFILE_LIST_H
588 +
589 +#include "conffile.h"
590 +#include "nv_pair_list.h"
591 +
592 +typedef struct nv_pair_list_elt conffile_list_elt_t;
593 +typedef struct nv_pair_list conffile_list_t;
594 +
595 +int conffile_list_init(conffile_list_t *list);
596 +void conffile_list_deinit(conffile_list_t *list);
597 +
598 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
599 + const char *root_dir);
600 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
601 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
602 +
603 +#endif
604 +
605 diff -ruN busybox-1.3.1-orig/archival/libipkg/file_util.c busybox-1.3.1-911/archival/libipkg/file_util.c
606 --- busybox-1.3.1-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
607 +++ busybox-1.3.1-911/archival/libipkg/file_util.c 2006-12-27 19:41:04.000000000 +0100
608 @@ -0,0 +1,177 @@
609 +/* file_util.c - convenience routines for common stat operations
610 +
611 + Carl D. Worth
612 +
613 + Copyright (C) 2001 University of Southern California
614 +
615 + This program is free software; you can redistribute it and/or
616 + modify it under the terms of the GNU General Public License as
617 + published by the Free Software Foundation; either version 2, or (at
618 + your option) any later version.
619 +
620 + This program is distributed in the hope that it will be useful, but
621 + WITHOUT ANY WARRANTY; without even the implied warranty of
622 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
623 + General Public License for more details.
624 +*/
625 +
626 +#include "ipkg.h"
627 +#include <sys/types.h>
628 +#include <sys/stat.h>
629 +
630 +#include "sprintf_alloc.h"
631 +#include "file_util.h"
632 +#include "md5.h"
633 +#include "libbb.h"
634 +#undef strlen
635 +
636 +int file_exists(const char *file_name)
637 +{
638 + int err;
639 + struct stat stat_buf;
640 +
641 + err = stat(file_name, &stat_buf);
642 + if (err == 0) {
643 + return 1;
644 + } else {
645 + return 0;
646 + }
647 +}
648 +
649 +int file_is_dir(const char *file_name)
650 +{
651 + int err;
652 + struct stat stat_buf;
653 +
654 + err = stat(file_name, &stat_buf);
655 + if (err) {
656 + return 0;
657 + }
658 +
659 + return S_ISDIR(stat_buf.st_mode);
660 +}
661 +
662 +/* read a single line from a file, stopping at a newline or EOF.
663 + If a newline is read, it will appear in the resulting string.
664 + Return value is a malloc'ed char * which should be freed at
665 + some point by the caller.
666 +
667 + Return value is NULL if the file is at EOF when called.
668 +*/
669 +#define FILE_READ_LINE_BUF_SIZE 1024
670 +char *file_read_line_alloc(FILE *file)
671 +{
672 + char buf[FILE_READ_LINE_BUF_SIZE];
673 + int buf_len;
674 + char *line = NULL;
675 + int line_size = 0;
676 +
677 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
678 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
679 + buf_len = strlen(buf);
680 + if (line) {
681 + line_size += buf_len;
682 + line = realloc(line, line_size);
683 + if (line == NULL) {
684 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
685 + break;
686 + }
687 + strcat(line, buf);
688 + } else {
689 + line_size = buf_len + 1;
690 + line = strdup(buf);
691 + }
692 + if (buf[buf_len - 1] == '\n') {
693 + break;
694 + }
695 + }
696 +
697 + return line;
698 +}
699 +
700 +int file_move(const char *src, const char *dest)
701 +{
702 + int err;
703 +
704 + err = rename(src, dest);
705 +
706 + if (err && errno == EXDEV) {
707 + err = file_copy(src, dest);
708 + unlink(src);
709 + } else if (err) {
710 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
711 + __FUNCTION__, src, dest, strerror(errno));
712 + }
713 +
714 + return err;
715 +}
716 +
717 +/* I put these here to keep libbb dependencies from creeping all over
718 + the ipkg code */
719 +int file_copy(const char *src, const char *dest)
720 +{
721 + int err;
722 +
723 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
724 + if (err) {
725 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
726 + __FUNCTION__, src, dest);
727 + }
728 +
729 + return err;
730 +}
731 +
732 +int file_mkdir_hier(const char *path, long mode)
733 +{
734 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
735 +}
736 +
737 +char *file_md5sum_alloc(const char *file_name)
738 +{
739 + static const int md5sum_bin_len = 16;
740 + static const int md5sum_hex_len = 32;
741 +
742 + static const unsigned char bin2hex[16] = {
743 + '0', '1', '2', '3',
744 + '4', '5', '6', '7',
745 + '8', '9', 'a', 'b',
746 + 'c', 'd', 'e', 'f'
747 + };
748 +
749 + int i, err;
750 + FILE *file;
751 + unsigned char *md5sum_hex;
752 + unsigned char md5sum_bin[md5sum_bin_len];
753 +
754 + md5sum_hex = malloc(md5sum_hex_len + 1);
755 + if (md5sum_hex == NULL) {
756 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
757 + return strdup("");
758 + }
759 +
760 + file = fopen(file_name, "r");
761 + if (file == NULL) {
762 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
763 + __FUNCTION__, file_name, strerror(errno));
764 + return strdup("");
765 + }
766 +
767 + err = md5_stream(file, md5sum_bin);
768 + if (err) {
769 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
770 + __FUNCTION__, file_name, strerror(err));
771 + return strdup("");
772 + }
773 +
774 + fclose(file);
775 +
776 + for (i=0; i < md5sum_bin_len; i++) {
777 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
778 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
779 + }
780 +
781 + md5sum_hex[md5sum_hex_len] = '\0';
782 +
783 + return md5sum_hex;
784 +}
785 +
786 diff -ruN busybox-1.3.1-orig/archival/libipkg/file_util.h busybox-1.3.1-911/archival/libipkg/file_util.h
787 --- busybox-1.3.1-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
788 +++ busybox-1.3.1-911/archival/libipkg/file_util.h 2006-12-27 19:41:04.000000000 +0100
789 @@ -0,0 +1,29 @@
790 +/* file_util.h - convenience routines for common file operations
791 +
792 + Carl D. Worth
793 +
794 + Copyright (C) 2001 University of Southern California
795 +
796 + This program is free software; you can redistribute it and/or
797 + modify it under the terms of the GNU General Public License as
798 + published by the Free Software Foundation; either version 2, or (at
799 + your option) any later version.
800 +
801 + This program is distributed in the hope that it will be useful, but
802 + WITHOUT ANY WARRANTY; without even the implied warranty of
803 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
804 + General Public License for more details.
805 +*/
806 +
807 +#ifndef FILE_UTIL_H
808 +#define FILE_UTIL_H
809 +
810 +int file_exists(const char *file_name);
811 +int file_is_dir(const char *file_name);
812 +char *file_read_line_alloc(FILE *file);
813 +int file_move(const char *src, const char *dest);
814 +int file_copy(const char *src, const char *dest);
815 +int file_mkdir_hier(const char *path, long mode);
816 +char *file_md5sum_alloc(const char *file_name);
817 +
818 +#endif
819 diff -ruN busybox-1.3.1-orig/archival/libipkg/hash_table.c busybox-1.3.1-911/archival/libipkg/hash_table.c
820 --- busybox-1.3.1-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
821 +++ busybox-1.3.1-911/archival/libipkg/hash_table.c 2006-12-27 19:41:04.000000000 +0100
822 @@ -0,0 +1,155 @@
823 +/* hash.c - hash tables for ipkg
824 +
825 + Steven M. Ayer, Jamey Hicks
826 +
827 + Copyright (C) 2002 Compaq Computer Corporation
828 +
829 + This program is free software; you can redistribute it and/or
830 + modify it under the terms of the GNU General Public License as
831 + published by the Free Software Foundation; either version 2, or (at
832 + your option) any later version.
833 +
834 + This program is distributed in the hope that it will be useful, but
835 + WITHOUT ANY WARRANTY; without even the implied warranty of
836 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
837 + General Public License for more details.
838 +*/
839 +
840 +#include <errno.h>
841 +#include <stdio.h>
842 +#include <stdlib.h>
843 +#include <string.h>
844 +#include "hash_table.h"
845 +#include "ipkg_message.h"
846 +
847 +
848 +static int hash_index(hash_table_t *hash, const char *pkg_name);
849 +static int rotating(const char *key, int len, int prime);
850 +
851 +static int hash_index(hash_table_t *hash, const char *pkg_name)
852 +{
853 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
854 +}
855 +
856 +static int rotating(const char *key, int len, int prime)
857 +{
858 + unsigned int hash, i;
859 + for (hash=len, i=0; i<len; ++i)
860 + hash = (hash<<4)^(hash>>28)^key[i];
861 + return (hash % prime);
862 +}
863 +
864 +
865 +/*
866 + * this is an open table keyed by strings
867 + */
868 +int hash_table_init(const char *name, hash_table_t *hash, int len)
869 +{
870 + static int primes_table[] = {
871 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
872 + 19471, 23143, 33961, 46499, 49727, 99529, 0
873 + };
874 + int *picker;
875 +
876 + if (hash->entries != NULL) {
877 + /* we have been here already */
878 + return 0;
879 + }
880 +
881 + hash->name = name;
882 + hash->entries = NULL;
883 + hash->n_entries = 0;
884 + hash->hash_entry_key = NULL;
885 +
886 + picker = primes_table;
887 + while(*picker && (*picker++ < len));
888 + if(!*picker)
889 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
890 + --picker;
891 +
892 + hash->n_entries = *picker;
893 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
894 + if (hash->entries == NULL) {
895 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
896 + return ENOMEM;
897 + }
898 + return 0;
899 +}
900 +
901 +void hash_table_deinit(hash_table_t *hash)
902 +{
903 + free(hash->entries);
904 + hash->entries = NULL;
905 + hash->n_entries = 0;
906 +}
907 +
908 +void *hash_table_get(hash_table_t *hash, const char *key)
909 +{
910 + int ndx= hash_index(hash, key);
911 + hash_entry_t *hash_entry = hash->entries + ndx;
912 + while (hash_entry)
913 + {
914 + if (hash_entry->key)
915 + {
916 + if (strcmp(key, hash_entry->key) == 0) {
917 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
918 + return hash_entry->data;
919 + }
920 + }
921 + hash_entry = hash_entry->next;
922 + }
923 + return NULL;
924 +}
925 +
926 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
927 +{
928 + int ndx= hash_index(hash, key);
929 + hash_entry_t *hash_entry = hash->entries + ndx;
930 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
931 + if (hash_entry->key) {
932 + if (strcmp(hash_entry->key, key) == 0) {
933 + /* alread in table, update the value */
934 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
935 + hash_entry->data = value;
936 + return 0;
937 + } else {
938 + /*
939 + * if this is a collision, we have to go to the end of the ll,
940 + * then add a new entry
941 + * before we can hook up the value
942 + */
943 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
944 + while (hash_entry->next)
945 + hash_entry = hash_entry->next;
946 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
947 + if (!hash_entry->next) {
948 + return -ENOMEM;
949 + }
950 + hash_entry = hash_entry->next;
951 + hash_entry->next = NULL;
952 + }
953 + }
954 + hash->n_elements++;
955 + hash_entry->key = strdup(key);
956 + hash_entry->data = value;
957 +
958 + return 0;
959 +}
960 +
961 +
962 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
963 +{
964 + int i;
965 + if (!hash || !f)
966 + return;
967 +
968 + for (i = 0; i < hash->n_entries; i++) {
969 + hash_entry_t *hash_entry = (hash->entries + i);
970 + do {
971 + if(hash_entry->key) {
972 + f(hash_entry->key, hash_entry->data, data);
973 + }
974 + } while((hash_entry = hash_entry->next));
975 + }
976 +}
977 +
978 diff -ruN busybox-1.3.1-orig/archival/libipkg/hash_table.h busybox-1.3.1-911/archival/libipkg/hash_table.h
979 --- busybox-1.3.1-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
980 +++ busybox-1.3.1-911/archival/libipkg/hash_table.h 2006-12-27 19:41:04.000000000 +0100
981 @@ -0,0 +1,44 @@
982 +/* hash.h - hash tables for ipkg
983 +
984 + Steven M. Ayer, Jamey Hicks
985 +
986 + Copyright (C) 2002 Compaq Computer Corporation
987 +
988 + This program is free software; you can redistribute it and/or
989 + modify it under the terms of the GNU General Public License as
990 + published by the Free Software Foundation; either version 2, or (at
991 + your option) any later version.
992 +
993 + This program is distributed in the hope that it will be useful, but
994 + WITHOUT ANY WARRANTY; without even the implied warranty of
995 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
996 + General Public License for more details.
997 +*/
998 +
999 +#ifndef _HASH_TABLE_H_
1000 +#define _HASH_TABLE_H_
1001 +
1002 +typedef struct hash_entry hash_entry_t;
1003 +typedef struct hash_table hash_table_t;
1004 +
1005 +struct hash_entry {
1006 + const char * key;
1007 + void * data;
1008 + struct hash_entry * next;
1009 +};
1010 +
1011 +struct hash_table {
1012 + const char *name;
1013 + hash_entry_t * entries;
1014 + int n_entries; /* number of buckets */
1015 + int n_elements;
1016 + const char * (*hash_entry_key)(void * data);
1017 +};
1018 +
1019 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1020 +void hash_table_deinit(hash_table_t *hash);
1021 +void *hash_table_get(hash_table_t *hash, const char *key);
1022 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1023 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1024 +
1025 +#endif /* _HASH_TABLE_H_ */
1026 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_cmd.c busybox-1.3.1-911/archival/libipkg/ipkg_cmd.c
1027 --- busybox-1.3.1-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1028 +++ busybox-1.3.1-911/archival/libipkg/ipkg_cmd.c 2006-12-27 19:41:04.000000000 +0100
1029 @@ -0,0 +1,1431 @@
1030 +/* ipkg_cmd.c - the itsy package management system
1031 +
1032 + Carl D. Worth
1033 +
1034 + Copyright (C) 2001 University of Southern California
1035 +
1036 + This program is free software; you can redistribute it and/or
1037 + modify it under the terms of the GNU General Public License as
1038 + published by the Free Software Foundation; either version 2, or (at
1039 + your option) any later version.
1040 +
1041 + This program is distributed in the hope that it will be useful, but
1042 + WITHOUT ANY WARRANTY; without even the implied warranty of
1043 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1044 + General Public License for more details.
1045 +*/
1046 +
1047 +#include <string.h>
1048 +
1049 +#include "ipkg.h"
1050 +#include <libgen.h>
1051 +#include <glob.h>
1052 +#include <errno.h>
1053 +#include <stdlib.h>
1054 +#include <unistd.h>
1055 +#include <signal.h>
1056 +#include <stdio.h>
1057 +#include <dirent.h>
1058 +
1059 +#include "ipkg_conf.h"
1060 +#include "ipkg_cmd.h"
1061 +#include "ipkg_message.h"
1062 +#include "pkg.h"
1063 +#include "pkg_dest.h"
1064 +#include "pkg_parse.h"
1065 +#include "sprintf_alloc.h"
1066 +#include "pkg.h"
1067 +#include "file_util.h"
1068 +#include "str_util.h"
1069 +#include "libbb.h"
1070 +#include "unarchive.h"
1071 +
1072 +#include <fnmatch.h>
1073 +
1074 +
1075 +#include "ipkg_download.h"
1076 +#include "ipkg_install.h"
1077 +#include "ipkg_upgrade.h"
1078 +#include "ipkg_remove.h"
1079 +#include "ipkg_configure.h"
1080 +#include "ipkg_message.h"
1081 +
1082 +#ifdef IPKG_LIB
1083 +#include "libipkg.h"
1084 +static void *p_userdata = NULL;
1085 +#endif
1086 +
1087 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1088 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1089 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1090 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1091 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1092 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1093 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1094 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1095 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1096 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1097 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1098 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1099 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1100 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1101 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1102 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1103 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1104 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1105 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1106 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1107 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1108 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1109 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1110 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1111 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1112 +
1113 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1114 + array for easier maintenance */
1115 +static ipkg_cmd_t cmds[] = {
1116 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1117 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1118 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1119 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1120 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1121 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1122 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1123 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1124 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1125 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1126 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1127 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1128 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1129 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1130 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1131 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1132 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1133 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1134 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1135 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1136 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1137 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1138 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1139 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1140 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1141 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1142 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1143 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1144 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1145 +};
1146 +
1147 +int ipkg_state_changed;
1148 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1149 +{
1150 + if (ipkg_state_changed && !conf->noaction) {
1151 + ipkg_message(conf, IPKG_INFO,
1152 + " writing status file\n");
1153 + ipkg_conf_write_status_files(conf);
1154 + pkg_write_changed_filelists(conf);
1155 + } else {
1156 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1157 + }
1158 +}
1159 +
1160 +
1161 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1162 +
1163 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1164 +{
1165 + int i;
1166 + ipkg_cmd_t *cmd;
1167 +
1168 + for (i=0; i < num_cmds; i++) {
1169 + cmd = &cmds[i];
1170 + if (strcmp(name, cmd->name) == 0) {
1171 + return cmd;
1172 + }
1173 + }
1174 +
1175 + return NULL;
1176 +}
1177 +
1178 +#ifdef IPKG_LIB
1179 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1180 +{
1181 + int result;
1182 + p_userdata = userdata;
1183 +
1184 +
1185 + result = (cmd->fun)(conf, argc, argv);
1186 + if ( result == 0 ) {
1187 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1188 + } else {
1189 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1190 +
1191 + }
1192 + if ( error_list ) {
1193 + reverse_error_list(&error_list);
1194 +
1195 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1196 + /* Here we print the errors collected and free the list */
1197 + while (error_list != NULL) {
1198 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1199 + error_list = error_list->next;
1200 +
1201 + }
1202 + free_error_list(&error_list);
1203 +
1204 + }
1205 +
1206 + p_userdata = NULL;
1207 + return result;
1208 +}
1209 +#else
1210 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1211 +{
1212 + return (cmd->fun)(conf, argc, argv);
1213 +}
1214 +#endif
1215 +
1216 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1217 +{
1218 + int err;
1219 + int failures;
1220 + char *lists_dir;
1221 + pkg_src_list_elt_t *iter;
1222 + pkg_src_t *src;
1223 +
1224 +
1225 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1226 +
1227 + if (! file_is_dir(lists_dir)) {
1228 + if (file_exists(lists_dir)) {
1229 + ipkg_message(conf, IPKG_ERROR,
1230 + "%s: ERROR: %s exists, but is not a directory\n",
1231 + __FUNCTION__, lists_dir);
1232 + free(lists_dir);
1233 + return EINVAL;
1234 + }
1235 + err = file_mkdir_hier(lists_dir, 0755);
1236 + if (err) {
1237 + ipkg_message(conf, IPKG_ERROR,
1238 + "%s: ERROR: failed to make directory %s: %s\n",
1239 + __FUNCTION__, lists_dir, strerror(errno));
1240 + free(lists_dir);
1241 + return EINVAL;
1242 + }
1243 + }
1244 +
1245 + failures = 0;
1246 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1247 + char *url, *list_file_name;
1248 +
1249 + src = iter->data;
1250 +
1251 + if (src->extra_data) /* debian style? */
1252 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1253 + src->gzip ? "Packages.gz" : "Packages");
1254 + else
1255 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1256 +
1257 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1258 + if (src->gzip) {
1259 + char *tmp;
1260 + char *tmp_file_name;
1261 + FILE *in, *out;
1262 +
1263 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1264 +
1265 + if (mkdtemp (tmp) == NULL) {
1266 + perror ("mkdtemp");
1267 + failures++;
1268 + continue;
1269 + }
1270 +
1271 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1272 + err = ipkg_download(conf, url, tmp_file_name);
1273 + if (err == 0) {
1274 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1275 + in = fopen (tmp_file_name, "r");
1276 + out = fopen (list_file_name, "w");
1277 + if (in && out)
1278 + inflate_unzip (in, out);
1279 + else
1280 + err = 1;
1281 + if (in)
1282 + fclose (in);
1283 + if (out)
1284 + fclose (out);
1285 + unlink (tmp_file_name);
1286 + rmdir (tmp);
1287 + free (tmp);
1288 + }
1289 + } else
1290 + err = ipkg_download(conf, url, list_file_name);
1291 + if (err) {
1292 + failures++;
1293 + } else {
1294 + ipkg_message(conf, IPKG_NOTICE,
1295 + "Updated list of available packages in %s\n",
1296 + list_file_name);
1297 + }
1298 + free(url);
1299 + free(list_file_name);
1300 + }
1301 + free(lists_dir);
1302 +
1303 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1304 +#warning here
1305 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1306 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1307 + * -Jamey 3/1/03
1308 + */
1309 + {
1310 + int i;
1311 + int changed = 0;
1312 + pkg_vec_t *available = pkg_vec_alloc();
1313 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1314 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1315 + for (i = 0; i < available->len; i++) {
1316 + pkg_t *pkg = available->pkgs[i];
1317 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1318 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1319 + pkg->state_want = SW_UNKNOWN;
1320 + changed = 1;
1321 + }
1322 + }
1323 + pkg_vec_free(available);
1324 + if (changed) {
1325 + write_status_files_if_changed(conf);
1326 + }
1327 + }
1328 +#endif
1329 +
1330 + return failures;
1331 +}
1332 +
1333 +
1334 +/* scan the args passed and cache the local filenames of the packages */
1335 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1336 +{
1337 + int i;
1338 + int err;
1339 +
1340 + /*
1341 + * First scan through package names/urls
1342 + * For any urls, download the packages and install in database.
1343 + * For any files, install package info in database.
1344 + */
1345 + for (i = 0; i < argc; i ++) {
1346 + char *filename = argv [i];
1347 + //char *tmp = basename (tmp);
1348 + //int tmplen = strlen (tmp);
1349 +
1350 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1351 + // continue;
1352 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1353 + // continue;
1354 +
1355 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1356 +
1357 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1358 + if (err)
1359 + return err;
1360 + }
1361 + return 0;
1362 +}
1363 +
1364 +struct ipkg_intercept
1365 +{
1366 + char *oldpath;
1367 + char *statedir;
1368 +};
1369 +
1370 +typedef struct ipkg_intercept *ipkg_intercept_t;
1371 +
1372 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1373 +{
1374 + ipkg_intercept_t ctx;
1375 + char *newpath;
1376 + int gen;
1377 +
1378 + ctx = malloc (sizeof (*ctx));
1379 + ctx->oldpath = strdup (getenv ("PATH"));
1380 +
1381 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1382 + setenv ("PATH", newpath, 1);
1383 + free (newpath);
1384 +
1385 + gen = 0;
1386 + retry:
1387 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1388 + if (mkdir (ctx->statedir, 0770) < 0) {
1389 + if (errno == EEXIST) {
1390 + free (ctx->statedir);
1391 + gen++;
1392 + goto retry;
1393 + }
1394 + perror (ctx->statedir);
1395 + return NULL;
1396 + }
1397 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1398 + return ctx;
1399 +}
1400 +
1401 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1402 +{
1403 + char *cmd;
1404 + DIR *dir;
1405 + int err = 0;
1406 +
1407 + setenv ("PATH", ctx->oldpath, 1);
1408 + free (ctx->oldpath);
1409 +
1410 + dir = opendir (ctx->statedir);
1411 + if (dir) {
1412 + struct dirent *de;
1413 + while (de = readdir (dir), de != NULL) {
1414 + char *path;
1415 +
1416 + if (de->d_name[0] == '.')
1417 + continue;
1418 +
1419 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1420 + if (access (path, X_OK) == 0) {
1421 + if (system (path)) {
1422 + err = errno;
1423 + perror (de->d_name);
1424 + }
1425 + }
1426 + free (path);
1427 + }
1428 + } else
1429 + perror (ctx->statedir);
1430 +
1431 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1432 + system (cmd);
1433 + free (cmd);
1434 +
1435 + free (ctx->statedir);
1436 + free (ctx);
1437 +
1438 + return err;
1439 +}
1440 +
1441 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1442 +{
1443 + pkg_vec_t *all;
1444 + int i;
1445 + pkg_t *pkg;
1446 + ipkg_intercept_t ic;
1447 + int r, err = 0;
1448 +
1449 + ipkg_message(conf, IPKG_INFO,
1450 + "Configuring unpacked packages\n");
1451 + fflush( stdout );
1452 +
1453 + all = pkg_vec_alloc();
1454 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1455 +
1456 + ic = ipkg_prep_intercepts (conf);
1457 +
1458 + for(i = 0; i < all->len; i++) {
1459 + pkg = all->pkgs[i];
1460 +
1461 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1462 + continue;
1463 +
1464 + if (pkg->state_status == SS_UNPACKED) {
1465 + ipkg_message(conf, IPKG_NOTICE,
1466 + "Configuring %s\n", pkg->name);
1467 + fflush( stdout );
1468 + r = ipkg_configure(conf, pkg);
1469 + if (r == 0) {
1470 + pkg->state_status = SS_INSTALLED;
1471 + pkg->parent->state_status = SS_INSTALLED;
1472 + pkg->state_flag &= ~SF_PREFER;
1473 + } else {
1474 + if (!err)
1475 + err = r;
1476 + }
1477 + }
1478 + }
1479 +
1480 + r = ipkg_finalize_intercepts (ic);
1481 + if (r && !err)
1482 + err = r;
1483 +
1484 + pkg_vec_free(all);
1485 + return err;
1486 +}
1487 +
1488 +static void sigint_handler(int sig)
1489 +{
1490 + signal(sig, SIG_DFL);
1491 + ipkg_message(NULL, IPKG_NOTICE,
1492 + "ipkg: interrupted. writing out status database\n");
1493 + write_status_files_if_changed(global_conf);
1494 + exit(128 + sig);
1495 +}
1496 +
1497 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1498 +{
1499 + int i;
1500 + char *arg;
1501 + int err=0;
1502 +
1503 + global_conf = conf;
1504 + signal(SIGINT, sigint_handler);
1505 +
1506 + /*
1507 + * Now scan through package names and install
1508 + */
1509 + for (i=0; i < argc; i++) {
1510 + arg = argv[i];
1511 +
1512 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1513 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1514 + if (err != EINVAL && err != 0)
1515 + return err;
1516 + }
1517 + pkg_info_preinstall_check(conf);
1518 +
1519 + for (i=0; i < argc; i++) {
1520 + arg = argv[i];
1521 + if (conf->multiple_providers)
1522 + err = ipkg_install_multi_by_name(conf, arg);
1523 + else{
1524 + err = ipkg_install_by_name(conf, arg);
1525 + }
1526 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1527 + ipkg_message(conf, IPKG_ERROR,
1528 + "Cannot find package %s.\n"
1529 + "Check the spelling or perhaps run 'ipkg update'\n",
1530 + arg);
1531 + }
1532 + }
1533 +
1534 + /* recheck to verify that all dependences are satisfied */
1535 + if (0) ipkg_satisfy_all_dependences(conf);
1536 +
1537 + ipkg_configure_packages(conf, NULL);
1538 +
1539 + write_status_files_if_changed(conf);
1540 +
1541 + return err;
1542 +}
1543 +
1544 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1545 +{
1546 + int i;
1547 + pkg_t *pkg;
1548 + int err;
1549 +
1550 + global_conf = conf;
1551 + signal(SIGINT, sigint_handler);
1552 +
1553 + if (argc) {
1554 + for (i=0; i < argc; i++) {
1555 + char *arg = argv[i];
1556 +
1557 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1558 + if (err != EINVAL && err != 0)
1559 + return err;
1560 + }
1561 + pkg_info_preinstall_check(conf);
1562 +
1563 + for (i=0; i < argc; i++) {
1564 + char *arg = argv[i];
1565 + if (conf->restrict_to_default_dest) {
1566 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1567 + argv[i],
1568 + conf->default_dest);
1569 + if (pkg == NULL) {
1570 + ipkg_message(conf, IPKG_NOTICE,
1571 + "Package %s not installed in %s\n",
1572 + argv[i], conf->default_dest->name);
1573 + continue;
1574 + }
1575 + } else {
1576 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1577 + argv[i]);
1578 + }
1579 + if (pkg)
1580 + ipkg_upgrade_pkg(conf, pkg);
1581 + else {
1582 + ipkg_install_by_name(conf, arg);
1583 + }
1584 + }
1585 + } else {
1586 + pkg_vec_t *installed = pkg_vec_alloc();
1587 +
1588 + pkg_info_preinstall_check(conf);
1589 +
1590 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1591 + for (i = 0; i < installed->len; i++) {
1592 + pkg = installed->pkgs[i];
1593 + ipkg_upgrade_pkg(conf, pkg);
1594 + }
1595 + pkg_vec_free(installed);
1596 + }
1597 +
1598 + /* recheck to verify that all dependences are satisfied */
1599 + if (0) ipkg_satisfy_all_dependences(conf);
1600 +
1601 + ipkg_configure_packages(conf, NULL);
1602 +
1603 + write_status_files_if_changed(conf);
1604 +
1605 + return 0;
1606 +}
1607 +
1608 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1609 +{
1610 + int i, err;
1611 + char *arg;
1612 + pkg_t *pkg;
1613 +
1614 + pkg_info_preinstall_check(conf);
1615 + for (i = 0; i < argc; i++) {
1616 + arg = argv[i];
1617 +
1618 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1619 + if (pkg == NULL) {
1620 + ipkg_message(conf, IPKG_ERROR,
1621 + "Cannot find package %s.\n"
1622 + "Check the spelling or perhaps run 'ipkg update'\n",
1623 + arg);
1624 + continue;
1625 + }
1626 +
1627 + err = ipkg_download_pkg(conf, pkg, ".");
1628 +
1629 + if (err) {
1630 + ipkg_message(conf, IPKG_ERROR,
1631 + "Failed to download %s\n", pkg->name);
1632 + } else {
1633 + ipkg_message(conf, IPKG_NOTICE,
1634 + "Downloaded %s as %s\n",
1635 + pkg->name, pkg->local_filename);
1636 + }
1637 + }
1638 +
1639 + return 0;
1640 +}
1641 +
1642 +
1643 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1644 +{
1645 + int i ;
1646 + pkg_vec_t *available;
1647 + pkg_t *pkg;
1648 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1649 + char *newline;
1650 + char *pkg_name = NULL;
1651 + char *version_str;
1652 +
1653 + if (argc > 0) {
1654 + pkg_name = argv[0];
1655 + }
1656 + available = pkg_vec_alloc();
1657 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1658 + for (i=0; i < available->len; i++) {
1659 + pkg = available->pkgs[i];
1660 + /* if we have package name or pattern and pkg does not match, then skip it */
1661 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1662 + continue;
1663 + if (pkg->description) {
1664 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1665 + } else {
1666 + desc_short[0] = '\0';
1667 + }
1668 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1669 + newline = strchr(desc_short, '\n');
1670 + if (newline) {
1671 + *newline = '\0';
1672 + }
1673 +#ifndef IPKG_LIB
1674 + printf("%s - %s\n", pkg->name, desc_short);
1675 +#else
1676 + if (ipkg_cb_list) {
1677 + version_str = pkg_version_str_alloc(pkg);
1678 + ipkg_cb_list(pkg->name,desc_short,
1679 + version_str,
1680 + pkg->state_status,
1681 + p_userdata);
1682 + free(version_str);
1683 + }
1684 +#endif
1685 + }
1686 + pkg_vec_free(available);
1687 +
1688 + return 0;
1689 +}
1690 +
1691 +
1692 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1693 +{
1694 + int i ;
1695 + pkg_vec_t *available;
1696 + pkg_t *pkg;
1697 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1698 + char *newline;
1699 + char *pkg_name = NULL;
1700 + char *version_str;
1701 +
1702 + if (argc > 0) {
1703 + pkg_name = argv[0];
1704 + }
1705 + available = pkg_vec_alloc();
1706 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1707 + for (i=0; i < available->len; i++) {
1708 + pkg = available->pkgs[i];
1709 + /* if we have package name or pattern and pkg does not match, then skip it */
1710 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1711 + continue;
1712 + if (pkg->description) {
1713 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1714 + } else {
1715 + desc_short[0] = '\0';
1716 + }
1717 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1718 + newline = strchr(desc_short, '\n');
1719 + if (newline) {
1720 + *newline = '\0';
1721 + }
1722 +#ifndef IPKG_LIB
1723 + printf("%s - %s\n", pkg->name, desc_short);
1724 +#else
1725 + if (ipkg_cb_list) {
1726 + version_str = pkg_version_str_alloc(pkg);
1727 + ipkg_cb_list(pkg->name,desc_short,
1728 + version_str,
1729 + pkg->state_status,
1730 + p_userdata);
1731 + free(version_str);
1732 + }
1733 +#endif
1734 + }
1735 +
1736 + return 0;
1737 +}
1738 +
1739 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1740 +{
1741 + int i;
1742 + pkg_vec_t *available;
1743 + pkg_t *pkg;
1744 + char *pkg_name = NULL;
1745 + char **pkg_fields = NULL;
1746 + int n_fields = 0;
1747 + char *buff ; // = (char *)malloc(1);
1748 +
1749 + if (argc > 0) {
1750 + pkg_name = argv[0];
1751 + }
1752 + if (argc > 1) {
1753 + pkg_fields = &argv[1];
1754 + n_fields = argc - 1;
1755 + }
1756 +
1757 + available = pkg_vec_alloc();
1758 + if (installed_only)
1759 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1760 + else
1761 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1762 + for (i=0; i < available->len; i++) {
1763 + pkg = available->pkgs[i];
1764 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1765 + continue;
1766 + }
1767 +#ifndef IPKG_LIB
1768 + if (n_fields) {
1769 + for (j = 0; j < n_fields; j++)
1770 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1771 + } else {
1772 + pkg_print_info(pkg, stdout);
1773 + }
1774 +#else
1775 +
1776 + buff = pkg_formatted_info(pkg);
1777 + if ( buff ) {
1778 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1779 + pkg->state_status,
1780 + buff,
1781 + p_userdata);
1782 +/*
1783 + We should not forget that actually the pointer is allocated.
1784 + We need to free it :) ( Thanks florian for seeing the error )
1785 +*/
1786 + free(buff);
1787 + }
1788 +#endif
1789 + if (conf->verbosity > 1) {
1790 + conffile_list_elt_t *iter;
1791 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1792 + conffile_t *cf = iter->data;
1793 + int modified = conffile_has_been_modified(conf, cf);
1794 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1795 + cf->name, cf->value, modified);
1796 + }
1797 + }
1798 + }
1799 +#ifndef IPKG_LIB
1800 + if (buff)
1801 + free(buff);
1802 +#endif
1803 + pkg_vec_free(available);
1804 +
1805 + return 0;
1806 +}
1807 +
1808 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1809 +{
1810 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1811 +}
1812 +
1813 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1814 +{
1815 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1816 +}
1817 +
1818 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1819 +{
1820 +
1821 + int err;
1822 + if (argc > 0) {
1823 + char *pkg_name = NULL;
1824 +
1825 + pkg_name = argv[0];
1826 +
1827 + err = ipkg_configure_packages (conf, pkg_name);
1828 +
1829 + } else {
1830 + err = ipkg_configure_packages (conf, NULL);
1831 + }
1832 +
1833 + write_status_files_if_changed(conf);
1834 +
1835 + return err;
1836 +}
1837 +
1838 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1839 +{
1840 + int i, err;
1841 + char *globpattern;
1842 + glob_t globbuf;
1843 +
1844 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1845 + err = glob(globpattern, 0, NULL, &globbuf);
1846 + free(globpattern);
1847 + if (err) {
1848 + return 0;
1849 + }
1850 +
1851 + ipkg_message(conf, IPKG_NOTICE,
1852 + "The following packages in %s will now be installed.\n",
1853 + conf->pending_dir);
1854 + for (i = 0; i < globbuf.gl_pathc; i++) {
1855 + ipkg_message(conf, IPKG_NOTICE,
1856 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1857 + }
1858 + ipkg_message(conf, IPKG_NOTICE, "\n");
1859 + for (i = 0; i < globbuf.gl_pathc; i++) {
1860 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1861 + if (err == 0) {
1862 + err = unlink(globbuf.gl_pathv[i]);
1863 + if (err) {
1864 + ipkg_message(conf, IPKG_ERROR,
1865 + "%s: ERROR: failed to unlink %s: %s\n",
1866 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1867 + return err;
1868 + }
1869 + }
1870 + }
1871 + globfree(&globbuf);
1872 +
1873 + return err;
1874 +}
1875 +
1876 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1877 +{
1878 + int i,a,done;
1879 + pkg_t *pkg;
1880 + pkg_t *pkg_to_remove;
1881 + pkg_vec_t *available;
1882 + char *pkg_name = NULL;
1883 + global_conf = conf;
1884 + signal(SIGINT, sigint_handler);
1885 +
1886 +// ENH: Add the "no pkg removed" just in case.
1887 +
1888 + done = 0;
1889 +
1890 + available = pkg_vec_alloc();
1891 + pkg_info_preinstall_check(conf);
1892 + if ( argc > 0 ) {
1893 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1894 + for (i=0; i < argc; i++) {
1895 + pkg_name = malloc(strlen(argv[i])+2);
1896 + strcpy(pkg_name,argv[i]);
1897 + for (a=0; a < available->len; a++) {
1898 + pkg = available->pkgs[a];
1899 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1900 + continue;
1901 + }
1902 + if (conf->restrict_to_default_dest) {
1903 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1904 + pkg->name,
1905 + conf->default_dest);
1906 + } else {
1907 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1908 + }
1909 +
1910 + if (pkg == NULL) {
1911 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1912 + continue;
1913 + }
1914 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1915 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1916 + continue;
1917 + }
1918 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1919 + done = 1;
1920 + }
1921 + free (pkg_name);
1922 + }
1923 + pkg_vec_free(available);
1924 + } else {
1925 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1926 + int i;
1927 + int flagged_pkg_count = 0;
1928 + int removed;
1929 +
1930 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1931 +
1932 + for (i = 0; i < installed_pkgs->len; i++) {
1933 + pkg_t *pkg = installed_pkgs->pkgs[i];
1934 + if (pkg->state_flag & SF_USER) {
1935 + flagged_pkg_count++;
1936 + } else {
1937 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1938 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1939 + }
1940 + }
1941 + if (!flagged_pkg_count) {
1942 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1943 + "so refusing to uninstall unflagged non-leaf packages\n");
1944 + return 0;
1945 + }
1946 +
1947 + /* find packages not flagged SF_USER (i.e., installed to
1948 + * satisfy a dependence) and not having any dependents, and
1949 + * remove them */
1950 + do {
1951 + removed = 0;
1952 + for (i = 0; i < installed_pkgs->len; i++) {
1953 + pkg_t *pkg = installed_pkgs->pkgs[i];
1954 + if (!(pkg->state_flag & SF_USER)
1955 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1956 + removed++;
1957 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1958 + ipkg_remove_pkg(conf, pkg,0);
1959 + done = 1;
1960 + }
1961 + }
1962 + } while (removed);
1963 + pkg_vec_free(installed_pkgs);
1964 + }
1965 +
1966 + if ( done == 0 )
1967 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1968 +
1969 + write_status_files_if_changed(conf);
1970 + return 0;
1971 +}
1972 +
1973 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1974 +{
1975 + int i;
1976 + pkg_t *pkg;
1977 +
1978 + global_conf = conf;
1979 + signal(SIGINT, sigint_handler);
1980 +
1981 + pkg_info_preinstall_check(conf);
1982 +
1983 + for (i=0; i < argc; i++) {
1984 + if (conf->restrict_to_default_dest) {
1985 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1986 + argv[i],
1987 + conf->default_dest);
1988 + } else {
1989 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1990 + }
1991 +
1992 + if (pkg == NULL) {
1993 + ipkg_message(conf, IPKG_ERROR,
1994 + "Package %s is not installed.\n", argv[i]);
1995 + continue;
1996 + }
1997 + ipkg_purge_pkg(conf, pkg);
1998 + }
1999 +
2000 + write_status_files_if_changed(conf);
2001 + return 0;
2002 +}
2003 +
2004 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2005 +{
2006 + int i;
2007 + pkg_t *pkg;
2008 + const char *flags = argv[0];
2009 +
2010 + global_conf = conf;
2011 + signal(SIGINT, sigint_handler);
2012 +
2013 + for (i=1; i < argc; i++) {
2014 + if (conf->restrict_to_default_dest) {
2015 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2016 + argv[i],
2017 + conf->default_dest);
2018 + } else {
2019 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2020 + }
2021 +
2022 + if (pkg == NULL) {
2023 + ipkg_message(conf, IPKG_ERROR,
2024 + "Package %s is not installed.\n", argv[i]);
2025 + continue;
2026 + }
2027 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2028 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2029 + pkg->state_flag = pkg_state_flag_from_str(flags);
2030 + }
2031 +/* pb_ asked this feature 03292004 */
2032 +/* Actually I will use only this two, but this is an open for various status */
2033 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2034 + pkg->state_status = pkg_state_status_from_str(flags);
2035 + }
2036 + ipkg_state_changed++;
2037 + ipkg_message(conf, IPKG_NOTICE,
2038 + "Setting flags for package %s to %s\n",
2039 + pkg->name, flags);
2040 + }
2041 +
2042 + write_status_files_if_changed(conf);
2043 + return 0;
2044 +}
2045 +
2046 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2047 +{
2048 + pkg_t *pkg;
2049 + str_list_t *installed_files;
2050 + str_list_elt_t *iter;
2051 + char *pkg_version;
2052 + size_t buff_len = 8192;
2053 + size_t used_len;
2054 + char *buff ;
2055 +
2056 + buff = (char *)malloc(buff_len);
2057 + if ( buff == NULL ) {
2058 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2059 + return ENOMEM;
2060 + }
2061 +
2062 + if (argc < 1) {
2063 + return EINVAL;
2064 + }
2065 +
2066 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2067 + argv[0]);
2068 + if (pkg == NULL) {
2069 + ipkg_message(conf, IPKG_ERROR,
2070 + "Package %s not installed.\n", argv[0]);
2071 + return 0;
2072 + }
2073 +
2074 + installed_files = pkg_get_installed_files(pkg);
2075 + pkg_version = pkg_version_str_alloc(pkg);
2076 +
2077 +#ifndef IPKG_LIB
2078 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2079 + pkg->name, pkg_version, pkg->dest->name);
2080 + for (iter = installed_files->head; iter; iter = iter->next) {
2081 + puts(iter->data);
2082 + }
2083 +#else
2084 + if (buff) {
2085 + try_again:
2086 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2087 + pkg->name, pkg_version, pkg->dest->name) + 1;
2088 + if (used_len > buff_len) {
2089 + buff_len *= 2;
2090 + buff = realloc (buff, buff_len);
2091 + goto try_again;
2092 + }
2093 + for (iter = installed_files->head; iter; iter = iter->next) {
2094 + used_len += strlen (iter->data) + 1;
2095 + while (buff_len <= used_len) {
2096 + buff_len *= 2;
2097 + buff = realloc (buff, buff_len);
2098 + }
2099 + strncat(buff, iter->data, buff_len);
2100 + strncat(buff, "\n", buff_len);
2101 + }
2102 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2103 + buff,
2104 + pkg_version_str_alloc(pkg),
2105 + pkg->state_status,
2106 + p_userdata);
2107 + free(buff);
2108 + }
2109 +#endif
2110 +
2111 + free(pkg_version);
2112 + pkg_free_installed_files(pkg);
2113 +
2114 + return 0;
2115 +}
2116 +
2117 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2118 +{
2119 +
2120 + if (argc > 0) {
2121 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2122 + const char *rel_str = "depends on";
2123 + int i;
2124 +
2125 + pkg_info_preinstall_check(conf);
2126 +
2127 + if (conf->query_all)
2128 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2129 + else
2130 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2131 + for (i = 0; i < argc; i++) {
2132 + const char *target = argv[i];
2133 + int j;
2134 +
2135 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2136 +
2137 + for (j = 0; j < available_pkgs->len; j++) {
2138 + pkg_t *pkg = available_pkgs->pkgs[j];
2139 + if (fnmatch(target, pkg->name, 0) == 0) {
2140 + int k;
2141 + int count = pkg->depends_count + pkg->pre_depends_count;
2142 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2143 + target, pkg->architecture, rel_str);
2144 + for (k = 0; k < count; k++) {
2145 + compound_depend_t *cdepend = &pkg->depends[k];
2146 + int l;
2147 + for (l = 0; l < cdepend->possibility_count; l++) {
2148 + depend_t *possibility = cdepend->possibilities[l];
2149 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2150 + if (conf->verbosity > 0) {
2151 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2152 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2153 + if (possibility->version) {
2154 + char *typestr = NULL;
2155 + switch (possibility->constraint) {
2156 + case NONE: typestr = "none"; break;
2157 + case EARLIER: typestr = "<"; break;
2158 + case EARLIER_EQUAL: typestr = "<="; break;
2159 + case EQUAL: typestr = "="; break;
2160 + case LATER_EQUAL: typestr = ">="; break;
2161 + case LATER: typestr = ">"; break;
2162 + }
2163 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2164 + }
2165 + // free(ver);
2166 + }
2167 + ipkg_message(conf, IPKG_ERROR, "\n");
2168 + }
2169 + }
2170 + }
2171 + }
2172 + }
2173 + pkg_vec_free(available_pkgs);
2174 + }
2175 + return 0;
2176 +}
2177 +
2178 +enum what_field_type {
2179 + WHATDEPENDS,
2180 + WHATCONFLICTS,
2181 + WHATPROVIDES,
2182 + WHATREPLACES,
2183 + WHATRECOMMENDS,
2184 + WHATSUGGESTS
2185 +};
2186 +
2187 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2188 +{
2189 +
2190 + if (argc > 0) {
2191 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2192 + const char *rel_str = NULL;
2193 + int i;
2194 + int changed;
2195 +
2196 + switch (what_field_type) {
2197 + case WHATDEPENDS: rel_str = "depends on"; break;
2198 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2199 + case WHATSUGGESTS: rel_str = "suggests"; break;
2200 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2201 + case WHATPROVIDES: rel_str = "provides"; break;
2202 + case WHATREPLACES: rel_str = "replaces"; break;
2203 + }
2204 +
2205 + if (conf->query_all)
2206 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2207 + else
2208 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2209 +
2210 + /* mark the root set */
2211 + pkg_vec_clear_marks(available_pkgs);
2212 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2213 + for (i = 0; i < argc; i++) {
2214 + const char *dependee_pattern = argv[i];
2215 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2216 + }
2217 + for (i = 0; i < available_pkgs->len; i++) {
2218 + pkg_t *pkg = available_pkgs->pkgs[i];
2219 + if (pkg->state_flag & SF_MARKED) {
2220 + /* mark the parent (abstract) package */
2221 + pkg_mark_provides(pkg);
2222 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2223 + }
2224 + }
2225 +
2226 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2227 + do {
2228 + int j;
2229 + changed = 0;
2230 +
2231 + for (j = 0; j < available_pkgs->len; j++) {
2232 + pkg_t *pkg = available_pkgs->pkgs[j];
2233 + int k;
2234 + int count = ((what_field_type == WHATCONFLICTS)
2235 + ? pkg->conflicts_count
2236 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2237 + /* skip this package if it is already marked */
2238 + if (pkg->parent->state_flag & SF_MARKED) {
2239 + continue;
2240 + }
2241 + for (k = 0; k < count; k++) {
2242 + compound_depend_t *cdepend =
2243 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2244 + int l;
2245 + for (l = 0; l < cdepend->possibility_count; l++) {
2246 + depend_t *possibility = cdepend->possibilities[l];
2247 + if (possibility->pkg->state_flag & SF_MARKED) {
2248 + /* mark the depending package so we won't visit it again */
2249 + pkg->state_flag |= SF_MARKED;
2250 + pkg_mark_provides(pkg);
2251 + changed++;
2252 +
2253 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2254 + if (conf->verbosity > 0) {
2255 + char *ver = pkg_version_str_alloc(pkg);
2256 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2257 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2258 + if (possibility->version) {
2259 + char *typestr = NULL;
2260 + switch (possibility->constraint) {
2261 + case NONE: typestr = "none"; break;
2262 + case EARLIER: typestr = "<"; break;
2263 + case EARLIER_EQUAL: typestr = "<="; break;
2264 + case EQUAL: typestr = "="; break;
2265 + case LATER_EQUAL: typestr = ">="; break;
2266 + case LATER: typestr = ">"; break;
2267 + }
2268 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2269 + }
2270 + free(ver);
2271 + if (!pkg_dependence_satisfiable(conf, possibility))
2272 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2273 + }
2274 + ipkg_message(conf, IPKG_NOTICE, "\n");
2275 + goto next_package;
2276 + }
2277 + }
2278 + }
2279 + next_package:
2280 + ;
2281 + }
2282 + } while (changed && recursive);
2283 + pkg_vec_free(available_pkgs);
2284 + }
2285 +
2286 + return 0;
2287 +}
2288 +
2289 +int pkg_mark_provides(pkg_t *pkg)
2290 +{
2291 + int provides_count = pkg->provides_count;
2292 + abstract_pkg_t **provides = pkg->provides;
2293 + int i;
2294 + pkg->parent->state_flag |= SF_MARKED;
2295 + for (i = 0; i < provides_count; i++) {
2296 + provides[i]->state_flag |= SF_MARKED;
2297 + }
2298 + return 0;
2299 +}
2300 +
2301 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2302 +{
2303 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2304 +}
2305 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2306 +{
2307 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2308 +}
2309 +
2310 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2311 +{
2312 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2313 +}
2314 +
2315 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2316 +{
2317 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2318 +}
2319 +
2320 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2321 +{
2322 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2323 +}
2324 +
2325 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2326 +{
2327 +
2328 + if (argc > 0) {
2329 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2330 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2331 + int i;
2332 +
2333 + pkg_info_preinstall_check(conf);
2334 +
2335 + if (conf->query_all)
2336 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2337 + else
2338 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2339 + for (i = 0; i < argc; i++) {
2340 + const char *target = argv[i];
2341 + int j;
2342 +
2343 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2344 + rel_str, target);
2345 + for (j = 0; j < available_pkgs->len; j++) {
2346 + pkg_t *pkg = available_pkgs->pkgs[j];
2347 + int k;
2348 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2349 + for (k = 0; k < count; k++) {
2350 + abstract_pkg_t *apkg =
2351 + ((what_field_type == WHATPROVIDES)
2352 + ? pkg->provides[k]
2353 + : pkg->replaces[k]);
2354 + if (fnmatch(target, apkg->name, 0) == 0) {
2355 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2356 + if (strcmp(target, apkg->name) != 0)
2357 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2358 + ipkg_message(conf, IPKG_ERROR, "\n");
2359 + }
2360 + }
2361 + }
2362 + }
2363 + pkg_vec_free(available_pkgs);
2364 + }
2365 + return 0;
2366 +}
2367 +
2368 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2369 +{
2370 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2371 +}
2372 +
2373 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2374 +{
2375 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2376 +}
2377 +
2378 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2379 +{
2380 + int i;
2381 +
2382 + pkg_vec_t *installed;
2383 + pkg_t *pkg;
2384 + str_list_t *installed_files;
2385 + str_list_elt_t *iter;
2386 + char *installed_file;
2387 +
2388 + if (argc < 1) {
2389 + return EINVAL;
2390 + }
2391 +
2392 + installed = pkg_vec_alloc();
2393 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2394 +
2395 + for (i=0; i < installed->len; i++) {
2396 + pkg = installed->pkgs[i];
2397 +
2398 + installed_files = pkg_get_installed_files(pkg);
2399 +
2400 + for (iter = installed_files->head; iter; iter = iter->next) {
2401 + installed_file = iter->data;
2402 + if (fnmatch(argv[0], installed_file, 0)==0) {
2403 +#ifndef IPKG_LIB
2404 + printf("%s: %s\n", pkg->name, installed_file);
2405 +#else
2406 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2407 + installed_file,
2408 + pkg_version_str_alloc(pkg),
2409 + pkg->state_status, p_userdata);
2410 +#endif
2411 + }
2412 + }
2413 +
2414 + pkg_free_installed_files(pkg);
2415 + }
2416 +
2417 + /* XXX: CLEANUP: It's not obvious from the name of
2418 + pkg_hash_fetch_all_installed that we need to call
2419 + pkg_vec_free to avoid a memory leak. */
2420 + pkg_vec_free(installed);
2421 +
2422 + return 0;
2423 +}
2424 +
2425 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2426 +{
2427 + if (argc == 3) {
2428 + /* this is a bit gross */
2429 + struct pkg p1, p2;
2430 + parseVersion(&p1, argv[0]);
2431 + parseVersion(&p2, argv[2]);
2432 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2433 + } else {
2434 + ipkg_message(conf, IPKG_ERROR,
2435 + "ipkg compare_versions <v1> <op> <v2>\n"
2436 + "<op> is one of <= >= << >> =\n");
2437 + return -1;
2438 + }
2439 +}
2440 +
2441 +#ifndef HOST_CPU_STR
2442 +#define HOST_CPU_STR__(X) #X
2443 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2444 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2445 +#endif
2446 +
2447 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2448 +{
2449 + nv_pair_list_elt_t *l;
2450 +
2451 + l = conf->arch_list.head;
2452 + while (l) {
2453 + nv_pair_t *nv = l->data;
2454 + printf("arch %s %s\n", nv->name, nv->value);
2455 + l = l->next;
2456 + }
2457 + return 0;
2458 +}
2459 +
2460 +
2461 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_cmd.h busybox-1.3.1-911/archival/libipkg/ipkg_cmd.h
2462 --- busybox-1.3.1-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2463 +++ busybox-1.3.1-911/archival/libipkg/ipkg_cmd.h 2006-12-27 19:41:04.000000000 +0100
2464 @@ -0,0 +1,46 @@
2465 +/* ipkg_cmd.h - the itsy package management system
2466 +
2467 + Carl D. Worth
2468 +
2469 + Copyright (C) 2001 University of Southern California
2470 +
2471 + This program is free software; you can redistribute it and/or
2472 + modify it under the terms of the GNU General Public License as
2473 + published by the Free Software Foundation; either version 2, or (at
2474 + your option) any later version.
2475 +
2476 + This program is distributed in the hope that it will be useful, but
2477 + WITHOUT ANY WARRANTY; without even the implied warranty of
2478 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2479 + General Public License for more details.
2480 +*/
2481 +
2482 +#ifndef IPKG_CMD_H
2483 +#define IPKG_CMD_H
2484 +
2485 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2486 +
2487 +struct ipkg_cmd
2488 +{
2489 + char *name;
2490 + int requires_args;
2491 + ipkg_cmd_fun_t fun;
2492 +};
2493 +typedef struct ipkg_cmd ipkg_cmd_t;
2494 +
2495 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2496 +#ifdef IPKG_LIB
2497 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2498 + const char **argv, void *userdata);
2499 +#else
2500 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2501 +#endif
2502 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2503 +/* install any packges with state_want == SW_INSTALL */
2504 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2505 +/* ensure that all dependences are satisfied */
2506 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2507 +
2508 +int pkg_mark_provides(pkg_t *pkg);
2509 +
2510 +#endif
2511 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_conf.c busybox-1.3.1-911/archival/libipkg/ipkg_conf.c
2512 --- busybox-1.3.1-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2513 +++ busybox-1.3.1-911/archival/libipkg/ipkg_conf.c 2006-12-27 19:41:04.000000000 +0100
2514 @@ -0,0 +1,711 @@
2515 +/* ipkg_conf.c - the itsy package management system
2516 +
2517 + Carl D. Worth
2518 +
2519 + Copyright (C) 2001 University of Southern California
2520 +
2521 + This program is free software; you can redistribute it and/or
2522 + modify it under the terms of the GNU General Public License as
2523 + published by the Free Software Foundation; either version 2, or (at
2524 + your option) any later version.
2525 +
2526 + This program is distributed in the hope that it will be useful, but
2527 + WITHOUT ANY WARRANTY; without even the implied warranty of
2528 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2529 + General Public License for more details.
2530 +*/
2531 +
2532 +#include <glob.h>
2533 +
2534 +#include "ipkg.h"
2535 +#include "ipkg_conf.h"
2536 +
2537 +#include "xregex.h"
2538 +#include "sprintf_alloc.h"
2539 +#include "ipkg_conf.h"
2540 +#include "ipkg_message.h"
2541 +#include "file_util.h"
2542 +#include "str_util.h"
2543 +#include "xsystem.h"
2544 +
2545 +
2546 +ipkg_conf_t *global_conf;
2547 +
2548 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2549 + pkg_src_list_t *pkg_src_list,
2550 + nv_pair_list_t *tmp_dest_nv_pair_list,
2551 + char **tmp_lists_dir);
2552 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2553 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2554 + const char *name, const char *value);
2555 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2556 + const char *default_dest_name);
2557 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2558 + pkg_src_list_t *nv_pair_list);
2559 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2560 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2561 +
2562 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2563 +{
2564 + ipkg_option_t tmp[] = {
2565 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2566 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2567 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2568 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2569 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2570 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2571 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2572 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2573 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2574 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2575 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2576 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2577 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2578 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2579 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2580 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2581 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2582 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2583 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2584 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2585 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2586 + { NULL }
2587 + };
2588 +
2589 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2590 + if ( options == NULL ){
2591 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2592 + return -1;
2593 + }
2594 +
2595 + memcpy(*options, tmp, sizeof(tmp));
2596 + return 0;
2597 +};
2598 +
2599 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2600 +{
2601 + if (arg_str) {
2602 + if (*conf_str) {
2603 + free(*conf_str);
2604 + }
2605 + *conf_str = strdup(arg_str);
2606 + }
2607 +}
2608 +
2609 +static void ipkg_conf_free_string(char **conf_str)
2610 +{
2611 + if (*conf_str) {
2612 + free(*conf_str);
2613 + *conf_str = NULL;
2614 + }
2615 +}
2616 +
2617 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2618 +{
2619 + int err;
2620 + char *tmp_dir_base;
2621 + nv_pair_list_t tmp_dest_nv_pair_list;
2622 + char * lists_dir =NULL;
2623 + glob_t globbuf;
2624 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2625 + char *pending_dir =NULL;
2626 +
2627 + memset(conf, 0, sizeof(ipkg_conf_t));
2628 +
2629 + pkg_src_list_init(&conf->pkg_src_list);
2630 +
2631 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2632 + pkg_dest_list_init(&conf->pkg_dest_list);
2633 +
2634 + nv_pair_list_init(&conf->arch_list);
2635 +
2636 + conf->restrict_to_default_dest = 0;
2637 + conf->default_dest = NULL;
2638 +
2639 +
2640 + if (args->tmp_dir)
2641 + tmp_dir_base = args->tmp_dir;
2642 + else
2643 + tmp_dir_base = getenv("TMPDIR");
2644 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2645 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2646 + IPKG_CONF_TMP_DIR_SUFFIX);
2647 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2648 + if (conf->tmp_dir == NULL) {
2649 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2650 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2651 + return errno;
2652 + }
2653 +
2654 + conf->force_depends = 0;
2655 + conf->force_defaults = 0;
2656 + conf->force_overwrite = 0;
2657 + conf->force_downgrade = 0;
2658 + conf->force_reinstall = 0;
2659 + conf->force_space = 0;
2660 + conf->force_removal_of_essential_packages = 0;
2661 + conf->force_removal_of_dependent_packages = 0;
2662 + conf->nodeps = 0;
2663 + conf->verbose_wget = 0;
2664 + conf->offline_root = NULL;
2665 + conf->offline_root_pre_script_cmd = NULL;
2666 + conf->offline_root_post_script_cmd = NULL;
2667 + conf->multiple_providers = 0;
2668 + conf->verbosity = 1;
2669 + conf->noaction = 0;
2670 +
2671 + conf->http_proxy = NULL;
2672 + conf->ftp_proxy = NULL;
2673 + conf->no_proxy = NULL;
2674 + conf->proxy_user = NULL;
2675 + conf->proxy_passwd = NULL;
2676 +
2677 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2678 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2679 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2680 + lists_dir=(char *)malloc(1);
2681 + lists_dir[0]='\0';
2682 + if (args->conf_file) {
2683 + struct stat stat_buf;
2684 + err = stat(args->conf_file, &stat_buf);
2685 + if (err == 0)
2686 + if (ipkg_conf_parse_file(conf, args->conf_file,
2687 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2688 + /* Memory leakage from ipkg_conf_parse-file */
2689 + return -1;
2690 + }
2691 +
2692 + }
2693 +
2694 + /* if (!lists_dir ){*/
2695 + if (strlen(lists_dir)<=1 ){
2696 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2697 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2698 + }
2699 +
2700 + if (args->offline_root) {
2701 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2702 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2703 + free(lists_dir);
2704 + lists_dir = tmp;
2705 + }
2706 +
2707 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2708 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2709 +
2710 + conf->lists_dir = strdup(lists_dir);
2711 + conf->pending_dir = strdup(pending_dir);
2712 +
2713 + if (args->offline_root)
2714 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2715 + memset(&globbuf, 0, sizeof(globbuf));
2716 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2717 + if (!err) {
2718 + int i;
2719 + for (i = 0; i < globbuf.gl_pathc; i++) {
2720 + if (globbuf.gl_pathv[i])
2721 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2722 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2723 + /* Memory leakage from ipkg_conf_parse-file */
2724 + return -1;
2725 + }
2726 + }
2727 + }
2728 + globfree(&globbuf);
2729 +
2730 + /* if no architectures were defined, then default all, noarch, and host architecture */
2731 + if (nv_pair_list_empty(&conf->arch_list)) {
2732 + nv_pair_list_append(&conf->arch_list, "all", "1");
2733 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2734 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2735 + }
2736 +
2737 + /* Even if there is no conf file, we'll need at least one dest. */
2738 + if (tmp_dest_nv_pair_list.head == NULL) {
2739 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2740 + IPKG_CONF_DEFAULT_DEST_NAME,
2741 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2742 + }
2743 +
2744 + /* After parsing the file, set options from command-line, (so that
2745 + command-line arguments take precedence) */
2746 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2747 + really needs to be cleaned up. There is so much duplication
2748 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2749 + a pointer to args_t (which could then not be freed), rather
2750 + than duplicating every field here? */
2751 + if (args->force_depends) {
2752 + conf->force_depends = 1;
2753 + }
2754 + if (args->force_defaults) {
2755 + conf->force_defaults = 1;
2756 + }
2757 + if (args->force_overwrite) {
2758 + conf->force_overwrite = 1;
2759 + }
2760 + if (args->force_downgrade) {
2761 + conf->force_downgrade = 1;
2762 + }
2763 + if (args->force_reinstall) {
2764 + conf->force_reinstall = 1;
2765 + }
2766 + if (args->force_removal_of_dependent_packages) {
2767 + conf->force_removal_of_dependent_packages = 1;
2768 + }
2769 + if (args->force_removal_of_essential_packages) {
2770 + conf->force_removal_of_essential_packages = 1;
2771 + }
2772 + if (args->nodeps) {
2773 + conf->nodeps = 1;
2774 + }
2775 + if (args->noaction) {
2776 + conf->noaction = 1;
2777 + }
2778 + if (args->query_all) {
2779 + conf->query_all = 1;
2780 + }
2781 + if (args->verbose_wget) {
2782 + conf->verbose_wget = 1;
2783 + }
2784 + if (args->multiple_providers) {
2785 + conf->multiple_providers = 1;
2786 + }
2787 + if (args->verbosity != conf->verbosity) {
2788 + conf->verbosity = args->verbosity;
2789 + }
2790 +
2791 + ipkg_conf_override_string(&conf->offline_root,
2792 + args->offline_root);
2793 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2794 + args->offline_root_pre_script_cmd);
2795 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2796 + args->offline_root_post_script_cmd);
2797 +
2798 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2799 + read anything from there.
2800 +*/
2801 + if ( !(args->nocheckfordirorfile)){
2802 + /* need to run load the source list before dest list -Jamey */
2803 + if ( !(args->noreadfeedsfile))
2804 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2805 +
2806 + /* Now that we have resolved conf->offline_root, we can commit to
2807 + the directory names for the dests and load in all the package
2808 + lists. */
2809 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2810 +
2811 + if (args->dest) {
2812 + err = ipkg_conf_set_default_dest(conf, args->dest);
2813 + if (err) {
2814 + return err;
2815 + }
2816 + }
2817 + }
2818 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2819 + free(lists_dir);
2820 + free(pending_dir);
2821 +
2822 + return 0;
2823 +}
2824 +
2825 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2826 +{
2827 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2828 +#error
2829 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2830 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2831 + __FUNCTION__, conf->tmp_dir);
2832 +#else
2833 + int err;
2834 +
2835 + err = rmdir(conf->tmp_dir);
2836 + if (err) {
2837 + if (errno == ENOTEMPTY) {
2838 + char *cmd;
2839 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2840 + err = xsystem(cmd);
2841 + free(cmd);
2842 + }
2843 + if (err)
2844 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2845 + }
2846 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2847 +
2848 + free(conf->tmp_dir); /*XXX*/
2849 +
2850 + pkg_src_list_deinit(&conf->pkg_src_list);
2851 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2852 + nv_pair_list_deinit(&conf->arch_list);
2853 + if (&conf->pkg_hash)
2854 + pkg_hash_deinit(&conf->pkg_hash);
2855 + if (&conf->file_hash)
2856 + hash_table_deinit(&conf->file_hash);
2857 + if (&conf->obs_file_hash)
2858 + hash_table_deinit(&conf->obs_file_hash);
2859 +
2860 + ipkg_conf_free_string(&conf->offline_root);
2861 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2862 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2863 +
2864 + if (conf->verbosity > 1) {
2865 + int i;
2866 + hash_table_t *hashes[] = {
2867 + &conf->pkg_hash,
2868 + &conf->file_hash,
2869 + &conf->obs_file_hash };
2870 + for (i = 0; i < 3; i++) {
2871 + hash_table_t *hash = hashes[i];
2872 + int c = 0;
2873 + int n_conflicts = 0;
2874 + int j;
2875 + for (j = 0; j < hash->n_entries; j++) {
2876 + int len = 0;
2877 + hash_entry_t *e = &hash->entries[j];
2878 + if (e->next)
2879 + n_conflicts++;
2880 + while (e && e->key) {
2881 + len++;
2882 + e = e->next;
2883 + }
2884 + if (len > c)
2885 + c = len;
2886 + }
2887 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2888 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2889 + hash_table_deinit(hash);
2890 + }
2891 + }
2892 +}
2893 +
2894 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2895 + const char *default_dest_name)
2896 +{
2897 + pkg_dest_list_elt_t *iter;
2898 + pkg_dest_t *dest;
2899 +
2900 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2901 + dest = iter->data;
2902 + if (strcmp(dest->name, default_dest_name) == 0) {
2903 + conf->default_dest = dest;
2904 + conf->restrict_to_default_dest = 1;
2905 + return 0;
2906 + }
2907 + }
2908 +
2909 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2910 +
2911 + return 1;
2912 +}
2913 +
2914 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2915 +{
2916 + pkg_src_list_elt_t *iter;
2917 + pkg_src_t *src;
2918 + char *list_file;
2919 +
2920 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2921 + src = iter->data;
2922 + if (src == NULL) {
2923 + continue;
2924 + }
2925 +
2926 + sprintf_alloc(&list_file, "%s/%s",
2927 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2928 + src->name);
2929 +
2930 + if (file_exists(list_file)) {
2931 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2932 + }
2933 + free(list_file);
2934 + }
2935 +
2936 + return 0;
2937 +}
2938 +
2939 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2940 +{
2941 + nv_pair_list_elt_t *iter;
2942 + nv_pair_t *nv_pair;
2943 + pkg_dest_t *dest;
2944 + char *root_dir;
2945 +
2946 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2947 + nv_pair = iter->data;
2948 +
2949 + if (conf->offline_root) {
2950 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2951 + } else {
2952 + root_dir = strdup(nv_pair->value);
2953 + }
2954 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2955 + free(root_dir);
2956 + if (dest == NULL) {
2957 + continue;
2958 + }
2959 + if (conf->default_dest == NULL) {
2960 + conf->default_dest = dest;
2961 + }
2962 + if (file_exists(dest->status_file_name)) {
2963 + pkg_hash_add_from_file(conf, dest->status_file_name,
2964 + NULL, dest, 1);
2965 + }
2966 + }
2967 +
2968 + return 0;
2969 +}
2970 +
2971 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2972 + pkg_src_list_t *pkg_src_list,
2973 + nv_pair_list_t *tmp_dest_nv_pair_list,
2974 + char **lists_dir)
2975 +{
2976 + ipkg_option_t * options;
2977 + FILE *file = fopen(filename, "r");
2978 + regex_t valid_line_re, comment_re;
2979 +#define regmatch_size 12
2980 + regmatch_t regmatch[regmatch_size];
2981 +
2982 + if (ipkg_init_options_array(conf, &options)<0)
2983 + return ENOMEM;
2984 +
2985 + if (file == NULL) {
2986 + fprintf(stderr, "%s: failed to open %s: %s\n",
2987 + __FUNCTION__, filename, strerror(errno));
2988 + free(options);
2989 + return errno;
2990 + }
2991 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2992 +
2993 + xregcomp(&comment_re,
2994 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2995 + REG_EXTENDED);
2996 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2997 +
2998 + while(1) {
2999 + int line_num = 0;
3000 + char *line;
3001 + char *type, *name, *value, *extra;
3002 +
3003 + line = file_read_line_alloc(file);
3004 + line_num++;
3005 + if (line == NULL) {
3006 + break;
3007 + }
3008 +
3009 + str_chomp(line);
3010 +
3011 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3012 + goto NEXT_LINE;
3013 + }
3014 +
3015 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3016 + str_chomp(line);
3017 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3018 + filename, line_num, line);
3019 + goto NEXT_LINE;
3020 + }
3021 +
3022 + /* This has to be so ugly to deal with optional quotation marks */
3023 + if (regmatch[2].rm_so > 0) {
3024 + type = strndup(line + regmatch[2].rm_so,
3025 + regmatch[2].rm_eo - regmatch[2].rm_so);
3026 + } else {
3027 + type = strndup(line + regmatch[3].rm_so,
3028 + regmatch[3].rm_eo - regmatch[3].rm_so);
3029 + }
3030 + if (regmatch[5].rm_so > 0) {
3031 + name = strndup(line + regmatch[5].rm_so,
3032 + regmatch[5].rm_eo - regmatch[5].rm_so);
3033 + } else {
3034 + name = strndup(line + regmatch[6].rm_so,
3035 + regmatch[6].rm_eo - regmatch[6].rm_so);
3036 + }
3037 + if (regmatch[8].rm_so > 0) {
3038 + value = strndup(line + regmatch[8].rm_so,
3039 + regmatch[8].rm_eo - regmatch[8].rm_so);
3040 + } else {
3041 + value = strndup(line + regmatch[9].rm_so,
3042 + regmatch[9].rm_eo - regmatch[9].rm_so);
3043 + }
3044 + extra = NULL;
3045 + if (regmatch[11].rm_so > 0) {
3046 + extra = strndup (line + regmatch[11].rm_so,
3047 + regmatch[11].rm_eo - regmatch[11].rm_so);
3048 + }
3049 +
3050 + /* We use the tmp_dest_nv_pair_list below instead of
3051 + conf->pkg_dest_list because we might encounter an
3052 + offline_root option later and that would invalidate the
3053 + directories we would have computed in
3054 + pkg_dest_list_init. (We do a similar thing with
3055 + tmp_src_nv_pair_list for sake of symmetry.) */
3056 + if (strcmp(type, "option") == 0) {
3057 + ipkg_conf_set_option(options, name, value);
3058 + } else if (strcmp(type, "src") == 0) {
3059 + if (!nv_pair_list_find(pkg_src_list, name)) {
3060 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3061 + } else {
3062 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3063 + name, value);
3064 + }
3065 + } else if (strcmp(type, "src/gz") == 0) {
3066 + if (!nv_pair_list_find(pkg_src_list, name)) {
3067 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3068 + } else {
3069 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3070 + name, value);
3071 + }
3072 + } else if (strcmp(type, "dest") == 0) {
3073 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3074 + } else if (strcmp(type, "lists_dir") == 0) {
3075 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3076 + if (*lists_dir == NULL) {
3077 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3078 + free(options);
3079 + return EINVAL;
3080 + }
3081 + sprintf (*lists_dir,"%s",value);
3082 + } else if (strcmp(type, "arch") == 0) {
3083 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3084 + if (!value) {
3085 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3086 + value = strdup("10");
3087 + }
3088 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3089 + } else {
3090 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3091 + "parameter: %s %s %s\n", type, name, value);
3092 + free(options);
3093 + return EINVAL;
3094 + }
3095 +
3096 + free(type);
3097 + free(name);
3098 + free(value);
3099 + if (extra)
3100 + free (extra);
3101 +
3102 + NEXT_LINE:
3103 + free(line);
3104 + }
3105 +
3106 + free(options);
3107 + regfree(&comment_re);
3108 + regfree(&valid_line_re);
3109 + fclose(file);
3110 +
3111 + return 0;
3112 +}
3113 +
3114 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3115 + const char *name, const char *value)
3116 +{
3117 + int i = 0;
3118 + while (options[i].name) {
3119 + if (strcmp(options[i].name, name) == 0) {
3120 + switch (options[i].type) {
3121 + case IPKG_OPT_TYPE_BOOL:
3122 + *((int *)options[i].value) = 1;
3123 + return 0;
3124 + case IPKG_OPT_TYPE_INT:
3125 + if (value) {
3126 + *((int *)options[i].value) = atoi(value);
3127 + return 0;
3128 + } else {
3129 + printf("%s: Option %s need an argument\n",
3130 + __FUNCTION__, name);
3131 + return EINVAL;
3132 + }
3133 + case IPKG_OPT_TYPE_STRING:
3134 + if (value) {
3135 + *((char **)options[i].value) = strdup(value);
3136 + return 0;
3137 + } else {
3138 + printf("%s: Option %s need an argument\n",
3139 + __FUNCTION__, name);
3140 + return EINVAL;
3141 + }
3142 + }
3143 + }
3144 + i++;
3145 + }
3146 +
3147 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3148 + __FUNCTION__, name, value);
3149 + return EINVAL;
3150 +}
3151 +
3152 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3153 +{
3154 + pkg_dest_list_elt_t *iter;
3155 + pkg_dest_t *dest;
3156 + pkg_vec_t *all;
3157 + pkg_t *pkg;
3158 + register int i;
3159 + int err;
3160 +
3161 + if (conf->noaction)
3162 + return 0;
3163 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3164 + dest = iter->data;
3165 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3166 + if (dest->status_file == NULL) {
3167 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3168 + __FUNCTION__, dest->status_file_name, strerror(errno));
3169 + }
3170 + }
3171 +
3172 + all = pkg_vec_alloc();
3173 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3174 +
3175 + for(i = 0; i < all->len; i++) {
3176 + pkg = all->pkgs[i];
3177 + /* We don't need most uninstalled packages in the status file */
3178 + if (pkg->state_status == SS_NOT_INSTALLED
3179 + && (pkg->state_want == SW_UNKNOWN
3180 + || pkg->state_want == SW_DEINSTALL
3181 + || pkg->state_want == SW_PURGE)) {
3182 + continue;
3183 + }
3184 + if (!pkg) {
3185 + fprintf(stderr, "Null package\n");
3186 + }
3187 + if (pkg->dest == NULL) {
3188 + fprintf(stderr, "%s: ERROR: Can't write status for "
3189 + "package %s since it has a NULL dest\n",
3190 + __FUNCTION__, pkg->name);
3191 + continue;
3192 + }
3193 + if (pkg->dest->status_file) {
3194 + pkg_print_status(pkg, pkg->dest->status_file);
3195 + }
3196 + }
3197 +
3198 + pkg_vec_free(all);
3199 +
3200 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3201 + dest = iter->data;
3202 + if (dest->status_file) {
3203 + err = ferror(dest->status_file);
3204 + fclose(dest->status_file);
3205 + dest->status_file = NULL;
3206 + if (!err) {
3207 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3208 + } else {
3209 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3210 + "retaining old %s\n", __FUNCTION__,
3211 + dest->status_file_tmp_name, dest->status_file_name);
3212 + }
3213 + }
3214 + }
3215 +
3216 + return 0;
3217 +}
3218 +
3219 +
3220 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3221 +{
3222 + char *root_filename;
3223 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3224 + return root_filename;
3225 +}
3226 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_conf.h busybox-1.3.1-911/archival/libipkg/ipkg_conf.h
3227 --- busybox-1.3.1-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3228 +++ busybox-1.3.1-911/archival/libipkg/ipkg_conf.h 2006-12-27 19:41:04.000000000 +0100
3229 @@ -0,0 +1,107 @@
3230 +/* ipkg_conf.h - the itsy package management system
3231 +
3232 + Carl D. Worth
3233 +
3234 + Copyright (C) 2001 University of Southern California
3235 +
3236 + This program is free software; you can redistribute it and/or
3237 + modify it under the terms of the GNU General Public License as
3238 + published by the Free Software Foundation; either version 2, or (at
3239 + your option) any later version.
3240 +
3241 + This program is distributed in the hope that it will be useful, but
3242 + WITHOUT ANY WARRANTY; without even the implied warranty of
3243 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3244 + General Public License for more details.
3245 +*/
3246 +
3247 +#ifndef IPKG_CONF_H
3248 +#define IPKG_CONF_H
3249 +
3250 +typedef struct ipkg_conf ipkg_conf_t;
3251 +
3252 +#include "hash_table.h"
3253 +#include "ipkg.h"
3254 +#include "args.h"
3255 +#include "pkg.h"
3256 +#include "pkg_hash.h"
3257 +#include "pkg_src_list.h"
3258 +#include "pkg_dest_list.h"
3259 +#include "nv_pair_list.h"
3260 +
3261 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3262 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3263 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3264 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3265 +
3266 +/* In case the config file defines no dest */
3267 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3268 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3269 +
3270 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3271 +
3272 +struct ipkg_conf
3273 +{
3274 + pkg_src_list_t pkg_src_list;
3275 + pkg_dest_list_t pkg_dest_list;
3276 + nv_pair_list_t arch_list;
3277 +
3278 + int restrict_to_default_dest;
3279 + pkg_dest_t *default_dest;
3280 +
3281 + char *tmp_dir;
3282 + const char *lists_dir;
3283 + const char *pending_dir;
3284 +
3285 + /* options */
3286 + int force_depends;
3287 + int force_defaults;
3288 + int force_overwrite;
3289 + int force_downgrade;
3290 + int force_reinstall;
3291 + int force_space;
3292 + int force_removal_of_dependent_packages;
3293 + int force_removal_of_essential_packages;
3294 + int nodeps; /* do not follow dependences */
3295 + int verbose_wget;
3296 + int multiple_providers;
3297 + char *offline_root;
3298 + char *offline_root_pre_script_cmd;
3299 + char *offline_root_post_script_cmd;
3300 + int query_all;
3301 + int verbosity;
3302 + int noaction;
3303 +
3304 + /* proxy options */
3305 + char *http_proxy;
3306 + char *ftp_proxy;
3307 + char *no_proxy;
3308 + char *proxy_user;
3309 + char *proxy_passwd;
3310 +
3311 + hash_table_t pkg_hash;
3312 + hash_table_t file_hash;
3313 + hash_table_t obs_file_hash;
3314 +};
3315 +
3316 +enum ipkg_option_type {
3317 + IPKG_OPT_TYPE_BOOL,
3318 + IPKG_OPT_TYPE_INT,
3319 + IPKG_OPT_TYPE_STRING
3320 +};
3321 +typedef enum ipkg_option_type ipkg_option_type_t;
3322 +
3323 +typedef struct ipkg_option ipkg_option_t;
3324 +struct ipkg_option {
3325 + const char *name;
3326 + const ipkg_option_type_t type;
3327 + const void *value;
3328 +};
3329 +
3330 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3331 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3332 +
3333 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3334 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3335 +
3336 +#endif
3337 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_configure.c busybox-1.3.1-911/archival/libipkg/ipkg_configure.c
3338 --- busybox-1.3.1-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3339 +++ busybox-1.3.1-911/archival/libipkg/ipkg_configure.c 2006-12-27 19:41:04.000000000 +0100
3340 @@ -0,0 +1,40 @@
3341 +/* ipkg_configure.c - the itsy package management system
3342 +
3343 + Carl D. Worth
3344 +
3345 + Copyright (C) 2001 University of Southern California
3346 +
3347 + This program is free software; you can redistribute it and/or
3348 + modify it under the terms of the GNU General Public License as
3349 + published by the Free Software Foundation; either version 2, or (at
3350 + your option) any later version.
3351 +
3352 + This program is distributed in the hope that it will be useful, but
3353 + WITHOUT ANY WARRANTY; without even the implied warranty of
3354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3355 + General Public License for more details.
3356 +*/
3357 +
3358 +#include "ipkg.h"
3359 +
3360 +#include "ipkg_configure.h"
3361 +
3362 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3363 +{
3364 + int err;
3365 +
3366 + /* DPKG_INCOMPATIBILITY:
3367 + dpkg actually does some conffile handling here, rather than at the
3368 + end of ipkg_install(). Do we care? */
3369 + /* DPKG_INCOMPATIBILITY:
3370 + dpkg actually includes a version number to this script call */
3371 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3372 + if (err) {
3373 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3374 + return err;
3375 + }
3376 +
3377 + ipkg_state_changed++;
3378 + return 0;
3379 +}
3380 +
3381 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_configure.h busybox-1.3.1-911/archival/libipkg/ipkg_configure.h
3382 --- busybox-1.3.1-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3383 +++ busybox-1.3.1-911/archival/libipkg/ipkg_configure.h 2006-12-27 19:41:04.000000000 +0100
3384 @@ -0,0 +1,25 @@
3385 +/* ipkg_configure.h - the itsy package management system
3386 +
3387 + Carl D. Worth
3388 +
3389 + Copyright (C) 2001 University of Southern California
3390 +
3391 + This program is free software; you can redistribute it and/or
3392 + modify it under the terms of the GNU General Public License as
3393 + published by the Free Software Foundation; either version 2, or (at
3394 + your option) any later version.
3395 +
3396 + This program is distributed in the hope that it will be useful, but
3397 + WITHOUT ANY WARRANTY; without even the implied warranty of
3398 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3399 + General Public License for more details.
3400 +*/
3401 +
3402 +#ifndef IPKG_CONFIGURE_H
3403 +#define IPKG_CONFIGURE_H
3404 +
3405 +#include "ipkg_conf.h"
3406 +
3407 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3408 +
3409 +#endif
3410 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_download.c busybox-1.3.1-911/archival/libipkg/ipkg_download.c
3411 --- busybox-1.3.1-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3412 +++ busybox-1.3.1-911/archival/libipkg/ipkg_download.c 2006-12-27 19:41:04.000000000 +0100
3413 @@ -0,0 +1,195 @@
3414 +/* ipkg_download.c - the itsy package management system
3415 +
3416 + Carl D. Worth
3417 +
3418 + Copyright (C) 2001 University of Southern California
3419 +
3420 + This program is free software; you can redistribute it and/or
3421 + modify it under the terms of the GNU General Public License as
3422 + published by the Free Software Foundation; either version 2, or (at
3423 + your option) any later version.
3424 +
3425 + This program is distributed in the hope that it will be useful, but
3426 + WITHOUT ANY WARRANTY; without even the implied warranty of
3427 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3428 + General Public License for more details.
3429 +*/
3430 +
3431 +#include "ipkg.h"
3432 +#include "ipkg_download.h"
3433 +#include "ipkg_message.h"
3434 +
3435 +#include "sprintf_alloc.h"
3436 +#include "xsystem.h"
3437 +#include "file_util.h"
3438 +#include "str_util.h"
3439 +
3440 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3441 +{
3442 + int err = 0;
3443 +
3444 + char *src_basec = strdup(src);
3445 + char *src_base = basename(src_basec);
3446 + char *tmp_file_location;
3447 + char *cmd;
3448 +
3449 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3450 +
3451 + fflush(stdout);
3452 +
3453 + if (str_starts_with(src, "file:")) {
3454 + int ret;
3455 + const char *file_src = src + 5;
3456 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3457 + ret = file_copy(src + 5, dest_file_name);
3458 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3459 + return ret;
3460 + }
3461 +
3462 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3463 + err = unlink(tmp_file_location);
3464 + if (err && errno != ENOENT) {
3465 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3466 + __FUNCTION__, tmp_file_location, strerror(errno));
3467 + free(tmp_file_location);
3468 + return errno;
3469 + }
3470 +
3471 + if (conf->http_proxy) {
3472 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3473 + setenv("http_proxy", conf->http_proxy, 1);
3474 + }
3475 + if (conf->ftp_proxy) {
3476 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3477 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3478 + }
3479 + if (conf->no_proxy) {
3480 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3481 + setenv("no_proxy", conf->no_proxy, 1);
3482 + }
3483 +
3484 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3485 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3486 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3487 + conf->proxy_user ? "--proxy-user=" : "",
3488 + conf->proxy_user ? conf->proxy_user : "",
3489 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3490 + conf->proxy_passwd ? conf->proxy_passwd : "",
3491 + conf->verbose_wget ? "" : "-q",
3492 + conf->tmp_dir,
3493 + src);
3494 + err = xsystem(cmd);
3495 + if (err) {
3496 + if (err != -1) {
3497 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3498 + __FUNCTION__, err, cmd);
3499 + }
3500 + unlink(tmp_file_location);
3501 + free(tmp_file_location);
3502 + free(src_basec);
3503 + free(cmd);
3504 + return EINVAL;
3505 + }
3506 + free(cmd);
3507 +
3508 + err = file_move(tmp_file_location, dest_file_name);
3509 +
3510 + free(tmp_file_location);
3511 + free(src_basec);
3512 +
3513 + if (err) {
3514 + return err;
3515 + }
3516 +
3517 + return 0;
3518 +}
3519 +
3520 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3521 +{
3522 + int err;
3523 + char *url;
3524 +
3525 + if (pkg->src == NULL) {
3526 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3527 + pkg->name, pkg->parent->name);
3528 + return -1;
3529 + }
3530 +
3531 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3532 +
3533 + /* XXX: BUG: The pkg->filename might be something like
3534 + "../../foo.ipk". While this is correct, and exactly what we
3535 + want to use to construct url above, here we actually need to
3536 + use just the filename part, without any directory. */
3537 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3538 +
3539 + err = ipkg_download(conf, url, pkg->local_filename);
3540 + free(url);
3541 +
3542 + return err;
3543 +}
3544 +
3545 +/*
3546 + * Downloads file from url, installs in package database, return package name.
3547 + */
3548 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3549 +{
3550 + int err = 0;
3551 + pkg_t *pkg;
3552 + pkg = pkg_new();
3553 + if (pkg == NULL)
3554 + return ENOMEM;
3555 +
3556 + if (str_starts_with(url, "http://")
3557 + || str_starts_with(url, "ftp://")) {
3558 + char *tmp_file;
3559 + char *file_basec = strdup(url);
3560 + char *file_base = basename(file_basec);
3561 +
3562 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3563 + err = ipkg_download(conf, url, tmp_file);
3564 + if (err)
3565 + return err;
3566 +
3567 + err = pkg_init_from_file(pkg, tmp_file);
3568 + if (err)
3569 + return err;
3570 + pkg->local_filename = strdup(tmp_file);
3571 +
3572 + free(tmp_file);
3573 + free(file_basec);
3574 +
3575 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3576 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3577 +
3578 + err = pkg_init_from_file(pkg, url);
3579 + if (err)
3580 + return err;
3581 + pkg->local_filename = strdup(url);
3582 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3583 + pkg->provided_by_hand = 1;
3584 +
3585 + } else {
3586 + pkg_deinit(pkg);
3587 + free(pkg);
3588 + return 0;
3589 + }
3590 +
3591 + if (!pkg->architecture) {
3592 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3593 + return -EINVAL;
3594 + }
3595 +
3596 + pkg->dest = conf->default_dest;
3597 + pkg->state_want = SW_INSTALL;
3598 + pkg->state_flag |= SF_PREFER;
3599 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3600 + if ( pkg == NULL ){
3601 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3602 + return 0;
3603 + }
3604 + if (namep) {
3605 + *namep = strdup(pkg->name);
3606 + }
3607 + return 0;
3608 +}
3609 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_download.h busybox-1.3.1-911/archival/libipkg/ipkg_download.h
3610 --- busybox-1.3.1-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3611 +++ busybox-1.3.1-911/archival/libipkg/ipkg_download.h 2006-12-27 19:41:04.000000000 +0100
3612 @@ -0,0 +1,30 @@
3613 +/* ipkg_download.h - the itsy package management system
3614 +
3615 + Carl D. Worth
3616 +
3617 + Copyright (C) 2001 University of Southern California
3618 +
3619 + This program is free software; you can redistribute it and/or
3620 + modify it under the terms of the GNU General Public License as
3621 + published by the Free Software Foundation; either version 2, or (at
3622 + your option) any later version.
3623 +
3624 + This program is distributed in the hope that it will be useful, but
3625 + WITHOUT ANY WARRANTY; without even the implied warranty of
3626 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3627 + General Public License for more details.
3628 +*/
3629 +
3630 +#ifndef IPKG_DOWNLOAD_H
3631 +#define IPKG_DOWNLOAD_H
3632 +
3633 +#include "ipkg_conf.h"
3634 +
3635 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3636 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3637 +/*
3638 + * Downloads file from url, installs in package database, return package name.
3639 + */
3640 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3641 +
3642 +#endif
3643 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg.h busybox-1.3.1-911/archival/libipkg/ipkg.h
3644 --- busybox-1.3.1-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3645 +++ busybox-1.3.1-911/archival/libipkg/ipkg.h 2006-12-27 19:41:04.000000000 +0100
3646 @@ -0,0 +1,74 @@
3647 +/* ipkg.h - the itsy package management system
3648 +
3649 + Carl D. Worth
3650 +
3651 + Copyright (C) 2001 University of Southern California
3652 +
3653 + This program is free software; you can redistribute it and/or
3654 + modify it under the terms of the GNU General Public License as
3655 + published by the Free Software Foundation; either version 2, or (at
3656 + your option) any later version.
3657 +
3658 + This program is distributed in the hope that it will be useful, but
3659 + WITHOUT ANY WARRANTY; without even the implied warranty of
3660 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3661 + General Public License for more details.
3662 +*/
3663 +
3664 +#ifndef IPKG_H
3665 +#define IPKG_H
3666 +
3667 +/*
3668 +#ifdef HAVE_CONFIG_H
3669 +#include "config.h"
3670 +#endif
3671 +*/
3672 +
3673 +#if 0
3674 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3675 +#endif
3676 +
3677 +#include "ipkg_includes.h"
3678 +#include "ipkg_conf.h"
3679 +#include "ipkg_message.h"
3680 +
3681 +#define IPKG_PKG_EXTENSION ".ipk"
3682 +#define DPKG_PKG_EXTENSION ".deb"
3683 +
3684 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3685 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3686 +
3687 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3688 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3689 +#define IPKG_INFO_DIR_SUFFIX "info"
3690 +#define IPKG_STATUS_FILE_SUFFIX "status"
3691 +
3692 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3693 +
3694 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3695 +
3696 +#define IPKG_VERSION "0.99.162"
3697 +
3698 +
3699 +enum ipkg_error {
3700 + IPKG_SUCCESS = 0,
3701 + IPKG_PKG_DEPS_UNSATISFIED,
3702 + IPKG_PKG_IS_ESSENTIAL,
3703 + IPKG_PKG_HAS_DEPENDENTS,
3704 + IPKG_PKG_HAS_NO_CANDIDATE
3705 +};
3706 +typedef enum ipkg_error ipkg_error_t;
3707 +
3708 +extern int ipkg_state_changed;
3709 +
3710 +
3711 +struct errlist {
3712 + char * errmsg;
3713 + struct errlist * next;
3714 +} ;
3715 +
3716 +extern struct errlist* error_list;
3717 +
3718 +extern ipkg_conf_t *global_conf;
3719 +
3720 +#endif
3721 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_includes.h busybox-1.3.1-911/archival/libipkg/ipkg_includes.h
3722 --- busybox-1.3.1-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3723 +++ busybox-1.3.1-911/archival/libipkg/ipkg_includes.h 2006-12-27 19:41:04.000000000 +0100
3724 @@ -0,0 +1,79 @@
3725 +#ifndef IPKG_INCLUDES_H
3726 +#define IPKG_INCLUDES_H
3727 +
3728 +/* Define to 1 if you have the <memory.h> header file. */
3729 +#define HAVE_MEMORY_H 1
3730 +
3731 +/* Define to 1 if you have the <regex.h> header file. */
3732 +#define HAVE_REGEX_H 1
3733 +
3734 +/* Define to 1 if you have the <stdlib.h> header file. */
3735 +#define HAVE_STDLIB_H 1
3736 +
3737 +/* Define to 1 if you have the <strings.h> header file. */
3738 +#define HAVE_STRINGS_H 1
3739 +
3740 +/* Define to 1 if you have the <string.h> header file. */
3741 +#define HAVE_STRING_H 1
3742 +
3743 +/* Define to 1 if you have the <sys/stat.h> header file. */
3744 +#define HAVE_SYS_STAT_H 1
3745 +
3746 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3747 +#define HAVE_SYS_WAIT_H 1
3748 +
3749 +/* Define to 1 if you have the <unistd.h> header file. */
3750 +#define HAVE_UNISTD_H 1
3751 +
3752 +/* Define to 1 if you have the ANSI C header files. */
3753 +#define STDC_HEADERS 1
3754 +
3755 +
3756 +#include <stdio.h>
3757 +
3758 +#if STDC_HEADERS
3759 +# include <stdlib.h>
3760 +# include <stdarg.h>
3761 +# include <stddef.h>
3762 +# include <ctype.h>
3763 +# include <errno.h>
3764 +#else
3765 +# if HAVE_STDLIB_H
3766 +# include <stdlib.h>
3767 +# endif
3768 +#endif
3769 +
3770 +#if HAVE_REGEX_H
3771 +# include <regex.h>
3772 +#endif
3773 +
3774 +#if HAVE_STRING_H
3775 +# if !STDC_HEADERS && HAVE_MEMORY_H
3776 +# include <memory.h>
3777 +# endif
3778 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3779 +# if __GNUC__
3780 +# define __USE_GNU 1
3781 +# endif
3782 +# include <string.h>
3783 +# undef __USE_GNU
3784 +#endif
3785 +
3786 +#if HAVE_STRINGS_H
3787 +# include <strings.h>
3788 +#endif
3789 +
3790 +#if HAVE_SYS_STAT_H
3791 +# include <sys/stat.h>
3792 +#endif
3793 +
3794 +#if HAVE_SYS_WAIT_H
3795 +# include <sys/wait.h>
3796 +#endif
3797 +
3798 +#if HAVE_UNISTD_H
3799 +# include <sys/types.h>
3800 +# include <unistd.h>
3801 +#endif
3802 +
3803 +#endif /* IPKG_INCLUDES_H */
3804 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_install.c busybox-1.3.1-911/archival/libipkg/ipkg_install.c
3805 --- busybox-1.3.1-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3806 +++ busybox-1.3.1-911/archival/libipkg/ipkg_install.c 2006-12-28 02:28:27.000000000 +0100
3807 @@ -0,0 +1,1942 @@
3808 +/* ipkg_install.c - the itsy package management system
3809 +
3810 + Carl D. Worth
3811 +
3812 + Copyright (C) 2001 University of Southern California
3813 +
3814 + This program is free software; you can redistribute it and/or
3815 + modify it under the terms of the GNU General Public License as
3816 + published by the Free Software Foundation; either version 2, or (at
3817 + your option) any later version.
3818 +
3819 + This program is distributed in the hope that it will be useful, but
3820 + WITHOUT ANY WARRANTY; without even the implied warranty of
3821 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3822 + General Public License for more details.
3823 +*/
3824 +
3825 +#include "ipkg.h"
3826 +#include <errno.h>
3827 +#include <dirent.h>
3828 +#include <glob.h>
3829 +#include <time.h>
3830 +#include <signal.h>
3831 +typedef void (*sighandler_t)(int);
3832 +
3833 +#include "pkg.h"
3834 +#include "pkg_hash.h"
3835 +#include "pkg_extract.h"
3836 +
3837 +#include "ipkg_install.h"
3838 +#include "ipkg_configure.h"
3839 +#include "ipkg_download.h"
3840 +#include "ipkg_remove.h"
3841 +
3842 +#include "ipkg_utils.h"
3843 +#include "ipkg_message.h"
3844 +
3845 +#include "sprintf_alloc.h"
3846 +#include "file_util.h"
3847 +#include "str_util.h"
3848 +#include "xsystem.h"
3849 +#include "user.h"
3850 +
3851 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3852 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3853 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3854 +
3855 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3856 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3857 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3858 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3859 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3860 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3861 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3862 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3863 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3864 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3865 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3866 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3867 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3868 +
3869 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3870 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3871 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3872 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3873 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3874 +
3875 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3876 +
3877 +static int user_prefers_old_conffile(const char *file, const char *backup);
3878 +
3879 +static char *backup_filename_alloc(const char *file_name);
3880 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3881 +static int backup_exists_for(const char *file_name);
3882 +static int backup_remove(const char *file_name);
3883 +
3884 +
3885 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3886 +{
3887 + int err, cmp;
3888 + pkg_t *pkg, *old;
3889 + char *old_version, *new_version;
3890 +
3891 + pkg = pkg_new();
3892 + if (pkg == NULL) {
3893 + return ENOMEM;
3894 + }
3895 +
3896 + err = pkg_init_from_file(pkg, filename);
3897 + if (err) {
3898 + return err;
3899 + }
3900 +
3901 + if (!pkg->architecture) {
3902 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3903 + return -EINVAL;
3904 + }
3905 +
3906 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3907 + freeing the pkg that we pass in. It might be nice to clean this up
3908 + if possible. */
3909 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3910 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3911 +
3912 + pkg->local_filename = strdup(filename);
3913 +
3914 + if (old) {
3915 + old_version = pkg_version_str_alloc(old);
3916 + new_version = pkg_version_str_alloc(pkg);
3917 +
3918 + cmp = pkg_compare_versions(old, pkg);
3919 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3920 + cmp = -1 ; /* then we force ipkg to downgrade */
3921 + /* We need to use a value < 0 because in the 0 case we are asking to */
3922 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3923 + }
3924 + if (cmp > 0) {
3925 + ipkg_message(conf, IPKG_NOTICE,
3926 + "Not downgrading package %s on %s from %s to %s.\n",
3927 + old->name, old->dest->name, old_version, new_version);
3928 + pkg->state_want = SW_DEINSTALL;
3929 + pkg->state_flag |= SF_OBSOLETE;
3930 + free(old_version);
3931 + free(new_version);
3932 + return 0;
3933 + } else {
3934 + free(old_version);
3935 + free(new_version);
3936 + }
3937 + }
3938 +
3939 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3940 + return ipkg_install_pkg(conf, pkg,0);
3941 +}
3942 +
3943 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3944 +{
3945 + int cmp;
3946 + pkg_t *old, *new;
3947 + char *old_version, *new_version;
3948 +
3949 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3950 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3951 + if ( old )
3952 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3953 +
3954 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3955 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3956 + if ( new )
3957 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3958 +
3959 +/* Pigi Basically here is broken the version stuff.
3960 + What's happening is that nothing provide the version to differents
3961 + functions, so the returned struct is always the latest.
3962 + That's why the install by name don't work.
3963 +*/
3964 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3965 +
3966 + if ( old )
3967 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3968 + if ( new )
3969 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3970 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3971 +
3972 + if (new == NULL) {
3973 + return IPKG_PKG_HAS_NO_CANDIDATE;
3974 + }
3975 +
3976 + new->state_flag |= SF_USER;
3977 + if (old) {
3978 + old_version = pkg_version_str_alloc(old);
3979 + new_version = pkg_version_str_alloc(new);
3980 +
3981 + cmp = pkg_compare_versions(old, new);
3982 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3983 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3984 + cmp = -1 ; /* then we force ipkg to downgrade */
3985 + /* We need to use a value < 0 because in the 0 case we are asking to */
3986 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3987 + }
3988 + ipkg_message(conf, IPKG_DEBUG,
3989 + "Comparing visible versions of pkg %s:"
3990 + "\n\t%s is installed "
3991 + "\n\t%s is available "
3992 + "\n\t%d was comparison result\n",
3993 + pkg_name, old_version, new_version, cmp);
3994 + if (cmp == 0 && !conf->force_reinstall) {
3995 + ipkg_message(conf, IPKG_NOTICE,
3996 + "Package %s (%s) installed in %s is up to date.\n",
3997 + old->name, old_version, old->dest->name);
3998 + free(old_version);
3999 + free(new_version);
4000 + return 0;
4001 + } else if (cmp > 0) {
4002 + ipkg_message(conf, IPKG_NOTICE,
4003 + "Not downgrading package %s on %s from %s to %s.\n",
4004 + old->name, old->dest->name, old_version, new_version);
4005 + free(old_version);
4006 + free(new_version);
4007 + return 0;
4008 + } else if (cmp < 0) {
4009 + new->dest = old->dest;
4010 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4011 + }
4012 + }
4013 +
4014 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4015 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4016 + return any kind of integer, (might be errno from a syscall,
4017 + etc.). This is a real mess and will need to be cleaned up if
4018 + anyone ever wants to make a nice libipkg. */
4019 +
4020 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4021 + return ipkg_install_pkg(conf, new,0);
4022 +}
4023 +
4024 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4025 +{
4026 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4027 + int i;
4028 + ipkg_error_t err;
4029 + abstract_pkg_t *ppkg ;
4030 +
4031 + if (providers == NULL)
4032 + return IPKG_PKG_HAS_NO_CANDIDATE;
4033 +
4034 + for (i = 0; i < providers->len; i++) {
4035 + ppkg = abstract_pkg_vec_get(providers, i);
4036 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4037 + err = ipkg_install_by_name(conf, ppkg->name);
4038 + if (err)
4039 + return err;
4040 +/* XXX Maybe ppkg should be freed ? */
4041 + }
4042 + return 0;
4043 +}
4044 +
4045 +/*
4046 + * Walk dependence graph starting with pkg, collect packages to be
4047 + * installed into pkgs_needed, in dependence order.
4048 + */
4049 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4050 +{
4051 + int i, err;
4052 + pkg_vec_t *depends = pkg_vec_alloc();
4053 + char **unresolved = NULL;
4054 + int ndepends;
4055 +
4056 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4057 + pkg, depends,
4058 + &unresolved);
4059 +
4060 + if (unresolved) {
4061 + ipkg_message(conf, IPKG_ERROR,
4062 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4063 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4064 + while (*unresolved) {
4065 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4066 + unresolved++;
4067 + }
4068 + ipkg_message(conf, IPKG_ERROR, "\n");
4069 + if (! conf->force_depends) {
4070 + ipkg_message(conf, IPKG_INFO,
4071 + "This could mean that your package list is out of date or that the packages\n"
4072 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4073 + "of this problem try again with the '-force-depends' option.\n");
4074 + pkg_vec_free(depends);
4075 + return IPKG_PKG_DEPS_UNSATISFIED;
4076 + }
4077 + }
4078 +
4079 + if (ndepends <= 0) {
4080 + pkg_vec_free(depends);
4081 + return 0;
4082 + }
4083 +
4084 + for (i = 0; i < depends->len; i++) {
4085 + pkg_t *dep = depends->pkgs[i];
4086 + /* The package was uninstalled when we started, but another
4087 + dep earlier in this loop may have depended on it and pulled
4088 + it in, so check first. */
4089 + if ((dep->state_status != SS_INSTALLED)
4090 + && (dep->state_status != SS_UNPACKED)
4091 + && (dep->state_want != SW_INSTALL)) {
4092 +
4093 + /* Mark packages as to-be-installed */
4094 + dep->state_want = SW_INSTALL;
4095 +
4096 + /* Dependencies should be installed the same place as pkg */
4097 + if (dep->dest == NULL) {
4098 + dep->dest = pkg->dest;
4099 + }
4100 +
4101 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4102 + if (err) {
4103 + pkg_vec_free(depends);
4104 + return err;
4105 + }
4106 + }
4107 + }
4108 + if (pkgs_needed)
4109 + pkg_vec_insert(pkgs_needed, pkg);
4110 +
4111 + pkg_vec_free(depends);
4112 +
4113 + return 0;
4114 +}
4115 +
4116 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4117 +{
4118 + int cmp;
4119 + pkg_t *old, *new;
4120 + char *old_version, *new_version;
4121 +
4122 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4123 +
4124 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4125 + if (new == NULL) {
4126 + return IPKG_PKG_HAS_NO_CANDIDATE;
4127 + }
4128 + if (old) {
4129 + old_version = pkg_version_str_alloc(old);
4130 + new_version = pkg_version_str_alloc(new);
4131 +
4132 + cmp = pkg_compare_versions(old, new);
4133 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4134 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4135 + cmp = -1 ; /* then we force ipkg to downgrade */
4136 + /* We need to use a value < 0 because in the 0 case we are asking to */
4137 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4138 + }
4139 + ipkg_message(conf, IPKG_DEBUG,
4140 + "comparing visible versions of pkg %s:"
4141 + "\n\t%s is installed "
4142 + "\n\t%s is available "
4143 + "\n\t%d was comparison result\n",
4144 + pkg_name, old_version, new_version, cmp);
4145 + if (cmp == 0 && !conf->force_reinstall) {
4146 + ipkg_message(conf, IPKG_NOTICE,
4147 + "Package %s (%s) installed in %s is up to date.\n",
4148 + old->name, old_version, old->dest->name);
4149 + free(old_version);
4150 + free(new_version);
4151 + return 0;
4152 + } else if (cmp > 0) {
4153 + ipkg_message(conf, IPKG_NOTICE,
4154 + "Not downgrading package %s on %s from %s to %s.\n",
4155 + old->name, old->dest->name, old_version, new_version);
4156 + free(old_version);
4157 + free(new_version);
4158 + return 0;
4159 + } else if (cmp < 0) {
4160 + new->dest = old->dest;
4161 + old->state_want = SW_DEINSTALL;
4162 + old->state_flag |= SF_OBSOLETE;
4163 + }
4164 + }
4165 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4166 +}
4167 +
4168 +\f
4169 +
4170 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4171 +{
4172 + int i, err;
4173 + pkg_vec_t *depends = pkg_vec_alloc();
4174 + pkg_t *dep;
4175 + char **unresolved = NULL;
4176 + int ndepends;
4177 +
4178 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4179 + pkg, depends,
4180 + &unresolved);
4181 +
4182 + if (unresolved) {
4183 + ipkg_message(conf, IPKG_ERROR,
4184 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4185 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4186 + while (*unresolved) {
4187 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4188 + unresolved++;
4189 + }
4190 + ipkg_message(conf, IPKG_ERROR, "\n");
4191 + if (! conf->force_depends) {
4192 + ipkg_message(conf, IPKG_INFO,
4193 + "This could mean that your package list is out of date or that the packages\n"
4194 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4195 + "of this problem try again with the '-force-depends' option.\n");
4196 + pkg_vec_free(depends);
4197 + return IPKG_PKG_DEPS_UNSATISFIED;
4198 + }
4199 + }
4200 +
4201 + if (ndepends <= 0) {
4202 + return 0;
4203 + }
4204 +
4205 + /* Mark packages as to-be-installed */
4206 + for (i=0; i < depends->len; i++) {
4207 + /* Dependencies should be installed the same place as pkg */
4208 + if (depends->pkgs[i]->dest == NULL) {
4209 + depends->pkgs[i]->dest = pkg->dest;
4210 + }
4211 + depends->pkgs[i]->state_want = SW_INSTALL;
4212 + }
4213 +
4214 + for (i = 0; i < depends->len; i++) {
4215 + dep = depends->pkgs[i];
4216 + /* The package was uninstalled when we started, but another
4217 + dep earlier in this loop may have depended on it and pulled
4218 + it in, so check first. */
4219 + if ((dep->state_status != SS_INSTALLED)
4220 + && (dep->state_status != SS_UNPACKED)) {
4221 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4222 + err = ipkg_install_pkg(conf, dep,0);
4223 + if (err) {
4224 + pkg_vec_free(depends);
4225 + return err;
4226 + }
4227 + }
4228 + }
4229 +
4230 + pkg_vec_free(depends);
4231 +
4232 + return 0;
4233 +}
4234 +
4235 +
4236 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4237 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4238 +{
4239 + if (conf->nodeps == 0) {
4240 + int i;
4241 + pkg_vec_t *installed = pkg_vec_alloc();
4242 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4243 + for (i = 0; i < installed->len; i++) {
4244 + pkg_t *pkg = installed->pkgs[i];
4245 + satisfy_dependencies_for(conf, pkg);
4246 + }
4247 + pkg_vec_free(installed);
4248 + }
4249 + return 0;
4250 +}
4251 +
4252 +\f
4253 +
4254 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4255 +{
4256 + int i;
4257 + pkg_vec_t *conflicts = NULL;
4258 + int level;
4259 + const char *prefix;
4260 + if (conf->force_depends) {
4261 + level = IPKG_NOTICE;
4262 + prefix = "Warning";
4263 + } else {
4264 + level = IPKG_ERROR;
4265 + prefix = "ERROR";
4266 + }
4267 +
4268 + if (!conf->force_depends)
4269 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4270 +
4271 + if (conflicts) {
4272 + ipkg_message(conf, level,
4273 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4274 + i = 0;
4275 + while (i < conflicts->len)
4276 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4277 + ipkg_message(conf, level, "\n");
4278 + pkg_vec_free(conflicts);
4279 + return IPKG_PKG_DEPS_UNSATISFIED;
4280 + }
4281 + return 0;
4282 +}
4283 +
4284 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4285 +{
4286 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4287 + str_list_elt_t *iter;
4288 +
4289 + for (iter = new_list->head; iter; iter = iter->next) {
4290 + char *new_file = iter->data;
4291 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4292 + if (!new_file)
4293 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4294 + if (!owner || (owner == old_pkg))
4295 + file_hash_set_file_owner(conf, new_file, new_pkg);
4296 + }
4297 + if (old_pkg) {
4298 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4299 + for (iter = old_list->head; iter; iter = iter->next) {
4300 + char *old_file = iter->data;
4301 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4302 + if (owner == old_pkg) {
4303 + /* obsolete */
4304 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4305 + }
4306 + }
4307 + }
4308 + return 0;
4309 +}
4310 +
4311 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4312 +{
4313 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4314 +
4315 + /* sma 6.20.02: yup; here's the first bit */
4316 + /*
4317 + * XXX: BUG easy for cworth
4318 + * 1) please point the call below to the correct current root destination
4319 + * 2) we need to resolve how to check the required space for a pending pkg,
4320 + * my diddling with the .ipk file size below isn't going to cut it.
4321 + * 3) return a proper error code instead of 1
4322 + */
4323 + int comp_size, blocks_available;
4324 +
4325 + if (!conf->force_space && pkg->installed_size != NULL) {
4326 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4327 +
4328 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4329 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4330 + comp_size = (int)((comp_size + 1023) / 1024);
4331 +
4332 + if (comp_size >= blocks_available) {
4333 + ipkg_message(conf, IPKG_ERROR,
4334 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4335 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4336 + return ENOSPC;
4337 + }
4338 + }
4339 + return 0;
4340 +}
4341 +
4342 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4343 +{
4344 + int err;
4345 + char *conffiles_file_name;
4346 + char *root_dir;
4347 + FILE *conffiles_file;
4348 +
4349 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4350 +
4351 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4352 + if (pkg->tmp_unpack_dir == NULL) {
4353 + ipkg_message(conf, IPKG_ERROR,
4354 + "%s: Failed to create temporary directory '%s': %s\n",
4355 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4356 + return errno;
4357 + }
4358 +
4359 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4360 + if (err) {
4361 + return err;
4362 + }
4363 +
4364 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4365 + conffiles. Seems like I should be able to get everything to go
4366 + through pkg_init_from_file. If so, maybe it would make sense to
4367 + move all of unpack_pkg_control_files to that function. */
4368 +
4369 + /* Don't need to re-read conffiles if we already have it */
4370 + if (pkg->conffiles.head) {
4371 + return 0;
4372 + }
4373 +
4374 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4375 + if (! file_exists(conffiles_file_name)) {
4376 + free(conffiles_file_name);
4377 + return 0;
4378 + }
4379 +
4380 + conffiles_file = fopen(conffiles_file_name, "r");
4381 + if (conffiles_file == NULL) {
4382 + fprintf(stderr, "%s: failed to open %s: %s\n",
4383 + __FUNCTION__, conffiles_file_name, strerror(errno));
4384 + free(conffiles_file_name);
4385 + return errno;
4386 + }
4387 + free(conffiles_file_name);
4388 +
4389 + while (1) {
4390 + char *cf_name;
4391 + char *cf_name_in_dest;
4392 +
4393 + cf_name = file_read_line_alloc(conffiles_file);
4394 + if (cf_name == NULL) {
4395 + break;
4396 + }
4397 + str_chomp(cf_name);
4398 + if (cf_name[0] == '\0') {
4399 + continue;
4400 + }
4401 +
4402 + /* Prepend dest->root_dir to conffile name.
4403 + Take pains to avoid multiple slashes. */
4404 + root_dir = pkg->dest->root_dir;
4405 + if (conf->offline_root)
4406 + /* skip the offline_root prefix */
4407 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4408 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4409 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4410 +
4411 + /* Can't get an md5sum now, (file isn't extracted yet).
4412 + We'll wait until resolve_conffiles */
4413 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4414 +
4415 + free(cf_name);
4416 + free(cf_name_in_dest);
4417 + }
4418 +
4419 + fclose(conffiles_file);
4420 +
4421 + return 0;
4422 +}
4423 +
4424 +/* returns number of installed replacees */
4425 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4426 +{
4427 + abstract_pkg_t **replaces = pkg->replaces;
4428 + int replaces_count = pkg->replaces_count;
4429 + int i, j;
4430 + for (i = 0; i < replaces_count; i++) {
4431 + abstract_pkg_t *ab_pkg = replaces[i];
4432 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4433 + if (pkg_vec) {
4434 + for (j = 0; j < pkg_vec->len; j++) {
4435 + pkg_t *replacee = pkg_vec->pkgs[j];
4436 + if (!pkg_conflicts(pkg, replacee))
4437 + continue;
4438 + if (replacee->state_status == SS_INSTALLED) {
4439 + pkg_vec_insert(installed_replacees, replacee);
4440 + }
4441 + }
4442 + }
4443 + }
4444 + return installed_replacees->len;
4445 +}
4446 +
4447 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4448 +{
4449 + int i;
4450 + int replaces_count = replacees->len;
4451 + for (i = 0; i < replaces_count; i++) {
4452 + pkg_t *replacee = replacees->pkgs[i];
4453 + int err;
4454 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4455 + err = ipkg_remove_pkg(conf, replacee,0);
4456 + if (err)
4457 + return err;
4458 + }
4459 + return 0;
4460 +}
4461 +
4462 +/* to unwind the removal: make sure they are installed */
4463 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4464 +{
4465 + int i, err;
4466 + int replaces_count = replacees->len;
4467 + for (i = 0; i < replaces_count; i++) {
4468 + pkg_t *replacee = replacees->pkgs[i];
4469 + if (replacee->state_status != SS_INSTALLED) {
4470 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4471 + err = ipkg_install_pkg(conf, replacee,0);
4472 + if (err)
4473 + return err;
4474 + }
4475 + }
4476 + return 0;
4477 +}
4478 +
4479 +int caught_sigint = 0;
4480 +static void ipkg_install_pkg_sigint_handler(int sig)
4481 +{
4482 + caught_sigint = sig;
4483 +}
4484 +
4485 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4486 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4487 +{
4488 + if (old_pkg) {
4489 + char message_out[15];
4490 + char *old_version = pkg_version_str_alloc(old_pkg);
4491 + char *new_version = pkg_version_str_alloc(pkg);
4492 + int cmp = pkg_compare_versions(old_pkg, pkg);
4493 + int rc = 0;
4494 +
4495 + memset(message_out,'\x0',15);
4496 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4497 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4498 + cmp = -1 ; /* then we force ipkg to downgrade */
4499 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4500 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4501 + }
4502 +
4503 + if (cmp > 0) {
4504 + ipkg_message(conf, IPKG_NOTICE,
4505 + "Not downgrading package %s on %s from %s to %s.\n",
4506 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4507 + rc = 1;
4508 + } else if (cmp < 0) {
4509 + ipkg_message(conf, IPKG_NOTICE,
4510 + "%s%s on %s from %s to %s...\n",
4511 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4512 + pkg->dest = old_pkg->dest;
4513 + rc = 0;
4514 + } else /* cmp == 0 */ {
4515 + if (conf->force_reinstall) {
4516 + ipkg_message(conf, IPKG_NOTICE,
4517 + "Reinstalling %s (%s) on %s...\n",
4518 + pkg->name, new_version, old_pkg->dest->name);
4519 + pkg->dest = old_pkg->dest;
4520 + rc = 0;
4521 + } else {
4522 + ipkg_message(conf, IPKG_NOTICE,
4523 + "Not installing %s (%s) on %s -- already installed.\n",
4524 + pkg->name, new_version, old_pkg->dest->name);
4525 + rc = 1;
4526 + }
4527 + }
4528 + free(old_version);
4529 + free(new_version);
4530 + return rc;
4531 + } else {
4532 + char message_out[15], *version ;
4533 + memset(message_out,'\x0',15);
4534 + if ( message )
4535 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4536 + else
4537 + strncpy( message_out,"Installing ",strlen("Installing ") );
4538 + version = pkg_version_str_alloc(pkg);
4539 +
4540 + ipkg_message(conf, IPKG_NOTICE,
4541 + "%s%s (%s) to %s...\n", message_out,
4542 + pkg->name, version, pkg->dest->name);
4543 + free(version);
4544 + return 0;
4545 + }
4546 +}
4547 +
4548 +/* and now the meat... */
4549 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4550 +{
4551 + int err = 0;
4552 + int message = 0;
4553 + pkg_t *old_pkg = NULL;
4554 + pkg_vec_t *replacees;
4555 + abstract_pkg_t *ab_pkg = NULL;
4556 + int old_state_flag;
4557 + char* file_md5;
4558 +
4559 +
4560 + if ( from_upgrade )
4561 + message = 1; /* Coming from an upgrade, and should change the output message */
4562 +
4563 + if (!pkg) {
4564 + ipkg_message(conf, IPKG_ERROR,
4565 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4566 + return -EINVAL;
4567 + }
4568 +
4569 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4570 +
4571 + if (!pkg_arch_supported(conf, pkg)) {
4572 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4573 + pkg->architecture, pkg->name);
4574 + return -EINVAL;
4575 + }
4576 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4577 + err = satisfy_dependencies_for(conf, pkg);
4578 + if (err) { return err; }
4579 +
4580 + ipkg_message(conf, IPKG_NOTICE,
4581 + "Package %s is already installed in %s.\n",
4582 + pkg->name, pkg->dest->name);
4583 + return 0;
4584 + }
4585 +
4586 + if (pkg->dest == NULL) {
4587 + pkg->dest = conf->default_dest;
4588 + }
4589 +
4590 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4591 +
4592 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4593 + if (err) { return err; }
4594 +
4595 + pkg->state_want = SW_INSTALL;
4596 + if (old_pkg){
4597 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4598 + }
4599 +
4600 +
4601 + /* Abhaya: conflicts check */
4602 + err = check_conflicts_for(conf, pkg);
4603 + if (err) { return err; }
4604 +
4605 + /* this setup is to remove the upgrade scenario in the end when
4606 + installing pkg A, A deps B & B deps on A. So both B and A are
4607 + installed. Then A's installation is started resulting in an
4608 + uncecessary upgrade */
4609 + if (pkg->state_status == SS_INSTALLED
4610 + && conf->force_reinstall == 0) return 0;
4611 +
4612 + err = verify_pkg_installable(conf, pkg);
4613 + if (err) { return err; }
4614 +
4615 + if (pkg->local_filename == NULL) {
4616 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4617 + if (err) {
4618 + ipkg_message(conf, IPKG_ERROR,
4619 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4620 + pkg->name);
4621 + return err;
4622 + }
4623 + }
4624 +
4625 +/* Check for md5 values */
4626 + if (pkg->md5sum)
4627 + {
4628 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4629 + if (strcmp(file_md5, pkg->md5sum))
4630 + {
4631 + ipkg_message(conf, IPKG_ERROR,
4632 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4633 + pkg->name);
4634 + free(file_md5);
4635 + return err;
4636 + }
4637 + free(file_md5);
4638 + }
4639 +
4640 + if (pkg->tmp_unpack_dir == NULL) {
4641 + unpack_pkg_control_files(conf, pkg);
4642 + }
4643 +
4644 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4645 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4646 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4647 + err = update_file_ownership(conf, pkg, old_pkg);
4648 + if (err) { return err; }
4649 +
4650 + if (conf->nodeps == 0) {
4651 + err = satisfy_dependencies_for(conf, pkg);
4652 + if (err) { return err; }
4653 + }
4654 +
4655 + replacees = pkg_vec_alloc();
4656 + pkg_get_installed_replacees(conf, pkg, replacees);
4657 +
4658 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4659 + {
4660 + sigset_t newset, oldset;
4661 + sighandler_t old_handler = NULL;
4662 + int use_signal = 0;
4663 + caught_sigint = 0;
4664 + if (use_signal) {
4665 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4666 + } else {
4667 + sigemptyset(&newset);
4668 + sigaddset(&newset, SIGINT);
4669 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4670 + }
4671 +
4672 + ipkg_state_changed++;
4673 + pkg->state_flag |= SF_FILELIST_CHANGED;
4674 +
4675 + /* XXX: BUG: we really should treat replacement more like an upgrade
4676 + * Instead, we're going to remove the replacees
4677 + */
4678 + err = pkg_remove_installed_replacees(conf, replacees);
4679 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4680 +
4681 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4682 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4683 +
4684 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4685 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4686 +
4687 + err = preinst_configure(conf, pkg, old_pkg);
4688 + if (err) goto UNWIND_PREINST_CONFIGURE;
4689 +
4690 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4691 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4692 +
4693 + err = check_data_file_clashes(conf, pkg, old_pkg);
4694 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4695 +
4696 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4697 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4698 +
4699 + if (conf->noaction) return 0;
4700 +
4701 + /* point of no return: no unwinding after this */
4702 + if (old_pkg && !conf->force_reinstall) {
4703 + old_pkg->state_want = SW_DEINSTALL;
4704 +
4705 + if (old_pkg->state_flag & SF_NOPRUNE) {
4706 + ipkg_message(conf, IPKG_INFO,
4707 + " not removing obsolesced files because package marked noprune\n");
4708 + } else {
4709 + ipkg_message(conf, IPKG_INFO,
4710 + " removing obsolesced files\n");
4711 + remove_obsolesced_files(conf, pkg, old_pkg);
4712 + }
4713 + /* removing files from old package, to avoid ghost files */
4714 + remove_data_files_and_list(conf, old_pkg);
4715 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4716 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4717 + remove_postrm(conf, old_pkg);
4718 +/* Pigi */
4719 +
4720 + }
4721 +
4722 +
4723 + ipkg_message(conf, IPKG_INFO,
4724 + " installing maintainer scripts\n");
4725 + install_maintainer_scripts(conf, pkg, old_pkg);
4726 +
4727 + /* the following just returns 0 */
4728 + remove_disappeared(conf, pkg);
4729 +
4730 + ipkg_message(conf, IPKG_INFO,
4731 + " installing data files\n");
4732 + install_data_files(conf, pkg);
4733 +
4734 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4735 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4736 +
4737 + ipkg_message(conf, IPKG_INFO,
4738 + " resolving conf files\n");
4739 + resolve_conffiles(conf, pkg);
4740 +
4741 + pkg->state_status = SS_UNPACKED;
4742 + old_state_flag = pkg->state_flag;
4743 + pkg->state_flag &= ~SF_PREFER;
4744 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4745 +
4746 + if (old_pkg && !conf->force_reinstall) {
4747 + old_pkg->state_status = SS_NOT_INSTALLED;
4748 + }
4749 +
4750 + time(&pkg->installed_time);
4751 +
4752 + ipkg_message(conf, IPKG_INFO,
4753 + " cleanup temp files\n");
4754 + cleanup_temporary_files(conf, pkg);
4755 +
4756 + ab_pkg = pkg->parent;
4757 + if (ab_pkg)
4758 + ab_pkg->state_status = pkg->state_status;
4759 +
4760 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4761 +
4762 + if (use_signal)
4763 + signal(SIGINT, old_handler);
4764 + else
4765 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4766 +
4767 + return 0;
4768 +
4769 +
4770 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4771 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4772 + UNWIND_CHECK_DATA_FILE_CLASHES:
4773 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4774 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4775 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4776 + UNWIND_PREINST_CONFIGURE:
4777 + preinst_configure_unwind(conf, pkg, old_pkg);
4778 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4779 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4780 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4781 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4782 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4783 + pkg_remove_installed_replacees_unwind(conf, replacees);
4784 +
4785 + ipkg_message(conf, IPKG_INFO,
4786 + " cleanup temp files\n");
4787 + cleanup_temporary_files(conf, pkg);
4788 +
4789 + ipkg_message(conf, IPKG_INFO,
4790 + "Failed.\n");
4791 + if (use_signal)
4792 + signal(SIGINT, old_handler);
4793 + else
4794 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4795 +
4796 + return err;
4797 + }
4798 +}
4799 +
4800 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4801 +{
4802 + /* DPKG_INCOMPATIBILITY:
4803 + dpkg does some things here that we don't do yet. Do we care?
4804 +
4805 + 1. If a version of the package is already installed, call
4806 + old-prerm upgrade new-version
4807 + 2. If the script runs but exits with a non-zero exit status
4808 + new-prerm failed-upgrade old-version
4809 + Error unwind, for both the above cases:
4810 + old-postinst abort-upgrade new-version
4811 + */
4812 + return 0;
4813 +}
4814 +
4815 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4816 +{
4817 + /* DPKG_INCOMPATIBILITY:
4818 + dpkg does some things here that we don't do yet. Do we care?
4819 + (See prerm_upgrade_old_package for details)
4820 + */
4821 + return 0;
4822 +}
4823 +
4824 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4825 +{
4826 + /* DPKG_INCOMPATIBILITY:
4827 + dpkg does some things here that we don't do yet. Do we care?
4828 + 2. If a 'conflicting' package is being removed at the same time:
4829 + 1. If any packages depended on that conflicting package and
4830 + --auto-deconfigure is specified, call, for each such package:
4831 + deconfigured's-prerm deconfigure \
4832 + in-favour package-being-installed version \
4833 + removing conflicting-package version
4834 + Error unwind:
4835 + deconfigured's-postinst abort-deconfigure \
4836 + in-favour package-being-installed-but-failed version \
4837 + removing conflicting-package version
4838 +
4839 + The deconfigured packages are marked as requiring
4840 + configuration, so that if --install is used they will be
4841 + configured again if possible.
4842 + 2. To prepare for removal of the conflicting package, call:
4843 + conflictor's-prerm remove in-favour package new-version
4844 + Error unwind:
4845 + conflictor's-postinst abort-remove in-favour package new-version
4846 + */
4847 + return 0;
4848 +}
4849 +
4850 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4851 +{
4852 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4853 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4854 + details) */
4855 + return 0;
4856 +}
4857 +
4858 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4859 +{
4860 + int err;
4861 + char *preinst_args;
4862 +
4863 + if (old_pkg) {
4864 + char *old_version = pkg_version_str_alloc(old_pkg);
4865 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4866 + free(old_version);
4867 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4868 + char *pkg_version = pkg_version_str_alloc(pkg);
4869 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4870 + free(pkg_version);
4871 + } else {
4872 + preinst_args = strdup("install");
4873 + }
4874 +
4875 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4876 + if (err) {
4877 + ipkg_message(conf, IPKG_ERROR,
4878 + "Aborting installation of %s\n", pkg->name);
4879 + return 1;
4880 + }
4881 +
4882 + free(preinst_args);
4883 +
4884 + return 0;
4885 +}
4886 +
4887 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4888 +{
4889 + /* DPKG_INCOMPATIBILITY:
4890 + dpkg does the following error unwind, should we?
4891 + pkg->postrm abort-upgrade old-version
4892 + OR pkg->postrm abort-install old-version
4893 + OR pkg->postrm abort-install
4894 + */
4895 + return 0;
4896 +}
4897 +
4898 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4899 +{
4900 + int err;
4901 + conffile_list_elt_t *iter;
4902 + conffile_t *cf;
4903 +
4904 + if (conf->noaction) return 0;
4905 +
4906 + /* Backup all modified conffiles */
4907 + if (old_pkg) {
4908 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4909 + char *cf_name;
4910 +
4911 + cf = iter->data;
4912 + cf_name = root_filename_alloc(conf, cf->name);
4913 +
4914 + /* Don't worry if the conffile is just plain gone */
4915 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4916 + err = backup_make_backup(conf, cf_name);
4917 + if (err) {
4918 + return err;
4919 + }
4920 + }
4921 + free(cf_name);
4922 + }
4923 + }
4924 +
4925 + /* Backup all conffiles that were not conffiles in old_pkg */
4926 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4927 + char *cf_name;
4928 + cf = iter->data;
4929 + cf_name = root_filename_alloc(conf, cf->name);
4930 + /* Ignore if this was a conffile in old_pkg as well */
4931 + if (pkg_get_conffile(old_pkg, cf->name)) {
4932 + continue;
4933 + }
4934 +
4935 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4936 + err = backup_make_backup(conf, cf_name);
4937 + if (err) {
4938 + return err;
4939 + }
4940 + }
4941 + free(cf_name);
4942 + }
4943 +
4944 + return 0;
4945 +}
4946 +
4947 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4948 +{
4949 + conffile_list_elt_t *iter;
4950 +
4951 + if (old_pkg) {
4952 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4953 + backup_remove(iter->data->name);
4954 + }
4955 + }
4956 +
4957 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4958 + backup_remove(iter->data->name);
4959 + }
4960 +
4961 + return 0;
4962 +}
4963 +
4964 +
4965 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4966 +{
4967 + /* DPKG_INCOMPATIBILITY:
4968 + ipkg takes a slightly different approach than dpkg at this
4969 + point. dpkg installs each file in the new package while
4970 + creating a backup for any file that is replaced, (so that it
4971 + can unwind if necessary). To avoid complexity and redundant
4972 + storage, ipkg doesn't do any installation until later, (at the
4973 + point at which dpkg removes the backups.
4974 +
4975 + But, we do have to check for data file clashes, since after
4976 + installing a package with a file clash, removing either of the
4977 + packages involved in the clash has the potential to break the
4978 + other package.
4979 + */
4980 + str_list_t *files_list;
4981 + str_list_elt_t *iter;
4982 +
4983 + int clashes = 0;
4984 +
4985 + files_list = pkg_get_installed_files(pkg);
4986 + for (iter = files_list->head; iter; iter = iter->next) {
4987 + char *root_filename;
4988 + char *filename = iter->data;
4989 + root_filename = root_filename_alloc(conf, filename);
4990 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4991 + pkg_t *owner;
4992 + pkg_t *obs;
4993 + /* Pre-existing conffiles are OK */
4994 + /* @@@@ should have way to check that it is a conffile -Jamey */
4995 + if (backup_exists_for(root_filename)) {
4996 + continue;
4997 + }
4998 +
4999 + /* Pre-existing files are OK if force-overwrite was asserted. */
5000 + if (conf->force_overwrite) {
5001 + /* but we need to change who owns this file */
5002 + file_hash_set_file_owner(conf, filename, pkg);
5003 + continue;
5004 + }
5005 +
5006 + owner = file_hash_get_file_owner(conf, filename);
5007 +
5008 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
5009 + if (owner && old_pkg) {
5010 + if (strcmp(owner->name, old_pkg->name) == 0) {
5011 + continue;
5012 + }
5013 + }
5014 +
5015 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5016 + if (owner) {
5017 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5018 + if (pkg_replaces(pkg, owner)) {
5019 + continue;
5020 + }
5021 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5022 + then it's ok to overwrite. */
5023 + if (strcmp(owner->name,pkg->name)==0){
5024 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5025 + continue;
5026 + }
5027 + }
5028 +
5029 + /* Pre-existing files are OK if they are obsolete */
5030 + obs = hash_table_get(&conf->obs_file_hash, filename);
5031 + if (obs) {
5032 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5033 + continue;
5034 + }
5035 +
5036 + /* We have found a clash. */
5037 + ipkg_message(conf, IPKG_ERROR,
5038 + "Package %s wants to install file %s\n"
5039 + "\tBut that file is already provided by package ",
5040 + pkg->name, filename);
5041 + if (owner) {
5042 + ipkg_message(conf, IPKG_ERROR,
5043 + "%s\n", owner->name);
5044 + } else {
5045 + ipkg_message(conf, IPKG_ERROR,
5046 + "<no package>\nPlease move this file out of the way and try again.\n");
5047 + }
5048 + clashes++;
5049 + }
5050 + free(root_filename);
5051 + }
5052 + pkg_free_installed_files(pkg);
5053 +
5054 + return clashes;
5055 +}
5056 +
5057 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5058 +{
5059 + /* Basically that's the worst hack I could do to be able to change ownership of
5060 + file list, but, being that we have no way to unwind the mods, due to structure
5061 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5062 + What we do here is change the ownership of file in hash if a replace ( or similar events
5063 + happens )
5064 + Only the action that are needed to change name should be considered.
5065 + @@@ To change after 1.0 release.
5066 + */
5067 + str_list_t *files_list;
5068 + str_list_elt_t *iter;
5069 +
5070 + int clashes = 0;
5071 +
5072 + files_list = pkg_get_installed_files(pkg);
5073 + for (iter = files_list->head; iter; iter = iter->next) {
5074 + char *root_filename;
5075 + char *filename = iter->data;
5076 + root_filename = root_filename_alloc(conf, filename);
5077 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5078 + pkg_t *owner;
5079 +
5080 + if (conf->force_overwrite) {
5081 + /* but we need to change who owns this file */
5082 + file_hash_set_file_owner(conf, filename, pkg);
5083 + continue;
5084 + }
5085 +
5086 + owner = file_hash_get_file_owner(conf, filename);
5087 +
5088 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5089 + if (owner) {
5090 + if (pkg_replaces(pkg, owner)) {
5091 +/* It's now time to change the owner of that file.
5092 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5093 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5094 + file_hash_set_file_owner(conf, filename, pkg);
5095 + continue;
5096 + }
5097 + }
5098 +
5099 + }
5100 + free(root_filename);
5101 + }
5102 + pkg_free_installed_files(pkg);
5103 +
5104 + return clashes;
5105 +}
5106 +
5107 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5108 +{
5109 + /* Nothing to do since check_data_file_clashes doesn't change state */
5110 + return 0;
5111 +}
5112 +
5113 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5114 +{
5115 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5116 + 1. If the package is being upgraded, call
5117 + old-postrm upgrade new-version
5118 + 2. If this fails, attempt:
5119 + new-postrm failed-upgrade old-version
5120 + Error unwind, for both cases:
5121 + old-preinst abort-upgrade new-version */
5122 + return 0;
5123 +}
5124 +
5125 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5126 +{
5127 + /* DPKG_INCOMPATIBILITY:
5128 + dpkg does some things here that we don't do yet. Do we care?
5129 + (See postrm_upgrade_old_pkg for details)
5130 + */
5131 + return 0;
5132 +}
5133 +
5134 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5135 +{
5136 + int err;
5137 + str_list_t *old_files;
5138 + str_list_elt_t *of;
5139 + str_list_t *new_files;
5140 + str_list_elt_t *nf;
5141 +
5142 + if (old_pkg == NULL) {
5143 + return 0;
5144 + }
5145 +
5146 + old_files = pkg_get_installed_files(old_pkg);
5147 + new_files = pkg_get_installed_files(pkg);
5148 +
5149 + for (of = old_files->head; of; of = of->next) {
5150 + pkg_t *owner;
5151 + char *old, *new;
5152 + old = of->data;
5153 + for (nf = new_files->head; nf; nf = nf->next) {
5154 + new = nf->data;
5155 + if (strcmp(old, new) == 0) {
5156 + goto NOT_OBSOLETE;
5157 + }
5158 + }
5159 + if (file_is_dir(old)) {
5160 + continue;
5161 + }
5162 + owner = file_hash_get_file_owner(conf, old);
5163 + if (owner != old_pkg) {
5164 + /* in case obsolete file no longer belongs to old_pkg */
5165 + continue;
5166 + }
5167 +
5168 + /* old file is obsolete */
5169 + ipkg_message(conf, IPKG_INFO,
5170 + " removing obsolete file %s\n", old);
5171 + if (!conf->noaction) {
5172 + err = unlink(old);
5173 + if (err) {
5174 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5175 + strerror(errno));
5176 + }
5177 + }
5178 +
5179 + NOT_OBSOLETE:
5180 + ;
5181 + }
5182 +
5183 + pkg_free_installed_files(old_pkg);
5184 + pkg_free_installed_files(pkg);
5185 +
5186 + return 0;
5187 +}
5188 +
5189 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5190 +{
5191 + int i;
5192 + int err = 0;
5193 + char *globpattern;
5194 + glob_t globbuf;
5195 + if (0) {
5196 + if (!pkg->dest) {
5197 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5198 + return -1;
5199 + }
5200 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5201 + err = glob(globpattern, 0, NULL, &globbuf);
5202 + free(globpattern);
5203 + if (err) {
5204 + return err;
5205 + }
5206 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5207 + for (i = 0; i < globbuf.gl_pathc; i++) {
5208 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5209 + globbuf.gl_pathv[i], old_pkg->name);
5210 + if (!conf->noaction)
5211 + unlink(globbuf.gl_pathv[i]);
5212 + }
5213 + globfree(&globbuf);
5214 + }
5215 + return err;
5216 +}
5217 +
5218 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5219 +{
5220 + int ret;
5221 + char *prefix;
5222 +
5223 + if (old_pkg)
5224 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5225 + sprintf_alloc(&prefix, "%s.", pkg->name);
5226 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5227 + pkg->dest->info_dir,
5228 + prefix);
5229 + free(prefix);
5230 + return ret;
5231 +}
5232 +
5233 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5234 +{
5235 + /* DPKG_INCOMPATIBILITY:
5236 + This is a fairly sophisticated dpkg operation. Shall we
5237 + skip it? */
5238 +
5239 + /* Any packages all of whose files have been overwritten during the
5240 + installation, and which aren't required for dependencies, are
5241 + considered to have been removed. For each such package
5242 + 1. disappearer's-postrm disappear overwriter overwriter-version
5243 + 2. The package's maintainer scripts are removed
5244 + 3. It is noted in the status database as being in a sane state,
5245 + namely not installed (any conffiles it may have are ignored,
5246 + rather than being removed by dpkg). Note that disappearing
5247 + packages do not have their prerm called, because dpkg doesn't
5248 + know in advance that the package is going to vanish.
5249 + */
5250 + return 0;
5251 +}
5252 +
5253 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5254 +{
5255 + int err;
5256 +
5257 + /* ipkg takes a slightly different approach to data file backups
5258 + than dpkg. Rather than removing backups at this point, we
5259 + actually do the data file installation now. See comments in
5260 + check_data_file_clashes() for more details. */
5261 +
5262 + ipkg_message(conf, IPKG_INFO,
5263 + " extracting data files to %s\n", pkg->dest->root_dir);
5264 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5265 + if (err) {
5266 + return err;
5267 + }
5268 +
5269 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5270 + so we can't save ourself from removing important packages
5271 + At this point we (should) have extracted the .control file, so it
5272 + would be a good idea to reload the data in it, and set the Essential
5273 + state in *pkg. From now on the Essential is back in status file and
5274 + we can protect again.
5275 + We should operate this way:
5276 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5277 + check for "Essential" in it
5278 + set the value in pkg->essential.
5279 + This new routine could be useful also for every other flag
5280 + Pigi: 16/03/2004 */
5281 + set_flags_from_control(conf, pkg) ;
5282 +
5283 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5284 + err = pkg_write_filelist(conf, pkg);
5285 + if (err)
5286 + return err;
5287 +
5288 + /* XXX: FEATURE: ipkg should identify any files which existed
5289 + before installation and which were overwritten, (see
5290 + check_data_file_clashes()). What it must do is remove any such
5291 + files from the filelist of the old package which provided the
5292 + file. Otherwise, if the old package were removed at some point
5293 + it would break the new package. Removing the new package will
5294 + also break the old one, but this cannot be helped since the old
5295 + package's file has already been deleted. This is the importance
5296 + of check_data_file_clashes(), and only allowing ipkg to install
5297 + a clashing package with a user force. */
5298 +
5299 + return 0;
5300 +}
5301 +
5302 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5303 +{
5304 + conffile_list_elt_t *iter;
5305 + conffile_t *cf;
5306 + char *cf_backup;
5307 +
5308 + char *md5sum;
5309 +
5310 +
5311 + if (conf->noaction) return 0;
5312 +
5313 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5314 + char *root_filename;
5315 + cf = iter->data;
5316 + root_filename = root_filename_alloc(conf, cf->name);
5317 +
5318 + /* Might need to initialize the md5sum for each conffile */
5319 + if (cf->value == NULL) {
5320 + cf->value = file_md5sum_alloc(root_filename);
5321 + }
5322 +
5323 + if (!file_exists(root_filename)) {
5324 + free(root_filename);
5325 + continue;
5326 + }
5327 +
5328 + cf_backup = backup_filename_alloc(root_filename);
5329 +
5330 +
5331 + if (file_exists(cf_backup)) {
5332 + /* Let's compute md5 to test if files are changed */
5333 + md5sum = file_md5sum_alloc(cf_backup);
5334 + if (strcmp( cf->value,md5sum) != 0 ) {
5335 + if (conf->force_defaults
5336 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5337 + rename(cf_backup, root_filename);
5338 + }
5339 + }
5340 + unlink(cf_backup);
5341 + free(md5sum);
5342 + }
5343 +
5344 + free(cf_backup);
5345 + free(root_filename);
5346 + }
5347 +
5348 + return 0;
5349 +}
5350 +
5351 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5352 +{
5353 + char *response;
5354 + const char *short_file_name;
5355 +
5356 + short_file_name = strrchr(file_name, '/');
5357 + if (short_file_name) {
5358 + short_file_name++;
5359 + } else {
5360 + short_file_name = file_name;
5361 + }
5362 +
5363 + while (1) {
5364 + response = get_user_response(" Configuration file '%s'\n"
5365 + " ==> File on system created by you or by a script.\n"
5366 + " ==> File also in package provided by package maintainer.\n"
5367 + " What would you like to do about it ? Your options are:\n"
5368 + " Y or I : install the package maintainer's version\n"
5369 + " N or O : keep your currently-installed version\n"
5370 + " D : show the differences between the versions (if diff is installed)\n"
5371 + " The default action is to keep your current version.\n"
5372 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5373 + if (strcmp(response, "y") == 0
5374 + || strcmp(response, "i") == 0
5375 + || strcmp(response, "yes") == 0) {
5376 + free(response);
5377 + return 0;
5378 + }
5379 +
5380 + if (strcmp(response, "d") == 0) {
5381 + char *cmd;
5382 +
5383 + free(response);
5384 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5385 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5386 + xsystem(cmd);
5387 + free(cmd);
5388 + printf(" [Press ENTER to continue]\n");
5389 + response = file_read_line_alloc(stdin);
5390 + free(response);
5391 + continue;
5392 + }
5393 +
5394 + free(response);
5395 + return 1;
5396 + }
5397 +}
5398 +
5399 +/* XXX: CLEANUP: I'd like to move all of the code for
5400 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5401 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5402 + pkg_deinit for example). */
5403 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5404 +{
5405 + DIR *tmp_dir;
5406 + struct dirent *dirent;
5407 + char *tmp_file;
5408 +
5409 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5410 +#error
5411 + ipkg_message(conf, IPKG_DEBUG,
5412 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5413 + __FUNCTION__, pkg->tmp_unpack_dir);
5414 + return 0;
5415 +#endif
5416 +
5417 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5418 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5419 + if (tmp_dir) {
5420 + while (1) {
5421 + dirent = readdir(tmp_dir);
5422 + if (dirent == NULL) {
5423 + break;
5424 + }
5425 + sprintf_alloc(&tmp_file, "%s/%s",
5426 + pkg->tmp_unpack_dir, dirent->d_name);
5427 + if (! file_is_dir(tmp_file)) {
5428 + unlink(tmp_file);
5429 + }
5430 + free(tmp_file);
5431 + }
5432 + closedir(tmp_dir);
5433 + rmdir(pkg->tmp_unpack_dir);
5434 + free(pkg->tmp_unpack_dir);
5435 + pkg->tmp_unpack_dir = NULL;
5436 + }
5437 + }
5438 +
5439 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5440 + pkg->name, pkg->local_filename, conf->tmp_dir);
5441 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5442 + unlink(pkg->local_filename);
5443 + free(pkg->local_filename);
5444 + pkg->local_filename = NULL;
5445 + }
5446 +
5447 + return 0;
5448 +}
5449 +
5450 +static char *backup_filename_alloc(const char *file_name)
5451 +{
5452 + char *backup;
5453 +
5454 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5455 +
5456 + return backup;
5457 +}
5458 +
5459 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5460 +{
5461 + int err;
5462 + char *backup;
5463 +
5464 + backup = backup_filename_alloc(file_name);
5465 + err = file_copy(file_name, backup);
5466 + if (err) {
5467 + ipkg_message(conf, IPKG_ERROR,
5468 + "%s: Failed to copy %s to %s\n",
5469 + __FUNCTION__, file_name, backup);
5470 + }
5471 +
5472 + free(backup);
5473 +
5474 + return err;
5475 +}
5476 +
5477 +static int backup_exists_for(const char *file_name)
5478 +{
5479 + int ret;
5480 + char *backup;
5481 +
5482 + backup = backup_filename_alloc(file_name);
5483 +
5484 + ret = file_exists(backup);
5485 +
5486 + free(backup);
5487 +
5488 + return ret;
5489 +}
5490 +
5491 +static int backup_remove(const char *file_name)
5492 +{
5493 + char *backup;
5494 +
5495 + backup = backup_filename_alloc(file_name);
5496 + unlink(backup);
5497 + free(backup);
5498 +
5499 + return 0;
5500 +}
5501 +
5502 +\f
5503 +
5504 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5505 +
5506 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5507 +{
5508 + /* first, remove the packages that need removing */
5509 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5510 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5511 + err = ipkg_remove_pkg(conf, pkg,0);
5512 + if (err) return err;
5513 + }
5514 + return 0;
5515 +}
5516 +
5517 +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5518 +{
5519 + int i;
5520 + /* now one more pass checking on the ones that need to be installed */
5521 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5522 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5523 + if (pkg->dest == NULL)
5524 + pkg->dest = conf->default_dest;
5525 +
5526 + pkg->state_want = SW_INSTALL;
5527 +
5528 + /* Abhaya: conflicts check */
5529 + err = check_conflicts_for(conf, pkg);
5530 + if (err) { return err; }
5531 + }
5532 + return 0;
5533 +}
5534 +
5535 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5536 +{
5537 + int i;
5538 + /* now one more pass checking on the ones that need to be installed */
5539 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5540 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5541 +
5542 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5543 + pkg_vec_t *replacees = pkg_vec_alloc();
5544 + pkg_get_installed_replacees(conf, pkg, replacees);
5545 +
5546 + /* XXX: BUG: we really should treat replacement more like an upgrade
5547 + * Instead, we're going to remove the replacees
5548 + */
5549 + err = pkg_remove_installed_replacees(conf, replacees);
5550 + if (err) return err;
5551 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5552 + }
5553 + return 0;
5554 +}
5555 +
5556 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5557 +{
5558 + int i;
5559 + /* now one more pass checking on the ones that need to be installed */
5560 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5561 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5562 + if (pkg->local_filename == NULL) {
5563 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5564 + if (err) {
5565 + ipkg_message(conf, IPKG_ERROR,
5566 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5567 + pkg->name);
5568 + return err;
5569 + }
5570 + }
5571 + if (pkg->tmp_unpack_dir == NULL) {
5572 + err = unpack_pkg_control_files(conf, pkg);
5573 + if (err) return err;
5574 + }
5575 + }
5576 + return 0;
5577 +}
5578 +
5579 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5580 +{
5581 + int i;
5582 + /* now one more pass checking on the ones that need to be installed */
5583 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5584 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5585 + pkg_t *old_pkg = pkg->old_pkg;
5586 +
5587 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5588 + if (err) return err;
5589 +
5590 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5591 + if (err) return err;
5592 +
5593 + err = preinst_configure(conf, pkg, old_pkg);
5594 + if (err) return err;
5595 +
5596 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5597 + if (err) return err;
5598 +
5599 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5600 + if (err) return err;
5601 + }
5602 + return 0;
5603 +}
5604 +
5605 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5606 +{
5607 + int i;
5608 + /* now one more pass checking on the ones that need to be installed */
5609 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5610 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5611 + pkg_t *old_pkg = pkg->old_pkg;
5612 +
5613 + if (old_pkg) {
5614 + old_pkg->state_want = SW_DEINSTALL;
5615 +
5616 + if (old_pkg->state_flag & SF_NOPRUNE) {
5617 + ipkg_message(conf, IPKG_INFO,
5618 + " not removing obsolesced files because package marked noprune\n");
5619 + } else {
5620 + ipkg_message(conf, IPKG_INFO,
5621 + " removing obsolesced files\n");
5622 + remove_obsolesced_files(conf, pkg, old_pkg);
5623 + }
5624 + }
5625 +
5626 + ipkg_message(conf, IPKG_INFO,
5627 + " installing maintainer scripts\n");
5628 + install_maintainer_scripts(conf, pkg, old_pkg);
5629 +
5630 + /* the following just returns 0 */
5631 + remove_disappeared(conf, pkg);
5632 +
5633 + ipkg_message(conf, IPKG_INFO,
5634 + " installing data files\n");
5635 + install_data_files(conf, pkg);
5636 +
5637 + ipkg_message(conf, IPKG_INFO,
5638 + " resolving conf files\n");
5639 + resolve_conffiles(conf, pkg);
5640 +
5641 + pkg->state_status = SS_UNPACKED;
5642 +
5643 + if (old_pkg) {
5644 + old_pkg->state_status = SS_NOT_INSTALLED;
5645 + }
5646 +
5647 + time(&pkg->installed_time);
5648 +
5649 + ipkg_message(conf, IPKG_INFO,
5650 + " cleanup temp files\n");
5651 + cleanup_temporary_files(conf, pkg);
5652 +
5653 + if (pkg->parent)
5654 + pkg->parent->state_status = pkg->state_status;
5655 + }
5656 + return 0;
5657 +}
5658 +
5659 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5660 +{
5661 + int i;
5662 + /* now one more pass checking on the ones that need to be installed */
5663 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5664 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5665 + pkg_t *old_pkg = pkg->old_pkg;
5666 +
5667 + if (old_pkg) {
5668 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5669 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5670 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5671 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5672 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5673 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5674 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5675 + preinst_configure_unwind(conf, pkg, old_pkg);
5676 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5677 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5678 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5679 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5680 +
5681 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5682 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5683 +
5684 + }
5685 + }
5686 + return 0;
5687 +}
5688 +
5689 +/*
5690 + * Perform all the actions.
5691 + *
5692 + * pkgs_to_remove are packages marked for removal.
5693 + * pkgs_superseded are the old packages being replaced by upgrades.
5694 + *
5695 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5696 + */
5697 +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5698 +{
5699 + int err;
5700 + int i;
5701 +
5702 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5703 + if (err) return err;
5704 +
5705 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5706 + if (err) return err;
5707 +
5708 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5709 + if (err) goto UNWIND;
5710 +
5711 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5712 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5713 + if (err) goto UNWIND;
5714 +
5715 + /*
5716 + * Now that we have the packages unpacked, we can look for data
5717 + * file clashes. First, we mark the files from the superseded
5718 + * packages as obsolete. Then we scan the files in
5719 + * pkgs_to_install, and only complain about clashes with
5720 + * non-obsolete files.
5721 + */
5722 +
5723 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5724 + if (err) goto UNWIND;
5725 +
5726 + /* this was before checking data file clashes */
5727 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5728 + if (err) goto UNWIND;
5729 +
5730 + /* point of no return: no unwinding after this */
5731 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5732 + if (err) return err;
5733 +
5734 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5735 + return 0;
5736 +
5737 + UNWIND:
5738 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5739 +
5740 + ipkg_message(conf, IPKG_INFO,
5741 + " cleanup temp files\n");
5742 + cleanup_temporary_files(conf, pkg);
5743 +
5744 + ipkg_message(conf, IPKG_INFO,
5745 + "Failed.\n");
5746 + return err;
5747 +}
5748 +
5749 +#endif
5750 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_install.h busybox-1.3.1-911/archival/libipkg/ipkg_install.h
5751 --- busybox-1.3.1-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5752 +++ busybox-1.3.1-911/archival/libipkg/ipkg_install.h 2006-12-27 19:41:04.000000000 +0100
5753 @@ -0,0 +1,35 @@
5754 +/* ipkg_install.h - the itsy package management system
5755 +
5756 + Carl D. Worth
5757 +
5758 + Copyright (C) 2001 University of Southern California
5759 +
5760 + This program is free software; you can redistribute it and/or
5761 + modify it under the terms of the GNU General Public License as
5762 + published by the Free Software Foundation; either version 2, or (at
5763 + your option) any later version.
5764 +
5765 + This program is distributed in the hope that it will be useful, but
5766 + WITHOUT ANY WARRANTY; without even the implied warranty of
5767 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5768 + General Public License for more details.
5769 +*/
5770 +
5771 +#ifndef IPKG_INSTALL_H
5772 +#define IPKG_INSTALL_H
5773 +
5774 +#include "pkg.h"
5775 +#include "ipkg_conf.h"
5776 +
5777 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5778 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5779 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5780 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5781 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5782 +
5783 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5784 +
5785 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5786 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5787 +
5788 +#endif
5789 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_message.c busybox-1.3.1-911/archival/libipkg/ipkg_message.c
5790 --- busybox-1.3.1-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5791 +++ busybox-1.3.1-911/archival/libipkg/ipkg_message.c 2006-12-27 19:41:04.000000000 +0100
5792 @@ -0,0 +1,61 @@
5793 +/* ipkg_message.c - the itsy package management system
5794 +
5795 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5796 +
5797 + This program is free software; you can redistribute it and/or
5798 + modify it under the terms of the GNU General Public License as
5799 + published by the Free Software Foundation; either version 2, or (at
5800 + your option) any later version.
5801 +
5802 + This program is distributed in the hope that it will be useful, but
5803 + WITHOUT ANY WARRANTY; without even the implied warranty of
5804 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5805 + General Public License for more details.
5806 +*/
5807 +
5808 +
5809 +#include "ipkg.h"
5810 +#include "ipkg_conf.h"
5811 +#include "ipkg_message.h"
5812 +
5813 +#ifndef IPKG_LIB
5814 +
5815 +void
5816 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5817 +{
5818 + va_list ap;
5819 +
5820 + if (conf && (conf->verbosity < level))
5821 + {
5822 + return;
5823 + }
5824 + else
5825 + {
5826 +
5827 + va_start (ap, fmt);
5828 + vprintf (fmt, ap);
5829 + va_end (ap);
5830 + }
5831 +}
5832 +
5833 +#else
5834 +
5835 +#include "libipkg.h"
5836 +
5837 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5838 +
5839 +void
5840 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5841 +{
5842 + va_list ap;
5843 + char ts[256];
5844 +
5845 + if (ipkg_cb_message)
5846 + {
5847 + va_start (ap, fmt);
5848 + vsnprintf (ts,256,fmt, ap);
5849 + va_end (ap);
5850 + ipkg_cb_message(conf,level,ts);
5851 + }
5852 +}
5853 +#endif
5854 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_message.h busybox-1.3.1-911/archival/libipkg/ipkg_message.h
5855 --- busybox-1.3.1-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5856 +++ busybox-1.3.1-911/archival/libipkg/ipkg_message.h 2006-12-27 19:41:04.000000000 +0100
5857 @@ -0,0 +1,32 @@
5858 +/* ipkg_message.h - the itsy package management system
5859 +
5860 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5861 +
5862 + This program is free software; you can redistribute it and/or
5863 + modify it under the terms of the GNU General Public License as
5864 + published by the Free Software Foundation; either version 2, or (at
5865 + your option) any later version.
5866 +
5867 + This program is distributed in the hope that it will be useful, but
5868 + WITHOUT ANY WARRANTY; without even the implied warranty of
5869 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5870 + General Public License for more details.
5871 +*/
5872 +
5873 +#ifndef _IPKG_MESSAGE_H_
5874 +#define _IPKG_MESSAGE_H_
5875 +
5876 +#include "ipkg.h"
5877 +#include "ipkg_conf.h"
5878 +
5879 +typedef enum {
5880 + IPKG_ERROR, /* error conditions */
5881 + IPKG_NOTICE, /* normal but significant condition */
5882 + IPKG_INFO, /* informational message */
5883 + IPKG_DEBUG, /* debug level message */
5884 + IPKG_DEBUG2, /* more debug level message */
5885 +} message_level_t;
5886 +
5887 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5888 +
5889 +#endif /* _IPKG_MESSAGE_H_ */
5890 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_remove.c busybox-1.3.1-911/archival/libipkg/ipkg_remove.c
5891 --- busybox-1.3.1-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5892 +++ busybox-1.3.1-911/archival/libipkg/ipkg_remove.c 2006-12-27 19:41:04.000000000 +0100
5893 @@ -0,0 +1,383 @@
5894 +/* ipkg_remove.c - the itsy package management system
5895 +
5896 + Carl D. Worth
5897 +
5898 + Copyright (C) 2001 University of Southern California
5899 +
5900 + This program is free software; you can redistribute it and/or
5901 + modify it under the terms of the GNU General Public License as
5902 + published by the Free Software Foundation; either version 2, or (at
5903 + your option) any later version.
5904 +
5905 + This program is distributed in the hope that it will be useful, but
5906 + WITHOUT ANY WARRANTY; without even the implied warranty of
5907 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5908 + General Public License for more details.
5909 +*/
5910 +
5911 +#include "ipkg.h"
5912 +#include "ipkg_message.h"
5913 +
5914 +#include <glob.h>
5915 +
5916 +#include "ipkg_remove.h"
5917 +
5918 +#include "file_util.h"
5919 +#include "sprintf_alloc.h"
5920 +#include "str_util.h"
5921 +
5922 +#include "ipkg_cmd.h"
5923 +
5924 +/*
5925 + * Returns number of the number of packages depending on the packages provided by this package.
5926 + * Every package implicitly provides itself.
5927 + */
5928 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5929 +{
5930 + int nprovides = pkg->provides_count;
5931 + abstract_pkg_t **provides = pkg->provides;
5932 + int n_installed_dependents = 0;
5933 + int i;
5934 + for (i = 0; i <= nprovides; i++) {
5935 + abstract_pkg_t *providee = provides[i];
5936 + abstract_pkg_t **dependers = providee->depended_upon_by;
5937 + abstract_pkg_t *dep_ab_pkg;
5938 + if (dependers == NULL)
5939 + continue;
5940 + while ((dep_ab_pkg = *dependers++) != NULL) {
5941 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5942 + n_installed_dependents++;
5943 + }
5944 + }
5945 +
5946 + }
5947 + /* if caller requested the set of installed dependents */
5948 + if (pdependents) {
5949 + int p = 0;
5950 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5951 +
5952 + if ( dependents == NULL ){
5953 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5954 + return -1;
5955 + }
5956 +
5957 + *pdependents = dependents;
5958 + for (i = 0; i <= nprovides; i++) {
5959 + abstract_pkg_t *providee = provides[i];
5960 + abstract_pkg_t **dependers = providee->depended_upon_by;
5961 + abstract_pkg_t *dep_ab_pkg;
5962 + if (dependers == NULL)
5963 + continue;
5964 + while ((dep_ab_pkg = *dependers++) != NULL) {
5965 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5966 + dependents[p++] = dep_ab_pkg;
5967 + dep_ab_pkg->state_flag |= SF_MARKED;
5968 + }
5969 + }
5970 + }
5971 + dependents[p] = NULL;
5972 + /* now clear the marks */
5973 + for (i = 0; i < p; i++) {
5974 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5975 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5976 + }
5977 + }
5978 + return n_installed_dependents;
5979 +}
5980 +
5981 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5982 +{
5983 + int i;
5984 + int a;
5985 + int count;
5986 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5987 + abstract_pkg_t * ab_pkg;
5988 +
5989 + if((ab_pkg = pkg->parent) == NULL){
5990 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5991 + __FUNCTION__, pkg->name);
5992 + return 0;
5993 + }
5994 +
5995 + if (dependents == NULL)
5996 + return 0;
5997 +
5998 + // here i am using the dependencies_checked
5999 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
6000 + return 0; // has already been encountered in the process
6001 + // of marking packages for removal - Karthik
6002 + ab_pkg->dependencies_checked = 2;
6003 +
6004 + i = 0;
6005 + count = 1;
6006 + while (dependents [i] != NULL) {
6007 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6008 +
6009 + if (dep_ab_pkg->dependencies_checked == 2){
6010 + i++;
6011 + continue;
6012 + }
6013 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
6014 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
6015 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6016 + if (dep_pkg->state_status == SS_INSTALLED) {
6017 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6018 + count++;
6019 + }
6020 + }
6021 + }
6022 + i++;
6023 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6024 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6025 + }
6026 +
6027 + if (count == 1)
6028 + return 0;
6029 +
6030 +
6031 + for (i = 0; i < dependent_pkgs->len; i++) {
6032 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6033 + if (err)
6034 + return err;
6035 + }
6036 + return 0;
6037 +}
6038 +
6039 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6040 +{
6041 + abstract_pkg_t *dep_ab_pkg;
6042 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6043 + while ((dep_ab_pkg = *dependents++) != NULL) {
6044 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6045 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6046 + }
6047 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6048 + ipkg_message(conf, IPKG_ERROR, "");
6049 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6050 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6051 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6052 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6053 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6054 + return 0;
6055 +}
6056 +
6057 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6058 +{
6059 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6060 + thus I wan't check for essential, as I'm upgrading.
6061 + I hope it won't break anything :)
6062 +*/
6063 + int err;
6064 + abstract_pkg_t *parent_pkg = NULL;
6065 +
6066 + if (pkg->essential && !message) {
6067 + if (conf->force_removal_of_essential_packages) {
6068 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6069 + "\tIf your system breaks, you get to keep both pieces\n",
6070 + pkg->name);
6071 + } else {
6072 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6073 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6074 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6075 + "\tits will with the option: -force-removal-of-essential-packages\n",
6076 + pkg->name);
6077 + return IPKG_PKG_IS_ESSENTIAL;
6078 + }
6079 + }
6080 +
6081 + if ((parent_pkg = pkg->parent) == NULL)
6082 + return 0;
6083 +
6084 + /* only attempt to remove dependent installed packages if
6085 + * force_depends is not specified or the package is being
6086 + * replaced.
6087 + */
6088 + if (!conf->force_depends
6089 + && !(pkg->state_flag & SF_REPLACE)) {
6090 + abstract_pkg_t **dependents;
6091 + int has_installed_dependents =
6092 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6093 +
6094 + if (has_installed_dependents) {
6095 + /*
6096 + * if this package is depended up by others, then either we should
6097 + * not remove it or we should remove it and all of its dependents
6098 + */
6099 +
6100 + if (!conf->force_removal_of_dependent_packages
6101 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6102 + return IPKG_PKG_HAS_DEPENDENTS;
6103 + }
6104 +
6105 + /* remove packages depending on this package - Karthik */
6106 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6107 + free(dependents);
6108 + if (err) return err;
6109 + }
6110 + }
6111 +
6112 + if ( message==0 ){
6113 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6114 + fflush(stdout);
6115 + }
6116 + pkg->state_flag |= SF_FILELIST_CHANGED;
6117 +
6118 + pkg->state_want = SW_DEINSTALL;
6119 + ipkg_state_changed++;
6120 +
6121 + pkg_run_script(conf, pkg, "prerm", "remove");
6122 +
6123 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6124 + maintains an empty filelist rather than deleting it. That seems
6125 + like a big pain, and I don't see that that should make a big
6126 + difference, but for anyone who wants tighter compatibility,
6127 + feel free to fix this. */
6128 + remove_data_files_and_list(conf, pkg);
6129 +
6130 + pkg_run_script(conf, pkg, "postrm", "remove");
6131 +
6132 + remove_maintainer_scripts_except_postrm(conf, pkg);
6133 +
6134 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6135 + * space, it doesn't make sense to leave extra configurations, files,
6136 + * and maintainer scripts left around. So, we make remove like purge,
6137 + * and take out all the crap :) */
6138 +
6139 + remove_postrm(conf, pkg);
6140 + pkg->state_status = SS_NOT_INSTALLED;
6141 +
6142 + if (parent_pkg)
6143 + parent_pkg->state_status = SS_NOT_INSTALLED;
6144 +
6145 + return 0;
6146 +}
6147 +
6148 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6149 +{
6150 + ipkg_remove_pkg(conf, pkg,0);
6151 + return 0;
6152 +}
6153 +
6154 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6155 +{
6156 + str_list_t installed_dirs;
6157 + str_list_t *installed_files;
6158 + str_list_elt_t *iter;
6159 + char *file_name;
6160 + conffile_t *conffile;
6161 + int removed_a_dir;
6162 + pkg_t *owner;
6163 +
6164 + str_list_init(&installed_dirs);
6165 + installed_files = pkg_get_installed_files(pkg);
6166 +
6167 + for (iter = installed_files->head; iter; iter = iter->next) {
6168 + file_name = iter->data;
6169 +
6170 + if (file_is_dir(file_name)) {
6171 + str_list_append(&installed_dirs, strdup(file_name));
6172 + continue;
6173 + }
6174 +
6175 + conffile = pkg_get_conffile(pkg, file_name);
6176 + if (conffile) {
6177 + /* XXX: QUESTION: Is this right? I figure we only need to
6178 + save the conffile if it has been modified. Is that what
6179 + dpkg does? Or does dpkg preserve all conffiles? If so,
6180 + this seems like a better thing to do to conserve
6181 + space. */
6182 + if (conffile_has_been_modified(conf, conffile)) {
6183 + printf(" not deleting modified conffile %s\n", file_name);
6184 + fflush(stdout);
6185 + continue;
6186 + }
6187 + }
6188 +
6189 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6190 + if (!conf->noaction)
6191 + unlink(file_name);
6192 + }
6193 +
6194 + if (!conf->noaction) {
6195 + do {
6196 + removed_a_dir = 0;
6197 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6198 + file_name = iter->data;
6199 +
6200 + if (rmdir(file_name) == 0) {
6201 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6202 + removed_a_dir = 1;
6203 + str_list_remove(&installed_dirs, &iter);
6204 + }
6205 + }
6206 + } while (removed_a_dir);
6207 + }
6208 +
6209 + pkg_free_installed_files(pkg);
6210 + /* We have to remove the file list now, so that
6211 + find_pkg_owning_file does not always just report this package */
6212 + pkg_remove_installed_files_list(conf, pkg);
6213 +
6214 + /* Don't print warning for dirs that are provided by other packages */
6215 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6216 + file_name = iter->data;
6217 +
6218 + owner = file_hash_get_file_owner(conf, file_name);
6219 + if (owner) {
6220 + free(iter->data);
6221 + iter->data = NULL;
6222 + str_list_remove(&installed_dirs, &iter);
6223 + }
6224 + }
6225 +
6226 + /* cleanup */
6227 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6228 + free(iter->data);
6229 + iter->data = NULL;
6230 + }
6231 + str_list_deinit(&installed_dirs);
6232 +
6233 + return 0;
6234 +}
6235 +
6236 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6237 +{
6238 + int i, err;
6239 + char *globpattern;
6240 + glob_t globbuf;
6241 +
6242 + if (conf->noaction) return 0;
6243 +
6244 + sprintf_alloc(&globpattern, "%s/%s.*",
6245 + pkg->dest->info_dir, pkg->name);
6246 + err = glob(globpattern, 0, NULL, &globbuf);
6247 + free(globpattern);
6248 + if (err) {
6249 + return 0;
6250 + }
6251 +
6252 + for (i = 0; i < globbuf.gl_pathc; i++) {
6253 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6254 + continue;
6255 + }
6256 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6257 + unlink(globbuf.gl_pathv[i]);
6258 + }
6259 + globfree(&globbuf);
6260 +
6261 + return 0;
6262 +}
6263 +
6264 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6265 +{
6266 + char *postrm_file_name;
6267 +
6268 + if (conf->noaction) return 0;
6269 +
6270 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6271 + pkg->dest->info_dir, pkg->name);
6272 + unlink(postrm_file_name);
6273 + free(postrm_file_name);
6274 +
6275 + return 0;
6276 +}
6277 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_remove.h busybox-1.3.1-911/archival/libipkg/ipkg_remove.h
6278 --- busybox-1.3.1-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6279 +++ busybox-1.3.1-911/archival/libipkg/ipkg_remove.h 2006-12-27 19:41:04.000000000 +0100
6280 @@ -0,0 +1,33 @@
6281 +/* ipkg_remove.h - the itsy package management system
6282 +
6283 + Carl D. Worth
6284 +
6285 + Copyright (C) 2001 University of Southern California
6286 +
6287 + This program is free software; you can redistribute it and/or
6288 + modify it under the terms of the GNU General Public License as
6289 + published by the Free Software Foundation; either version 2, or (at
6290 + your option) any later version.
6291 +
6292 + This program is distributed in the hope that it will be useful, but
6293 + WITHOUT ANY WARRANTY; without even the implied warranty of
6294 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6295 + General Public License for more details.
6296 +*/
6297 +
6298 +#ifndef IPKG_REMOVE_H
6299 +#define IPKG_REMOVE_H
6300 +
6301 +#include "pkg.h"
6302 +#include "ipkg_conf.h"
6303 +
6304 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6305 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6306 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6307 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6308 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6309 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6310 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6311 +
6312 +
6313 +#endif
6314 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_upgrade.c busybox-1.3.1-911/archival/libipkg/ipkg_upgrade.c
6315 --- busybox-1.3.1-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6316 +++ busybox-1.3.1-911/archival/libipkg/ipkg_upgrade.c 2006-12-27 19:41:04.000000000 +0100
6317 @@ -0,0 +1,77 @@
6318 +/* ipkg_upgrade.c - the itsy package management system
6319 +
6320 + Carl D. Worth
6321 + Copyright (C) 2001 University of Southern California
6322 +
6323 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6324 +
6325 + This program is free software; you can redistribute it and/or
6326 + modify it under the terms of the GNU General Public License as
6327 + published by the Free Software Foundation; either version 2, or (at
6328 + your option) any later version.
6329 +
6330 + This program is distributed in the hope that it will be useful, but
6331 + WITHOUT ANY WARRANTY; without even the implied warranty of
6332 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6333 + General Public License for more details.
6334 +*/
6335 +
6336 +#include "ipkg.h"
6337 +#include "ipkg_install.h"
6338 +#include "ipkg_message.h"
6339 +
6340 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6341 +{
6342 + pkg_t *new;
6343 + int cmp;
6344 + char *old_version, *new_version;
6345 +
6346 + if (old->state_flag & SF_HOLD) {
6347 + ipkg_message(conf, IPKG_NOTICE,
6348 + "Not upgrading package %s which is marked "
6349 + "hold (flags=%#x)\n", old->name, old->state_flag);
6350 + return 0;
6351 + }
6352 +
6353 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6354 + if (new == NULL) {
6355 + old_version = pkg_version_str_alloc(old);
6356 + ipkg_message(conf, IPKG_NOTICE,
6357 + "Assuming locally installed package %s (%s) "
6358 + "is up to date.\n", old->name, old_version);
6359 + free(old_version);
6360 + return 0;
6361 + }
6362 +
6363 + old_version = pkg_version_str_alloc(old);
6364 + new_version = pkg_version_str_alloc(new);
6365 +
6366 + cmp = pkg_compare_versions(old, new);
6367 + ipkg_message(conf, IPKG_DEBUG,
6368 + "comparing visible versions of pkg %s:"
6369 + "\n\t%s is installed "
6370 + "\n\t%s is available "
6371 + "\n\t%d was comparison result\n",
6372 + old->name, old_version, new_version, cmp);
6373 + if (cmp == 0) {
6374 + ipkg_message(conf, IPKG_INFO,
6375 + "Package %s (%s) installed in %s is up to date.\n",
6376 + old->name, old_version, old->dest->name);
6377 + free(old_version);
6378 + free(new_version);
6379 + return 0;
6380 + } else if (cmp > 0) {
6381 + ipkg_message(conf, IPKG_NOTICE,
6382 + "Not downgrading package %s on %s from %s to %s.\n",
6383 + old->name, old->dest->name, old_version, new_version);
6384 + free(old_version);
6385 + free(new_version);
6386 + return 0;
6387 + } else if (cmp < 0) {
6388 + new->dest = old->dest;
6389 + old->state_want = SW_DEINSTALL;
6390 + }
6391 +
6392 + new->state_flag |= SF_USER;
6393 + return ipkg_install_pkg(conf, new,1);
6394 +}
6395 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_upgrade.h busybox-1.3.1-911/archival/libipkg/ipkg_upgrade.h
6396 --- busybox-1.3.1-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6397 +++ busybox-1.3.1-911/archival/libipkg/ipkg_upgrade.h 2006-12-27 19:41:04.000000000 +0100
6398 @@ -0,0 +1,18 @@
6399 +/* ipkg_upgrade.c - the itsy package management system
6400 +
6401 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6402 +
6403 + This program is free software; you can redistribute it and/or
6404 + modify it under the terms of the GNU General Public License as
6405 + published by the Free Software Foundation; either version 2, or (at
6406 + your option) any later version.
6407 +
6408 + This program is distributed in the hope that it will be useful, but
6409 + WITHOUT ANY WARRANTY; without even the implied warranty of
6410 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6411 + General Public License for more details.
6412 +*/
6413 +
6414 +#include "ipkg.h"
6415 +
6416 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6417 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_utils.c busybox-1.3.1-911/archival/libipkg/ipkg_utils.c
6418 --- busybox-1.3.1-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6419 +++ busybox-1.3.1-911/archival/libipkg/ipkg_utils.c 2006-12-27 19:41:04.000000000 +0100
6420 @@ -0,0 +1,181 @@
6421 +/* ipkg_utils.c - the itsy package management system
6422 +
6423 + Steven M. Ayer
6424 +
6425 + Copyright (C) 2002 Compaq Computer Corporation
6426 +
6427 + This program is free software; you can redistribute it and/or
6428 + modify it under the terms of the GNU General Public License as
6429 + published by the Free Software Foundation; either version 2, or (at
6430 + your option) any later version.
6431 +
6432 + This program is distributed in the hope that it will be useful, but
6433 + WITHOUT ANY WARRANTY; without even the implied warranty of
6434 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6435 + General Public License for more details.
6436 +*/
6437 +
6438 +#include "ipkg.h"
6439 +#include <errno.h>
6440 +#include <ctype.h>
6441 +#include <sys/vfs.h>
6442 +
6443 +#include "ipkg_utils.h"
6444 +#include "pkg.h"
6445 +#include "pkg_hash.h"
6446 +
6447 +struct errlist* error_list;
6448 +
6449 +int get_available_blocks(char * filesystem)
6450 +{
6451 + struct statfs sfs;
6452 +
6453 + if(statfs(filesystem, &sfs)){
6454 + fprintf(stderr, "bad statfs\n");
6455 + return 0;
6456 + }
6457 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6458 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6459 +}
6460 +
6461 +char **read_raw_pkgs_from_file(const char *file_name)
6462 +{
6463 + FILE *fp;
6464 + char **ret;
6465 +
6466 + if(!(fp = fopen(file_name, "r"))){
6467 + fprintf(stderr, "can't get %s open for read\n", file_name);
6468 + return NULL;
6469 + }
6470 +
6471 + ret = read_raw_pkgs_from_stream(fp);
6472 +
6473 + fclose(fp);
6474 +
6475 + return ret;
6476 +}
6477 +
6478 +char **read_raw_pkgs_from_stream(FILE *fp)
6479 +{
6480 + char **raw = NULL, *buf, *scout;
6481 + int count = 0;
6482 + size_t size = 512;
6483 +
6484 + buf = malloc (size);
6485 +
6486 + while (fgets(buf, size, fp)) {
6487 + while (strlen (buf) == (size - 1)
6488 + && buf[size-2] != '\n') {
6489 + size_t o = size - 1;
6490 + size *= 2;
6491 + buf = realloc (buf, size);
6492 + if (fgets (buf + o, size - o, fp) == NULL)
6493 + break;
6494 + }
6495 +
6496 + if(!(count % 50))
6497 + raw = realloc(raw, (count + 50) * sizeof(char *));
6498 +
6499 + if((scout = strchr(buf, '\n')))
6500 + *scout = '\0';
6501 +
6502 + raw[count++] = strdup(buf);
6503 + }
6504 +
6505 + raw = realloc(raw, (count + 1) * sizeof(char *));
6506 + raw[count] = NULL;
6507 +
6508 + free (buf);
6509 +
6510 + return raw;
6511 +}
6512 +
6513 +/* something to remove whitespace, a hash pooper */
6514 +char *trim_alloc(char *line)
6515 +{
6516 + char *new;
6517 + char *dest, *src, *end;
6518 +
6519 + new = malloc(strlen(line) + 1);
6520 + if ( new == NULL ){
6521 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6522 + return NULL;
6523 + }
6524 + dest = new, src = line, end = line + (strlen(line) - 1);
6525 +
6526 + /* remove it from the front */
6527 + while(src &&
6528 + isspace(*src) &&
6529 + *src)
6530 + src++;
6531 + /* and now from the back */
6532 + while((end > src) &&
6533 + isspace(*end))
6534 + end--;
6535 + end++;
6536 + *end = '\0';
6537 + strcpy(new, src);
6538 + /* this does from the first space
6539 + * blasting away any versions stuff in depends
6540 + while(src &&
6541 + !isspace(*src) &&
6542 + *src)
6543 + *dest++ = *src++;
6544 + *dest = '\0';
6545 + */
6546 +
6547 + return new;
6548 +}
6549 +
6550 +int line_is_blank(const char *line)
6551 +{
6552 + const char *s;
6553 +
6554 + for (s = line; *s; s++) {
6555 + if (!isspace(*s))
6556 + return 0;
6557 + }
6558 + return 1;
6559 +}
6560 +
6561 +void push_error_list(struct errlist ** errors, char * msg){
6562 + struct errlist *err_lst_tmp;
6563 +
6564 +
6565 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6566 + err_lst_tmp->errmsg=strdup(msg) ;
6567 + err_lst_tmp->next = *errors;
6568 + *errors = err_lst_tmp;
6569 +}
6570 +
6571 +
6572 +void reverse_error_list(struct errlist **errors){
6573 + struct errlist *result=NULL;
6574 + struct errlist *current= *errors;
6575 + struct errlist *next;
6576 +
6577 + while ( current != NULL ) {
6578 + next = current->next;
6579 + current->next=result;
6580 + result=current;
6581 + current=next;
6582 + }
6583 + *errors=result;
6584 +
6585 +}
6586 +
6587 +
6588 +void free_error_list(struct errlist **errors){
6589 + struct errlist *current = *errors;
6590 +
6591 + while (current != NULL) {
6592 + free(current->errmsg);
6593 + current = (*errors)->next;
6594 + free(*errors);
6595 + *errors = current;
6596 + }
6597 +
6598 +
6599 +}
6600 +
6601 +
6602 diff -ruN busybox-1.3.1-orig/archival/libipkg/ipkg_utils.h busybox-1.3.1-911/archival/libipkg/ipkg_utils.h
6603 --- busybox-1.3.1-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6604 +++ busybox-1.3.1-911/archival/libipkg/ipkg_utils.h 2006-12-27 19:41:04.000000000 +0100
6605 @@ -0,0 +1,29 @@
6606 +/* ipkg_utils.h - the itsy package management system
6607 +
6608 + Steven M. Ayer
6609 +
6610 + Copyright (C) 2002 Compaq Computer Corporation
6611 +
6612 + This program is free software; you can redistribute it and/or
6613 + modify it under the terms of the GNU General Public License as
6614 + published by the Free Software Foundation; either version 2, or (at
6615 + your option) any later version.
6616 +
6617 + This program is distributed in the hope that it will be useful, but
6618 + WITHOUT ANY WARRANTY; without even the implied warranty of
6619 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6620 + General Public License for more details.
6621 +*/
6622 +
6623 +#ifndef IPKG_UTILS_H
6624 +#define IPKG_UTILS_H
6625 +
6626 +#include "pkg.h"
6627 +
6628 +int get_available_blocks(char * filesystem);
6629 +char **read_raw_pkgs_from_file(const char *file_name);
6630 +char **read_raw_pkgs_from_stream(FILE *fp);
6631 +char *trim_alloc(char * line);
6632 +int line_is_blank(const char *line);
6633 +
6634 +#endif
6635 diff -ruN busybox-1.3.1-orig/archival/libipkg/Kbuild busybox-1.3.1-911/archival/libipkg/Kbuild
6636 --- busybox-1.3.1-orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
6637 +++ busybox-1.3.1-911/archival/libipkg/Kbuild 2006-12-28 02:03:22.000000000 +0100
6638 @@ -0,0 +1,61 @@
6639 +# Makefile for busybox
6640 +#
6641 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6642 +# Copyright (C) 2006 OpenWrt.org
6643 +#
6644 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6645 +
6646 +LIBIPKG_CORE_OBJS:= \
6647 + args.o \
6648 + libipkg.o \
6649 + user.o \
6650 +
6651 +LIBIPKG_CMD_OBJS:= \
6652 + ipkg_cmd.o \
6653 + ipkg_configure.o \
6654 + ipkg_download.o \
6655 + ipkg_install.o \
6656 + ipkg_remove.o \
6657 + ipkg_upgrade.o \
6658 +
6659 +LIBIPKG_DB_OBJS:= \
6660 + hash_table.o \
6661 + ipkg_conf.o \
6662 + ipkg_utils.o \
6663 + pkg.o \
6664 + pkg_depends.o \
6665 + pkg_extract.o \
6666 + pkg_hash.o \
6667 + pkg_parse.o \
6668 + pkg_vec.o \
6669 +
6670 +LIBIPKG_LIST_OBJS:= \
6671 + conffile.o \
6672 + conffile_list.o \
6673 + nv_pair.o \
6674 + nv_pair_list.o \
6675 + pkg_dest.o \
6676 + pkg_dest_list.o \
6677 + pkg_src.o \
6678 + pkg_src_list.o \
6679 + str_list.o \
6680 + void_list.o \
6681 +
6682 +LIBIPKG_UTIL_OBJS:= \
6683 + file_util.o \
6684 + ipkg_message.o \
6685 + md5.o \
6686 + str_util.o \
6687 + xsystem.o \
6688 +
6689 +lib-y :=
6690 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6691 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6692 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6693 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6694 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6695 +
6696 +ifeq ($(strip $(IPKG_ARCH)),)
6697 +IPKG_ARCH:=$(TARGET_ARCH)
6698 +endif
6699 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6700 diff -ruN busybox-1.3.1-orig/archival/libipkg/libipkg.c busybox-1.3.1-911/archival/libipkg/libipkg.c
6701 --- busybox-1.3.1-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6702 +++ busybox-1.3.1-911/archival/libipkg/libipkg.c 2006-12-27 19:41:04.000000000 +0100
6703 @@ -0,0 +1,527 @@
6704 +/* ipkglib.c - the itsy package management system
6705 +
6706 + Florina Boor
6707 +
6708 + Copyright (C) 2003 kernel concepts
6709 +
6710 + This program is free software; you can redistribute it and/or
6711 + modify it under the terms of the GNU General Public License as
6712 + published by the Free Software Foundation; either version 2, or (at
6713 + your option) any later version.
6714 +
6715 + This program is distributed in the hope that it will be useful, but
6716 + WITHOUT ANY WARRANTY; without even the implied warranty of
6717 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6718 + General Public License for more details.
6719 +*/
6720 +
6721 +#ifdef IPKG_LIB
6722 +
6723 +#include "ipkg.h"
6724 +#include "ipkg_includes.h"
6725 +#include "libipkg.h"
6726 +
6727 +#include "args.h"
6728 +#include "ipkg_conf.h"
6729 +#include "ipkg_cmd.h"
6730 +#include "file_util.h"
6731 +
6732 +
6733 +
6734 +ipkg_message_callback ipkg_cb_message = NULL;
6735 +ipkg_response_callback ipkg_cb_response = NULL;
6736 +ipkg_status_callback ipkg_cb_status = NULL;
6737 +ipkg_list_callback ipkg_cb_list = NULL;
6738 +
6739 +
6740 +int
6741 +ipkg_init (ipkg_message_callback mcall,
6742 + ipkg_response_callback rcall,
6743 + args_t * args)
6744 +{
6745 + ipkg_cb_message = mcall;
6746 + ipkg_cb_response = rcall;
6747 +
6748 + args_init (args);
6749 +
6750 + return 0;
6751 +}
6752 +
6753 +
6754 +int
6755 +ipkg_deinit (args_t * args)
6756 +{
6757 + args_deinit (args);
6758 + ipkg_cb_message = NULL;
6759 + ipkg_cb_response = NULL;
6760 +
6761 + /* place other cleanup stuff here */
6762 +
6763 + return 0;
6764 +}
6765 +
6766 +
6767 +int
6768 +ipkg_packages_list(args_t *args,
6769 + const char *packages,
6770 + ipkg_list_callback cblist,
6771 + void *userdata)
6772 +{
6773 + ipkg_cmd_t *cmd;
6774 + ipkg_conf_t ipkg_conf;
6775 + int err;
6776 +
6777 + err = ipkg_conf_init (&ipkg_conf, args);
6778 + if (err)
6779 + {
6780 + return err;
6781 + }
6782 +
6783 + ipkg_cb_list = cblist;
6784 + /* we need to do this because of static declarations,
6785 + * maybe a good idea to change */
6786 + cmd = ipkg_cmd_find ("list");
6787 + if (packages)
6788 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6789 + else
6790 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6791 + ipkg_cb_list = NULL;
6792 + ipkg_conf_deinit (&ipkg_conf);
6793 + return (err);
6794 +}
6795 +
6796 +
6797 +int
6798 +ipkg_packages_status(args_t *args,
6799 + const char *packages,
6800 + ipkg_status_callback cbstatus,
6801 + void *userdata)
6802 +{
6803 + ipkg_cmd_t *cmd;
6804 + ipkg_conf_t ipkg_conf;
6805 + int err;
6806 +
6807 + err = ipkg_conf_init (&ipkg_conf, args);
6808 + if (err)
6809 + {
6810 + return err;
6811 + }
6812 +
6813 + ipkg_cb_status = cbstatus;
6814 +
6815 + /* we need to do this because of static declarations,
6816 + * maybe a good idea to change */
6817 + cmd = ipkg_cmd_find ("status");
6818 + if (packages)
6819 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6820 + else
6821 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6822 +
6823 + ipkg_cb_status = NULL;
6824 + ipkg_conf_deinit (&ipkg_conf);
6825 + return (err);
6826 +}
6827 +
6828 +
6829 +int
6830 +ipkg_packages_info(args_t *args,
6831 + const char *packages,
6832 + ipkg_status_callback cbstatus,
6833 + void *userdata)
6834 +{
6835 + ipkg_cmd_t *cmd;
6836 + ipkg_conf_t ipkg_conf;
6837 + int err;
6838 +
6839 + err = ipkg_conf_init (&ipkg_conf, args);
6840 + if (err)
6841 + {
6842 + return err;
6843 + }
6844 +
6845 + ipkg_cb_status = cbstatus;
6846 +
6847 + /* we need to do this because of static declarations,
6848 + * maybe a good idea to change */
6849 + cmd = ipkg_cmd_find ("info");
6850 + if (packages)
6851 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6852 + else
6853 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6854 +
6855 + ipkg_cb_status = NULL;
6856 + ipkg_conf_deinit (&ipkg_conf);
6857 + return (err);
6858 +}
6859 +
6860 +
6861 +int
6862 +ipkg_packages_install (args_t * args, const char *name)
6863 +{
6864 + ipkg_cmd_t *cmd;
6865 + ipkg_conf_t ipkg_conf;
6866 + int err;
6867 +
6868 + /* this error should be handled in application */
6869 + if (!name || !strlen (name))
6870 + return (-1);
6871 +
6872 + err = ipkg_conf_init (&ipkg_conf, args);
6873 + if (err)
6874 + {
6875 + return err;
6876 + }
6877 +
6878 + /* we need to do this because of static declarations,
6879 + * maybe a good idea to change */
6880 + cmd = ipkg_cmd_find ("install");
6881 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6882 +
6883 + ipkg_conf_deinit(&ipkg_conf);
6884 + return (err);
6885 +}
6886 +
6887 +
6888 +int
6889 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6890 +{
6891 + ipkg_cmd_t *cmd;
6892 + ipkg_conf_t ipkg_conf;
6893 + int err;
6894 +
6895 + /* this error should be handled in application */
6896 + if (!name || !strlen (name))
6897 + return (-1);
6898 +
6899 + err = ipkg_conf_init (&ipkg_conf, args);
6900 + if (err)
6901 + {
6902 + return err;
6903 + }
6904 +
6905 + /* we need to do this because of static declarations,
6906 + * maybe a good idea to change */
6907 + if (purge)
6908 + cmd = ipkg_cmd_find ("purge");
6909 + else
6910 + cmd = ipkg_cmd_find ("remove");
6911 +
6912 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6913 +
6914 + ipkg_conf_deinit(&ipkg_conf);
6915 + return (err);
6916 +}
6917 +
6918 +
6919 +int
6920 +ipkg_lists_update(args_t *args)
6921 +{
6922 + ipkg_cmd_t *cmd;
6923 + ipkg_conf_t ipkg_conf;
6924 + int err;
6925 +
6926 + err = ipkg_conf_init (&ipkg_conf, args);
6927 + if (err)
6928 + {
6929 + return err;
6930 + }
6931 +
6932 + /* we need to do this because of static declarations,
6933 + * maybe a good idea to change */
6934 + cmd = ipkg_cmd_find ("update");
6935 +
6936 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6937 +
6938 + ipkg_conf_deinit(&ipkg_conf);
6939 + return (err);
6940 +}
6941 +
6942 +
6943 +int
6944 +ipkg_packages_upgrade(args_t *args)
6945 +{
6946 + ipkg_cmd_t *cmd;
6947 + ipkg_conf_t ipkg_conf;
6948 + int err;
6949 +
6950 + err = ipkg_conf_init (&ipkg_conf, args);
6951 + if (err)
6952 + {
6953 + return err;
6954 + }
6955 +
6956 + /* we need to do this because of static declarations,
6957 + * maybe a good idea to change */
6958 + cmd = ipkg_cmd_find ("upgrade");
6959 +
6960 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6961 +
6962 + ipkg_conf_deinit(&ipkg_conf);
6963 + return (err);
6964 +}
6965 +
6966 +
6967 +int
6968 +ipkg_packages_download (args_t * args, const char *name)
6969 +{
6970 + ipkg_cmd_t *cmd;
6971 + ipkg_conf_t ipkg_conf;
6972 + int err;
6973 +
6974 + /* this error should be handled in application */
6975 + if (!name || !strlen (name))
6976 + return (-1);
6977 +
6978 + err = ipkg_conf_init (&ipkg_conf, args);
6979 + if (err)
6980 + {
6981 + return err;
6982 + }
6983 +
6984 + /* we need to do this because of static declarations,
6985 + * maybe a good idea to change */
6986 + cmd = ipkg_cmd_find ("download");
6987 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6988 +
6989 + ipkg_conf_deinit(&ipkg_conf);
6990 + return (err);
6991 +}
6992 +
6993 +
6994 +int
6995 +ipkg_package_files(args_t *args,
6996 + const char *name,
6997 + ipkg_list_callback cblist,
6998 + void *userdata)
6999 +{
7000 + ipkg_cmd_t *cmd;
7001 + ipkg_conf_t ipkg_conf;
7002 + int err;
7003 +
7004 + /* this error should be handled in application */
7005 + if (!name || !strlen (name))
7006 + return (-1);
7007 +
7008 + err = ipkg_conf_init (&ipkg_conf, args);
7009 + if (err)
7010 + {
7011 + return err;
7012 + }
7013 +
7014 + ipkg_cb_list = cblist;
7015 +
7016 + /* we need to do this because of static declarations,
7017 + * maybe a good idea to change */
7018 + cmd = ipkg_cmd_find ("files");
7019 +
7020 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7021 +
7022 + ipkg_cb_list = NULL;
7023 + ipkg_conf_deinit(&ipkg_conf);
7024 + return (err);
7025 +}
7026 +
7027 +
7028 +int
7029 +ipkg_file_search(args_t *args,
7030 + const char *file,
7031 + ipkg_list_callback cblist,
7032 + void *userdata)
7033 +{
7034 + ipkg_cmd_t *cmd;
7035 + ipkg_conf_t ipkg_conf;
7036 + int err;
7037 +
7038 + /* this error should be handled in application */
7039 + if (!file || !strlen (file))
7040 + return (-1);
7041 +
7042 + err = ipkg_conf_init (&ipkg_conf, args);
7043 + if (err)
7044 + {
7045 + return err;
7046 + }
7047 +
7048 + ipkg_cb_list = cblist;
7049 +
7050 + /* we need to do this because of static declarations,
7051 + * maybe a good idea to change */
7052 + cmd = ipkg_cmd_find ("search");
7053 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7054 +
7055 + ipkg_cb_list = NULL;
7056 + ipkg_conf_deinit(&ipkg_conf);
7057 + return(err);
7058 +}
7059 +
7060 +
7061 +int
7062 +ipkg_file_what(args_t *args, const char *file, const char* command)
7063 +{
7064 + ipkg_cmd_t *cmd;
7065 + ipkg_conf_t ipkg_conf;
7066 + int err;
7067 +
7068 + /* this error should be handled in application */
7069 + if (!file || !strlen (file))
7070 + return (-1);
7071 +
7072 + err = ipkg_conf_init (&ipkg_conf, args);
7073 + if (err)
7074 + {
7075 + return err;
7076 + }
7077 +
7078 + /* we need to do this because of static declarations,
7079 + * maybe a good idea to change */
7080 + cmd = ipkg_cmd_find (command);
7081 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7082 +
7083 + ipkg_conf_deinit(&ipkg_conf);
7084 + return(err);
7085 +}
7086 +
7087 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7088 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7089 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7090 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7091 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7092 +
7093 +
7094 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7095 + char *msg)
7096 +{
7097 + if (conf && (conf->verbosity < level)) {
7098 + return 0;
7099 + } else {
7100 +#ifdef IPKG_LIB
7101 + if ( level == IPKG_ERROR ){
7102 + push_error_list(&error_list, msg);
7103 +// printf(msg);
7104 + } else
7105 +#endif
7106 + printf(msg);
7107 + }
7108 + return 0;
7109 +}
7110 +
7111 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7112 + pkg_state_status_t status, void *userdata)
7113 +{
7114 + if (desc)
7115 + printf("%s - %s - %s\n", name, version, desc);
7116 + else
7117 + printf("%s - %s\n", name, version);
7118 + return 0;
7119 +}
7120 +
7121 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7122 + pkg_state_status_t status, void *userdata)
7123 +{
7124 + if (desc)
7125 + printf("%s\n", desc);
7126 + return 0;
7127 +}
7128 +
7129 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7130 + void *userdata)
7131 +{
7132 + printf("%s\n", desc);
7133 + return 0;
7134 +}
7135 +
7136 +char* default_ipkg_response_callback(char *question)
7137 +{
7138 + char *response = NULL;
7139 + printf(question);
7140 + fflush(stdout);
7141 + do {
7142 + response = (char *)file_read_line_alloc(stdin);
7143 + } while (response == NULL);
7144 + return response;
7145 +}
7146 +
7147 +/* This is used for backward compatibility */
7148 +int
7149 +ipkg_op (int argc, char *argv[])
7150 +{
7151 + int err, optind;
7152 + args_t args;
7153 + char *cmd_name;
7154 + ipkg_cmd_t *cmd;
7155 + ipkg_conf_t ipkg_conf;
7156 +
7157 + args_init (&args);
7158 +
7159 + optind = args_parse (&args, argc, argv);
7160 + if (optind == argc || optind < 0)
7161 + {
7162 + args_usage ("ipkg must have one sub-command argument");
7163 + }
7164 +
7165 + cmd_name = argv[optind++];
7166 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7167 + read anything from there.
7168 +*/
7169 + if ( !strcmp(cmd_name,"print-architecture") ||
7170 + !strcmp(cmd_name,"print_architecture") ||
7171 + !strcmp(cmd_name,"print-installation-architecture") ||
7172 + !strcmp(cmd_name,"print_installation_architecture") )
7173 + args.nocheckfordirorfile = 1;
7174 +
7175 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7176 + read anything from there.
7177 +*/
7178 + if ( !strcmp(cmd_name,"flag") ||
7179 + !strcmp(cmd_name,"configure") ||
7180 + !strcmp(cmd_name,"remove") ||
7181 + !strcmp(cmd_name,"files") ||
7182 + !strcmp(cmd_name,"search") ||
7183 + !strcmp(cmd_name,"compare_versions") ||
7184 + !strcmp(cmd_name,"compare-versions") ||
7185 + !strcmp(cmd_name,"list_installed") ||
7186 + !strcmp(cmd_name,"list-installed") ||
7187 + !strcmp(cmd_name,"status") )
7188 + args.noreadfeedsfile = 1;
7189 +
7190 +
7191 + err = ipkg_conf_init (&ipkg_conf, &args);
7192 + if (err)
7193 + {
7194 + return err;
7195 + }
7196 +
7197 + args_deinit (&args);
7198 +
7199 + ipkg_cb_message = default_ipkg_message_callback;
7200 + ipkg_cb_response = default_ipkg_response_callback;
7201 + ipkg_cb_status = default_ipkg_status_callback;
7202 + if ( strcmp(cmd_name, "files")==0)
7203 + ipkg_cb_list = default_ipkg_files_callback;
7204 + else
7205 + ipkg_cb_list = default_ipkg_list_callback;
7206 +
7207 + cmd = ipkg_cmd_find (cmd_name);
7208 + if (cmd == NULL)
7209 + {
7210 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7211 + cmd_name);
7212 + args_usage (NULL);
7213 + }
7214 +
7215 + if (cmd->requires_args && optind == argc)
7216 + {
7217 + fprintf (stderr,
7218 + "%s: the ``%s'' command requires at least one argument\n",
7219 + __FUNCTION__, cmd_name);
7220 + args_usage (NULL);
7221 + }
7222 +
7223 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7224 +
7225 + ipkg_conf_deinit (&ipkg_conf);
7226 +
7227 + return err;
7228 +}
7229 +
7230 +#endif /* IPKG_LIB */
7231 diff -ruN busybox-1.3.1-orig/archival/libipkg/libipkg.h busybox-1.3.1-911/archival/libipkg/libipkg.h
7232 --- busybox-1.3.1-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7233 +++ busybox-1.3.1-911/archival/libipkg/libipkg.h 2006-12-27 19:41:04.000000000 +0100
7234 @@ -0,0 +1,87 @@
7235 +/* ipkglib.h - the itsy package management system
7236 +
7237 + Florian Boor <florian.boor@kernelconcepts.de>
7238 +
7239 + This program is free software; you can redistribute it and/or
7240 + modify it under the terms of the GNU General Public License as
7241 + published by the Free Software Foundation; either version 2, or (at
7242 + your option) any later version.
7243 +
7244 + This program is distributed in the hope that it will be useful, but
7245 + WITHOUT ANY WARRANTY; without even the implied warranty of
7246 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7247 + General Public License for more details.
7248 +*/
7249 +
7250 +#ifndef IPKGLIB_H
7251 +#define IPKGLIB_H
7252 +
7253 +#ifdef IPKG_LIB
7254 +
7255 +#include "ipkg_conf.h"
7256 +#include "ipkg_message.h"
7257 +
7258 +#include "args.h"
7259 +#include "pkg.h"
7260 +
7261 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7262 + char *msg);
7263 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7264 + pkg_state_status_t status, void *userdata);
7265 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7266 + void *userdata);
7267 +typedef char* (*ipkg_response_callback)(char *question);
7268 +
7269 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7270 +extern int ipkg_init (ipkg_message_callback mcall,
7271 + ipkg_response_callback rcall,
7272 + args_t * args);
7273 +
7274 +extern int ipkg_deinit (args_t *args);
7275 +extern int ipkg_packages_list(args_t *args,
7276 + const char *packages,
7277 + ipkg_list_callback cblist,
7278 + void *userdata);
7279 +extern int ipkg_packages_status(args_t *args,
7280 + const char *packages,
7281 + ipkg_status_callback cbstatus,
7282 + void *userdata);
7283 +extern int ipkg_packages_info(args_t *args,
7284 + const char *packages,
7285 + ipkg_status_callback cbstatus,
7286 + void *userdata);
7287 +extern int ipkg_packages_install(args_t *args, const char *name);
7288 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7289 +extern int ipkg_lists_update(args_t *args);
7290 +extern int ipkg_packages_upgrade(args_t *args);
7291 +extern int ipkg_packages_download(args_t *args, const char *name);
7292 +extern int ipkg_package_files(args_t *args,
7293 + const char *name,
7294 + ipkg_list_callback cblist,
7295 + void *userdata);
7296 +extern int ipkg_file_search(args_t *args,
7297 + const char *file,
7298 + ipkg_list_callback cblist,
7299 + void *userdata);
7300 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7301 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7302 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7303 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7304 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7305 +
7306 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7307 +extern ipkg_response_callback ipkg_cb_response;
7308 +extern ipkg_status_callback ipkg_cb_status;
7309 +extern ipkg_list_callback ipkg_cb_list;
7310 +extern void push_error_list(struct errlist **errors,char * msg);
7311 +extern void reverse_error_list(struct errlist **errors);
7312 +extern void free_error_list(struct errlist **errors);
7313 +
7314 +#else
7315 +
7316 +extern int ipkg_op(int argc, char *argv[]);
7317 +
7318 +#endif
7319 +
7320 +
7321 +#endif
7322 diff -ruN busybox-1.3.1-orig/archival/libipkg/md5.c busybox-1.3.1-911/archival/libipkg/md5.c
7323 --- busybox-1.3.1-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7324 +++ busybox-1.3.1-911/archival/libipkg/md5.c 2006-12-27 19:41:04.000000000 +0100
7325 @@ -0,0 +1,48 @@
7326 +/* md5.c - wrappers to busybox md5 functions
7327 + *
7328 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7329 + *
7330 + * This program is free software; you can redistribute it and/or modify
7331 + * it under the terms of the GNU General Public License as published by
7332 + * the Free Software Foundation; either version 2, or (at your option)
7333 + * any later version.
7334 + *
7335 + * This program is distributed in the hope that it will be useful,
7336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7338 + * GNU General Public License for more details.
7339 + *
7340 + * You should have received a copy of the GNU General Public License
7341 + * along with this program; if not, write to the Free Software Foundation,
7342 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7343 + */
7344 +
7345 +#include <stdio.h>
7346 +#include "libbb.h"
7347 +
7348 +#include "md5.h"
7349 +
7350 +int md5_stream(FILE *stream, void *resblock)
7351 +{
7352 + int fd;
7353 + int sum;
7354 +
7355 + if( (fd = fileno(stream)) == -1 ) {
7356 + bb_error_msg("bad file descriptor");
7357 + return 1;
7358 + }
7359 +
7360 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7361 +
7362 + return 0;
7363 +}
7364 +
7365 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7366 +{
7367 + md5_ctx_t md5_cx;
7368 +
7369 + md5_begin(&md5_cx);
7370 + md5_hash(buffer, len, &md5_cx);
7371 + return md5_end(resblock, &md5_cx);
7372 +}
7373 +
7374 diff -ruN busybox-1.3.1-orig/archival/libipkg/md5.h busybox-1.3.1-911/archival/libipkg/md5.h
7375 --- busybox-1.3.1-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7376 +++ busybox-1.3.1-911/archival/libipkg/md5.h 2006-12-27 19:41:04.000000000 +0100
7377 @@ -0,0 +1,35 @@
7378 +/* md5.h - Compute MD5 checksum of files or strings according to the
7379 + * definition of MD5 in RFC 1321 from April 1992.
7380 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7381 + *
7382 + * This program is free software; you can redistribute it and/or modify
7383 + * it under the terms of the GNU General Public License as published by
7384 + * the Free Software Foundation; either version 2, or (at your option)
7385 + * any later version.
7386 + *
7387 + * This program is distributed in the hope that it will be useful,
7388 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7389 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7390 + * GNU General Public License for more details.
7391 + *
7392 + * You should have received a copy of the GNU General Public License
7393 + * along with this program; if not, write to the Free Software Foundation,
7394 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7395 + */
7396 +
7397 +#ifndef MD5_H
7398 +#define MD5_H
7399 +
7400 +/* Compute MD5 message digest for bytes read from STREAM. The
7401 + resulting message digest number will be written into the 16 bytes
7402 + beginning at RESBLOCK. */
7403 +int md5_stream(FILE *stream, void *resblock);
7404 +
7405 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7406 + result is always in little endian byte order, so that a byte-wise
7407 + output yields to the wanted ASCII representation of the message
7408 + digest. */
7409 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7410 +
7411 +#endif
7412 +
7413 diff -ruN busybox-1.3.1-orig/archival/libipkg/nv_pair.c busybox-1.3.1-911/archival/libipkg/nv_pair.c
7414 --- busybox-1.3.1-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7415 +++ busybox-1.3.1-911/archival/libipkg/nv_pair.c 2006-12-27 19:41:04.000000000 +0100
7416 @@ -0,0 +1,40 @@
7417 +/* nv_pair.c - the itsy package management system
7418 +
7419 + Carl D. Worth
7420 +
7421 + Copyright (C) 2001 University of Southern California
7422 +
7423 + This program is free software; you can redistribute it and/or
7424 + modify it under the terms of the GNU General Public License as
7425 + published by the Free Software Foundation; either version 2, or (at
7426 + your option) any later version.
7427 +
7428 + This program is distributed in the hope that it will be useful, but
7429 + WITHOUT ANY WARRANTY; without even the implied warranty of
7430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7431 + General Public License for more details.
7432 +*/
7433 +
7434 +#include "ipkg.h"
7435 +
7436 +#include "nv_pair.h"
7437 +#include "str_util.h"
7438 +
7439 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7440 +{
7441 + nv_pair->name = str_dup_safe(name);
7442 + nv_pair->value = str_dup_safe(value);
7443 +
7444 + return 0;
7445 +}
7446 +
7447 +void nv_pair_deinit(nv_pair_t *nv_pair)
7448 +{
7449 + free(nv_pair->name);
7450 + nv_pair->name = NULL;
7451 +
7452 + free(nv_pair->value);
7453 + nv_pair->value = NULL;
7454 +}
7455 +
7456 +
7457 diff -ruN busybox-1.3.1-orig/archival/libipkg/nv_pair.h busybox-1.3.1-911/archival/libipkg/nv_pair.h
7458 --- busybox-1.3.1-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7459 +++ busybox-1.3.1-911/archival/libipkg/nv_pair.h 2006-12-27 19:41:04.000000000 +0100
7460 @@ -0,0 +1,32 @@
7461 +/* nv_pair.h - the itsy package management system
7462 +
7463 + Carl D. Worth
7464 +
7465 + Copyright (C) 2001 University of Southern California
7466 +
7467 + This program is free software; you can redistribute it and/or
7468 + modify it under the terms of the GNU General Public License as
7469 + published by the Free Software Foundation; either version 2, or (at
7470 + your option) any later version.
7471 +
7472 + This program is distributed in the hope that it will be useful, but
7473 + WITHOUT ANY WARRANTY; without even the implied warranty of
7474 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7475 + General Public License for more details.
7476 +*/
7477 +
7478 +#ifndef NV_PAIR_H
7479 +#define NV_PAIR_H
7480 +
7481 +typedef struct nv_pair nv_pair_t;
7482 +struct nv_pair
7483 +{
7484 + char *name;
7485 + char *value;
7486 +};
7487 +
7488 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7489 +void nv_pair_deinit(nv_pair_t *nv_pair);
7490 +
7491 +#endif
7492 +
7493 diff -ruN busybox-1.3.1-orig/archival/libipkg/nv_pair_list.c busybox-1.3.1-911/archival/libipkg/nv_pair_list.c
7494 --- busybox-1.3.1-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7495 +++ busybox-1.3.1-911/archival/libipkg/nv_pair_list.c 2006-12-27 19:41:04.000000000 +0100
7496 @@ -0,0 +1,98 @@
7497 +/* nv_pair_list.c - the itsy package management system
7498 +
7499 + Carl D. Worth
7500 +
7501 + Copyright (C) 2001 University of Southern California
7502 +
7503 + This program is free software; you can redistribute it and/or
7504 + modify it under the terms of the GNU General Public License as
7505 + published by the Free Software Foundation; either version 2, or (at
7506 + your option) any later version.
7507 +
7508 + This program is distributed in the hope that it will be useful, but
7509 + WITHOUT ANY WARRANTY; without even the implied warranty of
7510 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7511 + General Public License for more details.
7512 +*/
7513 +
7514 +#include "ipkg.h"
7515 +
7516 +#include "nv_pair.h"
7517 +#include "void_list.h"
7518 +#include "nv_pair_list.h"
7519 +
7520 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7521 +{
7522 + return void_list_elt_init((void_list_elt_t *) elt, data);
7523 +}
7524 +
7525 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7526 +{
7527 + void_list_elt_deinit((void_list_elt_t *) elt);
7528 +}
7529 +
7530 +int nv_pair_list_init(nv_pair_list_t *list)
7531 +{
7532 + return void_list_init((void_list_t *) list);
7533 +}
7534 +
7535 +void nv_pair_list_deinit(nv_pair_list_t *list)
7536 +{
7537 + nv_pair_list_elt_t *iter;
7538 + nv_pair_t *nv_pair;
7539 +
7540 + for (iter = list->head; iter; iter = iter->next) {
7541 + nv_pair = iter->data;
7542 + nv_pair_deinit(nv_pair);
7543 +
7544 + /* malloced in nv_pair_list_append */
7545 + free(nv_pair);
7546 + iter->data = NULL;
7547 + }
7548 + void_list_deinit((void_list_t *) list);
7549 +}
7550 +
7551 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7552 +{
7553 + int err;
7554 +
7555 + /* freed in nv_pair_list_deinit */
7556 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7557 +
7558 + if (nv_pair == NULL) {
7559 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7560 + return NULL;
7561 + }
7562 + nv_pair_init(nv_pair, name, value);
7563 +
7564 + err = void_list_append((void_list_t *) list, nv_pair);
7565 + if (err) {
7566 + return NULL;
7567 + }
7568 +
7569 + return nv_pair;
7570 +}
7571 +
7572 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7573 +{
7574 + return void_list_push((void_list_t *) list, data);
7575 +}
7576 +
7577 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7578 +{
7579 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7580 +}
7581 +
7582 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7583 +{
7584 + nv_pair_list_elt_t *iter;
7585 + nv_pair_t *nv_pair;
7586 +
7587 + for (iter = list->head; iter; iter = iter->next) {
7588 + nv_pair = iter->data;
7589 + if (strcmp(nv_pair->name, name) == 0) {
7590 + return nv_pair->value;
7591 + }
7592 + }
7593 + return NULL;
7594 +}
7595 diff -ruN busybox-1.3.1-orig/archival/libipkg/nv_pair_list.h busybox-1.3.1-911/archival/libipkg/nv_pair_list.h
7596 --- busybox-1.3.1-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7597 +++ busybox-1.3.1-911/archival/libipkg/nv_pair_list.h 2006-12-27 19:41:04.000000000 +0100
7598 @@ -0,0 +1,60 @@
7599 +/* nv_pair_list.h - the itsy package management system
7600 +
7601 + Carl D. Worth
7602 +
7603 + Copyright (C) 2001 University of Southern California
7604 +
7605 + This program is free software; you can redistribute it and/or
7606 + modify it under the terms of the GNU General Public License as
7607 + published by the Free Software Foundation; either version 2, or (at
7608 + your option) any later version.
7609 +
7610 + This program is distributed in the hope that it will be useful, but
7611 + WITHOUT ANY WARRANTY; without even the implied warranty of
7612 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7613 + General Public License for more details.
7614 +*/
7615 +
7616 +#ifndef NV_PAIR_LIST_H
7617 +#define NV_PAIR_LIST_H
7618 +
7619 +#include "nv_pair.h"
7620 +#include "void_list.h"
7621 +
7622 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7623 +struct nv_pair_list_elt
7624 +{
7625 + nv_pair_list_elt_t *next;
7626 + nv_pair_t *data;
7627 +};
7628 +
7629 +typedef struct nv_pair_list nv_pair_list_t;
7630 +struct nv_pair_list
7631 +{
7632 + nv_pair_list_elt_t pre_head;
7633 + nv_pair_list_elt_t *head;
7634 + nv_pair_list_elt_t *tail;
7635 +};
7636 +
7637 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7638 +{
7639 + if (list->head == NULL)
7640 + return 1;
7641 + else
7642 + return 0;
7643 +}
7644 +
7645 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7646 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7647 +
7648 +int nv_pair_list_init(nv_pair_list_t *list);
7649 +void nv_pair_list_deinit(nv_pair_list_t *list);
7650 +
7651 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7652 + const char *name, const char *value);
7653 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7654 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7655 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7656 +
7657 +#endif
7658 +
7659 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg.c busybox-1.3.1-911/archival/libipkg/pkg.c
7660 --- busybox-1.3.1-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7661 +++ busybox-1.3.1-911/archival/libipkg/pkg.c 2006-12-27 19:41:04.000000000 +0100
7662 @@ -0,0 +1,1754 @@
7663 +/* pkg.c - the itsy package management system
7664 +
7665 + Carl D. Worth
7666 +
7667 + Copyright (C) 2001 University of Southern California
7668 +
7669 + This program is free software; you can redistribute it and/or
7670 + modify it under the terms of the GNU General Public License as
7671 + published by the Free Software Foundation; either version 2, or (at
7672 + your option) any later version.
7673 +
7674 + This program is distributed in the hope that it will be useful, but
7675 + WITHOUT ANY WARRANTY; without even the implied warranty of
7676 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7677 + General Public License for more details.
7678 +*/
7679 +
7680 +#include "ipkg.h"
7681 +#include <ctype.h>
7682 +#include <string.h>
7683 +#include <errno.h>
7684 +
7685 +#include "pkg.h"
7686 +
7687 +#include "pkg_parse.h"
7688 +#include "pkg_extract.h"
7689 +#include "ipkg_message.h"
7690 +#include "ipkg_utils.h"
7691 +
7692 +#include "sprintf_alloc.h"
7693 +#include "file_util.h"
7694 +#include "str_util.h"
7695 +#include "xsystem.h"
7696 +#include "ipkg_conf.h"
7697 +
7698 +typedef struct enum_map enum_map_t;
7699 +struct enum_map
7700 +{
7701 + int value;
7702 + char *str;
7703 +};
7704 +
7705 +static const enum_map_t pkg_state_want_map[] = {
7706 + { SW_UNKNOWN, "unknown"},
7707 + { SW_INSTALL, "install"},
7708 + { SW_DEINSTALL, "deinstall"},
7709 + { SW_PURGE, "purge"}
7710 +};
7711 +
7712 +static const enum_map_t pkg_state_flag_map[] = {
7713 + { SF_OK, "ok"},
7714 + { SF_REINSTREQ, "reinstreq"},
7715 + { SF_HOLD, "hold"},
7716 + { SF_REPLACE, "replace"},
7717 + { SF_NOPRUNE, "noprune"},
7718 + { SF_PREFER, "prefer"},
7719 + { SF_OBSOLETE, "obsolete"},
7720 + { SF_USER, "user"},
7721 +};
7722 +
7723 +static const enum_map_t pkg_state_status_map[] = {
7724 + { SS_NOT_INSTALLED, "not-installed" },
7725 + { SS_UNPACKED, "unpacked" },
7726 + { SS_HALF_CONFIGURED, "half-configured" },
7727 + { SS_INSTALLED, "installed" },
7728 + { SS_HALF_INSTALLED, "half-installed" },
7729 + { SS_CONFIG_FILES, "config-files" },
7730 + { SS_POST_INST_FAILED, "post-inst-failed" },
7731 + { SS_REMOVAL_FAILED, "removal-failed" }
7732 +};
7733 +
7734 +static int verrevcmp(const char *val, const char *ref);
7735 +
7736 +
7737 +pkg_t *pkg_new(void)
7738 +{
7739 + pkg_t *pkg;
7740 +
7741 + pkg = malloc(sizeof(pkg_t));
7742 + if (pkg == NULL) {
7743 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7744 + return NULL;
7745 + }
7746 +
7747 + pkg_init(pkg);
7748 +
7749 + return pkg;
7750 +}
7751 +
7752 +int pkg_init(pkg_t *pkg)
7753 +{
7754 + memset(pkg, 0, sizeof(pkg_t));
7755 + pkg->name = NULL;
7756 + pkg->epoch = 0;
7757 + pkg->version = NULL;
7758 + pkg->revision = NULL;
7759 + pkg->familiar_revision = NULL;
7760 + pkg->dest = NULL;
7761 + pkg->src = NULL;
7762 + pkg->architecture = NULL;
7763 + pkg->maintainer = NULL;
7764 + pkg->section = NULL;
7765 + pkg->description = NULL;
7766 + pkg->state_want = SW_UNKNOWN;
7767 + pkg->state_flag = SF_OK;
7768 + pkg->state_status = SS_NOT_INSTALLED;
7769 + pkg->depends_str = NULL;
7770 + pkg->provides_str = NULL;
7771 + pkg->depends_count = 0;
7772 + pkg->depends = NULL;
7773 + pkg->suggests_str = NULL;
7774 + pkg->recommends_str = NULL;
7775 + pkg->suggests_count = 0;
7776 + pkg->recommends_count = 0;
7777 +
7778 + /* Abhaya: added init for conflicts fields */
7779 + pkg->conflicts = NULL;
7780 + pkg->conflicts_count = 0;
7781 +
7782 + /* added for replaces. Jamey 7/23/2002 */
7783 + pkg->replaces = NULL;
7784 + pkg->replaces_count = 0;
7785 +
7786 + pkg->pre_depends_count = 0;
7787 + pkg->pre_depends_str = NULL;
7788 + pkg->provides_count = 0;
7789 + pkg->provides = NULL;
7790 + pkg->filename = NULL;
7791 + pkg->local_filename = NULL;
7792 + pkg->tmp_unpack_dir = NULL;
7793 + pkg->md5sum = NULL;
7794 + pkg->size = NULL;
7795 + pkg->installed_size = NULL;
7796 + pkg->priority = NULL;
7797 + pkg->source = NULL;
7798 + conffile_list_init(&pkg->conffiles);
7799 + pkg->installed_files = NULL;
7800 + pkg->installed_files_ref_cnt = 0;
7801 + pkg->essential = 0;
7802 + pkg->provided_by_hand = 0;
7803 +
7804 + return 0;
7805 +}
7806 +
7807 +void pkg_deinit(pkg_t *pkg)
7808 +{
7809 + free(pkg->name);
7810 + pkg->name = NULL;
7811 + pkg->epoch = 0;
7812 + free(pkg->version);
7813 + pkg->version = NULL;
7814 + /* revision and familiar_revision share storage with version, so
7815 + don't free */
7816 + pkg->revision = NULL;
7817 + pkg->familiar_revision = NULL;
7818 + /* owned by ipkg_conf_t */
7819 + pkg->dest = NULL;
7820 + /* owned by ipkg_conf_t */
7821 + pkg->src = NULL;
7822 + free(pkg->architecture);
7823 + pkg->architecture = NULL;
7824 + free(pkg->maintainer);
7825 + pkg->maintainer = NULL;
7826 + free(pkg->section);
7827 + pkg->section = NULL;
7828 + free(pkg->description);
7829 + pkg->description = NULL;
7830 + pkg->state_want = SW_UNKNOWN;
7831 + pkg->state_flag = SF_OK;
7832 + pkg->state_status = SS_NOT_INSTALLED;
7833 + free(pkg->depends_str);
7834 + pkg->depends_str = NULL;
7835 + free(pkg->provides_str);
7836 + pkg->provides_str = NULL;
7837 + pkg->depends_count = 0;
7838 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7839 + pkg->pre_depends_count = 0;
7840 + free(pkg->pre_depends_str);
7841 + pkg->pre_depends_str = NULL;
7842 + pkg->provides_count = 0;
7843 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7844 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7845 + free(pkg->filename);
7846 + pkg->filename = NULL;
7847 + free(pkg->local_filename);
7848 + pkg->local_filename = NULL;
7849 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7850 + ipkg_install.c here. See comment in
7851 + ipkg_install.c:cleanup_temporary_files */
7852 + free(pkg->tmp_unpack_dir);
7853 + pkg->tmp_unpack_dir = NULL;
7854 + free(pkg->md5sum);
7855 + pkg->md5sum = NULL;
7856 + free(pkg->size);
7857 + pkg->size = NULL;
7858 + free(pkg->installed_size);
7859 + pkg->installed_size = NULL;
7860 + free(pkg->priority);
7861 + pkg->priority = NULL;
7862 + free(pkg->source);
7863 + pkg->source = NULL;
7864 + conffile_list_deinit(&pkg->conffiles);
7865 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7866 + since if they are calling deinit, they should know. Maybe do an
7867 + assertion here instead? */
7868 + pkg->installed_files_ref_cnt = 1;
7869 + pkg_free_installed_files(pkg);
7870 + pkg->essential = 0;
7871 +}
7872 +
7873 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7874 +{
7875 + int err;
7876 + char **raw;
7877 + FILE *control_file;
7878 +
7879 + err = pkg_init(pkg);
7880 + if (err) { return err; }
7881 +
7882 + pkg->local_filename = strdup(filename);
7883 +
7884 + control_file = tmpfile();
7885 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7886 + if (err) { return err; }
7887 +
7888 + rewind(control_file);
7889 + raw = read_raw_pkgs_from_stream(control_file);
7890 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7891 +
7892 + fclose(control_file);
7893 +
7894 + return 0;
7895 +}
7896 +
7897 +/* Merge any new information in newpkg into oldpkg */
7898 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7899 + newpkg, but should leave it usable. This rework is so that
7900 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7901 +/*
7902 + * uh, i thought that i had originally written this so that it took
7903 + * two pkgs and returned a new one? we can do that again... -sma
7904 + */
7905 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7906 +{
7907 + if (oldpkg == newpkg) {
7908 + return 0;
7909 + }
7910 +
7911 + if (!oldpkg->src)
7912 + oldpkg->src = newpkg->src;
7913 + if (!oldpkg->dest)
7914 + oldpkg->dest = newpkg->dest;
7915 + if (!oldpkg->architecture)
7916 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7917 + if (!oldpkg->arch_priority)
7918 + oldpkg->arch_priority = newpkg->arch_priority;
7919 + if (!oldpkg->section)
7920 + oldpkg->section = str_dup_safe(newpkg->section);
7921 + if(!oldpkg->maintainer)
7922 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7923 + if(!oldpkg->description)
7924 + oldpkg->description = str_dup_safe(newpkg->description);
7925 + if (set_status) {
7926 + /* merge the state_flags from the new package */
7927 + oldpkg->state_want = newpkg->state_want;
7928 + oldpkg->state_status = newpkg->state_status;
7929 + oldpkg->state_flag = newpkg->state_flag;
7930 + } else {
7931 + if (oldpkg->state_want == SW_UNKNOWN)
7932 + oldpkg->state_want = newpkg->state_want;
7933 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7934 + oldpkg->state_status = newpkg->state_status;
7935 + oldpkg->state_flag |= newpkg->state_flag;
7936 + }
7937 +
7938 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7939 + oldpkg->depends_str = newpkg->depends_str;
7940 + newpkg->depends_str = NULL;
7941 + oldpkg->depends_count = newpkg->depends_count;
7942 + newpkg->depends_count = 0;
7943 +
7944 + oldpkg->depends = newpkg->depends;
7945 + newpkg->depends = NULL;
7946 +
7947 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7948 + newpkg->pre_depends_str = NULL;
7949 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7950 + newpkg->pre_depends_count = 0;
7951 +
7952 + oldpkg->recommends_str = newpkg->recommends_str;
7953 + newpkg->recommends_str = NULL;
7954 + oldpkg->recommends_count = newpkg->recommends_count;
7955 + newpkg->recommends_count = 0;
7956 +
7957 + oldpkg->suggests_str = newpkg->suggests_str;
7958 + newpkg->suggests_str = NULL;
7959 + oldpkg->suggests_count = newpkg->suggests_count;
7960 + newpkg->suggests_count = 0;
7961 + }
7962 +
7963 + if (!oldpkg->provides_str) {
7964 + oldpkg->provides_str = newpkg->provides_str;
7965 + newpkg->provides_str = NULL;
7966 + oldpkg->provides_count = newpkg->provides_count;
7967 + newpkg->provides_count = 0;
7968 +
7969 + oldpkg->provides = newpkg->provides;
7970 + newpkg->provides = NULL;
7971 + }
7972 +
7973 + if (!oldpkg->conflicts_str) {
7974 + oldpkg->conflicts_str = newpkg->conflicts_str;
7975 + newpkg->conflicts_str = NULL;
7976 + oldpkg->conflicts_count = newpkg->conflicts_count;
7977 + newpkg->conflicts_count = 0;
7978 +
7979 + oldpkg->conflicts = newpkg->conflicts;
7980 + newpkg->conflicts = NULL;
7981 + }
7982 +
7983 + if (!oldpkg->replaces_str) {
7984 + oldpkg->replaces_str = newpkg->replaces_str;
7985 + newpkg->replaces_str = NULL;
7986 + oldpkg->replaces_count = newpkg->replaces_count;
7987 + newpkg->replaces_count = 0;
7988 +
7989 + oldpkg->replaces = newpkg->replaces;
7990 + newpkg->replaces = NULL;
7991 + }
7992 +
7993 + if (!oldpkg->filename)
7994 + oldpkg->filename = str_dup_safe(newpkg->filename);
7995 + if (0)
7996 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7997 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7998 + if (!oldpkg->local_filename)
7999 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8000 + if (!oldpkg->tmp_unpack_dir)
8001 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8002 + if (!oldpkg->md5sum)
8003 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8004 + if (!oldpkg->size)
8005 + oldpkg->size = str_dup_safe(newpkg->size);
8006 + if (!oldpkg->installed_size)
8007 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8008 + if (!oldpkg->priority)
8009 + oldpkg->priority = str_dup_safe(newpkg->priority);
8010 + if (!oldpkg->source)
8011 + oldpkg->source = str_dup_safe(newpkg->source);
8012 + if (oldpkg->conffiles.head == NULL){
8013 + oldpkg->conffiles = newpkg->conffiles;
8014 + conffile_list_init(&newpkg->conffiles);
8015 + }
8016 + if (!oldpkg->installed_files){
8017 + oldpkg->installed_files = newpkg->installed_files;
8018 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8019 + newpkg->installed_files = NULL;
8020 + }
8021 + if (!oldpkg->essential)
8022 + oldpkg->essential = newpkg->essential;
8023 +
8024 + return 0;
8025 +}
8026 +
8027 +abstract_pkg_t *abstract_pkg_new(void)
8028 +{
8029 + abstract_pkg_t * ab_pkg;
8030 +
8031 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8032 +
8033 + if (ab_pkg == NULL) {
8034 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8035 + return NULL;
8036 + }
8037 +
8038 + if ( abstract_pkg_init(ab_pkg) < 0 )
8039 + return NULL;
8040 +
8041 + return ab_pkg;
8042 +}
8043 +
8044 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8045 +{
8046 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8047 +
8048 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8049 + if (ab_pkg->provided_by==NULL){
8050 + return -1;
8051 + }
8052 + ab_pkg->dependencies_checked = 0;
8053 + ab_pkg->state_status = SS_NOT_INSTALLED;
8054 +
8055 + return 0;
8056 +}
8057 +
8058 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8059 + char * temp_str;
8060 + char **raw =NULL;
8061 + char **raw_start=NULL;
8062 +
8063 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8064 + if (temp_str == NULL ){
8065 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8066 + return;
8067 + }
8068 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8069 +
8070 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8071 + if (raw == NULL ){
8072 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8073 + return;
8074 + }
8075 +
8076 + while(*raw){
8077 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8078 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8079 + }
8080 + }
8081 + raw = raw_start;
8082 + while (*raw) {
8083 + if (raw!=NULL)
8084 + free(*raw++);
8085 + }
8086 +
8087 + free(raw_start);
8088 + free(temp_str);
8089 +
8090 + return ;
8091 +
8092 +}
8093 +
8094 +char * pkg_formatted_info(pkg_t *pkg )
8095 +{
8096 + char *line;
8097 + char * buff;
8098 +
8099 + buff = malloc(8192);
8100 + if (buff == NULL) {
8101 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8102 + return NULL;
8103 + }
8104 +
8105 + buff[0] = '\0';
8106 +
8107 + line = pkg_formatted_field(pkg, "Package");
8108 + strncat(buff ,line, strlen(line));
8109 + free(line);
8110 +
8111 + line = pkg_formatted_field(pkg, "Version");
8112 + strncat(buff ,line, strlen(line));
8113 + free(line);
8114 +
8115 + line = pkg_formatted_field(pkg, "Depends");
8116 + strncat(buff ,line, strlen(line));
8117 + free(line);
8118 +
8119 + line = pkg_formatted_field(pkg, "Recommends");
8120 + strncat(buff ,line, strlen(line));
8121 + free(line);
8122 +
8123 + line = pkg_formatted_field(pkg, "Suggests");
8124 + strncat(buff ,line, strlen(line));
8125 + free(line);
8126 +
8127 + line = pkg_formatted_field(pkg, "Provides");
8128 + strncat(buff ,line, strlen(line));
8129 + free(line);
8130 +
8131 + line = pkg_formatted_field(pkg, "Replaces");
8132 + strncat(buff ,line, strlen(line));
8133 + free(line);
8134 +
8135 + line = pkg_formatted_field(pkg, "Conflicts");
8136 + strncat(buff ,line, strlen(line));
8137 + free(line);
8138 +
8139 + line = pkg_formatted_field(pkg, "Status");
8140 + strncat(buff ,line, strlen(line));
8141 + free(line);
8142 +
8143 + line = pkg_formatted_field(pkg, "Section");
8144 + strncat(buff ,line, strlen(line));
8145 + free(line);
8146 +
8147 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8148 + strncat(buff ,line, strlen(line));
8149 + free(line);
8150 +
8151 + line = pkg_formatted_field(pkg, "Architecture");
8152 + strncat(buff ,line, strlen(line));
8153 + free(line);
8154 +
8155 + line = pkg_formatted_field(pkg, "Maintainer");
8156 + strncat(buff ,line, strlen(line));
8157 + free(line);
8158 +
8159 + line = pkg_formatted_field(pkg, "MD5sum");
8160 + strncat(buff ,line, strlen(line));
8161 + free(line);
8162 +
8163 + line = pkg_formatted_field(pkg, "Size");
8164 + strncat(buff ,line, strlen(line));
8165 + free(line);
8166 +
8167 + line = pkg_formatted_field(pkg, "Filename");
8168 + strncat(buff ,line, strlen(line));
8169 + free(line);
8170 +
8171 + line = pkg_formatted_field(pkg, "Conffiles");
8172 + strncat(buff ,line, strlen(line));
8173 + free(line);
8174 +
8175 + line = pkg_formatted_field(pkg, "Source");
8176 + strncat(buff ,line, strlen(line));
8177 + free(line);
8178 +
8179 + line = pkg_formatted_field(pkg, "Description");
8180 + strncat(buff ,line, strlen(line));
8181 + free(line);
8182 +
8183 + line = pkg_formatted_field(pkg, "Installed-Time");
8184 + strncat(buff ,line, strlen(line));
8185 + free(line);
8186 +
8187 + return buff;
8188 +}
8189 +
8190 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8191 +{
8192 + static size_t LINE_LEN = 128;
8193 + char * temp = (char *)malloc(1);
8194 + int len = 0;
8195 + int flag_provide_false = 0;
8196 +
8197 +/*
8198 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8199 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8200 +*/
8201 +
8202 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8203 + goto UNKNOWN_FMT_FIELD;
8204 + }
8205 +
8206 + temp[0]='\0';
8207 +
8208 + switch (field[0])
8209 + {
8210 + case 'a':
8211 + case 'A':
8212 + if (strcasecmp(field, "Architecture") == 0) {
8213 + /* Architecture */
8214 + if (pkg->architecture) {
8215 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8216 + if ( temp == NULL ){
8217 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8218 + return NULL;
8219 + }
8220 + temp[0]='\0';
8221 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8222 + }
8223 + } else {
8224 + goto UNKNOWN_FMT_FIELD;
8225 + }
8226 + break;
8227 + case 'c':
8228 + case 'C':
8229 + if (strcasecmp(field, "Conffiles") == 0) {
8230 + /* Conffiles */
8231 + conffile_list_elt_t *iter;
8232 + char confstr[LINE_LEN];
8233 +
8234 + if (pkg->conffiles.head == NULL) {
8235 + return temp;
8236 + }
8237 +
8238 + len = 14 ;
8239 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8240 + if (iter->data->name && iter->data->value) {
8241 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8242 + }
8243 + }
8244 + temp = (char *)realloc(temp,len);
8245 + if ( temp == NULL ){
8246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8247 + return NULL;
8248 + }
8249 + temp[0]='\0';
8250 + strncpy(temp, "Conffiles:\n", 12);
8251 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8252 + if (iter->data->name && iter->data->value) {
8253 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8254 + strncat(temp, confstr, strlen(confstr));
8255 + }
8256 + }
8257 + } else if (strcasecmp(field, "Conflicts") == 0) {
8258 + int i;
8259 +
8260 + if (pkg->conflicts_count) {
8261 + char conflictstr[LINE_LEN];
8262 + len = 14 ;
8263 + for(i = 0; i < pkg->conflicts_count; i++) {
8264 + len = len + (strlen(pkg->conflicts_str[i])+5);
8265 + }
8266 + temp = (char *)realloc(temp,len);
8267 + if ( temp == NULL ){
8268 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8269 + return NULL;
8270 + }
8271 + temp[0]='\0';
8272 + strncpy(temp, "Conflicts:", 11);
8273 + for(i = 0; i < pkg->conflicts_count; i++) {
8274 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8275 + strncat(temp, conflictstr, strlen(conflictstr));
8276 + }
8277 + strncat(temp, "\n", strlen("\n"));
8278 + }
8279 + } else {
8280 + goto UNKNOWN_FMT_FIELD;
8281 + }
8282 + break;
8283 + case 'd':
8284 + case 'D':
8285 + if (strcasecmp(field, "Depends") == 0) {
8286 + /* Depends */
8287 + int i;
8288 +
8289 + if (pkg->depends_count) {
8290 + char depstr[LINE_LEN];
8291 + len = 14 ;
8292 + for(i = 0; i < pkg->depends_count; i++) {
8293 + len = len + (strlen(pkg->depends_str[i])+4);
8294 + }
8295 + temp = (char *)realloc(temp,len);
8296 + if ( temp == NULL ){
8297 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8298 + return NULL;
8299 + }
8300 + temp[0]='\0';
8301 + strncpy(temp, "Depends:", 10);
8302 + for(i = 0; i < pkg->depends_count; i++) {
8303 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8304 + strncat(temp, depstr, strlen(depstr));
8305 + }
8306 + strncat(temp, "\n", strlen("\n"));
8307 + }
8308 + } else if (strcasecmp(field, "Description") == 0) {
8309 + /* Description */
8310 + if (pkg->description) {
8311 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8312 + if ( temp == NULL ){
8313 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8314 + return NULL;
8315 + }
8316 + temp[0]='\0';
8317 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8318 + }
8319 + } else {
8320 + goto UNKNOWN_FMT_FIELD;
8321 + }
8322 + break;
8323 + case 'e':
8324 + case 'E': {
8325 + /* Essential */
8326 + if (pkg->essential) {
8327 + temp = (char *)realloc(temp,16);
8328 + if ( temp == NULL ){
8329 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8330 + return NULL;
8331 + }
8332 + temp[0]='\0';
8333 + snprintf(temp, (16), "Essential: yes\n");
8334 + }
8335 + }
8336 + break;
8337 + case 'f':
8338 + case 'F': {
8339 + /* Filename */
8340 + if (pkg->filename) {
8341 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8342 + if ( temp == NULL ){
8343 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8344 + return NULL;
8345 + }
8346 + temp[0]='\0';
8347 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8348 + }
8349 + }
8350 + break;
8351 + case 'i':
8352 + case 'I': {
8353 + if (strcasecmp(field, "Installed-Size") == 0) {
8354 + /* Installed-Size */
8355 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8356 + if ( temp == NULL ){
8357 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8358 + return NULL;
8359 + }
8360 + temp[0]='\0';
8361 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8362 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8363 + temp = (char *)realloc(temp,29);
8364 + if ( temp == NULL ){
8365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8366 + return NULL;
8367 + }
8368 + temp[0]='\0';
8369 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8370 + }
8371 + }
8372 + break;
8373 + case 'm':
8374 + case 'M': {
8375 + /* Maintainer | MD5sum */
8376 + if (strcasecmp(field, "Maintainer") == 0) {
8377 + /* Maintainer */
8378 + if (pkg->maintainer) {
8379 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8380 + if ( temp == NULL ){
8381 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8382 + return NULL;
8383 + }
8384 + temp[0]='\0';
8385 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8386 + }
8387 + } else if (strcasecmp(field, "MD5sum") == 0) {
8388 + /* MD5sum */
8389 + if (pkg->md5sum) {
8390 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8391 + if ( temp == NULL ){
8392 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8393 + return NULL;
8394 + }
8395 + temp[0]='\0';
8396 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8397 + }
8398 + } else {
8399 + goto UNKNOWN_FMT_FIELD;
8400 + }
8401 + }
8402 + break;
8403 + case 'p':
8404 + case 'P': {
8405 + if (strcasecmp(field, "Package") == 0) {
8406 + /* Package */
8407 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8408 + if ( temp == NULL ){
8409 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8410 + return NULL;
8411 + }
8412 + temp[0]='\0';
8413 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8414 + } else if (strcasecmp(field, "Priority") == 0) {
8415 + /* Priority */
8416 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8417 + if ( temp == NULL ){
8418 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8419 + return NULL;
8420 + }
8421 + temp[0]='\0';
8422 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8423 + } else if (strcasecmp(field, "Provides") == 0) {
8424 + /* Provides */
8425 + int i;
8426 +
8427 + if (pkg->provides_count) {
8428 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8429 + for ( i=0; i < pkg->provides_count; i++ ){
8430 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8431 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8432 + flag_provide_false = 1;
8433 + }
8434 + }
8435 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8436 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8437 + char provstr[LINE_LEN];
8438 + len = 15;
8439 + for(i = 0; i < pkg->provides_count; i++) {
8440 + len = len + (strlen(pkg->provides_str[i])+5);
8441 + }
8442 + temp = (char *)realloc(temp,len);
8443 + if ( temp == NULL ){
8444 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8445 + return NULL;
8446 + }
8447 + temp[0]='\0';
8448 + strncpy(temp, "Provides:", 12);
8449 + for(i = 0; i < pkg->provides_count; i++) {
8450 + if (strlen(pkg->provides_str[i])>0){;
8451 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8452 + strncat(temp, provstr, strlen(provstr));
8453 + }
8454 + }
8455 + strncat(temp, "\n", strlen("\n"));
8456 + }
8457 + }
8458 + } else {
8459 + goto UNKNOWN_FMT_FIELD;
8460 + }
8461 + }
8462 + break;
8463 + case 'r':
8464 + case 'R': {
8465 + int i;
8466 + /* Replaces | Recommends*/
8467 + if (strcasecmp (field, "Replaces") == 0) {
8468 + if (pkg->replaces_count) {
8469 + char replstr[LINE_LEN];
8470 + len = 14;
8471 + for (i = 0; i < pkg->replaces_count; i++) {
8472 + len = len + (strlen(pkg->replaces_str[i])+5);
8473 + }
8474 + temp = (char *)realloc(temp,len);
8475 + if ( temp == NULL ){
8476 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8477 + return NULL;
8478 + }
8479 + temp[0]='\0';
8480 + strncpy(temp, "Replaces:", 12);
8481 + for (i = 0; i < pkg->replaces_count; i++) {
8482 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8483 + strncat(temp, replstr, strlen(replstr));
8484 + }
8485 + strncat(temp, "\n", strlen("\n"));
8486 + }
8487 + } else if (strcasecmp (field, "Recommends") == 0) {
8488 + if (pkg->recommends_count) {
8489 + char recstr[LINE_LEN];
8490 + len = 15;
8491 + for(i = 0; i < pkg->recommends_count; i++) {
8492 + len = len + (strlen( pkg->recommends_str[i])+5);
8493 + }
8494 + temp = (char *)realloc(temp,len);
8495 + if ( temp == NULL ){
8496 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8497 + return NULL;
8498 + }
8499 + temp[0]='\0';
8500 + strncpy(temp, "Recommends:", 13);
8501 + for(i = 0; i < pkg->recommends_count; i++) {
8502 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8503 + strncat(temp, recstr, strlen(recstr));
8504 + }
8505 + strncat(temp, "\n", strlen("\n"));
8506 + }
8507 + } else {
8508 + goto UNKNOWN_FMT_FIELD;
8509 + }
8510 + }
8511 + break;
8512 + case 's':
8513 + case 'S': {
8514 + /* Section | Size | Source | Status | Suggests */
8515 + if (strcasecmp(field, "Section") == 0) {
8516 + /* Section */
8517 + if (pkg->section) {
8518 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8519 + if ( temp == NULL ){
8520 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8521 + return NULL;
8522 + }
8523 + temp[0]='\0';
8524 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8525 + }
8526 + } else if (strcasecmp(field, "Size") == 0) {
8527 + /* Size */
8528 + if (pkg->size) {
8529 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8530 + if ( temp == NULL ){
8531 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8532 + return NULL;
8533 + }
8534 + temp[0]='\0';
8535 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8536 + }
8537 + } else if (strcasecmp(field, "Source") == 0) {
8538 + /* Source */
8539 + if (pkg->source) {
8540 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8541 + if ( temp == NULL ){
8542 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8543 + return NULL;
8544 + }
8545 + temp[0]='\0';
8546 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8547 + }
8548 + } else if (strcasecmp(field, "Status") == 0) {
8549 + /* Status */
8550 + /* Benjamin Pineau note: we should avoid direct usage of
8551 + * strlen(arg) without keeping "arg" for later free()
8552 + */
8553 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8554 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8555 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8556 +
8557 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8558 + temp = (char *)realloc(temp,sum_of_sizes);
8559 + if ( temp == NULL ){
8560 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8561 + return NULL;
8562 + }
8563 + temp[0]='\0';
8564 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8565 + free(pflag);
8566 + free(pwant);
8567 + if(pstat) /* pfstat can be NULL if ENOMEM */
8568 + free(pstat);
8569 + } else if (strcasecmp(field, "Suggests") == 0) {
8570 + if (pkg->suggests_count) {
8571 + int i;
8572 + char sugstr[LINE_LEN];
8573 + len = 13;
8574 + for(i = 0; i < pkg->suggests_count; i++) {
8575 + len = len + (strlen(pkg->suggests_str[i])+5);
8576 + }
8577 + temp = (char *)realloc(temp,len);
8578 + if ( temp == NULL ){
8579 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8580 + return NULL;
8581 + }
8582 + temp[0]='\0';
8583 + strncpy(temp, "Suggests:", 10);
8584 + for(i = 0; i < pkg->suggests_count; i++) {
8585 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8586 + strncat(temp, sugstr, strlen(sugstr));
8587 + }
8588 + strncat(temp, "\n", strlen("\n"));
8589 + }
8590 + } else {
8591 + goto UNKNOWN_FMT_FIELD;
8592 + }
8593 + }
8594 + break;
8595 + case 'v':
8596 + case 'V': {
8597 + /* Version */
8598 + char *version = pkg_version_str_alloc(pkg);
8599 + temp = (char *)realloc(temp,strlen(version)+14);
8600 + if ( temp == NULL ){
8601 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8602 + return NULL;
8603 + }
8604 + temp[0]='\0';
8605 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8606 + free(version);
8607 + }
8608 + break;
8609 + default:
8610 + goto UNKNOWN_FMT_FIELD;
8611 + }
8612 +
8613 + if ( strlen(temp)<2 ) {
8614 + temp[0]='\0';
8615 + }
8616 + return temp;
8617 +
8618 + UNKNOWN_FMT_FIELD:
8619 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8620 + if ( strlen(temp)<2 ) {
8621 + temp[0]='\0';
8622 + }
8623 +
8624 + return temp;
8625 +}
8626 +
8627 +void pkg_print_info(pkg_t *pkg, FILE *file)
8628 +{
8629 + char * buff;
8630 + if (pkg == NULL) {
8631 + return;
8632 + }
8633 +
8634 + buff = pkg_formatted_info(pkg);
8635 + if ( buff == NULL )
8636 + return;
8637 + if (strlen(buff)>2){
8638 + fwrite(buff, 1, strlen(buff), file);
8639 + }
8640 + free(buff);
8641 +}
8642 +
8643 +void pkg_print_status(pkg_t * pkg, FILE * file)
8644 +{
8645 + if (pkg == NULL) {
8646 + return;
8647 + }
8648 +
8649 + /* XXX: QUESTION: Do we actually want more fields here? The
8650 + original idea was to save space by installing only what was
8651 + needed for actual computation, (package, version, status,
8652 + essential, conffiles). The assumption is that all other fields
8653 + can be found in th available file.
8654 +
8655 + But, someone proposed the idea to make it possible to
8656 + reconstruct a .ipk from an installed package, (ie. for beaming
8657 + from one handheld to another). So, maybe we actually want a few
8658 + more fields here, (depends, suggests, etc.), so that that would
8659 + be guaranteed to work even in the absence of more information
8660 + from the available file.
8661 +
8662 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8663 + the essential info needs to be here for all installed packages
8664 + because they may not appear in the Packages files on various
8665 + feeds. Furthermore, one should be able to install from URL or
8666 + local storage without requiring a Packages file from any feed.
8667 + -Jamey
8668 + */
8669 + pkg_print_field(pkg, file, "Package");
8670 + pkg_print_field(pkg, file, "Version");
8671 + pkg_print_field(pkg, file, "Depends");
8672 + pkg_print_field(pkg, file, "Recommends");
8673 + pkg_print_field(pkg, file, "Suggests");
8674 + pkg_print_field(pkg, file, "Provides");
8675 + pkg_print_field(pkg, file, "Replaces");
8676 + pkg_print_field(pkg, file, "Conflicts");
8677 + pkg_print_field(pkg, file, "Status");
8678 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8679 + pkg_print_field(pkg, file, "Architecture");
8680 + pkg_print_field(pkg, file, "Conffiles");
8681 + pkg_print_field(pkg, file, "Installed-Time");
8682 + fputs("\n", file);
8683 +}
8684 +
8685 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8686 +{
8687 + char *buff;
8688 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8689 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8690 + __FUNCTION__, field);
8691 + }
8692 + buff = pkg_formatted_field(pkg, field);
8693 + if (strlen(buff)>2) {
8694 + fprintf(file, "%s", buff);
8695 + fflush(file);
8696 + }
8697 + free(buff);
8698 + return;
8699 +}
8700 +
8701 +/*
8702 + * libdpkg - Debian packaging suite library routines
8703 + * vercmp.c - comparison of version numbers
8704 + *
8705 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8706 + */
8707 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8708 +{
8709 + int r;
8710 +
8711 + if (pkg->epoch > ref_pkg->epoch) {
8712 + return 1;
8713 + }
8714 +
8715 + if (pkg->epoch < ref_pkg->epoch) {
8716 + return -1;
8717 + }
8718 +
8719 + r = verrevcmp(pkg->version, ref_pkg->version);
8720 + if (r) {
8721 + return r;
8722 + }
8723 +
8724 +#ifdef USE_DEBVERSION
8725 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8726 + if (r) {
8727 + return r;
8728 + }
8729 +
8730 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8731 +#endif
8732 +
8733 + return r;
8734 +}
8735 +
8736 +int verrevcmp(const char *val, const char *ref)
8737 +{
8738 + int vc, rc;
8739 + long vl, rl;
8740 + const char *vp, *rp;
8741 + const char *vsep, *rsep;
8742 +
8743 + if (!val) val= "";
8744 + if (!ref) ref= "";
8745 + for (;;) {
8746 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8747 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8748 + for (;;) {
8749 + vc= (val == vp) ? 0 : *val++;
8750 + rc= (ref == rp) ? 0 : *ref++;
8751 + if (!rc && !vc) break;
8752 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8753 + if (rc && !isalpha(rc)) rc += 256;
8754 + if (vc != rc) return vc - rc;
8755 + }
8756 + val= vp;
8757 + ref= rp;
8758 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8759 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8760 + if (vl != rl) return vl - rl;
8761 +
8762 + vc = *val;
8763 + rc = *ref;
8764 + vsep = strchr(".-", vc);
8765 + rsep = strchr(".-", rc);
8766 + if (vsep && !rsep) return -1;
8767 + if (!vsep && rsep) return +1;
8768 +
8769 + if (!*val && !*ref) return 0;
8770 + if (!*val) return -1;
8771 + if (!*ref) return +1;
8772 + }
8773 +}
8774 +
8775 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8776 +{
8777 + int r;
8778 +
8779 + r = pkg_compare_versions(it, ref);
8780 +
8781 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8782 + return r <= 0;
8783 + }
8784 +
8785 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8786 + return r >= 0;
8787 + }
8788 +
8789 + if (strcmp(op, "<<") == 0) {
8790 + return r < 0;
8791 + }
8792 +
8793 + if (strcmp(op, ">>") == 0) {
8794 + return r > 0;
8795 + }
8796 +
8797 + if (strcmp(op, "=") == 0) {
8798 + return r == 0;
8799 + }
8800 +
8801 + fprintf(stderr, "unknown operator: %s", op);
8802 + return 0;
8803 +}
8804 +
8805 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8806 +{
8807 + const pkg_t *a = *(const pkg_t **)p1;
8808 + const pkg_t *b = *(const pkg_t **)p2;
8809 + int namecmp;
8810 + int vercmp;
8811 + if (!a->name || !b->name) {
8812 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8813 + a, a->name, b, b->name);
8814 + return 0;
8815 + }
8816 +
8817 + namecmp = strcmp(a->name, b->name);
8818 + if (namecmp)
8819 + return namecmp;
8820 + vercmp = pkg_compare_versions(a, b);
8821 + if (vercmp)
8822 + return vercmp;
8823 + if (!a->arch_priority || !b->arch_priority) {
8824 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8825 + a, a->arch_priority, b, b->arch_priority);
8826 + return 0;
8827 + }
8828 + if (a->arch_priority > b->arch_priority)
8829 + return 1;
8830 + if (a->arch_priority < b->arch_priority)
8831 + return -1;
8832 + return 0;
8833 +}
8834 +
8835 +int abstract_pkg_name_compare(void *p1, void *p2)
8836 +{
8837 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8838 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8839 + if (!a->name || !b->name) {
8840 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8841 + a, a->name, b, b->name);
8842 + return 0;
8843 + }
8844 + return strcmp(a->name, b->name);
8845 +}
8846 +
8847 +
8848 +char *pkg_version_str_alloc(pkg_t *pkg)
8849 +{
8850 + char *complete_version;
8851 + char *epoch_str;
8852 +#ifdef USE_DEBVERSION
8853 + char *revision_str;
8854 + char *familiar_revision_str;
8855 +#endif
8856 +
8857 + if (pkg->epoch) {
8858 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8859 + } else {
8860 + epoch_str = strdup("");
8861 + }
8862 +
8863 +#ifdef USE_DEBVERSION
8864 + if (pkg->revision && strlen(pkg->revision)) {
8865 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8866 + } else {
8867 + revision_str = strdup("");
8868 + }
8869 +
8870 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8871 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8872 + } else {
8873 + familiar_revision_str = strdup("");
8874 + }
8875 +#endif
8876 +
8877 +#ifdef USE_DEBVERSION
8878 + sprintf_alloc(&complete_version, "%s%s%s%s",
8879 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8880 +#else
8881 + sprintf_alloc(&complete_version, "%s%s",
8882 + epoch_str, pkg->version);
8883 +#endif
8884 +
8885 + free(epoch_str);
8886 +#ifdef USE_DEBVERSION
8887 + free(revision_str);
8888 + free(familiar_revision_str);
8889 +#endif
8890 +
8891 + return complete_version;
8892 +}
8893 +
8894 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8895 +{
8896 + int err;
8897 + char *list_file_name = NULL;
8898 + FILE *list_file = NULL;
8899 + char *line;
8900 + char *installed_file_name;
8901 + int rootdirlen;
8902 +
8903 + pkg->installed_files_ref_cnt++;
8904 +
8905 + if (pkg->installed_files) {
8906 + return pkg->installed_files;
8907 + }
8908 +
8909 + pkg->installed_files = str_list_alloc();
8910 + if (pkg->installed_files == NULL) {
8911 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8912 + return NULL;
8913 + }
8914 +
8915 + /* For uninstalled packages, get the file list firectly from the package.
8916 + For installed packages, look at the package.list file in the database.
8917 + */
8918 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8919 + if (pkg->local_filename == NULL) {
8920 + return pkg->installed_files;
8921 + }
8922 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8923 + file. In other words, change deb_extract so that it can
8924 + simply return the file list as a char *[] rather than
8925 + insisting on writing in to a FILE * as it does now. */
8926 + list_file = tmpfile();
8927 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8928 + if (err) {
8929 + fclose(list_file);
8930 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8931 + __FUNCTION__, pkg->local_filename, strerror(err));
8932 + return pkg->installed_files;
8933 + }
8934 + rewind(list_file);
8935 + } else {
8936 + sprintf_alloc(&list_file_name, "%s/%s.list",
8937 + pkg->dest->info_dir, pkg->name);
8938 + if (! file_exists(list_file_name)) {
8939 + free(list_file_name);
8940 + return pkg->installed_files;
8941 + }
8942 +
8943 + list_file = fopen(list_file_name, "r");
8944 + if (list_file == NULL) {
8945 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8946 + list_file_name, strerror(errno));
8947 + free(list_file_name);
8948 + return pkg->installed_files;
8949 + }
8950 + free(list_file_name);
8951 + }
8952 +
8953 + rootdirlen = strlen( pkg->dest->root_dir );
8954 + while (1) {
8955 + char *file_name;
8956 +
8957 + line = file_read_line_alloc(list_file);
8958 + if (line == NULL) {
8959 + break;
8960 + }
8961 + str_chomp(line);
8962 + file_name = line;
8963 +
8964 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8965 + if( strncmp( pkg->dest->root_dir,
8966 + file_name,
8967 + rootdirlen ) ) {
8968 + if (*file_name == '.') {
8969 + file_name++;
8970 + }
8971 + if (*file_name == '/') {
8972 + file_name++;
8973 + }
8974 +
8975 + /* Freed in pkg_free_installed_files */
8976 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8977 + } else {
8978 + // already contains root_dir as header -> ABSOLUTE
8979 + sprintf_alloc(&installed_file_name, "%s", file_name);
8980 + }
8981 + str_list_append(pkg->installed_files, installed_file_name);
8982 + free(line);
8983 + }
8984 +
8985 + fclose(list_file);
8986 +
8987 + return pkg->installed_files;
8988 +}
8989 +
8990 +/* XXX: CLEANUP: This function and it's counterpart,
8991 + (pkg_get_installed_files), do not match our init/deinit naming
8992 + convention. Nor the alloc/free convention. But, then again, neither
8993 + of these conventions currrently fit the way these two functions
8994 + work. */
8995 +int pkg_free_installed_files(pkg_t *pkg)
8996 +{
8997 + str_list_elt_t *iter;
8998 +
8999 + pkg->installed_files_ref_cnt--;
9000 + if (pkg->installed_files_ref_cnt > 0) {
9001 + return 0;
9002 + }
9003 +
9004 + if (pkg->installed_files) {
9005 +
9006 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9007 + /* malloced in pkg_get_installed_files */
9008 + free (iter->data);
9009 + iter->data = NULL;
9010 + }
9011 +
9012 + str_list_deinit(pkg->installed_files);
9013 + }
9014 +
9015 + pkg->installed_files = NULL;
9016 +
9017 + return 0;
9018 +}
9019 +
9020 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9021 +{
9022 + int err;
9023 + char *list_file_name;
9024 +
9025 + //I don't think pkg_free_installed_files should be called here. Jamey
9026 + //pkg_free_installed_files(pkg);
9027 +
9028 + sprintf_alloc(&list_file_name, "%s/%s.list",
9029 + pkg->dest->info_dir, pkg->name);
9030 + if (!conf->noaction) {
9031 + err = unlink(list_file_name);
9032 + free(list_file_name);
9033 +
9034 + if (err) {
9035 + return errno;
9036 + }
9037 + }
9038 + return 0;
9039 +}
9040 +
9041 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9042 +{
9043 + conffile_list_elt_t *iter;
9044 + conffile_t *conffile;
9045 +
9046 + if (pkg == NULL) {
9047 + return NULL;
9048 + }
9049 +
9050 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9051 + conffile = iter->data;
9052 +
9053 + if (strcmp(conffile->name, file_name) == 0) {
9054 + return conffile;
9055 + }
9056 + }
9057 +
9058 + return NULL;
9059 +}
9060 +
9061 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9062 + const char *script, const char *args)
9063 +{
9064 + int err;
9065 + char *path;
9066 + char *cmd;
9067 +
9068 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9069 + maintainer script within a chroot environment. */
9070 +
9071 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9072 + have scripts in pkg->tmp_unpack_dir. */
9073 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9074 + if (pkg->dest == NULL) {
9075 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9076 + __FUNCTION__, pkg->name);
9077 + return EINVAL;
9078 + }
9079 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9080 + } else {
9081 + if (pkg->tmp_unpack_dir == NULL) {
9082 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9083 + __FUNCTION__, pkg->name);
9084 + return EINVAL;
9085 + }
9086 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9087 + }
9088 +
9089 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9090 + if (conf->noaction) return 0;
9091 +
9092 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9093 + scripts when running with offline_root mode and/or a dest other
9094 + than '/'. I've been playing around with some clever chroot
9095 + tricks and I might come up with something workable. */
9096 + if (conf->offline_root) {
9097 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9098 + }
9099 +
9100 + setenv("PKG_ROOT",
9101 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9102 +
9103 + if (! file_exists(path)) {
9104 + free(path);
9105 + return 0;
9106 + }
9107 +
9108 + if (conf->offline_root) {
9109 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9110 + free(path);
9111 + return 0;
9112 + }
9113 +
9114 + sprintf_alloc(&cmd, "%s %s", path, args);
9115 + free(path);
9116 +
9117 + err = xsystem(cmd);
9118 + free(cmd);
9119 +
9120 + if (err) {
9121 + fprintf(stderr, "%s script returned status %d\n", script, err);
9122 + return err;
9123 + }
9124 +
9125 + return 0;
9126 +}
9127 +
9128 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9129 +{
9130 + int i;
9131 +
9132 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9133 + if (pkg_state_want_map[i].value == sw) {
9134 + return strdup(pkg_state_want_map[i].str);
9135 + }
9136 + }
9137 +
9138 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9139 + __FUNCTION__, sw);
9140 + return strdup("<STATE_WANT_UNKNOWN>");
9141 +}
9142 +
9143 +pkg_state_want_t pkg_state_want_from_str(char *str)
9144 +{
9145 + int i;
9146 +
9147 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9148 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9149 + return pkg_state_want_map[i].value;
9150 + }
9151 + }
9152 +
9153 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9154 + __FUNCTION__, str);
9155 + return SW_UNKNOWN;
9156 +}
9157 +
9158 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9159 +{
9160 + int i;
9161 + int len = 3; /* ok\000 is minimum */
9162 + char *str = NULL;
9163 +
9164 + /* clear the temporary flags before converting to string */
9165 + sf &= SF_NONVOLATILE_FLAGS;
9166 +
9167 + if (sf == 0) {
9168 + return strdup("ok");
9169 + } else {
9170 +
9171 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9172 + if (sf & pkg_state_flag_map[i].value) {
9173 + len += strlen(pkg_state_flag_map[i].str) + 1;
9174 + }
9175 + }
9176 + str = malloc(len);
9177 + if ( str == NULL ) {
9178 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9179 + return NULL;
9180 + }
9181 + str[0] = 0;
9182 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9183 + if (sf & pkg_state_flag_map[i].value) {
9184 + strcat(str, pkg_state_flag_map[i].str);
9185 + strcat(str, ",");
9186 + }
9187 + }
9188 + len = strlen(str);
9189 + str[len-1] = 0; /* squash last comma */
9190 + return str;
9191 + }
9192 +}
9193 +
9194 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9195 +{
9196 + int i;
9197 + int sf = SF_OK;
9198 +
9199 + if (strcmp(str, "ok") == 0) {
9200 + return SF_OK;
9201 + }
9202 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9203 + const char *sfname = pkg_state_flag_map[i].str;
9204 + int sfname_len = strlen(sfname);
9205 + if (strncmp(str, sfname, sfname_len) == 0) {
9206 + sf |= pkg_state_flag_map[i].value;
9207 + str += sfname_len;
9208 + if (str[0] == ',') {
9209 + str++;
9210 + } else {
9211 + break;
9212 + }
9213 + }
9214 + }
9215 +
9216 + return sf;
9217 +}
9218 +
9219 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9220 +{
9221 + int i;
9222 +
9223 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9224 + if (pkg_state_status_map[i].value == ss) {
9225 + return strdup(pkg_state_status_map[i].str);
9226 + }
9227 + }
9228 +
9229 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9230 + __FUNCTION__, ss);
9231 + return strdup("<STATE_STATUS_UNKNOWN>");
9232 +}
9233 +
9234 +pkg_state_status_t pkg_state_status_from_str(char *str)
9235 +{
9236 + int i;
9237 +
9238 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9239 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9240 + return pkg_state_status_map[i].value;
9241 + }
9242 + }
9243 +
9244 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9245 + __FUNCTION__, str);
9246 + return SS_NOT_INSTALLED;
9247 +}
9248 +
9249 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9250 +{
9251 + nv_pair_list_elt_t *l;
9252 +
9253 + if (!pkg->architecture)
9254 + return 1;
9255 +
9256 + l = conf->arch_list.head;
9257 +
9258 + while (l) {
9259 + nv_pair_t *nv = l->data;
9260 + if (strcmp(nv->name, pkg->architecture) == 0) {
9261 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9262 + return 1;
9263 + }
9264 + l = l->next;
9265 + }
9266 +
9267 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9268 + return 0;
9269 +}
9270 +
9271 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9272 +{
9273 + nv_pair_list_elt_t *l;
9274 +
9275 + l = conf->arch_list.head;
9276 +
9277 + while (l) {
9278 + nv_pair_t *nv = l->data;
9279 + if (strcmp(nv->name, archname) == 0) {
9280 + int priority = strtol(nv->value, NULL, 0);
9281 + return priority;
9282 + }
9283 + l = l->next;
9284 + }
9285 + return 0;
9286 +}
9287 +
9288 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9289 +{
9290 + int i;
9291 + hash_table_t *pkg_hash = &conf->pkg_hash;
9292 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9293 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9294 +
9295 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9296 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9297 + /* update arch_priority for each package */
9298 + for (i = 0; i < available_pkgs->len; i++) {
9299 + pkg_t *pkg = available_pkgs->pkgs[i];
9300 + int arch_priority = 1;
9301 + if (!pkg)
9302 + continue;
9303 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9304 + if (pkg->architecture)
9305 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9306 + else
9307 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9308 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9309 + pkg->arch_priority = arch_priority;
9310 + }
9311 +
9312 + for (i = 0; i < available_pkgs->len; i++) {
9313 + pkg_t *pkg = available_pkgs->pkgs[i];
9314 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9315 + /* clear flags and want for any uninstallable package */
9316 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9317 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9318 + pkg->state_want = SW_UNKNOWN;
9319 + pkg->state_flag = 0;
9320 + }
9321 + }
9322 + pkg_vec_free(available_pkgs);
9323 +
9324 + /* update the file owner data structure */
9325 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9326 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9327 + for (i = 0; i < installed_pkgs->len; i++) {
9328 + pkg_t *pkg = installed_pkgs->pkgs[i];
9329 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9330 + str_list_elt_t *iter;
9331 + if (installed_files == NULL) {
9332 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9333 + break;
9334 + }
9335 + for (iter = installed_files->head; iter; iter = iter->next) {
9336 + char *installed_file = iter->data;
9337 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9338 + file_hash_set_file_owner(conf, installed_file, pkg);
9339 + }
9340 + }
9341 + pkg_vec_free(installed_pkgs);
9342 +
9343 + return 0;
9344 +}
9345 +
9346 +struct pkg_write_filelist_data {
9347 + ipkg_conf_t *conf;
9348 + pkg_t *pkg;
9349 + FILE *stream;
9350 +};
9351 +
9352 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9353 +{
9354 + struct pkg_write_filelist_data *data = data_;
9355 + pkg_t *entry = entry_;
9356 + if (entry == data->pkg) {
9357 + fprintf(data->stream, "%s\n", key);
9358 + }
9359 +}
9360 +
9361 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9362 +{
9363 + struct pkg_write_filelist_data data;
9364 + char *list_file_name = NULL;
9365 + int err = 0;
9366 +
9367 + if (!pkg) {
9368 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9369 + return -EINVAL;
9370 + }
9371 + ipkg_message(conf, IPKG_INFO,
9372 + " creating %s.list file\n", pkg->name);
9373 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9374 + if (!list_file_name) {
9375 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9376 + return -ENOMEM;
9377 + }
9378 + ipkg_message(conf, IPKG_INFO,
9379 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9380 + data.stream = fopen(list_file_name, "w");
9381 + if (!data.stream) {
9382 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9383 + list_file_name, strerror(errno));
9384 + return errno;
9385 + }
9386 + data.pkg = pkg;
9387 + data.conf = conf;
9388 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9389 + fclose(data.stream);
9390 + free(list_file_name);
9391 +
9392 + return err;
9393 +}
9394 +
9395 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9396 +{
9397 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9398 + hash_table_t *pkg_hash = &conf->pkg_hash;
9399 + int i;
9400 + int err;
9401 + if (conf->noaction)
9402 + return 0;
9403 +
9404 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9405 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9406 + for (i = 0; i < installed_pkgs->len; i++) {
9407 + pkg_t *pkg = installed_pkgs->pkgs[i];
9408 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9409 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9410 + err = pkg_write_filelist(conf, pkg);
9411 + if (err)
9412 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9413 + }
9414 + }
9415 + return 0;
9416 +}
9417 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_depends.c busybox-1.3.1-911/archival/libipkg/pkg_depends.c
9418 --- busybox-1.3.1-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9419 +++ busybox-1.3.1-911/archival/libipkg/pkg_depends.c 2006-12-27 19:41:04.000000000 +0100
9420 @@ -0,0 +1,1033 @@
9421 +/* pkg_depends.c - the itsy package management system
9422 +
9423 + Steven M. Ayer
9424 +
9425 + Copyright (C) 2002 Compaq Computer Corporation
9426 +
9427 + This program is free software; you can redistribute it and/or
9428 + modify it under the terms of the GNU General Public License as
9429 + published by the Free Software Foundation; either version 2, or (at
9430 + your option) any later version.
9431 +
9432 + This program is distributed in the hope that it will be useful, but
9433 + WITHOUT ANY WARRANTY; without even the implied warranty of
9434 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9435 + General Public License for more details.
9436 +*/
9437 +
9438 +#include "ipkg.h"
9439 +#include <errno.h>
9440 +#include <ctype.h>
9441 +
9442 +#include "pkg.h"
9443 +#include "ipkg_utils.h"
9444 +#include "pkg_hash.h"
9445 +#include "ipkg_message.h"
9446 +#include "pkg_parse.h"
9447 +#include "hash_table.h"
9448 +
9449 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9450 +static depend_t * depend_init(void);
9451 +static void depend_deinit(depend_t *d);
9452 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9453 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9454 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9455 +
9456 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9457 +{
9458 + depend_t *depend = (depend_t *)cdata;
9459 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9460 + return 1;
9461 + else
9462 + return 0;
9463 +}
9464 +
9465 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9466 +{
9467 + depend_t *depend = (depend_t *)cdata;
9468 +#if 0
9469 + pkg_t * temp = pkg_new();
9470 + int comparison;
9471 + parseVersion(temp, depend->version);
9472 + comparison = pkg_compare_versions(pkg, temp);
9473 + free(temp);
9474 +
9475 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9476 + __FUNCTION__, pkg->name, pkg->version,
9477 + depend, depend->constraint, depend->version,
9478 + comparison, version_constraints_satisfied(depend, pkg));
9479 +#endif
9480 + if (version_constraints_satisfied(depend, pkg))
9481 + return 1;
9482 + else
9483 + return 0;
9484 +}
9485 +
9486 +/* returns ndependences or negative error value */
9487 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9488 + pkg_vec_t *unsatisfied, char *** unresolved)
9489 +{
9490 + pkg_t * satisfier_entry_pkg;
9491 + register int i, j, k;
9492 + int count, found;
9493 + char ** the_lost;
9494 + abstract_pkg_t * ab_pkg;
9495 +
9496 + /*
9497 + * this is a setup to check for redundant/cyclic dependency checks,
9498 + * which are marked at the abstract_pkg level
9499 + */
9500 + if (!(ab_pkg = pkg->parent)) {
9501 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9502 + *unresolved = NULL;
9503 + return 0;
9504 + }
9505 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9506 + *unresolved = NULL;
9507 + return 0;
9508 + } else {
9509 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9510 + }
9511 + /**/
9512 +
9513 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9514 + if (!count){
9515 + *unresolved = NULL;
9516 + return 0;
9517 + }
9518 +
9519 + the_lost = NULL;
9520 +
9521 + /* foreach dependency */
9522 + for (i = 0; i < count; i++) {
9523 + compound_depend_t * compound_depend = &pkg->depends[i];
9524 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9525 + found = 0;
9526 + satisfier_entry_pkg = NULL;
9527 +
9528 + if (compound_depend->type == GREEDY_DEPEND) {
9529 + /* foreach possible satisfier */
9530 + for (j = 0; j < compound_depend->possibility_count; j++) {
9531 + /* foreach provided_by, which includes the abstract_pkg itself */
9532 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9533 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9534 + int nposs = ab_provider_vec->len;
9535 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9536 + int l;
9537 + for (l = 0; l < nposs; l++) {
9538 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9539 + /* if no depends on this one, try the first package that Provides this one */
9540 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9541 + continue;
9542 + }
9543 +
9544 + /* cruise this possiblity's pkg_vec looking for an installed version */
9545 + for (k = 0; k < test_vec->len; k++) {
9546 + pkg_t *pkg_scout = test_vec->pkgs[k];
9547 + /* not installed, and not already known about? */
9548 + if ((pkg_scout->state_want != SW_INSTALL)
9549 + && !pkg_scout->parent->dependencies_checked
9550 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9551 + char ** newstuff = NULL;
9552 + int rc;
9553 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9554 + /* check for not-already-installed dependencies */
9555 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9556 + pkg_scout,
9557 + tmp_vec,
9558 + &newstuff);
9559 + if (newstuff == NULL) {
9560 + int i;
9561 + int ok = 1;
9562 + for (i = 0; i < rc; i++) {
9563 + pkg_t *p = tmp_vec->pkgs[i];
9564 + if (p->state_want == SW_INSTALL)
9565 + continue;
9566 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9567 + ok = 0;
9568 + break;
9569 + }
9570 + pkg_vec_free (tmp_vec);
9571 + if (ok) {
9572 + /* mark this one for installation */
9573 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9574 + pkg_vec_insert(unsatisfied, pkg_scout);
9575 + }
9576 + } else {
9577 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9578 + free (newstuff);
9579 + }
9580 + }
9581 + }
9582 + }
9583 + }
9584 +
9585 + continue;
9586 + }
9587 +
9588 + /* foreach possible satisfier, look for installed package */
9589 + for (j = 0; j < compound_depend->possibility_count; j++) {
9590 + /* foreach provided_by, which includes the abstract_pkg itself */
9591 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9592 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9593 + pkg_t *satisfying_pkg =
9594 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9595 + pkg_installed_and_constraint_satisfied,
9596 + dependence_to_satisfy, 1);
9597 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9598 + if (satisfying_pkg != NULL) {
9599 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9600 + satisfying_pkg = NULL;
9601 + }
9602 + }
9603 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9604 + if (satisfying_pkg != NULL) {
9605 + found = 1;
9606 + break;
9607 + }
9608 +
9609 + }
9610 + /* if nothing installed matches, then look for uninstalled satisfier */
9611 + if (!found) {
9612 + /* foreach possible satisfier, look for installed package */
9613 + for (j = 0; j < compound_depend->possibility_count; j++) {
9614 + /* foreach provided_by, which includes the abstract_pkg itself */
9615 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9616 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9617 + pkg_t *satisfying_pkg =
9618 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9619 + pkg_constraint_satisfied,
9620 + dependence_to_satisfy, 1);
9621 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9622 + if (satisfying_pkg != NULL) {
9623 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9624 + satisfying_pkg = NULL;
9625 + }
9626 + }
9627 +
9628 + /* user request overrides package recommendation */
9629 + if (satisfying_pkg != NULL
9630 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9631 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9632 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9633 + pkg->name, satisfying_pkg->name);
9634 + continue;
9635 + }
9636 +
9637 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9638 + if (satisfying_pkg != NULL) {
9639 + satisfier_entry_pkg = satisfying_pkg;
9640 + break;
9641 + }
9642 + }
9643 + }
9644 +
9645 + /* we didn't find one, add something to the unsatisfied vector */
9646 + if (!found) {
9647 + if (!satisfier_entry_pkg) {
9648 + /* failure to meet recommendations is not an error */
9649 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9650 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9651 + else
9652 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9653 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9654 + }
9655 + else {
9656 + if (compound_depend->type == SUGGEST) {
9657 + /* just mention it politely */
9658 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9659 + pkg->name, satisfier_entry_pkg->name);
9660 + } else {
9661 + char ** newstuff = NULL;
9662 +
9663 + if (satisfier_entry_pkg != pkg &&
9664 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9665 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9666 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9667 + satisfier_entry_pkg,
9668 + unsatisfied,
9669 + &newstuff);
9670 + the_lost = merge_unresolved(the_lost, newstuff);
9671 + }
9672 + }
9673 + }
9674 + }
9675 + }
9676 + *unresolved = the_lost;
9677 +
9678 + return unsatisfied->len;
9679 +}
9680 +
9681 +/*checking for conflicts !in replaces
9682 + If a packages conflicts with another but is also replacing it, I should not consider it a
9683 + really conflicts
9684 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9685 +*/
9686 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9687 +{
9688 + int i ;
9689 + int replaces_count = pkg->replaces_count;
9690 + abstract_pkg_t **replaces;
9691 +
9692 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9693 + return 0;
9694 +
9695 + replaces = pkg->replaces;
9696 +
9697 + for (i = 0; i < replaces_count; i++) {
9698 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9699 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9700 + return 1;
9701 + }
9702 + }
9703 + return 0;
9704 +
9705 +}
9706 +
9707 +
9708 +/* Abhaya: added support for conflicts */
9709 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9710 +{
9711 + pkg_vec_t * installed_conflicts, * test_vec;
9712 + compound_depend_t * conflicts;
9713 + depend_t ** possible_satisfiers;
9714 + depend_t * possible_satisfier;
9715 + register int i, j, k;
9716 + int count;
9717 + abstract_pkg_t * ab_pkg;
9718 + pkg_t **pkg_scouts;
9719 + pkg_t *pkg_scout;
9720 +
9721 + /*
9722 + * this is a setup to check for redundant/cyclic dependency checks,
9723 + * which are marked at the abstract_pkg level
9724 + */
9725 + if(!(ab_pkg = pkg->parent)){
9726 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9727 + return (pkg_vec_t *)NULL;
9728 + }
9729 +
9730 + conflicts = pkg->conflicts;
9731 + if(!conflicts){
9732 + return (pkg_vec_t *)NULL;
9733 + }
9734 + installed_conflicts = pkg_vec_alloc();
9735 +
9736 + count = pkg->conflicts_count;
9737 +
9738 +
9739 +
9740 + /* foreach conflict */
9741 + for(i = 0; i < pkg->conflicts_count; i++){
9742 +
9743 + possible_satisfiers = conflicts->possibilities;
9744 +
9745 + /* foreach possible satisfier */
9746 + for(j = 0; j < conflicts->possibility_count; j++){
9747 + possible_satisfier = possible_satisfiers[j];
9748 + if (!possible_satisfier)
9749 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9750 + if (!possible_satisfier->pkg)
9751 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9752 + test_vec = possible_satisfier->pkg->pkgs;
9753 + if (test_vec) {
9754 + /* pkg_vec found, it is an actual package conflict
9755 + * cruise this possiblity's pkg_vec looking for an installed version */
9756 + pkg_scouts = test_vec->pkgs;
9757 + for(k = 0; k < test_vec->len; k++){
9758 + pkg_scout = pkg_scouts[k];
9759 + if (!pkg_scout) {
9760 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9761 + continue;
9762 + }
9763 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9764 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9765 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9766 + pkg_vec_insert(installed_conflicts, pkg_scout);
9767 + }
9768 + }
9769 + }
9770 + }
9771 + }
9772 + conflicts++;
9773 + }
9774 +
9775 + if (installed_conflicts->len)
9776 + return installed_conflicts;
9777 + pkg_vec_free(installed_conflicts);
9778 + return (pkg_vec_t *)NULL;
9779 +}
9780 +
9781 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9782 +{
9783 + pkg_t * temp;
9784 + int comparison;
9785 +
9786 + if(depends->constraint == NONE)
9787 + return 1;
9788 +
9789 + temp = pkg_new();
9790 +
9791 + parseVersion(temp, depends->version);
9792 +
9793 + comparison = pkg_compare_versions(pkg, temp);
9794 +
9795 + free(temp);
9796 +
9797 + if((depends->constraint == EARLIER) &&
9798 + (comparison < 0))
9799 + return 1;
9800 + else if((depends->constraint == LATER) &&
9801 + (comparison > 0))
9802 + return 1;
9803 + else if(comparison == 0)
9804 + return 1;
9805 + else if((depends->constraint == LATER_EQUAL) &&
9806 + (comparison >= 0))
9807 + return 1;
9808 + else if((depends->constraint == EARLIER_EQUAL) &&
9809 + (comparison <= 0))
9810 + return 1;
9811 +
9812 + return 0;
9813 +}
9814 +
9815 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9816 +{
9817 + abstract_pkg_t *apkg = depend->pkg;
9818 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9819 + int n_providers = provider_apkgs->len;
9820 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9821 + pkg_vec_t *pkg_vec;
9822 + int n_pkgs ;
9823 + int i;
9824 + int j;
9825 +
9826 + for (i = 0; i < n_providers; i++) {
9827 + abstract_pkg_t *papkg = apkgs[i];
9828 + pkg_vec = papkg->pkgs;
9829 + if (pkg_vec) {
9830 + n_pkgs = pkg_vec->len;
9831 + for (j = 0; j < n_pkgs; j++) {
9832 + pkg_t *pkg = pkg_vec->pkgs[j];
9833 + if (version_constraints_satisfied(depend, pkg)) {
9834 + return 1;
9835 + }
9836 + }
9837 + }
9838 + }
9839 + return 0;
9840 +}
9841 +
9842 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9843 +{
9844 + abstract_pkg_t *apkg = depend->pkg;
9845 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9846 + int n_providers = provider_apkgs->len;
9847 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9848 + int i;
9849 + int n_pkgs;
9850 + int j;
9851 +
9852 + for (i = 0; i < n_providers; i++) {
9853 + abstract_pkg_t *papkg = apkgs[i];
9854 + pkg_vec_t *pkg_vec = papkg->pkgs;
9855 + if (pkg_vec) {
9856 + n_pkgs = pkg_vec->len;
9857 + for (j = 0; j < n_pkgs; j++) {
9858 + pkg_t *pkg = pkg_vec->pkgs[j];
9859 + if (version_constraints_satisfied(depend, pkg)) {
9860 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9861 + return 1;
9862 + }
9863 + }
9864 + }
9865 + }
9866 + return 0;
9867 +}
9868 +
9869 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9870 +{
9871 + register int i;
9872 + pkg_t ** pkgs = vec->pkgs;
9873 +
9874 + for(i = 0; i < vec->len; i++)
9875 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9876 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9877 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9878 + return 1;
9879 + return 0;
9880 +}
9881 +
9882 +
9883 +#ifdef DeadCode
9884 +/**
9885 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9886 + * the same abstract package and 0 otherwise.
9887 + */
9888 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9889 +{
9890 + abstract_pkg_t **provides = pkg->provides;
9891 + int provides_count = pkg->provides_count;
9892 + abstract_pkg_t **replacee_provides = replacee->provides;
9893 + int replacee_provides_count = replacee->provides_count;
9894 + int i, j;
9895 + for (i = 0; i < provides_count; i++) {
9896 + abstract_pkg_t *apkg = provides[i];
9897 + for (j = 0; j < replacee_provides_count; j++) {
9898 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9899 + if (apkg == replacee_apkg)
9900 + return 1;
9901 + }
9902 + }
9903 + return 0;
9904 +}
9905 +#endif
9906 +
9907 +/**
9908 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9909 + * and 0 otherwise.
9910 + */
9911 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9912 +{
9913 + abstract_pkg_t **provides = pkg->provides;
9914 + int provides_count = pkg->provides_count;
9915 + int i;
9916 + for (i = 0; i < provides_count; i++) {
9917 + if (provides[i] == providee)
9918 + return 1;
9919 + }
9920 + return 0;
9921 +}
9922 +
9923 +/**
9924 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9925 + * otherwise.
9926 + */
9927 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9928 +{
9929 + abstract_pkg_t **replaces = pkg->replaces;
9930 + int replaces_count = pkg->replaces_count;
9931 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9932 + int replacee_provides_count = pkg->provides_count; */
9933 + int i, j;
9934 + for (i = 0; i < replaces_count; i++) {
9935 + abstract_pkg_t *abstract_replacee = replaces[i];
9936 + for (j = 0; j < replaces_count; j++) {
9937 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9938 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9939 + if (replacee->provides[j] == abstract_replacee)
9940 + return 1;
9941 + }
9942 + }
9943 + return 0;
9944 +}
9945 +
9946 +
9947 +/**
9948 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9949 + * otherwise.
9950 + */
9951 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9952 +{
9953 + compound_depend_t *conflicts = pkg->conflicts;
9954 + int conflicts_count = pkg->conflicts_count;
9955 + int i, j;
9956 + for (i = 0; i < conflicts_count; i++) {
9957 + int possibility_count = conflicts[i].possibility_count;
9958 + struct depend **possibilities = conflicts[i].possibilities;
9959 + for (j = 0; j < possibility_count; j++) {
9960 + if (possibilities[j]->pkg == conflictee) {
9961 + return 1;
9962 + }
9963 + }
9964 + }
9965 + return 0;
9966 +}
9967 +
9968 +/**
9969 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9970 + * conflictee's provides and 0 otherwise.
9971 + */
9972 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9973 +{
9974 + compound_depend_t *conflicts = pkg->conflicts;
9975 + int conflicts_count = pkg->conflicts_count;
9976 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9977 + int conflictee_provides_count = conflictee->provides_count;
9978 + int i, j, k;
9979 + int possibility_count;
9980 + struct depend **possibilities;
9981 + abstract_pkg_t *possibility ;
9982 +
9983 + for (i = 0; i < conflicts_count; i++) {
9984 + possibility_count = conflicts[i].possibility_count;
9985 + possibilities = conflicts[i].possibilities;
9986 + for (j = 0; j < possibility_count; j++) {
9987 + possibility = possibilities[j]->pkg;
9988 + for (k = 0; k < conflictee_provides_count; k++) {
9989 + if (possibility == conflictee_provides[k]) {
9990 + return 1;
9991 + }
9992 + }
9993 + }
9994 + }
9995 + return 0;
9996 +}
9997 +
9998 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9999 +{
10000 + int oldlen = 0, newlen = 0;
10001 + char ** result;
10002 + register int i, j;
10003 +
10004 + if(!newstuff)
10005 + return oldstuff;
10006 +
10007 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10008 + while(newstuff && newstuff[newlen]) newlen++;
10009 +
10010 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10011 + if (result == NULL) {
10012 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10013 + return NULL;
10014 + }
10015 +
10016 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10017 + *(result + i) = *(newstuff + j);
10018 +
10019 + *(result + i) = NULL;
10020 +
10021 + return result;
10022 +}
10023 +
10024 +/*
10025 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10026 + * this is null terminated, no count is carried around
10027 + */
10028 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10029 +{
10030 + int count;
10031 + char ** resized;
10032 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10033 +
10034 + count = 0;
10035 + while(the_lost && the_lost[count]) count++;
10036 +
10037 + count++; /* need one to hold the null */
10038 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10039 + if (resized == NULL) {
10040 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10041 + return NULL;
10042 + }
10043 + resized[count - 1] = strdup(depend_str);
10044 + resized[count] = NULL;
10045 +
10046 + return resized;
10047 +}
10048 +
10049 +void printDepends(pkg_t * pkg)
10050 +{
10051 + register int i, j;
10052 + compound_depend_t * depend;
10053 + int count;
10054 +
10055 + count = pkg->pre_depends_count + pkg->depends_count;
10056 +
10057 + depend = pkg->depends;
10058 + if(!depend){
10059 + fprintf(stderr, "Depends pointer is NULL\n");
10060 + return;
10061 + }
10062 + for(i = 0; i < count; i++){
10063 + fprintf(stderr, "%s has %d possibilities:\n",
10064 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10065 + depend->possibility_count);
10066 + for(j = 0; j < depend->possibility_count; j++)
10067 + fprintf(stderr, "\t%s version %s (%d)\n",
10068 + depend->possibilities[j]->pkg->name,
10069 + depend->possibilities[j]->version,
10070 + depend->possibilities[j]->constraint);
10071 + depend++;
10072 + }
10073 +}
10074 +
10075 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10076 +{
10077 + register int i, j;
10078 +
10079 + /* every pkg provides itself */
10080 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10081 +
10082 + if (!pkg->provides_count)
10083 + return 0;
10084 +
10085 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10086 + if (pkg->provides == NULL) {
10087 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10088 + return -1 ;
10089 + }
10090 + pkg->provides[0] = ab_pkg;
10091 +
10092 + // if (strcmp(ab_pkg->name, pkg->name))
10093 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10094 +
10095 + for(i = 0; i < pkg->provides_count; i++){
10096 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10097 +
10098 + pkg->provides[i+1] = provided_abpkg;
10099 +
10100 + j = 0;
10101 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10102 + }
10103 + return 0;
10104 +}
10105 +
10106 +/* Abhaya: added conflicts support */
10107 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10108 +{
10109 + register int i;
10110 + compound_depend_t * conflicts;
10111 +
10112 + if (!pkg->conflicts_count)
10113 + return 0;
10114 +
10115 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10116 + pkg->conflicts_count);
10117 + if (conflicts == NULL) {
10118 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10119 + return -1;
10120 + }
10121 + for (i = 0; i < pkg->conflicts_count; i++) {
10122 + conflicts->type = CONFLICTS;
10123 + parseDepends(conflicts, hash,
10124 + pkg->conflicts_str[i]);
10125 +#if 0
10126 + for (j = 0; j < conflicts->possibility_count; j++) {
10127 + depend_t *possibility = conflicts->possibilities[j];
10128 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10129 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10130 + }
10131 +#endif
10132 + conflicts++;
10133 + }
10134 + return 0;
10135 +}
10136 +
10137 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10138 +{
10139 + register int i, j;
10140 +
10141 + if (!pkg->replaces_count)
10142 + return 0;
10143 +
10144 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10145 + if (pkg->replaces == NULL) {
10146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10147 + return -1;
10148 + }
10149 +
10150 + // if (strcmp(ab_pkg->name, pkg->name))
10151 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10152 +
10153 + for(i = 0; i < pkg->replaces_count; i++){
10154 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10155 +
10156 + pkg->replaces[i] = old_abpkg;
10157 +
10158 + j = 0;
10159 + if (!old_abpkg->replaced_by)
10160 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10161 + if ( old_abpkg->replaced_by == NULL ){
10162 + return -1;
10163 + }
10164 + /* if a package pkg both replaces and conflicts old_abpkg,
10165 + * then add it to the replaced_by vector so that old_abpkg
10166 + * will be upgraded to ab_pkg automatically */
10167 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10168 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10169 + }
10170 + return 0;
10171 +}
10172 +
10173 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10174 +{
10175 + int count;
10176 + register int i;
10177 + compound_depend_t * depends;
10178 +
10179 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10180 + return 0;
10181 +
10182 + if (0 && pkg->pre_depends_count)
10183 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10184 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10185 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10186 + if (depends == NULL) {
10187 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10188 + return -1;
10189 + }
10190 +
10191 +
10192 + for(i = 0; i < pkg->pre_depends_count; i++){
10193 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10194 + if (0 && pkg->pre_depends_count)
10195 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10196 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10197 + depends->type = PREDEPEND;
10198 + depends++;
10199 + }
10200 +
10201 + for(i = 0; i < pkg->recommends_count; i++){
10202 + parseDepends(depends, hash, pkg->recommends_str[i]);
10203 + if (0 && pkg->recommends_count)
10204 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10205 + pkg->recommends_str[i], depends, depends->possibility_count);
10206 + depends->type = RECOMMEND;
10207 + depends++;
10208 + }
10209 +
10210 + for(i = 0; i < pkg->suggests_count; i++){
10211 + parseDepends(depends, hash, pkg->suggests_str[i]);
10212 + if (0 && pkg->suggests_count)
10213 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10214 + pkg->suggests_str[i], depends, depends->possibility_count);
10215 + depends->type = SUGGEST;
10216 + depends++;
10217 + }
10218 +
10219 + for(i = 0; i < pkg->depends_count; i++){
10220 + parseDepends(depends, hash, pkg->depends_str[i]);
10221 + if (0 && pkg->depends_count)
10222 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10223 + pkg->depends_str[i], depends, depends->possibility_count);
10224 + depends++;
10225 + }
10226 + return 0;
10227 +}
10228 +
10229 +/*
10230 + * pkg_depend_string: returns the depends string specified by index.
10231 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10232 + * [0,npredepends) -> returns pre_depends_str[index]
10233 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10234 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10235 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10236 + */
10237 +char *pkg_depend_str(pkg_t *pkg, int index)
10238 +{
10239 + if (index < pkg->pre_depends_count) {
10240 + return pkg->pre_depends_str[index];
10241 + }
10242 + index -= pkg->pre_depends_count;
10243 +
10244 + if (index < pkg->recommends_count) {
10245 + return pkg->recommends_str[index];
10246 + }
10247 + index -= pkg->recommends_count;
10248 +
10249 + if (index < pkg->suggests_count) {
10250 + return pkg->suggests_str[index];
10251 + }
10252 + index -= pkg->suggests_count;
10253 +
10254 + if (index < pkg->depends_count) {
10255 + return pkg->depends_str[index];
10256 + }
10257 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10258 + return NULL;
10259 +}
10260 +
10261 +void freeDepends(pkg_t *pkg)
10262 +{
10263 + int i;
10264 +
10265 + if (pkg == NULL || pkg->depends == NULL) {
10266 + return;
10267 + }
10268 +
10269 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10270 + for (i=0; i < pkg->depends->possibility_count; i++) {
10271 + depend_deinit(pkg->depends->possibilities[i]);
10272 + }
10273 + free(pkg->depends->possibilities);
10274 + free(pkg->depends);
10275 + pkg->depends = NULL;
10276 +}
10277 +
10278 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10279 +{
10280 + compound_depend_t * depends;
10281 + int count, othercount;
10282 + register int i, j;
10283 + abstract_pkg_t * ab_depend;
10284 + abstract_pkg_t ** temp;
10285 +
10286 + count = pkg->pre_depends_count + pkg->depends_count;
10287 + depends = pkg->depends;
10288 +
10289 + if (0 && pkg->pre_depends_count)
10290 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10291 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10292 + for (i = 0; i < count; i++) {
10293 + if (0 && pkg->pre_depends_count)
10294 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10295 + for (j = 0; j < depends->possibility_count; j++){
10296 + ab_depend = depends->possibilities[j]->pkg;
10297 + if(!ab_depend->depended_upon_by)
10298 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10299 +
10300 + temp = ab_depend->depended_upon_by;
10301 + othercount = 1;
10302 + while(*temp){
10303 + temp++;
10304 + othercount++;
10305 + }
10306 + *temp = ab_pkg;
10307 +
10308 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10309 + (othercount + 1) * sizeof(abstract_pkg_t *));
10310 + /* the array may have moved */
10311 + temp = ab_depend->depended_upon_by + othercount;
10312 + *temp = NULL;
10313 + }
10314 + depends++;
10315 + }
10316 +}
10317 +
10318 +static depend_t * depend_init(void)
10319 +{
10320 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10321 + if ( d==NULL ){
10322 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10323 + return NULL;
10324 + }
10325 + d->constraint = NONE;
10326 + d->version = NULL;
10327 + d->pkg = NULL;
10328 +
10329 + return d;
10330 +}
10331 +
10332 +static void depend_deinit(depend_t *d)
10333 +{
10334 + free(d);
10335 +}
10336 +
10337 +static int parseDepends(compound_depend_t *compound_depend,
10338 + hash_table_t * hash, char * depend_str)
10339 +{
10340 + char * pkg_name, buffer[2048];
10341 + int num_of_ors = 0;
10342 + register int i;
10343 + register char * src, * dest;
10344 + depend_t ** possibilities;
10345 +
10346 + /* first count the number of ored possibilities for satisfying dependency */
10347 + src = depend_str;
10348 + while(*src)
10349 + if(*src++ == '|')
10350 + num_of_ors++;
10351 +
10352 + compound_depend->type = DEPEND;
10353 +
10354 + compound_depend->possibility_count = num_of_ors + 1;
10355 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10356 + if (!possibilities)
10357 + return -ENOMEM;
10358 + compound_depend->possibilities = possibilities;
10359 +
10360 + src = depend_str;
10361 + for(i = 0; i < num_of_ors + 1; i++){
10362 + possibilities[i] = depend_init();
10363 + if (!possibilities[i])
10364 + return -ENOMEM;
10365 + /* gobble up just the name first */
10366 + dest = buffer;
10367 + while(*src &&
10368 + !isspace(*src) &&
10369 + (*src != '(') &&
10370 + (*src != '*') &&
10371 + (*src != '|'))
10372 + *dest++ = *src++;
10373 + *dest = '\0';
10374 + pkg_name = trim_alloc(buffer);
10375 + if (pkg_name == NULL )
10376 + return -ENOMEM;
10377 +
10378 + /* now look at possible version info */
10379 +
10380 + /* skip to next chars */
10381 + if(isspace(*src))
10382 + while(*src && isspace(*src)) src++;
10383 +
10384 + /* extract constraint and version */
10385 + if(*src == '('){
10386 + src++;
10387 + if(!strncmp(src, "<<", 2)){
10388 + possibilities[i]->constraint = EARLIER;
10389 + src += 2;
10390 + }
10391 + else if(!strncmp(src, "<=", 2)){
10392 + possibilities[i]->constraint = EARLIER_EQUAL;
10393 + src += 2;
10394 + }
10395 + else if(!strncmp(src, ">=", 2)){
10396 + possibilities[i]->constraint = LATER_EQUAL;
10397 + src += 2;
10398 + }
10399 + else if(!strncmp(src, ">>", 2)){
10400 + possibilities[i]->constraint = LATER;
10401 + src += 2;
10402 + }
10403 + else if(!strncmp(src, "=", 1)){
10404 + possibilities[i]->constraint = EQUAL;
10405 + src++;
10406 + }
10407 + /* should these be here to support deprecated designations; dpkg does */
10408 + else if(!strncmp(src, "<", 1)){
10409 + possibilities[i]->constraint = EARLIER_EQUAL;
10410 + src++;
10411 + }
10412 + else if(!strncmp(src, ">", 1)){
10413 + possibilities[i]->constraint = LATER_EQUAL;
10414 + src++;
10415 + }
10416 +
10417 + /* now we have any constraint, pass space to version string */
10418 + while(isspace(*src)) src++;
10419 +
10420 + /* this would be the version string */
10421 + dest = buffer;
10422 + while(*src && *src != ')')
10423 + *dest++ = *src++;
10424 + *dest = '\0';
10425 +
10426 + possibilities[i]->version = trim_alloc(buffer);
10427 + /* fprintf(stderr, "let's print the depends version string:");
10428 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10429 + if (possibilities[i]->version == NULL )
10430 + return -ENOMEM;
10431 +
10432 +
10433 + }
10434 + /* hook up the dependency to its abstract pkg */
10435 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10436 +
10437 + free(pkg_name);
10438 +
10439 + /* now get past the ) and any possible | chars */
10440 + while(*src &&
10441 + (isspace(*src) ||
10442 + (*src == ')') ||
10443 + (*src == '|')))
10444 + src++;
10445 + if (*src == '*')
10446 + {
10447 + compound_depend->type = GREEDY_DEPEND;
10448 + src++;
10449 + }
10450 + }
10451 +
10452 + return 0;
10453 +}
10454 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_depends.h busybox-1.3.1-911/archival/libipkg/pkg_depends.h
10455 --- busybox-1.3.1-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10456 +++ busybox-1.3.1-911/archival/libipkg/pkg_depends.h 2006-12-27 19:41:04.000000000 +0100
10457 @@ -0,0 +1,105 @@
10458 +/* pkg_depends.h - the itsy package management system
10459 +
10460 + Steven M. Ayer
10461 +
10462 + Copyright (C) 2002 Compaq Computer Corporation
10463 +
10464 + This program is free software; you can redistribute it and/or
10465 + modify it under the terms of the GNU General Public License as
10466 + published by the Free Software Foundation; either version 2, or (at
10467 + your option) any later version.
10468 +
10469 + This program is distributed in the hope that it will be useful, but
10470 + WITHOUT ANY WARRANTY; without even the implied warranty of
10471 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10472 + General Public License for more details.
10473 +*/
10474 +
10475 +#ifndef PKG_DEPENDS_H
10476 +#define PKG_DEPENDS_H
10477 +
10478 +#include "pkg.h"
10479 +#include "pkg_hash.h"
10480 +
10481 +enum depend_type {
10482 + PREDEPEND,
10483 + DEPEND,
10484 + CONFLICTS,
10485 + GREEDY_DEPEND,
10486 + RECOMMEND,
10487 + SUGGEST
10488 +};
10489 +typedef enum depend_type depend_type_t;
10490 +
10491 +enum version_constraint {
10492 + NONE,
10493 + EARLIER,
10494 + EARLIER_EQUAL,
10495 + EQUAL,
10496 + LATER_EQUAL,
10497 + LATER
10498 +};
10499 +typedef enum version_constraint version_constraint_t;
10500 +
10501 +struct depend{
10502 + version_constraint_t constraint;
10503 + char * version;
10504 + abstract_pkg_t * pkg;
10505 +};
10506 +typedef struct depend depend_t;
10507 +
10508 +struct compound_depend{
10509 + depend_type_t type;
10510 + int possibility_count;
10511 + struct depend ** possibilities;
10512 +};
10513 +typedef struct compound_depend compound_depend_t;
10514 +
10515 +#include "hash_table.h"
10516 +
10517 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10518 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10519 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10520 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10521 +
10522 +/**
10523 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10524 + * the same abstract package and 0 otherwise.
10525 + */
10526 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10527 +
10528 +/**
10529 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10530 + * otherwise.
10531 + */
10532 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10533 +
10534 +/**
10535 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10536 + * otherwise.
10537 + */
10538 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10539 +
10540 +/**
10541 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10542 + * otherwise.
10543 + */
10544 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10545 +
10546 +/**
10547 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10548 + * otherwise.
10549 + */
10550 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10551 +
10552 +char *pkg_depend_str(pkg_t *pkg, int index);
10553 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10554 +void freeDepends(pkg_t *pkg);
10555 +void printDepends(pkg_t * pkg);
10556 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10557 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10558 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10559 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10560 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10561 +
10562 +#endif
10563 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_dest.c busybox-1.3.1-911/archival/libipkg/pkg_dest.c
10564 --- busybox-1.3.1-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10565 +++ busybox-1.3.1-911/archival/libipkg/pkg_dest.c 2006-12-27 19:41:04.000000000 +0100
10566 @@ -0,0 +1,92 @@
10567 +/* pkg_dest.c - the itsy package management system
10568 +
10569 + Carl D. Worth
10570 +
10571 + Copyright (C) 2001 University of Southern California
10572 +
10573 + This program is free software; you can redistribute it and/or
10574 + modify it under the terms of the GNU General Public License as
10575 + published by the Free Software Foundation; either version 2, or (at
10576 + your option) any later version.
10577 +
10578 + This program is distributed in the hope that it will be useful, but
10579 + WITHOUT ANY WARRANTY; without even the implied warranty of
10580 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10581 + General Public License for more details.
10582 +*/
10583 +
10584 +#include "ipkg.h"
10585 +
10586 +#include "pkg_dest.h"
10587 +#include "file_util.h"
10588 +#include "str_util.h"
10589 +#include "sprintf_alloc.h"
10590 +
10591 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10592 +{
10593 + dest->name = strdup(name);
10594 +
10595 + /* Guarantee that dest->root_dir ends with a '/' */
10596 + if (str_ends_with(root_dir, "/")) {
10597 + dest->root_dir = strdup(root_dir);
10598 + } else {
10599 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10600 + }
10601 + file_mkdir_hier(dest->root_dir, 0755);
10602 +
10603 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10604 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10605 + file_mkdir_hier(dest->ipkg_dir, 0755);
10606 +
10607 + if (str_starts_with (lists_dir, "/"))
10608 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10609 + else
10610 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10611 +
10612 + file_mkdir_hier(dest->lists_dir, 0755);
10613 +
10614 + sprintf_alloc(&dest->info_dir, "%s/%s",
10615 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10616 + file_mkdir_hier(dest->info_dir, 0755);
10617 +
10618 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10619 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10620 +
10621 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10622 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10623 +
10624 + dest->status_file = NULL;
10625 +
10626 + return 0;
10627 +}
10628 +
10629 +void pkg_dest_deinit(pkg_dest_t *dest)
10630 +{
10631 + free(dest->name);
10632 + dest->name = NULL;
10633 +
10634 + free(dest->root_dir);
10635 + dest->root_dir = NULL;
10636 +
10637 + free(dest->ipkg_dir);
10638 + dest->ipkg_dir = NULL;
10639 +
10640 + free(dest->lists_dir);
10641 + dest->lists_dir = NULL;
10642 +
10643 + free(dest->info_dir);
10644 + dest->info_dir = NULL;
10645 +
10646 + free(dest->status_file_name);
10647 + dest->status_file_name = NULL;
10648 +
10649 + free(dest->status_file_tmp_name);
10650 + dest->status_file_tmp_name = NULL;
10651 +
10652 + if (dest->status_file) {
10653 + fclose(dest->status_file);
10654 + }
10655 + dest->status_file = NULL;
10656 +
10657 + dest->root_dir = NULL;
10658 +}
10659 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_dest.h busybox-1.3.1-911/archival/libipkg/pkg_dest.h
10660 --- busybox-1.3.1-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10661 +++ busybox-1.3.1-911/archival/libipkg/pkg_dest.h 2006-12-27 19:41:04.000000000 +0100
10662 @@ -0,0 +1,38 @@
10663 +/* pkg_dest.h - the itsy package management system
10664 +
10665 + Carl D. Worth
10666 +
10667 + Copyright (C) 2001 University of Southern California
10668 +
10669 + This program is free software; you can redistribute it and/or
10670 + modify it under the terms of the GNU General Public License as
10671 + published by the Free Software Foundation; either version 2, or (at
10672 + your option) any later version.
10673 +
10674 + This program is distributed in the hope that it will be useful, but
10675 + WITHOUT ANY WARRANTY; without even the implied warranty of
10676 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10677 + General Public License for more details.
10678 +*/
10679 +
10680 +#ifndef PKG_DEST_H
10681 +#define PKG_DEST_H
10682 +
10683 +typedef struct pkg_dest pkg_dest_t;
10684 +struct pkg_dest
10685 +{
10686 + char *name;
10687 + char *root_dir;
10688 + char *ipkg_dir;
10689 + char *lists_dir;
10690 + char *info_dir;
10691 + char *status_file_name;
10692 + char *status_file_tmp_name;
10693 + FILE *status_file;
10694 +};
10695 +
10696 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10697 +void pkg_dest_deinit(pkg_dest_t *dest);
10698 +
10699 +#endif
10700 +
10701 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_dest_list.c busybox-1.3.1-911/archival/libipkg/pkg_dest_list.c
10702 --- busybox-1.3.1-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10703 +++ busybox-1.3.1-911/archival/libipkg/pkg_dest_list.c 2006-12-27 19:41:04.000000000 +0100
10704 @@ -0,0 +1,85 @@
10705 +/* pkg_dest_list.c - the itsy package management system
10706 +
10707 + Carl D. Worth
10708 +
10709 + Copyright (C) 2001 University of Southern California
10710 +
10711 + This program is free software; you can redistribute it and/or
10712 + modify it under the terms of the GNU General Public License as
10713 + published by the Free Software Foundation; either version 2, or (at
10714 + your option) any later version.
10715 +
10716 + This program is distributed in the hope that it will be useful, but
10717 + WITHOUT ANY WARRANTY; without even the implied warranty of
10718 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10719 + General Public License for more details.
10720 +*/
10721 +
10722 +#include "ipkg.h"
10723 +
10724 +#include "pkg_dest.h"
10725 +#include "void_list.h"
10726 +#include "pkg_dest_list.h"
10727 +
10728 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10729 +{
10730 + return void_list_elt_init((void_list_elt_t *) elt, data);
10731 +}
10732 +
10733 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10734 +{
10735 + void_list_elt_deinit((void_list_elt_t *) elt);
10736 +}
10737 +
10738 +int pkg_dest_list_init(pkg_dest_list_t *list)
10739 +{
10740 + return void_list_init((void_list_t *) list);
10741 +}
10742 +
10743 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10744 +{
10745 + pkg_dest_list_elt_t *iter;
10746 + pkg_dest_t *pkg_dest;
10747 +
10748 + for (iter = list->head; iter; iter = iter->next) {
10749 + pkg_dest = iter->data;
10750 + pkg_dest_deinit(pkg_dest);
10751 +
10752 + /* malloced in pkg_dest_list_append */
10753 + free(pkg_dest);
10754 + iter->data = NULL;
10755 + }
10756 + void_list_deinit((void_list_t *) list);
10757 +}
10758 +
10759 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10760 + const char *root_dir,const char *lists_dir)
10761 +{
10762 + int err;
10763 + pkg_dest_t *pkg_dest;
10764 +
10765 + /* freed in plg_dest_list_deinit */
10766 + pkg_dest = malloc(sizeof(pkg_dest_t));
10767 + if (pkg_dest == NULL) {
10768 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10769 + return NULL;
10770 + }
10771 +
10772 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10773 + err = void_list_append((void_list_t *) list, pkg_dest);
10774 + if (err) {
10775 + return NULL;
10776 + }
10777 +
10778 + return pkg_dest;
10779 +}
10780 +
10781 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10782 +{
10783 + return void_list_push((void_list_t *) list, data);
10784 +}
10785 +
10786 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10787 +{
10788 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10789 +}
10790 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_dest_list.h busybox-1.3.1-911/archival/libipkg/pkg_dest_list.h
10791 --- busybox-1.3.1-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10792 +++ busybox-1.3.1-911/archival/libipkg/pkg_dest_list.h 2006-12-27 19:41:04.000000000 +0100
10793 @@ -0,0 +1,50 @@
10794 +/* pkg_dest_list.h - the itsy package management system
10795 +
10796 + Carl D. Worth
10797 +
10798 + Copyright (C) 2001 University of Southern California
10799 +
10800 + This program is free software; you can redistribute it and/or
10801 + modify it under the terms of the GNU General Public License as
10802 + published by the Free Software Foundation; either version 2, or (at
10803 + your option) any later version.
10804 +
10805 + This program is distributed in the hope that it will be useful, but
10806 + WITHOUT ANY WARRANTY; without even the implied warranty of
10807 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10808 + General Public License for more details.
10809 +*/
10810 +
10811 +#ifndef PKG_DEST_LIST_H
10812 +#define PKG_DEST_LIST_H
10813 +
10814 +#include "pkg_dest.h"
10815 +
10816 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10817 +struct pkg_dest_list_elt
10818 +{
10819 + pkg_dest_list_elt_t *next;
10820 + pkg_dest_t *data;
10821 +};
10822 +
10823 +typedef struct pkg_dest_list pkg_dest_list_t;
10824 +struct pkg_dest_list
10825 +{
10826 + pkg_dest_list_elt_t pre_head;
10827 + pkg_dest_list_elt_t *head;
10828 + pkg_dest_list_elt_t *tail;
10829 +};
10830 +
10831 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10832 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10833 +
10834 +int pkg_dest_list_init(pkg_dest_list_t *list);
10835 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10836 +
10837 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10838 + const char *root_dir,const char* lists_dir);
10839 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10840 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10841 +
10842 +#endif
10843 +
10844 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_extract.c busybox-1.3.1-911/archival/libipkg/pkg_extract.c
10845 --- busybox-1.3.1-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10846 +++ busybox-1.3.1-911/archival/libipkg/pkg_extract.c 2006-12-28 02:28:27.000000000 +0100
10847 @@ -0,0 +1,224 @@
10848 +/* pkg_extract.c - the itsy package management system
10849 +
10850 + Carl D. Worth
10851 +
10852 + Copyright (C) 2001 University of Southern California
10853 +
10854 + This program is free software; you can redistribute it and/or
10855 + modify it under the terms of the GNU General Public License as
10856 + published by the Free Software Foundation; either version 2, or (at
10857 + your option) any later version.
10858 +
10859 + This program is distributed in the hope that it will be useful, but
10860 + WITHOUT ANY WARRANTY; without even the implied warranty of
10861 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10862 + General Public License for more details.
10863 +*/
10864 +
10865 +#include "ipkg.h"
10866 +#include <errno.h>
10867 +#include <fcntl.h>
10868 +#include <stdio.h>
10869 +
10870 +#include "pkg_extract.h"
10871 +
10872 +#include "libbb.h"
10873 +#include "file_util.h"
10874 +#include "sprintf_alloc.h"
10875 +#include "unarchive.h"
10876 +
10877 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10878 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10879 +#define IPKG_CONTROL_FILE "control"
10880 +
10881 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10882 +{
10883 + archive_handle_t *archive;
10884 + char *path;
10885 +
10886 + sprintf_alloc(&path, "%s/", dir);
10887 + archive = init_handle();
10888 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10889 + archive->filter = filter_accept_list;
10890 + llist_add_to(&(archive->accept), (char *)filename);
10891 + archive->buffer = path;
10892 + archive->action_data = data_extract_all_prefix;
10893 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10894 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10895 + close(archive->src_fd);
10896 + free(archive->accept);
10897 + free(archive);
10898 + free(path);
10899 +}
10900 +
10901 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10902 +{
10903 + unsigned int size = strlen(archive->file_header->name) + 2;
10904 +
10905 + if (archive->buffer == NULL) {
10906 + archive->buffer = xmalloc(size);
10907 + strcpy(archive->buffer, archive->file_header->name);
10908 + } else {
10909 + size += strlen(archive->buffer);
10910 + archive->buffer = xrealloc(archive->buffer, size);
10911 + strcat(archive->buffer, archive->file_header->name);
10912 + }
10913 + strcat(archive->buffer, "\n");
10914 + data_skip(archive);
10915 +}
10916 +
10917 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10918 +{
10919 + archive_handle_t *archive;
10920 + char *name;
10921 +
10922 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10923 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10924 + archive = init_handle();
10925 + archive->src_fd = xopen(name, O_RDONLY);
10926 + archive->filter = filter_accept_list;
10927 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10928 + archive->action_data = data_extract_to_buffer;
10929 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10930 + close(archive->src_fd);
10931 + fputs(archive->buffer, stream);
10932 + free(archive->buffer);
10933 + free(archive->accept);
10934 + free(archive);
10935 + free(name);
10936 +
10937 + return 0;
10938 +}
10939 +
10940 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10941 +{
10942 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10943 +}
10944 +
10945 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10946 +{
10947 + archive_handle_t *archive;
10948 + char *name;
10949 + char *path;
10950 +
10951 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10952 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10953 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10954 + archive = init_handle();
10955 + archive->src_fd = xopen(name, O_RDONLY);
10956 + archive->filter = filter_accept_all;
10957 + archive->buffer = path;
10958 + archive->action_data = data_extract_all_prefix;
10959 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10960 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10961 + close(archive->src_fd);
10962 + free(archive);
10963 + free(path);
10964 + free(name);
10965 +
10966 + return 0;
10967 +}
10968 +
10969 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10970 +{
10971 + archive_handle_t *archive;
10972 + char *name;
10973 + char *path;
10974 +
10975 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10976 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10977 + sprintf_alloc(&path, "%s/", dir);
10978 + archive = init_handle();
10979 + archive->src_fd = xopen(name, O_RDONLY);
10980 + archive->filter = filter_accept_all;
10981 + archive->buffer = path;
10982 + archive->action_data = data_extract_all_prefix;
10983 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10984 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10985 + close(archive->src_fd);
10986 + free(archive);
10987 + free(path);
10988 + free(name);
10989 +
10990 + return 0;
10991 +}
10992 +
10993 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10994 +{
10995 + int err=0;
10996 + char *line, *data_file;
10997 + FILE *file;
10998 + FILE *tmp;
10999 +
11000 + file = fopen(file_name, "w");
11001 + if (file == NULL) {
11002 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11003 + __FUNCTION__, file_name);
11004 + return EINVAL;
11005 + }
11006 +
11007 + tmp = tmpfile();
11008 + if (pkg->installed_files) {
11009 + str_list_elt_t *elt;
11010 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11011 + fprintf(file, "%s\n", elt->data);
11012 + }
11013 + } else {
11014 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11015 + if (err) {
11016 + fclose(file);
11017 + fclose(tmp);
11018 + return err;
11019 + }
11020 +
11021 + /* Fixup data file names by removing the initial '.' */
11022 + rewind(tmp);
11023 + while (1) {
11024 + line = file_read_line_alloc(tmp);
11025 + if (line == NULL) {
11026 + break;
11027 + }
11028 +
11029 + data_file = line;
11030 + if (*data_file == '.') {
11031 + data_file++;
11032 + }
11033 +
11034 + if (*data_file != '/') {
11035 + fputs("/", file);
11036 + }
11037 +
11038 + /* I have no idea why, but this is what dpkg does */
11039 + if (strcmp(data_file, "/\n") == 0) {
11040 + fputs("/.\n", file);
11041 + } else {
11042 + fputs(data_file, file);
11043 + }
11044 + }
11045 + }
11046 + fclose(tmp);
11047 + fclose(file);
11048 +
11049 + return err;
11050 +}
11051 +
11052 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11053 +{
11054 + archive_handle_t *archive;
11055 + char *name;
11056 +
11057 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11058 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11059 + archive = init_handle();
11060 + archive->src_fd = xopen(name, O_RDONLY);
11061 + archive->filter = filter_accept_all;
11062 + archive->action_data = data_extract_file_name_to_buffer;
11063 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11064 + close(archive->src_fd);
11065 + fputs(archive->buffer, file);
11066 + free(archive->buffer);
11067 + free(archive);
11068 + free(name);
11069 +
11070 + return 0;
11071 +}
11072 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_extract.h busybox-1.3.1-911/archival/libipkg/pkg_extract.h
11073 --- busybox-1.3.1-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11074 +++ busybox-1.3.1-911/archival/libipkg/pkg_extract.h 2006-12-27 19:41:04.000000000 +0100
11075 @@ -0,0 +1,32 @@
11076 +/* pkg_extract.c - the itsy package management system
11077 +
11078 + Carl D. Worth
11079 +
11080 + Copyright (C) 2001 University of Southern California
11081 +
11082 + This program is free software; you can redistribute it and/or
11083 + modify it under the terms of the GNU General Public License as
11084 + published by the Free Software Foundation; either version 2, or (at
11085 + your option) any later version.
11086 +
11087 + This program is distributed in the hope that it will be useful, but
11088 + WITHOUT ANY WARRANTY; without even the implied warranty of
11089 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11090 + General Public License for more details.
11091 +*/
11092 +
11093 +#ifndef PKG_EXTRACT_H
11094 +#define PKG_EXTRACT_H
11095 +
11096 +#include "pkg.h"
11097 +
11098 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11099 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11100 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11101 + const char *dir,
11102 + const char *prefix);
11103 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11104 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11105 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11106 +
11107 +#endif
11108 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg.h busybox-1.3.1-911/archival/libipkg/pkg.h
11109 --- busybox-1.3.1-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
11110 +++ busybox-1.3.1-911/archival/libipkg/pkg.h 2006-12-27 19:41:04.000000000 +0100
11111 @@ -0,0 +1,232 @@
11112 +/* pkg.h - the itsy package management system
11113 +
11114 + Carl D. Worth
11115 +
11116 + Copyright (C) 2001 University of Southern California
11117 +
11118 + This program is free software; you can redistribute it and/or
11119 + modify it under the terms of the GNU General Public License as
11120 + published by the Free Software Foundation; either version 2, or (at
11121 + your option) any later version.
11122 +
11123 + This program is distributed in the hope that it will be useful, but
11124 + WITHOUT ANY WARRANTY; without even the implied warranty of
11125 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11126 + General Public License for more details.
11127 +*/
11128 +
11129 +#ifndef PKG_H
11130 +#define PKG_H
11131 +
11132 +#include <sys/types.h>
11133 +#include <sys/stat.h>
11134 +#include <unistd.h>
11135 +
11136 +#include "pkg_vec.h"
11137 +#include "str_list.h"
11138 +#include "pkg_src.h"
11139 +#include "pkg_dest.h"
11140 +#include "ipkg_conf.h"
11141 +#include "conffile_list.h"
11142 +
11143 +struct ipkg_conf;
11144 +
11145 +
11146 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11147 +
11148 +/* I think "Size" is currently the shortest field name */
11149 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11150 +
11151 +enum pkg_state_want
11152 +{
11153 + SW_UNKNOWN = 1,
11154 + SW_INSTALL,
11155 + SW_DEINSTALL,
11156 + SW_PURGE,
11157 + SW_LAST_STATE_WANT
11158 +};
11159 +typedef enum pkg_state_want pkg_state_want_t;
11160 +
11161 +enum pkg_state_flag
11162 +{
11163 + SF_OK = 0,
11164 + SF_REINSTREQ = 1,
11165 + SF_HOLD = 2, /* do not upgrade version */
11166 + SF_REPLACE = 4, /* replace this package */
11167 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11168 + SF_PREFER = 16, /* prefer this version */
11169 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11170 + SF_MARKED = 64, /* temporary mark */
11171 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11172 + SF_USER = 256,
11173 + SF_LAST_STATE_FLAG
11174 +};
11175 +typedef enum pkg_state_flag pkg_state_flag_t;
11176 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11177 +
11178 +enum pkg_state_status
11179 +{
11180 + SS_NOT_INSTALLED = 1,
11181 + SS_UNPACKED,
11182 + SS_HALF_CONFIGURED,
11183 + SS_INSTALLED,
11184 + SS_HALF_INSTALLED,
11185 + SS_CONFIG_FILES,
11186 + SS_POST_INST_FAILED,
11187 + SS_REMOVAL_FAILED,
11188 + SS_LAST_STATE_STATUS
11189 +};
11190 +typedef enum pkg_state_status pkg_state_status_t;
11191 +
11192 +struct abstract_pkg{
11193 + char * name;
11194 + int dependencies_checked;
11195 + pkg_vec_t * pkgs;
11196 + pkg_state_status_t state_status;
11197 + pkg_state_flag_t state_flag;
11198 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11199 + abstract_pkg_vec_t * provided_by;
11200 + abstract_pkg_vec_t * replaced_by;
11201 +};
11202 +
11203 +#include "pkg_depends.h"
11204 +
11205 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11206 +
11207 + The 3 version fields should go into a single version struct. (This
11208 + is especially important since, currently, pkg->version can easily
11209 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11210 + distinct. This has been the source of multiple bugs.
11211 +
11212 + The 3 state fields could possibly also go into their own struct.
11213 +
11214 + All fields which deal with lists of packages, (Depends,
11215 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11216 + be handled by a single struct in pkg_t
11217 +
11218 + All string fields for which there is a small set of possible
11219 + values, (section, maintainer, architecture, maybe version?), that
11220 + are reused among different packages -- for all such packages we
11221 + should move from "char *"s to some atom datatype to share data
11222 + storage and use less memory. We might even do reference counting,
11223 + but probably not since most often we only create new pkg_t structs,
11224 + we don't often free them. */
11225 +struct pkg
11226 +{
11227 + char *name;
11228 + unsigned long epoch;
11229 + char *version;
11230 + char *revision;
11231 + char *familiar_revision;
11232 + pkg_src_t *src;
11233 + pkg_dest_t *dest;
11234 + char *architecture;
11235 + char *section;
11236 + char *maintainer;
11237 + char *description;
11238 + pkg_state_want_t state_want;
11239 + pkg_state_flag_t state_flag;
11240 + pkg_state_status_t state_status;
11241 + char **depends_str;
11242 + int depends_count;
11243 + char **pre_depends_str;
11244 + int pre_depends_count;
11245 + char **recommends_str;
11246 + int recommends_count;
11247 + char **suggests_str;
11248 + int suggests_count;
11249 + compound_depend_t * depends;
11250 +
11251 + /* Abhaya: new conflicts */
11252 + char **conflicts_str;
11253 + compound_depend_t * conflicts;
11254 + int conflicts_count;
11255 +
11256 + char **replaces_str;
11257 + int replaces_count;
11258 + abstract_pkg_t ** replaces;
11259 +
11260 + char **provides_str;
11261 + int provides_count;
11262 + abstract_pkg_t ** provides;
11263 +
11264 + abstract_pkg_t *parent;
11265 +
11266 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11267 +
11268 + char *filename;
11269 + char *local_filename;
11270 + char *url;
11271 + char *tmp_unpack_dir;
11272 + char *md5sum;
11273 + char *size;
11274 + char *installed_size;
11275 + char *priority;
11276 + char *source;
11277 + conffile_list_t conffiles;
11278 + time_t installed_time;
11279 + /* As pointer for lazy evaluation */
11280 + str_list_t *installed_files;
11281 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11282 + mechanism to avoid the problem here, (which is that the
11283 + installed_files list was being freed from an inner loop while
11284 + still being used within an outer loop. */
11285 + int installed_files_ref_cnt;
11286 + int essential;
11287 + int arch_priority;
11288 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11289 + int provided_by_hand;
11290 +};
11291 +
11292 +pkg_t *pkg_new(void);
11293 +int pkg_init(pkg_t *pkg);
11294 +void pkg_deinit(pkg_t *pkg);
11295 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11296 +abstract_pkg_t *abstract_pkg_new(void);
11297 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11298 +
11299 +/*
11300 + * merges fields from newpkg into oldpkg.
11301 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11302 + */
11303 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11304 +
11305 +char *pkg_version_str_alloc(pkg_t *pkg);
11306 +
11307 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11308 +int pkg_name_version_and_architecture_compare(void *a, void *b);
11309 +int abstract_pkg_name_compare(void *a, void *b);
11310 +
11311 +char * pkg_formatted_info(pkg_t *pkg );
11312 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11313 +
11314 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11315 +
11316 +void pkg_print_info(pkg_t *pkg, FILE *file);
11317 +void pkg_print_status(pkg_t * pkg, FILE * file);
11318 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11319 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11320 +int pkg_free_installed_files(pkg_t *pkg);
11321 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11322 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11323 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11324 + const char *script, const char *args);
11325 +
11326 +/* enum mappings */
11327 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11328 +pkg_state_want_t pkg_state_want_from_str(char *str);
11329 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11330 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11331 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11332 +pkg_state_status_t pkg_state_status_from_str(char *str);
11333 +
11334 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11335 +
11336 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11337 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11338 +int pkg_free_installed_files(pkg_t *pkg);
11339 +
11340 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11341 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11342 +
11343 +#endif
11344 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_hash.c busybox-1.3.1-911/archival/libipkg/pkg_hash.c
11345 --- busybox-1.3.1-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11346 +++ busybox-1.3.1-911/archival/libipkg/pkg_hash.c 2006-12-27 19:41:04.000000000 +0100
11347 @@ -0,0 +1,617 @@
11348 +/* ipkg_hash.c - the itsy package management system
11349 +
11350 + Steven M. Ayer
11351 +
11352 + Copyright (C) 2002 Compaq Computer Corporation
11353 +
11354 + This program is free software; you can redistribute it and/or
11355 + modify it under the terms of the GNU General Public License as
11356 + published by the Free Software Foundation; either version 2, or (at
11357 + your option) any later version.
11358 +
11359 + This program is distributed in the hope that it will be useful, but
11360 + WITHOUT ANY WARRANTY; without even the implied warranty of
11361 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11362 + General Public License for more details.
11363 +*/
11364 +
11365 +#include "ipkg.h"
11366 +#include <errno.h>
11367 +#include <ctype.h>
11368 +#include <stdlib.h>
11369 +#include <string.h>
11370 +
11371 +#include "hash_table.h"
11372 +#include "pkg.h"
11373 +#include "ipkg_message.h"
11374 +#include "pkg_vec.h"
11375 +#include "pkg_hash.h"
11376 +#include "pkg_parse.h"
11377 +#include "ipkg_utils.h"
11378 +
11379 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11380 +
11381 +/*
11382 + * this will talk to both feeds-lists files and installed status files
11383 + * example api:
11384 + *
11385 + * hash_table_t hash;
11386 + * pkg_hash_init(name, &hash, 1000);
11387 + * pkg_hash_add_from_file(<feed filename>);
11388 + *
11389 + * the query function is just there as a shell to prove to me that this
11390 + * sort of works, but isn't far from doing something useful
11391 + *
11392 + * -sma, 12/21/01
11393 + * modified: CDW 3 Jan. 2002
11394 + */
11395 +
11396 +
11397 +\f
11398 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11399 +{
11400 + return hash_table_init(name, hash, len);
11401 +}
11402 +
11403 +void pkg_hash_deinit(hash_table_t *hash)
11404 +{
11405 + hash_table_deinit(hash);
11406 +}
11407 +
11408 +
11409 +/* Find the default arch for a given package status file if none is given. */
11410 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11411 +{
11412 + nv_pair_list_elt_t *l;
11413 + char *def_arch = HOST_CPU_STR; /* Default arch */
11414 + int def_prio = 0; /* Other archs override this */
11415 +
11416 + l = conf->arch_list.head;
11417 +
11418 + while (l) {
11419 + nv_pair_t *nv = l->data;
11420 + int priority = strtol(nv->value, NULL, 0);
11421 +
11422 + /* Check if this arch has higher priority, and is valid */
11423 + if ((priority > def_prio) &&
11424 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11425 + /* Our new default */
11426 + def_prio = priority;
11427 + def_arch = nv->name;
11428 + }
11429 + l = l->next;
11430 + }
11431 +
11432 + return strdup(def_arch);
11433 +}
11434 +
11435 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11436 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11437 +{
11438 + hash_table_t *hash = &conf->pkg_hash;
11439 + char **raw;
11440 + char **raw_start;
11441 + pkg_t *pkg;
11442 +
11443 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11444 + if (!raw)
11445 + return -ENOMEM;
11446 +
11447 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11448 + pkg = pkg_new();
11449 + if (!pkg)
11450 + return -ENOMEM;
11451 +
11452 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11453 + if (!pkg->architecture) {
11454 + char *version_str = pkg_version_str_alloc(pkg);
11455 + pkg->architecture = pkg_get_default_arch(conf);
11456 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11457 + pkg->name, version_str, pkg->architecture);
11458 + free(version_str);
11459 + }
11460 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11461 + } else {
11462 + free(pkg);
11463 + }
11464 + }
11465 +
11466 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11467 + memory after read_raw_pkgs_from_file */
11468 + raw = raw_start;
11469 + while (*raw) {
11470 + free(*raw++);
11471 + }
11472 + free(raw_start);
11473 + return 0;
11474 +}
11475 +
11476 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11477 +{
11478 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11479 +}
11480 +
11481 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11482 +{
11483 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11484 + if (apkg)
11485 + return NULL;
11486 + return apkg->provided_by;
11487 +}
11488 +
11489 +
11490 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11491 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11492 +{
11493 + int i;
11494 + int nprovides = 0;
11495 + int nmatching = 0;
11496 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11497 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11498 + abstract_pkg_vec_t *provided_apkg_vec;
11499 + abstract_pkg_t **provided_apkgs;
11500 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11501 + pkg_t *latest_installed_parent = NULL;
11502 + pkg_t *latest_matching = NULL;
11503 + pkg_t *held_pkg = NULL;
11504 + pkg_t *good_pkg_by_name = NULL;
11505 +
11506 + if (matching_apkgs == NULL || providers == NULL ||
11507 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11508 + return NULL;
11509 +
11510 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11511 +
11512 + provided_apkg_vec = apkg->provided_by;
11513 + nprovides = provided_apkg_vec->len;
11514 + provided_apkgs = provided_apkg_vec->pkgs;
11515 + if (nprovides > 1)
11516 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11517 +
11518 + /* accumulate all the providers */
11519 + for (i = 0; i < nprovides; i++) {
11520 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11521 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11522 + abstract_pkg_vec_insert(providers, provider_apkg);
11523 + }
11524 + nprovides = providers->len;
11525 +
11526 + for (i = 0; i < nprovides; i++) {
11527 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11528 + abstract_pkg_t *replacement_apkg = NULL;
11529 + pkg_vec_t *vec;
11530 +
11531 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11532 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11533 + if (provider_apkg->replaced_by->len > 1) {
11534 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11535 + provider_apkg->name, replacement_apkg->name);
11536 + }
11537 + }
11538 +
11539 + if (replacement_apkg)
11540 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11541 + replacement_apkg->name, provider_apkg->name);
11542 +
11543 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11544 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11545 + continue;
11546 + else
11547 + provider_apkg = replacement_apkg;
11548 + }
11549 +
11550 + if (!(vec = provider_apkg->pkgs)) {
11551 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11552 + continue;
11553 + }
11554 +
11555 +
11556 + /* now check for supported architecture */
11557 + {
11558 + int max_count = 0;
11559 + int i;
11560 +
11561 + /* count packages matching max arch priority and keep track of last one */
11562 + for (i = 0; i < vec->len; i++) {
11563 + pkg_t *maybe = vec->pkgs[i];
11564 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11565 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11566 + if (maybe->arch_priority > 0) {
11567 + max_count++;
11568 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11569 + pkg_vec_insert(matching_pkgs, maybe);
11570 + }
11571 + }
11572 + }
11573 + }
11574 +
11575 + if (matching_pkgs->len > 1)
11576 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11577 + if (matching_apkgs->len > 1)
11578 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11579 +
11580 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11581 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11582 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11583 + Until now I always got the latest, but that breaks the downgrade option.
11584 + If I stop at the first one, I would probably miss the new ones
11585 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11586 + or from a Packages feed.
11587 + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
11588 +/*Pigi*/
11589 +
11590 + for (i = 0; i < matching_pkgs->len; i++) {
11591 + pkg_t *matching = matching_pkgs->pkgs[i];
11592 + if (constraint_fcn(matching, cdata)) { /* We found it */
11593 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11594 + good_pkg_by_name = matching;
11595 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11596 + break;
11597 + }
11598 + }
11599 +
11600 +
11601 + for (i = 0; i < matching_pkgs->len; i++) {
11602 + pkg_t *matching = matching_pkgs->pkgs[i];
11603 + latest_matching = matching;
11604 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11605 + latest_installed_parent = matching;
11606 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11607 + if (held_pkg)
11608 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11609 + held_pkg->name, matching->name);
11610 + held_pkg = matching;
11611 + }
11612 + }
11613 +
11614 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11615 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11616 + apkg->name, matching_apkgs->len);
11617 + for (i = 0; i < matching_apkgs->len; i++) {
11618 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11619 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11620 + }
11621 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11622 + }
11623 +
11624 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11625 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11626 + __FUNCTION__, apkg->name, matching_pkgs->len);
11627 + for (i = 0; i < matching_pkgs->len; i++) {
11628 + pkg_t *matching = matching_pkgs->pkgs[i];
11629 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11630 + matching->name, matching->version, matching->architecture);
11631 + }
11632 + }
11633 +
11634 + nmatching = matching_apkgs->len;
11635 +
11636 + pkg_vec_free(matching_pkgs);
11637 + abstract_pkg_vec_free(matching_apkgs);
11638 + abstract_pkg_vec_free(providers);
11639 +
11640 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11641 + return good_pkg_by_name;
11642 + }
11643 + if (held_pkg) {
11644 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11645 + return held_pkg;
11646 + }
11647 + if (latest_installed_parent) {
11648 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11649 + return latest_installed_parent;
11650 + }
11651 + if (nmatching > 1) {
11652 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11653 + return NULL;
11654 + }
11655 + if (latest_matching) {
11656 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11657 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11658 + return latest_matching;
11659 + }
11660 + return NULL;
11661 +}
11662 +
11663 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11664 +{
11665 + const char *name = (const char *)cdata;
11666 + if (strcmp(pkg->name, name) == 0)
11667 + return 1;
11668 + else
11669 + return 0;
11670 +}
11671 +
11672 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11673 +{
11674 + hash_table_t *hash = &conf->pkg_hash;
11675 + abstract_pkg_t *apkg = NULL;
11676 +
11677 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11678 + return NULL;
11679 +
11680 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11681 +}
11682 +
11683 +
11684 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11685 + const char *pkg_name,
11686 + const char * version)
11687 +{
11688 + pkg_vec_t * vec;
11689 + register int i;
11690 + char *version_str = NULL;
11691 +
11692 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11693 + return NULL;
11694 +
11695 + for(i = 0; i < vec->len; i++) {
11696 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11697 + if(!strcmp(version_str, version)) {
11698 + free(version_str);
11699 + break;
11700 + }
11701 + free(version_str);
11702 + }
11703 +
11704 + if(i == vec->len)
11705 + return NULL;
11706 +
11707 + return vec->pkgs[i];
11708 +}
11709 +
11710 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11711 + const char *pkg_name,
11712 + pkg_dest_t *dest)
11713 +{
11714 + pkg_vec_t * vec;
11715 + register int i;
11716 +
11717 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11718 + return NULL;
11719 + }
11720 +
11721 + for(i = 0; i < vec->len; i++)
11722 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11723 + return vec->pkgs[i];
11724 + }
11725 + return NULL;
11726 +}
11727 +
11728 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11729 + const char *pkg_name)
11730 +{
11731 + pkg_vec_t * vec;
11732 + register int i;
11733 +
11734 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11735 + return NULL;
11736 + }
11737 +
11738 + for(i = 0; i < vec->len; i++)
11739 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11740 + return vec->pkgs[i];
11741 + }
11742 +
11743 + return NULL;
11744 +}
11745 +
11746 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11747 +{
11748 + abstract_pkg_t * ab_pkg;
11749 +
11750 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11751 + return NULL;
11752 + }
11753 +
11754 + if (ab_pkg->pkgs) {
11755 + return ab_pkg->pkgs;
11756 + } else if (ab_pkg->provided_by) {
11757 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11758 + if (abpkg != NULL){
11759 + return abpkg->pkgs;
11760 + } else {
11761 + return ab_pkg->pkgs;
11762 + }
11763 + } else {
11764 + return NULL;
11765 + }
11766 +}
11767 +
11768 +static int pkg_compare_names(const void *p1, const void *p2)
11769 +{
11770 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11771 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11772 + if (pkg1->name == NULL)
11773 + return 1;
11774 + if (pkg2->name == NULL)
11775 + return -1;
11776 + return(strcmp(pkg1->name, pkg2->name));
11777 +}
11778 +
11779 +
11780 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11781 +{
11782 + int j;
11783 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11784 + pkg_vec_t *all = (pkg_vec_t *)data;
11785 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11786 + if (pkg_vec) {
11787 + for (j = 0; j < pkg_vec->len; j++) {
11788 + pkg_t *pkg = pkg_vec->pkgs[j];
11789 + pkg_vec_insert(all, pkg);
11790 + }
11791 + }
11792 +}
11793 +
11794 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11795 +{
11796 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11797 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11798 +}
11799 +
11800 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11801 +{
11802 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11803 + pkg_vec_t *all = (pkg_vec_t *)data;
11804 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11805 + int j;
11806 + if (pkg_vec) {
11807 + for (j = 0; j < pkg_vec->len; j++) {
11808 + pkg_t *pkg = pkg_vec->pkgs[j];
11809 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11810 + pkg_vec_insert(all, pkg);
11811 + }
11812 + }
11813 + }
11814 +}
11815 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11816 +{
11817 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11818 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11819 +}
11820 +
11821 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11822 +{
11823 + int i;
11824 + pkg_t *pkg;
11825 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11826 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11827 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11828 + fprintf(stdout, "%s\n", ab_pkg->name);
11829 + i = 0;
11830 + if (dependents != NULL)
11831 + while (dependents [i] != NULL)
11832 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11833 + dependents = ab_pkg->provided_by->pkgs;
11834 + i = 0;
11835 + if (dependents != NULL)
11836 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11837 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11838 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11839 + if (pkg) {
11840 + i = 0;
11841 + while (i < pkg->depends_count)
11842 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11843 + }
11844 +}
11845 +void pkg_hash_dump(hash_table_t *hash, void *data)
11846 +{
11847 +
11848 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11849 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11850 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11851 +}
11852 +
11853 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11854 +{
11855 + abstract_pkg_t * ab_pkg;
11856 +
11857 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11858 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11859 +
11860 + return ab_pkg;
11861 +}
11862 +
11863 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11864 +{
11865 + abstract_pkg_t * ab_pkg;
11866 + int arch_priority;
11867 +
11868 + if(!pkg)
11869 + return pkg;
11870 +
11871 + arch_priority = pkg->arch_priority;
11872 +
11873 + if (buildDepends(hash, pkg)<0){
11874 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11875 + return NULL;
11876 + }
11877 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11878 +
11879 + if (set_status) {
11880 + if (pkg->state_status == SS_INSTALLED) {
11881 + ab_pkg->state_status = SS_INSTALLED;
11882 + } else if (pkg->state_status == SS_UNPACKED) {
11883 + ab_pkg->state_status = SS_UNPACKED;
11884 + }
11885 + }
11886 +
11887 + if(!ab_pkg->pkgs)
11888 + ab_pkg->pkgs = pkg_vec_alloc();
11889 +
11890 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11891 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11892 + pkg->parent = ab_pkg;
11893 +
11894 + if (buildProvides(hash, ab_pkg, pkg)<0){
11895 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11896 + return NULL;
11897 + }
11898 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11899 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11900 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11901 + return NULL;
11902 + }
11903 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11904 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11905 + return NULL;
11906 + }
11907 +
11908 + buildDependedUponBy(pkg, ab_pkg);
11909 + return pkg;
11910 +}
11911 +
11912 +/*
11913 + * this will assume that we've already determined that
11914 + * the abstract pkg doesn't exist, 'cause we should know these things...
11915 + */
11916 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11917 +{
11918 + abstract_pkg_t * ab_pkg;
11919 +
11920 + ab_pkg = abstract_pkg_new();
11921 + if (ab_pkg == NULL) { return NULL; }
11922 +
11923 + ab_pkg->name = strdup(pkg_name);
11924 + hash_table_insert(hash, pkg_name, ab_pkg);
11925 +
11926 + return ab_pkg;
11927 +}
11928 +
11929 +
11930 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11931 +{
11932 + hash_table_t *file_hash = &conf->file_hash;
11933 +
11934 + return hash_table_get(file_hash, file_name);
11935 +}
11936 +
11937 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11938 +{
11939 + hash_table_t *file_hash = &conf->file_hash;
11940 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11941 + int file_name_len = strlen(file_name);
11942 +
11943 + if (file_name[file_name_len -1] == '/')
11944 + return 0;
11945 +
11946 + if (conf->offline_root) {
11947 + int len = strlen(conf->offline_root);
11948 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11949 + file_name += len;
11950 + }
11951 + }
11952 +
11953 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11954 + hash_table_insert(file_hash, file_name, owning_pkg);
11955 + if (old_owning_pkg) {
11956 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11957 + /* mark this package to have its filelist written */
11958 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11959 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11960 + }
11961 + return 0;
11962 +}
11963 +
11964 +
11965 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_hash.h busybox-1.3.1-911/archival/libipkg/pkg_hash.h
11966 --- busybox-1.3.1-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11967 +++ busybox-1.3.1-911/archival/libipkg/pkg_hash.h 2006-12-27 19:41:04.000000000 +0100
11968 @@ -0,0 +1,61 @@
11969 +/* pkg_hash.h - the itsy package management system
11970 +
11971 + Steven M. Ayer
11972 +
11973 + Copyright (C) 2002 Compaq Computer Corporation
11974 +
11975 + This program is free software; you can redistribute it and/or
11976 + modify it under the terms of the GNU General Public License as
11977 + published by the Free Software Foundation; either version 2, or (at
11978 + your option) any later version.
11979 +
11980 + This program is distributed in the hope that it will be useful, but
11981 + WITHOUT ANY WARRANTY; without even the implied warranty of
11982 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11983 + General Public License for more details.
11984 +*/
11985 +
11986 +#ifndef PKG_HASH_H
11987 +#define PKG_HASH_H
11988 +
11989 +#include "pkg.h"
11990 +#include "pkg_vec.h"
11991 +#include "hash_table.h"
11992 +
11993 +
11994 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11995 +void pkg_hash_deinit(hash_table_t *hash);
11996 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11997 +
11998 +void pkg_hash_dump(hash_table_t *hash, void *data);
11999 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12000 +
12001 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12002 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12003 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12004 +
12005 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12006 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12007 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12008 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12009 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12010 + const char *pkg_name,
12011 + const char * version);
12012 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12013 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12014 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12015 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12016 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12017 + const char *pkg_name);
12018 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12019 + const char *pkg_name,
12020 + pkg_dest_t *dest);
12021 +
12022 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12023 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12024 +
12025 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12026 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12027 +
12028 +#endif
12029 +
12030 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_parse.c busybox-1.3.1-911/archival/libipkg/pkg_parse.c
12031 --- busybox-1.3.1-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12032 +++ busybox-1.3.1-911/archival/libipkg/pkg_parse.c 2006-12-27 19:41:04.000000000 +0100
12033 @@ -0,0 +1,366 @@
12034 +/* pkg_parse.c - the itsy package management system
12035 +
12036 + Steven M. Ayer
12037 +
12038 + Copyright (C) 2002 Compaq Computer Corporation
12039 +
12040 + This program is free software; you can redistribute it and/or
12041 + modify it under the terms of the GNU General Public License as
12042 + published by the Free Software Foundation; either version 2, or (at
12043 + your option) any later version.
12044 +
12045 + This program is distributed in the hope that it will be useful, but
12046 + WITHOUT ANY WARRANTY; without even the implied warranty of
12047 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12048 + General Public License for more details.
12049 +*/
12050 +
12051 +#include "ipkg.h"
12052 +#include <errno.h>
12053 +#include <ctype.h>
12054 +
12055 +#include "pkg.h"
12056 +#include "ipkg_utils.h"
12057 +#include "pkg_parse.h"
12058 +
12059 +int isGenericFieldType(char * type, char * line)
12060 +{
12061 + if(!strncmp(line, type, strlen(type)))
12062 + return 1;
12063 + return 0;
12064 +}
12065 +
12066 +char * parseGenericFieldType(char * type, char * raw)
12067 +{
12068 + char * field_value = raw + (strlen(type) + 1);
12069 + return trim_alloc(field_value);
12070 +}
12071 +
12072 +void parseStatus(pkg_t *pkg, char * raw)
12073 +{
12074 + char sw_str[64], sf_str[64], ss_str[64];
12075 +
12076 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12077 + pkg->state_want = pkg_state_want_from_str(sw_str);
12078 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12079 + pkg->state_status = pkg_state_status_from_str(ss_str);
12080 +}
12081 +
12082 +char ** parseDependsString(char * raw, int * depends_count)
12083 +{
12084 + char ** depends = NULL;
12085 + int line_count = 0;
12086 + char buff[2048], * dest;
12087 +
12088 + while(raw && *raw && !isspace(*raw)) {
12089 + raw++;
12090 + }
12091 +
12092 + if(line_is_blank(raw)){
12093 + *depends_count = line_count;
12094 + return NULL;
12095 + }
12096 + while(raw && *raw){
12097 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12098 +
12099 + while(isspace(*raw)) raw++;
12100 +
12101 + dest = buff;
12102 + while((*raw != ',') && *raw)
12103 + *dest++ = *raw++;
12104 +
12105 + *dest = '\0';
12106 + depends[line_count] = trim_alloc(buff);
12107 + if(depends[line_count] ==NULL)
12108 + return NULL;
12109 + line_count++;
12110 + if(*raw == ',')
12111 + raw++;
12112 + }
12113 + *depends_count = line_count;
12114 + return depends;
12115 +}
12116 +
12117 +void parseConffiles(pkg_t * pkg, char * raw)
12118 +{
12119 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12120 +
12121 + if(!strncmp(raw, "Conffiles:", 10))
12122 + raw += strlen("Conffiles:");
12123 +
12124 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12125 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12126 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12127 + while (*raw && isspace(*raw)) {
12128 + raw++;
12129 + }
12130 + raw += strlen(file_name);
12131 + while (*raw && isspace(*raw)) {
12132 + raw++;
12133 + }
12134 + raw += strlen(md5sum);
12135 + }
12136 +}
12137 +
12138 +int parseVersion(pkg_t *pkg, char *raw)
12139 +{
12140 + char *colon, *eepochcolon;
12141 +#ifdef USE_DEBVERSION
12142 + char *hyphen;
12143 +#endif
12144 + unsigned long epoch;
12145 +
12146 + if (!*raw) {
12147 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12148 + return EINVAL;
12149 + }
12150 +
12151 + if (strncmp(raw, "Version:", 8) == 0) {
12152 + raw += 8;
12153 + }
12154 + while (*raw && isspace(*raw)) {
12155 + raw++;
12156 + }
12157 +
12158 + colon= strchr(raw,':');
12159 + if (colon) {
12160 + epoch= strtoul(raw,&eepochcolon,10);
12161 + if (colon != eepochcolon) {
12162 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12163 + return EINVAL;
12164 + }
12165 + if (!*++colon) {
12166 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12167 + return EINVAL;
12168 + }
12169 + raw= colon;
12170 + pkg->epoch= epoch;
12171 + } else {
12172 + pkg->epoch= 0;
12173 + }
12174 +
12175 + pkg->revision = "";
12176 + pkg->familiar_revision = "";
12177 +
12178 + pkg->version= malloc(strlen(raw)+1);
12179 + if ( pkg->version == NULL ) {
12180 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12181 + return ENOMEM;
12182 + }
12183 + strcpy(pkg->version, raw);
12184 +
12185 +#ifdef USE_DEBVERSION
12186 + hyphen= strrchr(pkg->version,'-');
12187 +
12188 + if (hyphen) {
12189 + *hyphen++= 0;
12190 + if (strncmp("fam", hyphen, 3) == 0) {
12191 + pkg->familiar_revision=hyphen+3;
12192 + hyphen= strrchr(pkg->version,'-');
12193 + if (hyphen) {
12194 + *hyphen++= 0;
12195 + pkg->revision = hyphen;
12196 + }
12197 + } else {
12198 + pkg->revision = hyphen;
12199 + }
12200 + }
12201 +#endif
12202 +
12203 +/*
12204 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12205 + pkg->epoch,
12206 + pkg->version,
12207 + pkg->revision,
12208 + pkg->familiar_revision);
12209 +*/
12210 +
12211 + return 0;
12212 +}
12213 +
12214 +
12215 +/* This code is needed to insert in first position the keyword for the aligning bug */
12216 +
12217 +int alterProvidesLine(char *raw, char *temp)
12218 +{
12219 +
12220 +
12221 + if (!*raw) {
12222 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12223 + return -EINVAL;
12224 + }
12225 +
12226 + if ( temp == NULL ) {
12227 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12228 + return -ENOMEM;
12229 + }
12230 +
12231 + if (strncmp(raw, "Provides:", 9) == 0) {
12232 + raw += 9;
12233 + }
12234 + while (*raw && isspace(*raw)) {
12235 + raw++;
12236 + }
12237 +
12238 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12239 + while (*raw) {
12240 + strncat( temp, raw++, 1);
12241 + }
12242 + return 0;
12243 +
12244 +}
12245 +
12246 +/* Some random thoughts from Carl:
12247 +
12248 + This function could be considerably simplified if we just kept
12249 + an array of all the generic string-valued field names, and looped
12250 + through those looking for a match. Also, these fields could perhaps
12251 + be stored in the package as an array as well, (or, probably better,
12252 + as an nv_pair_list_t).
12253 +
12254 + Fields which require special parsing or storage, (such as Depends:
12255 + and Status:) could be handled as they are now.
12256 +*/
12257 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12258 + to a dependency list. And, since we already have
12259 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12260 + Enhances, perhaps we could generalize all of these and save some
12261 + code duplication.
12262 +*/
12263 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12264 +{
12265 + int reading_conffiles, reading_description;
12266 + int pkg_false_provides=1;
12267 + char ** lines;
12268 + char * provide=NULL;
12269 +
12270 + pkg->src = src;
12271 + pkg->dest = dest;
12272 +
12273 + reading_conffiles = reading_description = 0;
12274 +
12275 + for (lines = *raw; *lines; lines++) {
12276 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12277 + if(isGenericFieldType("Package:", *lines))
12278 + pkg->name = parseGenericFieldType("Package", *lines);
12279 + else if(isGenericFieldType("Architecture:", *lines))
12280 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12281 + else if(isGenericFieldType("Filename:", *lines))
12282 + pkg->filename = parseGenericFieldType("Filename", *lines);
12283 + else if(isGenericFieldType("Section:", *lines))
12284 + pkg->section = parseGenericFieldType("Section", *lines);
12285 + else if(isGenericFieldType("MD5sum:", *lines))
12286 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12287 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12288 + let's parse it either way */
12289 + else if(isGenericFieldType("MD5Sum:", *lines))
12290 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12291 + else if(isGenericFieldType("Size:", *lines))
12292 + pkg->size = parseGenericFieldType("Size", *lines);
12293 + else if(isGenericFieldType("Source:", *lines))
12294 + pkg->source = parseGenericFieldType("Source", *lines);
12295 + else if(isGenericFieldType("Installed-Size:", *lines))
12296 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12297 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12298 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12299 + pkg->installed_time = strtoul(time_str, NULL, 0);
12300 + } else if(isGenericFieldType("Priority:", *lines))
12301 + pkg->priority = parseGenericFieldType("Priority", *lines);
12302 + else if(isGenericFieldType("Essential:", *lines)) {
12303 + char *essential_value;
12304 + essential_value = parseGenericFieldType("Essential", *lines);
12305 + if (strcmp(essential_value, "yes") == 0) {
12306 + pkg->essential = 1;
12307 + }
12308 + free(essential_value);
12309 + }
12310 + else if(isGenericFieldType("Status", *lines))
12311 + parseStatus(pkg, *lines);
12312 + else if(isGenericFieldType("Version", *lines))
12313 + parseVersion(pkg, *lines);
12314 + else if(isGenericFieldType("Maintainer", *lines))
12315 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12316 + else if(isGenericFieldType("Conffiles", *lines)){
12317 + parseConffiles(pkg, *lines);
12318 + reading_conffiles = 1;
12319 + }
12320 + else if(isGenericFieldType("Description", *lines)) {
12321 + pkg->description = parseGenericFieldType("Description", *lines);
12322 + reading_conffiles = 0;
12323 + reading_description = 1;
12324 + }
12325 +
12326 + else if(isGenericFieldType("Provides", *lines)){
12327 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12328 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12329 + if ( alterProvidesLine(*lines,provide) ){
12330 + return EINVAL;
12331 + }
12332 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12333 +/* Let's try to hack a bit here.
12334 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12335 + in alot of other places. We will remove it before writing down the status database */
12336 + pkg_false_provides=0;
12337 + free(provide);
12338 + }
12339 +
12340 + else if(isGenericFieldType("Depends", *lines))
12341 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12342 + else if(isGenericFieldType("Pre-Depends", *lines))
12343 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12344 + else if(isGenericFieldType("Recommends", *lines))
12345 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12346 + else if(isGenericFieldType("Suggests", *lines))
12347 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12348 + /* Abhaya: support for conflicts */
12349 + else if(isGenericFieldType("Conflicts", *lines))
12350 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12351 + else if(isGenericFieldType("Replaces", *lines))
12352 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12353 + else if(line_is_blank(*lines)) {
12354 + lines++;
12355 + break;
12356 + }
12357 + else if(**lines == ' '){
12358 + if(reading_description) {
12359 + /* we already know it's not blank, so the rest of description */
12360 + pkg->description = realloc(pkg->description,
12361 + strlen(pkg->description)
12362 + + 1 + strlen(*lines) + 1);
12363 + strcat(pkg->description, "\n");
12364 + strcat(pkg->description, (*lines));
12365 + }
12366 + else if(reading_conffiles)
12367 + parseConffiles(pkg, *lines);
12368 + }
12369 + }
12370 + *raw = lines;
12371 +/* If the ipk has not a Provides line, we insert our false line */
12372 + if ( pkg_false_provides==1)
12373 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12374 +
12375 + if (pkg->name) {
12376 + return 0;
12377 + } else {
12378 + return EINVAL;
12379 + }
12380 +}
12381 +
12382 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12383 +{
12384 + char ** lines;
12385 +
12386 + for (lines = *raw; *lines; lines++) {
12387 + if(isGenericFieldType("Essential:", *lines)) {
12388 + char *essential_value;
12389 + essential_value = parseGenericFieldType("Essential", *lines);
12390 + if (strcmp(essential_value, "yes") == 0) {
12391 + pkg->essential = 1;
12392 + }
12393 + free(essential_value);
12394 + }
12395 + }
12396 + *raw = lines;
12397 +
12398 + return 0;
12399 +}
12400 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_parse.h busybox-1.3.1-911/archival/libipkg/pkg_parse.h
12401 --- busybox-1.3.1-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12402 +++ busybox-1.3.1-911/archival/libipkg/pkg_parse.h 2006-12-27 19:41:04.000000000 +0100
12403 @@ -0,0 +1,31 @@
12404 +/* pkg_parse.h - the itsy package management system
12405 +
12406 + Steven M. Ayer
12407 +
12408 + Copyright (C) 2002 Compaq Computer Corporation
12409 +
12410 + This program is free software; you can redistribute it and/or
12411 + modify it under the terms of the GNU General Public License as
12412 + published by the Free Software Foundation; either version 2, or (at
12413 + your option) any later version.
12414 +
12415 + This program is distributed in the hope that it will be useful, but
12416 + WITHOUT ANY WARRANTY; without even the implied warranty of
12417 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12418 + General Public License for more details.
12419 +*/
12420 +
12421 +#ifndef PKG_PARSE_H
12422 +#define PKG_PARSE_H
12423 +
12424 +int isGenericFieldType(char * type, char * line);
12425 +char * parseGenericFieldType(char * type, char * raw);
12426 +void parseStatus(pkg_t *pkg, char * raw);
12427 +int parseVersion(pkg_t *pkg, char *raw);
12428 +char ** parseDependsString(char * raw, int * depends_count);
12429 +int parseVersion(pkg_t *pkg, char *raw);
12430 +void parseConffiles(pkg_t * pkg, char * raw);
12431 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12432 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12433 +
12434 +#endif
12435 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_src.c busybox-1.3.1-911/archival/libipkg/pkg_src.c
12436 --- busybox-1.3.1-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12437 +++ busybox-1.3.1-911/archival/libipkg/pkg_src.c 2006-12-27 19:41:04.000000000 +0100
12438 @@ -0,0 +1,43 @@
12439 +/* pkg_src.c - the itsy package management system
12440 +
12441 + Carl D. Worth
12442 +
12443 + Copyright (C) 2001 University of Southern California
12444 +
12445 + This program is free software; you can redistribute it and/or
12446 + modify it under the terms of the GNU General Public License as
12447 + published by the Free Software Foundation; either version 2, or (at
12448 + your option) any later version.
12449 +
12450 + This program is distributed in the hope that it will be useful, but
12451 + WITHOUT ANY WARRANTY; without even the implied warranty of
12452 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12453 + General Public License for more details.
12454 +*/
12455 +
12456 +#include "ipkg.h"
12457 +
12458 +#include "pkg_src.h"
12459 +#include "str_util.h"
12460 +
12461 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12462 +{
12463 + src->gzip = gzip;
12464 + src->name = str_dup_safe (name);
12465 + src->value = str_dup_safe (base_url);
12466 + if (extra_data)
12467 + src->extra_data = str_dup_safe (extra_data);
12468 + else
12469 + src->extra_data = NULL;
12470 + return 0;
12471 +}
12472 +
12473 +void pkg_src_deinit(pkg_src_t *src)
12474 +{
12475 + free (src->name);
12476 + free (src->value);
12477 + if (src->extra_data)
12478 + free (src->extra_data);
12479 +}
12480 +
12481 +
12482 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_src.h busybox-1.3.1-911/archival/libipkg/pkg_src.h
12483 --- busybox-1.3.1-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12484 +++ busybox-1.3.1-911/archival/libipkg/pkg_src.h 2006-12-27 19:41:04.000000000 +0100
12485 @@ -0,0 +1,34 @@
12486 +/* pkg_src.h - the itsy package management system
12487 +
12488 + Carl D. Worth
12489 +
12490 + Copyright (C) 2001 University of Southern California
12491 +
12492 + This program is free software; you can redistribute it and/or
12493 + modify it under the terms of the GNU General Public License as
12494 + published by the Free Software Foundation; either version 2, or (at
12495 + your option) any later version.
12496 +
12497 + This program is distributed in the hope that it will be useful, but
12498 + WITHOUT ANY WARRANTY; without even the implied warranty of
12499 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12500 + General Public License for more details.
12501 +*/
12502 +
12503 +#ifndef PKG_SRC_H
12504 +#define PKG_SRC_H
12505 +
12506 +#include "nv_pair.h"
12507 +
12508 +typedef struct
12509 +{
12510 + char *name;
12511 + char *value;
12512 + char *extra_data;
12513 + int gzip;
12514 +} pkg_src_t;
12515 +
12516 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12517 +void pkg_src_deinit(pkg_src_t *src);
12518 +
12519 +#endif
12520 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_src_list.c busybox-1.3.1-911/archival/libipkg/pkg_src_list.c
12521 --- busybox-1.3.1-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12522 +++ busybox-1.3.1-911/archival/libipkg/pkg_src_list.c 2006-12-27 19:41:04.000000000 +0100
12523 @@ -0,0 +1,75 @@
12524 +/* pkg_src_list.c - the itsy package management system
12525 +
12526 + Carl D. Worth
12527 +
12528 + Copyright (C) 2001 University of Southern California
12529 +
12530 + This program is free software; you can redistribute it and/or
12531 + modify it under the terms of the GNU General Public License as
12532 + published by the Free Software Foundation; either version 2, or (at
12533 + your option) any later version.
12534 +
12535 + This program is distributed in the hope that it will be useful, but
12536 + WITHOUT ANY WARRANTY; without even the implied warranty of
12537 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12538 + General Public License for more details.
12539 +*/
12540 +
12541 +#include "ipkg.h"
12542 +
12543 +#include "pkg_src_list.h"
12544 +#include "void_list.h"
12545 +
12546 +int pkg_src_list_init(pkg_src_list_t *list)
12547 +{
12548 + return void_list_init((void_list_t *) list);
12549 +}
12550 +
12551 +void pkg_src_list_deinit(pkg_src_list_t *list)
12552 +{
12553 + pkg_src_list_elt_t *iter;
12554 + pkg_src_t *pkg_src;
12555 +
12556 + for (iter = list->head; iter; iter = iter->next) {
12557 + pkg_src = iter->data;
12558 + pkg_src_deinit(pkg_src);
12559 +
12560 + /* malloced in pkg_src_list_append */
12561 + free(pkg_src);
12562 + iter->data = NULL;
12563 + }
12564 + void_list_deinit((void_list_t *) list);
12565 +}
12566 +
12567 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12568 + const char *name, const char *base_url, const char *extra_data,
12569 + int gzip)
12570 +{
12571 + int err;
12572 +
12573 + /* freed in pkg_src_list_deinit */
12574 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12575 +
12576 + if (pkg_src == NULL) {
12577 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12578 + return NULL;
12579 + }
12580 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12581 +
12582 + err = void_list_append((void_list_t *) list, pkg_src);
12583 + if (err) {
12584 + return NULL;
12585 + }
12586 +
12587 + return pkg_src;
12588 +}
12589 +
12590 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12591 +{
12592 + return void_list_push((void_list_t *) list, data);
12593 +}
12594 +
12595 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12596 +{
12597 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12598 +}
12599 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_src_list.h busybox-1.3.1-911/archival/libipkg/pkg_src_list.h
12600 --- busybox-1.3.1-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12601 +++ busybox-1.3.1-911/archival/libipkg/pkg_src_list.h 2006-12-27 19:41:04.000000000 +0100
12602 @@ -0,0 +1,57 @@
12603 +/* pkg_src_list.h - the itsy package management system
12604 +
12605 + Carl D. Worth
12606 +
12607 + Copyright (C) 2001 University of Southern California
12608 +
12609 + This program is free software; you can redistribute it and/or
12610 + modify it under the terms of the GNU General Public License as
12611 + published by the Free Software Foundation; either version 2, or (at
12612 + your option) any later version.
12613 +
12614 + This program is distributed in the hope that it will be useful, but
12615 + WITHOUT ANY WARRANTY; without even the implied warranty of
12616 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12617 + General Public License for more details.
12618 +*/
12619 +
12620 +#ifndef PKG_SRC_LIST_H
12621 +#define PKG_SRC_LIST_H
12622 +
12623 +#include "pkg_src.h"
12624 +
12625 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12626 +struct pkg_src_list_elt
12627 +{
12628 + pkg_src_list_elt_t *next;
12629 + pkg_src_t *data;
12630 +};
12631 +
12632 +typedef struct pkg_src_list pkg_src_list_t;
12633 +struct pkg_src_list
12634 +{
12635 + pkg_src_list_elt_t pre_head;
12636 + pkg_src_list_elt_t *head;
12637 + pkg_src_list_elt_t *tail;
12638 +};
12639 +
12640 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12641 +{
12642 + if (list->head == NULL)
12643 + return 1;
12644 + else
12645 + return 0;
12646 +}
12647 +
12648 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12649 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12650 +
12651 +int pkg_src_list_init(pkg_src_list_t *list);
12652 +void pkg_src_list_deinit(pkg_src_list_t *list);
12653 +
12654 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
12655 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12656 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12657 +
12658 +#endif
12659 +
12660 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_vec.c busybox-1.3.1-911/archival/libipkg/pkg_vec.c
12661 --- busybox-1.3.1-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12662 +++ busybox-1.3.1-911/archival/libipkg/pkg_vec.c 2006-12-27 19:41:04.000000000 +0100
12663 @@ -0,0 +1,230 @@
12664 +/* pkg_vec.c - the itsy package management system
12665 +
12666 + Steven M. Ayer
12667 +
12668 + Copyright (C) 2002 Compaq Computer Corporation
12669 +
12670 + This program is free software; you can redistribute it and/or
12671 + modify it under the terms of the GNU General Public License as
12672 + published by the Free Software Foundation; either version 2, or (at
12673 + your option) any later version.
12674 +
12675 + This program is distributed in the hope that it will be useful, but
12676 + WITHOUT ANY WARRANTY; without even the implied warranty of
12677 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12678 + General Public License for more details.
12679 +*/
12680 +
12681 +#include <stdlib.h>
12682 +#include <fnmatch.h>
12683 +#include "xregex.h"
12684 +#include "ipkg.h"
12685 +#include "pkg.h"
12686 +
12687 +pkg_vec_t * pkg_vec_alloc(void)
12688 +{
12689 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12690 + if (!vec) {
12691 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12692 + return NULL;
12693 + }
12694 + vec->pkgs = NULL;
12695 + vec->len = 0;
12696 +
12697 + return vec;
12698 +}
12699 +
12700 +void pkg_vec_free(pkg_vec_t *vec)
12701 +{
12702 + free(vec->pkgs);
12703 + free(vec);
12704 +}
12705 +
12706 +/*
12707 + * assumption: all names in a vector are identical
12708 + * assumption: all version strings are trimmed,
12709 + * so identical versions have identical version strings,
12710 + * implying identical packages; let's marry these
12711 + */
12712 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12713 +{
12714 + int i;
12715 + int found = 0;
12716 +
12717 + /* look for a duplicate pkg by name, version, and architecture */
12718 + for (i = 0; i < vec->len; i++){
12719 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12720 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12721 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12722 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12723 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12724 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12725 + found = 1;
12726 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12727 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12728 + break;
12729 + }
12730 + }
12731 +
12732 + /* we didn't find one, add it */
12733 + if (!found){
12734 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12735 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12736 +
12737 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12738 + vec->pkgs[vec->len] = pkg;
12739 + vec->len++;
12740 + return pkg;
12741 + }
12742 + /* update the one that we have */
12743 + else {
12744 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12745 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12746 + if (set_status) {
12747 + /* this is from the status file, so need to merge with existing database */
12748 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12749 + pkg_merge(vec->pkgs[i], pkg, set_status);
12750 + /* XXX: CLEANUP: It's not so polite to free something here
12751 + that was passed in from above. */
12752 + pkg_deinit(pkg);
12753 + free(pkg);
12754 + } else {
12755 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12756 + /* just overwrite the old one */
12757 + pkg_deinit(vec->pkgs[i]);
12758 + free(vec->pkgs[i]);
12759 + vec->pkgs[i] = pkg;
12760 + }
12761 + return vec->pkgs[i];
12762 + }
12763 +}
12764 +
12765 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12766 +{
12767 + int i;
12768 + int found = 0;
12769 +
12770 + /* look for a duplicate pkg by name, version, and architecture */
12771 + for (i = 0; i < vec->len; i++)
12772 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12773 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12774 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12775 + found = 1;
12776 + break;
12777 + }
12778 +
12779 + /* we didn't find one, add it */
12780 + if(!found){
12781 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12782 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12783 + vec->len++;
12784 + }
12785 +}
12786 +
12787 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12788 +{
12789 + int i;
12790 + for (i = 0; i < vec->len; i++)
12791 + if (vec->pkgs[i] == apkg)
12792 + return 1;
12793 + return 0;
12794 +}
12795 +
12796 +typedef int (*compare_fcn_t)(const void *, const void *);
12797 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12798 +{
12799 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12800 +}
12801 +
12802 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12803 +{
12804 + int npkgs = vec->len;
12805 + int i;
12806 + for (i = 0; i < npkgs; i++) {
12807 + pkg_t *pkg = vec->pkgs[i];
12808 + pkg->state_flag &= ~SF_MARKED;
12809 + }
12810 + return 0;
12811 +}
12812 +
12813 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12814 +{
12815 + int matching_count = 0;
12816 + pkg_t **pkgs = vec->pkgs;
12817 + int npkgs = vec->len;
12818 + int i;
12819 + for (i = 0; i < npkgs; i++) {
12820 + pkg_t *pkg = pkgs[i];
12821 + if (fnmatch(pattern, pkg->name, 0)==0) {
12822 + pkg->state_flag |= SF_MARKED;
12823 + matching_count++;
12824 + }
12825 + }
12826 + return matching_count;
12827 +}
12828 +
12829 +
12830 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12831 +{
12832 + abstract_pkg_vec_t * vec ;
12833 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12834 + if (!vec) {
12835 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12836 + return NULL;
12837 + }
12838 + vec->pkgs = NULL;
12839 + vec->len = 0;
12840 +
12841 + return vec;
12842 +}
12843 +
12844 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12845 +{
12846 + free(vec->pkgs);
12847 + free(vec);
12848 +}
12849 +
12850 +/*
12851 + * assumption: all names in a vector are unique
12852 + */
12853 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12854 +{
12855 + int i;
12856 +
12857 + /* look for a duplicate pkg by name */
12858 + for(i = 0; i < vec->len; i++)
12859 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12860 + break;
12861 +
12862 + /* we didn't find one, add it */
12863 + if(i == vec->len){
12864 + vec->pkgs =
12865 + (abstract_pkg_t **)
12866 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12867 + vec->pkgs[vec->len] = pkg;
12868 + vec->len++;
12869 + }
12870 +}
12871 +
12872 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12873 +{
12874 + if (vec->len > i)
12875 + return vec->pkgs[i];
12876 + else
12877 + return NULL;
12878 +}
12879 +
12880 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12881 +{
12882 + int i;
12883 + for (i = 0; i < vec->len; i++)
12884 + if (vec->pkgs[i] == apkg)
12885 + return 1;
12886 + return 0;
12887 +}
12888 +
12889 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12890 +{
12891 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12892 +}
12893 +
12894 diff -ruN busybox-1.3.1-orig/archival/libipkg/pkg_vec.h busybox-1.3.1-911/archival/libipkg/pkg_vec.h
12895 --- busybox-1.3.1-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12896 +++ busybox-1.3.1-911/archival/libipkg/pkg_vec.h 2006-12-27 19:41:04.000000000 +0100
12897 @@ -0,0 +1,62 @@
12898 +/* pkg_vec.h - the itsy package management system
12899 +
12900 + Steven M. Ayer
12901 +
12902 + Copyright (C) 2002 Compaq Computer Corporation
12903 +
12904 + This program is free software; you can redistribute it and/or
12905 + modify it under the terms of the GNU General Public License as
12906 + published by the Free Software Foundation; either version 2, or (at
12907 + your option) any later version.
12908 +
12909 + This program is distributed in the hope that it will be useful, but
12910 + WITHOUT ANY WARRANTY; without even the implied warranty of
12911 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12912 + General Public License for more details.
12913 +*/
12914 +
12915 +#ifndef PKG_VEC_H
12916 +#define PKG_VEC_H
12917 +
12918 +typedef struct pkg pkg_t;
12919 +typedef struct abstract_pkg abstract_pkg_t;
12920 +
12921 +struct pkg_vec
12922 +{
12923 + pkg_t **pkgs;
12924 + int len;
12925 +};
12926 +typedef struct pkg_vec pkg_vec_t;
12927 +
12928 +struct abstract_pkg_vec
12929 +{
12930 + abstract_pkg_t **pkgs;
12931 + int len;
12932 +};
12933 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12934 +
12935 +
12936 +pkg_vec_t * pkg_vec_alloc(void);
12937 +void pkg_vec_free(pkg_vec_t *vec);
12938 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12939 +
12940 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12941 +/* pkg_vec_insert_merge: might munge pkg.
12942 +* returns the pkg that is in the pkg graph */
12943 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12944 +/* this one never munges pkg */
12945 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12946 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12947 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12948 +
12949 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12950 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12951 +
12952 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12953 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12954 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12955 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12956 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12957 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12958 +#endif
12959 +
12960 diff -ruN busybox-1.3.1-orig/archival/libipkg/sprintf_alloc.h busybox-1.3.1-911/archival/libipkg/sprintf_alloc.h
12961 --- busybox-1.3.1-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12962 +++ busybox-1.3.1-911/archival/libipkg/sprintf_alloc.h 2006-12-28 02:28:27.000000000 +0100
12963 @@ -0,0 +1,25 @@
12964 +/* sprintf_alloca.c -- like sprintf with memory allocation
12965 +
12966 + Carl D. Worth
12967 +
12968 + Copyright (C) 2001 University of Southern California
12969 +
12970 + This program is free software; you can redistribute it and/or modify
12971 + it under the terms of the GNU General Public License as published by
12972 + the Free Software Foundation; either version 2, or (at your option)
12973 + any later version.
12974 +
12975 + This program is distributed in the hope that it will be useful,
12976 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12977 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12978 + GNU General Public License for more details.
12979 +*/
12980 +
12981 +#ifndef SPRINTF_ALLOC_H
12982 +#define SPRINTF_ALLOC_H
12983 +
12984 +#include "libbb.h"
12985 +
12986 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12987 +
12988 +#endif
12989 diff -ruN busybox-1.3.1-orig/archival/libipkg/str_list.c busybox-1.3.1-911/archival/libipkg/str_list.c
12990 --- busybox-1.3.1-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12991 +++ busybox-1.3.1-911/archival/libipkg/str_list.c 2006-12-27 19:41:04.000000000 +0100
12992 @@ -0,0 +1,76 @@
12993 +/* str_list.c - the itsy package management system
12994 +
12995 + Carl D. Worth
12996 +
12997 + Copyright (C) 2001 University of Southern California
12998 +
12999 + This program is free software; you can redistribute it and/or
13000 + modify it under the terms of the GNU General Public License as
13001 + published by the Free Software Foundation; either version 2, or (at
13002 + your option) any later version.
13003 +
13004 + This program is distributed in the hope that it will be useful, but
13005 + WITHOUT ANY WARRANTY; without even the implied warranty of
13006 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13007 + General Public License for more details.
13008 +*/
13009 +
13010 +#include "ipkg.h"
13011 +
13012 +#include "str_list.h"
13013 +
13014 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13015 +{
13016 + return void_list_elt_init((void_list_elt_t *) elt, data);
13017 +}
13018 +
13019 +void str_list_elt_deinit(str_list_elt_t *elt)
13020 +{
13021 + void_list_elt_deinit((void_list_elt_t *) elt);
13022 +}
13023 +
13024 +str_list_t *str_list_alloc()
13025 +{
13026 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13027 + if (list)
13028 + str_list_init(list);
13029 + return list;
13030 +}
13031 +
13032 +int str_list_init(str_list_t *list)
13033 +{
13034 + return void_list_init((void_list_t *) list);
13035 +}
13036 +
13037 +void str_list_deinit(str_list_t *list)
13038 +{
13039 + void_list_deinit((void_list_t *) list);
13040 +}
13041 +
13042 +int str_list_append(str_list_t *list, char *data)
13043 +{
13044 + return void_list_append((void_list_t *) list, data);
13045 +}
13046 +
13047 +int str_list_push(str_list_t *list, char *data)
13048 +{
13049 + return void_list_push((void_list_t *) list, data);
13050 +}
13051 +
13052 +str_list_elt_t *str_list_pop(str_list_t *list)
13053 +{
13054 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13055 +}
13056 +
13057 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13058 +{
13059 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13060 + (void_list_elt_t **) iter);
13061 +}
13062 +
13063 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13064 +{
13065 + return (char *)void_list_remove_elt((void_list_t *) list,
13066 + (void *)target_str,
13067 + (void_list_cmp_t)strcmp);
13068 +}
13069 diff -ruN busybox-1.3.1-orig/archival/libipkg/str_list.h busybox-1.3.1-911/archival/libipkg/str_list.h
13070 --- busybox-1.3.1-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13071 +++ busybox-1.3.1-911/archival/libipkg/str_list.h 2006-12-27 19:41:04.000000000 +0100
13072 @@ -0,0 +1,51 @@
13073 +/* str_list.h - the itsy package management system
13074 +
13075 + Carl D. Worth
13076 +
13077 + Copyright (C) 2001 University of Southern California
13078 +
13079 + This program is free software; you can redistribute it and/or
13080 + modify it under the terms of the GNU General Public License as
13081 + published by the Free Software Foundation; either version 2, or (at
13082 + your option) any later version.
13083 +
13084 + This program is distributed in the hope that it will be useful, but
13085 + WITHOUT ANY WARRANTY; without even the implied warranty of
13086 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13087 + General Public License for more details.
13088 +*/
13089 +
13090 +#ifndef STR_LIST_H
13091 +#define STR_LIST_H
13092 +
13093 +#include "void_list.h"
13094 +
13095 +typedef struct str_list_elt str_list_elt_t;
13096 +struct str_list_elt
13097 +{
13098 + str_list_elt_t *next;
13099 + char *data;
13100 +};
13101 +
13102 +typedef struct xstr_list str_list_t;
13103 +struct xstr_list
13104 +{
13105 + str_list_elt_t pre_head;
13106 + str_list_elt_t *head;
13107 + str_list_elt_t *tail;
13108 +};
13109 +
13110 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13111 +void str_list_elt_deinit(str_list_elt_t *elt);
13112 +
13113 +str_list_t *str_list_alloc(void);
13114 +int str_list_init(str_list_t *list);
13115 +void str_list_deinit(str_list_t *list);
13116 +
13117 +int str_list_append(str_list_t *list, char *data);
13118 +int str_list_push(str_list_t *list, char *data);
13119 +str_list_elt_t *str_list_pop(str_list_t *list);
13120 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13121 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13122 +
13123 +#endif
13124 diff -ruN busybox-1.3.1-orig/archival/libipkg/str_util.c busybox-1.3.1-911/archival/libipkg/str_util.c
13125 --- busybox-1.3.1-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13126 +++ busybox-1.3.1-911/archival/libipkg/str_util.c 2006-12-27 19:41:04.000000000 +0100
13127 @@ -0,0 +1,73 @@
13128 +/* str_utils.c - the itsy package management system
13129 +
13130 + Carl D. Worth
13131 +
13132 + Copyright (C) 2001 University of Southern California
13133 +
13134 + This program is free software; you can redistribute it and/or
13135 + modify it under the terms of the GNU General Public License as
13136 + published by the Free Software Foundation; either version 2, or (at
13137 + your option) any later version.
13138 +
13139 + This program is distributed in the hope that it will be useful, but
13140 + WITHOUT ANY WARRANTY; without even the implied warranty of
13141 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13142 + General Public License for more details.
13143 +*/
13144 +
13145 +#include "ipkg.h"
13146 +
13147 +int str_starts_with(const char *str, const char *prefix)
13148 +{
13149 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13150 +}
13151 +
13152 +int str_ends_with(const char *str, const char *suffix)
13153 +{
13154 + int suffix_len;
13155 + int str_len;
13156 +
13157 + str_len = strlen(str);
13158 + suffix_len = strlen(suffix);
13159 +
13160 + if (str_len < suffix_len) {
13161 + return 0;
13162 + }
13163 +
13164 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13165 +}
13166 +
13167 +int str_chomp(char *str)
13168 +{
13169 + if (str[strlen(str) - 1] == '\n') {
13170 + str[strlen(str) - 1] = '\0';
13171 + return 1;
13172 + }
13173 + return 0;
13174 +}
13175 +
13176 +int str_tolower(char *str)
13177 +{
13178 + while (*str) {
13179 + *str = tolower(*str);
13180 + str++;
13181 + }
13182 +
13183 + return 0;
13184 +}
13185 +
13186 +int str_toupper(char *str)
13187 +{
13188 + while (*str) {
13189 + *str = toupper(*str);
13190 + str++;
13191 + }
13192 +
13193 + return 0;
13194 +}
13195 +
13196 +char *str_dup_safe(const char *str)
13197 +{
13198 + return str ? strdup(str) : NULL;
13199 +}
13200 +
13201 diff -ruN busybox-1.3.1-orig/archival/libipkg/str_util.h busybox-1.3.1-911/archival/libipkg/str_util.h
13202 --- busybox-1.3.1-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13203 +++ busybox-1.3.1-911/archival/libipkg/str_util.h 2006-12-27 19:41:04.000000000 +0100
13204 @@ -0,0 +1,28 @@
13205 +/* str_utils.h - the itsy package management system
13206 +
13207 + Carl D. Worth
13208 +
13209 + Copyright (C) 2001 University of Southern California
13210 +
13211 + This program is free software; you can redistribute it and/or
13212 + modify it under the terms of the GNU General Public License as
13213 + published by the Free Software Foundation; either version 2, or (at
13214 + your option) any later version.
13215 +
13216 + This program is distributed in the hope that it will be useful, but
13217 + WITHOUT ANY WARRANTY; without even the implied warranty of
13218 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13219 + General Public License for more details.
13220 +*/
13221 +
13222 +#ifndef STR_UTILS_H
13223 +#define STR_UTILS_H
13224 +
13225 +int str_starts_with(const char *str, const char *prefix);
13226 +int str_ends_with(const char *str, const char *suffix);
13227 +int str_chomp(char *str);
13228 +int str_tolower(char *str);
13229 +int str_toupper(char *str);
13230 +char *str_dup_safe(const char *str);
13231 +
13232 +#endif
13233 diff -ruN busybox-1.3.1-orig/archival/libipkg/user.c busybox-1.3.1-911/archival/libipkg/user.c
13234 --- busybox-1.3.1-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13235 +++ busybox-1.3.1-911/archival/libipkg/user.c 2006-12-27 19:41:04.000000000 +0100
13236 @@ -0,0 +1,58 @@
13237 +/* user.c - the itsy package management system
13238 +
13239 + Jamey Hicks
13240 +
13241 + Copyright (C) 2002 Hewlett Packard Company
13242 + Copyright (C) 2001 University of Southern California
13243 +
13244 + This program is free software; you can redistribute it and/or
13245 + modify it under the terms of the GNU General Public License as
13246 + published by the Free Software Foundation; either version 2, or (at
13247 + your option) any later version.
13248 +
13249 + This program is distributed in the hope that it will be useful, but
13250 + WITHOUT ANY WARRANTY; without even the implied warranty of
13251 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13252 + General Public License for more details.
13253 +*/
13254 +
13255 +#include <stdio.h>
13256 +#include <stdarg.h>
13257 +#include "file_util.h"
13258 +#include "str_util.h"
13259 +#ifdef IPKG_LIB
13260 +#include "libipkg.h"
13261 +#endif
13262 +
13263 +
13264 +#ifdef IPKG_LIB
13265 +static char *question = NULL;
13266 +static int question_len = 255;
13267 +#endif
13268 +char *get_user_response(const char *format, ...)
13269 +{
13270 + int len = question_len;
13271 + va_list ap;
13272 + char *response;
13273 + va_start(ap, format);
13274 +
13275 +#ifndef IPKG_LIB
13276 + vprintf(format, ap);
13277 + do {
13278 + response = file_read_line_alloc(stdin);
13279 + } while (response == NULL);
13280 +#else
13281 + do {
13282 + if (question == NULL || len > question_len) {
13283 + question = realloc(question, len + 1);
13284 + question_len = len;
13285 + }
13286 + len = vsnprintf(question,question_len,format,ap);
13287 + } while (len > question_len);
13288 + response = strdup(ipkg_cb_response(question));
13289 +#endif
13290 + str_chomp(response);
13291 + str_tolower(response);
13292 +
13293 + return response;
13294 +}
13295 diff -ruN busybox-1.3.1-orig/archival/libipkg/user.h busybox-1.3.1-911/archival/libipkg/user.h
13296 --- busybox-1.3.1-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13297 +++ busybox-1.3.1-911/archival/libipkg/user.h 2006-12-27 19:41:04.000000000 +0100
13298 @@ -0,0 +1,23 @@
13299 +/* user.c - the itsy package management system
13300 +
13301 + Jamey Hicks
13302 +
13303 + Copyright (C) 2002 Hewlett Packard Company
13304 + Copyright (C) 2001 University of Southern California
13305 +
13306 + This program is free software; you can redistribute it and/or
13307 + modify it under the terms of the GNU General Public License as
13308 + published by the Free Software Foundation; either version 2, or (at
13309 + your option) any later version.
13310 +
13311 + This program is distributed in the hope that it will be useful, but
13312 + WITHOUT ANY WARRANTY; without even the implied warranty of
13313 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13314 + General Public License for more details.
13315 +*/
13316 +
13317 +#include <stdio.h>
13318 +#include <stdarg.h>
13319 +
13320 +char *get_user_response(const char *format, ...);
13321 +
13322 diff -ruN busybox-1.3.1-orig/archival/libipkg/void_list.c busybox-1.3.1-911/archival/libipkg/void_list.c
13323 --- busybox-1.3.1-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13324 +++ busybox-1.3.1-911/archival/libipkg/void_list.c 2006-12-27 19:41:04.000000000 +0100
13325 @@ -0,0 +1,194 @@
13326 +/* void_list.c - the itsy package management system
13327 +
13328 + Carl D. Worth
13329 +
13330 + Copyright (C) 2001 University of Southern California
13331 +
13332 + This program is free software; you can redistribute it and/or
13333 + modify it under the terms of the GNU General Public License as
13334 + published by the Free Software Foundation; either version 2, or (at
13335 + your option) any later version.
13336 +
13337 + This program is distributed in the hope that it will be useful, but
13338 + WITHOUT ANY WARRANTY; without even the implied warranty of
13339 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13340 + General Public License for more details.
13341 +*/
13342 +
13343 +#include "ipkg.h"
13344 +#include <errno.h>
13345 +
13346 +#include "void_list.h"
13347 +
13348 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13349 +{
13350 + elt->next = NULL;
13351 + elt->data = data;
13352 +
13353 + return 0;
13354 +}
13355 +
13356 +void void_list_elt_deinit(void_list_elt_t *elt)
13357 +{
13358 + void_list_elt_init(elt, NULL);
13359 +}
13360 +
13361 +int void_list_init(void_list_t *list)
13362 +{
13363 + void_list_elt_init(&list->pre_head, NULL);
13364 + list->head = NULL;
13365 + list->pre_head.next = list->head;
13366 + list->tail = NULL;
13367 +
13368 + return 0;
13369 +}
13370 +
13371 +void void_list_deinit(void_list_t *list)
13372 +{
13373 + void_list_elt_t *elt;
13374 +
13375 + while (list->head) {
13376 + elt = void_list_pop(list);
13377 + void_list_elt_deinit(elt);
13378 + /* malloced in void_list_append */
13379 + free(elt);
13380 + }
13381 +}
13382 +
13383 +int void_list_append(void_list_t *list, void *data)
13384 +{
13385 + void_list_elt_t *elt;
13386 +
13387 + /* freed in void_list_deinit */
13388 + elt = malloc(sizeof(void_list_elt_t));
13389 + if (elt == NULL) {
13390 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13391 + return ENOMEM;
13392 + }
13393 +
13394 + void_list_elt_init(elt, data);
13395 +
13396 + if (list->tail) {
13397 + list->tail->next = elt;
13398 + list->tail = elt;
13399 + } else {
13400 + list->head = elt;
13401 + list->pre_head.next = list->head;
13402 + list->tail = elt;
13403 + }
13404 +
13405 + return 0;
13406 +}
13407 +
13408 +int void_list_push(void_list_t *list, void *data)
13409 +{
13410 + void_list_elt_t *elt;
13411 +
13412 + elt = malloc(sizeof(void_list_elt_t));
13413 + if (elt == NULL) {
13414 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13415 + return ENOMEM;
13416 + }
13417 +
13418 + void_list_elt_init(elt, data);
13419 +
13420 + elt->next = list->head;
13421 + list->head->next = elt;
13422 + if (list->tail == NULL) {
13423 + list->tail = list->head;
13424 + }
13425 +
13426 + return 0;
13427 +}
13428 +
13429 +void_list_elt_t *void_list_pop(void_list_t *list)
13430 +{
13431 + void_list_elt_t *elt;
13432 +
13433 + elt = list->head;
13434 +
13435 + if (list->head) {
13436 + list->head = list->head->next;
13437 + list->pre_head.next = list->head;
13438 + if (list->head == NULL) {
13439 + list->tail = NULL;
13440 + }
13441 + }
13442 +
13443 + return elt;
13444 +}
13445 +
13446 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13447 +{
13448 + void_list_elt_t *prior;
13449 + void_list_elt_t *old_elt;
13450 + void *old_data;
13451 +
13452 + old_elt = *iter;
13453 + old_data = old_elt->data;
13454 +
13455 + if (old_elt == list->head) {
13456 + prior = &list->pre_head;
13457 + void_list_pop(list);
13458 + } else {
13459 + for (prior = list->head; prior; prior = prior->next) {
13460 + if (prior->next == old_elt) {
13461 + break;
13462 + }
13463 + }
13464 + if (prior == NULL || prior->next != old_elt) {
13465 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13466 + return NULL;
13467 + }
13468 + prior->next = old_elt->next;
13469 +
13470 + if (old_elt == list->tail) {
13471 + list->tail = prior;
13472 + }
13473 + }
13474 +
13475 + void_list_elt_deinit(old_elt);
13476 + *iter = prior;
13477 +
13478 + return old_data;
13479 +}
13480 +
13481 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13482 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13483 +{
13484 + void_list_elt_t *prior;
13485 + void_list_elt_t *old_elt = NULL;
13486 + void *old_data = NULL;
13487 +
13488 + /* first element */
13489 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13490 + old_elt = list->head;
13491 + old_data = list->head->data;
13492 + void_list_pop(list);
13493 + } else {
13494 + int found = 0;
13495 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13496 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13497 + old_elt = prior->next;
13498 + old_data = old_elt->data;
13499 + found = 1;
13500 + break;
13501 + }
13502 + }
13503 + if (!found) {
13504 + return NULL;
13505 + }
13506 + prior->next = old_elt->next;
13507 +
13508 + if (old_elt == list->tail) {
13509 + list->tail = prior;
13510 + }
13511 + }
13512 + if (old_elt)
13513 + void_list_elt_deinit(old_elt);
13514 +
13515 + if (old_data)
13516 + return old_data;
13517 + else
13518 + return NULL;
13519 +}
13520 diff -ruN busybox-1.3.1-orig/archival/libipkg/void_list.h busybox-1.3.1-911/archival/libipkg/void_list.h
13521 --- busybox-1.3.1-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13522 +++ busybox-1.3.1-911/archival/libipkg/void_list.h 2006-12-27 19:41:04.000000000 +0100
13523 @@ -0,0 +1,59 @@
13524 +/* void_list.h - the itsy package management system
13525 +
13526 + Carl D. Worth
13527 +
13528 + Copyright (C) 2001 University of Southern California
13529 +
13530 + This program is free software; you can redistribute it and/or
13531 + modify it under the terms of the GNU General Public License as
13532 + published by the Free Software Foundation; either version 2, or (at
13533 + your option) any later version.
13534 +
13535 + This program is distributed in the hope that it will be useful, but
13536 + WITHOUT ANY WARRANTY; without even the implied warranty of
13537 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13538 + General Public License for more details.
13539 +*/
13540 +
13541 +#ifndef VOID_LIST_H
13542 +#define VOID_LIST_H
13543 +
13544 +typedef struct void_list_elt void_list_elt_t;
13545 +struct void_list_elt
13546 +{
13547 + void_list_elt_t *next;
13548 + void *data;
13549 +};
13550 +
13551 +typedef struct void_list void_list_t;
13552 +struct void_list
13553 +{
13554 + void_list_elt_t pre_head;
13555 + void_list_elt_t *head;
13556 + void_list_elt_t *tail;
13557 +};
13558 +
13559 +static inline int void_list_empty(void_list_t *list)
13560 +{
13561 + if (list->head == NULL)
13562 + return 1;
13563 + else
13564 + return 0;
13565 +}
13566 +
13567 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13568 +void void_list_elt_deinit(void_list_elt_t *elt);
13569 +
13570 +int void_list_init(void_list_t *list);
13571 +void void_list_deinit(void_list_t *list);
13572 +
13573 +int void_list_append(void_list_t *list, void *data);
13574 +int void_list_push(void_list_t *list, void *data);
13575 +void_list_elt_t *void_list_pop(void_list_t *list);
13576 +
13577 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13578 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13579 +typedef int (*void_list_cmp_t)(const void *, const void *);
13580 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13581 +
13582 +#endif
13583 diff -ruN busybox-1.3.1-orig/archival/libipkg/xsystem.c busybox-1.3.1-911/archival/libipkg/xsystem.c
13584 --- busybox-1.3.1-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13585 +++ busybox-1.3.1-911/archival/libipkg/xsystem.c 2006-12-27 19:41:04.000000000 +0100
13586 @@ -0,0 +1,64 @@
13587 +/* xsystem.c - system(3) with error messages
13588 +
13589 + Carl D. Worth
13590 +
13591 + Copyright (C) 2001 University of Southern California
13592 +
13593 + This program is free software; you can redistribute it and/or
13594 + modify it under the terms of the GNU General Public License as
13595 + published by the Free Software Foundation; either version 2, or (at
13596 + your option) any later version.
13597 +
13598 + This program is distributed in the hope that it will be useful, but
13599 + WITHOUT ANY WARRANTY; without even the implied warranty of
13600 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13601 + General Public License for more details.
13602 +*/
13603 +
13604 +#include "ipkg.h"
13605 +#include <sys/wait.h>
13606 +
13607 +#include "xsystem.h"
13608 +
13609 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13610 + really need the /bin/sh invocation which takes resources and
13611 + introduces security problems. I should switch all of this to a sort
13612 + of execl() or execv() interface/implementation.
13613 +*/
13614 +
13615 +/* Like system(3), but with error messages printed if the fork fails
13616 + or if the child process dies due to an uncaught signal. Also, the
13617 + return value is a bit simpler:
13618 +
13619 + -1 if there was any problem
13620 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13621 + as defined in <sys/wait.h>.
13622 +*/
13623 +int xsystem(const char *cmd)
13624 +{
13625 + int err;
13626 +
13627 + err = system(cmd);
13628 +
13629 + if (err == -1) {
13630 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13631 + __FUNCTION__, cmd);
13632 + return -1;
13633 + }
13634 +
13635 + if (WIFSIGNALED(err)) {
13636 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13637 + __FUNCTION__, WTERMSIG(err), cmd);
13638 + return -1;
13639 + }
13640 +
13641 + if (WIFEXITED(err)) {
13642 + /* Normal child exit */
13643 + return WEXITSTATUS(err);
13644 + }
13645 +
13646 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13647 + __FUNCTION__, err);
13648 + return -1;
13649 +}
13650 +
13651 diff -ruN busybox-1.3.1-orig/archival/libipkg/xsystem.h busybox-1.3.1-911/archival/libipkg/xsystem.h
13652 --- busybox-1.3.1-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13653 +++ busybox-1.3.1-911/archival/libipkg/xsystem.h 2006-12-27 19:41:04.000000000 +0100
13654 @@ -0,0 +1,34 @@
13655 +/* xsystem.h - system(3) with error messages
13656 +
13657 + Carl D. Worth
13658 +
13659 + Copyright (C) 2001 University of Southern California
13660 +
13661 + This program is free software; you can redistribute it and/or
13662 + modify it under the terms of the GNU General Public License as
13663 + published by the Free Software Foundation; either version 2, or (at
13664 + your option) any later version.
13665 +
13666 + This program is distributed in the hope that it will be useful, but
13667 + WITHOUT ANY WARRANTY; without even the implied warranty of
13668 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13669 + General Public License for more details.
13670 +*/
13671 +
13672 +#ifndef XSYSTEM_H
13673 +#define XSYSTEM_H
13674 +
13675 +#include <stdlib.h>
13676 +
13677 +/* Like system(3), but with error messages printed if the fork fails
13678 + or if the child process dies due to an uncaught signal. Also, the
13679 + return value is a bit simpler:
13680 +
13681 + -1 if there was any problem
13682 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13683 + as defined in <sys/wait.h>.
13684 +*/
13685 +int xsystem(const char *cmd);
13686 +
13687 +#endif
13688 +
13689 diff -ruN busybox-1.3.1-orig/archival/libunarchive/data_extract_all.c busybox-1.3.1-911/archival/libunarchive/data_extract_all.c
13690 --- busybox-1.3.1-orig/archival/libunarchive/data_extract_all.c 2006-12-27 05:53:54.000000000 +0100
13691 +++ busybox-1.3.1-911/archival/libunarchive/data_extract_all.c 2006-12-27 19:41:04.000000000 +0100
13692 @@ -117,3 +117,17 @@
13693 utime(file_header->name, &t);
13694 }
13695 }
13696 +
13697 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13698 +{
13699 + char *name_ptr = archive_handle->file_header->name;
13700 +
13701 + name_ptr += strspn(name_ptr, "./");
13702 + if (name_ptr[0] != '\0') {
13703 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13704 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13705 + strcat(archive_handle->file_header->name, name_ptr);
13706 + data_extract_all(archive_handle);
13707 + }
13708 +}
13709 +
13710 diff -ruN busybox-1.3.1-orig/archival/libunarchive/Kbuild busybox-1.3.1-911/archival/libunarchive/Kbuild
13711 --- busybox-1.3.1-orig/archival/libunarchive/Kbuild 2006-12-27 05:53:54.000000000 +0100
13712 +++ busybox-1.3.1-911/archival/libunarchive/Kbuild 2006-12-27 19:50:13.000000000 +0100
13713 @@ -47,6 +47,7 @@
13714 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13715 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13716 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13717 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13718 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13719 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13720 lib-$(CONFIG_TAR) += get_header_tar.o
13721 diff -ruN busybox-1.3.1-orig/include/applets.h busybox-1.3.1-911/include/applets.h
13722 --- busybox-1.3.1-orig/include/applets.h 2006-12-27 05:56:18.000000000 +0100
13723 +++ busybox-1.3.1-911/include/applets.h 2006-12-27 19:41:59.000000000 +0100
13724 @@ -162,6 +162,7 @@
13725 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13726 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13727 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13728 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13729 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13730 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13731 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13732 diff -ruN busybox-1.3.1-orig/include/unarchive.h busybox-1.3.1-911/include/unarchive.h
13733 --- busybox-1.3.1-orig/include/unarchive.h 2006-12-27 05:56:18.000000000 +0100
13734 +++ busybox-1.3.1-911/include/unarchive.h 2006-12-27 19:41:59.000000000 +0100
13735 @@ -75,6 +75,7 @@
13736
13737 extern void data_skip(archive_handle_t *archive_handle);
13738 extern void data_extract_all(archive_handle_t *archive_handle);
13739 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13740 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13741 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13742
13743 diff -ruN busybox-1.3.1-orig/include/usage.h busybox-1.3.1-911/include/usage.h
13744 --- busybox-1.3.1-orig/include/usage.h 2006-12-27 05:56:18.000000000 +0100
13745 +++ busybox-1.3.1-911/include/usage.h 2006-12-27 19:41:59.000000000 +0100
13746 @@ -1101,6 +1101,82 @@
13747 "$ ls -la /tmp/busybox*\n" \
13748 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13749
13750 +#define ipkg_trivial_usage \
13751 + "[options]... sub-command [arguments]..."
13752 +#define ipkg_full_usage \
13753 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13754 + "\n" \
13755 + "Sub-commands:\n" \
13756 + "\nPackage Manipulation:\n" \
13757 + "\tupdate Update list of available packages\n" \
13758 + "\tupgrade Upgrade all installed packages to latest version\n" \
13759 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13760 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13761 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13762 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13763 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13764 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13765 + "\n" \
13766 + "Informational Commands:\n" \
13767 + "\tlist List available packages and descriptions\n" \
13768 + "\tlist_installed List all and only the installed packages and description \n" \
13769 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13770 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13771 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13772 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13773 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13774 + "\tcompare_versions <v1> <op> <v2>\n" \
13775 + "\t compare versions using <= < > >= = << >>\n" \
13776 + "\tprint_architecture prints the architecture.\n" \
13777 + "\tprint_installation_architecture\n" \
13778 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13779 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13780 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13781 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13782 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13783 + "\t prints the installation architecture.\n" \
13784 + "\n" \
13785 + "\nOptions:\n" \
13786 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13787 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13788 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13789 + "\t 0 errors only\n" \
13790 + "\t 1 normal messages (default)\n" \
13791 + "\t 2 informative messages\n" \
13792 + "\t 3 debug output\n" \
13793 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13794 + "\t-conf <conf_file> Default configuration file location\n" \
13795 + " is /etc/ipkg.conf\n" \
13796 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13797 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13798 + " <dest_name> should be a defined dest name from\n" \
13799 + " the configuration file, (but can also be a\n" \
13800 + " directory name in a pinch).\n" \
13801 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13802 + "\t-offline <offline_root> offline installation of packages.\n" \
13803 + "\t-verbose_wget more wget messages\n" \
13804 + "\n" \
13805 + "Force Options (use when ipkg is too smart for its own good):\n" \
13806 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13807 + "\t Install/remove package in spite of failed dependences\n" \
13808 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13809 + " (no prompts). Note that this will not prevent\n" \
13810 + " package installation scripts from prompting.\n" \
13811 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13812 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13813 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13814 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13815 + "\t-noaction No action -- test only\n" \
13816 + "\t-nodeps Do not follow dependences\n" \
13817 + "\t-force-removal-of-dependent-packages\n" \
13818 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13819 + "\t-test No action -- test only\n" \
13820 + "\t-t Specify tmp-dir.\n" \
13821 + "\t--tmp-dir Specify tmp-dir.\n" \
13822 + "\n" \
13823 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13824 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13825 +
13826 #define halt_trivial_usage \
13827 "[-d<delay>] [-n<nosync>] [-f<force>]"
13828 #define halt_full_usage \
13829 diff -ruN busybox-1.3.1-orig/Makefile busybox-1.3.1-911/Makefile
13830 --- busybox-1.3.1-orig/Makefile 2006-12-27 05:57:17.000000000 +0100
13831 +++ busybox-1.3.1-911/Makefile 2006-12-28 01:14:49.000000000 +0100
13832 @@ -423,6 +423,7 @@
13833
13834 libs-y := \
13835 archival/ \
13836 + archival/libipkg/ \
13837 archival/libunarchive/ \
13838 console-tools/ \
13839 coreutils/ \
This page took 0.59354 seconds and 5 git commands to generate.