1 diff -ruN busybox-1.00-orig/Makefile busybox-1.00+ipkg-0.99.152-pre2/Makefile
2 --- busybox-1.00-orig/Makefile 2004-10-08 07:45:08.000000000 +0000
3 +++ busybox-1.00+ipkg-0.99.152-pre2/Makefile 2005-07-20 13:24:00.000000000 +0000
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.152-pre2/archival/Config.in
14 --- busybox-1.00-orig/archival/Config.in 2004-03-15 08:28:16.000000000 +0000
15 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/Config.in 2005-07-20 16:53:48.805813848 +0000
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.152-pre2/archival/Makefile.in
32 --- busybox-1.00-orig/archival/Makefile.in 2004-10-08 07:45:09.000000000 +0000
33 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/Makefile.in 2005-07-18 11:40:31.000000000 +0000
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.152-pre2/archival/dpkg.c
43 --- busybox-1.00-orig/archival/dpkg.c 2004-04-14 17:51:08.000000000 +0000
44 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/dpkg.c 2005-07-20 13:15:04.000000000 +0000
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.152-pre2/archival/ipkg.c
66 --- busybox-1.00-orig/archival/ipkg.c 1970-01-01 00:00:00.000000000 +0000
67 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/ipkg.c 2005-07-20 13:16:47.000000000 +0000
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.152-pre2/archival/libipkg/Makefile
96 --- busybox-1.00-orig/archival/libipkg/Makefile 1970-01-01 00:00:00.000000000 +0000
97 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/Makefile.in
132 --- busybox-1.00-orig/archival/libipkg/Makefile.in 1970-01-01 00:00:00.000000000 +0000
133 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/Makefile.in 2005-07-20 17:24:44.092767360 +0000
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.152-pre2/archival/libipkg/args.c
219 --- busybox-1.00-orig/archival/libipkg/args.c 1970-01-01 00:00:00.000000000 +0000
220 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.c 2005-07-20 10:38:34.000000000 +0000
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.152-pre2/archival/libipkg/args.h
464 --- busybox-1.00-orig/archival/libipkg/args.h 1970-01-01 00:00:00.000000000 +0000
465 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/args.h 2005-07-19 00:46:01.000000000 +0000
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.152-pre2/archival/libipkg/conffile.c
539 --- busybox-1.00-orig/archival/libipkg/conffile.c 1970-01-01 00:00:00.000000000 +0000
540 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.c 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/conffile.h
607 --- busybox-1.00-orig/archival/libipkg/conffile.h 1970-01-01 00:00:00.000000000 +0000
608 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/conffile_list.c
641 --- busybox-1.00-orig/archival/libipkg/conffile_list.c 1970-01-01 00:00:00.000000000 +0000
642 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.c 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/conffile_list.h
692 --- busybox-1.00-orig/archival/libipkg/conffile_list.h 1970-01-01 00:00:00.000000000 +0000
693 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/conffile_list.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/file_util.c
732 --- busybox-1.00-orig/archival/libipkg/file_util.c 1970-01-01 00:00:00.000000000 +0000
733 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.c 2005-07-18 12:02:26.000000000 +0000
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.152-pre2/archival/libipkg/file_util.h
913 --- busybox-1.00-orig/archival/libipkg/file_util.h 1970-01-01 00:00:00.000000000 +0000
914 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/file_util.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/hash_table.c
946 --- busybox-1.00-orig/archival/libipkg/hash_table.c 1970-01-01 00:00:00.000000000 +0000
947 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.c 2005-07-20 09:45:35.000000000 +0000
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.152-pre2/archival/libipkg/hash_table.h
1105 --- busybox-1.00-orig/archival/libipkg/hash_table.h 1970-01-01 00:00:00.000000000 +0000
1106 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/hash_table.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg.h
1153 --- busybox-1.00-orig/archival/libipkg/ipkg.h 1970-01-01 00:00:00.000000000 +0000
1154 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg.h 2005-07-20 14:12:10.000000000 +0000
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.152"
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.152-pre2/archival/libipkg/ipkg_cmd.c
1231 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 00:00:00.000000000 +0000
1232 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.c 2005-07-20 10:42:05.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_cmd.h
2579 --- busybox-1.00-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 00:00:00.000000000 +0000
2580 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_cmd.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_conf.c
2629 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.c 1970-01-01 00:00:00.000000000 +0000
2630 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.c 2005-07-20 17:31:15.430275016 +0000
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.152-pre2/archival/libipkg/ipkg_conf.h
3342 --- busybox-1.00-orig/archival/libipkg/ipkg_conf.h 1970-01-01 00:00:00.000000000 +0000
3343 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_conf.h 2005-07-19 00:48:24.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_configure.c
3453 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.c 1970-01-01 00:00:00.000000000 +0000
3454 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.c 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_configure.h
3497 --- busybox-1.00-orig/archival/libipkg/ipkg_configure.h 1970-01-01 00:00:00.000000000 +0000
3498 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_configure.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_download.c
3526 --- busybox-1.00-orig/archival/libipkg/ipkg_download.c 1970-01-01 00:00:00.000000000 +0000
3527 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.c 2005-07-20 00:13:02.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_download.h
3721 --- busybox-1.00-orig/archival/libipkg/ipkg_download.h 1970-01-01 00:00:00.000000000 +0000
3722 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_download.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_includes.h
3755 --- busybox-1.00-orig/archival/libipkg/ipkg_includes.h 1970-01-01 00:00:00.000000000 +0000
3756 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_includes.h 2005-07-20 09:16:48.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_install.c
3838 --- busybox-1.00-orig/archival/libipkg/ipkg_install.c 1970-01-01 00:00:00.000000000 +0000
3839 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.c 2005-07-20 10:12:33.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_install.h
5665 --- busybox-1.00-orig/archival/libipkg/ipkg_install.h 1970-01-01 00:00:00.000000000 +0000
5666 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_install.h 2005-07-17 16:10:23.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_message.c
5704 --- busybox-1.00-orig/archival/libipkg/ipkg_message.c 1970-01-01 00:00:00.000000000 +0000
5705 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.c 2005-07-20 10:36:45.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_message.h
5769 --- busybox-1.00-orig/archival/libipkg/ipkg_message.h 1970-01-01 00:00:00.000000000 +0000
5770 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_message.h 2005-07-20 10:37:22.000000000 +0000
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.152-pre2/archival/libipkg/ipkg_remove.c
5805 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.c 1970-01-01 00:00:00.000000000 +0000
5806 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.c 2005-07-17 16:10:24.000000000 +0000
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++;
5863 + /* if caller requested the set of installed dependents */
5864 + if (pdependents) {
5866 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5868 + if ( dependents == NULL ){
5869 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5873 + *pdependents = dependents;
5874 + for (i = 0; i < nprovides; i++) {
5875 + abstract_pkg_t *providee = provides[i];
5876 + abstract_pkg_t **dependers = providee->depended_upon_by;
5877 + abstract_pkg_t *dep_ab_pkg;
5878 + if (dependers == NULL)
5880 + while ((dep_ab_pkg = *dependers++) != NULL) {
5881 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5882 + dependents[p++] = dep_ab_pkg;
5883 + dep_ab_pkg->state_flag |= SF_MARKED;
5887 + dependents[p] = NULL;
5888 + /* now clear the marks */
5889 + for (i = 0; i < p; i++) {
5890 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5891 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5894 + return n_installed_dependents;
5897 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5902 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5903 + abstract_pkg_t * ab_pkg;
5905 + if((ab_pkg = pkg->parent) == NULL){
5906 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5907 + __FUNCTION__, pkg->name);
5911 + if (dependents == NULL)
5914 + // here i am using the dependencies_checked
5915 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5916 + return 0; // has already been encountered in the process
5917 + // of marking packages for removal - Karthik
5918 + ab_pkg->dependencies_checked = 2;
5922 + while (dependents [i] != NULL) {
5923 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5925 + if (dep_ab_pkg->dependencies_checked == 2){
5929 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5930 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5931 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5932 + if (dep_pkg->state_status == SS_INSTALLED) {
5933 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5939 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5940 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5947 + for (i = 0; i < dependent_pkgs->len; i++) {
5948 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i]);
5955 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5957 + abstract_pkg_t *dep_ab_pkg;
5958 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5959 + while ((dep_ab_pkg = *dependents++) != NULL) {
5960 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5961 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5963 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5964 + ipkg_message(conf, IPKG_ERROR, "");
5965 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5966 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5967 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5968 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5969 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5973 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg)
5976 + abstract_pkg_t *parent_pkg = NULL;
5978 + if (pkg->essential) {
5979 + if (conf->force_removal_of_essential_packages) {
5980 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5981 + "\tIf your system breaks, you get to keep both pieces\n",
5984 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5985 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5986 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5987 + "\tits will with the option: -force-removal-of-essential-packages\n",
5989 + return IPKG_PKG_IS_ESSENTIAL;
5993 + if ((parent_pkg = pkg->parent) == NULL)
5996 + /* only attempt to remove dependent installed packages if
5997 + * force_depends is not specified or the package is being
6000 + if (!conf->force_depends
6001 + && !(pkg->state_flag & SF_REPLACE)) {
6002 + abstract_pkg_t **dependents;
6003 + int has_installed_dependents =
6004 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6006 + if (has_installed_dependents) {
6008 + * if this package is depended up by others, then either we should
6009 + * not remove it or we should remove it and all of its dependents
6012 + if (!conf->force_removal_of_dependent_packages
6013 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6014 + return IPKG_PKG_HAS_DEPENDENTS;
6017 + /* remove packages depending on this package - Karthik */
6018 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6020 + if (err) return err;
6024 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6027 + pkg->state_flag |= SF_FILELIST_CHANGED;
6029 + pkg->state_want = SW_DEINSTALL;
6030 + ipkg_state_changed++;
6032 + pkg_run_script(conf, pkg, "prerm", "remove");
6034 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6035 + maintains an empty filelist rather than deleting it. That seems
6036 + like a big pain, and I don't see that that should make a big
6037 + difference, but for anyone who wants tighter compatibility,
6038 + feel free to fix this. */
6039 + remove_data_files_and_list(conf, pkg);
6041 + pkg_run_script(conf, pkg, "postrm", "remove");
6043 + remove_maintainer_scripts_except_postrm(conf, pkg);
6045 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6046 + * space, it doesn't make sense to leave extra configurations, files,
6047 + * and maintainer scripts left around. So, we make remove like purge,
6048 + * and take out all the crap :) */
6050 + remove_postrm(conf, pkg);
6051 + pkg->state_status = SS_NOT_INSTALLED;
6054 + parent_pkg->state_status = SS_NOT_INSTALLED;
6059 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6061 + ipkg_remove_pkg(conf, pkg);
6065 +static int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6067 + str_list_t installed_dirs;
6068 + str_list_t *installed_files;
6069 + str_list_elt_t *iter;
6071 + conffile_t *conffile;
6072 + int removed_a_dir;
6075 + str_list_init(&installed_dirs);
6076 + installed_files = pkg_get_installed_files(pkg);
6078 + for (iter = installed_files->head; iter; iter = iter->next) {
6079 + file_name = iter->data;
6081 + if (file_is_dir(file_name)) {
6082 + str_list_append(&installed_dirs, strdup(file_name));
6086 + conffile = pkg_get_conffile(pkg, file_name);
6088 + /* XXX: QUESTION: Is this right? I figure we only need to
6089 + save the conffile if it has been modified. Is that what
6090 + dpkg does? Or does dpkg preserve all conffiles? If so,
6091 + this seems like a better thing to do to conserve
6093 + if (conffile_has_been_modified(conf, conffile)) {
6094 + printf(" not deleting modified conffile %s\n", file_name);
6100 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6101 + if (!conf->noaction)
6102 + unlink(file_name);
6105 + if (!conf->noaction) {
6107 + removed_a_dir = 0;
6108 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6109 + file_name = iter->data;
6111 + if (rmdir(file_name) == 0) {
6112 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6113 + removed_a_dir = 1;
6114 + str_list_remove(&installed_dirs, &iter);
6117 + } while (removed_a_dir);
6120 + pkg_free_installed_files(pkg);
6121 + /* We have to remove the file list now, so that
6122 + find_pkg_owning_file does not always just report this package */
6123 + pkg_remove_installed_files_list(conf, pkg);
6125 + /* Don't print warning for dirs that are provided by other packages */
6126 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6127 + file_name = iter->data;
6129 + owner = file_hash_get_file_owner(conf, file_name);
6132 + iter->data = NULL;
6133 + str_list_remove(&installed_dirs, &iter);
6138 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6140 + iter->data = NULL;
6142 + str_list_deinit(&installed_dirs);
6147 +static int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6150 + char *globpattern;
6153 + if (conf->noaction) return 0;
6155 + sprintf_alloc(&globpattern, "%s/%s.*",
6156 + pkg->dest->info_dir, pkg->name);
6157 + err = glob(globpattern, 0, NULL, &globbuf);
6158 + free(globpattern);
6163 + for (i = 0; i < globbuf.gl_pathc; i++) {
6164 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6167 + unlink(globbuf.gl_pathv[i]);
6169 + globfree(&globbuf);
6174 +static int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6176 + char *postrm_file_name;
6178 + if (conf->noaction) return 0;
6180 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6181 + pkg->dest->info_dir, pkg->name);
6182 + unlink(postrm_file_name);
6183 + free(postrm_file_name);
6187 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_remove.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.h
6188 --- busybox-1.00-orig/archival/libipkg/ipkg_remove.h 1970-01-01 00:00:00.000000000 +0000
6189 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_remove.h 2005-07-17 16:10:24.000000000 +0000
6191 +/* ipkg_remove.h - the itsy package management system
6195 + Copyright (C) 2001 University of Southern California
6197 + This program is free software; you can redistribute it and/or
6198 + modify it under the terms of the GNU General Public License as
6199 + published by the Free Software Foundation; either version 2, or (at
6200 + your option) any later version.
6202 + This program is distributed in the hope that it will be useful, but
6203 + WITHOUT ANY WARRANTY; without even the implied warranty of
6204 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6205 + General Public License for more details.
6208 +#ifndef IPKG_REMOVE_H
6209 +#define IPKG_REMOVE_H
6212 +#include "ipkg_conf.h"
6214 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6215 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6216 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6217 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6220 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.c
6221 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 00:00:00.000000000 +0000
6222 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.c 2005-07-17 16:10:24.000000000 +0000
6224 +/* ipkg_upgrade.c - the itsy package management system
6227 + Copyright (C) 2001 University of Southern California
6229 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6231 + This program is free software; you can redistribute it and/or
6232 + modify it under the terms of the GNU General Public License as
6233 + published by the Free Software Foundation; either version 2, or (at
6234 + your option) any later version.
6236 + This program is distributed in the hope that it will be useful, but
6237 + WITHOUT ANY WARRANTY; without even the implied warranty of
6238 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6239 + General Public License for more details.
6243 +#include "ipkg_install.h"
6244 +#include "ipkg_message.h"
6246 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6250 + char *old_version, *new_version;
6252 + if (old->state_flag & SF_HOLD) {
6253 + ipkg_message(conf, IPKG_NOTICE,
6254 + "Not upgrading package %s which is marked "
6255 + "hold (flags=%#x)\n", old->name, old->state_flag);
6259 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6260 + if (new == NULL) {
6261 + old_version = pkg_version_str_alloc(old);
6262 + ipkg_message(conf, IPKG_NOTICE,
6263 + "Assuming locally installed package %s (%s) "
6264 + "is up to date.\n", old->name, old_version);
6265 + free(old_version);
6269 + old_version = pkg_version_str_alloc(old);
6270 + new_version = pkg_version_str_alloc(new);
6272 + cmp = pkg_compare_versions(old, new);
6273 + ipkg_message(conf, IPKG_DEBUG,
6274 + "comparing visible versions of pkg %s:"
6275 + "\n\t%s is installed "
6276 + "\n\t%s is available "
6277 + "\n\t%d was comparison result\n",
6278 + old->name, old_version, new_version, cmp);
6280 + ipkg_message(conf, IPKG_INFO,
6281 + "Package %s (%s) installed in %s is up to date.\n",
6282 + old->name, old_version, old->dest->name);
6283 + free(old_version);
6284 + free(new_version);
6286 + } else if (cmp > 0) {
6287 + ipkg_message(conf, IPKG_NOTICE,
6288 + "Not downgrading package %s on %s from %s to %s.\n",
6289 + old->name, old->dest->name, old_version, new_version);
6290 + free(old_version);
6291 + free(new_version);
6293 + } else if (cmp < 0) {
6294 + new->dest = old->dest;
6295 + old->state_want = SW_DEINSTALL;
6298 + new->state_flag |= SF_USER;
6299 + return ipkg_install_pkg(conf, new);
6301 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.h
6302 --- busybox-1.00-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 00:00:00.000000000 +0000
6303 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_upgrade.h 2005-07-17 16:10:24.000000000 +0000
6305 +/* ipkg_upgrade.c - the itsy package management system
6307 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6309 + This program is free software; you can redistribute it and/or
6310 + modify it under the terms of the GNU General Public License as
6311 + published by the Free Software Foundation; either version 2, or (at
6312 + your option) any later version.
6314 + This program is distributed in the hope that it will be useful, but
6315 + WITHOUT ANY WARRANTY; without even the implied warranty of
6316 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6317 + General Public License for more details.
6322 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6323 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.c
6324 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.c 1970-01-01 00:00:00.000000000 +0000
6325 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.c 2005-07-20 10:16:42.000000000 +0000
6327 +/* ipkg_utils.c - the itsy package management system
6331 + Copyright (C) 2002 Compaq Computer Corporation
6333 + This program is free software; you can redistribute it and/or
6334 + modify it under the terms of the GNU General Public License as
6335 + published by the Free Software Foundation; either version 2, or (at
6336 + your option) any later version.
6338 + This program is distributed in the hope that it will be useful, but
6339 + WITHOUT ANY WARRANTY; without even the implied warranty of
6340 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6341 + General Public License for more details.
6347 +#include <sys/vfs.h>
6349 +#include "ipkg_utils.h"
6351 +#include "pkg_hash.h"
6353 +struct errlist* error_list;
6355 +int get_available_blocks(char * filesystem)
6357 + struct statfs sfs;
6359 + if(statfs(filesystem, &sfs)){
6360 + fprintf(stderr, "bad statfs\n");
6363 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6364 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6367 +char **read_raw_pkgs_from_file(const char *file_name)
6372 + if(!(fp = fopen(file_name, "r"))){
6373 + fprintf(stderr, "can't get %s open for read\n", file_name);
6377 + ret = read_raw_pkgs_from_stream(fp);
6384 +char **read_raw_pkgs_from_stream(FILE *fp)
6386 + char **raw = NULL, *buf, *scout;
6388 + size_t size = 512;
6390 + buf = malloc (size);
6392 + while (fgets(buf, size, fp)) {
6393 + while (strlen (buf) == (size - 1)
6394 + && buf[size-2] != '\n') {
6395 + size_t o = size - 1;
6397 + buf = realloc (buf, size);
6398 + if (fgets (buf + o, size - o, fp) == NULL)
6403 + raw = realloc(raw, (count + 50) * sizeof(char *));
6405 + if((scout = strchr(buf, '\n')))
6408 + raw[count++] = strdup(buf);
6411 + raw = realloc(raw, (count + 1) * sizeof(char *));
6412 + raw[count] = NULL;
6419 +/* something to remove whitespace, a hash pooper */
6420 +char *trim_alloc(char *line)
6423 + char *dest, *src, *end;
6425 + new = malloc(strlen(line) + 1);
6426 + if ( new == NULL ){
6427 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6430 + dest = new, src = line, end = line + (strlen(line) - 1);
6432 + /* remove it from the front */
6437 + /* and now from the back */
6438 + while((end > src) &&
6444 + /* this does from the first space
6445 + * blasting away any versions stuff in depends
6456 +int line_is_blank(const char *line)
6460 + for (s = line; *s; s++) {
6467 +void push_error_list(struct errlist ** errors, char * msg){
6468 + struct errlist *err_lst_tmp;
6471 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6472 + err_lst_tmp->errmsg=strdup(msg) ;
6473 + err_lst_tmp->next = *errors;
6474 + *errors = err_lst_tmp;
6478 +void reverse_error_list(struct errlist **errors){
6479 + struct errlist *result=NULL;
6480 + struct errlist *current= *errors;
6481 + struct errlist *next;
6483 + while ( current != NULL ) {
6484 + next = current->next;
6485 + current->next=result;
6494 +void free_error_list(struct errlist **errors){
6495 + struct errlist *current = *errors;
6497 + while (current != NULL) {
6498 + free(current->errmsg);
6499 + current = (*errors)->next;
6501 + *errors = current;
6508 diff -ruN busybox-1.00-orig/archival/libipkg/ipkg_utils.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.h
6509 --- busybox-1.00-orig/archival/libipkg/ipkg_utils.h 1970-01-01 00:00:00.000000000 +0000
6510 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/ipkg_utils.h 2005-07-17 16:10:24.000000000 +0000
6512 +/* ipkg_utils.h - the itsy package management system
6516 + Copyright (C) 2002 Compaq Computer Corporation
6518 + This program is free software; you can redistribute it and/or
6519 + modify it under the terms of the GNU General Public License as
6520 + published by the Free Software Foundation; either version 2, or (at
6521 + your option) any later version.
6523 + This program is distributed in the hope that it will be useful, but
6524 + WITHOUT ANY WARRANTY; without even the implied warranty of
6525 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6526 + General Public License for more details.
6529 +#ifndef IPKG_UTILS_H
6530 +#define IPKG_UTILS_H
6534 +int get_available_blocks(char * filesystem);
6535 +char **read_raw_pkgs_from_file(const char *file_name);
6536 +char **read_raw_pkgs_from_stream(FILE *fp);
6537 +char *trim_alloc(char * line);
6538 +int line_is_blank(const char *line);
6541 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.c
6542 --- busybox-1.00-orig/archival/libipkg/libipkg.c 1970-01-01 00:00:00.000000000 +0000
6543 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.c 2005-07-20 10:22:50.000000000 +0000
6545 +/* ipkglib.c - the itsy package management system
6549 + Copyright (C) 2003 kernel concepts
6551 + This program is free software; you can redistribute it and/or
6552 + modify it under the terms of the GNU General Public License as
6553 + published by the Free Software Foundation; either version 2, or (at
6554 + your option) any later version.
6556 + This program is distributed in the hope that it will be useful, but
6557 + WITHOUT ANY WARRANTY; without even the implied warranty of
6558 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6559 + General Public License for more details.
6565 +#include "ipkg_includes.h"
6566 +#include "libipkg.h"
6569 +#include "ipkg_conf.h"
6570 +#include "ipkg_cmd.h"
6571 +#include "file_util.h"
6575 +ipkg_message_callback ipkg_cb_message = NULL;
6576 +ipkg_response_callback ipkg_cb_response = NULL;
6577 +ipkg_status_callback ipkg_cb_status = NULL;
6578 +ipkg_list_callback ipkg_cb_list = NULL;
6582 +ipkg_init (ipkg_message_callback mcall,
6583 + ipkg_response_callback rcall,
6586 + ipkg_cb_message = mcall;
6587 + ipkg_cb_response = rcall;
6596 +ipkg_deinit (args_t * args)
6598 + args_deinit (args);
6599 + ipkg_cb_message = NULL;
6600 + ipkg_cb_response = NULL;
6602 + /* place other cleanup stuff here */
6609 +ipkg_packages_list(args_t *args,
6610 + const char *packages,
6611 + ipkg_list_callback cblist,
6615 + ipkg_conf_t ipkg_conf;
6618 + err = ipkg_conf_init (&ipkg_conf, args);
6624 + ipkg_cb_list = cblist;
6625 + /* we need to do this because of static declarations,
6626 + * maybe a good idea to change */
6627 + cmd = ipkg_cmd_find ("list");
6629 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6631 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6632 + ipkg_cb_list = NULL;
6633 + ipkg_conf_deinit (&ipkg_conf);
6639 +ipkg_packages_status(args_t *args,
6640 + const char *packages,
6641 + ipkg_status_callback cbstatus,
6645 + ipkg_conf_t ipkg_conf;
6648 + err = ipkg_conf_init (&ipkg_conf, args);
6654 + ipkg_cb_status = cbstatus;
6656 + /* we need to do this because of static declarations,
6657 + * maybe a good idea to change */
6658 + cmd = ipkg_cmd_find ("status");
6660 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6662 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6664 + ipkg_cb_status = NULL;
6665 + ipkg_conf_deinit (&ipkg_conf);
6671 +ipkg_packages_info(args_t *args,
6672 + const char *packages,
6673 + ipkg_status_callback cbstatus,
6677 + ipkg_conf_t ipkg_conf;
6680 + err = ipkg_conf_init (&ipkg_conf, args);
6686 + ipkg_cb_status = cbstatus;
6688 + /* we need to do this because of static declarations,
6689 + * maybe a good idea to change */
6690 + cmd = ipkg_cmd_find ("info");
6692 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6694 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6696 + ipkg_cb_status = NULL;
6697 + ipkg_conf_deinit (&ipkg_conf);
6703 +ipkg_packages_install (args_t * args, const char *name)
6706 + ipkg_conf_t ipkg_conf;
6709 + /* this error should be handled in application */
6710 + if (!name || !strlen (name))
6713 + err = ipkg_conf_init (&ipkg_conf, args);
6719 + /* we need to do this because of static declarations,
6720 + * maybe a good idea to change */
6721 + cmd = ipkg_cmd_find ("install");
6722 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6724 + ipkg_conf_deinit(&ipkg_conf);
6730 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6733 + ipkg_conf_t ipkg_conf;
6736 + /* this error should be handled in application */
6737 + if (!name || !strlen (name))
6740 + err = ipkg_conf_init (&ipkg_conf, args);
6746 + /* we need to do this because of static declarations,
6747 + * maybe a good idea to change */
6749 + cmd = ipkg_cmd_find ("purge");
6751 + cmd = ipkg_cmd_find ("remove");
6753 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6755 + ipkg_conf_deinit(&ipkg_conf);
6761 +ipkg_lists_update(args_t *args)
6764 + ipkg_conf_t ipkg_conf;
6767 + err = ipkg_conf_init (&ipkg_conf, args);
6773 + /* we need to do this because of static declarations,
6774 + * maybe a good idea to change */
6775 + cmd = ipkg_cmd_find ("update");
6777 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6779 + ipkg_conf_deinit(&ipkg_conf);
6785 +ipkg_packages_upgrade(args_t *args)
6788 + ipkg_conf_t ipkg_conf;
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6797 + /* we need to do this because of static declarations,
6798 + * maybe a good idea to change */
6799 + cmd = ipkg_cmd_find ("upgrade");
6801 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6803 + ipkg_conf_deinit(&ipkg_conf);
6809 +ipkg_packages_download (args_t * args, const char *name)
6812 + ipkg_conf_t ipkg_conf;
6815 + /* this error should be handled in application */
6816 + if (!name || !strlen (name))
6819 + err = ipkg_conf_init (&ipkg_conf, args);
6825 + /* we need to do this because of static declarations,
6826 + * maybe a good idea to change */
6827 + cmd = ipkg_cmd_find ("download");
6828 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6830 + ipkg_conf_deinit(&ipkg_conf);
6836 +ipkg_package_files(args_t *args,
6838 + ipkg_list_callback cblist,
6842 + ipkg_conf_t ipkg_conf;
6845 + /* this error should be handled in application */
6846 + if (!name || !strlen (name))
6849 + err = ipkg_conf_init (&ipkg_conf, args);
6855 + ipkg_cb_list = cblist;
6857 + /* we need to do this because of static declarations,
6858 + * maybe a good idea to change */
6859 + cmd = ipkg_cmd_find ("files");
6861 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6863 + ipkg_cb_list = NULL;
6864 + ipkg_conf_deinit(&ipkg_conf);
6870 +ipkg_file_search(args_t *args,
6872 + ipkg_list_callback cblist,
6876 + ipkg_conf_t ipkg_conf;
6879 + /* this error should be handled in application */
6880 + if (!file || !strlen (file))
6883 + err = ipkg_conf_init (&ipkg_conf, args);
6889 + ipkg_cb_list = cblist;
6891 + /* we need to do this because of static declarations,
6892 + * maybe a good idea to change */
6893 + cmd = ipkg_cmd_find ("search");
6894 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6896 + ipkg_cb_list = NULL;
6897 + ipkg_conf_deinit(&ipkg_conf);
6903 +ipkg_file_what(args_t *args, const char *file, const char* command)
6906 + ipkg_conf_t ipkg_conf;
6909 + /* this error should be handled in application */
6910 + if (!file || !strlen (file))
6913 + err = ipkg_conf_init (&ipkg_conf, args);
6919 + /* we need to do this because of static declarations,
6920 + * maybe a good idea to change */
6921 + cmd = ipkg_cmd_find (command);
6922 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6924 + ipkg_conf_deinit(&ipkg_conf);
6928 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
6929 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
6930 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
6931 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
6932 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
6935 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
6938 + if (conf && (conf->verbosity < level)) {
6942 + if ( level == IPKG_ERROR ){
6943 + push_error_list(&error_list, msg);
6952 +int default_ipkg_list_callback(char *name, char *desc, char *version,
6953 + pkg_state_status_t status, void *userdata)
6956 + printf("%s - %s - %s\n", name, version, desc);
6958 + printf("%s - %s\n", name, version);
6962 +int default_ipkg_files_callback(char *name, char *desc, char *version,
6963 + pkg_state_status_t status, void *userdata)
6966 + printf("%s\n", desc);
6970 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
6973 + printf("%s\n", desc);
6977 +char* default_ipkg_response_callback(char *question)
6979 + char *response = NULL;
6983 + response = (char *)file_read_line_alloc(stdin);
6984 + } while (response == NULL);
6988 +/* This is used for backward compatibility */
6990 +ipkg_op (int argc, char *argv[])
6996 + ipkg_conf_t ipkg_conf;
6998 + args_init (&args);
7000 + optind = args_parse (&args, argc, argv);
7001 + if (optind == argc || optind < 0)
7003 + args_usage ("ipkg must have one sub-command argument");
7006 + cmd_name = argv[optind++];
7007 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7008 + read anything from there.
7010 + if ( !strcmp(cmd_name,"print-architecture") ||
7011 + !strcmp(cmd_name,"print_architecture") ||
7012 + !strcmp(cmd_name,"print-installation-architecture") ||
7013 + !strcmp(cmd_name,"print_installation_architecture") )
7014 + args.nocheckfordirorfile = 1;
7017 + err = ipkg_conf_init (&ipkg_conf, &args);
7023 + args_deinit (&args);
7025 + ipkg_cb_message = default_ipkg_message_callback;
7026 + ipkg_cb_response = default_ipkg_response_callback;
7027 + ipkg_cb_status = default_ipkg_status_callback;
7028 + if ( strcmp(cmd_name, "files")==0)
7029 + ipkg_cb_list = default_ipkg_files_callback;
7031 + ipkg_cb_list = default_ipkg_list_callback;
7033 + cmd = ipkg_cmd_find (cmd_name);
7036 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7038 + args_usage (NULL);
7041 + if (cmd->requires_args && optind == argc)
7044 + "%s: the ``%s'' command requires at least one argument\n",
7045 + __FUNCTION__, cmd_name);
7046 + args_usage (NULL);
7049 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7051 + ipkg_conf_deinit (&ipkg_conf);
7056 +#endif /* IPKG_LIB */
7057 diff -ruN busybox-1.00-orig/archival/libipkg/libipkg.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.h
7058 --- busybox-1.00-orig/archival/libipkg/libipkg.h 1970-01-01 00:00:00.000000000 +0000
7059 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/libipkg.h 2005-07-20 10:21:59.000000000 +0000
7061 +/* ipkglib.h - the itsy package management system
7063 + Florian Boor <florian.boor@kernelconcepts.de>
7065 + This program is free software; you can redistribute it and/or
7066 + modify it under the terms of the GNU General Public License as
7067 + published by the Free Software Foundation; either version 2, or (at
7068 + your option) any later version.
7070 + This program is distributed in the hope that it will be useful, but
7071 + WITHOUT ANY WARRANTY; without even the implied warranty of
7072 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7073 + General Public License for more details.
7081 +#include "ipkg_conf.h"
7082 +#include "ipkg_message.h"
7087 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7089 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7090 + pkg_state_status_t status, void *userdata);
7091 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7093 +typedef char* (*ipkg_response_callback)(char *question);
7095 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7096 +extern int ipkg_init (ipkg_message_callback mcall,
7097 + ipkg_response_callback rcall,
7100 +extern int ipkg_deinit (args_t *args);
7101 +extern int ipkg_packages_list(args_t *args,
7102 + const char *packages,
7103 + ipkg_list_callback cblist,
7105 +extern int ipkg_packages_status(args_t *args,
7106 + const char *packages,
7107 + ipkg_status_callback cbstatus,
7109 +extern int ipkg_packages_info(args_t *args,
7110 + const char *packages,
7111 + ipkg_status_callback cbstatus,
7113 +extern int ipkg_packages_install(args_t *args, const char *name);
7114 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7115 +extern int ipkg_lists_update(args_t *args);
7116 +extern int ipkg_packages_upgrade(args_t *args);
7117 +extern int ipkg_packages_download(args_t *args, const char *name);
7118 +extern int ipkg_package_files(args_t *args,
7120 + ipkg_list_callback cblist,
7122 +extern int ipkg_file_search(args_t *args,
7124 + ipkg_list_callback cblist,
7126 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7127 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7128 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7129 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7130 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7132 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7133 +extern ipkg_response_callback ipkg_cb_response;
7134 +extern ipkg_status_callback ipkg_cb_status;
7135 +extern ipkg_list_callback ipkg_cb_list;
7136 +extern void push_error_list(struct errlist **errors,char * msg);
7137 +extern void reverse_error_list(struct errlist **errors);
7138 +extern void free_error_list(struct errlist **errors);
7142 +extern int ipkg_op(int argc, char *argv[]);
7148 diff -ruN busybox-1.00-orig/archival/libipkg/md5.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.c
7149 --- busybox-1.00-orig/archival/libipkg/md5.c 1970-01-01 00:00:00.000000000 +0000
7150 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.c 2005-07-20 16:54:34.905805584 +0000
7152 +/* md5.c - wrappers to busybox md5 functions
7154 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7156 + * This program is free software; you can redistribute it and/or modify
7157 + * it under the terms of the GNU General Public License as published by
7158 + * the Free Software Foundation; either version 2, or (at your option)
7159 + * any later version.
7161 + * This program is distributed in the hope that it will be useful,
7162 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7163 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7164 + * GNU General Public License for more details.
7166 + * You should have received a copy of the GNU General Public License
7167 + * along with this program; if not, write to the Free Software Foundation,
7168 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7176 +int md5_stream(FILE *stream, void *resblock)
7181 + if( (fd = fileno(stream)) == -1 ) {
7182 + bb_error_msg("bad file descriptor");
7186 + hash_fd(fd, -1, HASH_MD5, (uint8_t *)resblock);
7191 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7193 + struct md5_ctx_t md5_cx;
7195 + md5_begin(&md5_cx);
7196 + md5_hash(buffer, len, &md5_cx);
7197 + return md5_end(resblock, &md5_cx);
7200 diff -ruN busybox-1.00-orig/archival/libipkg/md5.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.h
7201 --- busybox-1.00-orig/archival/libipkg/md5.h 1970-01-01 00:00:00.000000000 +0000
7202 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/md5.h 2005-07-17 16:10:24.000000000 +0000
7204 +/* md5.h - Compute MD5 checksum of files or strings according to the
7205 + * definition of MD5 in RFC 1321 from April 1992.
7206 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7208 + * This program is free software; you can redistribute it and/or modify
7209 + * it under the terms of the GNU General Public License as published by
7210 + * the Free Software Foundation; either version 2, or (at your option)
7211 + * any later version.
7213 + * This program is distributed in the hope that it will be useful,
7214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7216 + * GNU General Public License for more details.
7218 + * You should have received a copy of the GNU General Public License
7219 + * along with this program; if not, write to the Free Software Foundation,
7220 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7226 +/* Compute MD5 message digest for bytes read from STREAM. The
7227 + resulting message digest number will be written into the 16 bytes
7228 + beginning at RESBLOCK. */
7229 +int md5_stream(FILE *stream, void *resblock);
7231 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7232 + result is always in little endian byte order, so that a byte-wise
7233 + output yields to the wanted ASCII representation of the message
7235 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7239 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.c
7240 --- busybox-1.00-orig/archival/libipkg/nv_pair.c 1970-01-01 00:00:00.000000000 +0000
7241 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.c 2005-07-17 16:10:24.000000000 +0000
7243 +/* nv_pair.c - the itsy package management system
7247 + Copyright (C) 2001 University of Southern California
7249 + This program is free software; you can redistribute it and/or
7250 + modify it under the terms of the GNU General Public License as
7251 + published by the Free Software Foundation; either version 2, or (at
7252 + your option) any later version.
7254 + This program is distributed in the hope that it will be useful, but
7255 + WITHOUT ANY WARRANTY; without even the implied warranty of
7256 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7257 + General Public License for more details.
7262 +#include "nv_pair.h"
7263 +#include "str_util.h"
7265 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7267 + nv_pair->name = str_dup_safe(name);
7268 + nv_pair->value = str_dup_safe(value);
7273 +void nv_pair_deinit(nv_pair_t *nv_pair)
7275 + free(nv_pair->name);
7276 + nv_pair->name = NULL;
7278 + free(nv_pair->value);
7279 + nv_pair->value = NULL;
7283 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.h
7284 --- busybox-1.00-orig/archival/libipkg/nv_pair.h 1970-01-01 00:00:00.000000000 +0000
7285 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair.h 2005-07-17 16:10:24.000000000 +0000
7287 +/* nv_pair.h - the itsy package management system
7291 + Copyright (C) 2001 University of Southern California
7293 + This program is free software; you can redistribute it and/or
7294 + modify it under the terms of the GNU General Public License as
7295 + published by the Free Software Foundation; either version 2, or (at
7296 + your option) any later version.
7298 + This program is distributed in the hope that it will be useful, but
7299 + WITHOUT ANY WARRANTY; without even the implied warranty of
7300 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7301 + General Public License for more details.
7307 +typedef struct nv_pair nv_pair_t;
7314 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7315 +void nv_pair_deinit(nv_pair_t *nv_pair);
7319 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.c
7320 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.c 1970-01-01 00:00:00.000000000 +0000
7321 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.c 2005-07-17 16:10:24.000000000 +0000
7323 +/* nv_pair_list.c - the itsy package management system
7327 + Copyright (C) 2001 University of Southern California
7329 + This program is free software; you can redistribute it and/or
7330 + modify it under the terms of the GNU General Public License as
7331 + published by the Free Software Foundation; either version 2, or (at
7332 + your option) any later version.
7334 + This program is distributed in the hope that it will be useful, but
7335 + WITHOUT ANY WARRANTY; without even the implied warranty of
7336 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7337 + General Public License for more details.
7342 +#include "nv_pair.h"
7343 +#include "void_list.h"
7344 +#include "nv_pair_list.h"
7346 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7348 + return void_list_elt_init((void_list_elt_t *) elt, data);
7351 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7353 + void_list_elt_deinit((void_list_elt_t *) elt);
7356 +int nv_pair_list_init(nv_pair_list_t *list)
7358 + return void_list_init((void_list_t *) list);
7361 +void nv_pair_list_deinit(nv_pair_list_t *list)
7363 + nv_pair_list_elt_t *iter;
7364 + nv_pair_t *nv_pair;
7366 + for (iter = list->head; iter; iter = iter->next) {
7367 + nv_pair = iter->data;
7368 + nv_pair_deinit(nv_pair);
7370 + /* malloced in nv_pair_list_append */
7372 + iter->data = NULL;
7374 + void_list_deinit((void_list_t *) list);
7377 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7381 + /* freed in nv_pair_list_deinit */
7382 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7384 + if (nv_pair == NULL) {
7385 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7388 + nv_pair_init(nv_pair, name, value);
7390 + err = void_list_append((void_list_t *) list, nv_pair);
7398 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7400 + return void_list_push((void_list_t *) list, data);
7403 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7405 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7408 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7410 + nv_pair_list_elt_t *iter;
7411 + nv_pair_t *nv_pair;
7413 + for (iter = list->head; iter; iter = iter->next) {
7414 + nv_pair = iter->data;
7415 + if (strcmp(nv_pair->name, name) == 0) {
7416 + return nv_pair->value;
7421 diff -ruN busybox-1.00-orig/archival/libipkg/nv_pair_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.h
7422 --- busybox-1.00-orig/archival/libipkg/nv_pair_list.h 1970-01-01 00:00:00.000000000 +0000
7423 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/nv_pair_list.h 2005-07-17 16:10:24.000000000 +0000
7425 +/* nv_pair_list.h - the itsy package management system
7429 + Copyright (C) 2001 University of Southern California
7431 + This program is free software; you can redistribute it and/or
7432 + modify it under the terms of the GNU General Public License as
7433 + published by the Free Software Foundation; either version 2, or (at
7434 + your option) any later version.
7436 + This program is distributed in the hope that it will be useful, but
7437 + WITHOUT ANY WARRANTY; without even the implied warranty of
7438 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7439 + General Public License for more details.
7442 +#ifndef NV_PAIR_LIST_H
7443 +#define NV_PAIR_LIST_H
7445 +#include "nv_pair.h"
7446 +#include "void_list.h"
7448 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7449 +struct nv_pair_list_elt
7451 + nv_pair_list_elt_t *next;
7455 +typedef struct nv_pair_list nv_pair_list_t;
7456 +struct nv_pair_list
7458 + nv_pair_list_elt_t pre_head;
7459 + nv_pair_list_elt_t *head;
7460 + nv_pair_list_elt_t *tail;
7463 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7465 + if (list->head == NULL)
7471 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7472 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7474 +int nv_pair_list_init(nv_pair_list_t *list);
7475 +void nv_pair_list_deinit(nv_pair_list_t *list);
7477 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7478 + const char *name, const char *value);
7479 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7480 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7481 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7485 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.c
7486 --- busybox-1.00-orig/archival/libipkg/pkg.c 1970-01-01 00:00:00.000000000 +0000
7487 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.c 2005-07-17 16:10:24.000000000 +0000
7489 +/* pkg.c - the itsy package management system
7493 + Copyright (C) 2001 University of Southern California
7495 + This program is free software; you can redistribute it and/or
7496 + modify it under the terms of the GNU General Public License as
7497 + published by the Free Software Foundation; either version 2, or (at
7498 + your option) any later version.
7500 + This program is distributed in the hope that it will be useful, but
7501 + WITHOUT ANY WARRANTY; without even the implied warranty of
7502 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7503 + General Public License for more details.
7508 +#include <string.h>
7513 +#include "pkg_parse.h"
7514 +#include "pkg_extract.h"
7515 +#include "ipkg_message.h"
7516 +#include "ipkg_utils.h"
7518 +#include "sprintf_alloc.h"
7519 +#include "file_util.h"
7520 +#include "str_util.h"
7521 +#include "xsystem.h"
7522 +#include "ipkg_conf.h"
7524 +typedef struct enum_map enum_map_t;
7531 +static const enum_map_t pkg_state_want_map[] = {
7532 + { SW_UNKNOWN, "unknown"},
7533 + { SW_INSTALL, "install"},
7534 + { SW_DEINSTALL, "deinstall"},
7535 + { SW_PURGE, "purge"}
7538 +static const enum_map_t pkg_state_flag_map[] = {
7540 + { SF_REINSTREQ, "reinstreq"},
7541 + { SF_HOLD, "hold"},
7542 + { SF_REPLACE, "replace"},
7543 + { SF_NOPRUNE, "noprune"},
7544 + { SF_PREFER, "prefer"},
7545 + { SF_OBSOLETE, "obsolete"},
7546 + { SF_USER, "user"},
7549 +static const enum_map_t pkg_state_status_map[] = {
7550 + { SS_NOT_INSTALLED, "not-installed" },
7551 + { SS_UNPACKED, "unpacked" },
7552 + { SS_HALF_CONFIGURED, "half-configured" },
7553 + { SS_INSTALLED, "installed" },
7554 + { SS_HALF_INSTALLED, "half-installed" },
7555 + { SS_CONFIG_FILES, "config-files" },
7556 + { SS_POST_INST_FAILED, "post-inst-failed" },
7557 + { SS_REMOVAL_FAILED, "removal-failed" }
7560 +static int verrevcmp(const char *val, const char *ref);
7563 +pkg_t *pkg_new(void)
7567 + pkg = malloc(sizeof(pkg_t));
7568 + if (pkg == NULL) {
7569 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7578 +int pkg_init(pkg_t *pkg)
7580 + memset(pkg, 0, sizeof(pkg_t));
7583 + pkg->version = NULL;
7584 + pkg->revision = NULL;
7585 + pkg->familiar_revision = NULL;
7588 + pkg->architecture = NULL;
7589 + pkg->maintainer = NULL;
7590 + pkg->section = NULL;
7591 + pkg->description = NULL;
7592 + pkg->state_want = SW_UNKNOWN;
7593 + pkg->state_flag = SF_OK;
7594 + pkg->state_status = SS_NOT_INSTALLED;
7595 + pkg->depends_str = NULL;
7596 + pkg->provides_str = NULL;
7597 + pkg->depends_count = 0;
7598 + pkg->depends = NULL;
7599 + pkg->suggests_str = NULL;
7600 + pkg->recommends_str = NULL;
7601 + pkg->suggests_count = 0;
7602 + pkg->recommends_count = 0;
7604 + /* Abhaya: added init for conflicts fields */
7605 + pkg->conflicts = NULL;
7606 + pkg->conflicts_count = 0;
7608 + /* added for replaces. Jamey 7/23/2002 */
7609 + pkg->replaces = NULL;
7610 + pkg->replaces_count = 0;
7612 + pkg->pre_depends_count = 0;
7613 + pkg->pre_depends_str = NULL;
7614 + pkg->provides_count = 0;
7615 + pkg->provides = NULL;
7616 + pkg->filename = NULL;
7617 + pkg->local_filename = NULL;
7618 + pkg->tmp_unpack_dir = NULL;
7619 + pkg->md5sum = NULL;
7621 + pkg->installed_size = NULL;
7622 + pkg->priority = NULL;
7623 + pkg->source = NULL;
7624 + conffile_list_init(&pkg->conffiles);
7625 + pkg->installed_files = NULL;
7626 + pkg->installed_files_ref_cnt = 0;
7627 + pkg->essential = 0;
7632 +void pkg_deinit(pkg_t *pkg)
7637 + free(pkg->version);
7638 + pkg->version = NULL;
7639 + /* revision and familiar_revision share storage with version, so
7641 + pkg->revision = NULL;
7642 + pkg->familiar_revision = NULL;
7643 + /* owned by ipkg_conf_t */
7645 + /* owned by ipkg_conf_t */
7647 + free(pkg->architecture);
7648 + pkg->architecture = NULL;
7649 + free(pkg->maintainer);
7650 + pkg->maintainer = NULL;
7651 + free(pkg->section);
7652 + pkg->section = NULL;
7653 + free(pkg->description);
7654 + pkg->description = NULL;
7655 + pkg->state_want = SW_UNKNOWN;
7656 + pkg->state_flag = SF_OK;
7657 + pkg->state_status = SS_NOT_INSTALLED;
7658 + free(pkg->depends_str);
7659 + pkg->depends_str = NULL;
7660 + free(pkg->provides_str);
7661 + pkg->provides_str = NULL;
7662 + pkg->depends_count = 0;
7663 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7664 + pkg->pre_depends_count = 0;
7665 + free(pkg->pre_depends_str);
7666 + pkg->pre_depends_str = NULL;
7667 + pkg->provides_count = 0;
7668 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7669 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7670 + free(pkg->filename);
7671 + pkg->filename = NULL;
7672 + free(pkg->local_filename);
7673 + pkg->local_filename = NULL;
7674 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7675 + ipkg_install.c here. See comment in
7676 + ipkg_install.c:cleanup_temporary_files */
7677 + free(pkg->tmp_unpack_dir);
7678 + pkg->tmp_unpack_dir = NULL;
7679 + free(pkg->md5sum);
7680 + pkg->md5sum = NULL;
7683 + free(pkg->installed_size);
7684 + pkg->installed_size = NULL;
7685 + free(pkg->priority);
7686 + pkg->priority = NULL;
7687 + free(pkg->source);
7688 + pkg->source = NULL;
7689 + conffile_list_deinit(&pkg->conffiles);
7690 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7691 + since if they are calling deinit, they should know. Maybe do an
7692 + assertion here instead? */
7693 + pkg->installed_files_ref_cnt = 1;
7694 + pkg_free_installed_files(pkg);
7695 + pkg->essential = 0;
7698 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7702 + FILE *control_file;
7704 + err = pkg_init(pkg);
7705 + if (err) { return err; }
7707 + pkg->local_filename = strdup(filename);
7709 + control_file = tmpfile();
7710 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7711 + if (err) { return err; }
7713 + rewind(control_file);
7714 + raw = read_raw_pkgs_from_stream(control_file);
7715 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7717 + fclose(control_file);
7722 +/* Merge any new information in newpkg into oldpkg */
7723 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7724 + newpkg, but should leave it usable. This rework is so that
7725 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7727 + * uh, i thought that i had originally written this so that it took
7728 + * two pkgs and returned a new one? we can do that again... -sma
7730 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7732 + if (oldpkg == newpkg) {
7737 + oldpkg->src = newpkg->src;
7738 + if (!oldpkg->dest)
7739 + oldpkg->dest = newpkg->dest;
7740 + if (!oldpkg->architecture)
7741 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7742 + if (!oldpkg->arch_priority)
7743 + oldpkg->arch_priority = newpkg->arch_priority;
7744 + if (!oldpkg->section)
7745 + oldpkg->section = str_dup_safe(newpkg->section);
7746 + if(!oldpkg->maintainer)
7747 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7748 + if(!oldpkg->description)
7749 + oldpkg->description = str_dup_safe(newpkg->description);
7751 + /* merge the state_flags from the new package */
7752 + oldpkg->state_want = newpkg->state_want;
7753 + oldpkg->state_status = newpkg->state_status;
7754 + oldpkg->state_flag = newpkg->state_flag;
7756 + if (oldpkg->state_want == SW_UNKNOWN)
7757 + oldpkg->state_want = newpkg->state_want;
7758 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7759 + oldpkg->state_status = newpkg->state_status;
7760 + oldpkg->state_flag |= newpkg->state_flag;
7763 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7764 + oldpkg->depends_str = newpkg->depends_str;
7765 + newpkg->depends_str = NULL;
7766 + oldpkg->depends_count = newpkg->depends_count;
7767 + newpkg->depends_count = 0;
7769 + oldpkg->depends = newpkg->depends;
7770 + newpkg->depends = NULL;
7772 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7773 + newpkg->pre_depends_str = NULL;
7774 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7775 + newpkg->pre_depends_count = 0;
7777 + oldpkg->recommends_str = newpkg->recommends_str;
7778 + newpkg->recommends_str = NULL;
7779 + oldpkg->recommends_count = newpkg->recommends_count;
7780 + newpkg->recommends_count = 0;
7782 + oldpkg->suggests_str = newpkg->suggests_str;
7783 + newpkg->suggests_str = NULL;
7784 + oldpkg->suggests_count = newpkg->suggests_count;
7785 + newpkg->suggests_count = 0;
7788 + if (!oldpkg->provides_str) {
7789 + oldpkg->provides_str = newpkg->provides_str;
7790 + newpkg->provides_str = NULL;
7791 + oldpkg->provides_count = newpkg->provides_count;
7792 + newpkg->provides_count = 0;
7794 + oldpkg->provides = newpkg->provides;
7795 + newpkg->provides = NULL;
7798 + if (!oldpkg->conflicts_str) {
7799 + oldpkg->conflicts_str = newpkg->conflicts_str;
7800 + newpkg->conflicts_str = NULL;
7801 + oldpkg->conflicts_count = newpkg->conflicts_count;
7802 + newpkg->conflicts_count = 0;
7804 + oldpkg->conflicts = newpkg->conflicts;
7805 + newpkg->conflicts = NULL;
7808 + if (!oldpkg->replaces_str) {
7809 + oldpkg->replaces_str = newpkg->replaces_str;
7810 + newpkg->replaces_str = NULL;
7811 + oldpkg->replaces_count = newpkg->replaces_count;
7812 + newpkg->replaces_count = 0;
7814 + oldpkg->replaces = newpkg->replaces;
7815 + newpkg->replaces = NULL;
7818 + if (!oldpkg->filename)
7819 + oldpkg->filename = str_dup_safe(newpkg->filename);
7821 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7822 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7823 + if (!oldpkg->local_filename)
7824 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7825 + if (!oldpkg->tmp_unpack_dir)
7826 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7827 + if (!oldpkg->md5sum)
7828 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7829 + if (!oldpkg->size)
7830 + oldpkg->size = str_dup_safe(newpkg->size);
7831 + if (!oldpkg->installed_size)
7832 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7833 + if (!oldpkg->priority)
7834 + oldpkg->priority = str_dup_safe(newpkg->priority);
7835 + if (!oldpkg->source)
7836 + oldpkg->source = str_dup_safe(newpkg->source);
7837 + if (oldpkg->conffiles.head == NULL){
7838 + oldpkg->conffiles = newpkg->conffiles;
7839 + conffile_list_init(&newpkg->conffiles);
7841 + if (!oldpkg->installed_files){
7842 + oldpkg->installed_files = newpkg->installed_files;
7843 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7844 + newpkg->installed_files = NULL;
7846 + if (!oldpkg->essential)
7847 + oldpkg->essential = newpkg->essential;
7852 +abstract_pkg_t *abstract_pkg_new(void)
7854 + abstract_pkg_t * ab_pkg;
7856 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7858 + if (ab_pkg == NULL) {
7859 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7863 + if ( abstract_pkg_init(ab_pkg) < 0 )
7869 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7871 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7873 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7874 + if (ab_pkg->provided_by==NULL){
7877 + ab_pkg->dependencies_checked = 0;
7878 + ab_pkg->state_status = SS_NOT_INSTALLED;
7883 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7886 + char **raw_start=NULL;
7888 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7889 + if (temp_str == NULL ){
7890 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7893 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7895 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7896 + if (raw == NULL ){
7897 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7902 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7903 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7919 +char * pkg_formatted_info(pkg_t *pkg )
7924 + buff = malloc(8192);
7925 + if (buff == NULL) {
7926 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7932 + line = pkg_formatted_field(pkg, "Package");
7933 + strncat(buff ,line, strlen(line));
7936 + line = pkg_formatted_field(pkg, "Version");
7937 + strncat(buff ,line, strlen(line));
7940 + line = pkg_formatted_field(pkg, "Depends");
7941 + strncat(buff ,line, strlen(line));
7944 + line = pkg_formatted_field(pkg, "Recommends");
7945 + strncat(buff ,line, strlen(line));
7948 + line = pkg_formatted_field(pkg, "Suggests");
7949 + strncat(buff ,line, strlen(line));
7952 + line = pkg_formatted_field(pkg, "Provides");
7953 + strncat(buff ,line, strlen(line));
7956 + line = pkg_formatted_field(pkg, "Replaces");
7957 + strncat(buff ,line, strlen(line));
7960 + line = pkg_formatted_field(pkg, "Conflicts");
7961 + strncat(buff ,line, strlen(line));
7964 + line = pkg_formatted_field(pkg, "Status");
7965 + strncat(buff ,line, strlen(line));
7968 + line = pkg_formatted_field(pkg, "Section");
7969 + strncat(buff ,line, strlen(line));
7972 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7973 + strncat(buff ,line, strlen(line));
7976 + line = pkg_formatted_field(pkg, "Architecture");
7977 + strncat(buff ,line, strlen(line));
7980 + line = pkg_formatted_field(pkg, "Maintainer");
7981 + strncat(buff ,line, strlen(line));
7984 + line = pkg_formatted_field(pkg, "MD5sum");
7985 + strncat(buff ,line, strlen(line));
7988 + line = pkg_formatted_field(pkg, "Size");
7989 + strncat(buff ,line, strlen(line));
7992 + line = pkg_formatted_field(pkg, "Filename");
7993 + strncat(buff ,line, strlen(line));
7996 + line = pkg_formatted_field(pkg, "Conffiles");
7997 + strncat(buff ,line, strlen(line));
8000 + line = pkg_formatted_field(pkg, "Source");
8001 + strncat(buff ,line, strlen(line));
8004 + line = pkg_formatted_field(pkg, "Description");
8005 + strncat(buff ,line, strlen(line));
8008 + line = pkg_formatted_field(pkg, "Installed-Time");
8009 + strncat(buff ,line, strlen(line));
8015 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8017 + static size_t LINE_LEN = 128;
8018 + char * temp = (char *)malloc(1);
8020 + int flag_provide_false = 0;
8023 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8024 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8027 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8028 + goto UNKNOWN_FMT_FIELD;
8037 + if (strcasecmp(field, "Architecture") == 0) {
8038 + /* Architecture */
8039 + if (pkg->architecture) {
8040 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8041 + if ( temp == NULL ){
8042 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8046 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8049 + goto UNKNOWN_FMT_FIELD;
8054 + if (strcasecmp(field, "Conffiles") == 0) {
8056 + conffile_list_elt_t *iter;
8057 + char confstr[LINE_LEN];
8059 + if (pkg->conffiles.head == NULL) {
8064 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8065 + if (iter->data->name && iter->data->value) {
8066 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8069 + temp = (char *)realloc(temp,len);
8070 + if ( temp == NULL ){
8071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8075 + strncpy(temp, "Conffiles:\n", 12);
8076 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8077 + if (iter->data->name && iter->data->value) {
8078 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8079 + strncat(temp, confstr, strlen(confstr));
8082 + } else if (strcasecmp(field, "Conflicts") == 0) {
8085 + if (pkg->conflicts_count) {
8086 + char conflictstr[LINE_LEN];
8088 + for(i = 0; i < pkg->conflicts_count; i++) {
8089 + len = len + (strlen(pkg->conflicts_str[i])+5);
8091 + temp = (char *)realloc(temp,len);
8092 + if ( temp == NULL ){
8093 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8097 + strncpy(temp, "Conflicts:", 11);
8098 + for(i = 0; i < pkg->conflicts_count; i++) {
8099 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8100 + strncat(temp, conflictstr, strlen(conflictstr));
8102 + strncat(temp, "\n", strlen("\n"));
8105 + goto UNKNOWN_FMT_FIELD;
8110 + if (strcasecmp(field, "Depends") == 0) {
8114 + if (pkg->depends_count) {
8115 + char depstr[LINE_LEN];
8117 + for(i = 0; i < pkg->depends_count; i++) {
8118 + len = len + (strlen(pkg->depends_str[i])+4);
8120 + temp = (char *)realloc(temp,len);
8121 + if ( temp == NULL ){
8122 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8126 + strncpy(temp, "Depends:", 10);
8127 + for(i = 0; i < pkg->depends_count; i++) {
8128 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8129 + strncat(temp, depstr, strlen(depstr));
8131 + strncat(temp, "\n", strlen("\n"));
8133 + } else if (strcasecmp(field, "Description") == 0) {
8135 + if (pkg->description) {
8136 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8137 + if ( temp == NULL ){
8138 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8142 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8145 + goto UNKNOWN_FMT_FIELD;
8151 + if (pkg->essential) {
8152 + temp = (char *)realloc(temp,16);
8153 + if ( temp == NULL ){
8154 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8158 + snprintf(temp, (16), "Essential: yes\n");
8165 + if (pkg->filename) {
8166 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8167 + if ( temp == NULL ){
8168 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8172 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8178 + if (strcasecmp(field, "Installed-Size") == 0) {
8179 + /* Installed-Size */
8180 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8181 + if ( temp == NULL ){
8182 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8186 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8187 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8188 + temp = (char *)realloc(temp,29);
8189 + if ( temp == NULL ){
8190 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8194 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8200 + /* Maintainer | MD5sum */
8201 + if (strcasecmp(field, "Maintainer") == 0) {
8203 + if (pkg->maintainer) {
8204 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8205 + if ( temp == NULL ){
8206 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8210 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8212 + } else if (strcasecmp(field, "MD5sum") == 0) {
8214 + if (pkg->md5sum) {
8215 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8216 + if ( temp == NULL ){
8217 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8221 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8224 + goto UNKNOWN_FMT_FIELD;
8230 + if (strcasecmp(field, "Package") == 0) {
8232 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8233 + if ( temp == NULL ){
8234 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8238 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8239 + } else if (strcasecmp(field, "Priority") == 0) {
8241 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8242 + if ( temp == NULL ){
8243 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8247 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8248 + } else if (strcasecmp(field, "Provides") == 0) {
8252 + if (pkg->provides_count) {
8253 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8254 + for ( i=0; i < pkg->provides_count; i++ ){
8255 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8256 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8257 + flag_provide_false = 1;
8260 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8261 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8262 + char provstr[LINE_LEN];
8264 + for(i = 0; i < pkg->provides_count; i++) {
8265 + len = len + (strlen(pkg->provides_str[i])+5);
8267 + temp = (char *)realloc(temp,len);
8268 + if ( temp == NULL ){
8269 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8273 + strncpy(temp, "Provides:", 12);
8274 + for(i = 0; i < pkg->provides_count; i++) {
8275 + if (strlen(pkg->provides_str[i])>0){;
8276 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8277 + strncat(temp, provstr, strlen(provstr));
8280 + strncat(temp, "\n", strlen("\n"));
8284 + goto UNKNOWN_FMT_FIELD;
8291 + /* Replaces | Recommends*/
8292 + if (strcasecmp (field, "Replaces") == 0) {
8293 + if (pkg->replaces_count) {
8294 + char replstr[LINE_LEN];
8296 + for (i = 0; i < pkg->replaces_count; i++) {
8297 + len = len + (strlen(pkg->replaces_str[i])+5);
8299 + temp = (char *)realloc(temp,len);
8300 + if ( temp == NULL ){
8301 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8305 + strncpy(temp, "Replaces:", 12);
8306 + for (i = 0; i < pkg->replaces_count; i++) {
8307 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8308 + strncat(temp, replstr, strlen(replstr));
8310 + strncat(temp, "\n", strlen("\n"));
8312 + } else if (strcasecmp (field, "Recommends") == 0) {
8313 + if (pkg->recommends_count) {
8314 + char recstr[LINE_LEN];
8316 + for(i = 0; i < pkg->recommends_count; i++) {
8317 + len = len + (strlen( pkg->recommends_str[i])+5);
8319 + temp = (char *)realloc(temp,len);
8320 + if ( temp == NULL ){
8321 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8325 + strncpy(temp, "Recommends:", 13);
8326 + for(i = 0; i < pkg->recommends_count; i++) {
8327 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8328 + strncat(temp, recstr, strlen(recstr));
8330 + strncat(temp, "\n", strlen("\n"));
8333 + goto UNKNOWN_FMT_FIELD;
8339 + /* Section | Size | Source | Status | Suggests */
8340 + if (strcasecmp(field, "Section") == 0) {
8342 + if (pkg->section) {
8343 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8344 + if ( temp == NULL ){
8345 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8349 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8351 + } else if (strcasecmp(field, "Size") == 0) {
8354 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8355 + if ( temp == NULL ){
8356 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8360 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8362 + } else if (strcasecmp(field, "Source") == 0) {
8364 + if (pkg->source) {
8365 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8366 + if ( temp == NULL ){
8367 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8371 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8373 + } else if (strcasecmp(field, "Status") == 0) {
8375 + /* Benjamin Pineau note: we should avoid direct usage of
8376 + * strlen(arg) without keeping "arg" for later free()
8378 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8379 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8380 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8382 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8383 + temp = (char *)realloc(temp,sum_of_sizes);
8384 + if ( temp == NULL ){
8385 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8389 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8392 + if(pstat) /* pfstat can be NULL if ENOMEM */
8394 + } else if (strcasecmp(field, "Suggests") == 0) {
8395 + if (pkg->suggests_count) {
8397 + char sugstr[LINE_LEN];
8399 + for(i = 0; i < pkg->suggests_count; i++) {
8400 + len = len + (strlen(pkg->suggests_str[i])+5);
8402 + temp = (char *)realloc(temp,len);
8403 + if ( temp == NULL ){
8404 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8408 + strncpy(temp, "Suggests:", 10);
8409 + for(i = 0; i < pkg->suggests_count; i++) {
8410 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8411 + strncat(temp, sugstr, strlen(sugstr));
8413 + strncat(temp, "\n", strlen("\n"));
8416 + goto UNKNOWN_FMT_FIELD;
8423 + char *version = pkg_version_str_alloc(pkg);
8424 + temp = (char *)realloc(temp,strlen(version)+14);
8425 + if ( temp == NULL ){
8426 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8430 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8435 + goto UNKNOWN_FMT_FIELD;
8438 + if ( strlen(temp)<2 ) {
8443 + UNKNOWN_FMT_FIELD:
8444 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8445 + if ( strlen(temp)<2 ) {
8452 +void pkg_print_info(pkg_t *pkg, FILE *file)
8455 + if (pkg == NULL) {
8459 + buff = pkg_formatted_info(pkg);
8460 + if ( buff == NULL )
8462 + if (strlen(buff)>2){
8463 + fwrite(buff, 1, strlen(buff), file);
8468 +void pkg_print_status(pkg_t * pkg, FILE * file)
8470 + if (pkg == NULL) {
8474 + /* XXX: QUESTION: Do we actually want more fields here? The
8475 + original idea was to save space by installing only what was
8476 + needed for actual computation, (package, version, status,
8477 + essential, conffiles). The assumption is that all other fields
8478 + can be found in th available file.
8480 + But, someone proposed the idea to make it possible to
8481 + reconstruct a .ipk from an installed package, (ie. for beaming
8482 + from one handheld to another). So, maybe we actually want a few
8483 + more fields here, (depends, suggests, etc.), so that that would
8484 + be guaranteed to work even in the absence of more information
8485 + from the available file.
8487 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8488 + the essential info needs to be here for all installed packages
8489 + because they may not appear in the Packages files on various
8490 + feeds. Furthermore, one should be able to install from URL or
8491 + local storage without requiring a Packages file from any feed.
8494 + pkg_print_field(pkg, file, "Package");
8495 + pkg_print_field(pkg, file, "Version");
8496 + pkg_print_field(pkg, file, "Depends");
8497 + pkg_print_field(pkg, file, "Recommends");
8498 + pkg_print_field(pkg, file, "Suggests");
8499 + pkg_print_field(pkg, file, "Provides");
8500 + pkg_print_field(pkg, file, "Replaces");
8501 + pkg_print_field(pkg, file, "Conflicts");
8502 + pkg_print_field(pkg, file, "Status");
8503 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8504 + pkg_print_field(pkg, file, "Architecture");
8505 + pkg_print_field(pkg, file, "Conffiles");
8506 + pkg_print_field(pkg, file, "Installed-Time");
8507 + fputs("\n", file);
8510 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8513 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8514 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8515 + __FUNCTION__, field);
8517 + buff = pkg_formatted_field(pkg, field);
8518 + if (strlen(buff)>2) {
8519 + fprintf(file, "%s", buff);
8527 + * libdpkg - Debian packaging suite library routines
8528 + * vercmp.c - comparison of version numbers
8530 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8532 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8536 + if (pkg->epoch > ref_pkg->epoch) {
8540 + if (pkg->epoch < ref_pkg->epoch) {
8544 + r = verrevcmp(pkg->version, ref_pkg->version);
8549 +#ifdef USE_DEBVERSION
8550 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8555 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8561 +int verrevcmp(const char *val, const char *ref)
8565 + const char *vp, *rp;
8566 + const char *vsep, *rsep;
8568 + if (!val) val= "";
8569 + if (!ref) ref= "";
8571 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8572 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8574 + vc= (val == vp) ? 0 : *val++;
8575 + rc= (ref == rp) ? 0 : *ref++;
8576 + if (!rc && !vc) break;
8577 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8578 + if (rc && !isalpha(rc)) rc += 256;
8579 + if (vc != rc) return vc - rc;
8583 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8584 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8585 + if (vl != rl) return vl - rl;
8589 + vsep = strchr(".-", vc);
8590 + rsep = strchr(".-", rc);
8591 + if (vsep && !rsep) return -1;
8592 + if (!vsep && rsep) return +1;
8594 + if (!*val && !*ref) return 0;
8595 + if (!*val) return -1;
8596 + if (!*ref) return +1;
8600 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8604 + r = pkg_compare_versions(it, ref);
8606 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8610 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8614 + if (strcmp(op, "<<") == 0) {
8618 + if (strcmp(op, ">>") == 0) {
8622 + if (strcmp(op, "=") == 0) {
8626 + fprintf(stderr, "unknown operator: %s", op);
8630 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8632 + const pkg_t *a = *(const pkg_t **)p1;
8633 + const pkg_t *b = *(const pkg_t **)p2;
8636 + if (!a->name || !b->name) {
8637 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8638 + a, a->name, b, b->name);
8642 + namecmp = strcmp(a->name, b->name);
8645 + vercmp = pkg_compare_versions(a, b);
8648 + if (!a->arch_priority || !b->arch_priority) {
8649 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8650 + a, a->arch_priority, b, b->arch_priority);
8653 + if (a->arch_priority > b->arch_priority)
8655 + if (a->arch_priority < b->arch_priority)
8660 +int abstract_pkg_name_compare(void *p1, void *p2)
8662 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8663 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8664 + if (!a->name || !b->name) {
8665 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8666 + a, a->name, b, b->name);
8669 + return strcmp(a->name, b->name);
8673 +char *pkg_version_str_alloc(pkg_t *pkg)
8675 + char *complete_version;
8677 +#ifdef USE_DEBVERSION
8678 + char *revision_str;
8679 + char *familiar_revision_str;
8683 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8685 + epoch_str = strdup("");
8688 +#ifdef USE_DEBVERSION
8689 + if (pkg->revision && strlen(pkg->revision)) {
8690 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8692 + revision_str = strdup("");
8695 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8696 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8698 + familiar_revision_str = strdup("");
8702 +#ifdef USE_DEBVERSION
8703 + sprintf_alloc(&complete_version, "%s%s%s%s",
8704 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8706 + sprintf_alloc(&complete_version, "%s%s",
8707 + epoch_str, pkg->version);
8711 +#ifdef USE_DEBVERSION
8712 + free(revision_str);
8713 + free(familiar_revision_str);
8716 + return complete_version;
8719 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8722 + char *list_file_name = NULL;
8723 + FILE *list_file = NULL;
8725 + char *installed_file_name;
8728 + pkg->installed_files_ref_cnt++;
8730 + if (pkg->installed_files) {
8731 + return pkg->installed_files;
8734 + pkg->installed_files = str_list_alloc();
8735 + if (pkg->installed_files == NULL) {
8736 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8740 + /* For uninstalled packages, get the file list firectly from the package.
8741 + For installed packages, look at the package.list file in the database.
8743 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8744 + if (pkg->local_filename == NULL) {
8745 + return pkg->installed_files;
8747 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8748 + file. In other words, change deb_extract so that it can
8749 + simply return the file list as a char *[] rather than
8750 + insisting on writing in to a FILE * as it does now. */
8751 + list_file = tmpfile();
8752 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8754 + fclose(list_file);
8755 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8756 + __FUNCTION__, pkg->local_filename, strerror(err));
8757 + return pkg->installed_files;
8759 + rewind(list_file);
8761 + sprintf_alloc(&list_file_name, "%s/%s.list",
8762 + pkg->dest->info_dir, pkg->name);
8763 + if (! file_exists(list_file_name)) {
8764 + free(list_file_name);
8765 + return pkg->installed_files;
8768 + list_file = fopen(list_file_name, "r");
8769 + if (list_file == NULL) {
8770 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8771 + list_file_name, strerror(errno));
8772 + free(list_file_name);
8773 + return pkg->installed_files;
8775 + free(list_file_name);
8778 + rootdirlen = strlen( pkg->dest->root_dir );
8782 + line = file_read_line_alloc(list_file);
8783 + if (line == NULL) {
8789 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8790 + if( strncmp( pkg->dest->root_dir,
8793 + if (*file_name == '.') {
8796 + if (*file_name == '/') {
8800 + /* Freed in pkg_free_installed_files */
8801 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8803 + // already contains root_dir as header -> ABSOLUTE
8804 + sprintf_alloc(&installed_file_name, "%s", file_name);
8806 + str_list_append(pkg->installed_files, installed_file_name);
8810 + fclose(list_file);
8812 + return pkg->installed_files;
8815 +/* XXX: CLEANUP: This function and it's counterpart,
8816 + (pkg_get_installed_files), do not match our init/deinit naming
8817 + convention. Nor the alloc/free convention. But, then again, neither
8818 + of these conventions currrently fit the way these two functions
8820 +int pkg_free_installed_files(pkg_t *pkg)
8822 + str_list_elt_t *iter;
8824 + pkg->installed_files_ref_cnt--;
8825 + if (pkg->installed_files_ref_cnt > 0) {
8829 + if (pkg->installed_files) {
8831 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8832 + /* malloced in pkg_get_installed_files */
8833 + free (iter->data);
8834 + iter->data = NULL;
8837 + str_list_deinit(pkg->installed_files);
8840 + pkg->installed_files = NULL;
8845 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8848 + char *list_file_name;
8850 + //I don't think pkg_free_installed_files should be called here. Jamey
8851 + //pkg_free_installed_files(pkg);
8853 + sprintf_alloc(&list_file_name, "%s/%s.list",
8854 + pkg->dest->info_dir, pkg->name);
8855 + if (!conf->noaction) {
8856 + err = unlink(list_file_name);
8857 + free(list_file_name);
8866 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8868 + conffile_list_elt_t *iter;
8869 + conffile_t *conffile;
8871 + if (pkg == NULL) {
8875 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8876 + conffile = iter->data;
8878 + if (strcmp(conffile->name, file_name) == 0) {
8886 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8887 + const char *script, const char *args)
8893 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8894 + maintainer script within a chroot environment. */
8896 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8897 + have scripts in pkg->tmp_unpack_dir. */
8898 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8899 + if (pkg->dest == NULL) {
8900 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8901 + __FUNCTION__, pkg->name);
8904 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8906 + if (pkg->tmp_unpack_dir == NULL) {
8907 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8908 + __FUNCTION__, pkg->name);
8911 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8914 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8915 + if (conf->noaction) return 0;
8917 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8918 + scripts when running with offline_root mode and/or a dest other
8919 + than '/'. I've been playing around with some clever chroot
8920 + tricks and I might come up with something workable. */
8921 + if (conf->offline_root) {
8922 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8925 + setenv("PKG_ROOT",
8926 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8928 + if (! file_exists(path)) {
8933 + if (conf->offline_root) {
8934 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8939 + sprintf_alloc(&cmd, "%s %s", path, args);
8942 + err = xsystem(cmd);
8946 + fprintf(stderr, "%s script returned status %d\n", script, err);
8953 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8957 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8958 + if (pkg_state_want_map[i].value == sw) {
8959 + return strdup(pkg_state_want_map[i].str);
8963 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8964 + __FUNCTION__, sw);
8965 + return strdup("<STATE_WANT_UNKNOWN>");
8968 +pkg_state_want_t pkg_state_want_from_str(char *str)
8972 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8973 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8974 + return pkg_state_want_map[i].value;
8978 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8979 + __FUNCTION__, str);
8980 + return SW_UNKNOWN;
8983 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8986 + int len = 3; /* ok\000 is minimum */
8989 + /* clear the temporary flags before converting to string */
8990 + sf &= SF_NONVOLATILE_FLAGS;
8993 + return strdup("ok");
8996 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8997 + if (sf & pkg_state_flag_map[i].value) {
8998 + len += strlen(pkg_state_flag_map[i].str) + 1;
9001 + str = malloc(len);
9002 + if ( str == NULL ) {
9003 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9007 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9008 + if (sf & pkg_state_flag_map[i].value) {
9009 + strcat(str, pkg_state_flag_map[i].str);
9013 + len = strlen(str);
9014 + str[len-1] = 0; /* squash last comma */
9019 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9024 + if (strcmp(str, "ok") == 0) {
9027 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9028 + const char *sfname = pkg_state_flag_map[i].str;
9029 + int sfname_len = strlen(sfname);
9030 + if (strncmp(str, sfname, sfname_len) == 0) {
9031 + sf |= pkg_state_flag_map[i].value;
9032 + str += sfname_len;
9033 + if (str[0] == ',') {
9044 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9048 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9049 + if (pkg_state_status_map[i].value == ss) {
9050 + return strdup(pkg_state_status_map[i].str);
9054 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9055 + __FUNCTION__, ss);
9056 + return strdup("<STATE_STATUS_UNKNOWN>");
9059 +pkg_state_status_t pkg_state_status_from_str(char *str)
9063 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9064 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9065 + return pkg_state_status_map[i].value;
9069 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9070 + __FUNCTION__, str);
9071 + return SS_NOT_INSTALLED;
9074 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9076 + nv_pair_list_elt_t *l;
9078 + if (!pkg->architecture)
9081 + l = conf->arch_list.head;
9084 + nv_pair_t *nv = l->data;
9085 + if (strcmp(nv->name, pkg->architecture) == 0) {
9086 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9092 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9096 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9098 + nv_pair_list_elt_t *l;
9100 + l = conf->arch_list.head;
9103 + nv_pair_t *nv = l->data;
9104 + if (strcmp(nv->name, archname) == 0) {
9105 + int priority = strtol(nv->value, NULL, 0);
9113 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9116 + hash_table_t *pkg_hash = &conf->pkg_hash;
9117 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9118 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9120 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9121 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9122 + /* update arch_priority for each package */
9123 + for (i = 0; i < available_pkgs->len; i++) {
9124 + pkg_t *pkg = available_pkgs->pkgs[i];
9125 + int arch_priority = 1;
9128 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9129 + if (pkg->architecture)
9130 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9132 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9133 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9134 + pkg->arch_priority = arch_priority;
9137 + for (i = 0; i < available_pkgs->len; i++) {
9138 + pkg_t *pkg = available_pkgs->pkgs[i];
9139 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9140 + /* clear flags and want for any uninstallable package */
9141 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9142 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9143 + pkg->state_want = SW_UNKNOWN;
9144 + pkg->state_flag = 0;
9147 + pkg_vec_free(available_pkgs);
9149 + /* update the file owner data structure */
9150 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9151 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9152 + for (i = 0; i < installed_pkgs->len; i++) {
9153 + pkg_t *pkg = installed_pkgs->pkgs[i];
9154 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9155 + str_list_elt_t *iter;
9156 + if (installed_files == NULL) {
9157 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9160 + for (iter = installed_files->head; iter; iter = iter->next) {
9161 + char *installed_file = iter->data;
9162 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9163 + file_hash_set_file_owner(conf, installed_file, pkg);
9166 + pkg_vec_free(installed_pkgs);
9171 +struct pkg_write_filelist_data {
9172 + ipkg_conf_t *conf;
9177 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9179 + struct pkg_write_filelist_data *data = data_;
9180 + pkg_t *entry = entry_;
9181 + if (entry == data->pkg) {
9182 + fprintf(data->stream, "%s\n", key);
9186 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9188 + struct pkg_write_filelist_data data;
9189 + char *list_file_name = NULL;
9193 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9196 + ipkg_message(conf, IPKG_INFO,
9197 + " creating %s.list file\n", pkg->name);
9198 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9199 + if (!list_file_name) {
9200 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9203 + ipkg_message(conf, IPKG_INFO,
9204 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9205 + data.stream = fopen(list_file_name, "w");
9206 + if (!data.stream) {
9207 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9208 + list_file_name, strerror(errno));
9213 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9214 + fclose(data.stream);
9215 + free(list_file_name);
9220 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9222 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9223 + hash_table_t *pkg_hash = &conf->pkg_hash;
9226 + if (conf->noaction)
9229 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9230 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9231 + for (i = 0; i < installed_pkgs->len; i++) {
9232 + pkg_t *pkg = installed_pkgs->pkgs[i];
9233 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9234 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9235 + err = pkg_write_filelist(conf, pkg);
9237 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9242 diff -ruN busybox-1.00-orig/archival/libipkg/pkg.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.h
9243 --- busybox-1.00-orig/archival/libipkg/pkg.h 1970-01-01 00:00:00.000000000 +0000
9244 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg.h 2005-07-17 16:10:24.000000000 +0000
9246 +/* pkg.h - the itsy package management system
9250 + Copyright (C) 2001 University of Southern California
9252 + This program is free software; you can redistribute it and/or
9253 + modify it under the terms of the GNU General Public License as
9254 + published by the Free Software Foundation; either version 2, or (at
9255 + your option) any later version.
9257 + This program is distributed in the hope that it will be useful, but
9258 + WITHOUT ANY WARRANTY; without even the implied warranty of
9259 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9260 + General Public License for more details.
9266 +#include <sys/types.h>
9267 +#include <sys/stat.h>
9268 +#include <unistd.h>
9270 +#include "pkg_vec.h"
9271 +#include "str_list.h"
9272 +#include "pkg_src.h"
9273 +#include "pkg_dest.h"
9274 +#include "ipkg_conf.h"
9275 +#include "conffile_list.h"
9280 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9282 +/* I think "Size" is currently the shortest field name */
9283 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9285 +enum pkg_state_want
9291 + SW_LAST_STATE_WANT
9293 +typedef enum pkg_state_want pkg_state_want_t;
9295 +enum pkg_state_flag
9299 + SF_HOLD = 2, /* do not upgrade version */
9300 + SF_REPLACE = 4, /* replace this package */
9301 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9302 + SF_PREFER = 16, /* prefer this version */
9303 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9304 + SF_MARKED = 64, /* temporary mark */
9305 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9307 + SF_LAST_STATE_FLAG
9309 +typedef enum pkg_state_flag pkg_state_flag_t;
9310 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9312 +enum pkg_state_status
9314 + SS_NOT_INSTALLED = 1,
9316 + SS_HALF_CONFIGURED,
9318 + SS_HALF_INSTALLED,
9320 + SS_POST_INST_FAILED,
9321 + SS_REMOVAL_FAILED,
9322 + SS_LAST_STATE_STATUS
9324 +typedef enum pkg_state_status pkg_state_status_t;
9326 +struct abstract_pkg{
9328 + int dependencies_checked;
9330 + pkg_state_status_t state_status;
9331 + pkg_state_flag_t state_flag;
9332 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9333 + abstract_pkg_vec_t * provided_by;
9334 + abstract_pkg_vec_t * replaced_by;
9337 +#include "pkg_depends.h"
9339 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9341 + The 3 version fields should go into a single version struct. (This
9342 + is especially important since, currently, pkg->version can easily
9343 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9344 + distinct. This has been the source of multiple bugs.
9346 + The 3 state fields could possibly also go into their own struct.
9348 + All fields which deal with lists of packages, (Depends,
9349 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9350 + be handled by a single struct in pkg_t
9352 + All string fields for which there is a small set of possible
9353 + values, (section, maintainer, architecture, maybe version?), that
9354 + are reused among different packages -- for all such packages we
9355 + should move from "char *"s to some atom datatype to share data
9356 + storage and use less memory. We might even do reference counting,
9357 + but probably not since most often we only create new pkg_t structs,
9358 + we don't often free them. */
9362 + unsigned long epoch;
9365 + char *familiar_revision;
9368 + char *architecture;
9371 + char *description;
9372 + pkg_state_want_t state_want;
9373 + pkg_state_flag_t state_flag;
9374 + pkg_state_status_t state_status;
9375 + char **depends_str;
9376 + int depends_count;
9377 + char **pre_depends_str;
9378 + int pre_depends_count;
9379 + char **recommends_str;
9380 + int recommends_count;
9381 + char **suggests_str;
9382 + int suggests_count;
9383 + compound_depend_t * depends;
9385 + /* Abhaya: new conflicts */
9386 + char **conflicts_str;
9387 + compound_depend_t * conflicts;
9388 + int conflicts_count;
9390 + char **replaces_str;
9391 + int replaces_count;
9392 + abstract_pkg_t ** replaces;
9394 + char **provides_str;
9395 + int provides_count;
9396 + abstract_pkg_t ** provides;
9398 + abstract_pkg_t *parent;
9400 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9403 + char *local_filename;
9405 + char *tmp_unpack_dir;
9408 + char *installed_size;
9411 + conffile_list_t conffiles;
9412 + time_t installed_time;
9413 + /* As pointer for lazy evaluation */
9414 + str_list_t *installed_files;
9415 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9416 + mechanism to avoid the problem here, (which is that the
9417 + installed_files list was being freed from an inner loop while
9418 + still being used within an outer loop. */
9419 + int installed_files_ref_cnt;
9421 + int arch_priority;
9424 +pkg_t *pkg_new(void);
9425 +int pkg_init(pkg_t *pkg);
9426 +void pkg_deinit(pkg_t *pkg);
9427 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9428 +abstract_pkg_t *abstract_pkg_new(void);
9429 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9432 + * merges fields from newpkg into oldpkg.
9433 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9435 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9437 +char *pkg_version_str_alloc(pkg_t *pkg);
9439 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9440 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9441 +int abstract_pkg_name_compare(void *a, void *b);
9443 +char * pkg_formatted_info(pkg_t *pkg );
9444 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9446 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9448 +void pkg_print_info(pkg_t *pkg, FILE *file);
9449 +void pkg_print_status(pkg_t * pkg, FILE * file);
9450 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9451 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9452 +int pkg_free_installed_files(pkg_t *pkg);
9453 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9454 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9455 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9456 + const char *script, const char *args);
9458 +/* enum mappings */
9459 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9460 +pkg_state_want_t pkg_state_want_from_str(char *str);
9461 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9462 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9463 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9464 +pkg_state_status_t pkg_state_status_from_str(char *str);
9466 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9468 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9469 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9470 +int pkg_free_installed_files(pkg_t *pkg);
9472 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9473 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9476 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.c
9477 --- busybox-1.00-orig/archival/libipkg/pkg_depends.c 1970-01-01 00:00:00.000000000 +0000
9478 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.c 2005-07-20 10:19:23.000000000 +0000
9480 +/* pkg_depends.c - the itsy package management system
9484 + Copyright (C) 2002 Compaq Computer Corporation
9486 + This program is free software; you can redistribute it and/or
9487 + modify it under the terms of the GNU General Public License as
9488 + published by the Free Software Foundation; either version 2, or (at
9489 + your option) any later version.
9491 + This program is distributed in the hope that it will be useful, but
9492 + WITHOUT ANY WARRANTY; without even the implied warranty of
9493 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9494 + General Public License for more details.
9502 +#include "ipkg_utils.h"
9503 +#include "pkg_hash.h"
9504 +#include "ipkg_message.h"
9505 +#include "pkg_parse.h"
9506 +#include "hash_table.h"
9508 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9509 +static depend_t * depend_init(void);
9510 +static void depend_deinit(depend_t *d);
9511 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9512 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9513 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9515 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9517 + depend_t *depend = (depend_t *)cdata;
9518 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9524 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9526 + depend_t *depend = (depend_t *)cdata;
9528 + pkg_t * temp = pkg_new();
9530 + parseVersion(temp, depend->version);
9531 + comparison = pkg_compare_versions(pkg, temp);
9534 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9535 + __FUNCTION__, pkg->name, pkg->version,
9536 + depend, depend->constraint, depend->version,
9537 + comparison, version_constraints_satisfied(depend, pkg));
9539 + if (version_constraints_satisfied(depend, pkg))
9545 +/* returns ndependences or negative error value */
9546 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9547 + pkg_vec_t *unsatisfied, char *** unresolved)
9549 + pkg_t * satisfier_entry_pkg;
9550 + register int i, j, k;
9553 + abstract_pkg_t * ab_pkg;
9556 + * this is a setup to check for redundant/cyclic dependency checks,
9557 + * which are marked at the abstract_pkg level
9559 + if (!(ab_pkg = pkg->parent)) {
9560 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9561 + *unresolved = NULL;
9564 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9565 + *unresolved = NULL;
9568 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9572 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9574 + *unresolved = NULL;
9580 + /* foreach dependency */
9581 + for (i = 0; i < count; i++) {
9582 + compound_depend_t * compound_depend = &pkg->depends[i];
9583 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9585 + satisfier_entry_pkg = NULL;
9587 + if (compound_depend->type == GREEDY_DEPEND) {
9588 + /* foreach possible satisfier */
9589 + for (j = 0; j < compound_depend->possibility_count; j++) {
9590 + /* foreach provided_by, which includes the abstract_pkg itself */
9591 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9592 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9593 + int nposs = ab_provider_vec->len;
9594 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9596 + for (l = 0; l < nposs; l++) {
9597 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9598 + /* if no depends on this one, try the first package that Provides this one */
9599 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9603 + /* cruise this possiblity's pkg_vec looking for an installed version */
9604 + for (k = 0; k < test_vec->len; k++) {
9605 + pkg_t *pkg_scout = test_vec->pkgs[k];
9606 + /* not installed, and not already known about? */
9607 + if ((pkg_scout->state_want != SW_INSTALL)
9608 + && !pkg_scout->parent->dependencies_checked
9609 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9610 + char ** newstuff = NULL;
9612 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9613 + /* check for not-already-installed dependencies */
9614 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9618 + if (newstuff == NULL) {
9621 + for (i = 0; i < rc; i++) {
9622 + pkg_t *p = tmp_vec->pkgs[i];
9623 + if (p->state_want == SW_INSTALL)
9625 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9629 + pkg_vec_free (tmp_vec);
9631 + /* mark this one for installation */
9632 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9633 + pkg_vec_insert(unsatisfied, pkg_scout);
9636 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9647 + /* foreach possible satisfier, look for installed package */
9648 + for (j = 0; j < compound_depend->possibility_count; j++) {
9649 + /* foreach provided_by, which includes the abstract_pkg itself */
9650 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9651 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9652 + pkg_t *satisfying_pkg =
9653 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9654 + pkg_installed_and_constraint_satisfied,
9655 + dependence_to_satisfy, 1);
9656 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9657 + if (satisfying_pkg != NULL) {
9663 + /* if nothing installed matches, then look for uninstalled satisfier */
9665 + /* foreach possible satisfier, look for installed package */
9666 + for (j = 0; j < compound_depend->possibility_count; j++) {
9667 + /* foreach provided_by, which includes the abstract_pkg itself */
9668 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9669 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9670 + pkg_t *satisfying_pkg =
9671 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9672 + pkg_constraint_satisfied,
9673 + dependence_to_satisfy, 1);
9675 + /* user request overrides package recommendation */
9676 + if (satisfying_pkg != NULL
9677 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9678 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9679 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9680 + pkg->name, satisfying_pkg->name);
9684 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9685 + if (satisfying_pkg != NULL) {
9686 + satisfier_entry_pkg = satisfying_pkg;
9692 + /* we didn't find one, add something to the unsatisfied vector */
9694 + if (!satisfier_entry_pkg) {
9695 + /* failure to meet recommendations is not an error */
9696 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9697 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9699 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9700 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9703 + if (compound_depend->type == SUGGEST) {
9704 + /* just mention it politely */
9705 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9706 + pkg->name, satisfier_entry_pkg->name);
9708 + char ** newstuff = NULL;
9710 + if (satisfier_entry_pkg != pkg &&
9711 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9712 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9713 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9714 + satisfier_entry_pkg,
9717 + the_lost = merge_unresolved(the_lost, newstuff);
9723 + *unresolved = the_lost;
9725 + return unsatisfied->len;
9728 +/*checking for conflicts !in replaces
9729 + If a packages conflicts with another but is also replacing it, I should not consider it a
9731 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9733 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9736 + int replaces_count = pkg->replaces_count;
9737 + abstract_pkg_t **replaces;
9739 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9742 + replaces = pkg->replaces;
9744 + for (i = 0; i < replaces_count; i++) {
9745 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) // Found
9753 +/* Abhaya: added support for conflicts */
9754 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9756 + pkg_vec_t * installed_conflicts, * test_vec;
9757 + compound_depend_t * conflicts;
9758 + depend_t ** possible_satisfiers;
9759 + depend_t * possible_satisfier;
9760 + register int i, j, k;
9762 + abstract_pkg_t * ab_pkg;
9763 + pkg_t **pkg_scouts;
9767 + * this is a setup to check for redundant/cyclic dependency checks,
9768 + * which are marked at the abstract_pkg level
9770 + if(!(ab_pkg = pkg->parent)){
9771 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9772 + return (pkg_vec_t *)NULL;
9775 + conflicts = pkg->conflicts;
9777 + return (pkg_vec_t *)NULL;
9779 + installed_conflicts = pkg_vec_alloc();
9781 + count = pkg->conflicts_count;
9785 + /* foreach conflict */
9786 + for(i = 0; i < pkg->conflicts_count; i++){
9788 + possible_satisfiers = conflicts->possibilities;
9790 + /* foreach possible satisfier */
9791 + for(j = 0; j < conflicts->possibility_count; j++){
9792 + possible_satisfier = possible_satisfiers[j];
9793 + if (!possible_satisfier)
9794 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9795 + if (!possible_satisfier->pkg)
9796 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9797 + test_vec = possible_satisfier->pkg->pkgs;
9799 + /* pkg_vec found, it is an actual package conflict
9800 + * cruise this possiblity's pkg_vec looking for an installed version */
9801 + pkg_scouts = test_vec->pkgs;
9802 + for(k = 0; k < test_vec->len; k++){
9803 + pkg_scout = pkg_scouts[k];
9805 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9808 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9809 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9810 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9811 + pkg_vec_insert(installed_conflicts, pkg_scout);
9820 + if (installed_conflicts->len)
9821 + return installed_conflicts;
9822 + pkg_vec_free(installed_conflicts);
9823 + return (pkg_vec_t *)NULL;
9826 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9831 + if(depends->constraint == NONE)
9836 + parseVersion(temp, depends->version);
9838 + comparison = pkg_compare_versions(pkg, temp);
9842 + if((depends->constraint == EARLIER) &&
9845 + else if((depends->constraint == LATER) &&
9848 + else if(comparison == 0)
9850 + else if((depends->constraint == LATER_EQUAL) &&
9851 + (comparison >= 0))
9853 + else if((depends->constraint == EARLIER_EQUAL) &&
9854 + (comparison <= 0))
9860 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9862 + abstract_pkg_t *apkg = depend->pkg;
9863 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9864 + int n_providers = provider_apkgs->len;
9865 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9866 + pkg_vec_t *pkg_vec;
9871 + for (i = 0; i < n_providers; i++) {
9872 + abstract_pkg_t *papkg = apkgs[i];
9873 + pkg_vec = papkg->pkgs;
9875 + n_pkgs = pkg_vec->len;
9876 + for (j = 0; j < n_pkgs; j++) {
9877 + pkg_t *pkg = pkg_vec->pkgs[j];
9878 + if (version_constraints_satisfied(depend, pkg)) {
9887 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9889 + abstract_pkg_t *apkg = depend->pkg;
9890 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9891 + int n_providers = provider_apkgs->len;
9892 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9897 + for (i = 0; i < n_providers; i++) {
9898 + abstract_pkg_t *papkg = apkgs[i];
9899 + pkg_vec_t *pkg_vec = papkg->pkgs;
9901 + n_pkgs = pkg_vec->len;
9902 + for (j = 0; j < n_pkgs; j++) {
9903 + pkg_t *pkg = pkg_vec->pkgs[j];
9904 + if (version_constraints_satisfied(depend, pkg)) {
9905 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9914 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9917 + pkg_t ** pkgs = vec->pkgs;
9919 + for(i = 0; i < vec->len; i++)
9920 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9921 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9922 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9930 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9931 + * the same abstract package and 0 otherwise.
9933 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9935 + abstract_pkg_t **provides = pkg->provides;
9936 + int provides_count = pkg->provides_count;
9937 + abstract_pkg_t **replacee_provides = replacee->provides;
9938 + int replacee_provides_count = replacee->provides_count;
9940 + for (i = 0; i < provides_count; i++) {
9941 + abstract_pkg_t *apkg = provides[i];
9942 + for (j = 0; j < replacee_provides_count; j++) {
9943 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9944 + if (apkg == replacee_apkg)
9953 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9954 + * and 0 otherwise.
9956 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9958 + abstract_pkg_t **provides = pkg->provides;
9959 + int provides_count = pkg->provides_count;
9961 + for (i = 0; i < provides_count; i++) {
9962 + if (provides[i] == providee)
9969 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9972 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9974 + abstract_pkg_t **replaces = pkg->replaces;
9975 + int replaces_count = pkg->replaces_count;
9976 + abstract_pkg_t **replacee_provides = pkg->provides;
9977 + int replacee_provides_count = pkg->provides_count;
9979 + for (i = 0; i < replaces_count; i++) {
9980 + abstract_pkg_t *abstract_replacee = replaces[i];
9981 + for (j = 0; j < replacee_provides_count; j++) {
9982 + if (replacee_provides[j] == abstract_replacee)
9991 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9994 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9996 + compound_depend_t *conflicts = pkg->conflicts;
9997 + int conflicts_count = pkg->conflicts_count;
9999 + for (i = 0; i < conflicts_count; i++) {
10000 + int possibility_count = conflicts[i].possibility_count;
10001 + struct depend **possibilities = conflicts[i].possibilities;
10002 + for (j = 0; j < possibility_count; j++) {
10003 + if (possibilities[j]->pkg == conflictee) {
10012 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10013 + * conflictee's provides and 0 otherwise.
10015 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10017 + compound_depend_t *conflicts = pkg->conflicts;
10018 + int conflicts_count = pkg->conflicts_count;
10019 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10020 + int conflictee_provides_count = conflictee->provides_count;
10022 + int possibility_count;
10023 + struct depend **possibilities;
10024 + abstract_pkg_t *possibility ;
10026 + for (i = 0; i < conflicts_count; i++) {
10027 + possibility_count = conflicts[i].possibility_count;
10028 + possibilities = conflicts[i].possibilities;
10029 + for (j = 0; j < possibility_count; j++) {
10030 + possibility = possibilities[j]->pkg;
10031 + for (k = 0; k < conflictee_provides_count; k++) {
10032 + if (possibility == conflictee_provides[k]) {
10041 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10043 + int oldlen = 0, newlen = 0;
10045 + register int i, j;
10050 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10051 + while(newstuff && newstuff[newlen]) newlen++;
10053 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10054 + if (result == NULL) {
10055 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10059 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10060 + *(result + i) = *(newstuff + j);
10062 + *(result + i) = NULL;
10068 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10069 + * this is null terminated, no count is carried around
10071 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10075 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10078 + while(the_lost && the_lost[count]) count++;
10080 + count++; /* need one to hold the null */
10081 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10082 + if (resized == NULL) {
10083 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10086 + resized[count - 1] = strdup(depend_str);
10087 + resized[count] = NULL;
10092 +void printDepends(pkg_t * pkg)
10094 + register int i, j;
10095 + compound_depend_t * depend;
10098 + count = pkg->pre_depends_count + pkg->depends_count;
10100 + depend = pkg->depends;
10102 + fprintf(stderr, "Depends pointer is NULL\n");
10105 + for(i = 0; i < count; i++){
10106 + fprintf(stderr, "%s has %d possibilities:\n",
10107 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10108 + depend->possibility_count);
10109 + for(j = 0; j < depend->possibility_count; j++)
10110 + fprintf(stderr, "\t%s version %s (%d)\n",
10111 + depend->possibilities[j]->pkg->name,
10112 + depend->possibilities[j]->version,
10113 + depend->possibilities[j]->constraint);
10118 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10120 + register int i, j;
10122 + /* every pkg provides itself */
10123 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10125 + if (!pkg->provides_count)
10128 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10129 + if (pkg->provides == NULL) {
10130 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10133 + pkg->provides[0] = ab_pkg;
10135 + // if (strcmp(ab_pkg->name, pkg->name))
10136 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10138 + for(i = 0; i < pkg->provides_count; i++){
10139 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10141 + pkg->provides[i+1] = provided_abpkg;
10144 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10149 +/* Abhaya: added conflicts support */
10150 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10153 + compound_depend_t * conflicts;
10155 + if (!pkg->conflicts_count)
10158 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10159 + pkg->conflicts_count);
10160 + if (conflicts == NULL) {
10161 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10164 + for (i = 0; i < pkg->conflicts_count; i++) {
10165 + conflicts->type = CONFLICTS;
10166 + parseDepends(conflicts, hash,
10167 + pkg->conflicts_str[i]);
10169 + for (j = 0; j < conflicts->possibility_count; j++) {
10170 + depend_t *possibility = conflicts->possibilities[j];
10171 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10172 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10180 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10182 + register int i, j;
10184 + if (!pkg->replaces_count)
10187 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10188 + if (pkg->replaces == NULL) {
10189 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10193 + // if (strcmp(ab_pkg->name, pkg->name))
10194 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10196 + for(i = 0; i < pkg->replaces_count; i++){
10197 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10199 + pkg->replaces[i] = old_abpkg;
10202 + if (!old_abpkg->replaced_by)
10203 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10204 + if ( old_abpkg->replaced_by == NULL ){
10207 + /* if a package pkg both replaces and conflicts old_abpkg,
10208 + * then add it to the replaced_by vector so that old_abpkg
10209 + * will be upgraded to ab_pkg automatically */
10210 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10211 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10216 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10220 + compound_depend_t * depends;
10222 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10225 + if (0 && pkg->pre_depends_count)
10226 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10227 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10228 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10229 + if (depends == NULL) {
10230 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10235 + for(i = 0; i < pkg->pre_depends_count; i++){
10236 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10237 + if (0 && pkg->pre_depends_count)
10238 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10239 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10240 + depends->type = PREDEPEND;
10244 + for(i = 0; i < pkg->recommends_count; i++){
10245 + parseDepends(depends, hash, pkg->recommends_str[i]);
10246 + if (0 && pkg->recommends_count)
10247 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10248 + pkg->recommends_str[i], depends, depends->possibility_count);
10249 + depends->type = RECOMMEND;
10253 + for(i = 0; i < pkg->suggests_count; i++){
10254 + parseDepends(depends, hash, pkg->suggests_str[i]);
10255 + if (0 && pkg->suggests_count)
10256 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10257 + pkg->suggests_str[i], depends, depends->possibility_count);
10258 + depends->type = SUGGEST;
10262 + for(i = 0; i < pkg->depends_count; i++){
10263 + parseDepends(depends, hash, pkg->depends_str[i]);
10264 + if (0 && pkg->depends_count)
10265 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10266 + pkg->depends_str[i], depends, depends->possibility_count);
10273 + * pkg_depend_string: returns the depends string specified by index.
10274 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10275 + * [0,npredepends) -> returns pre_depends_str[index]
10276 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10277 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10278 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10280 +char *pkg_depend_str(pkg_t *pkg, int index)
10282 + if (index < pkg->pre_depends_count) {
10283 + return pkg->pre_depends_str[index];
10285 + index -= pkg->pre_depends_count;
10287 + if (index < pkg->recommends_count) {
10288 + return pkg->recommends_str[index];
10290 + index -= pkg->recommends_count;
10292 + if (index < pkg->suggests_count) {
10293 + return pkg->suggests_str[index];
10295 + index -= pkg->suggests_count;
10297 + if (index < pkg->depends_count) {
10298 + return pkg->depends_str[index];
10300 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10304 +void freeDepends(pkg_t *pkg)
10308 + if (pkg == NULL || pkg->depends == NULL) {
10312 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10313 + for (i=0; i < pkg->depends->possibility_count; i++) {
10314 + depend_deinit(pkg->depends->possibilities[i]);
10316 + free(pkg->depends->possibilities);
10317 + free(pkg->depends);
10318 + pkg->depends = NULL;
10321 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10323 + compound_depend_t * depends;
10324 + int count, othercount;
10325 + register int i, j;
10326 + abstract_pkg_t * ab_depend;
10327 + abstract_pkg_t ** temp;
10329 + count = pkg->pre_depends_count + pkg->depends_count;
10330 + depends = pkg->depends;
10332 + if (0 && pkg->pre_depends_count)
10333 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10334 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10335 + for (i = 0; i < count; i++) {
10336 + if (0 && pkg->pre_depends_count)
10337 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10338 + for (j = 0; j < depends->possibility_count; j++){
10339 + ab_depend = depends->possibilities[j]->pkg;
10340 + if(!ab_depend->depended_upon_by)
10341 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10343 + temp = ab_depend->depended_upon_by;
10351 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10352 + (othercount + 1) * sizeof(abstract_pkg_t *));
10353 + /* the array may have moved */
10354 + temp = ab_depend->depended_upon_by + othercount;
10361 +static depend_t * depend_init(void)
10363 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10368 + d->constraint = NONE;
10369 + d->version = NULL;
10375 +static void depend_deinit(depend_t *d)
10380 +static int parseDepends(compound_depend_t *compound_depend,
10381 + hash_table_t * hash, char * depend_str)
10383 + char * pkg_name, buffer[2048];
10384 + int num_of_ors = 0;
10386 + register char * src, * dest;
10387 + depend_t ** possibilities;
10389 + /* first count the number of ored possibilities for satisfying dependency */
10390 + src = depend_str;
10392 + if(*src++ == '|')
10395 + compound_depend->type = DEPEND;
10397 + compound_depend->possibility_count = num_of_ors + 1;
10398 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10399 + if (!possibilities)
10401 + compound_depend->possibilities = possibilities;
10403 + src = depend_str;
10404 + for(i = 0; i < num_of_ors + 1; i++){
10405 + possibilities[i] = depend_init();
10406 + if (!possibilities[i])
10408 + /* gobble up just the name first */
10411 + !isspace(*src) &&
10415 + *dest++ = *src++;
10417 + pkg_name = trim_alloc(buffer);
10418 + if (pkg_name == NULL )
10421 + /* now look at possible version info */
10423 + /* skip to next chars */
10424 + if(isspace(*src))
10425 + while(*src && isspace(*src)) src++;
10427 + /* extract constraint and version */
10430 + if(!strncmp(src, "<<", 2)){
10431 + possibilities[i]->constraint = EARLIER;
10434 + else if(!strncmp(src, "<=", 2)){
10435 + possibilities[i]->constraint = EARLIER_EQUAL;
10438 + else if(!strncmp(src, ">=", 2)){
10439 + possibilities[i]->constraint = LATER_EQUAL;
10442 + else if(!strncmp(src, ">>", 2)){
10443 + possibilities[i]->constraint = LATER;
10446 + else if(!strncmp(src, "=", 1)){
10447 + possibilities[i]->constraint = EQUAL;
10450 + /* should these be here to support deprecated designations; dpkg does */
10451 + else if(!strncmp(src, "<", 1)){
10452 + possibilities[i]->constraint = EARLIER_EQUAL;
10455 + else if(!strncmp(src, ">", 1)){
10456 + possibilities[i]->constraint = LATER_EQUAL;
10460 + /* now we have any constraint, pass space to version string */
10461 + while(isspace(*src)) src++;
10463 + /* this would be the version string */
10465 + while(*src && *src != ')')
10466 + *dest++ = *src++;
10469 + possibilities[i]->version = trim_alloc(buffer);
10470 + /* fprintf(stderr, "let's print the depends version string:");
10471 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10472 + if (possibilities[i]->version == NULL )
10477 + /* hook up the dependency to its abstract pkg */
10478 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10482 + /* now get past the ) and any possible | chars */
10484 + (isspace(*src) ||
10490 + compound_depend->type = GREEDY_DEPEND;
10497 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_depends.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.h
10498 --- busybox-1.00-orig/archival/libipkg/pkg_depends.h 1970-01-01 00:00:00.000000000 +0000
10499 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_depends.h 2005-07-20 10:19:05.000000000 +0000
10501 +/* pkg_depends.h - the itsy package management system
10505 + Copyright (C) 2002 Compaq Computer Corporation
10507 + This program is free software; you can redistribute it and/or
10508 + modify it under the terms of the GNU General Public License as
10509 + published by the Free Software Foundation; either version 2, or (at
10510 + your option) any later version.
10512 + This program is distributed in the hope that it will be useful, but
10513 + WITHOUT ANY WARRANTY; without even the implied warranty of
10514 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10515 + General Public License for more details.
10518 +#ifndef PKG_DEPENDS_H
10519 +#define PKG_DEPENDS_H
10522 +#include "pkg_hash.h"
10524 +enum depend_type {
10532 +typedef enum depend_type depend_type_t;
10534 +enum version_constraint {
10542 +typedef enum version_constraint version_constraint_t;
10545 + version_constraint_t constraint;
10547 + abstract_pkg_t * pkg;
10549 +typedef struct depend depend_t;
10551 +struct compound_depend{
10552 + depend_type_t type;
10553 + int possibility_count;
10554 + struct depend ** possibilities;
10556 +typedef struct compound_depend compound_depend_t;
10558 +#include "hash_table.h"
10560 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10561 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10562 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10563 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10566 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10567 + * the same abstract package and 0 otherwise.
10569 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10572 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10575 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10578 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10581 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10584 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10587 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10590 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10593 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10595 +char *pkg_depend_str(pkg_t *pkg, int index);
10596 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10597 +void freeDepends(pkg_t *pkg);
10598 +void printDepends(pkg_t * pkg);
10599 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10600 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10601 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10602 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10603 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10606 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.c
10607 --- busybox-1.00-orig/archival/libipkg/pkg_dest.c 1970-01-01 00:00:00.000000000 +0000
10608 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.c 2005-07-17 16:10:25.000000000 +0000
10610 +/* pkg_dest.c - the itsy package management system
10614 + Copyright (C) 2001 University of Southern California
10616 + This program is free software; you can redistribute it and/or
10617 + modify it under the terms of the GNU General Public License as
10618 + published by the Free Software Foundation; either version 2, or (at
10619 + your option) any later version.
10621 + This program is distributed in the hope that it will be useful, but
10622 + WITHOUT ANY WARRANTY; without even the implied warranty of
10623 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10624 + General Public License for more details.
10629 +#include "pkg_dest.h"
10630 +#include "file_util.h"
10631 +#include "str_util.h"
10632 +#include "sprintf_alloc.h"
10634 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10636 + dest->name = strdup(name);
10638 + /* Guarantee that dest->root_dir ends with a '/' */
10639 + if (str_ends_with(root_dir, "/")) {
10640 + dest->root_dir = strdup(root_dir);
10642 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10644 + file_mkdir_hier(dest->root_dir, 0755);
10646 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10647 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10648 + file_mkdir_hier(dest->ipkg_dir, 0755);
10650 + if (str_starts_with (lists_dir, "/"))
10651 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10653 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10655 + file_mkdir_hier(dest->lists_dir, 0755);
10657 + sprintf_alloc(&dest->info_dir, "%s/%s",
10658 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10659 + file_mkdir_hier(dest->info_dir, 0755);
10661 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10662 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10664 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10665 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10667 + dest->status_file = NULL;
10672 +void pkg_dest_deinit(pkg_dest_t *dest)
10674 + free(dest->name);
10675 + dest->name = NULL;
10677 + free(dest->root_dir);
10678 + dest->root_dir = NULL;
10680 + free(dest->ipkg_dir);
10681 + dest->ipkg_dir = NULL;
10683 + free(dest->lists_dir);
10684 + dest->lists_dir = NULL;
10686 + free(dest->info_dir);
10687 + dest->info_dir = NULL;
10689 + free(dest->status_file_name);
10690 + dest->status_file_name = NULL;
10692 + free(dest->status_file_tmp_name);
10693 + dest->status_file_tmp_name = NULL;
10695 + if (dest->status_file) {
10696 + fclose(dest->status_file);
10698 + dest->status_file = NULL;
10700 + dest->root_dir = NULL;
10702 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.h
10703 --- busybox-1.00-orig/archival/libipkg/pkg_dest.h 1970-01-01 00:00:00.000000000 +0000
10704 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest.h 2005-07-17 16:10:25.000000000 +0000
10706 +/* pkg_dest.h - the itsy package management system
10710 + Copyright (C) 2001 University of Southern California
10712 + This program is free software; you can redistribute it and/or
10713 + modify it under the terms of the GNU General Public License as
10714 + published by the Free Software Foundation; either version 2, or (at
10715 + your option) any later version.
10717 + This program is distributed in the hope that it will be useful, but
10718 + WITHOUT ANY WARRANTY; without even the implied warranty of
10719 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10720 + General Public License for more details.
10723 +#ifndef PKG_DEST_H
10724 +#define PKG_DEST_H
10726 +typedef struct pkg_dest pkg_dest_t;
10734 + char *status_file_name;
10735 + char *status_file_tmp_name;
10736 + FILE *status_file;
10739 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10740 +void pkg_dest_deinit(pkg_dest_t *dest);
10744 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.c
10745 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 00:00:00.000000000 +0000
10746 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.c 2005-07-17 16:10:25.000000000 +0000
10748 +/* pkg_dest_list.c - the itsy package management system
10752 + Copyright (C) 2001 University of Southern California
10754 + This program is free software; you can redistribute it and/or
10755 + modify it under the terms of the GNU General Public License as
10756 + published by the Free Software Foundation; either version 2, or (at
10757 + your option) any later version.
10759 + This program is distributed in the hope that it will be useful, but
10760 + WITHOUT ANY WARRANTY; without even the implied warranty of
10761 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10762 + General Public License for more details.
10767 +#include "pkg_dest.h"
10768 +#include "void_list.h"
10769 +#include "pkg_dest_list.h"
10771 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10773 + return void_list_elt_init((void_list_elt_t *) elt, data);
10776 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10778 + void_list_elt_deinit((void_list_elt_t *) elt);
10781 +int pkg_dest_list_init(pkg_dest_list_t *list)
10783 + return void_list_init((void_list_t *) list);
10786 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10788 + pkg_dest_list_elt_t *iter;
10789 + pkg_dest_t *pkg_dest;
10791 + for (iter = list->head; iter; iter = iter->next) {
10792 + pkg_dest = iter->data;
10793 + pkg_dest_deinit(pkg_dest);
10795 + /* malloced in pkg_dest_list_append */
10797 + iter->data = NULL;
10799 + void_list_deinit((void_list_t *) list);
10802 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10803 + const char *root_dir,const char *lists_dir)
10806 + pkg_dest_t *pkg_dest;
10808 + /* freed in plg_dest_list_deinit */
10809 + pkg_dest = malloc(sizeof(pkg_dest_t));
10810 + if (pkg_dest == NULL) {
10811 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10815 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10816 + err = void_list_append((void_list_t *) list, pkg_dest);
10824 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10826 + return void_list_push((void_list_t *) list, data);
10829 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10831 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10833 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_dest_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.h
10834 --- busybox-1.00-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 00:00:00.000000000 +0000
10835 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_dest_list.h 2005-07-17 16:10:25.000000000 +0000
10837 +/* pkg_dest_list.h - the itsy package management system
10841 + Copyright (C) 2001 University of Southern California
10843 + This program is free software; you can redistribute it and/or
10844 + modify it under the terms of the GNU General Public License as
10845 + published by the Free Software Foundation; either version 2, or (at
10846 + your option) any later version.
10848 + This program is distributed in the hope that it will be useful, but
10849 + WITHOUT ANY WARRANTY; without even the implied warranty of
10850 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10851 + General Public License for more details.
10854 +#ifndef PKG_DEST_LIST_H
10855 +#define PKG_DEST_LIST_H
10857 +#include "pkg_dest.h"
10859 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10860 +struct pkg_dest_list_elt
10862 + pkg_dest_list_elt_t *next;
10863 + pkg_dest_t *data;
10866 +typedef struct pkg_dest_list pkg_dest_list_t;
10867 +struct pkg_dest_list
10869 + pkg_dest_list_elt_t pre_head;
10870 + pkg_dest_list_elt_t *head;
10871 + pkg_dest_list_elt_t *tail;
10874 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10875 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10877 +int pkg_dest_list_init(pkg_dest_list_t *list);
10878 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10880 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10881 + const char *root_dir,const char* lists_dir);
10882 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10883 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10887 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.c
10888 --- busybox-1.00-orig/archival/libipkg/pkg_extract.c 1970-01-01 00:00:00.000000000 +0000
10889 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.c 2005-07-20 08:43:49.000000000 +0000
10891 +/* pkg_extract.c - the itsy package management system
10895 + Copyright (C) 2001 University of Southern California
10897 + This program is free software; you can redistribute it and/or
10898 + modify it under the terms of the GNU General Public License as
10899 + published by the Free Software Foundation; either version 2, or (at
10900 + your option) any later version.
10902 + This program is distributed in the hope that it will be useful, but
10903 + WITHOUT ANY WARRANTY; without even the implied warranty of
10904 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10905 + General Public License for more details.
10909 +#include <errno.h>
10910 +#include <fcntl.h>
10911 +#include <stdio.h>
10913 +#include "pkg_extract.h"
10915 +#include "libbb.h"
10916 +#include "file_util.h"
10917 +#include "sprintf_alloc.h"
10918 +#include "unarchive.h"
10920 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10921 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10922 +#define IPKG_CONTROL_FILE "control"
10924 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10926 + archive_handle_t *archive;
10929 + sprintf_alloc(&path, "%s/", dir);
10930 + archive = init_handle();
10931 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10932 + archive->filter = filter_accept_list;
10933 + archive->accept = llist_add_to(NULL, (char *)filename);
10934 + archive->buffer = path;
10935 + archive->action_data = data_extract_all_prefix;
10936 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10937 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10938 + close(archive->src_fd);
10939 + free(archive->accept);
10944 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10946 + unsigned int size = strlen(archive->file_header->name) + 2;
10948 + if (archive->buffer == NULL) {
10949 + archive->buffer = xmalloc(size);
10950 + strcpy(archive->buffer, archive->file_header->name);
10952 + size += strlen(archive->buffer);
10953 + archive->buffer = xrealloc(archive->buffer, size);
10954 + strcat(archive->buffer, archive->file_header->name);
10956 + strcat(archive->buffer, "\n");
10957 + data_skip(archive);
10960 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10962 + archive_handle_t *archive;
10965 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10966 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10967 + archive = init_handle();
10968 + archive->src_fd = bb_xopen(name, O_RDONLY);
10969 + archive->filter = filter_accept_list;
10970 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
10971 + archive->action_data = data_extract_to_buffer;
10972 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10973 + close(archive->src_fd);
10974 + fputs(archive->buffer, stream);
10975 + free(archive->buffer);
10976 + free(archive->accept);
10983 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10985 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10988 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10990 + archive_handle_t *archive;
10994 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10995 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10996 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10997 + archive = init_handle();
10998 + archive->src_fd = bb_xopen(name, O_RDONLY);
10999 + archive->filter = filter_accept_all;
11000 + archive->buffer = path;
11001 + archive->action_data = data_extract_all_prefix;
11002 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11003 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11004 + close(archive->src_fd);
11012 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11014 + archive_handle_t *archive;
11018 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11019 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11020 + sprintf_alloc(&path, "%s/", dir);
11021 + archive = init_handle();
11022 + archive->src_fd = bb_xopen(name, O_RDONLY);
11023 + archive->filter = filter_accept_all;
11024 + archive->buffer = path;
11025 + archive->action_data = data_extract_all_prefix;
11026 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11027 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11028 + close(archive->src_fd);
11036 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11039 + char *line, *data_file;
11043 + file = fopen(file_name, "w");
11044 + if (file == NULL) {
11045 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11046 + __FUNCTION__, file_name);
11051 + if (pkg->installed_files) {
11052 + str_list_elt_t *elt;
11053 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11054 + fprintf(file, "%s\n", elt->data);
11057 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11064 + /* Fixup data file names by removing the initial '.' */
11067 + line = file_read_line_alloc(tmp);
11068 + if (line == NULL) {
11072 + data_file = line;
11073 + if (*data_file == '.') {
11077 + if (*data_file != '/') {
11078 + fputs("/", file);
11081 + /* I have no idea why, but this is what dpkg does */
11082 + if (strcmp(data_file, "/\n") == 0) {
11083 + fputs("/.\n", file);
11085 + fputs(data_file, file);
11095 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11097 + archive_handle_t *archive;
11100 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11101 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11102 + archive = init_handle();
11103 + archive->src_fd = bb_xopen(name, O_RDONLY);
11104 + archive->filter = filter_accept_all;
11105 + archive->action_data = data_extract_file_name_to_buffer;
11106 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11107 + close(archive->src_fd);
11108 + fputs(archive->buffer, file);
11109 + free(archive->buffer);
11115 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_extract.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.h
11116 --- busybox-1.00-orig/archival/libipkg/pkg_extract.h 1970-01-01 00:00:00.000000000 +0000
11117 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_extract.h 2005-07-17 16:10:25.000000000 +0000
11119 +/* pkg_extract.c - the itsy package management system
11123 + Copyright (C) 2001 University of Southern California
11125 + This program is free software; you can redistribute it and/or
11126 + modify it under the terms of the GNU General Public License as
11127 + published by the Free Software Foundation; either version 2, or (at
11128 + your option) any later version.
11130 + This program is distributed in the hope that it will be useful, but
11131 + WITHOUT ANY WARRANTY; without even the implied warranty of
11132 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11133 + General Public License for more details.
11136 +#ifndef PKG_EXTRACT_H
11137 +#define PKG_EXTRACT_H
11141 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11142 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11143 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11145 + const char *prefix);
11146 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11147 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11148 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11151 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.c
11152 --- busybox-1.00-orig/archival/libipkg/pkg_hash.c 1970-01-01 00:00:00.000000000 +0000
11153 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.c 2005-07-20 10:18:39.000000000 +0000
11155 +/* ipkg_hash.c - the itsy package management system
11159 + Copyright (C) 2002 Compaq Computer Corporation
11161 + This program is free software; you can redistribute it and/or
11162 + modify it under the terms of the GNU General Public License as
11163 + published by the Free Software Foundation; either version 2, or (at
11164 + your option) any later version.
11166 + This program is distributed in the hope that it will be useful, but
11167 + WITHOUT ANY WARRANTY; without even the implied warranty of
11168 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11169 + General Public License for more details.
11173 +#include <errno.h>
11174 +#include <ctype.h>
11175 +#include <stdlib.h>
11176 +#include <string.h>
11178 +#include "hash_table.h"
11180 +#include "ipkg_message.h"
11181 +#include "pkg_vec.h"
11182 +#include "pkg_hash.h"
11183 +#include "pkg_parse.h"
11184 +#include "ipkg_utils.h"
11186 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11189 + * this will talk to both feeds-lists files and installed status files
11192 + * hash_table_t hash;
11193 + * pkg_hash_init(name, &hash, 1000);
11194 + * pkg_hash_add_from_file(<feed filename>);
11196 + * the query function is just there as a shell to prove to me that this
11197 + * sort of works, but isn't far from doing something useful
11200 + * modified: CDW 3 Jan. 2002
11205 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11207 + return hash_table_init(name, hash, len);
11210 +void pkg_hash_deinit(hash_table_t *hash)
11212 + hash_table_deinit(hash);
11216 +/* Find the default arch for a given package status file if none is given. */
11217 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11219 + nv_pair_list_elt_t *l;
11220 + char *def_arch = HOST_CPU_STR; /* Default arch */
11221 + int def_prio = 0; /* Other archs override this */
11223 + l = conf->arch_list.head;
11226 + nv_pair_t *nv = l->data;
11227 + int priority = strtol(nv->value, NULL, 0);
11229 + /* Check if this arch has higher priority, and is valid */
11230 + if ((priority > def_prio) &&
11231 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11232 + /* Our new default */
11233 + def_prio = priority;
11234 + def_arch = nv->name;
11239 + return strdup(def_arch);
11242 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11243 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11245 + hash_table_t *hash = &conf->pkg_hash;
11247 + char **raw_start;
11250 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11254 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11259 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11260 + if (!pkg->architecture) {
11261 + char *version_str = pkg_version_str_alloc(pkg);
11262 + pkg->architecture = pkg_get_default_arch(conf);
11263 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11264 + pkg->name, version_str, pkg->architecture);
11265 + free(version_str);
11267 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11273 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11274 + memory after read_raw_pkgs_from_file */
11283 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11285 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11288 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11290 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11293 + return apkg->provided_by;
11297 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11298 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11301 + int nprovides = 0;
11302 + int nmatching = 0;
11303 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11304 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11305 + abstract_pkg_vec_t *provided_apkg_vec;
11306 + abstract_pkg_t **provided_apkgs;
11307 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11308 + pkg_t *latest_installed_parent = NULL;
11309 + pkg_t *latest_matching = NULL;
11310 + pkg_t *held_pkg = NULL;
11312 + if (matching_apkgs == NULL || providers == NULL ||
11313 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11316 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11318 + provided_apkg_vec = apkg->provided_by;
11319 + nprovides = provided_apkg_vec->len;
11320 + provided_apkgs = provided_apkg_vec->pkgs;
11321 + if (nprovides > 1)
11322 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11324 + /* accumulate all the providers */
11325 + for (i = 0; i < nprovides; i++) {
11326 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11327 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11328 + abstract_pkg_vec_insert(providers, provider_apkg);
11330 + nprovides = providers->len;
11332 + for (i = 0; i < nprovides; i++) {
11333 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11334 + abstract_pkg_t *replacement_apkg = NULL;
11337 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11338 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11339 + if (provider_apkg->replaced_by->len > 1) {
11340 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11341 + provider_apkg->name, replacement_apkg->name);
11345 + if (replacement_apkg)
11346 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11347 + replacement_apkg->name, provider_apkg->name);
11349 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11350 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11353 + provider_apkg = replacement_apkg;
11356 + if (!(vec = provider_apkg->pkgs)) {
11357 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11362 +/* Could a package provide more than a package ? */
11363 + /* now check for supported architecture and satisfaction of constraint_fcn */
11365 + int max_count = 0;
11368 + /* count packages matching max arch priority and keep track of last one */
11369 + for (i = 0; i < vec->len; i++) {
11370 + pkg_t *maybe = vec->pkgs[i];
11371 + /* only consider the ones that satisfy the constraint */
11372 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d constraint=%d \n",
11373 + maybe->name, maybe->architecture,
11374 + maybe->arch_priority,
11375 + ((constraint_fcn == NULL) || constraint_fcn(maybe, cdata)));
11376 + if ((maybe->arch_priority > 0)
11377 + && ((constraint_fcn == NULL) || constraint_fcn(maybe, cdata))) {
11380 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11381 + pkg_vec_insert(matching_pkgs, maybe);
11387 + if (matching_pkgs->len > 1)
11388 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11389 + if (matching_apkgs->len > 1)
11390 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11392 + for (i = 0; i < matching_pkgs->len; i++) {
11393 + pkg_t *matching = matching_pkgs->pkgs[i];
11394 + latest_matching = matching;
11395 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11396 + latest_installed_parent = matching;
11397 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11399 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11400 + held_pkg->name, matching->name);
11401 + held_pkg = matching;
11405 + if (!held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11406 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11407 + apkg->name, matching_apkgs->len);
11408 + if (conf->verbosity > 1) {
11409 + for (i = 0; i < matching_apkgs->len; i++) {
11410 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11411 + ipkg_message(conf, IPKG_NOTICE, " %s\n", matching->name);
11414 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11417 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11418 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11419 + __FUNCTION__, apkg->name, matching_pkgs->len);
11420 + for (i = 0; i < matching_pkgs->len; i++) {
11421 + pkg_t *matching = matching_pkgs->pkgs[i];
11422 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11423 + matching->name, matching->version, matching->architecture);
11427 + nmatching = matching_apkgs->len;
11429 + pkg_vec_free(matching_pkgs);
11430 + abstract_pkg_vec_free(matching_apkgs);
11431 + abstract_pkg_vec_free(providers);
11434 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11437 + if (latest_installed_parent) {
11438 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11439 + return latest_installed_parent;
11441 + if (nmatching > 1) {
11442 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11445 + if (latest_matching) {
11446 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11447 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11448 + return latest_matching;
11453 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11455 + const char *name = (const char *)cdata;
11456 + if (strcmp(pkg->name, name) == 0)
11462 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11464 + hash_table_t *hash = &conf->pkg_hash;
11465 + abstract_pkg_t *apkg = NULL;
11467 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11470 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11474 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11475 + const char *pkg_name,
11476 + const char * version)
11480 + char *version_str = NULL;
11482 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11485 + for(i = 0; i < vec->len; i++) {
11486 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11487 + if(!strcmp(version_str, version)) {
11488 + free(version_str);
11491 + free(version_str);
11494 + if(i == vec->len)
11497 + return vec->pkgs[i];
11500 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11501 + const char *pkg_name,
11502 + pkg_dest_t *dest)
11507 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11511 + for(i = 0; i < vec->len; i++)
11512 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11513 + return vec->pkgs[i];
11518 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11519 + const char *pkg_name)
11524 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11528 + for(i = 0; i < vec->len; i++)
11529 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11530 + return vec->pkgs[i];
11536 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11538 + abstract_pkg_t * ab_pkg;
11540 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11544 + if (ab_pkg->pkgs) {
11545 + return ab_pkg->pkgs;
11546 + } else if (ab_pkg->provided_by) {
11547 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11548 + if (abpkg != NULL){
11549 + return abpkg->pkgs;
11551 + return ab_pkg->pkgs;
11558 +static int pkg_compare_names(const void *p1, const void *p2)
11560 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11561 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11562 + if (pkg1->name == NULL)
11564 + if (pkg2->name == NULL)
11566 + return(strcmp(pkg1->name, pkg2->name));
11570 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11573 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11574 + pkg_vec_t *all = (pkg_vec_t *)data;
11575 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11577 + for (j = 0; j < pkg_vec->len; j++) {
11578 + pkg_t *pkg = pkg_vec->pkgs[j];
11579 + pkg_vec_insert(all, pkg);
11584 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11586 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11587 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11590 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11592 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11593 + pkg_vec_t *all = (pkg_vec_t *)data;
11594 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11597 + for (j = 0; j < pkg_vec->len; j++) {
11598 + pkg_t *pkg = pkg_vec->pkgs[j];
11599 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11600 + pkg_vec_insert(all, pkg);
11605 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11607 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11608 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11611 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11615 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11616 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11617 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11618 + fprintf(stdout, "%s\n", ab_pkg->name);
11620 + if (dependents != NULL)
11621 + while (dependents [i] != NULL)
11622 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11623 + dependents = ab_pkg->provided_by->pkgs;
11625 + if (dependents != NULL)
11626 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11627 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11628 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11631 + while (i < pkg->depends_count)
11632 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11635 +void pkg_hash_dump(hash_table_t *hash, void *data)
11638 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11639 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11640 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11643 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11645 + abstract_pkg_t * ab_pkg;
11647 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11648 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11653 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11655 + abstract_pkg_t * ab_pkg;
11656 + int arch_priority;
11661 + arch_priority = pkg->arch_priority;
11663 + if (buildDepends(hash, pkg)<0){
11664 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11667 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11669 + if (set_status) {
11670 + if (pkg->state_status == SS_INSTALLED) {
11671 + ab_pkg->state_status = SS_INSTALLED;
11672 + } else if (pkg->state_status == SS_UNPACKED) {
11673 + ab_pkg->state_status = SS_UNPACKED;
11677 + if(!ab_pkg->pkgs)
11678 + ab_pkg->pkgs = pkg_vec_alloc();
11680 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11681 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11682 + pkg->parent = ab_pkg;
11684 + if (buildProvides(hash, ab_pkg, pkg)<0){
11685 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11688 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11689 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11690 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11693 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11694 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11698 + buildDependedUponBy(pkg, ab_pkg);
11703 + * this will assume that we've already determined that
11704 + * the abstract pkg doesn't exist, 'cause we should know these things...
11706 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11708 + abstract_pkg_t * ab_pkg;
11710 + ab_pkg = abstract_pkg_new();
11711 + if (ab_pkg == NULL) { return NULL; }
11713 + ab_pkg->name = strdup(pkg_name);
11714 + hash_table_insert(hash, pkg_name, ab_pkg);
11720 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11722 + hash_table_t *file_hash = &conf->file_hash;
11724 + return hash_table_get(file_hash, file_name);
11727 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11729 + hash_table_t *file_hash = &conf->file_hash;
11730 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11731 + int file_name_len = strlen(file_name);
11733 + if (file_name[file_name_len -1] == '/')
11736 + if (conf->offline_root) {
11737 + int len = strlen(conf->offline_root);
11738 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11739 + file_name += len;
11743 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11744 + hash_table_insert(file_hash, file_name, owning_pkg);
11745 + if (old_owning_pkg) {
11746 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11747 + /* mark this package to have its filelist written */
11748 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11749 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11755 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_hash.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.h
11756 --- busybox-1.00-orig/archival/libipkg/pkg_hash.h 1970-01-01 00:00:00.000000000 +0000
11757 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_hash.h 2005-07-17 16:10:25.000000000 +0000
11759 +/* pkg_hash.h - the itsy package management system
11763 + Copyright (C) 2002 Compaq Computer Corporation
11765 + This program is free software; you can redistribute it and/or
11766 + modify it under the terms of the GNU General Public License as
11767 + published by the Free Software Foundation; either version 2, or (at
11768 + your option) any later version.
11770 + This program is distributed in the hope that it will be useful, but
11771 + WITHOUT ANY WARRANTY; without even the implied warranty of
11772 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11773 + General Public License for more details.
11776 +#ifndef PKG_HASH_H
11777 +#define PKG_HASH_H
11780 +#include "pkg_vec.h"
11781 +#include "hash_table.h"
11784 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11785 +void pkg_hash_deinit(hash_table_t *hash);
11786 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11788 +void pkg_hash_dump(hash_table_t *hash, void *data);
11789 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11791 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11792 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11793 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11795 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11796 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11797 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11798 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11799 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11800 + const char *pkg_name,
11801 + const char * version);
11802 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11803 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11804 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11805 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11806 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11807 + const char *pkg_name);
11808 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11809 + const char *pkg_name,
11810 + pkg_dest_t *dest);
11812 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11813 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11815 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11816 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11820 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.c
11821 --- busybox-1.00-orig/archival/libipkg/pkg_parse.c 1970-01-01 00:00:00.000000000 +0000
11822 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.c 2005-07-17 16:10:25.000000000 +0000
11824 +/* pkg_parse.c - the itsy package management system
11828 + Copyright (C) 2002 Compaq Computer Corporation
11830 + This program is free software; you can redistribute it and/or
11831 + modify it under the terms of the GNU General Public License as
11832 + published by the Free Software Foundation; either version 2, or (at
11833 + your option) any later version.
11835 + This program is distributed in the hope that it will be useful, but
11836 + WITHOUT ANY WARRANTY; without even the implied warranty of
11837 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11838 + General Public License for more details.
11842 +#include <errno.h>
11843 +#include <ctype.h>
11846 +#include "ipkg_utils.h"
11847 +#include "pkg_parse.h"
11849 +int isGenericFieldType(char * type, char * line)
11851 + if(!strncmp(line, type, strlen(type)))
11856 +char * parseGenericFieldType(char * type, char * raw)
11858 + char * field_value = raw + (strlen(type) + 1);
11859 + return trim_alloc(field_value);
11862 +void parseStatus(pkg_t *pkg, char * raw)
11864 + char sw_str[64], sf_str[64], ss_str[64];
11866 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11867 + pkg->state_want = pkg_state_want_from_str(sw_str);
11868 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11869 + pkg->state_status = pkg_state_status_from_str(ss_str);
11872 +char ** parseDependsString(char * raw, int * depends_count)
11874 + char ** depends = NULL;
11875 + int line_count = 0;
11876 + char buff[2048], * dest;
11878 + while(raw && *raw && !isspace(*raw)) {
11882 + if(line_is_blank(raw)){
11883 + *depends_count = line_count;
11886 + while(raw && *raw){
11887 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11889 + while(isspace(*raw)) raw++;
11892 + while((*raw != ',') && *raw)
11893 + *dest++ = *raw++;
11896 + depends[line_count] = trim_alloc(buff);
11897 + if(depends[line_count] ==NULL)
11903 + *depends_count = line_count;
11907 +void parseConffiles(pkg_t * pkg, char * raw)
11909 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11911 + if(!strncmp(raw, "Conffiles:", 10))
11912 + raw += strlen("Conffiles:");
11914 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11915 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11916 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11917 + while (*raw && isspace(*raw)) {
11920 + raw += strlen(file_name);
11921 + while (*raw && isspace(*raw)) {
11924 + raw += strlen(md5sum);
11928 +int parseVersion(pkg_t *pkg, char *raw)
11930 + char *colon, *eepochcolon;
11931 +#ifdef USE_DEBVERSION
11934 + unsigned long epoch;
11937 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11941 + if (strncmp(raw, "Version:", 8) == 0) {
11944 + while (*raw && isspace(*raw)) {
11948 + colon= strchr(raw,':');
11950 + epoch= strtoul(raw,&eepochcolon,10);
11951 + if (colon != eepochcolon) {
11952 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11956 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11960 + pkg->epoch= epoch;
11965 + pkg->revision = "";
11966 + pkg->familiar_revision = "";
11968 + pkg->version= malloc(strlen(raw)+1);
11969 + if ( pkg->version == NULL ) {
11970 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11973 + strcpy(pkg->version, raw);
11975 +#ifdef USE_DEBVERSION
11976 + hyphen= strrchr(pkg->version,'-');
11980 + if (strncmp("fam", hyphen, 3) == 0) {
11981 + pkg->familiar_revision=hyphen+3;
11982 + hyphen= strrchr(pkg->version,'-');
11985 + pkg->revision = hyphen;
11988 + pkg->revision = hyphen;
11994 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
11998 + pkg->familiar_revision);
12005 +/* This code is needed to insert in first position the keyword for the aligning bug */
12007 +int alterProvidesLine(char *raw, char *temp)
12012 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12016 + if ( temp == NULL ) {
12017 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12021 + if (strncmp(raw, "Provides:", 9) == 0) {
12024 + while (*raw && isspace(*raw)) {
12028 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12030 + strncat( temp, raw++, 1);
12036 +/* Some random thoughts from Carl:
12038 + This function could be considerably simplified if we just kept
12039 + an array of all the generic string-valued field names, and looped
12040 + through those looking for a match. Also, these fields could perhaps
12041 + be stored in the package as an array as well, (or, probably better,
12042 + as an nv_pair_list_t).
12044 + Fields which require special parsing or storage, (such as Depends:
12045 + and Status:) could be handled as they are now.
12047 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12048 + to a dependency list. And, since we already have
12049 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12050 + Enhances, perhaps we could generalize all of these and save some
12051 + code duplication.
12053 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12055 + int reading_conffiles, reading_description;
12056 + int pkg_false_provides=1;
12058 + char * provide=NULL;
12061 + pkg->dest = dest;
12063 + reading_conffiles = reading_description = 0;
12065 + for (lines = *raw; *lines; lines++) {
12066 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12067 + if(isGenericFieldType("Package:", *lines))
12068 + pkg->name = parseGenericFieldType("Package", *lines);
12069 + else if(isGenericFieldType("Architecture:", *lines))
12070 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12071 + else if(isGenericFieldType("Filename:", *lines))
12072 + pkg->filename = parseGenericFieldType("Filename", *lines);
12073 + else if(isGenericFieldType("Section:", *lines))
12074 + pkg->section = parseGenericFieldType("Section", *lines);
12075 + else if(isGenericFieldType("MD5sum:", *lines))
12076 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12077 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12078 + let's parse it either way */
12079 + else if(isGenericFieldType("MD5Sum:", *lines))
12080 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12081 + else if(isGenericFieldType("Size:", *lines))
12082 + pkg->size = parseGenericFieldType("Size", *lines);
12083 + else if(isGenericFieldType("Source:", *lines))
12084 + pkg->source = parseGenericFieldType("Source", *lines);
12085 + else if(isGenericFieldType("Installed-Size:", *lines))
12086 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12087 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12088 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12089 + pkg->installed_time = strtoul(time_str, NULL, 0);
12090 + } else if(isGenericFieldType("Priority:", *lines))
12091 + pkg->priority = parseGenericFieldType("Priority", *lines);
12092 + else if(isGenericFieldType("Essential:", *lines)) {
12093 + char *essential_value;
12094 + essential_value = parseGenericFieldType("Essential", *lines);
12095 + if (strcmp(essential_value, "yes") == 0) {
12096 + pkg->essential = 1;
12098 + free(essential_value);
12100 + else if(isGenericFieldType("Status", *lines))
12101 + parseStatus(pkg, *lines);
12102 + else if(isGenericFieldType("Version", *lines))
12103 + parseVersion(pkg, *lines);
12104 + else if(isGenericFieldType("Maintainer", *lines))
12105 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12106 + else if(isGenericFieldType("Conffiles", *lines)){
12107 + parseConffiles(pkg, *lines);
12108 + reading_conffiles = 1;
12110 + else if(isGenericFieldType("Description", *lines)) {
12111 + pkg->description = parseGenericFieldType("Description", *lines);
12112 + reading_conffiles = 0;
12113 + reading_description = 1;
12116 + else if(isGenericFieldType("Provides", *lines)){
12117 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12118 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12119 + if ( alterProvidesLine(*lines,provide) ){
12122 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12123 +/* Let's try to hack a bit here.
12124 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12125 + in alot of other places. We will remove it before writing down the status database */
12126 + pkg_false_provides=0;
12130 + else if(isGenericFieldType("Depends", *lines))
12131 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12132 + else if(isGenericFieldType("Pre-Depends", *lines))
12133 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12134 + else if(isGenericFieldType("Recommends", *lines))
12135 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12136 + else if(isGenericFieldType("Suggests", *lines))
12137 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12138 + /* Abhaya: support for conflicts */
12139 + else if(isGenericFieldType("Conflicts", *lines))
12140 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12141 + else if(isGenericFieldType("Replaces", *lines))
12142 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12143 + else if(line_is_blank(*lines)) {
12147 + else if(**lines == ' '){
12148 + if(reading_description) {
12149 + /* we already know it's not blank, so the rest of description */
12150 + pkg->description = realloc(pkg->description,
12151 + strlen(pkg->description)
12152 + + 1 + strlen(*lines) + 1);
12153 + strcat(pkg->description, "\n");
12154 + strcat(pkg->description, (*lines));
12156 + else if(reading_conffiles)
12157 + parseConffiles(pkg, *lines);
12161 +/* If the ipk has not a Provides line, we insert our false line */
12162 + if ( pkg_false_provides==1)
12163 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12172 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12176 + for (lines = *raw; *lines; lines++) {
12177 + if(isGenericFieldType("Essential:", *lines)) {
12178 + char *essential_value;
12179 + essential_value = parseGenericFieldType("Essential", *lines);
12180 + if (strcmp(essential_value, "yes") == 0) {
12181 + pkg->essential = 1;
12183 + free(essential_value);
12190 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_parse.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.h
12191 --- busybox-1.00-orig/archival/libipkg/pkg_parse.h 1970-01-01 00:00:00.000000000 +0000
12192 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_parse.h 2005-07-17 16:10:25.000000000 +0000
12194 +/* pkg_parse.h - the itsy package management system
12198 + Copyright (C) 2002 Compaq Computer Corporation
12200 + This program is free software; you can redistribute it and/or
12201 + modify it under the terms of the GNU General Public License as
12202 + published by the Free Software Foundation; either version 2, or (at
12203 + your option) any later version.
12205 + This program is distributed in the hope that it will be useful, but
12206 + WITHOUT ANY WARRANTY; without even the implied warranty of
12207 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12208 + General Public License for more details.
12211 +#ifndef PKG_PARSE_H
12212 +#define PKG_PARSE_H
12214 +int isGenericFieldType(char * type, char * line);
12215 +char * parseGenericFieldType(char * type, char * raw);
12216 +void parseStatus(pkg_t *pkg, char * raw);
12217 +int parseVersion(pkg_t *pkg, char *raw);
12218 +char ** parseDependsString(char * raw, int * depends_count);
12219 +int parseVersion(pkg_t *pkg, char *raw);
12220 +void parseConffiles(pkg_t * pkg, char * raw);
12221 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12222 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12225 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.c
12226 --- busybox-1.00-orig/archival/libipkg/pkg_src.c 1970-01-01 00:00:00.000000000 +0000
12227 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.c 2005-07-17 16:10:25.000000000 +0000
12229 +/* pkg_src.c - the itsy package management system
12233 + Copyright (C) 2001 University of Southern California
12235 + This program is free software; you can redistribute it and/or
12236 + modify it under the terms of the GNU General Public License as
12237 + published by the Free Software Foundation; either version 2, or (at
12238 + your option) any later version.
12240 + This program is distributed in the hope that it will be useful, but
12241 + WITHOUT ANY WARRANTY; without even the implied warranty of
12242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12243 + General Public License for more details.
12248 +#include "pkg_src.h"
12249 +#include "str_util.h"
12251 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12253 + src->gzip = gzip;
12254 + src->name = str_dup_safe (name);
12255 + src->value = str_dup_safe (base_url);
12257 + src->extra_data = str_dup_safe (extra_data);
12259 + src->extra_data = NULL;
12263 +void pkg_src_deinit(pkg_src_t *src)
12265 + free (src->name);
12266 + free (src->value);
12267 + if (src->extra_data)
12268 + free (src->extra_data);
12272 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.h
12273 --- busybox-1.00-orig/archival/libipkg/pkg_src.h 1970-01-01 00:00:00.000000000 +0000
12274 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src.h 2005-07-17 16:10:25.000000000 +0000
12276 +/* pkg_src.h - the itsy package management system
12280 + Copyright (C) 2001 University of Southern California
12282 + This program is free software; you can redistribute it and/or
12283 + modify it under the terms of the GNU General Public License as
12284 + published by the Free Software Foundation; either version 2, or (at
12285 + your option) any later version.
12287 + This program is distributed in the hope that it will be useful, but
12288 + WITHOUT ANY WARRANTY; without even the implied warranty of
12289 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12290 + General Public License for more details.
12296 +#include "nv_pair.h"
12302 + char *extra_data;
12306 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12307 +void pkg_src_deinit(pkg_src_t *src);
12310 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.c
12311 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.c 1970-01-01 00:00:00.000000000 +0000
12312 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.c 2005-07-17 16:10:25.000000000 +0000
12314 +/* pkg_src_list.c - the itsy package management system
12318 + Copyright (C) 2001 University of Southern California
12320 + This program is free software; you can redistribute it and/or
12321 + modify it under the terms of the GNU General Public License as
12322 + published by the Free Software Foundation; either version 2, or (at
12323 + your option) any later version.
12325 + This program is distributed in the hope that it will be useful, but
12326 + WITHOUT ANY WARRANTY; without even the implied warranty of
12327 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12328 + General Public License for more details.
12333 +#include "pkg_src_list.h"
12334 +#include "void_list.h"
12336 +int pkg_src_list_init(pkg_src_list_t *list)
12338 + return void_list_init((void_list_t *) list);
12341 +void pkg_src_list_deinit(pkg_src_list_t *list)
12343 + pkg_src_list_elt_t *iter;
12344 + pkg_src_t *pkg_src;
12346 + for (iter = list->head; iter; iter = iter->next) {
12347 + pkg_src = iter->data;
12348 + pkg_src_deinit(pkg_src);
12350 + /* malloced in pkg_src_list_append */
12352 + iter->data = NULL;
12354 + void_list_deinit((void_list_t *) list);
12357 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12358 + const char *name, const char *base_url, const char *extra_data,
12363 + /* freed in pkg_src_list_deinit */
12364 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12366 + if (pkg_src == NULL) {
12367 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12370 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12372 + err = void_list_append((void_list_t *) list, pkg_src);
12380 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12382 + return void_list_push((void_list_t *) list, data);
12385 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12387 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12389 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_src_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.h
12390 --- busybox-1.00-orig/archival/libipkg/pkg_src_list.h 1970-01-01 00:00:00.000000000 +0000
12391 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_src_list.h 2005-07-17 16:10:25.000000000 +0000
12393 +/* pkg_src_list.h - the itsy package management system
12397 + Copyright (C) 2001 University of Southern California
12399 + This program is free software; you can redistribute it and/or
12400 + modify it under the terms of the GNU General Public License as
12401 + published by the Free Software Foundation; either version 2, or (at
12402 + your option) any later version.
12404 + This program is distributed in the hope that it will be useful, but
12405 + WITHOUT ANY WARRANTY; without even the implied warranty of
12406 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12407 + General Public License for more details.
12410 +#ifndef PKG_SRC_LIST_H
12411 +#define PKG_SRC_LIST_H
12413 +#include "pkg_src.h"
12415 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12416 +struct pkg_src_list_elt
12418 + pkg_src_list_elt_t *next;
12422 +typedef struct pkg_src_list pkg_src_list_t;
12423 +struct pkg_src_list
12425 + pkg_src_list_elt_t pre_head;
12426 + pkg_src_list_elt_t *head;
12427 + pkg_src_list_elt_t *tail;
12430 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12432 + if (list->head == NULL)
12438 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12439 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12441 +int pkg_src_list_init(pkg_src_list_t *list);
12442 +void pkg_src_list_deinit(pkg_src_list_t *list);
12444 +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);
12445 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12446 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12450 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.c
12451 --- busybox-1.00-orig/archival/libipkg/pkg_vec.c 1970-01-01 00:00:00.000000000 +0000
12452 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.c 2005-07-17 16:10:25.000000000 +0000
12454 +/* pkg_vec.c - the itsy package management system
12458 + Copyright (C) 2002 Compaq Computer Corporation
12460 + This program is free software; you can redistribute it and/or
12461 + modify it under the terms of the GNU General Public License as
12462 + published by the Free Software Foundation; either version 2, or (at
12463 + your option) any later version.
12465 + This program is distributed in the hope that it will be useful, but
12466 + WITHOUT ANY WARRANTY; without even the implied warranty of
12467 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12468 + General Public License for more details.
12471 +#include <stdlib.h>
12472 +#include <fnmatch.h>
12473 +#include "xregex.h"
12477 +pkg_vec_t * pkg_vec_alloc(void)
12479 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12481 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12484 + vec->pkgs = NULL;
12490 +void pkg_vec_free(pkg_vec_t *vec)
12497 + * assumption: all names in a vector are identical
12498 + * assumption: all version strings are trimmed,
12499 + * so identical versions have identical version strings,
12500 + * implying identical packages; let's marry these
12502 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12507 + /* look for a duplicate pkg by name, version, and architecture */
12508 + for (i = 0; i < vec->len; i++)
12509 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12510 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12511 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12513 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12514 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12518 + /* we didn't find one, add it */
12520 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12521 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12523 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12524 + vec->pkgs[vec->len] = pkg;
12528 + /* update the one that we have */
12530 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12531 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12532 + if (set_status) {
12533 + /* this is from the status file, so need to merge with existing database */
12534 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12535 + pkg_merge(vec->pkgs[i], pkg, set_status);
12536 + /* XXX: CLEANUP: It's not so polite to free something here
12537 + that was passed in from above. */
12541 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12542 + /* just overwrite the old one */
12543 + pkg_deinit(vec->pkgs[i]);
12544 + free(vec->pkgs[i]);
12545 + vec->pkgs[i] = pkg;
12547 + return vec->pkgs[i];
12551 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12556 + /* look for a duplicate pkg by name, version, and architecture */
12557 + for (i = 0; i < vec->len; i++)
12558 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12559 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12560 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12565 + /* we didn't find one, add it */
12567 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12568 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12573 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12576 + for (i = 0; i < vec->len; i++)
12577 + if (vec->pkgs[i] == apkg)
12582 +typedef int (*compare_fcn_t)(const void *, const void *);
12583 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12585 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12588 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12590 + int npkgs = vec->len;
12592 + for (i = 0; i < npkgs; i++) {
12593 + pkg_t *pkg = vec->pkgs[i];
12594 + pkg->state_flag &= ~SF_MARKED;
12599 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12601 + int matching_count = 0;
12602 + pkg_t **pkgs = vec->pkgs;
12603 + int npkgs = vec->len;
12605 + for (i = 0; i < npkgs; i++) {
12606 + pkg_t *pkg = pkgs[i];
12607 + if (fnmatch(pattern, pkg->name, 0)==0) {
12608 + pkg->state_flag |= SF_MARKED;
12609 + matching_count++;
12612 + return matching_count;
12616 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12618 + abstract_pkg_vec_t * vec ;
12619 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12621 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12624 + vec->pkgs = NULL;
12630 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12637 + * assumption: all names in a vector are unique
12639 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12643 + /* look for a duplicate pkg by name */
12644 + for(i = 0; i < vec->len; i++)
12645 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12648 + /* we didn't find one, add it */
12649 + if(i == vec->len){
12651 + (abstract_pkg_t **)
12652 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12653 + vec->pkgs[vec->len] = pkg;
12658 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12660 + if (vec->len > i)
12661 + return vec->pkgs[i];
12666 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12669 + for (i = 0; i < vec->len; i++)
12670 + if (vec->pkgs[i] == apkg)
12675 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12677 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12680 diff -ruN busybox-1.00-orig/archival/libipkg/pkg_vec.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.h
12681 --- busybox-1.00-orig/archival/libipkg/pkg_vec.h 1970-01-01 00:00:00.000000000 +0000
12682 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/pkg_vec.h 2005-07-17 16:10:25.000000000 +0000
12684 +/* pkg_vec.h - the itsy package management system
12688 + Copyright (C) 2002 Compaq Computer Corporation
12690 + This program is free software; you can redistribute it and/or
12691 + modify it under the terms of the GNU General Public License as
12692 + published by the Free Software Foundation; either version 2, or (at
12693 + your option) any later version.
12695 + This program is distributed in the hope that it will be useful, but
12696 + WITHOUT ANY WARRANTY; without even the implied warranty of
12697 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12698 + General Public License for more details.
12704 +typedef struct pkg pkg_t;
12705 +typedef struct abstract_pkg abstract_pkg_t;
12712 +typedef struct pkg_vec pkg_vec_t;
12714 +struct abstract_pkg_vec
12716 + abstract_pkg_t **pkgs;
12719 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12722 +pkg_vec_t * pkg_vec_alloc(void);
12723 +void pkg_vec_free(pkg_vec_t *vec);
12724 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12726 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12727 +/* pkg_vec_insert_merge: might munge pkg.
12728 +* returns the pkg that is in the pkg graph */
12729 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12730 +/* this one never munges pkg */
12731 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12732 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12733 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12735 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12736 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12738 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12739 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12740 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12741 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12742 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12743 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12746 diff -ruN busybox-1.00-orig/archival/libipkg/sprintf_alloc.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/sprintf_alloc.h
12747 --- busybox-1.00-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 00:00:00.000000000 +0000
12748 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/sprintf_alloc.h 2005-07-20 17:16:41.554124384 +0000
12750 +/* sprintf_alloca.c -- like sprintf with memory allocation
12754 + Copyright (C) 2001 University of Southern California
12756 + This program is free software; you can redistribute it and/or modify
12757 + it under the terms of the GNU General Public License as published by
12758 + the Free Software Foundation; either version 2, or (at your option)
12759 + any later version.
12761 + This program is distributed in the hope that it will be useful,
12762 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12764 + GNU General Public License for more details.
12767 +#ifndef SPRINTF_ALLOC_H
12768 +#define SPRINTF_ALLOC_H
12770 +#include "libbb.h"
12772 +#define sprintf_alloc bb_xasprintf
12775 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.c
12776 --- busybox-1.00-orig/archival/libipkg/str_list.c 1970-01-01 00:00:00.000000000 +0000
12777 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.c 2005-07-17 16:10:25.000000000 +0000
12779 +/* str_list.c - the itsy package management system
12783 + Copyright (C) 2001 University of Southern California
12785 + This program is free software; you can redistribute it and/or
12786 + modify it under the terms of the GNU General Public License as
12787 + published by the Free Software Foundation; either version 2, or (at
12788 + your option) any later version.
12790 + This program is distributed in the hope that it will be useful, but
12791 + WITHOUT ANY WARRANTY; without even the implied warranty of
12792 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12793 + General Public License for more details.
12798 +#include "str_list.h"
12800 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12802 + return void_list_elt_init((void_list_elt_t *) elt, data);
12805 +void str_list_elt_deinit(str_list_elt_t *elt)
12807 + void_list_elt_deinit((void_list_elt_t *) elt);
12810 +str_list_t *str_list_alloc()
12812 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12814 + str_list_init(list);
12818 +int str_list_init(str_list_t *list)
12820 + return void_list_init((void_list_t *) list);
12823 +void str_list_deinit(str_list_t *list)
12825 + void_list_deinit((void_list_t *) list);
12828 +int str_list_append(str_list_t *list, char *data)
12830 + return void_list_append((void_list_t *) list, data);
12833 +int str_list_push(str_list_t *list, char *data)
12835 + return void_list_push((void_list_t *) list, data);
12838 +str_list_elt_t *str_list_pop(str_list_t *list)
12840 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12843 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12845 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12846 + (void_list_elt_t **) iter);
12849 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12851 + return (char *)void_list_remove_elt((void_list_t *) list,
12852 + (void *)target_str,
12853 + (void_list_cmp_t)strcmp);
12855 diff -ruN busybox-1.00-orig/archival/libipkg/str_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.h
12856 --- busybox-1.00-orig/archival/libipkg/str_list.h 1970-01-01 00:00:00.000000000 +0000
12857 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_list.h 2005-07-17 16:10:25.000000000 +0000
12859 +/* str_list.h - the itsy package management system
12863 + Copyright (C) 2001 University of Southern California
12865 + This program is free software; you can redistribute it and/or
12866 + modify it under the terms of the GNU General Public License as
12867 + published by the Free Software Foundation; either version 2, or (at
12868 + your option) any later version.
12870 + This program is distributed in the hope that it will be useful, but
12871 + WITHOUT ANY WARRANTY; without even the implied warranty of
12872 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12873 + General Public License for more details.
12876 +#ifndef STR_LIST_H
12877 +#define STR_LIST_H
12879 +#include "void_list.h"
12881 +typedef struct str_list_elt str_list_elt_t;
12882 +struct str_list_elt
12884 + str_list_elt_t *next;
12888 +typedef struct xstr_list str_list_t;
12891 + str_list_elt_t pre_head;
12892 + str_list_elt_t *head;
12893 + str_list_elt_t *tail;
12896 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12897 +void str_list_elt_deinit(str_list_elt_t *elt);
12899 +str_list_t *str_list_alloc(void);
12900 +int str_list_init(str_list_t *list);
12901 +void str_list_deinit(str_list_t *list);
12903 +int str_list_append(str_list_t *list, char *data);
12904 +int str_list_push(str_list_t *list, char *data);
12905 +str_list_elt_t *str_list_pop(str_list_t *list);
12906 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12907 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12910 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.c
12911 --- busybox-1.00-orig/archival/libipkg/str_util.c 1970-01-01 00:00:00.000000000 +0000
12912 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.c 2005-07-17 16:10:25.000000000 +0000
12914 +/* str_utils.c - the itsy package management system
12918 + Copyright (C) 2001 University of Southern California
12920 + This program is free software; you can redistribute it and/or
12921 + modify it under the terms of the GNU General Public License as
12922 + published by the Free Software Foundation; either version 2, or (at
12923 + your option) any later version.
12925 + This program is distributed in the hope that it will be useful, but
12926 + WITHOUT ANY WARRANTY; without even the implied warranty of
12927 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12928 + General Public License for more details.
12933 +int str_starts_with(const char *str, const char *prefix)
12935 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12938 +int str_ends_with(const char *str, const char *suffix)
12943 + str_len = strlen(str);
12944 + suffix_len = strlen(suffix);
12946 + if (str_len < suffix_len) {
12950 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12953 +int str_chomp(char *str)
12955 + if (str[strlen(str) - 1] == '\n') {
12956 + str[strlen(str) - 1] = '\0';
12962 +int str_tolower(char *str)
12965 + *str = tolower(*str);
12972 +int str_toupper(char *str)
12975 + *str = toupper(*str);
12982 +char *str_dup_safe(const char *str)
12984 + return str ? strdup(str) : NULL;
12987 diff -ruN busybox-1.00-orig/archival/libipkg/str_util.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.h
12988 --- busybox-1.00-orig/archival/libipkg/str_util.h 1970-01-01 00:00:00.000000000 +0000
12989 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/str_util.h 2005-07-17 16:10:25.000000000 +0000
12991 +/* str_utils.h - the itsy package management system
12995 + Copyright (C) 2001 University of Southern California
12997 + This program is free software; you can redistribute it and/or
12998 + modify it under the terms of the GNU General Public License as
12999 + published by the Free Software Foundation; either version 2, or (at
13000 + your option) any later version.
13002 + This program is distributed in the hope that it will be useful, but
13003 + WITHOUT ANY WARRANTY; without even the implied warranty of
13004 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13005 + General Public License for more details.
13008 +#ifndef STR_UTILS_H
13009 +#define STR_UTILS_H
13011 +int str_starts_with(const char *str, const char *prefix);
13012 +int str_ends_with(const char *str, const char *suffix);
13013 +int str_chomp(char *str);
13014 +int str_tolower(char *str);
13015 +int str_toupper(char *str);
13016 +char *str_dup_safe(const char *str);
13019 diff -ruN busybox-1.00-orig/archival/libipkg/user.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.c
13020 --- busybox-1.00-orig/archival/libipkg/user.c 1970-01-01 00:00:00.000000000 +0000
13021 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.c 2005-07-17 16:10:26.000000000 +0000
13023 +/* user.c - the itsy package management system
13027 + Copyright (C) 2002 Hewlett Packard Company
13028 + Copyright (C) 2001 University of Southern California
13030 + This program is free software; you can redistribute it and/or
13031 + modify it under the terms of the GNU General Public License as
13032 + published by the Free Software Foundation; either version 2, or (at
13033 + your option) any later version.
13035 + This program is distributed in the hope that it will be useful, but
13036 + WITHOUT ANY WARRANTY; without even the implied warranty of
13037 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13038 + General Public License for more details.
13041 +#include <stdio.h>
13042 +#include <stdarg.h>
13043 +#include "file_util.h"
13044 +#include "str_util.h"
13046 +#include "libipkg.h"
13051 +static char *question = NULL;
13052 +static int question_len = 255;
13054 +char *get_user_response(const char *format, ...)
13056 + int len = question_len;
13059 + va_start(ap, format);
13062 + vprintf(format, ap);
13064 + response = file_read_line_alloc(stdin);
13065 + } while (response == NULL);
13068 + if (question == NULL || len > question_len) {
13069 + question = realloc(question, len + 1);
13070 + question_len = len;
13072 + len = vsnprintf(question,question_len,format,ap);
13073 + } while (len > question_len);
13074 + response = strdup(ipkg_cb_response(question));
13076 + str_chomp(response);
13077 + str_tolower(response);
13081 diff -ruN busybox-1.00-orig/archival/libipkg/user.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.h
13082 --- busybox-1.00-orig/archival/libipkg/user.h 1970-01-01 00:00:00.000000000 +0000
13083 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/user.h 2005-07-17 16:10:26.000000000 +0000
13085 +/* user.c - the itsy package management system
13089 + Copyright (C) 2002 Hewlett Packard Company
13090 + Copyright (C) 2001 University of Southern California
13092 + This program is free software; you can redistribute it and/or
13093 + modify it under the terms of the GNU General Public License as
13094 + published by the Free Software Foundation; either version 2, or (at
13095 + your option) any later version.
13097 + This program is distributed in the hope that it will be useful, but
13098 + WITHOUT ANY WARRANTY; without even the implied warranty of
13099 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13100 + General Public License for more details.
13103 +#include <stdio.h>
13104 +#include <stdarg.h>
13106 +char *get_user_response(const char *format, ...);
13108 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.c
13109 --- busybox-1.00-orig/archival/libipkg/void_list.c 1970-01-01 00:00:00.000000000 +0000
13110 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.c 2005-07-17 16:10:26.000000000 +0000
13112 +/* void_list.c - the itsy package management system
13116 + Copyright (C) 2001 University of Southern California
13118 + This program is free software; you can redistribute it and/or
13119 + modify it under the terms of the GNU General Public License as
13120 + published by the Free Software Foundation; either version 2, or (at
13121 + your option) any later version.
13123 + This program is distributed in the hope that it will be useful, but
13124 + WITHOUT ANY WARRANTY; without even the implied warranty of
13125 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13126 + General Public License for more details.
13130 +#include <errno.h>
13132 +#include "void_list.h"
13134 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13136 + elt->next = NULL;
13137 + elt->data = data;
13142 +void void_list_elt_deinit(void_list_elt_t *elt)
13144 + void_list_elt_init(elt, NULL);
13147 +int void_list_init(void_list_t *list)
13149 + void_list_elt_init(&list->pre_head, NULL);
13150 + list->head = NULL;
13151 + list->pre_head.next = list->head;
13152 + list->tail = NULL;
13157 +void void_list_deinit(void_list_t *list)
13159 + void_list_elt_t *elt;
13161 + while (list->head) {
13162 + elt = void_list_pop(list);
13163 + void_list_elt_deinit(elt);
13164 + /* malloced in void_list_append */
13169 +int void_list_append(void_list_t *list, void *data)
13171 + void_list_elt_t *elt;
13173 + /* freed in void_list_deinit */
13174 + elt = malloc(sizeof(void_list_elt_t));
13175 + if (elt == NULL) {
13176 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13180 + void_list_elt_init(elt, data);
13182 + if (list->tail) {
13183 + list->tail->next = elt;
13184 + list->tail = elt;
13186 + list->head = elt;
13187 + list->pre_head.next = list->head;
13188 + list->tail = elt;
13194 +int void_list_push(void_list_t *list, void *data)
13196 + void_list_elt_t *elt;
13198 + elt = malloc(sizeof(void_list_elt_t));
13199 + if (elt == NULL) {
13200 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13204 + void_list_elt_init(elt, data);
13206 + elt->next = list->head;
13207 + list->head->next = elt;
13208 + if (list->tail == NULL) {
13209 + list->tail = list->head;
13215 +void_list_elt_t *void_list_pop(void_list_t *list)
13217 + void_list_elt_t *elt;
13219 + elt = list->head;
13221 + if (list->head) {
13222 + list->head = list->head->next;
13223 + list->pre_head.next = list->head;
13224 + if (list->head == NULL) {
13225 + list->tail = NULL;
13232 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13234 + void_list_elt_t *prior;
13235 + void_list_elt_t *old_elt;
13239 + old_data = old_elt->data;
13241 + if (old_elt == list->head) {
13242 + prior = &list->pre_head;
13243 + void_list_pop(list);
13245 + for (prior = list->head; prior; prior = prior->next) {
13246 + if (prior->next == old_elt) {
13250 + if (prior == NULL || prior->next != old_elt) {
13251 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13254 + prior->next = old_elt->next;
13256 + if (old_elt == list->tail) {
13257 + list->tail = prior;
13261 + void_list_elt_deinit(old_elt);
13267 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13268 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13270 + void_list_elt_t *prior;
13271 + void_list_elt_t *old_elt = NULL;
13272 + void *old_data = NULL;
13274 + /* first element */
13275 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13276 + old_elt = list->head;
13277 + old_data = list->head->data;
13278 + void_list_pop(list);
13281 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13282 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13283 + old_elt = prior->next;
13284 + old_data = old_elt->data;
13292 + prior->next = old_elt->next;
13294 + if (old_elt == list->tail) {
13295 + list->tail = prior;
13299 + void_list_elt_deinit(old_elt);
13306 diff -ruN busybox-1.00-orig/archival/libipkg/void_list.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.h
13307 --- busybox-1.00-orig/archival/libipkg/void_list.h 1970-01-01 00:00:00.000000000 +0000
13308 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/void_list.h 2005-07-17 16:10:26.000000000 +0000
13310 +/* void_list.h - the itsy package management system
13314 + Copyright (C) 2001 University of Southern California
13316 + This program is free software; you can redistribute it and/or
13317 + modify it under the terms of the GNU General Public License as
13318 + published by the Free Software Foundation; either version 2, or (at
13319 + your option) any later version.
13321 + This program is distributed in the hope that it will be useful, but
13322 + WITHOUT ANY WARRANTY; without even the implied warranty of
13323 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13324 + General Public License for more details.
13327 +#ifndef VOID_LIST_H
13328 +#define VOID_LIST_H
13330 +typedef struct void_list_elt void_list_elt_t;
13331 +struct void_list_elt
13333 + void_list_elt_t *next;
13337 +typedef struct void_list void_list_t;
13340 + void_list_elt_t pre_head;
13341 + void_list_elt_t *head;
13342 + void_list_elt_t *tail;
13345 +static inline int void_list_empty(void_list_t *list)
13347 + if (list->head == NULL)
13353 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13354 +void void_list_elt_deinit(void_list_elt_t *elt);
13356 +int void_list_init(void_list_t *list);
13357 +void void_list_deinit(void_list_t *list);
13359 +int void_list_append(void_list_t *list, void *data);
13360 +int void_list_push(void_list_t *list, void *data);
13361 +void_list_elt_t *void_list_pop(void_list_t *list);
13363 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13364 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13365 +typedef int (*void_list_cmp_t)(const void *, const void *);
13366 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13369 diff -ruN busybox-1.00-orig/archival/libipkg/xregex.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xregex.h
13370 --- busybox-1.00-orig/archival/libipkg/xregex.h 1970-01-01 00:00:00.000000000 +0000
13371 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xregex.h 2005-07-20 17:28:42.773482376 +0000
13373 +/* xregex.h - regex functions with error messages
13377 + Copyright (C) 2001 University of Southern California
13379 + This program is free software; you can redistribute it and/or modify
13380 + it under the terms of the GNU General Public License as published by
13381 + the Free Software Foundation; either version 2, or (at your option)
13382 + any later version.
13384 + This program is distributed in the hope that it will be useful,
13385 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13386 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13387 + GNU General Public License for more details.
13393 +#include "libbb.h"
13395 +static inline void xregfree(regex_t *preg)
13402 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.c busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.c
13403 --- busybox-1.00-orig/archival/libipkg/xsystem.c 1970-01-01 00:00:00.000000000 +0000
13404 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.c 2005-07-17 16:10:26.000000000 +0000
13406 +/* xsystem.c - system(3) with error messages
13410 + Copyright (C) 2001 University of Southern California
13412 + This program is free software; you can redistribute it and/or
13413 + modify it under the terms of the GNU General Public License as
13414 + published by the Free Software Foundation; either version 2, or (at
13415 + your option) any later version.
13417 + This program is distributed in the hope that it will be useful, but
13418 + WITHOUT ANY WARRANTY; without even the implied warranty of
13419 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13420 + General Public License for more details.
13424 +#include <sys/wait.h>
13426 +#include "xsystem.h"
13428 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13429 + really need the /bin/sh invocation which takes resources and
13430 + introduces security problems. I should switch all of this to a sort
13431 + of execl() or execv() interface/implementation.
13434 +/* Like system(3), but with error messages printed if the fork fails
13435 + or if the child process dies due to an uncaught signal. Also, the
13436 + return value is a bit simpler:
13438 + -1 if there was any problem
13439 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13440 + as defined in <sys/wait.h>.
13442 +int xsystem(const char *cmd)
13446 + err = system(cmd);
13449 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13450 + __FUNCTION__, cmd);
13454 + if (WIFSIGNALED(err)) {
13455 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13456 + __FUNCTION__, WTERMSIG(err), cmd);
13460 + if (WIFEXITED(err)) {
13461 + /* Normal child exit */
13462 + return WEXITSTATUS(err);
13465 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13466 + __FUNCTION__, err);
13470 diff -ruN busybox-1.00-orig/archival/libipkg/xsystem.h busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.h
13471 --- busybox-1.00-orig/archival/libipkg/xsystem.h 1970-01-01 00:00:00.000000000 +0000
13472 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libipkg/xsystem.h 2005-07-17 16:10:26.000000000 +0000
13474 +/* xsystem.h - system(3) with error messages
13478 + Copyright (C) 2001 University of Southern California
13480 + This program is free software; you can redistribute it and/or
13481 + modify it under the terms of the GNU General Public License as
13482 + published by the Free Software Foundation; either version 2, or (at
13483 + your option) any later version.
13485 + This program is distributed in the hope that it will be useful, but
13486 + WITHOUT ANY WARRANTY; without even the implied warranty of
13487 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13488 + General Public License for more details.
13494 +#include <stdlib.h>
13496 +/* Like system(3), but with error messages printed if the fork fails
13497 + or if the child process dies due to an uncaught signal. Also, the
13498 + return value is a bit simpler:
13500 + -1 if there was any problem
13501 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13502 + as defined in <sys/wait.h>.
13504 +int xsystem(const char *cmd);
13508 diff -ruN busybox-1.00-orig/archival/libunarchive/data_extract_all.c busybox-1.00+ipkg-0.99.152-pre2/archival/libunarchive/data_extract_all.c
13509 --- busybox-1.00-orig/archival/libunarchive/data_extract_all.c 2004-10-13 06:25:51.000000000 +0000
13510 +++ busybox-1.00+ipkg-0.99.152-pre2/archival/libunarchive/data_extract_all.c 2005-07-20 00:02:41.000000000 +0000
13511 @@ -122,3 +122,17 @@
13512 utime(file_header->name, &t);
13516 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13518 + char *name_ptr = archive_handle->file_header->name;
13520 + name_ptr += strspn(name_ptr, "./");
13521 + if (name_ptr[0] != '\0') {
13522 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13523 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13524 + strcat(archive_handle->file_header->name, name_ptr);
13525 + data_extract_all(archive_handle);
13529 diff -ruN busybox-1.00-orig/include/applets.h busybox-1.00+ipkg-0.99.152-pre2/include/applets.h
13530 --- busybox-1.00-orig/include/applets.h 2005-07-20 13:09:57.000000000 +0000
13531 +++ busybox-1.00+ipkg-0.99.152-pre2/include/applets.h 2005-07-17 16:29:18.000000000 +0000
13532 @@ -298,6 +298,9 @@
13533 #ifdef CONFIG_IPCALC
13534 APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13536 +#ifdef CONFIG_IPKG
13537 + APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
13539 #ifdef CONFIG_IPLINK
13540 APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER)
13542 diff -ruN busybox-1.00-orig/include/libbb.h busybox-1.00+ipkg-0.99.152-pre2/include/libbb.h
13543 --- busybox-1.00-orig/include/libbb.h 2004-09-15 03:04:07.000000000 +0000
13544 +++ busybox-1.00+ipkg-0.99.152-pre2/include/libbb.h 2005-07-20 17:13:46.442745360 +0000
13545 @@ -484,4 +484,17 @@
13547 extern int hash_fd(int fd, const size_t size, const uint8_t hash_algo, uint8_t *hashval);
13549 +struct md5_ctx_t {
13554 + uint32_t total[2];
13556 + char buffer[128];
13558 +extern void md5_begin(struct md5_ctx_t *ctx);
13559 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx);
13560 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
13562 #endif /* __LIBCONFIG_H__ */
13563 diff -ruN busybox-1.00-orig/include/unarchive.h busybox-1.00+ipkg-0.99.152-pre2/include/unarchive.h
13564 --- busybox-1.00-orig/include/unarchive.h 2004-03-15 08:28:38.000000000 +0000
13565 +++ busybox-1.00+ipkg-0.99.152-pre2/include/unarchive.h 2005-07-19 16:40:11.000000000 +0000
13568 extern void data_skip(archive_handle_t *archive_handle);
13569 extern void data_extract_all(archive_handle_t *archive_handle);
13570 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13571 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13572 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13574 diff -ruN busybox-1.00-orig/include/usage.h busybox-1.00+ipkg-0.99.152-pre2/include/usage.h
13575 --- busybox-1.00-orig/include/usage.h 2005-07-20 13:09:58.000000000 +0000
13576 +++ busybox-1.00+ipkg-0.99.152-pre2/include/usage.h 2005-07-20 09:33:45.367746000 +0000
13577 @@ -836,6 +836,82 @@
13578 "$ ls -la /tmp/busybox*\n" \
13579 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13581 +#define ipkg_trivial_usage \
13582 + "[options...] sub-command [arguments...]"
13583 +#define ipkg_full_usage \
13584 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13586 + "Sub-commands:\n" \
13587 + "\nPackage Manipulation:\n" \
13588 + "\tupdate Update list of available packages\n" \
13589 + "\tupgrade Upgrade all installed packages to latest version\n" \
13590 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13591 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13592 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13593 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13594 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13595 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13597 + "Informational Commands:\n" \
13598 + "\tlist List available packages and descriptions\n" \
13599 + "\tlist_installed List all and only the installed packages and description \n" \
13600 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13601 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13602 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13603 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13604 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13605 + "\tcompare_versions <v1> <op> <v2>\n" \
13606 + "\t compare versions using <= < > >= = << >>\n" \
13607 + "\tprint_architecture prints the architecture.\n" \
13608 + "\tprint_installation_architecture\n" \
13609 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13610 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13611 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13612 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13613 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13614 + "\t prints the installation architecture.\n" \
13617 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13618 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13619 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13620 + "\t 0 errors only\n" \
13621 + "\t 1 normal messages (default)\n" \
13622 + "\t 2 informative messages\n" \
13623 + "\t 3 debug output\n" \
13624 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13625 + "\t-conf <conf_file> Default configuration file location\n" \
13626 + " is /etc/ipkg.conf\n" \
13627 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13628 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13629 + " <dest_name> should be a defined dest name from\n" \
13630 + " the configuration file, (but can also be a\n" \
13631 + " directory name in a pinch).\n" \
13632 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13633 + "\t-offline <offline_root> offline installation of packages.\n" \
13634 + "\t-verbose_wget more wget messages\n" \
13636 + "Force Options (use when ipkg is too smart for its own good):\n" \
13637 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13638 + "\t Install/remove package in spite of failed dependences\n" \
13639 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13640 + " (no prompts). Note that this will not prevent\n" \
13641 + " package installation scripts from prompting.\n" \
13642 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13643 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13644 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13645 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13646 + "\t-noaction No action -- test only\n" \
13647 + "\t-nodeps Do not follow dependences\n" \
13648 + "\t-force-removal-of-dependent-packages\n" \
13649 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13650 + "\t-test No action -- test only\n" \
13651 + "\t-t Specify tmp-dir.\n" \
13652 + "\t--tmp-dir Specify tmp-dir.\n" \
13654 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13655 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13657 #define halt_trivial_usage \
13659 #define halt_full_usage \
13660 diff -ruN busybox-1.00-orig/libbb/hash_fd.c busybox-1.00+ipkg-0.99.152-pre2/libbb/hash_fd.c
13661 --- busybox-1.00-orig/libbb/hash_fd.c 2004-03-15 08:28:42.000000000 +0000
13662 +++ busybox-1.00+ipkg-0.99.152-pre2/libbb/hash_fd.c 2005-07-20 17:13:48.129488936 +0000
13663 @@ -288,21 +288,10 @@
13664 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
13665 # endif /* MD5SUM_SIZE_VS_SPEED == 0 */
13667 -/* Structure to save state of computation between the single steps. */
13668 -struct md5_ctx_t {
13673 - uint32_t total[2];
13675 - char buffer[128];
13678 /* Initialize structure containing state of computation.
13679 * (RFC 1321, 3.3: Step 3)
13681 -static void md5_begin(struct md5_ctx_t *ctx)
13682 +extern void md5_begin(struct md5_ctx_t *ctx)
13684 ctx->A = 0x67452301;
13685 ctx->B = 0xefcdab89;
13686 @@ -706,7 +695,7 @@
13690 -static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13691 +extern void md5_hash(const void *buffer, size_t length, void *md5_ctx)
13693 if (length % 64 == 0) {
13694 md5_hash_block(buffer, length, md5_ctx);
13695 @@ -723,7 +712,7 @@
13696 * IMPORTANT: On some systems it is required that RESBUF is correctly
13697 * aligned for a 32 bits value.
13699 -static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13700 +extern void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
13702 /* Take yet unprocessed bytes into account. */
13703 uint32_t bytes = ctx->buflen;