1 diff -ruN busybox-1.00-orig/Makefile busybox-1.00+ipkg-0.99.154/Makefile
2 --- busybox-1.00-orig/Makefile 2004-10-08 09:45:08.000000000 +0200
3 +++ busybox-1.00+ipkg-0.99.154/Makefile 2005-10-26 17:36:45.000000000 +0200
6 include $(top_builddir)/Rules.mak
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 libpwdgrp coreutils/libcoreutils libbb
13 diff -ruN busybox-1.00-orig/archival/Config.in busybox-1.00+ipkg-0.99.154/archival/Config.in
14 --- busybox-1.00-orig/archival/Config.in 2004-03-15 09:28:16.000000000 +0100
15 +++ busybox-1.00+ipkg-0.99.154/archival/Config.in 2005-10-26 17:36:45.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.00-orig/archival/Makefile.in busybox-1.00+ipkg-0.99.154/archival/Makefile.in
32 --- busybox-1.00-orig/archival/Makefile.in 2004-10-08 09:45:09.000000000 +0200
33 +++ busybox-1.00+ipkg-0.99.154/archival/Makefile.in 2005-10-26 17:36:45.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.00-orig/archival/dpkg.c busybox-1.00+ipkg-0.99.154/archival/dpkg.c
43 --- busybox-1.00-orig/archival/dpkg.c 2004-04-14 19:51:08.000000000 +0200
44 +++ busybox-1.00+ipkg-0.99.154/archival/dpkg.c 2005-10-26 17:36:45.000000000 +0200
45 @@ -1527,6 +1527,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.00-orig/archival/ipkg.c busybox-1.00+ipkg-0.99.154/archival/ipkg.c
66 --- busybox-1.00-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
67 +++ busybox-1.00+ipkg-0.99.154/archival/ipkg.c 2005-10-26 17:36:45.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.00-orig/archival/libipkg/Makefile busybox-1.00+ipkg-0.99.154/archival/libipkg/Makefile
96 --- busybox-1.00-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
97 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/Makefile 2005-10-26 17:36:45.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.00-orig/archival/libipkg/Makefile.in busybox-1.00+ipkg-0.99.154/archival/libipkg/Makefile.in
132 --- busybox-1.00-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
133 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/Makefile.in 2005-10-26 17:36:45.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 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
212 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
215 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
216 + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(ARCH)\"" -c -o $@ $<
218 diff -ruN busybox-1.00-orig/archival/libipkg/args.c busybox-1.00+ipkg-0.99.154/archival/libipkg/args.c
219 --- busybox-1.00-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
220 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/args.c 2005-10-26 17:36:45.000000000 +0200
222 +/* args.c - parse command-line args
226 + Copyright 2001 University of Southern California
228 + This program is free software; you can redistribute it and/or modify
229 + it under the terms of the GNU General Public License as published by
230 + the Free Software Foundation; either version 2, or (at your option)
233 + This program is distributed in the hope that it will be useful,
234 + but WITHOUT ANY WARRANTY; without even the implied warranty of
235 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236 + GNU General Public License for more details.
245 +#include "ipkg_message.h"
248 +#include "sprintf_alloc.h"
253 +static void print_version(void);
257 + ARGS_OPT_FORCE_DEFAULTS = 129,
258 + ARGS_OPT_FORCE_DEPENDS,
259 + ARGS_OPT_FORCE_OVERWRITE,
260 + ARGS_OPT_FORCE_DOWNGRADE,
261 + ARGS_OPT_FORCE_REINSTALL,
262 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
263 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
264 + ARGS_OPT_FORCE_SPACE,
267 + ARGS_OPT_VERBOSE_WGET,
268 + ARGS_OPT_VERBOSITY,
269 + ARGS_OPT_MULTIPLE_PROVIDERS
272 +int args_init(args_t *args)
274 + char *conf_file_dir;
276 + memset(args, 0, sizeof(args_t));
278 + args->dest = ARGS_DEFAULT_DEST;
280 + conf_file_dir = getenv("IPKG_CONF_DIR");
281 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
282 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
284 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
285 + ARGS_DEFAULT_CONF_FILE_NAME);
287 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
288 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
289 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
290 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
291 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
292 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
293 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
294 + args->noaction = ARGS_DEFAULT_NOACTION;
295 + args->nodeps = ARGS_DEFAULT_NODEPS;
296 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
297 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
298 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
299 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
300 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
301 + args->multiple_providers = 0;
302 + args->nocheckfordirorfile = 0;
307 +void args_deinit(args_t *args)
309 + free(args->conf_file);
310 + args->conf_file = NULL;
313 +int args_parse(args_t *args, int argc, char *argv[])
316 + int option_index = 0;
318 + static struct option long_options[] = {
319 + {"query-all", 0, 0, 'A'},
320 + {"conf-file", 1, 0, 'f'},
321 + {"conf", 1, 0, 'f'},
322 + {"dest", 1, 0, 'd'},
323 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
324 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
325 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
326 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
327 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
328 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
329 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
330 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
331 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
332 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
333 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
334 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
335 + {"recursive", 0, 0,
336 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
337 + {"force-removal-of-dependent-packages", 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-essential-packages", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
343 + {"force_removal_of_essential_packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
345 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
346 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
347 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
348 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
349 + {"offline", 1, 0, 'o'},
350 + {"offline-root", 1, 0, 'o'},
351 + {"test", 0, 0, ARGS_OPT_NOACTION},
352 + {"tmp-dir", 1, 0, 't'},
353 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
354 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
355 + {"verbosity", 2, 0, 'V'},
356 + {"version", 0, 0, 'v'},
361 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
367 + args->query_all = 1;
370 + args->dest = optarg;
373 + free(args->conf_file);
374 + args->conf_file = strdup(optarg);
377 + args->offline_root = optarg;
380 + args->noaction = 1;
383 + args->tmp_dir = strdup(optarg);
389 + case ARGS_OPT_VERBOSITY:
391 + args->verbosity = atoi(optarg);
393 + args->verbosity += 1;
395 + case ARGS_OPT_FORCE_DEFAULTS:
396 + args->force_defaults = 1;
398 + case ARGS_OPT_FORCE_DEPENDS:
399 + args->force_depends = 1;
401 + case ARGS_OPT_FORCE_OVERWRITE:
402 + args->force_overwrite = 1;
404 + case ARGS_OPT_FORCE_DOWNGRADE:
405 + args->force_downgrade = 1;
407 + case ARGS_OPT_FORCE_REINSTALL:
408 + args->force_reinstall = 1;
410 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
411 + args->force_removal_of_essential_packages = 1;
413 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
414 + args->force_removal_of_dependent_packages = 1;
416 + case ARGS_OPT_FORCE_SPACE:
417 + args->force_space = 1;
419 + case ARGS_OPT_VERBOSE_WGET:
420 + args->verbose_wget = 1;
422 + case ARGS_OPT_MULTIPLE_PROVIDERS:
423 + args->multiple_providers = 1;
425 + case ARGS_OPT_NODEPS:
428 + case ARGS_OPT_NOACTION:
429 + args->noaction = 1;
438 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
449 +void args_usage(char *complaint)
452 + bb_error_msg("%s\n", complaint);
459 +static void print_version(void)
461 + bb_error_msg("version %s\n", IPKG_VERSION);
463 diff -ruN busybox-1.00-orig/archival/libipkg/args.h busybox-1.00+ipkg-0.99.154/archival/libipkg/args.h
464 --- busybox-1.00-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
465 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/args.h 2005-10-26 17:36:45.000000000 +0200
467 +/* args.h - parse command-line args
471 + Copyright 2001 University of Southern California
473 + This program is free software; you can redistribute it and/or modify
474 + it under the terms of the GNU General Public License as published by
475 + the Free Software Foundation; either version 2, or (at your option)
478 + This program is distributed in the hope that it will be useful,
479 + but WITHOUT ANY WARRANTY; without even the implied warranty of
480 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
481 + GNU General Public License for more details.
492 + int force_defaults;
494 + int force_overwrite;
495 + int force_downgrade;
496 + int force_reinstall;
497 + int force_removal_of_essential_packages;
498 + int force_removal_of_dependent_packages;
502 + int multiple_providers;
506 + int nocheckfordirorfile;
507 + char *offline_root;
508 + char *offline_root_pre_script_cmd;
509 + char *offline_root_post_script_cmd;
511 +typedef struct args args_t;
513 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
514 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
515 +#define ARGS_DEFAULT_DEST NULL
516 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
517 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
518 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
519 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
520 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
521 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
522 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
523 +#define ARGS_DEFAULT_FORCE_SPACE 0
524 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
525 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
526 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
527 +#define ARGS_DEFAULT_NOACTION 0
528 +#define ARGS_DEFAULT_NODEPS 0
529 +#define ARGS_DEFAULT_VERBOSE_WGET 0
530 +#define ARGS_DEFAULT_VERBOSITY 1
532 +int args_init(args_t *args);
533 +void args_deinit(args_t *args);
534 +int args_parse(args_t *args, int argc, char *argv[]);
535 +void args_usage(char *complaint);
538 diff -ruN busybox-1.00-orig/archival/libipkg/conffile.c busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile.c
539 --- busybox-1.00-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
540 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile.c 2005-10-26 17:36:45.000000000 +0200
542 +/* conffile.c - the itsy package management system
546 + Copyright (C) 2001 University of Southern California
548 + This program is free software; you can redistribute it and/or
549 + modify it under the terms of the GNU General Public License as
550 + published by the Free Software Foundation; either version 2, or (at
551 + your option) any later version.
553 + This program is distributed in the hope that it will be useful, but
554 + WITHOUT ANY WARRANTY; without even the implied warranty of
555 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
556 + General Public License for more details.
563 +#include "ipkg_message.h"
565 +#include "conffile.h"
566 +#include "file_util.h"
567 +#include "sprintf_alloc.h"
569 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
571 + return nv_pair_init(conffile, file_name, md5sum);
574 +void conffile_deinit(conffile_t *conffile)
576 + nv_pair_deinit(conffile);
579 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
582 + char *filename = conffile->name;
583 + char *root_filename;
586 + if (conffile->value == NULL) {
587 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
591 + root_filename = root_filename_alloc(conf, filename);
593 + md5sum = file_md5sum_alloc(root_filename);
595 + ret = strcmp(md5sum, conffile->value);
597 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
598 + conffile->name, md5sum, conffile->value);
601 + free(root_filename);
606 diff -ruN busybox-1.00-orig/archival/libipkg/conffile.h busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile.h
607 --- busybox-1.00-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
608 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile.h 2005-10-26 17:36:45.000000000 +0200
610 +/* conffile.h - the itsy package management system
614 + Copyright (C) 2001 University of Southern California
616 + This program is free software; you can redistribute it and/or
617 + modify it under the terms of the GNU General Public License as
618 + published by the Free Software Foundation; either version 2, or (at
619 + your option) any later version.
621 + This program is distributed in the hope that it will be useful, but
622 + WITHOUT ANY WARRANTY; without even the implied warranty of
623 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
624 + General Public License for more details.
630 +#include "nv_pair.h"
632 +typedef struct nv_pair conffile_t;
634 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
635 +void conffile_deinit(conffile_t *conffile);
636 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
640 diff -ruN busybox-1.00-orig/archival/libipkg/conffile_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile_list.c
641 --- busybox-1.00-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
642 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile_list.c 2005-10-26 17:36:45.000000000 +0200
644 +/* conffile_list.c - the itsy package management system
648 + Copyright (C) 2001 University of Southern California
650 + This program is free software; you can redistribute it and/or
651 + modify it under the terms of the GNU General Public License as
652 + published by the Free Software Foundation; either version 2, or (at
653 + your option) any later version.
655 + This program is distributed in the hope that it will be useful, but
656 + WITHOUT ANY WARRANTY; without even the implied warranty of
657 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
658 + General Public License for more details.
663 +#include "conffile_list.h"
665 +int conffile_list_init(conffile_list_t *list)
667 + return nv_pair_list_init(list);
670 +void conffile_list_deinit(conffile_list_t *list)
672 + nv_pair_list_deinit(list);
675 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
676 + const char *md5sum)
678 + return nv_pair_list_append(list, file_name, md5sum);
681 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
683 + return nv_pair_list_push(list, data);
686 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
688 + return nv_pair_list_pop(list);
691 diff -ruN busybox-1.00-orig/archival/libipkg/conffile_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile_list.h
692 --- busybox-1.00-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
693 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/conffile_list.h 2005-10-26 17:36:45.000000000 +0200
695 +/* conffile_list.h - the itsy package management system
699 + Copyright (C) 2001 University of Southern California
701 + This program is free software; you can redistribute it and/or
702 + modify it under the terms of the GNU General Public License as
703 + published by the Free Software Foundation; either version 2, or (at
704 + your option) any later version.
706 + This program is distributed in the hope that it will be useful, but
707 + WITHOUT ANY WARRANTY; without even the implied warranty of
708 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
709 + General Public License for more details.
712 +#ifndef CONFFILE_LIST_H
713 +#define CONFFILE_LIST_H
715 +#include "conffile.h"
716 +#include "nv_pair_list.h"
718 +typedef struct nv_pair_list_elt conffile_list_elt_t;
719 +typedef struct nv_pair_list conffile_list_t;
721 +int conffile_list_init(conffile_list_t *list);
722 +void conffile_list_deinit(conffile_list_t *list);
724 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
725 + const char *root_dir);
726 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
727 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
731 diff -ruN busybox-1.00-orig/archival/libipkg/file_util.c busybox-1.00+ipkg-0.99.154/archival/libipkg/file_util.c
732 --- busybox-1.00-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
733 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/file_util.c 2005-10-26 17:36:45.000000000 +0200
735 +/* file_util.c - convenience routines for common stat operations
739 + Copyright (C) 2001 University of Southern California
741 + This program is free software; you can redistribute it and/or
742 + modify it under the terms of the GNU General Public License as
743 + published by the Free Software Foundation; either version 2, or (at
744 + your option) any later version.
746 + This program is distributed in the hope that it will be useful, but
747 + WITHOUT ANY WARRANTY; without even the implied warranty of
748 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
749 + General Public License for more details.
753 +#include <sys/types.h>
754 +#include <sys/stat.h>
756 +#include "sprintf_alloc.h"
757 +#include "file_util.h"
762 +int file_exists(const char *file_name)
765 + struct stat stat_buf;
767 + err = stat(file_name, &stat_buf);
775 +int file_is_dir(const char *file_name)
778 + struct stat stat_buf;
780 + err = stat(file_name, &stat_buf);
785 + return S_ISDIR(stat_buf.st_mode);
788 +/* read a single line from a file, stopping at a newline or EOF.
789 + If a newline is read, it will appear in the resulting string.
790 + Return value is a malloc'ed char * which should be freed at
791 + some point by the caller.
793 + Return value is NULL if the file is at EOF when called.
795 +#define FILE_READ_LINE_BUF_SIZE 1024
796 +char *file_read_line_alloc(FILE *file)
798 + char buf[FILE_READ_LINE_BUF_SIZE];
803 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
804 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
805 + buf_len = strlen(buf);
807 + line_size += buf_len;
808 + line = realloc(line, line_size);
809 + if (line == NULL) {
810 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
815 + line_size = buf_len + 1;
816 + line = strdup(buf);
818 + if (buf[buf_len - 1] == '\n') {
826 +int file_move(const char *src, const char *dest)
830 + err = rename(src, dest);
832 + if (err && errno == EXDEV) {
833 + err = file_copy(src, dest);
836 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
837 + __FUNCTION__, src, dest, strerror(errno));
843 +/* I put these here to keep libbb dependencies from creeping all over
845 +int file_copy(const char *src, const char *dest)
849 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
851 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
852 + __FUNCTION__, src, dest);
858 +int file_mkdir_hier(const char *path, long mode)
860 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
863 +char *file_md5sum_alloc(const char *file_name)
865 + static const int md5sum_bin_len = 16;
866 + static const int md5sum_hex_len = 32;
868 + static const unsigned char bin2hex[16] = {
869 + '0', '1', '2', '3',
870 + '4', '5', '6', '7',
871 + '8', '9', 'a', 'b',
877 + unsigned char *md5sum_hex;
878 + unsigned char md5sum_bin[md5sum_bin_len];
880 + md5sum_hex = malloc(md5sum_hex_len + 1);
881 + if (md5sum_hex == NULL) {
882 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
886 + file = fopen(file_name, "r");
887 + if (file == NULL) {
888 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
889 + __FUNCTION__, file_name, strerror(errno));
893 + err = md5_stream(file, md5sum_bin);
895 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
896 + __FUNCTION__, file_name, strerror(err));
902 + for (i=0; i < md5sum_bin_len; i++) {
903 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
904 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
907 + md5sum_hex[md5sum_hex_len] = '\0';
912 diff -ruN busybox-1.00-orig/archival/libipkg/file_util.h busybox-1.00+ipkg-0.99.154/archival/libipkg/file_util.h
913 --- busybox-1.00-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
914 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/file_util.h 2005-10-26 17:36:45.000000000 +0200
916 +/* file_util.h - convenience routines for common file operations
920 + Copyright (C) 2001 University of Southern California
922 + This program is free software; you can redistribute it and/or
923 + modify it under the terms of the GNU General Public License as
924 + published by the Free Software Foundation; either version 2, or (at
925 + your option) any later version.
927 + This program is distributed in the hope that it will be useful, but
928 + WITHOUT ANY WARRANTY; without even the implied warranty of
929 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
930 + General Public License for more details.
936 +int file_exists(const char *file_name);
937 +int file_is_dir(const char *file_name);
938 +char *file_read_line_alloc(FILE *file);
939 +int file_move(const char *src, const char *dest);
940 +int file_copy(const char *src, const char *dest);
941 +int file_mkdir_hier(const char *path, long mode);
942 +char *file_md5sum_alloc(const char *file_name);
945 diff -ruN busybox-1.00-orig/archival/libipkg/hash_table.c busybox-1.00+ipkg-0.99.154/archival/libipkg/hash_table.c
946 --- busybox-1.00-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
947 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/hash_table.c 2005-10-26 17:36:45.000000000 +0200
949 +/* hash.c - hash tables for ipkg
951 + Steven M. Ayer, Jamey Hicks
953 + Copyright (C) 2002 Compaq Computer Corporation
955 + This program is free software; you can redistribute it and/or
956 + modify it under the terms of the GNU General Public License as
957 + published by the Free Software Foundation; either version 2, or (at
958 + your option) any later version.
960 + This program is distributed in the hope that it will be useful, but
961 + WITHOUT ANY WARRANTY; without even the implied warranty of
962 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
963 + General Public License for more details.
970 +#include "hash_table.h"
971 +#include "ipkg_message.h"
974 +static int hash_index(hash_table_t *hash, const char *pkg_name);
975 +static int rotating(const char *key, int len, int prime);
977 +static int hash_index(hash_table_t *hash, const char *pkg_name)
979 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
982 +static int rotating(const char *key, int len, int prime)
984 + unsigned int hash, i;
985 + for (hash=len, i=0; i<len; ++i)
986 + hash = (hash<<4)^(hash>>28)^key[i];
987 + return (hash % prime);
992 + * this is an open table keyed by strings
994 +int hash_table_init(const char *name, hash_table_t *hash, int len)
996 + static int primes_table[] = {
997 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
998 + 19471, 23143, 33961, 46499, 49727, 99529, 0
1002 + if (hash->entries != NULL) {
1003 + /* we have been here already */
1007 + hash->name = name;
1008 + hash->entries = NULL;
1009 + hash->n_entries = 0;
1010 + hash->hash_entry_key = NULL;
1012 + picker = primes_table;
1013 + while(*picker && (*picker++ < len));
1015 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1018 + hash->n_entries = *picker;
1019 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1020 + if (hash->entries == NULL) {
1021 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1027 +void hash_table_deinit(hash_table_t *hash)
1029 + free(hash->entries);
1030 + hash->entries = NULL;
1031 + hash->n_entries = 0;
1034 +void *hash_table_get(hash_table_t *hash, const char *key)
1036 + int ndx= hash_index(hash, key);
1037 + hash_entry_t *hash_entry = hash->entries + ndx;
1038 + while (hash_entry)
1040 + if (hash_entry->key)
1042 + if (strcmp(key, hash_entry->key) == 0) {
1043 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1044 + return hash_entry->data;
1047 + hash_entry = hash_entry->next;
1052 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1054 + int ndx= hash_index(hash, key);
1055 + hash_entry_t *hash_entry = hash->entries + ndx;
1056 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1057 + if (hash_entry->key) {
1058 + if (strcmp(hash_entry->key, key) == 0) {
1059 + /* alread in table, update the value */
1060 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1061 + hash_entry->data = value;
1065 + * if this is a collision, we have to go to the end of the ll,
1066 + * then add a new entry
1067 + * before we can hook up the value
1069 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1070 + while (hash_entry->next)
1071 + hash_entry = hash_entry->next;
1072 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1073 + if (!hash_entry->next) {
1076 + hash_entry = hash_entry->next;
1077 + hash_entry->next = NULL;
1080 + hash->n_elements++;
1081 + hash_entry->key = strdup(key);
1082 + hash_entry->data = value;
1088 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1094 + for (i = 0; i < hash->n_entries; i++) {
1095 + hash_entry_t *hash_entry = (hash->entries + i);
1097 + if(hash_entry->key) {
1098 + f(hash_entry->key, hash_entry->data, data);
1100 + } while((hash_entry = hash_entry->next));
1104 diff -ruN busybox-1.00-orig/archival/libipkg/hash_table.h busybox-1.00+ipkg-0.99.154/archival/libipkg/hash_table.h
1105 --- busybox-1.00-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1106 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/hash_table.h 2005-10-26 17:36:45.000000000 +0200
1108 +/* hash.h - hash tables for ipkg
1110 + Steven M. Ayer, Jamey Hicks
1112 + Copyright (C) 2002 Compaq Computer Corporation
1114 + This program is free software; you can redistribute it and/or
1115 + modify it under the terms of the GNU General Public License as
1116 + published by the Free Software Foundation; either version 2, or (at
1117 + your option) any later version.
1119 + This program is distributed in the hope that it will be useful, but
1120 + WITHOUT ANY WARRANTY; without even the implied warranty of
1121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1122 + General Public License for more details.
1125 +#ifndef _HASH_TABLE_H_
1126 +#define _HASH_TABLE_H_
1128 +typedef struct hash_entry hash_entry_t;
1129 +typedef struct hash_table hash_table_t;
1131 +struct hash_entry {
1134 + struct hash_entry * next;
1137 +struct hash_table {
1139 + hash_entry_t * entries;
1140 + int n_entries; /* number of buckets */
1142 + const char * (*hash_entry_key)(void * data);
1145 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1146 +void hash_table_deinit(hash_table_t *hash);
1147 +void *hash_table_get(hash_table_t *hash, const char *key);
1148 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1149 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1151 +#endif /* _HASH_TABLE_H_ */
1152 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg.h
1153 --- busybox-1.00-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1154 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg.h 2005-10-26 17:45:05.000000000 +0200
1156 +/* ipkg.h - the itsy package management system
1160 + Copyright (C) 2001 University of Southern California
1162 + This program is free software; you can redistribute it and/or
1163 + modify it under the terms of the GNU General Public License as
1164 + published by the Free Software Foundation; either version 2, or (at
1165 + your option) any later version.
1167 + This program is distributed in the hope that it will be useful, but
1168 + WITHOUT ANY WARRANTY; without even the implied warranty of
1169 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1170 + General Public License for more details.
1177 +#ifdef HAVE_CONFIG_H
1178 +#include "config.h"
1183 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1186 +#include "ipkg_includes.h"
1187 +#include "ipkg_conf.h"
1188 +#include "ipkg_message.h"
1190 +#define IPKG_PKG_EXTENSION ".ipk"
1191 +#define DPKG_PKG_EXTENSION ".deb"
1193 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1194 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1196 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1197 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1198 +#define IPKG_INFO_DIR_SUFFIX "info"
1199 +#define IPKG_STATUS_FILE_SUFFIX "status"
1201 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1203 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1205 +#define IPKG_VERSION "0.99.154"
1210 + IPKG_PKG_DEPS_UNSATISFIED,
1211 + IPKG_PKG_IS_ESSENTIAL,
1212 + IPKG_PKG_HAS_DEPENDENTS,
1213 + IPKG_PKG_HAS_NO_CANDIDATE
1215 +typedef enum ipkg_error ipkg_error_t;
1217 +extern int ipkg_state_changed;
1222 + struct errlist * next;
1225 +extern struct errlist* error_list;
1227 +extern ipkg_conf_t *global_conf;
1230 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_cmd.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_cmd.c
1231 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1232 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_cmd.c 2005-10-26 17:36:46.000000000 +0200
1234 +/* ipkg_cmd.c - the itsy package management system
1238 + Copyright (C) 2001 University of Southern California
1240 + This program is free software; you can redistribute it and/or
1241 + modify it under the terms of the GNU General Public License as
1242 + published by the Free Software Foundation; either version 2, or (at
1243 + your option) any later version.
1245 + This program is distributed in the hope that it will be useful, but
1246 + WITHOUT ANY WARRANTY; without even the implied warranty of
1247 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1248 + General Public License for more details.
1251 +#include <string.h>
1254 +#include <libgen.h>
1257 +#include <stdlib.h>
1258 +#include <unistd.h>
1259 +#include <signal.h>
1262 +#include "ipkg_conf.h"
1263 +#include "ipkg_cmd.h"
1264 +#include "ipkg_message.h"
1266 +#include "pkg_dest.h"
1267 +#include "pkg_parse.h"
1268 +#include "sprintf_alloc.h"
1270 +#include "file_util.h"
1271 +#include "str_util.h"
1273 +#include "unarchive.h"
1275 +#include <fnmatch.h>
1278 +#include "ipkg_download.h"
1279 +#include "ipkg_install.h"
1280 +#include "ipkg_upgrade.h"
1281 +#include "ipkg_remove.h"
1282 +#include "ipkg_configure.h"
1283 +#include "ipkg_message.h"
1286 +#include "libipkg.h"
1287 +static void *p_userdata = NULL;
1290 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1291 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1292 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1293 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1294 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1295 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1296 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1297 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1298 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1316 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1317 + array for easier maintenance */
1318 +static ipkg_cmd_t cmds[] = {
1319 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1320 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1321 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1322 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1323 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1324 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1325 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1326 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1327 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1328 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1329 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1330 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1331 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1332 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1333 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1334 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1335 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1336 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1337 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1338 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1339 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1340 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1341 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1342 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1343 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1344 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1345 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1346 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1347 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1350 +int ipkg_state_changed;
1351 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1353 + if (ipkg_state_changed && !conf->noaction) {
1354 + ipkg_message(conf, IPKG_INFO,
1355 + " writing status file\n");
1356 + ipkg_conf_write_status_files(conf);
1357 + pkg_write_changed_filelists(conf);
1359 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1364 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1366 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1371 + for (i=0; i < num_cmds; i++) {
1373 + if (strcmp(name, cmd->name) == 0) {
1382 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1385 + p_userdata = userdata;
1388 + result = (cmd->fun)(conf, argc, argv);
1389 + if ( result == 0 ) {
1390 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1392 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1395 + if ( error_list ) {
1396 + reverse_error_list(&error_list);
1398 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1399 + /* Here we print the errors collected and free the list */
1400 + while (error_list != NULL) {
1401 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1402 + error_list = error_list->next;
1405 + free_error_list(&error_list);
1409 + p_userdata = NULL;
1413 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1415 + return (cmd->fun)(conf, argc, argv);
1419 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1424 + pkg_src_list_elt_t *iter;
1428 + if (conf->offline_root) {
1429 + sprintf_alloc(&lists_dir, "%s/%s",
1430 + conf->offline_root,
1431 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1433 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1436 + if (! file_is_dir(lists_dir)) {
1437 + if (file_exists(lists_dir)) {
1438 + ipkg_message(conf, IPKG_ERROR,
1439 + "%s: ERROR: %s exists, but is not a directory\n",
1440 + __FUNCTION__, lists_dir);
1444 + err = file_mkdir_hier(lists_dir, 0755);
1446 + ipkg_message(conf, IPKG_ERROR,
1447 + "%s: ERROR: failed to make directory %s: %s\n",
1448 + __FUNCTION__, lists_dir, strerror(errno));
1455 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1456 + char *url, *list_file_name;
1460 + if (src->extra_data) /* debian style? */
1461 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1462 + src->gzip ? "Packages.gz" : "Packages");
1464 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1466 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1469 + char *tmp_file_name;
1472 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1474 + if (mkdtemp (tmp) == NULL) {
1475 + perror ("mkdtemp");
1480 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1481 + err = ipkg_download(conf, url, tmp_file_name);
1483 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1484 + in = fopen (tmp_file_name, "r");
1485 + out = fopen (list_file_name, "w");
1487 + inflate_unzip (in, out);
1494 + unlink (tmp_file_name);
1499 + err = ipkg_download(conf, url, list_file_name);
1503 + ipkg_message(conf, IPKG_NOTICE,
1504 + "Updated list of available packages in %s\n",
1508 + free(list_file_name);
1512 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1514 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1515 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1521 + pkg_vec_t *available = pkg_vec_alloc();
1522 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1523 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1524 + for (i = 0; i < available->len; i++) {
1525 + pkg_t *pkg = available->pkgs[i];
1526 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1527 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1528 + pkg->state_want = SW_UNKNOWN;
1532 + pkg_vec_free(available);
1534 + write_status_files_if_changed(conf);
1543 +/* scan the args passed and cache the local filenames of the packages */
1544 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1550 + * First scan through package names/urls
1551 + * For any urls, download the packages and install in database.
1552 + * For any files, install package info in database.
1554 + for (i = 0; i < argc; i ++) {
1555 + char *filename = argv [i];
1556 + //char *tmp = basename (tmp);
1557 + //int tmplen = strlen (tmp);
1559 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1561 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1564 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1571 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1577 + ipkg_message(conf, IPKG_INFO,
1578 + "Configuring unpacked packages\n");
1581 + all = pkg_vec_alloc();
1582 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1584 + for(i = 0; i < all->len; i++) {
1585 + pkg = all->pkgs[i];
1587 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1590 + if (pkg->state_status == SS_UNPACKED) {
1591 + ipkg_message(conf, IPKG_NOTICE,
1592 + "Configuring %s\n", pkg->name);
1594 + if (ipkg_configure(conf, pkg) == 0) {
1595 + pkg->state_status = SS_INSTALLED;
1596 + pkg->parent->state_status = SS_INSTALLED;
1597 + pkg->state_flag &= ~SF_PREFER;
1602 + pkg_vec_free(all);
1606 +static void sigint_handler(int sig)
1608 + signal(sig, SIG_DFL);
1609 + ipkg_message(NULL, IPKG_NOTICE,
1610 + "ipkg: interrupted. writing out status database\n");
1611 + write_status_files_if_changed(global_conf);
1615 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1621 + global_conf = conf;
1622 + signal(SIGINT, sigint_handler);
1625 + * Now scan through package names and install
1627 + for (i=0; i < argc; i++) {
1630 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1631 + if (err != EINVAL && err != 0)
1634 + pkg_info_preinstall_check(conf);
1636 + for (i=0; i < argc; i++) {
1638 + if (conf->multiple_providers)
1639 + err = ipkg_install_multi_by_name(conf, arg);
1641 + err = ipkg_install_by_name(conf, arg);
1643 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1644 + ipkg_message(conf, IPKG_ERROR,
1645 + "Cannot find package %s.\n"
1646 + "Check the spelling or perhaps run 'ipkg update'\n",
1651 + /* recheck to verify that all dependences are satisfied */
1652 + if (0) ipkg_satisfy_all_dependences(conf);
1654 + ipkg_configure_packages(conf, NULL);
1656 + write_status_files_if_changed(conf);
1661 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1667 + global_conf = conf;
1668 + signal(SIGINT, sigint_handler);
1671 + for (i=0; i < argc; i++) {
1672 + char *arg = argv[i];
1674 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1675 + if (err != EINVAL && err != 0)
1678 + pkg_info_preinstall_check(conf);
1680 + for (i=0; i < argc; i++) {
1681 + char *arg = argv[i];
1682 + if (conf->restrict_to_default_dest) {
1683 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1685 + conf->default_dest);
1686 + if (pkg == NULL) {
1687 + ipkg_message(conf, IPKG_NOTICE,
1688 + "Package %s not installed in %s\n",
1689 + argv[i], conf->default_dest->name);
1693 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1697 + ipkg_upgrade_pkg(conf, pkg);
1699 + ipkg_install_by_name(conf, arg);
1703 + pkg_vec_t *installed = pkg_vec_alloc();
1705 + pkg_info_preinstall_check(conf);
1707 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1708 + for (i = 0; i < installed->len; i++) {
1709 + pkg = installed->pkgs[i];
1710 + ipkg_upgrade_pkg(conf, pkg);
1712 + pkg_vec_free(installed);
1715 + /* recheck to verify that all dependences are satisfied */
1716 + if (0) ipkg_satisfy_all_dependences(conf);
1718 + ipkg_configure_packages(conf, NULL);
1720 + write_status_files_if_changed(conf);
1725 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1731 + pkg_info_preinstall_check(conf);
1732 + for (i = 0; i < argc; i++) {
1735 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1736 + if (pkg == NULL) {
1737 + ipkg_message(conf, IPKG_ERROR,
1738 + "Cannot find package %s.\n"
1739 + "Check the spelling or perhaps run 'ipkg update'\n",
1744 + err = ipkg_download_pkg(conf, pkg, ".");
1747 + ipkg_message(conf, IPKG_ERROR,
1748 + "Failed to download %s\n", pkg->name);
1750 + ipkg_message(conf, IPKG_NOTICE,
1751 + "Downloaded %s as %s\n",
1752 + pkg->name, pkg->local_filename);
1760 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1763 + pkg_vec_t *available;
1765 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1767 + char *pkg_name = NULL;
1768 + char *version_str;
1771 + pkg_name = argv[0];
1773 + available = pkg_vec_alloc();
1774 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1775 + for (i=0; i < available->len; i++) {
1776 + pkg = available->pkgs[i];
1777 + /* if we have package name or pattern and pkg does not match, then skip it */
1778 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1780 + if (pkg->description) {
1781 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1783 + desc_short[0] = '\0';
1785 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1786 + newline = strchr(desc_short, '\n');
1791 + printf("%s - %s\n", pkg->name, desc_short);
1793 + if (ipkg_cb_list) {
1794 + version_str = pkg_version_str_alloc(pkg);
1795 + ipkg_cb_list(pkg->name,desc_short,
1797 + pkg->state_status,
1799 + free(version_str);
1803 + pkg_vec_free(available);
1809 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1812 + pkg_vec_t *available;
1814 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1816 + char *pkg_name = NULL;
1817 + char *version_str;
1820 + pkg_name = argv[0];
1822 + available = pkg_vec_alloc();
1823 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1824 + for (i=0; i < available->len; i++) {
1825 + pkg = available->pkgs[i];
1826 + /* if we have package name or pattern and pkg does not match, then skip it */
1827 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1829 + if (pkg->description) {
1830 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1832 + desc_short[0] = '\0';
1834 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1835 + newline = strchr(desc_short, '\n');
1840 + printf("%s - %s\n", pkg->name, desc_short);
1842 + if (ipkg_cb_list) {
1843 + version_str = pkg_version_str_alloc(pkg);
1844 + ipkg_cb_list(pkg->name,desc_short,
1846 + pkg->state_status,
1848 + free(version_str);
1856 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1859 + pkg_vec_t *available;
1861 + char *pkg_name = NULL;
1862 + char **pkg_fields = NULL;
1864 + char *buff ; // = (char *)malloc(1);
1867 + pkg_name = argv[0];
1870 + pkg_fields = &argv[1];
1871 + n_fields = argc - 1;
1874 + available = pkg_vec_alloc();
1875 + if (installed_only)
1876 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1878 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1879 + for (i=0; i < available->len; i++) {
1880 + pkg = available->pkgs[i];
1881 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1886 + for (j = 0; j < n_fields; j++)
1887 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1889 + pkg_print_info(pkg, stdout);
1893 + buff = pkg_formatted_info(pkg);
1895 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1896 + pkg->state_status,
1900 + We should not forget that actually the pointer is allocated.
1901 + We need to free it :) ( Thanks florian for seeing the error )
1906 + if (conf->verbosity > 1) {
1907 + conffile_list_elt_t *iter;
1908 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1909 + conffile_t *cf = iter->data;
1910 + int modified = conffile_has_been_modified(conf, cf);
1911 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1912 + cf->name, cf->value, modified);
1920 + pkg_vec_free(available);
1925 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1927 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1930 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1932 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1935 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1940 + char *pkg_name = NULL;
1942 + pkg_name = argv[0];
1944 + err = ipkg_configure_packages (conf, pkg_name);
1947 + err = ipkg_configure_packages (conf, NULL);
1950 + write_status_files_if_changed(conf);
1955 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1958 + char *globpattern;
1961 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1962 + err = glob(globpattern, 0, NULL, &globbuf);
1963 + free(globpattern);
1968 + ipkg_message(conf, IPKG_NOTICE,
1969 + "The following packages in %s will now be installed.\n",
1970 + conf->pending_dir);
1971 + for (i = 0; i < globbuf.gl_pathc; i++) {
1972 + ipkg_message(conf, IPKG_NOTICE,
1973 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1975 + ipkg_message(conf, IPKG_NOTICE, "\n");
1976 + for (i = 0; i < globbuf.gl_pathc; i++) {
1977 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1979 + err = unlink(globbuf.gl_pathv[i]);
1981 + ipkg_message(conf, IPKG_ERROR,
1982 + "%s: ERROR: failed to unlink %s: %s\n",
1983 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1988 + globfree(&globbuf);
1993 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1997 + pkg_t *pkg_to_remove;
1998 + pkg_vec_t *available;
1999 + char *pkg_name = NULL;
2000 + global_conf = conf;
2001 + signal(SIGINT, sigint_handler);
2003 +// ENH: Add the "no pkg removed" just in case.
2007 + available = pkg_vec_alloc();
2008 + pkg_info_preinstall_check(conf);
2010 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2011 + for (i=0; i < argc; i++) {
2012 + pkg_name = malloc(strlen(argv[i])+2);
2013 + strcpy(pkg_name,argv[i]);
2014 + for (a=0; a < available->len; a++) {
2015 + pkg = available->pkgs[a];
2016 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2019 + if (conf->restrict_to_default_dest) {
2020 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2022 + conf->default_dest);
2024 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2027 + if (pkg == NULL) {
2028 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2031 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2032 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2035 + ipkg_remove_pkg(conf, pkg_to_remove);
2040 + pkg_vec_free(available);
2042 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2044 + int flagged_pkg_count = 0;
2047 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2049 + for (i = 0; i < installed_pkgs->len; i++) {
2050 + pkg_t *pkg = installed_pkgs->pkgs[i];
2051 + if (pkg->state_flag & SF_USER) {
2052 + flagged_pkg_count++;
2054 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2055 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2058 + if (!flagged_pkg_count) {
2059 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2060 + "so refusing to uninstall unflagged non-leaf packages\n");
2064 + /* find packages not flagged SF_USER (i.e., installed to
2065 + * satisfy a dependence) and not having any dependents, and
2069 + for (i = 0; i < installed_pkgs->len; i++) {
2070 + pkg_t *pkg = installed_pkgs->pkgs[i];
2071 + if (!(pkg->state_flag & SF_USER)
2072 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2074 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2075 + ipkg_remove_pkg(conf, pkg);
2079 + } while (removed);
2080 + pkg_vec_free(installed_pkgs);
2084 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2086 + write_status_files_if_changed(conf);
2090 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2095 + global_conf = conf;
2096 + signal(SIGINT, sigint_handler);
2098 + pkg_info_preinstall_check(conf);
2100 + for (i=0; i < argc; i++) {
2101 + if (conf->restrict_to_default_dest) {
2102 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2104 + conf->default_dest);
2106 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2109 + if (pkg == NULL) {
2110 + ipkg_message(conf, IPKG_ERROR,
2111 + "Package %s is not installed.\n", argv[i]);
2114 + ipkg_purge_pkg(conf, pkg);
2117 + write_status_files_if_changed(conf);
2121 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2125 + const char *flags = argv[0];
2127 + global_conf = conf;
2128 + signal(SIGINT, sigint_handler);
2130 + for (i=1; i < argc; i++) {
2131 + if (conf->restrict_to_default_dest) {
2132 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2134 + conf->default_dest);
2136 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2139 + if (pkg == NULL) {
2140 + ipkg_message(conf, IPKG_ERROR,
2141 + "Package %s is not installed.\n", argv[i]);
2144 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2145 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2146 + pkg->state_flag = pkg_state_flag_from_str(flags);
2148 +/* pb_ asked this feature 03292004 */
2149 +/* Actually I will use only this two, but this is an open for various status */
2150 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2151 + pkg->state_status = pkg_state_status_from_str(flags);
2153 + ipkg_state_changed++;
2154 + ipkg_message(conf, IPKG_NOTICE,
2155 + "Setting flags for package %s to %s\n",
2156 + pkg->name, flags);
2159 + write_status_files_if_changed(conf);
2163 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2166 + str_list_t *installed_files;
2167 + str_list_elt_t *iter;
2168 + char *pkg_version;
2169 + size_t buff_len = 8192;
2173 + buff = (char *)malloc(buff_len);
2174 + if ( buff == NULL ) {
2175 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2183 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2185 + if (pkg == NULL) {
2186 + ipkg_message(conf, IPKG_ERROR,
2187 + "Package %s not installed.\n", argv[0]);
2191 + installed_files = pkg_get_installed_files(pkg);
2192 + pkg_version = pkg_version_str_alloc(pkg);
2195 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2196 + pkg->name, pkg_version, pkg->dest->name);
2197 + for (iter = installed_files->head; iter; iter = iter->next) {
2203 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2204 + pkg->name, pkg_version, pkg->dest->name) + 1;
2205 + if (used_len > buff_len) {
2207 + buff = realloc (buff, buff_len);
2210 + for (iter = installed_files->head; iter; iter = iter->next) {
2211 + used_len += strlen (iter->data) + 1;
2212 + while (buff_len <= used_len) {
2214 + buff = realloc (buff, buff_len);
2216 + strncat(buff, iter->data, buff_len);
2217 + strncat(buff, "\n", buff_len);
2219 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2221 + pkg_version_str_alloc(pkg),
2222 + pkg->state_status,
2228 + free(pkg_version);
2229 + pkg_free_installed_files(pkg);
2234 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2238 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2239 + const char *rel_str = "depends on";
2242 + pkg_info_preinstall_check(conf);
2244 + if (conf->query_all)
2245 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2247 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2248 + for (i = 0; i < argc; i++) {
2249 + const char *target = argv[i];
2252 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2254 + for (j = 0; j < available_pkgs->len; j++) {
2255 + pkg_t *pkg = available_pkgs->pkgs[j];
2256 + if (fnmatch(target, pkg->name, 0) == 0) {
2258 + int count = pkg->depends_count + pkg->pre_depends_count;
2259 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2260 + target, pkg->architecture, rel_str);
2261 + for (k = 0; k < count; k++) {
2262 + compound_depend_t *cdepend = &pkg->depends[k];
2264 + for (l = 0; l < cdepend->possibility_count; l++) {
2265 + depend_t *possibility = cdepend->possibilities[l];
2266 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2267 + if (conf->verbosity > 0) {
2268 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2269 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2270 + if (possibility->version) {
2271 + char *typestr = NULL;
2272 + switch (possibility->constraint) {
2273 + case NONE: typestr = "none"; break;
2274 + case EARLIER: typestr = "<"; break;
2275 + case EARLIER_EQUAL: typestr = "<="; break;
2276 + case EQUAL: typestr = "="; break;
2277 + case LATER_EQUAL: typestr = ">="; break;
2278 + case LATER: typestr = ">"; break;
2280 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2284 + ipkg_message(conf, IPKG_ERROR, "\n");
2290 + pkg_vec_free(available_pkgs);
2295 +enum what_field_type {
2304 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2308 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2309 + const char *rel_str = NULL;
2313 + switch (what_field_type) {
2314 + case WHATDEPENDS: rel_str = "depends on"; break;
2315 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2316 + case WHATSUGGESTS: rel_str = "suggests"; break;
2317 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2318 + case WHATPROVIDES: rel_str = "provides"; break;
2319 + case WHATREPLACES: rel_str = "replaces"; break;
2322 + if (conf->query_all)
2323 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2325 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2327 + /* mark the root set */
2328 + pkg_vec_clear_marks(available_pkgs);
2329 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2330 + for (i = 0; i < argc; i++) {
2331 + const char *dependee_pattern = argv[i];
2332 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2334 + for (i = 0; i < available_pkgs->len; i++) {
2335 + pkg_t *pkg = available_pkgs->pkgs[i];
2336 + if (pkg->state_flag & SF_MARKED) {
2337 + /* mark the parent (abstract) package */
2338 + pkg_mark_provides(pkg);
2339 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2343 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2348 + for (j = 0; j < available_pkgs->len; j++) {
2349 + pkg_t *pkg = available_pkgs->pkgs[j];
2351 + int count = ((what_field_type == WHATCONFLICTS)
2352 + ? pkg->conflicts_count
2353 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2354 + /* skip this package if it is already marked */
2355 + if (pkg->parent->state_flag & SF_MARKED) {
2358 + for (k = 0; k < count; k++) {
2359 + compound_depend_t *cdepend =
2360 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2362 + for (l = 0; l < cdepend->possibility_count; l++) {
2363 + depend_t *possibility = cdepend->possibilities[l];
2364 + if (possibility->pkg->state_flag & SF_MARKED) {
2365 + /* mark the depending package so we won't visit it again */
2366 + pkg->state_flag |= SF_MARKED;
2367 + pkg_mark_provides(pkg);
2370 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2371 + if (conf->verbosity > 0) {
2372 + char *ver = pkg_version_str_alloc(pkg);
2373 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2374 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2375 + if (possibility->version) {
2376 + char *typestr = NULL;
2377 + switch (possibility->constraint) {
2378 + case NONE: typestr = "none"; break;
2379 + case EARLIER: typestr = "<"; break;
2380 + case EARLIER_EQUAL: typestr = "<="; break;
2381 + case EQUAL: typestr = "="; break;
2382 + case LATER_EQUAL: typestr = ">="; break;
2383 + case LATER: typestr = ">"; break;
2385 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2388 + if (!pkg_dependence_satisfiable(conf, possibility))
2389 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2391 + ipkg_message(conf, IPKG_NOTICE, "\n");
2392 + goto next_package;
2399 + } while (changed && recursive);
2400 + pkg_vec_free(available_pkgs);
2406 +int pkg_mark_provides(pkg_t *pkg)
2408 + int provides_count = pkg->provides_count;
2409 + abstract_pkg_t **provides = pkg->provides;
2411 + pkg->parent->state_flag |= SF_MARKED;
2412 + for (i = 0; i < provides_count; i++) {
2413 + provides[i]->state_flag |= SF_MARKED;
2418 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2420 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2422 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2424 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2427 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2429 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2432 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2434 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2437 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2439 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2442 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2446 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2447 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2450 + pkg_info_preinstall_check(conf);
2452 + if (conf->query_all)
2453 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2455 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2456 + for (i = 0; i < argc; i++) {
2457 + const char *target = argv[i];
2460 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2462 + for (j = 0; j < available_pkgs->len; j++) {
2463 + pkg_t *pkg = available_pkgs->pkgs[j];
2465 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2466 + for (k = 0; k < count; k++) {
2467 + abstract_pkg_t *apkg =
2468 + ((what_field_type == WHATPROVIDES)
2469 + ? pkg->provides[k]
2470 + : pkg->replaces[k]);
2471 + if (fnmatch(target, apkg->name, 0) == 0) {
2472 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2473 + if (strcmp(target, apkg->name) != 0)
2474 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2475 + ipkg_message(conf, IPKG_ERROR, "\n");
2480 + pkg_vec_free(available_pkgs);
2485 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2487 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2490 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2492 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2495 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2499 + pkg_vec_t *installed;
2501 + str_list_t *installed_files;
2502 + str_list_elt_t *iter;
2503 + char *installed_file;
2509 + installed = pkg_vec_alloc();
2510 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2512 + for (i=0; i < installed->len; i++) {
2513 + pkg = installed->pkgs[i];
2515 + installed_files = pkg_get_installed_files(pkg);
2517 + for (iter = installed_files->head; iter; iter = iter->next) {
2518 + installed_file = iter->data;
2519 + if (fnmatch(argv[0], installed_file, 0)==0) {
2521 + printf("%s: %s\n", pkg->name, installed_file);
2523 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2525 + pkg_version_str_alloc(pkg),
2526 + pkg->state_status, p_userdata);
2531 + pkg_free_installed_files(pkg);
2534 + /* XXX: CLEANUP: It's not obvious from the name of
2535 + pkg_hash_fetch_all_installed that we need to call
2536 + pkg_vec_free to avoid a memory leak. */
2537 + pkg_vec_free(installed);
2542 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2545 + /* this is a bit gross */
2546 + struct pkg p1, p2;
2547 + parseVersion(&p1, argv[0]);
2548 + parseVersion(&p2, argv[2]);
2549 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2551 + ipkg_message(conf, IPKG_ERROR,
2552 + "ipkg compare_versions <v1> <op> <v2>\n"
2553 + "<op> is one of <= >= << >> =\n");
2558 +#ifndef HOST_CPU_STR
2559 +#define HOST_CPU_STR__(X) #X
2560 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2561 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2564 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2566 + nv_pair_list_elt_t *l;
2568 + l = conf->arch_list.head;
2570 + nv_pair_t *nv = l->data;
2571 + printf("arch %s %s\n", nv->name, nv->value);
2578 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_cmd.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_cmd.h
2579 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2580 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_cmd.h 2005-10-26 17:36:46.000000000 +0200
2582 +/* ipkg_cmd.h - the itsy package management system
2586 + Copyright (C) 2001 University of Southern California
2588 + This program is free software; you can redistribute it and/or
2589 + modify it under the terms of the GNU General Public License as
2590 + published by the Free Software Foundation; either version 2, or (at
2591 + your option) any later version.
2593 + This program is distributed in the hope that it will be useful, but
2594 + WITHOUT ANY WARRANTY; without even the implied warranty of
2595 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2596 + General Public License for more details.
2602 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2607 + int requires_args;
2608 + ipkg_cmd_fun_t fun;
2610 +typedef struct ipkg_cmd ipkg_cmd_t;
2612 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2614 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2615 + const char **argv, void *userdata);
2617 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2619 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2620 +/* install any packges with state_want == SW_INSTALL */
2621 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2622 +/* ensure that all dependences are satisfied */
2623 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2625 +int pkg_mark_provides(pkg_t *pkg);
2628 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_conf.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_conf.c
2629 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2630 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_conf.c 2005-10-26 17:36:46.000000000 +0200
2632 +/* ipkg_conf.c - the itsy package management system
2636 + Copyright (C) 2001 University of Southern California
2638 + This program is free software; you can redistribute it and/or
2639 + modify it under the terms of the GNU General Public License as
2640 + published by the Free Software Foundation; either version 2, or (at
2641 + your option) any later version.
2643 + This program is distributed in the hope that it will be useful, but
2644 + WITHOUT ANY WARRANTY; without even the implied warranty of
2645 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2646 + General Public License for more details.
2652 +#include "ipkg_conf.h"
2654 +#include "xregex.h"
2655 +#include "sprintf_alloc.h"
2656 +#include "ipkg_conf.h"
2657 +#include "ipkg_message.h"
2658 +#include "file_util.h"
2659 +#include "str_util.h"
2660 +#include "xsystem.h"
2663 +ipkg_conf_t *global_conf;
2665 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2666 + pkg_src_list_t *pkg_src_list,
2667 + nv_pair_list_t *tmp_dest_nv_pair_list,
2668 + char **tmp_lists_dir);
2669 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2670 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2671 + const char *name, const char *value);
2672 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2673 + const char *default_dest_name);
2674 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2675 + pkg_src_list_t *nv_pair_list);
2676 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2677 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2679 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2681 + ipkg_option_t tmp[] = {
2682 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2683 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2684 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2685 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2686 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2687 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2688 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2689 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2690 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2691 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2692 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2693 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2694 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2695 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2696 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2697 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2698 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2699 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2700 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2701 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2702 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2706 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2707 + if ( options == NULL ){
2708 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2712 + memcpy(*options, tmp, sizeof(tmp));
2716 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2722 + *conf_str = strdup(arg_str);
2726 +static void ipkg_conf_free_string(char **conf_str)
2734 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2737 + char *tmp_dir_base;
2738 + nv_pair_list_t tmp_dest_nv_pair_list;
2739 + char * lists_dir =NULL;
2741 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2742 + char *pending_dir =NULL;
2744 + memset(conf, 0, sizeof(ipkg_conf_t));
2746 + pkg_src_list_init(&conf->pkg_src_list);
2748 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2749 + pkg_dest_list_init(&conf->pkg_dest_list);
2751 + nv_pair_list_init(&conf->arch_list);
2753 + conf->restrict_to_default_dest = 0;
2754 + conf->default_dest = NULL;
2757 + if (args->tmp_dir)
2758 + tmp_dir_base = args->tmp_dir;
2760 + tmp_dir_base = getenv("TMPDIR");
2761 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2762 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2763 + IPKG_CONF_TMP_DIR_SUFFIX);
2764 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2765 + if (conf->tmp_dir == NULL) {
2766 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2767 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2771 + conf->force_depends = 0;
2772 + conf->force_defaults = 0;
2773 + conf->force_overwrite = 0;
2774 + conf->force_downgrade = 0;
2775 + conf->force_reinstall = 0;
2776 + conf->force_space = 0;
2777 + conf->force_removal_of_essential_packages = 0;
2778 + conf->force_removal_of_dependent_packages = 0;
2780 + conf->verbose_wget = 0;
2781 + conf->offline_root = NULL;
2782 + conf->offline_root_pre_script_cmd = NULL;
2783 + conf->offline_root_post_script_cmd = NULL;
2784 + conf->multiple_providers = 0;
2785 + conf->verbosity = 1;
2786 + conf->noaction = 0;
2788 + conf->http_proxy = NULL;
2789 + conf->ftp_proxy = NULL;
2790 + conf->no_proxy = NULL;
2791 + conf->proxy_user = NULL;
2792 + conf->proxy_passwd = NULL;
2794 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2795 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2796 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2797 + lists_dir=(char *)malloc(1);
2798 + lists_dir[0]='\0';
2799 + if (args->conf_file) {
2800 + struct stat stat_buf;
2801 + err = stat(args->conf_file, &stat_buf);
2803 + if (ipkg_conf_parse_file(conf, args->conf_file,
2804 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2805 + /* Memory leakage from ipkg_conf_parse-file */
2811 + /* if (!lists_dir ){*/
2812 + if (strlen(lists_dir)<=1 ){
2813 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2814 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2817 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2818 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2820 + conf->lists_dir = strdup(lists_dir);
2821 + conf->pending_dir = strdup(pending_dir);
2823 + if (args->offline_root)
2824 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2825 + memset(&globbuf, 0, sizeof(globbuf));
2826 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2829 + for (i = 0; i < globbuf.gl_pathc; i++) {
2830 + if (globbuf.gl_pathv[i])
2831 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2832 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2833 + /* Memory leakage from ipkg_conf_parse-file */
2838 + globfree(&globbuf);
2840 + /* if no architectures were defined, then default all, noarch, and host architecture */
2841 + if (nv_pair_list_empty(&conf->arch_list)) {
2842 + nv_pair_list_append(&conf->arch_list, "all", "1");
2843 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2844 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2847 + /* Even if there is no conf file, we'll need at least one dest. */
2848 + if (tmp_dest_nv_pair_list.head == NULL) {
2849 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2850 + IPKG_CONF_DEFAULT_DEST_NAME,
2851 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2854 + /* After parsing the file, set options from command-line, (so that
2855 + command-line arguments take precedence) */
2856 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2857 + really needs to be cleaned up. There is so much duplication
2858 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2859 + a pointer to args_t (which could then not be freed), rather
2860 + than duplicating every field here? */
2861 + if (args->force_depends) {
2862 + conf->force_depends = 1;
2864 + if (args->force_defaults) {
2865 + conf->force_defaults = 1;
2867 + if (args->force_overwrite) {
2868 + conf->force_overwrite = 1;
2870 + if (args->force_downgrade) {
2871 + conf->force_downgrade = 1;
2873 + if (args->force_reinstall) {
2874 + conf->force_reinstall = 1;
2876 + if (args->force_removal_of_dependent_packages) {
2877 + conf->force_removal_of_dependent_packages = 1;
2879 + if (args->force_removal_of_essential_packages) {
2880 + conf->force_removal_of_essential_packages = 1;
2882 + if (args->nodeps) {
2885 + if (args->noaction) {
2886 + conf->noaction = 1;
2888 + if (args->query_all) {
2889 + conf->query_all = 1;
2891 + if (args->verbose_wget) {
2892 + conf->verbose_wget = 1;
2894 + if (args->multiple_providers) {
2895 + conf->multiple_providers = 1;
2897 + if (args->verbosity != conf->verbosity) {
2898 + conf->verbosity = args->verbosity;
2901 + ipkg_conf_override_string(&conf->offline_root,
2902 + args->offline_root);
2903 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2904 + args->offline_root_pre_script_cmd);
2905 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2906 + args->offline_root_post_script_cmd);
2908 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2909 + read anything from there.
2911 + if ( !(args->nocheckfordirorfile)){
2912 + /* need to run load the source list before dest list -Jamey */
2913 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2915 + /* Now that we have resolved conf->offline_root, we can commit to
2916 + the directory names for the dests and load in all the package
2918 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2921 + err = ipkg_conf_set_default_dest(conf, args->dest);
2927 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2929 + free(pending_dir);
2934 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2936 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2938 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2939 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2940 + __FUNCTION__, conf->tmp_dir);
2944 + err = rmdir(conf->tmp_dir);
2946 + if (errno == ENOTEMPTY) {
2948 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2949 + err = xsystem(cmd);
2953 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2955 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2957 + free(conf->tmp_dir); /*XXX*/
2959 + pkg_src_list_deinit(&conf->pkg_src_list);
2960 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2961 + nv_pair_list_deinit(&conf->arch_list);
2962 + if (&conf->pkg_hash)
2963 + pkg_hash_deinit(&conf->pkg_hash);
2964 + if (&conf->file_hash)
2965 + hash_table_deinit(&conf->file_hash);
2966 + if (&conf->obs_file_hash)
2967 + hash_table_deinit(&conf->obs_file_hash);
2969 + ipkg_conf_free_string(&conf->offline_root);
2970 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2971 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2973 + if (conf->verbosity > 1) {
2975 + hash_table_t *hashes[] = {
2978 + &conf->obs_file_hash };
2979 + for (i = 0; i < 3; i++) {
2980 + hash_table_t *hash = hashes[i];
2982 + int n_conflicts = 0;
2984 + for (j = 0; j < hash->n_entries; j++) {
2986 + hash_entry_t *e = &hash->entries[j];
2989 + while (e && e->key) {
2996 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2997 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2998 + hash_table_deinit(hash);
3003 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3004 + const char *default_dest_name)
3006 + pkg_dest_list_elt_t *iter;
3009 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3010 + dest = iter->data;
3011 + if (strcmp(dest->name, default_dest_name) == 0) {
3012 + conf->default_dest = dest;
3013 + conf->restrict_to_default_dest = 1;
3018 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3023 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3025 + pkg_src_list_elt_t *iter;
3029 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3031 + if (src == NULL) {
3034 + if (conf->offline_root) {
3035 + sprintf_alloc(&list_file, "%s/%s/%s",
3036 + conf->offline_root,
3037 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3040 + sprintf_alloc(&list_file, "%s/%s",
3041 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3045 + if (file_exists(list_file)) {
3046 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3054 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3056 + nv_pair_list_elt_t *iter;
3057 + nv_pair_t *nv_pair;
3061 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3062 + nv_pair = iter->data;
3064 + if (conf->offline_root) {
3065 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3067 + root_dir = strdup(nv_pair->value);
3069 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3071 + if (dest == NULL) {
3074 + if (conf->default_dest == NULL) {
3075 + conf->default_dest = dest;
3077 + if (file_exists(dest->status_file_name)) {
3078 + pkg_hash_add_from_file(conf, dest->status_file_name,
3086 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3087 + pkg_src_list_t *pkg_src_list,
3088 + nv_pair_list_t *tmp_dest_nv_pair_list,
3091 + ipkg_option_t * options;
3092 + FILE *file = fopen(filename, "r");
3093 + regex_t valid_line_re, comment_re;
3094 +#define regmatch_size 12
3095 + regmatch_t regmatch[regmatch_size];
3097 + if (ipkg_init_options_array(conf, &options)<0)
3100 + if (file == NULL) {
3101 + fprintf(stderr, "%s: failed to open %s: %s\n",
3102 + __FUNCTION__, filename, strerror(errno));
3106 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3108 + xregcomp(&comment_re,
3109 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3111 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3116 + char *type, *name, *value, *extra;
3118 + line = file_read_line_alloc(file);
3120 + if (line == NULL) {
3126 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3130 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3132 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3133 + filename, line_num, line);
3137 + /* This has to be so ugly to deal with optional quotation marks */
3138 + if (regmatch[2].rm_so > 0) {
3139 + type = strndup(line + regmatch[2].rm_so,
3140 + regmatch[2].rm_eo - regmatch[2].rm_so);
3142 + type = strndup(line + regmatch[3].rm_so,
3143 + regmatch[3].rm_eo - regmatch[3].rm_so);
3145 + if (regmatch[5].rm_so > 0) {
3146 + name = strndup(line + regmatch[5].rm_so,
3147 + regmatch[5].rm_eo - regmatch[5].rm_so);
3149 + name = strndup(line + regmatch[6].rm_so,
3150 + regmatch[6].rm_eo - regmatch[6].rm_so);
3152 + if (regmatch[8].rm_so > 0) {
3153 + value = strndup(line + regmatch[8].rm_so,
3154 + regmatch[8].rm_eo - regmatch[8].rm_so);
3156 + value = strndup(line + regmatch[9].rm_so,
3157 + regmatch[9].rm_eo - regmatch[9].rm_so);
3160 + if (regmatch[11].rm_so > 0) {
3161 + extra = strndup (line + regmatch[11].rm_so,
3162 + regmatch[11].rm_eo - regmatch[11].rm_so);
3165 + /* We use the tmp_dest_nv_pair_list below instead of
3166 + conf->pkg_dest_list because we might encounter an
3167 + offline_root option later and that would invalidate the
3168 + directories we would have computed in
3169 + pkg_dest_list_init. (We do a similar thing with
3170 + tmp_src_nv_pair_list for sake of symmetry.) */
3171 + if (strcmp(type, "option") == 0) {
3172 + ipkg_conf_set_option(options, name, value);
3173 + } else if (strcmp(type, "src") == 0) {
3174 + if (!nv_pair_list_find(pkg_src_list, name)) {
3175 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3177 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3180 + } else if (strcmp(type, "src/gz") == 0) {
3181 + if (!nv_pair_list_find(pkg_src_list, name)) {
3182 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3184 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3187 + } else if (strcmp(type, "dest") == 0) {
3188 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3189 + } else if (strcmp(type, "lists_dir") == 0) {
3190 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3191 + if (*lists_dir == NULL) {
3192 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3196 + sprintf (*lists_dir,"%s",value);
3197 + } else if (strcmp(type, "arch") == 0) {
3198 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3200 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3201 + value = strdup("10");
3203 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3205 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3206 + "parameter: %s %s %s\n", type, name, value);
3222 + regfree(&comment_re);
3223 + regfree(&valid_line_re);
3229 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3230 + const char *name, const char *value)
3233 + while (options[i].name) {
3234 + if (strcmp(options[i].name, name) == 0) {
3235 + switch (options[i].type) {
3236 + case IPKG_OPT_TYPE_BOOL:
3237 + *((int *)options[i].value) = 1;
3239 + case IPKG_OPT_TYPE_INT:
3241 + *((int *)options[i].value) = atoi(value);
3244 + printf("%s: Option %s need an argument\n",
3245 + __FUNCTION__, name);
3248 + case IPKG_OPT_TYPE_STRING:
3250 + *((char **)options[i].value) = strdup(value);
3253 + printf("%s: Option %s need an argument\n",
3254 + __FUNCTION__, name);
3262 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3263 + __FUNCTION__, name, value);
3267 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3269 + pkg_dest_list_elt_t *iter;
3276 + if (conf->noaction)
3278 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3279 + dest = iter->data;
3280 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3281 + if (dest->status_file == NULL) {
3282 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3283 + __FUNCTION__, dest->status_file_name, strerror(errno));
3287 + all = pkg_vec_alloc();
3288 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3290 + for(i = 0; i < all->len; i++) {
3291 + pkg = all->pkgs[i];
3292 + /* We don't need most uninstalled packages in the status file */
3293 + if (pkg->state_status == SS_NOT_INSTALLED
3294 + && (pkg->state_want == SW_UNKNOWN
3295 + || pkg->state_want == SW_DEINSTALL
3296 + || pkg->state_want == SW_PURGE)) {
3300 + fprintf(stderr, "Null package\n");
3302 + if (pkg->dest == NULL) {
3303 + fprintf(stderr, "%s: ERROR: Can't write status for "
3304 + "package %s since it has a NULL dest\n",
3305 + __FUNCTION__, pkg->name);
3308 + if (pkg->dest->status_file) {
3309 + pkg_print_status(pkg, pkg->dest->status_file);
3313 + pkg_vec_free(all);
3315 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3316 + dest = iter->data;
3317 + if (dest->status_file) {
3318 + err = ferror(dest->status_file);
3319 + fclose(dest->status_file);
3320 + dest->status_file = NULL;
3322 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3324 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3325 + "retaining old %s\n", __FUNCTION__,
3326 + dest->status_file_tmp_name, dest->status_file_name);
3335 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3337 + char *root_filename;
3338 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3339 + return root_filename;
3341 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_conf.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_conf.h
3342 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3343 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_conf.h 2005-10-26 17:36:46.000000000 +0200
3345 +/* ipkg_conf.h - the itsy package management system
3349 + Copyright (C) 2001 University of Southern California
3351 + This program is free software; you can redistribute it and/or
3352 + modify it under the terms of the GNU General Public License as
3353 + published by the Free Software Foundation; either version 2, or (at
3354 + your option) any later version.
3356 + This program is distributed in the hope that it will be useful, but
3357 + WITHOUT ANY WARRANTY; without even the implied warranty of
3358 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3359 + General Public License for more details.
3362 +#ifndef IPKG_CONF_H
3363 +#define IPKG_CONF_H
3365 +typedef struct ipkg_conf ipkg_conf_t;
3367 +#include "hash_table.h"
3371 +#include "pkg_hash.h"
3372 +#include "pkg_src_list.h"
3373 +#include "pkg_dest_list.h"
3374 +#include "nv_pair_list.h"
3376 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3377 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3378 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3379 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3381 +/* In case the config file defines no dest */
3382 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3383 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3385 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3389 + pkg_src_list_t pkg_src_list;
3390 + pkg_dest_list_t pkg_dest_list;
3391 + nv_pair_list_t arch_list;
3393 + int restrict_to_default_dest;
3394 + pkg_dest_t *default_dest;
3397 + const char *lists_dir;
3398 + const char *pending_dir;
3401 + int force_depends;
3402 + int force_defaults;
3403 + int force_overwrite;
3404 + int force_downgrade;
3405 + int force_reinstall;
3407 + int force_removal_of_dependent_packages;
3408 + int force_removal_of_essential_packages;
3409 + int nodeps; /* do not follow dependences */
3411 + int multiple_providers;
3412 + char *offline_root;
3413 + char *offline_root_pre_script_cmd;
3414 + char *offline_root_post_script_cmd;
3419 + /* proxy options */
3424 + char *proxy_passwd;
3426 + hash_table_t pkg_hash;
3427 + hash_table_t file_hash;
3428 + hash_table_t obs_file_hash;
3431 +enum ipkg_option_type {
3432 + IPKG_OPT_TYPE_BOOL,
3433 + IPKG_OPT_TYPE_INT,
3434 + IPKG_OPT_TYPE_STRING
3436 +typedef enum ipkg_option_type ipkg_option_type_t;
3438 +typedef struct ipkg_option ipkg_option_t;
3439 +struct ipkg_option {
3441 + const ipkg_option_type_t type;
3442 + const void *value;
3445 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3446 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3448 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3449 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3452 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_configure.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_configure.c
3453 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3454 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_configure.c 2005-10-26 17:36:46.000000000 +0200
3456 +/* ipkg_configure.c - the itsy package management system
3460 + Copyright (C) 2001 University of Southern California
3462 + This program is free software; you can redistribute it and/or
3463 + modify it under the terms of the GNU General Public License as
3464 + published by the Free Software Foundation; either version 2, or (at
3465 + your option) any later version.
3467 + This program is distributed in the hope that it will be useful, but
3468 + WITHOUT ANY WARRANTY; without even the implied warranty of
3469 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3470 + General Public License for more details.
3475 +#include "ipkg_configure.h"
3477 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3481 + /* DPKG_INCOMPATIBILITY:
3482 + dpkg actually does some conffile handling here, rather than at the
3483 + end of ipkg_install(). Do we care? */
3484 + /* DPKG_INCOMPATIBILITY:
3485 + dpkg actually includes a version number to this script call */
3486 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3488 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3492 + ipkg_state_changed++;
3496 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_configure.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_configure.h
3497 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3498 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_configure.h 2005-10-26 17:36:46.000000000 +0200
3500 +/* ipkg_configure.h - the itsy package management system
3504 + Copyright (C) 2001 University of Southern California
3506 + This program is free software; you can redistribute it and/or
3507 + modify it under the terms of the GNU General Public License as
3508 + published by the Free Software Foundation; either version 2, or (at
3509 + your option) any later version.
3511 + This program is distributed in the hope that it will be useful, but
3512 + WITHOUT ANY WARRANTY; without even the implied warranty of
3513 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3514 + General Public License for more details.
3517 +#ifndef IPKG_CONFIGURE_H
3518 +#define IPKG_CONFIGURE_H
3520 +#include "ipkg_conf.h"
3522 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3525 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_download.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_download.c
3526 --- busybox-1.00-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3527 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_download.c 2005-10-26 17:36:46.000000000 +0200
3529 +/* ipkg_download.c - the itsy package management system
3533 + Copyright (C) 2001 University of Southern California
3535 + This program is free software; you can redistribute it and/or
3536 + modify it under the terms of the GNU General Public License as
3537 + published by the Free Software Foundation; either version 2, or (at
3538 + your option) any later version.
3540 + This program is distributed in the hope that it will be useful, but
3541 + WITHOUT ANY WARRANTY; without even the implied warranty of
3542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3543 + General Public License for more details.
3547 +#include "ipkg_download.h"
3548 +#include "ipkg_message.h"
3550 +#include "sprintf_alloc.h"
3551 +#include "xsystem.h"
3552 +#include "file_util.h"
3553 +#include "str_util.h"
3555 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3559 + char *src_basec = strdup(src);
3560 + char *src_base = basename(src_basec);
3561 + char *tmp_file_location;
3564 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3568 + if (str_starts_with(src, "file:")) {
3570 + const char *file_src = src + 5;
3571 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3572 + ret = file_copy(src + 5, dest_file_name);
3573 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3577 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3578 + err = unlink(tmp_file_location);
3579 + if (err && errno != ENOENT) {
3580 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3581 + __FUNCTION__, tmp_file_location, strerror(errno));
3582 + free(tmp_file_location);
3586 + if (conf->http_proxy) {
3587 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3588 + setenv("http_proxy", conf->http_proxy, 1);
3590 + if (conf->ftp_proxy) {
3591 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3592 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3594 + if (conf->no_proxy) {
3595 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3596 + setenv("no_proxy", conf->no_proxy, 1);
3599 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3600 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3601 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3602 + conf->proxy_user ? "--proxy-user=" : "",
3603 + conf->proxy_user ? conf->proxy_user : "",
3604 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3605 + conf->proxy_passwd ? conf->proxy_passwd : "",
3606 + conf->verbose_wget ? "" : "-q",
3609 + err = xsystem(cmd);
3612 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3613 + __FUNCTION__, err, cmd);
3615 + unlink(tmp_file_location);
3616 + free(tmp_file_location);
3623 + err = file_move(tmp_file_location, dest_file_name);
3625 + free(tmp_file_location);
3635 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3640 + if (pkg->src == NULL) {
3641 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3642 + pkg->name, pkg->parent->name);
3646 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3648 + /* XXX: BUG: The pkg->filename might be something like
3649 + "../../foo.ipk". While this is correct, and exactly what we
3650 + want to use to construct url above, here we actually need to
3651 + use just the filename part, without any directory. */
3652 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3654 + err = ipkg_download(conf, url, pkg->local_filename);
3661 + * Downloads file from url, installs in package database, return package name.
3663 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3671 + if (str_starts_with(url, "http://")
3672 + || str_starts_with(url, "ftp://")) {
3674 + char *file_basec = strdup(url);
3675 + char *file_base = basename(file_basec);
3677 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3678 + err = ipkg_download(conf, url, tmp_file);
3682 + err = pkg_init_from_file(pkg, tmp_file);
3685 + pkg->local_filename = strdup(tmp_file);
3690 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3691 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3693 + err = pkg_init_from_file(pkg, url);
3696 + pkg->local_filename = strdup(url);
3702 + if (!pkg->architecture) {
3703 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3707 + pkg->dest = conf->default_dest;
3708 + pkg->state_want = SW_INSTALL;
3709 + pkg->state_flag |= SF_PREFER;
3710 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3711 + if ( pkg == NULL ){
3712 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3716 + *namep = pkg->name;
3720 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_download.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_download.h
3721 --- busybox-1.00-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3722 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_download.h 2005-10-26 17:36:46.000000000 +0200
3724 +/* ipkg_download.h - the itsy package management system
3728 + Copyright (C) 2001 University of Southern California
3730 + This program is free software; you can redistribute it and/or
3731 + modify it under the terms of the GNU General Public License as
3732 + published by the Free Software Foundation; either version 2, or (at
3733 + your option) any later version.
3735 + This program is distributed in the hope that it will be useful, but
3736 + WITHOUT ANY WARRANTY; without even the implied warranty of
3737 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3738 + General Public License for more details.
3741 +#ifndef IPKG_DOWNLOAD_H
3742 +#define IPKG_DOWNLOAD_H
3744 +#include "ipkg_conf.h"
3746 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3747 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3749 + * Downloads file from url, installs in package database, return package name.
3751 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3754 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_includes.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_includes.h
3755 --- busybox-1.00-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3756 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_includes.h 2005-10-26 17:36:46.000000000 +0200
3758 +#ifndef IPKG_INCLUDES_H
3759 +#define IPKG_INCLUDES_H
3761 +/* Define to 1 if you have the <memory.h> header file. */
3762 +#define HAVE_MEMORY_H 1
3764 +/* Define to 1 if you have the <regex.h> header file. */
3765 +#define HAVE_REGEX_H 1
3767 +/* Define to 1 if you have the <stdlib.h> header file. */
3768 +#define HAVE_STDLIB_H 1
3770 +/* Define to 1 if you have the <strings.h> header file. */
3771 +#define HAVE_STRINGS_H 1
3773 +/* Define to 1 if you have the <string.h> header file. */
3774 +#define HAVE_STRING_H 1
3776 +/* Define to 1 if you have the <sys/stat.h> header file. */
3777 +#define HAVE_SYS_STAT_H 1
3779 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3780 +#define HAVE_SYS_WAIT_H 1
3782 +/* Define to 1 if you have the <unistd.h> header file. */
3783 +#define HAVE_UNISTD_H 1
3785 +/* Define to 1 if you have the ANSI C header files. */
3786 +#define STDC_HEADERS 1
3792 +# include <stdlib.h>
3793 +# include <stdarg.h>
3794 +# include <stddef.h>
3795 +# include <ctype.h>
3796 +# include <errno.h>
3799 +# include <stdlib.h>
3804 +# include <regex.h>
3808 +# if !STDC_HEADERS && HAVE_MEMORY_H
3809 +# include <memory.h>
3811 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3813 +# define __USE_GNU 1
3815 +# include <string.h>
3820 +# include <strings.h>
3823 +#if HAVE_SYS_STAT_H
3824 +# include <sys/stat.h>
3827 +#if HAVE_SYS_WAIT_H
3828 +# include <sys/wait.h>
3832 +# include <sys/types.h>
3833 +# include <unistd.h>
3836 +#endif /* IPKG_INCLUDES_H */
3837 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_install.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_install.c
3838 --- busybox-1.00-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3839 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_install.c 2005-10-26 17:36:46.000000000 +0200
3841 +/* ipkg_install.c - the itsy package management system
3845 + Copyright (C) 2001 University of Southern California
3847 + This program is free software; you can redistribute it and/or
3848 + modify it under the terms of the GNU General Public License as
3849 + published by the Free Software Foundation; either version 2, or (at
3850 + your option) any later version.
3852 + This program is distributed in the hope that it will be useful, but
3853 + WITHOUT ANY WARRANTY; without even the implied warranty of
3854 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3855 + General Public License for more details.
3860 +#include <dirent.h>
3863 +#include <signal.h>
3864 +typedef void (*sighandler_t)(int);
3867 +#include "pkg_hash.h"
3868 +#include "pkg_extract.h"
3870 +#include "ipkg_install.h"
3871 +#include "ipkg_configure.h"
3872 +#include "ipkg_download.h"
3873 +#include "ipkg_remove.h"
3875 +#include "ipkg_utils.h"
3876 +#include "ipkg_message.h"
3878 +#include "sprintf_alloc.h"
3879 +#include "file_util.h"
3880 +#include "str_util.h"
3881 +#include "xsystem.h"
3884 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3885 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3886 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3888 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3889 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3890 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3891 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3892 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3893 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3894 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3895 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3896 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3897 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3898 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3899 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3901 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3902 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3903 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3904 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3905 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3907 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3909 +static int user_prefers_old_conffile(const char *file, const char *backup);
3911 +static char *backup_filename_alloc(const char *file_name);
3912 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3913 +static int backup_exists_for(const char *file_name);
3914 +static int backup_remove(const char *file_name);
3917 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3921 + char *old_version, *new_version;
3924 + if (pkg == NULL) {
3928 + err = pkg_init_from_file(pkg, filename);
3933 + if (!pkg->architecture) {
3934 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3938 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3939 + freeing the pkg that we pass in. It might be nice to clean this up
3941 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3942 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3944 + pkg->local_filename = strdup(filename);
3947 + old_version = pkg_version_str_alloc(old);
3948 + new_version = pkg_version_str_alloc(pkg);
3950 + cmp = pkg_compare_versions(old, pkg);
3951 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3952 + cmp = -1 ; /* then we force ipkg to downgrade */
3953 + /* We need to use a value < 0 because in the 0 case we are asking to */
3954 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3957 + ipkg_message(conf, IPKG_NOTICE,
3958 + "Not downgrading package %s on %s from %s to %s.\n",
3959 + old->name, old->dest->name, old_version, new_version);
3960 + pkg->state_want = SW_DEINSTALL;
3961 + pkg->state_flag |= SF_OBSOLETE;
3962 + free(old_version);
3963 + free(new_version);
3966 + free(old_version);
3967 + free(new_version);
3971 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3972 + return ipkg_install_pkg(conf, pkg);
3975 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3979 + char *old_version, *new_version;
3981 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3983 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3984 + if (new == NULL) {
3985 + return IPKG_PKG_HAS_NO_CANDIDATE;
3988 + new->state_flag |= SF_USER;
3990 + old_version = pkg_version_str_alloc(old);
3991 + new_version = pkg_version_str_alloc(new);
3993 + cmp = pkg_compare_versions(old, new);
3994 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3995 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3996 + cmp = -1 ; /* then we force ipkg to downgrade */
3997 + /* We need to use a value < 0 because in the 0 case we are asking to */
3998 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4000 + ipkg_message(conf, IPKG_DEBUG,
4001 + "comparing visible versions of pkg %s:"
4002 + "\n\t%s is installed "
4003 + "\n\t%s is available "
4004 + "\n\t%d was comparison result\n",
4005 + pkg_name, old_version, new_version, cmp);
4006 + if (cmp == 0 && !conf->force_reinstall) {
4007 + ipkg_message(conf, IPKG_NOTICE,
4008 + "Package %s (%s) installed in %s is up to date.\n",
4009 + old->name, old_version, old->dest->name);
4010 + free(old_version);
4011 + free(new_version);
4013 + } else if (cmp > 0) {
4014 + ipkg_message(conf, IPKG_NOTICE,
4015 + "Not downgrading package %s on %s from %s to %s.\n",
4016 + old->name, old->dest->name, old_version, new_version);
4017 + free(old_version);
4018 + free(new_version);
4020 + } else if (cmp < 0) {
4021 + new->dest = old->dest;
4022 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4026 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4027 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4028 + return any kind of integer, (might be errno from a syscall,
4029 + etc.). This is a real mess and will need to be cleaned up if
4030 + anyone ever wants to make a nice libipkg. */
4032 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4033 + return ipkg_install_pkg(conf, new);
4036 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4038 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4041 + abstract_pkg_t *ppkg ;
4043 + if (providers == NULL)
4044 + return IPKG_PKG_HAS_NO_CANDIDATE;
4046 + for (i = 0; i < providers->len; i++) {
4047 + ppkg = abstract_pkg_vec_get(providers, i);
4048 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4049 + err = ipkg_install_by_name(conf, ppkg->name);
4052 +/* XXX Maybe ppkg should be freed ? */
4058 + * Walk dependence graph starting with pkg, collect packages to be
4059 + * installed into pkgs_needed, in dependence order.
4061 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4064 + pkg_vec_t *depends = pkg_vec_alloc();
4065 + char **unresolved = NULL;
4068 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4073 + ipkg_message(conf, IPKG_ERROR,
4074 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4075 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4076 + while (*unresolved) {
4077 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4080 + ipkg_message(conf, IPKG_ERROR, "\n");
4081 + if (! conf->force_depends) {
4082 + ipkg_message(conf, IPKG_INFO,
4083 + "This could mean that your package list is out of date or that the packages\n"
4084 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4085 + "of this problem try again with the '-force-depends' option.\n");
4086 + pkg_vec_free(depends);
4087 + return IPKG_PKG_DEPS_UNSATISFIED;
4091 + if (ndepends <= 0) {
4092 + pkg_vec_free(depends);
4096 + for (i = 0; i < depends->len; i++) {
4097 + pkg_t *dep = depends->pkgs[i];
4098 + /* The package was uninstalled when we started, but another
4099 + dep earlier in this loop may have depended on it and pulled
4100 + it in, so check first. */
4101 + if ((dep->state_status != SS_INSTALLED)
4102 + && (dep->state_status != SS_UNPACKED)
4103 + && (dep->state_want != SW_INSTALL)) {
4105 + /* Mark packages as to-be-installed */
4106 + dep->state_want = SW_INSTALL;
4108 + /* Dependencies should be installed the same place as pkg */
4109 + if (dep->dest == NULL) {
4110 + dep->dest = pkg->dest;
4113 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4115 + pkg_vec_free(depends);
4121 + pkg_vec_insert(pkgs_needed, pkg);
4123 + pkg_vec_free(depends);
4128 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4132 + char *old_version, *new_version;
4134 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4136 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4137 + if (new == NULL) {
4138 + return IPKG_PKG_HAS_NO_CANDIDATE;
4141 + old_version = pkg_version_str_alloc(old);
4142 + new_version = pkg_version_str_alloc(new);
4144 + cmp = pkg_compare_versions(old, new);
4145 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4146 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4147 + cmp = -1 ; /* then we force ipkg to downgrade */
4148 + /* We need to use a value < 0 because in the 0 case we are asking to */
4149 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4151 + ipkg_message(conf, IPKG_DEBUG,
4152 + "comparing visible versions of pkg %s:"
4153 + "\n\t%s is installed "
4154 + "\n\t%s is available "
4155 + "\n\t%d was comparison result\n",
4156 + pkg_name, old_version, new_version, cmp);
4157 + if (cmp == 0 && !conf->force_reinstall) {
4158 + ipkg_message(conf, IPKG_NOTICE,
4159 + "Package %s (%s) installed in %s is up to date.\n",
4160 + old->name, old_version, old->dest->name);
4161 + free(old_version);
4162 + free(new_version);
4164 + } else if (cmp > 0) {
4165 + ipkg_message(conf, IPKG_NOTICE,
4166 + "Not downgrading package %s on %s from %s to %s.\n",
4167 + old->name, old->dest->name, old_version, new_version);
4168 + free(old_version);
4169 + free(new_version);
4171 + } else if (cmp < 0) {
4172 + new->dest = old->dest;
4173 + old->state_want = SW_DEINSTALL;
4174 + old->state_flag |= SF_OBSOLETE;
4177 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4182 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4185 + pkg_vec_t *depends = pkg_vec_alloc();
4187 + char **unresolved = NULL;
4190 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4195 + ipkg_message(conf, IPKG_ERROR,
4196 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4197 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4198 + while (*unresolved) {
4199 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4202 + ipkg_message(conf, IPKG_ERROR, "\n");
4203 + if (! conf->force_depends) {
4204 + ipkg_message(conf, IPKG_INFO,
4205 + "This could mean that your package list is out of date or that the packages\n"
4206 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4207 + "of this problem try again with the '-force-depends' option.\n");
4208 + pkg_vec_free(depends);
4209 + return IPKG_PKG_DEPS_UNSATISFIED;
4213 + if (ndepends <= 0) {
4217 + /* Mark packages as to-be-installed */
4218 + for (i=0; i < depends->len; i++) {
4219 + /* Dependencies should be installed the same place as pkg */
4220 + if (depends->pkgs[i]->dest == NULL) {
4221 + depends->pkgs[i]->dest = pkg->dest;
4223 + depends->pkgs[i]->state_want = SW_INSTALL;
4226 + for (i = 0; i < depends->len; i++) {
4227 + dep = depends->pkgs[i];
4228 + /* The package was uninstalled when we started, but another
4229 + dep earlier in this loop may have depended on it and pulled
4230 + it in, so check first. */
4231 + if ((dep->state_status != SS_INSTALLED)
4232 + && (dep->state_status != SS_UNPACKED)) {
4233 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4234 + err = ipkg_install_pkg(conf, dep);
4236 + pkg_vec_free(depends);
4242 + pkg_vec_free(depends);
4248 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4249 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4251 + if (conf->nodeps == 0) {
4253 + pkg_vec_t *installed = pkg_vec_alloc();
4254 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4255 + for (i = 0; i < installed->len; i++) {
4256 + pkg_t *pkg = installed->pkgs[i];
4257 + satisfy_dependencies_for(conf, pkg);
4259 + pkg_vec_free(installed);
4266 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4269 + pkg_vec_t *conflicts = NULL;
4271 + const char *prefix;
4272 + if (conf->force_depends) {
4273 + level = IPKG_NOTICE;
4274 + prefix = "Warning";
4276 + level = IPKG_ERROR;
4280 + if (!conf->force_depends)
4281 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4284 + ipkg_message(conf, level,
4285 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4287 + while (i < conflicts->len)
4288 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4289 + ipkg_message(conf, level, "\n");
4290 + pkg_vec_free(conflicts);
4291 + return IPKG_PKG_DEPS_UNSATISFIED;
4296 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4298 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4299 + str_list_elt_t *iter;
4301 + for (iter = new_list->head; iter; iter = iter->next) {
4302 + char *new_file = iter->data;
4303 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4305 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4306 + if (!owner || (owner == old_pkg))
4307 + file_hash_set_file_owner(conf, new_file, new_pkg);
4310 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4311 + for (iter = old_list->head; iter; iter = iter->next) {
4312 + char *old_file = iter->data;
4313 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4314 + if (owner == old_pkg) {
4316 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4323 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4325 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4327 + /* sma 6.20.02: yup; here's the first bit */
4329 + * XXX: BUG easy for cworth
4330 + * 1) please point the call below to the correct current root destination
4331 + * 2) we need to resolve how to check the required space for a pending pkg,
4332 + * my diddling with the .ipk file size below isn't going to cut it.
4333 + * 3) return a proper error code instead of 1
4335 + int comp_size, blocks_available;
4337 + if (!conf->force_space && pkg->installed_size != NULL) {
4338 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4340 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4341 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4342 + comp_size = (int)((comp_size + 1023) / 1024);
4344 + if (comp_size >= blocks_available) {
4345 + ipkg_message(conf, IPKG_ERROR,
4346 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4347 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4354 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4357 + char *conffiles_file_name;
4359 + FILE *conffiles_file;
4361 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4363 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4364 + if (pkg->tmp_unpack_dir == NULL) {
4365 + ipkg_message(conf, IPKG_ERROR,
4366 + "%s: Failed to create temporary directory '%s': %s\n",
4367 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4371 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4376 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4377 + conffiles. Seems like I should be able to get everything to go
4378 + through pkg_init_from_file. If so, maybe it would make sense to
4379 + move all of unpack_pkg_control_files to that function. */
4381 + /* Don't need to re-read conffiles if we already have it */
4382 + if (pkg->conffiles.head) {
4386 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4387 + if (! file_exists(conffiles_file_name)) {
4388 + free(conffiles_file_name);
4392 + conffiles_file = fopen(conffiles_file_name, "r");
4393 + if (conffiles_file == NULL) {
4394 + fprintf(stderr, "%s: failed to open %s: %s\n",
4395 + __FUNCTION__, conffiles_file_name, strerror(errno));
4396 + free(conffiles_file_name);
4399 + free(conffiles_file_name);
4403 + char *cf_name_in_dest;
4405 + cf_name = file_read_line_alloc(conffiles_file);
4406 + if (cf_name == NULL) {
4409 + str_chomp(cf_name);
4410 + if (cf_name[0] == '\0') {
4414 + /* Prepend dest->root_dir to conffile name.
4415 + Take pains to avoid multiple slashes. */
4416 + root_dir = pkg->dest->root_dir;
4417 + if (conf->offline_root)
4418 + /* skip the offline_root prefix */
4419 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4420 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4421 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4423 + /* Can't get an md5sum now, (file isn't extracted yet).
4424 + We'll wait until resolve_conffiles */
4425 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4428 + free(cf_name_in_dest);
4431 + fclose(conffiles_file);
4436 +/* returns number of installed replacees */
4437 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4439 + abstract_pkg_t **replaces = pkg->replaces;
4440 + int replaces_count = pkg->replaces_count;
4442 + for (i = 0; i < replaces_count; i++) {
4443 + abstract_pkg_t *ab_pkg = replaces[i];
4444 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4446 + for (j = 0; j < pkg_vec->len; j++) {
4447 + pkg_t *replacee = pkg_vec->pkgs[j];
4448 + if (!pkg_conflicts(pkg, replacee))
4450 + if (replacee->state_status == SS_INSTALLED) {
4451 + pkg_vec_insert(installed_replacees, replacee);
4456 + return installed_replacees->len;
4459 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4462 + int replaces_count = replacees->len;
4463 + for (i = 0; i < replaces_count; i++) {
4464 + pkg_t *replacee = replacees->pkgs[i];
4466 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4467 + err = ipkg_remove_pkg(conf, replacee);
4474 +/* to unwind the removal: make sure they are installed */
4475 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4478 + int replaces_count = replacees->len;
4479 + for (i = 0; i < replaces_count; i++) {
4480 + pkg_t *replacee = replacees->pkgs[i];
4481 + if (replacee->state_status != SS_INSTALLED) {
4482 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4483 + err = ipkg_install_pkg(conf, replacee);
4491 +int caught_sigint = 0;
4492 +static void ipkg_install_pkg_sigint_handler(int sig)
4494 + caught_sigint = sig;
4497 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4498 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4501 + char message_out[15];
4502 + char *old_version = pkg_version_str_alloc(old_pkg);
4503 + char *new_version = pkg_version_str_alloc(pkg);
4504 + int cmp = pkg_compare_versions(old_pkg, pkg);
4507 + strncpy (message_out,"Upgrading ",13);
4508 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4509 + cmp = -1 ; /* then we force ipkg to downgrade */
4510 + strncpy (message_out,"Downgrading ",13); /* We need to use a value < 0 because in the 0 case we are asking to */
4511 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4515 + ipkg_message(conf, IPKG_NOTICE,
4516 + "Not downgrading package %s on %s from %s to %s.\n",
4517 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4519 + } else if (cmp < 0) {
4520 + ipkg_message(conf, IPKG_NOTICE,
4521 + "%s %s on %s from %s to %s...\n",
4522 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4523 + pkg->dest = old_pkg->dest;
4525 + } else /* cmp == 0 */ {
4526 + if (conf->force_reinstall) {
4527 + ipkg_message(conf, IPKG_NOTICE,
4528 + "Reinstalling %s (%s) on %s...\n",
4529 + pkg->name, new_version, old_pkg->dest->name);
4530 + pkg->dest = old_pkg->dest;
4533 + ipkg_message(conf, IPKG_NOTICE,
4534 + "Not installing %s (%s) on %s -- already installed.\n",
4535 + pkg->name, new_version, old_pkg->dest->name);
4539 + free(old_version);
4540 + free(new_version);
4543 + char *version = pkg_version_str_alloc(pkg);
4544 + ipkg_message(conf, IPKG_NOTICE,
4545 + "Installing %s (%s) to %s...\n",
4546 + pkg->name, version, pkg->dest->name);
4552 +/* and now the meat... */
4553 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg)
4556 + pkg_t *old_pkg = NULL;
4557 + pkg_vec_t *replacees;
4558 + abstract_pkg_t *ab_pkg = NULL;
4559 + int old_state_flag;
4562 + ipkg_message(conf, IPKG_ERROR,
4563 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4567 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4569 + if (!pkg_arch_supported(conf, pkg)) {
4570 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4571 + pkg->architecture, pkg->name);
4574 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4575 + err = satisfy_dependencies_for(conf, pkg);
4576 + if (err) { return err; }
4578 + ipkg_message(conf, IPKG_NOTICE,
4579 + "Package %s is already installed in %s.\n",
4580 + pkg->name, pkg->dest->name);
4584 + if (pkg->dest == NULL) {
4585 + pkg->dest = conf->default_dest;
4588 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4590 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg);
4591 + if (err) { return err; }
4593 + pkg->state_want = SW_INSTALL;
4594 + if (old_pkg) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4596 + /* Abhaya: conflicts check */
4597 + err = check_conflicts_for(conf, pkg);
4598 + if (err) { return err; }
4600 + /* this setup is to remove the upgrade scenario in the end when
4601 + installing pkg A, A deps B & B deps on A. So both B and A are
4602 + installed. Then A's installation is started resulting in an
4603 + uncecessary upgrade */
4604 + if (pkg->state_status == SS_INSTALLED
4605 + && conf->force_reinstall == 0) return 0;
4607 + err = verify_pkg_installable(conf, pkg);
4608 + if (err) { return err; }
4610 + if (pkg->local_filename == NULL) {
4611 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4613 + ipkg_message(conf, IPKG_ERROR,
4614 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4619 + if (pkg->tmp_unpack_dir == NULL) {
4620 + unpack_pkg_control_files(conf, pkg);
4623 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4624 + err = update_file_ownership(conf, pkg, old_pkg);
4625 + if (err) { return err; }
4627 + if (conf->nodeps == 0) {
4628 + err = satisfy_dependencies_for(conf, pkg);
4629 + if (err) { return err; }
4632 + replacees = pkg_vec_alloc();
4633 + pkg_get_installed_replacees(conf, pkg, replacees);
4635 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4637 + sigset_t newset, oldset;
4638 + sighandler_t old_handler = NULL;
4639 + int use_signal = 0;
4640 + caught_sigint = 0;
4642 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4644 + sigemptyset(&newset);
4645 + sigaddset(&newset, SIGINT);
4646 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4649 + ipkg_state_changed++;
4650 + pkg->state_flag |= SF_FILELIST_CHANGED;
4652 + /* XXX: BUG: we really should treat replacement more like an upgrade
4653 + * Instead, we're going to remove the replacees
4655 + err = pkg_remove_installed_replacees(conf, replacees);
4656 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4658 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4659 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4661 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4662 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4664 + err = preinst_configure(conf, pkg, old_pkg);
4665 + if (err) goto UNWIND_PREINST_CONFIGURE;
4667 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4668 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4670 + err = check_data_file_clashes(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4673 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4674 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4676 + if (conf->noaction) return 0;
4678 + /* point of no return: no unwinding after this */
4679 + if (old_pkg && !conf->force_reinstall) {
4680 + old_pkg->state_want = SW_DEINSTALL;
4682 + if (old_pkg->state_flag & SF_NOPRUNE) {
4683 + ipkg_message(conf, IPKG_INFO,
4684 + " not removing obsolesced files because package marked noprune\n");
4686 + ipkg_message(conf, IPKG_INFO,
4687 + " removing obsolesced files\n");
4688 + remove_obsolesced_files(conf, pkg, old_pkg);
4691 + ipkg_message(conf, IPKG_INFO,
4692 + " installing maintainer scripts\n");
4693 + install_maintainer_scripts(conf, pkg, old_pkg);
4695 + /* the following just returns 0 */
4696 + remove_disappeared(conf, pkg);
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " installing data files\n");
4700 + install_data_files(conf, pkg);
4702 + ipkg_message(conf, IPKG_INFO,
4703 + " resolving conf files\n");
4704 + resolve_conffiles(conf, pkg);
4706 + pkg->state_status = SS_UNPACKED;
4707 + old_state_flag = pkg->state_flag;
4708 + pkg->state_flag &= ~SF_PREFER;
4709 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4711 + if (old_pkg && !conf->force_reinstall) {
4712 + old_pkg->state_status = SS_NOT_INSTALLED;
4715 + time(&pkg->installed_time);
4717 + ipkg_message(conf, IPKG_INFO,
4718 + " cleanup temp files\n");
4719 + cleanup_temporary_files(conf, pkg);
4721 + ab_pkg = pkg->parent;
4723 + ab_pkg->state_status = pkg->state_status;
4725 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4728 + signal(SIGINT, old_handler);
4730 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4735 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4736 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4737 + UNWIND_CHECK_DATA_FILE_CLASHES:
4738 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4739 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4740 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4741 + UNWIND_PREINST_CONFIGURE:
4742 + preinst_configure_unwind(conf, pkg, old_pkg);
4743 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4744 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4745 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4746 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4747 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4748 + pkg_remove_installed_replacees_unwind(conf, replacees);
4750 + ipkg_message(conf, IPKG_INFO,
4751 + " cleanup temp files\n");
4752 + cleanup_temporary_files(conf, pkg);
4754 + ipkg_message(conf, IPKG_INFO,
4757 + signal(SIGINT, old_handler);
4759 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4765 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4767 + /* DPKG_INCOMPATIBILITY:
4768 + dpkg does some things here that we don't do yet. Do we care?
4770 + 1. If a version of the package is already installed, call
4771 + old-prerm upgrade new-version
4772 + 2. If the script runs but exits with a non-zero exit status
4773 + new-prerm failed-upgrade old-version
4774 + Error unwind, for both the above cases:
4775 + old-postinst abort-upgrade new-version
4780 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4782 + /* DPKG_INCOMPATIBILITY:
4783 + dpkg does some things here that we don't do yet. Do we care?
4784 + (See prerm_upgrade_old_package for details)
4789 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4793 + 2. If a 'conflicting' package is being removed at the same time:
4794 + 1. If any packages depended on that conflicting package and
4795 + --auto-deconfigure is specified, call, for each such package:
4796 + deconfigured's-prerm deconfigure \
4797 + in-favour package-being-installed version \
4798 + removing conflicting-package version
4800 + deconfigured's-postinst abort-deconfigure \
4801 + in-favour package-being-installed-but-failed version \
4802 + removing conflicting-package version
4804 + The deconfigured packages are marked as requiring
4805 + configuration, so that if --install is used they will be
4806 + configured again if possible.
4807 + 2. To prepare for removal of the conflicting package, call:
4808 + conflictor's-prerm remove in-favour package new-version
4810 + conflictor's-postinst abort-remove in-favour package new-version
4815 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4817 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4818 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4823 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4826 + char *preinst_args;
4829 + char *old_version = pkg_version_str_alloc(old_pkg);
4830 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4831 + free(old_version);
4832 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4833 + char *pkg_version = pkg_version_str_alloc(pkg);
4834 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4835 + free(pkg_version);
4837 + preinst_args = strdup("install");
4840 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4842 + ipkg_message(conf, IPKG_ERROR,
4843 + "Aborting installation of %s\n", pkg->name);
4847 + free(preinst_args);
4852 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4854 + /* DPKG_INCOMPATIBILITY:
4855 + dpkg does the following error unwind, should we?
4856 + pkg->postrm abort-upgrade old-version
4857 + OR pkg->postrm abort-install old-version
4858 + OR pkg->postrm abort-install
4863 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4866 + conffile_list_elt_t *iter;
4869 + if (conf->noaction) return 0;
4871 + /* Backup all modified conffiles */
4873 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4877 + cf_name = root_filename_alloc(conf, cf->name);
4879 + /* Don't worry if the conffile is just plain gone */
4880 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4881 + err = backup_make_backup(conf, cf_name);
4890 + /* Backup all conffiles that were not conffiles in old_pkg */
4891 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4894 + cf_name = root_filename_alloc(conf, cf->name);
4895 + /* Ignore if this was a conffile in old_pkg as well */
4896 + if (pkg_get_conffile(old_pkg, cf->name)) {
4900 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4901 + err = backup_make_backup(conf, cf_name);
4912 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4914 + conffile_list_elt_t *iter;
4917 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4918 + backup_remove(iter->data->name);
4922 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4923 + backup_remove(iter->data->name);
4929 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4931 + /* DPKG_INCOMPATIBILITY:
4932 + ipkg takes a slightly different approach than dpkg at this
4933 + point. dpkg installs each file in the new package while
4934 + creating a backup for any file that is replaced, (so that it
4935 + can unwind if necessary). To avoid complexity and redundant
4936 + storage, ipkg doesn't do any installation until later, (at the
4937 + point at which dpkg removes the backups.
4939 + But, we do have to check for data file clashes, since after
4940 + installing a package with a file clash, removing either of the
4941 + packages involved in the clash has the potential to break the
4944 + str_list_t *files_list;
4945 + str_list_elt_t *iter;
4949 + files_list = pkg_get_installed_files(pkg);
4950 + for (iter = files_list->head; iter; iter = iter->next) {
4951 + char *root_filename;
4952 + char *filename = iter->data;
4953 + root_filename = root_filename_alloc(conf, filename);
4954 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4957 + /* Pre-existing conffiles are OK */
4958 + /* @@@@ should have way to check that it is a conffile -Jamey */
4959 + if (backup_exists_for(root_filename)) {
4963 + /* Pre-existing files are OK if force-overwrite was asserted. */
4964 + if (conf->force_overwrite) {
4965 + /* but we need to change who owns this file */
4966 + file_hash_set_file_owner(conf, filename, pkg);
4970 + owner = file_hash_get_file_owner(conf, filename);
4972 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4973 + if (owner && old_pkg) {
4974 + if (strcmp(owner->name, old_pkg->name) == 0) {
4979 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4981 + if (pkg_replaces(pkg, owner)) {
4982 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4985 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4986 + then it's ok to overwrite. */
4987 + if (strcmp(owner->name,pkg->name)==0){
4988 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4993 + /* Pre-existing files are OK if they are obsolete */
4994 + obs = hash_table_get(&conf->obs_file_hash, filename);
4996 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5000 + /* We have found a clash. */
5001 + ipkg_message(conf, IPKG_ERROR,
5002 + "Package %s wants to install file %s\n"
5003 + "\tBut that file is already provided by package ",
5004 + pkg->name, filename);
5006 + ipkg_message(conf, IPKG_ERROR,
5007 + "%s\n", owner->name);
5009 + ipkg_message(conf, IPKG_ERROR,
5010 + "<no package>\nPlease move this file out of the way and try again.\n");
5014 + free(root_filename);
5016 + pkg_free_installed_files(pkg);
5021 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5023 + /* Nothing to do since check_data_file_clashes doesn't change state */
5027 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5029 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5030 + 1. If the package is being upgraded, call
5031 + old-postrm upgrade new-version
5032 + 2. If this fails, attempt:
5033 + new-postrm failed-upgrade old-version
5034 + Error unwind, for both cases:
5035 + old-preinst abort-upgrade new-version */
5039 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5041 + /* DPKG_INCOMPATIBILITY:
5042 + dpkg does some things here that we don't do yet. Do we care?
5043 + (See postrm_upgrade_old_pkg for details)
5048 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5051 + str_list_t *old_files;
5052 + str_list_elt_t *of;
5053 + str_list_t *new_files;
5054 + str_list_elt_t *nf;
5056 + if (old_pkg == NULL) {
5060 + old_files = pkg_get_installed_files(old_pkg);
5061 + new_files = pkg_get_installed_files(pkg);
5063 + for (of = old_files->head; of; of = of->next) {
5067 + for (nf = new_files->head; nf; nf = nf->next) {
5069 + if (strcmp(old, new) == 0) {
5070 + goto NOT_OBSOLETE;
5073 + if (file_is_dir(old)) {
5076 + owner = file_hash_get_file_owner(conf, old);
5077 + if (owner != old_pkg) {
5078 + /* in case obsolete file no longer belongs to old_pkg */
5082 + /* old file is obsolete */
5083 + ipkg_message(conf, IPKG_INFO,
5084 + " removing obsolete file %s\n", old);
5085 + if (!conf->noaction) {
5086 + err = unlink(old);
5088 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5097 + pkg_free_installed_files(old_pkg);
5098 + pkg_free_installed_files(pkg);
5103 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5107 + char *globpattern;
5111 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5114 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5115 + err = glob(globpattern, 0, NULL, &globbuf);
5116 + free(globpattern);
5120 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5121 + for (i = 0; i < globbuf.gl_pathc; i++) {
5122 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5123 + globbuf.gl_pathv[i], old_pkg->name);
5124 + if (!conf->noaction)
5125 + unlink(globbuf.gl_pathv[i]);
5127 + globfree(&globbuf);
5132 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5138 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5139 + sprintf_alloc(&prefix, "%s.", pkg->name);
5140 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5141 + pkg->dest->info_dir,
5147 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5149 + /* DPKG_INCOMPATIBILITY:
5150 + This is a fairly sophisticated dpkg operation. Shall we
5153 + /* Any packages all of whose files have been overwritten during the
5154 + installation, and which aren't required for dependencies, are
5155 + considered to have been removed. For each such package
5156 + 1. disappearer's-postrm disappear overwriter overwriter-version
5157 + 2. The package's maintainer scripts are removed
5158 + 3. It is noted in the status database as being in a sane state,
5159 + namely not installed (any conffiles it may have are ignored,
5160 + rather than being removed by dpkg). Note that disappearing
5161 + packages do not have their prerm called, because dpkg doesn't
5162 + know in advance that the package is going to vanish.
5167 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5171 + /* ipkg takes a slightly different approach to data file backups
5172 + than dpkg. Rather than removing backups at this point, we
5173 + actually do the data file installation now. See comments in
5174 + check_data_file_clashes() for more details. */
5176 + ipkg_message(conf, IPKG_INFO,
5177 + " extracting data files to %s\n", pkg->dest->root_dir);
5178 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5183 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5184 + so we can't save ourself from removing important packages
5185 + At this point we (should) have extracted the .control file, so it
5186 + would be a good idea to reload the data in it, and set the Essential
5187 + state in *pkg. From now on the Essential is back in status file and
5188 + we can protect again.
5189 + We should operate this way:
5190 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5191 + check for "Essential" in it
5192 + set the value in pkg->essential.
5193 + This new routine could be useful also for every other flag
5194 + Pigi: 16/03/2004 */
5195 + set_flags_from_control(conf, pkg) ;
5197 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5198 + err = pkg_write_filelist(conf, pkg);
5202 + /* XXX: FEATURE: ipkg should identify any files which existed
5203 + before installation and which were overwritten, (see
5204 + check_data_file_clashes()). What it must do is remove any such
5205 + files from the filelist of the old package which provided the
5206 + file. Otherwise, if the old package were removed at some point
5207 + it would break the new package. Removing the new package will
5208 + also break the old one, but this cannot be helped since the old
5209 + package's file has already been deleted. This is the importance
5210 + of check_data_file_clashes(), and only allowing ipkg to install
5211 + a clashing package with a user force. */
5216 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5218 + conffile_list_elt_t *iter;
5225 + if (conf->noaction) return 0;
5227 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5228 + char *root_filename;
5230 + root_filename = root_filename_alloc(conf, cf->name);
5232 + /* Might need to initialize the md5sum for each conffile */
5233 + if (cf->value == NULL) {
5234 + cf->value = file_md5sum_alloc(root_filename);
5237 + if (!file_exists(root_filename)) {
5238 + free(root_filename);
5242 + cf_backup = backup_filename_alloc(root_filename);
5245 + if (file_exists(cf_backup)) {
5246 + /* Let's compute md5 to test if files are changed */
5247 + md5sum = file_md5sum_alloc(cf_backup);
5248 + if (strcmp( cf->value,md5sum) != 0 ) {
5249 + if (conf->force_defaults
5250 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5251 + rename(cf_backup, root_filename);
5254 + unlink(cf_backup);
5259 + free(root_filename);
5265 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5268 + const char *short_file_name;
5270 + short_file_name = strrchr(file_name, '/');
5271 + if (short_file_name) {
5272 + short_file_name++;
5274 + short_file_name = file_name;
5278 + response = get_user_response(" Configuration file '%s'\n"
5279 + " ==> File on system created by you or by a script.\n"
5280 + " ==> File also in package provided by package maintainer.\n"
5281 + " What would you like to do about it ? Your options are:\n"
5282 + " Y or I : install the package maintainer's version\n"
5283 + " N or O : keep your currently-installed version\n"
5284 + " D : show the differences between the versions (if diff is installed)\n"
5285 + " The default action is to keep your current version.\n"
5286 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5287 + if (strcmp(response, "y") == 0
5288 + || strcmp(response, "i") == 0
5289 + || strcmp(response, "yes") == 0) {
5294 + if (strcmp(response, "d") == 0) {
5298 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5299 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5302 + printf(" [Press ENTER to continue]\n");
5303 + response = file_read_line_alloc(stdin);
5313 +/* XXX: CLEANUP: I'd like to move all of the code for
5314 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5315 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5316 + pkg_deinit for example). */
5317 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5320 + struct dirent *dirent;
5323 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5325 + ipkg_message(conf, IPKG_DEBUG,
5326 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5327 + __FUNCTION__, pkg->tmp_unpack_dir);
5331 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5332 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5335 + dirent = readdir(tmp_dir);
5336 + if (dirent == NULL) {
5339 + sprintf_alloc(&tmp_file, "%s/%s",
5340 + pkg->tmp_unpack_dir, dirent->d_name);
5341 + if (! file_is_dir(tmp_file)) {
5346 + closedir(tmp_dir);
5347 + rmdir(pkg->tmp_unpack_dir);
5348 + free(pkg->tmp_unpack_dir);
5349 + pkg->tmp_unpack_dir = NULL;
5353 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5354 + pkg->name, pkg->local_filename, conf->tmp_dir);
5355 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5356 + unlink(pkg->local_filename);
5357 + free(pkg->local_filename);
5358 + pkg->local_filename = NULL;
5364 +static char *backup_filename_alloc(const char *file_name)
5368 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5373 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5378 + backup = backup_filename_alloc(file_name);
5379 + err = file_copy(file_name, backup);
5381 + ipkg_message(conf, IPKG_ERROR,
5382 + "%s: Failed to copy %s to %s\n",
5383 + __FUNCTION__, file_name, backup);
5391 +static int backup_exists_for(const char *file_name)
5396 + backup = backup_filename_alloc(file_name);
5398 + ret = file_exists(backup);
5405 +static int backup_remove(const char *file_name)
5409 + backup = backup_filename_alloc(file_name);
5418 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5420 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5422 + /* first, remove the packages that need removing */
5423 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5424 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5425 + err = ipkg_remove_pkg(conf, pkg);
5426 + if (err) return err;
5431 +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)
5434 + /* now one more pass checking on the ones that need to be installed */
5435 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5436 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5437 + if (pkg->dest == NULL)
5438 + pkg->dest = conf->default_dest;
5440 + pkg->state_want = SW_INSTALL;
5442 + /* Abhaya: conflicts check */
5443 + err = check_conflicts_for(conf, pkg);
5444 + if (err) { return err; }
5449 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5452 + /* now one more pass checking on the ones that need to be installed */
5453 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5454 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5456 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5457 + pkg_vec_t *replacees = pkg_vec_alloc();
5458 + pkg_get_installed_replacees(conf, pkg, replacees);
5460 + /* XXX: BUG: we really should treat replacement more like an upgrade
5461 + * Instead, we're going to remove the replacees
5463 + err = pkg_remove_installed_replacees(conf, replacees);
5464 + if (err) return err;
5465 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5470 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5473 + /* now one more pass checking on the ones that need to be installed */
5474 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5475 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5476 + if (pkg->local_filename == NULL) {
5477 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5479 + ipkg_message(conf, IPKG_ERROR,
5480 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5485 + if (pkg->tmp_unpack_dir == NULL) {
5486 + err = unpack_pkg_control_files(conf, pkg);
5487 + if (err) return err;
5493 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5496 + /* now one more pass checking on the ones that need to be installed */
5497 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5498 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5499 + pkg_t *old_pkg = pkg->old_pkg;
5501 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5502 + if (err) return err;
5504 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5505 + if (err) return err;
5507 + err = preinst_configure(conf, pkg, old_pkg);
5508 + if (err) return err;
5510 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5511 + if (err) return err;
5513 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5514 + if (err) return err;
5519 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5522 + /* now one more pass checking on the ones that need to be installed */
5523 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5524 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5525 + pkg_t *old_pkg = pkg->old_pkg;
5528 + old_pkg->state_want = SW_DEINSTALL;
5530 + if (old_pkg->state_flag & SF_NOPRUNE) {
5531 + ipkg_message(conf, IPKG_INFO,
5532 + " not removing obsolesced files because package marked noprune\n");
5534 + ipkg_message(conf, IPKG_INFO,
5535 + " removing obsolesced files\n");
5536 + remove_obsolesced_files(conf, pkg, old_pkg);
5540 + ipkg_message(conf, IPKG_INFO,
5541 + " installing maintainer scripts\n");
5542 + install_maintainer_scripts(conf, pkg, old_pkg);
5544 + /* the following just returns 0 */
5545 + remove_disappeared(conf, pkg);
5547 + ipkg_message(conf, IPKG_INFO,
5548 + " installing data files\n");
5549 + install_data_files(conf, pkg);
5551 + ipkg_message(conf, IPKG_INFO,
5552 + " resolving conf files\n");
5553 + resolve_conffiles(conf, pkg);
5555 + pkg->state_status = SS_UNPACKED;
5558 + old_pkg->state_status = SS_NOT_INSTALLED;
5561 + time(&pkg->installed_time);
5563 + ipkg_message(conf, IPKG_INFO,
5564 + " cleanup temp files\n");
5565 + cleanup_temporary_files(conf, pkg);
5568 + pkg->parent->state_status = pkg->state_status;
5573 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5576 + /* now one more pass checking on the ones that need to be installed */
5577 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5578 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5579 + pkg_t *old_pkg = pkg->old_pkg;
5582 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5583 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5584 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5585 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5586 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5587 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5588 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5589 + preinst_configure_unwind(conf, pkg, old_pkg);
5590 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5591 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5592 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5593 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5595 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5596 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5604 + * Perform all the actions.
5606 + * pkgs_to_remove are packages marked for removal.
5607 + * pkgs_superseded are the old packages being replaced by upgrades.
5609 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5611 +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)
5616 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5617 + if (err) return err;
5619 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5620 + if (err) return err;
5622 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5623 + if (err) goto UNWIND;
5625 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5626 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5627 + if (err) goto UNWIND;
5630 + * Now that we have the packages unpacked, we can look for data
5631 + * file clashes. First, we mark the files from the superseded
5632 + * packages as obsolete. Then we scan the files in
5633 + * pkgs_to_install, and only complain about clashes with
5634 + * non-obsolete files.
5637 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5638 + if (err) goto UNWIND;
5640 + /* this was before checking data file clashes */
5641 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5642 + if (err) goto UNWIND;
5644 + /* point of no return: no unwinding after this */
5645 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5646 + if (err) return err;
5648 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5652 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5654 + ipkg_message(conf, IPKG_INFO,
5655 + " cleanup temp files\n");
5656 + cleanup_temporary_files(conf, pkg);
5658 + ipkg_message(conf, IPKG_INFO,
5664 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_install.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_install.h
5665 --- busybox-1.00-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5666 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_install.h 2005-10-26 17:36:46.000000000 +0200
5668 +/* ipkg_install.h - the itsy package management system
5672 + Copyright (C) 2001 University of Southern California
5674 + This program is free software; you can redistribute it and/or
5675 + modify it under the terms of the GNU General Public License as
5676 + published by the Free Software Foundation; either version 2, or (at
5677 + your option) any later version.
5679 + This program is distributed in the hope that it will be useful, but
5680 + WITHOUT ANY WARRANTY; without even the implied warranty of
5681 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5682 + General Public License for more details.
5685 +#ifndef IPKG_INSTALL_H
5686 +#define IPKG_INSTALL_H
5689 +#include "ipkg_conf.h"
5691 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5692 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5693 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5694 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg);
5695 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5697 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5699 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5700 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5703 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_message.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_message.c
5704 --- busybox-1.00-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5705 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_message.c 2005-10-26 17:36:46.000000000 +0200
5707 +/* ipkg_message.c - the itsy package management system
5709 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5711 + This program is free software; you can redistribute it and/or
5712 + modify it under the terms of the GNU General Public License as
5713 + published by the Free Software Foundation; either version 2, or (at
5714 + your option) any later version.
5716 + This program is distributed in the hope that it will be useful, but
5717 + WITHOUT ANY WARRANTY; without even the implied warranty of
5718 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5719 + General Public License for more details.
5724 +#include "ipkg_conf.h"
5725 +#include "ipkg_message.h"
5730 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5734 + if (conf && (conf->verbosity < level))
5741 + va_start (ap, fmt);
5742 + vprintf (fmt, ap);
5749 +#include "libipkg.h"
5751 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5754 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5759 + if (ipkg_cb_message)
5761 + va_start (ap, fmt);
5762 + vsnprintf (ts,256,fmt, ap);
5764 + ipkg_cb_message(conf,level,ts);
5768 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_message.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_message.h
5769 --- busybox-1.00-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5770 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_message.h 2005-10-26 17:36:46.000000000 +0200
5772 +/* ipkg_message.h - the itsy package management system
5774 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5776 + This program is free software; you can redistribute it and/or
5777 + modify it under the terms of the GNU General Public License as
5778 + published by the Free Software Foundation; either version 2, or (at
5779 + your option) any later version.
5781 + This program is distributed in the hope that it will be useful, but
5782 + WITHOUT ANY WARRANTY; without even the implied warranty of
5783 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5784 + General Public License for more details.
5787 +#ifndef _IPKG_MESSAGE_H_
5788 +#define _IPKG_MESSAGE_H_
5791 +#include "ipkg_conf.h"
5794 + IPKG_ERROR, /* error conditions */
5795 + IPKG_NOTICE, /* normal but significant condition */
5796 + IPKG_INFO, /* informational message */
5797 + IPKG_DEBUG, /* debug level message */
5798 + IPKG_DEBUG2, /* more debug level message */
5801 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5803 +#endif /* _IPKG_MESSAGE_H_ */
5804 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_remove.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_remove.c
5805 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5806 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_remove.c 2005-10-26 17:45:58.000000000 +0200
5808 +/* ipkg_remove.c - the itsy package management system
5812 + Copyright (C) 2001 University of Southern California
5814 + This program is free software; you can redistribute it and/or
5815 + modify it under the terms of the GNU General Public License as
5816 + published by the Free Software Foundation; either version 2, or (at
5817 + your option) any later version.
5819 + This program is distributed in the hope that it will be useful, but
5820 + WITHOUT ANY WARRANTY; without even the implied warranty of
5821 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5822 + General Public License for more details.
5826 +#include "ipkg_message.h"
5830 +#include "ipkg_remove.h"
5832 +#include "file_util.h"
5833 +#include "sprintf_alloc.h"
5834 +#include "str_util.h"
5836 +#include "ipkg_cmd.h"
5838 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
5839 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5840 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg);
5843 + * Returns number of the number of packages depending on the packages provided by this package.
5844 + * Every package implicitly provides itself.
5846 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5848 + int nprovides = pkg->provides_count;
5849 + abstract_pkg_t **provides = pkg->provides;
5850 + int n_installed_dependents = 0;
5852 + for (i = 0; i <= nprovides; i++) {
5853 + abstract_pkg_t *providee = provides[i];
5854 + abstract_pkg_t **dependers = providee->depended_upon_by;
5855 + abstract_pkg_t *dep_ab_pkg;
5856 + if (dependers == NULL)
5858 + while ((dep_ab_pkg = *dependers++) != NULL) {
5859 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5860 + n_installed_dependents++;
5865 + /* if caller requested the set of installed dependents */
5866 + if (pdependents) {
5868 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5870 + if ( dependents == NULL ){
5871 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5875 + *pdependents = dependents;
5876 + for (i = 0; i <= nprovides; i++) {
5877 + abstract_pkg_t *providee = provides[i];
5878 + abstract_pkg_t **dependers = providee->depended_upon_by;
5879 + abstract_pkg_t *dep_ab_pkg;
5880 + if (dependers == NULL)
5882 + while ((dep_ab_pkg = *dependers++) != NULL) {
5883 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5884 + dependents[p++] = dep_ab_pkg;
5885 + dep_ab_pkg->state_flag |= SF_MARKED;
5889 + dependents[p] = NULL;
5890 + /* now clear the marks */
5891 + for (i = 0; i < p; i++) {
5892 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5893 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5896 + return n_installed_dependents;
5899 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5904 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5905 + abstract_pkg_t * ab_pkg;
5907 + if((ab_pkg = pkg->parent) == NULL){
5908 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5909 + __FUNCTION__, pkg->name);
5913 + if (dependents == NULL)
5916 + // here i am using the dependencies_checked
5917 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5918 + return 0; // has already been encountered in the process
5919 + // of marking packages for removal - Karthik
5920 + ab_pkg->dependencies_checked = 2;
5924 + while (dependents [i] != NULL) {
5925 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5927 + if (dep_ab_pkg->dependencies_checked == 2){
5931 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5932 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5933 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5934 + if (dep_pkg->state_status == SS_INSTALLED) {
5935 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5941 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5942 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5949 + for (i = 0; i < dependent_pkgs->len; i++) {
5950 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5957 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5959 + abstract_pkg_t *dep_ab_pkg;
5960 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5961 + while ((dep_ab_pkg = *dependents++) != NULL) {
5962 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5963 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5965 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5966 + ipkg_message(conf, IPKG_ERROR, "");
5967 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5968 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5969 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5970 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5971 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5975 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5978 + abstract_pkg_t *parent_pkg = NULL;
5980 + if (pkg->essential) {
5981 + if (conf->force_removal_of_essential_packages) {
5982 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5983 + "\tIf your system breaks, you get to keep both pieces\n",
5986 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5987 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5988 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5989 + "\tits will with the option: -force-removal-of-essential-packages\n",
5991 + return IPKG_PKG_IS_ESSENTIAL;
5995 + if ((parent_pkg = pkg->parent) == NULL)
5998 + /* only attempt to remove dependent installed packages if
5999 + * force_depends is not specified or the package is being
6002 + if (!conf->force_depends
6003 + && !(pkg->state_flag & SF_REPLACE)) {
6004 + abstract_pkg_t **dependents;
6005 + int has_installed_dependents =
6006 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6008 + if (has_installed_dependents) {
6010 + * if this package is depended up by others, then either we should
6011 + * not remove it or we should remove it and all of its dependents
6014 + if (!conf->force_removal_of_dependent_packages
6015 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6016 + return IPKG_PKG_HAS_DEPENDENTS;
6019 + /* remove packages depending on this package - Karthik */
6020 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6022 + if (err) return err;
6026 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6029 + pkg->state_flag |= SF_FILELIST_CHANGED;
6031 + pkg->state_want = SW_DEINSTALL;
6032 + ipkg_state_changed++;
6034 + pkg_run_script(conf, pkg, "prerm", "remove");
6036 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6037 + maintains an empty filelist rather than deleting it. That seems
6038 + like a big pain, and I don't see that that should make a big
6039 + difference, but for anyone who wants tighter compatibility,
6040 + feel free to fix this. */
6041 + remove_data_files_and_list(conf, pkg);
6043 + pkg_run_script(conf, pkg, "postrm", "remove");
6045 + remove_maintainer_scripts_except_postrm(conf, pkg);
6047 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6048 + * space, it doesn't make sense to leave extra configurations, files,
6049 + * and maintainer scripts left around. So, we make remove like purge,
6050 + * and take out all the crap :) */
6052 + remove_postrm(conf, pkg);
6053 + pkg->state_status = SS_NOT_INSTALLED;
6056 + parent_pkg->state_status = SS_NOT_INSTALLED;
6061 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6063 + ipkg_remove_pkg(conf, pkg);
6067 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6069 + str_list_t installed_dirs;
6070 + str_list_t *installed_files;
6071 + str_list_elt_t *iter;
6073 + conffile_t *conffile;
6074 + int removed_a_dir;
6077 + str_list_init(&installed_dirs);
6078 + installed_files = pkg_get_installed_files(pkg);
6080 + for (iter = installed_files->head; iter; iter = iter->next) {
6081 + file_name = iter->data;
6083 + if (file_is_dir(file_name)) {
6084 + str_list_append(&installed_dirs, strdup(file_name));
6088 + conffile = pkg_get_conffile(pkg, file_name);
6090 + /* XXX: QUESTION: Is this right? I figure we only need to
6091 + save the conffile if it has been modified. Is that what
6092 + dpkg does? Or does dpkg preserve all conffiles? If so,
6093 + this seems like a better thing to do to conserve
6095 + if (conffile_has_been_modified(conf, conffile)) {
6096 + printf(" not deleting modified conffile %s\n", file_name);
6102 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6103 + if (!conf->noaction)
6104 + unlink(file_name);
6107 + if (!conf->noaction) {
6109 + removed_a_dir = 0;
6110 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6111 + file_name = iter->data;
6113 + if (rmdir(file_name) == 0) {
6114 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6115 + removed_a_dir = 1;
6116 + str_list_remove(&installed_dirs, &iter);
6119 + } while (removed_a_dir);
6122 + pkg_free_installed_files(pkg);
6123 + /* We have to remove the file list now, so that
6124 + find_pkg_owning_file does not always just report this package */
6125 + pkg_remove_installed_files_list(conf, pkg);
6127 + /* Don't print warning for dirs that are provided by other packages */
6128 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6129 + file_name = iter->data;
6131 + owner = file_hash_get_file_owner(conf, file_name);
6134 + iter->data = NULL;
6135 + str_list_remove(&installed_dirs, &iter);
6140 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6142 + iter->data = NULL;
6144 + str_list_deinit(&installed_dirs);
6149 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6152 + char *globpattern;
6155 + if (conf->noaction) return 0;
6157 + sprintf_alloc(&globpattern, "%s/%s.*",
6158 + pkg->dest->info_dir, pkg->name);
6159 + err = glob(globpattern, 0, NULL, &globbuf);
6160 + free(globpattern);
6165 + for (i = 0; i < globbuf.gl_pathc; i++) {
6166 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6169 + unlink(globbuf.gl_pathv[i]);
6171 + globfree(&globbuf);
6176 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6178 + char *postrm_file_name;
6180 + if (conf->noaction) return 0;
6182 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6183 + pkg->dest->info_dir, pkg->name);
6184 + unlink(postrm_file_name);
6185 + free(postrm_file_name);
6189 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_remove.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_remove.h
6190 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6191 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_remove.h 2005-10-26 17:36:46.000000000 +0200
6193 +/* ipkg_remove.h - the itsy package management system
6197 + Copyright (C) 2001 University of Southern California
6199 + This program is free software; you can redistribute it and/or
6200 + modify it under the terms of the GNU General Public License as
6201 + published by the Free Software Foundation; either version 2, or (at
6202 + your option) any later version.
6204 + This program is distributed in the hope that it will be useful, but
6205 + WITHOUT ANY WARRANTY; without even the implied warranty of
6206 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6207 + General Public License for more details.
6210 +#ifndef IPKG_REMOVE_H
6211 +#define IPKG_REMOVE_H
6214 +#include "ipkg_conf.h"
6216 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6217 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6218 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6219 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6222 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_upgrade.c
6223 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6224 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_upgrade.c 2005-10-26 17:36:46.000000000 +0200
6226 +/* ipkg_upgrade.c - the itsy package management system
6229 + Copyright (C) 2001 University of Southern California
6231 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6233 + This program is free software; you can redistribute it and/or
6234 + modify it under the terms of the GNU General Public License as
6235 + published by the Free Software Foundation; either version 2, or (at
6236 + your option) any later version.
6238 + This program is distributed in the hope that it will be useful, but
6239 + WITHOUT ANY WARRANTY; without even the implied warranty of
6240 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6241 + General Public License for more details.
6245 +#include "ipkg_install.h"
6246 +#include "ipkg_message.h"
6248 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6252 + char *old_version, *new_version;
6254 + if (old->state_flag & SF_HOLD) {
6255 + ipkg_message(conf, IPKG_NOTICE,
6256 + "Not upgrading package %s which is marked "
6257 + "hold (flags=%#x)\n", old->name, old->state_flag);
6261 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6262 + if (new == NULL) {
6263 + old_version = pkg_version_str_alloc(old);
6264 + ipkg_message(conf, IPKG_NOTICE,
6265 + "Assuming locally installed package %s (%s) "
6266 + "is up to date.\n", old->name, old_version);
6267 + free(old_version);
6271 + old_version = pkg_version_str_alloc(old);
6272 + new_version = pkg_version_str_alloc(new);
6274 + cmp = pkg_compare_versions(old, new);
6275 + ipkg_message(conf, IPKG_DEBUG,
6276 + "comparing visible versions of pkg %s:"
6277 + "\n\t%s is installed "
6278 + "\n\t%s is available "
6279 + "\n\t%d was comparison result\n",
6280 + old->name, old_version, new_version, cmp);
6282 + ipkg_message(conf, IPKG_INFO,
6283 + "Package %s (%s) installed in %s is up to date.\n",
6284 + old->name, old_version, old->dest->name);
6285 + free(old_version);
6286 + free(new_version);
6288 + } else if (cmp > 0) {
6289 + ipkg_message(conf, IPKG_NOTICE,
6290 + "Not downgrading package %s on %s from %s to %s.\n",
6291 + old->name, old->dest->name, old_version, new_version);
6292 + free(old_version);
6293 + free(new_version);
6295 + } else if (cmp < 0) {
6296 + new->dest = old->dest;
6297 + old->state_want = SW_DEINSTALL;
6300 + new->state_flag |= SF_USER;
6301 + return ipkg_install_pkg(conf, new);
6303 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_upgrade.h
6304 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6305 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_upgrade.h 2005-10-26 17:36:46.000000000 +0200
6307 +/* ipkg_upgrade.c - the itsy package management system
6309 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6311 + This program is free software; you can redistribute it and/or
6312 + modify it under the terms of the GNU General Public License as
6313 + published by the Free Software Foundation; either version 2, or (at
6314 + your option) any later version.
6316 + This program is distributed in the hope that it will be useful, but
6317 + WITHOUT ANY WARRANTY; without even the implied warranty of
6318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6319 + General Public License for more details.
6324 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6325 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.c busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_utils.c
6326 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6327 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_utils.c 2005-10-26 17:36:46.000000000 +0200
6329 +/* ipkg_utils.c - the itsy package management system
6333 + Copyright (C) 2002 Compaq Computer Corporation
6335 + This program is free software; you can redistribute it and/or
6336 + modify it under the terms of the GNU General Public License as
6337 + published by the Free Software Foundation; either version 2, or (at
6338 + your option) any later version.
6340 + This program is distributed in the hope that it will be useful, but
6341 + WITHOUT ANY WARRANTY; without even the implied warranty of
6342 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6343 + General Public License for more details.
6349 +#include <sys/vfs.h>
6351 +#include "ipkg_utils.h"
6353 +#include "pkg_hash.h"
6355 +struct errlist* error_list;
6357 +int get_available_blocks(char * filesystem)
6359 + struct statfs sfs;
6361 + if(statfs(filesystem, &sfs)){
6362 + fprintf(stderr, "bad statfs\n");
6365 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6366 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6369 +char **read_raw_pkgs_from_file(const char *file_name)
6374 + if(!(fp = fopen(file_name, "r"))){
6375 + fprintf(stderr, "can't get %s open for read\n", file_name);
6379 + ret = read_raw_pkgs_from_stream(fp);
6386 +char **read_raw_pkgs_from_stream(FILE *fp)
6388 + char **raw = NULL, *buf, *scout;
6390 + size_t size = 512;
6392 + buf = malloc (size);
6394 + while (fgets(buf, size, fp)) {
6395 + while (strlen (buf) == (size - 1)
6396 + && buf[size-2] != '\n') {
6397 + size_t o = size - 1;
6399 + buf = realloc (buf, size);
6400 + if (fgets (buf + o, size - o, fp) == NULL)
6405 + raw = realloc(raw, (count + 50) * sizeof(char *));
6407 + if((scout = strchr(buf, '\n')))
6410 + raw[count++] = strdup(buf);
6413 + raw = realloc(raw, (count + 1) * sizeof(char *));
6414 + raw[count] = NULL;
6421 +/* something to remove whitespace, a hash pooper */
6422 +char *trim_alloc(char *line)
6425 + char *dest, *src, *end;
6427 + new = malloc(strlen(line) + 1);
6428 + if ( new == NULL ){
6429 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6432 + dest = new, src = line, end = line + (strlen(line) - 1);
6434 + /* remove it from the front */
6439 + /* and now from the back */
6440 + while((end > src) &&
6446 + /* this does from the first space
6447 + * blasting away any versions stuff in depends
6458 +int line_is_blank(const char *line)
6462 + for (s = line; *s; s++) {
6469 +void push_error_list(struct errlist ** errors, char * msg){
6470 + struct errlist *err_lst_tmp;
6473 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6474 + err_lst_tmp->errmsg=strdup(msg) ;
6475 + err_lst_tmp->next = *errors;
6476 + *errors = err_lst_tmp;
6480 +void reverse_error_list(struct errlist **errors){
6481 + struct errlist *result=NULL;
6482 + struct errlist *current= *errors;
6483 + struct errlist *next;
6485 + while ( current != NULL ) {
6486 + next = current->next;
6487 + current->next=result;
6496 +void free_error_list(struct errlist **errors){
6497 + struct errlist *current = *errors;
6499 + while (current != NULL) {
6500 + free(current->errmsg);
6501 + current = (*errors)->next;
6503 + *errors = current;
6510 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.h busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_utils.h
6511 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6512 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/ipkg_utils.h 2005-10-26 17:36:46.000000000 +0200
6514 +/* ipkg_utils.h - the itsy package management system
6518 + Copyright (C) 2002 Compaq Computer Corporation
6520 + This program is free software; you can redistribute it and/or
6521 + modify it under the terms of the GNU General Public License as
6522 + published by the Free Software Foundation; either version 2, or (at
6523 + your option) any later version.
6525 + This program is distributed in the hope that it will be useful, but
6526 + WITHOUT ANY WARRANTY; without even the implied warranty of
6527 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6528 + General Public License for more details.
6531 +#ifndef IPKG_UTILS_H
6532 +#define IPKG_UTILS_H
6536 +int get_available_blocks(char * filesystem);
6537 +char **read_raw_pkgs_from_file(const char *file_name);
6538 +char **read_raw_pkgs_from_stream(FILE *fp);
6539 +char *trim_alloc(char * line);
6540 +int line_is_blank(const char *line);
6543 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.c busybox-1.00+ipkg-0.99.154/archival/libipkg/libipkg.c
6544 --- busybox-1.00-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6545 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/libipkg.c 2005-10-26 17:36:46.000000000 +0200
6547 +/* ipkglib.c - the itsy package management system
6551 + Copyright (C) 2003 kernel concepts
6553 + This program is free software; you can redistribute it and/or
6554 + modify it under the terms of the GNU General Public License as
6555 + published by the Free Software Foundation; either version 2, or (at
6556 + your option) any later version.
6558 + This program is distributed in the hope that it will be useful, but
6559 + WITHOUT ANY WARRANTY; without even the implied warranty of
6560 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6561 + General Public License for more details.
6567 +#include "ipkg_includes.h"
6568 +#include "libipkg.h"
6571 +#include "ipkg_conf.h"
6572 +#include "ipkg_cmd.h"
6573 +#include "file_util.h"
6577 +ipkg_message_callback ipkg_cb_message = NULL;
6578 +ipkg_response_callback ipkg_cb_response = NULL;
6579 +ipkg_status_callback ipkg_cb_status = NULL;
6580 +ipkg_list_callback ipkg_cb_list = NULL;
6584 +ipkg_init (ipkg_message_callback mcall,
6585 + ipkg_response_callback rcall,
6588 + ipkg_cb_message = mcall;
6589 + ipkg_cb_response = rcall;
6598 +ipkg_deinit (args_t * args)
6600 + args_deinit (args);
6601 + ipkg_cb_message = NULL;
6602 + ipkg_cb_response = NULL;
6604 + /* place other cleanup stuff here */
6611 +ipkg_packages_list(args_t *args,
6612 + const char *packages,
6613 + ipkg_list_callback cblist,
6617 + ipkg_conf_t ipkg_conf;
6620 + err = ipkg_conf_init (&ipkg_conf, args);
6626 + ipkg_cb_list = cblist;
6627 + /* we need to do this because of static declarations,
6628 + * maybe a good idea to change */
6629 + cmd = ipkg_cmd_find ("list");
6631 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6633 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6634 + ipkg_cb_list = NULL;
6635 + ipkg_conf_deinit (&ipkg_conf);
6641 +ipkg_packages_status(args_t *args,
6642 + const char *packages,
6643 + ipkg_status_callback cbstatus,
6647 + ipkg_conf_t ipkg_conf;
6650 + err = ipkg_conf_init (&ipkg_conf, args);
6656 + ipkg_cb_status = cbstatus;
6658 + /* we need to do this because of static declarations,
6659 + * maybe a good idea to change */
6660 + cmd = ipkg_cmd_find ("status");
6662 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6664 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6666 + ipkg_cb_status = NULL;
6667 + ipkg_conf_deinit (&ipkg_conf);
6673 +ipkg_packages_info(args_t *args,
6674 + const char *packages,
6675 + ipkg_status_callback cbstatus,
6679 + ipkg_conf_t ipkg_conf;
6682 + err = ipkg_conf_init (&ipkg_conf, args);
6688 + ipkg_cb_status = cbstatus;
6690 + /* we need to do this because of static declarations,
6691 + * maybe a good idea to change */
6692 + cmd = ipkg_cmd_find ("info");
6694 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6696 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6698 + ipkg_cb_status = NULL;
6699 + ipkg_conf_deinit (&ipkg_conf);
6705 +ipkg_packages_install (args_t * args, const char *name)
6708 + ipkg_conf_t ipkg_conf;
6711 + /* this error should be handled in application */
6712 + if (!name || !strlen (name))
6715 + err = ipkg_conf_init (&ipkg_conf, args);
6721 + /* we need to do this because of static declarations,
6722 + * maybe a good idea to change */
6723 + cmd = ipkg_cmd_find ("install");
6724 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6726 + ipkg_conf_deinit(&ipkg_conf);
6732 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6735 + ipkg_conf_t ipkg_conf;
6738 + /* this error should be handled in application */
6739 + if (!name || !strlen (name))
6742 + err = ipkg_conf_init (&ipkg_conf, args);
6748 + /* we need to do this because of static declarations,
6749 + * maybe a good idea to change */
6751 + cmd = ipkg_cmd_find ("purge");
6753 + cmd = ipkg_cmd_find ("remove");
6755 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6757 + ipkg_conf_deinit(&ipkg_conf);
6763 +ipkg_lists_update(args_t *args)
6766 + ipkg_conf_t ipkg_conf;
6769 + err = ipkg_conf_init (&ipkg_conf, args);
6775 + /* we need to do this because of static declarations,
6776 + * maybe a good idea to change */
6777 + cmd = ipkg_cmd_find ("update");
6779 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6781 + ipkg_conf_deinit(&ipkg_conf);
6787 +ipkg_packages_upgrade(args_t *args)
6790 + ipkg_conf_t ipkg_conf;
6793 + err = ipkg_conf_init (&ipkg_conf, args);
6799 + /* we need to do this because of static declarations,
6800 + * maybe a good idea to change */
6801 + cmd = ipkg_cmd_find ("upgrade");
6803 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6805 + ipkg_conf_deinit(&ipkg_conf);
6811 +ipkg_packages_download (args_t * args, const char *name)
6814 + ipkg_conf_t ipkg_conf;
6817 + /* this error should be handled in application */
6818 + if (!name || !strlen (name))
6821 + err = ipkg_conf_init (&ipkg_conf, args);
6827 + /* we need to do this because of static declarations,
6828 + * maybe a good idea to change */
6829 + cmd = ipkg_cmd_find ("download");
6830 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6832 + ipkg_conf_deinit(&ipkg_conf);
6838 +ipkg_package_files(args_t *args,
6840 + ipkg_list_callback cblist,
6844 + ipkg_conf_t ipkg_conf;
6847 + /* this error should be handled in application */
6848 + if (!name || !strlen (name))
6851 + err = ipkg_conf_init (&ipkg_conf, args);
6857 + ipkg_cb_list = cblist;
6859 + /* we need to do this because of static declarations,
6860 + * maybe a good idea to change */
6861 + cmd = ipkg_cmd_find ("files");
6863 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6865 + ipkg_cb_list = NULL;
6866 + ipkg_conf_deinit(&ipkg_conf);
6872 +ipkg_file_search(args_t *args,
6874 + ipkg_list_callback cblist,
6878 + ipkg_conf_t ipkg_conf;
6881 + /* this error should be handled in application */
6882 + if (!file || !strlen (file))
6885 + err = ipkg_conf_init (&ipkg_conf, args);
6891 + ipkg_cb_list = cblist;
6893 + /* we need to do this because of static declarations,
6894 + * maybe a good idea to change */
6895 + cmd = ipkg_cmd_find ("search");
6896 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6898 + ipkg_cb_list = NULL;
6899 + ipkg_conf_deinit(&ipkg_conf);
6905 +ipkg_file_what(args_t *args, const char *file, const char* command)
6908 + ipkg_conf_t ipkg_conf;
6911 + /* this error should be handled in application */
6912 + if (!file || !strlen (file))
6915 + err = ipkg_conf_init (&ipkg_conf, args);
6921 + /* we need to do this because of static declarations,
6922 + * maybe a good idea to change */
6923 + cmd = ipkg_cmd_find (command);
6924 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6926 + ipkg_conf_deinit(&ipkg_conf);
6930 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6931 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6932 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6933 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6934 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6937 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6940 + if (conf && (conf->verbosity < level)) {
6944 + if ( level == IPKG_ERROR ){
6945 + push_error_list(&error_list, msg);
6954 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6955 + pkg_state_status_t status, void *userdata)
6958 + printf("%s - %s - %s\n", name, version, desc);
6960 + printf("%s - %s\n", name, version);
6964 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6965 + pkg_state_status_t status, void *userdata)
6968 + printf("%s\n", desc);
6972 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6975 + printf("%s\n", desc);
6979 +char* default_ipkg_response_callback(char *question)
6981 + char *response = NULL;
6985 + response = (char *)file_read_line_alloc(stdin);
6986 + } while (response == NULL);
6990 +/* This is used for backward compatibility */
6992 +ipkg_op (int argc, char *argv[])
6998 + ipkg_conf_t ipkg_conf;
7000 + args_init (&args);
7002 + optind = args_parse (&args, argc, argv);
7003 + if (optind == argc || optind < 0)
7005 + args_usage ("ipkg must have one sub-command argument");
7008 + cmd_name = argv[optind++];
7009 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7010 + read anything from there.
7012 + if ( !strcmp(cmd_name,"print-architecture") ||
7013 + !strcmp(cmd_name,"print_architecture") ||
7014 + !strcmp(cmd_name,"print-installation-architecture") ||
7015 + !strcmp(cmd_name,"print_installation_architecture") )
7016 + args.nocheckfordirorfile = 1;
7019 + err = ipkg_conf_init (&ipkg_conf, &args);
7025 + args_deinit (&args);
7027 + ipkg_cb_message = default_ipkg_message_callback;
7028 + ipkg_cb_response = default_ipkg_response_callback;
7029 + ipkg_cb_status = default_ipkg_status_callback;
7030 + if ( strcmp(cmd_name, "files")==0)
7031 + ipkg_cb_list = default_ipkg_files_callback;
7033 + ipkg_cb_list = default_ipkg_list_callback;
7035 + cmd = ipkg_cmd_find (cmd_name);
7038 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7040 + args_usage (NULL);
7043 + if (cmd->requires_args && optind == argc)
7046 + "%s: the ``%s'' command requires at least one argument\n",
7047 + __FUNCTION__, cmd_name);
7048 + args_usage (NULL);
7051 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7053 + ipkg_conf_deinit (&ipkg_conf);
7058 +#endif /* IPKG_LIB */
7059 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.h busybox-1.00+ipkg-0.99.154/archival/libipkg/libipkg.h
7060 --- busybox-1.00-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7061 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/libipkg.h 2005-10-26 17:36:46.000000000 +0200
7063 +/* ipkglib.h - the itsy package management system
7065 + Florian Boor <florian.boor@kernelconcepts.de>
7067 + This program is free software; you can redistribute it and/or
7068 + modify it under the terms of the GNU General Public License as
7069 + published by the Free Software Foundation; either version 2, or (at
7070 + your option) any later version.
7072 + This program is distributed in the hope that it will be useful, but
7073 + WITHOUT ANY WARRANTY; without even the implied warranty of
7074 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7075 + General Public License for more details.
7083 +#include "ipkg_conf.h"
7084 +#include "ipkg_message.h"
7089 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7091 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7092 + pkg_state_status_t status, void *userdata);
7093 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7095 +typedef char* (*ipkg_response_callback)(char *question);
7097 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7098 +extern int ipkg_init (ipkg_message_callback mcall,
7099 + ipkg_response_callback rcall,
7102 +extern int ipkg_deinit (args_t *args);
7103 +extern int ipkg_packages_list(args_t *args,
7104 + const char *packages,
7105 + ipkg_list_callback cblist,
7107 +extern int ipkg_packages_status(args_t *args,
7108 + const char *packages,
7109 + ipkg_status_callback cbstatus,
7111 +extern int ipkg_packages_info(args_t *args,
7112 + const char *packages,
7113 + ipkg_status_callback cbstatus,
7115 +extern int ipkg_packages_install(args_t *args, const char *name);
7116 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7117 +extern int ipkg_lists_update(args_t *args);
7118 +extern int ipkg_packages_upgrade(args_t *args);
7119 +extern int ipkg_packages_download(args_t *args, const char *name);
7120 +extern int ipkg_package_files(args_t *args,
7122 + ipkg_list_callback cblist,
7124 +extern int ipkg_file_search(args_t *args,
7126 + ipkg_list_callback cblist,
7128 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7129 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7130 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7131 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7132 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7134 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7135 +extern ipkg_response_callback ipkg_cb_response;
7136 +extern ipkg_status_callback ipkg_cb_status;
7137 +extern ipkg_list_callback ipkg_cb_list;
7138 +extern void push_error_list(struct errlist **errors,char * msg);
7139 +extern void reverse_error_list(struct errlist **errors);
7140 +extern void free_error_list(struct errlist **errors);
7144 +extern int ipkg_op(int argc, char *argv[]);
7150 diff -ruN busybox-1.00-orig/archival/libipkg/md5.c busybox-1.00+ipkg-0.99.154/archival/libipkg/md5.c
7151 --- busybox-1.00-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7152 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/md5.c 2005-10-26 17:36:46.000000000 +0200
7154 +/* md5.c - wrappers to busybox md5 functions
7156 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7158 + * This program is free software; you can redistribute it and/or modify
7159 + * it under the terms of the GNU General Public License as published by
7160 + * the Free Software Foundation; either version 2, or (at your option)
7161 + * any later version.
7163 + * This program is distributed in the hope that it will be useful,
7164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7166 + * GNU General Public License for more details.
7168 + * You should have received a copy of the GNU General Public License
7169 + * along with this program; if not, write to the Free Software Foundation,
7170 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7178 +int md5_stream(FILE *stream, void *resblock)
7183 + if( (fd = fileno(stream)) == -1 ) {
7184 + bb_error_msg("bad file descriptor");
7188 + hash_fd(fd, -1, HASH_MD5, (uint8_t *)resblock);
7193 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7195 + struct md5_ctx_t md5_cx;
7197 + md5_begin(&md5_cx);
7198 + md5_hash(buffer, len, &md5_cx);
7199 + return md5_end(resblock, &md5_cx);
7202 diff -ruN busybox-1.00-orig/archival/libipkg/md5.h busybox-1.00+ipkg-0.99.154/archival/libipkg/md5.h
7203 --- busybox-1.00-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7204 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/md5.h 2005-10-26 17:36:46.000000000 +0200
7206 +/* md5.h - Compute MD5 checksum of files or strings according to the
7207 + * definition of MD5 in RFC 1321 from April 1992.
7208 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7210 + * This program is free software; you can redistribute it and/or modify
7211 + * it under the terms of the GNU General Public License as published by
7212 + * the Free Software Foundation; either version 2, or (at your option)
7213 + * any later version.
7215 + * This program is distributed in the hope that it will be useful,
7216 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7217 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7218 + * GNU General Public License for more details.
7220 + * You should have received a copy of the GNU General Public License
7221 + * along with this program; if not, write to the Free Software Foundation,
7222 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7228 +/* Compute MD5 message digest for bytes read from STREAM. The
7229 + resulting message digest number will be written into the 16 bytes
7230 + beginning at RESBLOCK. */
7231 +int md5_stream(FILE *stream, void *resblock);
7233 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7234 + result is always in little endian byte order, so that a byte-wise
7235 + output yields to the wanted ASCII representation of the message
7237 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7241 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.c busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair.c
7242 --- busybox-1.00-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7243 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair.c 2005-10-26 17:36:46.000000000 +0200
7245 +/* nv_pair.c - the itsy package management system
7249 + Copyright (C) 2001 University of Southern California
7251 + This program is free software; you can redistribute it and/or
7252 + modify it under the terms of the GNU General Public License as
7253 + published by the Free Software Foundation; either version 2, or (at
7254 + your option) any later version.
7256 + This program is distributed in the hope that it will be useful, but
7257 + WITHOUT ANY WARRANTY; without even the implied warranty of
7258 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7259 + General Public License for more details.
7264 +#include "nv_pair.h"
7265 +#include "str_util.h"
7267 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7269 + nv_pair->name = str_dup_safe(name);
7270 + nv_pair->value = str_dup_safe(value);
7275 +void nv_pair_deinit(nv_pair_t *nv_pair)
7277 + free(nv_pair->name);
7278 + nv_pair->name = NULL;
7280 + free(nv_pair->value);
7281 + nv_pair->value = NULL;
7285 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.h busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair.h
7286 --- busybox-1.00-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7287 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair.h 2005-10-26 17:36:46.000000000 +0200
7289 +/* nv_pair.h - the itsy package management system
7293 + Copyright (C) 2001 University of Southern California
7295 + This program is free software; you can redistribute it and/or
7296 + modify it under the terms of the GNU General Public License as
7297 + published by the Free Software Foundation; either version 2, or (at
7298 + your option) any later version.
7300 + This program is distributed in the hope that it will be useful, but
7301 + WITHOUT ANY WARRANTY; without even the implied warranty of
7302 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7303 + General Public License for more details.
7309 +typedef struct nv_pair nv_pair_t;
7316 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7317 +void nv_pair_deinit(nv_pair_t *nv_pair);
7321 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair_list.c
7322 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7323 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair_list.c 2005-10-26 17:36:46.000000000 +0200
7325 +/* nv_pair_list.c - the itsy package management system
7329 + Copyright (C) 2001 University of Southern California
7331 + This program is free software; you can redistribute it and/or
7332 + modify it under the terms of the GNU General Public License as
7333 + published by the Free Software Foundation; either version 2, or (at
7334 + your option) any later version.
7336 + This program is distributed in the hope that it will be useful, but
7337 + WITHOUT ANY WARRANTY; without even the implied warranty of
7338 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7339 + General Public License for more details.
7344 +#include "nv_pair.h"
7345 +#include "void_list.h"
7346 +#include "nv_pair_list.h"
7348 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7350 + return void_list_elt_init((void_list_elt_t *) elt, data);
7353 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7355 + void_list_elt_deinit((void_list_elt_t *) elt);
7358 +int nv_pair_list_init(nv_pair_list_t *list)
7360 + return void_list_init((void_list_t *) list);
7363 +void nv_pair_list_deinit(nv_pair_list_t *list)
7365 + nv_pair_list_elt_t *iter;
7366 + nv_pair_t *nv_pair;
7368 + for (iter = list->head; iter; iter = iter->next) {
7369 + nv_pair = iter->data;
7370 + nv_pair_deinit(nv_pair);
7372 + /* malloced in nv_pair_list_append */
7374 + iter->data = NULL;
7376 + void_list_deinit((void_list_t *) list);
7379 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7383 + /* freed in nv_pair_list_deinit */
7384 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7386 + if (nv_pair == NULL) {
7387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7390 + nv_pair_init(nv_pair, name, value);
7392 + err = void_list_append((void_list_t *) list, nv_pair);
7400 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7402 + return void_list_push((void_list_t *) list, data);
7405 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7407 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7410 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7412 + nv_pair_list_elt_t *iter;
7413 + nv_pair_t *nv_pair;
7415 + for (iter = list->head; iter; iter = iter->next) {
7416 + nv_pair = iter->data;
7417 + if (strcmp(nv_pair->name, name) == 0) {
7418 + return nv_pair->value;
7423 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair_list.h
7424 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7425 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/nv_pair_list.h 2005-10-26 17:36:46.000000000 +0200
7427 +/* nv_pair_list.h - the itsy package management system
7431 + Copyright (C) 2001 University of Southern California
7433 + This program is free software; you can redistribute it and/or
7434 + modify it under the terms of the GNU General Public License as
7435 + published by the Free Software Foundation; either version 2, or (at
7436 + your option) any later version.
7438 + This program is distributed in the hope that it will be useful, but
7439 + WITHOUT ANY WARRANTY; without even the implied warranty of
7440 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7441 + General Public License for more details.
7444 +#ifndef NV_PAIR_LIST_H
7445 +#define NV_PAIR_LIST_H
7447 +#include "nv_pair.h"
7448 +#include "void_list.h"
7450 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7451 +struct nv_pair_list_elt
7453 + nv_pair_list_elt_t *next;
7457 +typedef struct nv_pair_list nv_pair_list_t;
7458 +struct nv_pair_list
7460 + nv_pair_list_elt_t pre_head;
7461 + nv_pair_list_elt_t *head;
7462 + nv_pair_list_elt_t *tail;
7465 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7467 + if (list->head == NULL)
7473 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7474 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7476 +int nv_pair_list_init(nv_pair_list_t *list);
7477 +void nv_pair_list_deinit(nv_pair_list_t *list);
7479 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7480 + const char *name, const char *value);
7481 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7482 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7483 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7487 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg.c
7488 --- busybox-1.00-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7489 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg.c 2005-10-26 17:36:46.000000000 +0200
7491 +/* pkg.c - the itsy package management system
7495 + Copyright (C) 2001 University of Southern California
7497 + This program is free software; you can redistribute it and/or
7498 + modify it under the terms of the GNU General Public License as
7499 + published by the Free Software Foundation; either version 2, or (at
7500 + your option) any later version.
7502 + This program is distributed in the hope that it will be useful, but
7503 + WITHOUT ANY WARRANTY; without even the implied warranty of
7504 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7505 + General Public License for more details.
7510 +#include <string.h>
7515 +#include "pkg_parse.h"
7516 +#include "pkg_extract.h"
7517 +#include "ipkg_message.h"
7518 +#include "ipkg_utils.h"
7520 +#include "sprintf_alloc.h"
7521 +#include "file_util.h"
7522 +#include "str_util.h"
7523 +#include "xsystem.h"
7524 +#include "ipkg_conf.h"
7526 +typedef struct enum_map enum_map_t;
7533 +static const enum_map_t pkg_state_want_map[] = {
7534 + { SW_UNKNOWN, "unknown"},
7535 + { SW_INSTALL, "install"},
7536 + { SW_DEINSTALL, "deinstall"},
7537 + { SW_PURGE, "purge"}
7540 +static const enum_map_t pkg_state_flag_map[] = {
7542 + { SF_REINSTREQ, "reinstreq"},
7543 + { SF_HOLD, "hold"},
7544 + { SF_REPLACE, "replace"},
7545 + { SF_NOPRUNE, "noprune"},
7546 + { SF_PREFER, "prefer"},
7547 + { SF_OBSOLETE, "obsolete"},
7548 + { SF_USER, "user"},
7551 +static const enum_map_t pkg_state_status_map[] = {
7552 + { SS_NOT_INSTALLED, "not-installed" },
7553 + { SS_UNPACKED, "unpacked" },
7554 + { SS_HALF_CONFIGURED, "half-configured" },
7555 + { SS_INSTALLED, "installed" },
7556 + { SS_HALF_INSTALLED, "half-installed" },
7557 + { SS_CONFIG_FILES, "config-files" },
7558 + { SS_POST_INST_FAILED, "post-inst-failed" },
7559 + { SS_REMOVAL_FAILED, "removal-failed" }
7562 +static int verrevcmp(const char *val, const char *ref);
7565 +pkg_t *pkg_new(void)
7569 + pkg = malloc(sizeof(pkg_t));
7570 + if (pkg == NULL) {
7571 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7580 +int pkg_init(pkg_t *pkg)
7582 + memset(pkg, 0, sizeof(pkg_t));
7585 + pkg->version = NULL;
7586 + pkg->revision = NULL;
7587 + pkg->familiar_revision = NULL;
7590 + pkg->architecture = NULL;
7591 + pkg->maintainer = NULL;
7592 + pkg->section = NULL;
7593 + pkg->description = NULL;
7594 + pkg->state_want = SW_UNKNOWN;
7595 + pkg->state_flag = SF_OK;
7596 + pkg->state_status = SS_NOT_INSTALLED;
7597 + pkg->depends_str = NULL;
7598 + pkg->provides_str = NULL;
7599 + pkg->depends_count = 0;
7600 + pkg->depends = NULL;
7601 + pkg->suggests_str = NULL;
7602 + pkg->recommends_str = NULL;
7603 + pkg->suggests_count = 0;
7604 + pkg->recommends_count = 0;
7606 + /* Abhaya: added init for conflicts fields */
7607 + pkg->conflicts = NULL;
7608 + pkg->conflicts_count = 0;
7610 + /* added for replaces. Jamey 7/23/2002 */
7611 + pkg->replaces = NULL;
7612 + pkg->replaces_count = 0;
7614 + pkg->pre_depends_count = 0;
7615 + pkg->pre_depends_str = NULL;
7616 + pkg->provides_count = 0;
7617 + pkg->provides = NULL;
7618 + pkg->filename = NULL;
7619 + pkg->local_filename = NULL;
7620 + pkg->tmp_unpack_dir = NULL;
7621 + pkg->md5sum = NULL;
7623 + pkg->installed_size = NULL;
7624 + pkg->priority = NULL;
7625 + pkg->source = NULL;
7626 + conffile_list_init(&pkg->conffiles);
7627 + pkg->installed_files = NULL;
7628 + pkg->installed_files_ref_cnt = 0;
7629 + pkg->essential = 0;
7634 +void pkg_deinit(pkg_t *pkg)
7639 + free(pkg->version);
7640 + pkg->version = NULL;
7641 + /* revision and familiar_revision share storage with version, so
7643 + pkg->revision = NULL;
7644 + pkg->familiar_revision = NULL;
7645 + /* owned by ipkg_conf_t */
7647 + /* owned by ipkg_conf_t */
7649 + free(pkg->architecture);
7650 + pkg->architecture = NULL;
7651 + free(pkg->maintainer);
7652 + pkg->maintainer = NULL;
7653 + free(pkg->section);
7654 + pkg->section = NULL;
7655 + free(pkg->description);
7656 + pkg->description = NULL;
7657 + pkg->state_want = SW_UNKNOWN;
7658 + pkg->state_flag = SF_OK;
7659 + pkg->state_status = SS_NOT_INSTALLED;
7660 + free(pkg->depends_str);
7661 + pkg->depends_str = NULL;
7662 + free(pkg->provides_str);
7663 + pkg->provides_str = NULL;
7664 + pkg->depends_count = 0;
7665 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7666 + pkg->pre_depends_count = 0;
7667 + free(pkg->pre_depends_str);
7668 + pkg->pre_depends_str = NULL;
7669 + pkg->provides_count = 0;
7670 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7671 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7672 + free(pkg->filename);
7673 + pkg->filename = NULL;
7674 + free(pkg->local_filename);
7675 + pkg->local_filename = NULL;
7676 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7677 + ipkg_install.c here. See comment in
7678 + ipkg_install.c:cleanup_temporary_files */
7679 + free(pkg->tmp_unpack_dir);
7680 + pkg->tmp_unpack_dir = NULL;
7681 + free(pkg->md5sum);
7682 + pkg->md5sum = NULL;
7685 + free(pkg->installed_size);
7686 + pkg->installed_size = NULL;
7687 + free(pkg->priority);
7688 + pkg->priority = NULL;
7689 + free(pkg->source);
7690 + pkg->source = NULL;
7691 + conffile_list_deinit(&pkg->conffiles);
7692 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7693 + since if they are calling deinit, they should know. Maybe do an
7694 + assertion here instead? */
7695 + pkg->installed_files_ref_cnt = 1;
7696 + pkg_free_installed_files(pkg);
7697 + pkg->essential = 0;
7700 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7704 + FILE *control_file;
7706 + err = pkg_init(pkg);
7707 + if (err) { return err; }
7709 + pkg->local_filename = strdup(filename);
7711 + control_file = tmpfile();
7712 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7713 + if (err) { return err; }
7715 + rewind(control_file);
7716 + raw = read_raw_pkgs_from_stream(control_file);
7717 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7719 + fclose(control_file);
7724 +/* Merge any new information in newpkg into oldpkg */
7725 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7726 + newpkg, but should leave it usable. This rework is so that
7727 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7729 + * uh, i thought that i had originally written this so that it took
7730 + * two pkgs and returned a new one? we can do that again... -sma
7732 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7734 + if (oldpkg == newpkg) {
7739 + oldpkg->src = newpkg->src;
7740 + if (!oldpkg->dest)
7741 + oldpkg->dest = newpkg->dest;
7742 + if (!oldpkg->architecture)
7743 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7744 + if (!oldpkg->arch_priority)
7745 + oldpkg->arch_priority = newpkg->arch_priority;
7746 + if (!oldpkg->section)
7747 + oldpkg->section = str_dup_safe(newpkg->section);
7748 + if(!oldpkg->maintainer)
7749 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7750 + if(!oldpkg->description)
7751 + oldpkg->description = str_dup_safe(newpkg->description);
7753 + /* merge the state_flags from the new package */
7754 + oldpkg->state_want = newpkg->state_want;
7755 + oldpkg->state_status = newpkg->state_status;
7756 + oldpkg->state_flag = newpkg->state_flag;
7758 + if (oldpkg->state_want == SW_UNKNOWN)
7759 + oldpkg->state_want = newpkg->state_want;
7760 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7761 + oldpkg->state_status = newpkg->state_status;
7762 + oldpkg->state_flag |= newpkg->state_flag;
7765 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7766 + oldpkg->depends_str = newpkg->depends_str;
7767 + newpkg->depends_str = NULL;
7768 + oldpkg->depends_count = newpkg->depends_count;
7769 + newpkg->depends_count = 0;
7771 + oldpkg->depends = newpkg->depends;
7772 + newpkg->depends = NULL;
7774 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7775 + newpkg->pre_depends_str = NULL;
7776 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7777 + newpkg->pre_depends_count = 0;
7779 + oldpkg->recommends_str = newpkg->recommends_str;
7780 + newpkg->recommends_str = NULL;
7781 + oldpkg->recommends_count = newpkg->recommends_count;
7782 + newpkg->recommends_count = 0;
7784 + oldpkg->suggests_str = newpkg->suggests_str;
7785 + newpkg->suggests_str = NULL;
7786 + oldpkg->suggests_count = newpkg->suggests_count;
7787 + newpkg->suggests_count = 0;
7790 + if (!oldpkg->provides_str) {
7791 + oldpkg->provides_str = newpkg->provides_str;
7792 + newpkg->provides_str = NULL;
7793 + oldpkg->provides_count = newpkg->provides_count;
7794 + newpkg->provides_count = 0;
7796 + oldpkg->provides = newpkg->provides;
7797 + newpkg->provides = NULL;
7800 + if (!oldpkg->conflicts_str) {
7801 + oldpkg->conflicts_str = newpkg->conflicts_str;
7802 + newpkg->conflicts_str = NULL;
7803 + oldpkg->conflicts_count = newpkg->conflicts_count;
7804 + newpkg->conflicts_count = 0;
7806 + oldpkg->conflicts = newpkg->conflicts;
7807 + newpkg->conflicts = NULL;
7810 + if (!oldpkg->replaces_str) {
7811 + oldpkg->replaces_str = newpkg->replaces_str;
7812 + newpkg->replaces_str = NULL;
7813 + oldpkg->replaces_count = newpkg->replaces_count;
7814 + newpkg->replaces_count = 0;
7816 + oldpkg->replaces = newpkg->replaces;
7817 + newpkg->replaces = NULL;
7820 + if (!oldpkg->filename)
7821 + oldpkg->filename = str_dup_safe(newpkg->filename);
7823 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7824 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7825 + if (!oldpkg->local_filename)
7826 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7827 + if (!oldpkg->tmp_unpack_dir)
7828 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7829 + if (!oldpkg->md5sum)
7830 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7831 + if (!oldpkg->size)
7832 + oldpkg->size = str_dup_safe(newpkg->size);
7833 + if (!oldpkg->installed_size)
7834 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7835 + if (!oldpkg->priority)
7836 + oldpkg->priority = str_dup_safe(newpkg->priority);
7837 + if (!oldpkg->source)
7838 + oldpkg->source = str_dup_safe(newpkg->source);
7839 + if (oldpkg->conffiles.head == NULL){
7840 + oldpkg->conffiles = newpkg->conffiles;
7841 + conffile_list_init(&newpkg->conffiles);
7843 + if (!oldpkg->installed_files){
7844 + oldpkg->installed_files = newpkg->installed_files;
7845 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7846 + newpkg->installed_files = NULL;
7848 + if (!oldpkg->essential)
7849 + oldpkg->essential = newpkg->essential;
7854 +abstract_pkg_t *abstract_pkg_new(void)
7856 + abstract_pkg_t * ab_pkg;
7858 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7860 + if (ab_pkg == NULL) {
7861 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7865 + if ( abstract_pkg_init(ab_pkg) < 0 )
7871 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7873 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7875 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7876 + if (ab_pkg->provided_by==NULL){
7879 + ab_pkg->dependencies_checked = 0;
7880 + ab_pkg->state_status = SS_NOT_INSTALLED;
7885 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7888 + char **raw_start=NULL;
7890 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7891 + if (temp_str == NULL ){
7892 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7895 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7897 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7898 + if (raw == NULL ){
7899 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7904 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7905 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7921 +char * pkg_formatted_info(pkg_t *pkg )
7926 + buff = malloc(8192);
7927 + if (buff == NULL) {
7928 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7934 + line = pkg_formatted_field(pkg, "Package");
7935 + strncat(buff ,line, strlen(line));
7938 + line = pkg_formatted_field(pkg, "Version");
7939 + strncat(buff ,line, strlen(line));
7942 + line = pkg_formatted_field(pkg, "Depends");
7943 + strncat(buff ,line, strlen(line));
7946 + line = pkg_formatted_field(pkg, "Recommends");
7947 + strncat(buff ,line, strlen(line));
7950 + line = pkg_formatted_field(pkg, "Suggests");
7951 + strncat(buff ,line, strlen(line));
7954 + line = pkg_formatted_field(pkg, "Provides");
7955 + strncat(buff ,line, strlen(line));
7958 + line = pkg_formatted_field(pkg, "Replaces");
7959 + strncat(buff ,line, strlen(line));
7962 + line = pkg_formatted_field(pkg, "Conflicts");
7963 + strncat(buff ,line, strlen(line));
7966 + line = pkg_formatted_field(pkg, "Status");
7967 + strncat(buff ,line, strlen(line));
7970 + line = pkg_formatted_field(pkg, "Section");
7971 + strncat(buff ,line, strlen(line));
7974 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7975 + strncat(buff ,line, strlen(line));
7978 + line = pkg_formatted_field(pkg, "Architecture");
7979 + strncat(buff ,line, strlen(line));
7982 + line = pkg_formatted_field(pkg, "Maintainer");
7983 + strncat(buff ,line, strlen(line));
7986 + line = pkg_formatted_field(pkg, "MD5sum");
7987 + strncat(buff ,line, strlen(line));
7990 + line = pkg_formatted_field(pkg, "Size");
7991 + strncat(buff ,line, strlen(line));
7994 + line = pkg_formatted_field(pkg, "Filename");
7995 + strncat(buff ,line, strlen(line));
7998 + line = pkg_formatted_field(pkg, "Conffiles");
7999 + strncat(buff ,line, strlen(line));
8002 + line = pkg_formatted_field(pkg, "Source");
8003 + strncat(buff ,line, strlen(line));
8006 + line = pkg_formatted_field(pkg, "Description");
8007 + strncat(buff ,line, strlen(line));
8010 + line = pkg_formatted_field(pkg, "Installed-Time");
8011 + strncat(buff ,line, strlen(line));
8017 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8019 + static size_t LINE_LEN = 128;
8020 + char * temp = (char *)malloc(1);
8022 + int flag_provide_false = 0;
8025 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8026 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8029 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8030 + goto UNKNOWN_FMT_FIELD;
8039 + if (strcasecmp(field, "Architecture") == 0) {
8040 + /* Architecture */
8041 + if (pkg->architecture) {
8042 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8043 + if ( temp == NULL ){
8044 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8048 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8051 + goto UNKNOWN_FMT_FIELD;
8056 + if (strcasecmp(field, "Conffiles") == 0) {
8058 + conffile_list_elt_t *iter;
8059 + char confstr[LINE_LEN];
8061 + if (pkg->conffiles.head == NULL) {
8066 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8067 + if (iter->data->name && iter->data->value) {
8068 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8071 + temp = (char *)realloc(temp,len);
8072 + if ( temp == NULL ){
8073 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8077 + strncpy(temp, "Conffiles:\n", 12);
8078 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8079 + if (iter->data->name && iter->data->value) {
8080 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8081 + strncat(temp, confstr, strlen(confstr));
8084 + } else if (strcasecmp(field, "Conflicts") == 0) {
8087 + if (pkg->conflicts_count) {
8088 + char conflictstr[LINE_LEN];
8090 + for(i = 0; i < pkg->conflicts_count; i++) {
8091 + len = len + (strlen(pkg->conflicts_str[i])+5);
8093 + temp = (char *)realloc(temp,len);
8094 + if ( temp == NULL ){
8095 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8099 + strncpy(temp, "Conflicts:", 11);
8100 + for(i = 0; i < pkg->conflicts_count; i++) {
8101 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8102 + strncat(temp, conflictstr, strlen(conflictstr));
8104 + strncat(temp, "\n", strlen("\n"));
8107 + goto UNKNOWN_FMT_FIELD;
8112 + if (strcasecmp(field, "Depends") == 0) {
8116 + if (pkg->depends_count) {
8117 + char depstr[LINE_LEN];
8119 + for(i = 0; i < pkg->depends_count; i++) {
8120 + len = len + (strlen(pkg->depends_str[i])+4);
8122 + temp = (char *)realloc(temp,len);
8123 + if ( temp == NULL ){
8124 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8128 + strncpy(temp, "Depends:", 10);
8129 + for(i = 0; i < pkg->depends_count; i++) {
8130 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8131 + strncat(temp, depstr, strlen(depstr));
8133 + strncat(temp, "\n", strlen("\n"));
8135 + } else if (strcasecmp(field, "Description") == 0) {
8137 + if (pkg->description) {
8138 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8139 + if ( temp == NULL ){
8140 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8144 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8147 + goto UNKNOWN_FMT_FIELD;
8153 + if (pkg->essential) {
8154 + temp = (char *)realloc(temp,16);
8155 + if ( temp == NULL ){
8156 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8160 + snprintf(temp, (16), "Essential: yes\n");
8167 + if (pkg->filename) {
8168 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8169 + if ( temp == NULL ){
8170 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8174 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8180 + if (strcasecmp(field, "Installed-Size") == 0) {
8181 + /* Installed-Size */
8182 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8183 + if ( temp == NULL ){
8184 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8188 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8189 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8190 + temp = (char *)realloc(temp,29);
8191 + if ( temp == NULL ){
8192 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8196 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8202 + /* Maintainer | MD5sum */
8203 + if (strcasecmp(field, "Maintainer") == 0) {
8205 + if (pkg->maintainer) {
8206 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8207 + if ( temp == NULL ){
8208 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8212 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8214 + } else if (strcasecmp(field, "MD5sum") == 0) {
8216 + if (pkg->md5sum) {
8217 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8218 + if ( temp == NULL ){
8219 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8223 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8226 + goto UNKNOWN_FMT_FIELD;
8232 + if (strcasecmp(field, "Package") == 0) {
8234 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8235 + if ( temp == NULL ){
8236 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8240 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8241 + } else if (strcasecmp(field, "Priority") == 0) {
8243 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8244 + if ( temp == NULL ){
8245 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8249 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8250 + } else if (strcasecmp(field, "Provides") == 0) {
8254 + if (pkg->provides_count) {
8255 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8256 + for ( i=0; i < pkg->provides_count; i++ ){
8257 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8258 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8259 + flag_provide_false = 1;
8262 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8263 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8264 + char provstr[LINE_LEN];
8266 + for(i = 0; i < pkg->provides_count; i++) {
8267 + len = len + (strlen(pkg->provides_str[i])+5);
8269 + temp = (char *)realloc(temp,len);
8270 + if ( temp == NULL ){
8271 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8275 + strncpy(temp, "Provides:", 12);
8276 + for(i = 0; i < pkg->provides_count; i++) {
8277 + if (strlen(pkg->provides_str[i])>0){;
8278 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8279 + strncat(temp, provstr, strlen(provstr));
8282 + strncat(temp, "\n", strlen("\n"));
8286 + goto UNKNOWN_FMT_FIELD;
8293 + /* Replaces | Recommends*/
8294 + if (strcasecmp (field, "Replaces") == 0) {
8295 + if (pkg->replaces_count) {
8296 + char replstr[LINE_LEN];
8298 + for (i = 0; i < pkg->replaces_count; i++) {
8299 + len = len + (strlen(pkg->replaces_str[i])+5);
8301 + temp = (char *)realloc(temp,len);
8302 + if ( temp == NULL ){
8303 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8307 + strncpy(temp, "Replaces:", 12);
8308 + for (i = 0; i < pkg->replaces_count; i++) {
8309 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8310 + strncat(temp, replstr, strlen(replstr));
8312 + strncat(temp, "\n", strlen("\n"));
8314 + } else if (strcasecmp (field, "Recommends") == 0) {
8315 + if (pkg->recommends_count) {
8316 + char recstr[LINE_LEN];
8318 + for(i = 0; i < pkg->recommends_count; i++) {
8319 + len = len + (strlen( pkg->recommends_str[i])+5);
8321 + temp = (char *)realloc(temp,len);
8322 + if ( temp == NULL ){
8323 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8327 + strncpy(temp, "Recommends:", 13);
8328 + for(i = 0; i < pkg->recommends_count; i++) {
8329 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8330 + strncat(temp, recstr, strlen(recstr));
8332 + strncat(temp, "\n", strlen("\n"));
8335 + goto UNKNOWN_FMT_FIELD;
8341 + /* Section | Size | Source | Status | Suggests */
8342 + if (strcasecmp(field, "Section") == 0) {
8344 + if (pkg->section) {
8345 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8346 + if ( temp == NULL ){
8347 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8351 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8353 + } else if (strcasecmp(field, "Size") == 0) {
8356 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8357 + if ( temp == NULL ){
8358 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8362 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8364 + } else if (strcasecmp(field, "Source") == 0) {
8366 + if (pkg->source) {
8367 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8368 + if ( temp == NULL ){
8369 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8373 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8375 + } else if (strcasecmp(field, "Status") == 0) {
8377 + /* Benjamin Pineau note: we should avoid direct usage of
8378 + * strlen(arg) without keeping "arg" for later free()
8380 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8381 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8382 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8384 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8385 + temp = (char *)realloc(temp,sum_of_sizes);
8386 + if ( temp == NULL ){
8387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8391 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8394 + if(pstat) /* pfstat can be NULL if ENOMEM */
8396 + } else if (strcasecmp(field, "Suggests") == 0) {
8397 + if (pkg->suggests_count) {
8399 + char sugstr[LINE_LEN];
8401 + for(i = 0; i < pkg->suggests_count; i++) {
8402 + len = len + (strlen(pkg->suggests_str[i])+5);
8404 + temp = (char *)realloc(temp,len);
8405 + if ( temp == NULL ){
8406 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8410 + strncpy(temp, "Suggests:", 10);
8411 + for(i = 0; i < pkg->suggests_count; i++) {
8412 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8413 + strncat(temp, sugstr, strlen(sugstr));
8415 + strncat(temp, "\n", strlen("\n"));
8418 + goto UNKNOWN_FMT_FIELD;
8425 + char *version = pkg_version_str_alloc(pkg);
8426 + temp = (char *)realloc(temp,strlen(version)+14);
8427 + if ( temp == NULL ){
8428 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8432 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8437 + goto UNKNOWN_FMT_FIELD;
8440 + if ( strlen(temp)<2 ) {
8445 + UNKNOWN_FMT_FIELD:
8446 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8447 + if ( strlen(temp)<2 ) {
8454 +void pkg_print_info(pkg_t *pkg, FILE *file)
8457 + if (pkg == NULL) {
8461 + buff = pkg_formatted_info(pkg);
8462 + if ( buff == NULL )
8464 + if (strlen(buff)>2){
8465 + fwrite(buff, 1, strlen(buff), file);
8470 +void pkg_print_status(pkg_t * pkg, FILE * file)
8472 + if (pkg == NULL) {
8476 + /* XXX: QUESTION: Do we actually want more fields here? The
8477 + original idea was to save space by installing only what was
8478 + needed for actual computation, (package, version, status,
8479 + essential, conffiles). The assumption is that all other fields
8480 + can be found in th available file.
8482 + But, someone proposed the idea to make it possible to
8483 + reconstruct a .ipk from an installed package, (ie. for beaming
8484 + from one handheld to another). So, maybe we actually want a few
8485 + more fields here, (depends, suggests, etc.), so that that would
8486 + be guaranteed to work even in the absence of more information
8487 + from the available file.
8489 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8490 + the essential info needs to be here for all installed packages
8491 + because they may not appear in the Packages files on various
8492 + feeds. Furthermore, one should be able to install from URL or
8493 + local storage without requiring a Packages file from any feed.
8496 + pkg_print_field(pkg, file, "Package");
8497 + pkg_print_field(pkg, file, "Version");
8498 + pkg_print_field(pkg, file, "Depends");
8499 + pkg_print_field(pkg, file, "Recommends");
8500 + pkg_print_field(pkg, file, "Suggests");
8501 + pkg_print_field(pkg, file, "Provides");
8502 + pkg_print_field(pkg, file, "Replaces");
8503 + pkg_print_field(pkg, file, "Conflicts");
8504 + pkg_print_field(pkg, file, "Status");
8505 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8506 + pkg_print_field(pkg, file, "Architecture");
8507 + pkg_print_field(pkg, file, "Conffiles");
8508 + pkg_print_field(pkg, file, "Installed-Time");
8509 + fputs("\n", file);
8512 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8515 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8516 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8517 + __FUNCTION__, field);
8519 + buff = pkg_formatted_field(pkg, field);
8520 + if (strlen(buff)>2) {
8521 + fprintf(file, "%s", buff);
8529 + * libdpkg - Debian packaging suite library routines
8530 + * vercmp.c - comparison of version numbers
8532 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8534 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8538 + if (pkg->epoch > ref_pkg->epoch) {
8542 + if (pkg->epoch < ref_pkg->epoch) {
8546 + r = verrevcmp(pkg->version, ref_pkg->version);
8551 +#ifdef USE_DEBVERSION
8552 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8557 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8563 +int verrevcmp(const char *val, const char *ref)
8567 + const char *vp, *rp;
8568 + const char *vsep, *rsep;
8570 + if (!val) val= "";
8571 + if (!ref) ref= "";
8573 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8574 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8576 + vc= (val == vp) ? 0 : *val++;
8577 + rc= (ref == rp) ? 0 : *ref++;
8578 + if (!rc && !vc) break;
8579 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8580 + if (rc && !isalpha(rc)) rc += 256;
8581 + if (vc != rc) return vc - rc;
8585 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8586 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8587 + if (vl != rl) return vl - rl;
8591 + vsep = strchr(".-", vc);
8592 + rsep = strchr(".-", rc);
8593 + if (vsep && !rsep) return -1;
8594 + if (!vsep && rsep) return +1;
8596 + if (!*val && !*ref) return 0;
8597 + if (!*val) return -1;
8598 + if (!*ref) return +1;
8602 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8606 + r = pkg_compare_versions(it, ref);
8608 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8612 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8616 + if (strcmp(op, "<<") == 0) {
8620 + if (strcmp(op, ">>") == 0) {
8624 + if (strcmp(op, "=") == 0) {
8628 + fprintf(stderr, "unknown operator: %s", op);
8632 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8634 + const pkg_t *a = *(const pkg_t **)p1;
8635 + const pkg_t *b = *(const pkg_t **)p2;
8638 + if (!a->name || !b->name) {
8639 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8640 + a, a->name, b, b->name);
8644 + namecmp = strcmp(a->name, b->name);
8647 + vercmp = pkg_compare_versions(a, b);
8650 + if (!a->arch_priority || !b->arch_priority) {
8651 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8652 + a, a->arch_priority, b, b->arch_priority);
8655 + if (a->arch_priority > b->arch_priority)
8657 + if (a->arch_priority < b->arch_priority)
8662 +int abstract_pkg_name_compare(void *p1, void *p2)
8664 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8665 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8666 + if (!a->name || !b->name) {
8667 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8668 + a, a->name, b, b->name);
8671 + return strcmp(a->name, b->name);
8675 +char *pkg_version_str_alloc(pkg_t *pkg)
8677 + char *complete_version;
8679 +#ifdef USE_DEBVERSION
8680 + char *revision_str;
8681 + char *familiar_revision_str;
8685 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8687 + epoch_str = strdup("");
8690 +#ifdef USE_DEBVERSION
8691 + if (pkg->revision && strlen(pkg->revision)) {
8692 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8694 + revision_str = strdup("");
8697 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8698 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8700 + familiar_revision_str = strdup("");
8704 +#ifdef USE_DEBVERSION
8705 + sprintf_alloc(&complete_version, "%s%s%s%s",
8706 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8708 + sprintf_alloc(&complete_version, "%s%s",
8709 + epoch_str, pkg->version);
8713 +#ifdef USE_DEBVERSION
8714 + free(revision_str);
8715 + free(familiar_revision_str);
8718 + return complete_version;
8721 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8724 + char *list_file_name = NULL;
8725 + FILE *list_file = NULL;
8727 + char *installed_file_name;
8730 + pkg->installed_files_ref_cnt++;
8732 + if (pkg->installed_files) {
8733 + return pkg->installed_files;
8736 + pkg->installed_files = str_list_alloc();
8737 + if (pkg->installed_files == NULL) {
8738 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8742 + /* For uninstalled packages, get the file list firectly from the package.
8743 + For installed packages, look at the package.list file in the database.
8745 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8746 + if (pkg->local_filename == NULL) {
8747 + return pkg->installed_files;
8749 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8750 + file. In other words, change deb_extract so that it can
8751 + simply return the file list as a char *[] rather than
8752 + insisting on writing in to a FILE * as it does now. */
8753 + list_file = tmpfile();
8754 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8756 + fclose(list_file);
8757 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8758 + __FUNCTION__, pkg->local_filename, strerror(err));
8759 + return pkg->installed_files;
8761 + rewind(list_file);
8763 + sprintf_alloc(&list_file_name, "%s/%s.list",
8764 + pkg->dest->info_dir, pkg->name);
8765 + if (! file_exists(list_file_name)) {
8766 + free(list_file_name);
8767 + return pkg->installed_files;
8770 + list_file = fopen(list_file_name, "r");
8771 + if (list_file == NULL) {
8772 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8773 + list_file_name, strerror(errno));
8774 + free(list_file_name);
8775 + return pkg->installed_files;
8777 + free(list_file_name);
8780 + rootdirlen = strlen( pkg->dest->root_dir );
8784 + line = file_read_line_alloc(list_file);
8785 + if (line == NULL) {
8791 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8792 + if( strncmp( pkg->dest->root_dir,
8795 + if (*file_name == '.') {
8798 + if (*file_name == '/') {
8802 + /* Freed in pkg_free_installed_files */
8803 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8805 + // already contains root_dir as header -> ABSOLUTE
8806 + sprintf_alloc(&installed_file_name, "%s", file_name);
8808 + str_list_append(pkg->installed_files, installed_file_name);
8812 + fclose(list_file);
8814 + return pkg->installed_files;
8817 +/* XXX: CLEANUP: This function and it's counterpart,
8818 + (pkg_get_installed_files), do not match our init/deinit naming
8819 + convention. Nor the alloc/free convention. But, then again, neither
8820 + of these conventions currrently fit the way these two functions
8822 +int pkg_free_installed_files(pkg_t *pkg)
8824 + str_list_elt_t *iter;
8826 + pkg->installed_files_ref_cnt--;
8827 + if (pkg->installed_files_ref_cnt > 0) {
8831 + if (pkg->installed_files) {
8833 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8834 + /* malloced in pkg_get_installed_files */
8835 + free (iter->data);
8836 + iter->data = NULL;
8839 + str_list_deinit(pkg->installed_files);
8842 + pkg->installed_files = NULL;
8847 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8850 + char *list_file_name;
8852 + //I don't think pkg_free_installed_files should be called here. Jamey
8853 + //pkg_free_installed_files(pkg);
8855 + sprintf_alloc(&list_file_name, "%s/%s.list",
8856 + pkg->dest->info_dir, pkg->name);
8857 + if (!conf->noaction) {
8858 + err = unlink(list_file_name);
8859 + free(list_file_name);
8868 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8870 + conffile_list_elt_t *iter;
8871 + conffile_t *conffile;
8873 + if (pkg == NULL) {
8877 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8878 + conffile = iter->data;
8880 + if (strcmp(conffile->name, file_name) == 0) {
8888 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8889 + const char *script, const char *args)
8895 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8896 + maintainer script within a chroot environment. */
8898 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8899 + have scripts in pkg->tmp_unpack_dir. */
8900 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8901 + if (pkg->dest == NULL) {
8902 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8903 + __FUNCTION__, pkg->name);
8906 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8908 + if (pkg->tmp_unpack_dir == NULL) {
8909 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8910 + __FUNCTION__, pkg->name);
8913 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8916 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8917 + if (conf->noaction) return 0;
8919 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8920 + scripts when running with offline_root mode and/or a dest other
8921 + than '/'. I've been playing around with some clever chroot
8922 + tricks and I might come up with something workable. */
8923 + if (conf->offline_root) {
8924 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8927 + setenv("PKG_ROOT",
8928 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8930 + if (! file_exists(path)) {
8935 + if (conf->offline_root) {
8936 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8941 + sprintf_alloc(&cmd, "%s %s", path, args);
8944 + err = xsystem(cmd);
8948 + fprintf(stderr, "%s script returned status %d\n", script, err);
8955 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8959 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8960 + if (pkg_state_want_map[i].value == sw) {
8961 + return strdup(pkg_state_want_map[i].str);
8965 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8966 + __FUNCTION__, sw);
8967 + return strdup("<STATE_WANT_UNKNOWN>");
8970 +pkg_state_want_t pkg_state_want_from_str(char *str)
8974 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8975 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8976 + return pkg_state_want_map[i].value;
8980 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8981 + __FUNCTION__, str);
8982 + return SW_UNKNOWN;
8985 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8988 + int len = 3; /* ok\000 is minimum */
8991 + /* clear the temporary flags before converting to string */
8992 + sf &= SF_NONVOLATILE_FLAGS;
8995 + return strdup("ok");
8998 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8999 + if (sf & pkg_state_flag_map[i].value) {
9000 + len += strlen(pkg_state_flag_map[i].str) + 1;
9003 + str = malloc(len);
9004 + if ( str == NULL ) {
9005 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9009 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9010 + if (sf & pkg_state_flag_map[i].value) {
9011 + strcat(str, pkg_state_flag_map[i].str);
9015 + len = strlen(str);
9016 + str[len-1] = 0; /* squash last comma */
9021 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9026 + if (strcmp(str, "ok") == 0) {
9029 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9030 + const char *sfname = pkg_state_flag_map[i].str;
9031 + int sfname_len = strlen(sfname);
9032 + if (strncmp(str, sfname, sfname_len) == 0) {
9033 + sf |= pkg_state_flag_map[i].value;
9034 + str += sfname_len;
9035 + if (str[0] == ',') {
9046 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9050 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9051 + if (pkg_state_status_map[i].value == ss) {
9052 + return strdup(pkg_state_status_map[i].str);
9056 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9057 + __FUNCTION__, ss);
9058 + return strdup("<STATE_STATUS_UNKNOWN>");
9061 +pkg_state_status_t pkg_state_status_from_str(char *str)
9065 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9066 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9067 + return pkg_state_status_map[i].value;
9071 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9072 + __FUNCTION__, str);
9073 + return SS_NOT_INSTALLED;
9076 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9078 + nv_pair_list_elt_t *l;
9080 + if (!pkg->architecture)
9083 + l = conf->arch_list.head;
9086 + nv_pair_t *nv = l->data;
9087 + if (strcmp(nv->name, pkg->architecture) == 0) {
9088 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9094 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9098 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9100 + nv_pair_list_elt_t *l;
9102 + l = conf->arch_list.head;
9105 + nv_pair_t *nv = l->data;
9106 + if (strcmp(nv->name, archname) == 0) {
9107 + int priority = strtol(nv->value, NULL, 0);
9115 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9118 + hash_table_t *pkg_hash = &conf->pkg_hash;
9119 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9120 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9122 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9123 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9124 + /* update arch_priority for each package */
9125 + for (i = 0; i < available_pkgs->len; i++) {
9126 + pkg_t *pkg = available_pkgs->pkgs[i];
9127 + int arch_priority = 1;
9130 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9131 + if (pkg->architecture)
9132 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9134 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9135 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9136 + pkg->arch_priority = arch_priority;
9139 + for (i = 0; i < available_pkgs->len; i++) {
9140 + pkg_t *pkg = available_pkgs->pkgs[i];
9141 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9142 + /* clear flags and want for any uninstallable package */
9143 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9144 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9145 + pkg->state_want = SW_UNKNOWN;
9146 + pkg->state_flag = 0;
9149 + pkg_vec_free(available_pkgs);
9151 + /* update the file owner data structure */
9152 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9153 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9154 + for (i = 0; i < installed_pkgs->len; i++) {
9155 + pkg_t *pkg = installed_pkgs->pkgs[i];
9156 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9157 + str_list_elt_t *iter;
9158 + if (installed_files == NULL) {
9159 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9162 + for (iter = installed_files->head; iter; iter = iter->next) {
9163 + char *installed_file = iter->data;
9164 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9165 + file_hash_set_file_owner(conf, installed_file, pkg);
9168 + pkg_vec_free(installed_pkgs);
9173 +struct pkg_write_filelist_data {
9174 + ipkg_conf_t *conf;
9179 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9181 + struct pkg_write_filelist_data *data = data_;
9182 + pkg_t *entry = entry_;
9183 + if (entry == data->pkg) {
9184 + fprintf(data->stream, "%s\n", key);
9188 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9190 + struct pkg_write_filelist_data data;
9191 + char *list_file_name = NULL;
9195 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9198 + ipkg_message(conf, IPKG_INFO,
9199 + " creating %s.list file\n", pkg->name);
9200 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9201 + if (!list_file_name) {
9202 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9205 + ipkg_message(conf, IPKG_INFO,
9206 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9207 + data.stream = fopen(list_file_name, "w");
9208 + if (!data.stream) {
9209 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9210 + list_file_name, strerror(errno));
9215 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9216 + fclose(data.stream);
9217 + free(list_file_name);
9222 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9224 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9225 + hash_table_t *pkg_hash = &conf->pkg_hash;
9228 + if (conf->noaction)
9231 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9232 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9233 + for (i = 0; i < installed_pkgs->len; i++) {
9234 + pkg_t *pkg = installed_pkgs->pkgs[i];
9235 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9236 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9237 + err = pkg_write_filelist(conf, pkg);
9239 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9244 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg.h
9245 --- busybox-1.00-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9246 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg.h 2005-10-26 17:36:46.000000000 +0200
9248 +/* pkg.h - the itsy package management system
9252 + Copyright (C) 2001 University of Southern California
9254 + This program is free software; you can redistribute it and/or
9255 + modify it under the terms of the GNU General Public License as
9256 + published by the Free Software Foundation; either version 2, or (at
9257 + your option) any later version.
9259 + This program is distributed in the hope that it will be useful, but
9260 + WITHOUT ANY WARRANTY; without even the implied warranty of
9261 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9262 + General Public License for more details.
9268 +#include <sys/types.h>
9269 +#include <sys/stat.h>
9270 +#include <unistd.h>
9272 +#include "pkg_vec.h"
9273 +#include "str_list.h"
9274 +#include "pkg_src.h"
9275 +#include "pkg_dest.h"
9276 +#include "ipkg_conf.h"
9277 +#include "conffile_list.h"
9282 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9284 +/* I think "Size" is currently the shortest field name */
9285 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9287 +enum pkg_state_want
9293 + SW_LAST_STATE_WANT
9295 +typedef enum pkg_state_want pkg_state_want_t;
9297 +enum pkg_state_flag
9301 + SF_HOLD = 2, /* do not upgrade version */
9302 + SF_REPLACE = 4, /* replace this package */
9303 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9304 + SF_PREFER = 16, /* prefer this version */
9305 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9306 + SF_MARKED = 64, /* temporary mark */
9307 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9309 + SF_LAST_STATE_FLAG
9311 +typedef enum pkg_state_flag pkg_state_flag_t;
9312 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9314 +enum pkg_state_status
9316 + SS_NOT_INSTALLED = 1,
9318 + SS_HALF_CONFIGURED,
9320 + SS_HALF_INSTALLED,
9322 + SS_POST_INST_FAILED,
9323 + SS_REMOVAL_FAILED,
9324 + SS_LAST_STATE_STATUS
9326 +typedef enum pkg_state_status pkg_state_status_t;
9328 +struct abstract_pkg{
9330 + int dependencies_checked;
9332 + pkg_state_status_t state_status;
9333 + pkg_state_flag_t state_flag;
9334 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9335 + abstract_pkg_vec_t * provided_by;
9336 + abstract_pkg_vec_t * replaced_by;
9339 +#include "pkg_depends.h"
9341 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9343 + The 3 version fields should go into a single version struct. (This
9344 + is especially important since, currently, pkg->version can easily
9345 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9346 + distinct. This has been the source of multiple bugs.
9348 + The 3 state fields could possibly also go into their own struct.
9350 + All fields which deal with lists of packages, (Depends,
9351 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9352 + be handled by a single struct in pkg_t
9354 + All string fields for which there is a small set of possible
9355 + values, (section, maintainer, architecture, maybe version?), that
9356 + are reused among different packages -- for all such packages we
9357 + should move from "char *"s to some atom datatype to share data
9358 + storage and use less memory. We might even do reference counting,
9359 + but probably not since most often we only create new pkg_t structs,
9360 + we don't often free them. */
9364 + unsigned long epoch;
9367 + char *familiar_revision;
9370 + char *architecture;
9373 + char *description;
9374 + pkg_state_want_t state_want;
9375 + pkg_state_flag_t state_flag;
9376 + pkg_state_status_t state_status;
9377 + char **depends_str;
9378 + int depends_count;
9379 + char **pre_depends_str;
9380 + int pre_depends_count;
9381 + char **recommends_str;
9382 + int recommends_count;
9383 + char **suggests_str;
9384 + int suggests_count;
9385 + compound_depend_t * depends;
9387 + /* Abhaya: new conflicts */
9388 + char **conflicts_str;
9389 + compound_depend_t * conflicts;
9390 + int conflicts_count;
9392 + char **replaces_str;
9393 + int replaces_count;
9394 + abstract_pkg_t ** replaces;
9396 + char **provides_str;
9397 + int provides_count;
9398 + abstract_pkg_t ** provides;
9400 + abstract_pkg_t *parent;
9402 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9405 + char *local_filename;
9407 + char *tmp_unpack_dir;
9410 + char *installed_size;
9413 + conffile_list_t conffiles;
9414 + time_t installed_time;
9415 + /* As pointer for lazy evaluation */
9416 + str_list_t *installed_files;
9417 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9418 + mechanism to avoid the problem here, (which is that the
9419 + installed_files list was being freed from an inner loop while
9420 + still being used within an outer loop. */
9421 + int installed_files_ref_cnt;
9423 + int arch_priority;
9426 +pkg_t *pkg_new(void);
9427 +int pkg_init(pkg_t *pkg);
9428 +void pkg_deinit(pkg_t *pkg);
9429 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9430 +abstract_pkg_t *abstract_pkg_new(void);
9431 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9434 + * merges fields from newpkg into oldpkg.
9435 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9437 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9439 +char *pkg_version_str_alloc(pkg_t *pkg);
9441 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9442 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9443 +int abstract_pkg_name_compare(void *a, void *b);
9445 +char * pkg_formatted_info(pkg_t *pkg );
9446 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9448 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9450 +void pkg_print_info(pkg_t *pkg, FILE *file);
9451 +void pkg_print_status(pkg_t * pkg, FILE * file);
9452 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9453 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9454 +int pkg_free_installed_files(pkg_t *pkg);
9455 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9456 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9457 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9458 + const char *script, const char *args);
9460 +/* enum mappings */
9461 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9462 +pkg_state_want_t pkg_state_want_from_str(char *str);
9463 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9464 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9465 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9466 +pkg_state_status_t pkg_state_status_from_str(char *str);
9468 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9470 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9471 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9472 +int pkg_free_installed_files(pkg_t *pkg);
9474 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9475 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9478 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_depends.c
9479 --- busybox-1.00-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9480 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_depends.c 2005-10-26 17:45:58.000000000 +0200
9482 +/* pkg_depends.c - the itsy package management system
9486 + Copyright (C) 2002 Compaq Computer Corporation
9488 + This program is free software; you can redistribute it and/or
9489 + modify it under the terms of the GNU General Public License as
9490 + published by the Free Software Foundation; either version 2, or (at
9491 + your option) any later version.
9493 + This program is distributed in the hope that it will be useful, but
9494 + WITHOUT ANY WARRANTY; without even the implied warranty of
9495 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9496 + General Public License for more details.
9504 +#include "ipkg_utils.h"
9505 +#include "pkg_hash.h"
9506 +#include "ipkg_message.h"
9507 +#include "pkg_parse.h"
9508 +#include "hash_table.h"
9510 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9511 +static depend_t * depend_init(void);
9512 +static void depend_deinit(depend_t *d);
9513 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9514 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9515 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9517 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9519 + depend_t *depend = (depend_t *)cdata;
9520 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9526 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9528 + depend_t *depend = (depend_t *)cdata;
9530 + pkg_t * temp = pkg_new();
9532 + parseVersion(temp, depend->version);
9533 + comparison = pkg_compare_versions(pkg, temp);
9536 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9537 + __FUNCTION__, pkg->name, pkg->version,
9538 + depend, depend->constraint, depend->version,
9539 + comparison, version_constraints_satisfied(depend, pkg));
9541 + if (version_constraints_satisfied(depend, pkg))
9547 +/* returns ndependences or negative error value */
9548 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9549 + pkg_vec_t *unsatisfied, char *** unresolved)
9551 + pkg_t * satisfier_entry_pkg;
9552 + register int i, j, k;
9555 + abstract_pkg_t * ab_pkg;
9558 + * this is a setup to check for redundant/cyclic dependency checks,
9559 + * which are marked at the abstract_pkg level
9561 + if (!(ab_pkg = pkg->parent)) {
9562 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9563 + *unresolved = NULL;
9566 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9567 + *unresolved = NULL;
9570 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9574 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9576 + *unresolved = NULL;
9582 + /* foreach dependency */
9583 + for (i = 0; i < count; i++) {
9584 + compound_depend_t * compound_depend = &pkg->depends[i];
9585 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9587 + satisfier_entry_pkg = NULL;
9589 + if (compound_depend->type == GREEDY_DEPEND) {
9590 + /* foreach possible satisfier */
9591 + for (j = 0; j < compound_depend->possibility_count; j++) {
9592 + /* foreach provided_by, which includes the abstract_pkg itself */
9593 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9594 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9595 + int nposs = ab_provider_vec->len;
9596 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9598 + for (l = 0; l < nposs; l++) {
9599 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9600 + /* if no depends on this one, try the first package that Provides this one */
9601 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9605 + /* cruise this possiblity's pkg_vec looking for an installed version */
9606 + for (k = 0; k < test_vec->len; k++) {
9607 + pkg_t *pkg_scout = test_vec->pkgs[k];
9608 + /* not installed, and not already known about? */
9609 + if ((pkg_scout->state_want != SW_INSTALL)
9610 + && !pkg_scout->parent->dependencies_checked
9611 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9612 + char ** newstuff = NULL;
9614 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9615 + /* check for not-already-installed dependencies */
9616 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9620 + if (newstuff == NULL) {
9623 + for (i = 0; i < rc; i++) {
9624 + pkg_t *p = tmp_vec->pkgs[i];
9625 + if (p->state_want == SW_INSTALL)
9627 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9631 + pkg_vec_free (tmp_vec);
9633 + /* mark this one for installation */
9634 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9635 + pkg_vec_insert(unsatisfied, pkg_scout);
9638 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9649 + /* foreach possible satisfier, look for installed package */
9650 + for (j = 0; j < compound_depend->possibility_count; j++) {
9651 + /* foreach provided_by, which includes the abstract_pkg itself */
9652 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9653 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9654 + pkg_t *satisfying_pkg =
9655 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9656 + pkg_installed_and_constraint_satisfied,
9657 + dependence_to_satisfy, 1);
9658 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9659 + if (satisfying_pkg != NULL) {
9660 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9661 + satisfying_pkg = NULL;
9664 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9665 + if (satisfying_pkg != NULL) {
9671 + /* if nothing installed matches, then look for uninstalled satisfier */
9673 + /* foreach possible satisfier, look for installed package */
9674 + for (j = 0; j < compound_depend->possibility_count; j++) {
9675 + /* foreach provided_by, which includes the abstract_pkg itself */
9676 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9677 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9678 + pkg_t *satisfying_pkg =
9679 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9680 + pkg_constraint_satisfied,
9681 + dependence_to_satisfy, 1);
9682 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9683 + if (satisfying_pkg != NULL) {
9684 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9685 + satisfying_pkg = NULL;
9689 + /* user request overrides package recommendation */
9690 + if (satisfying_pkg != NULL
9691 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9692 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9693 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9694 + pkg->name, satisfying_pkg->name);
9698 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9699 + if (satisfying_pkg != NULL) {
9700 + satisfier_entry_pkg = satisfying_pkg;
9706 + /* we didn't find one, add something to the unsatisfied vector */
9708 + if (!satisfier_entry_pkg) {
9709 + /* failure to meet recommendations is not an error */
9710 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9711 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9713 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9714 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9717 + if (compound_depend->type == SUGGEST) {
9718 + /* just mention it politely */
9719 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9720 + pkg->name, satisfier_entry_pkg->name);
9722 + char ** newstuff = NULL;
9724 + if (satisfier_entry_pkg != pkg &&
9725 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9726 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9727 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9728 + satisfier_entry_pkg,
9731 + the_lost = merge_unresolved(the_lost, newstuff);
9737 + *unresolved = the_lost;
9739 + return unsatisfied->len;
9742 +/*checking for conflicts !in replaces
9743 + If a packages conflicts with another but is also replacing it, I should not consider it a
9745 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9747 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9750 + int replaces_count = pkg->replaces_count;
9751 + abstract_pkg_t **replaces;
9753 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9756 + replaces = pkg->replaces;
9758 + for (i = 0; i < replaces_count; i++) {
9759 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9767 +/* Abhaya: added support for conflicts */
9768 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9770 + pkg_vec_t * installed_conflicts, * test_vec;
9771 + compound_depend_t * conflicts;
9772 + depend_t ** possible_satisfiers;
9773 + depend_t * possible_satisfier;
9774 + register int i, j, k;
9776 + abstract_pkg_t * ab_pkg;
9777 + pkg_t **pkg_scouts;
9781 + * this is a setup to check for redundant/cyclic dependency checks,
9782 + * which are marked at the abstract_pkg level
9784 + if(!(ab_pkg = pkg->parent)){
9785 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9786 + return (pkg_vec_t *)NULL;
9789 + conflicts = pkg->conflicts;
9791 + return (pkg_vec_t *)NULL;
9793 + installed_conflicts = pkg_vec_alloc();
9795 + count = pkg->conflicts_count;
9799 + /* foreach conflict */
9800 + for(i = 0; i < pkg->conflicts_count; i++){
9802 + possible_satisfiers = conflicts->possibilities;
9804 + /* foreach possible satisfier */
9805 + for(j = 0; j < conflicts->possibility_count; j++){
9806 + possible_satisfier = possible_satisfiers[j];
9807 + if (!possible_satisfier)
9808 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9809 + if (!possible_satisfier->pkg)
9810 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9811 + test_vec = possible_satisfier->pkg->pkgs;
9813 + /* pkg_vec found, it is an actual package conflict
9814 + * cruise this possiblity's pkg_vec looking for an installed version */
9815 + pkg_scouts = test_vec->pkgs;
9816 + for(k = 0; k < test_vec->len; k++){
9817 + pkg_scout = pkg_scouts[k];
9819 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9822 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9823 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9824 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9825 + pkg_vec_insert(installed_conflicts, pkg_scout);
9834 + if (installed_conflicts->len)
9835 + return installed_conflicts;
9836 + pkg_vec_free(installed_conflicts);
9837 + return (pkg_vec_t *)NULL;
9840 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9845 + if(depends->constraint == NONE)
9850 + parseVersion(temp, depends->version);
9852 + comparison = pkg_compare_versions(pkg, temp);
9856 + if((depends->constraint == EARLIER) &&
9859 + else if((depends->constraint == LATER) &&
9862 + else if(comparison == 0)
9864 + else if((depends->constraint == LATER_EQUAL) &&
9865 + (comparison >= 0))
9867 + else if((depends->constraint == EARLIER_EQUAL) &&
9868 + (comparison <= 0))
9874 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9876 + abstract_pkg_t *apkg = depend->pkg;
9877 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9878 + int n_providers = provider_apkgs->len;
9879 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9880 + pkg_vec_t *pkg_vec;
9885 + for (i = 0; i < n_providers; i++) {
9886 + abstract_pkg_t *papkg = apkgs[i];
9887 + pkg_vec = papkg->pkgs;
9889 + n_pkgs = pkg_vec->len;
9890 + for (j = 0; j < n_pkgs; j++) {
9891 + pkg_t *pkg = pkg_vec->pkgs[j];
9892 + if (version_constraints_satisfied(depend, pkg)) {
9901 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9903 + abstract_pkg_t *apkg = depend->pkg;
9904 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9905 + int n_providers = provider_apkgs->len;
9906 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9911 + for (i = 0; i < n_providers; i++) {
9912 + abstract_pkg_t *papkg = apkgs[i];
9913 + pkg_vec_t *pkg_vec = papkg->pkgs;
9915 + n_pkgs = pkg_vec->len;
9916 + for (j = 0; j < n_pkgs; j++) {
9917 + pkg_t *pkg = pkg_vec->pkgs[j];
9918 + if (version_constraints_satisfied(depend, pkg)) {
9919 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9928 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9931 + pkg_t ** pkgs = vec->pkgs;
9933 + for(i = 0; i < vec->len; i++)
9934 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9935 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9936 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9944 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9945 + * the same abstract package and 0 otherwise.
9947 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9949 + abstract_pkg_t **provides = pkg->provides;
9950 + int provides_count = pkg->provides_count;
9951 + abstract_pkg_t **replacee_provides = replacee->provides;
9952 + int replacee_provides_count = replacee->provides_count;
9954 + for (i = 0; i < provides_count; i++) {
9955 + abstract_pkg_t *apkg = provides[i];
9956 + for (j = 0; j < replacee_provides_count; j++) {
9957 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9958 + if (apkg == replacee_apkg)
9967 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9968 + * and 0 otherwise.
9970 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9972 + abstract_pkg_t **provides = pkg->provides;
9973 + int provides_count = pkg->provides_count;
9975 + for (i = 0; i < provides_count; i++) {
9976 + if (provides[i] == providee)
9983 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9986 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9988 + abstract_pkg_t **replaces = pkg->replaces;
9989 + int replaces_count = pkg->replaces_count;
9990 + abstract_pkg_t **replacee_provides = pkg->provides;
9991 + int replacee_provides_count = pkg->provides_count;
9993 + for (i = 0; i < replaces_count; i++) {
9994 + abstract_pkg_t *abstract_replacee = replaces[i];
9995 + for (j = 0; j < replacee_provides_count; j++) {
9996 + if (replacee_provides[j] == abstract_replacee)
10005 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10008 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10010 + compound_depend_t *conflicts = pkg->conflicts;
10011 + int conflicts_count = pkg->conflicts_count;
10013 + for (i = 0; i < conflicts_count; i++) {
10014 + int possibility_count = conflicts[i].possibility_count;
10015 + struct depend **possibilities = conflicts[i].possibilities;
10016 + for (j = 0; j < possibility_count; j++) {
10017 + if (possibilities[j]->pkg == conflictee) {
10026 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10027 + * conflictee's provides and 0 otherwise.
10029 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10031 + compound_depend_t *conflicts = pkg->conflicts;
10032 + int conflicts_count = pkg->conflicts_count;
10033 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10034 + int conflictee_provides_count = conflictee->provides_count;
10036 + int possibility_count;
10037 + struct depend **possibilities;
10038 + abstract_pkg_t *possibility ;
10040 + for (i = 0; i < conflicts_count; i++) {
10041 + possibility_count = conflicts[i].possibility_count;
10042 + possibilities = conflicts[i].possibilities;
10043 + for (j = 0; j < possibility_count; j++) {
10044 + possibility = possibilities[j]->pkg;
10045 + for (k = 0; k < conflictee_provides_count; k++) {
10046 + if (possibility == conflictee_provides[k]) {
10055 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10057 + int oldlen = 0, newlen = 0;
10059 + register int i, j;
10064 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10065 + while(newstuff && newstuff[newlen]) newlen++;
10067 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10068 + if (result == NULL) {
10069 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10073 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10074 + *(result + i) = *(newstuff + j);
10076 + *(result + i) = NULL;
10082 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10083 + * this is null terminated, no count is carried around
10085 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10089 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10092 + while(the_lost && the_lost[count]) count++;
10094 + count++; /* need one to hold the null */
10095 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10096 + if (resized == NULL) {
10097 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10100 + resized[count - 1] = strdup(depend_str);
10101 + resized[count] = NULL;
10106 +void printDepends(pkg_t * pkg)
10108 + register int i, j;
10109 + compound_depend_t * depend;
10112 + count = pkg->pre_depends_count + pkg->depends_count;
10114 + depend = pkg->depends;
10116 + fprintf(stderr, "Depends pointer is NULL\n");
10119 + for(i = 0; i < count; i++){
10120 + fprintf(stderr, "%s has %d possibilities:\n",
10121 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10122 + depend->possibility_count);
10123 + for(j = 0; j < depend->possibility_count; j++)
10124 + fprintf(stderr, "\t%s version %s (%d)\n",
10125 + depend->possibilities[j]->pkg->name,
10126 + depend->possibilities[j]->version,
10127 + depend->possibilities[j]->constraint);
10132 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10134 + register int i, j;
10136 + /* every pkg provides itself */
10137 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10139 + if (!pkg->provides_count)
10142 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10143 + if (pkg->provides == NULL) {
10144 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10147 + pkg->provides[0] = ab_pkg;
10149 + // if (strcmp(ab_pkg->name, pkg->name))
10150 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10152 + for(i = 0; i < pkg->provides_count; i++){
10153 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10155 + pkg->provides[i+1] = provided_abpkg;
10158 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10163 +/* Abhaya: added conflicts support */
10164 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10167 + compound_depend_t * conflicts;
10169 + if (!pkg->conflicts_count)
10172 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10173 + pkg->conflicts_count);
10174 + if (conflicts == NULL) {
10175 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10178 + for (i = 0; i < pkg->conflicts_count; i++) {
10179 + conflicts->type = CONFLICTS;
10180 + parseDepends(conflicts, hash,
10181 + pkg->conflicts_str[i]);
10183 + for (j = 0; j < conflicts->possibility_count; j++) {
10184 + depend_t *possibility = conflicts->possibilities[j];
10185 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10186 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10194 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10196 + register int i, j;
10198 + if (!pkg->replaces_count)
10201 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10202 + if (pkg->replaces == NULL) {
10203 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10207 + // if (strcmp(ab_pkg->name, pkg->name))
10208 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10210 + for(i = 0; i < pkg->replaces_count; i++){
10211 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10213 + pkg->replaces[i] = old_abpkg;
10216 + if (!old_abpkg->replaced_by)
10217 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10218 + if ( old_abpkg->replaced_by == NULL ){
10221 + /* if a package pkg both replaces and conflicts old_abpkg,
10222 + * then add it to the replaced_by vector so that old_abpkg
10223 + * will be upgraded to ab_pkg automatically */
10224 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10225 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10230 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10234 + compound_depend_t * depends;
10236 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10239 + if (0 && pkg->pre_depends_count)
10240 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10241 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10242 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10243 + if (depends == NULL) {
10244 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10249 + for(i = 0; i < pkg->pre_depends_count; i++){
10250 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10251 + if (0 && pkg->pre_depends_count)
10252 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10253 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10254 + depends->type = PREDEPEND;
10258 + for(i = 0; i < pkg->recommends_count; i++){
10259 + parseDepends(depends, hash, pkg->recommends_str[i]);
10260 + if (0 && pkg->recommends_count)
10261 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10262 + pkg->recommends_str[i], depends, depends->possibility_count);
10263 + depends->type = RECOMMEND;
10267 + for(i = 0; i < pkg->suggests_count; i++){
10268 + parseDepends(depends, hash, pkg->suggests_str[i]);
10269 + if (0 && pkg->suggests_count)
10270 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10271 + pkg->suggests_str[i], depends, depends->possibility_count);
10272 + depends->type = SUGGEST;
10276 + for(i = 0; i < pkg->depends_count; i++){
10277 + parseDepends(depends, hash, pkg->depends_str[i]);
10278 + if (0 && pkg->depends_count)
10279 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10280 + pkg->depends_str[i], depends, depends->possibility_count);
10287 + * pkg_depend_string: returns the depends string specified by index.
10288 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10289 + * [0,npredepends) -> returns pre_depends_str[index]
10290 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10291 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10292 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10294 +char *pkg_depend_str(pkg_t *pkg, int index)
10296 + if (index < pkg->pre_depends_count) {
10297 + return pkg->pre_depends_str[index];
10299 + index -= pkg->pre_depends_count;
10301 + if (index < pkg->recommends_count) {
10302 + return pkg->recommends_str[index];
10304 + index -= pkg->recommends_count;
10306 + if (index < pkg->suggests_count) {
10307 + return pkg->suggests_str[index];
10309 + index -= pkg->suggests_count;
10311 + if (index < pkg->depends_count) {
10312 + return pkg->depends_str[index];
10314 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10318 +void freeDepends(pkg_t *pkg)
10322 + if (pkg == NULL || pkg->depends == NULL) {
10326 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10327 + for (i=0; i < pkg->depends->possibility_count; i++) {
10328 + depend_deinit(pkg->depends->possibilities[i]);
10330 + free(pkg->depends->possibilities);
10331 + free(pkg->depends);
10332 + pkg->depends = NULL;
10335 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10337 + compound_depend_t * depends;
10338 + int count, othercount;
10339 + register int i, j;
10340 + abstract_pkg_t * ab_depend;
10341 + abstract_pkg_t ** temp;
10343 + count = pkg->pre_depends_count + pkg->depends_count;
10344 + depends = pkg->depends;
10346 + if (0 && pkg->pre_depends_count)
10347 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10348 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10349 + for (i = 0; i < count; i++) {
10350 + if (0 && pkg->pre_depends_count)
10351 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10352 + for (j = 0; j < depends->possibility_count; j++){
10353 + ab_depend = depends->possibilities[j]->pkg;
10354 + if(!ab_depend->depended_upon_by)
10355 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10357 + temp = ab_depend->depended_upon_by;
10365 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10366 + (othercount + 1) * sizeof(abstract_pkg_t *));
10367 + /* the array may have moved */
10368 + temp = ab_depend->depended_upon_by + othercount;
10375 +static depend_t * depend_init(void)
10377 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10379 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10382 + d->constraint = NONE;
10383 + d->version = NULL;
10389 +static void depend_deinit(depend_t *d)
10394 +static int parseDepends(compound_depend_t *compound_depend,
10395 + hash_table_t * hash, char * depend_str)
10397 + char * pkg_name, buffer[2048];
10398 + int num_of_ors = 0;
10400 + register char * src, * dest;
10401 + depend_t ** possibilities;
10403 + /* first count the number of ored possibilities for satisfying dependency */
10404 + src = depend_str;
10406 + if(*src++ == '|')
10409 + compound_depend->type = DEPEND;
10411 + compound_depend->possibility_count = num_of_ors + 1;
10412 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10413 + if (!possibilities)
10415 + compound_depend->possibilities = possibilities;
10417 + src = depend_str;
10418 + for(i = 0; i < num_of_ors + 1; i++){
10419 + possibilities[i] = depend_init();
10420 + if (!possibilities[i])
10422 + /* gobble up just the name first */
10425 + !isspace(*src) &&
10429 + *dest++ = *src++;
10431 + pkg_name = trim_alloc(buffer);
10432 + if (pkg_name == NULL )
10435 + /* now look at possible version info */
10437 + /* skip to next chars */
10438 + if(isspace(*src))
10439 + while(*src && isspace(*src)) src++;
10441 + /* extract constraint and version */
10444 + if(!strncmp(src, "<<", 2)){
10445 + possibilities[i]->constraint = EARLIER;
10448 + else if(!strncmp(src, "<=", 2)){
10449 + possibilities[i]->constraint = EARLIER_EQUAL;
10452 + else if(!strncmp(src, ">=", 2)){
10453 + possibilities[i]->constraint = LATER_EQUAL;
10456 + else if(!strncmp(src, ">>", 2)){
10457 + possibilities[i]->constraint = LATER;
10460 + else if(!strncmp(src, "=", 1)){
10461 + possibilities[i]->constraint = EQUAL;
10464 + /* should these be here to support deprecated designations; dpkg does */
10465 + else if(!strncmp(src, "<", 1)){
10466 + possibilities[i]->constraint = EARLIER_EQUAL;
10469 + else if(!strncmp(src, ">", 1)){
10470 + possibilities[i]->constraint = LATER_EQUAL;
10474 + /* now we have any constraint, pass space to version string */
10475 + while(isspace(*src)) src++;
10477 + /* this would be the version string */
10479 + while(*src && *src != ')')
10480 + *dest++ = *src++;
10483 + possibilities[i]->version = trim_alloc(buffer);
10484 + /* fprintf(stderr, "let's print the depends version string:");
10485 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10486 + if (possibilities[i]->version == NULL )
10491 + /* hook up the dependency to its abstract pkg */
10492 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10496 + /* now get past the ) and any possible | chars */
10498 + (isspace(*src) ||
10504 + compound_depend->type = GREEDY_DEPEND;
10511 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_depends.h
10512 --- busybox-1.00-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10513 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_depends.h 2005-10-26 17:36:46.000000000 +0200
10515 +/* pkg_depends.h - the itsy package management system
10519 + Copyright (C) 2002 Compaq Computer Corporation
10521 + This program is free software; you can redistribute it and/or
10522 + modify it under the terms of the GNU General Public License as
10523 + published by the Free Software Foundation; either version 2, or (at
10524 + your option) any later version.
10526 + This program is distributed in the hope that it will be useful, but
10527 + WITHOUT ANY WARRANTY; without even the implied warranty of
10528 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10529 + General Public License for more details.
10532 +#ifndef PKG_DEPENDS_H
10533 +#define PKG_DEPENDS_H
10536 +#include "pkg_hash.h"
10538 +enum depend_type {
10546 +typedef enum depend_type depend_type_t;
10548 +enum version_constraint {
10556 +typedef enum version_constraint version_constraint_t;
10559 + version_constraint_t constraint;
10561 + abstract_pkg_t * pkg;
10563 +typedef struct depend depend_t;
10565 +struct compound_depend{
10566 + depend_type_t type;
10567 + int possibility_count;
10568 + struct depend ** possibilities;
10570 +typedef struct compound_depend compound_depend_t;
10572 +#include "hash_table.h"
10574 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10575 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10576 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10577 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10580 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10581 + * the same abstract package and 0 otherwise.
10583 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10586 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10589 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10592 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10595 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10598 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10601 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10604 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10607 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10609 +char *pkg_depend_str(pkg_t *pkg, int index);
10610 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10611 +void freeDepends(pkg_t *pkg);
10612 +void printDepends(pkg_t * pkg);
10613 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10614 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10615 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10616 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10617 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10620 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest.c
10621 --- busybox-1.00-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10622 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest.c 2005-10-26 17:36:46.000000000 +0200
10624 +/* pkg_dest.c - the itsy package management system
10628 + Copyright (C) 2001 University of Southern California
10630 + This program is free software; you can redistribute it and/or
10631 + modify it under the terms of the GNU General Public License as
10632 + published by the Free Software Foundation; either version 2, or (at
10633 + your option) any later version.
10635 + This program is distributed in the hope that it will be useful, but
10636 + WITHOUT ANY WARRANTY; without even the implied warranty of
10637 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10638 + General Public License for more details.
10643 +#include "pkg_dest.h"
10644 +#include "file_util.h"
10645 +#include "str_util.h"
10646 +#include "sprintf_alloc.h"
10648 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10650 + dest->name = strdup(name);
10652 + /* Guarantee that dest->root_dir ends with a '/' */
10653 + if (str_ends_with(root_dir, "/")) {
10654 + dest->root_dir = strdup(root_dir);
10656 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10658 + file_mkdir_hier(dest->root_dir, 0755);
10660 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10661 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10662 + file_mkdir_hier(dest->ipkg_dir, 0755);
10664 + if (str_starts_with (lists_dir, "/"))
10665 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10667 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10669 + file_mkdir_hier(dest->lists_dir, 0755);
10671 + sprintf_alloc(&dest->info_dir, "%s/%s",
10672 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10673 + file_mkdir_hier(dest->info_dir, 0755);
10675 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10676 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10678 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10679 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10681 + dest->status_file = NULL;
10686 +void pkg_dest_deinit(pkg_dest_t *dest)
10688 + free(dest->name);
10689 + dest->name = NULL;
10691 + free(dest->root_dir);
10692 + dest->root_dir = NULL;
10694 + free(dest->ipkg_dir);
10695 + dest->ipkg_dir = NULL;
10697 + free(dest->lists_dir);
10698 + dest->lists_dir = NULL;
10700 + free(dest->info_dir);
10701 + dest->info_dir = NULL;
10703 + free(dest->status_file_name);
10704 + dest->status_file_name = NULL;
10706 + free(dest->status_file_tmp_name);
10707 + dest->status_file_tmp_name = NULL;
10709 + if (dest->status_file) {
10710 + fclose(dest->status_file);
10712 + dest->status_file = NULL;
10714 + dest->root_dir = NULL;
10716 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest.h
10717 --- busybox-1.00-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10718 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest.h 2005-10-26 17:36:46.000000000 +0200
10720 +/* pkg_dest.h - the itsy package management system
10724 + Copyright (C) 2001 University of Southern California
10726 + This program is free software; you can redistribute it and/or
10727 + modify it under the terms of the GNU General Public License as
10728 + published by the Free Software Foundation; either version 2, or (at
10729 + your option) any later version.
10731 + This program is distributed in the hope that it will be useful, but
10732 + WITHOUT ANY WARRANTY; without even the implied warranty of
10733 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10734 + General Public License for more details.
10737 +#ifndef PKG_DEST_H
10738 +#define PKG_DEST_H
10740 +typedef struct pkg_dest pkg_dest_t;
10748 + char *status_file_name;
10749 + char *status_file_tmp_name;
10750 + FILE *status_file;
10753 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10754 +void pkg_dest_deinit(pkg_dest_t *dest);
10758 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest_list.c
10759 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10760 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest_list.c 2005-10-26 17:36:46.000000000 +0200
10762 +/* pkg_dest_list.c - the itsy package management system
10766 + Copyright (C) 2001 University of Southern California
10768 + This program is free software; you can redistribute it and/or
10769 + modify it under the terms of the GNU General Public License as
10770 + published by the Free Software Foundation; either version 2, or (at
10771 + your option) any later version.
10773 + This program is distributed in the hope that it will be useful, but
10774 + WITHOUT ANY WARRANTY; without even the implied warranty of
10775 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10776 + General Public License for more details.
10781 +#include "pkg_dest.h"
10782 +#include "void_list.h"
10783 +#include "pkg_dest_list.h"
10785 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10787 + return void_list_elt_init((void_list_elt_t *) elt, data);
10790 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10792 + void_list_elt_deinit((void_list_elt_t *) elt);
10795 +int pkg_dest_list_init(pkg_dest_list_t *list)
10797 + return void_list_init((void_list_t *) list);
10800 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10802 + pkg_dest_list_elt_t *iter;
10803 + pkg_dest_t *pkg_dest;
10805 + for (iter = list->head; iter; iter = iter->next) {
10806 + pkg_dest = iter->data;
10807 + pkg_dest_deinit(pkg_dest);
10809 + /* malloced in pkg_dest_list_append */
10811 + iter->data = NULL;
10813 + void_list_deinit((void_list_t *) list);
10816 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10817 + const char *root_dir,const char *lists_dir)
10820 + pkg_dest_t *pkg_dest;
10822 + /* freed in plg_dest_list_deinit */
10823 + pkg_dest = malloc(sizeof(pkg_dest_t));
10824 + if (pkg_dest == NULL) {
10825 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10829 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10830 + err = void_list_append((void_list_t *) list, pkg_dest);
10838 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10840 + return void_list_push((void_list_t *) list, data);
10843 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10845 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10847 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest_list.h
10848 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10849 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_dest_list.h 2005-10-26 17:36:46.000000000 +0200
10851 +/* pkg_dest_list.h - the itsy package management system
10855 + Copyright (C) 2001 University of Southern California
10857 + This program is free software; you can redistribute it and/or
10858 + modify it under the terms of the GNU General Public License as
10859 + published by the Free Software Foundation; either version 2, or (at
10860 + your option) any later version.
10862 + This program is distributed in the hope that it will be useful, but
10863 + WITHOUT ANY WARRANTY; without even the implied warranty of
10864 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10865 + General Public License for more details.
10868 +#ifndef PKG_DEST_LIST_H
10869 +#define PKG_DEST_LIST_H
10871 +#include "pkg_dest.h"
10873 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10874 +struct pkg_dest_list_elt
10876 + pkg_dest_list_elt_t *next;
10877 + pkg_dest_t *data;
10880 +typedef struct pkg_dest_list pkg_dest_list_t;
10881 +struct pkg_dest_list
10883 + pkg_dest_list_elt_t pre_head;
10884 + pkg_dest_list_elt_t *head;
10885 + pkg_dest_list_elt_t *tail;
10888 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10889 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10891 +int pkg_dest_list_init(pkg_dest_list_t *list);
10892 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10894 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10895 + const char *root_dir,const char* lists_dir);
10896 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10897 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10901 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_extract.c
10902 --- busybox-1.00-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10903 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_extract.c 2005-10-26 17:36:46.000000000 +0200
10905 +/* pkg_extract.c - the itsy package management system
10909 + Copyright (C) 2001 University of Southern California
10911 + This program is free software; you can redistribute it and/or
10912 + modify it under the terms of the GNU General Public License as
10913 + published by the Free Software Foundation; either version 2, or (at
10914 + your option) any later version.
10916 + This program is distributed in the hope that it will be useful, but
10917 + WITHOUT ANY WARRANTY; without even the implied warranty of
10918 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10919 + General Public License for more details.
10923 +#include <errno.h>
10924 +#include <fcntl.h>
10925 +#include <stdio.h>
10927 +#include "pkg_extract.h"
10929 +#include "libbb.h"
10930 +#include "file_util.h"
10931 +#include "sprintf_alloc.h"
10932 +#include "unarchive.h"
10934 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10935 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10936 +#define IPKG_CONTROL_FILE "control"
10938 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10940 + archive_handle_t *archive;
10943 + sprintf_alloc(&path, "%s/", dir);
10944 + archive = init_handle();
10945 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10946 + archive->filter = filter_accept_list;
10947 + archive->accept = llist_add_to(NULL, (char *)filename);
10948 + archive->buffer = path;
10949 + archive->action_data = data_extract_all_prefix;
10950 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10951 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10952 + close(archive->src_fd);
10953 + free(archive->accept);
10958 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10960 + unsigned int size = strlen(archive->file_header->name) + 2;
10962 + if (archive->buffer == NULL) {
10963 + archive->buffer = xmalloc(size);
10964 + strcpy(archive->buffer, archive->file_header->name);
10966 + size += strlen(archive->buffer);
10967 + archive->buffer = xrealloc(archive->buffer, size);
10968 + strcat(archive->buffer, archive->file_header->name);
10970 + strcat(archive->buffer, "\n");
10971 + data_skip(archive);
10974 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10976 + archive_handle_t *archive;
10979 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10980 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10981 + archive = init_handle();
10982 + archive->src_fd = bb_xopen(name, O_RDONLY);
10983 + archive->filter = filter_accept_list;
10984 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10985 + archive->action_data = data_extract_to_buffer;
10986 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10987 + close(archive->src_fd);
10988 + fputs(archive->buffer, stream);
10989 + free(archive->buffer);
10990 + free(archive->accept);
10997 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10999 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11002 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11004 + archive_handle_t *archive;
11008 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11009 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11010 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11011 + archive = init_handle();
11012 + archive->src_fd = bb_xopen(name, O_RDONLY);
11013 + archive->filter = filter_accept_all;
11014 + archive->buffer = path;
11015 + archive->action_data = data_extract_all_prefix;
11016 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11017 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11018 + close(archive->src_fd);
11026 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11028 + archive_handle_t *archive;
11032 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11033 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11034 + sprintf_alloc(&path, "%s/", dir);
11035 + archive = init_handle();
11036 + archive->src_fd = bb_xopen(name, O_RDONLY);
11037 + archive->filter = filter_accept_all;
11038 + archive->buffer = path;
11039 + archive->action_data = data_extract_all_prefix;
11040 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11041 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11042 + close(archive->src_fd);
11050 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11053 + char *line, *data_file;
11057 + file = fopen(file_name, "w");
11058 + if (file == NULL) {
11059 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11060 + __FUNCTION__, file_name);
11065 + if (pkg->installed_files) {
11066 + str_list_elt_t *elt;
11067 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11068 + fprintf(file, "%s\n", elt->data);
11071 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11078 + /* Fixup data file names by removing the initial '.' */
11081 + line = file_read_line_alloc(tmp);
11082 + if (line == NULL) {
11086 + data_file = line;
11087 + if (*data_file == '.') {
11091 + if (*data_file != '/') {
11092 + fputs("/", file);
11095 + /* I have no idea why, but this is what dpkg does */
11096 + if (strcmp(data_file, "/\n") == 0) {
11097 + fputs("/.\n", file);
11099 + fputs(data_file, file);
11109 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11111 + archive_handle_t *archive;
11114 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11115 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11116 + archive = init_handle();
11117 + archive->src_fd = bb_xopen(name, O_RDONLY);
11118 + archive->filter = filter_accept_all;
11119 + archive->action_data = data_extract_file_name_to_buffer;
11120 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11121 + close(archive->src_fd);
11122 + fputs(archive->buffer, file);
11123 + free(archive->buffer);
11129 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_extract.h
11130 --- busybox-1.00-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11131 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_extract.h 2005-10-26 17:36:46.000000000 +0200
11133 +/* pkg_extract.c - the itsy package management system
11137 + Copyright (C) 2001 University of Southern California
11139 + This program is free software; you can redistribute it and/or
11140 + modify it under the terms of the GNU General Public License as
11141 + published by the Free Software Foundation; either version 2, or (at
11142 + your option) any later version.
11144 + This program is distributed in the hope that it will be useful, but
11145 + WITHOUT ANY WARRANTY; without even the implied warranty of
11146 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11147 + General Public License for more details.
11150 +#ifndef PKG_EXTRACT_H
11151 +#define PKG_EXTRACT_H
11155 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11156 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11157 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11159 + const char *prefix);
11160 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11161 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11162 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11165 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_hash.c
11166 --- busybox-1.00-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11167 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_hash.c 2005-10-26 17:45:58.000000000 +0200
11169 +/* ipkg_hash.c - the itsy package management system
11173 + Copyright (C) 2002 Compaq Computer Corporation
11175 + This program is free software; you can redistribute it and/or
11176 + modify it under the terms of the GNU General Public License as
11177 + published by the Free Software Foundation; either version 2, or (at
11178 + your option) any later version.
11180 + This program is distributed in the hope that it will be useful, but
11181 + WITHOUT ANY WARRANTY; without even the implied warranty of
11182 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11183 + General Public License for more details.
11187 +#include <errno.h>
11188 +#include <ctype.h>
11189 +#include <stdlib.h>
11190 +#include <string.h>
11192 +#include "hash_table.h"
11194 +#include "ipkg_message.h"
11195 +#include "pkg_vec.h"
11196 +#include "pkg_hash.h"
11197 +#include "pkg_parse.h"
11198 +#include "ipkg_utils.h"
11200 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11203 + * this will talk to both feeds-lists files and installed status files
11206 + * hash_table_t hash;
11207 + * pkg_hash_init(name, &hash, 1000);
11208 + * pkg_hash_add_from_file(<feed filename>);
11210 + * the query function is just there as a shell to prove to me that this
11211 + * sort of works, but isn't far from doing something useful
11214 + * modified: CDW 3 Jan. 2002
11219 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11221 + return hash_table_init(name, hash, len);
11224 +void pkg_hash_deinit(hash_table_t *hash)
11226 + hash_table_deinit(hash);
11230 +/* Find the default arch for a given package status file if none is given. */
11231 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11233 + nv_pair_list_elt_t *l;
11234 + char *def_arch = HOST_CPU_STR; /* Default arch */
11235 + int def_prio = 0; /* Other archs override this */
11237 + l = conf->arch_list.head;
11240 + nv_pair_t *nv = l->data;
11241 + int priority = strtol(nv->value, NULL, 0);
11243 + /* Check if this arch has higher priority, and is valid */
11244 + if ((priority > def_prio) &&
11245 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11246 + /* Our new default */
11247 + def_prio = priority;
11248 + def_arch = nv->name;
11253 + return strdup(def_arch);
11256 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11257 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11259 + hash_table_t *hash = &conf->pkg_hash;
11261 + char **raw_start;
11264 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11268 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11273 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11274 + if (!pkg->architecture) {
11275 + char *version_str = pkg_version_str_alloc(pkg);
11276 + pkg->architecture = pkg_get_default_arch(conf);
11277 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11278 + pkg->name, version_str, pkg->architecture);
11279 + free(version_str);
11281 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11287 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11288 + memory after read_raw_pkgs_from_file */
11297 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11299 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11302 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11304 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11307 + return apkg->provided_by;
11311 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11312 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11315 + int nprovides = 0;
11316 + int nmatching = 0;
11317 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11318 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11319 + abstract_pkg_vec_t *provided_apkg_vec;
11320 + abstract_pkg_t **provided_apkgs;
11321 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11322 + pkg_t *latest_installed_parent = NULL;
11323 + pkg_t *latest_matching = NULL;
11324 + pkg_t *held_pkg = NULL;
11325 + pkg_t *good_pkg_by_name = NULL;
11327 + if (matching_apkgs == NULL || providers == NULL ||
11328 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11331 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11333 + provided_apkg_vec = apkg->provided_by;
11334 + nprovides = provided_apkg_vec->len;
11335 + provided_apkgs = provided_apkg_vec->pkgs;
11336 + if (nprovides > 1)
11337 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11339 + /* accumulate all the providers */
11340 + for (i = 0; i < nprovides; i++) {
11341 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11342 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11343 + abstract_pkg_vec_insert(providers, provider_apkg);
11345 + nprovides = providers->len;
11347 + for (i = 0; i < nprovides; i++) {
11348 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11349 + abstract_pkg_t *replacement_apkg = NULL;
11352 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11353 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11354 + if (provider_apkg->replaced_by->len > 1) {
11355 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11356 + provider_apkg->name, replacement_apkg->name);
11360 + if (replacement_apkg)
11361 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11362 + replacement_apkg->name, provider_apkg->name);
11364 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11365 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11368 + provider_apkg = replacement_apkg;
11371 + if (!(vec = provider_apkg->pkgs)) {
11372 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11377 + /* now check for supported architecture */
11379 + int max_count = 0;
11382 + /* count packages matching max arch priority and keep track of last one */
11383 + for (i = 0; i < vec->len; i++) {
11384 + pkg_t *maybe = vec->pkgs[i];
11385 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d \n",
11386 + maybe->name, maybe->architecture, maybe->arch_priority);
11387 + if (maybe->arch_priority > 0) {
11389 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11390 + pkg_vec_insert(matching_pkgs, maybe);
11396 + if (matching_pkgs->len > 1)
11397 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11398 + if (matching_apkgs->len > 1)
11399 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11401 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11402 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11404 + for (i = 0; i < matching_pkgs->len; i++) {
11405 + pkg_t *matching = matching_pkgs->pkgs[i];
11406 + if (constraint_fcn(matching, cdata)) { /* We found it */
11407 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s \n", matching->name) ;
11408 + good_pkg_by_name = matching;
11413 + for (i = 0; i < matching_pkgs->len; i++) {
11414 + pkg_t *matching = matching_pkgs->pkgs[i];
11415 + latest_matching = matching;
11416 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11417 + latest_installed_parent = matching;
11418 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11420 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11421 + held_pkg->name, matching->name);
11422 + held_pkg = matching;
11426 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11427 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11428 + apkg->name, matching_apkgs->len);
11429 + for (i = 0; i < matching_apkgs->len; i++) {
11430 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11431 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11433 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11436 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11437 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11438 + __FUNCTION__, apkg->name, matching_pkgs->len);
11439 + for (i = 0; i < matching_pkgs->len; i++) {
11440 + pkg_t *matching = matching_pkgs->pkgs[i];
11441 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11442 + matching->name, matching->version, matching->architecture);
11446 + nmatching = matching_apkgs->len;
11448 + pkg_vec_free(matching_pkgs);
11449 + abstract_pkg_vec_free(matching_apkgs);
11450 + abstract_pkg_vec_free(providers);
11452 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11453 + return good_pkg_by_name;
11456 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11459 + if (latest_installed_parent) {
11460 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11461 + return latest_installed_parent;
11463 + if (nmatching > 1) {
11464 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11467 + if (latest_matching) {
11468 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11469 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11470 + return latest_matching;
11475 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11477 + const char *name = (const char *)cdata;
11478 + if (strcmp(pkg->name, name) == 0)
11481 + return 0; /* Pigi */
11484 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11486 + hash_table_t *hash = &conf->pkg_hash;
11487 + abstract_pkg_t *apkg = NULL;
11489 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11492 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11496 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11497 + const char *pkg_name,
11498 + const char * version)
11502 + char *version_str = NULL;
11504 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11507 + for(i = 0; i < vec->len; i++) {
11508 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11509 + if(!strcmp(version_str, version)) {
11510 + free(version_str);
11513 + free(version_str);
11516 + if(i == vec->len)
11519 + return vec->pkgs[i];
11522 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11523 + const char *pkg_name,
11524 + pkg_dest_t *dest)
11529 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11533 + for(i = 0; i < vec->len; i++)
11534 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11535 + return vec->pkgs[i];
11540 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11541 + const char *pkg_name)
11546 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11550 + for(i = 0; i < vec->len; i++)
11551 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11552 + return vec->pkgs[i];
11558 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11560 + abstract_pkg_t * ab_pkg;
11562 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11566 + if (ab_pkg->pkgs) {
11567 + return ab_pkg->pkgs;
11568 + } else if (ab_pkg->provided_by) {
11569 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11570 + if (abpkg != NULL){
11571 + return abpkg->pkgs;
11573 + return ab_pkg->pkgs;
11580 +static int pkg_compare_names(const void *p1, const void *p2)
11582 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11583 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11584 + if (pkg1->name == NULL)
11586 + if (pkg2->name == NULL)
11588 + return(strcmp(pkg1->name, pkg2->name));
11592 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11595 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11596 + pkg_vec_t *all = (pkg_vec_t *)data;
11597 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11599 + for (j = 0; j < pkg_vec->len; j++) {
11600 + pkg_t *pkg = pkg_vec->pkgs[j];
11601 + pkg_vec_insert(all, pkg);
11606 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11608 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11609 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11612 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11614 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11615 + pkg_vec_t *all = (pkg_vec_t *)data;
11616 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11619 + for (j = 0; j < pkg_vec->len; j++) {
11620 + pkg_t *pkg = pkg_vec->pkgs[j];
11621 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11622 + pkg_vec_insert(all, pkg);
11627 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11629 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11630 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11633 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11637 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11638 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11639 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11640 + fprintf(stdout, "%s\n", ab_pkg->name);
11642 + if (dependents != NULL)
11643 + while (dependents [i] != NULL)
11644 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11645 + dependents = ab_pkg->provided_by->pkgs;
11647 + if (dependents != NULL)
11648 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11649 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11650 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11653 + while (i < pkg->depends_count)
11654 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11657 +void pkg_hash_dump(hash_table_t *hash, void *data)
11660 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11661 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11662 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11665 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11667 + abstract_pkg_t * ab_pkg;
11669 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11670 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11675 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11677 + abstract_pkg_t * ab_pkg;
11678 + int arch_priority;
11683 + arch_priority = pkg->arch_priority;
11685 + if (buildDepends(hash, pkg)<0){
11686 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11689 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11691 + if (set_status) {
11692 + if (pkg->state_status == SS_INSTALLED) {
11693 + ab_pkg->state_status = SS_INSTALLED;
11694 + } else if (pkg->state_status == SS_UNPACKED) {
11695 + ab_pkg->state_status = SS_UNPACKED;
11699 + if(!ab_pkg->pkgs)
11700 + ab_pkg->pkgs = pkg_vec_alloc();
11702 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11703 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11704 + pkg->parent = ab_pkg;
11706 + if (buildProvides(hash, ab_pkg, pkg)<0){
11707 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11710 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11711 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11712 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11715 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11716 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11720 + buildDependedUponBy(pkg, ab_pkg);
11725 + * this will assume that we've already determined that
11726 + * the abstract pkg doesn't exist, 'cause we should know these things...
11728 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11730 + abstract_pkg_t * ab_pkg;
11732 + ab_pkg = abstract_pkg_new();
11733 + if (ab_pkg == NULL) { return NULL; }
11735 + ab_pkg->name = strdup(pkg_name);
11736 + hash_table_insert(hash, pkg_name, ab_pkg);
11742 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11744 + hash_table_t *file_hash = &conf->file_hash;
11746 + return hash_table_get(file_hash, file_name);
11749 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11751 + hash_table_t *file_hash = &conf->file_hash;
11752 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11753 + int file_name_len = strlen(file_name);
11755 + if (file_name[file_name_len -1] == '/')
11758 + if (conf->offline_root) {
11759 + int len = strlen(conf->offline_root);
11760 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11761 + file_name += len;
11765 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11766 + hash_table_insert(file_hash, file_name, owning_pkg);
11767 + if (old_owning_pkg) {
11768 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11769 + /* mark this package to have its filelist written */
11770 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11771 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11777 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_hash.h
11778 --- busybox-1.00-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11779 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_hash.h 2005-10-26 17:36:46.000000000 +0200
11781 +/* pkg_hash.h - the itsy package management system
11785 + Copyright (C) 2002 Compaq Computer Corporation
11787 + This program is free software; you can redistribute it and/or
11788 + modify it under the terms of the GNU General Public License as
11789 + published by the Free Software Foundation; either version 2, or (at
11790 + your option) any later version.
11792 + This program is distributed in the hope that it will be useful, but
11793 + WITHOUT ANY WARRANTY; without even the implied warranty of
11794 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11795 + General Public License for more details.
11798 +#ifndef PKG_HASH_H
11799 +#define PKG_HASH_H
11802 +#include "pkg_vec.h"
11803 +#include "hash_table.h"
11806 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11807 +void pkg_hash_deinit(hash_table_t *hash);
11808 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11810 +void pkg_hash_dump(hash_table_t *hash, void *data);
11811 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11813 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11814 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11815 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11817 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11818 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11819 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11820 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11821 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11822 + const char *pkg_name,
11823 + const char * version);
11824 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11825 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11826 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11827 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11828 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11829 + const char *pkg_name);
11830 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11831 + const char *pkg_name,
11832 + pkg_dest_t *dest);
11834 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11835 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11837 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11838 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11842 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_parse.c
11843 --- busybox-1.00-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
11844 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_parse.c 2005-10-26 17:36:46.000000000 +0200
11846 +/* pkg_parse.c - the itsy package management system
11850 + Copyright (C) 2002 Compaq Computer Corporation
11852 + This program is free software; you can redistribute it and/or
11853 + modify it under the terms of the GNU General Public License as
11854 + published by the Free Software Foundation; either version 2, or (at
11855 + your option) any later version.
11857 + This program is distributed in the hope that it will be useful, but
11858 + WITHOUT ANY WARRANTY; without even the implied warranty of
11859 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11860 + General Public License for more details.
11864 +#include <errno.h>
11865 +#include <ctype.h>
11868 +#include "ipkg_utils.h"
11869 +#include "pkg_parse.h"
11871 +int isGenericFieldType(char * type, char * line)
11873 + if(!strncmp(line, type, strlen(type)))
11878 +char * parseGenericFieldType(char * type, char * raw)
11880 + char * field_value = raw + (strlen(type) + 1);
11881 + return trim_alloc(field_value);
11884 +void parseStatus(pkg_t *pkg, char * raw)
11886 + char sw_str[64], sf_str[64], ss_str[64];
11888 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11889 + pkg->state_want = pkg_state_want_from_str(sw_str);
11890 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11891 + pkg->state_status = pkg_state_status_from_str(ss_str);
11894 +char ** parseDependsString(char * raw, int * depends_count)
11896 + char ** depends = NULL;
11897 + int line_count = 0;
11898 + char buff[2048], * dest;
11900 + while(raw && *raw && !isspace(*raw)) {
11904 + if(line_is_blank(raw)){
11905 + *depends_count = line_count;
11908 + while(raw && *raw){
11909 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11911 + while(isspace(*raw)) raw++;
11914 + while((*raw != ',') && *raw)
11915 + *dest++ = *raw++;
11918 + depends[line_count] = trim_alloc(buff);
11919 + if(depends[line_count] ==NULL)
11925 + *depends_count = line_count;
11929 +void parseConffiles(pkg_t * pkg, char * raw)
11931 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11933 + if(!strncmp(raw, "Conffiles:", 10))
11934 + raw += strlen("Conffiles:");
11936 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11937 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11938 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11939 + while (*raw && isspace(*raw)) {
11942 + raw += strlen(file_name);
11943 + while (*raw && isspace(*raw)) {
11946 + raw += strlen(md5sum);
11950 +int parseVersion(pkg_t *pkg, char *raw)
11952 + char *colon, *eepochcolon;
11953 +#ifdef USE_DEBVERSION
11956 + unsigned long epoch;
11959 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11963 + if (strncmp(raw, "Version:", 8) == 0) {
11966 + while (*raw && isspace(*raw)) {
11970 + colon= strchr(raw,':');
11972 + epoch= strtoul(raw,&eepochcolon,10);
11973 + if (colon != eepochcolon) {
11974 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11978 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11982 + pkg->epoch= epoch;
11987 + pkg->revision = "";
11988 + pkg->familiar_revision = "";
11990 + pkg->version= malloc(strlen(raw)+1);
11991 + if ( pkg->version == NULL ) {
11992 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11995 + strcpy(pkg->version, raw);
11997 +#ifdef USE_DEBVERSION
11998 + hyphen= strrchr(pkg->version,'-');
12002 + if (strncmp("fam", hyphen, 3) == 0) {
12003 + pkg->familiar_revision=hyphen+3;
12004 + hyphen= strrchr(pkg->version,'-');
12007 + pkg->revision = hyphen;
12010 + pkg->revision = hyphen;
12016 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12020 + pkg->familiar_revision);
12027 +/* This code is needed to insert in first position the keyword for the aligning bug */
12029 +int alterProvidesLine(char *raw, char *temp)
12034 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12038 + if ( temp == NULL ) {
12039 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12043 + if (strncmp(raw, "Provides:", 9) == 0) {
12046 + while (*raw && isspace(*raw)) {
12050 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12052 + strncat( temp, raw++, 1);
12058 +/* Some random thoughts from Carl:
12060 + This function could be considerably simplified if we just kept
12061 + an array of all the generic string-valued field names, and looped
12062 + through those looking for a match. Also, these fields could perhaps
12063 + be stored in the package as an array as well, (or, probably better,
12064 + as an nv_pair_list_t).
12066 + Fields which require special parsing or storage, (such as Depends:
12067 + and Status:) could be handled as they are now.
12069 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12070 + to a dependency list. And, since we already have
12071 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12072 + Enhances, perhaps we could generalize all of these and save some
12073 + code duplication.
12075 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12077 + int reading_conffiles, reading_description;
12078 + int pkg_false_provides=1;
12080 + char * provide=NULL;
12083 + pkg->dest = dest;
12085 + reading_conffiles = reading_description = 0;
12087 + for (lines = *raw; *lines; lines++) {
12088 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12089 + if(isGenericFieldType("Package:", *lines))
12090 + pkg->name = parseGenericFieldType("Package", *lines);
12091 + else if(isGenericFieldType("Architecture:", *lines))
12092 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12093 + else if(isGenericFieldType("Filename:", *lines))
12094 + pkg->filename = parseGenericFieldType("Filename", *lines);
12095 + else if(isGenericFieldType("Section:", *lines))
12096 + pkg->section = parseGenericFieldType("Section", *lines);
12097 + else if(isGenericFieldType("MD5sum:", *lines))
12098 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12099 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12100 + let's parse it either way */
12101 + else if(isGenericFieldType("MD5Sum:", *lines))
12102 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12103 + else if(isGenericFieldType("Size:", *lines))
12104 + pkg->size = parseGenericFieldType("Size", *lines);
12105 + else if(isGenericFieldType("Source:", *lines))
12106 + pkg->source = parseGenericFieldType("Source", *lines);
12107 + else if(isGenericFieldType("Installed-Size:", *lines))
12108 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12109 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12110 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12111 + pkg->installed_time = strtoul(time_str, NULL, 0);
12112 + } else if(isGenericFieldType("Priority:", *lines))
12113 + pkg->priority = parseGenericFieldType("Priority", *lines);
12114 + else if(isGenericFieldType("Essential:", *lines)) {
12115 + char *essential_value;
12116 + essential_value = parseGenericFieldType("Essential", *lines);
12117 + if (strcmp(essential_value, "yes") == 0) {
12118 + pkg->essential = 1;
12120 + free(essential_value);
12122 + else if(isGenericFieldType("Status", *lines))
12123 + parseStatus(pkg, *lines);
12124 + else if(isGenericFieldType("Version", *lines))
12125 + parseVersion(pkg, *lines);
12126 + else if(isGenericFieldType("Maintainer", *lines))
12127 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12128 + else if(isGenericFieldType("Conffiles", *lines)){
12129 + parseConffiles(pkg, *lines);
12130 + reading_conffiles = 1;
12132 + else if(isGenericFieldType("Description", *lines)) {
12133 + pkg->description = parseGenericFieldType("Description", *lines);
12134 + reading_conffiles = 0;
12135 + reading_description = 1;
12138 + else if(isGenericFieldType("Provides", *lines)){
12139 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12140 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12141 + if ( alterProvidesLine(*lines,provide) ){
12144 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12145 +/* Let's try to hack a bit here.
12146 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12147 + in alot of other places. We will remove it before writing down the status database */
12148 + pkg_false_provides=0;
12152 + else if(isGenericFieldType("Depends", *lines))
12153 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12154 + else if(isGenericFieldType("Pre-Depends", *lines))
12155 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12156 + else if(isGenericFieldType("Recommends", *lines))
12157 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12158 + else if(isGenericFieldType("Suggests", *lines))
12159 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12160 + /* Abhaya: support for conflicts */
12161 + else if(isGenericFieldType("Conflicts", *lines))
12162 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12163 + else if(isGenericFieldType("Replaces", *lines))
12164 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12165 + else if(line_is_blank(*lines)) {
12169 + else if(**lines == ' '){
12170 + if(reading_description) {
12171 + /* we already know it's not blank, so the rest of description */
12172 + pkg->description = realloc(pkg->description,
12173 + strlen(pkg->description)
12174 + + 1 + strlen(*lines) + 1);
12175 + strcat(pkg->description, "\n");
12176 + strcat(pkg->description, (*lines));
12178 + else if(reading_conffiles)
12179 + parseConffiles(pkg, *lines);
12183 +/* If the ipk has not a Provides line, we insert our false line */
12184 + if ( pkg_false_provides==1)
12185 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12194 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12198 + for (lines = *raw; *lines; lines++) {
12199 + if(isGenericFieldType("Essential:", *lines)) {
12200 + char *essential_value;
12201 + essential_value = parseGenericFieldType("Essential", *lines);
12202 + if (strcmp(essential_value, "yes") == 0) {
12203 + pkg->essential = 1;
12205 + free(essential_value);
12212 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_parse.h
12213 --- busybox-1.00-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12214 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_parse.h 2005-10-26 17:36:46.000000000 +0200
12216 +/* pkg_parse.h - the itsy package management system
12220 + Copyright (C) 2002 Compaq Computer Corporation
12222 + This program is free software; you can redistribute it and/or
12223 + modify it under the terms of the GNU General Public License as
12224 + published by the Free Software Foundation; either version 2, or (at
12225 + your option) any later version.
12227 + This program is distributed in the hope that it will be useful, but
12228 + WITHOUT ANY WARRANTY; without even the implied warranty of
12229 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12230 + General Public License for more details.
12233 +#ifndef PKG_PARSE_H
12234 +#define PKG_PARSE_H
12236 +int isGenericFieldType(char * type, char * line);
12237 +char * parseGenericFieldType(char * type, char * raw);
12238 +void parseStatus(pkg_t *pkg, char * raw);
12239 +int parseVersion(pkg_t *pkg, char *raw);
12240 +char ** parseDependsString(char * raw, int * depends_count);
12241 +int parseVersion(pkg_t *pkg, char *raw);
12242 +void parseConffiles(pkg_t * pkg, char * raw);
12243 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12244 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12247 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src.c
12248 --- busybox-1.00-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12249 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src.c 2005-10-26 17:36:46.000000000 +0200
12251 +/* pkg_src.c - the itsy package management system
12255 + Copyright (C) 2001 University of Southern California
12257 + This program is free software; you can redistribute it and/or
12258 + modify it under the terms of the GNU General Public License as
12259 + published by the Free Software Foundation; either version 2, or (at
12260 + your option) any later version.
12262 + This program is distributed in the hope that it will be useful, but
12263 + WITHOUT ANY WARRANTY; without even the implied warranty of
12264 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12265 + General Public License for more details.
12270 +#include "pkg_src.h"
12271 +#include "str_util.h"
12273 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12275 + src->gzip = gzip;
12276 + src->name = str_dup_safe (name);
12277 + src->value = str_dup_safe (base_url);
12279 + src->extra_data = str_dup_safe (extra_data);
12281 + src->extra_data = NULL;
12285 +void pkg_src_deinit(pkg_src_t *src)
12287 + free (src->name);
12288 + free (src->value);
12289 + if (src->extra_data)
12290 + free (src->extra_data);
12294 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src.h
12295 --- busybox-1.00-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12296 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src.h 2005-10-26 17:36:46.000000000 +0200
12298 +/* pkg_src.h - the itsy package management system
12302 + Copyright (C) 2001 University of Southern California
12304 + This program is free software; you can redistribute it and/or
12305 + modify it under the terms of the GNU General Public License as
12306 + published by the Free Software Foundation; either version 2, or (at
12307 + your option) any later version.
12309 + This program is distributed in the hope that it will be useful, but
12310 + WITHOUT ANY WARRANTY; without even the implied warranty of
12311 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12312 + General Public License for more details.
12318 +#include "nv_pair.h"
12324 + char *extra_data;
12328 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12329 +void pkg_src_deinit(pkg_src_t *src);
12332 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src_list.c
12333 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12334 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src_list.c 2005-10-26 17:36:46.000000000 +0200
12336 +/* pkg_src_list.c - the itsy package management system
12340 + Copyright (C) 2001 University of Southern California
12342 + This program is free software; you can redistribute it and/or
12343 + modify it under the terms of the GNU General Public License as
12344 + published by the Free Software Foundation; either version 2, or (at
12345 + your option) any later version.
12347 + This program is distributed in the hope that it will be useful, but
12348 + WITHOUT ANY WARRANTY; without even the implied warranty of
12349 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12350 + General Public License for more details.
12355 +#include "pkg_src_list.h"
12356 +#include "void_list.h"
12358 +int pkg_src_list_init(pkg_src_list_t *list)
12360 + return void_list_init((void_list_t *) list);
12363 +void pkg_src_list_deinit(pkg_src_list_t *list)
12365 + pkg_src_list_elt_t *iter;
12366 + pkg_src_t *pkg_src;
12368 + for (iter = list->head; iter; iter = iter->next) {
12369 + pkg_src = iter->data;
12370 + pkg_src_deinit(pkg_src);
12372 + /* malloced in pkg_src_list_append */
12374 + iter->data = NULL;
12376 + void_list_deinit((void_list_t *) list);
12379 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12380 + const char *name, const char *base_url, const char *extra_data,
12385 + /* freed in pkg_src_list_deinit */
12386 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12388 + if (pkg_src == NULL) {
12389 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12392 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12394 + err = void_list_append((void_list_t *) list, pkg_src);
12402 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12404 + return void_list_push((void_list_t *) list, data);
12407 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12409 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12411 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src_list.h
12412 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12413 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_src_list.h 2005-10-26 17:36:46.000000000 +0200
12415 +/* pkg_src_list.h - the itsy package management system
12419 + Copyright (C) 2001 University of Southern California
12421 + This program is free software; you can redistribute it and/or
12422 + modify it under the terms of the GNU General Public License as
12423 + published by the Free Software Foundation; either version 2, or (at
12424 + your option) any later version.
12426 + This program is distributed in the hope that it will be useful, but
12427 + WITHOUT ANY WARRANTY; without even the implied warranty of
12428 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12429 + General Public License for more details.
12432 +#ifndef PKG_SRC_LIST_H
12433 +#define PKG_SRC_LIST_H
12435 +#include "pkg_src.h"
12437 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12438 +struct pkg_src_list_elt
12440 + pkg_src_list_elt_t *next;
12444 +typedef struct pkg_src_list pkg_src_list_t;
12445 +struct pkg_src_list
12447 + pkg_src_list_elt_t pre_head;
12448 + pkg_src_list_elt_t *head;
12449 + pkg_src_list_elt_t *tail;
12452 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12454 + if (list->head == NULL)
12460 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12461 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12463 +int pkg_src_list_init(pkg_src_list_t *list);
12464 +void pkg_src_list_deinit(pkg_src_list_t *list);
12466 +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);
12467 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12468 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12472 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.c busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_vec.c
12473 --- busybox-1.00-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12474 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_vec.c 2005-10-26 17:36:46.000000000 +0200
12476 +/* pkg_vec.c - the itsy package management system
12480 + Copyright (C) 2002 Compaq Computer Corporation
12482 + This program is free software; you can redistribute it and/or
12483 + modify it under the terms of the GNU General Public License as
12484 + published by the Free Software Foundation; either version 2, or (at
12485 + your option) any later version.
12487 + This program is distributed in the hope that it will be useful, but
12488 + WITHOUT ANY WARRANTY; without even the implied warranty of
12489 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12490 + General Public License for more details.
12493 +#include <stdlib.h>
12494 +#include <fnmatch.h>
12495 +#include "xregex.h"
12499 +pkg_vec_t * pkg_vec_alloc(void)
12501 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12503 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12506 + vec->pkgs = NULL;
12512 +void pkg_vec_free(pkg_vec_t *vec)
12519 + * assumption: all names in a vector are identical
12520 + * assumption: all version strings are trimmed,
12521 + * so identical versions have identical version strings,
12522 + * implying identical packages; let's marry these
12524 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12529 + /* look for a duplicate pkg by name, version, and architecture */
12530 + for (i = 0; i < vec->len; i++)
12531 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12532 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12533 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12535 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12536 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12540 + /* we didn't find one, add it */
12542 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12543 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12545 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12546 + vec->pkgs[vec->len] = pkg;
12550 + /* update the one that we have */
12552 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12553 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12554 + if (set_status) {
12555 + /* this is from the status file, so need to merge with existing database */
12556 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12557 + pkg_merge(vec->pkgs[i], pkg, set_status);
12558 + /* XXX: CLEANUP: It's not so polite to free something here
12559 + that was passed in from above. */
12563 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12564 + /* just overwrite the old one */
12565 + pkg_deinit(vec->pkgs[i]);
12566 + free(vec->pkgs[i]);
12567 + vec->pkgs[i] = pkg;
12569 + return vec->pkgs[i];
12573 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12578 + /* look for a duplicate pkg by name, version, and architecture */
12579 + for (i = 0; i < vec->len; i++)
12580 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12581 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12582 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12587 + /* we didn't find one, add it */
12589 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12590 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12595 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12598 + for (i = 0; i < vec->len; i++)
12599 + if (vec->pkgs[i] == apkg)
12604 +typedef int (*compare_fcn_t)(const void *, const void *);
12605 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12607 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12610 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12612 + int npkgs = vec->len;
12614 + for (i = 0; i < npkgs; i++) {
12615 + pkg_t *pkg = vec->pkgs[i];
12616 + pkg->state_flag &= ~SF_MARKED;
12621 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12623 + int matching_count = 0;
12624 + pkg_t **pkgs = vec->pkgs;
12625 + int npkgs = vec->len;
12627 + for (i = 0; i < npkgs; i++) {
12628 + pkg_t *pkg = pkgs[i];
12629 + if (fnmatch(pattern, pkg->name, 0)==0) {
12630 + pkg->state_flag |= SF_MARKED;
12631 + matching_count++;
12634 + return matching_count;
12638 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12640 + abstract_pkg_vec_t * vec ;
12641 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12643 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12646 + vec->pkgs = NULL;
12652 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12659 + * assumption: all names in a vector are unique
12661 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12665 + /* look for a duplicate pkg by name */
12666 + for(i = 0; i < vec->len; i++)
12667 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12670 + /* we didn't find one, add it */
12671 + if(i == vec->len){
12673 + (abstract_pkg_t **)
12674 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12675 + vec->pkgs[vec->len] = pkg;
12680 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12682 + if (vec->len > i)
12683 + return vec->pkgs[i];
12688 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12691 + for (i = 0; i < vec->len; i++)
12692 + if (vec->pkgs[i] == apkg)
12697 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12699 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12702 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.h busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_vec.h
12703 --- busybox-1.00-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12704 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/pkg_vec.h 2005-10-26 17:36:46.000000000 +0200
12706 +/* pkg_vec.h - the itsy package management system
12710 + Copyright (C) 2002 Compaq Computer Corporation
12712 + This program is free software; you can redistribute it and/or
12713 + modify it under the terms of the GNU General Public License as
12714 + published by the Free Software Foundation; either version 2, or (at
12715 + your option) any later version.
12717 + This program is distributed in the hope that it will be useful, but
12718 + WITHOUT ANY WARRANTY; without even the implied warranty of
12719 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12720 + General Public License for more details.
12726 +typedef struct pkg pkg_t;
12727 +typedef struct abstract_pkg abstract_pkg_t;
12734 +typedef struct pkg_vec pkg_vec_t;
12736 +struct abstract_pkg_vec
12738 + abstract_pkg_t **pkgs;
12741 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12744 +pkg_vec_t * pkg_vec_alloc(void);
12745 +void pkg_vec_free(pkg_vec_t *vec);
12746 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12748 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12749 +/* pkg_vec_insert_merge: might munge pkg.
12750 +* returns the pkg that is in the pkg graph */
12751 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12752 +/* this one never munges pkg */
12753 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12754 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12755 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12757 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12758 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12760 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12761 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12762 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12763 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12764 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12765 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12768 diff -ruN busybox-1.00-orig/archival/libipkg/sprintf_alloc.h busybox-1.00+ipkg-0.99.154/archival/libipkg/sprintf_alloc.h
12769 --- busybox-1.00-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12770 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/sprintf_alloc.h 2005-10-26 17:36:46.000000000 +0200
12772 +/* sprintf_alloca.c -- like sprintf with memory allocation
12776 + Copyright (C) 2001 University of Southern California
12778 + This program is free software; you can redistribute it and/or modify
12779 + it under the terms of the GNU General Public License as published by
12780 + the Free Software Foundation; either version 2, or (at your option)
12781 + any later version.
12783 + This program is distributed in the hope that it will be useful,
12784 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12786 + GNU General Public License for more details.
12789 +#ifndef SPRINTF_ALLOC_H
12790 +#define SPRINTF_ALLOC_H
12792 +#include "libbb.h"
12794 +#define sprintf_alloc bb_xasprintf
12797 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/str_list.c
12798 --- busybox-1.00-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12799 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/str_list.c 2005-10-26 17:36:46.000000000 +0200
12801 +/* str_list.c - the itsy package management system
12805 + Copyright (C) 2001 University of Southern California
12807 + This program is free software; you can redistribute it and/or
12808 + modify it under the terms of the GNU General Public License as
12809 + published by the Free Software Foundation; either version 2, or (at
12810 + your option) any later version.
12812 + This program is distributed in the hope that it will be useful, but
12813 + WITHOUT ANY WARRANTY; without even the implied warranty of
12814 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12815 + General Public License for more details.
12820 +#include "str_list.h"
12822 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12824 + return void_list_elt_init((void_list_elt_t *) elt, data);
12827 +void str_list_elt_deinit(str_list_elt_t *elt)
12829 + void_list_elt_deinit((void_list_elt_t *) elt);
12832 +str_list_t *str_list_alloc()
12834 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12836 + str_list_init(list);
12840 +int str_list_init(str_list_t *list)
12842 + return void_list_init((void_list_t *) list);
12845 +void str_list_deinit(str_list_t *list)
12847 + void_list_deinit((void_list_t *) list);
12850 +int str_list_append(str_list_t *list, char *data)
12852 + return void_list_append((void_list_t *) list, data);
12855 +int str_list_push(str_list_t *list, char *data)
12857 + return void_list_push((void_list_t *) list, data);
12860 +str_list_elt_t *str_list_pop(str_list_t *list)
12862 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12865 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12867 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12868 + (void_list_elt_t **) iter);
12871 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12873 + return (char *)void_list_remove_elt((void_list_t *) list,
12874 + (void *)target_str,
12875 + (void_list_cmp_t)strcmp);
12877 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/str_list.h
12878 --- busybox-1.00-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
12879 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/str_list.h 2005-10-26 17:36:46.000000000 +0200
12881 +/* str_list.h - the itsy package management system
12885 + Copyright (C) 2001 University of Southern California
12887 + This program is free software; you can redistribute it and/or
12888 + modify it under the terms of the GNU General Public License as
12889 + published by the Free Software Foundation; either version 2, or (at
12890 + your option) any later version.
12892 + This program is distributed in the hope that it will be useful, but
12893 + WITHOUT ANY WARRANTY; without even the implied warranty of
12894 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12895 + General Public License for more details.
12898 +#ifndef STR_LIST_H
12899 +#define STR_LIST_H
12901 +#include "void_list.h"
12903 +typedef struct str_list_elt str_list_elt_t;
12904 +struct str_list_elt
12906 + str_list_elt_t *next;
12910 +typedef struct xstr_list str_list_t;
12913 + str_list_elt_t pre_head;
12914 + str_list_elt_t *head;
12915 + str_list_elt_t *tail;
12918 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12919 +void str_list_elt_deinit(str_list_elt_t *elt);
12921 +str_list_t *str_list_alloc(void);
12922 +int str_list_init(str_list_t *list);
12923 +void str_list_deinit(str_list_t *list);
12925 +int str_list_append(str_list_t *list, char *data);
12926 +int str_list_push(str_list_t *list, char *data);
12927 +str_list_elt_t *str_list_pop(str_list_t *list);
12928 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12929 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12932 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.c busybox-1.00+ipkg-0.99.154/archival/libipkg/str_util.c
12933 --- busybox-1.00-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
12934 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/str_util.c 2005-10-26 17:36:46.000000000 +0200
12936 +/* str_utils.c - the itsy package management system
12940 + Copyright (C) 2001 University of Southern California
12942 + This program is free software; you can redistribute it and/or
12943 + modify it under the terms of the GNU General Public License as
12944 + published by the Free Software Foundation; either version 2, or (at
12945 + your option) any later version.
12947 + This program is distributed in the hope that it will be useful, but
12948 + WITHOUT ANY WARRANTY; without even the implied warranty of
12949 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12950 + General Public License for more details.
12955 +int str_starts_with(const char *str, const char *prefix)
12957 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12960 +int str_ends_with(const char *str, const char *suffix)
12965 + str_len = strlen(str);
12966 + suffix_len = strlen(suffix);
12968 + if (str_len < suffix_len) {
12972 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12975 +int str_chomp(char *str)
12977 + if (str[strlen(str) - 1] == '\n') {
12978 + str[strlen(str) - 1] = '\0';
12984 +int str_tolower(char *str)
12987 + *str = tolower(*str);
12994 +int str_toupper(char *str)
12997 + *str = toupper(*str);
13004 +char *str_dup_safe(const char *str)
13006 + return str ? strdup(str) : NULL;
13009 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.h busybox-1.00+ipkg-0.99.154/archival/libipkg/str_util.h
13010 --- busybox-1.00-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13011 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/str_util.h 2005-10-26 17:36:46.000000000 +0200
13013 +/* str_utils.h - the itsy package management system
13017 + Copyright (C) 2001 University of Southern California
13019 + This program is free software; you can redistribute it and/or
13020 + modify it under the terms of the GNU General Public License as
13021 + published by the Free Software Foundation; either version 2, or (at
13022 + your option) any later version.
13024 + This program is distributed in the hope that it will be useful, but
13025 + WITHOUT ANY WARRANTY; without even the implied warranty of
13026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13027 + General Public License for more details.
13030 +#ifndef STR_UTILS_H
13031 +#define STR_UTILS_H
13033 +int str_starts_with(const char *str, const char *prefix);
13034 +int str_ends_with(const char *str, const char *suffix);
13035 +int str_chomp(char *str);
13036 +int str_tolower(char *str);
13037 +int str_toupper(char *str);
13038 +char *str_dup_safe(const char *str);
13041 diff -ruN busybox-1.00-orig/archival/libipkg/user.c busybox-1.00+ipkg-0.99.154/archival/libipkg/user.c
13042 --- busybox-1.00-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13043 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/user.c 2005-10-26 17:36:46.000000000 +0200
13045 +/* user.c - the itsy package management system
13049 + Copyright (C) 2002 Hewlett Packard Company
13050 + Copyright (C) 2001 University of Southern California
13052 + This program is free software; you can redistribute it and/or
13053 + modify it under the terms of the GNU General Public License as
13054 + published by the Free Software Foundation; either version 2, or (at
13055 + your option) any later version.
13057 + This program is distributed in the hope that it will be useful, but
13058 + WITHOUT ANY WARRANTY; without even the implied warranty of
13059 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13060 + General Public License for more details.
13063 +#include <stdio.h>
13064 +#include <stdarg.h>
13065 +#include "file_util.h"
13066 +#include "str_util.h"
13068 +#include "libipkg.h"
13073 +static char *question = NULL;
13074 +static int question_len = 255;
13076 +char *get_user_response(const char *format, ...)
13078 + int len = question_len;
13081 + va_start(ap, format);
13084 + vprintf(format, ap);
13086 + response = file_read_line_alloc(stdin);
13087 + } while (response == NULL);
13090 + if (question == NULL || len > question_len) {
13091 + question = realloc(question, len + 1);
13092 + question_len = len;
13094 + len = vsnprintf(question,question_len,format,ap);
13095 + } while (len > question_len);
13096 + response = strdup(ipkg_cb_response(question));
13098 + str_chomp(response);
13099 + str_tolower(response);
13103 diff -ruN busybox-1.00-orig/archival/libipkg/user.h busybox-1.00+ipkg-0.99.154/archival/libipkg/user.h
13104 --- busybox-1.00-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13105 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/user.h 2005-10-26 17:36:46.000000000 +0200
13107 +/* user.c - the itsy package management system
13111 + Copyright (C) 2002 Hewlett Packard Company
13112 + Copyright (C) 2001 University of Southern California
13114 + This program is free software; you can redistribute it and/or
13115 + modify it under the terms of the GNU General Public License as
13116 + published by the Free Software Foundation; either version 2, or (at
13117 + your option) any later version.
13119 + This program is distributed in the hope that it will be useful, but
13120 + WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13122 + General Public License for more details.
13125 +#include <stdio.h>
13126 +#include <stdarg.h>
13128 +char *get_user_response(const char *format, ...);
13130 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.c busybox-1.00+ipkg-0.99.154/archival/libipkg/void_list.c
13131 --- busybox-1.00-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13132 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/void_list.c 2005-10-26 17:36:46.000000000 +0200
13134 +/* void_list.c - the itsy package management system
13138 + Copyright (C) 2001 University of Southern California
13140 + This program is free software; you can redistribute it and/or
13141 + modify it under the terms of the GNU General Public License as
13142 + published by the Free Software Foundation; either version 2, or (at
13143 + your option) any later version.
13145 + This program is distributed in the hope that it will be useful, but
13146 + WITHOUT ANY WARRANTY; without even the implied warranty of
13147 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13148 + General Public License for more details.
13152 +#include <errno.h>
13154 +#include "void_list.h"
13156 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13158 + elt->next = NULL;
13159 + elt->data = data;
13164 +void void_list_elt_deinit(void_list_elt_t *elt)
13166 + void_list_elt_init(elt, NULL);
13169 +int void_list_init(void_list_t *list)
13171 + void_list_elt_init(&list->pre_head, NULL);
13172 + list->head = NULL;
13173 + list->pre_head.next = list->head;
13174 + list->tail = NULL;
13179 +void void_list_deinit(void_list_t *list)
13181 + void_list_elt_t *elt;
13183 + while (list->head) {
13184 + elt = void_list_pop(list);
13185 + void_list_elt_deinit(elt);
13186 + /* malloced in void_list_append */
13191 +int void_list_append(void_list_t *list, void *data)
13193 + void_list_elt_t *elt;
13195 + /* freed in void_list_deinit */
13196 + elt = malloc(sizeof(void_list_elt_t));
13197 + if (elt == NULL) {
13198 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13202 + void_list_elt_init(elt, data);
13204 + if (list->tail) {
13205 + list->tail->next = elt;
13206 + list->tail = elt;
13208 + list->head = elt;
13209 + list->pre_head.next = list->head;
13210 + list->tail = elt;
13216 +int void_list_push(void_list_t *list, void *data)
13218 + void_list_elt_t *elt;
13220 + elt = malloc(sizeof(void_list_elt_t));
13221 + if (elt == NULL) {
13222 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13226 + void_list_elt_init(elt, data);
13228 + elt->next = list->head;
13229 + list->head->next = elt;
13230 + if (list->tail == NULL) {
13231 + list->tail = list->head;
13237 +void_list_elt_t *void_list_pop(void_list_t *list)
13239 + void_list_elt_t *elt;
13241 + elt = list->head;
13243 + if (list->head) {
13244 + list->head = list->head->next;
13245 + list->pre_head.next = list->head;
13246 + if (list->head == NULL) {
13247 + list->tail = NULL;
13254 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13256 + void_list_elt_t *prior;
13257 + void_list_elt_t *old_elt;
13261 + old_data = old_elt->data;
13263 + if (old_elt == list->head) {
13264 + prior = &list->pre_head;
13265 + void_list_pop(list);
13267 + for (prior = list->head; prior; prior = prior->next) {
13268 + if (prior->next == old_elt) {
13272 + if (prior == NULL || prior->next != old_elt) {
13273 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13276 + prior->next = old_elt->next;
13278 + if (old_elt == list->tail) {
13279 + list->tail = prior;
13283 + void_list_elt_deinit(old_elt);
13289 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13290 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13292 + void_list_elt_t *prior;
13293 + void_list_elt_t *old_elt = NULL;
13294 + void *old_data = NULL;
13296 + /* first element */
13297 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13298 + old_elt = list->head;
13299 + old_data = list->head->data;
13300 + void_list_pop(list);
13303 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13304 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13305 + old_elt = prior->next;
13306 + old_data = old_elt->data;
13314 + prior->next = old_elt->next;
13316 + if (old_elt == list->tail) {
13317 + list->tail = prior;
13321 + void_list_elt_deinit(old_elt);
13328 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.h busybox-1.00+ipkg-0.99.154/archival/libipkg/void_list.h
13329 --- busybox-1.00-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13330 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/void_list.h 2005-10-26 17:36:46.000000000 +0200
13332 +/* void_list.h - the itsy package management system
13336 + Copyright (C) 2001 University of Southern California
13338 + This program is free software; you can redistribute it and/or
13339 + modify it under the terms of the GNU General Public License as
13340 + published by the Free Software Foundation; either version 2, or (at
13341 + your option) any later version.
13343 + This program is distributed in the hope that it will be useful, but
13344 + WITHOUT ANY WARRANTY; without even the implied warranty of
13345 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13346 + General Public License for more details.
13349 +#ifndef VOID_LIST_H
13350 +#define VOID_LIST_H
13352 +typedef struct void_list_elt void_list_elt_t;
13353 +struct void_list_elt
13355 + void_list_elt_t *next;
13359 +typedef struct void_list void_list_t;
13362 + void_list_elt_t pre_head;
13363 + void_list_elt_t *head;
13364 + void_list_elt_t *tail;
13367 +static inline int void_list_empty(void_list_t *list)
13369 + if (list->head == NULL)
13375 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13376 +void void_list_elt_deinit(void_list_elt_t *elt);
13378 +int void_list_init(void_list_t *list);
13379 +void void_list_deinit(void_list_t *list);
13381 +int void_list_append(void_list_t *list, void *data);
13382 +int void_list_push(void_list_t *list, void *data);
13383 +void_list_elt_t *void_list_pop(void_list_t *list);
13385 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13386 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13387 +typedef int (*void_list_cmp_t)(const void *, const void *);
13388 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13391 diff -ruN busybox-1.00-orig/archival/libipkg/xregex.h busybox-1.00+ipkg-0.99.154/archival/libipkg/xregex.h
13392 --- busybox-1.00-orig/archival/libipkg/xregex.h 1970-01-01 01:00:00.000000000 +0100
13393 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/xregex.h 2005-10-26 17:36:46.000000000 +0200
13395 +/* xregex.h - regex functions with error messages
13399 + Copyright (C) 2001 University of Southern California
13401 + This program is free software; you can redistribute it and/or modify
13402 + it under the terms of the GNU General Public License as published by
13403 + the Free Software Foundation; either version 2, or (at your option)
13404 + any later version.
13406 + This program is distributed in the hope that it will be useful,
13407 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13408 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13409 + GNU General Public License for more details.
13415 +#include "libbb.h"
13417 +static inline void xregfree(regex_t *preg)
13424 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.c busybox-1.00+ipkg-0.99.154/archival/libipkg/xsystem.c
13425 --- busybox-1.00-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13426 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/xsystem.c 2005-10-26 17:36:46.000000000 +0200
13428 +/* xsystem.c - system(3) with error messages
13432 + Copyright (C) 2001 University of Southern California
13434 + This program is free software; you can redistribute it and/or
13435 + modify it under the terms of the GNU General Public License as
13436 + published by the Free Software Foundation; either version 2, or (at
13437 + your option) any later version.
13439 + This program is distributed in the hope that it will be useful, but
13440 + WITHOUT ANY WARRANTY; without even the implied warranty of
13441 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13442 + General Public License for more details.
13446 +#include <sys/wait.h>
13448 +#include "xsystem.h"
13450 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13451 + really need the /bin/sh invocation which takes resources and
13452 + introduces security problems. I should switch all of this to a sort
13453 + of execl() or execv() interface/implementation.
13456 +/* Like system(3), but with error messages printed if the fork fails
13457 + or if the child process dies due to an uncaught signal. Also, the
13458 + return value is a bit simpler:
13460 + -1 if there was any problem
13461 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13462 + as defined in <sys/wait.h>.
13464 +int xsystem(const char *cmd)
13468 + err = system(cmd);
13471 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13472 + __FUNCTION__, cmd);
13476 + if (WIFSIGNALED(err)) {
13477 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13478 + __FUNCTION__, WTERMSIG(err), cmd);
13482 + if (WIFEXITED(err)) {
13483 + /* Normal child exit */
13484 + return WEXITSTATUS(err);
13487 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13488 + __FUNCTION__, err);
13492 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.h busybox-1.00+ipkg-0.99.154/archival/libipkg/xsystem.h
13493 --- busybox-1.00-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13494 +++ busybox-1.00+ipkg-0.99.154/archival/libipkg/xsystem.h 2005-10-26 17:36:46.000000000 +0200
13496 +/* xsystem.h - system(3) with error messages
13500 + Copyright (C) 2001 University of Southern California
13502 + This program is free software; you can redistribute it and/or
13503 + modify it under the terms of the GNU General Public License as
13504 + published by the Free Software Foundation; either version 2, or (at
13505 + your option) any later version.
13507 + This program is distributed in the hope that it will be useful, but
13508 + WITHOUT ANY WARRANTY; without even the implied warranty of
13509 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13510 + General Public License for more details.
13516 +#include <stdlib.h>
13518 +/* Like system(3), but with error messages printed if the fork fails
13519 + or if the child process dies due to an uncaught signal. Also, the
13520 + return value is a bit simpler:
13522 + -1 if there was any problem
13523 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13524 + as defined in <sys/wait.h>.
13526 +int xsystem(const char *cmd);
13530 diff -ruN busybox-1.00-orig/archival/libunarchive/data_extract_all.c busybox-1.00+ipkg-0.99.154/archival/libunarchive/data_extract_all.c
13531 --- busybox-1.00-orig/archival/libunarchive/data_extract_all.c 2004-10-13 08:25:51.000000000 +0200
13532 +++ busybox-1.00+ipkg-0.99.154/archival/libunarchive/data_extract_all.c 2005-10-26 17:36:46.000000000 +0200
13533 @@ -122,3 +122,17 @@
13534 utime(file_header->name, &t);
13538 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13540 + char *name_ptr = archive_handle->file_header->name;
13542 + name_ptr += strspn(name_ptr, "./");
13543 + if (name_ptr[0] != '\0') {
13544 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13545 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13546 + strcat(archive_handle->file_header->name, name_ptr);
13547 + data_extract_all(archive_handle);
13551 diff -ruN busybox-1.00-orig/include/applets.h busybox-1.00+ipkg-0.99.154/include/applets.h
13552 --- busybox-1.00-orig/include/applets.h 2004-08-27 01:01:34.000000000 +0200
13553 +++ busybox-1.00+ipkg-0.99.154/include/applets.h 2005-10-26 17:36:46.000000000 +0200
13554 @@ -298,6 +298,9 @@
13555 #ifdef CONFIG_IPCALC
13556 APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13558 +#ifdef CONFIG_IPKG
13559 + APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
13561 #ifdef CONFIG_IPLINK
13562 APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13564 diff -ruN busybox-1.00-orig/include/libbb.h busybox-1.00+ipkg-0.99.154/include/libbb.h
13565 --- busybox-1.00-orig/include/libbb.h 2004-09-15 05:04:07.000000000 +0200
13566 +++ busybox-1.00+ipkg-0.99.154/include/libbb.h 2005-10-26 17:36:46.000000000 +0200
13567 @@ -484,4 +484,17 @@
13569 extern int hash_fd(int fd, const size_t size, const uint8_t hash_algo, uint8_t *hashval);
13571 +struct md5_ctx_t {
13576 + uint32_t total[2];
13578 + char buffer[128];
13580 +extern void md5_begin(struct md5_ctx_t *ctx);
13581 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx);
13582 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
13584 #endif /* __LIBCONFIG_H__ */
13585 diff -ruN busybox-1.00-orig/include/unarchive.h busybox-1.00+ipkg-0.99.154/include/unarchive.h
13586 --- busybox-1.00-orig/include/unarchive.h 2004-03-15 09:28:38.000000000 +0100
13587 +++ busybox-1.00+ipkg-0.99.154/include/unarchive.h 2005-10-26 17:36:46.000000000 +0200
13590 extern void data_skip(archive_handle_t *archive_handle);
13591 extern void data_extract_all(archive_handle_t *archive_handle);
13592 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13593 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13594 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13596 diff -ruN busybox-1.00-orig/include/usage.h busybox-1.00+ipkg-0.99.154/include/usage.h
13597 --- busybox-1.00-orig/include/usage.h 2004-09-14 18:23:56.000000000 +0200
13598 +++ busybox-1.00+ipkg-0.99.154/include/usage.h 2005-10-26 17:36:46.000000000 +0200
13599 @@ -836,6 +836,82 @@
13600 "$ ls -la /tmp/busybox*\n" \
13601 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13603 +#define ipkg_trivial_usage \
13604 + "[options...] sub-command [arguments...]"
13605 +#define ipkg_full_usage \
13606 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13608 + "Sub-commands:\n" \
13609 + "\nPackage Manipulation:\n" \
13610 + "\tupdate Update list of available packages\n" \
13611 + "\tupgrade Upgrade all installed packages to latest version\n" \
13612 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13613 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13614 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13615 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13616 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13617 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13619 + "Informational Commands:\n" \
13620 + "\tlist List available packages and descriptions\n" \
13621 + "\tlist_installed List all and only the installed packages and description \n" \
13622 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13623 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13624 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13625 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13626 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13627 + "\tcompare_versions <v1> <op> <v2>\n" \
13628 + "\t compare versions using <= < > >= = << >>\n" \
13629 + "\tprint_architecture prints the architecture.\n" \
13630 + "\tprint_installation_architecture\n" \
13631 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13632 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13633 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13634 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13635 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13636 + "\t prints the installation architecture.\n" \
13639 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13640 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13641 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13642 + "\t 0 errors only\n" \
13643 + "\t 1 normal messages (default)\n" \
13644 + "\t 2 informative messages\n" \
13645 + "\t 3 debug output\n" \
13646 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13647 + "\t-conf <conf_file> Default configuration file location\n" \
13648 + " is /etc/ipkg.conf\n" \
13649 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13650 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13651 + " <dest_name> should be a defined dest name from\n" \
13652 + " the configuration file, (but can also be a\n" \
13653 + " directory name in a pinch).\n" \
13654 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13655 + "\t-offline <offline_root> offline installation of packages.\n" \
13656 + "\t-verbose_wget more wget messages\n" \
13658 + "Force Options (use when ipkg is too smart for its own good):\n" \
13659 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13660 + "\t Install/remove package in spite of failed dependences\n" \
13661 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13662 + " (no prompts). Note that this will not prevent\n" \
13663 + " package installation scripts from prompting.\n" \
13664 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13665 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13666 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13667 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13668 + "\t-noaction No action -- test only\n" \
13669 + "\t-nodeps Do not follow dependences\n" \
13670 + "\t-force-removal-of-dependent-packages\n" \
13671 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13672 + "\t-test No action -- test only\n" \
13673 + "\t-t Specify tmp-dir.\n" \
13674 + "\t--tmp-dir Specify tmp-dir.\n" \
13676 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13677 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13679 #define halt_trivial_usage \
13681 #define halt_full_usage \
13682 diff -ruN busybox-1.00-orig/libbb/hash_fd.c busybox-1.00+ipkg-0.99.154/libbb/hash_fd.c
13683 --- busybox-1.00-orig/libbb/hash_fd.c 2004-03-15 09:28:42.000000000 +0100
13684 +++ busybox-1.00+ipkg-0.99.154/libbb/hash_fd.c 2005-10-26 17:36:46.000000000 +0200
13685 @@ -288,21 +288,10 @@
13686 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
13687 # endif /* MD5SUM_SIZE_VS_SPEED == 0 */
13689 -/* Structure to save state of computation between the single steps. */
13690 -struct md5_ctx_t {
13695 - uint32_t total[2];
13697 - char buffer[128];
13700 /* Initialize structure containing state of computation.
13701 * (RFC 1321, 3.3: Step 3)
13703 -static void md5_begin(struct md5_ctx_t *ctx)
13704 +extern void md5_begin(struct md5_ctx_t *ctx)
13706 ctx->A = 0x67452301;
13707 ctx->B = 0xefcdab89;
13708 @@ -706,7 +695,7 @@
13712 -static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13713 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13715 if (length % 64 == 0) {
13716 md5_hash_block(buffer, length, md5_ctx);
13717 @@ -723,7 +712,7 @@
13718 * IMPORTANT: On some systems it is required that RESBUF is correctly
13719 * aligned for a 32 bits value.
13721 -static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13722 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13724 /* Take yet unprocessed bytes into account. */
13725 uint32_t bytes = ctx->buflen;