1 diff -ruN busybox-1.1.1-old/Makefile busybox-1.1.1-new/Makefile
2 --- busybox-1.1.1-old/Makefile 2006-03-22 22:16:26.000000000 +0100
3 +++ busybox-1.1.1-new/Makefile 2006-03-30 00:39:48.000000000 +0200
5 export srctree=$(top_srcdir)
6 vpath %/Config.in $(srctree)
8 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
9 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
10 debianutils editors findutils init miscutils modutils networking \
11 networking/libiproute networking/udhcp procps loginutils shell \
12 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
13 diff -ruN busybox-1.1.1-old/archival/Config.in busybox-1.1.1-new/archival/Config.in
14 --- busybox-1.1.1-old/archival/Config.in 2006-03-22 22:16:20.000000000 +0100
15 +++ busybox-1.1.1-new/archival/Config.in 2006-03-30 00:39:48.000000000 +0200
17 gzip is used to compress files.
18 It's probably the most widely used UNIX compression program.
23 + select CONFIG_MD5SUM
26 + ipkg is the itsy package management system.
28 config CONFIG_RPM2CPIO
31 diff -ruN busybox-1.1.1-old/archival/Makefile.in busybox-1.1.1-new/archival/Makefile.in
32 --- busybox-1.1.1-old/archival/Makefile.in 2006-03-22 22:16:20.000000000 +0100
33 +++ busybox-1.1.1-new/archival/Makefile.in 2006-03-30 00:39:48.000000000 +0200
35 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
36 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
37 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
38 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
39 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
40 ARCHIVAL-$(CONFIG_RPM) += rpm.o
41 ARCHIVAL-$(CONFIG_TAR) += tar.o
42 diff -ruN busybox-1.1.1-old/archival/dpkg.c busybox-1.1.1-new/archival/dpkg.c
43 --- busybox-1.1.1-old/archival/dpkg.c 2006-03-22 22:16:20.000000000 +0100
44 +++ busybox-1.1.1-new/archival/dpkg.c 2006-03-30 00:39:48.000000000 +0200
45 @@ -1530,6 +1530,10 @@
46 return(ar_handle->sub_archive->buffer);
51 +// moved to data_extract_all.c
53 static void data_extract_all_prefix(archive_handle_t *archive_handle)
55 char *name_ptr = archive_handle->file_header->name;
62 static void unpack_package(deb_file_t *deb_file)
64 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
65 diff -ruN busybox-1.1.1-old/archival/ipkg.c busybox-1.1.1-new/archival/ipkg.c
66 --- busybox-1.1.1-old/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
67 +++ busybox-1.1.1-new/archival/ipkg.c 2006-03-30 00:39:48.000000000 +0200
69 +/* ipkg.c - the itsy package management system
73 + Copyright (C) 2003 kernel concepts
75 + This program is free software; you can redistribute it and/or
76 + modify it under the terms of the GNU General Public License as
77 + published by the Free Software Foundation; either version 2, or (at
78 + your option) any later version.
80 + This program is distributed in the hope that it will be useful, but
81 + WITHOUT ANY WARRANTY; without even the implied warranty of
82 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83 + General Public License for more details.
85 + ipkg command line frontend using libipkg
89 +#include "libipkg/libipkg.h"
91 +int ipkg_main(int argc, char **argv)
93 + return ipkg_op(argc, argv);
95 diff -ruN busybox-1.1.1-old/archival/libipkg/Makefile busybox-1.1.1-new/archival/libipkg/Makefile
96 --- busybox-1.1.1-old/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
97 +++ busybox-1.1.1-new/archival/libipkg/Makefile 2006-03-30 00:39:48.000000000 +0200
99 +# Makefile for busybox
101 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
103 +# This program is free software; you can redistribute it and/or modify
104 +# it under the terms of the GNU General Public License as published by
105 +# the Free Software Foundation; either version 2 of the License, or
106 +# (at your option) any later version.
108 +# This program is distributed in the hope that it will be useful,
109 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
110 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
111 +# General Public License for more details.
113 +# You should have received a copy of the GNU General Public License
114 +# along with this program; if not, write to the Free Software
115 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
120 +srcdir=$(top_srcdir)/archival/libipkg
122 +include $(top_builddir)/Rules.mak
123 +include $(top_builddir)/.config
124 +include $(srcdir)/Makefile.in
126 +-include $(top_builddir)/.depend
129 + rm -f *.o *.a $(AR_TARGET)
131 diff -ruN busybox-1.1.1-old/archival/libipkg/Makefile.in busybox-1.1.1-new/archival/libipkg/Makefile.in
132 --- busybox-1.1.1-old/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
133 +++ busybox-1.1.1-new/archival/libipkg/Makefile.in 2006-03-30 01:14:50.000000000 +0200
135 +# Makefile for busybox
137 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
139 +# This program is free software; you can redistribute it and/or modify
140 +# it under the terms of the GNU General Public License as published by
141 +# the Free Software Foundation; either version 2 of the License, or
142 +# (at your option) any later version.
144 +# This program is distributed in the hope that it will be useful,
145 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
146 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
147 +# General Public License for more details.
149 +# You should have received a copy of the GNU General Public License
150 +# along with this program; if not, write to the Free Software
151 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
154 +LIBIPKG_AR:=libipkg.a
155 +ifndef $(LIBIPKG_DIR)
156 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
158 +srcdir=$(top_srcdir)/archival/libipkg
160 +LIBIPKG_CORE_SOURCES:= \
165 +LIBIPKG_CMD_SOURCES:= \
173 +LIBIPKG_DB_SOURCES:= \
184 +LIBIPKG_LIST_SOURCES:= \
196 +LIBIPKG_UTIL_SOURCES:= \
203 +LIBIPKG-y += $(LIBIPKG_CORE_SOURCES)
204 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
205 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
206 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_UTIL_SOURCES)
208 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
210 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
212 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
214 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
217 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
220 diff -ruN busybox-1.1.1-old/archival/libipkg/args.c busybox-1.1.1-new/archival/libipkg/args.c
221 --- busybox-1.1.1-old/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
222 +++ busybox-1.1.1-new/archival/libipkg/args.c 2006-03-30 00:39:48.000000000 +0200
224 +/* args.c - parse command-line args
228 + Copyright 2001 University of Southern California
230 + This program is free software; you can redistribute it and/or modify
231 + it under the terms of the GNU General Public License as published by
232 + the Free Software Foundation; either version 2, or (at your option)
235 + This program is distributed in the hope that it will be useful,
236 + but WITHOUT ANY WARRANTY; without even the implied warranty of
237 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238 + GNU General Public License for more details.
247 +#include "ipkg_message.h"
250 +#include "sprintf_alloc.h"
255 +static void print_version(void);
259 + ARGS_OPT_FORCE_DEFAULTS = 129,
260 + ARGS_OPT_FORCE_DEPENDS,
261 + ARGS_OPT_FORCE_OVERWRITE,
262 + ARGS_OPT_FORCE_DOWNGRADE,
263 + ARGS_OPT_FORCE_REINSTALL,
264 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
265 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
266 + ARGS_OPT_FORCE_SPACE,
269 + ARGS_OPT_VERBOSE_WGET,
270 + ARGS_OPT_VERBOSITY,
271 + ARGS_OPT_MULTIPLE_PROVIDERS
274 +int args_init(args_t *args)
276 + char *conf_file_dir;
278 + memset(args, 0, sizeof(args_t));
280 + args->dest = ARGS_DEFAULT_DEST;
282 + conf_file_dir = getenv("IPKG_CONF_DIR");
283 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
284 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
286 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
287 + ARGS_DEFAULT_CONF_FILE_NAME);
289 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
290 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
291 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
292 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
293 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
294 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
295 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
296 + args->noaction = ARGS_DEFAULT_NOACTION;
297 + args->nodeps = ARGS_DEFAULT_NODEPS;
298 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
299 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
300 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
301 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
302 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
303 + args->multiple_providers = 0;
304 + args->nocheckfordirorfile = 0;
309 +void args_deinit(args_t *args)
311 + free(args->conf_file);
312 + args->conf_file = NULL;
315 +int args_parse(args_t *args, int argc, char *argv[])
318 + int option_index = 0;
320 + static struct option long_options[] = {
321 + {"query-all", 0, 0, 'A'},
322 + {"conf-file", 1, 0, 'f'},
323 + {"conf", 1, 0, 'f'},
324 + {"dest", 1, 0, 'd'},
325 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
326 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
327 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
328 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
329 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
330 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
331 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
332 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
333 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
334 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
335 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
336 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
337 + {"recursive", 0, 0,
338 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
339 + {"force-removal-of-dependent-packages", 0, 0,
340 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
341 + {"force_removal_of_dependent_packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
343 + {"force-removal-of-essential-packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"force_removal_of_essential_packages", 0, 0,
346 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
347 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
348 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
349 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
350 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
351 + {"offline", 1, 0, 'o'},
352 + {"offline-root", 1, 0, 'o'},
353 + {"test", 0, 0, ARGS_OPT_NOACTION},
354 + {"tmp-dir", 1, 0, 't'},
355 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
356 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
357 + {"verbosity", 2, 0, 'V'},
358 + {"version", 0, 0, 'v'},
363 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
369 + args->query_all = 1;
372 + args->dest = optarg;
375 + free(args->conf_file);
376 + args->conf_file = strdup(optarg);
379 + args->offline_root = optarg;
382 + args->noaction = 1;
385 + args->tmp_dir = strdup(optarg);
391 + case ARGS_OPT_VERBOSITY:
393 + args->verbosity = atoi(optarg);
395 + args->verbosity += 1;
397 + case ARGS_OPT_FORCE_DEFAULTS:
398 + args->force_defaults = 1;
400 + case ARGS_OPT_FORCE_DEPENDS:
401 + args->force_depends = 1;
403 + case ARGS_OPT_FORCE_OVERWRITE:
404 + args->force_overwrite = 1;
406 + case ARGS_OPT_FORCE_DOWNGRADE:
407 + args->force_downgrade = 1;
409 + case ARGS_OPT_FORCE_REINSTALL:
410 + args->force_reinstall = 1;
412 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
413 + args->force_removal_of_essential_packages = 1;
415 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
416 + args->force_removal_of_dependent_packages = 1;
418 + case ARGS_OPT_FORCE_SPACE:
419 + args->force_space = 1;
421 + case ARGS_OPT_VERBOSE_WGET:
422 + args->verbose_wget = 1;
424 + case ARGS_OPT_MULTIPLE_PROVIDERS:
425 + args->multiple_providers = 1;
427 + case ARGS_OPT_NODEPS:
430 + case ARGS_OPT_NOACTION:
431 + args->noaction = 1;
440 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
451 +void args_usage(char *complaint)
454 + bb_error_msg("%s\n", complaint);
461 +static void print_version(void)
463 + bb_error_msg("version %s\n", IPKG_VERSION);
465 diff -ruN busybox-1.1.1-old/archival/libipkg/args.h busybox-1.1.1-new/archival/libipkg/args.h
466 --- busybox-1.1.1-old/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
467 +++ busybox-1.1.1-new/archival/libipkg/args.h 2006-03-30 00:39:48.000000000 +0200
469 +/* args.h - parse command-line args
473 + Copyright 2001 University of Southern California
475 + This program is free software; you can redistribute it and/or modify
476 + it under the terms of the GNU General Public License as published by
477 + the Free Software Foundation; either version 2, or (at your option)
480 + This program is distributed in the hope that it will be useful,
481 + but WITHOUT ANY WARRANTY; without even the implied warranty of
482 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
483 + GNU General Public License for more details.
494 + int force_defaults;
496 + int force_overwrite;
497 + int force_downgrade;
498 + int force_reinstall;
499 + int force_removal_of_essential_packages;
500 + int force_removal_of_dependent_packages;
504 + int multiple_providers;
508 + int nocheckfordirorfile;
509 + char *offline_root;
510 + char *offline_root_pre_script_cmd;
511 + char *offline_root_post_script_cmd;
513 +typedef struct args args_t;
515 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
516 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
517 +#define ARGS_DEFAULT_DEST NULL
518 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
519 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
520 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
521 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
522 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
523 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
524 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
525 +#define ARGS_DEFAULT_FORCE_SPACE 0
526 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
527 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
528 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
529 +#define ARGS_DEFAULT_NOACTION 0
530 +#define ARGS_DEFAULT_NODEPS 0
531 +#define ARGS_DEFAULT_VERBOSE_WGET 0
532 +#define ARGS_DEFAULT_VERBOSITY 1
534 +int args_init(args_t *args);
535 +void args_deinit(args_t *args);
536 +int args_parse(args_t *args, int argc, char *argv[]);
537 +void args_usage(char *complaint);
540 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.c busybox-1.1.1-new/archival/libipkg/conffile.c
541 --- busybox-1.1.1-old/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
542 +++ busybox-1.1.1-new/archival/libipkg/conffile.c 2006-03-30 00:39:48.000000000 +0200
544 +/* conffile.c - the itsy package management system
548 + Copyright (C) 2001 University of Southern California
550 + This program is free software; you can redistribute it and/or
551 + modify it under the terms of the GNU General Public License as
552 + published by the Free Software Foundation; either version 2, or (at
553 + your option) any later version.
555 + This program is distributed in the hope that it will be useful, but
556 + WITHOUT ANY WARRANTY; without even the implied warranty of
557 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
558 + General Public License for more details.
565 +#include "ipkg_message.h"
567 +#include "conffile.h"
568 +#include "file_util.h"
569 +#include "sprintf_alloc.h"
571 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
573 + return nv_pair_init(conffile, file_name, md5sum);
576 +void conffile_deinit(conffile_t *conffile)
578 + nv_pair_deinit(conffile);
581 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
584 + char *filename = conffile->name;
585 + char *root_filename;
588 + if (conffile->value == NULL) {
589 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
593 + root_filename = root_filename_alloc(conf, filename);
595 + md5sum = file_md5sum_alloc(root_filename);
597 + ret = strcmp(md5sum, conffile->value);
599 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
600 + conffile->name, md5sum, conffile->value);
603 + free(root_filename);
608 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile.h busybox-1.1.1-new/archival/libipkg/conffile.h
609 --- busybox-1.1.1-old/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
610 +++ busybox-1.1.1-new/archival/libipkg/conffile.h 2006-03-30 00:39:48.000000000 +0200
612 +/* conffile.h - the itsy package management system
616 + Copyright (C) 2001 University of Southern California
618 + This program is free software; you can redistribute it and/or
619 + modify it under the terms of the GNU General Public License as
620 + published by the Free Software Foundation; either version 2, or (at
621 + your option) any later version.
623 + This program is distributed in the hope that it will be useful, but
624 + WITHOUT ANY WARRANTY; without even the implied warranty of
625 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
626 + General Public License for more details.
632 +#include "nv_pair.h"
634 +typedef struct nv_pair conffile_t;
636 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
637 +void conffile_deinit(conffile_t *conffile);
638 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
642 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.c busybox-1.1.1-new/archival/libipkg/conffile_list.c
643 --- busybox-1.1.1-old/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
644 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.c 2006-03-30 00:39:48.000000000 +0200
646 +/* conffile_list.c - the itsy package management system
650 + Copyright (C) 2001 University of Southern California
652 + This program is free software; you can redistribute it and/or
653 + modify it under the terms of the GNU General Public License as
654 + published by the Free Software Foundation; either version 2, or (at
655 + your option) any later version.
657 + This program is distributed in the hope that it will be useful, but
658 + WITHOUT ANY WARRANTY; without even the implied warranty of
659 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
660 + General Public License for more details.
665 +#include "conffile_list.h"
667 +int conffile_list_init(conffile_list_t *list)
669 + return nv_pair_list_init(list);
672 +void conffile_list_deinit(conffile_list_t *list)
674 + nv_pair_list_deinit(list);
677 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
678 + const char *md5sum)
680 + return nv_pair_list_append(list, file_name, md5sum);
683 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
685 + return nv_pair_list_push(list, data);
688 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
690 + return nv_pair_list_pop(list);
693 diff -ruN busybox-1.1.1-old/archival/libipkg/conffile_list.h busybox-1.1.1-new/archival/libipkg/conffile_list.h
694 --- busybox-1.1.1-old/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
695 +++ busybox-1.1.1-new/archival/libipkg/conffile_list.h 2006-03-30 00:39:48.000000000 +0200
697 +/* conffile_list.h - the itsy package management system
701 + Copyright (C) 2001 University of Southern California
703 + This program is free software; you can redistribute it and/or
704 + modify it under the terms of the GNU General Public License as
705 + published by the Free Software Foundation; either version 2, or (at
706 + your option) any later version.
708 + This program is distributed in the hope that it will be useful, but
709 + WITHOUT ANY WARRANTY; without even the implied warranty of
710 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
711 + General Public License for more details.
714 +#ifndef CONFFILE_LIST_H
715 +#define CONFFILE_LIST_H
717 +#include "conffile.h"
718 +#include "nv_pair_list.h"
720 +typedef struct nv_pair_list_elt conffile_list_elt_t;
721 +typedef struct nv_pair_list conffile_list_t;
723 +int conffile_list_init(conffile_list_t *list);
724 +void conffile_list_deinit(conffile_list_t *list);
726 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
727 + const char *root_dir);
728 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
729 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
733 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.c busybox-1.1.1-new/archival/libipkg/file_util.c
734 --- busybox-1.1.1-old/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
735 +++ busybox-1.1.1-new/archival/libipkg/file_util.c 2006-03-30 00:39:48.000000000 +0200
737 +/* file_util.c - convenience routines for common stat operations
741 + Copyright (C) 2001 University of Southern California
743 + This program is free software; you can redistribute it and/or
744 + modify it under the terms of the GNU General Public License as
745 + published by the Free Software Foundation; either version 2, or (at
746 + your option) any later version.
748 + This program is distributed in the hope that it will be useful, but
749 + WITHOUT ANY WARRANTY; without even the implied warranty of
750 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
751 + General Public License for more details.
755 +#include <sys/types.h>
756 +#include <sys/stat.h>
758 +#include "sprintf_alloc.h"
759 +#include "file_util.h"
764 +int file_exists(const char *file_name)
767 + struct stat stat_buf;
769 + err = stat(file_name, &stat_buf);
777 +int file_is_dir(const char *file_name)
780 + struct stat stat_buf;
782 + err = stat(file_name, &stat_buf);
787 + return S_ISDIR(stat_buf.st_mode);
790 +/* read a single line from a file, stopping at a newline or EOF.
791 + If a newline is read, it will appear in the resulting string.
792 + Return value is a malloc'ed char * which should be freed at
793 + some point by the caller.
795 + Return value is NULL if the file is at EOF when called.
797 +#define FILE_READ_LINE_BUF_SIZE 1024
798 +char *file_read_line_alloc(FILE *file)
800 + char buf[FILE_READ_LINE_BUF_SIZE];
805 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
806 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
807 + buf_len = strlen(buf);
809 + line_size += buf_len;
810 + line = realloc(line, line_size);
811 + if (line == NULL) {
812 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
817 + line_size = buf_len + 1;
818 + line = strdup(buf);
820 + if (buf[buf_len - 1] == '\n') {
828 +int file_move(const char *src, const char *dest)
832 + err = rename(src, dest);
834 + if (err && errno == EXDEV) {
835 + err = file_copy(src, dest);
838 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
839 + __FUNCTION__, src, dest, strerror(errno));
845 +/* I put these here to keep libbb dependencies from creeping all over
847 +int file_copy(const char *src, const char *dest)
851 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
853 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
854 + __FUNCTION__, src, dest);
860 +int file_mkdir_hier(const char *path, long mode)
862 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
865 +char *file_md5sum_alloc(const char *file_name)
867 + static const int md5sum_bin_len = 16;
868 + static const int md5sum_hex_len = 32;
870 + static const unsigned char bin2hex[16] = {
871 + '0', '1', '2', '3',
872 + '4', '5', '6', '7',
873 + '8', '9', 'a', 'b',
879 + unsigned char *md5sum_hex;
880 + unsigned char md5sum_bin[md5sum_bin_len];
882 + md5sum_hex = malloc(md5sum_hex_len + 1);
883 + if (md5sum_hex == NULL) {
884 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
888 + file = fopen(file_name, "r");
889 + if (file == NULL) {
890 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
891 + __FUNCTION__, file_name, strerror(errno));
895 + err = md5_stream(file, md5sum_bin);
897 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
898 + __FUNCTION__, file_name, strerror(err));
904 + for (i=0; i < md5sum_bin_len; i++) {
905 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
906 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
909 + md5sum_hex[md5sum_hex_len] = '\0';
914 diff -ruN busybox-1.1.1-old/archival/libipkg/file_util.h busybox-1.1.1-new/archival/libipkg/file_util.h
915 --- busybox-1.1.1-old/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
916 +++ busybox-1.1.1-new/archival/libipkg/file_util.h 2006-03-30 00:39:48.000000000 +0200
918 +/* file_util.h - convenience routines for common file operations
922 + Copyright (C) 2001 University of Southern California
924 + This program is free software; you can redistribute it and/or
925 + modify it under the terms of the GNU General Public License as
926 + published by the Free Software Foundation; either version 2, or (at
927 + your option) any later version.
929 + This program is distributed in the hope that it will be useful, but
930 + WITHOUT ANY WARRANTY; without even the implied warranty of
931 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
932 + General Public License for more details.
938 +int file_exists(const char *file_name);
939 +int file_is_dir(const char *file_name);
940 +char *file_read_line_alloc(FILE *file);
941 +int file_move(const char *src, const char *dest);
942 +int file_copy(const char *src, const char *dest);
943 +int file_mkdir_hier(const char *path, long mode);
944 +char *file_md5sum_alloc(const char *file_name);
947 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.c busybox-1.1.1-new/archival/libipkg/hash_table.c
948 --- busybox-1.1.1-old/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
949 +++ busybox-1.1.1-new/archival/libipkg/hash_table.c 2006-03-30 00:39:48.000000000 +0200
951 +/* hash.c - hash tables for ipkg
953 + Steven M. Ayer, Jamey Hicks
955 + Copyright (C) 2002 Compaq Computer Corporation
957 + This program is free software; you can redistribute it and/or
958 + modify it under the terms of the GNU General Public License as
959 + published by the Free Software Foundation; either version 2, or (at
960 + your option) any later version.
962 + This program is distributed in the hope that it will be useful, but
963 + WITHOUT ANY WARRANTY; without even the implied warranty of
964 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
965 + General Public License for more details.
972 +#include "hash_table.h"
973 +#include "ipkg_message.h"
976 +static int hash_index(hash_table_t *hash, const char *pkg_name);
977 +static int rotating(const char *key, int len, int prime);
979 +static int hash_index(hash_table_t *hash, const char *pkg_name)
981 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
984 +static int rotating(const char *key, int len, int prime)
986 + unsigned int hash, i;
987 + for (hash=len, i=0; i<len; ++i)
988 + hash = (hash<<4)^(hash>>28)^key[i];
989 + return (hash % prime);
994 + * this is an open table keyed by strings
996 +int hash_table_init(const char *name, hash_table_t *hash, int len)
998 + static int primes_table[] = {
999 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
1000 + 19471, 23143, 33961, 46499, 49727, 99529, 0
1004 + if (hash->entries != NULL) {
1005 + /* we have been here already */
1009 + hash->name = name;
1010 + hash->entries = NULL;
1011 + hash->n_entries = 0;
1012 + hash->hash_entry_key = NULL;
1014 + picker = primes_table;
1015 + while(*picker && (*picker++ < len));
1017 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1020 + hash->n_entries = *picker;
1021 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1022 + if (hash->entries == NULL) {
1023 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1029 +void hash_table_deinit(hash_table_t *hash)
1031 + free(hash->entries);
1032 + hash->entries = NULL;
1033 + hash->n_entries = 0;
1036 +void *hash_table_get(hash_table_t *hash, const char *key)
1038 + int ndx= hash_index(hash, key);
1039 + hash_entry_t *hash_entry = hash->entries + ndx;
1040 + while (hash_entry)
1042 + if (hash_entry->key)
1044 + if (strcmp(key, hash_entry->key) == 0) {
1045 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1046 + return hash_entry->data;
1049 + hash_entry = hash_entry->next;
1054 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1056 + int ndx= hash_index(hash, key);
1057 + hash_entry_t *hash_entry = hash->entries + ndx;
1058 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1059 + if (hash_entry->key) {
1060 + if (strcmp(hash_entry->key, key) == 0) {
1061 + /* alread in table, update the value */
1062 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1063 + hash_entry->data = value;
1067 + * if this is a collision, we have to go to the end of the ll,
1068 + * then add a new entry
1069 + * before we can hook up the value
1071 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1072 + while (hash_entry->next)
1073 + hash_entry = hash_entry->next;
1074 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1075 + if (!hash_entry->next) {
1078 + hash_entry = hash_entry->next;
1079 + hash_entry->next = NULL;
1082 + hash->n_elements++;
1083 + hash_entry->key = strdup(key);
1084 + hash_entry->data = value;
1090 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1096 + for (i = 0; i < hash->n_entries; i++) {
1097 + hash_entry_t *hash_entry = (hash->entries + i);
1099 + if(hash_entry->key) {
1100 + f(hash_entry->key, hash_entry->data, data);
1102 + } while((hash_entry = hash_entry->next));
1106 diff -ruN busybox-1.1.1-old/archival/libipkg/hash_table.h busybox-1.1.1-new/archival/libipkg/hash_table.h
1107 --- busybox-1.1.1-old/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1108 +++ busybox-1.1.1-new/archival/libipkg/hash_table.h 2006-03-30 00:39:48.000000000 +0200
1110 +/* hash.h - hash tables for ipkg
1112 + Steven M. Ayer, Jamey Hicks
1114 + Copyright (C) 2002 Compaq Computer Corporation
1116 + This program is free software; you can redistribute it and/or
1117 + modify it under the terms of the GNU General Public License as
1118 + published by the Free Software Foundation; either version 2, or (at
1119 + your option) any later version.
1121 + This program is distributed in the hope that it will be useful, but
1122 + WITHOUT ANY WARRANTY; without even the implied warranty of
1123 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1124 + General Public License for more details.
1127 +#ifndef _HASH_TABLE_H_
1128 +#define _HASH_TABLE_H_
1130 +typedef struct hash_entry hash_entry_t;
1131 +typedef struct hash_table hash_table_t;
1133 +struct hash_entry {
1136 + struct hash_entry * next;
1139 +struct hash_table {
1141 + hash_entry_t * entries;
1142 + int n_entries; /* number of buckets */
1144 + const char * (*hash_entry_key)(void * data);
1147 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1148 +void hash_table_deinit(hash_table_t *hash);
1149 +void *hash_table_get(hash_table_t *hash, const char *key);
1150 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1151 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1153 +#endif /* _HASH_TABLE_H_ */
1154 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg.h busybox-1.1.1-new/archival/libipkg/ipkg.h
1155 --- busybox-1.1.1-old/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1156 +++ busybox-1.1.1-new/archival/libipkg/ipkg.h 2006-03-30 00:39:48.000000000 +0200
1158 +/* ipkg.h - the itsy package management system
1162 + Copyright (C) 2001 University of Southern California
1164 + This program is free software; you can redistribute it and/or
1165 + modify it under the terms of the GNU General Public License as
1166 + published by the Free Software Foundation; either version 2, or (at
1167 + your option) any later version.
1169 + This program is distributed in the hope that it will be useful, but
1170 + WITHOUT ANY WARRANTY; without even the implied warranty of
1171 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1172 + General Public License for more details.
1179 +#ifdef HAVE_CONFIG_H
1180 +#include "config.h"
1185 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1188 +#include "ipkg_includes.h"
1189 +#include "ipkg_conf.h"
1190 +#include "ipkg_message.h"
1192 +#define IPKG_PKG_EXTENSION ".ipk"
1193 +#define DPKG_PKG_EXTENSION ".deb"
1195 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1196 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1198 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1199 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1200 +#define IPKG_INFO_DIR_SUFFIX "info"
1201 +#define IPKG_STATUS_FILE_SUFFIX "status"
1203 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1205 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1207 +#define IPKG_VERSION "0.99.154"
1212 + IPKG_PKG_DEPS_UNSATISFIED,
1213 + IPKG_PKG_IS_ESSENTIAL,
1214 + IPKG_PKG_HAS_DEPENDENTS,
1215 + IPKG_PKG_HAS_NO_CANDIDATE
1217 +typedef enum ipkg_error ipkg_error_t;
1219 +extern int ipkg_state_changed;
1224 + struct errlist * next;
1227 +extern struct errlist* error_list;
1229 +extern ipkg_conf_t *global_conf;
1232 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c
1233 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1234 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.c 2006-03-30 00:39:48.000000000 +0200
1236 +/* ipkg_cmd.c - the itsy package management system
1240 + Copyright (C) 2001 University of Southern California
1242 + This program is free software; you can redistribute it and/or
1243 + modify it under the terms of the GNU General Public License as
1244 + published by the Free Software Foundation; either version 2, or (at
1245 + your option) any later version.
1247 + This program is distributed in the hope that it will be useful, but
1248 + WITHOUT ANY WARRANTY; without even the implied warranty of
1249 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1250 + General Public License for more details.
1253 +#include <string.h>
1256 +#include <libgen.h>
1259 +#include <stdlib.h>
1260 +#include <unistd.h>
1261 +#include <signal.h>
1264 +#include "ipkg_conf.h"
1265 +#include "ipkg_cmd.h"
1266 +#include "ipkg_message.h"
1268 +#include "pkg_dest.h"
1269 +#include "pkg_parse.h"
1270 +#include "sprintf_alloc.h"
1272 +#include "file_util.h"
1273 +#include "str_util.h"
1275 +#include "unarchive.h"
1277 +#include <fnmatch.h>
1280 +#include "ipkg_download.h"
1281 +#include "ipkg_install.h"
1282 +#include "ipkg_upgrade.h"
1283 +#include "ipkg_remove.h"
1284 +#include "ipkg_configure.h"
1285 +#include "ipkg_message.h"
1288 +#include "libipkg.h"
1289 +static void *p_userdata = NULL;
1292 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1316 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1318 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1319 + array for easier maintenance */
1320 +static ipkg_cmd_t cmds[] = {
1321 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1322 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1323 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1324 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1325 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1326 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1327 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1328 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1329 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1330 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1331 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1332 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1333 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1334 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1335 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1336 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1337 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1338 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1341 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1342 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1343 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1344 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1345 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1346 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1347 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1348 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1349 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1352 +int ipkg_state_changed;
1353 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1355 + if (ipkg_state_changed && !conf->noaction) {
1356 + ipkg_message(conf, IPKG_INFO,
1357 + " writing status file\n");
1358 + ipkg_conf_write_status_files(conf);
1359 + pkg_write_changed_filelists(conf);
1361 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1366 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1368 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1373 + for (i=0; i < num_cmds; i++) {
1375 + if (strcmp(name, cmd->name) == 0) {
1384 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1387 + p_userdata = userdata;
1390 + result = (cmd->fun)(conf, argc, argv);
1391 + if ( result == 0 ) {
1392 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1394 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1397 + if ( error_list ) {
1398 + reverse_error_list(&error_list);
1400 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1401 + /* Here we print the errors collected and free the list */
1402 + while (error_list != NULL) {
1403 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1404 + error_list = error_list->next;
1407 + free_error_list(&error_list);
1411 + p_userdata = NULL;
1415 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1417 + return (cmd->fun)(conf, argc, argv);
1421 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1426 + pkg_src_list_elt_t *iter;
1430 + if (conf->offline_root) {
1431 + sprintf_alloc(&lists_dir, "%s/%s",
1432 + conf->offline_root,
1433 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1435 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1438 + if (! file_is_dir(lists_dir)) {
1439 + if (file_exists(lists_dir)) {
1440 + ipkg_message(conf, IPKG_ERROR,
1441 + "%s: ERROR: %s exists, but is not a directory\n",
1442 + __FUNCTION__, lists_dir);
1446 + err = file_mkdir_hier(lists_dir, 0755);
1448 + ipkg_message(conf, IPKG_ERROR,
1449 + "%s: ERROR: failed to make directory %s: %s\n",
1450 + __FUNCTION__, lists_dir, strerror(errno));
1457 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1458 + char *url, *list_file_name;
1462 + if (src->extra_data) /* debian style? */
1463 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1464 + src->gzip ? "Packages.gz" : "Packages");
1466 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1468 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1471 + char *tmp_file_name;
1474 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1476 + if (mkdtemp (tmp) == NULL) {
1477 + perror ("mkdtemp");
1482 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1483 + err = ipkg_download(conf, url, tmp_file_name);
1485 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1486 + in = fopen (tmp_file_name, "r");
1487 + out = fopen (list_file_name, "w");
1489 + inflate_unzip (in, out);
1496 + unlink (tmp_file_name);
1501 + err = ipkg_download(conf, url, list_file_name);
1505 + ipkg_message(conf, IPKG_NOTICE,
1506 + "Updated list of available packages in %s\n",
1510 + free(list_file_name);
1514 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1516 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1517 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1523 + pkg_vec_t *available = pkg_vec_alloc();
1524 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1525 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1526 + for (i = 0; i < available->len; i++) {
1527 + pkg_t *pkg = available->pkgs[i];
1528 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1529 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1530 + pkg->state_want = SW_UNKNOWN;
1534 + pkg_vec_free(available);
1536 + write_status_files_if_changed(conf);
1545 +/* scan the args passed and cache the local filenames of the packages */
1546 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1552 + * First scan through package names/urls
1553 + * For any urls, download the packages and install in database.
1554 + * For any files, install package info in database.
1556 + for (i = 0; i < argc; i ++) {
1557 + char *filename = argv [i];
1558 + //char *tmp = basename (tmp);
1559 + //int tmplen = strlen (tmp);
1561 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1563 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1566 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1573 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1579 + ipkg_message(conf, IPKG_INFO,
1580 + "Configuring unpacked packages\n");
1583 + all = pkg_vec_alloc();
1584 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1586 + for(i = 0; i < all->len; i++) {
1587 + pkg = all->pkgs[i];
1589 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1592 + if (pkg->state_status == SS_UNPACKED) {
1593 + ipkg_message(conf, IPKG_NOTICE,
1594 + "Configuring %s\n", pkg->name);
1596 + if (ipkg_configure(conf, pkg) == 0) {
1597 + pkg->state_status = SS_INSTALLED;
1598 + pkg->parent->state_status = SS_INSTALLED;
1599 + pkg->state_flag &= ~SF_PREFER;
1604 + pkg_vec_free(all);
1608 +static void sigint_handler(int sig)
1610 + signal(sig, SIG_DFL);
1611 + ipkg_message(NULL, IPKG_NOTICE,
1612 + "ipkg: interrupted. writing out status database\n");
1613 + write_status_files_if_changed(global_conf);
1617 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1623 + global_conf = conf;
1624 + signal(SIGINT, sigint_handler);
1627 + * Now scan through package names and install
1629 + for (i=0; i < argc; i++) {
1632 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1633 + if (err != EINVAL && err != 0)
1636 + pkg_info_preinstall_check(conf);
1638 + for (i=0; i < argc; i++) {
1640 + if (conf->multiple_providers)
1641 + err = ipkg_install_multi_by_name(conf, arg);
1643 + err = ipkg_install_by_name(conf, arg);
1645 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1646 + ipkg_message(conf, IPKG_ERROR,
1647 + "Cannot find package %s.\n"
1648 + "Check the spelling or perhaps run 'ipkg update'\n",
1653 + /* recheck to verify that all dependences are satisfied */
1654 + if (0) ipkg_satisfy_all_dependences(conf);
1656 + ipkg_configure_packages(conf, NULL);
1658 + write_status_files_if_changed(conf);
1663 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1669 + global_conf = conf;
1670 + signal(SIGINT, sigint_handler);
1673 + for (i=0; i < argc; i++) {
1674 + char *arg = argv[i];
1676 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1677 + if (err != EINVAL && err != 0)
1680 + pkg_info_preinstall_check(conf);
1682 + for (i=0; i < argc; i++) {
1683 + char *arg = argv[i];
1684 + if (conf->restrict_to_default_dest) {
1685 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1687 + conf->default_dest);
1688 + if (pkg == NULL) {
1689 + ipkg_message(conf, IPKG_NOTICE,
1690 + "Package %s not installed in %s\n",
1691 + argv[i], conf->default_dest->name);
1695 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1699 + ipkg_upgrade_pkg(conf, pkg);
1701 + ipkg_install_by_name(conf, arg);
1705 + pkg_vec_t *installed = pkg_vec_alloc();
1707 + pkg_info_preinstall_check(conf);
1709 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1710 + for (i = 0; i < installed->len; i++) {
1711 + pkg = installed->pkgs[i];
1712 + ipkg_upgrade_pkg(conf, pkg);
1714 + pkg_vec_free(installed);
1717 + /* recheck to verify that all dependences are satisfied */
1718 + if (0) ipkg_satisfy_all_dependences(conf);
1720 + ipkg_configure_packages(conf, NULL);
1722 + write_status_files_if_changed(conf);
1727 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1733 + pkg_info_preinstall_check(conf);
1734 + for (i = 0; i < argc; i++) {
1737 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1738 + if (pkg == NULL) {
1739 + ipkg_message(conf, IPKG_ERROR,
1740 + "Cannot find package %s.\n"
1741 + "Check the spelling or perhaps run 'ipkg update'\n",
1746 + err = ipkg_download_pkg(conf, pkg, ".");
1749 + ipkg_message(conf, IPKG_ERROR,
1750 + "Failed to download %s\n", pkg->name);
1752 + ipkg_message(conf, IPKG_NOTICE,
1753 + "Downloaded %s as %s\n",
1754 + pkg->name, pkg->local_filename);
1762 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1765 + pkg_vec_t *available;
1767 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1769 + char *pkg_name = NULL;
1770 + char *version_str;
1773 + pkg_name = argv[0];
1775 + available = pkg_vec_alloc();
1776 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1777 + for (i=0; i < available->len; i++) {
1778 + pkg = available->pkgs[i];
1779 + /* if we have package name or pattern and pkg does not match, then skip it */
1780 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1782 + if (pkg->description) {
1783 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1785 + desc_short[0] = '\0';
1787 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1788 + newline = strchr(desc_short, '\n');
1793 + printf("%s - %s\n", pkg->name, desc_short);
1795 + if (ipkg_cb_list) {
1796 + version_str = pkg_version_str_alloc(pkg);
1797 + ipkg_cb_list(pkg->name,desc_short,
1799 + pkg->state_status,
1801 + free(version_str);
1805 + pkg_vec_free(available);
1811 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1814 + pkg_vec_t *available;
1816 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1818 + char *pkg_name = NULL;
1819 + char *version_str;
1822 + pkg_name = argv[0];
1824 + available = pkg_vec_alloc();
1825 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1826 + for (i=0; i < available->len; i++) {
1827 + pkg = available->pkgs[i];
1828 + /* if we have package name or pattern and pkg does not match, then skip it */
1829 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1831 + if (pkg->description) {
1832 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1834 + desc_short[0] = '\0';
1836 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1837 + newline = strchr(desc_short, '\n');
1842 + printf("%s - %s\n", pkg->name, desc_short);
1844 + if (ipkg_cb_list) {
1845 + version_str = pkg_version_str_alloc(pkg);
1846 + ipkg_cb_list(pkg->name,desc_short,
1848 + pkg->state_status,
1850 + free(version_str);
1858 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1861 + pkg_vec_t *available;
1863 + char *pkg_name = NULL;
1864 + char **pkg_fields = NULL;
1866 + char *buff ; // = (char *)malloc(1);
1869 + pkg_name = argv[0];
1872 + pkg_fields = &argv[1];
1873 + n_fields = argc - 1;
1876 + available = pkg_vec_alloc();
1877 + if (installed_only)
1878 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1880 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1881 + for (i=0; i < available->len; i++) {
1882 + pkg = available->pkgs[i];
1883 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1888 + for (j = 0; j < n_fields; j++)
1889 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1891 + pkg_print_info(pkg, stdout);
1895 + buff = pkg_formatted_info(pkg);
1897 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1898 + pkg->state_status,
1902 + We should not forget that actually the pointer is allocated.
1903 + We need to free it :) ( Thanks florian for seeing the error )
1908 + if (conf->verbosity > 1) {
1909 + conffile_list_elt_t *iter;
1910 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1911 + conffile_t *cf = iter->data;
1912 + int modified = conffile_has_been_modified(conf, cf);
1913 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1914 + cf->name, cf->value, modified);
1922 + pkg_vec_free(available);
1927 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1929 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1932 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1934 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1937 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1942 + char *pkg_name = NULL;
1944 + pkg_name = argv[0];
1946 + err = ipkg_configure_packages (conf, pkg_name);
1949 + err = ipkg_configure_packages (conf, NULL);
1952 + write_status_files_if_changed(conf);
1957 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1960 + char *globpattern;
1963 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1964 + err = glob(globpattern, 0, NULL, &globbuf);
1965 + free(globpattern);
1970 + ipkg_message(conf, IPKG_NOTICE,
1971 + "The following packages in %s will now be installed.\n",
1972 + conf->pending_dir);
1973 + for (i = 0; i < globbuf.gl_pathc; i++) {
1974 + ipkg_message(conf, IPKG_NOTICE,
1975 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1977 + ipkg_message(conf, IPKG_NOTICE, "\n");
1978 + for (i = 0; i < globbuf.gl_pathc; i++) {
1979 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1981 + err = unlink(globbuf.gl_pathv[i]);
1983 + ipkg_message(conf, IPKG_ERROR,
1984 + "%s: ERROR: failed to unlink %s: %s\n",
1985 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1990 + globfree(&globbuf);
1995 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1999 + pkg_t *pkg_to_remove;
2000 + pkg_vec_t *available;
2001 + char *pkg_name = NULL;
2002 + global_conf = conf;
2003 + signal(SIGINT, sigint_handler);
2005 +// ENH: Add the "no pkg removed" just in case.
2009 + available = pkg_vec_alloc();
2010 + pkg_info_preinstall_check(conf);
2012 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2013 + for (i=0; i < argc; i++) {
2014 + pkg_name = malloc(strlen(argv[i])+2);
2015 + strcpy(pkg_name,argv[i]);
2016 + for (a=0; a < available->len; a++) {
2017 + pkg = available->pkgs[a];
2018 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2021 + if (conf->restrict_to_default_dest) {
2022 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2024 + conf->default_dest);
2026 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2029 + if (pkg == NULL) {
2030 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2033 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2034 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2037 + ipkg_remove_pkg(conf, pkg_to_remove);
2042 + pkg_vec_free(available);
2044 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2046 + int flagged_pkg_count = 0;
2049 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2051 + for (i = 0; i < installed_pkgs->len; i++) {
2052 + pkg_t *pkg = installed_pkgs->pkgs[i];
2053 + if (pkg->state_flag & SF_USER) {
2054 + flagged_pkg_count++;
2056 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2057 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2060 + if (!flagged_pkg_count) {
2061 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2062 + "so refusing to uninstall unflagged non-leaf packages\n");
2066 + /* find packages not flagged SF_USER (i.e., installed to
2067 + * satisfy a dependence) and not having any dependents, and
2071 + for (i = 0; i < installed_pkgs->len; i++) {
2072 + pkg_t *pkg = installed_pkgs->pkgs[i];
2073 + if (!(pkg->state_flag & SF_USER)
2074 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2076 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2077 + ipkg_remove_pkg(conf, pkg);
2081 + } while (removed);
2082 + pkg_vec_free(installed_pkgs);
2086 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2088 + write_status_files_if_changed(conf);
2092 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2097 + global_conf = conf;
2098 + signal(SIGINT, sigint_handler);
2100 + pkg_info_preinstall_check(conf);
2102 + for (i=0; i < argc; i++) {
2103 + if (conf->restrict_to_default_dest) {
2104 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2106 + conf->default_dest);
2108 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2111 + if (pkg == NULL) {
2112 + ipkg_message(conf, IPKG_ERROR,
2113 + "Package %s is not installed.\n", argv[i]);
2116 + ipkg_purge_pkg(conf, pkg);
2119 + write_status_files_if_changed(conf);
2123 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2127 + const char *flags = argv[0];
2129 + global_conf = conf;
2130 + signal(SIGINT, sigint_handler);
2132 + for (i=1; i < argc; i++) {
2133 + if (conf->restrict_to_default_dest) {
2134 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2136 + conf->default_dest);
2138 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2141 + if (pkg == NULL) {
2142 + ipkg_message(conf, IPKG_ERROR,
2143 + "Package %s is not installed.\n", argv[i]);
2146 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2147 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2148 + pkg->state_flag = pkg_state_flag_from_str(flags);
2150 +/* pb_ asked this feature 03292004 */
2151 +/* Actually I will use only this two, but this is an open for various status */
2152 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2153 + pkg->state_status = pkg_state_status_from_str(flags);
2155 + ipkg_state_changed++;
2156 + ipkg_message(conf, IPKG_NOTICE,
2157 + "Setting flags for package %s to %s\n",
2158 + pkg->name, flags);
2161 + write_status_files_if_changed(conf);
2165 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2168 + str_list_t *installed_files;
2169 + str_list_elt_t *iter;
2170 + char *pkg_version;
2171 + size_t buff_len = 8192;
2175 + buff = (char *)malloc(buff_len);
2176 + if ( buff == NULL ) {
2177 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2185 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2187 + if (pkg == NULL) {
2188 + ipkg_message(conf, IPKG_ERROR,
2189 + "Package %s not installed.\n", argv[0]);
2193 + installed_files = pkg_get_installed_files(pkg);
2194 + pkg_version = pkg_version_str_alloc(pkg);
2197 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2198 + pkg->name, pkg_version, pkg->dest->name);
2199 + for (iter = installed_files->head; iter; iter = iter->next) {
2205 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2206 + pkg->name, pkg_version, pkg->dest->name) + 1;
2207 + if (used_len > buff_len) {
2209 + buff = realloc (buff, buff_len);
2212 + for (iter = installed_files->head; iter; iter = iter->next) {
2213 + used_len += strlen (iter->data) + 1;
2214 + while (buff_len <= used_len) {
2216 + buff = realloc (buff, buff_len);
2218 + strncat(buff, iter->data, buff_len);
2219 + strncat(buff, "\n", buff_len);
2221 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2223 + pkg_version_str_alloc(pkg),
2224 + pkg->state_status,
2230 + free(pkg_version);
2231 + pkg_free_installed_files(pkg);
2236 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2240 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2241 + const char *rel_str = "depends on";
2244 + pkg_info_preinstall_check(conf);
2246 + if (conf->query_all)
2247 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2249 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2250 + for (i = 0; i < argc; i++) {
2251 + const char *target = argv[i];
2254 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2256 + for (j = 0; j < available_pkgs->len; j++) {
2257 + pkg_t *pkg = available_pkgs->pkgs[j];
2258 + if (fnmatch(target, pkg->name, 0) == 0) {
2260 + int count = pkg->depends_count + pkg->pre_depends_count;
2261 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2262 + target, pkg->architecture, rel_str);
2263 + for (k = 0; k < count; k++) {
2264 + compound_depend_t *cdepend = &pkg->depends[k];
2266 + for (l = 0; l < cdepend->possibility_count; l++) {
2267 + depend_t *possibility = cdepend->possibilities[l];
2268 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2269 + if (conf->verbosity > 0) {
2270 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2271 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2272 + if (possibility->version) {
2273 + char *typestr = NULL;
2274 + switch (possibility->constraint) {
2275 + case NONE: typestr = "none"; break;
2276 + case EARLIER: typestr = "<"; break;
2277 + case EARLIER_EQUAL: typestr = "<="; break;
2278 + case EQUAL: typestr = "="; break;
2279 + case LATER_EQUAL: typestr = ">="; break;
2280 + case LATER: typestr = ">"; break;
2282 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2286 + ipkg_message(conf, IPKG_ERROR, "\n");
2292 + pkg_vec_free(available_pkgs);
2297 +enum what_field_type {
2306 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2310 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2311 + const char *rel_str = NULL;
2315 + switch (what_field_type) {
2316 + case WHATDEPENDS: rel_str = "depends on"; break;
2317 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2318 + case WHATSUGGESTS: rel_str = "suggests"; break;
2319 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2320 + case WHATPROVIDES: rel_str = "provides"; break;
2321 + case WHATREPLACES: rel_str = "replaces"; break;
2324 + if (conf->query_all)
2325 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2327 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2329 + /* mark the root set */
2330 + pkg_vec_clear_marks(available_pkgs);
2331 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2332 + for (i = 0; i < argc; i++) {
2333 + const char *dependee_pattern = argv[i];
2334 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2336 + for (i = 0; i < available_pkgs->len; i++) {
2337 + pkg_t *pkg = available_pkgs->pkgs[i];
2338 + if (pkg->state_flag & SF_MARKED) {
2339 + /* mark the parent (abstract) package */
2340 + pkg_mark_provides(pkg);
2341 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2345 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2350 + for (j = 0; j < available_pkgs->len; j++) {
2351 + pkg_t *pkg = available_pkgs->pkgs[j];
2353 + int count = ((what_field_type == WHATCONFLICTS)
2354 + ? pkg->conflicts_count
2355 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2356 + /* skip this package if it is already marked */
2357 + if (pkg->parent->state_flag & SF_MARKED) {
2360 + for (k = 0; k < count; k++) {
2361 + compound_depend_t *cdepend =
2362 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2364 + for (l = 0; l < cdepend->possibility_count; l++) {
2365 + depend_t *possibility = cdepend->possibilities[l];
2366 + if (possibility->pkg->state_flag & SF_MARKED) {
2367 + /* mark the depending package so we won't visit it again */
2368 + pkg->state_flag |= SF_MARKED;
2369 + pkg_mark_provides(pkg);
2372 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2373 + if (conf->verbosity > 0) {
2374 + char *ver = pkg_version_str_alloc(pkg);
2375 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2376 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2377 + if (possibility->version) {
2378 + char *typestr = NULL;
2379 + switch (possibility->constraint) {
2380 + case NONE: typestr = "none"; break;
2381 + case EARLIER: typestr = "<"; break;
2382 + case EARLIER_EQUAL: typestr = "<="; break;
2383 + case EQUAL: typestr = "="; break;
2384 + case LATER_EQUAL: typestr = ">="; break;
2385 + case LATER: typestr = ">"; break;
2387 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2390 + if (!pkg_dependence_satisfiable(conf, possibility))
2391 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2393 + ipkg_message(conf, IPKG_NOTICE, "\n");
2394 + goto next_package;
2401 + } while (changed && recursive);
2402 + pkg_vec_free(available_pkgs);
2408 +int pkg_mark_provides(pkg_t *pkg)
2410 + int provides_count = pkg->provides_count;
2411 + abstract_pkg_t **provides = pkg->provides;
2413 + pkg->parent->state_flag |= SF_MARKED;
2414 + for (i = 0; i < provides_count; i++) {
2415 + provides[i]->state_flag |= SF_MARKED;
2420 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2422 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2424 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2426 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2429 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2431 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2434 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2436 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2439 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2441 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2444 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2448 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2449 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2452 + pkg_info_preinstall_check(conf);
2454 + if (conf->query_all)
2455 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2457 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2458 + for (i = 0; i < argc; i++) {
2459 + const char *target = argv[i];
2462 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2464 + for (j = 0; j < available_pkgs->len; j++) {
2465 + pkg_t *pkg = available_pkgs->pkgs[j];
2467 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2468 + for (k = 0; k < count; k++) {
2469 + abstract_pkg_t *apkg =
2470 + ((what_field_type == WHATPROVIDES)
2471 + ? pkg->provides[k]
2472 + : pkg->replaces[k]);
2473 + if (fnmatch(target, apkg->name, 0) == 0) {
2474 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2475 + if (strcmp(target, apkg->name) != 0)
2476 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2477 + ipkg_message(conf, IPKG_ERROR, "\n");
2482 + pkg_vec_free(available_pkgs);
2487 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2489 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2492 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2494 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2497 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2501 + pkg_vec_t *installed;
2503 + str_list_t *installed_files;
2504 + str_list_elt_t *iter;
2505 + char *installed_file;
2511 + installed = pkg_vec_alloc();
2512 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2514 + for (i=0; i < installed->len; i++) {
2515 + pkg = installed->pkgs[i];
2517 + installed_files = pkg_get_installed_files(pkg);
2519 + for (iter = installed_files->head; iter; iter = iter->next) {
2520 + installed_file = iter->data;
2521 + if (fnmatch(argv[0], installed_file, 0)==0) {
2523 + printf("%s: %s\n", pkg->name, installed_file);
2525 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2527 + pkg_version_str_alloc(pkg),
2528 + pkg->state_status, p_userdata);
2533 + pkg_free_installed_files(pkg);
2536 + /* XXX: CLEANUP: It's not obvious from the name of
2537 + pkg_hash_fetch_all_installed that we need to call
2538 + pkg_vec_free to avoid a memory leak. */
2539 + pkg_vec_free(installed);
2544 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2547 + /* this is a bit gross */
2548 + struct pkg p1, p2;
2549 + parseVersion(&p1, argv[0]);
2550 + parseVersion(&p2, argv[2]);
2551 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2553 + ipkg_message(conf, IPKG_ERROR,
2554 + "ipkg compare_versions <v1> <op> <v2>\n"
2555 + "<op> is one of <= >= << >> =\n");
2560 +#ifndef HOST_CPU_STR
2561 +#define HOST_CPU_STR__(X) #X
2562 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2563 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2566 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2568 + nv_pair_list_elt_t *l;
2570 + l = conf->arch_list.head;
2572 + nv_pair_t *nv = l->data;
2573 + printf("arch %s %s\n", nv->name, nv->value);
2580 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h
2581 --- busybox-1.1.1-old/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2582 +++ busybox-1.1.1-new/archival/libipkg/ipkg_cmd.h 2006-03-30 00:39:48.000000000 +0200
2584 +/* ipkg_cmd.h - the itsy package management system
2588 + Copyright (C) 2001 University of Southern California
2590 + This program is free software; you can redistribute it and/or
2591 + modify it under the terms of the GNU General Public License as
2592 + published by the Free Software Foundation; either version 2, or (at
2593 + your option) any later version.
2595 + This program is distributed in the hope that it will be useful, but
2596 + WITHOUT ANY WARRANTY; without even the implied warranty of
2597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2598 + General Public License for more details.
2604 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2609 + int requires_args;
2610 + ipkg_cmd_fun_t fun;
2612 +typedef struct ipkg_cmd ipkg_cmd_t;
2614 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2616 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2617 + const char **argv, void *userdata);
2619 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2621 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2622 +/* install any packges with state_want == SW_INSTALL */
2623 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2624 +/* ensure that all dependences are satisfied */
2625 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2627 +int pkg_mark_provides(pkg_t *pkg);
2630 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.c busybox-1.1.1-new/archival/libipkg/ipkg_conf.c
2631 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2632 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.c 2006-03-30 00:39:48.000000000 +0200
2634 +/* ipkg_conf.c - the itsy package management system
2638 + Copyright (C) 2001 University of Southern California
2640 + This program is free software; you can redistribute it and/or
2641 + modify it under the terms of the GNU General Public License as
2642 + published by the Free Software Foundation; either version 2, or (at
2643 + your option) any later version.
2645 + This program is distributed in the hope that it will be useful, but
2646 + WITHOUT ANY WARRANTY; without even the implied warranty of
2647 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2648 + General Public License for more details.
2654 +#include "ipkg_conf.h"
2656 +#include "xregex.h"
2657 +#include "sprintf_alloc.h"
2658 +#include "ipkg_conf.h"
2659 +#include "ipkg_message.h"
2660 +#include "file_util.h"
2661 +#include "str_util.h"
2662 +#include "xsystem.h"
2665 +ipkg_conf_t *global_conf;
2667 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2668 + pkg_src_list_t *pkg_src_list,
2669 + nv_pair_list_t *tmp_dest_nv_pair_list,
2670 + char **tmp_lists_dir);
2671 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2672 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2673 + const char *name, const char *value);
2674 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2675 + const char *default_dest_name);
2676 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2677 + pkg_src_list_t *nv_pair_list);
2678 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2679 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2681 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2683 + ipkg_option_t tmp[] = {
2684 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2685 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2686 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2687 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2688 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2689 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2690 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2691 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2692 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2693 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2694 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2695 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2696 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2697 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2698 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2699 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2700 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2701 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2702 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2703 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2704 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2708 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2709 + if ( options == NULL ){
2710 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2714 + memcpy(*options, tmp, sizeof(tmp));
2718 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2724 + *conf_str = strdup(arg_str);
2728 +static void ipkg_conf_free_string(char **conf_str)
2736 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2739 + char *tmp_dir_base;
2740 + nv_pair_list_t tmp_dest_nv_pair_list;
2741 + char * lists_dir =NULL;
2743 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2744 + char *pending_dir =NULL;
2746 + memset(conf, 0, sizeof(ipkg_conf_t));
2748 + pkg_src_list_init(&conf->pkg_src_list);
2750 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2751 + pkg_dest_list_init(&conf->pkg_dest_list);
2753 + nv_pair_list_init(&conf->arch_list);
2755 + conf->restrict_to_default_dest = 0;
2756 + conf->default_dest = NULL;
2759 + if (args->tmp_dir)
2760 + tmp_dir_base = args->tmp_dir;
2762 + tmp_dir_base = getenv("TMPDIR");
2763 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2764 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2765 + IPKG_CONF_TMP_DIR_SUFFIX);
2766 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2767 + if (conf->tmp_dir == NULL) {
2768 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2769 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2773 + conf->force_depends = 0;
2774 + conf->force_defaults = 0;
2775 + conf->force_overwrite = 0;
2776 + conf->force_downgrade = 0;
2777 + conf->force_reinstall = 0;
2778 + conf->force_space = 0;
2779 + conf->force_removal_of_essential_packages = 0;
2780 + conf->force_removal_of_dependent_packages = 0;
2782 + conf->verbose_wget = 0;
2783 + conf->offline_root = NULL;
2784 + conf->offline_root_pre_script_cmd = NULL;
2785 + conf->offline_root_post_script_cmd = NULL;
2786 + conf->multiple_providers = 0;
2787 + conf->verbosity = 1;
2788 + conf->noaction = 0;
2790 + conf->http_proxy = NULL;
2791 + conf->ftp_proxy = NULL;
2792 + conf->no_proxy = NULL;
2793 + conf->proxy_user = NULL;
2794 + conf->proxy_passwd = NULL;
2796 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2798 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2799 + lists_dir=(char *)malloc(1);
2800 + lists_dir[0]='\0';
2801 + if (args->conf_file) {
2802 + struct stat stat_buf;
2803 + err = stat(args->conf_file, &stat_buf);
2805 + if (ipkg_conf_parse_file(conf, args->conf_file,
2806 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2807 + /* Memory leakage from ipkg_conf_parse-file */
2813 + /* if (!lists_dir ){*/
2814 + if (strlen(lists_dir)<=1 ){
2815 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2816 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2819 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2820 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2822 + conf->lists_dir = strdup(lists_dir);
2823 + conf->pending_dir = strdup(pending_dir);
2825 + if (args->offline_root)
2826 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2827 + memset(&globbuf, 0, sizeof(globbuf));
2828 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2831 + for (i = 0; i < globbuf.gl_pathc; i++) {
2832 + if (globbuf.gl_pathv[i])
2833 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2834 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2835 + /* Memory leakage from ipkg_conf_parse-file */
2840 + globfree(&globbuf);
2842 + /* if no architectures were defined, then default all, noarch, and host architecture */
2843 + if (nv_pair_list_empty(&conf->arch_list)) {
2844 + nv_pair_list_append(&conf->arch_list, "all", "1");
2845 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2846 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2849 + /* Even if there is no conf file, we'll need at least one dest. */
2850 + if (tmp_dest_nv_pair_list.head == NULL) {
2851 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2852 + IPKG_CONF_DEFAULT_DEST_NAME,
2853 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2856 + /* After parsing the file, set options from command-line, (so that
2857 + command-line arguments take precedence) */
2858 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2859 + really needs to be cleaned up. There is so much duplication
2860 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2861 + a pointer to args_t (which could then not be freed), rather
2862 + than duplicating every field here? */
2863 + if (args->force_depends) {
2864 + conf->force_depends = 1;
2866 + if (args->force_defaults) {
2867 + conf->force_defaults = 1;
2869 + if (args->force_overwrite) {
2870 + conf->force_overwrite = 1;
2872 + if (args->force_downgrade) {
2873 + conf->force_downgrade = 1;
2875 + if (args->force_reinstall) {
2876 + conf->force_reinstall = 1;
2878 + if (args->force_removal_of_dependent_packages) {
2879 + conf->force_removal_of_dependent_packages = 1;
2881 + if (args->force_removal_of_essential_packages) {
2882 + conf->force_removal_of_essential_packages = 1;
2884 + if (args->nodeps) {
2887 + if (args->noaction) {
2888 + conf->noaction = 1;
2890 + if (args->query_all) {
2891 + conf->query_all = 1;
2893 + if (args->verbose_wget) {
2894 + conf->verbose_wget = 1;
2896 + if (args->multiple_providers) {
2897 + conf->multiple_providers = 1;
2899 + if (args->verbosity != conf->verbosity) {
2900 + conf->verbosity = args->verbosity;
2903 + ipkg_conf_override_string(&conf->offline_root,
2904 + args->offline_root);
2905 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2906 + args->offline_root_pre_script_cmd);
2907 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2908 + args->offline_root_post_script_cmd);
2910 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2911 + read anything from there.
2913 + if ( !(args->nocheckfordirorfile)){
2914 + /* need to run load the source list before dest list -Jamey */
2915 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2917 + /* Now that we have resolved conf->offline_root, we can commit to
2918 + the directory names for the dests and load in all the package
2920 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2923 + err = ipkg_conf_set_default_dest(conf, args->dest);
2929 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2931 + free(pending_dir);
2936 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2938 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2940 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2941 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2942 + __FUNCTION__, conf->tmp_dir);
2946 + err = rmdir(conf->tmp_dir);
2948 + if (errno == ENOTEMPTY) {
2950 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2951 + err = xsystem(cmd);
2955 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2957 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2959 + free(conf->tmp_dir); /*XXX*/
2961 + pkg_src_list_deinit(&conf->pkg_src_list);
2962 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2963 + nv_pair_list_deinit(&conf->arch_list);
2964 + if (&conf->pkg_hash)
2965 + pkg_hash_deinit(&conf->pkg_hash);
2966 + if (&conf->file_hash)
2967 + hash_table_deinit(&conf->file_hash);
2968 + if (&conf->obs_file_hash)
2969 + hash_table_deinit(&conf->obs_file_hash);
2971 + ipkg_conf_free_string(&conf->offline_root);
2972 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2973 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2975 + if (conf->verbosity > 1) {
2977 + hash_table_t *hashes[] = {
2980 + &conf->obs_file_hash };
2981 + for (i = 0; i < 3; i++) {
2982 + hash_table_t *hash = hashes[i];
2984 + int n_conflicts = 0;
2986 + for (j = 0; j < hash->n_entries; j++) {
2988 + hash_entry_t *e = &hash->entries[j];
2991 + while (e && e->key) {
2998 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2999 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
3000 + hash_table_deinit(hash);
3005 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3006 + const char *default_dest_name)
3008 + pkg_dest_list_elt_t *iter;
3011 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3012 + dest = iter->data;
3013 + if (strcmp(dest->name, default_dest_name) == 0) {
3014 + conf->default_dest = dest;
3015 + conf->restrict_to_default_dest = 1;
3020 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3025 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3027 + pkg_src_list_elt_t *iter;
3031 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3033 + if (src == NULL) {
3036 + if (conf->offline_root) {
3037 + sprintf_alloc(&list_file, "%s/%s/%s",
3038 + conf->offline_root,
3039 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3042 + sprintf_alloc(&list_file, "%s/%s",
3043 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3047 + if (file_exists(list_file)) {
3048 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3056 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3058 + nv_pair_list_elt_t *iter;
3059 + nv_pair_t *nv_pair;
3063 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3064 + nv_pair = iter->data;
3066 + if (conf->offline_root) {
3067 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3069 + root_dir = strdup(nv_pair->value);
3071 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3073 + if (dest == NULL) {
3076 + if (conf->default_dest == NULL) {
3077 + conf->default_dest = dest;
3079 + if (file_exists(dest->status_file_name)) {
3080 + pkg_hash_add_from_file(conf, dest->status_file_name,
3088 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3089 + pkg_src_list_t *pkg_src_list,
3090 + nv_pair_list_t *tmp_dest_nv_pair_list,
3093 + ipkg_option_t * options;
3094 + FILE *file = fopen(filename, "r");
3095 + regex_t valid_line_re, comment_re;
3096 +#define regmatch_size 12
3097 + regmatch_t regmatch[regmatch_size];
3099 + if (ipkg_init_options_array(conf, &options)<0)
3102 + if (file == NULL) {
3103 + fprintf(stderr, "%s: failed to open %s: %s\n",
3104 + __FUNCTION__, filename, strerror(errno));
3108 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3110 + xregcomp(&comment_re,
3111 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3113 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3118 + char *type, *name, *value, *extra;
3120 + line = file_read_line_alloc(file);
3122 + if (line == NULL) {
3128 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3132 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3134 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3135 + filename, line_num, line);
3139 + /* This has to be so ugly to deal with optional quotation marks */
3140 + if (regmatch[2].rm_so > 0) {
3141 + type = strndup(line + regmatch[2].rm_so,
3142 + regmatch[2].rm_eo - regmatch[2].rm_so);
3144 + type = strndup(line + regmatch[3].rm_so,
3145 + regmatch[3].rm_eo - regmatch[3].rm_so);
3147 + if (regmatch[5].rm_so > 0) {
3148 + name = strndup(line + regmatch[5].rm_so,
3149 + regmatch[5].rm_eo - regmatch[5].rm_so);
3151 + name = strndup(line + regmatch[6].rm_so,
3152 + regmatch[6].rm_eo - regmatch[6].rm_so);
3154 + if (regmatch[8].rm_so > 0) {
3155 + value = strndup(line + regmatch[8].rm_so,
3156 + regmatch[8].rm_eo - regmatch[8].rm_so);
3158 + value = strndup(line + regmatch[9].rm_so,
3159 + regmatch[9].rm_eo - regmatch[9].rm_so);
3162 + if (regmatch[11].rm_so > 0) {
3163 + extra = strndup (line + regmatch[11].rm_so,
3164 + regmatch[11].rm_eo - regmatch[11].rm_so);
3167 + /* We use the tmp_dest_nv_pair_list below instead of
3168 + conf->pkg_dest_list because we might encounter an
3169 + offline_root option later and that would invalidate the
3170 + directories we would have computed in
3171 + pkg_dest_list_init. (We do a similar thing with
3172 + tmp_src_nv_pair_list for sake of symmetry.) */
3173 + if (strcmp(type, "option") == 0) {
3174 + ipkg_conf_set_option(options, name, value);
3175 + } else if (strcmp(type, "src") == 0) {
3176 + if (!nv_pair_list_find(pkg_src_list, name)) {
3177 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3179 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3182 + } else if (strcmp(type, "src/gz") == 0) {
3183 + if (!nv_pair_list_find(pkg_src_list, name)) {
3184 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3186 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3189 + } else if (strcmp(type, "dest") == 0) {
3190 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3191 + } else if (strcmp(type, "lists_dir") == 0) {
3192 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3193 + if (*lists_dir == NULL) {
3194 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3198 + sprintf (*lists_dir,"%s",value);
3199 + } else if (strcmp(type, "arch") == 0) {
3200 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3202 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3203 + value = strdup("10");
3205 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3207 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3208 + "parameter: %s %s %s\n", type, name, value);
3224 + regfree(&comment_re);
3225 + regfree(&valid_line_re);
3231 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3232 + const char *name, const char *value)
3235 + while (options[i].name) {
3236 + if (strcmp(options[i].name, name) == 0) {
3237 + switch (options[i].type) {
3238 + case IPKG_OPT_TYPE_BOOL:
3239 + *((int *)options[i].value) = 1;
3241 + case IPKG_OPT_TYPE_INT:
3243 + *((int *)options[i].value) = atoi(value);
3246 + printf("%s: Option %s need an argument\n",
3247 + __FUNCTION__, name);
3250 + case IPKG_OPT_TYPE_STRING:
3252 + *((char **)options[i].value) = strdup(value);
3255 + printf("%s: Option %s need an argument\n",
3256 + __FUNCTION__, name);
3264 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3265 + __FUNCTION__, name, value);
3269 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3271 + pkg_dest_list_elt_t *iter;
3278 + if (conf->noaction)
3280 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3281 + dest = iter->data;
3282 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3283 + if (dest->status_file == NULL) {
3284 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3285 + __FUNCTION__, dest->status_file_name, strerror(errno));
3289 + all = pkg_vec_alloc();
3290 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3292 + for(i = 0; i < all->len; i++) {
3293 + pkg = all->pkgs[i];
3294 + /* We don't need most uninstalled packages in the status file */
3295 + if (pkg->state_status == SS_NOT_INSTALLED
3296 + && (pkg->state_want == SW_UNKNOWN
3297 + || pkg->state_want == SW_DEINSTALL
3298 + || pkg->state_want == SW_PURGE)) {
3302 + fprintf(stderr, "Null package\n");
3304 + if (pkg->dest == NULL) {
3305 + fprintf(stderr, "%s: ERROR: Can't write status for "
3306 + "package %s since it has a NULL dest\n",
3307 + __FUNCTION__, pkg->name);
3310 + if (pkg->dest->status_file) {
3311 + pkg_print_status(pkg, pkg->dest->status_file);
3315 + pkg_vec_free(all);
3317 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3318 + dest = iter->data;
3319 + if (dest->status_file) {
3320 + err = ferror(dest->status_file);
3321 + fclose(dest->status_file);
3322 + dest->status_file = NULL;
3324 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3326 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3327 + "retaining old %s\n", __FUNCTION__,
3328 + dest->status_file_tmp_name, dest->status_file_name);
3337 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3339 + char *root_filename;
3340 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3341 + return root_filename;
3343 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_conf.h busybox-1.1.1-new/archival/libipkg/ipkg_conf.h
3344 --- busybox-1.1.1-old/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3345 +++ busybox-1.1.1-new/archival/libipkg/ipkg_conf.h 2006-03-30 00:39:48.000000000 +0200
3347 +/* ipkg_conf.h - the itsy package management system
3351 + Copyright (C) 2001 University of Southern California
3353 + This program is free software; you can redistribute it and/or
3354 + modify it under the terms of the GNU General Public License as
3355 + published by the Free Software Foundation; either version 2, or (at
3356 + your option) any later version.
3358 + This program is distributed in the hope that it will be useful, but
3359 + WITHOUT ANY WARRANTY; without even the implied warranty of
3360 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3361 + General Public License for more details.
3364 +#ifndef IPKG_CONF_H
3365 +#define IPKG_CONF_H
3367 +typedef struct ipkg_conf ipkg_conf_t;
3369 +#include "hash_table.h"
3373 +#include "pkg_hash.h"
3374 +#include "pkg_src_list.h"
3375 +#include "pkg_dest_list.h"
3376 +#include "nv_pair_list.h"
3378 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3379 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3380 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3381 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3383 +/* In case the config file defines no dest */
3384 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3385 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3387 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3391 + pkg_src_list_t pkg_src_list;
3392 + pkg_dest_list_t pkg_dest_list;
3393 + nv_pair_list_t arch_list;
3395 + int restrict_to_default_dest;
3396 + pkg_dest_t *default_dest;
3399 + const char *lists_dir;
3400 + const char *pending_dir;
3403 + int force_depends;
3404 + int force_defaults;
3405 + int force_overwrite;
3406 + int force_downgrade;
3407 + int force_reinstall;
3409 + int force_removal_of_dependent_packages;
3410 + int force_removal_of_essential_packages;
3411 + int nodeps; /* do not follow dependences */
3413 + int multiple_providers;
3414 + char *offline_root;
3415 + char *offline_root_pre_script_cmd;
3416 + char *offline_root_post_script_cmd;
3421 + /* proxy options */
3426 + char *proxy_passwd;
3428 + hash_table_t pkg_hash;
3429 + hash_table_t file_hash;
3430 + hash_table_t obs_file_hash;
3433 +enum ipkg_option_type {
3434 + IPKG_OPT_TYPE_BOOL,
3435 + IPKG_OPT_TYPE_INT,
3436 + IPKG_OPT_TYPE_STRING
3438 +typedef enum ipkg_option_type ipkg_option_type_t;
3440 +typedef struct ipkg_option ipkg_option_t;
3441 +struct ipkg_option {
3443 + const ipkg_option_type_t type;
3444 + const void *value;
3447 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3448 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3450 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3451 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3454 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.c busybox-1.1.1-new/archival/libipkg/ipkg_configure.c
3455 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3456 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.c 2006-03-30 00:39:48.000000000 +0200
3458 +/* ipkg_configure.c - the itsy package management system
3462 + Copyright (C) 2001 University of Southern California
3464 + This program is free software; you can redistribute it and/or
3465 + modify it under the terms of the GNU General Public License as
3466 + published by the Free Software Foundation; either version 2, or (at
3467 + your option) any later version.
3469 + This program is distributed in the hope that it will be useful, but
3470 + WITHOUT ANY WARRANTY; without even the implied warranty of
3471 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3472 + General Public License for more details.
3477 +#include "ipkg_configure.h"
3479 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3483 + /* DPKG_INCOMPATIBILITY:
3484 + dpkg actually does some conffile handling here, rather than at the
3485 + end of ipkg_install(). Do we care? */
3486 + /* DPKG_INCOMPATIBILITY:
3487 + dpkg actually includes a version number to this script call */
3488 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3490 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3494 + ipkg_state_changed++;
3498 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_configure.h busybox-1.1.1-new/archival/libipkg/ipkg_configure.h
3499 --- busybox-1.1.1-old/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3500 +++ busybox-1.1.1-new/archival/libipkg/ipkg_configure.h 2006-03-30 00:39:48.000000000 +0200
3502 +/* ipkg_configure.h - the itsy package management system
3506 + Copyright (C) 2001 University of Southern California
3508 + This program is free software; you can redistribute it and/or
3509 + modify it under the terms of the GNU General Public License as
3510 + published by the Free Software Foundation; either version 2, or (at
3511 + your option) any later version.
3513 + This program is distributed in the hope that it will be useful, but
3514 + WITHOUT ANY WARRANTY; without even the implied warranty of
3515 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3516 + General Public License for more details.
3519 +#ifndef IPKG_CONFIGURE_H
3520 +#define IPKG_CONFIGURE_H
3522 +#include "ipkg_conf.h"
3524 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3527 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.c busybox-1.1.1-new/archival/libipkg/ipkg_download.c
3528 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3529 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.c 2006-03-30 00:39:48.000000000 +0200
3531 +/* ipkg_download.c - the itsy package management system
3535 + Copyright (C) 2001 University of Southern California
3537 + This program is free software; you can redistribute it and/or
3538 + modify it under the terms of the GNU General Public License as
3539 + published by the Free Software Foundation; either version 2, or (at
3540 + your option) any later version.
3542 + This program is distributed in the hope that it will be useful, but
3543 + WITHOUT ANY WARRANTY; without even the implied warranty of
3544 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3545 + General Public License for more details.
3549 +#include "ipkg_download.h"
3550 +#include "ipkg_message.h"
3552 +#include "sprintf_alloc.h"
3553 +#include "xsystem.h"
3554 +#include "file_util.h"
3555 +#include "str_util.h"
3557 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3561 + char *src_basec = strdup(src);
3562 + char *src_base = basename(src_basec);
3563 + char *tmp_file_location;
3566 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3570 + if (str_starts_with(src, "file:")) {
3572 + const char *file_src = src + 5;
3573 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3574 + ret = file_copy(src + 5, dest_file_name);
3575 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3579 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3580 + err = unlink(tmp_file_location);
3581 + if (err && errno != ENOENT) {
3582 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3583 + __FUNCTION__, tmp_file_location, strerror(errno));
3584 + free(tmp_file_location);
3588 + if (conf->http_proxy) {
3589 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3590 + setenv("http_proxy", conf->http_proxy, 1);
3592 + if (conf->ftp_proxy) {
3593 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3594 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3596 + if (conf->no_proxy) {
3597 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3598 + setenv("no_proxy", conf->no_proxy, 1);
3601 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3602 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3603 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3604 + conf->proxy_user ? "--proxy-user=" : "",
3605 + conf->proxy_user ? conf->proxy_user : "",
3606 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3607 + conf->proxy_passwd ? conf->proxy_passwd : "",
3608 + conf->verbose_wget ? "" : "-q",
3611 + err = xsystem(cmd);
3614 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3615 + __FUNCTION__, err, cmd);
3617 + unlink(tmp_file_location);
3618 + free(tmp_file_location);
3625 + err = file_move(tmp_file_location, dest_file_name);
3627 + free(tmp_file_location);
3637 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3642 + if (pkg->src == NULL) {
3643 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3644 + pkg->name, pkg->parent->name);
3648 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3650 + /* XXX: BUG: The pkg->filename might be something like
3651 + "../../foo.ipk". While this is correct, and exactly what we
3652 + want to use to construct url above, here we actually need to
3653 + use just the filename part, without any directory. */
3654 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3656 + err = ipkg_download(conf, url, pkg->local_filename);
3663 + * Downloads file from url, installs in package database, return package name.
3665 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3673 + if (str_starts_with(url, "http://")
3674 + || str_starts_with(url, "ftp://")) {
3676 + char *file_basec = strdup(url);
3677 + char *file_base = basename(file_basec);
3679 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3680 + err = ipkg_download(conf, url, tmp_file);
3684 + err = pkg_init_from_file(pkg, tmp_file);
3687 + pkg->local_filename = strdup(tmp_file);
3692 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3693 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3695 + err = pkg_init_from_file(pkg, url);
3698 + pkg->local_filename = strdup(url);
3704 + if (!pkg->architecture) {
3705 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3709 + pkg->dest = conf->default_dest;
3710 + pkg->state_want = SW_INSTALL;
3711 + pkg->state_flag |= SF_PREFER;
3712 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3713 + if ( pkg == NULL ){
3714 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3718 + *namep = pkg->name;
3722 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_download.h busybox-1.1.1-new/archival/libipkg/ipkg_download.h
3723 --- busybox-1.1.1-old/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3724 +++ busybox-1.1.1-new/archival/libipkg/ipkg_download.h 2006-03-30 00:39:48.000000000 +0200
3726 +/* ipkg_download.h - the itsy package management system
3730 + Copyright (C) 2001 University of Southern California
3732 + This program is free software; you can redistribute it and/or
3733 + modify it under the terms of the GNU General Public License as
3734 + published by the Free Software Foundation; either version 2, or (at
3735 + your option) any later version.
3737 + This program is distributed in the hope that it will be useful, but
3738 + WITHOUT ANY WARRANTY; without even the implied warranty of
3739 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3740 + General Public License for more details.
3743 +#ifndef IPKG_DOWNLOAD_H
3744 +#define IPKG_DOWNLOAD_H
3746 +#include "ipkg_conf.h"
3748 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3749 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3751 + * Downloads file from url, installs in package database, return package name.
3753 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3756 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_includes.h busybox-1.1.1-new/archival/libipkg/ipkg_includes.h
3757 --- busybox-1.1.1-old/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3758 +++ busybox-1.1.1-new/archival/libipkg/ipkg_includes.h 2006-03-30 00:39:48.000000000 +0200
3760 +#ifndef IPKG_INCLUDES_H
3761 +#define IPKG_INCLUDES_H
3763 +/* Define to 1 if you have the <memory.h> header file. */
3764 +#define HAVE_MEMORY_H 1
3766 +/* Define to 1 if you have the <regex.h> header file. */
3767 +#define HAVE_REGEX_H 1
3769 +/* Define to 1 if you have the <stdlib.h> header file. */
3770 +#define HAVE_STDLIB_H 1
3772 +/* Define to 1 if you have the <strings.h> header file. */
3773 +#define HAVE_STRINGS_H 1
3775 +/* Define to 1 if you have the <string.h> header file. */
3776 +#define HAVE_STRING_H 1
3778 +/* Define to 1 if you have the <sys/stat.h> header file. */
3779 +#define HAVE_SYS_STAT_H 1
3781 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3782 +#define HAVE_SYS_WAIT_H 1
3784 +/* Define to 1 if you have the <unistd.h> header file. */
3785 +#define HAVE_UNISTD_H 1
3787 +/* Define to 1 if you have the ANSI C header files. */
3788 +#define STDC_HEADERS 1
3794 +# include <stdlib.h>
3795 +# include <stdarg.h>
3796 +# include <stddef.h>
3797 +# include <ctype.h>
3798 +# include <errno.h>
3801 +# include <stdlib.h>
3806 +# include <regex.h>
3810 +# if !STDC_HEADERS && HAVE_MEMORY_H
3811 +# include <memory.h>
3813 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3815 +# define __USE_GNU 1
3817 +# include <string.h>
3822 +# include <strings.h>
3825 +#if HAVE_SYS_STAT_H
3826 +# include <sys/stat.h>
3829 +#if HAVE_SYS_WAIT_H
3830 +# include <sys/wait.h>
3834 +# include <sys/types.h>
3835 +# include <unistd.h>
3838 +#endif /* IPKG_INCLUDES_H */
3839 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_install.c busybox-1.1.1-new/archival/libipkg/ipkg_install.c
3840 --- busybox-1.1.1-old/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3841 +++ busybox-1.1.1-new/archival/libipkg/ipkg_install.c 2006-03-30 00:39:48.000000000 +0200
3843 +/* ipkg_install.c - the itsy package management system
3847 + Copyright (C) 2001 University of Southern California
3849 + This program is free software; you can redistribute it and/or
3850 + modify it under the terms of the GNU General Public License as
3851 + published by the Free Software Foundation; either version 2, or (at
3852 + your option) any later version.
3854 + This program is distributed in the hope that it will be useful, but
3855 + WITHOUT ANY WARRANTY; without even the implied warranty of
3856 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3857 + General Public License for more details.
3862 +#include <dirent.h>
3865 +#include <signal.h>
3866 +typedef void (*sighandler_t)(int);
3869 +#include "pkg_hash.h"
3870 +#include "pkg_extract.h"
3872 +#include "ipkg_install.h"
3873 +#include "ipkg_configure.h"
3874 +#include "ipkg_download.h"
3875 +#include "ipkg_remove.h"
3877 +#include "ipkg_utils.h"
3878 +#include "ipkg_message.h"
3880 +#include "sprintf_alloc.h"
3881 +#include "file_util.h"
3882 +#include "str_util.h"
3883 +#include "xsystem.h"
3886 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3887 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3888 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3890 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3891 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3892 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3893 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3894 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3900 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3901 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3903 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3904 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3905 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3906 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3907 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3909 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3911 +static int user_prefers_old_conffile(const char *file, const char *backup);
3913 +static char *backup_filename_alloc(const char *file_name);
3914 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3915 +static int backup_exists_for(const char *file_name);
3916 +static int backup_remove(const char *file_name);
3919 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3923 + char *old_version, *new_version;
3926 + if (pkg == NULL) {
3930 + err = pkg_init_from_file(pkg, filename);
3935 + if (!pkg->architecture) {
3936 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3940 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3941 + freeing the pkg that we pass in. It might be nice to clean this up
3943 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3944 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3946 + pkg->local_filename = strdup(filename);
3949 + old_version = pkg_version_str_alloc(old);
3950 + new_version = pkg_version_str_alloc(pkg);
3952 + cmp = pkg_compare_versions(old, pkg);
3953 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3954 + cmp = -1 ; /* then we force ipkg to downgrade */
3955 + /* We need to use a value < 0 because in the 0 case we are asking to */
3956 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3959 + ipkg_message(conf, IPKG_NOTICE,
3960 + "Not downgrading package %s on %s from %s to %s.\n",
3961 + old->name, old->dest->name, old_version, new_version);
3962 + pkg->state_want = SW_DEINSTALL;
3963 + pkg->state_flag |= SF_OBSOLETE;
3964 + free(old_version);
3965 + free(new_version);
3968 + free(old_version);
3969 + free(new_version);
3973 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3974 + return ipkg_install_pkg(conf, pkg);
3977 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3981 + char *old_version, *new_version;
3983 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3985 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3986 + if (new == NULL) {
3987 + return IPKG_PKG_HAS_NO_CANDIDATE;
3990 + new->state_flag |= SF_USER;
3992 + old_version = pkg_version_str_alloc(old);
3993 + new_version = pkg_version_str_alloc(new);
3995 + cmp = pkg_compare_versions(old, new);
3996 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3997 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3998 + cmp = -1 ; /* then we force ipkg to downgrade */
3999 + /* We need to use a value < 0 because in the 0 case we are asking to */
4000 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4002 + ipkg_message(conf, IPKG_DEBUG,
4003 + "comparing visible versions of pkg %s:"
4004 + "\n\t%s is installed "
4005 + "\n\t%s is available "
4006 + "\n\t%d was comparison result\n",
4007 + pkg_name, old_version, new_version, cmp);
4008 + if (cmp == 0 && !conf->force_reinstall) {
4009 + ipkg_message(conf, IPKG_NOTICE,
4010 + "Package %s (%s) installed in %s is up to date.\n",
4011 + old->name, old_version, old->dest->name);
4012 + free(old_version);
4013 + free(new_version);
4015 + } else if (cmp > 0) {
4016 + ipkg_message(conf, IPKG_NOTICE,
4017 + "Not downgrading package %s on %s from %s to %s.\n",
4018 + old->name, old->dest->name, old_version, new_version);
4019 + free(old_version);
4020 + free(new_version);
4022 + } else if (cmp < 0) {
4023 + new->dest = old->dest;
4024 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4028 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4029 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4030 + return any kind of integer, (might be errno from a syscall,
4031 + etc.). This is a real mess and will need to be cleaned up if
4032 + anyone ever wants to make a nice libipkg. */
4034 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4035 + return ipkg_install_pkg(conf, new);
4038 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4040 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4043 + abstract_pkg_t *ppkg ;
4045 + if (providers == NULL)
4046 + return IPKG_PKG_HAS_NO_CANDIDATE;
4048 + for (i = 0; i < providers->len; i++) {
4049 + ppkg = abstract_pkg_vec_get(providers, i);
4050 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4051 + err = ipkg_install_by_name(conf, ppkg->name);
4054 +/* XXX Maybe ppkg should be freed ? */
4060 + * Walk dependence graph starting with pkg, collect packages to be
4061 + * installed into pkgs_needed, in dependence order.
4063 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4066 + pkg_vec_t *depends = pkg_vec_alloc();
4067 + char **unresolved = NULL;
4070 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4075 + ipkg_message(conf, IPKG_ERROR,
4076 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4077 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4078 + while (*unresolved) {
4079 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4082 + ipkg_message(conf, IPKG_ERROR, "\n");
4083 + if (! conf->force_depends) {
4084 + ipkg_message(conf, IPKG_INFO,
4085 + "This could mean that your package list is out of date or that the packages\n"
4086 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4087 + "of this problem try again with the '-force-depends' option.\n");
4088 + pkg_vec_free(depends);
4089 + return IPKG_PKG_DEPS_UNSATISFIED;
4093 + if (ndepends <= 0) {
4094 + pkg_vec_free(depends);
4098 + for (i = 0; i < depends->len; i++) {
4099 + pkg_t *dep = depends->pkgs[i];
4100 + /* The package was uninstalled when we started, but another
4101 + dep earlier in this loop may have depended on it and pulled
4102 + it in, so check first. */
4103 + if ((dep->state_status != SS_INSTALLED)
4104 + && (dep->state_status != SS_UNPACKED)
4105 + && (dep->state_want != SW_INSTALL)) {
4107 + /* Mark packages as to-be-installed */
4108 + dep->state_want = SW_INSTALL;
4110 + /* Dependencies should be installed the same place as pkg */
4111 + if (dep->dest == NULL) {
4112 + dep->dest = pkg->dest;
4115 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4117 + pkg_vec_free(depends);
4123 + pkg_vec_insert(pkgs_needed, pkg);
4125 + pkg_vec_free(depends);
4130 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4134 + char *old_version, *new_version;
4136 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4138 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4139 + if (new == NULL) {
4140 + return IPKG_PKG_HAS_NO_CANDIDATE;
4143 + old_version = pkg_version_str_alloc(old);
4144 + new_version = pkg_version_str_alloc(new);
4146 + cmp = pkg_compare_versions(old, new);
4147 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4148 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4149 + cmp = -1 ; /* then we force ipkg to downgrade */
4150 + /* We need to use a value < 0 because in the 0 case we are asking to */
4151 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4153 + ipkg_message(conf, IPKG_DEBUG,
4154 + "comparing visible versions of pkg %s:"
4155 + "\n\t%s is installed "
4156 + "\n\t%s is available "
4157 + "\n\t%d was comparison result\n",
4158 + pkg_name, old_version, new_version, cmp);
4159 + if (cmp == 0 && !conf->force_reinstall) {
4160 + ipkg_message(conf, IPKG_NOTICE,
4161 + "Package %s (%s) installed in %s is up to date.\n",
4162 + old->name, old_version, old->dest->name);
4163 + free(old_version);
4164 + free(new_version);
4166 + } else if (cmp > 0) {
4167 + ipkg_message(conf, IPKG_NOTICE,
4168 + "Not downgrading package %s on %s from %s to %s.\n",
4169 + old->name, old->dest->name, old_version, new_version);
4170 + free(old_version);
4171 + free(new_version);
4173 + } else if (cmp < 0) {
4174 + new->dest = old->dest;
4175 + old->state_want = SW_DEINSTALL;
4176 + old->state_flag |= SF_OBSOLETE;
4179 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4184 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4187 + pkg_vec_t *depends = pkg_vec_alloc();
4189 + char **unresolved = NULL;
4192 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4197 + ipkg_message(conf, IPKG_ERROR,
4198 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4199 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4200 + while (*unresolved) {
4201 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4204 + ipkg_message(conf, IPKG_ERROR, "\n");
4205 + if (! conf->force_depends) {
4206 + ipkg_message(conf, IPKG_INFO,
4207 + "This could mean that your package list is out of date or that the packages\n"
4208 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4209 + "of this problem try again with the '-force-depends' option.\n");
4210 + pkg_vec_free(depends);
4211 + return IPKG_PKG_DEPS_UNSATISFIED;
4215 + if (ndepends <= 0) {
4219 + /* Mark packages as to-be-installed */
4220 + for (i=0; i < depends->len; i++) {
4221 + /* Dependencies should be installed the same place as pkg */
4222 + if (depends->pkgs[i]->dest == NULL) {
4223 + depends->pkgs[i]->dest = pkg->dest;
4225 + depends->pkgs[i]->state_want = SW_INSTALL;
4228 + for (i = 0; i < depends->len; i++) {
4229 + dep = depends->pkgs[i];
4230 + /* The package was uninstalled when we started, but another
4231 + dep earlier in this loop may have depended on it and pulled
4232 + it in, so check first. */
4233 + if ((dep->state_status != SS_INSTALLED)
4234 + && (dep->state_status != SS_UNPACKED)) {
4235 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4236 + err = ipkg_install_pkg(conf, dep);
4238 + pkg_vec_free(depends);
4244 + pkg_vec_free(depends);
4250 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4251 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4253 + if (conf->nodeps == 0) {
4255 + pkg_vec_t *installed = pkg_vec_alloc();
4256 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4257 + for (i = 0; i < installed->len; i++) {
4258 + pkg_t *pkg = installed->pkgs[i];
4259 + satisfy_dependencies_for(conf, pkg);
4261 + pkg_vec_free(installed);
4268 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4271 + pkg_vec_t *conflicts = NULL;
4273 + const char *prefix;
4274 + if (conf->force_depends) {
4275 + level = IPKG_NOTICE;
4276 + prefix = "Warning";
4278 + level = IPKG_ERROR;
4282 + if (!conf->force_depends)
4283 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4286 + ipkg_message(conf, level,
4287 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4289 + while (i < conflicts->len)
4290 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4291 + ipkg_message(conf, level, "\n");
4292 + pkg_vec_free(conflicts);
4293 + return IPKG_PKG_DEPS_UNSATISFIED;
4298 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4300 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4301 + str_list_elt_t *iter;
4303 + for (iter = new_list->head; iter; iter = iter->next) {
4304 + char *new_file = iter->data;
4305 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4307 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4308 + if (!owner || (owner == old_pkg))
4309 + file_hash_set_file_owner(conf, new_file, new_pkg);
4312 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4313 + for (iter = old_list->head; iter; iter = iter->next) {
4314 + char *old_file = iter->data;
4315 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4316 + if (owner == old_pkg) {
4318 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4325 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4327 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4329 + /* sma 6.20.02: yup; here's the first bit */
4331 + * XXX: BUG easy for cworth
4332 + * 1) please point the call below to the correct current root destination
4333 + * 2) we need to resolve how to check the required space for a pending pkg,
4334 + * my diddling with the .ipk file size below isn't going to cut it.
4335 + * 3) return a proper error code instead of 1
4337 + int comp_size, blocks_available;
4339 + if (!conf->force_space && pkg->installed_size != NULL) {
4340 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4342 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4343 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4344 + comp_size = (int)((comp_size + 1023) / 1024);
4346 + if (comp_size >= blocks_available) {
4347 + ipkg_message(conf, IPKG_ERROR,
4348 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4349 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4356 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4359 + char *conffiles_file_name;
4361 + FILE *conffiles_file;
4363 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4365 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4366 + if (pkg->tmp_unpack_dir == NULL) {
4367 + ipkg_message(conf, IPKG_ERROR,
4368 + "%s: Failed to create temporary directory '%s': %s\n",
4369 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4373 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4378 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4379 + conffiles. Seems like I should be able to get everything to go
4380 + through pkg_init_from_file. If so, maybe it would make sense to
4381 + move all of unpack_pkg_control_files to that function. */
4383 + /* Don't need to re-read conffiles if we already have it */
4384 + if (pkg->conffiles.head) {
4388 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4389 + if (! file_exists(conffiles_file_name)) {
4390 + free(conffiles_file_name);
4394 + conffiles_file = fopen(conffiles_file_name, "r");
4395 + if (conffiles_file == NULL) {
4396 + fprintf(stderr, "%s: failed to open %s: %s\n",
4397 + __FUNCTION__, conffiles_file_name, strerror(errno));
4398 + free(conffiles_file_name);
4401 + free(conffiles_file_name);
4405 + char *cf_name_in_dest;
4407 + cf_name = file_read_line_alloc(conffiles_file);
4408 + if (cf_name == NULL) {
4411 + str_chomp(cf_name);
4412 + if (cf_name[0] == '\0') {
4416 + /* Prepend dest->root_dir to conffile name.
4417 + Take pains to avoid multiple slashes. */
4418 + root_dir = pkg->dest->root_dir;
4419 + if (conf->offline_root)
4420 + /* skip the offline_root prefix */
4421 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4422 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4423 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4425 + /* Can't get an md5sum now, (file isn't extracted yet).
4426 + We'll wait until resolve_conffiles */
4427 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4430 + free(cf_name_in_dest);
4433 + fclose(conffiles_file);
4438 +/* returns number of installed replacees */
4439 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4441 + abstract_pkg_t **replaces = pkg->replaces;
4442 + int replaces_count = pkg->replaces_count;
4444 + for (i = 0; i < replaces_count; i++) {
4445 + abstract_pkg_t *ab_pkg = replaces[i];
4446 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4448 + for (j = 0; j < pkg_vec->len; j++) {
4449 + pkg_t *replacee = pkg_vec->pkgs[j];
4450 + if (!pkg_conflicts(pkg, replacee))
4452 + if (replacee->state_status == SS_INSTALLED) {
4453 + pkg_vec_insert(installed_replacees, replacee);
4458 + return installed_replacees->len;
4461 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4464 + int replaces_count = replacees->len;
4465 + for (i = 0; i < replaces_count; i++) {
4466 + pkg_t *replacee = replacees->pkgs[i];
4468 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4469 + err = ipkg_remove_pkg(conf, replacee);
4476 +/* to unwind the removal: make sure they are installed */
4477 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4480 + int replaces_count = replacees->len;
4481 + for (i = 0; i < replaces_count; i++) {
4482 + pkg_t *replacee = replacees->pkgs[i];
4483 + if (replacee->state_status != SS_INSTALLED) {
4484 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4485 + err = ipkg_install_pkg(conf, replacee);
4493 +int caught_sigint = 0;
4494 +static void ipkg_install_pkg_sigint_handler(int sig)
4496 + caught_sigint = sig;
4499 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4500 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4503 + char message_out[15];
4504 + char *old_version = pkg_version_str_alloc(old_pkg);
4505 + char *new_version = pkg_version_str_alloc(pkg);
4506 + int cmp = pkg_compare_versions(old_pkg, pkg);
4509 + strncpy (message_out,"Upgrading ",13);
4510 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4511 + cmp = -1 ; /* then we force ipkg to downgrade */
4512 + strncpy (message_out,"Downgrading ",13); /* We need to use a value < 0 because in the 0 case we are asking to */
4513 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4517 + ipkg_message(conf, IPKG_NOTICE,
4518 + "Not downgrading package %s on %s from %s to %s.\n",
4519 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4521 + } else if (cmp < 0) {
4522 + ipkg_message(conf, IPKG_NOTICE,
4523 + "%s %s on %s from %s to %s...\n",
4524 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4525 + pkg->dest = old_pkg->dest;
4527 + } else /* cmp == 0 */ {
4528 + if (conf->force_reinstall) {
4529 + ipkg_message(conf, IPKG_NOTICE,
4530 + "Reinstalling %s (%s) on %s...\n",
4531 + pkg->name, new_version, old_pkg->dest->name);
4532 + pkg->dest = old_pkg->dest;
4535 + ipkg_message(conf, IPKG_NOTICE,
4536 + "Not installing %s (%s) on %s -- already installed.\n",
4537 + pkg->name, new_version, old_pkg->dest->name);
4541 + free(old_version);
4542 + free(new_version);
4545 + char *version = pkg_version_str_alloc(pkg);
4546 + ipkg_message(conf, IPKG_NOTICE,
4547 + "Installing %s (%s) to %s...\n",
4548 + pkg->name, version, pkg->dest->name);
4554 +/* and now the meat... */
4555 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg)
4558 + pkg_t *old_pkg = NULL;
4559 + pkg_vec_t *replacees;
4560 + abstract_pkg_t *ab_pkg = NULL;
4561 + int old_state_flag;
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);
4593 + if (err) { return err; }
4595 + pkg->state_want = SW_INSTALL;
4596 + if (old_pkg) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4598 + /* Abhaya: conflicts check */
4599 + err = check_conflicts_for(conf, pkg);
4600 + if (err) { return err; }
4602 + /* this setup is to remove the upgrade scenario in the end when
4603 + installing pkg A, A deps B & B deps on A. So both B and A are
4604 + installed. Then A's installation is started resulting in an
4605 + uncecessary upgrade */
4606 + if (pkg->state_status == SS_INSTALLED
4607 + && conf->force_reinstall == 0) return 0;
4609 + err = verify_pkg_installable(conf, pkg);
4610 + if (err) { return err; }
4612 + if (pkg->local_filename == NULL) {
4613 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4615 + ipkg_message(conf, IPKG_ERROR,
4616 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4621 + if (pkg->tmp_unpack_dir == NULL) {
4622 + unpack_pkg_control_files(conf, pkg);
4625 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4626 + err = update_file_ownership(conf, pkg, old_pkg);
4627 + if (err) { return err; }
4629 + if (conf->nodeps == 0) {
4630 + err = satisfy_dependencies_for(conf, pkg);
4631 + if (err) { return err; }
4634 + replacees = pkg_vec_alloc();
4635 + pkg_get_installed_replacees(conf, pkg, replacees);
4637 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4639 + sigset_t newset, oldset;
4640 + sighandler_t old_handler = NULL;
4641 + int use_signal = 0;
4642 + caught_sigint = 0;
4644 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4646 + sigemptyset(&newset);
4647 + sigaddset(&newset, SIGINT);
4648 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4651 + ipkg_state_changed++;
4652 + pkg->state_flag |= SF_FILELIST_CHANGED;
4654 + /* XXX: BUG: we really should treat replacement more like an upgrade
4655 + * Instead, we're going to remove the replacees
4657 + err = pkg_remove_installed_replacees(conf, replacees);
4658 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4660 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4661 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4663 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4664 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4666 + err = preinst_configure(conf, pkg, old_pkg);
4667 + if (err) goto UNWIND_PREINST_CONFIGURE;
4669 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4670 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4672 + err = check_data_file_clashes(conf, pkg, old_pkg);
4673 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4675 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4676 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4678 + if (conf->noaction) return 0;
4680 + /* point of no return: no unwinding after this */
4681 + if (old_pkg && !conf->force_reinstall) {
4682 + old_pkg->state_want = SW_DEINSTALL;
4684 + if (old_pkg->state_flag & SF_NOPRUNE) {
4685 + ipkg_message(conf, IPKG_INFO,
4686 + " not removing obsolesced files because package marked noprune\n");
4688 + ipkg_message(conf, IPKG_INFO,
4689 + " removing obsolesced files\n");
4690 + remove_obsolesced_files(conf, pkg, old_pkg);
4693 + ipkg_message(conf, IPKG_INFO,
4694 + " installing maintainer scripts\n");
4695 + install_maintainer_scripts(conf, pkg, old_pkg);
4697 + /* the following just returns 0 */
4698 + remove_disappeared(conf, pkg);
4700 + ipkg_message(conf, IPKG_INFO,
4701 + " installing data files\n");
4702 + install_data_files(conf, pkg);
4704 + ipkg_message(conf, IPKG_INFO,
4705 + " resolving conf files\n");
4706 + resolve_conffiles(conf, pkg);
4708 + pkg->state_status = SS_UNPACKED;
4709 + old_state_flag = pkg->state_flag;
4710 + pkg->state_flag &= ~SF_PREFER;
4711 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4713 + if (old_pkg && !conf->force_reinstall) {
4714 + old_pkg->state_status = SS_NOT_INSTALLED;
4717 + time(&pkg->installed_time);
4719 + ipkg_message(conf, IPKG_INFO,
4720 + " cleanup temp files\n");
4721 + cleanup_temporary_files(conf, pkg);
4723 + ab_pkg = pkg->parent;
4725 + ab_pkg->state_status = pkg->state_status;
4727 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4730 + signal(SIGINT, old_handler);
4732 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4737 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4738 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4739 + UNWIND_CHECK_DATA_FILE_CLASHES:
4740 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4741 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4742 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4743 + UNWIND_PREINST_CONFIGURE:
4744 + preinst_configure_unwind(conf, pkg, old_pkg);
4745 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4746 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4747 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4748 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4749 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4750 + pkg_remove_installed_replacees_unwind(conf, replacees);
4752 + ipkg_message(conf, IPKG_INFO,
4753 + " cleanup temp files\n");
4754 + cleanup_temporary_files(conf, pkg);
4756 + ipkg_message(conf, IPKG_INFO,
4759 + signal(SIGINT, old_handler);
4761 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4767 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4769 + /* DPKG_INCOMPATIBILITY:
4770 + dpkg does some things here that we don't do yet. Do we care?
4772 + 1. If a version of the package is already installed, call
4773 + old-prerm upgrade new-version
4774 + 2. If the script runs but exits with a non-zero exit status
4775 + new-prerm failed-upgrade old-version
4776 + Error unwind, for both the above cases:
4777 + old-postinst abort-upgrade new-version
4782 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4784 + /* DPKG_INCOMPATIBILITY:
4785 + dpkg does some things here that we don't do yet. Do we care?
4786 + (See prerm_upgrade_old_package for details)
4791 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4793 + /* DPKG_INCOMPATIBILITY:
4794 + dpkg does some things here that we don't do yet. Do we care?
4795 + 2. If a 'conflicting' package is being removed at the same time:
4796 + 1. If any packages depended on that conflicting package and
4797 + --auto-deconfigure is specified, call, for each such package:
4798 + deconfigured's-prerm deconfigure \
4799 + in-favour package-being-installed version \
4800 + removing conflicting-package version
4802 + deconfigured's-postinst abort-deconfigure \
4803 + in-favour package-being-installed-but-failed version \
4804 + removing conflicting-package version
4806 + The deconfigured packages are marked as requiring
4807 + configuration, so that if --install is used they will be
4808 + configured again if possible.
4809 + 2. To prepare for removal of the conflicting package, call:
4810 + conflictor's-prerm remove in-favour package new-version
4812 + conflictor's-postinst abort-remove in-favour package new-version
4817 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4819 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4820 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4825 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4828 + char *preinst_args;
4831 + char *old_version = pkg_version_str_alloc(old_pkg);
4832 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4833 + free(old_version);
4834 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4835 + char *pkg_version = pkg_version_str_alloc(pkg);
4836 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4837 + free(pkg_version);
4839 + preinst_args = strdup("install");
4842 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4844 + ipkg_message(conf, IPKG_ERROR,
4845 + "Aborting installation of %s\n", pkg->name);
4849 + free(preinst_args);
4854 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4856 + /* DPKG_INCOMPATIBILITY:
4857 + dpkg does the following error unwind, should we?
4858 + pkg->postrm abort-upgrade old-version
4859 + OR pkg->postrm abort-install old-version
4860 + OR pkg->postrm abort-install
4865 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4868 + conffile_list_elt_t *iter;
4871 + if (conf->noaction) return 0;
4873 + /* Backup all modified conffiles */
4875 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4879 + cf_name = root_filename_alloc(conf, cf->name);
4881 + /* Don't worry if the conffile is just plain gone */
4882 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4883 + err = backup_make_backup(conf, cf_name);
4892 + /* Backup all conffiles that were not conffiles in old_pkg */
4893 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4896 + cf_name = root_filename_alloc(conf, cf->name);
4897 + /* Ignore if this was a conffile in old_pkg as well */
4898 + if (pkg_get_conffile(old_pkg, cf->name)) {
4902 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4903 + err = backup_make_backup(conf, cf_name);
4914 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4916 + conffile_list_elt_t *iter;
4919 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4920 + backup_remove(iter->data->name);
4924 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4925 + backup_remove(iter->data->name);
4931 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4933 + /* DPKG_INCOMPATIBILITY:
4934 + ipkg takes a slightly different approach than dpkg at this
4935 + point. dpkg installs each file in the new package while
4936 + creating a backup for any file that is replaced, (so that it
4937 + can unwind if necessary). To avoid complexity and redundant
4938 + storage, ipkg doesn't do any installation until later, (at the
4939 + point at which dpkg removes the backups.
4941 + But, we do have to check for data file clashes, since after
4942 + installing a package with a file clash, removing either of the
4943 + packages involved in the clash has the potential to break the
4946 + str_list_t *files_list;
4947 + str_list_elt_t *iter;
4951 + files_list = pkg_get_installed_files(pkg);
4952 + for (iter = files_list->head; iter; iter = iter->next) {
4953 + char *root_filename;
4954 + char *filename = iter->data;
4955 + root_filename = root_filename_alloc(conf, filename);
4956 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4959 + /* Pre-existing conffiles are OK */
4960 + /* @@@@ should have way to check that it is a conffile -Jamey */
4961 + if (backup_exists_for(root_filename)) {
4965 + /* Pre-existing files are OK if force-overwrite was asserted. */
4966 + if (conf->force_overwrite) {
4967 + /* but we need to change who owns this file */
4968 + file_hash_set_file_owner(conf, filename, pkg);
4972 + owner = file_hash_get_file_owner(conf, filename);
4974 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4975 + if (owner && old_pkg) {
4976 + if (strcmp(owner->name, old_pkg->name) == 0) {
4981 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4983 + if (pkg_replaces(pkg, owner)) {
4984 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4987 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4988 + then it's ok to overwrite. */
4989 + if (strcmp(owner->name,pkg->name)==0){
4990 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4995 + /* Pre-existing files are OK if they are obsolete */
4996 + obs = hash_table_get(&conf->obs_file_hash, filename);
4998 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5002 + /* We have found a clash. */
5003 + ipkg_message(conf, IPKG_ERROR,
5004 + "Package %s wants to install file %s\n"
5005 + "\tBut that file is already provided by package ",
5006 + pkg->name, filename);
5008 + ipkg_message(conf, IPKG_ERROR,
5009 + "%s\n", owner->name);
5011 + ipkg_message(conf, IPKG_ERROR,
5012 + "<no package>\nPlease move this file out of the way and try again.\n");
5016 + free(root_filename);
5018 + pkg_free_installed_files(pkg);
5023 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5025 + /* Nothing to do since check_data_file_clashes doesn't change state */
5029 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5031 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5032 + 1. If the package is being upgraded, call
5033 + old-postrm upgrade new-version
5034 + 2. If this fails, attempt:
5035 + new-postrm failed-upgrade old-version
5036 + Error unwind, for both cases:
5037 + old-preinst abort-upgrade new-version */
5041 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5043 + /* DPKG_INCOMPATIBILITY:
5044 + dpkg does some things here that we don't do yet. Do we care?
5045 + (See postrm_upgrade_old_pkg for details)
5050 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5053 + str_list_t *old_files;
5054 + str_list_elt_t *of;
5055 + str_list_t *new_files;
5056 + str_list_elt_t *nf;
5058 + if (old_pkg == NULL) {
5062 + old_files = pkg_get_installed_files(old_pkg);
5063 + new_files = pkg_get_installed_files(pkg);
5065 + for (of = old_files->head; of; of = of->next) {
5069 + for (nf = new_files->head; nf; nf = nf->next) {
5071 + if (strcmp(old, new) == 0) {
5072 + goto NOT_OBSOLETE;
5075 + if (file_is_dir(old)) {
5078 + owner = file_hash_get_file_owner(conf, old);
5079 + if (owner != old_pkg) {
5080 + /* in case obsolete file no longer belongs to old_pkg */
5084 + /* old file is obsolete */
5085 + ipkg_message(conf, IPKG_INFO,
5086 + " removing obsolete file %s\n", old);
5087 + if (!conf->noaction) {
5088 + err = unlink(old);
5090 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5099 + pkg_free_installed_files(old_pkg);
5100 + pkg_free_installed_files(pkg);
5105 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5109 + char *globpattern;
5113 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5116 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5117 + err = glob(globpattern, 0, NULL, &globbuf);
5118 + free(globpattern);
5122 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5123 + for (i = 0; i < globbuf.gl_pathc; i++) {
5124 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5125 + globbuf.gl_pathv[i], old_pkg->name);
5126 + if (!conf->noaction)
5127 + unlink(globbuf.gl_pathv[i]);
5129 + globfree(&globbuf);
5134 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5140 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5141 + sprintf_alloc(&prefix, "%s.", pkg->name);
5142 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5143 + pkg->dest->info_dir,
5149 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5151 + /* DPKG_INCOMPATIBILITY:
5152 + This is a fairly sophisticated dpkg operation. Shall we
5155 + /* Any packages all of whose files have been overwritten during the
5156 + installation, and which aren't required for dependencies, are
5157 + considered to have been removed. For each such package
5158 + 1. disappearer's-postrm disappear overwriter overwriter-version
5159 + 2. The package's maintainer scripts are removed
5160 + 3. It is noted in the status database as being in a sane state,
5161 + namely not installed (any conffiles it may have are ignored,
5162 + rather than being removed by dpkg). Note that disappearing
5163 + packages do not have their prerm called, because dpkg doesn't
5164 + know in advance that the package is going to vanish.
5169 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5173 + /* ipkg takes a slightly different approach to data file backups
5174 + than dpkg. Rather than removing backups at this point, we
5175 + actually do the data file installation now. See comments in
5176 + check_data_file_clashes() for more details. */
5178 + ipkg_message(conf, IPKG_INFO,
5179 + " extracting data files to %s\n", pkg->dest->root_dir);
5180 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5185 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5186 + so we can't save ourself from removing important packages
5187 + At this point we (should) have extracted the .control file, so it
5188 + would be a good idea to reload the data in it, and set the Essential
5189 + state in *pkg. From now on the Essential is back in status file and
5190 + we can protect again.
5191 + We should operate this way:
5192 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5193 + check for "Essential" in it
5194 + set the value in pkg->essential.
5195 + This new routine could be useful also for every other flag
5196 + Pigi: 16/03/2004 */
5197 + set_flags_from_control(conf, pkg) ;
5199 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5200 + err = pkg_write_filelist(conf, pkg);
5204 + /* XXX: FEATURE: ipkg should identify any files which existed
5205 + before installation and which were overwritten, (see
5206 + check_data_file_clashes()). What it must do is remove any such
5207 + files from the filelist of the old package which provided the
5208 + file. Otherwise, if the old package were removed at some point
5209 + it would break the new package. Removing the new package will
5210 + also break the old one, but this cannot be helped since the old
5211 + package's file has already been deleted. This is the importance
5212 + of check_data_file_clashes(), and only allowing ipkg to install
5213 + a clashing package with a user force. */
5218 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5220 + conffile_list_elt_t *iter;
5227 + if (conf->noaction) return 0;
5229 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5230 + char *root_filename;
5232 + root_filename = root_filename_alloc(conf, cf->name);
5234 + /* Might need to initialize the md5sum for each conffile */
5235 + if (cf->value == NULL) {
5236 + cf->value = file_md5sum_alloc(root_filename);
5239 + if (!file_exists(root_filename)) {
5240 + free(root_filename);
5244 + cf_backup = backup_filename_alloc(root_filename);
5247 + if (file_exists(cf_backup)) {
5248 + /* Let's compute md5 to test if files are changed */
5249 + md5sum = file_md5sum_alloc(cf_backup);
5250 + if (strcmp( cf->value,md5sum) != 0 ) {
5251 + if (conf->force_defaults
5252 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5253 + rename(cf_backup, root_filename);
5256 + unlink(cf_backup);
5261 + free(root_filename);
5267 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5270 + const char *short_file_name;
5272 + short_file_name = strrchr(file_name, '/');
5273 + if (short_file_name) {
5274 + short_file_name++;
5276 + short_file_name = file_name;
5280 + response = get_user_response(" Configuration file '%s'\n"
5281 + " ==> File on system created by you or by a script.\n"
5282 + " ==> File also in package provided by package maintainer.\n"
5283 + " What would you like to do about it ? Your options are:\n"
5284 + " Y or I : install the package maintainer's version\n"
5285 + " N or O : keep your currently-installed version\n"
5286 + " D : show the differences between the versions (if diff is installed)\n"
5287 + " The default action is to keep your current version.\n"
5288 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5289 + if (strcmp(response, "y") == 0
5290 + || strcmp(response, "i") == 0
5291 + || strcmp(response, "yes") == 0) {
5296 + if (strcmp(response, "d") == 0) {
5300 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5301 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5304 + printf(" [Press ENTER to continue]\n");
5305 + response = file_read_line_alloc(stdin);
5315 +/* XXX: CLEANUP: I'd like to move all of the code for
5316 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5317 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5318 + pkg_deinit for example). */
5319 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5322 + struct dirent *dirent;
5325 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5327 + ipkg_message(conf, IPKG_DEBUG,
5328 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5329 + __FUNCTION__, pkg->tmp_unpack_dir);
5333 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5334 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5337 + dirent = readdir(tmp_dir);
5338 + if (dirent == NULL) {
5341 + sprintf_alloc(&tmp_file, "%s/%s",
5342 + pkg->tmp_unpack_dir, dirent->d_name);
5343 + if (! file_is_dir(tmp_file)) {
5348 + closedir(tmp_dir);
5349 + rmdir(pkg->tmp_unpack_dir);
5350 + free(pkg->tmp_unpack_dir);
5351 + pkg->tmp_unpack_dir = NULL;
5355 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5356 + pkg->name, pkg->local_filename, conf->tmp_dir);
5357 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5358 + unlink(pkg->local_filename);
5359 + free(pkg->local_filename);
5360 + pkg->local_filename = NULL;
5366 +static char *backup_filename_alloc(const char *file_name)
5370 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5375 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5380 + backup = backup_filename_alloc(file_name);
5381 + err = file_copy(file_name, backup);
5383 + ipkg_message(conf, IPKG_ERROR,
5384 + "%s: Failed to copy %s to %s\n",
5385 + __FUNCTION__, file_name, backup);
5393 +static int backup_exists_for(const char *file_name)
5398 + backup = backup_filename_alloc(file_name);
5400 + ret = file_exists(backup);
5407 +static int backup_remove(const char *file_name)
5411 + backup = backup_filename_alloc(file_name);
5420 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5422 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5424 + /* first, remove the packages that need removing */
5425 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5426 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5427 + err = ipkg_remove_pkg(conf, pkg);
5428 + if (err) return err;
5433 +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)
5436 + /* now one more pass checking on the ones that need to be installed */
5437 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5438 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5439 + if (pkg->dest == NULL)
5440 + pkg->dest = conf->default_dest;
5442 + pkg->state_want = SW_INSTALL;
5444 + /* Abhaya: conflicts check */
5445 + err = check_conflicts_for(conf, pkg);
5446 + if (err) { return err; }
5451 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5454 + /* now one more pass checking on the ones that need to be installed */
5455 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5456 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5458 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5459 + pkg_vec_t *replacees = pkg_vec_alloc();
5460 + pkg_get_installed_replacees(conf, pkg, replacees);
5462 + /* XXX: BUG: we really should treat replacement more like an upgrade
5463 + * Instead, we're going to remove the replacees
5465 + err = pkg_remove_installed_replacees(conf, replacees);
5466 + if (err) return err;
5467 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5472 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5475 + /* now one more pass checking on the ones that need to be installed */
5476 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5477 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5478 + if (pkg->local_filename == NULL) {
5479 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5481 + ipkg_message(conf, IPKG_ERROR,
5482 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5487 + if (pkg->tmp_unpack_dir == NULL) {
5488 + err = unpack_pkg_control_files(conf, pkg);
5489 + if (err) return err;
5495 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5498 + /* now one more pass checking on the ones that need to be installed */
5499 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5500 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5501 + pkg_t *old_pkg = pkg->old_pkg;
5503 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5504 + if (err) return err;
5506 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5507 + if (err) return err;
5509 + err = preinst_configure(conf, pkg, old_pkg);
5510 + if (err) return err;
5512 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5513 + if (err) return err;
5515 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5516 + if (err) return err;
5521 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5524 + /* now one more pass checking on the ones that need to be installed */
5525 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5526 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5527 + pkg_t *old_pkg = pkg->old_pkg;
5530 + old_pkg->state_want = SW_DEINSTALL;
5532 + if (old_pkg->state_flag & SF_NOPRUNE) {
5533 + ipkg_message(conf, IPKG_INFO,
5534 + " not removing obsolesced files because package marked noprune\n");
5536 + ipkg_message(conf, IPKG_INFO,
5537 + " removing obsolesced files\n");
5538 + remove_obsolesced_files(conf, pkg, old_pkg);
5542 + ipkg_message(conf, IPKG_INFO,
5543 + " installing maintainer scripts\n");
5544 + install_maintainer_scripts(conf, pkg, old_pkg);
5546 + /* the following just returns 0 */
5547 + remove_disappeared(conf, pkg);
5549 + ipkg_message(conf, IPKG_INFO,
5550 + " installing data files\n");
5551 + install_data_files(conf, pkg);
5553 + ipkg_message(conf, IPKG_INFO,
5554 + " resolving conf files\n");
5555 + resolve_conffiles(conf, pkg);
5557 + pkg->state_status = SS_UNPACKED;
5560 + old_pkg->state_status = SS_NOT_INSTALLED;
5563 + time(&pkg->installed_time);
5565 + ipkg_message(conf, IPKG_INFO,
5566 + " cleanup temp files\n");
5567 + cleanup_temporary_files(conf, pkg);
5570 + pkg->parent->state_status = pkg->state_status;
5575 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5578 + /* now one more pass checking on the ones that need to be installed */
5579 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5580 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5581 + pkg_t *old_pkg = pkg->old_pkg;
5584 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5585 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5586 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5587 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5588 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5589 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5590 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5591 + preinst_configure_unwind(conf, pkg, old_pkg);
5592 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5593 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5594 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5595 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5597 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5598 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5606 + * Perform all the actions.
5608 + * pkgs_to_remove are packages marked for removal.
5609 + * pkgs_superseded are the old packages being replaced by upgrades.
5611 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5613 +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)
5618 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5619 + if (err) return err;
5621 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5622 + if (err) return err;
5624 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5625 + if (err) goto UNWIND;
5627 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5628 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5629 + if (err) goto UNWIND;
5632 + * Now that we have the packages unpacked, we can look for data
5633 + * file clashes. First, we mark the files from the superseded
5634 + * packages as obsolete. Then we scan the files in
5635 + * pkgs_to_install, and only complain about clashes with
5636 + * non-obsolete files.
5639 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5640 + if (err) goto UNWIND;
5642 + /* this was before checking data file clashes */
5643 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5644 + if (err) goto UNWIND;
5646 + /* point of no return: no unwinding after this */
5647 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5648 + if (err) return err;
5650 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5654 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5656 + ipkg_message(conf, IPKG_INFO,
5657 + " cleanup temp files\n");
5658 + cleanup_temporary_files(conf, pkg);
5660 + ipkg_message(conf, IPKG_INFO,
5666 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_install.h busybox-1.1.1-new/archival/libipkg/ipkg_install.h
5667 --- busybox-1.1.1-old/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5668 +++ busybox-1.1.1-new/archival/libipkg/ipkg_install.h 2006-03-30 00:39:48.000000000 +0200
5670 +/* ipkg_install.h - the itsy package management system
5674 + Copyright (C) 2001 University of Southern California
5676 + This program is free software; you can redistribute it and/or
5677 + modify it under the terms of the GNU General Public License as
5678 + published by the Free Software Foundation; either version 2, or (at
5679 + your option) any later version.
5681 + This program is distributed in the hope that it will be useful, but
5682 + WITHOUT ANY WARRANTY; without even the implied warranty of
5683 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5684 + General Public License for more details.
5687 +#ifndef IPKG_INSTALL_H
5688 +#define IPKG_INSTALL_H
5691 +#include "ipkg_conf.h"
5693 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5694 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5695 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5696 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg);
5697 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5699 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5701 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5702 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5705 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_message.c busybox-1.1.1-new/archival/libipkg/ipkg_message.c
5706 --- busybox-1.1.1-old/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5707 +++ busybox-1.1.1-new/archival/libipkg/ipkg_message.c 2006-03-30 00:39:48.000000000 +0200
5709 +/* ipkg_message.c - the itsy package management system
5711 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5713 + This program is free software; you can redistribute it and/or
5714 + modify it under the terms of the GNU General Public License as
5715 + published by the Free Software Foundation; either version 2, or (at
5716 + your option) any later version.
5718 + This program is distributed in the hope that it will be useful, but
5719 + WITHOUT ANY WARRANTY; without even the implied warranty of
5720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5721 + General Public License for more details.
5726 +#include "ipkg_conf.h"
5727 +#include "ipkg_message.h"
5732 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5736 + if (conf && (conf->verbosity < level))
5743 + va_start (ap, fmt);
5744 + vprintf (fmt, ap);
5751 +#include "libipkg.h"
5753 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5756 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5761 + if (ipkg_cb_message)
5763 + va_start (ap, fmt);
5764 + vsnprintf (ts,256,fmt, ap);
5766 + ipkg_cb_message(conf,level,ts);
5770 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_message.h busybox-1.1.1-new/archival/libipkg/ipkg_message.h
5771 --- busybox-1.1.1-old/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5772 +++ busybox-1.1.1-new/archival/libipkg/ipkg_message.h 2006-03-30 00:39:48.000000000 +0200
5774 +/* ipkg_message.h - the itsy package management system
5776 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5778 + This program is free software; you can redistribute it and/or
5779 + modify it under the terms of the GNU General Public License as
5780 + published by the Free Software Foundation; either version 2, or (at
5781 + your option) any later version.
5783 + This program is distributed in the hope that it will be useful, but
5784 + WITHOUT ANY WARRANTY; without even the implied warranty of
5785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5786 + General Public License for more details.
5789 +#ifndef _IPKG_MESSAGE_H_
5790 +#define _IPKG_MESSAGE_H_
5793 +#include "ipkg_conf.h"
5796 + IPKG_ERROR, /* error conditions */
5797 + IPKG_NOTICE, /* normal but significant condition */
5798 + IPKG_INFO, /* informational message */
5799 + IPKG_DEBUG, /* debug level message */
5800 + IPKG_DEBUG2, /* more debug level message */
5803 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5805 +#endif /* _IPKG_MESSAGE_H_ */
5806 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_remove.c busybox-1.1.1-new/archival/libipkg/ipkg_remove.c
5807 --- busybox-1.1.1-old/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5808 +++ busybox-1.1.1-new/archival/libipkg/ipkg_remove.c 2006-03-30 00:39:48.000000000 +0200
5810 +/* ipkg_remove.c - the itsy package management system
5814 + Copyright (C) 2001 University of Southern California
5816 + This program is free software; you can redistribute it and/or
5817 + modify it under the terms of the GNU General Public License as
5818 + published by the Free Software Foundation; either version 2, or (at
5819 + your option) any later version.
5821 + This program is distributed in the hope that it will be useful, but
5822 + WITHOUT ANY WARRANTY; without even the implied warranty of
5823 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5824 + General Public License for more details.
5828 +#include "ipkg_message.h"
5832 +#include "ipkg_remove.h"
5834 +#include "file_util.h"
5835 +#include "sprintf_alloc.h"
5836 +#include "str_util.h"
5838 +#include "ipkg_cmd.h"
5840 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
5841 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5842 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5845 + * Returns number of the number of packages depending on the packages provided by this package.
5846 + * Every package implicitly provides itself.
5848 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5850 + int nprovides = pkg->provides_count;
5851 + abstract_pkg_t **provides = pkg->provides;
5852 + int n_installed_dependents = 0;
5854 + for (i = 0; i <= nprovides; i++) {
5855 + abstract_pkg_t *providee = provides[i];
5856 + abstract_pkg_t **dependers = providee->depended_upon_by;
5857 + abstract_pkg_t *dep_ab_pkg;
5858 + if (dependers == NULL)
5860 + while ((dep_ab_pkg = *dependers++) != NULL) {
5861 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5862 + n_installed_dependents++;
5867 + /* if caller requested the set of installed dependents */
5868 + if (pdependents) {
5870 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5872 + if ( dependents == NULL ){
5873 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5877 + *pdependents = dependents;
5878 + for (i = 0; i <= nprovides; i++) {
5879 + abstract_pkg_t *providee = provides[i];
5880 + abstract_pkg_t **dependers = providee->depended_upon_by;
5881 + abstract_pkg_t *dep_ab_pkg;
5882 + if (dependers == NULL)
5884 + while ((dep_ab_pkg = *dependers++) != NULL) {
5885 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5886 + dependents[p++] = dep_ab_pkg;
5887 + dep_ab_pkg->state_flag |= SF_MARKED;
5891 + dependents[p] = NULL;
5892 + /* now clear the marks */
5893 + for (i = 0; i < p; i++) {
5894 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5895 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5898 + return n_installed_dependents;
5901 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5906 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5907 + abstract_pkg_t * ab_pkg;
5909 + if((ab_pkg = pkg->parent) == NULL){
5910 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5911 + __FUNCTION__, pkg->name);
5915 + if (dependents == NULL)
5918 + // here i am using the dependencies_checked
5919 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5920 + return 0; // has already been encountered in the process
5921 + // of marking packages for removal - Karthik
5922 + ab_pkg->dependencies_checked = 2;
5926 + while (dependents [i] != NULL) {
5927 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5929 + if (dep_ab_pkg->dependencies_checked == 2){
5933 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5934 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5935 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5936 + if (dep_pkg->state_status == SS_INSTALLED) {
5937 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5943 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5944 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5951 + for (i = 0; i < dependent_pkgs->len; i++) {
5952 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5959 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5961 + abstract_pkg_t *dep_ab_pkg;
5962 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5963 + while ((dep_ab_pkg = *dependents++) != NULL) {
5964 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5965 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5967 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5968 + ipkg_message(conf, IPKG_ERROR, "");
5969 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5970 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5971 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5972 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5973 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5977 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5980 + abstract_pkg_t *parent_pkg = NULL;
5982 + if (pkg->essential) {
5983 + if (conf->force_removal_of_essential_packages) {
5984 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5985 + "\tIf your system breaks, you get to keep both pieces\n",
5988 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5989 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5990 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5991 + "\tits will with the option: -force-removal-of-essential-packages\n",
5993 + return IPKG_PKG_IS_ESSENTIAL;
5997 + if ((parent_pkg = pkg->parent) == NULL)
6000 + /* only attempt to remove dependent installed packages if
6001 + * force_depends is not specified or the package is being
6004 + if (!conf->force_depends
6005 + && !(pkg->state_flag & SF_REPLACE)) {
6006 + abstract_pkg_t **dependents;
6007 + int has_installed_dependents =
6008 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6010 + if (has_installed_dependents) {
6012 + * if this package is depended up by others, then either we should
6013 + * not remove it or we should remove it and all of its dependents
6016 + if (!conf->force_removal_of_dependent_packages
6017 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6018 + return IPKG_PKG_HAS_DEPENDENTS;
6021 + /* remove packages depending on this package - Karthik */
6022 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6024 + if (err) return err;
6028 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6031 + pkg->state_flag |= SF_FILELIST_CHANGED;
6033 + pkg->state_want = SW_DEINSTALL;
6034 + ipkg_state_changed++;
6036 + pkg_run_script(conf, pkg, "prerm", "remove");
6038 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6039 + maintains an empty filelist rather than deleting it. That seems
6040 + like a big pain, and I don't see that that should make a big
6041 + difference, but for anyone who wants tighter compatibility,
6042 + feel free to fix this. */
6043 + remove_data_files_and_list(conf, pkg);
6045 + pkg_run_script(conf, pkg, "postrm", "remove");
6047 + remove_maintainer_scripts_except_postrm(conf, pkg);
6049 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6050 + * space, it doesn't make sense to leave extra configurations, files,
6051 + * and maintainer scripts left around. So, we make remove like purge,
6052 + * and take out all the crap :) */
6054 + remove_postrm(conf, pkg);
6055 + pkg->state_status = SS_NOT_INSTALLED;
6058 + parent_pkg->state_status = SS_NOT_INSTALLED;
6063 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6065 + ipkg_remove_pkg(conf, pkg);
6069 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6071 + str_list_t installed_dirs;
6072 + str_list_t *installed_files;
6073 + str_list_elt_t *iter;
6075 + conffile_t *conffile;
6076 + int removed_a_dir;
6079 + str_list_init(&installed_dirs);
6080 + installed_files = pkg_get_installed_files(pkg);
6082 + for (iter = installed_files->head; iter; iter = iter->next) {
6083 + file_name = iter->data;
6085 + if (file_is_dir(file_name)) {
6086 + str_list_append(&installed_dirs, strdup(file_name));
6090 + conffile = pkg_get_conffile(pkg, file_name);
6092 + /* XXX: QUESTION: Is this right? I figure we only need to
6093 + save the conffile if it has been modified. Is that what
6094 + dpkg does? Or does dpkg preserve all conffiles? If so,
6095 + this seems like a better thing to do to conserve
6097 + if (conffile_has_been_modified(conf, conffile)) {
6098 + printf(" not deleting modified conffile %s\n", file_name);
6104 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6105 + if (!conf->noaction)
6106 + unlink(file_name);
6109 + if (!conf->noaction) {
6111 + removed_a_dir = 0;
6112 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6113 + file_name = iter->data;
6115 + if (rmdir(file_name) == 0) {
6116 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6117 + removed_a_dir = 1;
6118 + str_list_remove(&installed_dirs, &iter);
6121 + } while (removed_a_dir);
6124 + pkg_free_installed_files(pkg);
6125 + /* We have to remove the file list now, so that
6126 + find_pkg_owning_file does not always just report this package */
6127 + pkg_remove_installed_files_list(conf, pkg);
6129 + /* Don't print warning for dirs that are provided by other packages */
6130 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6131 + file_name = iter->data;
6133 + owner = file_hash_get_file_owner(conf, file_name);
6136 + iter->data = NULL;
6137 + str_list_remove(&installed_dirs, &iter);
6142 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6144 + iter->data = NULL;
6146 + str_list_deinit(&installed_dirs);
6151 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6154 + char *globpattern;
6157 + if (conf->noaction) return 0;
6159 + sprintf_alloc(&globpattern, "%s/%s.*",
6160 + pkg->dest->info_dir, pkg->name);
6161 + err = glob(globpattern, 0, NULL, &globbuf);
6162 + free(globpattern);
6167 + for (i = 0; i < globbuf.gl_pathc; i++) {
6168 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6171 + unlink(globbuf.gl_pathv[i]);
6173 + globfree(&globbuf);
6178 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6180 + char *postrm_file_name;
6182 + if (conf->noaction) return 0;
6184 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6185 + pkg->dest->info_dir, pkg->name);
6186 + unlink(postrm_file_name);
6187 + free(postrm_file_name);
6191 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_remove.h busybox-1.1.1-new/archival/libipkg/ipkg_remove.h
6192 --- busybox-1.1.1-old/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6193 +++ busybox-1.1.1-new/archival/libipkg/ipkg_remove.h 2006-03-30 00:39:48.000000000 +0200
6195 +/* ipkg_remove.h - the itsy package management system
6199 + Copyright (C) 2001 University of Southern California
6201 + This program is free software; you can redistribute it and/or
6202 + modify it under the terms of the GNU General Public License as
6203 + published by the Free Software Foundation; either version 2, or (at
6204 + your option) any later version.
6206 + This program is distributed in the hope that it will be useful, but
6207 + WITHOUT ANY WARRANTY; without even the implied warranty of
6208 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6209 + General Public License for more details.
6212 +#ifndef IPKG_REMOVE_H
6213 +#define IPKG_REMOVE_H
6216 +#include "ipkg_conf.h"
6218 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6219 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6220 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6221 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6224 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.c busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.c
6225 --- busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6226 +++ busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.c 2006-03-30 00:39:48.000000000 +0200
6228 +/* ipkg_upgrade.c - the itsy package management system
6231 + Copyright (C) 2001 University of Southern California
6233 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6235 + This program is free software; you can redistribute it and/or
6236 + modify it under the terms of the GNU General Public License as
6237 + published by the Free Software Foundation; either version 2, or (at
6238 + your option) any later version.
6240 + This program is distributed in the hope that it will be useful, but
6241 + WITHOUT ANY WARRANTY; without even the implied warranty of
6242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6243 + General Public License for more details.
6247 +#include "ipkg_install.h"
6248 +#include "ipkg_message.h"
6250 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6254 + char *old_version, *new_version;
6256 + if (old->state_flag & SF_HOLD) {
6257 + ipkg_message(conf, IPKG_NOTICE,
6258 + "Not upgrading package %s which is marked "
6259 + "hold (flags=%#x)\n", old->name, old->state_flag);
6263 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6264 + if (new == NULL) {
6265 + old_version = pkg_version_str_alloc(old);
6266 + ipkg_message(conf, IPKG_NOTICE,
6267 + "Assuming locally installed package %s (%s) "
6268 + "is up to date.\n", old->name, old_version);
6269 + free(old_version);
6273 + old_version = pkg_version_str_alloc(old);
6274 + new_version = pkg_version_str_alloc(new);
6276 + cmp = pkg_compare_versions(old, new);
6277 + ipkg_message(conf, IPKG_DEBUG,
6278 + "comparing visible versions of pkg %s:"
6279 + "\n\t%s is installed "
6280 + "\n\t%s is available "
6281 + "\n\t%d was comparison result\n",
6282 + old->name, old_version, new_version, cmp);
6284 + ipkg_message(conf, IPKG_INFO,
6285 + "Package %s (%s) installed in %s is up to date.\n",
6286 + old->name, old_version, old->dest->name);
6287 + free(old_version);
6288 + free(new_version);
6290 + } else if (cmp > 0) {
6291 + ipkg_message(conf, IPKG_NOTICE,
6292 + "Not downgrading package %s on %s from %s to %s.\n",
6293 + old->name, old->dest->name, old_version, new_version);
6294 + free(old_version);
6295 + free(new_version);
6297 + } else if (cmp < 0) {
6298 + new->dest = old->dest;
6299 + old->state_want = SW_DEINSTALL;
6302 + new->state_flag |= SF_USER;
6303 + return ipkg_install_pkg(conf, new);
6305 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.h busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.h
6306 --- busybox-1.1.1-old/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6307 +++ busybox-1.1.1-new/archival/libipkg/ipkg_upgrade.h 2006-03-30 00:39:48.000000000 +0200
6309 +/* ipkg_upgrade.c - the itsy package management system
6311 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6313 + This program is free software; you can redistribute it and/or
6314 + modify it under the terms of the GNU General Public License as
6315 + published by the Free Software Foundation; either version 2, or (at
6316 + your option) any later version.
6318 + This program is distributed in the hope that it will be useful, but
6319 + WITHOUT ANY WARRANTY; without even the implied warranty of
6320 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6321 + General Public License for more details.
6326 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6327 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_utils.c busybox-1.1.1-new/archival/libipkg/ipkg_utils.c
6328 --- busybox-1.1.1-old/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6329 +++ busybox-1.1.1-new/archival/libipkg/ipkg_utils.c 2006-03-30 00:39:48.000000000 +0200
6331 +/* ipkg_utils.c - the itsy package management system
6335 + Copyright (C) 2002 Compaq Computer Corporation
6337 + This program is free software; you can redistribute it and/or
6338 + modify it under the terms of the GNU General Public License as
6339 + published by the Free Software Foundation; either version 2, or (at
6340 + your option) any later version.
6342 + This program is distributed in the hope that it will be useful, but
6343 + WITHOUT ANY WARRANTY; without even the implied warranty of
6344 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6345 + General Public License for more details.
6351 +#include <sys/vfs.h>
6353 +#include "ipkg_utils.h"
6355 +#include "pkg_hash.h"
6357 +struct errlist* error_list;
6359 +int get_available_blocks(char * filesystem)
6361 + struct statfs sfs;
6363 + if(statfs(filesystem, &sfs)){
6364 + fprintf(stderr, "bad statfs\n");
6367 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6368 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6371 +char **read_raw_pkgs_from_file(const char *file_name)
6376 + if(!(fp = fopen(file_name, "r"))){
6377 + fprintf(stderr, "can't get %s open for read\n", file_name);
6381 + ret = read_raw_pkgs_from_stream(fp);
6388 +char **read_raw_pkgs_from_stream(FILE *fp)
6390 + char **raw = NULL, *buf, *scout;
6392 + size_t size = 512;
6394 + buf = malloc (size);
6396 + while (fgets(buf, size, fp)) {
6397 + while (strlen (buf) == (size - 1)
6398 + && buf[size-2] != '\n') {
6399 + size_t o = size - 1;
6401 + buf = realloc (buf, size);
6402 + if (fgets (buf + o, size - o, fp) == NULL)
6407 + raw = realloc(raw, (count + 50) * sizeof(char *));
6409 + if((scout = strchr(buf, '\n')))
6412 + raw[count++] = strdup(buf);
6415 + raw = realloc(raw, (count + 1) * sizeof(char *));
6416 + raw[count] = NULL;
6423 +/* something to remove whitespace, a hash pooper */
6424 +char *trim_alloc(char *line)
6427 + char *dest, *src, *end;
6429 + new = malloc(strlen(line) + 1);
6430 + if ( new == NULL ){
6431 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6434 + dest = new, src = line, end = line + (strlen(line) - 1);
6436 + /* remove it from the front */
6441 + /* and now from the back */
6442 + while((end > src) &&
6448 + /* this does from the first space
6449 + * blasting away any versions stuff in depends
6460 +int line_is_blank(const char *line)
6464 + for (s = line; *s; s++) {
6471 +void push_error_list(struct errlist ** errors, char * msg){
6472 + struct errlist *err_lst_tmp;
6475 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6476 + err_lst_tmp->errmsg=strdup(msg) ;
6477 + err_lst_tmp->next = *errors;
6478 + *errors = err_lst_tmp;
6482 +void reverse_error_list(struct errlist **errors){
6483 + struct errlist *result=NULL;
6484 + struct errlist *current= *errors;
6485 + struct errlist *next;
6487 + while ( current != NULL ) {
6488 + next = current->next;
6489 + current->next=result;
6498 +void free_error_list(struct errlist **errors){
6499 + struct errlist *current = *errors;
6501 + while (current != NULL) {
6502 + free(current->errmsg);
6503 + current = (*errors)->next;
6505 + *errors = current;
6512 diff -ruN busybox-1.1.1-old/archival/libipkg/ipkg_utils.h busybox-1.1.1-new/archival/libipkg/ipkg_utils.h
6513 --- busybox-1.1.1-old/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6514 +++ busybox-1.1.1-new/archival/libipkg/ipkg_utils.h 2006-03-30 00:39:48.000000000 +0200
6516 +/* ipkg_utils.h - the itsy package management system
6520 + Copyright (C) 2002 Compaq Computer Corporation
6522 + This program is free software; you can redistribute it and/or
6523 + modify it under the terms of the GNU General Public License as
6524 + published by the Free Software Foundation; either version 2, or (at
6525 + your option) any later version.
6527 + This program is distributed in the hope that it will be useful, but
6528 + WITHOUT ANY WARRANTY; without even the implied warranty of
6529 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6530 + General Public License for more details.
6533 +#ifndef IPKG_UTILS_H
6534 +#define IPKG_UTILS_H
6538 +int get_available_blocks(char * filesystem);
6539 +char **read_raw_pkgs_from_file(const char *file_name);
6540 +char **read_raw_pkgs_from_stream(FILE *fp);
6541 +char *trim_alloc(char * line);
6542 +int line_is_blank(const char *line);
6545 diff -ruN busybox-1.1.1-old/archival/libipkg/libipkg.c busybox-1.1.1-new/archival/libipkg/libipkg.c
6546 --- busybox-1.1.1-old/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6547 +++ busybox-1.1.1-new/archival/libipkg/libipkg.c 2006-03-30 00:39:48.000000000 +0200
6549 +/* ipkglib.c - the itsy package management system
6553 + Copyright (C) 2003 kernel concepts
6555 + This program is free software; you can redistribute it and/or
6556 + modify it under the terms of the GNU General Public License as
6557 + published by the Free Software Foundation; either version 2, or (at
6558 + your option) any later version.
6560 + This program is distributed in the hope that it will be useful, but
6561 + WITHOUT ANY WARRANTY; without even the implied warranty of
6562 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6563 + General Public License for more details.
6569 +#include "ipkg_includes.h"
6570 +#include "libipkg.h"
6573 +#include "ipkg_conf.h"
6574 +#include "ipkg_cmd.h"
6575 +#include "file_util.h"
6579 +ipkg_message_callback ipkg_cb_message = NULL;
6580 +ipkg_response_callback ipkg_cb_response = NULL;
6581 +ipkg_status_callback ipkg_cb_status = NULL;
6582 +ipkg_list_callback ipkg_cb_list = NULL;
6586 +ipkg_init (ipkg_message_callback mcall,
6587 + ipkg_response_callback rcall,
6590 + ipkg_cb_message = mcall;
6591 + ipkg_cb_response = rcall;
6600 +ipkg_deinit (args_t * args)
6602 + args_deinit (args);
6603 + ipkg_cb_message = NULL;
6604 + ipkg_cb_response = NULL;
6606 + /* place other cleanup stuff here */
6613 +ipkg_packages_list(args_t *args,
6614 + const char *packages,
6615 + ipkg_list_callback cblist,
6619 + ipkg_conf_t ipkg_conf;
6622 + err = ipkg_conf_init (&ipkg_conf, args);
6628 + ipkg_cb_list = cblist;
6629 + /* we need to do this because of static declarations,
6630 + * maybe a good idea to change */
6631 + cmd = ipkg_cmd_find ("list");
6633 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6635 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6636 + ipkg_cb_list = NULL;
6637 + ipkg_conf_deinit (&ipkg_conf);
6643 +ipkg_packages_status(args_t *args,
6644 + const char *packages,
6645 + ipkg_status_callback cbstatus,
6649 + ipkg_conf_t ipkg_conf;
6652 + err = ipkg_conf_init (&ipkg_conf, args);
6658 + ipkg_cb_status = cbstatus;
6660 + /* we need to do this because of static declarations,
6661 + * maybe a good idea to change */
6662 + cmd = ipkg_cmd_find ("status");
6664 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6666 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6668 + ipkg_cb_status = NULL;
6669 + ipkg_conf_deinit (&ipkg_conf);
6675 +ipkg_packages_info(args_t *args,
6676 + const char *packages,
6677 + ipkg_status_callback cbstatus,
6681 + ipkg_conf_t ipkg_conf;
6684 + err = ipkg_conf_init (&ipkg_conf, args);
6690 + ipkg_cb_status = cbstatus;
6692 + /* we need to do this because of static declarations,
6693 + * maybe a good idea to change */
6694 + cmd = ipkg_cmd_find ("info");
6696 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6698 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6700 + ipkg_cb_status = NULL;
6701 + ipkg_conf_deinit (&ipkg_conf);
6707 +ipkg_packages_install (args_t * args, const char *name)
6710 + ipkg_conf_t ipkg_conf;
6713 + /* this error should be handled in application */
6714 + if (!name || !strlen (name))
6717 + err = ipkg_conf_init (&ipkg_conf, args);
6723 + /* we need to do this because of static declarations,
6724 + * maybe a good idea to change */
6725 + cmd = ipkg_cmd_find ("install");
6726 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6728 + ipkg_conf_deinit(&ipkg_conf);
6734 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6737 + ipkg_conf_t ipkg_conf;
6740 + /* this error should be handled in application */
6741 + if (!name || !strlen (name))
6744 + err = ipkg_conf_init (&ipkg_conf, args);
6750 + /* we need to do this because of static declarations,
6751 + * maybe a good idea to change */
6753 + cmd = ipkg_cmd_find ("purge");
6755 + cmd = ipkg_cmd_find ("remove");
6757 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6759 + ipkg_conf_deinit(&ipkg_conf);
6765 +ipkg_lists_update(args_t *args)
6768 + ipkg_conf_t ipkg_conf;
6771 + err = ipkg_conf_init (&ipkg_conf, args);
6777 + /* we need to do this because of static declarations,
6778 + * maybe a good idea to change */
6779 + cmd = ipkg_cmd_find ("update");
6781 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6783 + ipkg_conf_deinit(&ipkg_conf);
6789 +ipkg_packages_upgrade(args_t *args)
6792 + ipkg_conf_t ipkg_conf;
6795 + err = ipkg_conf_init (&ipkg_conf, args);
6801 + /* we need to do this because of static declarations,
6802 + * maybe a good idea to change */
6803 + cmd = ipkg_cmd_find ("upgrade");
6805 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6807 + ipkg_conf_deinit(&ipkg_conf);
6813 +ipkg_packages_download (args_t * args, const char *name)
6816 + ipkg_conf_t ipkg_conf;
6819 + /* this error should be handled in application */
6820 + if (!name || !strlen (name))
6823 + err = ipkg_conf_init (&ipkg_conf, args);
6829 + /* we need to do this because of static declarations,
6830 + * maybe a good idea to change */
6831 + cmd = ipkg_cmd_find ("download");
6832 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6834 + ipkg_conf_deinit(&ipkg_conf);
6840 +ipkg_package_files(args_t *args,
6842 + ipkg_list_callback cblist,
6846 + ipkg_conf_t ipkg_conf;
6849 + /* this error should be handled in application */
6850 + if (!name || !strlen (name))
6853 + err = ipkg_conf_init (&ipkg_conf, args);
6859 + ipkg_cb_list = cblist;
6861 + /* we need to do this because of static declarations,
6862 + * maybe a good idea to change */
6863 + cmd = ipkg_cmd_find ("files");
6865 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6867 + ipkg_cb_list = NULL;
6868 + ipkg_conf_deinit(&ipkg_conf);
6874 +ipkg_file_search(args_t *args,
6876 + ipkg_list_callback cblist,
6880 + ipkg_conf_t ipkg_conf;
6883 + /* this error should be handled in application */
6884 + if (!file || !strlen (file))
6887 + err = ipkg_conf_init (&ipkg_conf, args);
6893 + ipkg_cb_list = cblist;
6895 + /* we need to do this because of static declarations,
6896 + * maybe a good idea to change */
6897 + cmd = ipkg_cmd_find ("search");
6898 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6900 + ipkg_cb_list = NULL;
6901 + ipkg_conf_deinit(&ipkg_conf);
6907 +ipkg_file_what(args_t *args, const char *file, const char* command)
6910 + ipkg_conf_t ipkg_conf;
6913 + /* this error should be handled in application */
6914 + if (!file || !strlen (file))
6917 + err = ipkg_conf_init (&ipkg_conf, args);
6923 + /* we need to do this because of static declarations,
6924 + * maybe a good idea to change */
6925 + cmd = ipkg_cmd_find (command);
6926 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6928 + ipkg_conf_deinit(&ipkg_conf);
6932 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6933 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6934 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6935 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6936 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6939 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6942 + if (conf && (conf->verbosity < level)) {
6946 + if ( level == IPKG_ERROR ){
6947 + push_error_list(&error_list, msg);
6956 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6957 + pkg_state_status_t status, void *userdata)
6960 + printf("%s - %s - %s\n", name, version, desc);
6962 + printf("%s - %s\n", name, version);
6966 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6967 + pkg_state_status_t status, void *userdata)
6970 + printf("%s\n", desc);
6974 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6977 + printf("%s\n", desc);
6981 +char* default_ipkg_response_callback(char *question)
6983 + char *response = NULL;
6987 + response = (char *)file_read_line_alloc(stdin);
6988 + } while (response == NULL);
6992 +/* This is used for backward compatibility */
6994 +ipkg_op (int argc, char *argv[])
7000 + ipkg_conf_t ipkg_conf;
7002 + args_init (&args);
7004 + optind = args_parse (&args, argc, argv);
7005 + if (optind == argc || optind < 0)
7007 + args_usage ("ipkg must have one sub-command argument");
7010 + cmd_name = argv[optind++];
7011 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7012 + read anything from there.
7014 + if ( !strcmp(cmd_name,"print-architecture") ||
7015 + !strcmp(cmd_name,"print_architecture") ||
7016 + !strcmp(cmd_name,"print-installation-architecture") ||
7017 + !strcmp(cmd_name,"print_installation_architecture") )
7018 + args.nocheckfordirorfile = 1;
7021 + err = ipkg_conf_init (&ipkg_conf, &args);
7027 + args_deinit (&args);
7029 + ipkg_cb_message = default_ipkg_message_callback;
7030 + ipkg_cb_response = default_ipkg_response_callback;
7031 + ipkg_cb_status = default_ipkg_status_callback;
7032 + if ( strcmp(cmd_name, "files")==0)
7033 + ipkg_cb_list = default_ipkg_files_callback;
7035 + ipkg_cb_list = default_ipkg_list_callback;
7037 + cmd = ipkg_cmd_find (cmd_name);
7040 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7042 + args_usage (NULL);
7045 + if (cmd->requires_args && optind == argc)
7048 + "%s: the ``%s'' command requires at least one argument\n",
7049 + __FUNCTION__, cmd_name);
7050 + args_usage (NULL);
7053 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7055 + ipkg_conf_deinit (&ipkg_conf);
7060 +#endif /* IPKG_LIB */
7061 diff -ruN busybox-1.1.1-old/archival/libipkg/libipkg.h busybox-1.1.1-new/archival/libipkg/libipkg.h
7062 --- busybox-1.1.1-old/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7063 +++ busybox-1.1.1-new/archival/libipkg/libipkg.h 2006-03-30 00:39:48.000000000 +0200
7065 +/* ipkglib.h - the itsy package management system
7067 + Florian Boor <florian.boor@kernelconcepts.de>
7069 + This program is free software; you can redistribute it and/or
7070 + modify it under the terms of the GNU General Public License as
7071 + published by the Free Software Foundation; either version 2, or (at
7072 + your option) any later version.
7074 + This program is distributed in the hope that it will be useful, but
7075 + WITHOUT ANY WARRANTY; without even the implied warranty of
7076 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7077 + General Public License for more details.
7085 +#include "ipkg_conf.h"
7086 +#include "ipkg_message.h"
7091 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7093 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7094 + pkg_state_status_t status, void *userdata);
7095 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7097 +typedef char* (*ipkg_response_callback)(char *question);
7099 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7100 +extern int ipkg_init (ipkg_message_callback mcall,
7101 + ipkg_response_callback rcall,
7104 +extern int ipkg_deinit (args_t *args);
7105 +extern int ipkg_packages_list(args_t *args,
7106 + const char *packages,
7107 + ipkg_list_callback cblist,
7109 +extern int ipkg_packages_status(args_t *args,
7110 + const char *packages,
7111 + ipkg_status_callback cbstatus,
7113 +extern int ipkg_packages_info(args_t *args,
7114 + const char *packages,
7115 + ipkg_status_callback cbstatus,
7117 +extern int ipkg_packages_install(args_t *args, const char *name);
7118 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7119 +extern int ipkg_lists_update(args_t *args);
7120 +extern int ipkg_packages_upgrade(args_t *args);
7121 +extern int ipkg_packages_download(args_t *args, const char *name);
7122 +extern int ipkg_package_files(args_t *args,
7124 + ipkg_list_callback cblist,
7126 +extern int ipkg_file_search(args_t *args,
7128 + ipkg_list_callback cblist,
7130 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7131 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7132 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7133 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7134 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7136 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7137 +extern ipkg_response_callback ipkg_cb_response;
7138 +extern ipkg_status_callback ipkg_cb_status;
7139 +extern ipkg_list_callback ipkg_cb_list;
7140 +extern void push_error_list(struct errlist **errors,char * msg);
7141 +extern void reverse_error_list(struct errlist **errors);
7142 +extern void free_error_list(struct errlist **errors);
7146 +extern int ipkg_op(int argc, char *argv[]);
7152 diff -ruN busybox-1.1.1-old/archival/libipkg/md5.c busybox-1.1.1-new/archival/libipkg/md5.c
7153 --- busybox-1.1.1-old/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7154 +++ busybox-1.1.1-new/archival/libipkg/md5.c 2006-03-30 01:24:25.000000000 +0200
7156 +/* md5.c - wrappers to busybox md5 functions
7158 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7160 + * This program is free software; you can redistribute it and/or modify
7161 + * it under the terms of the GNU General Public License as published by
7162 + * the Free Software Foundation; either version 2, or (at your option)
7163 + * any later version.
7165 + * This program is distributed in the hope that it will be useful,
7166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7168 + * GNU General Public License for more details.
7170 + * You should have received a copy of the GNU General Public License
7171 + * along with this program; if not, write to the Free Software Foundation,
7172 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7180 +int md5_stream(FILE *stream, void *resblock)
7185 + if( (fd = fileno(stream)) == -1 ) {
7186 + bb_error_msg("bad file descriptor");
7190 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7195 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7199 + md5_begin(&md5_cx);
7200 + md5_hash(buffer, len, &md5_cx);
7201 + return md5_end(resblock, &md5_cx);
7204 diff -ruN busybox-1.1.1-old/archival/libipkg/md5.h busybox-1.1.1-new/archival/libipkg/md5.h
7205 --- busybox-1.1.1-old/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7206 +++ busybox-1.1.1-new/archival/libipkg/md5.h 2006-03-30 00:39:48.000000000 +0200
7208 +/* md5.h - Compute MD5 checksum of files or strings according to the
7209 + * definition of MD5 in RFC 1321 from April 1992.
7210 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7212 + * This program is free software; you can redistribute it and/or modify
7213 + * it under the terms of the GNU General Public License as published by
7214 + * the Free Software Foundation; either version 2, or (at your option)
7215 + * any later version.
7217 + * This program is distributed in the hope that it will be useful,
7218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7220 + * GNU General Public License for more details.
7222 + * You should have received a copy of the GNU General Public License
7223 + * along with this program; if not, write to the Free Software Foundation,
7224 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7230 +/* Compute MD5 message digest for bytes read from STREAM. The
7231 + resulting message digest number will be written into the 16 bytes
7232 + beginning at RESBLOCK. */
7233 +int md5_stream(FILE *stream, void *resblock);
7235 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7236 + result is always in little endian byte order, so that a byte-wise
7237 + output yields to the wanted ASCII representation of the message
7239 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7243 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair.c busybox-1.1.1-new/archival/libipkg/nv_pair.c
7244 --- busybox-1.1.1-old/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7245 +++ busybox-1.1.1-new/archival/libipkg/nv_pair.c 2006-03-30 00:39:48.000000000 +0200
7247 +/* nv_pair.c - the itsy package management system
7251 + Copyright (C) 2001 University of Southern California
7253 + This program is free software; you can redistribute it and/or
7254 + modify it under the terms of the GNU General Public License as
7255 + published by the Free Software Foundation; either version 2, or (at
7256 + your option) any later version.
7258 + This program is distributed in the hope that it will be useful, but
7259 + WITHOUT ANY WARRANTY; without even the implied warranty of
7260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7261 + General Public License for more details.
7266 +#include "nv_pair.h"
7267 +#include "str_util.h"
7269 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7271 + nv_pair->name = str_dup_safe(name);
7272 + nv_pair->value = str_dup_safe(value);
7277 +void nv_pair_deinit(nv_pair_t *nv_pair)
7279 + free(nv_pair->name);
7280 + nv_pair->name = NULL;
7282 + free(nv_pair->value);
7283 + nv_pair->value = NULL;
7287 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair.h busybox-1.1.1-new/archival/libipkg/nv_pair.h
7288 --- busybox-1.1.1-old/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7289 +++ busybox-1.1.1-new/archival/libipkg/nv_pair.h 2006-03-30 00:39:48.000000000 +0200
7291 +/* nv_pair.h - the itsy package management system
7295 + Copyright (C) 2001 University of Southern California
7297 + This program is free software; you can redistribute it and/or
7298 + modify it under the terms of the GNU General Public License as
7299 + published by the Free Software Foundation; either version 2, or (at
7300 + your option) any later version.
7302 + This program is distributed in the hope that it will be useful, but
7303 + WITHOUT ANY WARRANTY; without even the implied warranty of
7304 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7305 + General Public License for more details.
7311 +typedef struct nv_pair nv_pair_t;
7318 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7319 +void nv_pair_deinit(nv_pair_t *nv_pair);
7323 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair_list.c busybox-1.1.1-new/archival/libipkg/nv_pair_list.c
7324 --- busybox-1.1.1-old/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7325 +++ busybox-1.1.1-new/archival/libipkg/nv_pair_list.c 2006-03-30 00:39:48.000000000 +0200
7327 +/* nv_pair_list.c - the itsy package management system
7331 + Copyright (C) 2001 University of Southern California
7333 + This program is free software; you can redistribute it and/or
7334 + modify it under the terms of the GNU General Public License as
7335 + published by the Free Software Foundation; either version 2, or (at
7336 + your option) any later version.
7338 + This program is distributed in the hope that it will be useful, but
7339 + WITHOUT ANY WARRANTY; without even the implied warranty of
7340 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7341 + General Public License for more details.
7346 +#include "nv_pair.h"
7347 +#include "void_list.h"
7348 +#include "nv_pair_list.h"
7350 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7352 + return void_list_elt_init((void_list_elt_t *) elt, data);
7355 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7357 + void_list_elt_deinit((void_list_elt_t *) elt);
7360 +int nv_pair_list_init(nv_pair_list_t *list)
7362 + return void_list_init((void_list_t *) list);
7365 +void nv_pair_list_deinit(nv_pair_list_t *list)
7367 + nv_pair_list_elt_t *iter;
7368 + nv_pair_t *nv_pair;
7370 + for (iter = list->head; iter; iter = iter->next) {
7371 + nv_pair = iter->data;
7372 + nv_pair_deinit(nv_pair);
7374 + /* malloced in nv_pair_list_append */
7376 + iter->data = NULL;
7378 + void_list_deinit((void_list_t *) list);
7381 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7385 + /* freed in nv_pair_list_deinit */
7386 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7388 + if (nv_pair == NULL) {
7389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7392 + nv_pair_init(nv_pair, name, value);
7394 + err = void_list_append((void_list_t *) list, nv_pair);
7402 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7404 + return void_list_push((void_list_t *) list, data);
7407 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7409 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7412 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7414 + nv_pair_list_elt_t *iter;
7415 + nv_pair_t *nv_pair;
7417 + for (iter = list->head; iter; iter = iter->next) {
7418 + nv_pair = iter->data;
7419 + if (strcmp(nv_pair->name, name) == 0) {
7420 + return nv_pair->value;
7425 diff -ruN busybox-1.1.1-old/archival/libipkg/nv_pair_list.h busybox-1.1.1-new/archival/libipkg/nv_pair_list.h
7426 --- busybox-1.1.1-old/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7427 +++ busybox-1.1.1-new/archival/libipkg/nv_pair_list.h 2006-03-30 00:39:48.000000000 +0200
7429 +/* nv_pair_list.h - the itsy package management system
7433 + Copyright (C) 2001 University of Southern California
7435 + This program is free software; you can redistribute it and/or
7436 + modify it under the terms of the GNU General Public License as
7437 + published by the Free Software Foundation; either version 2, or (at
7438 + your option) any later version.
7440 + This program is distributed in the hope that it will be useful, but
7441 + WITHOUT ANY WARRANTY; without even the implied warranty of
7442 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7443 + General Public License for more details.
7446 +#ifndef NV_PAIR_LIST_H
7447 +#define NV_PAIR_LIST_H
7449 +#include "nv_pair.h"
7450 +#include "void_list.h"
7452 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7453 +struct nv_pair_list_elt
7455 + nv_pair_list_elt_t *next;
7459 +typedef struct nv_pair_list nv_pair_list_t;
7460 +struct nv_pair_list
7462 + nv_pair_list_elt_t pre_head;
7463 + nv_pair_list_elt_t *head;
7464 + nv_pair_list_elt_t *tail;
7467 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7469 + if (list->head == NULL)
7475 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7476 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7478 +int nv_pair_list_init(nv_pair_list_t *list);
7479 +void nv_pair_list_deinit(nv_pair_list_t *list);
7481 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7482 + const char *name, const char *value);
7483 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7484 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7485 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7489 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg.c busybox-1.1.1-new/archival/libipkg/pkg.c
7490 --- busybox-1.1.1-old/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7491 +++ busybox-1.1.1-new/archival/libipkg/pkg.c 2006-03-30 00:39:48.000000000 +0200
7493 +/* pkg.c - the itsy package management system
7497 + Copyright (C) 2001 University of Southern California
7499 + This program is free software; you can redistribute it and/or
7500 + modify it under the terms of the GNU General Public License as
7501 + published by the Free Software Foundation; either version 2, or (at
7502 + your option) any later version.
7504 + This program is distributed in the hope that it will be useful, but
7505 + WITHOUT ANY WARRANTY; without even the implied warranty of
7506 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7507 + General Public License for more details.
7512 +#include <string.h>
7517 +#include "pkg_parse.h"
7518 +#include "pkg_extract.h"
7519 +#include "ipkg_message.h"
7520 +#include "ipkg_utils.h"
7522 +#include "sprintf_alloc.h"
7523 +#include "file_util.h"
7524 +#include "str_util.h"
7525 +#include "xsystem.h"
7526 +#include "ipkg_conf.h"
7528 +typedef struct enum_map enum_map_t;
7535 +static const enum_map_t pkg_state_want_map[] = {
7536 + { SW_UNKNOWN, "unknown"},
7537 + { SW_INSTALL, "install"},
7538 + { SW_DEINSTALL, "deinstall"},
7539 + { SW_PURGE, "purge"}
7542 +static const enum_map_t pkg_state_flag_map[] = {
7544 + { SF_REINSTREQ, "reinstreq"},
7545 + { SF_HOLD, "hold"},
7546 + { SF_REPLACE, "replace"},
7547 + { SF_NOPRUNE, "noprune"},
7548 + { SF_PREFER, "prefer"},
7549 + { SF_OBSOLETE, "obsolete"},
7550 + { SF_USER, "user"},
7553 +static const enum_map_t pkg_state_status_map[] = {
7554 + { SS_NOT_INSTALLED, "not-installed" },
7555 + { SS_UNPACKED, "unpacked" },
7556 + { SS_HALF_CONFIGURED, "half-configured" },
7557 + { SS_INSTALLED, "installed" },
7558 + { SS_HALF_INSTALLED, "half-installed" },
7559 + { SS_CONFIG_FILES, "config-files" },
7560 + { SS_POST_INST_FAILED, "post-inst-failed" },
7561 + { SS_REMOVAL_FAILED, "removal-failed" }
7564 +static int verrevcmp(const char *val, const char *ref);
7567 +pkg_t *pkg_new(void)
7571 + pkg = malloc(sizeof(pkg_t));
7572 + if (pkg == NULL) {
7573 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7582 +int pkg_init(pkg_t *pkg)
7584 + memset(pkg, 0, sizeof(pkg_t));
7587 + pkg->version = NULL;
7588 + pkg->revision = NULL;
7589 + pkg->familiar_revision = NULL;
7592 + pkg->architecture = NULL;
7593 + pkg->maintainer = NULL;
7594 + pkg->section = NULL;
7595 + pkg->description = NULL;
7596 + pkg->state_want = SW_UNKNOWN;
7597 + pkg->state_flag = SF_OK;
7598 + pkg->state_status = SS_NOT_INSTALLED;
7599 + pkg->depends_str = NULL;
7600 + pkg->provides_str = NULL;
7601 + pkg->depends_count = 0;
7602 + pkg->depends = NULL;
7603 + pkg->suggests_str = NULL;
7604 + pkg->recommends_str = NULL;
7605 + pkg->suggests_count = 0;
7606 + pkg->recommends_count = 0;
7608 + /* Abhaya: added init for conflicts fields */
7609 + pkg->conflicts = NULL;
7610 + pkg->conflicts_count = 0;
7612 + /* added for replaces. Jamey 7/23/2002 */
7613 + pkg->replaces = NULL;
7614 + pkg->replaces_count = 0;
7616 + pkg->pre_depends_count = 0;
7617 + pkg->pre_depends_str = NULL;
7618 + pkg->provides_count = 0;
7619 + pkg->provides = NULL;
7620 + pkg->filename = NULL;
7621 + pkg->local_filename = NULL;
7622 + pkg->tmp_unpack_dir = NULL;
7623 + pkg->md5sum = NULL;
7625 + pkg->installed_size = NULL;
7626 + pkg->priority = NULL;
7627 + pkg->source = NULL;
7628 + conffile_list_init(&pkg->conffiles);
7629 + pkg->installed_files = NULL;
7630 + pkg->installed_files_ref_cnt = 0;
7631 + pkg->essential = 0;
7636 +void pkg_deinit(pkg_t *pkg)
7641 + free(pkg->version);
7642 + pkg->version = NULL;
7643 + /* revision and familiar_revision share storage with version, so
7645 + pkg->revision = NULL;
7646 + pkg->familiar_revision = NULL;
7647 + /* owned by ipkg_conf_t */
7649 + /* owned by ipkg_conf_t */
7651 + free(pkg->architecture);
7652 + pkg->architecture = NULL;
7653 + free(pkg->maintainer);
7654 + pkg->maintainer = NULL;
7655 + free(pkg->section);
7656 + pkg->section = NULL;
7657 + free(pkg->description);
7658 + pkg->description = NULL;
7659 + pkg->state_want = SW_UNKNOWN;
7660 + pkg->state_flag = SF_OK;
7661 + pkg->state_status = SS_NOT_INSTALLED;
7662 + free(pkg->depends_str);
7663 + pkg->depends_str = NULL;
7664 + free(pkg->provides_str);
7665 + pkg->provides_str = NULL;
7666 + pkg->depends_count = 0;
7667 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7668 + pkg->pre_depends_count = 0;
7669 + free(pkg->pre_depends_str);
7670 + pkg->pre_depends_str = NULL;
7671 + pkg->provides_count = 0;
7672 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7673 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7674 + free(pkg->filename);
7675 + pkg->filename = NULL;
7676 + free(pkg->local_filename);
7677 + pkg->local_filename = NULL;
7678 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7679 + ipkg_install.c here. See comment in
7680 + ipkg_install.c:cleanup_temporary_files */
7681 + free(pkg->tmp_unpack_dir);
7682 + pkg->tmp_unpack_dir = NULL;
7683 + free(pkg->md5sum);
7684 + pkg->md5sum = NULL;
7687 + free(pkg->installed_size);
7688 + pkg->installed_size = NULL;
7689 + free(pkg->priority);
7690 + pkg->priority = NULL;
7691 + free(pkg->source);
7692 + pkg->source = NULL;
7693 + conffile_list_deinit(&pkg->conffiles);
7694 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7695 + since if they are calling deinit, they should know. Maybe do an
7696 + assertion here instead? */
7697 + pkg->installed_files_ref_cnt = 1;
7698 + pkg_free_installed_files(pkg);
7699 + pkg->essential = 0;
7702 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7706 + FILE *control_file;
7708 + err = pkg_init(pkg);
7709 + if (err) { return err; }
7711 + pkg->local_filename = strdup(filename);
7713 + control_file = tmpfile();
7714 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7715 + if (err) { return err; }
7717 + rewind(control_file);
7718 + raw = read_raw_pkgs_from_stream(control_file);
7719 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7721 + fclose(control_file);
7726 +/* Merge any new information in newpkg into oldpkg */
7727 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7728 + newpkg, but should leave it usable. This rework is so that
7729 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7731 + * uh, i thought that i had originally written this so that it took
7732 + * two pkgs and returned a new one? we can do that again... -sma
7734 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7736 + if (oldpkg == newpkg) {
7741 + oldpkg->src = newpkg->src;
7742 + if (!oldpkg->dest)
7743 + oldpkg->dest = newpkg->dest;
7744 + if (!oldpkg->architecture)
7745 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7746 + if (!oldpkg->arch_priority)
7747 + oldpkg->arch_priority = newpkg->arch_priority;
7748 + if (!oldpkg->section)
7749 + oldpkg->section = str_dup_safe(newpkg->section);
7750 + if(!oldpkg->maintainer)
7751 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7752 + if(!oldpkg->description)
7753 + oldpkg->description = str_dup_safe(newpkg->description);
7755 + /* merge the state_flags from the new package */
7756 + oldpkg->state_want = newpkg->state_want;
7757 + oldpkg->state_status = newpkg->state_status;
7758 + oldpkg->state_flag = newpkg->state_flag;
7760 + if (oldpkg->state_want == SW_UNKNOWN)
7761 + oldpkg->state_want = newpkg->state_want;
7762 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7763 + oldpkg->state_status = newpkg->state_status;
7764 + oldpkg->state_flag |= newpkg->state_flag;
7767 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7768 + oldpkg->depends_str = newpkg->depends_str;
7769 + newpkg->depends_str = NULL;
7770 + oldpkg->depends_count = newpkg->depends_count;
7771 + newpkg->depends_count = 0;
7773 + oldpkg->depends = newpkg->depends;
7774 + newpkg->depends = NULL;
7776 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7777 + newpkg->pre_depends_str = NULL;
7778 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7779 + newpkg->pre_depends_count = 0;
7781 + oldpkg->recommends_str = newpkg->recommends_str;
7782 + newpkg->recommends_str = NULL;
7783 + oldpkg->recommends_count = newpkg->recommends_count;
7784 + newpkg->recommends_count = 0;
7786 + oldpkg->suggests_str = newpkg->suggests_str;
7787 + newpkg->suggests_str = NULL;
7788 + oldpkg->suggests_count = newpkg->suggests_count;
7789 + newpkg->suggests_count = 0;
7792 + if (!oldpkg->provides_str) {
7793 + oldpkg->provides_str = newpkg->provides_str;
7794 + newpkg->provides_str = NULL;
7795 + oldpkg->provides_count = newpkg->provides_count;
7796 + newpkg->provides_count = 0;
7798 + oldpkg->provides = newpkg->provides;
7799 + newpkg->provides = NULL;
7802 + if (!oldpkg->conflicts_str) {
7803 + oldpkg->conflicts_str = newpkg->conflicts_str;
7804 + newpkg->conflicts_str = NULL;
7805 + oldpkg->conflicts_count = newpkg->conflicts_count;
7806 + newpkg->conflicts_count = 0;
7808 + oldpkg->conflicts = newpkg->conflicts;
7809 + newpkg->conflicts = NULL;
7812 + if (!oldpkg->replaces_str) {
7813 + oldpkg->replaces_str = newpkg->replaces_str;
7814 + newpkg->replaces_str = NULL;
7815 + oldpkg->replaces_count = newpkg->replaces_count;
7816 + newpkg->replaces_count = 0;
7818 + oldpkg->replaces = newpkg->replaces;
7819 + newpkg->replaces = NULL;
7822 + if (!oldpkg->filename)
7823 + oldpkg->filename = str_dup_safe(newpkg->filename);
7825 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7826 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7827 + if (!oldpkg->local_filename)
7828 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7829 + if (!oldpkg->tmp_unpack_dir)
7830 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7831 + if (!oldpkg->md5sum)
7832 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7833 + if (!oldpkg->size)
7834 + oldpkg->size = str_dup_safe(newpkg->size);
7835 + if (!oldpkg->installed_size)
7836 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7837 + if (!oldpkg->priority)
7838 + oldpkg->priority = str_dup_safe(newpkg->priority);
7839 + if (!oldpkg->source)
7840 + oldpkg->source = str_dup_safe(newpkg->source);
7841 + if (oldpkg->conffiles.head == NULL){
7842 + oldpkg->conffiles = newpkg->conffiles;
7843 + conffile_list_init(&newpkg->conffiles);
7845 + if (!oldpkg->installed_files){
7846 + oldpkg->installed_files = newpkg->installed_files;
7847 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7848 + newpkg->installed_files = NULL;
7850 + if (!oldpkg->essential)
7851 + oldpkg->essential = newpkg->essential;
7856 +abstract_pkg_t *abstract_pkg_new(void)
7858 + abstract_pkg_t * ab_pkg;
7860 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7862 + if (ab_pkg == NULL) {
7863 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7867 + if ( abstract_pkg_init(ab_pkg) < 0 )
7873 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7875 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7877 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7878 + if (ab_pkg->provided_by==NULL){
7881 + ab_pkg->dependencies_checked = 0;
7882 + ab_pkg->state_status = SS_NOT_INSTALLED;
7887 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7890 + char **raw_start=NULL;
7892 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7893 + if (temp_str == NULL ){
7894 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7897 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7899 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7900 + if (raw == NULL ){
7901 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7906 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7907 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7923 +char * pkg_formatted_info(pkg_t *pkg )
7928 + buff = malloc(8192);
7929 + if (buff == NULL) {
7930 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7936 + line = pkg_formatted_field(pkg, "Package");
7937 + strncat(buff ,line, strlen(line));
7940 + line = pkg_formatted_field(pkg, "Version");
7941 + strncat(buff ,line, strlen(line));
7944 + line = pkg_formatted_field(pkg, "Depends");
7945 + strncat(buff ,line, strlen(line));
7948 + line = pkg_formatted_field(pkg, "Recommends");
7949 + strncat(buff ,line, strlen(line));
7952 + line = pkg_formatted_field(pkg, "Suggests");
7953 + strncat(buff ,line, strlen(line));
7956 + line = pkg_formatted_field(pkg, "Provides");
7957 + strncat(buff ,line, strlen(line));
7960 + line = pkg_formatted_field(pkg, "Replaces");
7961 + strncat(buff ,line, strlen(line));
7964 + line = pkg_formatted_field(pkg, "Conflicts");
7965 + strncat(buff ,line, strlen(line));
7968 + line = pkg_formatted_field(pkg, "Status");
7969 + strncat(buff ,line, strlen(line));
7972 + line = pkg_formatted_field(pkg, "Section");
7973 + strncat(buff ,line, strlen(line));
7976 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7977 + strncat(buff ,line, strlen(line));
7980 + line = pkg_formatted_field(pkg, "Architecture");
7981 + strncat(buff ,line, strlen(line));
7984 + line = pkg_formatted_field(pkg, "Maintainer");
7985 + strncat(buff ,line, strlen(line));
7988 + line = pkg_formatted_field(pkg, "MD5sum");
7989 + strncat(buff ,line, strlen(line));
7992 + line = pkg_formatted_field(pkg, "Size");
7993 + strncat(buff ,line, strlen(line));
7996 + line = pkg_formatted_field(pkg, "Filename");
7997 + strncat(buff ,line, strlen(line));
8000 + line = pkg_formatted_field(pkg, "Conffiles");
8001 + strncat(buff ,line, strlen(line));
8004 + line = pkg_formatted_field(pkg, "Source");
8005 + strncat(buff ,line, strlen(line));
8008 + line = pkg_formatted_field(pkg, "Description");
8009 + strncat(buff ,line, strlen(line));
8012 + line = pkg_formatted_field(pkg, "Installed-Time");
8013 + strncat(buff ,line, strlen(line));
8019 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8021 + static size_t LINE_LEN = 128;
8022 + char * temp = (char *)malloc(1);
8024 + int flag_provide_false = 0;
8027 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8028 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8031 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8032 + goto UNKNOWN_FMT_FIELD;
8041 + if (strcasecmp(field, "Architecture") == 0) {
8042 + /* Architecture */
8043 + if (pkg->architecture) {
8044 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8045 + if ( temp == NULL ){
8046 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8050 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8053 + goto UNKNOWN_FMT_FIELD;
8058 + if (strcasecmp(field, "Conffiles") == 0) {
8060 + conffile_list_elt_t *iter;
8061 + char confstr[LINE_LEN];
8063 + if (pkg->conffiles.head == NULL) {
8068 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8069 + if (iter->data->name && iter->data->value) {
8070 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8073 + temp = (char *)realloc(temp,len);
8074 + if ( temp == NULL ){
8075 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8079 + strncpy(temp, "Conffiles:\n", 12);
8080 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8081 + if (iter->data->name && iter->data->value) {
8082 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8083 + strncat(temp, confstr, strlen(confstr));
8086 + } else if (strcasecmp(field, "Conflicts") == 0) {
8089 + if (pkg->conflicts_count) {
8090 + char conflictstr[LINE_LEN];
8092 + for(i = 0; i < pkg->conflicts_count; i++) {
8093 + len = len + (strlen(pkg->conflicts_str[i])+5);
8095 + temp = (char *)realloc(temp,len);
8096 + if ( temp == NULL ){
8097 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8101 + strncpy(temp, "Conflicts:", 11);
8102 + for(i = 0; i < pkg->conflicts_count; i++) {
8103 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8104 + strncat(temp, conflictstr, strlen(conflictstr));
8106 + strncat(temp, "\n", strlen("\n"));
8109 + goto UNKNOWN_FMT_FIELD;
8114 + if (strcasecmp(field, "Depends") == 0) {
8118 + if (pkg->depends_count) {
8119 + char depstr[LINE_LEN];
8121 + for(i = 0; i < pkg->depends_count; i++) {
8122 + len = len + (strlen(pkg->depends_str[i])+4);
8124 + temp = (char *)realloc(temp,len);
8125 + if ( temp == NULL ){
8126 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8130 + strncpy(temp, "Depends:", 10);
8131 + for(i = 0; i < pkg->depends_count; i++) {
8132 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8133 + strncat(temp, depstr, strlen(depstr));
8135 + strncat(temp, "\n", strlen("\n"));
8137 + } else if (strcasecmp(field, "Description") == 0) {
8139 + if (pkg->description) {
8140 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8141 + if ( temp == NULL ){
8142 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8146 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8149 + goto UNKNOWN_FMT_FIELD;
8155 + if (pkg->essential) {
8156 + temp = (char *)realloc(temp,16);
8157 + if ( temp == NULL ){
8158 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8162 + snprintf(temp, (16), "Essential: yes\n");
8169 + if (pkg->filename) {
8170 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8171 + if ( temp == NULL ){
8172 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8176 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8182 + if (strcasecmp(field, "Installed-Size") == 0) {
8183 + /* Installed-Size */
8184 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8185 + if ( temp == NULL ){
8186 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8190 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8191 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8192 + temp = (char *)realloc(temp,29);
8193 + if ( temp == NULL ){
8194 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8198 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8204 + /* Maintainer | MD5sum */
8205 + if (strcasecmp(field, "Maintainer") == 0) {
8207 + if (pkg->maintainer) {
8208 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8209 + if ( temp == NULL ){
8210 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8214 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8216 + } else if (strcasecmp(field, "MD5sum") == 0) {
8218 + if (pkg->md5sum) {
8219 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8220 + if ( temp == NULL ){
8221 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8225 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8228 + goto UNKNOWN_FMT_FIELD;
8234 + if (strcasecmp(field, "Package") == 0) {
8236 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8237 + if ( temp == NULL ){
8238 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8242 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8243 + } else if (strcasecmp(field, "Priority") == 0) {
8245 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8246 + if ( temp == NULL ){
8247 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8251 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8252 + } else if (strcasecmp(field, "Provides") == 0) {
8256 + if (pkg->provides_count) {
8257 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8258 + for ( i=0; i < pkg->provides_count; i++ ){
8259 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8260 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8261 + flag_provide_false = 1;
8264 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8265 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8266 + char provstr[LINE_LEN];
8268 + for(i = 0; i < pkg->provides_count; i++) {
8269 + len = len + (strlen(pkg->provides_str[i])+5);
8271 + temp = (char *)realloc(temp,len);
8272 + if ( temp == NULL ){
8273 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8277 + strncpy(temp, "Provides:", 12);
8278 + for(i = 0; i < pkg->provides_count; i++) {
8279 + if (strlen(pkg->provides_str[i])>0){;
8280 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8281 + strncat(temp, provstr, strlen(provstr));
8284 + strncat(temp, "\n", strlen("\n"));
8288 + goto UNKNOWN_FMT_FIELD;
8295 + /* Replaces | Recommends*/
8296 + if (strcasecmp (field, "Replaces") == 0) {
8297 + if (pkg->replaces_count) {
8298 + char replstr[LINE_LEN];
8300 + for (i = 0; i < pkg->replaces_count; i++) {
8301 + len = len + (strlen(pkg->replaces_str[i])+5);
8303 + temp = (char *)realloc(temp,len);
8304 + if ( temp == NULL ){
8305 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8309 + strncpy(temp, "Replaces:", 12);
8310 + for (i = 0; i < pkg->replaces_count; i++) {
8311 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8312 + strncat(temp, replstr, strlen(replstr));
8314 + strncat(temp, "\n", strlen("\n"));
8316 + } else if (strcasecmp (field, "Recommends") == 0) {
8317 + if (pkg->recommends_count) {
8318 + char recstr[LINE_LEN];
8320 + for(i = 0; i < pkg->recommends_count; i++) {
8321 + len = len + (strlen( pkg->recommends_str[i])+5);
8323 + temp = (char *)realloc(temp,len);
8324 + if ( temp == NULL ){
8325 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8329 + strncpy(temp, "Recommends:", 13);
8330 + for(i = 0; i < pkg->recommends_count; i++) {
8331 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8332 + strncat(temp, recstr, strlen(recstr));
8334 + strncat(temp, "\n", strlen("\n"));
8337 + goto UNKNOWN_FMT_FIELD;
8343 + /* Section | Size | Source | Status | Suggests */
8344 + if (strcasecmp(field, "Section") == 0) {
8346 + if (pkg->section) {
8347 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8348 + if ( temp == NULL ){
8349 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8353 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8355 + } else if (strcasecmp(field, "Size") == 0) {
8358 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8359 + if ( temp == NULL ){
8360 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8364 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8366 + } else if (strcasecmp(field, "Source") == 0) {
8368 + if (pkg->source) {
8369 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8370 + if ( temp == NULL ){
8371 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8375 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8377 + } else if (strcasecmp(field, "Status") == 0) {
8379 + /* Benjamin Pineau note: we should avoid direct usage of
8380 + * strlen(arg) without keeping "arg" for later free()
8382 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8383 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8384 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8386 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8387 + temp = (char *)realloc(temp,sum_of_sizes);
8388 + if ( temp == NULL ){
8389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8393 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8396 + if(pstat) /* pfstat can be NULL if ENOMEM */
8398 + } else if (strcasecmp(field, "Suggests") == 0) {
8399 + if (pkg->suggests_count) {
8401 + char sugstr[LINE_LEN];
8403 + for(i = 0; i < pkg->suggests_count; i++) {
8404 + len = len + (strlen(pkg->suggests_str[i])+5);
8406 + temp = (char *)realloc(temp,len);
8407 + if ( temp == NULL ){
8408 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8412 + strncpy(temp, "Suggests:", 10);
8413 + for(i = 0; i < pkg->suggests_count; i++) {
8414 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8415 + strncat(temp, sugstr, strlen(sugstr));
8417 + strncat(temp, "\n", strlen("\n"));
8420 + goto UNKNOWN_FMT_FIELD;
8427 + char *version = pkg_version_str_alloc(pkg);
8428 + temp = (char *)realloc(temp,strlen(version)+14);
8429 + if ( temp == NULL ){
8430 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8434 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8439 + goto UNKNOWN_FMT_FIELD;
8442 + if ( strlen(temp)<2 ) {
8447 + UNKNOWN_FMT_FIELD:
8448 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8449 + if ( strlen(temp)<2 ) {
8456 +void pkg_print_info(pkg_t *pkg, FILE *file)
8459 + if (pkg == NULL) {
8463 + buff = pkg_formatted_info(pkg);
8464 + if ( buff == NULL )
8466 + if (strlen(buff)>2){
8467 + fwrite(buff, 1, strlen(buff), file);
8472 +void pkg_print_status(pkg_t * pkg, FILE * file)
8474 + if (pkg == NULL) {
8478 + /* XXX: QUESTION: Do we actually want more fields here? The
8479 + original idea was to save space by installing only what was
8480 + needed for actual computation, (package, version, status,
8481 + essential, conffiles). The assumption is that all other fields
8482 + can be found in th available file.
8484 + But, someone proposed the idea to make it possible to
8485 + reconstruct a .ipk from an installed package, (ie. for beaming
8486 + from one handheld to another). So, maybe we actually want a few
8487 + more fields here, (depends, suggests, etc.), so that that would
8488 + be guaranteed to work even in the absence of more information
8489 + from the available file.
8491 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8492 + the essential info needs to be here for all installed packages
8493 + because they may not appear in the Packages files on various
8494 + feeds. Furthermore, one should be able to install from URL or
8495 + local storage without requiring a Packages file from any feed.
8498 + pkg_print_field(pkg, file, "Package");
8499 + pkg_print_field(pkg, file, "Version");
8500 + pkg_print_field(pkg, file, "Depends");
8501 + pkg_print_field(pkg, file, "Recommends");
8502 + pkg_print_field(pkg, file, "Suggests");
8503 + pkg_print_field(pkg, file, "Provides");
8504 + pkg_print_field(pkg, file, "Replaces");
8505 + pkg_print_field(pkg, file, "Conflicts");
8506 + pkg_print_field(pkg, file, "Status");
8507 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8508 + pkg_print_field(pkg, file, "Architecture");
8509 + pkg_print_field(pkg, file, "Conffiles");
8510 + pkg_print_field(pkg, file, "Installed-Time");
8511 + fputs("\n", file);
8514 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8517 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8518 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8519 + __FUNCTION__, field);
8521 + buff = pkg_formatted_field(pkg, field);
8522 + if (strlen(buff)>2) {
8523 + fprintf(file, "%s", buff);
8531 + * libdpkg - Debian packaging suite library routines
8532 + * vercmp.c - comparison of version numbers
8534 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8536 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8540 + if (pkg->epoch > ref_pkg->epoch) {
8544 + if (pkg->epoch < ref_pkg->epoch) {
8548 + r = verrevcmp(pkg->version, ref_pkg->version);
8553 +#ifdef USE_DEBVERSION
8554 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8559 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8565 +int verrevcmp(const char *val, const char *ref)
8569 + const char *vp, *rp;
8570 + const char *vsep, *rsep;
8572 + if (!val) val= "";
8573 + if (!ref) ref= "";
8575 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8576 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8578 + vc= (val == vp) ? 0 : *val++;
8579 + rc= (ref == rp) ? 0 : *ref++;
8580 + if (!rc && !vc) break;
8581 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8582 + if (rc && !isalpha(rc)) rc += 256;
8583 + if (vc != rc) return vc - rc;
8587 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8588 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8589 + if (vl != rl) return vl - rl;
8593 + vsep = strchr(".-", vc);
8594 + rsep = strchr(".-", rc);
8595 + if (vsep && !rsep) return -1;
8596 + if (!vsep && rsep) return +1;
8598 + if (!*val && !*ref) return 0;
8599 + if (!*val) return -1;
8600 + if (!*ref) return +1;
8604 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8608 + r = pkg_compare_versions(it, ref);
8610 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8614 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8618 + if (strcmp(op, "<<") == 0) {
8622 + if (strcmp(op, ">>") == 0) {
8626 + if (strcmp(op, "=") == 0) {
8630 + fprintf(stderr, "unknown operator: %s", op);
8634 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8636 + const pkg_t *a = *(const pkg_t **)p1;
8637 + const pkg_t *b = *(const pkg_t **)p2;
8640 + if (!a->name || !b->name) {
8641 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8642 + a, a->name, b, b->name);
8646 + namecmp = strcmp(a->name, b->name);
8649 + vercmp = pkg_compare_versions(a, b);
8652 + if (!a->arch_priority || !b->arch_priority) {
8653 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8654 + a, a->arch_priority, b, b->arch_priority);
8657 + if (a->arch_priority > b->arch_priority)
8659 + if (a->arch_priority < b->arch_priority)
8664 +int abstract_pkg_name_compare(void *p1, void *p2)
8666 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8667 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8668 + if (!a->name || !b->name) {
8669 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8670 + a, a->name, b, b->name);
8673 + return strcmp(a->name, b->name);
8677 +char *pkg_version_str_alloc(pkg_t *pkg)
8679 + char *complete_version;
8681 +#ifdef USE_DEBVERSION
8682 + char *revision_str;
8683 + char *familiar_revision_str;
8687 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8689 + epoch_str = strdup("");
8692 +#ifdef USE_DEBVERSION
8693 + if (pkg->revision && strlen(pkg->revision)) {
8694 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8696 + revision_str = strdup("");
8699 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8700 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8702 + familiar_revision_str = strdup("");
8706 +#ifdef USE_DEBVERSION
8707 + sprintf_alloc(&complete_version, "%s%s%s%s",
8708 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8710 + sprintf_alloc(&complete_version, "%s%s",
8711 + epoch_str, pkg->version);
8715 +#ifdef USE_DEBVERSION
8716 + free(revision_str);
8717 + free(familiar_revision_str);
8720 + return complete_version;
8723 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8726 + char *list_file_name = NULL;
8727 + FILE *list_file = NULL;
8729 + char *installed_file_name;
8732 + pkg->installed_files_ref_cnt++;
8734 + if (pkg->installed_files) {
8735 + return pkg->installed_files;
8738 + pkg->installed_files = str_list_alloc();
8739 + if (pkg->installed_files == NULL) {
8740 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8744 + /* For uninstalled packages, get the file list firectly from the package.
8745 + For installed packages, look at the package.list file in the database.
8747 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8748 + if (pkg->local_filename == NULL) {
8749 + return pkg->installed_files;
8751 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8752 + file. In other words, change deb_extract so that it can
8753 + simply return the file list as a char *[] rather than
8754 + insisting on writing in to a FILE * as it does now. */
8755 + list_file = tmpfile();
8756 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8758 + fclose(list_file);
8759 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8760 + __FUNCTION__, pkg->local_filename, strerror(err));
8761 + return pkg->installed_files;
8763 + rewind(list_file);
8765 + sprintf_alloc(&list_file_name, "%s/%s.list",
8766 + pkg->dest->info_dir, pkg->name);
8767 + if (! file_exists(list_file_name)) {
8768 + free(list_file_name);
8769 + return pkg->installed_files;
8772 + list_file = fopen(list_file_name, "r");
8773 + if (list_file == NULL) {
8774 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8775 + list_file_name, strerror(errno));
8776 + free(list_file_name);
8777 + return pkg->installed_files;
8779 + free(list_file_name);
8782 + rootdirlen = strlen( pkg->dest->root_dir );
8786 + line = file_read_line_alloc(list_file);
8787 + if (line == NULL) {
8793 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8794 + if( strncmp( pkg->dest->root_dir,
8797 + if (*file_name == '.') {
8800 + if (*file_name == '/') {
8804 + /* Freed in pkg_free_installed_files */
8805 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8807 + // already contains root_dir as header -> ABSOLUTE
8808 + sprintf_alloc(&installed_file_name, "%s", file_name);
8810 + str_list_append(pkg->installed_files, installed_file_name);
8814 + fclose(list_file);
8816 + return pkg->installed_files;
8819 +/* XXX: CLEANUP: This function and it's counterpart,
8820 + (pkg_get_installed_files), do not match our init/deinit naming
8821 + convention. Nor the alloc/free convention. But, then again, neither
8822 + of these conventions currrently fit the way these two functions
8824 +int pkg_free_installed_files(pkg_t *pkg)
8826 + str_list_elt_t *iter;
8828 + pkg->installed_files_ref_cnt--;
8829 + if (pkg->installed_files_ref_cnt > 0) {
8833 + if (pkg->installed_files) {
8835 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8836 + /* malloced in pkg_get_installed_files */
8837 + free (iter->data);
8838 + iter->data = NULL;
8841 + str_list_deinit(pkg->installed_files);
8844 + pkg->installed_files = NULL;
8849 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8852 + char *list_file_name;
8854 + //I don't think pkg_free_installed_files should be called here. Jamey
8855 + //pkg_free_installed_files(pkg);
8857 + sprintf_alloc(&list_file_name, "%s/%s.list",
8858 + pkg->dest->info_dir, pkg->name);
8859 + if (!conf->noaction) {
8860 + err = unlink(list_file_name);
8861 + free(list_file_name);
8870 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8872 + conffile_list_elt_t *iter;
8873 + conffile_t *conffile;
8875 + if (pkg == NULL) {
8879 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8880 + conffile = iter->data;
8882 + if (strcmp(conffile->name, file_name) == 0) {
8890 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8891 + const char *script, const char *args)
8897 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8898 + maintainer script within a chroot environment. */
8900 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8901 + have scripts in pkg->tmp_unpack_dir. */
8902 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8903 + if (pkg->dest == NULL) {
8904 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8905 + __FUNCTION__, pkg->name);
8908 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8910 + if (pkg->tmp_unpack_dir == NULL) {
8911 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8912 + __FUNCTION__, pkg->name);
8915 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8918 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8919 + if (conf->noaction) return 0;
8921 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8922 + scripts when running with offline_root mode and/or a dest other
8923 + than '/'. I've been playing around with some clever chroot
8924 + tricks and I might come up with something workable. */
8925 + if (conf->offline_root) {
8926 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8929 + setenv("PKG_ROOT",
8930 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8932 + if (! file_exists(path)) {
8937 + if (conf->offline_root) {
8938 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8943 + sprintf_alloc(&cmd, "%s %s", path, args);
8946 + err = xsystem(cmd);
8950 + fprintf(stderr, "%s script returned status %d\n", script, err);
8957 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8961 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8962 + if (pkg_state_want_map[i].value == sw) {
8963 + return strdup(pkg_state_want_map[i].str);
8967 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8968 + __FUNCTION__, sw);
8969 + return strdup("<STATE_WANT_UNKNOWN>");
8972 +pkg_state_want_t pkg_state_want_from_str(char *str)
8976 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8977 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8978 + return pkg_state_want_map[i].value;
8982 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8983 + __FUNCTION__, str);
8984 + return SW_UNKNOWN;
8987 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8990 + int len = 3; /* ok\000 is minimum */
8993 + /* clear the temporary flags before converting to string */
8994 + sf &= SF_NONVOLATILE_FLAGS;
8997 + return strdup("ok");
9000 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9001 + if (sf & pkg_state_flag_map[i].value) {
9002 + len += strlen(pkg_state_flag_map[i].str) + 1;
9005 + str = malloc(len);
9006 + if ( str == NULL ) {
9007 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9011 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9012 + if (sf & pkg_state_flag_map[i].value) {
9013 + strcat(str, pkg_state_flag_map[i].str);
9017 + len = strlen(str);
9018 + str[len-1] = 0; /* squash last comma */
9023 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9028 + if (strcmp(str, "ok") == 0) {
9031 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9032 + const char *sfname = pkg_state_flag_map[i].str;
9033 + int sfname_len = strlen(sfname);
9034 + if (strncmp(str, sfname, sfname_len) == 0) {
9035 + sf |= pkg_state_flag_map[i].value;
9036 + str += sfname_len;
9037 + if (str[0] == ',') {
9048 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9052 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9053 + if (pkg_state_status_map[i].value == ss) {
9054 + return strdup(pkg_state_status_map[i].str);
9058 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9059 + __FUNCTION__, ss);
9060 + return strdup("<STATE_STATUS_UNKNOWN>");
9063 +pkg_state_status_t pkg_state_status_from_str(char *str)
9067 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9068 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9069 + return pkg_state_status_map[i].value;
9073 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9074 + __FUNCTION__, str);
9075 + return SS_NOT_INSTALLED;
9078 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9080 + nv_pair_list_elt_t *l;
9082 + if (!pkg->architecture)
9085 + l = conf->arch_list.head;
9088 + nv_pair_t *nv = l->data;
9089 + if (strcmp(nv->name, pkg->architecture) == 0) {
9090 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9096 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9100 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9102 + nv_pair_list_elt_t *l;
9104 + l = conf->arch_list.head;
9107 + nv_pair_t *nv = l->data;
9108 + if (strcmp(nv->name, archname) == 0) {
9109 + int priority = strtol(nv->value, NULL, 0);
9117 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9120 + hash_table_t *pkg_hash = &conf->pkg_hash;
9121 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9122 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9124 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9125 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9126 + /* update arch_priority for each package */
9127 + for (i = 0; i < available_pkgs->len; i++) {
9128 + pkg_t *pkg = available_pkgs->pkgs[i];
9129 + int arch_priority = 1;
9132 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9133 + if (pkg->architecture)
9134 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9136 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9137 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9138 + pkg->arch_priority = arch_priority;
9141 + for (i = 0; i < available_pkgs->len; i++) {
9142 + pkg_t *pkg = available_pkgs->pkgs[i];
9143 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9144 + /* clear flags and want for any uninstallable package */
9145 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9146 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9147 + pkg->state_want = SW_UNKNOWN;
9148 + pkg->state_flag = 0;
9151 + pkg_vec_free(available_pkgs);
9153 + /* update the file owner data structure */
9154 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9155 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9156 + for (i = 0; i < installed_pkgs->len; i++) {
9157 + pkg_t *pkg = installed_pkgs->pkgs[i];
9158 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9159 + str_list_elt_t *iter;
9160 + if (installed_files == NULL) {
9161 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9164 + for (iter = installed_files->head; iter; iter = iter->next) {
9165 + char *installed_file = iter->data;
9166 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9167 + file_hash_set_file_owner(conf, installed_file, pkg);
9170 + pkg_vec_free(installed_pkgs);
9175 +struct pkg_write_filelist_data {
9176 + ipkg_conf_t *conf;
9181 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9183 + struct pkg_write_filelist_data *data = data_;
9184 + pkg_t *entry = entry_;
9185 + if (entry == data->pkg) {
9186 + fprintf(data->stream, "%s\n", key);
9190 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9192 + struct pkg_write_filelist_data data;
9193 + char *list_file_name = NULL;
9197 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9200 + ipkg_message(conf, IPKG_INFO,
9201 + " creating %s.list file\n", pkg->name);
9202 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9203 + if (!list_file_name) {
9204 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9207 + ipkg_message(conf, IPKG_INFO,
9208 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9209 + data.stream = fopen(list_file_name, "w");
9210 + if (!data.stream) {
9211 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9212 + list_file_name, strerror(errno));
9217 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9218 + fclose(data.stream);
9219 + free(list_file_name);
9224 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9226 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9227 + hash_table_t *pkg_hash = &conf->pkg_hash;
9230 + if (conf->noaction)
9233 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9234 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9235 + for (i = 0; i < installed_pkgs->len; i++) {
9236 + pkg_t *pkg = installed_pkgs->pkgs[i];
9237 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9238 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9239 + err = pkg_write_filelist(conf, pkg);
9241 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9246 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg.h busybox-1.1.1-new/archival/libipkg/pkg.h
9247 --- busybox-1.1.1-old/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9248 +++ busybox-1.1.1-new/archival/libipkg/pkg.h 2006-03-30 00:39:48.000000000 +0200
9250 +/* pkg.h - the itsy package management system
9254 + Copyright (C) 2001 University of Southern California
9256 + This program is free software; you can redistribute it and/or
9257 + modify it under the terms of the GNU General Public License as
9258 + published by the Free Software Foundation; either version 2, or (at
9259 + your option) any later version.
9261 + This program is distributed in the hope that it will be useful, but
9262 + WITHOUT ANY WARRANTY; without even the implied warranty of
9263 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9264 + General Public License for more details.
9270 +#include <sys/types.h>
9271 +#include <sys/stat.h>
9272 +#include <unistd.h>
9274 +#include "pkg_vec.h"
9275 +#include "str_list.h"
9276 +#include "pkg_src.h"
9277 +#include "pkg_dest.h"
9278 +#include "ipkg_conf.h"
9279 +#include "conffile_list.h"
9284 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9286 +/* I think "Size" is currently the shortest field name */
9287 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9289 +enum pkg_state_want
9295 + SW_LAST_STATE_WANT
9297 +typedef enum pkg_state_want pkg_state_want_t;
9299 +enum pkg_state_flag
9303 + SF_HOLD = 2, /* do not upgrade version */
9304 + SF_REPLACE = 4, /* replace this package */
9305 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9306 + SF_PREFER = 16, /* prefer this version */
9307 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9308 + SF_MARKED = 64, /* temporary mark */
9309 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9311 + SF_LAST_STATE_FLAG
9313 +typedef enum pkg_state_flag pkg_state_flag_t;
9314 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9316 +enum pkg_state_status
9318 + SS_NOT_INSTALLED = 1,
9320 + SS_HALF_CONFIGURED,
9322 + SS_HALF_INSTALLED,
9324 + SS_POST_INST_FAILED,
9325 + SS_REMOVAL_FAILED,
9326 + SS_LAST_STATE_STATUS
9328 +typedef enum pkg_state_status pkg_state_status_t;
9330 +struct abstract_pkg{
9332 + int dependencies_checked;
9334 + pkg_state_status_t state_status;
9335 + pkg_state_flag_t state_flag;
9336 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9337 + abstract_pkg_vec_t * provided_by;
9338 + abstract_pkg_vec_t * replaced_by;
9341 +#include "pkg_depends.h"
9343 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9345 + The 3 version fields should go into a single version struct. (This
9346 + is especially important since, currently, pkg->version can easily
9347 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9348 + distinct. This has been the source of multiple bugs.
9350 + The 3 state fields could possibly also go into their own struct.
9352 + All fields which deal with lists of packages, (Depends,
9353 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9354 + be handled by a single struct in pkg_t
9356 + All string fields for which there is a small set of possible
9357 + values, (section, maintainer, architecture, maybe version?), that
9358 + are reused among different packages -- for all such packages we
9359 + should move from "char *"s to some atom datatype to share data
9360 + storage and use less memory. We might even do reference counting,
9361 + but probably not since most often we only create new pkg_t structs,
9362 + we don't often free them. */
9366 + unsigned long epoch;
9369 + char *familiar_revision;
9372 + char *architecture;
9375 + char *description;
9376 + pkg_state_want_t state_want;
9377 + pkg_state_flag_t state_flag;
9378 + pkg_state_status_t state_status;
9379 + char **depends_str;
9380 + int depends_count;
9381 + char **pre_depends_str;
9382 + int pre_depends_count;
9383 + char **recommends_str;
9384 + int recommends_count;
9385 + char **suggests_str;
9386 + int suggests_count;
9387 + compound_depend_t * depends;
9389 + /* Abhaya: new conflicts */
9390 + char **conflicts_str;
9391 + compound_depend_t * conflicts;
9392 + int conflicts_count;
9394 + char **replaces_str;
9395 + int replaces_count;
9396 + abstract_pkg_t ** replaces;
9398 + char **provides_str;
9399 + int provides_count;
9400 + abstract_pkg_t ** provides;
9402 + abstract_pkg_t *parent;
9404 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9407 + char *local_filename;
9409 + char *tmp_unpack_dir;
9412 + char *installed_size;
9415 + conffile_list_t conffiles;
9416 + time_t installed_time;
9417 + /* As pointer for lazy evaluation */
9418 + str_list_t *installed_files;
9419 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9420 + mechanism to avoid the problem here, (which is that the
9421 + installed_files list was being freed from an inner loop while
9422 + still being used within an outer loop. */
9423 + int installed_files_ref_cnt;
9425 + int arch_priority;
9428 +pkg_t *pkg_new(void);
9429 +int pkg_init(pkg_t *pkg);
9430 +void pkg_deinit(pkg_t *pkg);
9431 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9432 +abstract_pkg_t *abstract_pkg_new(void);
9433 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9436 + * merges fields from newpkg into oldpkg.
9437 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9439 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9441 +char *pkg_version_str_alloc(pkg_t *pkg);
9443 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9444 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9445 +int abstract_pkg_name_compare(void *a, void *b);
9447 +char * pkg_formatted_info(pkg_t *pkg );
9448 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9450 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9452 +void pkg_print_info(pkg_t *pkg, FILE *file);
9453 +void pkg_print_status(pkg_t * pkg, FILE * file);
9454 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9455 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9456 +int pkg_free_installed_files(pkg_t *pkg);
9457 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9458 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9459 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9460 + const char *script, const char *args);
9462 +/* enum mappings */
9463 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9464 +pkg_state_want_t pkg_state_want_from_str(char *str);
9465 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9466 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9467 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9468 +pkg_state_status_t pkg_state_status_from_str(char *str);
9470 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9472 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9473 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9474 +int pkg_free_installed_files(pkg_t *pkg);
9476 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9477 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9480 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_depends.c busybox-1.1.1-new/archival/libipkg/pkg_depends.c
9481 --- busybox-1.1.1-old/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9482 +++ busybox-1.1.1-new/archival/libipkg/pkg_depends.c 2006-03-30 00:39:48.000000000 +0200
9484 +/* pkg_depends.c - the itsy package management system
9488 + Copyright (C) 2002 Compaq Computer Corporation
9490 + This program is free software; you can redistribute it and/or
9491 + modify it under the terms of the GNU General Public License as
9492 + published by the Free Software Foundation; either version 2, or (at
9493 + your option) any later version.
9495 + This program is distributed in the hope that it will be useful, but
9496 + WITHOUT ANY WARRANTY; without even the implied warranty of
9497 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9498 + General Public License for more details.
9506 +#include "ipkg_utils.h"
9507 +#include "pkg_hash.h"
9508 +#include "ipkg_message.h"
9509 +#include "pkg_parse.h"
9510 +#include "hash_table.h"
9512 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9513 +static depend_t * depend_init(void);
9514 +static void depend_deinit(depend_t *d);
9515 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9516 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9517 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9519 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9521 + depend_t *depend = (depend_t *)cdata;
9522 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9528 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9530 + depend_t *depend = (depend_t *)cdata;
9532 + pkg_t * temp = pkg_new();
9534 + parseVersion(temp, depend->version);
9535 + comparison = pkg_compare_versions(pkg, temp);
9538 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9539 + __FUNCTION__, pkg->name, pkg->version,
9540 + depend, depend->constraint, depend->version,
9541 + comparison, version_constraints_satisfied(depend, pkg));
9543 + if (version_constraints_satisfied(depend, pkg))
9549 +/* returns ndependences or negative error value */
9550 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9551 + pkg_vec_t *unsatisfied, char *** unresolved)
9553 + pkg_t * satisfier_entry_pkg;
9554 + register int i, j, k;
9557 + abstract_pkg_t * ab_pkg;
9560 + * this is a setup to check for redundant/cyclic dependency checks,
9561 + * which are marked at the abstract_pkg level
9563 + if (!(ab_pkg = pkg->parent)) {
9564 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9565 + *unresolved = NULL;
9568 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9569 + *unresolved = NULL;
9572 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9576 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9578 + *unresolved = NULL;
9584 + /* foreach dependency */
9585 + for (i = 0; i < count; i++) {
9586 + compound_depend_t * compound_depend = &pkg->depends[i];
9587 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9589 + satisfier_entry_pkg = NULL;
9591 + if (compound_depend->type == GREEDY_DEPEND) {
9592 + /* foreach possible satisfier */
9593 + for (j = 0; j < compound_depend->possibility_count; j++) {
9594 + /* foreach provided_by, which includes the abstract_pkg itself */
9595 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9596 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9597 + int nposs = ab_provider_vec->len;
9598 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9600 + for (l = 0; l < nposs; l++) {
9601 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9602 + /* if no depends on this one, try the first package that Provides this one */
9603 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9607 + /* cruise this possiblity's pkg_vec looking for an installed version */
9608 + for (k = 0; k < test_vec->len; k++) {
9609 + pkg_t *pkg_scout = test_vec->pkgs[k];
9610 + /* not installed, and not already known about? */
9611 + if ((pkg_scout->state_want != SW_INSTALL)
9612 + && !pkg_scout->parent->dependencies_checked
9613 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9614 + char ** newstuff = NULL;
9616 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9617 + /* check for not-already-installed dependencies */
9618 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9622 + if (newstuff == NULL) {
9625 + for (i = 0; i < rc; i++) {
9626 + pkg_t *p = tmp_vec->pkgs[i];
9627 + if (p->state_want == SW_INSTALL)
9629 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9633 + pkg_vec_free (tmp_vec);
9635 + /* mark this one for installation */
9636 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9637 + pkg_vec_insert(unsatisfied, pkg_scout);
9640 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9651 + /* foreach possible satisfier, look for installed package */
9652 + for (j = 0; j < compound_depend->possibility_count; j++) {
9653 + /* foreach provided_by, which includes the abstract_pkg itself */
9654 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9655 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9656 + pkg_t *satisfying_pkg =
9657 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9658 + pkg_installed_and_constraint_satisfied,
9659 + dependence_to_satisfy, 1);
9660 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9661 + if (satisfying_pkg != NULL) {
9662 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9663 + satisfying_pkg = NULL;
9666 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9667 + if (satisfying_pkg != NULL) {
9673 + /* if nothing installed matches, then look for uninstalled satisfier */
9675 + /* foreach possible satisfier, look for installed package */
9676 + for (j = 0; j < compound_depend->possibility_count; j++) {
9677 + /* foreach provided_by, which includes the abstract_pkg itself */
9678 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9679 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9680 + pkg_t *satisfying_pkg =
9681 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9682 + pkg_constraint_satisfied,
9683 + dependence_to_satisfy, 1);
9684 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9685 + if (satisfying_pkg != NULL) {
9686 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9687 + satisfying_pkg = NULL;
9691 + /* user request overrides package recommendation */
9692 + if (satisfying_pkg != NULL
9693 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9694 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9695 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9696 + pkg->name, satisfying_pkg->name);
9700 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9701 + if (satisfying_pkg != NULL) {
9702 + satisfier_entry_pkg = satisfying_pkg;
9708 + /* we didn't find one, add something to the unsatisfied vector */
9710 + if (!satisfier_entry_pkg) {
9711 + /* failure to meet recommendations is not an error */
9712 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9713 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9715 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9716 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9719 + if (compound_depend->type == SUGGEST) {
9720 + /* just mention it politely */
9721 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9722 + pkg->name, satisfier_entry_pkg->name);
9724 + char ** newstuff = NULL;
9726 + if (satisfier_entry_pkg != pkg &&
9727 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9728 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9729 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9730 + satisfier_entry_pkg,
9733 + the_lost = merge_unresolved(the_lost, newstuff);
9739 + *unresolved = the_lost;
9741 + return unsatisfied->len;
9744 +/*checking for conflicts !in replaces
9745 + If a packages conflicts with another but is also replacing it, I should not consider it a
9747 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9749 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9752 + int replaces_count = pkg->replaces_count;
9753 + abstract_pkg_t **replaces;
9755 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9758 + replaces = pkg->replaces;
9760 + for (i = 0; i < replaces_count; i++) {
9761 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9769 +/* Abhaya: added support for conflicts */
9770 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9772 + pkg_vec_t * installed_conflicts, * test_vec;
9773 + compound_depend_t * conflicts;
9774 + depend_t ** possible_satisfiers;
9775 + depend_t * possible_satisfier;
9776 + register int i, j, k;
9778 + abstract_pkg_t * ab_pkg;
9779 + pkg_t **pkg_scouts;
9783 + * this is a setup to check for redundant/cyclic dependency checks,
9784 + * which are marked at the abstract_pkg level
9786 + if(!(ab_pkg = pkg->parent)){
9787 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9788 + return (pkg_vec_t *)NULL;
9791 + conflicts = pkg->conflicts;
9793 + return (pkg_vec_t *)NULL;
9795 + installed_conflicts = pkg_vec_alloc();
9797 + count = pkg->conflicts_count;
9801 + /* foreach conflict */
9802 + for(i = 0; i < pkg->conflicts_count; i++){
9804 + possible_satisfiers = conflicts->possibilities;
9806 + /* foreach possible satisfier */
9807 + for(j = 0; j < conflicts->possibility_count; j++){
9808 + possible_satisfier = possible_satisfiers[j];
9809 + if (!possible_satisfier)
9810 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9811 + if (!possible_satisfier->pkg)
9812 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9813 + test_vec = possible_satisfier->pkg->pkgs;
9815 + /* pkg_vec found, it is an actual package conflict
9816 + * cruise this possiblity's pkg_vec looking for an installed version */
9817 + pkg_scouts = test_vec->pkgs;
9818 + for(k = 0; k < test_vec->len; k++){
9819 + pkg_scout = pkg_scouts[k];
9821 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9824 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9825 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9826 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9827 + pkg_vec_insert(installed_conflicts, pkg_scout);
9836 + if (installed_conflicts->len)
9837 + return installed_conflicts;
9838 + pkg_vec_free(installed_conflicts);
9839 + return (pkg_vec_t *)NULL;
9842 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9847 + if(depends->constraint == NONE)
9852 + parseVersion(temp, depends->version);
9854 + comparison = pkg_compare_versions(pkg, temp);
9858 + if((depends->constraint == EARLIER) &&
9861 + else if((depends->constraint == LATER) &&
9864 + else if(comparison == 0)
9866 + else if((depends->constraint == LATER_EQUAL) &&
9867 + (comparison >= 0))
9869 + else if((depends->constraint == EARLIER_EQUAL) &&
9870 + (comparison <= 0))
9876 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9878 + abstract_pkg_t *apkg = depend->pkg;
9879 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9880 + int n_providers = provider_apkgs->len;
9881 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9882 + pkg_vec_t *pkg_vec;
9887 + for (i = 0; i < n_providers; i++) {
9888 + abstract_pkg_t *papkg = apkgs[i];
9889 + pkg_vec = papkg->pkgs;
9891 + n_pkgs = pkg_vec->len;
9892 + for (j = 0; j < n_pkgs; j++) {
9893 + pkg_t *pkg = pkg_vec->pkgs[j];
9894 + if (version_constraints_satisfied(depend, pkg)) {
9903 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9905 + abstract_pkg_t *apkg = depend->pkg;
9906 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9907 + int n_providers = provider_apkgs->len;
9908 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9913 + for (i = 0; i < n_providers; i++) {
9914 + abstract_pkg_t *papkg = apkgs[i];
9915 + pkg_vec_t *pkg_vec = papkg->pkgs;
9917 + n_pkgs = pkg_vec->len;
9918 + for (j = 0; j < n_pkgs; j++) {
9919 + pkg_t *pkg = pkg_vec->pkgs[j];
9920 + if (version_constraints_satisfied(depend, pkg)) {
9921 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9930 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9933 + pkg_t ** pkgs = vec->pkgs;
9935 + for(i = 0; i < vec->len; i++)
9936 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9937 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9938 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9946 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9947 + * the same abstract package and 0 otherwise.
9949 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9951 + abstract_pkg_t **provides = pkg->provides;
9952 + int provides_count = pkg->provides_count;
9953 + abstract_pkg_t **replacee_provides = replacee->provides;
9954 + int replacee_provides_count = replacee->provides_count;
9956 + for (i = 0; i < provides_count; i++) {
9957 + abstract_pkg_t *apkg = provides[i];
9958 + for (j = 0; j < replacee_provides_count; j++) {
9959 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9960 + if (apkg == replacee_apkg)
9969 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9970 + * and 0 otherwise.
9972 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9974 + abstract_pkg_t **provides = pkg->provides;
9975 + int provides_count = pkg->provides_count;
9977 + for (i = 0; i < provides_count; i++) {
9978 + if (provides[i] == providee)
9985 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9988 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9990 + abstract_pkg_t **replaces = pkg->replaces;
9991 + int replaces_count = pkg->replaces_count;
9992 + abstract_pkg_t **replacee_provides = pkg->provides;
9993 + int replacee_provides_count = pkg->provides_count;
9995 + for (i = 0; i < replaces_count; i++) {
9996 + abstract_pkg_t *abstract_replacee = replaces[i];
9997 + for (j = 0; j < replacee_provides_count; j++) {
9998 + if (replacee_provides[j] == abstract_replacee)
10007 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10010 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10012 + compound_depend_t *conflicts = pkg->conflicts;
10013 + int conflicts_count = pkg->conflicts_count;
10015 + for (i = 0; i < conflicts_count; i++) {
10016 + int possibility_count = conflicts[i].possibility_count;
10017 + struct depend **possibilities = conflicts[i].possibilities;
10018 + for (j = 0; j < possibility_count; j++) {
10019 + if (possibilities[j]->pkg == conflictee) {
10028 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10029 + * conflictee's provides and 0 otherwise.
10031 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10033 + compound_depend_t *conflicts = pkg->conflicts;
10034 + int conflicts_count = pkg->conflicts_count;
10035 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10036 + int conflictee_provides_count = conflictee->provides_count;
10038 + int possibility_count;
10039 + struct depend **possibilities;
10040 + abstract_pkg_t *possibility ;
10042 + for (i = 0; i < conflicts_count; i++) {
10043 + possibility_count = conflicts[i].possibility_count;
10044 + possibilities = conflicts[i].possibilities;
10045 + for (j = 0; j < possibility_count; j++) {
10046 + possibility = possibilities[j]->pkg;
10047 + for (k = 0; k < conflictee_provides_count; k++) {
10048 + if (possibility == conflictee_provides[k]) {
10057 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10059 + int oldlen = 0, newlen = 0;
10061 + register int i, j;
10066 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10067 + while(newstuff && newstuff[newlen]) newlen++;
10069 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10070 + if (result == NULL) {
10071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10075 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10076 + *(result + i) = *(newstuff + j);
10078 + *(result + i) = NULL;
10084 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10085 + * this is null terminated, no count is carried around
10087 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10091 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10094 + while(the_lost && the_lost[count]) count++;
10096 + count++; /* need one to hold the null */
10097 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10098 + if (resized == NULL) {
10099 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10102 + resized[count - 1] = strdup(depend_str);
10103 + resized[count] = NULL;
10108 +void printDepends(pkg_t * pkg)
10110 + register int i, j;
10111 + compound_depend_t * depend;
10114 + count = pkg->pre_depends_count + pkg->depends_count;
10116 + depend = pkg->depends;
10118 + fprintf(stderr, "Depends pointer is NULL\n");
10121 + for(i = 0; i < count; i++){
10122 + fprintf(stderr, "%s has %d possibilities:\n",
10123 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10124 + depend->possibility_count);
10125 + for(j = 0; j < depend->possibility_count; j++)
10126 + fprintf(stderr, "\t%s version %s (%d)\n",
10127 + depend->possibilities[j]->pkg->name,
10128 + depend->possibilities[j]->version,
10129 + depend->possibilities[j]->constraint);
10134 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10136 + register int i, j;
10138 + /* every pkg provides itself */
10139 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10141 + if (!pkg->provides_count)
10144 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10145 + if (pkg->provides == NULL) {
10146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10149 + pkg->provides[0] = ab_pkg;
10151 + // if (strcmp(ab_pkg->name, pkg->name))
10152 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10154 + for(i = 0; i < pkg->provides_count; i++){
10155 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10157 + pkg->provides[i+1] = provided_abpkg;
10160 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10165 +/* Abhaya: added conflicts support */
10166 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10169 + compound_depend_t * conflicts;
10171 + if (!pkg->conflicts_count)
10174 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10175 + pkg->conflicts_count);
10176 + if (conflicts == NULL) {
10177 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10180 + for (i = 0; i < pkg->conflicts_count; i++) {
10181 + conflicts->type = CONFLICTS;
10182 + parseDepends(conflicts, hash,
10183 + pkg->conflicts_str[i]);
10185 + for (j = 0; j < conflicts->possibility_count; j++) {
10186 + depend_t *possibility = conflicts->possibilities[j];
10187 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10188 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10196 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10198 + register int i, j;
10200 + if (!pkg->replaces_count)
10203 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10204 + if (pkg->replaces == NULL) {
10205 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10209 + // if (strcmp(ab_pkg->name, pkg->name))
10210 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10212 + for(i = 0; i < pkg->replaces_count; i++){
10213 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10215 + pkg->replaces[i] = old_abpkg;
10218 + if (!old_abpkg->replaced_by)
10219 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10220 + if ( old_abpkg->replaced_by == NULL ){
10223 + /* if a package pkg both replaces and conflicts old_abpkg,
10224 + * then add it to the replaced_by vector so that old_abpkg
10225 + * will be upgraded to ab_pkg automatically */
10226 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10227 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10232 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10236 + compound_depend_t * depends;
10238 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10241 + if (0 && pkg->pre_depends_count)
10242 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10243 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10244 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10245 + if (depends == NULL) {
10246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10251 + for(i = 0; i < pkg->pre_depends_count; i++){
10252 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10253 + if (0 && pkg->pre_depends_count)
10254 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10255 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10256 + depends->type = PREDEPEND;
10260 + for(i = 0; i < pkg->recommends_count; i++){
10261 + parseDepends(depends, hash, pkg->recommends_str[i]);
10262 + if (0 && pkg->recommends_count)
10263 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10264 + pkg->recommends_str[i], depends, depends->possibility_count);
10265 + depends->type = RECOMMEND;
10269 + for(i = 0; i < pkg->suggests_count; i++){
10270 + parseDepends(depends, hash, pkg->suggests_str[i]);
10271 + if (0 && pkg->suggests_count)
10272 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10273 + pkg->suggests_str[i], depends, depends->possibility_count);
10274 + depends->type = SUGGEST;
10278 + for(i = 0; i < pkg->depends_count; i++){
10279 + parseDepends(depends, hash, pkg->depends_str[i]);
10280 + if (0 && pkg->depends_count)
10281 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10282 + pkg->depends_str[i], depends, depends->possibility_count);
10289 + * pkg_depend_string: returns the depends string specified by index.
10290 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10291 + * [0,npredepends) -> returns pre_depends_str[index]
10292 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10293 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10294 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10296 +char *pkg_depend_str(pkg_t *pkg, int index)
10298 + if (index < pkg->pre_depends_count) {
10299 + return pkg->pre_depends_str[index];
10301 + index -= pkg->pre_depends_count;
10303 + if (index < pkg->recommends_count) {
10304 + return pkg->recommends_str[index];
10306 + index -= pkg->recommends_count;
10308 + if (index < pkg->suggests_count) {
10309 + return pkg->suggests_str[index];
10311 + index -= pkg->suggests_count;
10313 + if (index < pkg->depends_count) {
10314 + return pkg->depends_str[index];
10316 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10320 +void freeDepends(pkg_t *pkg)
10324 + if (pkg == NULL || pkg->depends == NULL) {
10328 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10329 + for (i=0; i < pkg->depends->possibility_count; i++) {
10330 + depend_deinit(pkg->depends->possibilities[i]);
10332 + free(pkg->depends->possibilities);
10333 + free(pkg->depends);
10334 + pkg->depends = NULL;
10337 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10339 + compound_depend_t * depends;
10340 + int count, othercount;
10341 + register int i, j;
10342 + abstract_pkg_t * ab_depend;
10343 + abstract_pkg_t ** temp;
10345 + count = pkg->pre_depends_count + pkg->depends_count;
10346 + depends = pkg->depends;
10348 + if (0 && pkg->pre_depends_count)
10349 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10350 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10351 + for (i = 0; i < count; i++) {
10352 + if (0 && pkg->pre_depends_count)
10353 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10354 + for (j = 0; j < depends->possibility_count; j++){
10355 + ab_depend = depends->possibilities[j]->pkg;
10356 + if(!ab_depend->depended_upon_by)
10357 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10359 + temp = ab_depend->depended_upon_by;
10367 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10368 + (othercount + 1) * sizeof(abstract_pkg_t *));
10369 + /* the array may have moved */
10370 + temp = ab_depend->depended_upon_by + othercount;
10377 +static depend_t * depend_init(void)
10379 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10381 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10384 + d->constraint = NONE;
10385 + d->version = NULL;
10391 +static void depend_deinit(depend_t *d)
10396 +static int parseDepends(compound_depend_t *compound_depend,
10397 + hash_table_t * hash, char * depend_str)
10399 + char * pkg_name, buffer[2048];
10400 + int num_of_ors = 0;
10402 + register char * src, * dest;
10403 + depend_t ** possibilities;
10405 + /* first count the number of ored possibilities for satisfying dependency */
10406 + src = depend_str;
10408 + if(*src++ == '|')
10411 + compound_depend->type = DEPEND;
10413 + compound_depend->possibility_count = num_of_ors + 1;
10414 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10415 + if (!possibilities)
10417 + compound_depend->possibilities = possibilities;
10419 + src = depend_str;
10420 + for(i = 0; i < num_of_ors + 1; i++){
10421 + possibilities[i] = depend_init();
10422 + if (!possibilities[i])
10424 + /* gobble up just the name first */
10427 + !isspace(*src) &&
10431 + *dest++ = *src++;
10433 + pkg_name = trim_alloc(buffer);
10434 + if (pkg_name == NULL )
10437 + /* now look at possible version info */
10439 + /* skip to next chars */
10440 + if(isspace(*src))
10441 + while(*src && isspace(*src)) src++;
10443 + /* extract constraint and version */
10446 + if(!strncmp(src, "<<", 2)){
10447 + possibilities[i]->constraint = EARLIER;
10450 + else if(!strncmp(src, "<=", 2)){
10451 + possibilities[i]->constraint = EARLIER_EQUAL;
10454 + else if(!strncmp(src, ">=", 2)){
10455 + possibilities[i]->constraint = LATER_EQUAL;
10458 + else if(!strncmp(src, ">>", 2)){
10459 + possibilities[i]->constraint = LATER;
10462 + else if(!strncmp(src, "=", 1)){
10463 + possibilities[i]->constraint = EQUAL;
10466 + /* should these be here to support deprecated designations; dpkg does */
10467 + else if(!strncmp(src, "<", 1)){
10468 + possibilities[i]->constraint = EARLIER_EQUAL;
10471 + else if(!strncmp(src, ">", 1)){
10472 + possibilities[i]->constraint = LATER_EQUAL;
10476 + /* now we have any constraint, pass space to version string */
10477 + while(isspace(*src)) src++;
10479 + /* this would be the version string */
10481 + while(*src && *src != ')')
10482 + *dest++ = *src++;
10485 + possibilities[i]->version = trim_alloc(buffer);
10486 + /* fprintf(stderr, "let's print the depends version string:");
10487 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10488 + if (possibilities[i]->version == NULL )
10493 + /* hook up the dependency to its abstract pkg */
10494 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10498 + /* now get past the ) and any possible | chars */
10500 + (isspace(*src) ||
10506 + compound_depend->type = GREEDY_DEPEND;
10513 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_depends.h busybox-1.1.1-new/archival/libipkg/pkg_depends.h
10514 --- busybox-1.1.1-old/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10515 +++ busybox-1.1.1-new/archival/libipkg/pkg_depends.h 2006-03-30 00:39:48.000000000 +0200
10517 +/* pkg_depends.h - the itsy package management system
10521 + Copyright (C) 2002 Compaq Computer Corporation
10523 + This program is free software; you can redistribute it and/or
10524 + modify it under the terms of the GNU General Public License as
10525 + published by the Free Software Foundation; either version 2, or (at
10526 + your option) any later version.
10528 + This program is distributed in the hope that it will be useful, but
10529 + WITHOUT ANY WARRANTY; without even the implied warranty of
10530 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10531 + General Public License for more details.
10534 +#ifndef PKG_DEPENDS_H
10535 +#define PKG_DEPENDS_H
10538 +#include "pkg_hash.h"
10540 +enum depend_type {
10548 +typedef enum depend_type depend_type_t;
10550 +enum version_constraint {
10558 +typedef enum version_constraint version_constraint_t;
10561 + version_constraint_t constraint;
10563 + abstract_pkg_t * pkg;
10565 +typedef struct depend depend_t;
10567 +struct compound_depend{
10568 + depend_type_t type;
10569 + int possibility_count;
10570 + struct depend ** possibilities;
10572 +typedef struct compound_depend compound_depend_t;
10574 +#include "hash_table.h"
10576 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10577 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10578 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10579 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10582 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10583 + * the same abstract package and 0 otherwise.
10585 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10588 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10591 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10594 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10597 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10600 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10603 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10606 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10609 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10611 +char *pkg_depend_str(pkg_t *pkg, int index);
10612 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10613 +void freeDepends(pkg_t *pkg);
10614 +void printDepends(pkg_t * pkg);
10615 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10616 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10617 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10618 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10619 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10622 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest.c busybox-1.1.1-new/archival/libipkg/pkg_dest.c
10623 --- busybox-1.1.1-old/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10624 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest.c 2006-03-30 00:39:48.000000000 +0200
10626 +/* pkg_dest.c - the itsy package management system
10630 + Copyright (C) 2001 University of Southern California
10632 + This program is free software; you can redistribute it and/or
10633 + modify it under the terms of the GNU General Public License as
10634 + published by the Free Software Foundation; either version 2, or (at
10635 + your option) any later version.
10637 + This program is distributed in the hope that it will be useful, but
10638 + WITHOUT ANY WARRANTY; without even the implied warranty of
10639 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10640 + General Public License for more details.
10645 +#include "pkg_dest.h"
10646 +#include "file_util.h"
10647 +#include "str_util.h"
10648 +#include "sprintf_alloc.h"
10650 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10652 + dest->name = strdup(name);
10654 + /* Guarantee that dest->root_dir ends with a '/' */
10655 + if (str_ends_with(root_dir, "/")) {
10656 + dest->root_dir = strdup(root_dir);
10658 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10660 + file_mkdir_hier(dest->root_dir, 0755);
10662 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10663 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10664 + file_mkdir_hier(dest->ipkg_dir, 0755);
10666 + if (str_starts_with (lists_dir, "/"))
10667 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10669 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10671 + file_mkdir_hier(dest->lists_dir, 0755);
10673 + sprintf_alloc(&dest->info_dir, "%s/%s",
10674 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10675 + file_mkdir_hier(dest->info_dir, 0755);
10677 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10678 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10680 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10681 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10683 + dest->status_file = NULL;
10688 +void pkg_dest_deinit(pkg_dest_t *dest)
10690 + free(dest->name);
10691 + dest->name = NULL;
10693 + free(dest->root_dir);
10694 + dest->root_dir = NULL;
10696 + free(dest->ipkg_dir);
10697 + dest->ipkg_dir = NULL;
10699 + free(dest->lists_dir);
10700 + dest->lists_dir = NULL;
10702 + free(dest->info_dir);
10703 + dest->info_dir = NULL;
10705 + free(dest->status_file_name);
10706 + dest->status_file_name = NULL;
10708 + free(dest->status_file_tmp_name);
10709 + dest->status_file_tmp_name = NULL;
10711 + if (dest->status_file) {
10712 + fclose(dest->status_file);
10714 + dest->status_file = NULL;
10716 + dest->root_dir = NULL;
10718 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest.h busybox-1.1.1-new/archival/libipkg/pkg_dest.h
10719 --- busybox-1.1.1-old/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10720 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest.h 2006-03-30 00:39:48.000000000 +0200
10722 +/* pkg_dest.h - the itsy package management system
10726 + Copyright (C) 2001 University of Southern California
10728 + This program is free software; you can redistribute it and/or
10729 + modify it under the terms of the GNU General Public License as
10730 + published by the Free Software Foundation; either version 2, or (at
10731 + your option) any later version.
10733 + This program is distributed in the hope that it will be useful, but
10734 + WITHOUT ANY WARRANTY; without even the implied warranty of
10735 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10736 + General Public License for more details.
10739 +#ifndef PKG_DEST_H
10740 +#define PKG_DEST_H
10742 +typedef struct pkg_dest pkg_dest_t;
10750 + char *status_file_name;
10751 + char *status_file_tmp_name;
10752 + FILE *status_file;
10755 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10756 +void pkg_dest_deinit(pkg_dest_t *dest);
10760 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest_list.c busybox-1.1.1-new/archival/libipkg/pkg_dest_list.c
10761 --- busybox-1.1.1-old/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10762 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest_list.c 2006-03-30 00:39:48.000000000 +0200
10764 +/* pkg_dest_list.c - the itsy package management system
10768 + Copyright (C) 2001 University of Southern California
10770 + This program is free software; you can redistribute it and/or
10771 + modify it under the terms of the GNU General Public License as
10772 + published by the Free Software Foundation; either version 2, or (at
10773 + your option) any later version.
10775 + This program is distributed in the hope that it will be useful, but
10776 + WITHOUT ANY WARRANTY; without even the implied warranty of
10777 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10778 + General Public License for more details.
10783 +#include "pkg_dest.h"
10784 +#include "void_list.h"
10785 +#include "pkg_dest_list.h"
10787 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10789 + return void_list_elt_init((void_list_elt_t *) elt, data);
10792 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10794 + void_list_elt_deinit((void_list_elt_t *) elt);
10797 +int pkg_dest_list_init(pkg_dest_list_t *list)
10799 + return void_list_init((void_list_t *) list);
10802 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10804 + pkg_dest_list_elt_t *iter;
10805 + pkg_dest_t *pkg_dest;
10807 + for (iter = list->head; iter; iter = iter->next) {
10808 + pkg_dest = iter->data;
10809 + pkg_dest_deinit(pkg_dest);
10811 + /* malloced in pkg_dest_list_append */
10813 + iter->data = NULL;
10815 + void_list_deinit((void_list_t *) list);
10818 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10819 + const char *root_dir,const char *lists_dir)
10822 + pkg_dest_t *pkg_dest;
10824 + /* freed in plg_dest_list_deinit */
10825 + pkg_dest = malloc(sizeof(pkg_dest_t));
10826 + if (pkg_dest == NULL) {
10827 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10831 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10832 + err = void_list_append((void_list_t *) list, pkg_dest);
10840 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10842 + return void_list_push((void_list_t *) list, data);
10845 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10847 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10849 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_dest_list.h busybox-1.1.1-new/archival/libipkg/pkg_dest_list.h
10850 --- busybox-1.1.1-old/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10851 +++ busybox-1.1.1-new/archival/libipkg/pkg_dest_list.h 2006-03-30 00:39:48.000000000 +0200
10853 +/* pkg_dest_list.h - the itsy package management system
10857 + Copyright (C) 2001 University of Southern California
10859 + This program is free software; you can redistribute it and/or
10860 + modify it under the terms of the GNU General Public License as
10861 + published by the Free Software Foundation; either version 2, or (at
10862 + your option) any later version.
10864 + This program is distributed in the hope that it will be useful, but
10865 + WITHOUT ANY WARRANTY; without even the implied warranty of
10866 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10867 + General Public License for more details.
10870 +#ifndef PKG_DEST_LIST_H
10871 +#define PKG_DEST_LIST_H
10873 +#include "pkg_dest.h"
10875 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10876 +struct pkg_dest_list_elt
10878 + pkg_dest_list_elt_t *next;
10879 + pkg_dest_t *data;
10882 +typedef struct pkg_dest_list pkg_dest_list_t;
10883 +struct pkg_dest_list
10885 + pkg_dest_list_elt_t pre_head;
10886 + pkg_dest_list_elt_t *head;
10887 + pkg_dest_list_elt_t *tail;
10890 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10891 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10893 +int pkg_dest_list_init(pkg_dest_list_t *list);
10894 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10896 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10897 + const char *root_dir,const char* lists_dir);
10898 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10899 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10903 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_extract.c busybox-1.1.1-new/archival/libipkg/pkg_extract.c
10904 --- busybox-1.1.1-old/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10905 +++ busybox-1.1.1-new/archival/libipkg/pkg_extract.c 2006-03-30 00:39:48.000000000 +0200
10907 +/* pkg_extract.c - the itsy package management system
10911 + Copyright (C) 2001 University of Southern California
10913 + This program is free software; you can redistribute it and/or
10914 + modify it under the terms of the GNU General Public License as
10915 + published by the Free Software Foundation; either version 2, or (at
10916 + your option) any later version.
10918 + This program is distributed in the hope that it will be useful, but
10919 + WITHOUT ANY WARRANTY; without even the implied warranty of
10920 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10921 + General Public License for more details.
10925 +#include <errno.h>
10926 +#include <fcntl.h>
10927 +#include <stdio.h>
10929 +#include "pkg_extract.h"
10931 +#include "libbb.h"
10932 +#include "file_util.h"
10933 +#include "sprintf_alloc.h"
10934 +#include "unarchive.h"
10936 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10937 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10938 +#define IPKG_CONTROL_FILE "control"
10940 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10942 + archive_handle_t *archive;
10945 + sprintf_alloc(&path, "%s/", dir);
10946 + archive = init_handle();
10947 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10948 + archive->filter = filter_accept_list;
10949 + archive->accept = llist_add_to(NULL, (char *)filename);
10950 + archive->buffer = path;
10951 + archive->action_data = data_extract_all_prefix;
10952 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10953 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10954 + close(archive->src_fd);
10955 + free(archive->accept);
10960 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10962 + unsigned int size = strlen(archive->file_header->name) + 2;
10964 + if (archive->buffer == NULL) {
10965 + archive->buffer = xmalloc(size);
10966 + strcpy(archive->buffer, archive->file_header->name);
10968 + size += strlen(archive->buffer);
10969 + archive->buffer = xrealloc(archive->buffer, size);
10970 + strcat(archive->buffer, archive->file_header->name);
10972 + strcat(archive->buffer, "\n");
10973 + data_skip(archive);
10976 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10978 + archive_handle_t *archive;
10981 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10982 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10983 + archive = init_handle();
10984 + archive->src_fd = bb_xopen(name, O_RDONLY);
10985 + archive->filter = filter_accept_list;
10986 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10987 + archive->action_data = data_extract_to_buffer;
10988 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10989 + close(archive->src_fd);
10990 + fputs(archive->buffer, stream);
10991 + free(archive->buffer);
10992 + free(archive->accept);
10999 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
11001 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11004 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11006 + archive_handle_t *archive;
11010 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11011 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11012 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11013 + archive = init_handle();
11014 + archive->src_fd = bb_xopen(name, O_RDONLY);
11015 + archive->filter = filter_accept_all;
11016 + archive->buffer = path;
11017 + archive->action_data = data_extract_all_prefix;
11018 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11019 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11020 + close(archive->src_fd);
11028 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11030 + archive_handle_t *archive;
11034 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11035 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11036 + sprintf_alloc(&path, "%s/", dir);
11037 + archive = init_handle();
11038 + archive->src_fd = bb_xopen(name, O_RDONLY);
11039 + archive->filter = filter_accept_all;
11040 + archive->buffer = path;
11041 + archive->action_data = data_extract_all_prefix;
11042 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11043 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11044 + close(archive->src_fd);
11052 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11055 + char *line, *data_file;
11059 + file = fopen(file_name, "w");
11060 + if (file == NULL) {
11061 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11062 + __FUNCTION__, file_name);
11067 + if (pkg->installed_files) {
11068 + str_list_elt_t *elt;
11069 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11070 + fprintf(file, "%s\n", elt->data);
11073 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11080 + /* Fixup data file names by removing the initial '.' */
11083 + line = file_read_line_alloc(tmp);
11084 + if (line == NULL) {
11088 + data_file = line;
11089 + if (*data_file == '.') {
11093 + if (*data_file != '/') {
11094 + fputs("/", file);
11097 + /* I have no idea why, but this is what dpkg does */
11098 + if (strcmp(data_file, "/\n") == 0) {
11099 + fputs("/.\n", file);
11101 + fputs(data_file, file);
11111 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11113 + archive_handle_t *archive;
11116 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11117 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11118 + archive = init_handle();
11119 + archive->src_fd = bb_xopen(name, O_RDONLY);
11120 + archive->filter = filter_accept_all;
11121 + archive->action_data = data_extract_file_name_to_buffer;
11122 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11123 + close(archive->src_fd);
11124 + fputs(archive->buffer, file);
11125 + free(archive->buffer);
11131 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_extract.h busybox-1.1.1-new/archival/libipkg/pkg_extract.h
11132 --- busybox-1.1.1-old/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11133 +++ busybox-1.1.1-new/archival/libipkg/pkg_extract.h 2006-03-30 00:39:48.000000000 +0200
11135 +/* pkg_extract.c - the itsy package management system
11139 + Copyright (C) 2001 University of Southern California
11141 + This program is free software; you can redistribute it and/or
11142 + modify it under the terms of the GNU General Public License as
11143 + published by the Free Software Foundation; either version 2, or (at
11144 + your option) any later version.
11146 + This program is distributed in the hope that it will be useful, but
11147 + WITHOUT ANY WARRANTY; without even the implied warranty of
11148 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11149 + General Public License for more details.
11152 +#ifndef PKG_EXTRACT_H
11153 +#define PKG_EXTRACT_H
11157 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11158 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11159 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11161 + const char *prefix);
11162 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11163 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11164 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11167 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_hash.c busybox-1.1.1-new/archival/libipkg/pkg_hash.c
11168 --- busybox-1.1.1-old/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11169 +++ busybox-1.1.1-new/archival/libipkg/pkg_hash.c 2006-03-30 00:39:48.000000000 +0200
11171 +/* ipkg_hash.c - the itsy package management system
11175 + Copyright (C) 2002 Compaq Computer Corporation
11177 + This program is free software; you can redistribute it and/or
11178 + modify it under the terms of the GNU General Public License as
11179 + published by the Free Software Foundation; either version 2, or (at
11180 + your option) any later version.
11182 + This program is distributed in the hope that it will be useful, but
11183 + WITHOUT ANY WARRANTY; without even the implied warranty of
11184 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11185 + General Public License for more details.
11189 +#include <errno.h>
11190 +#include <ctype.h>
11191 +#include <stdlib.h>
11192 +#include <string.h>
11194 +#include "hash_table.h"
11196 +#include "ipkg_message.h"
11197 +#include "pkg_vec.h"
11198 +#include "pkg_hash.h"
11199 +#include "pkg_parse.h"
11200 +#include "ipkg_utils.h"
11202 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11205 + * this will talk to both feeds-lists files and installed status files
11208 + * hash_table_t hash;
11209 + * pkg_hash_init(name, &hash, 1000);
11210 + * pkg_hash_add_from_file(<feed filename>);
11212 + * the query function is just there as a shell to prove to me that this
11213 + * sort of works, but isn't far from doing something useful
11216 + * modified: CDW 3 Jan. 2002
11221 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11223 + return hash_table_init(name, hash, len);
11226 +void pkg_hash_deinit(hash_table_t *hash)
11228 + hash_table_deinit(hash);
11232 +/* Find the default arch for a given package status file if none is given. */
11233 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11235 + nv_pair_list_elt_t *l;
11236 + char *def_arch = HOST_CPU_STR; /* Default arch */
11237 + int def_prio = 0; /* Other archs override this */
11239 + l = conf->arch_list.head;
11242 + nv_pair_t *nv = l->data;
11243 + int priority = strtol(nv->value, NULL, 0);
11245 + /* Check if this arch has higher priority, and is valid */
11246 + if ((priority > def_prio) &&
11247 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11248 + /* Our new default */
11249 + def_prio = priority;
11250 + def_arch = nv->name;
11255 + return strdup(def_arch);
11258 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11259 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11261 + hash_table_t *hash = &conf->pkg_hash;
11263 + char **raw_start;
11266 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11270 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11275 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11276 + if (!pkg->architecture) {
11277 + char *version_str = pkg_version_str_alloc(pkg);
11278 + pkg->architecture = pkg_get_default_arch(conf);
11279 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11280 + pkg->name, version_str, pkg->architecture);
11281 + free(version_str);
11283 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11289 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11290 + memory after read_raw_pkgs_from_file */
11299 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11301 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11304 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11306 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11309 + return apkg->provided_by;
11313 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11314 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11317 + int nprovides = 0;
11318 + int nmatching = 0;
11319 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11320 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11321 + abstract_pkg_vec_t *provided_apkg_vec;
11322 + abstract_pkg_t **provided_apkgs;
11323 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11324 + pkg_t *latest_installed_parent = NULL;
11325 + pkg_t *latest_matching = NULL;
11326 + pkg_t *held_pkg = NULL;
11327 + pkg_t *good_pkg_by_name = NULL;
11329 + if (matching_apkgs == NULL || providers == NULL ||
11330 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11333 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11335 + provided_apkg_vec = apkg->provided_by;
11336 + nprovides = provided_apkg_vec->len;
11337 + provided_apkgs = provided_apkg_vec->pkgs;
11338 + if (nprovides > 1)
11339 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11341 + /* accumulate all the providers */
11342 + for (i = 0; i < nprovides; i++) {
11343 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11344 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11345 + abstract_pkg_vec_insert(providers, provider_apkg);
11347 + nprovides = providers->len;
11349 + for (i = 0; i < nprovides; i++) {
11350 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11351 + abstract_pkg_t *replacement_apkg = NULL;
11354 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11355 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11356 + if (provider_apkg->replaced_by->len > 1) {
11357 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11358 + provider_apkg->name, replacement_apkg->name);
11362 + if (replacement_apkg)
11363 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11364 + replacement_apkg->name, provider_apkg->name);
11366 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11367 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11370 + provider_apkg = replacement_apkg;
11373 + if (!(vec = provider_apkg->pkgs)) {
11374 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11379 + /* now check for supported architecture */
11381 + int max_count = 0;
11384 + /* count packages matching max arch priority and keep track of last one */
11385 + for (i = 0; i < vec->len; i++) {
11386 + pkg_t *maybe = vec->pkgs[i];
11387 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d \n",
11388 + maybe->name, maybe->architecture, maybe->arch_priority);
11389 + if (maybe->arch_priority > 0) {
11391 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11392 + pkg_vec_insert(matching_pkgs, maybe);
11398 + if (matching_pkgs->len > 1)
11399 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11400 + if (matching_apkgs->len > 1)
11401 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11403 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11404 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11406 + for (i = 0; i < matching_pkgs->len; i++) {
11407 + pkg_t *matching = matching_pkgs->pkgs[i];
11408 + if (constraint_fcn(matching, cdata)) { /* We found it */
11409 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s \n", matching->name) ;
11410 + good_pkg_by_name = matching;
11415 + for (i = 0; i < matching_pkgs->len; i++) {
11416 + pkg_t *matching = matching_pkgs->pkgs[i];
11417 + latest_matching = matching;
11418 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11419 + latest_installed_parent = matching;
11420 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11422 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11423 + held_pkg->name, matching->name);
11424 + held_pkg = matching;
11428 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11429 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11430 + apkg->name, matching_apkgs->len);
11431 + for (i = 0; i < matching_apkgs->len; i++) {
11432 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11433 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11435 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11438 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11439 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11440 + __FUNCTION__, apkg->name, matching_pkgs->len);
11441 + for (i = 0; i < matching_pkgs->len; i++) {
11442 + pkg_t *matching = matching_pkgs->pkgs[i];
11443 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11444 + matching->name, matching->version, matching->architecture);
11448 + nmatching = matching_apkgs->len;
11450 + pkg_vec_free(matching_pkgs);
11451 + abstract_pkg_vec_free(matching_apkgs);
11452 + abstract_pkg_vec_free(providers);
11454 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11455 + return good_pkg_by_name;
11458 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11461 + if (latest_installed_parent) {
11462 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11463 + return latest_installed_parent;
11465 + if (nmatching > 1) {
11466 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11469 + if (latest_matching) {
11470 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11471 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11472 + return latest_matching;
11477 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11479 + const char *name = (const char *)cdata;
11480 + if (strcmp(pkg->name, name) == 0)
11483 + return 0; /* Pigi */
11486 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11488 + hash_table_t *hash = &conf->pkg_hash;
11489 + abstract_pkg_t *apkg = NULL;
11491 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11494 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11498 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11499 + const char *pkg_name,
11500 + const char * version)
11504 + char *version_str = NULL;
11506 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11509 + for(i = 0; i < vec->len; i++) {
11510 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11511 + if(!strcmp(version_str, version)) {
11512 + free(version_str);
11515 + free(version_str);
11518 + if(i == vec->len)
11521 + return vec->pkgs[i];
11524 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11525 + const char *pkg_name,
11526 + pkg_dest_t *dest)
11531 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11535 + for(i = 0; i < vec->len; i++)
11536 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11537 + return vec->pkgs[i];
11542 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11543 + const char *pkg_name)
11548 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11552 + for(i = 0; i < vec->len; i++)
11553 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11554 + return vec->pkgs[i];
11560 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11562 + abstract_pkg_t * ab_pkg;
11564 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11568 + if (ab_pkg->pkgs) {
11569 + return ab_pkg->pkgs;
11570 + } else if (ab_pkg->provided_by) {
11571 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11572 + if (abpkg != NULL){
11573 + return abpkg->pkgs;
11575 + return ab_pkg->pkgs;
11582 +static int pkg_compare_names(const void *p1, const void *p2)
11584 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11585 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11586 + if (pkg1->name == NULL)
11588 + if (pkg2->name == NULL)
11590 + return(strcmp(pkg1->name, pkg2->name));
11594 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11597 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11598 + pkg_vec_t *all = (pkg_vec_t *)data;
11599 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11601 + for (j = 0; j < pkg_vec->len; j++) {
11602 + pkg_t *pkg = pkg_vec->pkgs[j];
11603 + pkg_vec_insert(all, pkg);
11608 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11610 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11611 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11614 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11616 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11617 + pkg_vec_t *all = (pkg_vec_t *)data;
11618 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11621 + for (j = 0; j < pkg_vec->len; j++) {
11622 + pkg_t *pkg = pkg_vec->pkgs[j];
11623 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11624 + pkg_vec_insert(all, pkg);
11629 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11631 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11632 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11635 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11639 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11640 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11641 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11642 + fprintf(stdout, "%s\n", ab_pkg->name);
11644 + if (dependents != NULL)
11645 + while (dependents [i] != NULL)
11646 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11647 + dependents = ab_pkg->provided_by->pkgs;
11649 + if (dependents != NULL)
11650 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11651 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11652 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11655 + while (i < pkg->depends_count)
11656 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11659 +void pkg_hash_dump(hash_table_t *hash, void *data)
11662 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11663 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11664 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11667 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11669 + abstract_pkg_t * ab_pkg;
11671 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11672 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11677 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11679 + abstract_pkg_t * ab_pkg;
11680 + int arch_priority;
11685 + arch_priority = pkg->arch_priority;
11687 + if (buildDepends(hash, pkg)<0){
11688 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11691 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11693 + if (set_status) {
11694 + if (pkg->state_status == SS_INSTALLED) {
11695 + ab_pkg->state_status = SS_INSTALLED;
11696 + } else if (pkg->state_status == SS_UNPACKED) {
11697 + ab_pkg->state_status = SS_UNPACKED;
11701 + if(!ab_pkg->pkgs)
11702 + ab_pkg->pkgs = pkg_vec_alloc();
11704 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11705 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11706 + pkg->parent = ab_pkg;
11708 + if (buildProvides(hash, ab_pkg, pkg)<0){
11709 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11712 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11713 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11714 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11717 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11718 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11722 + buildDependedUponBy(pkg, ab_pkg);
11727 + * this will assume that we've already determined that
11728 + * the abstract pkg doesn't exist, 'cause we should know these things...
11730 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11732 + abstract_pkg_t * ab_pkg;
11734 + ab_pkg = abstract_pkg_new();
11735 + if (ab_pkg == NULL) { return NULL; }
11737 + ab_pkg->name = strdup(pkg_name);
11738 + hash_table_insert(hash, pkg_name, ab_pkg);
11744 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11746 + hash_table_t *file_hash = &conf->file_hash;
11748 + return hash_table_get(file_hash, file_name);
11751 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11753 + hash_table_t *file_hash = &conf->file_hash;
11754 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11755 + int file_name_len = strlen(file_name);
11757 + if (file_name[file_name_len -1] == '/')
11760 + if (conf->offline_root) {
11761 + int len = strlen(conf->offline_root);
11762 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11763 + file_name += len;
11767 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11768 + hash_table_insert(file_hash, file_name, owning_pkg);
11769 + if (old_owning_pkg) {
11770 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11771 + /* mark this package to have its filelist written */
11772 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11773 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11779 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_hash.h busybox-1.1.1-new/archival/libipkg/pkg_hash.h
11780 --- busybox-1.1.1-old/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11781 +++ busybox-1.1.1-new/archival/libipkg/pkg_hash.h 2006-03-30 00:39:48.000000000 +0200
11783 +/* pkg_hash.h - the itsy package management system
11787 + Copyright (C) 2002 Compaq Computer Corporation
11789 + This program is free software; you can redistribute it and/or
11790 + modify it under the terms of the GNU General Public License as
11791 + published by the Free Software Foundation; either version 2, or (at
11792 + your option) any later version.
11794 + This program is distributed in the hope that it will be useful, but
11795 + WITHOUT ANY WARRANTY; without even the implied warranty of
11796 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11797 + General Public License for more details.
11800 +#ifndef PKG_HASH_H
11801 +#define PKG_HASH_H
11804 +#include "pkg_vec.h"
11805 +#include "hash_table.h"
11808 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11809 +void pkg_hash_deinit(hash_table_t *hash);
11810 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11812 +void pkg_hash_dump(hash_table_t *hash, void *data);
11813 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11815 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11816 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11817 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11819 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11820 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11821 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11822 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11823 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11824 + const char *pkg_name,
11825 + const char * version);
11826 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11827 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11828 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11829 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11830 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11831 + const char *pkg_name);
11832 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11833 + const char *pkg_name,
11834 + pkg_dest_t *dest);
11836 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11837 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11839 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11840 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11844 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_parse.c busybox-1.1.1-new/archival/libipkg/pkg_parse.c
11845 --- busybox-1.1.1-old/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
11846 +++ busybox-1.1.1-new/archival/libipkg/pkg_parse.c 2006-03-30 00:39:48.000000000 +0200
11848 +/* pkg_parse.c - the itsy package management system
11852 + Copyright (C) 2002 Compaq Computer Corporation
11854 + This program is free software; you can redistribute it and/or
11855 + modify it under the terms of the GNU General Public License as
11856 + published by the Free Software Foundation; either version 2, or (at
11857 + your option) any later version.
11859 + This program is distributed in the hope that it will be useful, but
11860 + WITHOUT ANY WARRANTY; without even the implied warranty of
11861 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11862 + General Public License for more details.
11866 +#include <errno.h>
11867 +#include <ctype.h>
11870 +#include "ipkg_utils.h"
11871 +#include "pkg_parse.h"
11873 +int isGenericFieldType(char * type, char * line)
11875 + if(!strncmp(line, type, strlen(type)))
11880 +char * parseGenericFieldType(char * type, char * raw)
11882 + char * field_value = raw + (strlen(type) + 1);
11883 + return trim_alloc(field_value);
11886 +void parseStatus(pkg_t *pkg, char * raw)
11888 + char sw_str[64], sf_str[64], ss_str[64];
11890 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11891 + pkg->state_want = pkg_state_want_from_str(sw_str);
11892 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11893 + pkg->state_status = pkg_state_status_from_str(ss_str);
11896 +char ** parseDependsString(char * raw, int * depends_count)
11898 + char ** depends = NULL;
11899 + int line_count = 0;
11900 + char buff[2048], * dest;
11902 + while(raw && *raw && !isspace(*raw)) {
11906 + if(line_is_blank(raw)){
11907 + *depends_count = line_count;
11910 + while(raw && *raw){
11911 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11913 + while(isspace(*raw)) raw++;
11916 + while((*raw != ',') && *raw)
11917 + *dest++ = *raw++;
11920 + depends[line_count] = trim_alloc(buff);
11921 + if(depends[line_count] ==NULL)
11927 + *depends_count = line_count;
11931 +void parseConffiles(pkg_t * pkg, char * raw)
11933 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11935 + if(!strncmp(raw, "Conffiles:", 10))
11936 + raw += strlen("Conffiles:");
11938 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11939 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11940 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11941 + while (*raw && isspace(*raw)) {
11944 + raw += strlen(file_name);
11945 + while (*raw && isspace(*raw)) {
11948 + raw += strlen(md5sum);
11952 +int parseVersion(pkg_t *pkg, char *raw)
11954 + char *colon, *eepochcolon;
11955 +#ifdef USE_DEBVERSION
11958 + unsigned long epoch;
11961 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11965 + if (strncmp(raw, "Version:", 8) == 0) {
11968 + while (*raw && isspace(*raw)) {
11972 + colon= strchr(raw,':');
11974 + epoch= strtoul(raw,&eepochcolon,10);
11975 + if (colon != eepochcolon) {
11976 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11980 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11984 + pkg->epoch= epoch;
11989 + pkg->revision = "";
11990 + pkg->familiar_revision = "";
11992 + pkg->version= malloc(strlen(raw)+1);
11993 + if ( pkg->version == NULL ) {
11994 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11997 + strcpy(pkg->version, raw);
11999 +#ifdef USE_DEBVERSION
12000 + hyphen= strrchr(pkg->version,'-');
12004 + if (strncmp("fam", hyphen, 3) == 0) {
12005 + pkg->familiar_revision=hyphen+3;
12006 + hyphen= strrchr(pkg->version,'-');
12009 + pkg->revision = hyphen;
12012 + pkg->revision = hyphen;
12018 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12022 + pkg->familiar_revision);
12029 +/* This code is needed to insert in first position the keyword for the aligning bug */
12031 +int alterProvidesLine(char *raw, char *temp)
12036 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12040 + if ( temp == NULL ) {
12041 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12045 + if (strncmp(raw, "Provides:", 9) == 0) {
12048 + while (*raw && isspace(*raw)) {
12052 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12054 + strncat( temp, raw++, 1);
12060 +/* Some random thoughts from Carl:
12062 + This function could be considerably simplified if we just kept
12063 + an array of all the generic string-valued field names, and looped
12064 + through those looking for a match. Also, these fields could perhaps
12065 + be stored in the package as an array as well, (or, probably better,
12066 + as an nv_pair_list_t).
12068 + Fields which require special parsing or storage, (such as Depends:
12069 + and Status:) could be handled as they are now.
12071 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12072 + to a dependency list. And, since we already have
12073 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12074 + Enhances, perhaps we could generalize all of these and save some
12075 + code duplication.
12077 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12079 + int reading_conffiles, reading_description;
12080 + int pkg_false_provides=1;
12082 + char * provide=NULL;
12085 + pkg->dest = dest;
12087 + reading_conffiles = reading_description = 0;
12089 + for (lines = *raw; *lines; lines++) {
12090 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12091 + if(isGenericFieldType("Package:", *lines))
12092 + pkg->name = parseGenericFieldType("Package", *lines);
12093 + else if(isGenericFieldType("Architecture:", *lines))
12094 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12095 + else if(isGenericFieldType("Filename:", *lines))
12096 + pkg->filename = parseGenericFieldType("Filename", *lines);
12097 + else if(isGenericFieldType("Section:", *lines))
12098 + pkg->section = parseGenericFieldType("Section", *lines);
12099 + else if(isGenericFieldType("MD5sum:", *lines))
12100 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12101 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12102 + let's parse it either way */
12103 + else if(isGenericFieldType("MD5Sum:", *lines))
12104 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12105 + else if(isGenericFieldType("Size:", *lines))
12106 + pkg->size = parseGenericFieldType("Size", *lines);
12107 + else if(isGenericFieldType("Source:", *lines))
12108 + pkg->source = parseGenericFieldType("Source", *lines);
12109 + else if(isGenericFieldType("Installed-Size:", *lines))
12110 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12111 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12112 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12113 + pkg->installed_time = strtoul(time_str, NULL, 0);
12114 + } else if(isGenericFieldType("Priority:", *lines))
12115 + pkg->priority = parseGenericFieldType("Priority", *lines);
12116 + else if(isGenericFieldType("Essential:", *lines)) {
12117 + char *essential_value;
12118 + essential_value = parseGenericFieldType("Essential", *lines);
12119 + if (strcmp(essential_value, "yes") == 0) {
12120 + pkg->essential = 1;
12122 + free(essential_value);
12124 + else if(isGenericFieldType("Status", *lines))
12125 + parseStatus(pkg, *lines);
12126 + else if(isGenericFieldType("Version", *lines))
12127 + parseVersion(pkg, *lines);
12128 + else if(isGenericFieldType("Maintainer", *lines))
12129 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12130 + else if(isGenericFieldType("Conffiles", *lines)){
12131 + parseConffiles(pkg, *lines);
12132 + reading_conffiles = 1;
12134 + else if(isGenericFieldType("Description", *lines)) {
12135 + pkg->description = parseGenericFieldType("Description", *lines);
12136 + reading_conffiles = 0;
12137 + reading_description = 1;
12140 + else if(isGenericFieldType("Provides", *lines)){
12141 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12142 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12143 + if ( alterProvidesLine(*lines,provide) ){
12146 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12147 +/* Let's try to hack a bit here.
12148 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12149 + in alot of other places. We will remove it before writing down the status database */
12150 + pkg_false_provides=0;
12154 + else if(isGenericFieldType("Depends", *lines))
12155 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12156 + else if(isGenericFieldType("Pre-Depends", *lines))
12157 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12158 + else if(isGenericFieldType("Recommends", *lines))
12159 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12160 + else if(isGenericFieldType("Suggests", *lines))
12161 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12162 + /* Abhaya: support for conflicts */
12163 + else if(isGenericFieldType("Conflicts", *lines))
12164 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12165 + else if(isGenericFieldType("Replaces", *lines))
12166 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12167 + else if(line_is_blank(*lines)) {
12171 + else if(**lines == ' '){
12172 + if(reading_description) {
12173 + /* we already know it's not blank, so the rest of description */
12174 + pkg->description = realloc(pkg->description,
12175 + strlen(pkg->description)
12176 + + 1 + strlen(*lines) + 1);
12177 + strcat(pkg->description, "\n");
12178 + strcat(pkg->description, (*lines));
12180 + else if(reading_conffiles)
12181 + parseConffiles(pkg, *lines);
12185 +/* If the ipk has not a Provides line, we insert our false line */
12186 + if ( pkg_false_provides==1)
12187 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12196 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12200 + for (lines = *raw; *lines; lines++) {
12201 + if(isGenericFieldType("Essential:", *lines)) {
12202 + char *essential_value;
12203 + essential_value = parseGenericFieldType("Essential", *lines);
12204 + if (strcmp(essential_value, "yes") == 0) {
12205 + pkg->essential = 1;
12207 + free(essential_value);
12214 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_parse.h busybox-1.1.1-new/archival/libipkg/pkg_parse.h
12215 --- busybox-1.1.1-old/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12216 +++ busybox-1.1.1-new/archival/libipkg/pkg_parse.h 2006-03-30 00:39:48.000000000 +0200
12218 +/* pkg_parse.h - the itsy package management system
12222 + Copyright (C) 2002 Compaq Computer Corporation
12224 + This program is free software; you can redistribute it and/or
12225 + modify it under the terms of the GNU General Public License as
12226 + published by the Free Software Foundation; either version 2, or (at
12227 + your option) any later version.
12229 + This program is distributed in the hope that it will be useful, but
12230 + WITHOUT ANY WARRANTY; without even the implied warranty of
12231 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12232 + General Public License for more details.
12235 +#ifndef PKG_PARSE_H
12236 +#define PKG_PARSE_H
12238 +int isGenericFieldType(char * type, char * line);
12239 +char * parseGenericFieldType(char * type, char * raw);
12240 +void parseStatus(pkg_t *pkg, char * raw);
12241 +int parseVersion(pkg_t *pkg, char *raw);
12242 +char ** parseDependsString(char * raw, int * depends_count);
12243 +int parseVersion(pkg_t *pkg, char *raw);
12244 +void parseConffiles(pkg_t * pkg, char * raw);
12245 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12246 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12249 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src.c busybox-1.1.1-new/archival/libipkg/pkg_src.c
12250 --- busybox-1.1.1-old/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12251 +++ busybox-1.1.1-new/archival/libipkg/pkg_src.c 2006-03-30 00:39:48.000000000 +0200
12253 +/* pkg_src.c - the itsy package management system
12257 + Copyright (C) 2001 University of Southern California
12259 + This program is free software; you can redistribute it and/or
12260 + modify it under the terms of the GNU General Public License as
12261 + published by the Free Software Foundation; either version 2, or (at
12262 + your option) any later version.
12264 + This program is distributed in the hope that it will be useful, but
12265 + WITHOUT ANY WARRANTY; without even the implied warranty of
12266 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12267 + General Public License for more details.
12272 +#include "pkg_src.h"
12273 +#include "str_util.h"
12275 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12277 + src->gzip = gzip;
12278 + src->name = str_dup_safe (name);
12279 + src->value = str_dup_safe (base_url);
12281 + src->extra_data = str_dup_safe (extra_data);
12283 + src->extra_data = NULL;
12287 +void pkg_src_deinit(pkg_src_t *src)
12289 + free (src->name);
12290 + free (src->value);
12291 + if (src->extra_data)
12292 + free (src->extra_data);
12296 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src.h busybox-1.1.1-new/archival/libipkg/pkg_src.h
12297 --- busybox-1.1.1-old/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12298 +++ busybox-1.1.1-new/archival/libipkg/pkg_src.h 2006-03-30 00:39:48.000000000 +0200
12300 +/* pkg_src.h - the itsy package management system
12304 + Copyright (C) 2001 University of Southern California
12306 + This program is free software; you can redistribute it and/or
12307 + modify it under the terms of the GNU General Public License as
12308 + published by the Free Software Foundation; either version 2, or (at
12309 + your option) any later version.
12311 + This program is distributed in the hope that it will be useful, but
12312 + WITHOUT ANY WARRANTY; without even the implied warranty of
12313 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12314 + General Public License for more details.
12320 +#include "nv_pair.h"
12326 + char *extra_data;
12330 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12331 +void pkg_src_deinit(pkg_src_t *src);
12334 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src_list.c busybox-1.1.1-new/archival/libipkg/pkg_src_list.c
12335 --- busybox-1.1.1-old/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12336 +++ busybox-1.1.1-new/archival/libipkg/pkg_src_list.c 2006-03-30 00:39:48.000000000 +0200
12338 +/* pkg_src_list.c - the itsy package management system
12342 + Copyright (C) 2001 University of Southern California
12344 + This program is free software; you can redistribute it and/or
12345 + modify it under the terms of the GNU General Public License as
12346 + published by the Free Software Foundation; either version 2, or (at
12347 + your option) any later version.
12349 + This program is distributed in the hope that it will be useful, but
12350 + WITHOUT ANY WARRANTY; without even the implied warranty of
12351 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12352 + General Public License for more details.
12357 +#include "pkg_src_list.h"
12358 +#include "void_list.h"
12360 +int pkg_src_list_init(pkg_src_list_t *list)
12362 + return void_list_init((void_list_t *) list);
12365 +void pkg_src_list_deinit(pkg_src_list_t *list)
12367 + pkg_src_list_elt_t *iter;
12368 + pkg_src_t *pkg_src;
12370 + for (iter = list->head; iter; iter = iter->next) {
12371 + pkg_src = iter->data;
12372 + pkg_src_deinit(pkg_src);
12374 + /* malloced in pkg_src_list_append */
12376 + iter->data = NULL;
12378 + void_list_deinit((void_list_t *) list);
12381 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12382 + const char *name, const char *base_url, const char *extra_data,
12387 + /* freed in pkg_src_list_deinit */
12388 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12390 + if (pkg_src == NULL) {
12391 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12394 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12396 + err = void_list_append((void_list_t *) list, pkg_src);
12404 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12406 + return void_list_push((void_list_t *) list, data);
12409 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12411 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12413 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_src_list.h busybox-1.1.1-new/archival/libipkg/pkg_src_list.h
12414 --- busybox-1.1.1-old/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12415 +++ busybox-1.1.1-new/archival/libipkg/pkg_src_list.h 2006-03-30 00:39:48.000000000 +0200
12417 +/* pkg_src_list.h - the itsy package management system
12421 + Copyright (C) 2001 University of Southern California
12423 + This program is free software; you can redistribute it and/or
12424 + modify it under the terms of the GNU General Public License as
12425 + published by the Free Software Foundation; either version 2, or (at
12426 + your option) any later version.
12428 + This program is distributed in the hope that it will be useful, but
12429 + WITHOUT ANY WARRANTY; without even the implied warranty of
12430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12431 + General Public License for more details.
12434 +#ifndef PKG_SRC_LIST_H
12435 +#define PKG_SRC_LIST_H
12437 +#include "pkg_src.h"
12439 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12440 +struct pkg_src_list_elt
12442 + pkg_src_list_elt_t *next;
12446 +typedef struct pkg_src_list pkg_src_list_t;
12447 +struct pkg_src_list
12449 + pkg_src_list_elt_t pre_head;
12450 + pkg_src_list_elt_t *head;
12451 + pkg_src_list_elt_t *tail;
12454 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12456 + if (list->head == NULL)
12462 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12463 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12465 +int pkg_src_list_init(pkg_src_list_t *list);
12466 +void pkg_src_list_deinit(pkg_src_list_t *list);
12468 +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);
12469 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12470 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12474 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_vec.c busybox-1.1.1-new/archival/libipkg/pkg_vec.c
12475 --- busybox-1.1.1-old/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12476 +++ busybox-1.1.1-new/archival/libipkg/pkg_vec.c 2006-03-30 00:39:48.000000000 +0200
12478 +/* pkg_vec.c - the itsy package management system
12482 + Copyright (C) 2002 Compaq Computer Corporation
12484 + This program is free software; you can redistribute it and/or
12485 + modify it under the terms of the GNU General Public License as
12486 + published by the Free Software Foundation; either version 2, or (at
12487 + your option) any later version.
12489 + This program is distributed in the hope that it will be useful, but
12490 + WITHOUT ANY WARRANTY; without even the implied warranty of
12491 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12492 + General Public License for more details.
12495 +#include <stdlib.h>
12496 +#include <fnmatch.h>
12497 +#include "xregex.h"
12501 +pkg_vec_t * pkg_vec_alloc(void)
12503 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12505 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12508 + vec->pkgs = NULL;
12514 +void pkg_vec_free(pkg_vec_t *vec)
12521 + * assumption: all names in a vector are identical
12522 + * assumption: all version strings are trimmed,
12523 + * so identical versions have identical version strings,
12524 + * implying identical packages; let's marry these
12526 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12531 + /* look for a duplicate pkg by name, version, and architecture */
12532 + for (i = 0; i < vec->len; i++)
12533 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12534 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12535 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12537 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12538 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12542 + /* we didn't find one, add it */
12544 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12545 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12547 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12548 + vec->pkgs[vec->len] = pkg;
12552 + /* update the one that we have */
12554 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12555 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12556 + if (set_status) {
12557 + /* this is from the status file, so need to merge with existing database */
12558 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12559 + pkg_merge(vec->pkgs[i], pkg, set_status);
12560 + /* XXX: CLEANUP: It's not so polite to free something here
12561 + that was passed in from above. */
12565 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12566 + /* just overwrite the old one */
12567 + pkg_deinit(vec->pkgs[i]);
12568 + free(vec->pkgs[i]);
12569 + vec->pkgs[i] = pkg;
12571 + return vec->pkgs[i];
12575 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12580 + /* look for a duplicate pkg by name, version, and architecture */
12581 + for (i = 0; i < vec->len; i++)
12582 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12583 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12584 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12589 + /* we didn't find one, add it */
12591 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12592 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12597 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12600 + for (i = 0; i < vec->len; i++)
12601 + if (vec->pkgs[i] == apkg)
12606 +typedef int (*compare_fcn_t)(const void *, const void *);
12607 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12609 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12612 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12614 + int npkgs = vec->len;
12616 + for (i = 0; i < npkgs; i++) {
12617 + pkg_t *pkg = vec->pkgs[i];
12618 + pkg->state_flag &= ~SF_MARKED;
12623 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12625 + int matching_count = 0;
12626 + pkg_t **pkgs = vec->pkgs;
12627 + int npkgs = vec->len;
12629 + for (i = 0; i < npkgs; i++) {
12630 + pkg_t *pkg = pkgs[i];
12631 + if (fnmatch(pattern, pkg->name, 0)==0) {
12632 + pkg->state_flag |= SF_MARKED;
12633 + matching_count++;
12636 + return matching_count;
12640 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12642 + abstract_pkg_vec_t * vec ;
12643 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12648 + vec->pkgs = NULL;
12654 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12661 + * assumption: all names in a vector are unique
12663 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12667 + /* look for a duplicate pkg by name */
12668 + for(i = 0; i < vec->len; i++)
12669 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12672 + /* we didn't find one, add it */
12673 + if(i == vec->len){
12675 + (abstract_pkg_t **)
12676 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12677 + vec->pkgs[vec->len] = pkg;
12682 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12684 + if (vec->len > i)
12685 + return vec->pkgs[i];
12690 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12693 + for (i = 0; i < vec->len; i++)
12694 + if (vec->pkgs[i] == apkg)
12699 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12701 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12704 diff -ruN busybox-1.1.1-old/archival/libipkg/pkg_vec.h busybox-1.1.1-new/archival/libipkg/pkg_vec.h
12705 --- busybox-1.1.1-old/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12706 +++ busybox-1.1.1-new/archival/libipkg/pkg_vec.h 2006-03-30 00:39:48.000000000 +0200
12708 +/* pkg_vec.h - the itsy package management system
12712 + Copyright (C) 2002 Compaq Computer Corporation
12714 + This program is free software; you can redistribute it and/or
12715 + modify it under the terms of the GNU General Public License as
12716 + published by the Free Software Foundation; either version 2, or (at
12717 + your option) any later version.
12719 + This program is distributed in the hope that it will be useful, but
12720 + WITHOUT ANY WARRANTY; without even the implied warranty of
12721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12722 + General Public License for more details.
12728 +typedef struct pkg pkg_t;
12729 +typedef struct abstract_pkg abstract_pkg_t;
12736 +typedef struct pkg_vec pkg_vec_t;
12738 +struct abstract_pkg_vec
12740 + abstract_pkg_t **pkgs;
12743 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12746 +pkg_vec_t * pkg_vec_alloc(void);
12747 +void pkg_vec_free(pkg_vec_t *vec);
12748 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12750 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12751 +/* pkg_vec_insert_merge: might munge pkg.
12752 +* returns the pkg that is in the pkg graph */
12753 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12754 +/* this one never munges pkg */
12755 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12756 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12757 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12759 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12760 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12762 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12763 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12764 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12765 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12766 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12767 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12770 diff -ruN busybox-1.1.1-old/archival/libipkg/sprintf_alloc.h busybox-1.1.1-new/archival/libipkg/sprintf_alloc.h
12771 --- busybox-1.1.1-old/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12772 +++ busybox-1.1.1-new/archival/libipkg/sprintf_alloc.h 2006-03-31 02:19:07.000000000 +0200
12774 +/* sprintf_alloca.c -- like sprintf with memory allocation
12778 + Copyright (C) 2001 University of Southern California
12780 + This program is free software; you can redistribute it and/or modify
12781 + it under the terms of the GNU General Public License as published by
12782 + the Free Software Foundation; either version 2, or (at your option)
12783 + any later version.
12785 + This program is distributed in the hope that it will be useful,
12786 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12787 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12788 + GNU General Public License for more details.
12791 +#ifndef SPRINTF_ALLOC_H
12792 +#define SPRINTF_ALLOC_H
12794 +#include "libbb.h"
12796 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
12799 diff -ruN busybox-1.1.1-old/archival/libipkg/str_list.c busybox-1.1.1-new/archival/libipkg/str_list.c
12800 --- busybox-1.1.1-old/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12801 +++ busybox-1.1.1-new/archival/libipkg/str_list.c 2006-03-30 00:39:48.000000000 +0200
12803 +/* str_list.c - the itsy package management system
12807 + Copyright (C) 2001 University of Southern California
12809 + This program is free software; you can redistribute it and/or
12810 + modify it under the terms of the GNU General Public License as
12811 + published by the Free Software Foundation; either version 2, or (at
12812 + your option) any later version.
12814 + This program is distributed in the hope that it will be useful, but
12815 + WITHOUT ANY WARRANTY; without even the implied warranty of
12816 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12817 + General Public License for more details.
12822 +#include "str_list.h"
12824 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12826 + return void_list_elt_init((void_list_elt_t *) elt, data);
12829 +void str_list_elt_deinit(str_list_elt_t *elt)
12831 + void_list_elt_deinit((void_list_elt_t *) elt);
12834 +str_list_t *str_list_alloc()
12836 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12838 + str_list_init(list);
12842 +int str_list_init(str_list_t *list)
12844 + return void_list_init((void_list_t *) list);
12847 +void str_list_deinit(str_list_t *list)
12849 + void_list_deinit((void_list_t *) list);
12852 +int str_list_append(str_list_t *list, char *data)
12854 + return void_list_append((void_list_t *) list, data);
12857 +int str_list_push(str_list_t *list, char *data)
12859 + return void_list_push((void_list_t *) list, data);
12862 +str_list_elt_t *str_list_pop(str_list_t *list)
12864 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12867 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12869 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12870 + (void_list_elt_t **) iter);
12873 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12875 + return (char *)void_list_remove_elt((void_list_t *) list,
12876 + (void *)target_str,
12877 + (void_list_cmp_t)strcmp);
12879 diff -ruN busybox-1.1.1-old/archival/libipkg/str_list.h busybox-1.1.1-new/archival/libipkg/str_list.h
12880 --- busybox-1.1.1-old/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
12881 +++ busybox-1.1.1-new/archival/libipkg/str_list.h 2006-03-30 00:39:48.000000000 +0200
12883 +/* str_list.h - the itsy package management system
12887 + Copyright (C) 2001 University of Southern California
12889 + This program is free software; you can redistribute it and/or
12890 + modify it under the terms of the GNU General Public License as
12891 + published by the Free Software Foundation; either version 2, or (at
12892 + your option) any later version.
12894 + This program is distributed in the hope that it will be useful, but
12895 + WITHOUT ANY WARRANTY; without even the implied warranty of
12896 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12897 + General Public License for more details.
12900 +#ifndef STR_LIST_H
12901 +#define STR_LIST_H
12903 +#include "void_list.h"
12905 +typedef struct str_list_elt str_list_elt_t;
12906 +struct str_list_elt
12908 + str_list_elt_t *next;
12912 +typedef struct xstr_list str_list_t;
12915 + str_list_elt_t pre_head;
12916 + str_list_elt_t *head;
12917 + str_list_elt_t *tail;
12920 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12921 +void str_list_elt_deinit(str_list_elt_t *elt);
12923 +str_list_t *str_list_alloc(void);
12924 +int str_list_init(str_list_t *list);
12925 +void str_list_deinit(str_list_t *list);
12927 +int str_list_append(str_list_t *list, char *data);
12928 +int str_list_push(str_list_t *list, char *data);
12929 +str_list_elt_t *str_list_pop(str_list_t *list);
12930 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12931 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12934 diff -ruN busybox-1.1.1-old/archival/libipkg/str_util.c busybox-1.1.1-new/archival/libipkg/str_util.c
12935 --- busybox-1.1.1-old/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
12936 +++ busybox-1.1.1-new/archival/libipkg/str_util.c 2006-03-30 00:39:48.000000000 +0200
12938 +/* str_utils.c - the itsy package management system
12942 + Copyright (C) 2001 University of Southern California
12944 + This program is free software; you can redistribute it and/or
12945 + modify it under the terms of the GNU General Public License as
12946 + published by the Free Software Foundation; either version 2, or (at
12947 + your option) any later version.
12949 + This program is distributed in the hope that it will be useful, but
12950 + WITHOUT ANY WARRANTY; without even the implied warranty of
12951 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12952 + General Public License for more details.
12957 +int str_starts_with(const char *str, const char *prefix)
12959 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12962 +int str_ends_with(const char *str, const char *suffix)
12967 + str_len = strlen(str);
12968 + suffix_len = strlen(suffix);
12970 + if (str_len < suffix_len) {
12974 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12977 +int str_chomp(char *str)
12979 + if (str[strlen(str) - 1] == '\n') {
12980 + str[strlen(str) - 1] = '\0';
12986 +int str_tolower(char *str)
12989 + *str = tolower(*str);
12996 +int str_toupper(char *str)
12999 + *str = toupper(*str);
13006 +char *str_dup_safe(const char *str)
13008 + return str ? strdup(str) : NULL;
13011 diff -ruN busybox-1.1.1-old/archival/libipkg/str_util.h busybox-1.1.1-new/archival/libipkg/str_util.h
13012 --- busybox-1.1.1-old/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13013 +++ busybox-1.1.1-new/archival/libipkg/str_util.h 2006-03-30 00:39:48.000000000 +0200
13015 +/* str_utils.h - the itsy package management system
13019 + Copyright (C) 2001 University of Southern California
13021 + This program is free software; you can redistribute it and/or
13022 + modify it under the terms of the GNU General Public License as
13023 + published by the Free Software Foundation; either version 2, or (at
13024 + your option) any later version.
13026 + This program is distributed in the hope that it will be useful, but
13027 + WITHOUT ANY WARRANTY; without even the implied warranty of
13028 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13029 + General Public License for more details.
13032 +#ifndef STR_UTILS_H
13033 +#define STR_UTILS_H
13035 +int str_starts_with(const char *str, const char *prefix);
13036 +int str_ends_with(const char *str, const char *suffix);
13037 +int str_chomp(char *str);
13038 +int str_tolower(char *str);
13039 +int str_toupper(char *str);
13040 +char *str_dup_safe(const char *str);
13043 diff -ruN busybox-1.1.1-old/archival/libipkg/user.c busybox-1.1.1-new/archival/libipkg/user.c
13044 --- busybox-1.1.1-old/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13045 +++ busybox-1.1.1-new/archival/libipkg/user.c 2006-03-30 00:39:48.000000000 +0200
13047 +/* user.c - the itsy package management system
13051 + Copyright (C) 2002 Hewlett Packard Company
13052 + Copyright (C) 2001 University of Southern California
13054 + This program is free software; you can redistribute it and/or
13055 + modify it under the terms of the GNU General Public License as
13056 + published by the Free Software Foundation; either version 2, or (at
13057 + your option) any later version.
13059 + This program is distributed in the hope that it will be useful, but
13060 + WITHOUT ANY WARRANTY; without even the implied warranty of
13061 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13062 + General Public License for more details.
13065 +#include <stdio.h>
13066 +#include <stdarg.h>
13067 +#include "file_util.h"
13068 +#include "str_util.h"
13070 +#include "libipkg.h"
13075 +static char *question = NULL;
13076 +static int question_len = 255;
13078 +char *get_user_response(const char *format, ...)
13080 + int len = question_len;
13083 + va_start(ap, format);
13086 + vprintf(format, ap);
13088 + response = file_read_line_alloc(stdin);
13089 + } while (response == NULL);
13092 + if (question == NULL || len > question_len) {
13093 + question = realloc(question, len + 1);
13094 + question_len = len;
13096 + len = vsnprintf(question,question_len,format,ap);
13097 + } while (len > question_len);
13098 + response = strdup(ipkg_cb_response(question));
13100 + str_chomp(response);
13101 + str_tolower(response);
13105 diff -ruN busybox-1.1.1-old/archival/libipkg/user.h busybox-1.1.1-new/archival/libipkg/user.h
13106 --- busybox-1.1.1-old/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13107 +++ busybox-1.1.1-new/archival/libipkg/user.h 2006-03-30 00:39:48.000000000 +0200
13109 +/* user.c - the itsy package management system
13113 + Copyright (C) 2002 Hewlett Packard Company
13114 + Copyright (C) 2001 University of Southern California
13116 + This program is free software; you can redistribute it and/or
13117 + modify it under the terms of the GNU General Public License as
13118 + published by the Free Software Foundation; either version 2, or (at
13119 + your option) any later version.
13121 + This program is distributed in the hope that it will be useful, but
13122 + WITHOUT ANY WARRANTY; without even the implied warranty of
13123 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13124 + General Public License for more details.
13127 +#include <stdio.h>
13128 +#include <stdarg.h>
13130 +char *get_user_response(const char *format, ...);
13132 diff -ruN busybox-1.1.1-old/archival/libipkg/void_list.c busybox-1.1.1-new/archival/libipkg/void_list.c
13133 --- busybox-1.1.1-old/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13134 +++ busybox-1.1.1-new/archival/libipkg/void_list.c 2006-03-30 00:39:48.000000000 +0200
13136 +/* void_list.c - the itsy package management system
13140 + Copyright (C) 2001 University of Southern California
13142 + This program is free software; you can redistribute it and/or
13143 + modify it under the terms of the GNU General Public License as
13144 + published by the Free Software Foundation; either version 2, or (at
13145 + your option) any later version.
13147 + This program is distributed in the hope that it will be useful, but
13148 + WITHOUT ANY WARRANTY; without even the implied warranty of
13149 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13150 + General Public License for more details.
13154 +#include <errno.h>
13156 +#include "void_list.h"
13158 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13160 + elt->next = NULL;
13161 + elt->data = data;
13166 +void void_list_elt_deinit(void_list_elt_t *elt)
13168 + void_list_elt_init(elt, NULL);
13171 +int void_list_init(void_list_t *list)
13173 + void_list_elt_init(&list->pre_head, NULL);
13174 + list->head = NULL;
13175 + list->pre_head.next = list->head;
13176 + list->tail = NULL;
13181 +void void_list_deinit(void_list_t *list)
13183 + void_list_elt_t *elt;
13185 + while (list->head) {
13186 + elt = void_list_pop(list);
13187 + void_list_elt_deinit(elt);
13188 + /* malloced in void_list_append */
13193 +int void_list_append(void_list_t *list, void *data)
13195 + void_list_elt_t *elt;
13197 + /* freed in void_list_deinit */
13198 + elt = malloc(sizeof(void_list_elt_t));
13199 + if (elt == NULL) {
13200 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13204 + void_list_elt_init(elt, data);
13206 + if (list->tail) {
13207 + list->tail->next = elt;
13208 + list->tail = elt;
13210 + list->head = elt;
13211 + list->pre_head.next = list->head;
13212 + list->tail = elt;
13218 +int void_list_push(void_list_t *list, void *data)
13220 + void_list_elt_t *elt;
13222 + elt = malloc(sizeof(void_list_elt_t));
13223 + if (elt == NULL) {
13224 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13228 + void_list_elt_init(elt, data);
13230 + elt->next = list->head;
13231 + list->head->next = elt;
13232 + if (list->tail == NULL) {
13233 + list->tail = list->head;
13239 +void_list_elt_t *void_list_pop(void_list_t *list)
13241 + void_list_elt_t *elt;
13243 + elt = list->head;
13245 + if (list->head) {
13246 + list->head = list->head->next;
13247 + list->pre_head.next = list->head;
13248 + if (list->head == NULL) {
13249 + list->tail = NULL;
13256 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13258 + void_list_elt_t *prior;
13259 + void_list_elt_t *old_elt;
13263 + old_data = old_elt->data;
13265 + if (old_elt == list->head) {
13266 + prior = &list->pre_head;
13267 + void_list_pop(list);
13269 + for (prior = list->head; prior; prior = prior->next) {
13270 + if (prior->next == old_elt) {
13274 + if (prior == NULL || prior->next != old_elt) {
13275 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13278 + prior->next = old_elt->next;
13280 + if (old_elt == list->tail) {
13281 + list->tail = prior;
13285 + void_list_elt_deinit(old_elt);
13291 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13292 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13294 + void_list_elt_t *prior;
13295 + void_list_elt_t *old_elt = NULL;
13296 + void *old_data = NULL;
13298 + /* first element */
13299 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13300 + old_elt = list->head;
13301 + old_data = list->head->data;
13302 + void_list_pop(list);
13305 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13306 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13307 + old_elt = prior->next;
13308 + old_data = old_elt->data;
13316 + prior->next = old_elt->next;
13318 + if (old_elt == list->tail) {
13319 + list->tail = prior;
13323 + void_list_elt_deinit(old_elt);
13330 diff -ruN busybox-1.1.1-old/archival/libipkg/void_list.h busybox-1.1.1-new/archival/libipkg/void_list.h
13331 --- busybox-1.1.1-old/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13332 +++ busybox-1.1.1-new/archival/libipkg/void_list.h 2006-03-30 00:39:48.000000000 +0200
13334 +/* void_list.h - the itsy package management system
13338 + Copyright (C) 2001 University of Southern California
13340 + This program is free software; you can redistribute it and/or
13341 + modify it under the terms of the GNU General Public License as
13342 + published by the Free Software Foundation; either version 2, or (at
13343 + your option) any later version.
13345 + This program is distributed in the hope that it will be useful, but
13346 + WITHOUT ANY WARRANTY; without even the implied warranty of
13347 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13348 + General Public License for more details.
13351 +#ifndef VOID_LIST_H
13352 +#define VOID_LIST_H
13354 +typedef struct void_list_elt void_list_elt_t;
13355 +struct void_list_elt
13357 + void_list_elt_t *next;
13361 +typedef struct void_list void_list_t;
13364 + void_list_elt_t pre_head;
13365 + void_list_elt_t *head;
13366 + void_list_elt_t *tail;
13369 +static inline int void_list_empty(void_list_t *list)
13371 + if (list->head == NULL)
13377 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13378 +void void_list_elt_deinit(void_list_elt_t *elt);
13380 +int void_list_init(void_list_t *list);
13381 +void void_list_deinit(void_list_t *list);
13383 +int void_list_append(void_list_t *list, void *data);
13384 +int void_list_push(void_list_t *list, void *data);
13385 +void_list_elt_t *void_list_pop(void_list_t *list);
13387 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13388 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13389 +typedef int (*void_list_cmp_t)(const void *, const void *);
13390 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13393 diff -ruN busybox-1.1.1-old/archival/libipkg/xsystem.c busybox-1.1.1-new/archival/libipkg/xsystem.c
13394 --- busybox-1.1.1-old/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13395 +++ busybox-1.1.1-new/archival/libipkg/xsystem.c 2006-03-30 00:39:48.000000000 +0200
13397 +/* xsystem.c - system(3) with error messages
13401 + Copyright (C) 2001 University of Southern California
13403 + This program is free software; you can redistribute it and/or
13404 + modify it under the terms of the GNU General Public License as
13405 + published by the Free Software Foundation; either version 2, or (at
13406 + your option) any later version.
13408 + This program is distributed in the hope that it will be useful, but
13409 + WITHOUT ANY WARRANTY; without even the implied warranty of
13410 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13411 + General Public License for more details.
13415 +#include <sys/wait.h>
13417 +#include "xsystem.h"
13419 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13420 + really need the /bin/sh invocation which takes resources and
13421 + introduces security problems. I should switch all of this to a sort
13422 + of execl() or execv() interface/implementation.
13425 +/* Like system(3), but with error messages printed if the fork fails
13426 + or if the child process dies due to an uncaught signal. Also, the
13427 + return value is a bit simpler:
13429 + -1 if there was any problem
13430 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13431 + as defined in <sys/wait.h>.
13433 +int xsystem(const char *cmd)
13437 + err = system(cmd);
13440 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13441 + __FUNCTION__, cmd);
13445 + if (WIFSIGNALED(err)) {
13446 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13447 + __FUNCTION__, WTERMSIG(err), cmd);
13451 + if (WIFEXITED(err)) {
13452 + /* Normal child exit */
13453 + return WEXITSTATUS(err);
13456 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13457 + __FUNCTION__, err);
13461 diff -ruN busybox-1.1.1-old/archival/libipkg/xsystem.h busybox-1.1.1-new/archival/libipkg/xsystem.h
13462 --- busybox-1.1.1-old/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13463 +++ busybox-1.1.1-new/archival/libipkg/xsystem.h 2006-03-30 00:39:48.000000000 +0200
13465 +/* xsystem.h - system(3) with error messages
13469 + Copyright (C) 2001 University of Southern California
13471 + This program is free software; you can redistribute it and/or
13472 + modify it under the terms of the GNU General Public License as
13473 + published by the Free Software Foundation; either version 2, or (at
13474 + your option) any later version.
13476 + This program is distributed in the hope that it will be useful, but
13477 + WITHOUT ANY WARRANTY; without even the implied warranty of
13478 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13479 + General Public License for more details.
13485 +#include <stdlib.h>
13487 +/* Like system(3), but with error messages printed if the fork fails
13488 + or if the child process dies due to an uncaught signal. Also, the
13489 + return value is a bit simpler:
13491 + -1 if there was any problem
13492 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13493 + as defined in <sys/wait.h>.
13495 +int xsystem(const char *cmd);
13499 diff -ruN busybox-1.1.1-old/archival/libunarchive/Makefile.in busybox-1.1.1-new/archival/libunarchive/Makefile.in
13500 --- busybox-1.1.1-old/archival/libunarchive/Makefile.in 2006-03-22 22:16:20.000000000 +0100
13501 +++ busybox-1.1.1-new/archival/libunarchive/Makefile.in 2006-03-30 00:56:59.000000000 +0200
13503 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13504 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13505 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13506 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13507 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13508 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13509 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13510 diff -ruN busybox-1.1.1-old/archival/libunarchive/data_extract_all.c busybox-1.1.1-new/archival/libunarchive/data_extract_all.c
13511 --- busybox-1.1.1-old/archival/libunarchive/data_extract_all.c 2006-03-22 22:16:20.000000000 +0100
13512 +++ busybox-1.1.1-new/archival/libunarchive/data_extract_all.c 2006-03-30 00:39:48.000000000 +0200
13513 @@ -126,3 +126,17 @@
13514 utime(file_header->name, &t);
13518 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13520 + char *name_ptr = archive_handle->file_header->name;
13522 + name_ptr += strspn(name_ptr, "./");
13523 + if (name_ptr[0] != '\0') {
13524 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13525 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13526 + strcat(archive_handle->file_header->name, name_ptr);
13527 + data_extract_all(archive_handle);
13531 diff -ruN busybox-1.1.1-old/include/applets.h busybox-1.1.1-new/include/applets.h
13532 --- busybox-1.1.1-old/include/applets.h 2006-03-22 22:16:24.000000000 +0100
13533 +++ busybox-1.1.1-new/include/applets.h 2006-03-30 00:42:08.000000000 +0200
13534 @@ -149,6 +149,7 @@
13535 USE_IPCALC(APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13536 USE_IPCRM(APPLET(ipcrm, ipcrm_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13537 USE_IPCS(APPLET(ipcs, ipcs_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13538 +USE_IPKG(APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13539 USE_IPLINK(APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13540 USE_IPROUTE(APPLET(iproute, iproute_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13541 USE_IPTUNNEL(APPLET(iptunnel, iptunnel_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13542 diff -ruN busybox-1.1.1-old/include/unarchive.h busybox-1.1.1-new/include/unarchive.h
13543 --- busybox-1.1.1-old/include/unarchive.h 2006-03-22 22:16:24.000000000 +0100
13544 +++ busybox-1.1.1-new/include/unarchive.h 2006-03-30 00:39:48.000000000 +0200
13547 extern void data_skip(archive_handle_t *archive_handle);
13548 extern void data_extract_all(archive_handle_t *archive_handle);
13549 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13550 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13551 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13553 diff -ruN busybox-1.1.1-old/include/usage.h busybox-1.1.1-new/include/usage.h
13554 --- busybox-1.1.1-old/include/usage.h 2006-03-22 22:16:24.000000000 +0100
13555 +++ busybox-1.1.1-new/include/usage.h 2006-03-30 00:42:53.000000000 +0200
13556 @@ -1013,6 +1013,82 @@
13557 "$ ls -la /tmp/busybox*\n" \
13558 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13560 +#define ipkg_trivial_usage \
13561 + "[options]... sub-command [arguments]..."
13562 +#define ipkg_full_usage \
13563 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13565 + "Sub-commands:\n" \
13566 + "\nPackage Manipulation:\n" \
13567 + "\tupdate Update list of available packages\n" \
13568 + "\tupgrade Upgrade all installed packages to latest version\n" \
13569 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13570 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13571 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13572 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13573 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13574 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13576 + "Informational Commands:\n" \
13577 + "\tlist List available packages and descriptions\n" \
13578 + "\tlist_installed List all and only the installed packages and description \n" \
13579 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13580 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13581 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13582 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13583 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13584 + "\tcompare_versions <v1> <op> <v2>\n" \
13585 + "\t compare versions using <= < > >= = << >>\n" \
13586 + "\tprint_architecture prints the architecture.\n" \
13587 + "\tprint_installation_architecture\n" \
13588 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13589 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13590 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13591 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13592 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13593 + "\t prints the installation architecture.\n" \
13596 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13597 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13598 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13599 + "\t 0 errors only\n" \
13600 + "\t 1 normal messages (default)\n" \
13601 + "\t 2 informative messages\n" \
13602 + "\t 3 debug output\n" \
13603 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13604 + "\t-conf <conf_file> Default configuration file location\n" \
13605 + " is /etc/ipkg.conf\n" \
13606 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13607 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13608 + " <dest_name> should be a defined dest name from\n" \
13609 + " the configuration file, (but can also be a\n" \
13610 + " directory name in a pinch).\n" \
13611 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13612 + "\t-offline <offline_root> offline installation of packages.\n" \
13613 + "\t-verbose_wget more wget messages\n" \
13615 + "Force Options (use when ipkg is too smart for its own good):\n" \
13616 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13617 + "\t Install/remove package in spite of failed dependences\n" \
13618 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13619 + " (no prompts). Note that this will not prevent\n" \
13620 + " package installation scripts from prompting.\n" \
13621 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13622 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13623 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13624 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13625 + "\t-noaction No action -- test only\n" \
13626 + "\t-nodeps Do not follow dependences\n" \
13627 + "\t-force-removal-of-dependent-packages\n" \
13628 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13629 + "\t-test No action -- test only\n" \
13630 + "\t-t Specify tmp-dir.\n" \
13631 + "\t--tmp-dir Specify tmp-dir.\n" \
13633 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13634 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13636 #define halt_trivial_usage \
13637 "[-d<delay>] [-n<nosync>] [-f<force>]"
13638 #define halt_full_usage \