1 # Copyright (C) 2006 OpenWrt.org
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
6 # add ipkg support to busybox
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
12 gzip is used to compress files.
13 It's probably the most widely used UNIX compression program.
21 + ipkg is the itsy package management system.
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;
35 +// moved to data_extract_all.c
37 static void data_extract_all_prefix(archive_handle_t *archive_handle)
39 char *name_ptr = archive_handle->file_header->name;
46 static void unpack_package(deb_file_t *deb_file)
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
53 +/* ipkg.c - the itsy package management system
57 + Copyright (C) 2003 kernel concepts
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.
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.
69 + ipkg command line frontend using libipkg
73 +#include "libipkg/libipkg.h"
75 +int ipkg_main(int argc, char **argv)
77 + return ipkg_op(argc, argv);
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
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
94 +/* args.c - parse command-line args
98 + Copyright 2001 University of Southern California
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)
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.
117 +#include "ipkg_message.h"
120 +#include "sprintf_alloc.h"
125 +static void print_version(void);
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,
139 + ARGS_OPT_VERBOSE_WGET,
140 + ARGS_OPT_VERBOSITY,
141 + ARGS_OPT_MULTIPLE_PROVIDERS
144 +int args_init(args_t *args)
146 + char *conf_file_dir;
148 + memset(args, 0, sizeof(args_t));
150 + args->dest = ARGS_DEFAULT_DEST;
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;
156 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
157 + ARGS_DEFAULT_CONF_FILE_NAME);
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;
180 +void args_deinit(args_t *args)
182 + free(args->conf_file);
183 + args->conf_file = NULL;
186 +int args_parse(args_t *args, int argc, char *argv[])
189 + int option_index = 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'},
234 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
240 + args->query_all = 1;
243 + args->dest = optarg;
246 + free(args->conf_file);
247 + args->conf_file = strdup(optarg);
250 + args->offline_root = optarg;
253 + args->noaction = 1;
256 + args->tmp_dir = strdup(optarg);
262 + case ARGS_OPT_VERBOSITY:
264 + args->verbosity = atoi(optarg);
266 + args->verbosity += 1;
268 + case ARGS_OPT_FORCE_DEFAULTS:
269 + args->force_defaults = 1;
271 + case ARGS_OPT_FORCE_DEPENDS:
272 + args->force_depends = 1;
274 + case ARGS_OPT_FORCE_OVERWRITE:
275 + args->force_overwrite = 1;
277 + case ARGS_OPT_FORCE_DOWNGRADE:
278 + args->force_downgrade = 1;
280 + case ARGS_OPT_FORCE_REINSTALL:
281 + args->force_reinstall = 1;
283 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
284 + args->force_removal_of_essential_packages = 1;
286 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
287 + args->force_removal_of_dependent_packages = 1;
289 + case ARGS_OPT_FORCE_SPACE:
290 + args->force_space = 1;
292 + case ARGS_OPT_VERBOSE_WGET:
293 + args->verbose_wget = 1;
295 + case ARGS_OPT_MULTIPLE_PROVIDERS:
296 + args->multiple_providers = 1;
298 + case ARGS_OPT_NODEPS:
301 + case ARGS_OPT_NOACTION:
302 + args->noaction = 1;
311 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
322 +void args_usage(char *complaint)
325 + bb_error_msg("%s\n", complaint);
332 +static void print_version(void)
334 + bb_error_msg("version %s\n", IPKG_VERSION);
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
340 +/* args.h - parse command-line args
344 + Copyright 2001 University of Southern California
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)
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.
365 + int force_defaults;
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;
375 + int multiple_providers;
379 + int nocheckfordirorfile;
380 + int noreadfeedsfile;
381 + char *offline_root;
382 + char *offline_root_pre_script_cmd;
383 + char *offline_root_post_script_cmd;
385 +typedef struct args args_t;
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
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);
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
416 +/* conffile.c - the itsy package management system
420 + Copyright (C) 2001 University of Southern California
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.
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.
437 +#include "ipkg_message.h"
439 +#include "conffile.h"
440 +#include "file_util.h"
441 +#include "sprintf_alloc.h"
443 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
445 + return nv_pair_init(conffile, file_name, md5sum);
448 +void conffile_deinit(conffile_t *conffile)
450 + nv_pair_deinit(conffile);
453 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
456 + char *filename = conffile->name;
457 + char *root_filename;
460 + if (conffile->value == NULL) {
461 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
465 + root_filename = root_filename_alloc(conf, filename);
467 + md5sum = file_md5sum_alloc(root_filename);
469 + ret = strcmp(md5sum, conffile->value);
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);
475 + free(root_filename);
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
484 +/* conffile.h - the itsy package management system
488 + Copyright (C) 2001 University of Southern California
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.
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.
504 +#include "nv_pair.h"
506 +typedef struct nv_pair conffile_t;
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);
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
518 +/* conffile_list.c - the itsy package management system
522 + Copyright (C) 2001 University of Southern California
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.
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.
537 +#include "conffile_list.h"
539 +int conffile_list_init(conffile_list_t *list)
541 + return nv_pair_list_init(list);
544 +void conffile_list_deinit(conffile_list_t *list)
546 + nv_pair_list_deinit(list);
549 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
550 + const char *md5sum)
552 + return nv_pair_list_append(list, file_name, md5sum);
555 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
557 + return nv_pair_list_push(list, data);
560 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
562 + return nv_pair_list_pop(list);
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
569 +/* conffile_list.h - the itsy package management system
573 + Copyright (C) 2001 University of Southern California
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.
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.
586 +#ifndef CONFFILE_LIST_H
587 +#define CONFFILE_LIST_H
589 +#include "conffile.h"
590 +#include "nv_pair_list.h"
592 +typedef struct nv_pair_list_elt conffile_list_elt_t;
593 +typedef struct nv_pair_list conffile_list_t;
595 +int conffile_list_init(conffile_list_t *list);
596 +void conffile_list_deinit(conffile_list_t *list);
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);
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
609 +/* file_util.c - convenience routines for common stat operations
613 + Copyright (C) 2001 University of Southern California
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.
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.
627 +#include <sys/types.h>
628 +#include <sys/stat.h>
630 +#include "sprintf_alloc.h"
631 +#include "file_util.h"
636 +int file_exists(const char *file_name)
639 + struct stat stat_buf;
641 + err = stat(file_name, &stat_buf);
649 +int file_is_dir(const char *file_name)
652 + struct stat stat_buf;
654 + err = stat(file_name, &stat_buf);
659 + return S_ISDIR(stat_buf.st_mode);
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.
667 + Return value is NULL if the file is at EOF when called.
669 +#define FILE_READ_LINE_BUF_SIZE 1024
670 +char *file_read_line_alloc(FILE *file)
672 + char buf[FILE_READ_LINE_BUF_SIZE];
677 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
678 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
679 + buf_len = strlen(buf);
681 + line_size += buf_len;
682 + line = realloc(line, line_size);
683 + if (line == NULL) {
684 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
689 + line_size = buf_len + 1;
690 + line = strdup(buf);
692 + if (buf[buf_len - 1] == '\n') {
700 +int file_move(const char *src, const char *dest)
704 + err = rename(src, dest);
706 + if (err && errno == EXDEV) {
707 + err = file_copy(src, dest);
710 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
711 + __FUNCTION__, src, dest, strerror(errno));
717 +/* I put these here to keep libbb dependencies from creeping all over
719 +int file_copy(const char *src, const char *dest)
723 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
725 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
726 + __FUNCTION__, src, dest);
732 +int file_mkdir_hier(const char *path, long mode)
734 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
737 +char *file_md5sum_alloc(const char *file_name)
739 + static const int md5sum_bin_len = 16;
740 + static const int md5sum_hex_len = 32;
742 + static const unsigned char bin2hex[16] = {
743 + '0', '1', '2', '3',
744 + '4', '5', '6', '7',
745 + '8', '9', 'a', 'b',
751 + unsigned char *md5sum_hex;
752 + unsigned char md5sum_bin[md5sum_bin_len];
754 + md5sum_hex = malloc(md5sum_hex_len + 1);
755 + if (md5sum_hex == NULL) {
756 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
767 + err = md5_stream(file, md5sum_bin);
769 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
770 + __FUNCTION__, file_name, strerror(err));
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];
781 + md5sum_hex[md5sum_hex_len] = '\0';
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
790 +/* file_util.h - convenience routines for common file operations
794 + Copyright (C) 2001 University of Southern California
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.
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.
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);
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
823 +/* hash.c - hash tables for ipkg
825 + Steven M. Ayer, Jamey Hicks
827 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
844 +#include "hash_table.h"
845 +#include "ipkg_message.h"
848 +static int hash_index(hash_table_t *hash, const char *pkg_name);
849 +static int rotating(const char *key, int len, int prime);
851 +static int hash_index(hash_table_t *hash, const char *pkg_name)
853 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
856 +static int rotating(const char *key, int len, int prime)
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);
866 + * this is an open table keyed by strings
868 +int hash_table_init(const char *name, hash_table_t *hash, int len)
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
876 + if (hash->entries != NULL) {
877 + /* we have been here already */
882 + hash->entries = NULL;
883 + hash->n_entries = 0;
884 + hash->hash_entry_key = NULL;
886 + picker = primes_table;
887 + while(*picker && (*picker++ < len));
889 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
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__);
901 +void hash_table_deinit(hash_table_t *hash)
903 + free(hash->entries);
904 + hash->entries = NULL;
905 + hash->n_entries = 0;
908 +void *hash_table_get(hash_table_t *hash, const char *key)
910 + int ndx= hash_index(hash, key);
911 + hash_entry_t *hash_entry = hash->entries + ndx;
914 + if (hash_entry->key)
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;
921 + hash_entry = hash_entry->next;
926 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
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;
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
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) {
950 + hash_entry = hash_entry->next;
951 + hash_entry->next = NULL;
954 + hash->n_elements++;
955 + hash_entry->key = strdup(key);
956 + hash_entry->data = value;
962 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
968 + for (i = 0; i < hash->n_entries; i++) {
969 + hash_entry_t *hash_entry = (hash->entries + i);
971 + if(hash_entry->key) {
972 + f(hash_entry->key, hash_entry->data, data);
974 + } while((hash_entry = hash_entry->next));
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
982 +/* hash.h - hash tables for ipkg
984 + Steven M. Ayer, Jamey Hicks
986 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
999 +#ifndef _HASH_TABLE_H_
1000 +#define _HASH_TABLE_H_
1002 +typedef struct hash_entry hash_entry_t;
1003 +typedef struct hash_table hash_table_t;
1005 +struct hash_entry {
1008 + struct hash_entry * next;
1011 +struct hash_table {
1013 + hash_entry_t * entries;
1014 + int n_entries; /* number of buckets */
1016 + const char * (*hash_entry_key)(void * data);
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);
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
1030 +/* ipkg_cmd.c - the itsy package management system
1034 + Copyright (C) 2001 University of Southern California
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.
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.
1047 +#include <string.h>
1050 +#include <libgen.h>
1053 +#include <stdlib.h>
1054 +#include <unistd.h>
1055 +#include <signal.h>
1057 +#include <dirent.h>
1059 +#include "ipkg_conf.h"
1060 +#include "ipkg_cmd.h"
1061 +#include "ipkg_message.h"
1063 +#include "pkg_dest.h"
1064 +#include "pkg_parse.h"
1065 +#include "sprintf_alloc.h"
1067 +#include "file_util.h"
1068 +#include "str_util.h"
1070 +#include "unarchive.h"
1072 +#include <fnmatch.h>
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"
1083 +#include "libipkg.h"
1084 +static void *p_userdata = NULL;
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);
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},
1147 +int ipkg_state_changed;
1148 +static void write_status_files_if_changed(ipkg_conf_t *conf)
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);
1156 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1161 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1163 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1168 + for (i=0; i < num_cmds; i++) {
1170 + if (strcmp(name, cmd->name) == 0) {
1179 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1182 + p_userdata = userdata;
1185 + result = (cmd->fun)(conf, argc, argv);
1186 + if ( result == 0 ) {
1187 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1189 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1192 + if ( error_list ) {
1193 + reverse_error_list(&error_list);
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;
1202 + free_error_list(&error_list);
1206 + p_userdata = NULL;
1210 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1212 + return (cmd->fun)(conf, argc, argv);
1216 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1221 + pkg_src_list_elt_t *iter;
1225 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
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);
1235 + err = file_mkdir_hier(lists_dir, 0755);
1237 + ipkg_message(conf, IPKG_ERROR,
1238 + "%s: ERROR: failed to make directory %s: %s\n",
1239 + __FUNCTION__, lists_dir, strerror(errno));
1246 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1247 + char *url, *list_file_name;
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");
1255 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1257 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1260 + char *tmp_file_name;
1263 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1265 + if (mkdtemp (tmp) == NULL) {
1266 + perror ("mkdtemp");
1271 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1272 + err = ipkg_download(conf, url, tmp_file_name);
1274 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1275 + in = fopen (tmp_file_name, "r");
1276 + out = fopen (list_file_name, "w");
1278 + inflate_unzip (in, out);
1285 + unlink (tmp_file_name);
1290 + err = ipkg_download(conf, url, list_file_name);
1294 + ipkg_message(conf, IPKG_NOTICE,
1295 + "Updated list of available packages in %s\n",
1299 + free(list_file_name);
1303 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
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
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;
1323 + pkg_vec_free(available);
1325 + write_status_files_if_changed(conf);
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)
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.
1345 + for (i = 0; i < argc; i ++) {
1346 + char *filename = argv [i];
1347 + //char *tmp = basename (tmp);
1348 + //int tmplen = strlen (tmp);
1350 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1352 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1355 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1357 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1364 +struct ipkg_intercept
1370 +typedef struct ipkg_intercept *ipkg_intercept_t;
1372 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1374 + ipkg_intercept_t ctx;
1378 + ctx = malloc (sizeof (*ctx));
1379 + ctx->oldpath = strdup (getenv ("PATH"));
1381 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1382 + setenv ("PATH", newpath, 1);
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);
1394 + perror (ctx->statedir);
1397 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1401 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1407 + setenv ("PATH", ctx->oldpath, 1);
1408 + free (ctx->oldpath);
1410 + dir = opendir (ctx->statedir);
1412 + struct dirent *de;
1413 + while (de = readdir (dir), de != NULL) {
1416 + if (de->d_name[0] == '.')
1419 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1420 + if (access (path, X_OK) == 0) {
1421 + if (system (path)) {
1423 + perror (de->d_name);
1429 + perror (ctx->statedir);
1431 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1435 + free (ctx->statedir);
1441 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1446 + ipkg_intercept_t ic;
1449 + ipkg_message(conf, IPKG_INFO,
1450 + "Configuring unpacked packages\n");
1453 + all = pkg_vec_alloc();
1454 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1456 + ic = ipkg_prep_intercepts (conf);
1458 + for(i = 0; i < all->len; i++) {
1459 + pkg = all->pkgs[i];
1461 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1464 + if (pkg->state_status == SS_UNPACKED) {
1465 + ipkg_message(conf, IPKG_NOTICE,
1466 + "Configuring %s\n", pkg->name);
1468 + r = ipkg_configure(conf, pkg);
1470 + pkg->state_status = SS_INSTALLED;
1471 + pkg->parent->state_status = SS_INSTALLED;
1472 + pkg->state_flag &= ~SF_PREFER;
1480 + r = ipkg_finalize_intercepts (ic);
1484 + pkg_vec_free(all);
1488 +static void sigint_handler(int sig)
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);
1497 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1503 + global_conf = conf;
1504 + signal(SIGINT, sigint_handler);
1507 + * Now scan through package names and install
1509 + for (i=0; i < argc; i++) {
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)
1517 + pkg_info_preinstall_check(conf);
1519 + for (i=0; i < argc; i++) {
1521 + if (conf->multiple_providers)
1522 + err = ipkg_install_multi_by_name(conf, arg);
1524 + err = ipkg_install_by_name(conf, arg);
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",
1534 + /* recheck to verify that all dependences are satisfied */
1535 + if (0) ipkg_satisfy_all_dependences(conf);
1537 + ipkg_configure_packages(conf, NULL);
1539 + write_status_files_if_changed(conf);
1544 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1550 + global_conf = conf;
1551 + signal(SIGINT, sigint_handler);
1554 + for (i=0; i < argc; i++) {
1555 + char *arg = argv[i];
1557 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1558 + if (err != EINVAL && err != 0)
1561 + pkg_info_preinstall_check(conf);
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,
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);
1576 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1580 + ipkg_upgrade_pkg(conf, pkg);
1582 + ipkg_install_by_name(conf, arg);
1586 + pkg_vec_t *installed = pkg_vec_alloc();
1588 + pkg_info_preinstall_check(conf);
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);
1595 + pkg_vec_free(installed);
1598 + /* recheck to verify that all dependences are satisfied */
1599 + if (0) ipkg_satisfy_all_dependences(conf);
1601 + ipkg_configure_packages(conf, NULL);
1603 + write_status_files_if_changed(conf);
1608 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1614 + pkg_info_preinstall_check(conf);
1615 + for (i = 0; i < argc; i++) {
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",
1627 + err = ipkg_download_pkg(conf, pkg, ".");
1630 + ipkg_message(conf, IPKG_ERROR,
1631 + "Failed to download %s\n", pkg->name);
1633 + ipkg_message(conf, IPKG_NOTICE,
1634 + "Downloaded %s as %s\n",
1635 + pkg->name, pkg->local_filename);
1643 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1646 + pkg_vec_t *available;
1648 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1650 + char *pkg_name = NULL;
1651 + char *version_str;
1654 + pkg_name = argv[0];
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))
1663 + if (pkg->description) {
1664 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1666 + desc_short[0] = '\0';
1668 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1669 + newline = strchr(desc_short, '\n');
1674 + printf("%s - %s\n", pkg->name, desc_short);
1676 + if (ipkg_cb_list) {
1677 + version_str = pkg_version_str_alloc(pkg);
1678 + ipkg_cb_list(pkg->name,desc_short,
1680 + pkg->state_status,
1682 + free(version_str);
1686 + pkg_vec_free(available);
1692 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1695 + pkg_vec_t *available;
1697 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1699 + char *pkg_name = NULL;
1700 + char *version_str;
1703 + pkg_name = argv[0];
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))
1712 + if (pkg->description) {
1713 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1715 + desc_short[0] = '\0';
1717 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1718 + newline = strchr(desc_short, '\n');
1723 + printf("%s - %s\n", pkg->name, desc_short);
1725 + if (ipkg_cb_list) {
1726 + version_str = pkg_version_str_alloc(pkg);
1727 + ipkg_cb_list(pkg->name,desc_short,
1729 + pkg->state_status,
1731 + free(version_str);
1739 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1742 + pkg_vec_t *available;
1744 + char *pkg_name = NULL;
1745 + char **pkg_fields = NULL;
1747 + char *buff ; // = (char *)malloc(1);
1750 + pkg_name = argv[0];
1753 + pkg_fields = &argv[1];
1754 + n_fields = argc - 1;
1757 + available = pkg_vec_alloc();
1758 + if (installed_only)
1759 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
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)) {
1769 + for (j = 0; j < n_fields; j++)
1770 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1772 + pkg_print_info(pkg, stdout);
1776 + buff = pkg_formatted_info(pkg);
1778 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1779 + pkg->state_status,
1783 + We should not forget that actually the pointer is allocated.
1784 + We need to free it :) ( Thanks florian for seeing the error )
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);
1803 + pkg_vec_free(available);
1808 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1810 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1813 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1815 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1818 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1823 + char *pkg_name = NULL;
1825 + pkg_name = argv[0];
1827 + err = ipkg_configure_packages (conf, pkg_name);
1830 + err = ipkg_configure_packages (conf, NULL);
1833 + write_status_files_if_changed(conf);
1838 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1841 + char *globpattern;
1844 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1845 + err = glob(globpattern, 0, NULL, &globbuf);
1846 + free(globpattern);
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]);
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]);
1862 + err = unlink(globbuf.gl_pathv[i]);
1864 + ipkg_message(conf, IPKG_ERROR,
1865 + "%s: ERROR: failed to unlink %s: %s\n",
1866 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1871 + globfree(&globbuf);
1876 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
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);
1886 +// ENH: Add the "no pkg removed" just in case.
1890 + available = pkg_vec_alloc();
1891 + pkg_info_preinstall_check(conf);
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)) {
1902 + if (conf->restrict_to_default_dest) {
1903 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1905 + conf->default_dest);
1907 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1910 + if (pkg == NULL) {
1911 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
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);
1918 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1923 + pkg_vec_free(available);
1925 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1927 + int flagged_pkg_count = 0;
1930 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
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++;
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);
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");
1947 + /* find packages not flagged SF_USER (i.e., installed to
1948 + * satisfy a dependence) and not having any dependents, and
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)) {
1957 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1958 + ipkg_remove_pkg(conf, pkg,0);
1962 + } while (removed);
1963 + pkg_vec_free(installed_pkgs);
1967 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1969 + write_status_files_if_changed(conf);
1973 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1978 + global_conf = conf;
1979 + signal(SIGINT, sigint_handler);
1981 + pkg_info_preinstall_check(conf);
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,
1987 + conf->default_dest);
1989 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1992 + if (pkg == NULL) {
1993 + ipkg_message(conf, IPKG_ERROR,
1994 + "Package %s is not installed.\n", argv[i]);
1997 + ipkg_purge_pkg(conf, pkg);
2000 + write_status_files_if_changed(conf);
2004 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2008 + const char *flags = argv[0];
2010 + global_conf = conf;
2011 + signal(SIGINT, sigint_handler);
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,
2017 + conf->default_dest);
2019 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2022 + if (pkg == NULL) {
2023 + ipkg_message(conf, IPKG_ERROR,
2024 + "Package %s is not installed.\n", argv[i]);
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);
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);
2036 + ipkg_state_changed++;
2037 + ipkg_message(conf, IPKG_NOTICE,
2038 + "Setting flags for package %s to %s\n",
2039 + pkg->name, flags);
2042 + write_status_files_if_changed(conf);
2046 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2049 + str_list_t *installed_files;
2050 + str_list_elt_t *iter;
2051 + char *pkg_version;
2052 + size_t buff_len = 8192;
2056 + buff = (char *)malloc(buff_len);
2057 + if ( buff == NULL ) {
2058 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2066 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2068 + if (pkg == NULL) {
2069 + ipkg_message(conf, IPKG_ERROR,
2070 + "Package %s not installed.\n", argv[0]);
2074 + installed_files = pkg_get_installed_files(pkg);
2075 + pkg_version = pkg_version_str_alloc(pkg);
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) {
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) {
2090 + buff = realloc (buff, buff_len);
2093 + for (iter = installed_files->head; iter; iter = iter->next) {
2094 + used_len += strlen (iter->data) + 1;
2095 + while (buff_len <= used_len) {
2097 + buff = realloc (buff, buff_len);
2099 + strncat(buff, iter->data, buff_len);
2100 + strncat(buff, "\n", buff_len);
2102 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2104 + pkg_version_str_alloc(pkg),
2105 + pkg->state_status,
2111 + free(pkg_version);
2112 + pkg_free_installed_files(pkg);
2117 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2121 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2122 + const char *rel_str = "depends on";
2125 + pkg_info_preinstall_check(conf);
2127 + if (conf->query_all)
2128 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2130 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2131 + for (i = 0; i < argc; i++) {
2132 + const char *target = argv[i];
2135 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
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) {
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];
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;
2163 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2167 + ipkg_message(conf, IPKG_ERROR, "\n");
2173 + pkg_vec_free(available_pkgs);
2178 +enum what_field_type {
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)
2191 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2192 + const char *rel_str = NULL;
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;
2205 + if (conf->query_all)
2206 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2208 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
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);
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);
2226 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2231 + for (j = 0; j < available_pkgs->len; j++) {
2232 + pkg_t *pkg = available_pkgs->pkgs[j];
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) {
2241 + for (k = 0; k < count; k++) {
2242 + compound_depend_t *cdepend =
2243 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
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);
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;
2268 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2271 + if (!pkg_dependence_satisfiable(conf, possibility))
2272 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2274 + ipkg_message(conf, IPKG_NOTICE, "\n");
2275 + goto next_package;
2282 + } while (changed && recursive);
2283 + pkg_vec_free(available_pkgs);
2289 +int pkg_mark_provides(pkg_t *pkg)
2291 + int provides_count = pkg->provides_count;
2292 + abstract_pkg_t **provides = pkg->provides;
2294 + pkg->parent->state_flag |= SF_MARKED;
2295 + for (i = 0; i < provides_count; i++) {
2296 + provides[i]->state_flag |= SF_MARKED;
2301 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2303 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2305 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2307 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2310 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2312 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2315 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2317 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2320 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2322 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2325 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2329 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2330 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2333 + pkg_info_preinstall_check(conf);
2335 + if (conf->query_all)
2336 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2338 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2339 + for (i = 0; i < argc; i++) {
2340 + const char *target = argv[i];
2343 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2345 + for (j = 0; j < available_pkgs->len; j++) {
2346 + pkg_t *pkg = available_pkgs->pkgs[j];
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");
2363 + pkg_vec_free(available_pkgs);
2368 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2370 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2373 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2375 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2378 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2382 + pkg_vec_t *installed;
2384 + str_list_t *installed_files;
2385 + str_list_elt_t *iter;
2386 + char *installed_file;
2392 + installed = pkg_vec_alloc();
2393 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2395 + for (i=0; i < installed->len; i++) {
2396 + pkg = installed->pkgs[i];
2398 + installed_files = pkg_get_installed_files(pkg);
2400 + for (iter = installed_files->head; iter; iter = iter->next) {
2401 + installed_file = iter->data;
2402 + if (fnmatch(argv[0], installed_file, 0)==0) {
2404 + printf("%s: %s\n", pkg->name, installed_file);
2406 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2408 + pkg_version_str_alloc(pkg),
2409 + pkg->state_status, p_userdata);
2414 + pkg_free_installed_files(pkg);
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);
2425 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
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]);
2434 + ipkg_message(conf, IPKG_ERROR,
2435 + "ipkg compare_versions <v1> <op> <v2>\n"
2436 + "<op> is one of <= >= << >> =\n");
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)
2447 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2449 + nv_pair_list_elt_t *l;
2451 + l = conf->arch_list.head;
2453 + nv_pair_t *nv = l->data;
2454 + printf("arch %s %s\n", nv->name, nv->value);
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
2465 +/* ipkg_cmd.h - the itsy package management system
2469 + Copyright (C) 2001 University of Southern California
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.
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.
2485 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2490 + int requires_args;
2491 + ipkg_cmd_fun_t fun;
2493 +typedef struct ipkg_cmd ipkg_cmd_t;
2495 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2497 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2498 + const char **argv, void *userdata);
2500 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
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);
2508 +int pkg_mark_provides(pkg_t *pkg);
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
2515 +/* ipkg_conf.c - the itsy package management system
2519 + Copyright (C) 2001 University of Southern California
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.
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.
2535 +#include "ipkg_conf.h"
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"
2546 +ipkg_conf_t *global_conf;
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);
2562 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
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 },
2589 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2590 + if ( options == NULL ){
2591 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2595 + memcpy(*options, tmp, sizeof(tmp));
2599 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2605 + *conf_str = strdup(arg_str);
2609 +static void ipkg_conf_free_string(char **conf_str)
2617 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2620 + char *tmp_dir_base;
2621 + nv_pair_list_t tmp_dest_nv_pair_list;
2622 + char * lists_dir =NULL;
2624 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2625 + char *pending_dir =NULL;
2627 + memset(conf, 0, sizeof(ipkg_conf_t));
2629 + pkg_src_list_init(&conf->pkg_src_list);
2631 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2632 + pkg_dest_list_init(&conf->pkg_dest_list);
2634 + nv_pair_list_init(&conf->arch_list);
2636 + conf->restrict_to_default_dest = 0;
2637 + conf->default_dest = NULL;
2640 + if (args->tmp_dir)
2641 + tmp_dir_base = args->tmp_dir;
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));
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;
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;
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;
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);
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 */
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);
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);
2707 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2708 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2710 + conf->lists_dir = strdup(lists_dir);
2711 + conf->pending_dir = strdup(pending_dir);
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);
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 */
2728 + globfree(&globbuf);
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");
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);
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;
2754 + if (args->force_defaults) {
2755 + conf->force_defaults = 1;
2757 + if (args->force_overwrite) {
2758 + conf->force_overwrite = 1;
2760 + if (args->force_downgrade) {
2761 + conf->force_downgrade = 1;
2763 + if (args->force_reinstall) {
2764 + conf->force_reinstall = 1;
2766 + if (args->force_removal_of_dependent_packages) {
2767 + conf->force_removal_of_dependent_packages = 1;
2769 + if (args->force_removal_of_essential_packages) {
2770 + conf->force_removal_of_essential_packages = 1;
2772 + if (args->nodeps) {
2775 + if (args->noaction) {
2776 + conf->noaction = 1;
2778 + if (args->query_all) {
2779 + conf->query_all = 1;
2781 + if (args->verbose_wget) {
2782 + conf->verbose_wget = 1;
2784 + if (args->multiple_providers) {
2785 + conf->multiple_providers = 1;
2787 + if (args->verbosity != conf->verbosity) {
2788 + conf->verbosity = args->verbosity;
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);
2798 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2799 + read anything from there.
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);
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
2809 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2812 + err = ipkg_conf_set_default_dest(conf, args->dest);
2818 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2820 + free(pending_dir);
2825 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2827 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2829 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2830 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2831 + __FUNCTION__, conf->tmp_dir);
2835 + err = rmdir(conf->tmp_dir);
2837 + if (errno == ENOTEMPTY) {
2839 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2840 + err = xsystem(cmd);
2844 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2846 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2848 + free(conf->tmp_dir); /*XXX*/
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);
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);
2864 + if (conf->verbosity > 1) {
2866 + hash_table_t *hashes[] = {
2869 + &conf->obs_file_hash };
2870 + for (i = 0; i < 3; i++) {
2871 + hash_table_t *hash = hashes[i];
2873 + int n_conflicts = 0;
2875 + for (j = 0; j < hash->n_entries; j++) {
2877 + hash_entry_t *e = &hash->entries[j];
2880 + while (e && e->key) {
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);
2894 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2895 + const char *default_dest_name)
2897 + pkg_dest_list_elt_t *iter;
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;
2909 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2914 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2916 + pkg_src_list_elt_t *iter;
2920 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2922 + if (src == NULL) {
2926 + sprintf_alloc(&list_file, "%s/%s",
2927 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2930 + if (file_exists(list_file)) {
2931 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2939 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2941 + nv_pair_list_elt_t *iter;
2942 + nv_pair_t *nv_pair;
2946 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2947 + nv_pair = iter->data;
2949 + if (conf->offline_root) {
2950 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2952 + root_dir = strdup(nv_pair->value);
2954 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2956 + if (dest == NULL) {
2959 + if (conf->default_dest == NULL) {
2960 + conf->default_dest = dest;
2962 + if (file_exists(dest->status_file_name)) {
2963 + pkg_hash_add_from_file(conf, dest->status_file_name,
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,
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];
2982 + if (ipkg_init_options_array(conf, &options)<0)
2985 + if (file == NULL) {
2986 + fprintf(stderr, "%s: failed to open %s: %s\n",
2987 + __FUNCTION__, filename, strerror(errno));
2991 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2993 + xregcomp(&comment_re,
2994 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2996 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3001 + char *type, *name, *value, *extra;
3003 + line = file_read_line_alloc(file);
3005 + if (line == NULL) {
3011 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3015 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3017 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3018 + filename, line_num, line);
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);
3027 + type = strndup(line + regmatch[3].rm_so,
3028 + regmatch[3].rm_eo - regmatch[3].rm_so);
3030 + if (regmatch[5].rm_so > 0) {
3031 + name = strndup(line + regmatch[5].rm_so,
3032 + regmatch[5].rm_eo - regmatch[5].rm_so);
3034 + name = strndup(line + regmatch[6].rm_so,
3035 + regmatch[6].rm_eo - regmatch[6].rm_so);
3037 + if (regmatch[8].rm_so > 0) {
3038 + value = strndup(line + regmatch[8].rm_so,
3039 + regmatch[8].rm_eo - regmatch[8].rm_so);
3041 + value = strndup(line + regmatch[9].rm_so,
3042 + regmatch[9].rm_eo - regmatch[9].rm_so);
3045 + if (regmatch[11].rm_so > 0) {
3046 + extra = strndup (line + regmatch[11].rm_so,
3047 + regmatch[11].rm_eo - regmatch[11].rm_so);
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);
3062 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
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);
3069 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
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");
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);
3085 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3086 + value = strdup("10");
3088 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3090 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3091 + "parameter: %s %s %s\n", type, name, value);
3107 + regfree(&comment_re);
3108 + regfree(&valid_line_re);
3114 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3115 + const char *name, const char *value)
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;
3124 + case IPKG_OPT_TYPE_INT:
3126 + *((int *)options[i].value) = atoi(value);
3129 + printf("%s: Option %s need an argument\n",
3130 + __FUNCTION__, name);
3133 + case IPKG_OPT_TYPE_STRING:
3135 + *((char **)options[i].value) = strdup(value);
3138 + printf("%s: Option %s need an argument\n",
3139 + __FUNCTION__, name);
3147 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3148 + __FUNCTION__, name, value);
3152 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3154 + pkg_dest_list_elt_t *iter;
3161 + if (conf->noaction)
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));
3172 + all = pkg_vec_alloc();
3173 + pkg_hash_fetch_available(&conf->pkg_hash, all);
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)) {
3185 + fprintf(stderr, "Null package\n");
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);
3193 + if (pkg->dest->status_file) {
3194 + pkg_print_status(pkg, pkg->dest->status_file);
3198 + pkg_vec_free(all);
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;
3207 + file_move(dest->status_file_tmp_name, dest->status_file_name);
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);
3220 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3222 + char *root_filename;
3223 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3224 + return root_filename;
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
3230 +/* ipkg_conf.h - the itsy package management system
3234 + Copyright (C) 2001 University of Southern California
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.
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.
3247 +#ifndef IPKG_CONF_H
3248 +#define IPKG_CONF_H
3250 +typedef struct ipkg_conf ipkg_conf_t;
3252 +#include "hash_table.h"
3256 +#include "pkg_hash.h"
3257 +#include "pkg_src_list.h"
3258 +#include "pkg_dest_list.h"
3259 +#include "nv_pair_list.h"
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"
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 "/"
3270 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3274 + pkg_src_list_t pkg_src_list;
3275 + pkg_dest_list_t pkg_dest_list;
3276 + nv_pair_list_t arch_list;
3278 + int restrict_to_default_dest;
3279 + pkg_dest_t *default_dest;
3282 + const char *lists_dir;
3283 + const char *pending_dir;
3286 + int force_depends;
3287 + int force_defaults;
3288 + int force_overwrite;
3289 + int force_downgrade;
3290 + int force_reinstall;
3292 + int force_removal_of_dependent_packages;
3293 + int force_removal_of_essential_packages;
3294 + int nodeps; /* do not follow dependences */
3296 + int multiple_providers;
3297 + char *offline_root;
3298 + char *offline_root_pre_script_cmd;
3299 + char *offline_root_post_script_cmd;
3304 + /* proxy options */
3309 + char *proxy_passwd;
3311 + hash_table_t pkg_hash;
3312 + hash_table_t file_hash;
3313 + hash_table_t obs_file_hash;
3316 +enum ipkg_option_type {
3317 + IPKG_OPT_TYPE_BOOL,
3318 + IPKG_OPT_TYPE_INT,
3319 + IPKG_OPT_TYPE_STRING
3321 +typedef enum ipkg_option_type ipkg_option_type_t;
3323 +typedef struct ipkg_option ipkg_option_t;
3324 +struct ipkg_option {
3326 + const ipkg_option_type_t type;
3327 + const void *value;
3330 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3331 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3333 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3334 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
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
3341 +/* ipkg_configure.c - the itsy package management system
3345 + Copyright (C) 2001 University of Southern California
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.
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.
3360 +#include "ipkg_configure.h"
3362 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
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");
3373 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3377 + ipkg_state_changed++;
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
3385 +/* ipkg_configure.h - the itsy package management system
3389 + Copyright (C) 2001 University of Southern California
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.
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.
3402 +#ifndef IPKG_CONFIGURE_H
3403 +#define IPKG_CONFIGURE_H
3405 +#include "ipkg_conf.h"
3407 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
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
3414 +/* ipkg_download.c - the itsy package management system
3418 + Copyright (C) 2001 University of Southern California
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.
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.
3432 +#include "ipkg_download.h"
3433 +#include "ipkg_message.h"
3435 +#include "sprintf_alloc.h"
3436 +#include "xsystem.h"
3437 +#include "file_util.h"
3438 +#include "str_util.h"
3440 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3444 + char *src_basec = strdup(src);
3445 + char *src_base = basename(src_basec);
3446 + char *tmp_file_location;
3449 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3453 + if (str_starts_with(src, "file:")) {
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");
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);
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);
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);
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);
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",
3494 + err = xsystem(cmd);
3497 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3498 + __FUNCTION__, err, cmd);
3500 + unlink(tmp_file_location);
3501 + free(tmp_file_location);
3508 + err = file_move(tmp_file_location, dest_file_name);
3510 + free(tmp_file_location);
3520 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
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);
3531 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
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);
3539 + err = ipkg_download(conf, url, pkg->local_filename);
3546 + * Downloads file from url, installs in package database, return package name.
3548 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3556 + if (str_starts_with(url, "http://")
3557 + || str_starts_with(url, "ftp://")) {
3559 + char *file_basec = strdup(url);
3560 + char *file_base = basename(file_basec);
3562 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3563 + err = ipkg_download(conf, url, tmp_file);
3567 + err = pkg_init_from_file(pkg, tmp_file);
3570 + pkg->local_filename = strdup(tmp_file);
3575 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3576 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3578 + err = pkg_init_from_file(pkg, url);
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;
3591 + if (!pkg->architecture) {
3592 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
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__);
3605 + *namep = strdup(pkg->name);
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
3613 +/* ipkg_download.h - the itsy package management system
3617 + Copyright (C) 2001 University of Southern California
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.
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.
3630 +#ifndef IPKG_DOWNLOAD_H
3631 +#define IPKG_DOWNLOAD_H
3633 +#include "ipkg_conf.h"
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);
3638 + * Downloads file from url, installs in package database, return package name.
3640 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
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
3647 +/* ipkg.h - the itsy package management system
3651 + Copyright (C) 2001 University of Southern California
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.
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.
3668 +#ifdef HAVE_CONFIG_H
3669 +#include "config.h"
3674 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3677 +#include "ipkg_includes.h"
3678 +#include "ipkg_conf.h"
3679 +#include "ipkg_message.h"
3681 +#define IPKG_PKG_EXTENSION ".ipk"
3682 +#define DPKG_PKG_EXTENSION ".deb"
3684 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3685 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
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"
3692 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3694 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3696 +#define IPKG_VERSION "0.99.162"
3701 + IPKG_PKG_DEPS_UNSATISFIED,
3702 + IPKG_PKG_IS_ESSENTIAL,
3703 + IPKG_PKG_HAS_DEPENDENTS,
3704 + IPKG_PKG_HAS_NO_CANDIDATE
3706 +typedef enum ipkg_error ipkg_error_t;
3708 +extern int ipkg_state_changed;
3713 + struct errlist * next;
3716 +extern struct errlist* error_list;
3718 +extern ipkg_conf_t *global_conf;
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
3725 +#ifndef IPKG_INCLUDES_H
3726 +#define IPKG_INCLUDES_H
3728 +/* Define to 1 if you have the <memory.h> header file. */
3729 +#define HAVE_MEMORY_H 1
3731 +/* Define to 1 if you have the <regex.h> header file. */
3732 +#define HAVE_REGEX_H 1
3734 +/* Define to 1 if you have the <stdlib.h> header file. */
3735 +#define HAVE_STDLIB_H 1
3737 +/* Define to 1 if you have the <strings.h> header file. */
3738 +#define HAVE_STRINGS_H 1
3740 +/* Define to 1 if you have the <string.h> header file. */
3741 +#define HAVE_STRING_H 1
3743 +/* Define to 1 if you have the <sys/stat.h> header file. */
3744 +#define HAVE_SYS_STAT_H 1
3746 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3747 +#define HAVE_SYS_WAIT_H 1
3749 +/* Define to 1 if you have the <unistd.h> header file. */
3750 +#define HAVE_UNISTD_H 1
3752 +/* Define to 1 if you have the ANSI C header files. */
3753 +#define STDC_HEADERS 1
3759 +# include <stdlib.h>
3760 +# include <stdarg.h>
3761 +# include <stddef.h>
3762 +# include <ctype.h>
3763 +# include <errno.h>
3766 +# include <stdlib.h>
3771 +# include <regex.h>
3775 +# if !STDC_HEADERS && HAVE_MEMORY_H
3776 +# include <memory.h>
3778 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3780 +# define __USE_GNU 1
3782 +# include <string.h>
3787 +# include <strings.h>
3790 +#if HAVE_SYS_STAT_H
3791 +# include <sys/stat.h>
3794 +#if HAVE_SYS_WAIT_H
3795 +# include <sys/wait.h>
3799 +# include <sys/types.h>
3800 +# include <unistd.h>
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
3808 +/* ipkg_install.c - the itsy package management system
3812 + Copyright (C) 2001 University of Southern California
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.
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.
3827 +#include <dirent.h>
3830 +#include <signal.h>
3831 +typedef void (*sighandler_t)(int);
3834 +#include "pkg_hash.h"
3835 +#include "pkg_extract.h"
3837 +#include "ipkg_install.h"
3838 +#include "ipkg_configure.h"
3839 +#include "ipkg_download.h"
3840 +#include "ipkg_remove.h"
3842 +#include "ipkg_utils.h"
3843 +#include "ipkg_message.h"
3845 +#include "sprintf_alloc.h"
3846 +#include "file_util.h"
3847 +#include "str_util.h"
3848 +#include "xsystem.h"
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);
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);
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);
3875 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3877 +static int user_prefers_old_conffile(const char *file, const char *backup);
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);
3885 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3889 + char *old_version, *new_version;
3892 + if (pkg == NULL) {
3896 + err = pkg_init_from_file(pkg, filename);
3901 + if (!pkg->architecture) {
3902 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
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
3909 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3910 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3912 + pkg->local_filename = strdup(filename);
3915 + old_version = pkg_version_str_alloc(old);
3916 + new_version = pkg_version_str_alloc(pkg);
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 */
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);
3934 + free(old_version);
3935 + free(new_version);
3939 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3940 + return ipkg_install_pkg(conf, pkg,0);
3943 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3947 + char *old_version, *new_version;
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);
3952 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
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);
3957 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
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.
3964 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3967 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3969 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3970 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3972 + if (new == NULL) {
3973 + return IPKG_PKG_HAS_NO_CANDIDATE;
3976 + new->state_flag |= SF_USER;
3978 + old_version = pkg_version_str_alloc(old);
3979 + new_version = pkg_version_str_alloc(new);
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 */
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);
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);
4008 + } else if (cmp < 0) {
4009 + new->dest = old->dest;
4010 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
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. */
4020 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4021 + return ipkg_install_pkg(conf, new,0);
4024 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4026 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4029 + abstract_pkg_t *ppkg ;
4031 + if (providers == NULL)
4032 + return IPKG_PKG_HAS_NO_CANDIDATE;
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);
4040 +/* XXX Maybe ppkg should be freed ? */
4046 + * Walk dependence graph starting with pkg, collect packages to be
4047 + * installed into pkgs_needed, in dependence order.
4049 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4052 + pkg_vec_t *depends = pkg_vec_alloc();
4053 + char **unresolved = NULL;
4056 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
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);
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;
4079 + if (ndepends <= 0) {
4080 + pkg_vec_free(depends);
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)) {
4093 + /* Mark packages as to-be-installed */
4094 + dep->state_want = SW_INSTALL;
4096 + /* Dependencies should be installed the same place as pkg */
4097 + if (dep->dest == NULL) {
4098 + dep->dest = pkg->dest;
4101 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4103 + pkg_vec_free(depends);
4109 + pkg_vec_insert(pkgs_needed, pkg);
4111 + pkg_vec_free(depends);
4116 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4120 + char *old_version, *new_version;
4122 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4124 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4125 + if (new == NULL) {
4126 + return IPKG_PKG_HAS_NO_CANDIDATE;
4129 + old_version = pkg_version_str_alloc(old);
4130 + new_version = pkg_version_str_alloc(new);
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 */
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);
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);
4159 + } else if (cmp < 0) {
4160 + new->dest = old->dest;
4161 + old->state_want = SW_DEINSTALL;
4162 + old->state_flag |= SF_OBSOLETE;
4165 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4170 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4173 + pkg_vec_t *depends = pkg_vec_alloc();
4175 + char **unresolved = NULL;
4178 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
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);
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;
4201 + if (ndepends <= 0) {
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;
4211 + depends->pkgs[i]->state_want = SW_INSTALL;
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);
4224 + pkg_vec_free(depends);
4230 + pkg_vec_free(depends);
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)
4239 + if (conf->nodeps == 0) {
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);
4247 + pkg_vec_free(installed);
4254 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4257 + pkg_vec_t *conflicts = NULL;
4259 + const char *prefix;
4260 + if (conf->force_depends) {
4261 + level = IPKG_NOTICE;
4262 + prefix = "Warning";
4264 + level = IPKG_ERROR;
4268 + if (!conf->force_depends)
4269 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4272 + ipkg_message(conf, level,
4273 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
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;
4284 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4286 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4287 + str_list_elt_t *iter;
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);
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);
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) {
4304 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4311 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4313 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4315 + /* sma 6.20.02: yup; here's the first bit */
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
4323 + int comp_size, blocks_available;
4325 + if (!conf->force_space && pkg->installed_size != NULL) {
4326 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
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);
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);
4342 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4345 + char *conffiles_file_name;
4347 + FILE *conffiles_file;
4349 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
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));
4359 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
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. */
4369 + /* Don't need to re-read conffiles if we already have it */
4370 + if (pkg->conffiles.head) {
4374 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4375 + if (! file_exists(conffiles_file_name)) {
4376 + free(conffiles_file_name);
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);
4387 + free(conffiles_file_name);
4391 + char *cf_name_in_dest;
4393 + cf_name = file_read_line_alloc(conffiles_file);
4394 + if (cf_name == NULL) {
4397 + str_chomp(cf_name);
4398 + if (cf_name[0] == '\0') {
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);
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);
4416 + free(cf_name_in_dest);
4419 + fclose(conffiles_file);
4424 +/* returns number of installed replacees */
4425 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4427 + abstract_pkg_t **replaces = pkg->replaces;
4428 + int replaces_count = pkg->replaces_count;
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;
4434 + for (j = 0; j < pkg_vec->len; j++) {
4435 + pkg_t *replacee = pkg_vec->pkgs[j];
4436 + if (!pkg_conflicts(pkg, replacee))
4438 + if (replacee->state_status == SS_INSTALLED) {
4439 + pkg_vec_insert(installed_replacees, replacee);
4444 + return installed_replacees->len;
4447 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4450 + int replaces_count = replacees->len;
4451 + for (i = 0; i < replaces_count; i++) {
4452 + pkg_t *replacee = replacees->pkgs[i];
4454 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4455 + err = ipkg_remove_pkg(conf, replacee,0);
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)
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);
4479 +int caught_sigint = 0;
4480 +static void ipkg_install_pkg_sigint_handler(int sig)
4482 + caught_sigint = sig;
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)
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);
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 */
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);
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;
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;
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);
4528 + free(old_version);
4529 + free(new_version);
4532 + char message_out[15], *version ;
4533 + memset(message_out,'\x0',15);
4535 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4537 + strncpy( message_out,"Installing ",strlen("Installing ") );
4538 + version = pkg_version_str_alloc(pkg);
4540 + ipkg_message(conf, IPKG_NOTICE,
4541 + "%s%s (%s) to %s...\n", message_out,
4542 + pkg->name, version, pkg->dest->name);
4548 +/* and now the meat... */
4549 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4553 + pkg_t *old_pkg = NULL;
4554 + pkg_vec_t *replacees;
4555 + abstract_pkg_t *ab_pkg = NULL;
4556 + int old_state_flag;
4560 + if ( from_upgrade )
4561 + message = 1; /* Coming from an upgrade, and should change the output message */
4564 + ipkg_message(conf, IPKG_ERROR,
4565 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4569 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
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);
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; }
4580 + ipkg_message(conf, IPKG_NOTICE,
4581 + "Package %s is already installed in %s.\n",
4582 + pkg->name, pkg->dest->name);
4586 + if (pkg->dest == NULL) {
4587 + pkg->dest = conf->default_dest;
4590 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4592 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4593 + if (err) { return err; }
4595 + pkg->state_want = SW_INSTALL;
4597 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4601 + /* Abhaya: conflicts check */
4602 + err = check_conflicts_for(conf, pkg);
4603 + if (err) { return err; }
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;
4612 + err = verify_pkg_installable(conf, pkg);
4613 + if (err) { return err; }
4615 + if (pkg->local_filename == NULL) {
4616 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4618 + ipkg_message(conf, IPKG_ERROR,
4619 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4625 +/* Check for md5 values */
4628 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4629 + if (strcmp(file_md5, pkg->md5sum))
4631 + ipkg_message(conf, IPKG_ERROR,
4632 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4640 + if (pkg->tmp_unpack_dir == NULL) {
4641 + unpack_pkg_control_files(conf, pkg);
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; }
4650 + if (conf->nodeps == 0) {
4651 + err = satisfy_dependencies_for(conf, pkg);
4652 + if (err) { return err; }
4655 + replacees = pkg_vec_alloc();
4656 + pkg_get_installed_replacees(conf, pkg, replacees);
4658 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4660 + sigset_t newset, oldset;
4661 + sighandler_t old_handler = NULL;
4662 + int use_signal = 0;
4663 + caught_sigint = 0;
4665 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4667 + sigemptyset(&newset);
4668 + sigaddset(&newset, SIGINT);
4669 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4672 + ipkg_state_changed++;
4673 + pkg->state_flag |= SF_FILELIST_CHANGED;
4675 + /* XXX: BUG: we really should treat replacement more like an upgrade
4676 + * Instead, we're going to remove the replacees
4678 + err = pkg_remove_installed_replacees(conf, replacees);
4679 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4681 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4682 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4684 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4685 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4687 + err = preinst_configure(conf, pkg, old_pkg);
4688 + if (err) goto UNWIND_PREINST_CONFIGURE;
4690 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4691 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4693 + err = check_data_file_clashes(conf, pkg, old_pkg);
4694 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4696 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4697 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4699 + if (conf->noaction) return 0;
4701 + /* point of no return: no unwinding after this */
4702 + if (old_pkg && !conf->force_reinstall) {
4703 + old_pkg->state_want = SW_DEINSTALL;
4705 + if (old_pkg->state_flag & SF_NOPRUNE) {
4706 + ipkg_message(conf, IPKG_INFO,
4707 + " not removing obsolesced files because package marked noprune\n");
4709 + ipkg_message(conf, IPKG_INFO,
4710 + " removing obsolesced files\n");
4711 + remove_obsolesced_files(conf, pkg, old_pkg);
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);
4723 + ipkg_message(conf, IPKG_INFO,
4724 + " installing maintainer scripts\n");
4725 + install_maintainer_scripts(conf, pkg, old_pkg);
4727 + /* the following just returns 0 */
4728 + remove_disappeared(conf, pkg);
4730 + ipkg_message(conf, IPKG_INFO,
4731 + " installing data files\n");
4732 + install_data_files(conf, pkg);
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);
4737 + ipkg_message(conf, IPKG_INFO,
4738 + " resolving conf files\n");
4739 + resolve_conffiles(conf, pkg);
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);
4746 + if (old_pkg && !conf->force_reinstall) {
4747 + old_pkg->state_status = SS_NOT_INSTALLED;
4750 + time(&pkg->installed_time);
4752 + ipkg_message(conf, IPKG_INFO,
4753 + " cleanup temp files\n");
4754 + cleanup_temporary_files(conf, pkg);
4756 + ab_pkg = pkg->parent;
4758 + ab_pkg->state_status = pkg->state_status;
4760 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4763 + signal(SIGINT, old_handler);
4765 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
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);
4785 + ipkg_message(conf, IPKG_INFO,
4786 + " cleanup temp files\n");
4787 + cleanup_temporary_files(conf, pkg);
4789 + ipkg_message(conf, IPKG_INFO,
4792 + signal(SIGINT, old_handler);
4794 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4800 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4802 + /* DPKG_INCOMPATIBILITY:
4803 + dpkg does some things here that we don't do yet. Do we care?
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
4815 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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)
4824 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
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
4835 + deconfigured's-postinst abort-deconfigure \
4836 + in-favour package-being-installed-but-failed version \
4837 + removing conflicting-package version
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
4845 + conflictor's-postinst abort-remove in-favour package new-version
4850 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4852 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4853 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4858 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4861 + char *preinst_args;
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);
4872 + preinst_args = strdup("install");
4875 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4877 + ipkg_message(conf, IPKG_ERROR,
4878 + "Aborting installation of %s\n", pkg->name);
4882 + free(preinst_args);
4887 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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
4898 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4901 + conffile_list_elt_t *iter;
4904 + if (conf->noaction) return 0;
4906 + /* Backup all modified conffiles */
4908 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4912 + cf_name = root_filename_alloc(conf, cf->name);
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);
4925 + /* Backup all conffiles that were not conffiles in old_pkg */
4926 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
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)) {
4935 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4936 + err = backup_make_backup(conf, cf_name);
4947 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4949 + conffile_list_elt_t *iter;
4952 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4953 + backup_remove(iter->data->name);
4957 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4958 + backup_remove(iter->data->name);
4965 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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.
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
4980 + str_list_t *files_list;
4981 + str_list_elt_t *iter;
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))) {
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)) {
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);
5006 + owner = file_hash_get_file_owner(conf, filename);
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) {
5015 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5017 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5018 + if (pkg_replaces(pkg, owner)) {
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);
5029 + /* Pre-existing files are OK if they are obsolete */
5030 + obs = hash_table_get(&conf->obs_file_hash, filename);
5032 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
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);
5042 + ipkg_message(conf, IPKG_ERROR,
5043 + "%s\n", owner->name);
5045 + ipkg_message(conf, IPKG_ERROR,
5046 + "<no package>\nPlease move this file out of the way and try again.\n");
5050 + free(root_filename);
5052 + pkg_free_installed_files(pkg);
5057 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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
5064 + Only the action that are needed to change name should be considered.
5065 + @@@ To change after 1.0 release.
5067 + str_list_t *files_list;
5068 + str_list_elt_t *iter;
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))) {
5080 + if (conf->force_overwrite) {
5081 + /* but we need to change who owns this file */
5082 + file_hash_set_file_owner(conf, filename, pkg);
5086 + owner = file_hash_get_file_owner(conf, filename);
5088 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
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);
5100 + free(root_filename);
5102 + pkg_free_installed_files(pkg);
5107 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5109 + /* Nothing to do since check_data_file_clashes doesn't change state */
5113 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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 */
5125 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
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)
5134 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5137 + str_list_t *old_files;
5138 + str_list_elt_t *of;
5139 + str_list_t *new_files;
5140 + str_list_elt_t *nf;
5142 + if (old_pkg == NULL) {
5146 + old_files = pkg_get_installed_files(old_pkg);
5147 + new_files = pkg_get_installed_files(pkg);
5149 + for (of = old_files->head; of; of = of->next) {
5153 + for (nf = new_files->head; nf; nf = nf->next) {
5155 + if (strcmp(old, new) == 0) {
5156 + goto NOT_OBSOLETE;
5159 + if (file_is_dir(old)) {
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 */
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);
5174 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5183 + pkg_free_installed_files(old_pkg);
5184 + pkg_free_installed_files(pkg);
5189 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5193 + char *globpattern;
5197 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5200 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5201 + err = glob(globpattern, 0, NULL, &globbuf);
5202 + free(globpattern);
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]);
5213 + globfree(&globbuf);
5218 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *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,
5233 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5235 + /* DPKG_INCOMPATIBILITY:
5236 + This is a fairly sophisticated dpkg operation. Shall we
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.
5253 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
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. */
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);
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) ;
5283 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5284 + err = pkg_write_filelist(conf, pkg);
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. */
5302 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5304 + conffile_list_elt_t *iter;
5311 + if (conf->noaction) return 0;
5313 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5314 + char *root_filename;
5316 + root_filename = root_filename_alloc(conf, cf->name);
5318 + /* Might need to initialize the md5sum for each conffile */
5319 + if (cf->value == NULL) {
5320 + cf->value = file_md5sum_alloc(root_filename);
5323 + if (!file_exists(root_filename)) {
5324 + free(root_filename);
5328 + cf_backup = backup_filename_alloc(root_filename);
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);
5340 + unlink(cf_backup);
5345 + free(root_filename);
5351 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5354 + const char *short_file_name;
5356 + short_file_name = strrchr(file_name, '/');
5357 + if (short_file_name) {
5358 + short_file_name++;
5360 + short_file_name = file_name;
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) {
5380 + if (strcmp(response, "d") == 0) {
5384 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5385 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5388 + printf(" [Press ENTER to continue]\n");
5389 + response = file_read_line_alloc(stdin);
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)
5406 + struct dirent *dirent;
5409 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
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);
5417 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5418 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5421 + dirent = readdir(tmp_dir);
5422 + if (dirent == NULL) {
5425 + sprintf_alloc(&tmp_file, "%s/%s",
5426 + pkg->tmp_unpack_dir, dirent->d_name);
5427 + if (! file_is_dir(tmp_file)) {
5432 + closedir(tmp_dir);
5433 + rmdir(pkg->tmp_unpack_dir);
5434 + free(pkg->tmp_unpack_dir);
5435 + pkg->tmp_unpack_dir = NULL;
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;
5450 +static char *backup_filename_alloc(const char *file_name)
5454 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5459 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5464 + backup = backup_filename_alloc(file_name);
5465 + err = file_copy(file_name, backup);
5467 + ipkg_message(conf, IPKG_ERROR,
5468 + "%s: Failed to copy %s to %s\n",
5469 + __FUNCTION__, file_name, backup);
5477 +static int backup_exists_for(const char *file_name)
5482 + backup = backup_filename_alloc(file_name);
5484 + ret = file_exists(backup);
5491 +static int backup_remove(const char *file_name)
5495 + backup = backup_filename_alloc(file_name);
5504 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5506 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
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;
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)
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;
5526 + pkg->state_want = SW_INSTALL;
5528 + /* Abhaya: conflicts check */
5529 + err = check_conflicts_for(conf, pkg);
5530 + if (err) { return err; }
5535 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
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];
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);
5546 + /* XXX: BUG: we really should treat replacement more like an upgrade
5547 + * Instead, we're going to remove the replacees
5549 + err = pkg_remove_installed_replacees(conf, replacees);
5550 + if (err) return err;
5551 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5556 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
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);
5565 + ipkg_message(conf, IPKG_ERROR,
5566 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5571 + if (pkg->tmp_unpack_dir == NULL) {
5572 + err = unpack_pkg_control_files(conf, pkg);
5573 + if (err) return err;
5579 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
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;
5587 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5588 + if (err) return err;
5590 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5591 + if (err) return err;
5593 + err = preinst_configure(conf, pkg, old_pkg);
5594 + if (err) return err;
5596 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5597 + if (err) return err;
5599 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5600 + if (err) return err;
5605 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
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;
5614 + old_pkg->state_want = SW_DEINSTALL;
5616 + if (old_pkg->state_flag & SF_NOPRUNE) {
5617 + ipkg_message(conf, IPKG_INFO,
5618 + " not removing obsolesced files because package marked noprune\n");
5620 + ipkg_message(conf, IPKG_INFO,
5621 + " removing obsolesced files\n");
5622 + remove_obsolesced_files(conf, pkg, old_pkg);
5626 + ipkg_message(conf, IPKG_INFO,
5627 + " installing maintainer scripts\n");
5628 + install_maintainer_scripts(conf, pkg, old_pkg);
5630 + /* the following just returns 0 */
5631 + remove_disappeared(conf, pkg);
5633 + ipkg_message(conf, IPKG_INFO,
5634 + " installing data files\n");
5635 + install_data_files(conf, pkg);
5637 + ipkg_message(conf, IPKG_INFO,
5638 + " resolving conf files\n");
5639 + resolve_conffiles(conf, pkg);
5641 + pkg->state_status = SS_UNPACKED;
5644 + old_pkg->state_status = SS_NOT_INSTALLED;
5647 + time(&pkg->installed_time);
5649 + ipkg_message(conf, IPKG_INFO,
5650 + " cleanup temp files\n");
5651 + cleanup_temporary_files(conf, pkg);
5654 + pkg->parent->state_status = pkg->state_status;
5659 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
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;
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);
5681 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5682 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5690 + * Perform all the actions.
5692 + * pkgs_to_remove are packages marked for removal.
5693 + * pkgs_superseded are the old packages being replaced by upgrades.
5695 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
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)
5702 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5703 + if (err) return err;
5705 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5706 + if (err) return err;
5708 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5709 + if (err) goto UNWIND;
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;
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.
5723 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5724 + if (err) goto UNWIND;
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;
5730 + /* point of no return: no unwinding after this */
5731 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5732 + if (err) return err;
5734 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5738 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5740 + ipkg_message(conf, IPKG_INFO,
5741 + " cleanup temp files\n");
5742 + cleanup_temporary_files(conf, pkg);
5744 + ipkg_message(conf, IPKG_INFO,
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
5754 +/* ipkg_install.h - the itsy package management system
5758 + Copyright (C) 2001 University of Southern California
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.
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.
5771 +#ifndef IPKG_INSTALL_H
5772 +#define IPKG_INSTALL_H
5775 +#include "ipkg_conf.h"
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);
5783 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
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);
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
5793 +/* ipkg_message.c - the itsy package management system
5795 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
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.
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.
5810 +#include "ipkg_conf.h"
5811 +#include "ipkg_message.h"
5816 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5820 + if (conf && (conf->verbosity < level))
5827 + va_start (ap, fmt);
5828 + vprintf (fmt, ap);
5835 +#include "libipkg.h"
5837 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5840 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5845 + if (ipkg_cb_message)
5847 + va_start (ap, fmt);
5848 + vsnprintf (ts,256,fmt, ap);
5850 + ipkg_cb_message(conf,level,ts);
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
5858 +/* ipkg_message.h - the itsy package management system
5860 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
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.
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.
5873 +#ifndef _IPKG_MESSAGE_H_
5874 +#define _IPKG_MESSAGE_H_
5877 +#include "ipkg_conf.h"
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 */
5887 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
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
5894 +/* ipkg_remove.c - the itsy package management system
5898 + Copyright (C) 2001 University of Southern California
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.
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.
5912 +#include "ipkg_message.h"
5916 +#include "ipkg_remove.h"
5918 +#include "file_util.h"
5919 +#include "sprintf_alloc.h"
5920 +#include "str_util.h"
5922 +#include "ipkg_cmd.h"
5925 + * Returns number of the number of packages depending on the packages provided by this package.
5926 + * Every package implicitly provides itself.
5928 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5930 + int nprovides = pkg->provides_count;
5931 + abstract_pkg_t **provides = pkg->provides;
5932 + int n_installed_dependents = 0;
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)
5940 + while ((dep_ab_pkg = *dependers++) != NULL) {
5941 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5942 + n_installed_dependents++;
5947 + /* if caller requested the set of installed dependents */
5948 + if (pdependents) {
5950 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5952 + if ( dependents == NULL ){
5953 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
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)
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;
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;
5978 + return n_installed_dependents;
5981 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5986 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5987 + abstract_pkg_t * ab_pkg;
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);
5995 + if (dependents == NULL)
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;
6006 + while (dependents [i] != NULL) {
6007 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6009 + if (dep_ab_pkg->dependencies_checked == 2){
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);
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 */
6031 + for (i = 0; i < dependent_pkgs->len; i++) {
6032 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6039 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
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);
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");
6057 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
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 :)
6064 + abstract_pkg_t *parent_pkg = NULL;
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",
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",
6077 + return IPKG_PKG_IS_ESSENTIAL;
6081 + if ((parent_pkg = pkg->parent) == NULL)
6084 + /* only attempt to remove dependent installed packages if
6085 + * force_depends is not specified or the package is being
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);
6094 + if (has_installed_dependents) {
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
6100 + if (!conf->force_removal_of_dependent_packages
6101 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6102 + return IPKG_PKG_HAS_DEPENDENTS;
6105 + /* remove packages depending on this package - Karthik */
6106 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6108 + if (err) return err;
6112 + if ( message==0 ){
6113 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6116 + pkg->state_flag |= SF_FILELIST_CHANGED;
6118 + pkg->state_want = SW_DEINSTALL;
6119 + ipkg_state_changed++;
6121 + pkg_run_script(conf, pkg, "prerm", "remove");
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);
6130 + pkg_run_script(conf, pkg, "postrm", "remove");
6132 + remove_maintainer_scripts_except_postrm(conf, pkg);
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 :) */
6139 + remove_postrm(conf, pkg);
6140 + pkg->state_status = SS_NOT_INSTALLED;
6143 + parent_pkg->state_status = SS_NOT_INSTALLED;
6148 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6150 + ipkg_remove_pkg(conf, pkg,0);
6154 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6156 + str_list_t installed_dirs;
6157 + str_list_t *installed_files;
6158 + str_list_elt_t *iter;
6160 + conffile_t *conffile;
6161 + int removed_a_dir;
6164 + str_list_init(&installed_dirs);
6165 + installed_files = pkg_get_installed_files(pkg);
6167 + for (iter = installed_files->head; iter; iter = iter->next) {
6168 + file_name = iter->data;
6170 + if (file_is_dir(file_name)) {
6171 + str_list_append(&installed_dirs, strdup(file_name));
6175 + conffile = pkg_get_conffile(pkg, file_name);
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
6182 + if (conffile_has_been_modified(conf, conffile)) {
6183 + printf(" not deleting modified conffile %s\n", file_name);
6189 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6190 + if (!conf->noaction)
6191 + unlink(file_name);
6194 + if (!conf->noaction) {
6196 + removed_a_dir = 0;
6197 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6198 + file_name = iter->data;
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);
6206 + } while (removed_a_dir);
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);
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;
6218 + owner = file_hash_get_file_owner(conf, file_name);
6221 + iter->data = NULL;
6222 + str_list_remove(&installed_dirs, &iter);
6227 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6229 + iter->data = NULL;
6231 + str_list_deinit(&installed_dirs);
6236 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6239 + char *globpattern;
6242 + if (conf->noaction) return 0;
6244 + sprintf_alloc(&globpattern, "%s/%s.*",
6245 + pkg->dest->info_dir, pkg->name);
6246 + err = glob(globpattern, 0, NULL, &globbuf);
6247 + free(globpattern);
6252 + for (i = 0; i < globbuf.gl_pathc; i++) {
6253 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6256 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6257 + unlink(globbuf.gl_pathv[i]);
6259 + globfree(&globbuf);
6264 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6266 + char *postrm_file_name;
6268 + if (conf->noaction) return 0;
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);
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
6281 +/* ipkg_remove.h - the itsy package management system
6285 + Copyright (C) 2001 University of Southern California
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.
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.
6298 +#ifndef IPKG_REMOVE_H
6299 +#define IPKG_REMOVE_H
6302 +#include "ipkg_conf.h"
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);
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
6318 +/* ipkg_upgrade.c - the itsy package management system
6321 + Copyright (C) 2001 University of Southern California
6323 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
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.
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.
6337 +#include "ipkg_install.h"
6338 +#include "ipkg_message.h"
6340 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6344 + char *old_version, *new_version;
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);
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);
6363 + old_version = pkg_version_str_alloc(old);
6364 + new_version = pkg_version_str_alloc(new);
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);
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);
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);
6387 + } else if (cmp < 0) {
6388 + new->dest = old->dest;
6389 + old->state_want = SW_DEINSTALL;
6392 + new->state_flag |= SF_USER;
6393 + return ipkg_install_pkg(conf, new,1);
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
6399 +/* ipkg_upgrade.c - the itsy package management system
6401 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
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.
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.
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
6421 +/* ipkg_utils.c - the itsy package management system
6425 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
6441 +#include <sys/vfs.h>
6443 +#include "ipkg_utils.h"
6445 +#include "pkg_hash.h"
6447 +struct errlist* error_list;
6449 +int get_available_blocks(char * filesystem)
6451 + struct statfs sfs;
6453 + if(statfs(filesystem, &sfs)){
6454 + fprintf(stderr, "bad statfs\n");
6457 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6458 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6461 +char **read_raw_pkgs_from_file(const char *file_name)
6466 + if(!(fp = fopen(file_name, "r"))){
6467 + fprintf(stderr, "can't get %s open for read\n", file_name);
6471 + ret = read_raw_pkgs_from_stream(fp);
6478 +char **read_raw_pkgs_from_stream(FILE *fp)
6480 + char **raw = NULL, *buf, *scout;
6482 + size_t size = 512;
6484 + buf = malloc (size);
6486 + while (fgets(buf, size, fp)) {
6487 + while (strlen (buf) == (size - 1)
6488 + && buf[size-2] != '\n') {
6489 + size_t o = size - 1;
6491 + buf = realloc (buf, size);
6492 + if (fgets (buf + o, size - o, fp) == NULL)
6497 + raw = realloc(raw, (count + 50) * sizeof(char *));
6499 + if((scout = strchr(buf, '\n')))
6502 + raw[count++] = strdup(buf);
6505 + raw = realloc(raw, (count + 1) * sizeof(char *));
6506 + raw[count] = NULL;
6513 +/* something to remove whitespace, a hash pooper */
6514 +char *trim_alloc(char *line)
6517 + char *dest, *src, *end;
6519 + new = malloc(strlen(line) + 1);
6520 + if ( new == NULL ){
6521 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6524 + dest = new, src = line, end = line + (strlen(line) - 1);
6526 + /* remove it from the front */
6531 + /* and now from the back */
6532 + while((end > src) &&
6538 + /* this does from the first space
6539 + * blasting away any versions stuff in depends
6550 +int line_is_blank(const char *line)
6554 + for (s = line; *s; s++) {
6561 +void push_error_list(struct errlist ** errors, char * msg){
6562 + struct errlist *err_lst_tmp;
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;
6572 +void reverse_error_list(struct errlist **errors){
6573 + struct errlist *result=NULL;
6574 + struct errlist *current= *errors;
6575 + struct errlist *next;
6577 + while ( current != NULL ) {
6578 + next = current->next;
6579 + current->next=result;
6588 +void free_error_list(struct errlist **errors){
6589 + struct errlist *current = *errors;
6591 + while (current != NULL) {
6592 + free(current->errmsg);
6593 + current = (*errors)->next;
6595 + *errors = current;
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
6606 +/* ipkg_utils.h - the itsy package management system
6610 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
6623 +#ifndef IPKG_UTILS_H
6624 +#define IPKG_UTILS_H
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);
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
6639 +# Makefile for busybox
6641 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6642 +# Copyright (C) 2006 OpenWrt.org
6644 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6646 +LIBIPKG_CORE_OBJS:= \
6651 +LIBIPKG_CMD_OBJS:= \
6653 + ipkg_configure.o \
6659 +LIBIPKG_DB_OBJS:= \
6670 +LIBIPKG_LIST_OBJS:= \
6682 +LIBIPKG_UTIL_OBJS:= \
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)
6696 +ifeq ($(strip $(IPKG_ARCH)),)
6697 +IPKG_ARCH:=$(TARGET_ARCH)
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
6704 +/* ipkglib.c - the itsy package management system
6708 + Copyright (C) 2003 kernel concepts
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.
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.
6724 +#include "ipkg_includes.h"
6725 +#include "libipkg.h"
6728 +#include "ipkg_conf.h"
6729 +#include "ipkg_cmd.h"
6730 +#include "file_util.h"
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;
6741 +ipkg_init (ipkg_message_callback mcall,
6742 + ipkg_response_callback rcall,
6745 + ipkg_cb_message = mcall;
6746 + ipkg_cb_response = rcall;
6755 +ipkg_deinit (args_t * args)
6757 + args_deinit (args);
6758 + ipkg_cb_message = NULL;
6759 + ipkg_cb_response = NULL;
6761 + /* place other cleanup stuff here */
6768 +ipkg_packages_list(args_t *args,
6769 + const char *packages,
6770 + ipkg_list_callback cblist,
6774 + ipkg_conf_t ipkg_conf;
6777 + err = ipkg_conf_init (&ipkg_conf, args);
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");
6788 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6790 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6791 + ipkg_cb_list = NULL;
6792 + ipkg_conf_deinit (&ipkg_conf);
6798 +ipkg_packages_status(args_t *args,
6799 + const char *packages,
6800 + ipkg_status_callback cbstatus,
6804 + ipkg_conf_t ipkg_conf;
6807 + err = ipkg_conf_init (&ipkg_conf, args);
6813 + ipkg_cb_status = cbstatus;
6815 + /* we need to do this because of static declarations,
6816 + * maybe a good idea to change */
6817 + cmd = ipkg_cmd_find ("status");
6819 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6821 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6823 + ipkg_cb_status = NULL;
6824 + ipkg_conf_deinit (&ipkg_conf);
6830 +ipkg_packages_info(args_t *args,
6831 + const char *packages,
6832 + ipkg_status_callback cbstatus,
6836 + ipkg_conf_t ipkg_conf;
6839 + err = ipkg_conf_init (&ipkg_conf, args);
6845 + ipkg_cb_status = cbstatus;
6847 + /* we need to do this because of static declarations,
6848 + * maybe a good idea to change */
6849 + cmd = ipkg_cmd_find ("info");
6851 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6853 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6855 + ipkg_cb_status = NULL;
6856 + ipkg_conf_deinit (&ipkg_conf);
6862 +ipkg_packages_install (args_t * args, const char *name)
6865 + ipkg_conf_t ipkg_conf;
6868 + /* this error should be handled in application */
6869 + if (!name || !strlen (name))
6872 + err = ipkg_conf_init (&ipkg_conf, args);
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);
6883 + ipkg_conf_deinit(&ipkg_conf);
6889 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6892 + ipkg_conf_t ipkg_conf;
6895 + /* this error should be handled in application */
6896 + if (!name || !strlen (name))
6899 + err = ipkg_conf_init (&ipkg_conf, args);
6905 + /* we need to do this because of static declarations,
6906 + * maybe a good idea to change */
6908 + cmd = ipkg_cmd_find ("purge");
6910 + cmd = ipkg_cmd_find ("remove");
6912 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6914 + ipkg_conf_deinit(&ipkg_conf);
6920 +ipkg_lists_update(args_t *args)
6923 + ipkg_conf_t ipkg_conf;
6926 + err = ipkg_conf_init (&ipkg_conf, args);
6932 + /* we need to do this because of static declarations,
6933 + * maybe a good idea to change */
6934 + cmd = ipkg_cmd_find ("update");
6936 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6938 + ipkg_conf_deinit(&ipkg_conf);
6944 +ipkg_packages_upgrade(args_t *args)
6947 + ipkg_conf_t ipkg_conf;
6950 + err = ipkg_conf_init (&ipkg_conf, args);
6956 + /* we need to do this because of static declarations,
6957 + * maybe a good idea to change */
6958 + cmd = ipkg_cmd_find ("upgrade");
6960 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6962 + ipkg_conf_deinit(&ipkg_conf);
6968 +ipkg_packages_download (args_t * args, const char *name)
6971 + ipkg_conf_t ipkg_conf;
6974 + /* this error should be handled in application */
6975 + if (!name || !strlen (name))
6978 + err = ipkg_conf_init (&ipkg_conf, args);
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);
6989 + ipkg_conf_deinit(&ipkg_conf);
6995 +ipkg_package_files(args_t *args,
6997 + ipkg_list_callback cblist,
7001 + ipkg_conf_t ipkg_conf;
7004 + /* this error should be handled in application */
7005 + if (!name || !strlen (name))
7008 + err = ipkg_conf_init (&ipkg_conf, args);
7014 + ipkg_cb_list = cblist;
7016 + /* we need to do this because of static declarations,
7017 + * maybe a good idea to change */
7018 + cmd = ipkg_cmd_find ("files");
7020 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7022 + ipkg_cb_list = NULL;
7023 + ipkg_conf_deinit(&ipkg_conf);
7029 +ipkg_file_search(args_t *args,
7031 + ipkg_list_callback cblist,
7035 + ipkg_conf_t ipkg_conf;
7038 + /* this error should be handled in application */
7039 + if (!file || !strlen (file))
7042 + err = ipkg_conf_init (&ipkg_conf, args);
7048 + ipkg_cb_list = cblist;
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);
7055 + ipkg_cb_list = NULL;
7056 + ipkg_conf_deinit(&ipkg_conf);
7062 +ipkg_file_what(args_t *args, const char *file, const char* command)
7065 + ipkg_conf_t ipkg_conf;
7068 + /* this error should be handled in application */
7069 + if (!file || !strlen (file))
7072 + err = ipkg_conf_init (&ipkg_conf, args);
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);
7083 + ipkg_conf_deinit(&ipkg_conf);
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")
7094 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7097 + if (conf && (conf->verbosity < level)) {
7101 + if ( level == IPKG_ERROR ){
7102 + push_error_list(&error_list, msg);
7111 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7112 + pkg_state_status_t status, void *userdata)
7115 + printf("%s - %s - %s\n", name, version, desc);
7117 + printf("%s - %s\n", name, version);
7121 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7122 + pkg_state_status_t status, void *userdata)
7125 + printf("%s\n", desc);
7129 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7132 + printf("%s\n", desc);
7136 +char* default_ipkg_response_callback(char *question)
7138 + char *response = NULL;
7142 + response = (char *)file_read_line_alloc(stdin);
7143 + } while (response == NULL);
7147 +/* This is used for backward compatibility */
7149 +ipkg_op (int argc, char *argv[])
7155 + ipkg_conf_t ipkg_conf;
7157 + args_init (&args);
7159 + optind = args_parse (&args, argc, argv);
7160 + if (optind == argc || optind < 0)
7162 + args_usage ("ipkg must have one sub-command argument");
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.
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;
7175 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7176 + read anything from there.
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;
7191 + err = ipkg_conf_init (&ipkg_conf, &args);
7197 + args_deinit (&args);
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;
7205 + ipkg_cb_list = default_ipkg_list_callback;
7207 + cmd = ipkg_cmd_find (cmd_name);
7210 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7212 + args_usage (NULL);
7215 + if (cmd->requires_args && optind == argc)
7218 + "%s: the ``%s'' command requires at least one argument\n",
7219 + __FUNCTION__, cmd_name);
7220 + args_usage (NULL);
7223 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7225 + ipkg_conf_deinit (&ipkg_conf);
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
7235 +/* ipkglib.h - the itsy package management system
7237 + Florian Boor <florian.boor@kernelconcepts.de>
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.
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.
7255 +#include "ipkg_conf.h"
7256 +#include "ipkg_message.h"
7261 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
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,
7267 +typedef char* (*ipkg_response_callback)(char *question);
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,
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,
7279 +extern int ipkg_packages_status(args_t *args,
7280 + const char *packages,
7281 + ipkg_status_callback cbstatus,
7283 +extern int ipkg_packages_info(args_t *args,
7284 + const char *packages,
7285 + ipkg_status_callback cbstatus,
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,
7294 + ipkg_list_callback cblist,
7296 +extern int ipkg_file_search(args_t *args,
7298 + ipkg_list_callback cblist,
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);
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);
7316 +extern int ipkg_op(int argc, char *argv[]);
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
7326 +/* md5.c - wrappers to busybox md5 functions
7328 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
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.
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.
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.
7350 +int md5_stream(FILE *stream, void *resblock)
7355 + if( (fd = fileno(stream)) == -1 ) {
7356 + bb_error_msg("bad file descriptor");
7360 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7365 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7369 + md5_begin(&md5_cx);
7370 + md5_hash(buffer, len, &md5_cx);
7371 + return md5_end(resblock, &md5_cx);
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
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.
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.
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.
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.
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);
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
7409 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
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
7417 +/* nv_pair.c - the itsy package management system
7421 + Copyright (C) 2001 University of Southern California
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.
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.
7436 +#include "nv_pair.h"
7437 +#include "str_util.h"
7439 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7441 + nv_pair->name = str_dup_safe(name);
7442 + nv_pair->value = str_dup_safe(value);
7447 +void nv_pair_deinit(nv_pair_t *nv_pair)
7449 + free(nv_pair->name);
7450 + nv_pair->name = NULL;
7452 + free(nv_pair->value);
7453 + nv_pair->value = NULL;
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
7461 +/* nv_pair.h - the itsy package management system
7465 + Copyright (C) 2001 University of Southern California
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.
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.
7481 +typedef struct nv_pair nv_pair_t;
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);
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
7497 +/* nv_pair_list.c - the itsy package management system
7501 + Copyright (C) 2001 University of Southern California
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.
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.
7516 +#include "nv_pair.h"
7517 +#include "void_list.h"
7518 +#include "nv_pair_list.h"
7520 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7522 + return void_list_elt_init((void_list_elt_t *) elt, data);
7525 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7527 + void_list_elt_deinit((void_list_elt_t *) elt);
7530 +int nv_pair_list_init(nv_pair_list_t *list)
7532 + return void_list_init((void_list_t *) list);
7535 +void nv_pair_list_deinit(nv_pair_list_t *list)
7537 + nv_pair_list_elt_t *iter;
7538 + nv_pair_t *nv_pair;
7540 + for (iter = list->head; iter; iter = iter->next) {
7541 + nv_pair = iter->data;
7542 + nv_pair_deinit(nv_pair);
7544 + /* malloced in nv_pair_list_append */
7546 + iter->data = NULL;
7548 + void_list_deinit((void_list_t *) list);
7551 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7555 + /* freed in nv_pair_list_deinit */
7556 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7558 + if (nv_pair == NULL) {
7559 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7562 + nv_pair_init(nv_pair, name, value);
7564 + err = void_list_append((void_list_t *) list, nv_pair);
7572 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7574 + return void_list_push((void_list_t *) list, data);
7577 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7579 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7582 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7584 + nv_pair_list_elt_t *iter;
7585 + nv_pair_t *nv_pair;
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;
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
7599 +/* nv_pair_list.h - the itsy package management system
7603 + Copyright (C) 2001 University of Southern California
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.
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.
7616 +#ifndef NV_PAIR_LIST_H
7617 +#define NV_PAIR_LIST_H
7619 +#include "nv_pair.h"
7620 +#include "void_list.h"
7622 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7623 +struct nv_pair_list_elt
7625 + nv_pair_list_elt_t *next;
7629 +typedef struct nv_pair_list nv_pair_list_t;
7630 +struct nv_pair_list
7632 + nv_pair_list_elt_t pre_head;
7633 + nv_pair_list_elt_t *head;
7634 + nv_pair_list_elt_t *tail;
7637 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7639 + if (list->head == NULL)
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);
7648 +int nv_pair_list_init(nv_pair_list_t *list);
7649 +void nv_pair_list_deinit(nv_pair_list_t *list);
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);
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
7663 +/* pkg.c - the itsy package management system
7667 + Copyright (C) 2001 University of Southern California
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.
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.
7682 +#include <string.h>
7687 +#include "pkg_parse.h"
7688 +#include "pkg_extract.h"
7689 +#include "ipkg_message.h"
7690 +#include "ipkg_utils.h"
7692 +#include "sprintf_alloc.h"
7693 +#include "file_util.h"
7694 +#include "str_util.h"
7695 +#include "xsystem.h"
7696 +#include "ipkg_conf.h"
7698 +typedef struct enum_map enum_map_t;
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"}
7712 +static const enum_map_t pkg_state_flag_map[] = {
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"},
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" }
7734 +static int verrevcmp(const char *val, const char *ref);
7737 +pkg_t *pkg_new(void)
7741 + pkg = malloc(sizeof(pkg_t));
7742 + if (pkg == NULL) {
7743 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7752 +int pkg_init(pkg_t *pkg)
7754 + memset(pkg, 0, sizeof(pkg_t));
7757 + pkg->version = NULL;
7758 + pkg->revision = NULL;
7759 + pkg->familiar_revision = 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;
7778 + /* Abhaya: added init for conflicts fields */
7779 + pkg->conflicts = NULL;
7780 + pkg->conflicts_count = 0;
7782 + /* added for replaces. Jamey 7/23/2002 */
7783 + pkg->replaces = NULL;
7784 + pkg->replaces_count = 0;
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;
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;
7807 +void pkg_deinit(pkg_t *pkg)
7812 + free(pkg->version);
7813 + pkg->version = NULL;
7814 + /* revision and familiar_revision share storage with version, so
7816 + pkg->revision = NULL;
7817 + pkg->familiar_revision = NULL;
7818 + /* owned by ipkg_conf_t */
7820 + /* owned by ipkg_conf_t */
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;
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;
7873 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7877 + FILE *control_file;
7879 + err = pkg_init(pkg);
7880 + if (err) { return err; }
7882 + pkg->local_filename = strdup(filename);
7884 + control_file = tmpfile();
7885 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7886 + if (err) { return err; }
7888 + rewind(control_file);
7889 + raw = read_raw_pkgs_from_stream(control_file);
7890 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7892 + fclose(control_file);
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. */
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
7905 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7907 + if (oldpkg == newpkg) {
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);
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;
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;
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;
7944 + oldpkg->depends = newpkg->depends;
7945 + newpkg->depends = NULL;
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;
7952 + oldpkg->recommends_str = newpkg->recommends_str;
7953 + newpkg->recommends_str = NULL;
7954 + oldpkg->recommends_count = newpkg->recommends_count;
7955 + newpkg->recommends_count = 0;
7957 + oldpkg->suggests_str = newpkg->suggests_str;
7958 + newpkg->suggests_str = NULL;
7959 + oldpkg->suggests_count = newpkg->suggests_count;
7960 + newpkg->suggests_count = 0;
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;
7969 + oldpkg->provides = newpkg->provides;
7970 + newpkg->provides = NULL;
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;
7979 + oldpkg->conflicts = newpkg->conflicts;
7980 + newpkg->conflicts = NULL;
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;
7989 + oldpkg->replaces = newpkg->replaces;
7990 + newpkg->replaces = NULL;
7993 + if (!oldpkg->filename)
7994 + oldpkg->filename = str_dup_safe(newpkg->filename);
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);
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;
8021 + if (!oldpkg->essential)
8022 + oldpkg->essential = newpkg->essential;
8027 +abstract_pkg_t *abstract_pkg_new(void)
8029 + abstract_pkg_t * ab_pkg;
8031 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8033 + if (ab_pkg == NULL) {
8034 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8038 + if ( abstract_pkg_init(ab_pkg) < 0 )
8044 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8046 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8048 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8049 + if (ab_pkg->provided_by==NULL){
8052 + ab_pkg->dependencies_checked = 0;
8053 + ab_pkg->state_status = SS_NOT_INSTALLED;
8058 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8061 + char **raw_start=NULL;
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__);
8068 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
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__);
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);
8094 +char * pkg_formatted_info(pkg_t *pkg )
8099 + buff = malloc(8192);
8100 + if (buff == NULL) {
8101 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8107 + line = pkg_formatted_field(pkg, "Package");
8108 + strncat(buff ,line, strlen(line));
8111 + line = pkg_formatted_field(pkg, "Version");
8112 + strncat(buff ,line, strlen(line));
8115 + line = pkg_formatted_field(pkg, "Depends");
8116 + strncat(buff ,line, strlen(line));
8119 + line = pkg_formatted_field(pkg, "Recommends");
8120 + strncat(buff ,line, strlen(line));
8123 + line = pkg_formatted_field(pkg, "Suggests");
8124 + strncat(buff ,line, strlen(line));
8127 + line = pkg_formatted_field(pkg, "Provides");
8128 + strncat(buff ,line, strlen(line));
8131 + line = pkg_formatted_field(pkg, "Replaces");
8132 + strncat(buff ,line, strlen(line));
8135 + line = pkg_formatted_field(pkg, "Conflicts");
8136 + strncat(buff ,line, strlen(line));
8139 + line = pkg_formatted_field(pkg, "Status");
8140 + strncat(buff ,line, strlen(line));
8143 + line = pkg_formatted_field(pkg, "Section");
8144 + strncat(buff ,line, strlen(line));
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));
8151 + line = pkg_formatted_field(pkg, "Architecture");
8152 + strncat(buff ,line, strlen(line));
8155 + line = pkg_formatted_field(pkg, "Maintainer");
8156 + strncat(buff ,line, strlen(line));
8159 + line = pkg_formatted_field(pkg, "MD5sum");
8160 + strncat(buff ,line, strlen(line));
8163 + line = pkg_formatted_field(pkg, "Size");
8164 + strncat(buff ,line, strlen(line));
8167 + line = pkg_formatted_field(pkg, "Filename");
8168 + strncat(buff ,line, strlen(line));
8171 + line = pkg_formatted_field(pkg, "Conffiles");
8172 + strncat(buff ,line, strlen(line));
8175 + line = pkg_formatted_field(pkg, "Source");
8176 + strncat(buff ,line, strlen(line));
8179 + line = pkg_formatted_field(pkg, "Description");
8180 + strncat(buff ,line, strlen(line));
8183 + line = pkg_formatted_field(pkg, "Installed-Time");
8184 + strncat(buff ,line, strlen(line));
8190 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8192 + static size_t LINE_LEN = 128;
8193 + char * temp = (char *)malloc(1);
8195 + int flag_provide_false = 0;
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 )
8202 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8203 + goto UNKNOWN_FMT_FIELD;
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__);
8221 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8224 + goto UNKNOWN_FMT_FIELD;
8229 + if (strcasecmp(field, "Conffiles") == 0) {
8231 + conffile_list_elt_t *iter;
8232 + char confstr[LINE_LEN];
8234 + if (pkg->conffiles.head == NULL) {
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);
8244 + temp = (char *)realloc(temp,len);
8245 + if ( temp == NULL ){
8246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8257 + } else if (strcasecmp(field, "Conflicts") == 0) {
8260 + if (pkg->conflicts_count) {
8261 + char conflictstr[LINE_LEN];
8263 + for(i = 0; i < pkg->conflicts_count; i++) {
8264 + len = len + (strlen(pkg->conflicts_str[i])+5);
8266 + temp = (char *)realloc(temp,len);
8267 + if ( temp == NULL ){
8268 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8277 + strncat(temp, "\n", strlen("\n"));
8280 + goto UNKNOWN_FMT_FIELD;
8285 + if (strcasecmp(field, "Depends") == 0) {
8289 + if (pkg->depends_count) {
8290 + char depstr[LINE_LEN];
8292 + for(i = 0; i < pkg->depends_count; i++) {
8293 + len = len + (strlen(pkg->depends_str[i])+4);
8295 + temp = (char *)realloc(temp,len);
8296 + if ( temp == NULL ){
8297 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8306 + strncat(temp, "\n", strlen("\n"));
8308 + } else if (strcasecmp(field, "Description") == 0) {
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__);
8317 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8320 + goto UNKNOWN_FMT_FIELD;
8326 + if (pkg->essential) {
8327 + temp = (char *)realloc(temp,16);
8328 + if ( temp == NULL ){
8329 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8333 + snprintf(temp, (16), "Essential: yes\n");
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__);
8347 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
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__);
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__);
8369 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8375 + /* Maintainer | MD5sum */
8376 + if (strcasecmp(field, "Maintainer") == 0) {
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__);
8385 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8387 + } else if (strcasecmp(field, "MD5sum") == 0) {
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__);
8396 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8399 + goto UNKNOWN_FMT_FIELD;
8405 + if (strcasecmp(field, "Package") == 0) {
8407 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8408 + if ( temp == NULL ){
8409 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8413 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8414 + } else if (strcasecmp(field, "Priority") == 0) {
8416 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8417 + if ( temp == NULL ){
8418 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8422 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8423 + } else if (strcasecmp(field, "Provides") == 0) {
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;
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];
8439 + for(i = 0; i < pkg->provides_count; i++) {
8440 + len = len + (strlen(pkg->provides_str[i])+5);
8442 + temp = (char *)realloc(temp,len);
8443 + if ( temp == NULL ){
8444 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8455 + strncat(temp, "\n", strlen("\n"));
8459 + goto UNKNOWN_FMT_FIELD;
8466 + /* Replaces | Recommends*/
8467 + if (strcasecmp (field, "Replaces") == 0) {
8468 + if (pkg->replaces_count) {
8469 + char replstr[LINE_LEN];
8471 + for (i = 0; i < pkg->replaces_count; i++) {
8472 + len = len + (strlen(pkg->replaces_str[i])+5);
8474 + temp = (char *)realloc(temp,len);
8475 + if ( temp == NULL ){
8476 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8485 + strncat(temp, "\n", strlen("\n"));
8487 + } else if (strcasecmp (field, "Recommends") == 0) {
8488 + if (pkg->recommends_count) {
8489 + char recstr[LINE_LEN];
8491 + for(i = 0; i < pkg->recommends_count; i++) {
8492 + len = len + (strlen( pkg->recommends_str[i])+5);
8494 + temp = (char *)realloc(temp,len);
8495 + if ( temp == NULL ){
8496 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8505 + strncat(temp, "\n", strlen("\n"));
8508 + goto UNKNOWN_FMT_FIELD;
8514 + /* Section | Size | Source | Status | Suggests */
8515 + if (strcasecmp(field, "Section") == 0) {
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__);
8524 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8526 + } else if (strcasecmp(field, "Size") == 0) {
8529 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8530 + if ( temp == NULL ){
8531 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8535 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8537 + } else if (strcasecmp(field, "Source") == 0) {
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__);
8546 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8548 + } else if (strcasecmp(field, "Status") == 0) {
8550 + /* Benjamin Pineau note: we should avoid direct usage of
8551 + * strlen(arg) without keeping "arg" for later free()
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);
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__);
8564 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8567 + if(pstat) /* pfstat can be NULL if ENOMEM */
8569 + } else if (strcasecmp(field, "Suggests") == 0) {
8570 + if (pkg->suggests_count) {
8572 + char sugstr[LINE_LEN];
8574 + for(i = 0; i < pkg->suggests_count; i++) {
8575 + len = len + (strlen(pkg->suggests_str[i])+5);
8577 + temp = (char *)realloc(temp,len);
8578 + if ( temp == NULL ){
8579 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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));
8588 + strncat(temp, "\n", strlen("\n"));
8591 + goto UNKNOWN_FMT_FIELD;
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__);
8605 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8610 + goto UNKNOWN_FMT_FIELD;
8613 + if ( strlen(temp)<2 ) {
8618 + UNKNOWN_FMT_FIELD:
8619 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8620 + if ( strlen(temp)<2 ) {
8627 +void pkg_print_info(pkg_t *pkg, FILE *file)
8630 + if (pkg == NULL) {
8634 + buff = pkg_formatted_info(pkg);
8635 + if ( buff == NULL )
8637 + if (strlen(buff)>2){
8638 + fwrite(buff, 1, strlen(buff), file);
8643 +void pkg_print_status(pkg_t * pkg, FILE * file)
8645 + if (pkg == NULL) {
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.
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.
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.
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);
8685 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8688 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8689 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8690 + __FUNCTION__, field);
8692 + buff = pkg_formatted_field(pkg, field);
8693 + if (strlen(buff)>2) {
8694 + fprintf(file, "%s", buff);
8702 + * libdpkg - Debian packaging suite library routines
8703 + * vercmp.c - comparison of version numbers
8705 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8707 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8711 + if (pkg->epoch > ref_pkg->epoch) {
8715 + if (pkg->epoch < ref_pkg->epoch) {
8719 + r = verrevcmp(pkg->version, ref_pkg->version);
8724 +#ifdef USE_DEBVERSION
8725 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8730 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8736 +int verrevcmp(const char *val, const char *ref)
8740 + const char *vp, *rp;
8741 + const char *vsep, *rsep;
8743 + if (!val) val= "";
8744 + if (!ref) ref= "";
8746 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8747 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
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;
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;
8764 + vsep = strchr(".-", vc);
8765 + rsep = strchr(".-", rc);
8766 + if (vsep && !rsep) return -1;
8767 + if (!vsep && rsep) return +1;
8769 + if (!*val && !*ref) return 0;
8770 + if (!*val) return -1;
8771 + if (!*ref) return +1;
8775 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8779 + r = pkg_compare_versions(it, ref);
8781 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8785 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8789 + if (strcmp(op, "<<") == 0) {
8793 + if (strcmp(op, ">>") == 0) {
8797 + if (strcmp(op, "=") == 0) {
8801 + fprintf(stderr, "unknown operator: %s", op);
8805 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8807 + const pkg_t *a = *(const pkg_t **)p1;
8808 + const pkg_t *b = *(const pkg_t **)p2;
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);
8817 + namecmp = strcmp(a->name, b->name);
8820 + vercmp = pkg_compare_versions(a, b);
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);
8828 + if (a->arch_priority > b->arch_priority)
8830 + if (a->arch_priority < b->arch_priority)
8835 +int abstract_pkg_name_compare(void *p1, void *p2)
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);
8844 + return strcmp(a->name, b->name);
8848 +char *pkg_version_str_alloc(pkg_t *pkg)
8850 + char *complete_version;
8852 +#ifdef USE_DEBVERSION
8853 + char *revision_str;
8854 + char *familiar_revision_str;
8858 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8860 + epoch_str = strdup("");
8863 +#ifdef USE_DEBVERSION
8864 + if (pkg->revision && strlen(pkg->revision)) {
8865 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8867 + revision_str = strdup("");
8870 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8871 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8873 + familiar_revision_str = strdup("");
8877 +#ifdef USE_DEBVERSION
8878 + sprintf_alloc(&complete_version, "%s%s%s%s",
8879 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8881 + sprintf_alloc(&complete_version, "%s%s",
8882 + epoch_str, pkg->version);
8886 +#ifdef USE_DEBVERSION
8887 + free(revision_str);
8888 + free(familiar_revision_str);
8891 + return complete_version;
8894 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8897 + char *list_file_name = NULL;
8898 + FILE *list_file = NULL;
8900 + char *installed_file_name;
8903 + pkg->installed_files_ref_cnt++;
8905 + if (pkg->installed_files) {
8906 + return pkg->installed_files;
8909 + pkg->installed_files = str_list_alloc();
8910 + if (pkg->installed_files == NULL) {
8911 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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.
8918 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8919 + if (pkg->local_filename == NULL) {
8920 + return pkg->installed_files;
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);
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;
8934 + rewind(list_file);
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;
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;
8950 + free(list_file_name);
8953 + rootdirlen = strlen( pkg->dest->root_dir );
8957 + line = file_read_line_alloc(list_file);
8958 + if (line == NULL) {
8964 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8965 + if( strncmp( pkg->dest->root_dir,
8968 + if (*file_name == '.') {
8971 + if (*file_name == '/') {
8975 + /* Freed in pkg_free_installed_files */
8976 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8978 + // already contains root_dir as header -> ABSOLUTE
8979 + sprintf_alloc(&installed_file_name, "%s", file_name);
8981 + str_list_append(pkg->installed_files, installed_file_name);
8985 + fclose(list_file);
8987 + return pkg->installed_files;
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
8995 +int pkg_free_installed_files(pkg_t *pkg)
8997 + str_list_elt_t *iter;
8999 + pkg->installed_files_ref_cnt--;
9000 + if (pkg->installed_files_ref_cnt > 0) {
9004 + if (pkg->installed_files) {
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;
9012 + str_list_deinit(pkg->installed_files);
9015 + pkg->installed_files = NULL;
9020 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9023 + char *list_file_name;
9025 + //I don't think pkg_free_installed_files should be called here. Jamey
9026 + //pkg_free_installed_files(pkg);
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);
9041 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9043 + conffile_list_elt_t *iter;
9044 + conffile_t *conffile;
9046 + if (pkg == NULL) {
9050 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9051 + conffile = iter->data;
9053 + if (strcmp(conffile->name, file_name) == 0) {
9061 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9062 + const char *script, const char *args)
9068 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9069 + maintainer script within a chroot environment. */
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);
9079 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
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);
9086 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9089 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9090 + if (conf->noaction) return 0;
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);
9100 + setenv("PKG_ROOT",
9101 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9103 + if (! file_exists(path)) {
9108 + if (conf->offline_root) {
9109 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9114 + sprintf_alloc(&cmd, "%s %s", path, args);
9117 + err = xsystem(cmd);
9121 + fprintf(stderr, "%s script returned status %d\n", script, err);
9128 +char *pkg_state_want_to_str(pkg_state_want_t sw)
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);
9138 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9139 + __FUNCTION__, sw);
9140 + return strdup("<STATE_WANT_UNKNOWN>");
9143 +pkg_state_want_t pkg_state_want_from_str(char *str)
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;
9153 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9154 + __FUNCTION__, str);
9155 + return SW_UNKNOWN;
9158 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9161 + int len = 3; /* ok\000 is minimum */
9164 + /* clear the temporary flags before converting to string */
9165 + sf &= SF_NONVOLATILE_FLAGS;
9168 + return strdup("ok");
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;
9176 + str = malloc(len);
9177 + if ( str == NULL ) {
9178 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
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);
9188 + len = strlen(str);
9189 + str[len-1] = 0; /* squash last comma */
9194 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9199 + if (strcmp(str, "ok") == 0) {
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] == ',') {
9219 +char *pkg_state_status_to_str(pkg_state_status_t ss)
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);
9229 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9230 + __FUNCTION__, ss);
9231 + return strdup("<STATE_STATUS_UNKNOWN>");
9234 +pkg_state_status_t pkg_state_status_from_str(char *str)
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;
9244 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9245 + __FUNCTION__, str);
9246 + return SS_NOT_INSTALLED;
9249 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9251 + nv_pair_list_elt_t *l;
9253 + if (!pkg->architecture)
9256 + l = conf->arch_list.head;
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);
9267 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9271 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9273 + nv_pair_list_elt_t *l;
9275 + l = conf->arch_list.head;
9278 + nv_pair_t *nv = l->data;
9279 + if (strcmp(nv->name, archname) == 0) {
9280 + int priority = strtol(nv->value, NULL, 0);
9288 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
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();
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;
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);
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;
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;
9322 + pkg_vec_free(available_pkgs);
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);
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);
9341 + pkg_vec_free(installed_pkgs);
9346 +struct pkg_write_filelist_data {
9347 + ipkg_conf_t *conf;
9352 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
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);
9361 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9363 + struct pkg_write_filelist_data data;
9364 + char *list_file_name = NULL;
9368 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
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");
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));
9388 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9389 + fclose(data.stream);
9390 + free(list_file_name);
9395 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9397 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9398 + hash_table_t *pkg_hash = &conf->pkg_hash;
9401 + if (conf->noaction)
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);
9412 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
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
9421 +/* pkg_depends.c - the itsy package management system
9425 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
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"
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);
9456 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9458 + depend_t *depend = (depend_t *)cdata;
9459 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9465 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9467 + depend_t *depend = (depend_t *)cdata;
9469 + pkg_t * temp = pkg_new();
9471 + parseVersion(temp, depend->version);
9472 + comparison = pkg_compare_versions(pkg, temp);
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));
9480 + if (version_constraints_satisfied(depend, pkg))
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)
9490 + pkg_t * satisfier_entry_pkg;
9491 + register int i, j, k;
9494 + abstract_pkg_t * ab_pkg;
9497 + * this is a setup to check for redundant/cyclic dependency checks,
9498 + * which are marked at the abstract_pkg level
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;
9505 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9506 + *unresolved = NULL;
9509 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9513 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9515 + *unresolved = NULL;
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;;
9526 + satisfier_entry_pkg = NULL;
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;
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?) */
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;
9553 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9554 + /* check for not-already-installed dependencies */
9555 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9559 + if (newstuff == NULL) {
9562 + for (i = 0; i < rc; i++) {
9563 + pkg_t *p = tmp_vec->pkgs[i];
9564 + if (p->state_want == SW_INSTALL)
9566 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9570 + pkg_vec_free (tmp_vec);
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);
9577 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
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;
9603 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9604 + if (satisfying_pkg != NULL) {
9610 + /* if nothing installed matches, then look for uninstalled satisfier */
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;
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);
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;
9645 + /* we didn't find one, add something to the unsatisfied vector */
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);
9652 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9653 + pkg->name, compound_depend->possibilities[0]->pkg->name);
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);
9661 + char ** newstuff = NULL;
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,
9670 + the_lost = merge_unresolved(the_lost, newstuff);
9676 + *unresolved = the_lost;
9678 + return unsatisfied->len;
9681 +/*checking for conflicts !in replaces
9682 + If a packages conflicts with another but is also replacing it, I should not consider it a
9684 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9686 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9689 + int replaces_count = pkg->replaces_count;
9690 + abstract_pkg_t **replaces;
9692 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9695 + replaces = pkg->replaces;
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);
9708 +/* Abhaya: added support for conflicts */
9709 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
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;
9717 + abstract_pkg_t * ab_pkg;
9718 + pkg_t **pkg_scouts;
9722 + * this is a setup to check for redundant/cyclic dependency checks,
9723 + * which are marked at the abstract_pkg level
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;
9730 + conflicts = pkg->conflicts;
9732 + return (pkg_vec_t *)NULL;
9734 + installed_conflicts = pkg_vec_alloc();
9736 + count = pkg->conflicts_count;
9740 + /* foreach conflict */
9741 + for(i = 0; i < pkg->conflicts_count; i++){
9743 + possible_satisfiers = conflicts->possibilities;
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;
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];
9760 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
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);
9775 + if (installed_conflicts->len)
9776 + return installed_conflicts;
9777 + pkg_vec_free(installed_conflicts);
9778 + return (pkg_vec_t *)NULL;
9781 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9786 + if(depends->constraint == NONE)
9791 + parseVersion(temp, depends->version);
9793 + comparison = pkg_compare_versions(pkg, temp);
9797 + if((depends->constraint == EARLIER) &&
9800 + else if((depends->constraint == LATER) &&
9803 + else if(comparison == 0)
9805 + else if((depends->constraint == LATER_EQUAL) &&
9806 + (comparison >= 0))
9808 + else if((depends->constraint == EARLIER_EQUAL) &&
9809 + (comparison <= 0))
9815 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
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;
9826 + for (i = 0; i < n_providers; i++) {
9827 + abstract_pkg_t *papkg = apkgs[i];
9828 + pkg_vec = papkg->pkgs;
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)) {
9842 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
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;
9852 + for (i = 0; i < n_providers; i++) {
9853 + abstract_pkg_t *papkg = apkgs[i];
9854 + pkg_vec_t *pkg_vec = papkg->pkgs;
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)
9869 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9872 + pkg_t ** pkgs = vec->pkgs;
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))
9885 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9886 + * the same abstract package and 0 otherwise.
9888 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
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;
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)
9908 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9909 + * and 0 otherwise.
9911 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9913 + abstract_pkg_t **provides = pkg->provides;
9914 + int provides_count = pkg->provides_count;
9916 + for (i = 0; i < provides_count; i++) {
9917 + if (provides[i] == providee)
9924 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9927 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
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; */
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)
9948 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9951 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9953 + compound_depend_t *conflicts = pkg->conflicts;
9954 + int conflicts_count = pkg->conflicts_count;
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) {
9969 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9970 + * conflictee's provides and 0 otherwise.
9972 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
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;
9979 + int possibility_count;
9980 + struct depend **possibilities;
9981 + abstract_pkg_t *possibility ;
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]) {
9998 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10000 + int oldlen = 0, newlen = 0;
10002 + register int i, j;
10007 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10008 + while(newstuff && newstuff[newlen]) newlen++;
10010 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10011 + if (result == NULL) {
10012 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10016 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10017 + *(result + i) = *(newstuff + j);
10019 + *(result + i) = NULL;
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
10028 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10032 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10035 + while(the_lost && the_lost[count]) count++;
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__);
10043 + resized[count - 1] = strdup(depend_str);
10044 + resized[count] = NULL;
10049 +void printDepends(pkg_t * pkg)
10051 + register int i, j;
10052 + compound_depend_t * depend;
10055 + count = pkg->pre_depends_count + pkg->depends_count;
10057 + depend = pkg->depends;
10059 + fprintf(stderr, "Depends pointer is NULL\n");
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);
10075 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10077 + register int i, j;
10079 + /* every pkg provides itself */
10080 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10082 + if (!pkg->provides_count)
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__);
10090 + pkg->provides[0] = ab_pkg;
10092 + // if (strcmp(ab_pkg->name, pkg->name))
10093 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
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]);
10098 + pkg->provides[i+1] = provided_abpkg;
10101 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10106 +/* Abhaya: added conflicts support */
10107 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10110 + compound_depend_t * conflicts;
10112 + if (!pkg->conflicts_count)
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__);
10121 + for (i = 0; i < pkg->conflicts_count; i++) {
10122 + conflicts->type = CONFLICTS;
10123 + parseDepends(conflicts, hash,
10124 + pkg->conflicts_str[i]);
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);
10137 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10139 + register int i, j;
10141 + if (!pkg->replaces_count)
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__);
10150 + // if (strcmp(ab_pkg->name, pkg->name))
10151 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
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]);
10156 + pkg->replaces[i] = old_abpkg;
10159 + if (!old_abpkg->replaced_by)
10160 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10161 + if ( old_abpkg->replaced_by == NULL ){
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);
10173 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10177 + compound_depend_t * depends;
10179 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
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__);
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;
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;
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;
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);
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]
10237 +char *pkg_depend_str(pkg_t *pkg, int index)
10239 + if (index < pkg->pre_depends_count) {
10240 + return pkg->pre_depends_str[index];
10242 + index -= pkg->pre_depends_count;
10244 + if (index < pkg->recommends_count) {
10245 + return pkg->recommends_str[index];
10247 + index -= pkg->recommends_count;
10249 + if (index < pkg->suggests_count) {
10250 + return pkg->suggests_str[index];
10252 + index -= pkg->suggests_count;
10254 + if (index < pkg->depends_count) {
10255 + return pkg->depends_str[index];
10257 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10261 +void freeDepends(pkg_t *pkg)
10265 + if (pkg == NULL || pkg->depends == NULL) {
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]);
10273 + free(pkg->depends->possibilities);
10274 + free(pkg->depends);
10275 + pkg->depends = NULL;
10278 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
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;
10286 + count = pkg->pre_depends_count + pkg->depends_count;
10287 + depends = pkg->depends;
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 *));
10300 + temp = ab_depend->depended_upon_by;
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;
10318 +static depend_t * depend_init(void)
10320 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10322 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10325 + d->constraint = NONE;
10326 + d->version = NULL;
10332 +static void depend_deinit(depend_t *d)
10337 +static int parseDepends(compound_depend_t *compound_depend,
10338 + hash_table_t * hash, char * depend_str)
10340 + char * pkg_name, buffer[2048];
10341 + int num_of_ors = 0;
10343 + register char * src, * dest;
10344 + depend_t ** possibilities;
10346 + /* first count the number of ored possibilities for satisfying dependency */
10347 + src = depend_str;
10349 + if(*src++ == '|')
10352 + compound_depend->type = DEPEND;
10354 + compound_depend->possibility_count = num_of_ors + 1;
10355 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10356 + if (!possibilities)
10358 + compound_depend->possibilities = possibilities;
10360 + src = depend_str;
10361 + for(i = 0; i < num_of_ors + 1; i++){
10362 + possibilities[i] = depend_init();
10363 + if (!possibilities[i])
10365 + /* gobble up just the name first */
10368 + !isspace(*src) &&
10372 + *dest++ = *src++;
10374 + pkg_name = trim_alloc(buffer);
10375 + if (pkg_name == NULL )
10378 + /* now look at possible version info */
10380 + /* skip to next chars */
10381 + if(isspace(*src))
10382 + while(*src && isspace(*src)) src++;
10384 + /* extract constraint and version */
10387 + if(!strncmp(src, "<<", 2)){
10388 + possibilities[i]->constraint = EARLIER;
10391 + else if(!strncmp(src, "<=", 2)){
10392 + possibilities[i]->constraint = EARLIER_EQUAL;
10395 + else if(!strncmp(src, ">=", 2)){
10396 + possibilities[i]->constraint = LATER_EQUAL;
10399 + else if(!strncmp(src, ">>", 2)){
10400 + possibilities[i]->constraint = LATER;
10403 + else if(!strncmp(src, "=", 1)){
10404 + possibilities[i]->constraint = EQUAL;
10407 + /* should these be here to support deprecated designations; dpkg does */
10408 + else if(!strncmp(src, "<", 1)){
10409 + possibilities[i]->constraint = EARLIER_EQUAL;
10412 + else if(!strncmp(src, ">", 1)){
10413 + possibilities[i]->constraint = LATER_EQUAL;
10417 + /* now we have any constraint, pass space to version string */
10418 + while(isspace(*src)) src++;
10420 + /* this would be the version string */
10422 + while(*src && *src != ')')
10423 + *dest++ = *src++;
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 )
10434 + /* hook up the dependency to its abstract pkg */
10435 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10439 + /* now get past the ) and any possible | chars */
10441 + (isspace(*src) ||
10447 + compound_depend->type = GREEDY_DEPEND;
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
10458 +/* pkg_depends.h - the itsy package management system
10462 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
10475 +#ifndef PKG_DEPENDS_H
10476 +#define PKG_DEPENDS_H
10479 +#include "pkg_hash.h"
10481 +enum depend_type {
10489 +typedef enum depend_type depend_type_t;
10491 +enum version_constraint {
10499 +typedef enum version_constraint version_constraint_t;
10502 + version_constraint_t constraint;
10504 + abstract_pkg_t * pkg;
10506 +typedef struct depend depend_t;
10508 +struct compound_depend{
10509 + depend_type_t type;
10510 + int possibility_count;
10511 + struct depend ** possibilities;
10513 +typedef struct compound_depend compound_depend_t;
10515 +#include "hash_table.h"
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);
10523 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10524 + * the same abstract package and 0 otherwise.
10526 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10529 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10532 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10535 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10538 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10541 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10544 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10547 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10550 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
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);
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
10567 +/* pkg_dest.c - the itsy package management system
10571 + Copyright (C) 2001 University of Southern California
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.
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.
10586 +#include "pkg_dest.h"
10587 +#include "file_util.h"
10588 +#include "str_util.h"
10589 +#include "sprintf_alloc.h"
10591 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10593 + dest->name = strdup(name);
10595 + /* Guarantee that dest->root_dir ends with a '/' */
10596 + if (str_ends_with(root_dir, "/")) {
10597 + dest->root_dir = strdup(root_dir);
10599 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10601 + file_mkdir_hier(dest->root_dir, 0755);
10603 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10604 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10605 + file_mkdir_hier(dest->ipkg_dir, 0755);
10607 + if (str_starts_with (lists_dir, "/"))
10608 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10610 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10612 + file_mkdir_hier(dest->lists_dir, 0755);
10614 + sprintf_alloc(&dest->info_dir, "%s/%s",
10615 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10616 + file_mkdir_hier(dest->info_dir, 0755);
10618 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10619 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10621 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10622 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10624 + dest->status_file = NULL;
10629 +void pkg_dest_deinit(pkg_dest_t *dest)
10631 + free(dest->name);
10632 + dest->name = NULL;
10634 + free(dest->root_dir);
10635 + dest->root_dir = NULL;
10637 + free(dest->ipkg_dir);
10638 + dest->ipkg_dir = NULL;
10640 + free(dest->lists_dir);
10641 + dest->lists_dir = NULL;
10643 + free(dest->info_dir);
10644 + dest->info_dir = NULL;
10646 + free(dest->status_file_name);
10647 + dest->status_file_name = NULL;
10649 + free(dest->status_file_tmp_name);
10650 + dest->status_file_tmp_name = NULL;
10652 + if (dest->status_file) {
10653 + fclose(dest->status_file);
10655 + dest->status_file = NULL;
10657 + dest->root_dir = NULL;
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
10663 +/* pkg_dest.h - the itsy package management system
10667 + Copyright (C) 2001 University of Southern California
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.
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.
10680 +#ifndef PKG_DEST_H
10681 +#define PKG_DEST_H
10683 +typedef struct pkg_dest pkg_dest_t;
10691 + char *status_file_name;
10692 + char *status_file_tmp_name;
10693 + FILE *status_file;
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);
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
10705 +/* pkg_dest_list.c - the itsy package management system
10709 + Copyright (C) 2001 University of Southern California
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.
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.
10724 +#include "pkg_dest.h"
10725 +#include "void_list.h"
10726 +#include "pkg_dest_list.h"
10728 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10730 + return void_list_elt_init((void_list_elt_t *) elt, data);
10733 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10735 + void_list_elt_deinit((void_list_elt_t *) elt);
10738 +int pkg_dest_list_init(pkg_dest_list_t *list)
10740 + return void_list_init((void_list_t *) list);
10743 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10745 + pkg_dest_list_elt_t *iter;
10746 + pkg_dest_t *pkg_dest;
10748 + for (iter = list->head; iter; iter = iter->next) {
10749 + pkg_dest = iter->data;
10750 + pkg_dest_deinit(pkg_dest);
10752 + /* malloced in pkg_dest_list_append */
10754 + iter->data = NULL;
10756 + void_list_deinit((void_list_t *) list);
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)
10763 + pkg_dest_t *pkg_dest;
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__);
10772 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10773 + err = void_list_append((void_list_t *) list, pkg_dest);
10781 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10783 + return void_list_push((void_list_t *) list, data);
10786 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10788 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
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
10794 +/* pkg_dest_list.h - the itsy package management system
10798 + Copyright (C) 2001 University of Southern California
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.
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.
10811 +#ifndef PKG_DEST_LIST_H
10812 +#define PKG_DEST_LIST_H
10814 +#include "pkg_dest.h"
10816 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10817 +struct pkg_dest_list_elt
10819 + pkg_dest_list_elt_t *next;
10820 + pkg_dest_t *data;
10823 +typedef struct pkg_dest_list pkg_dest_list_t;
10824 +struct pkg_dest_list
10826 + pkg_dest_list_elt_t pre_head;
10827 + pkg_dest_list_elt_t *head;
10828 + pkg_dest_list_elt_t *tail;
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);
10834 +int pkg_dest_list_init(pkg_dest_list_t *list);
10835 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
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);
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
10848 +/* pkg_extract.c - the itsy package management system
10852 + Copyright (C) 2001 University of Southern California
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.
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.
10866 +#include <errno.h>
10867 +#include <fcntl.h>
10868 +#include <stdio.h>
10870 +#include "pkg_extract.h"
10872 +#include "libbb.h"
10873 +#include "file_util.h"
10874 +#include "sprintf_alloc.h"
10875 +#include "unarchive.h"
10877 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10878 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10879 +#define IPKG_CONTROL_FILE "control"
10881 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10883 + archive_handle_t *archive;
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);
10901 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10903 + unsigned int size = strlen(archive->file_header->name) + 2;
10905 + if (archive->buffer == NULL) {
10906 + archive->buffer = xmalloc(size);
10907 + strcpy(archive->buffer, archive->file_header->name);
10909 + size += strlen(archive->buffer);
10910 + archive->buffer = xrealloc(archive->buffer, size);
10911 + strcat(archive->buffer, archive->file_header->name);
10913 + strcat(archive->buffer, "\n");
10914 + data_skip(archive);
10917 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10919 + archive_handle_t *archive;
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);
10940 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10942 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10945 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10947 + archive_handle_t *archive;
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);
10969 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10971 + archive_handle_t *archive;
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);
10993 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10996 + char *line, *data_file;
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);
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);
11014 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11021 + /* Fixup data file names by removing the initial '.' */
11024 + line = file_read_line_alloc(tmp);
11025 + if (line == NULL) {
11029 + data_file = line;
11030 + if (*data_file == '.') {
11034 + if (*data_file != '/') {
11035 + fputs("/", file);
11038 + /* I have no idea why, but this is what dpkg does */
11039 + if (strcmp(data_file, "/\n") == 0) {
11040 + fputs("/.\n", file);
11042 + fputs(data_file, file);
11052 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11054 + archive_handle_t *archive;
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);
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
11076 +/* pkg_extract.c - the itsy package management system
11080 + Copyright (C) 2001 University of Southern California
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.
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.
11093 +#ifndef PKG_EXTRACT_H
11094 +#define PKG_EXTRACT_H
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,
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);
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
11112 +/* pkg.h - the itsy package management system
11116 + Copyright (C) 2001 University of Southern California
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.
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.
11132 +#include <sys/types.h>
11133 +#include <sys/stat.h>
11134 +#include <unistd.h>
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"
11146 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11148 +/* I think "Size" is currently the shortest field name */
11149 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11151 +enum pkg_state_want
11157 + SW_LAST_STATE_WANT
11159 +typedef enum pkg_state_want pkg_state_want_t;
11161 +enum pkg_state_flag
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 */
11173 + SF_LAST_STATE_FLAG
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)
11178 +enum pkg_state_status
11180 + SS_NOT_INSTALLED = 1,
11182 + SS_HALF_CONFIGURED,
11184 + SS_HALF_INSTALLED,
11186 + SS_POST_INST_FAILED,
11187 + SS_REMOVAL_FAILED,
11188 + SS_LAST_STATE_STATUS
11190 +typedef enum pkg_state_status pkg_state_status_t;
11192 +struct abstract_pkg{
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;
11203 +#include "pkg_depends.h"
11205 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
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.
11212 + The 3 state fields could possibly also go into their own struct.
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
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. */
11228 + unsigned long epoch;
11231 + char *familiar_revision;
11233 + pkg_dest_t *dest;
11234 + char *architecture;
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;
11251 + /* Abhaya: new conflicts */
11252 + char **conflicts_str;
11253 + compound_depend_t * conflicts;
11254 + int conflicts_count;
11256 + char **replaces_str;
11257 + int replaces_count;
11258 + abstract_pkg_t ** replaces;
11260 + char **provides_str;
11261 + int provides_count;
11262 + abstract_pkg_t ** provides;
11264 + abstract_pkg_t *parent;
11266 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11269 + char *local_filename;
11271 + char *tmp_unpack_dir;
11274 + char *installed_size;
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;
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;
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);
11300 + * merges fields from newpkg into oldpkg.
11301 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11303 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11305 +char *pkg_version_str_alloc(pkg_t *pkg);
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);
11311 +char * pkg_formatted_info(pkg_t *pkg );
11312 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11314 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
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);
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);
11334 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
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);
11340 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11341 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
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
11348 +/* ipkg_hash.c - the itsy package management system
11352 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
11366 +#include <errno.h>
11367 +#include <ctype.h>
11368 +#include <stdlib.h>
11369 +#include <string.h>
11371 +#include "hash_table.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"
11379 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11382 + * this will talk to both feeds-lists files and installed status files
11385 + * hash_table_t hash;
11386 + * pkg_hash_init(name, &hash, 1000);
11387 + * pkg_hash_add_from_file(<feed filename>);
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
11393 + * modified: CDW 3 Jan. 2002
11398 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11400 + return hash_table_init(name, hash, len);
11403 +void pkg_hash_deinit(hash_table_t *hash)
11405 + hash_table_deinit(hash);
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)
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 */
11416 + l = conf->arch_list.head;
11419 + nv_pair_t *nv = l->data;
11420 + int priority = strtol(nv->value, NULL, 0);
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;
11432 + return strdup(def_arch);
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)
11438 + hash_table_t *hash = &conf->pkg_hash;
11440 + char **raw_start;
11443 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11447 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
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);
11460 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11466 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11467 + memory after read_raw_pkgs_from_file */
11476 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11478 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11481 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11483 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11486 + return apkg->provided_by;
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)
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;
11506 + if (matching_apkgs == NULL || providers == NULL ||
11507 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11510 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
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);
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);
11524 + nprovides = providers->len;
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;
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);
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);
11543 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11544 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11547 + provider_apkg = replacement_apkg;
11550 + if (!(vec = provider_apkg->pkgs)) {
11551 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11556 + /* now check for supported architecture */
11558 + int max_count = 0;
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) {
11568 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11569 + pkg_vec_insert(matching_pkgs, maybe);
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);
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*/
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 */
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)) {
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;
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);
11621 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
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);
11634 + nmatching = matching_apkgs->len;
11636 + pkg_vec_free(matching_pkgs);
11637 + abstract_pkg_vec_free(matching_apkgs);
11638 + abstract_pkg_vec_free(providers);
11640 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11641 + return good_pkg_by_name;
11644 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
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;
11651 + if (nmatching > 1) {
11652 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
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;
11663 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11665 + const char *name = (const char *)cdata;
11666 + if (strcmp(pkg->name, name) == 0)
11672 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11674 + hash_table_t *hash = &conf->pkg_hash;
11675 + abstract_pkg_t *apkg = NULL;
11677 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11680 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11684 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11685 + const char *pkg_name,
11686 + const char * version)
11690 + char *version_str = NULL;
11692 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
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);
11701 + free(version_str);
11704 + if(i == vec->len)
11707 + return vec->pkgs[i];
11710 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11711 + const char *pkg_name,
11712 + pkg_dest_t *dest)
11717 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
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];
11728 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11729 + const char *pkg_name)
11734 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
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];
11746 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11748 + abstract_pkg_t * ab_pkg;
11750 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
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;
11761 + return ab_pkg->pkgs;
11768 +static int pkg_compare_names(const void *p1, const void *p2)
11770 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11771 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11772 + if (pkg1->name == NULL)
11774 + if (pkg2->name == NULL)
11776 + return(strcmp(pkg1->name, pkg2->name));
11780 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
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;
11787 + for (j = 0; j < pkg_vec->len; j++) {
11788 + pkg_t *pkg = pkg_vec->pkgs[j];
11789 + pkg_vec_insert(all, pkg);
11794 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11796 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11797 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11800 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
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;
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);
11815 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11817 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11818 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11821 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
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);
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;
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);
11841 + while (i < pkg->depends_count)
11842 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11845 +void pkg_hash_dump(hash_table_t *hash, void *data)
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__);
11853 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11855 + abstract_pkg_t * ab_pkg;
11857 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11858 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11863 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11865 + abstract_pkg_t * ab_pkg;
11866 + int arch_priority;
11871 + arch_priority = pkg->arch_priority;
11873 + if (buildDepends(hash, pkg)<0){
11874 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11877 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
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;
11887 + if(!ab_pkg->pkgs)
11888 + ab_pkg->pkgs = pkg_vec_alloc();
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;
11894 + if (buildProvides(hash, ab_pkg, pkg)<0){
11895 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
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__);
11903 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11904 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11908 + buildDependedUponBy(pkg, ab_pkg);
11913 + * this will assume that we've already determined that
11914 + * the abstract pkg doesn't exist, 'cause we should know these things...
11916 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11918 + abstract_pkg_t * ab_pkg;
11920 + ab_pkg = abstract_pkg_new();
11921 + if (ab_pkg == NULL) { return NULL; }
11923 + ab_pkg->name = strdup(pkg_name);
11924 + hash_table_insert(hash, pkg_name, ab_pkg);
11930 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11932 + hash_table_t *file_hash = &conf->file_hash;
11934 + return hash_table_get(file_hash, file_name);
11937 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
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);
11943 + if (file_name[file_name_len -1] == '/')
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;
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;
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
11969 +/* pkg_hash.h - the itsy package management system
11973 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
11986 +#ifndef PKG_HASH_H
11987 +#define PKG_HASH_H
11990 +#include "pkg_vec.h"
11991 +#include "hash_table.h"
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);
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);
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);
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);
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);
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);
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
12034 +/* pkg_parse.c - the itsy package management system
12038 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
12052 +#include <errno.h>
12053 +#include <ctype.h>
12056 +#include "ipkg_utils.h"
12057 +#include "pkg_parse.h"
12059 +int isGenericFieldType(char * type, char * line)
12061 + if(!strncmp(line, type, strlen(type)))
12066 +char * parseGenericFieldType(char * type, char * raw)
12068 + char * field_value = raw + (strlen(type) + 1);
12069 + return trim_alloc(field_value);
12072 +void parseStatus(pkg_t *pkg, char * raw)
12074 + char sw_str[64], sf_str[64], ss_str[64];
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);
12082 +char ** parseDependsString(char * raw, int * depends_count)
12084 + char ** depends = NULL;
12085 + int line_count = 0;
12086 + char buff[2048], * dest;
12088 + while(raw && *raw && !isspace(*raw)) {
12092 + if(line_is_blank(raw)){
12093 + *depends_count = line_count;
12096 + while(raw && *raw){
12097 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12099 + while(isspace(*raw)) raw++;
12102 + while((*raw != ',') && *raw)
12103 + *dest++ = *raw++;
12106 + depends[line_count] = trim_alloc(buff);
12107 + if(depends[line_count] ==NULL)
12113 + *depends_count = line_count;
12117 +void parseConffiles(pkg_t * pkg, char * raw)
12119 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12121 + if(!strncmp(raw, "Conffiles:", 10))
12122 + raw += strlen("Conffiles:");
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)) {
12130 + raw += strlen(file_name);
12131 + while (*raw && isspace(*raw)) {
12134 + raw += strlen(md5sum);
12138 +int parseVersion(pkg_t *pkg, char *raw)
12140 + char *colon, *eepochcolon;
12141 +#ifdef USE_DEBVERSION
12144 + unsigned long epoch;
12147 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12151 + if (strncmp(raw, "Version:", 8) == 0) {
12154 + while (*raw && isspace(*raw)) {
12158 + colon= strchr(raw,':');
12160 + epoch= strtoul(raw,&eepochcolon,10);
12161 + if (colon != eepochcolon) {
12162 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12166 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12170 + pkg->epoch= epoch;
12175 + pkg->revision = "";
12176 + pkg->familiar_revision = "";
12178 + pkg->version= malloc(strlen(raw)+1);
12179 + if ( pkg->version == NULL ) {
12180 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12183 + strcpy(pkg->version, raw);
12185 +#ifdef USE_DEBVERSION
12186 + hyphen= strrchr(pkg->version,'-');
12190 + if (strncmp("fam", hyphen, 3) == 0) {
12191 + pkg->familiar_revision=hyphen+3;
12192 + hyphen= strrchr(pkg->version,'-');
12195 + pkg->revision = hyphen;
12198 + pkg->revision = hyphen;
12204 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12208 + pkg->familiar_revision);
12215 +/* This code is needed to insert in first position the keyword for the aligning bug */
12217 +int alterProvidesLine(char *raw, char *temp)
12222 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12226 + if ( temp == NULL ) {
12227 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12231 + if (strncmp(raw, "Provides:", 9) == 0) {
12234 + while (*raw && isspace(*raw)) {
12238 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12240 + strncat( temp, raw++, 1);
12246 +/* Some random thoughts from Carl:
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).
12254 + Fields which require special parsing or storage, (such as Depends:
12255 + and Status:) could be handled as they are now.
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.
12263 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12265 + int reading_conffiles, reading_description;
12266 + int pkg_false_provides=1;
12268 + char * provide=NULL;
12271 + pkg->dest = dest;
12273 + reading_conffiles = reading_description = 0;
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;
12308 + free(essential_value);
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;
12320 + else if(isGenericFieldType("Description", *lines)) {
12321 + pkg->description = parseGenericFieldType("Description", *lines);
12322 + reading_conffiles = 0;
12323 + reading_description = 1;
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) ){
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;
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)) {
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));
12366 + else if(reading_conffiles)
12367 + parseConffiles(pkg, *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);
12382 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
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;
12393 + free(essential_value);
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
12404 +/* pkg_parse.h - the itsy package management system
12408 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
12421 +#ifndef PKG_PARSE_H
12422 +#define PKG_PARSE_H
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);
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
12439 +/* pkg_src.c - the itsy package management system
12443 + Copyright (C) 2001 University of Southern California
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.
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.
12458 +#include "pkg_src.h"
12459 +#include "str_util.h"
12461 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12463 + src->gzip = gzip;
12464 + src->name = str_dup_safe (name);
12465 + src->value = str_dup_safe (base_url);
12467 + src->extra_data = str_dup_safe (extra_data);
12469 + src->extra_data = NULL;
12473 +void pkg_src_deinit(pkg_src_t *src)
12475 + free (src->name);
12476 + free (src->value);
12477 + if (src->extra_data)
12478 + free (src->extra_data);
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
12486 +/* pkg_src.h - the itsy package management system
12490 + Copyright (C) 2001 University of Southern California
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.
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.
12506 +#include "nv_pair.h"
12512 + char *extra_data;
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);
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
12524 +/* pkg_src_list.c - the itsy package management system
12528 + Copyright (C) 2001 University of Southern California
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.
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.
12543 +#include "pkg_src_list.h"
12544 +#include "void_list.h"
12546 +int pkg_src_list_init(pkg_src_list_t *list)
12548 + return void_list_init((void_list_t *) list);
12551 +void pkg_src_list_deinit(pkg_src_list_t *list)
12553 + pkg_src_list_elt_t *iter;
12554 + pkg_src_t *pkg_src;
12556 + for (iter = list->head; iter; iter = iter->next) {
12557 + pkg_src = iter->data;
12558 + pkg_src_deinit(pkg_src);
12560 + /* malloced in pkg_src_list_append */
12562 + iter->data = NULL;
12564 + void_list_deinit((void_list_t *) list);
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,
12573 + /* freed in pkg_src_list_deinit */
12574 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12576 + if (pkg_src == NULL) {
12577 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12580 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12582 + err = void_list_append((void_list_t *) list, pkg_src);
12590 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12592 + return void_list_push((void_list_t *) list, data);
12595 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12597 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
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
12603 +/* pkg_src_list.h - the itsy package management system
12607 + Copyright (C) 2001 University of Southern California
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.
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.
12620 +#ifndef PKG_SRC_LIST_H
12621 +#define PKG_SRC_LIST_H
12623 +#include "pkg_src.h"
12625 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12626 +struct pkg_src_list_elt
12628 + pkg_src_list_elt_t *next;
12632 +typedef struct pkg_src_list pkg_src_list_t;
12633 +struct pkg_src_list
12635 + pkg_src_list_elt_t pre_head;
12636 + pkg_src_list_elt_t *head;
12637 + pkg_src_list_elt_t *tail;
12640 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12642 + if (list->head == NULL)
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);
12651 +int pkg_src_list_init(pkg_src_list_t *list);
12652 +void pkg_src_list_deinit(pkg_src_list_t *list);
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);
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
12664 +/* pkg_vec.c - the itsy package management system
12668 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
12681 +#include <stdlib.h>
12682 +#include <fnmatch.h>
12683 +#include "xregex.h"
12687 +pkg_vec_t * pkg_vec_alloc(void)
12689 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12691 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12694 + vec->pkgs = NULL;
12700 +void pkg_vec_free(pkg_vec_t *vec)
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
12712 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
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)) {
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);
12732 + /* we didn't find one, add it */
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);
12737 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12738 + vec->pkgs[vec->len] = pkg;
12742 + /* update the one that we have */
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. */
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;
12761 + return vec->pkgs[i];
12765 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
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)) {
12779 + /* we didn't find one, add it */
12781 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12782 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12787 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12790 + for (i = 0; i < vec->len; i++)
12791 + if (vec->pkgs[i] == apkg)
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 *))
12799 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12802 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12804 + int npkgs = vec->len;
12806 + for (i = 0; i < npkgs; i++) {
12807 + pkg_t *pkg = vec->pkgs[i];
12808 + pkg->state_flag &= ~SF_MARKED;
12813 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12815 + int matching_count = 0;
12816 + pkg_t **pkgs = vec->pkgs;
12817 + int npkgs = vec->len;
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++;
12826 + return matching_count;
12830 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12832 + abstract_pkg_vec_t * vec ;
12833 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12835 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12838 + vec->pkgs = NULL;
12844 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12851 + * assumption: all names in a vector are unique
12853 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
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)
12862 + /* we didn't find one, add it */
12863 + if(i == vec->len){
12865 + (abstract_pkg_t **)
12866 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12867 + vec->pkgs[vec->len] = pkg;
12872 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12874 + if (vec->len > i)
12875 + return vec->pkgs[i];
12880 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12883 + for (i = 0; i < vec->len; i++)
12884 + if (vec->pkgs[i] == apkg)
12889 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12891 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
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
12898 +/* pkg_vec.h - the itsy package management system
12902 + Copyright (C) 2002 Compaq Computer Corporation
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.
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.
12918 +typedef struct pkg pkg_t;
12919 +typedef struct abstract_pkg abstract_pkg_t;
12926 +typedef struct pkg_vec pkg_vec_t;
12928 +struct abstract_pkg_vec
12930 + abstract_pkg_t **pkgs;
12933 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
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);
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 *));
12949 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12950 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
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 *));
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
12964 +/* sprintf_alloca.c -- like sprintf with memory allocation
12968 + Copyright (C) 2001 University of Southern California
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.
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.
12981 +#ifndef SPRINTF_ALLOC_H
12982 +#define SPRINTF_ALLOC_H
12984 +#include "libbb.h"
12986 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
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
12993 +/* str_list.c - the itsy package management system
12997 + Copyright (C) 2001 University of Southern California
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.
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.
13012 +#include "str_list.h"
13014 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13016 + return void_list_elt_init((void_list_elt_t *) elt, data);
13019 +void str_list_elt_deinit(str_list_elt_t *elt)
13021 + void_list_elt_deinit((void_list_elt_t *) elt);
13024 +str_list_t *str_list_alloc()
13026 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13028 + str_list_init(list);
13032 +int str_list_init(str_list_t *list)
13034 + return void_list_init((void_list_t *) list);
13037 +void str_list_deinit(str_list_t *list)
13039 + void_list_deinit((void_list_t *) list);
13042 +int str_list_append(str_list_t *list, char *data)
13044 + return void_list_append((void_list_t *) list, data);
13047 +int str_list_push(str_list_t *list, char *data)
13049 + return void_list_push((void_list_t *) list, data);
13052 +str_list_elt_t *str_list_pop(str_list_t *list)
13054 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13057 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13059 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13060 + (void_list_elt_t **) iter);
13063 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13065 + return (char *)void_list_remove_elt((void_list_t *) list,
13066 + (void *)target_str,
13067 + (void_list_cmp_t)strcmp);
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
13073 +/* str_list.h - the itsy package management system
13077 + Copyright (C) 2001 University of Southern California
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.
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.
13090 +#ifndef STR_LIST_H
13091 +#define STR_LIST_H
13093 +#include "void_list.h"
13095 +typedef struct str_list_elt str_list_elt_t;
13096 +struct str_list_elt
13098 + str_list_elt_t *next;
13102 +typedef struct xstr_list str_list_t;
13105 + str_list_elt_t pre_head;
13106 + str_list_elt_t *head;
13107 + str_list_elt_t *tail;
13110 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13111 +void str_list_elt_deinit(str_list_elt_t *elt);
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);
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);
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
13128 +/* str_utils.c - the itsy package management system
13132 + Copyright (C) 2001 University of Southern California
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.
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.
13147 +int str_starts_with(const char *str, const char *prefix)
13149 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13152 +int str_ends_with(const char *str, const char *suffix)
13157 + str_len = strlen(str);
13158 + suffix_len = strlen(suffix);
13160 + if (str_len < suffix_len) {
13164 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13167 +int str_chomp(char *str)
13169 + if (str[strlen(str) - 1] == '\n') {
13170 + str[strlen(str) - 1] = '\0';
13176 +int str_tolower(char *str)
13179 + *str = tolower(*str);
13186 +int str_toupper(char *str)
13189 + *str = toupper(*str);
13196 +char *str_dup_safe(const char *str)
13198 + return str ? strdup(str) : NULL;
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
13205 +/* str_utils.h - the itsy package management system
13209 + Copyright (C) 2001 University of Southern California
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.
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.
13222 +#ifndef STR_UTILS_H
13223 +#define STR_UTILS_H
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);
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
13237 +/* user.c - the itsy package management system
13241 + Copyright (C) 2002 Hewlett Packard Company
13242 + Copyright (C) 2001 University of Southern California
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.
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.
13255 +#include <stdio.h>
13256 +#include <stdarg.h>
13257 +#include "file_util.h"
13258 +#include "str_util.h"
13260 +#include "libipkg.h"
13265 +static char *question = NULL;
13266 +static int question_len = 255;
13268 +char *get_user_response(const char *format, ...)
13270 + int len = question_len;
13273 + va_start(ap, format);
13276 + vprintf(format, ap);
13278 + response = file_read_line_alloc(stdin);
13279 + } while (response == NULL);
13282 + if (question == NULL || len > question_len) {
13283 + question = realloc(question, len + 1);
13284 + question_len = len;
13286 + len = vsnprintf(question,question_len,format,ap);
13287 + } while (len > question_len);
13288 + response = strdup(ipkg_cb_response(question));
13290 + str_chomp(response);
13291 + str_tolower(response);
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
13299 +/* user.c - the itsy package management system
13303 + Copyright (C) 2002 Hewlett Packard Company
13304 + Copyright (C) 2001 University of Southern California
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.
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.
13317 +#include <stdio.h>
13318 +#include <stdarg.h>
13320 +char *get_user_response(const char *format, ...);
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
13326 +/* void_list.c - the itsy package management system
13330 + Copyright (C) 2001 University of Southern California
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.
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.
13344 +#include <errno.h>
13346 +#include "void_list.h"
13348 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13350 + elt->next = NULL;
13351 + elt->data = data;
13356 +void void_list_elt_deinit(void_list_elt_t *elt)
13358 + void_list_elt_init(elt, NULL);
13361 +int void_list_init(void_list_t *list)
13363 + void_list_elt_init(&list->pre_head, NULL);
13364 + list->head = NULL;
13365 + list->pre_head.next = list->head;
13366 + list->tail = NULL;
13371 +void void_list_deinit(void_list_t *list)
13373 + void_list_elt_t *elt;
13375 + while (list->head) {
13376 + elt = void_list_pop(list);
13377 + void_list_elt_deinit(elt);
13378 + /* malloced in void_list_append */
13383 +int void_list_append(void_list_t *list, void *data)
13385 + void_list_elt_t *elt;
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__);
13394 + void_list_elt_init(elt, data);
13396 + if (list->tail) {
13397 + list->tail->next = elt;
13398 + list->tail = elt;
13400 + list->head = elt;
13401 + list->pre_head.next = list->head;
13402 + list->tail = elt;
13408 +int void_list_push(void_list_t *list, void *data)
13410 + void_list_elt_t *elt;
13412 + elt = malloc(sizeof(void_list_elt_t));
13413 + if (elt == NULL) {
13414 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13418 + void_list_elt_init(elt, data);
13420 + elt->next = list->head;
13421 + list->head->next = elt;
13422 + if (list->tail == NULL) {
13423 + list->tail = list->head;
13429 +void_list_elt_t *void_list_pop(void_list_t *list)
13431 + void_list_elt_t *elt;
13433 + elt = list->head;
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;
13446 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13448 + void_list_elt_t *prior;
13449 + void_list_elt_t *old_elt;
13453 + old_data = old_elt->data;
13455 + if (old_elt == list->head) {
13456 + prior = &list->pre_head;
13457 + void_list_pop(list);
13459 + for (prior = list->head; prior; prior = prior->next) {
13460 + if (prior->next == old_elt) {
13464 + if (prior == NULL || prior->next != old_elt) {
13465 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13468 + prior->next = old_elt->next;
13470 + if (old_elt == list->tail) {
13471 + list->tail = prior;
13475 + void_list_elt_deinit(old_elt);
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)
13484 + void_list_elt_t *prior;
13485 + void_list_elt_t *old_elt = NULL;
13486 + void *old_data = NULL;
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);
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;
13506 + prior->next = old_elt->next;
13508 + if (old_elt == list->tail) {
13509 + list->tail = prior;
13513 + void_list_elt_deinit(old_elt);
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
13524 +/* void_list.h - the itsy package management system
13528 + Copyright (C) 2001 University of Southern California
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.
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.
13541 +#ifndef VOID_LIST_H
13542 +#define VOID_LIST_H
13544 +typedef struct void_list_elt void_list_elt_t;
13545 +struct void_list_elt
13547 + void_list_elt_t *next;
13551 +typedef struct void_list void_list_t;
13554 + void_list_elt_t pre_head;
13555 + void_list_elt_t *head;
13556 + void_list_elt_t *tail;
13559 +static inline int void_list_empty(void_list_t *list)
13561 + if (list->head == NULL)
13567 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13568 +void void_list_elt_deinit(void_list_elt_t *elt);
13570 +int void_list_init(void_list_t *list);
13571 +void void_list_deinit(void_list_t *list);
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);
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);
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
13587 +/* xsystem.c - system(3) with error messages
13591 + Copyright (C) 2001 University of Southern California
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.
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.
13605 +#include <sys/wait.h>
13607 +#include "xsystem.h"
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.
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:
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>.
13623 +int xsystem(const char *cmd)
13627 + err = system(cmd);
13630 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13631 + __FUNCTION__, cmd);
13635 + if (WIFSIGNALED(err)) {
13636 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13637 + __FUNCTION__, WTERMSIG(err), cmd);
13641 + if (WIFEXITED(err)) {
13642 + /* Normal child exit */
13643 + return WEXITSTATUS(err);
13646 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13647 + __FUNCTION__, err);
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
13655 +/* xsystem.h - system(3) with error messages
13659 + Copyright (C) 2001 University of Southern California
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.
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.
13675 +#include <stdlib.h>
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:
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>.
13685 +int xsystem(const char *cmd);
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);
13697 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13699 + char *name_ptr = archive_handle->file_header->name;
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);
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
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
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);
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"
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" \
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" \
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" \
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" \
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" \
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"
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 @@
13836 + archival/libipkg/ \
13837 archival/libunarchive/ \