2 # add ipkg support to busybox
4 diff -ruN busybox-1.1.2-orig/Makefile busybox-1.1.2+ipkg-0.99.162/Makefile
5 --- busybox-1.1.2-orig/Makefile 2006-04-10 21:45:46.000000000 +0200
6 +++ busybox-1.1.2+ipkg-0.99.162/Makefile 2006-05-09 02:06:48.000000000 +0200
8 export srctree=$(top_srcdir)
9 vpath %/Config.in $(srctree)
11 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
12 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
13 debianutils editors findutils init miscutils modutils networking \
14 networking/libiproute networking/udhcp procps loginutils shell \
15 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
16 diff -ruN busybox-1.1.2-orig/archival/Config.in busybox-1.1.2+ipkg-0.99.162/archival/Config.in
17 --- busybox-1.1.2-orig/archival/Config.in 2006-03-22 22:16:20.000000000 +0100
18 +++ busybox-1.1.2+ipkg-0.99.162/archival/Config.in 2006-05-09 02:06:48.000000000 +0200
20 gzip is used to compress files.
21 It's probably the most widely used UNIX compression program.
26 + select CONFIG_MD5SUM
29 + ipkg is the itsy package management system.
31 config CONFIG_RPM2CPIO
34 diff -ruN busybox-1.1.2-orig/archival/Makefile.in busybox-1.1.2+ipkg-0.99.162/archival/Makefile.in
35 --- busybox-1.1.2-orig/archival/Makefile.in 2006-03-22 22:16:20.000000000 +0100
36 +++ busybox-1.1.2+ipkg-0.99.162/archival/Makefile.in 2006-05-09 02:06:48.000000000 +0200
38 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
39 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
40 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
41 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
42 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
43 ARCHIVAL-$(CONFIG_RPM) += rpm.o
44 ARCHIVAL-$(CONFIG_TAR) += tar.o
45 diff -ruN busybox-1.1.2-orig/archival/dpkg.c busybox-1.1.2+ipkg-0.99.162/archival/dpkg.c
46 --- busybox-1.1.2-orig/archival/dpkg.c 2006-03-22 22:16:20.000000000 +0100
47 +++ busybox-1.1.2+ipkg-0.99.162/archival/dpkg.c 2006-05-09 02:06:48.000000000 +0200
48 @@ -1530,6 +1530,10 @@
49 return(ar_handle->sub_archive->buffer);
54 +// moved to data_extract_all.c
56 static void data_extract_all_prefix(archive_handle_t *archive_handle)
58 char *name_ptr = archive_handle->file_header->name;
65 static void unpack_package(deb_file_t *deb_file)
67 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
68 diff -ruN busybox-1.1.2-orig/archival/ipkg.c busybox-1.1.2+ipkg-0.99.162/archival/ipkg.c
69 --- busybox-1.1.2-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
70 +++ busybox-1.1.2+ipkg-0.99.162/archival/ipkg.c 2006-05-09 02:06:48.000000000 +0200
72 +/* ipkg.c - the itsy package management system
76 + Copyright (C) 2003 kernel concepts
78 + This program is free software; you can redistribute it and/or
79 + modify it under the terms of the GNU General Public License as
80 + published by the Free Software Foundation; either version 2, or (at
81 + your option) any later version.
83 + This program is distributed in the hope that it will be useful, but
84 + WITHOUT ANY WARRANTY; without even the implied warranty of
85 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
86 + General Public License for more details.
88 + ipkg command line frontend using libipkg
92 +#include "libipkg/libipkg.h"
94 +int ipkg_main(int argc, char **argv)
96 + return ipkg_op(argc, argv);
98 diff -ruN busybox-1.1.2-orig/archival/libipkg/Makefile busybox-1.1.2+ipkg-0.99.162/archival/libipkg/Makefile
99 --- busybox-1.1.2-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
100 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/Makefile 2006-05-09 02:06:48.000000000 +0200
102 +# Makefile for busybox
104 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
106 +# This program is free software; you can redistribute it and/or modify
107 +# it under the terms of the GNU General Public License as published by
108 +# the Free Software Foundation; either version 2 of the License, or
109 +# (at your option) any later version.
111 +# This program is distributed in the hope that it will be useful,
112 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
113 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
114 +# General Public License for more details.
116 +# You should have received a copy of the GNU General Public License
117 +# along with this program; if not, write to the Free Software
118 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
123 +srcdir=$(top_srcdir)/archival/libipkg
125 +include $(top_builddir)/Rules.mak
126 +include $(top_builddir)/.config
127 +include $(srcdir)/Makefile.in
129 +-include $(top_builddir)/.depend
132 + rm -f *.o *.a $(AR_TARGET)
134 diff -ruN busybox-1.1.2-orig/archival/libipkg/Makefile.in busybox-1.1.2+ipkg-0.99.162/archival/libipkg/Makefile.in
135 --- busybox-1.1.2-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
136 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/Makefile.in 2006-05-09 02:06:48.000000000 +0200
138 +# Makefile for busybox
140 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
142 +# This program is free software; you can redistribute it and/or modify
143 +# it under the terms of the GNU General Public License as published by
144 +# the Free Software Foundation; either version 2 of the License, or
145 +# (at your option) any later version.
147 +# This program is distributed in the hope that it will be useful,
148 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
149 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
150 +# General Public License for more details.
152 +# You should have received a copy of the GNU General Public License
153 +# along with this program; if not, write to the Free Software
154 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
157 +LIBIPKG_AR:=libipkg.a
158 +ifndef $(LIBIPKG_DIR)
159 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
161 +srcdir=$(top_srcdir)/archival/libipkg
163 +LIBIPKG_CORE_SOURCES:= \
168 +LIBIPKG_CMD_SOURCES:= \
176 +LIBIPKG_DB_SOURCES:= \
187 +LIBIPKG_LIST_SOURCES:= \
199 +LIBIPKG_UTIL_SOURCES:= \
206 +LIBIPKG-y += $(LIBIPKG_CORE_SOURCES)
207 +LIBIPKG-y += $(LIBIPKG_CMD_SOURCES)
208 +LIBIPKG-y += $(LIBIPKG_DB_SOURCES)
209 +LIBIPKG-y += $(LIBIPKG_LIST_SOURCES)
210 +LIBIPKG-y += $(LIBIPKG_UTIL_SOURCES)
211 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
213 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
215 +libraries-y += $(LIBIPKG_DIR)$(LIBIPKG_AR)
217 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
220 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
223 diff -ruN busybox-1.1.2-orig/archival/libipkg/args.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/args.c
224 --- busybox-1.1.2-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
225 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/args.c 2006-05-09 02:12:03.000000000 +0200
227 +/* args.c - parse command-line args
231 + Copyright 2001 University of Southern California
233 + This program is free software; you can redistribute it and/or modify
234 + it under the terms of the GNU General Public License as published by
235 + the Free Software Foundation; either version 2, or (at your option)
238 + This program is distributed in the hope that it will be useful,
239 + but WITHOUT ANY WARRANTY; without even the implied warranty of
240 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
241 + GNU General Public License for more details.
250 +#include "ipkg_message.h"
253 +#include "sprintf_alloc.h"
258 +static void print_version(void);
262 + ARGS_OPT_FORCE_DEFAULTS = 129,
263 + ARGS_OPT_FORCE_DEPENDS,
264 + ARGS_OPT_FORCE_OVERWRITE,
265 + ARGS_OPT_FORCE_DOWNGRADE,
266 + ARGS_OPT_FORCE_REINSTALL,
267 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
268 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
269 + ARGS_OPT_FORCE_SPACE,
272 + ARGS_OPT_VERBOSE_WGET,
273 + ARGS_OPT_VERBOSITY,
274 + ARGS_OPT_MULTIPLE_PROVIDERS
277 +int args_init(args_t *args)
279 + char *conf_file_dir;
281 + memset(args, 0, sizeof(args_t));
283 + args->dest = ARGS_DEFAULT_DEST;
285 + conf_file_dir = getenv("IPKG_CONF_DIR");
286 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
287 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
289 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
290 + ARGS_DEFAULT_CONF_FILE_NAME);
292 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
293 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
294 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
295 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
296 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
297 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
298 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
299 + args->noaction = ARGS_DEFAULT_NOACTION;
300 + args->nodeps = ARGS_DEFAULT_NODEPS;
301 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
302 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
303 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
304 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
305 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
306 + args->multiple_providers = 0;
307 + args->nocheckfordirorfile = 0;
308 + args->noreadfeedsfile = 0;
313 +void args_deinit(args_t *args)
315 + free(args->conf_file);
316 + args->conf_file = NULL;
319 +int args_parse(args_t *args, int argc, char *argv[])
322 + int option_index = 0;
324 + static struct option long_options[] = {
325 + {"query-all", 0, 0, 'A'},
326 + {"conf-file", 1, 0, 'f'},
327 + {"conf", 1, 0, 'f'},
328 + {"dest", 1, 0, 'd'},
329 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
330 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
331 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
332 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
333 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
334 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
335 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
336 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
337 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
338 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
339 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
340 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
341 + {"recursive", 0, 0,
342 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
343 + {"force-removal-of-dependent-packages", 0, 0,
344 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
345 + {"force_removal_of_dependent_packages", 0, 0,
346 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
347 + {"force-removal-of-essential-packages", 0, 0,
348 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
349 + {"force_removal_of_essential_packages", 0, 0,
350 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
351 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
352 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
353 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
354 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
355 + {"offline", 1, 0, 'o'},
356 + {"offline-root", 1, 0, 'o'},
357 + {"test", 0, 0, ARGS_OPT_NOACTION},
358 + {"tmp-dir", 1, 0, 't'},
359 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
360 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
361 + {"verbosity", 2, 0, 'V'},
362 + {"version", 0, 0, 'v'},
367 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
373 + args->query_all = 1;
376 + args->dest = optarg;
379 + free(args->conf_file);
380 + args->conf_file = strdup(optarg);
383 + args->offline_root = optarg;
386 + args->noaction = 1;
389 + args->tmp_dir = strdup(optarg);
395 + case ARGS_OPT_VERBOSITY:
397 + args->verbosity = atoi(optarg);
399 + args->verbosity += 1;
401 + case ARGS_OPT_FORCE_DEFAULTS:
402 + args->force_defaults = 1;
404 + case ARGS_OPT_FORCE_DEPENDS:
405 + args->force_depends = 1;
407 + case ARGS_OPT_FORCE_OVERWRITE:
408 + args->force_overwrite = 1;
410 + case ARGS_OPT_FORCE_DOWNGRADE:
411 + args->force_downgrade = 1;
413 + case ARGS_OPT_FORCE_REINSTALL:
414 + args->force_reinstall = 1;
416 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
417 + args->force_removal_of_essential_packages = 1;
419 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
420 + args->force_removal_of_dependent_packages = 1;
422 + case ARGS_OPT_FORCE_SPACE:
423 + args->force_space = 1;
425 + case ARGS_OPT_VERBOSE_WGET:
426 + args->verbose_wget = 1;
428 + case ARGS_OPT_MULTIPLE_PROVIDERS:
429 + args->multiple_providers = 1;
431 + case ARGS_OPT_NODEPS:
434 + case ARGS_OPT_NOACTION:
435 + args->noaction = 1;
444 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
455 +void args_usage(char *complaint)
458 + bb_error_msg("%s\n", complaint);
465 +static void print_version(void)
467 + bb_error_msg("version %s\n", IPKG_VERSION);
469 diff -ruN busybox-1.1.2-orig/archival/libipkg/args.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/args.h
470 --- busybox-1.1.2-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
471 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/args.h 2006-05-09 02:12:03.000000000 +0200
473 +/* args.h - parse command-line args
477 + Copyright 2001 University of Southern California
479 + This program is free software; you can redistribute it and/or modify
480 + it under the terms of the GNU General Public License as published by
481 + the Free Software Foundation; either version 2, or (at your option)
484 + This program is distributed in the hope that it will be useful,
485 + but WITHOUT ANY WARRANTY; without even the implied warranty of
486 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
487 + GNU General Public License for more details.
498 + int force_defaults;
500 + int force_overwrite;
501 + int force_downgrade;
502 + int force_reinstall;
503 + int force_removal_of_essential_packages;
504 + int force_removal_of_dependent_packages;
508 + int multiple_providers;
512 + int nocheckfordirorfile;
513 + int noreadfeedsfile;
514 + char *offline_root;
515 + char *offline_root_pre_script_cmd;
516 + char *offline_root_post_script_cmd;
518 +typedef struct args args_t;
520 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
521 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
522 +#define ARGS_DEFAULT_DEST NULL
523 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
524 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
525 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
526 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
527 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
528 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
529 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
530 +#define ARGS_DEFAULT_FORCE_SPACE 0
531 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
532 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
533 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
534 +#define ARGS_DEFAULT_NOACTION 0
535 +#define ARGS_DEFAULT_NODEPS 0
536 +#define ARGS_DEFAULT_VERBOSE_WGET 0
537 +#define ARGS_DEFAULT_VERBOSITY 1
539 +int args_init(args_t *args);
540 +void args_deinit(args_t *args);
541 +int args_parse(args_t *args, int argc, char *argv[]);
542 +void args_usage(char *complaint);
545 diff -ruN busybox-1.1.2-orig/archival/libipkg/conffile.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile.c
546 --- busybox-1.1.2-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
547 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile.c 2006-05-09 02:06:48.000000000 +0200
549 +/* conffile.c - the itsy package management system
553 + Copyright (C) 2001 University of Southern California
555 + This program is free software; you can redistribute it and/or
556 + modify it under the terms of the GNU General Public License as
557 + published by the Free Software Foundation; either version 2, or (at
558 + your option) any later version.
560 + This program is distributed in the hope that it will be useful, but
561 + WITHOUT ANY WARRANTY; without even the implied warranty of
562 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
563 + General Public License for more details.
570 +#include "ipkg_message.h"
572 +#include "conffile.h"
573 +#include "file_util.h"
574 +#include "sprintf_alloc.h"
576 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
578 + return nv_pair_init(conffile, file_name, md5sum);
581 +void conffile_deinit(conffile_t *conffile)
583 + nv_pair_deinit(conffile);
586 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
589 + char *filename = conffile->name;
590 + char *root_filename;
593 + if (conffile->value == NULL) {
594 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
598 + root_filename = root_filename_alloc(conf, filename);
600 + md5sum = file_md5sum_alloc(root_filename);
602 + ret = strcmp(md5sum, conffile->value);
604 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
605 + conffile->name, md5sum, conffile->value);
608 + free(root_filename);
613 diff -ruN busybox-1.1.2-orig/archival/libipkg/conffile.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile.h
614 --- busybox-1.1.2-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
615 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile.h 2006-05-09 02:06:48.000000000 +0200
617 +/* conffile.h - the itsy package management system
621 + Copyright (C) 2001 University of Southern California
623 + This program is free software; you can redistribute it and/or
624 + modify it under the terms of the GNU General Public License as
625 + published by the Free Software Foundation; either version 2, or (at
626 + your option) any later version.
628 + This program is distributed in the hope that it will be useful, but
629 + WITHOUT ANY WARRANTY; without even the implied warranty of
630 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
631 + General Public License for more details.
637 +#include "nv_pair.h"
639 +typedef struct nv_pair conffile_t;
641 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
642 +void conffile_deinit(conffile_t *conffile);
643 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
647 diff -ruN busybox-1.1.2-orig/archival/libipkg/conffile_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile_list.c
648 --- busybox-1.1.2-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
649 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile_list.c 2006-05-09 02:06:48.000000000 +0200
651 +/* conffile_list.c - the itsy package management system
655 + Copyright (C) 2001 University of Southern California
657 + This program is free software; you can redistribute it and/or
658 + modify it under the terms of the GNU General Public License as
659 + published by the Free Software Foundation; either version 2, or (at
660 + your option) any later version.
662 + This program is distributed in the hope that it will be useful, but
663 + WITHOUT ANY WARRANTY; without even the implied warranty of
664 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
665 + General Public License for more details.
670 +#include "conffile_list.h"
672 +int conffile_list_init(conffile_list_t *list)
674 + return nv_pair_list_init(list);
677 +void conffile_list_deinit(conffile_list_t *list)
679 + nv_pair_list_deinit(list);
682 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
683 + const char *md5sum)
685 + return nv_pair_list_append(list, file_name, md5sum);
688 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
690 + return nv_pair_list_push(list, data);
693 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
695 + return nv_pair_list_pop(list);
698 diff -ruN busybox-1.1.2-orig/archival/libipkg/conffile_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile_list.h
699 --- busybox-1.1.2-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
700 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/conffile_list.h 2006-05-09 02:06:48.000000000 +0200
702 +/* conffile_list.h - the itsy package management system
706 + Copyright (C) 2001 University of Southern California
708 + This program is free software; you can redistribute it and/or
709 + modify it under the terms of the GNU General Public License as
710 + published by the Free Software Foundation; either version 2, or (at
711 + your option) any later version.
713 + This program is distributed in the hope that it will be useful, but
714 + WITHOUT ANY WARRANTY; without even the implied warranty of
715 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
716 + General Public License for more details.
719 +#ifndef CONFFILE_LIST_H
720 +#define CONFFILE_LIST_H
722 +#include "conffile.h"
723 +#include "nv_pair_list.h"
725 +typedef struct nv_pair_list_elt conffile_list_elt_t;
726 +typedef struct nv_pair_list conffile_list_t;
728 +int conffile_list_init(conffile_list_t *list);
729 +void conffile_list_deinit(conffile_list_t *list);
731 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
732 + const char *root_dir);
733 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
734 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
738 diff -ruN busybox-1.1.2-orig/archival/libipkg/file_util.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/file_util.c
739 --- busybox-1.1.2-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
740 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/file_util.c 2006-05-09 02:06:48.000000000 +0200
742 +/* file_util.c - convenience routines for common stat operations
746 + Copyright (C) 2001 University of Southern California
748 + This program is free software; you can redistribute it and/or
749 + modify it under the terms of the GNU General Public License as
750 + published by the Free Software Foundation; either version 2, or (at
751 + your option) any later version.
753 + This program is distributed in the hope that it will be useful, but
754 + WITHOUT ANY WARRANTY; without even the implied warranty of
755 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
756 + General Public License for more details.
760 +#include <sys/types.h>
761 +#include <sys/stat.h>
763 +#include "sprintf_alloc.h"
764 +#include "file_util.h"
769 +int file_exists(const char *file_name)
772 + struct stat stat_buf;
774 + err = stat(file_name, &stat_buf);
782 +int file_is_dir(const char *file_name)
785 + struct stat stat_buf;
787 + err = stat(file_name, &stat_buf);
792 + return S_ISDIR(stat_buf.st_mode);
795 +/* read a single line from a file, stopping at a newline or EOF.
796 + If a newline is read, it will appear in the resulting string.
797 + Return value is a malloc'ed char * which should be freed at
798 + some point by the caller.
800 + Return value is NULL if the file is at EOF when called.
802 +#define FILE_READ_LINE_BUF_SIZE 1024
803 +char *file_read_line_alloc(FILE *file)
805 + char buf[FILE_READ_LINE_BUF_SIZE];
810 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
811 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
812 + buf_len = strlen(buf);
814 + line_size += buf_len;
815 + line = realloc(line, line_size);
816 + if (line == NULL) {
817 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
822 + line_size = buf_len + 1;
823 + line = strdup(buf);
825 + if (buf[buf_len - 1] == '\n') {
833 +int file_move(const char *src, const char *dest)
837 + err = rename(src, dest);
839 + if (err && errno == EXDEV) {
840 + err = file_copy(src, dest);
843 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
844 + __FUNCTION__, src, dest, strerror(errno));
850 +/* I put these here to keep libbb dependencies from creeping all over
852 +int file_copy(const char *src, const char *dest)
856 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
858 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
859 + __FUNCTION__, src, dest);
865 +int file_mkdir_hier(const char *path, long mode)
867 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
870 +char *file_md5sum_alloc(const char *file_name)
872 + static const int md5sum_bin_len = 16;
873 + static const int md5sum_hex_len = 32;
875 + static const unsigned char bin2hex[16] = {
876 + '0', '1', '2', '3',
877 + '4', '5', '6', '7',
878 + '8', '9', 'a', 'b',
884 + unsigned char *md5sum_hex;
885 + unsigned char md5sum_bin[md5sum_bin_len];
887 + md5sum_hex = malloc(md5sum_hex_len + 1);
888 + if (md5sum_hex == NULL) {
889 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
893 + file = fopen(file_name, "r");
894 + if (file == NULL) {
895 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
896 + __FUNCTION__, file_name, strerror(errno));
900 + err = md5_stream(file, md5sum_bin);
902 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
903 + __FUNCTION__, file_name, strerror(err));
909 + for (i=0; i < md5sum_bin_len; i++) {
910 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
911 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
914 + md5sum_hex[md5sum_hex_len] = '\0';
919 diff -ruN busybox-1.1.2-orig/archival/libipkg/file_util.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/file_util.h
920 --- busybox-1.1.2-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
921 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/file_util.h 2006-05-09 02:06:48.000000000 +0200
923 +/* file_util.h - convenience routines for common file operations
927 + Copyright (C) 2001 University of Southern California
929 + This program is free software; you can redistribute it and/or
930 + modify it under the terms of the GNU General Public License as
931 + published by the Free Software Foundation; either version 2, or (at
932 + your option) any later version.
934 + This program is distributed in the hope that it will be useful, but
935 + WITHOUT ANY WARRANTY; without even the implied warranty of
936 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
937 + General Public License for more details.
943 +int file_exists(const char *file_name);
944 +int file_is_dir(const char *file_name);
945 +char *file_read_line_alloc(FILE *file);
946 +int file_move(const char *src, const char *dest);
947 +int file_copy(const char *src, const char *dest);
948 +int file_mkdir_hier(const char *path, long mode);
949 +char *file_md5sum_alloc(const char *file_name);
952 diff -ruN busybox-1.1.2-orig/archival/libipkg/hash_table.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/hash_table.c
953 --- busybox-1.1.2-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
954 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/hash_table.c 2006-05-09 02:06:48.000000000 +0200
956 +/* hash.c - hash tables for ipkg
958 + Steven M. Ayer, Jamey Hicks
960 + Copyright (C) 2002 Compaq Computer Corporation
962 + This program is free software; you can redistribute it and/or
963 + modify it under the terms of the GNU General Public License as
964 + published by the Free Software Foundation; either version 2, or (at
965 + your option) any later version.
967 + This program is distributed in the hope that it will be useful, but
968 + WITHOUT ANY WARRANTY; without even the implied warranty of
969 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
970 + General Public License for more details.
977 +#include "hash_table.h"
978 +#include "ipkg_message.h"
981 +static int hash_index(hash_table_t *hash, const char *pkg_name);
982 +static int rotating(const char *key, int len, int prime);
984 +static int hash_index(hash_table_t *hash, const char *pkg_name)
986 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
989 +static int rotating(const char *key, int len, int prime)
991 + unsigned int hash, i;
992 + for (hash=len, i=0; i<len; ++i)
993 + hash = (hash<<4)^(hash>>28)^key[i];
994 + return (hash % prime);
999 + * this is an open table keyed by strings
1001 +int hash_table_init(const char *name, hash_table_t *hash, int len)
1003 + static int primes_table[] = {
1004 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
1005 + 19471, 23143, 33961, 46499, 49727, 99529, 0
1009 + if (hash->entries != NULL) {
1010 + /* we have been here already */
1014 + hash->name = name;
1015 + hash->entries = NULL;
1016 + hash->n_entries = 0;
1017 + hash->hash_entry_key = NULL;
1019 + picker = primes_table;
1020 + while(*picker && (*picker++ < len));
1022 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
1025 + hash->n_entries = *picker;
1026 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
1027 + if (hash->entries == NULL) {
1028 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
1034 +void hash_table_deinit(hash_table_t *hash)
1036 + free(hash->entries);
1037 + hash->entries = NULL;
1038 + hash->n_entries = 0;
1041 +void *hash_table_get(hash_table_t *hash, const char *key)
1043 + int ndx= hash_index(hash, key);
1044 + hash_entry_t *hash_entry = hash->entries + ndx;
1045 + while (hash_entry)
1047 + if (hash_entry->key)
1049 + if (strcmp(key, hash_entry->key) == 0) {
1050 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
1051 + return hash_entry->data;
1054 + hash_entry = hash_entry->next;
1059 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
1061 + int ndx= hash_index(hash, key);
1062 + hash_entry_t *hash_entry = hash->entries + ndx;
1063 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
1064 + if (hash_entry->key) {
1065 + if (strcmp(hash_entry->key, key) == 0) {
1066 + /* alread in table, update the value */
1067 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
1068 + hash_entry->data = value;
1072 + * if this is a collision, we have to go to the end of the ll,
1073 + * then add a new entry
1074 + * before we can hook up the value
1076 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
1077 + while (hash_entry->next)
1078 + hash_entry = hash_entry->next;
1079 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
1080 + if (!hash_entry->next) {
1083 + hash_entry = hash_entry->next;
1084 + hash_entry->next = NULL;
1087 + hash->n_elements++;
1088 + hash_entry->key = strdup(key);
1089 + hash_entry->data = value;
1095 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
1101 + for (i = 0; i < hash->n_entries; i++) {
1102 + hash_entry_t *hash_entry = (hash->entries + i);
1104 + if(hash_entry->key) {
1105 + f(hash_entry->key, hash_entry->data, data);
1107 + } while((hash_entry = hash_entry->next));
1111 diff -ruN busybox-1.1.2-orig/archival/libipkg/hash_table.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/hash_table.h
1112 --- busybox-1.1.2-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
1113 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/hash_table.h 2006-05-09 02:06:48.000000000 +0200
1115 +/* hash.h - hash tables for ipkg
1117 + Steven M. Ayer, Jamey Hicks
1119 + Copyright (C) 2002 Compaq Computer Corporation
1121 + This program is free software; you can redistribute it and/or
1122 + modify it under the terms of the GNU General Public License as
1123 + published by the Free Software Foundation; either version 2, or (at
1124 + your option) any later version.
1126 + This program is distributed in the hope that it will be useful, but
1127 + WITHOUT ANY WARRANTY; without even the implied warranty of
1128 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1129 + General Public License for more details.
1132 +#ifndef _HASH_TABLE_H_
1133 +#define _HASH_TABLE_H_
1135 +typedef struct hash_entry hash_entry_t;
1136 +typedef struct hash_table hash_table_t;
1138 +struct hash_entry {
1141 + struct hash_entry * next;
1144 +struct hash_table {
1146 + hash_entry_t * entries;
1147 + int n_entries; /* number of buckets */
1149 + const char * (*hash_entry_key)(void * data);
1152 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1153 +void hash_table_deinit(hash_table_t *hash);
1154 +void *hash_table_get(hash_table_t *hash, const char *key);
1155 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1156 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1158 +#endif /* _HASH_TABLE_H_ */
1159 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg.h
1160 --- busybox-1.1.2-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
1161 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg.h 2006-05-09 02:06:48.000000000 +0200
1163 +/* ipkg.h - the itsy package management system
1167 + Copyright (C) 2001 University of Southern California
1169 + This program is free software; you can redistribute it and/or
1170 + modify it under the terms of the GNU General Public License as
1171 + published by the Free Software Foundation; either version 2, or (at
1172 + your option) any later version.
1174 + This program is distributed in the hope that it will be useful, but
1175 + WITHOUT ANY WARRANTY; without even the implied warranty of
1176 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1177 + General Public License for more details.
1184 +#ifdef HAVE_CONFIG_H
1185 +#include "config.h"
1190 +#define IPKG_DEBUG_NO_TMP_CLEANUP
1193 +#include "ipkg_includes.h"
1194 +#include "ipkg_conf.h"
1195 +#include "ipkg_message.h"
1197 +#define IPKG_PKG_EXTENSION ".ipk"
1198 +#define DPKG_PKG_EXTENSION ".deb"
1200 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
1201 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
1203 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
1204 +#define IPKG_LISTS_DIR_SUFFIX "lists"
1205 +#define IPKG_INFO_DIR_SUFFIX "info"
1206 +#define IPKG_STATUS_FILE_SUFFIX "status"
1208 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
1210 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
1212 +#define IPKG_VERSION "0.99.162"
1217 + IPKG_PKG_DEPS_UNSATISFIED,
1218 + IPKG_PKG_IS_ESSENTIAL,
1219 + IPKG_PKG_HAS_DEPENDENTS,
1220 + IPKG_PKG_HAS_NO_CANDIDATE
1222 +typedef enum ipkg_error ipkg_error_t;
1224 +extern int ipkg_state_changed;
1229 + struct errlist * next;
1232 +extern struct errlist* error_list;
1234 +extern ipkg_conf_t *global_conf;
1237 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_cmd.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c
1238 --- busybox-1.1.2-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1239 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c 2006-05-09 02:23:37.000000000 +0200
1241 +/* ipkg_cmd.c - the itsy package management system
1245 + Copyright (C) 2001 University of Southern California
1247 + This program is free software; you can redistribute it and/or
1248 + modify it under the terms of the GNU General Public License as
1249 + published by the Free Software Foundation; either version 2, or (at
1250 + your option) any later version.
1252 + This program is distributed in the hope that it will be useful, but
1253 + WITHOUT ANY WARRANTY; without even the implied warranty of
1254 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1255 + General Public License for more details.
1258 +#include <string.h>
1261 +#include <libgen.h>
1264 +#include <stdlib.h>
1265 +#include <unistd.h>
1266 +#include <signal.h>
1268 +#include <dirent.h>
1270 +#include "ipkg_conf.h"
1271 +#include "ipkg_cmd.h"
1272 +#include "ipkg_message.h"
1274 +#include "pkg_dest.h"
1275 +#include "pkg_parse.h"
1276 +#include "sprintf_alloc.h"
1278 +#include "file_util.h"
1279 +#include "str_util.h"
1281 +#include "unarchive.h"
1283 +#include <fnmatch.h>
1286 +#include "ipkg_download.h"
1287 +#include "ipkg_install.h"
1288 +#include "ipkg_upgrade.h"
1289 +#include "ipkg_remove.h"
1290 +#include "ipkg_configure.h"
1291 +#include "ipkg_message.h"
1294 +#include "libipkg.h"
1295 +static void *p_userdata = NULL;
1298 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1299 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1300 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1301 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1302 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1303 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1304 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1305 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1306 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1307 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1308 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1309 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1310 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1311 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1312 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1313 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1314 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1315 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1316 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1317 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1318 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1319 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1320 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1321 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1322 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1324 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1325 + array for easier maintenance */
1326 +static ipkg_cmd_t cmds[] = {
1327 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1328 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1329 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1330 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1331 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1332 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1333 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1334 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1335 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1336 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1337 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1338 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1339 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1340 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1341 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1342 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1343 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1344 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1345 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1346 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1347 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1348 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1349 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1350 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1351 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1352 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1353 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1354 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1355 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1358 +int ipkg_state_changed;
1359 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1361 + if (ipkg_state_changed && !conf->noaction) {
1362 + ipkg_message(conf, IPKG_INFO,
1363 + " writing status file\n");
1364 + ipkg_conf_write_status_files(conf);
1365 + pkg_write_changed_filelists(conf);
1367 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1372 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1374 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1379 + for (i=0; i < num_cmds; i++) {
1381 + if (strcmp(name, cmd->name) == 0) {
1390 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1393 + p_userdata = userdata;
1396 + result = (cmd->fun)(conf, argc, argv);
1397 + if ( result == 0 ) {
1398 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1400 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1403 + if ( error_list ) {
1404 + reverse_error_list(&error_list);
1406 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1407 + /* Here we print the errors collected and free the list */
1408 + while (error_list != NULL) {
1409 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1410 + error_list = error_list->next;
1413 + free_error_list(&error_list);
1417 + p_userdata = NULL;
1421 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1423 + return (cmd->fun)(conf, argc, argv);
1427 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1432 + pkg_src_list_elt_t *iter;
1436 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1438 + if (! file_is_dir(lists_dir)) {
1439 + if (file_exists(lists_dir)) {
1440 + ipkg_message(conf, IPKG_ERROR,
1441 + "%s: ERROR: %s exists, but is not a directory\n",
1442 + __FUNCTION__, lists_dir);
1446 + err = file_mkdir_hier(lists_dir, 0755);
1448 + ipkg_message(conf, IPKG_ERROR,
1449 + "%s: ERROR: failed to make directory %s: %s\n",
1450 + __FUNCTION__, lists_dir, strerror(errno));
1457 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1458 + char *url, *list_file_name;
1462 + if (src->extra_data) /* debian style? */
1463 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1464 + src->gzip ? "Packages.gz" : "Packages");
1466 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1468 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1471 + char *tmp_file_name;
1474 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1476 + if (mkdtemp (tmp) == NULL) {
1477 + perror ("mkdtemp");
1482 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1483 + err = ipkg_download(conf, url, tmp_file_name);
1485 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1486 + in = fopen (tmp_file_name, "r");
1487 + out = fopen (list_file_name, "w");
1489 + inflate_unzip (in, out);
1496 + unlink (tmp_file_name);
1501 + err = ipkg_download(conf, url, list_file_name);
1505 + ipkg_message(conf, IPKG_NOTICE,
1506 + "Updated list of available packages in %s\n",
1510 + free(list_file_name);
1514 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1516 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1517 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1523 + pkg_vec_t *available = pkg_vec_alloc();
1524 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1525 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1526 + for (i = 0; i < available->len; i++) {
1527 + pkg_t *pkg = available->pkgs[i];
1528 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1529 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1530 + pkg->state_want = SW_UNKNOWN;
1534 + pkg_vec_free(available);
1536 + write_status_files_if_changed(conf);
1545 +/* scan the args passed and cache the local filenames of the packages */
1546 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1552 + * First scan through package names/urls
1553 + * For any urls, download the packages and install in database.
1554 + * For any files, install package info in database.
1556 + for (i = 0; i < argc; i ++) {
1557 + char *filename = argv [i];
1558 + //char *tmp = basename (tmp);
1559 + //int tmplen = strlen (tmp);
1561 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1563 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1566 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1568 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1575 +struct ipkg_intercept
1581 +typedef struct ipkg_intercept *ipkg_intercept_t;
1583 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1585 + ipkg_intercept_t ctx;
1589 + ctx = malloc (sizeof (*ctx));
1590 + ctx->oldpath = strdup (getenv ("PATH"));
1592 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1593 + setenv ("PATH", newpath, 1);
1598 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1599 + if (mkdir (ctx->statedir, 0770) < 0) {
1600 + if (errno == EEXIST) {
1601 + free (ctx->statedir);
1605 + perror (ctx->statedir);
1608 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1612 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1618 + setenv ("PATH", ctx->oldpath, 1);
1619 + free (ctx->oldpath);
1621 + dir = opendir (ctx->statedir);
1623 + struct dirent *de;
1624 + while (de = readdir (dir), de != NULL) {
1627 + if (de->d_name[0] == '.')
1630 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1631 + if (access (path, X_OK) == 0) {
1632 + if (system (path)) {
1634 + perror (de->d_name);
1640 + perror (ctx->statedir);
1642 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1646 + free (ctx->statedir);
1652 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1657 + ipkg_intercept_t ic;
1660 + ipkg_message(conf, IPKG_INFO,
1661 + "Configuring unpacked packages\n");
1664 + all = pkg_vec_alloc();
1665 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1667 + ic = ipkg_prep_intercepts (conf);
1669 + for(i = 0; i < all->len; i++) {
1670 + pkg = all->pkgs[i];
1672 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1675 + if (pkg->state_status == SS_UNPACKED) {
1676 + ipkg_message(conf, IPKG_NOTICE,
1677 + "Configuring %s\n", pkg->name);
1679 + r = ipkg_configure(conf, pkg);
1681 + pkg->state_status = SS_INSTALLED;
1682 + pkg->parent->state_status = SS_INSTALLED;
1683 + pkg->state_flag &= ~SF_PREFER;
1691 + r = ipkg_finalize_intercepts (ic);
1695 + pkg_vec_free(all);
1699 +static void sigint_handler(int sig)
1701 + signal(sig, SIG_DFL);
1702 + ipkg_message(NULL, IPKG_NOTICE,
1703 + "ipkg: interrupted. writing out status database\n");
1704 + write_status_files_if_changed(global_conf);
1708 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1714 + global_conf = conf;
1715 + signal(SIGINT, sigint_handler);
1718 + * Now scan through package names and install
1720 + for (i=0; i < argc; i++) {
1723 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1724 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1725 + if (err != EINVAL && err != 0)
1728 + pkg_info_preinstall_check(conf);
1730 + for (i=0; i < argc; i++) {
1732 + if (conf->multiple_providers)
1733 + err = ipkg_install_multi_by_name(conf, arg);
1735 + err = ipkg_install_by_name(conf, arg);
1737 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1738 + ipkg_message(conf, IPKG_ERROR,
1739 + "Cannot find package %s.\n"
1740 + "Check the spelling or perhaps run 'ipkg update'\n",
1745 + /* recheck to verify that all dependences are satisfied */
1746 + if (0) ipkg_satisfy_all_dependences(conf);
1748 + ipkg_configure_packages(conf, NULL);
1750 + write_status_files_if_changed(conf);
1755 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1761 + global_conf = conf;
1762 + signal(SIGINT, sigint_handler);
1765 + for (i=0; i < argc; i++) {
1766 + char *arg = argv[i];
1768 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1769 + if (err != EINVAL && err != 0)
1772 + pkg_info_preinstall_check(conf);
1774 + for (i=0; i < argc; i++) {
1775 + char *arg = argv[i];
1776 + if (conf->restrict_to_default_dest) {
1777 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1779 + conf->default_dest);
1780 + if (pkg == NULL) {
1781 + ipkg_message(conf, IPKG_NOTICE,
1782 + "Package %s not installed in %s\n",
1783 + argv[i], conf->default_dest->name);
1787 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1791 + ipkg_upgrade_pkg(conf, pkg);
1793 + ipkg_install_by_name(conf, arg);
1797 + pkg_vec_t *installed = pkg_vec_alloc();
1799 + pkg_info_preinstall_check(conf);
1801 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1802 + for (i = 0; i < installed->len; i++) {
1803 + pkg = installed->pkgs[i];
1804 + ipkg_upgrade_pkg(conf, pkg);
1806 + pkg_vec_free(installed);
1809 + /* recheck to verify that all dependences are satisfied */
1810 + if (0) ipkg_satisfy_all_dependences(conf);
1812 + ipkg_configure_packages(conf, NULL);
1814 + write_status_files_if_changed(conf);
1819 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1825 + pkg_info_preinstall_check(conf);
1826 + for (i = 0; i < argc; i++) {
1829 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1830 + if (pkg == NULL) {
1831 + ipkg_message(conf, IPKG_ERROR,
1832 + "Cannot find package %s.\n"
1833 + "Check the spelling or perhaps run 'ipkg update'\n",
1838 + err = ipkg_download_pkg(conf, pkg, ".");
1841 + ipkg_message(conf, IPKG_ERROR,
1842 + "Failed to download %s\n", pkg->name);
1844 + ipkg_message(conf, IPKG_NOTICE,
1845 + "Downloaded %s as %s\n",
1846 + pkg->name, pkg->local_filename);
1854 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1857 + pkg_vec_t *available;
1859 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1861 + char *pkg_name = NULL;
1862 + char *version_str;
1865 + pkg_name = argv[0];
1867 + available = pkg_vec_alloc();
1868 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1869 + for (i=0; i < available->len; i++) {
1870 + pkg = available->pkgs[i];
1871 + /* if we have package name or pattern and pkg does not match, then skip it */
1872 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1874 + if (pkg->description) {
1875 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1877 + desc_short[0] = '\0';
1879 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1880 + newline = strchr(desc_short, '\n');
1885 + printf("%s - %s\n", pkg->name, desc_short);
1887 + if (ipkg_cb_list) {
1888 + version_str = pkg_version_str_alloc(pkg);
1889 + ipkg_cb_list(pkg->name,desc_short,
1891 + pkg->state_status,
1893 + free(version_str);
1897 + pkg_vec_free(available);
1903 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1906 + pkg_vec_t *available;
1908 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1910 + char *pkg_name = NULL;
1911 + char *version_str;
1914 + pkg_name = argv[0];
1916 + available = pkg_vec_alloc();
1917 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1918 + for (i=0; i < available->len; i++) {
1919 + pkg = available->pkgs[i];
1920 + /* if we have package name or pattern and pkg does not match, then skip it */
1921 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1923 + if (pkg->description) {
1924 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1926 + desc_short[0] = '\0';
1928 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1929 + newline = strchr(desc_short, '\n');
1934 + printf("%s - %s\n", pkg->name, desc_short);
1936 + if (ipkg_cb_list) {
1937 + version_str = pkg_version_str_alloc(pkg);
1938 + ipkg_cb_list(pkg->name,desc_short,
1940 + pkg->state_status,
1942 + free(version_str);
1950 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1953 + pkg_vec_t *available;
1955 + char *pkg_name = NULL;
1956 + char **pkg_fields = NULL;
1958 + char *buff ; // = (char *)malloc(1);
1961 + pkg_name = argv[0];
1964 + pkg_fields = &argv[1];
1965 + n_fields = argc - 1;
1968 + available = pkg_vec_alloc();
1969 + if (installed_only)
1970 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1972 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1973 + for (i=0; i < available->len; i++) {
1974 + pkg = available->pkgs[i];
1975 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1980 + for (j = 0; j < n_fields; j++)
1981 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1983 + pkg_print_info(pkg, stdout);
1987 + buff = pkg_formatted_info(pkg);
1989 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1990 + pkg->state_status,
1994 + We should not forget that actually the pointer is allocated.
1995 + We need to free it :) ( Thanks florian for seeing the error )
2000 + if (conf->verbosity > 1) {
2001 + conffile_list_elt_t *iter;
2002 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
2003 + conffile_t *cf = iter->data;
2004 + int modified = conffile_has_been_modified(conf, cf);
2005 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
2006 + cf->name, cf->value, modified);
2014 + pkg_vec_free(available);
2019 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
2021 + return ipkg_info_status_cmd(conf, argc, argv, 0);
2024 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
2026 + return ipkg_info_status_cmd(conf, argc, argv, 1);
2029 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
2034 + char *pkg_name = NULL;
2036 + pkg_name = argv[0];
2038 + err = ipkg_configure_packages (conf, pkg_name);
2041 + err = ipkg_configure_packages (conf, NULL);
2044 + write_status_files_if_changed(conf);
2049 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
2052 + char *globpattern;
2055 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
2056 + err = glob(globpattern, 0, NULL, &globbuf);
2057 + free(globpattern);
2062 + ipkg_message(conf, IPKG_NOTICE,
2063 + "The following packages in %s will now be installed.\n",
2064 + conf->pending_dir);
2065 + for (i = 0; i < globbuf.gl_pathc; i++) {
2066 + ipkg_message(conf, IPKG_NOTICE,
2067 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
2069 + ipkg_message(conf, IPKG_NOTICE, "\n");
2070 + for (i = 0; i < globbuf.gl_pathc; i++) {
2071 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
2073 + err = unlink(globbuf.gl_pathv[i]);
2075 + ipkg_message(conf, IPKG_ERROR,
2076 + "%s: ERROR: failed to unlink %s: %s\n",
2077 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
2082 + globfree(&globbuf);
2087 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
2091 + pkg_t *pkg_to_remove;
2092 + pkg_vec_t *available;
2093 + char *pkg_name = NULL;
2094 + global_conf = conf;
2095 + signal(SIGINT, sigint_handler);
2097 +// ENH: Add the "no pkg removed" just in case.
2101 + available = pkg_vec_alloc();
2102 + pkg_info_preinstall_check(conf);
2104 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
2105 + for (i=0; i < argc; i++) {
2106 + pkg_name = malloc(strlen(argv[i])+2);
2107 + strcpy(pkg_name,argv[i]);
2108 + for (a=0; a < available->len; a++) {
2109 + pkg = available->pkgs[a];
2110 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
2113 + if (conf->restrict_to_default_dest) {
2114 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2116 + conf->default_dest);
2118 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
2121 + if (pkg == NULL) {
2122 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
2125 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
2126 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
2129 + ipkg_remove_pkg(conf, pkg_to_remove,0);
2134 + pkg_vec_free(available);
2136 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
2138 + int flagged_pkg_count = 0;
2141 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
2143 + for (i = 0; i < installed_pkgs->len; i++) {
2144 + pkg_t *pkg = installed_pkgs->pkgs[i];
2145 + if (pkg->state_flag & SF_USER) {
2146 + flagged_pkg_count++;
2148 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
2149 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
2152 + if (!flagged_pkg_count) {
2153 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
2154 + "so refusing to uninstall unflagged non-leaf packages\n");
2158 + /* find packages not flagged SF_USER (i.e., installed to
2159 + * satisfy a dependence) and not having any dependents, and
2163 + for (i = 0; i < installed_pkgs->len; i++) {
2164 + pkg_t *pkg = installed_pkgs->pkgs[i];
2165 + if (!(pkg->state_flag & SF_USER)
2166 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
2168 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
2169 + ipkg_remove_pkg(conf, pkg,0);
2173 + } while (removed);
2174 + pkg_vec_free(installed_pkgs);
2178 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
2180 + write_status_files_if_changed(conf);
2184 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
2189 + global_conf = conf;
2190 + signal(SIGINT, sigint_handler);
2192 + pkg_info_preinstall_check(conf);
2194 + for (i=0; i < argc; i++) {
2195 + if (conf->restrict_to_default_dest) {
2196 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2198 + conf->default_dest);
2200 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2203 + if (pkg == NULL) {
2204 + ipkg_message(conf, IPKG_ERROR,
2205 + "Package %s is not installed.\n", argv[i]);
2208 + ipkg_purge_pkg(conf, pkg);
2211 + write_status_files_if_changed(conf);
2215 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
2219 + const char *flags = argv[0];
2221 + global_conf = conf;
2222 + signal(SIGINT, sigint_handler);
2224 + for (i=1; i < argc; i++) {
2225 + if (conf->restrict_to_default_dest) {
2226 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2228 + conf->default_dest);
2230 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2233 + if (pkg == NULL) {
2234 + ipkg_message(conf, IPKG_ERROR,
2235 + "Package %s is not installed.\n", argv[i]);
2238 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2239 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2240 + pkg->state_flag = pkg_state_flag_from_str(flags);
2242 +/* pb_ asked this feature 03292004 */
2243 +/* Actually I will use only this two, but this is an open for various status */
2244 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2245 + pkg->state_status = pkg_state_status_from_str(flags);
2247 + ipkg_state_changed++;
2248 + ipkg_message(conf, IPKG_NOTICE,
2249 + "Setting flags for package %s to %s\n",
2250 + pkg->name, flags);
2253 + write_status_files_if_changed(conf);
2257 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2260 + str_list_t *installed_files;
2261 + str_list_elt_t *iter;
2262 + char *pkg_version;
2263 + size_t buff_len = 8192;
2267 + buff = (char *)malloc(buff_len);
2268 + if ( buff == NULL ) {
2269 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2277 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2279 + if (pkg == NULL) {
2280 + ipkg_message(conf, IPKG_ERROR,
2281 + "Package %s not installed.\n", argv[0]);
2285 + installed_files = pkg_get_installed_files(pkg);
2286 + pkg_version = pkg_version_str_alloc(pkg);
2289 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2290 + pkg->name, pkg_version, pkg->dest->name);
2291 + for (iter = installed_files->head; iter; iter = iter->next) {
2297 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2298 + pkg->name, pkg_version, pkg->dest->name) + 1;
2299 + if (used_len > buff_len) {
2301 + buff = realloc (buff, buff_len);
2304 + for (iter = installed_files->head; iter; iter = iter->next) {
2305 + used_len += strlen (iter->data) + 1;
2306 + while (buff_len <= used_len) {
2308 + buff = realloc (buff, buff_len);
2310 + strncat(buff, iter->data, buff_len);
2311 + strncat(buff, "\n", buff_len);
2313 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2315 + pkg_version_str_alloc(pkg),
2316 + pkg->state_status,
2322 + free(pkg_version);
2323 + pkg_free_installed_files(pkg);
2328 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2332 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2333 + const char *rel_str = "depends on";
2336 + pkg_info_preinstall_check(conf);
2338 + if (conf->query_all)
2339 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2341 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2342 + for (i = 0; i < argc; i++) {
2343 + const char *target = argv[i];
2346 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2348 + for (j = 0; j < available_pkgs->len; j++) {
2349 + pkg_t *pkg = available_pkgs->pkgs[j];
2350 + if (fnmatch(target, pkg->name, 0) == 0) {
2352 + int count = pkg->depends_count + pkg->pre_depends_count;
2353 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2354 + target, pkg->architecture, rel_str);
2355 + for (k = 0; k < count; k++) {
2356 + compound_depend_t *cdepend = &pkg->depends[k];
2358 + for (l = 0; l < cdepend->possibility_count; l++) {
2359 + depend_t *possibility = cdepend->possibilities[l];
2360 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2361 + if (conf->verbosity > 0) {
2362 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2363 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2364 + if (possibility->version) {
2365 + char *typestr = NULL;
2366 + switch (possibility->constraint) {
2367 + case NONE: typestr = "none"; break;
2368 + case EARLIER: typestr = "<"; break;
2369 + case EARLIER_EQUAL: typestr = "<="; break;
2370 + case EQUAL: typestr = "="; break;
2371 + case LATER_EQUAL: typestr = ">="; break;
2372 + case LATER: typestr = ">"; break;
2374 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2378 + ipkg_message(conf, IPKG_ERROR, "\n");
2384 + pkg_vec_free(available_pkgs);
2389 +enum what_field_type {
2398 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2402 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2403 + const char *rel_str = NULL;
2407 + switch (what_field_type) {
2408 + case WHATDEPENDS: rel_str = "depends on"; break;
2409 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2410 + case WHATSUGGESTS: rel_str = "suggests"; break;
2411 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2412 + case WHATPROVIDES: rel_str = "provides"; break;
2413 + case WHATREPLACES: rel_str = "replaces"; break;
2416 + if (conf->query_all)
2417 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2419 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2421 + /* mark the root set */
2422 + pkg_vec_clear_marks(available_pkgs);
2423 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2424 + for (i = 0; i < argc; i++) {
2425 + const char *dependee_pattern = argv[i];
2426 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2428 + for (i = 0; i < available_pkgs->len; i++) {
2429 + pkg_t *pkg = available_pkgs->pkgs[i];
2430 + if (pkg->state_flag & SF_MARKED) {
2431 + /* mark the parent (abstract) package */
2432 + pkg_mark_provides(pkg);
2433 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2437 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2442 + for (j = 0; j < available_pkgs->len; j++) {
2443 + pkg_t *pkg = available_pkgs->pkgs[j];
2445 + int count = ((what_field_type == WHATCONFLICTS)
2446 + ? pkg->conflicts_count
2447 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2448 + /* skip this package if it is already marked */
2449 + if (pkg->parent->state_flag & SF_MARKED) {
2452 + for (k = 0; k < count; k++) {
2453 + compound_depend_t *cdepend =
2454 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2456 + for (l = 0; l < cdepend->possibility_count; l++) {
2457 + depend_t *possibility = cdepend->possibilities[l];
2458 + if (possibility->pkg->state_flag & SF_MARKED) {
2459 + /* mark the depending package so we won't visit it again */
2460 + pkg->state_flag |= SF_MARKED;
2461 + pkg_mark_provides(pkg);
2464 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2465 + if (conf->verbosity > 0) {
2466 + char *ver = pkg_version_str_alloc(pkg);
2467 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2468 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2469 + if (possibility->version) {
2470 + char *typestr = NULL;
2471 + switch (possibility->constraint) {
2472 + case NONE: typestr = "none"; break;
2473 + case EARLIER: typestr = "<"; break;
2474 + case EARLIER_EQUAL: typestr = "<="; break;
2475 + case EQUAL: typestr = "="; break;
2476 + case LATER_EQUAL: typestr = ">="; break;
2477 + case LATER: typestr = ">"; break;
2479 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2482 + if (!pkg_dependence_satisfiable(conf, possibility))
2483 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2485 + ipkg_message(conf, IPKG_NOTICE, "\n");
2486 + goto next_package;
2493 + } while (changed && recursive);
2494 + pkg_vec_free(available_pkgs);
2500 +int pkg_mark_provides(pkg_t *pkg)
2502 + int provides_count = pkg->provides_count;
2503 + abstract_pkg_t **provides = pkg->provides;
2505 + pkg->parent->state_flag |= SF_MARKED;
2506 + for (i = 0; i < provides_count; i++) {
2507 + provides[i]->state_flag |= SF_MARKED;
2512 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2514 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2516 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2518 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2521 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2523 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2526 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2528 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2531 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2533 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2536 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2540 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2541 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2544 + pkg_info_preinstall_check(conf);
2546 + if (conf->query_all)
2547 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2549 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2550 + for (i = 0; i < argc; i++) {
2551 + const char *target = argv[i];
2554 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2556 + for (j = 0; j < available_pkgs->len; j++) {
2557 + pkg_t *pkg = available_pkgs->pkgs[j];
2559 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2560 + for (k = 0; k < count; k++) {
2561 + abstract_pkg_t *apkg =
2562 + ((what_field_type == WHATPROVIDES)
2563 + ? pkg->provides[k]
2564 + : pkg->replaces[k]);
2565 + if (fnmatch(target, apkg->name, 0) == 0) {
2566 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2567 + if (strcmp(target, apkg->name) != 0)
2568 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2569 + ipkg_message(conf, IPKG_ERROR, "\n");
2574 + pkg_vec_free(available_pkgs);
2579 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2581 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2584 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2586 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2589 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2593 + pkg_vec_t *installed;
2595 + str_list_t *installed_files;
2596 + str_list_elt_t *iter;
2597 + char *installed_file;
2603 + installed = pkg_vec_alloc();
2604 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2606 + for (i=0; i < installed->len; i++) {
2607 + pkg = installed->pkgs[i];
2609 + installed_files = pkg_get_installed_files(pkg);
2611 + for (iter = installed_files->head; iter; iter = iter->next) {
2612 + installed_file = iter->data;
2613 + if (fnmatch(argv[0], installed_file, 0)==0) {
2615 + printf("%s: %s\n", pkg->name, installed_file);
2617 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2619 + pkg_version_str_alloc(pkg),
2620 + pkg->state_status, p_userdata);
2625 + pkg_free_installed_files(pkg);
2628 + /* XXX: CLEANUP: It's not obvious from the name of
2629 + pkg_hash_fetch_all_installed that we need to call
2630 + pkg_vec_free to avoid a memory leak. */
2631 + pkg_vec_free(installed);
2636 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2639 + /* this is a bit gross */
2640 + struct pkg p1, p2;
2641 + parseVersion(&p1, argv[0]);
2642 + parseVersion(&p2, argv[2]);
2643 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2645 + ipkg_message(conf, IPKG_ERROR,
2646 + "ipkg compare_versions <v1> <op> <v2>\n"
2647 + "<op> is one of <= >= << >> =\n");
2652 +#ifndef HOST_CPU_STR
2653 +#define HOST_CPU_STR__(X) #X
2654 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2655 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2658 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2660 + nv_pair_list_elt_t *l;
2662 + l = conf->arch_list.head;
2664 + nv_pair_t *nv = l->data;
2665 + printf("arch %s %s\n", nv->name, nv->value);
2672 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_cmd.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h
2673 --- busybox-1.1.2-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2674 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h 2006-05-09 02:06:48.000000000 +0200
2676 +/* ipkg_cmd.h - the itsy package management system
2680 + Copyright (C) 2001 University of Southern California
2682 + This program is free software; you can redistribute it and/or
2683 + modify it under the terms of the GNU General Public License as
2684 + published by the Free Software Foundation; either version 2, or (at
2685 + your option) any later version.
2687 + This program is distributed in the hope that it will be useful, but
2688 + WITHOUT ANY WARRANTY; without even the implied warranty of
2689 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2690 + General Public License for more details.
2696 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2701 + int requires_args;
2702 + ipkg_cmd_fun_t fun;
2704 +typedef struct ipkg_cmd ipkg_cmd_t;
2706 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2708 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2709 + const char **argv, void *userdata);
2711 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2713 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2714 +/* install any packges with state_want == SW_INSTALL */
2715 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2716 +/* ensure that all dependences are satisfied */
2717 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2719 +int pkg_mark_provides(pkg_t *pkg);
2722 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_conf.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_conf.c
2723 --- busybox-1.1.2-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2724 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_conf.c 2006-05-09 02:12:04.000000000 +0200
2726 +/* ipkg_conf.c - the itsy package management system
2730 + Copyright (C) 2001 University of Southern California
2732 + This program is free software; you can redistribute it and/or
2733 + modify it under the terms of the GNU General Public License as
2734 + published by the Free Software Foundation; either version 2, or (at
2735 + your option) any later version.
2737 + This program is distributed in the hope that it will be useful, but
2738 + WITHOUT ANY WARRANTY; without even the implied warranty of
2739 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2740 + General Public License for more details.
2746 +#include "ipkg_conf.h"
2748 +#include "xregex.h"
2749 +#include "sprintf_alloc.h"
2750 +#include "ipkg_conf.h"
2751 +#include "ipkg_message.h"
2752 +#include "file_util.h"
2753 +#include "str_util.h"
2754 +#include "xsystem.h"
2757 +ipkg_conf_t *global_conf;
2759 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2760 + pkg_src_list_t *pkg_src_list,
2761 + nv_pair_list_t *tmp_dest_nv_pair_list,
2762 + char **tmp_lists_dir);
2763 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2764 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2765 + const char *name, const char *value);
2766 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2767 + const char *default_dest_name);
2768 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2769 + pkg_src_list_t *nv_pair_list);
2770 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2771 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2773 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2775 + ipkg_option_t tmp[] = {
2776 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2777 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2778 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2779 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2780 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2781 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2782 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2783 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2784 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2785 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2786 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2787 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2788 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2789 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2790 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2791 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2792 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2793 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2794 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2795 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2796 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2800 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2801 + if ( options == NULL ){
2802 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2806 + memcpy(*options, tmp, sizeof(tmp));
2810 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2816 + *conf_str = strdup(arg_str);
2820 +static void ipkg_conf_free_string(char **conf_str)
2828 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2831 + char *tmp_dir_base;
2832 + nv_pair_list_t tmp_dest_nv_pair_list;
2833 + char * lists_dir =NULL;
2835 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2836 + char *pending_dir =NULL;
2838 + memset(conf, 0, sizeof(ipkg_conf_t));
2840 + pkg_src_list_init(&conf->pkg_src_list);
2842 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2843 + pkg_dest_list_init(&conf->pkg_dest_list);
2845 + nv_pair_list_init(&conf->arch_list);
2847 + conf->restrict_to_default_dest = 0;
2848 + conf->default_dest = NULL;
2851 + if (args->tmp_dir)
2852 + tmp_dir_base = args->tmp_dir;
2854 + tmp_dir_base = getenv("TMPDIR");
2855 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2856 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2857 + IPKG_CONF_TMP_DIR_SUFFIX);
2858 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2859 + if (conf->tmp_dir == NULL) {
2860 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2861 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2865 + conf->force_depends = 0;
2866 + conf->force_defaults = 0;
2867 + conf->force_overwrite = 0;
2868 + conf->force_downgrade = 0;
2869 + conf->force_reinstall = 0;
2870 + conf->force_space = 0;
2871 + conf->force_removal_of_essential_packages = 0;
2872 + conf->force_removal_of_dependent_packages = 0;
2874 + conf->verbose_wget = 0;
2875 + conf->offline_root = NULL;
2876 + conf->offline_root_pre_script_cmd = NULL;
2877 + conf->offline_root_post_script_cmd = NULL;
2878 + conf->multiple_providers = 0;
2879 + conf->verbosity = 1;
2880 + conf->noaction = 0;
2882 + conf->http_proxy = NULL;
2883 + conf->ftp_proxy = NULL;
2884 + conf->no_proxy = NULL;
2885 + conf->proxy_user = NULL;
2886 + conf->proxy_passwd = NULL;
2888 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2889 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2890 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2891 + lists_dir=(char *)malloc(1);
2892 + lists_dir[0]='\0';
2893 + if (args->conf_file) {
2894 + struct stat stat_buf;
2895 + err = stat(args->conf_file, &stat_buf);
2897 + if (ipkg_conf_parse_file(conf, args->conf_file,
2898 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2899 + /* Memory leakage from ipkg_conf_parse-file */
2905 + /* if (!lists_dir ){*/
2906 + if (strlen(lists_dir)<=1 ){
2907 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2908 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2911 + if (args->offline_root) {
2912 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2913 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2918 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2919 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2921 + conf->lists_dir = strdup(lists_dir);
2922 + conf->pending_dir = strdup(pending_dir);
2924 + if (args->offline_root)
2925 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2926 + memset(&globbuf, 0, sizeof(globbuf));
2927 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2930 + for (i = 0; i < globbuf.gl_pathc; i++) {
2931 + if (globbuf.gl_pathv[i])
2932 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2933 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2934 + /* Memory leakage from ipkg_conf_parse-file */
2939 + globfree(&globbuf);
2941 + /* if no architectures were defined, then default all, noarch, and host architecture */
2942 + if (nv_pair_list_empty(&conf->arch_list)) {
2943 + nv_pair_list_append(&conf->arch_list, "all", "1");
2944 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2945 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2948 + /* Even if there is no conf file, we'll need at least one dest. */
2949 + if (tmp_dest_nv_pair_list.head == NULL) {
2950 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2951 + IPKG_CONF_DEFAULT_DEST_NAME,
2952 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2955 + /* After parsing the file, set options from command-line, (so that
2956 + command-line arguments take precedence) */
2957 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2958 + really needs to be cleaned up. There is so much duplication
2959 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2960 + a pointer to args_t (which could then not be freed), rather
2961 + than duplicating every field here? */
2962 + if (args->force_depends) {
2963 + conf->force_depends = 1;
2965 + if (args->force_defaults) {
2966 + conf->force_defaults = 1;
2968 + if (args->force_overwrite) {
2969 + conf->force_overwrite = 1;
2971 + if (args->force_downgrade) {
2972 + conf->force_downgrade = 1;
2974 + if (args->force_reinstall) {
2975 + conf->force_reinstall = 1;
2977 + if (args->force_removal_of_dependent_packages) {
2978 + conf->force_removal_of_dependent_packages = 1;
2980 + if (args->force_removal_of_essential_packages) {
2981 + conf->force_removal_of_essential_packages = 1;
2983 + if (args->nodeps) {
2986 + if (args->noaction) {
2987 + conf->noaction = 1;
2989 + if (args->query_all) {
2990 + conf->query_all = 1;
2992 + if (args->verbose_wget) {
2993 + conf->verbose_wget = 1;
2995 + if (args->multiple_providers) {
2996 + conf->multiple_providers = 1;
2998 + if (args->verbosity != conf->verbosity) {
2999 + conf->verbosity = args->verbosity;
3002 + ipkg_conf_override_string(&conf->offline_root,
3003 + args->offline_root);
3004 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
3005 + args->offline_root_pre_script_cmd);
3006 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
3007 + args->offline_root_post_script_cmd);
3009 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
3010 + read anything from there.
3012 + if ( !(args->nocheckfordirorfile)){
3013 + /* need to run load the source list before dest list -Jamey */
3014 + if ( !(args->noreadfeedsfile))
3015 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
3017 + /* Now that we have resolved conf->offline_root, we can commit to
3018 + the directory names for the dests and load in all the package
3020 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
3023 + err = ipkg_conf_set_default_dest(conf, args->dest);
3029 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
3031 + free(pending_dir);
3036 +void ipkg_conf_deinit(ipkg_conf_t *conf)
3038 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
3040 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
3041 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
3042 + __FUNCTION__, conf->tmp_dir);
3046 + err = rmdir(conf->tmp_dir);
3048 + if (errno == ENOTEMPTY) {
3050 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
3051 + err = xsystem(cmd);
3055 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
3057 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
3059 + free(conf->tmp_dir); /*XXX*/
3061 + pkg_src_list_deinit(&conf->pkg_src_list);
3062 + pkg_dest_list_deinit(&conf->pkg_dest_list);
3063 + nv_pair_list_deinit(&conf->arch_list);
3064 + if (&conf->pkg_hash)
3065 + pkg_hash_deinit(&conf->pkg_hash);
3066 + if (&conf->file_hash)
3067 + hash_table_deinit(&conf->file_hash);
3068 + if (&conf->obs_file_hash)
3069 + hash_table_deinit(&conf->obs_file_hash);
3071 + ipkg_conf_free_string(&conf->offline_root);
3072 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
3073 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
3075 + if (conf->verbosity > 1) {
3077 + hash_table_t *hashes[] = {
3080 + &conf->obs_file_hash };
3081 + for (i = 0; i < 3; i++) {
3082 + hash_table_t *hash = hashes[i];
3084 + int n_conflicts = 0;
3086 + for (j = 0; j < hash->n_entries; j++) {
3088 + hash_entry_t *e = &hash->entries[j];
3091 + while (e && e->key) {
3098 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
3099 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
3100 + hash_table_deinit(hash);
3105 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
3106 + const char *default_dest_name)
3108 + pkg_dest_list_elt_t *iter;
3111 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3112 + dest = iter->data;
3113 + if (strcmp(dest->name, default_dest_name) == 0) {
3114 + conf->default_dest = dest;
3115 + conf->restrict_to_default_dest = 1;
3120 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
3125 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
3127 + pkg_src_list_elt_t *iter;
3131 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
3133 + if (src == NULL) {
3137 + sprintf_alloc(&list_file, "%s/%s",
3138 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
3141 + if (file_exists(list_file)) {
3142 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
3150 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
3152 + nv_pair_list_elt_t *iter;
3153 + nv_pair_t *nv_pair;
3157 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
3158 + nv_pair = iter->data;
3160 + if (conf->offline_root) {
3161 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
3163 + root_dir = strdup(nv_pair->value);
3165 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
3167 + if (dest == NULL) {
3170 + if (conf->default_dest == NULL) {
3171 + conf->default_dest = dest;
3173 + if (file_exists(dest->status_file_name)) {
3174 + pkg_hash_add_from_file(conf, dest->status_file_name,
3182 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
3183 + pkg_src_list_t *pkg_src_list,
3184 + nv_pair_list_t *tmp_dest_nv_pair_list,
3187 + ipkg_option_t * options;
3188 + FILE *file = fopen(filename, "r");
3189 + regex_t valid_line_re, comment_re;
3190 +#define regmatch_size 12
3191 + regmatch_t regmatch[regmatch_size];
3193 + if (ipkg_init_options_array(conf, &options)<0)
3196 + if (file == NULL) {
3197 + fprintf(stderr, "%s: failed to open %s: %s\n",
3198 + __FUNCTION__, filename, strerror(errno));
3202 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
3204 + xregcomp(&comment_re,
3205 + "^[[:space:]]*(#.*|[[:space:]]*)$",
3207 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
3212 + char *type, *name, *value, *extra;
3214 + line = file_read_line_alloc(file);
3216 + if (line == NULL) {
3222 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3226 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3228 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3229 + filename, line_num, line);
3233 + /* This has to be so ugly to deal with optional quotation marks */
3234 + if (regmatch[2].rm_so > 0) {
3235 + type = strndup(line + regmatch[2].rm_so,
3236 + regmatch[2].rm_eo - regmatch[2].rm_so);
3238 + type = strndup(line + regmatch[3].rm_so,
3239 + regmatch[3].rm_eo - regmatch[3].rm_so);
3241 + if (regmatch[5].rm_so > 0) {
3242 + name = strndup(line + regmatch[5].rm_so,
3243 + regmatch[5].rm_eo - regmatch[5].rm_so);
3245 + name = strndup(line + regmatch[6].rm_so,
3246 + regmatch[6].rm_eo - regmatch[6].rm_so);
3248 + if (regmatch[8].rm_so > 0) {
3249 + value = strndup(line + regmatch[8].rm_so,
3250 + regmatch[8].rm_eo - regmatch[8].rm_so);
3252 + value = strndup(line + regmatch[9].rm_so,
3253 + regmatch[9].rm_eo - regmatch[9].rm_so);
3256 + if (regmatch[11].rm_so > 0) {
3257 + extra = strndup (line + regmatch[11].rm_so,
3258 + regmatch[11].rm_eo - regmatch[11].rm_so);
3261 + /* We use the tmp_dest_nv_pair_list below instead of
3262 + conf->pkg_dest_list because we might encounter an
3263 + offline_root option later and that would invalidate the
3264 + directories we would have computed in
3265 + pkg_dest_list_init. (We do a similar thing with
3266 + tmp_src_nv_pair_list for sake of symmetry.) */
3267 + if (strcmp(type, "option") == 0) {
3268 + ipkg_conf_set_option(options, name, value);
3269 + } else if (strcmp(type, "src") == 0) {
3270 + if (!nv_pair_list_find(pkg_src_list, name)) {
3271 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3273 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3276 + } else if (strcmp(type, "src/gz") == 0) {
3277 + if (!nv_pair_list_find(pkg_src_list, name)) {
3278 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3280 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3283 + } else if (strcmp(type, "dest") == 0) {
3284 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3285 + } else if (strcmp(type, "lists_dir") == 0) {
3286 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3287 + if (*lists_dir == NULL) {
3288 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3292 + sprintf (*lists_dir,"%s",value);
3293 + } else if (strcmp(type, "arch") == 0) {
3294 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3296 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3297 + value = strdup("10");
3299 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3301 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3302 + "parameter: %s %s %s\n", type, name, value);
3318 + regfree(&comment_re);
3319 + regfree(&valid_line_re);
3325 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3326 + const char *name, const char *value)
3329 + while (options[i].name) {
3330 + if (strcmp(options[i].name, name) == 0) {
3331 + switch (options[i].type) {
3332 + case IPKG_OPT_TYPE_BOOL:
3333 + *((int *)options[i].value) = 1;
3335 + case IPKG_OPT_TYPE_INT:
3337 + *((int *)options[i].value) = atoi(value);
3340 + printf("%s: Option %s need an argument\n",
3341 + __FUNCTION__, name);
3344 + case IPKG_OPT_TYPE_STRING:
3346 + *((char **)options[i].value) = strdup(value);
3349 + printf("%s: Option %s need an argument\n",
3350 + __FUNCTION__, name);
3358 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3359 + __FUNCTION__, name, value);
3363 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3365 + pkg_dest_list_elt_t *iter;
3372 + if (conf->noaction)
3374 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3375 + dest = iter->data;
3376 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3377 + if (dest->status_file == NULL) {
3378 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3379 + __FUNCTION__, dest->status_file_name, strerror(errno));
3383 + all = pkg_vec_alloc();
3384 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3386 + for(i = 0; i < all->len; i++) {
3387 + pkg = all->pkgs[i];
3388 + /* We don't need most uninstalled packages in the status file */
3389 + if (pkg->state_status == SS_NOT_INSTALLED
3390 + && (pkg->state_want == SW_UNKNOWN
3391 + || pkg->state_want == SW_DEINSTALL
3392 + || pkg->state_want == SW_PURGE)) {
3396 + fprintf(stderr, "Null package\n");
3398 + if (pkg->dest == NULL) {
3399 + fprintf(stderr, "%s: ERROR: Can't write status for "
3400 + "package %s since it has a NULL dest\n",
3401 + __FUNCTION__, pkg->name);
3404 + if (pkg->dest->status_file) {
3405 + pkg_print_status(pkg, pkg->dest->status_file);
3409 + pkg_vec_free(all);
3411 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3412 + dest = iter->data;
3413 + if (dest->status_file) {
3414 + err = ferror(dest->status_file);
3415 + fclose(dest->status_file);
3416 + dest->status_file = NULL;
3418 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3420 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3421 + "retaining old %s\n", __FUNCTION__,
3422 + dest->status_file_tmp_name, dest->status_file_name);
3431 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3433 + char *root_filename;
3434 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3435 + return root_filename;
3437 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_conf.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_conf.h
3438 --- busybox-1.1.2-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3439 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_conf.h 2006-05-09 02:06:48.000000000 +0200
3441 +/* ipkg_conf.h - the itsy package management system
3445 + Copyright (C) 2001 University of Southern California
3447 + This program is free software; you can redistribute it and/or
3448 + modify it under the terms of the GNU General Public License as
3449 + published by the Free Software Foundation; either version 2, or (at
3450 + your option) any later version.
3452 + This program is distributed in the hope that it will be useful, but
3453 + WITHOUT ANY WARRANTY; without even the implied warranty of
3454 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3455 + General Public License for more details.
3458 +#ifndef IPKG_CONF_H
3459 +#define IPKG_CONF_H
3461 +typedef struct ipkg_conf ipkg_conf_t;
3463 +#include "hash_table.h"
3467 +#include "pkg_hash.h"
3468 +#include "pkg_src_list.h"
3469 +#include "pkg_dest_list.h"
3470 +#include "nv_pair_list.h"
3472 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3473 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3474 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3475 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3477 +/* In case the config file defines no dest */
3478 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3479 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3481 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3485 + pkg_src_list_t pkg_src_list;
3486 + pkg_dest_list_t pkg_dest_list;
3487 + nv_pair_list_t arch_list;
3489 + int restrict_to_default_dest;
3490 + pkg_dest_t *default_dest;
3493 + const char *lists_dir;
3494 + const char *pending_dir;
3497 + int force_depends;
3498 + int force_defaults;
3499 + int force_overwrite;
3500 + int force_downgrade;
3501 + int force_reinstall;
3503 + int force_removal_of_dependent_packages;
3504 + int force_removal_of_essential_packages;
3505 + int nodeps; /* do not follow dependences */
3507 + int multiple_providers;
3508 + char *offline_root;
3509 + char *offline_root_pre_script_cmd;
3510 + char *offline_root_post_script_cmd;
3515 + /* proxy options */
3520 + char *proxy_passwd;
3522 + hash_table_t pkg_hash;
3523 + hash_table_t file_hash;
3524 + hash_table_t obs_file_hash;
3527 +enum ipkg_option_type {
3528 + IPKG_OPT_TYPE_BOOL,
3529 + IPKG_OPT_TYPE_INT,
3530 + IPKG_OPT_TYPE_STRING
3532 +typedef enum ipkg_option_type ipkg_option_type_t;
3534 +typedef struct ipkg_option ipkg_option_t;
3535 +struct ipkg_option {
3537 + const ipkg_option_type_t type;
3538 + const void *value;
3541 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3542 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3544 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3545 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3548 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_configure.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_configure.c
3549 --- busybox-1.1.2-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3550 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_configure.c 2006-05-09 02:06:48.000000000 +0200
3552 +/* ipkg_configure.c - the itsy package management system
3556 + Copyright (C) 2001 University of Southern California
3558 + This program is free software; you can redistribute it and/or
3559 + modify it under the terms of the GNU General Public License as
3560 + published by the Free Software Foundation; either version 2, or (at
3561 + your option) any later version.
3563 + This program is distributed in the hope that it will be useful, but
3564 + WITHOUT ANY WARRANTY; without even the implied warranty of
3565 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3566 + General Public License for more details.
3571 +#include "ipkg_configure.h"
3573 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3577 + /* DPKG_INCOMPATIBILITY:
3578 + dpkg actually does some conffile handling here, rather than at the
3579 + end of ipkg_install(). Do we care? */
3580 + /* DPKG_INCOMPATIBILITY:
3581 + dpkg actually includes a version number to this script call */
3582 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3584 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3588 + ipkg_state_changed++;
3592 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_configure.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_configure.h
3593 --- busybox-1.1.2-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3594 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_configure.h 2006-05-09 02:06:48.000000000 +0200
3596 +/* ipkg_configure.h - the itsy package management system
3600 + Copyright (C) 2001 University of Southern California
3602 + This program is free software; you can redistribute it and/or
3603 + modify it under the terms of the GNU General Public License as
3604 + published by the Free Software Foundation; either version 2, or (at
3605 + your option) any later version.
3607 + This program is distributed in the hope that it will be useful, but
3608 + WITHOUT ANY WARRANTY; without even the implied warranty of
3609 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3610 + General Public License for more details.
3613 +#ifndef IPKG_CONFIGURE_H
3614 +#define IPKG_CONFIGURE_H
3616 +#include "ipkg_conf.h"
3618 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3621 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_download.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.c
3622 --- busybox-1.1.2-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3623 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.c 2006-05-09 02:12:04.000000000 +0200
3625 +/* ipkg_download.c - the itsy package management system
3629 + Copyright (C) 2001 University of Southern California
3631 + This program is free software; you can redistribute it and/or
3632 + modify it under the terms of the GNU General Public License as
3633 + published by the Free Software Foundation; either version 2, or (at
3634 + your option) any later version.
3636 + This program is distributed in the hope that it will be useful, but
3637 + WITHOUT ANY WARRANTY; without even the implied warranty of
3638 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3639 + General Public License for more details.
3643 +#include "ipkg_download.h"
3644 +#include "ipkg_message.h"
3646 +#include "sprintf_alloc.h"
3647 +#include "xsystem.h"
3648 +#include "file_util.h"
3649 +#include "str_util.h"
3651 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3655 + char *src_basec = strdup(src);
3656 + char *src_base = basename(src_basec);
3657 + char *tmp_file_location;
3660 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3664 + if (str_starts_with(src, "file:")) {
3666 + const char *file_src = src + 5;
3667 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3668 + ret = file_copy(src + 5, dest_file_name);
3669 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3673 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3674 + err = unlink(tmp_file_location);
3675 + if (err && errno != ENOENT) {
3676 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3677 + __FUNCTION__, tmp_file_location, strerror(errno));
3678 + free(tmp_file_location);
3682 + if (conf->http_proxy) {
3683 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3684 + setenv("http_proxy", conf->http_proxy, 1);
3686 + if (conf->ftp_proxy) {
3687 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3688 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3690 + if (conf->no_proxy) {
3691 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3692 + setenv("no_proxy", conf->no_proxy, 1);
3695 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3696 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3697 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3698 + conf->proxy_user ? "--proxy-user=" : "",
3699 + conf->proxy_user ? conf->proxy_user : "",
3700 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3701 + conf->proxy_passwd ? conf->proxy_passwd : "",
3702 + conf->verbose_wget ? "" : "-q",
3705 + err = xsystem(cmd);
3708 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3709 + __FUNCTION__, err, cmd);
3711 + unlink(tmp_file_location);
3712 + free(tmp_file_location);
3719 + err = file_move(tmp_file_location, dest_file_name);
3721 + free(tmp_file_location);
3731 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3736 + if (pkg->src == NULL) {
3737 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3738 + pkg->name, pkg->parent->name);
3742 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3744 + /* XXX: BUG: The pkg->filename might be something like
3745 + "../../foo.ipk". While this is correct, and exactly what we
3746 + want to use to construct url above, here we actually need to
3747 + use just the filename part, without any directory. */
3748 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3750 + err = ipkg_download(conf, url, pkg->local_filename);
3757 + * Downloads file from url, installs in package database, return package name.
3759 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3767 + if (str_starts_with(url, "http://")
3768 + || str_starts_with(url, "ftp://")) {
3770 + char *file_basec = strdup(url);
3771 + char *file_base = basename(file_basec);
3773 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3774 + err = ipkg_download(conf, url, tmp_file);
3778 + err = pkg_init_from_file(pkg, tmp_file);
3781 + pkg->local_filename = strdup(tmp_file);
3786 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3787 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3789 + err = pkg_init_from_file(pkg, url);
3792 + pkg->local_filename = strdup(url);
3793 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3794 + pkg->provided_by_hand = 1;
3802 + if (!pkg->architecture) {
3803 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3807 + pkg->dest = conf->default_dest;
3808 + pkg->state_want = SW_INSTALL;
3809 + pkg->state_flag |= SF_PREFER;
3810 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3811 + if ( pkg == NULL ){
3812 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3816 + *namep = strdup(pkg->name);
3820 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_download.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.h
3821 --- busybox-1.1.2-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3822 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-05-09 02:06:48.000000000 +0200
3824 +/* ipkg_download.h - the itsy package management system
3828 + Copyright (C) 2001 University of Southern California
3830 + This program is free software; you can redistribute it and/or
3831 + modify it under the terms of the GNU General Public License as
3832 + published by the Free Software Foundation; either version 2, or (at
3833 + your option) any later version.
3835 + This program is distributed in the hope that it will be useful, but
3836 + WITHOUT ANY WARRANTY; without even the implied warranty of
3837 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3838 + General Public License for more details.
3841 +#ifndef IPKG_DOWNLOAD_H
3842 +#define IPKG_DOWNLOAD_H
3844 +#include "ipkg_conf.h"
3846 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3847 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3849 + * Downloads file from url, installs in package database, return package name.
3851 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3854 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_includes.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_includes.h
3855 --- busybox-1.1.2-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3856 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-05-09 02:06:48.000000000 +0200
3858 +#ifndef IPKG_INCLUDES_H
3859 +#define IPKG_INCLUDES_H
3861 +/* Define to 1 if you have the <memory.h> header file. */
3862 +#define HAVE_MEMORY_H 1
3864 +/* Define to 1 if you have the <regex.h> header file. */
3865 +#define HAVE_REGEX_H 1
3867 +/* Define to 1 if you have the <stdlib.h> header file. */
3868 +#define HAVE_STDLIB_H 1
3870 +/* Define to 1 if you have the <strings.h> header file. */
3871 +#define HAVE_STRINGS_H 1
3873 +/* Define to 1 if you have the <string.h> header file. */
3874 +#define HAVE_STRING_H 1
3876 +/* Define to 1 if you have the <sys/stat.h> header file. */
3877 +#define HAVE_SYS_STAT_H 1
3879 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3880 +#define HAVE_SYS_WAIT_H 1
3882 +/* Define to 1 if you have the <unistd.h> header file. */
3883 +#define HAVE_UNISTD_H 1
3885 +/* Define to 1 if you have the ANSI C header files. */
3886 +#define STDC_HEADERS 1
3892 +# include <stdlib.h>
3893 +# include <stdarg.h>
3894 +# include <stddef.h>
3895 +# include <ctype.h>
3896 +# include <errno.h>
3899 +# include <stdlib.h>
3904 +# include <regex.h>
3908 +# if !STDC_HEADERS && HAVE_MEMORY_H
3909 +# include <memory.h>
3911 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3913 +# define __USE_GNU 1
3915 +# include <string.h>
3920 +# include <strings.h>
3923 +#if HAVE_SYS_STAT_H
3924 +# include <sys/stat.h>
3927 +#if HAVE_SYS_WAIT_H
3928 +# include <sys/wait.h>
3932 +# include <sys/types.h>
3933 +# include <unistd.h>
3936 +#endif /* IPKG_INCLUDES_H */
3937 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_install.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.c
3938 --- busybox-1.1.2-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3939 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-05-09 02:12:04.000000000 +0200
3941 +/* ipkg_install.c - the itsy package management system
3945 + Copyright (C) 2001 University of Southern California
3947 + This program is free software; you can redistribute it and/or
3948 + modify it under the terms of the GNU General Public License as
3949 + published by the Free Software Foundation; either version 2, or (at
3950 + your option) any later version.
3952 + This program is distributed in the hope that it will be useful, but
3953 + WITHOUT ANY WARRANTY; without even the implied warranty of
3954 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3955 + General Public License for more details.
3960 +#include <dirent.h>
3963 +#include <signal.h>
3964 +typedef void (*sighandler_t)(int);
3967 +#include "pkg_hash.h"
3968 +#include "pkg_extract.h"
3970 +#include "ipkg_install.h"
3971 +#include "ipkg_configure.h"
3972 +#include "ipkg_download.h"
3973 +#include "ipkg_remove.h"
3975 +#include "ipkg_utils.h"
3976 +#include "ipkg_message.h"
3978 +#include "sprintf_alloc.h"
3979 +#include "file_util.h"
3980 +#include "str_util.h"
3981 +#include "xsystem.h"
3984 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3985 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3986 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3988 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3989 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3990 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3991 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3992 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3993 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3994 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3995 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3996 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3997 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3998 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3999 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4000 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4002 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4003 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
4004 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
4005 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
4006 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
4008 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
4010 +static int user_prefers_old_conffile(const char *file, const char *backup);
4012 +static char *backup_filename_alloc(const char *file_name);
4013 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
4014 +static int backup_exists_for(const char *file_name);
4015 +static int backup_remove(const char *file_name);
4018 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
4022 + char *old_version, *new_version;
4025 + if (pkg == NULL) {
4029 + err = pkg_init_from_file(pkg, filename);
4034 + if (!pkg->architecture) {
4035 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
4039 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
4040 + freeing the pkg that we pass in. It might be nice to clean this up
4042 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
4043 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4045 + pkg->local_filename = strdup(filename);
4048 + old_version = pkg_version_str_alloc(old);
4049 + new_version = pkg_version_str_alloc(pkg);
4051 + cmp = pkg_compare_versions(old, pkg);
4052 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4053 + cmp = -1 ; /* then we force ipkg to downgrade */
4054 + /* We need to use a value < 0 because in the 0 case we are asking to */
4055 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4058 + ipkg_message(conf, IPKG_NOTICE,
4059 + "Not downgrading package %s on %s from %s to %s.\n",
4060 + old->name, old->dest->name, old_version, new_version);
4061 + pkg->state_want = SW_DEINSTALL;
4062 + pkg->state_flag |= SF_OBSOLETE;
4063 + free(old_version);
4064 + free(new_version);
4067 + free(old_version);
4068 + free(new_version);
4072 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4073 + return ipkg_install_pkg(conf, pkg,0);
4076 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
4080 + char *old_version, *new_version;
4082 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
4083 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4085 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
4087 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
4088 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4090 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
4092 +/* Pigi Basically here is broken the version stuff.
4093 + What's happening is that nothing provide the version to differents
4094 + functions, so the returned struct is always the latest.
4095 + That's why the install by name don't work.
4097 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
4100 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
4102 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
4103 + ipkg_message(conf, IPKG_DEBUG2, " \n");
4105 + if (new == NULL) {
4106 + return IPKG_PKG_HAS_NO_CANDIDATE;
4109 + new->state_flag |= SF_USER;
4111 + old_version = pkg_version_str_alloc(old);
4112 + new_version = pkg_version_str_alloc(new);
4114 + cmp = pkg_compare_versions(old, new);
4115 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4116 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
4117 + cmp = -1 ; /* then we force ipkg to downgrade */
4118 + /* We need to use a value < 0 because in the 0 case we are asking to */
4119 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4121 + ipkg_message(conf, IPKG_DEBUG,
4122 + "Comparing visible versions of pkg %s:"
4123 + "\n\t%s is installed "
4124 + "\n\t%s is available "
4125 + "\n\t%d was comparison result\n",
4126 + pkg_name, old_version, new_version, cmp);
4127 + if (cmp == 0 && !conf->force_reinstall) {
4128 + ipkg_message(conf, IPKG_NOTICE,
4129 + "Package %s (%s) installed in %s is up to date.\n",
4130 + old->name, old_version, old->dest->name);
4131 + free(old_version);
4132 + free(new_version);
4134 + } else if (cmp > 0) {
4135 + ipkg_message(conf, IPKG_NOTICE,
4136 + "Not downgrading package %s on %s from %s to %s.\n",
4137 + old->name, old->dest->name, old_version, new_version);
4138 + free(old_version);
4139 + free(new_version);
4141 + } else if (cmp < 0) {
4142 + new->dest = old->dest;
4143 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4147 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4148 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4149 + return any kind of integer, (might be errno from a syscall,
4150 + etc.). This is a real mess and will need to be cleaned up if
4151 + anyone ever wants to make a nice libipkg. */
4153 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4154 + return ipkg_install_pkg(conf, new,0);
4157 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4159 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4162 + abstract_pkg_t *ppkg ;
4164 + if (providers == NULL)
4165 + return IPKG_PKG_HAS_NO_CANDIDATE;
4167 + for (i = 0; i < providers->len; i++) {
4168 + ppkg = abstract_pkg_vec_get(providers, i);
4169 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4170 + err = ipkg_install_by_name(conf, ppkg->name);
4173 +/* XXX Maybe ppkg should be freed ? */
4179 + * Walk dependence graph starting with pkg, collect packages to be
4180 + * installed into pkgs_needed, in dependence order.
4182 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4185 + pkg_vec_t *depends = pkg_vec_alloc();
4186 + char **unresolved = NULL;
4189 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4194 + ipkg_message(conf, IPKG_ERROR,
4195 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4196 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4197 + while (*unresolved) {
4198 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4201 + ipkg_message(conf, IPKG_ERROR, "\n");
4202 + if (! conf->force_depends) {
4203 + ipkg_message(conf, IPKG_INFO,
4204 + "This could mean that your package list is out of date or that the packages\n"
4205 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4206 + "of this problem try again with the '-force-depends' option.\n");
4207 + pkg_vec_free(depends);
4208 + return IPKG_PKG_DEPS_UNSATISFIED;
4212 + if (ndepends <= 0) {
4213 + pkg_vec_free(depends);
4217 + for (i = 0; i < depends->len; i++) {
4218 + pkg_t *dep = depends->pkgs[i];
4219 + /* The package was uninstalled when we started, but another
4220 + dep earlier in this loop may have depended on it and pulled
4221 + it in, so check first. */
4222 + if ((dep->state_status != SS_INSTALLED)
4223 + && (dep->state_status != SS_UNPACKED)
4224 + && (dep->state_want != SW_INSTALL)) {
4226 + /* Mark packages as to-be-installed */
4227 + dep->state_want = SW_INSTALL;
4229 + /* Dependencies should be installed the same place as pkg */
4230 + if (dep->dest == NULL) {
4231 + dep->dest = pkg->dest;
4234 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4236 + pkg_vec_free(depends);
4242 + pkg_vec_insert(pkgs_needed, pkg);
4244 + pkg_vec_free(depends);
4249 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4253 + char *old_version, *new_version;
4255 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4257 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4258 + if (new == NULL) {
4259 + return IPKG_PKG_HAS_NO_CANDIDATE;
4262 + old_version = pkg_version_str_alloc(old);
4263 + new_version = pkg_version_str_alloc(new);
4265 + cmp = pkg_compare_versions(old, new);
4266 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4267 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4268 + cmp = -1 ; /* then we force ipkg to downgrade */
4269 + /* We need to use a value < 0 because in the 0 case we are asking to */
4270 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4272 + ipkg_message(conf, IPKG_DEBUG,
4273 + "comparing visible versions of pkg %s:"
4274 + "\n\t%s is installed "
4275 + "\n\t%s is available "
4276 + "\n\t%d was comparison result\n",
4277 + pkg_name, old_version, new_version, cmp);
4278 + if (cmp == 0 && !conf->force_reinstall) {
4279 + ipkg_message(conf, IPKG_NOTICE,
4280 + "Package %s (%s) installed in %s is up to date.\n",
4281 + old->name, old_version, old->dest->name);
4282 + free(old_version);
4283 + free(new_version);
4285 + } else if (cmp > 0) {
4286 + ipkg_message(conf, IPKG_NOTICE,
4287 + "Not downgrading package %s on %s from %s to %s.\n",
4288 + old->name, old->dest->name, old_version, new_version);
4289 + free(old_version);
4290 + free(new_version);
4292 + } else if (cmp < 0) {
4293 + new->dest = old->dest;
4294 + old->state_want = SW_DEINSTALL;
4295 + old->state_flag |= SF_OBSOLETE;
4298 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4303 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4306 + pkg_vec_t *depends = pkg_vec_alloc();
4308 + char **unresolved = NULL;
4311 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4316 + ipkg_message(conf, IPKG_ERROR,
4317 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4318 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4319 + while (*unresolved) {
4320 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4323 + ipkg_message(conf, IPKG_ERROR, "\n");
4324 + if (! conf->force_depends) {
4325 + ipkg_message(conf, IPKG_INFO,
4326 + "This could mean that your package list is out of date or that the packages\n"
4327 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4328 + "of this problem try again with the '-force-depends' option.\n");
4329 + pkg_vec_free(depends);
4330 + return IPKG_PKG_DEPS_UNSATISFIED;
4334 + if (ndepends <= 0) {
4338 + /* Mark packages as to-be-installed */
4339 + for (i=0; i < depends->len; i++) {
4340 + /* Dependencies should be installed the same place as pkg */
4341 + if (depends->pkgs[i]->dest == NULL) {
4342 + depends->pkgs[i]->dest = pkg->dest;
4344 + depends->pkgs[i]->state_want = SW_INSTALL;
4347 + for (i = 0; i < depends->len; i++) {
4348 + dep = depends->pkgs[i];
4349 + /* The package was uninstalled when we started, but another
4350 + dep earlier in this loop may have depended on it and pulled
4351 + it in, so check first. */
4352 + if ((dep->state_status != SS_INSTALLED)
4353 + && (dep->state_status != SS_UNPACKED)) {
4354 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4355 + err = ipkg_install_pkg(conf, dep,0);
4357 + pkg_vec_free(depends);
4363 + pkg_vec_free(depends);
4369 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4370 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4372 + if (conf->nodeps == 0) {
4374 + pkg_vec_t *installed = pkg_vec_alloc();
4375 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4376 + for (i = 0; i < installed->len; i++) {
4377 + pkg_t *pkg = installed->pkgs[i];
4378 + satisfy_dependencies_for(conf, pkg);
4380 + pkg_vec_free(installed);
4387 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4390 + pkg_vec_t *conflicts = NULL;
4392 + const char *prefix;
4393 + if (conf->force_depends) {
4394 + level = IPKG_NOTICE;
4395 + prefix = "Warning";
4397 + level = IPKG_ERROR;
4401 + if (!conf->force_depends)
4402 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4405 + ipkg_message(conf, level,
4406 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4408 + while (i < conflicts->len)
4409 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4410 + ipkg_message(conf, level, "\n");
4411 + pkg_vec_free(conflicts);
4412 + return IPKG_PKG_DEPS_UNSATISFIED;
4417 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4419 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4420 + str_list_elt_t *iter;
4422 + for (iter = new_list->head; iter; iter = iter->next) {
4423 + char *new_file = iter->data;
4424 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4426 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4427 + if (!owner || (owner == old_pkg))
4428 + file_hash_set_file_owner(conf, new_file, new_pkg);
4431 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4432 + for (iter = old_list->head; iter; iter = iter->next) {
4433 + char *old_file = iter->data;
4434 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4435 + if (owner == old_pkg) {
4437 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4444 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4446 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4448 + /* sma 6.20.02: yup; here's the first bit */
4450 + * XXX: BUG easy for cworth
4451 + * 1) please point the call below to the correct current root destination
4452 + * 2) we need to resolve how to check the required space for a pending pkg,
4453 + * my diddling with the .ipk file size below isn't going to cut it.
4454 + * 3) return a proper error code instead of 1
4456 + int comp_size, blocks_available;
4458 + if (!conf->force_space && pkg->installed_size != NULL) {
4459 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4461 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4462 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4463 + comp_size = (int)((comp_size + 1023) / 1024);
4465 + if (comp_size >= blocks_available) {
4466 + ipkg_message(conf, IPKG_ERROR,
4467 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4468 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4475 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4478 + char *conffiles_file_name;
4480 + FILE *conffiles_file;
4482 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4484 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4485 + if (pkg->tmp_unpack_dir == NULL) {
4486 + ipkg_message(conf, IPKG_ERROR,
4487 + "%s: Failed to create temporary directory '%s': %s\n",
4488 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4492 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4497 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4498 + conffiles. Seems like I should be able to get everything to go
4499 + through pkg_init_from_file. If so, maybe it would make sense to
4500 + move all of unpack_pkg_control_files to that function. */
4502 + /* Don't need to re-read conffiles if we already have it */
4503 + if (pkg->conffiles.head) {
4507 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4508 + if (! file_exists(conffiles_file_name)) {
4509 + free(conffiles_file_name);
4513 + conffiles_file = fopen(conffiles_file_name, "r");
4514 + if (conffiles_file == NULL) {
4515 + fprintf(stderr, "%s: failed to open %s: %s\n",
4516 + __FUNCTION__, conffiles_file_name, strerror(errno));
4517 + free(conffiles_file_name);
4520 + free(conffiles_file_name);
4524 + char *cf_name_in_dest;
4526 + cf_name = file_read_line_alloc(conffiles_file);
4527 + if (cf_name == NULL) {
4530 + str_chomp(cf_name);
4531 + if (cf_name[0] == '\0') {
4535 + /* Prepend dest->root_dir to conffile name.
4536 + Take pains to avoid multiple slashes. */
4537 + root_dir = pkg->dest->root_dir;
4538 + if (conf->offline_root)
4539 + /* skip the offline_root prefix */
4540 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4541 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4542 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4544 + /* Can't get an md5sum now, (file isn't extracted yet).
4545 + We'll wait until resolve_conffiles */
4546 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4549 + free(cf_name_in_dest);
4552 + fclose(conffiles_file);
4557 +/* returns number of installed replacees */
4558 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4560 + abstract_pkg_t **replaces = pkg->replaces;
4561 + int replaces_count = pkg->replaces_count;
4563 + for (i = 0; i < replaces_count; i++) {
4564 + abstract_pkg_t *ab_pkg = replaces[i];
4565 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4567 + for (j = 0; j < pkg_vec->len; j++) {
4568 + pkg_t *replacee = pkg_vec->pkgs[j];
4569 + if (!pkg_conflicts(pkg, replacee))
4571 + if (replacee->state_status == SS_INSTALLED) {
4572 + pkg_vec_insert(installed_replacees, replacee);
4577 + return installed_replacees->len;
4580 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4583 + int replaces_count = replacees->len;
4584 + for (i = 0; i < replaces_count; i++) {
4585 + pkg_t *replacee = replacees->pkgs[i];
4587 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4588 + err = ipkg_remove_pkg(conf, replacee,0);
4595 +/* to unwind the removal: make sure they are installed */
4596 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4599 + int replaces_count = replacees->len;
4600 + for (i = 0; i < replaces_count; i++) {
4601 + pkg_t *replacee = replacees->pkgs[i];
4602 + if (replacee->state_status != SS_INSTALLED) {
4603 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4604 + err = ipkg_install_pkg(conf, replacee,0);
4612 +int caught_sigint = 0;
4613 +static void ipkg_install_pkg_sigint_handler(int sig)
4615 + caught_sigint = sig;
4618 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4619 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4622 + char message_out[15];
4623 + char *old_version = pkg_version_str_alloc(old_pkg);
4624 + char *new_version = pkg_version_str_alloc(pkg);
4625 + int cmp = pkg_compare_versions(old_pkg, pkg);
4628 + memset(message_out,'\x0',15);
4629 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4630 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4631 + cmp = -1 ; /* then we force ipkg to downgrade */
4632 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4633 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4637 + ipkg_message(conf, IPKG_NOTICE,
4638 + "Not downgrading package %s on %s from %s to %s.\n",
4639 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4641 + } else if (cmp < 0) {
4642 + ipkg_message(conf, IPKG_NOTICE,
4643 + "%s%s on %s from %s to %s...\n",
4644 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4645 + pkg->dest = old_pkg->dest;
4647 + } else /* cmp == 0 */ {
4648 + if (conf->force_reinstall) {
4649 + ipkg_message(conf, IPKG_NOTICE,
4650 + "Reinstalling %s (%s) on %s...\n",
4651 + pkg->name, new_version, old_pkg->dest->name);
4652 + pkg->dest = old_pkg->dest;
4655 + ipkg_message(conf, IPKG_NOTICE,
4656 + "Not installing %s (%s) on %s -- already installed.\n",
4657 + pkg->name, new_version, old_pkg->dest->name);
4661 + free(old_version);
4662 + free(new_version);
4665 + char message_out[15] ;
4666 + memset(message_out,'\x0',15);
4668 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4670 + strncpy( message_out,"Installing ",strlen("Installing ") );
4671 + char *version = pkg_version_str_alloc(pkg);
4673 + ipkg_message(conf, IPKG_NOTICE,
4674 + "%s%s (%s) to %s...\n", message_out,
4675 + pkg->name, version, pkg->dest->name);
4681 +/* and now the meat... */
4682 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4686 + pkg_t *old_pkg = NULL;
4687 + pkg_vec_t *replacees;
4688 + abstract_pkg_t *ab_pkg = NULL;
4689 + int old_state_flag;
4693 + if ( from_upgrade )
4694 + message = 1; /* Coming from an upgrade, and should change the output message */
4697 + ipkg_message(conf, IPKG_ERROR,
4698 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4702 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4704 + if (!pkg_arch_supported(conf, pkg)) {
4705 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4706 + pkg->architecture, pkg->name);
4709 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4710 + err = satisfy_dependencies_for(conf, pkg);
4711 + if (err) { return err; }
4713 + ipkg_message(conf, IPKG_NOTICE,
4714 + "Package %s is already installed in %s.\n",
4715 + pkg->name, pkg->dest->name);
4719 + if (pkg->dest == NULL) {
4720 + pkg->dest = conf->default_dest;
4723 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4725 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4726 + if (err) { return err; }
4728 + pkg->state_want = SW_INSTALL;
4730 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4734 + /* Abhaya: conflicts check */
4735 + err = check_conflicts_for(conf, pkg);
4736 + if (err) { return err; }
4738 + /* this setup is to remove the upgrade scenario in the end when
4739 + installing pkg A, A deps B & B deps on A. So both B and A are
4740 + installed. Then A's installation is started resulting in an
4741 + uncecessary upgrade */
4742 + if (pkg->state_status == SS_INSTALLED
4743 + && conf->force_reinstall == 0) return 0;
4745 + err = verify_pkg_installable(conf, pkg);
4746 + if (err) { return err; }
4748 + if (pkg->local_filename == NULL) {
4749 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4751 + ipkg_message(conf, IPKG_ERROR,
4752 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4758 +/* Check for md5 values */
4761 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4762 + if (strcmp(file_md5, pkg->md5sum))
4764 + ipkg_message(conf, IPKG_ERROR,
4765 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4773 + if (pkg->tmp_unpack_dir == NULL) {
4774 + unpack_pkg_control_files(conf, pkg);
4777 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4778 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4779 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4780 + err = update_file_ownership(conf, pkg, old_pkg);
4781 + if (err) { return err; }
4783 + if (conf->nodeps == 0) {
4784 + err = satisfy_dependencies_for(conf, pkg);
4785 + if (err) { return err; }
4788 + replacees = pkg_vec_alloc();
4789 + pkg_get_installed_replacees(conf, pkg, replacees);
4791 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4793 + sigset_t newset, oldset;
4794 + sighandler_t old_handler = NULL;
4795 + int use_signal = 0;
4796 + caught_sigint = 0;
4798 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4800 + sigemptyset(&newset);
4801 + sigaddset(&newset, SIGINT);
4802 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4805 + ipkg_state_changed++;
4806 + pkg->state_flag |= SF_FILELIST_CHANGED;
4808 + /* XXX: BUG: we really should treat replacement more like an upgrade
4809 + * Instead, we're going to remove the replacees
4811 + err = pkg_remove_installed_replacees(conf, replacees);
4812 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4814 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4815 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4817 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4818 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4820 + err = preinst_configure(conf, pkg, old_pkg);
4821 + if (err) goto UNWIND_PREINST_CONFIGURE;
4823 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4824 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4826 + err = check_data_file_clashes(conf, pkg, old_pkg);
4827 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4829 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4830 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4832 + if (conf->noaction) return 0;
4834 + /* point of no return: no unwinding after this */
4835 + if (old_pkg && !conf->force_reinstall) {
4836 + old_pkg->state_want = SW_DEINSTALL;
4838 + if (old_pkg->state_flag & SF_NOPRUNE) {
4839 + ipkg_message(conf, IPKG_INFO,
4840 + " not removing obsolesced files because package marked noprune\n");
4842 + ipkg_message(conf, IPKG_INFO,
4843 + " removing obsolesced files\n");
4844 + remove_obsolesced_files(conf, pkg, old_pkg);
4846 + /* removing files from old package, to avoid ghost files */
4847 + remove_data_files_and_list(conf, old_pkg);
4848 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4849 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4850 + remove_postrm(conf, old_pkg);
4856 + ipkg_message(conf, IPKG_INFO,
4857 + " installing maintainer scripts\n");
4858 + install_maintainer_scripts(conf, pkg, old_pkg);
4860 + /* the following just returns 0 */
4861 + remove_disappeared(conf, pkg);
4863 + ipkg_message(conf, IPKG_INFO,
4864 + " installing data files\n");
4865 + install_data_files(conf, pkg);
4867 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4868 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4870 + ipkg_message(conf, IPKG_INFO,
4871 + " resolving conf files\n");
4872 + resolve_conffiles(conf, pkg);
4874 + pkg->state_status = SS_UNPACKED;
4875 + old_state_flag = pkg->state_flag;
4876 + pkg->state_flag &= ~SF_PREFER;
4877 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4879 + if (old_pkg && !conf->force_reinstall) {
4880 + old_pkg->state_status = SS_NOT_INSTALLED;
4883 + time(&pkg->installed_time);
4885 + ipkg_message(conf, IPKG_INFO,
4886 + " cleanup temp files\n");
4887 + cleanup_temporary_files(conf, pkg);
4889 + ab_pkg = pkg->parent;
4891 + ab_pkg->state_status = pkg->state_status;
4893 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4896 + signal(SIGINT, old_handler);
4898 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4903 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4904 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4905 + UNWIND_CHECK_DATA_FILE_CLASHES:
4906 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4907 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4908 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4909 + UNWIND_PREINST_CONFIGURE:
4910 + preinst_configure_unwind(conf, pkg, old_pkg);
4911 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4912 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4913 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4914 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4915 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4916 + pkg_remove_installed_replacees_unwind(conf, replacees);
4918 + ipkg_message(conf, IPKG_INFO,
4919 + " cleanup temp files\n");
4920 + cleanup_temporary_files(conf, pkg);
4922 + ipkg_message(conf, IPKG_INFO,
4925 + signal(SIGINT, old_handler);
4927 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4933 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4935 + /* DPKG_INCOMPATIBILITY:
4936 + dpkg does some things here that we don't do yet. Do we care?
4938 + 1. If a version of the package is already installed, call
4939 + old-prerm upgrade new-version
4940 + 2. If the script runs but exits with a non-zero exit status
4941 + new-prerm failed-upgrade old-version
4942 + Error unwind, for both the above cases:
4943 + old-postinst abort-upgrade new-version
4948 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4950 + /* DPKG_INCOMPATIBILITY:
4951 + dpkg does some things here that we don't do yet. Do we care?
4952 + (See prerm_upgrade_old_package for details)
4957 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4959 + /* DPKG_INCOMPATIBILITY:
4960 + dpkg does some things here that we don't do yet. Do we care?
4961 + 2. If a 'conflicting' package is being removed at the same time:
4962 + 1. If any packages depended on that conflicting package and
4963 + --auto-deconfigure is specified, call, for each such package:
4964 + deconfigured's-prerm deconfigure \
4965 + in-favour package-being-installed version \
4966 + removing conflicting-package version
4968 + deconfigured's-postinst abort-deconfigure \
4969 + in-favour package-being-installed-but-failed version \
4970 + removing conflicting-package version
4972 + The deconfigured packages are marked as requiring
4973 + configuration, so that if --install is used they will be
4974 + configured again if possible.
4975 + 2. To prepare for removal of the conflicting package, call:
4976 + conflictor's-prerm remove in-favour package new-version
4978 + conflictor's-postinst abort-remove in-favour package new-version
4983 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4985 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4986 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4991 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4994 + char *preinst_args;
4997 + char *old_version = pkg_version_str_alloc(old_pkg);
4998 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4999 + free(old_version);
5000 + } else if (pkg->state_status == SS_CONFIG_FILES) {
5001 + char *pkg_version = pkg_version_str_alloc(pkg);
5002 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
5003 + free(pkg_version);
5005 + preinst_args = strdup("install");
5008 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
5010 + ipkg_message(conf, IPKG_ERROR,
5011 + "Aborting installation of %s\n", pkg->name);
5015 + free(preinst_args);
5020 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5022 + /* DPKG_INCOMPATIBILITY:
5023 + dpkg does the following error unwind, should we?
5024 + pkg->postrm abort-upgrade old-version
5025 + OR pkg->postrm abort-install old-version
5026 + OR pkg->postrm abort-install
5031 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5034 + conffile_list_elt_t *iter;
5037 + if (conf->noaction) return 0;
5039 + /* Backup all modified conffiles */
5041 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
5045 + cf_name = root_filename_alloc(conf, cf->name);
5047 + /* Don't worry if the conffile is just plain gone */
5048 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
5049 + err = backup_make_backup(conf, cf_name);
5058 + /* Backup all conffiles that were not conffiles in old_pkg */
5059 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5062 + cf_name = root_filename_alloc(conf, cf->name);
5063 + /* Ignore if this was a conffile in old_pkg as well */
5064 + if (pkg_get_conffile(old_pkg, cf->name)) {
5068 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
5069 + err = backup_make_backup(conf, cf_name);
5080 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5082 + conffile_list_elt_t *iter;
5085 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
5086 + backup_remove(iter->data->name);
5090 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5091 + backup_remove(iter->data->name);
5098 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5100 + /* DPKG_INCOMPATIBILITY:
5101 + ipkg takes a slightly different approach than dpkg at this
5102 + point. dpkg installs each file in the new package while
5103 + creating a backup for any file that is replaced, (so that it
5104 + can unwind if necessary). To avoid complexity and redundant
5105 + storage, ipkg doesn't do any installation until later, (at the
5106 + point at which dpkg removes the backups.
5108 + But, we do have to check for data file clashes, since after
5109 + installing a package with a file clash, removing either of the
5110 + packages involved in the clash has the potential to break the
5113 + str_list_t *files_list;
5114 + str_list_elt_t *iter;
5118 + files_list = pkg_get_installed_files(pkg);
5119 + for (iter = files_list->head; iter; iter = iter->next) {
5120 + char *root_filename;
5121 + char *filename = iter->data;
5122 + root_filename = root_filename_alloc(conf, filename);
5123 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5126 + /* Pre-existing conffiles are OK */
5127 + /* @@@@ should have way to check that it is a conffile -Jamey */
5128 + if (backup_exists_for(root_filename)) {
5132 + /* Pre-existing files are OK if force-overwrite was asserted. */
5133 + if (conf->force_overwrite) {
5134 + /* but we need to change who owns this file */
5135 + file_hash_set_file_owner(conf, filename, pkg);
5139 + owner = file_hash_get_file_owner(conf, filename);
5141 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
5142 + if (owner && old_pkg) {
5143 + if (strcmp(owner->name, old_pkg->name) == 0) {
5148 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5150 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5151 + if (pkg_replaces(pkg, owner)) {
5154 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5155 + then it's ok to overwrite. */
5156 + if (strcmp(owner->name,pkg->name)==0){
5157 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5162 + /* Pre-existing files are OK if they are obsolete */
5163 + obs = hash_table_get(&conf->obs_file_hash, filename);
5165 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5169 + /* We have found a clash. */
5170 + ipkg_message(conf, IPKG_ERROR,
5171 + "Package %s wants to install file %s\n"
5172 + "\tBut that file is already provided by package ",
5173 + pkg->name, filename);
5175 + ipkg_message(conf, IPKG_ERROR,
5176 + "%s\n", owner->name);
5178 + ipkg_message(conf, IPKG_ERROR,
5179 + "<no package>\nPlease move this file out of the way and try again.\n");
5183 + free(root_filename);
5185 + pkg_free_installed_files(pkg);
5190 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5192 + /* Basically that's the worst hack I could do to be able to change ownership of
5193 + file list, but, being that we have no way to unwind the mods, due to structure
5194 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5195 + What we do here is change the ownership of file in hash if a replace ( or similar events
5197 + Only the action that are needed to change name should be considered.
5198 + @@@ To change after 1.0 release.
5200 + str_list_t *files_list;
5201 + str_list_elt_t *iter;
5205 + files_list = pkg_get_installed_files(pkg);
5206 + for (iter = files_list->head; iter; iter = iter->next) {
5207 + char *root_filename;
5208 + char *filename = iter->data;
5209 + root_filename = root_filename_alloc(conf, filename);
5210 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5213 + if (conf->force_overwrite) {
5214 + /* but we need to change who owns this file */
5215 + file_hash_set_file_owner(conf, filename, pkg);
5219 + owner = file_hash_get_file_owner(conf, filename);
5221 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5223 + if (pkg_replaces(pkg, owner)) {
5224 +/* It's now time to change the owner of that file.
5225 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5226 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5227 + file_hash_set_file_owner(conf, filename, pkg);
5233 + free(root_filename);
5235 + pkg_free_installed_files(pkg);
5240 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5242 + /* Nothing to do since check_data_file_clashes doesn't change state */
5246 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5248 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5249 + 1. If the package is being upgraded, call
5250 + old-postrm upgrade new-version
5251 + 2. If this fails, attempt:
5252 + new-postrm failed-upgrade old-version
5253 + Error unwind, for both cases:
5254 + old-preinst abort-upgrade new-version */
5258 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5260 + /* DPKG_INCOMPATIBILITY:
5261 + dpkg does some things here that we don't do yet. Do we care?
5262 + (See postrm_upgrade_old_pkg for details)
5267 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5270 + str_list_t *old_files;
5271 + str_list_elt_t *of;
5272 + str_list_t *new_files;
5273 + str_list_elt_t *nf;
5275 + if (old_pkg == NULL) {
5279 + old_files = pkg_get_installed_files(old_pkg);
5280 + new_files = pkg_get_installed_files(pkg);
5282 + for (of = old_files->head; of; of = of->next) {
5286 + for (nf = new_files->head; nf; nf = nf->next) {
5288 + if (strcmp(old, new) == 0) {
5289 + goto NOT_OBSOLETE;
5292 + if (file_is_dir(old)) {
5295 + owner = file_hash_get_file_owner(conf, old);
5296 + if (owner != old_pkg) {
5297 + /* in case obsolete file no longer belongs to old_pkg */
5301 + /* old file is obsolete */
5302 + ipkg_message(conf, IPKG_INFO,
5303 + " removing obsolete file %s\n", old);
5304 + if (!conf->noaction) {
5305 + err = unlink(old);
5307 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5316 + pkg_free_installed_files(old_pkg);
5317 + pkg_free_installed_files(pkg);
5322 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5326 + char *globpattern;
5330 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5333 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5334 + err = glob(globpattern, 0, NULL, &globbuf);
5335 + free(globpattern);
5339 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5340 + for (i = 0; i < globbuf.gl_pathc; i++) {
5341 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5342 + globbuf.gl_pathv[i], old_pkg->name);
5343 + if (!conf->noaction)
5344 + unlink(globbuf.gl_pathv[i]);
5346 + globfree(&globbuf);
5351 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5357 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5358 + sprintf_alloc(&prefix, "%s.", pkg->name);
5359 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5360 + pkg->dest->info_dir,
5366 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5368 + /* DPKG_INCOMPATIBILITY:
5369 + This is a fairly sophisticated dpkg operation. Shall we
5372 + /* Any packages all of whose files have been overwritten during the
5373 + installation, and which aren't required for dependencies, are
5374 + considered to have been removed. For each such package
5375 + 1. disappearer's-postrm disappear overwriter overwriter-version
5376 + 2. The package's maintainer scripts are removed
5377 + 3. It is noted in the status database as being in a sane state,
5378 + namely not installed (any conffiles it may have are ignored,
5379 + rather than being removed by dpkg). Note that disappearing
5380 + packages do not have their prerm called, because dpkg doesn't
5381 + know in advance that the package is going to vanish.
5386 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5390 + /* ipkg takes a slightly different approach to data file backups
5391 + than dpkg. Rather than removing backups at this point, we
5392 + actually do the data file installation now. See comments in
5393 + check_data_file_clashes() for more details. */
5395 + ipkg_message(conf, IPKG_INFO,
5396 + " extracting data files to %s\n", pkg->dest->root_dir);
5397 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5402 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5403 + so we can't save ourself from removing important packages
5404 + At this point we (should) have extracted the .control file, so it
5405 + would be a good idea to reload the data in it, and set the Essential
5406 + state in *pkg. From now on the Essential is back in status file and
5407 + we can protect again.
5408 + We should operate this way:
5409 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5410 + check for "Essential" in it
5411 + set the value in pkg->essential.
5412 + This new routine could be useful also for every other flag
5413 + Pigi: 16/03/2004 */
5414 + set_flags_from_control(conf, pkg) ;
5416 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5417 + err = pkg_write_filelist(conf, pkg);
5421 + /* XXX: FEATURE: ipkg should identify any files which existed
5422 + before installation and which were overwritten, (see
5423 + check_data_file_clashes()). What it must do is remove any such
5424 + files from the filelist of the old package which provided the
5425 + file. Otherwise, if the old package were removed at some point
5426 + it would break the new package. Removing the new package will
5427 + also break the old one, but this cannot be helped since the old
5428 + package's file has already been deleted. This is the importance
5429 + of check_data_file_clashes(), and only allowing ipkg to install
5430 + a clashing package with a user force. */
5435 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5437 + conffile_list_elt_t *iter;
5444 + if (conf->noaction) return 0;
5446 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5447 + char *root_filename;
5449 + root_filename = root_filename_alloc(conf, cf->name);
5451 + /* Might need to initialize the md5sum for each conffile */
5452 + if (cf->value == NULL) {
5453 + cf->value = file_md5sum_alloc(root_filename);
5456 + if (!file_exists(root_filename)) {
5457 + free(root_filename);
5461 + cf_backup = backup_filename_alloc(root_filename);
5464 + if (file_exists(cf_backup)) {
5465 + /* Let's compute md5 to test if files are changed */
5466 + md5sum = file_md5sum_alloc(cf_backup);
5467 + if (strcmp( cf->value,md5sum) != 0 ) {
5468 + if (conf->force_defaults
5469 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5470 + rename(cf_backup, root_filename);
5473 + unlink(cf_backup);
5478 + free(root_filename);
5484 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5487 + const char *short_file_name;
5489 + short_file_name = strrchr(file_name, '/');
5490 + if (short_file_name) {
5491 + short_file_name++;
5493 + short_file_name = file_name;
5497 + response = get_user_response(" Configuration file '%s'\n"
5498 + " ==> File on system created by you or by a script.\n"
5499 + " ==> File also in package provided by package maintainer.\n"
5500 + " What would you like to do about it ? Your options are:\n"
5501 + " Y or I : install the package maintainer's version\n"
5502 + " N or O : keep your currently-installed version\n"
5503 + " D : show the differences between the versions (if diff is installed)\n"
5504 + " The default action is to keep your current version.\n"
5505 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5506 + if (strcmp(response, "y") == 0
5507 + || strcmp(response, "i") == 0
5508 + || strcmp(response, "yes") == 0) {
5513 + if (strcmp(response, "d") == 0) {
5517 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5518 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5521 + printf(" [Press ENTER to continue]\n");
5522 + response = file_read_line_alloc(stdin);
5532 +/* XXX: CLEANUP: I'd like to move all of the code for
5533 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5534 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5535 + pkg_deinit for example). */
5536 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5539 + struct dirent *dirent;
5542 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5544 + ipkg_message(conf, IPKG_DEBUG,
5545 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5546 + __FUNCTION__, pkg->tmp_unpack_dir);
5550 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5551 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5554 + dirent = readdir(tmp_dir);
5555 + if (dirent == NULL) {
5558 + sprintf_alloc(&tmp_file, "%s/%s",
5559 + pkg->tmp_unpack_dir, dirent->d_name);
5560 + if (! file_is_dir(tmp_file)) {
5565 + closedir(tmp_dir);
5566 + rmdir(pkg->tmp_unpack_dir);
5567 + free(pkg->tmp_unpack_dir);
5568 + pkg->tmp_unpack_dir = NULL;
5572 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5573 + pkg->name, pkg->local_filename, conf->tmp_dir);
5574 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5575 + unlink(pkg->local_filename);
5576 + free(pkg->local_filename);
5577 + pkg->local_filename = NULL;
5583 +static char *backup_filename_alloc(const char *file_name)
5587 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5592 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5597 + backup = backup_filename_alloc(file_name);
5598 + err = file_copy(file_name, backup);
5600 + ipkg_message(conf, IPKG_ERROR,
5601 + "%s: Failed to copy %s to %s\n",
5602 + __FUNCTION__, file_name, backup);
5610 +static int backup_exists_for(const char *file_name)
5615 + backup = backup_filename_alloc(file_name);
5617 + ret = file_exists(backup);
5624 +static int backup_remove(const char *file_name)
5628 + backup = backup_filename_alloc(file_name);
5637 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5639 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5641 + /* first, remove the packages that need removing */
5642 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5643 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5644 + err = ipkg_remove_pkg(conf, pkg,0);
5645 + if (err) return err;
5650 +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)
5653 + /* now one more pass checking on the ones that need to be installed */
5654 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5655 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5656 + if (pkg->dest == NULL)
5657 + pkg->dest = conf->default_dest;
5659 + pkg->state_want = SW_INSTALL;
5661 + /* Abhaya: conflicts check */
5662 + err = check_conflicts_for(conf, pkg);
5663 + if (err) { return err; }
5668 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5671 + /* now one more pass checking on the ones that need to be installed */
5672 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5673 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5675 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5676 + pkg_vec_t *replacees = pkg_vec_alloc();
5677 + pkg_get_installed_replacees(conf, pkg, replacees);
5679 + /* XXX: BUG: we really should treat replacement more like an upgrade
5680 + * Instead, we're going to remove the replacees
5682 + err = pkg_remove_installed_replacees(conf, replacees);
5683 + if (err) return err;
5684 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5689 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5692 + /* now one more pass checking on the ones that need to be installed */
5693 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5694 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5695 + if (pkg->local_filename == NULL) {
5696 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5698 + ipkg_message(conf, IPKG_ERROR,
5699 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5704 + if (pkg->tmp_unpack_dir == NULL) {
5705 + err = unpack_pkg_control_files(conf, pkg);
5706 + if (err) return err;
5712 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5715 + /* now one more pass checking on the ones that need to be installed */
5716 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5717 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5718 + pkg_t *old_pkg = pkg->old_pkg;
5720 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5721 + if (err) return err;
5723 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5724 + if (err) return err;
5726 + err = preinst_configure(conf, pkg, old_pkg);
5727 + if (err) return err;
5729 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5730 + if (err) return err;
5732 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5733 + if (err) return err;
5738 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5741 + /* now one more pass checking on the ones that need to be installed */
5742 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5743 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5744 + pkg_t *old_pkg = pkg->old_pkg;
5747 + old_pkg->state_want = SW_DEINSTALL;
5749 + if (old_pkg->state_flag & SF_NOPRUNE) {
5750 + ipkg_message(conf, IPKG_INFO,
5751 + " not removing obsolesced files because package marked noprune\n");
5753 + ipkg_message(conf, IPKG_INFO,
5754 + " removing obsolesced files\n");
5755 + remove_obsolesced_files(conf, pkg, old_pkg);
5759 + ipkg_message(conf, IPKG_INFO,
5760 + " installing maintainer scripts\n");
5761 + install_maintainer_scripts(conf, pkg, old_pkg);
5763 + /* the following just returns 0 */
5764 + remove_disappeared(conf, pkg);
5766 + ipkg_message(conf, IPKG_INFO,
5767 + " installing data files\n");
5768 + install_data_files(conf, pkg);
5770 + ipkg_message(conf, IPKG_INFO,
5771 + " resolving conf files\n");
5772 + resolve_conffiles(conf, pkg);
5774 + pkg->state_status = SS_UNPACKED;
5777 + old_pkg->state_status = SS_NOT_INSTALLED;
5780 + time(&pkg->installed_time);
5782 + ipkg_message(conf, IPKG_INFO,
5783 + " cleanup temp files\n");
5784 + cleanup_temporary_files(conf, pkg);
5787 + pkg->parent->state_status = pkg->state_status;
5792 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5795 + /* now one more pass checking on the ones that need to be installed */
5796 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5797 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5798 + pkg_t *old_pkg = pkg->old_pkg;
5801 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5802 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5803 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5804 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5805 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5806 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5807 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5808 + preinst_configure_unwind(conf, pkg, old_pkg);
5809 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5810 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5811 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5812 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5814 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5815 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5823 + * Perform all the actions.
5825 + * pkgs_to_remove are packages marked for removal.
5826 + * pkgs_superseded are the old packages being replaced by upgrades.
5828 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5830 +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)
5835 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5836 + if (err) return err;
5838 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5839 + if (err) return err;
5841 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5842 + if (err) goto UNWIND;
5844 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5845 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5846 + if (err) goto UNWIND;
5849 + * Now that we have the packages unpacked, we can look for data
5850 + * file clashes. First, we mark the files from the superseded
5851 + * packages as obsolete. Then we scan the files in
5852 + * pkgs_to_install, and only complain about clashes with
5853 + * non-obsolete files.
5856 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5857 + if (err) goto UNWIND;
5859 + /* this was before checking data file clashes */
5860 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5861 + if (err) goto UNWIND;
5863 + /* point of no return: no unwinding after this */
5864 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5865 + if (err) return err;
5867 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5871 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5873 + ipkg_message(conf, IPKG_INFO,
5874 + " cleanup temp files\n");
5875 + cleanup_temporary_files(conf, pkg);
5877 + ipkg_message(conf, IPKG_INFO,
5883 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_install.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.h
5884 --- busybox-1.1.2-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5885 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-05-09 02:12:04.000000000 +0200
5887 +/* ipkg_install.h - the itsy package management system
5891 + Copyright (C) 2001 University of Southern California
5893 + This program is free software; you can redistribute it and/or
5894 + modify it under the terms of the GNU General Public License as
5895 + published by the Free Software Foundation; either version 2, or (at
5896 + your option) any later version.
5898 + This program is distributed in the hope that it will be useful, but
5899 + WITHOUT ANY WARRANTY; without even the implied warranty of
5900 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5901 + General Public License for more details.
5904 +#ifndef IPKG_INSTALL_H
5905 +#define IPKG_INSTALL_H
5908 +#include "ipkg_conf.h"
5910 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5911 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5912 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5913 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5914 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5916 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5918 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5919 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5922 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_message.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.c
5923 --- busybox-1.1.2-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5924 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-05-09 02:06:48.000000000 +0200
5926 +/* ipkg_message.c - the itsy package management system
5928 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5930 + This program is free software; you can redistribute it and/or
5931 + modify it under the terms of the GNU General Public License as
5932 + published by the Free Software Foundation; either version 2, or (at
5933 + your option) any later version.
5935 + This program is distributed in the hope that it will be useful, but
5936 + WITHOUT ANY WARRANTY; without even the implied warranty of
5937 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5938 + General Public License for more details.
5943 +#include "ipkg_conf.h"
5944 +#include "ipkg_message.h"
5949 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5953 + if (conf && (conf->verbosity < level))
5960 + va_start (ap, fmt);
5961 + vprintf (fmt, ap);
5968 +#include "libipkg.h"
5970 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5973 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5978 + if (ipkg_cb_message)
5980 + va_start (ap, fmt);
5981 + vsnprintf (ts,256,fmt, ap);
5983 + ipkg_cb_message(conf,level,ts);
5987 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_message.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.h
5988 --- busybox-1.1.2-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5989 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-05-09 02:06:48.000000000 +0200
5991 +/* ipkg_message.h - the itsy package management system
5993 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5995 + This program is free software; you can redistribute it and/or
5996 + modify it under the terms of the GNU General Public License as
5997 + published by the Free Software Foundation; either version 2, or (at
5998 + your option) any later version.
6000 + This program is distributed in the hope that it will be useful, but
6001 + WITHOUT ANY WARRANTY; without even the implied warranty of
6002 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6003 + General Public License for more details.
6006 +#ifndef _IPKG_MESSAGE_H_
6007 +#define _IPKG_MESSAGE_H_
6010 +#include "ipkg_conf.h"
6013 + IPKG_ERROR, /* error conditions */
6014 + IPKG_NOTICE, /* normal but significant condition */
6015 + IPKG_INFO, /* informational message */
6016 + IPKG_DEBUG, /* debug level message */
6017 + IPKG_DEBUG2, /* more debug level message */
6020 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
6022 +#endif /* _IPKG_MESSAGE_H_ */
6023 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_remove.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.c
6024 --- busybox-1.1.2-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
6025 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-05-09 02:12:04.000000000 +0200
6027 +/* ipkg_remove.c - the itsy package management system
6031 + Copyright (C) 2001 University of Southern California
6033 + This program is free software; you can redistribute it and/or
6034 + modify it under the terms of the GNU General Public License as
6035 + published by the Free Software Foundation; either version 2, or (at
6036 + your option) any later version.
6038 + This program is distributed in the hope that it will be useful, but
6039 + WITHOUT ANY WARRANTY; without even the implied warranty of
6040 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6041 + General Public License for more details.
6045 +#include "ipkg_message.h"
6049 +#include "ipkg_remove.h"
6051 +#include "file_util.h"
6052 +#include "sprintf_alloc.h"
6053 +#include "str_util.h"
6055 +#include "ipkg_cmd.h"
6058 + * Returns number of the number of packages depending on the packages provided by this package.
6059 + * Every package implicitly provides itself.
6061 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
6063 + int nprovides = pkg->provides_count;
6064 + abstract_pkg_t **provides = pkg->provides;
6065 + int n_installed_dependents = 0;
6067 + for (i = 0; i <= nprovides; i++) {
6068 + abstract_pkg_t *providee = provides[i];
6069 + abstract_pkg_t **dependers = providee->depended_upon_by;
6070 + abstract_pkg_t *dep_ab_pkg;
6071 + if (dependers == NULL)
6073 + while ((dep_ab_pkg = *dependers++) != NULL) {
6074 + if (dep_ab_pkg->state_status == SS_INSTALLED){
6075 + n_installed_dependents++;
6080 + /* if caller requested the set of installed dependents */
6081 + if (pdependents) {
6083 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
6085 + if ( dependents == NULL ){
6086 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
6090 + *pdependents = dependents;
6091 + for (i = 0; i <= nprovides; i++) {
6092 + abstract_pkg_t *providee = provides[i];
6093 + abstract_pkg_t **dependers = providee->depended_upon_by;
6094 + abstract_pkg_t *dep_ab_pkg;
6095 + if (dependers == NULL)
6097 + while ((dep_ab_pkg = *dependers++) != NULL) {
6098 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
6099 + dependents[p++] = dep_ab_pkg;
6100 + dep_ab_pkg->state_flag |= SF_MARKED;
6104 + dependents[p] = NULL;
6105 + /* now clear the marks */
6106 + for (i = 0; i < p; i++) {
6107 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6108 + dep_ab_pkg->state_flag &= ~SF_MARKED;
6111 + return n_installed_dependents;
6114 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
6119 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
6120 + abstract_pkg_t * ab_pkg;
6122 + if((ab_pkg = pkg->parent) == NULL){
6123 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
6124 + __FUNCTION__, pkg->name);
6128 + if (dependents == NULL)
6131 + // here i am using the dependencies_checked
6132 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
6133 + return 0; // has already been encountered in the process
6134 + // of marking packages for removal - Karthik
6135 + ab_pkg->dependencies_checked = 2;
6139 + while (dependents [i] != NULL) {
6140 + abstract_pkg_t *dep_ab_pkg = dependents[i];
6142 + if (dep_ab_pkg->dependencies_checked == 2){
6146 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
6147 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
6148 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6149 + if (dep_pkg->state_status == SS_INSTALLED) {
6150 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6156 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6157 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6164 + for (i = 0; i < dependent_pkgs->len; i++) {
6165 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6172 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6174 + abstract_pkg_t *dep_ab_pkg;
6175 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6176 + while ((dep_ab_pkg = *dependents++) != NULL) {
6177 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6178 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6180 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6181 + ipkg_message(conf, IPKG_ERROR, "");
6182 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6183 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6184 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6185 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6186 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6190 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6192 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6193 + thus I wan't check for essential, as I'm upgrading.
6194 + I hope it won't break anything :)
6197 + abstract_pkg_t *parent_pkg = NULL;
6199 + if (pkg->essential && !message) {
6200 + if (conf->force_removal_of_essential_packages) {
6201 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6202 + "\tIf your system breaks, you get to keep both pieces\n",
6205 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6206 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6207 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6208 + "\tits will with the option: -force-removal-of-essential-packages\n",
6210 + return IPKG_PKG_IS_ESSENTIAL;
6214 + if ((parent_pkg = pkg->parent) == NULL)
6217 + /* only attempt to remove dependent installed packages if
6218 + * force_depends is not specified or the package is being
6221 + if (!conf->force_depends
6222 + && !(pkg->state_flag & SF_REPLACE)) {
6223 + abstract_pkg_t **dependents;
6224 + int has_installed_dependents =
6225 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6227 + if (has_installed_dependents) {
6229 + * if this package is depended up by others, then either we should
6230 + * not remove it or we should remove it and all of its dependents
6233 + if (!conf->force_removal_of_dependent_packages
6234 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6235 + return IPKG_PKG_HAS_DEPENDENTS;
6238 + /* remove packages depending on this package - Karthik */
6239 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6241 + if (err) return err;
6245 + if ( message==0 ){
6246 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6249 + pkg->state_flag |= SF_FILELIST_CHANGED;
6251 + pkg->state_want = SW_DEINSTALL;
6252 + ipkg_state_changed++;
6254 + pkg_run_script(conf, pkg, "prerm", "remove");
6256 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6257 + maintains an empty filelist rather than deleting it. That seems
6258 + like a big pain, and I don't see that that should make a big
6259 + difference, but for anyone who wants tighter compatibility,
6260 + feel free to fix this. */
6261 + remove_data_files_and_list(conf, pkg);
6263 + pkg_run_script(conf, pkg, "postrm", "remove");
6265 + remove_maintainer_scripts_except_postrm(conf, pkg);
6267 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6268 + * space, it doesn't make sense to leave extra configurations, files,
6269 + * and maintainer scripts left around. So, we make remove like purge,
6270 + * and take out all the crap :) */
6272 + remove_postrm(conf, pkg);
6273 + pkg->state_status = SS_NOT_INSTALLED;
6276 + parent_pkg->state_status = SS_NOT_INSTALLED;
6281 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6283 + ipkg_remove_pkg(conf, pkg,0);
6287 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6289 + str_list_t installed_dirs;
6290 + str_list_t *installed_files;
6291 + str_list_elt_t *iter;
6293 + conffile_t *conffile;
6294 + int removed_a_dir;
6297 + str_list_init(&installed_dirs);
6298 + installed_files = pkg_get_installed_files(pkg);
6300 + for (iter = installed_files->head; iter; iter = iter->next) {
6301 + file_name = iter->data;
6303 + if (file_is_dir(file_name)) {
6304 + str_list_append(&installed_dirs, strdup(file_name));
6308 + conffile = pkg_get_conffile(pkg, file_name);
6310 + /* XXX: QUESTION: Is this right? I figure we only need to
6311 + save the conffile if it has been modified. Is that what
6312 + dpkg does? Or does dpkg preserve all conffiles? If so,
6313 + this seems like a better thing to do to conserve
6315 + if (conffile_has_been_modified(conf, conffile)) {
6316 + printf(" not deleting modified conffile %s\n", file_name);
6322 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6323 + if (!conf->noaction)
6324 + unlink(file_name);
6327 + if (!conf->noaction) {
6329 + removed_a_dir = 0;
6330 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6331 + file_name = iter->data;
6333 + if (rmdir(file_name) == 0) {
6334 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6335 + removed_a_dir = 1;
6336 + str_list_remove(&installed_dirs, &iter);
6339 + } while (removed_a_dir);
6342 + pkg_free_installed_files(pkg);
6343 + /* We have to remove the file list now, so that
6344 + find_pkg_owning_file does not always just report this package */
6345 + pkg_remove_installed_files_list(conf, pkg);
6347 + /* Don't print warning for dirs that are provided by other packages */
6348 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6349 + file_name = iter->data;
6351 + owner = file_hash_get_file_owner(conf, file_name);
6354 + iter->data = NULL;
6355 + str_list_remove(&installed_dirs, &iter);
6360 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6362 + iter->data = NULL;
6364 + str_list_deinit(&installed_dirs);
6369 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6372 + char *globpattern;
6375 + if (conf->noaction) return 0;
6377 + sprintf_alloc(&globpattern, "%s/%s.*",
6378 + pkg->dest->info_dir, pkg->name);
6379 + err = glob(globpattern, 0, NULL, &globbuf);
6380 + free(globpattern);
6385 + for (i = 0; i < globbuf.gl_pathc; i++) {
6386 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6389 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6390 + unlink(globbuf.gl_pathv[i]);
6392 + globfree(&globbuf);
6397 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6399 + char *postrm_file_name;
6401 + if (conf->noaction) return 0;
6403 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6404 + pkg->dest->info_dir, pkg->name);
6405 + unlink(postrm_file_name);
6406 + free(postrm_file_name);
6410 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_remove.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.h
6411 --- busybox-1.1.2-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6412 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-05-09 02:12:04.000000000 +0200
6414 +/* ipkg_remove.h - the itsy package management system
6418 + Copyright (C) 2001 University of Southern California
6420 + This program is free software; you can redistribute it and/or
6421 + modify it under the terms of the GNU General Public License as
6422 + published by the Free Software Foundation; either version 2, or (at
6423 + your option) any later version.
6425 + This program is distributed in the hope that it will be useful, but
6426 + WITHOUT ANY WARRANTY; without even the implied warranty of
6427 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6428 + General Public License for more details.
6431 +#ifndef IPKG_REMOVE_H
6432 +#define IPKG_REMOVE_H
6435 +#include "ipkg_conf.h"
6437 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6438 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6439 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6440 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6441 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6442 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6443 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6447 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c
6448 --- busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6449 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-05-09 02:12:04.000000000 +0200
6451 +/* ipkg_upgrade.c - the itsy package management system
6454 + Copyright (C) 2001 University of Southern California
6456 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6458 + This program is free software; you can redistribute it and/or
6459 + modify it under the terms of the GNU General Public License as
6460 + published by the Free Software Foundation; either version 2, or (at
6461 + your option) any later version.
6463 + This program is distributed in the hope that it will be useful, but
6464 + WITHOUT ANY WARRANTY; without even the implied warranty of
6465 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6466 + General Public License for more details.
6470 +#include "ipkg_install.h"
6471 +#include "ipkg_message.h"
6473 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6477 + char *old_version, *new_version;
6479 + if (old->state_flag & SF_HOLD) {
6480 + ipkg_message(conf, IPKG_NOTICE,
6481 + "Not upgrading package %s which is marked "
6482 + "hold (flags=%#x)\n", old->name, old->state_flag);
6486 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6487 + if (new == NULL) {
6488 + old_version = pkg_version_str_alloc(old);
6489 + ipkg_message(conf, IPKG_NOTICE,
6490 + "Assuming locally installed package %s (%s) "
6491 + "is up to date.\n", old->name, old_version);
6492 + free(old_version);
6496 + old_version = pkg_version_str_alloc(old);
6497 + new_version = pkg_version_str_alloc(new);
6499 + cmp = pkg_compare_versions(old, new);
6500 + ipkg_message(conf, IPKG_DEBUG,
6501 + "comparing visible versions of pkg %s:"
6502 + "\n\t%s is installed "
6503 + "\n\t%s is available "
6504 + "\n\t%d was comparison result\n",
6505 + old->name, old_version, new_version, cmp);
6507 + ipkg_message(conf, IPKG_INFO,
6508 + "Package %s (%s) installed in %s is up to date.\n",
6509 + old->name, old_version, old->dest->name);
6510 + free(old_version);
6511 + free(new_version);
6513 + } else if (cmp > 0) {
6514 + ipkg_message(conf, IPKG_NOTICE,
6515 + "Not downgrading package %s on %s from %s to %s.\n",
6516 + old->name, old->dest->name, old_version, new_version);
6517 + free(old_version);
6518 + free(new_version);
6520 + } else if (cmp < 0) {
6521 + new->dest = old->dest;
6522 + old->state_want = SW_DEINSTALL;
6525 + new->state_flag |= SF_USER;
6526 + return ipkg_install_pkg(conf, new,1);
6528 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h
6529 --- busybox-1.1.2-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6530 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-05-09 02:06:48.000000000 +0200
6532 +/* ipkg_upgrade.c - the itsy package management system
6534 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6536 + This program is free software; you can redistribute it and/or
6537 + modify it under the terms of the GNU General Public License as
6538 + published by the Free Software Foundation; either version 2, or (at
6539 + your option) any later version.
6541 + This program is distributed in the hope that it will be useful, but
6542 + WITHOUT ANY WARRANTY; without even the implied warranty of
6543 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6544 + General Public License for more details.
6549 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6550 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_utils.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.c
6551 --- busybox-1.1.2-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6552 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-05-09 02:06:48.000000000 +0200
6554 +/* ipkg_utils.c - the itsy package management system
6558 + Copyright (C) 2002 Compaq Computer Corporation
6560 + This program is free software; you can redistribute it and/or
6561 + modify it under the terms of the GNU General Public License as
6562 + published by the Free Software Foundation; either version 2, or (at
6563 + your option) any later version.
6565 + This program is distributed in the hope that it will be useful, but
6566 + WITHOUT ANY WARRANTY; without even the implied warranty of
6567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6568 + General Public License for more details.
6574 +#include <sys/vfs.h>
6576 +#include "ipkg_utils.h"
6578 +#include "pkg_hash.h"
6580 +struct errlist* error_list;
6582 +int get_available_blocks(char * filesystem)
6584 + struct statfs sfs;
6586 + if(statfs(filesystem, &sfs)){
6587 + fprintf(stderr, "bad statfs\n");
6590 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6591 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6594 +char **read_raw_pkgs_from_file(const char *file_name)
6599 + if(!(fp = fopen(file_name, "r"))){
6600 + fprintf(stderr, "can't get %s open for read\n", file_name);
6604 + ret = read_raw_pkgs_from_stream(fp);
6611 +char **read_raw_pkgs_from_stream(FILE *fp)
6613 + char **raw = NULL, *buf, *scout;
6615 + size_t size = 512;
6617 + buf = malloc (size);
6619 + while (fgets(buf, size, fp)) {
6620 + while (strlen (buf) == (size - 1)
6621 + && buf[size-2] != '\n') {
6622 + size_t o = size - 1;
6624 + buf = realloc (buf, size);
6625 + if (fgets (buf + o, size - o, fp) == NULL)
6630 + raw = realloc(raw, (count + 50) * sizeof(char *));
6632 + if((scout = strchr(buf, '\n')))
6635 + raw[count++] = strdup(buf);
6638 + raw = realloc(raw, (count + 1) * sizeof(char *));
6639 + raw[count] = NULL;
6646 +/* something to remove whitespace, a hash pooper */
6647 +char *trim_alloc(char *line)
6650 + char *dest, *src, *end;
6652 + new = malloc(strlen(line) + 1);
6653 + if ( new == NULL ){
6654 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6657 + dest = new, src = line, end = line + (strlen(line) - 1);
6659 + /* remove it from the front */
6664 + /* and now from the back */
6665 + while((end > src) &&
6671 + /* this does from the first space
6672 + * blasting away any versions stuff in depends
6683 +int line_is_blank(const char *line)
6687 + for (s = line; *s; s++) {
6694 +void push_error_list(struct errlist ** errors, char * msg){
6695 + struct errlist *err_lst_tmp;
6698 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6699 + err_lst_tmp->errmsg=strdup(msg) ;
6700 + err_lst_tmp->next = *errors;
6701 + *errors = err_lst_tmp;
6705 +void reverse_error_list(struct errlist **errors){
6706 + struct errlist *result=NULL;
6707 + struct errlist *current= *errors;
6708 + struct errlist *next;
6710 + while ( current != NULL ) {
6711 + next = current->next;
6712 + current->next=result;
6721 +void free_error_list(struct errlist **errors){
6722 + struct errlist *current = *errors;
6724 + while (current != NULL) {
6725 + free(current->errmsg);
6726 + current = (*errors)->next;
6728 + *errors = current;
6735 diff -ruN busybox-1.1.2-orig/archival/libipkg/ipkg_utils.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.h
6736 --- busybox-1.1.2-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6737 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-05-09 02:06:48.000000000 +0200
6739 +/* ipkg_utils.h - the itsy package management system
6743 + Copyright (C) 2002 Compaq Computer Corporation
6745 + This program is free software; you can redistribute it and/or
6746 + modify it under the terms of the GNU General Public License as
6747 + published by the Free Software Foundation; either version 2, or (at
6748 + your option) any later version.
6750 + This program is distributed in the hope that it will be useful, but
6751 + WITHOUT ANY WARRANTY; without even the implied warranty of
6752 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6753 + General Public License for more details.
6756 +#ifndef IPKG_UTILS_H
6757 +#define IPKG_UTILS_H
6761 +int get_available_blocks(char * filesystem);
6762 +char **read_raw_pkgs_from_file(const char *file_name);
6763 +char **read_raw_pkgs_from_stream(FILE *fp);
6764 +char *trim_alloc(char * line);
6765 +int line_is_blank(const char *line);
6768 diff -ruN busybox-1.1.2-orig/archival/libipkg/libipkg.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.c
6769 --- busybox-1.1.2-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6770 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-05-09 02:12:05.000000000 +0200
6772 +/* ipkglib.c - the itsy package management system
6776 + Copyright (C) 2003 kernel concepts
6778 + This program is free software; you can redistribute it and/or
6779 + modify it under the terms of the GNU General Public License as
6780 + published by the Free Software Foundation; either version 2, or (at
6781 + your option) any later version.
6783 + This program is distributed in the hope that it will be useful, but
6784 + WITHOUT ANY WARRANTY; without even the implied warranty of
6785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6786 + General Public License for more details.
6792 +#include "ipkg_includes.h"
6793 +#include "libipkg.h"
6796 +#include "ipkg_conf.h"
6797 +#include "ipkg_cmd.h"
6798 +#include "file_util.h"
6802 +ipkg_message_callback ipkg_cb_message = NULL;
6803 +ipkg_response_callback ipkg_cb_response = NULL;
6804 +ipkg_status_callback ipkg_cb_status = NULL;
6805 +ipkg_list_callback ipkg_cb_list = NULL;
6809 +ipkg_init (ipkg_message_callback mcall,
6810 + ipkg_response_callback rcall,
6813 + ipkg_cb_message = mcall;
6814 + ipkg_cb_response = rcall;
6823 +ipkg_deinit (args_t * args)
6825 + args_deinit (args);
6826 + ipkg_cb_message = NULL;
6827 + ipkg_cb_response = NULL;
6829 + /* place other cleanup stuff here */
6836 +ipkg_packages_list(args_t *args,
6837 + const char *packages,
6838 + ipkg_list_callback cblist,
6842 + ipkg_conf_t ipkg_conf;
6845 + err = ipkg_conf_init (&ipkg_conf, args);
6851 + ipkg_cb_list = cblist;
6852 + /* we need to do this because of static declarations,
6853 + * maybe a good idea to change */
6854 + cmd = ipkg_cmd_find ("list");
6856 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6858 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6859 + ipkg_cb_list = NULL;
6860 + ipkg_conf_deinit (&ipkg_conf);
6866 +ipkg_packages_status(args_t *args,
6867 + const char *packages,
6868 + ipkg_status_callback cbstatus,
6872 + ipkg_conf_t ipkg_conf;
6875 + err = ipkg_conf_init (&ipkg_conf, args);
6881 + ipkg_cb_status = cbstatus;
6883 + /* we need to do this because of static declarations,
6884 + * maybe a good idea to change */
6885 + cmd = ipkg_cmd_find ("status");
6887 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6889 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6891 + ipkg_cb_status = NULL;
6892 + ipkg_conf_deinit (&ipkg_conf);
6898 +ipkg_packages_info(args_t *args,
6899 + const char *packages,
6900 + ipkg_status_callback cbstatus,
6904 + ipkg_conf_t ipkg_conf;
6907 + err = ipkg_conf_init (&ipkg_conf, args);
6913 + ipkg_cb_status = cbstatus;
6915 + /* we need to do this because of static declarations,
6916 + * maybe a good idea to change */
6917 + cmd = ipkg_cmd_find ("info");
6919 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6921 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6923 + ipkg_cb_status = NULL;
6924 + ipkg_conf_deinit (&ipkg_conf);
6930 +ipkg_packages_install (args_t * args, const char *name)
6933 + ipkg_conf_t ipkg_conf;
6936 + /* this error should be handled in application */
6937 + if (!name || !strlen (name))
6940 + err = ipkg_conf_init (&ipkg_conf, args);
6946 + /* we need to do this because of static declarations,
6947 + * maybe a good idea to change */
6948 + cmd = ipkg_cmd_find ("install");
6949 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6951 + ipkg_conf_deinit(&ipkg_conf);
6957 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6960 + ipkg_conf_t ipkg_conf;
6963 + /* this error should be handled in application */
6964 + if (!name || !strlen (name))
6967 + err = ipkg_conf_init (&ipkg_conf, args);
6973 + /* we need to do this because of static declarations,
6974 + * maybe a good idea to change */
6976 + cmd = ipkg_cmd_find ("purge");
6978 + cmd = ipkg_cmd_find ("remove");
6980 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6982 + ipkg_conf_deinit(&ipkg_conf);
6988 +ipkg_lists_update(args_t *args)
6991 + ipkg_conf_t ipkg_conf;
6994 + err = ipkg_conf_init (&ipkg_conf, args);
7000 + /* we need to do this because of static declarations,
7001 + * maybe a good idea to change */
7002 + cmd = ipkg_cmd_find ("update");
7004 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
7006 + ipkg_conf_deinit(&ipkg_conf);
7012 +ipkg_packages_upgrade(args_t *args)
7015 + ipkg_conf_t ipkg_conf;
7018 + err = ipkg_conf_init (&ipkg_conf, args);
7024 + /* we need to do this because of static declarations,
7025 + * maybe a good idea to change */
7026 + cmd = ipkg_cmd_find ("upgrade");
7028 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
7030 + ipkg_conf_deinit(&ipkg_conf);
7036 +ipkg_packages_download (args_t * args, const char *name)
7039 + ipkg_conf_t ipkg_conf;
7042 + /* this error should be handled in application */
7043 + if (!name || !strlen (name))
7046 + err = ipkg_conf_init (&ipkg_conf, args);
7052 + /* we need to do this because of static declarations,
7053 + * maybe a good idea to change */
7054 + cmd = ipkg_cmd_find ("download");
7055 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
7057 + ipkg_conf_deinit(&ipkg_conf);
7063 +ipkg_package_files(args_t *args,
7065 + ipkg_list_callback cblist,
7069 + ipkg_conf_t ipkg_conf;
7072 + /* this error should be handled in application */
7073 + if (!name || !strlen (name))
7076 + err = ipkg_conf_init (&ipkg_conf, args);
7082 + ipkg_cb_list = cblist;
7084 + /* we need to do this because of static declarations,
7085 + * maybe a good idea to change */
7086 + cmd = ipkg_cmd_find ("files");
7088 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7090 + ipkg_cb_list = NULL;
7091 + ipkg_conf_deinit(&ipkg_conf);
7097 +ipkg_file_search(args_t *args,
7099 + ipkg_list_callback cblist,
7103 + ipkg_conf_t ipkg_conf;
7106 + /* this error should be handled in application */
7107 + if (!file || !strlen (file))
7110 + err = ipkg_conf_init (&ipkg_conf, args);
7116 + ipkg_cb_list = cblist;
7118 + /* we need to do this because of static declarations,
7119 + * maybe a good idea to change */
7120 + cmd = ipkg_cmd_find ("search");
7121 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7123 + ipkg_cb_list = NULL;
7124 + ipkg_conf_deinit(&ipkg_conf);
7130 +ipkg_file_what(args_t *args, const char *file, const char* command)
7133 + ipkg_conf_t ipkg_conf;
7136 + /* this error should be handled in application */
7137 + if (!file || !strlen (file))
7140 + err = ipkg_conf_init (&ipkg_conf, args);
7146 + /* we need to do this because of static declarations,
7147 + * maybe a good idea to change */
7148 + cmd = ipkg_cmd_find (command);
7149 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7151 + ipkg_conf_deinit(&ipkg_conf);
7155 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7156 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7157 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7158 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7159 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7162 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7165 + if (conf && (conf->verbosity < level)) {
7169 + if ( level == IPKG_ERROR ){
7170 + push_error_list(&error_list, msg);
7179 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7180 + pkg_state_status_t status, void *userdata)
7183 + printf("%s - %s - %s\n", name, version, desc);
7185 + printf("%s - %s\n", name, version);
7189 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7190 + pkg_state_status_t status, void *userdata)
7193 + printf("%s\n", desc);
7197 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7200 + printf("%s\n", desc);
7204 +char* default_ipkg_response_callback(char *question)
7206 + char *response = NULL;
7210 + response = (char *)file_read_line_alloc(stdin);
7211 + } while (response == NULL);
7215 +/* This is used for backward compatibility */
7217 +ipkg_op (int argc, char *argv[])
7223 + ipkg_conf_t ipkg_conf;
7225 + args_init (&args);
7227 + optind = args_parse (&args, argc, argv);
7228 + if (optind == argc || optind < 0)
7230 + args_usage ("ipkg must have one sub-command argument");
7233 + cmd_name = argv[optind++];
7234 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7235 + read anything from there.
7237 + if ( !strcmp(cmd_name,"print-architecture") ||
7238 + !strcmp(cmd_name,"print_architecture") ||
7239 + !strcmp(cmd_name,"print-installation-architecture") ||
7240 + !strcmp(cmd_name,"print_installation_architecture") )
7241 + args.nocheckfordirorfile = 1;
7243 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7244 + read anything from there.
7246 + if ( !strcmp(cmd_name,"flag") ||
7247 + !strcmp(cmd_name,"configure") ||
7248 + !strcmp(cmd_name,"remove") ||
7249 + !strcmp(cmd_name,"files") ||
7250 + !strcmp(cmd_name,"search") ||
7251 + !strcmp(cmd_name,"compare_versions") ||
7252 + !strcmp(cmd_name,"compare-versions") ||
7253 + !strcmp(cmd_name,"list_installed") ||
7254 + !strcmp(cmd_name,"list-installed") ||
7255 + !strcmp(cmd_name,"status") )
7256 + args.noreadfeedsfile = 1;
7259 + err = ipkg_conf_init (&ipkg_conf, &args);
7265 + args_deinit (&args);
7267 + ipkg_cb_message = default_ipkg_message_callback;
7268 + ipkg_cb_response = default_ipkg_response_callback;
7269 + ipkg_cb_status = default_ipkg_status_callback;
7270 + if ( strcmp(cmd_name, "files")==0)
7271 + ipkg_cb_list = default_ipkg_files_callback;
7273 + ipkg_cb_list = default_ipkg_list_callback;
7275 + cmd = ipkg_cmd_find (cmd_name);
7278 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7280 + args_usage (NULL);
7283 + if (cmd->requires_args && optind == argc)
7286 + "%s: the ``%s'' command requires at least one argument\n",
7287 + __FUNCTION__, cmd_name);
7288 + args_usage (NULL);
7291 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7293 + ipkg_conf_deinit (&ipkg_conf);
7298 +#endif /* IPKG_LIB */
7299 diff -ruN busybox-1.1.2-orig/archival/libipkg/libipkg.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.h
7300 --- busybox-1.1.2-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7301 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-05-09 02:06:48.000000000 +0200
7303 +/* ipkglib.h - the itsy package management system
7305 + Florian Boor <florian.boor@kernelconcepts.de>
7307 + This program is free software; you can redistribute it and/or
7308 + modify it under the terms of the GNU General Public License as
7309 + published by the Free Software Foundation; either version 2, or (at
7310 + your option) any later version.
7312 + This program is distributed in the hope that it will be useful, but
7313 + WITHOUT ANY WARRANTY; without even the implied warranty of
7314 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7315 + General Public License for more details.
7323 +#include "ipkg_conf.h"
7324 +#include "ipkg_message.h"
7329 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7331 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7332 + pkg_state_status_t status, void *userdata);
7333 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7335 +typedef char* (*ipkg_response_callback)(char *question);
7337 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7338 +extern int ipkg_init (ipkg_message_callback mcall,
7339 + ipkg_response_callback rcall,
7342 +extern int ipkg_deinit (args_t *args);
7343 +extern int ipkg_packages_list(args_t *args,
7344 + const char *packages,
7345 + ipkg_list_callback cblist,
7347 +extern int ipkg_packages_status(args_t *args,
7348 + const char *packages,
7349 + ipkg_status_callback cbstatus,
7351 +extern int ipkg_packages_info(args_t *args,
7352 + const char *packages,
7353 + ipkg_status_callback cbstatus,
7355 +extern int ipkg_packages_install(args_t *args, const char *name);
7356 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7357 +extern int ipkg_lists_update(args_t *args);
7358 +extern int ipkg_packages_upgrade(args_t *args);
7359 +extern int ipkg_packages_download(args_t *args, const char *name);
7360 +extern int ipkg_package_files(args_t *args,
7362 + ipkg_list_callback cblist,
7364 +extern int ipkg_file_search(args_t *args,
7366 + ipkg_list_callback cblist,
7368 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7369 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7370 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7371 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7372 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7374 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7375 +extern ipkg_response_callback ipkg_cb_response;
7376 +extern ipkg_status_callback ipkg_cb_status;
7377 +extern ipkg_list_callback ipkg_cb_list;
7378 +extern void push_error_list(struct errlist **errors,char * msg);
7379 +extern void reverse_error_list(struct errlist **errors);
7380 +extern void free_error_list(struct errlist **errors);
7384 +extern int ipkg_op(int argc, char *argv[]);
7390 diff -ruN busybox-1.1.2-orig/archival/libipkg/md5.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.c
7391 --- busybox-1.1.2-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7392 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.c 2006-05-09 02:06:48.000000000 +0200
7394 +/* md5.c - wrappers to busybox md5 functions
7396 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7398 + * This program is free software; you can redistribute it and/or modify
7399 + * it under the terms of the GNU General Public License as published by
7400 + * the Free Software Foundation; either version 2, or (at your option)
7401 + * any later version.
7403 + * This program is distributed in the hope that it will be useful,
7404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7406 + * GNU General Public License for more details.
7408 + * You should have received a copy of the GNU General Public License
7409 + * along with this program; if not, write to the Free Software Foundation,
7410 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7418 +int md5_stream(FILE *stream, void *resblock)
7423 + if( (fd = fileno(stream)) == -1 ) {
7424 + bb_error_msg("bad file descriptor");
7428 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7433 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7437 + md5_begin(&md5_cx);
7438 + md5_hash(buffer, len, &md5_cx);
7439 + return md5_end(resblock, &md5_cx);
7442 diff -ruN busybox-1.1.2-orig/archival/libipkg/md5.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.h
7443 --- busybox-1.1.2-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7444 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/md5.h 2006-05-09 02:06:48.000000000 +0200
7446 +/* md5.h - Compute MD5 checksum of files or strings according to the
7447 + * definition of MD5 in RFC 1321 from April 1992.
7448 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7450 + * This program is free software; you can redistribute it and/or modify
7451 + * it under the terms of the GNU General Public License as published by
7452 + * the Free Software Foundation; either version 2, or (at your option)
7453 + * any later version.
7455 + * This program is distributed in the hope that it will be useful,
7456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7458 + * GNU General Public License for more details.
7460 + * You should have received a copy of the GNU General Public License
7461 + * along with this program; if not, write to the Free Software Foundation,
7462 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7468 +/* Compute MD5 message digest for bytes read from STREAM. The
7469 + resulting message digest number will be written into the 16 bytes
7470 + beginning at RESBLOCK. */
7471 +int md5_stream(FILE *stream, void *resblock);
7473 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7474 + result is always in little endian byte order, so that a byte-wise
7475 + output yields to the wanted ASCII representation of the message
7477 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7481 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.c
7482 --- busybox-1.1.2-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7483 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-05-09 02:06:48.000000000 +0200
7485 +/* nv_pair.c - the itsy package management system
7489 + Copyright (C) 2001 University of Southern California
7491 + This program is free software; you can redistribute it and/or
7492 + modify it under the terms of the GNU General Public License as
7493 + published by the Free Software Foundation; either version 2, or (at
7494 + your option) any later version.
7496 + This program is distributed in the hope that it will be useful, but
7497 + WITHOUT ANY WARRANTY; without even the implied warranty of
7498 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7499 + General Public License for more details.
7504 +#include "nv_pair.h"
7505 +#include "str_util.h"
7507 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7509 + nv_pair->name = str_dup_safe(name);
7510 + nv_pair->value = str_dup_safe(value);
7515 +void nv_pair_deinit(nv_pair_t *nv_pair)
7517 + free(nv_pair->name);
7518 + nv_pair->name = NULL;
7520 + free(nv_pair->value);
7521 + nv_pair->value = NULL;
7525 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.h
7526 --- busybox-1.1.2-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7527 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-05-09 02:06:48.000000000 +0200
7529 +/* nv_pair.h - the itsy package management system
7533 + Copyright (C) 2001 University of Southern California
7535 + This program is free software; you can redistribute it and/or
7536 + modify it under the terms of the GNU General Public License as
7537 + published by the Free Software Foundation; either version 2, or (at
7538 + your option) any later version.
7540 + This program is distributed in the hope that it will be useful, but
7541 + WITHOUT ANY WARRANTY; without even the implied warranty of
7542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7543 + General Public License for more details.
7549 +typedef struct nv_pair nv_pair_t;
7556 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7557 +void nv_pair_deinit(nv_pair_t *nv_pair);
7561 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.c
7562 --- busybox-1.1.2-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7563 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-05-09 02:06:48.000000000 +0200
7565 +/* nv_pair_list.c - the itsy package management system
7569 + Copyright (C) 2001 University of Southern California
7571 + This program is free software; you can redistribute it and/or
7572 + modify it under the terms of the GNU General Public License as
7573 + published by the Free Software Foundation; either version 2, or (at
7574 + your option) any later version.
7576 + This program is distributed in the hope that it will be useful, but
7577 + WITHOUT ANY WARRANTY; without even the implied warranty of
7578 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7579 + General Public License for more details.
7584 +#include "nv_pair.h"
7585 +#include "void_list.h"
7586 +#include "nv_pair_list.h"
7588 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7590 + return void_list_elt_init((void_list_elt_t *) elt, data);
7593 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7595 + void_list_elt_deinit((void_list_elt_t *) elt);
7598 +int nv_pair_list_init(nv_pair_list_t *list)
7600 + return void_list_init((void_list_t *) list);
7603 +void nv_pair_list_deinit(nv_pair_list_t *list)
7605 + nv_pair_list_elt_t *iter;
7606 + nv_pair_t *nv_pair;
7608 + for (iter = list->head; iter; iter = iter->next) {
7609 + nv_pair = iter->data;
7610 + nv_pair_deinit(nv_pair);
7612 + /* malloced in nv_pair_list_append */
7614 + iter->data = NULL;
7616 + void_list_deinit((void_list_t *) list);
7619 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7623 + /* freed in nv_pair_list_deinit */
7624 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7626 + if (nv_pair == NULL) {
7627 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7630 + nv_pair_init(nv_pair, name, value);
7632 + err = void_list_append((void_list_t *) list, nv_pair);
7640 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7642 + return void_list_push((void_list_t *) list, data);
7645 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7647 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7650 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7652 + nv_pair_list_elt_t *iter;
7653 + nv_pair_t *nv_pair;
7655 + for (iter = list->head; iter; iter = iter->next) {
7656 + nv_pair = iter->data;
7657 + if (strcmp(nv_pair->name, name) == 0) {
7658 + return nv_pair->value;
7663 diff -ruN busybox-1.1.2-orig/archival/libipkg/nv_pair_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.h
7664 --- busybox-1.1.2-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7665 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-05-09 02:06:48.000000000 +0200
7667 +/* nv_pair_list.h - the itsy package management system
7671 + Copyright (C) 2001 University of Southern California
7673 + This program is free software; you can redistribute it and/or
7674 + modify it under the terms of the GNU General Public License as
7675 + published by the Free Software Foundation; either version 2, or (at
7676 + your option) any later version.
7678 + This program is distributed in the hope that it will be useful, but
7679 + WITHOUT ANY WARRANTY; without even the implied warranty of
7680 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7681 + General Public License for more details.
7684 +#ifndef NV_PAIR_LIST_H
7685 +#define NV_PAIR_LIST_H
7687 +#include "nv_pair.h"
7688 +#include "void_list.h"
7690 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7691 +struct nv_pair_list_elt
7693 + nv_pair_list_elt_t *next;
7697 +typedef struct nv_pair_list nv_pair_list_t;
7698 +struct nv_pair_list
7700 + nv_pair_list_elt_t pre_head;
7701 + nv_pair_list_elt_t *head;
7702 + nv_pair_list_elt_t *tail;
7705 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7707 + if (list->head == NULL)
7713 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7714 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7716 +int nv_pair_list_init(nv_pair_list_t *list);
7717 +void nv_pair_list_deinit(nv_pair_list_t *list);
7719 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7720 + const char *name, const char *value);
7721 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7722 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7723 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7727 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.c
7728 --- busybox-1.1.2-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7729 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.c 2006-05-09 02:12:05.000000000 +0200
7731 +/* pkg.c - the itsy package management system
7735 + Copyright (C) 2001 University of Southern California
7737 + This program is free software; you can redistribute it and/or
7738 + modify it under the terms of the GNU General Public License as
7739 + published by the Free Software Foundation; either version 2, or (at
7740 + your option) any later version.
7742 + This program is distributed in the hope that it will be useful, but
7743 + WITHOUT ANY WARRANTY; without even the implied warranty of
7744 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7745 + General Public License for more details.
7750 +#include <string.h>
7755 +#include "pkg_parse.h"
7756 +#include "pkg_extract.h"
7757 +#include "ipkg_message.h"
7758 +#include "ipkg_utils.h"
7760 +#include "sprintf_alloc.h"
7761 +#include "file_util.h"
7762 +#include "str_util.h"
7763 +#include "xsystem.h"
7764 +#include "ipkg_conf.h"
7766 +typedef struct enum_map enum_map_t;
7773 +static const enum_map_t pkg_state_want_map[] = {
7774 + { SW_UNKNOWN, "unknown"},
7775 + { SW_INSTALL, "install"},
7776 + { SW_DEINSTALL, "deinstall"},
7777 + { SW_PURGE, "purge"}
7780 +static const enum_map_t pkg_state_flag_map[] = {
7782 + { SF_REINSTREQ, "reinstreq"},
7783 + { SF_HOLD, "hold"},
7784 + { SF_REPLACE, "replace"},
7785 + { SF_NOPRUNE, "noprune"},
7786 + { SF_PREFER, "prefer"},
7787 + { SF_OBSOLETE, "obsolete"},
7788 + { SF_USER, "user"},
7791 +static const enum_map_t pkg_state_status_map[] = {
7792 + { SS_NOT_INSTALLED, "not-installed" },
7793 + { SS_UNPACKED, "unpacked" },
7794 + { SS_HALF_CONFIGURED, "half-configured" },
7795 + { SS_INSTALLED, "installed" },
7796 + { SS_HALF_INSTALLED, "half-installed" },
7797 + { SS_CONFIG_FILES, "config-files" },
7798 + { SS_POST_INST_FAILED, "post-inst-failed" },
7799 + { SS_REMOVAL_FAILED, "removal-failed" }
7802 +static int verrevcmp(const char *val, const char *ref);
7805 +pkg_t *pkg_new(void)
7809 + pkg = malloc(sizeof(pkg_t));
7810 + if (pkg == NULL) {
7811 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7820 +int pkg_init(pkg_t *pkg)
7822 + memset(pkg, 0, sizeof(pkg_t));
7825 + pkg->version = NULL;
7826 + pkg->revision = NULL;
7827 + pkg->familiar_revision = NULL;
7830 + pkg->architecture = NULL;
7831 + pkg->maintainer = NULL;
7832 + pkg->section = NULL;
7833 + pkg->description = NULL;
7834 + pkg->state_want = SW_UNKNOWN;
7835 + pkg->state_flag = SF_OK;
7836 + pkg->state_status = SS_NOT_INSTALLED;
7837 + pkg->depends_str = NULL;
7838 + pkg->provides_str = NULL;
7839 + pkg->depends_count = 0;
7840 + pkg->depends = NULL;
7841 + pkg->suggests_str = NULL;
7842 + pkg->recommends_str = NULL;
7843 + pkg->suggests_count = 0;
7844 + pkg->recommends_count = 0;
7846 + /* Abhaya: added init for conflicts fields */
7847 + pkg->conflicts = NULL;
7848 + pkg->conflicts_count = 0;
7850 + /* added for replaces. Jamey 7/23/2002 */
7851 + pkg->replaces = NULL;
7852 + pkg->replaces_count = 0;
7854 + pkg->pre_depends_count = 0;
7855 + pkg->pre_depends_str = NULL;
7856 + pkg->provides_count = 0;
7857 + pkg->provides = NULL;
7858 + pkg->filename = NULL;
7859 + pkg->local_filename = NULL;
7860 + pkg->tmp_unpack_dir = NULL;
7861 + pkg->md5sum = NULL;
7863 + pkg->installed_size = NULL;
7864 + pkg->priority = NULL;
7865 + pkg->source = NULL;
7866 + conffile_list_init(&pkg->conffiles);
7867 + pkg->installed_files = NULL;
7868 + pkg->installed_files_ref_cnt = 0;
7869 + pkg->essential = 0;
7870 + pkg->provided_by_hand = 0;
7875 +void pkg_deinit(pkg_t *pkg)
7880 + free(pkg->version);
7881 + pkg->version = NULL;
7882 + /* revision and familiar_revision share storage with version, so
7884 + pkg->revision = NULL;
7885 + pkg->familiar_revision = NULL;
7886 + /* owned by ipkg_conf_t */
7888 + /* owned by ipkg_conf_t */
7890 + free(pkg->architecture);
7891 + pkg->architecture = NULL;
7892 + free(pkg->maintainer);
7893 + pkg->maintainer = NULL;
7894 + free(pkg->section);
7895 + pkg->section = NULL;
7896 + free(pkg->description);
7897 + pkg->description = NULL;
7898 + pkg->state_want = SW_UNKNOWN;
7899 + pkg->state_flag = SF_OK;
7900 + pkg->state_status = SS_NOT_INSTALLED;
7901 + free(pkg->depends_str);
7902 + pkg->depends_str = NULL;
7903 + free(pkg->provides_str);
7904 + pkg->provides_str = NULL;
7905 + pkg->depends_count = 0;
7906 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7907 + pkg->pre_depends_count = 0;
7908 + free(pkg->pre_depends_str);
7909 + pkg->pre_depends_str = NULL;
7910 + pkg->provides_count = 0;
7911 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7912 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7913 + free(pkg->filename);
7914 + pkg->filename = NULL;
7915 + free(pkg->local_filename);
7916 + pkg->local_filename = NULL;
7917 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7918 + ipkg_install.c here. See comment in
7919 + ipkg_install.c:cleanup_temporary_files */
7920 + free(pkg->tmp_unpack_dir);
7921 + pkg->tmp_unpack_dir = NULL;
7922 + free(pkg->md5sum);
7923 + pkg->md5sum = NULL;
7926 + free(pkg->installed_size);
7927 + pkg->installed_size = NULL;
7928 + free(pkg->priority);
7929 + pkg->priority = NULL;
7930 + free(pkg->source);
7931 + pkg->source = NULL;
7932 + conffile_list_deinit(&pkg->conffiles);
7933 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7934 + since if they are calling deinit, they should know. Maybe do an
7935 + assertion here instead? */
7936 + pkg->installed_files_ref_cnt = 1;
7937 + pkg_free_installed_files(pkg);
7938 + pkg->essential = 0;
7941 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7945 + FILE *control_file;
7947 + err = pkg_init(pkg);
7948 + if (err) { return err; }
7950 + pkg->local_filename = strdup(filename);
7952 + control_file = tmpfile();
7953 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7954 + if (err) { return err; }
7956 + rewind(control_file);
7957 + raw = read_raw_pkgs_from_stream(control_file);
7958 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7960 + fclose(control_file);
7965 +/* Merge any new information in newpkg into oldpkg */
7966 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7967 + newpkg, but should leave it usable. This rework is so that
7968 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7970 + * uh, i thought that i had originally written this so that it took
7971 + * two pkgs and returned a new one? we can do that again... -sma
7973 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7975 + if (oldpkg == newpkg) {
7980 + oldpkg->src = newpkg->src;
7981 + if (!oldpkg->dest)
7982 + oldpkg->dest = newpkg->dest;
7983 + if (!oldpkg->architecture)
7984 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7985 + if (!oldpkg->arch_priority)
7986 + oldpkg->arch_priority = newpkg->arch_priority;
7987 + if (!oldpkg->section)
7988 + oldpkg->section = str_dup_safe(newpkg->section);
7989 + if(!oldpkg->maintainer)
7990 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7991 + if(!oldpkg->description)
7992 + oldpkg->description = str_dup_safe(newpkg->description);
7994 + /* merge the state_flags from the new package */
7995 + oldpkg->state_want = newpkg->state_want;
7996 + oldpkg->state_status = newpkg->state_status;
7997 + oldpkg->state_flag = newpkg->state_flag;
7999 + if (oldpkg->state_want == SW_UNKNOWN)
8000 + oldpkg->state_want = newpkg->state_want;
8001 + if (oldpkg->state_status == SS_NOT_INSTALLED)
8002 + oldpkg->state_status = newpkg->state_status;
8003 + oldpkg->state_flag |= newpkg->state_flag;
8006 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
8007 + oldpkg->depends_str = newpkg->depends_str;
8008 + newpkg->depends_str = NULL;
8009 + oldpkg->depends_count = newpkg->depends_count;
8010 + newpkg->depends_count = 0;
8012 + oldpkg->depends = newpkg->depends;
8013 + newpkg->depends = NULL;
8015 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
8016 + newpkg->pre_depends_str = NULL;
8017 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
8018 + newpkg->pre_depends_count = 0;
8020 + oldpkg->recommends_str = newpkg->recommends_str;
8021 + newpkg->recommends_str = NULL;
8022 + oldpkg->recommends_count = newpkg->recommends_count;
8023 + newpkg->recommends_count = 0;
8025 + oldpkg->suggests_str = newpkg->suggests_str;
8026 + newpkg->suggests_str = NULL;
8027 + oldpkg->suggests_count = newpkg->suggests_count;
8028 + newpkg->suggests_count = 0;
8031 + if (!oldpkg->provides_str) {
8032 + oldpkg->provides_str = newpkg->provides_str;
8033 + newpkg->provides_str = NULL;
8034 + oldpkg->provides_count = newpkg->provides_count;
8035 + newpkg->provides_count = 0;
8037 + oldpkg->provides = newpkg->provides;
8038 + newpkg->provides = NULL;
8041 + if (!oldpkg->conflicts_str) {
8042 + oldpkg->conflicts_str = newpkg->conflicts_str;
8043 + newpkg->conflicts_str = NULL;
8044 + oldpkg->conflicts_count = newpkg->conflicts_count;
8045 + newpkg->conflicts_count = 0;
8047 + oldpkg->conflicts = newpkg->conflicts;
8048 + newpkg->conflicts = NULL;
8051 + if (!oldpkg->replaces_str) {
8052 + oldpkg->replaces_str = newpkg->replaces_str;
8053 + newpkg->replaces_str = NULL;
8054 + oldpkg->replaces_count = newpkg->replaces_count;
8055 + newpkg->replaces_count = 0;
8057 + oldpkg->replaces = newpkg->replaces;
8058 + newpkg->replaces = NULL;
8061 + if (!oldpkg->filename)
8062 + oldpkg->filename = str_dup_safe(newpkg->filename);
8064 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8065 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8066 + if (!oldpkg->local_filename)
8067 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8068 + if (!oldpkg->tmp_unpack_dir)
8069 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8070 + if (!oldpkg->md5sum)
8071 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8072 + if (!oldpkg->size)
8073 + oldpkg->size = str_dup_safe(newpkg->size);
8074 + if (!oldpkg->installed_size)
8075 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8076 + if (!oldpkg->priority)
8077 + oldpkg->priority = str_dup_safe(newpkg->priority);
8078 + if (!oldpkg->source)
8079 + oldpkg->source = str_dup_safe(newpkg->source);
8080 + if (oldpkg->conffiles.head == NULL){
8081 + oldpkg->conffiles = newpkg->conffiles;
8082 + conffile_list_init(&newpkg->conffiles);
8084 + if (!oldpkg->installed_files){
8085 + oldpkg->installed_files = newpkg->installed_files;
8086 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8087 + newpkg->installed_files = NULL;
8089 + if (!oldpkg->essential)
8090 + oldpkg->essential = newpkg->essential;
8095 +abstract_pkg_t *abstract_pkg_new(void)
8097 + abstract_pkg_t * ab_pkg;
8099 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8101 + if (ab_pkg == NULL) {
8102 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8106 + if ( abstract_pkg_init(ab_pkg) < 0 )
8112 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8114 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8116 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8117 + if (ab_pkg->provided_by==NULL){
8120 + ab_pkg->dependencies_checked = 0;
8121 + ab_pkg->state_status = SS_NOT_INSTALLED;
8126 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8129 + char **raw_start=NULL;
8131 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8132 + if (temp_str == NULL ){
8133 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8136 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8138 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8139 + if (raw == NULL ){
8140 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8145 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8146 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8162 +char * pkg_formatted_info(pkg_t *pkg )
8167 + buff = malloc(8192);
8168 + if (buff == NULL) {
8169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8175 + line = pkg_formatted_field(pkg, "Package");
8176 + strncat(buff ,line, strlen(line));
8179 + line = pkg_formatted_field(pkg, "Version");
8180 + strncat(buff ,line, strlen(line));
8183 + line = pkg_formatted_field(pkg, "Depends");
8184 + strncat(buff ,line, strlen(line));
8187 + line = pkg_formatted_field(pkg, "Recommends");
8188 + strncat(buff ,line, strlen(line));
8191 + line = pkg_formatted_field(pkg, "Suggests");
8192 + strncat(buff ,line, strlen(line));
8195 + line = pkg_formatted_field(pkg, "Provides");
8196 + strncat(buff ,line, strlen(line));
8199 + line = pkg_formatted_field(pkg, "Replaces");
8200 + strncat(buff ,line, strlen(line));
8203 + line = pkg_formatted_field(pkg, "Conflicts");
8204 + strncat(buff ,line, strlen(line));
8207 + line = pkg_formatted_field(pkg, "Status");
8208 + strncat(buff ,line, strlen(line));
8211 + line = pkg_formatted_field(pkg, "Section");
8212 + strncat(buff ,line, strlen(line));
8215 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8216 + strncat(buff ,line, strlen(line));
8219 + line = pkg_formatted_field(pkg, "Architecture");
8220 + strncat(buff ,line, strlen(line));
8223 + line = pkg_formatted_field(pkg, "Maintainer");
8224 + strncat(buff ,line, strlen(line));
8227 + line = pkg_formatted_field(pkg, "MD5sum");
8228 + strncat(buff ,line, strlen(line));
8231 + line = pkg_formatted_field(pkg, "Size");
8232 + strncat(buff ,line, strlen(line));
8235 + line = pkg_formatted_field(pkg, "Filename");
8236 + strncat(buff ,line, strlen(line));
8239 + line = pkg_formatted_field(pkg, "Conffiles");
8240 + strncat(buff ,line, strlen(line));
8243 + line = pkg_formatted_field(pkg, "Source");
8244 + strncat(buff ,line, strlen(line));
8247 + line = pkg_formatted_field(pkg, "Description");
8248 + strncat(buff ,line, strlen(line));
8251 + line = pkg_formatted_field(pkg, "Installed-Time");
8252 + strncat(buff ,line, strlen(line));
8258 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8260 + static size_t LINE_LEN = 128;
8261 + char * temp = (char *)malloc(1);
8263 + int flag_provide_false = 0;
8266 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8267 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8270 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8271 + goto UNKNOWN_FMT_FIELD;
8280 + if (strcasecmp(field, "Architecture") == 0) {
8281 + /* Architecture */
8282 + if (pkg->architecture) {
8283 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8284 + if ( temp == NULL ){
8285 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8289 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8292 + goto UNKNOWN_FMT_FIELD;
8297 + if (strcasecmp(field, "Conffiles") == 0) {
8299 + conffile_list_elt_t *iter;
8300 + char confstr[LINE_LEN];
8302 + if (pkg->conffiles.head == NULL) {
8307 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8308 + if (iter->data->name && iter->data->value) {
8309 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8312 + temp = (char *)realloc(temp,len);
8313 + if ( temp == NULL ){
8314 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8318 + strncpy(temp, "Conffiles:\n", 12);
8319 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8320 + if (iter->data->name && iter->data->value) {
8321 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8322 + strncat(temp, confstr, strlen(confstr));
8325 + } else if (strcasecmp(field, "Conflicts") == 0) {
8328 + if (pkg->conflicts_count) {
8329 + char conflictstr[LINE_LEN];
8331 + for(i = 0; i < pkg->conflicts_count; i++) {
8332 + len = len + (strlen(pkg->conflicts_str[i])+5);
8334 + temp = (char *)realloc(temp,len);
8335 + if ( temp == NULL ){
8336 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8340 + strncpy(temp, "Conflicts:", 11);
8341 + for(i = 0; i < pkg->conflicts_count; i++) {
8342 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8343 + strncat(temp, conflictstr, strlen(conflictstr));
8345 + strncat(temp, "\n", strlen("\n"));
8348 + goto UNKNOWN_FMT_FIELD;
8353 + if (strcasecmp(field, "Depends") == 0) {
8357 + if (pkg->depends_count) {
8358 + char depstr[LINE_LEN];
8360 + for(i = 0; i < pkg->depends_count; i++) {
8361 + len = len + (strlen(pkg->depends_str[i])+4);
8363 + temp = (char *)realloc(temp,len);
8364 + if ( temp == NULL ){
8365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8369 + strncpy(temp, "Depends:", 10);
8370 + for(i = 0; i < pkg->depends_count; i++) {
8371 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8372 + strncat(temp, depstr, strlen(depstr));
8374 + strncat(temp, "\n", strlen("\n"));
8376 + } else if (strcasecmp(field, "Description") == 0) {
8378 + if (pkg->description) {
8379 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8380 + if ( temp == NULL ){
8381 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8385 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8388 + goto UNKNOWN_FMT_FIELD;
8394 + if (pkg->essential) {
8395 + temp = (char *)realloc(temp,16);
8396 + if ( temp == NULL ){
8397 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8401 + snprintf(temp, (16), "Essential: yes\n");
8408 + if (pkg->filename) {
8409 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8410 + if ( temp == NULL ){
8411 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8415 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8421 + if (strcasecmp(field, "Installed-Size") == 0) {
8422 + /* Installed-Size */
8423 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8424 + if ( temp == NULL ){
8425 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8429 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8430 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8431 + temp = (char *)realloc(temp,29);
8432 + if ( temp == NULL ){
8433 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8437 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8443 + /* Maintainer | MD5sum */
8444 + if (strcasecmp(field, "Maintainer") == 0) {
8446 + if (pkg->maintainer) {
8447 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8448 + if ( temp == NULL ){
8449 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8453 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8455 + } else if (strcasecmp(field, "MD5sum") == 0) {
8457 + if (pkg->md5sum) {
8458 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8459 + if ( temp == NULL ){
8460 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8464 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8467 + goto UNKNOWN_FMT_FIELD;
8473 + if (strcasecmp(field, "Package") == 0) {
8475 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8476 + if ( temp == NULL ){
8477 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8481 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8482 + } else if (strcasecmp(field, "Priority") == 0) {
8484 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8485 + if ( temp == NULL ){
8486 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8490 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8491 + } else if (strcasecmp(field, "Provides") == 0) {
8495 + if (pkg->provides_count) {
8496 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8497 + for ( i=0; i < pkg->provides_count; i++ ){
8498 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8499 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8500 + flag_provide_false = 1;
8503 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8504 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8505 + char provstr[LINE_LEN];
8507 + for(i = 0; i < pkg->provides_count; i++) {
8508 + len = len + (strlen(pkg->provides_str[i])+5);
8510 + temp = (char *)realloc(temp,len);
8511 + if ( temp == NULL ){
8512 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8516 + strncpy(temp, "Provides:", 12);
8517 + for(i = 0; i < pkg->provides_count; i++) {
8518 + if (strlen(pkg->provides_str[i])>0){;
8519 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8520 + strncat(temp, provstr, strlen(provstr));
8523 + strncat(temp, "\n", strlen("\n"));
8527 + goto UNKNOWN_FMT_FIELD;
8534 + /* Replaces | Recommends*/
8535 + if (strcasecmp (field, "Replaces") == 0) {
8536 + if (pkg->replaces_count) {
8537 + char replstr[LINE_LEN];
8539 + for (i = 0; i < pkg->replaces_count; i++) {
8540 + len = len + (strlen(pkg->replaces_str[i])+5);
8542 + temp = (char *)realloc(temp,len);
8543 + if ( temp == NULL ){
8544 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8548 + strncpy(temp, "Replaces:", 12);
8549 + for (i = 0; i < pkg->replaces_count; i++) {
8550 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8551 + strncat(temp, replstr, strlen(replstr));
8553 + strncat(temp, "\n", strlen("\n"));
8555 + } else if (strcasecmp (field, "Recommends") == 0) {
8556 + if (pkg->recommends_count) {
8557 + char recstr[LINE_LEN];
8559 + for(i = 0; i < pkg->recommends_count; i++) {
8560 + len = len + (strlen( pkg->recommends_str[i])+5);
8562 + temp = (char *)realloc(temp,len);
8563 + if ( temp == NULL ){
8564 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8568 + strncpy(temp, "Recommends:", 13);
8569 + for(i = 0; i < pkg->recommends_count; i++) {
8570 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8571 + strncat(temp, recstr, strlen(recstr));
8573 + strncat(temp, "\n", strlen("\n"));
8576 + goto UNKNOWN_FMT_FIELD;
8582 + /* Section | Size | Source | Status | Suggests */
8583 + if (strcasecmp(field, "Section") == 0) {
8585 + if (pkg->section) {
8586 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8587 + if ( temp == NULL ){
8588 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8592 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8594 + } else if (strcasecmp(field, "Size") == 0) {
8597 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8598 + if ( temp == NULL ){
8599 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8603 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8605 + } else if (strcasecmp(field, "Source") == 0) {
8607 + if (pkg->source) {
8608 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8609 + if ( temp == NULL ){
8610 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8614 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8616 + } else if (strcasecmp(field, "Status") == 0) {
8618 + /* Benjamin Pineau note: we should avoid direct usage of
8619 + * strlen(arg) without keeping "arg" for later free()
8621 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8622 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8623 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8625 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8626 + temp = (char *)realloc(temp,sum_of_sizes);
8627 + if ( temp == NULL ){
8628 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8632 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8635 + if(pstat) /* pfstat can be NULL if ENOMEM */
8637 + } else if (strcasecmp(field, "Suggests") == 0) {
8638 + if (pkg->suggests_count) {
8640 + char sugstr[LINE_LEN];
8642 + for(i = 0; i < pkg->suggests_count; i++) {
8643 + len = len + (strlen(pkg->suggests_str[i])+5);
8645 + temp = (char *)realloc(temp,len);
8646 + if ( temp == NULL ){
8647 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8651 + strncpy(temp, "Suggests:", 10);
8652 + for(i = 0; i < pkg->suggests_count; i++) {
8653 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8654 + strncat(temp, sugstr, strlen(sugstr));
8656 + strncat(temp, "\n", strlen("\n"));
8659 + goto UNKNOWN_FMT_FIELD;
8666 + char *version = pkg_version_str_alloc(pkg);
8667 + temp = (char *)realloc(temp,strlen(version)+14);
8668 + if ( temp == NULL ){
8669 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8673 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8678 + goto UNKNOWN_FMT_FIELD;
8681 + if ( strlen(temp)<2 ) {
8686 + UNKNOWN_FMT_FIELD:
8687 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8688 + if ( strlen(temp)<2 ) {
8695 +void pkg_print_info(pkg_t *pkg, FILE *file)
8698 + if (pkg == NULL) {
8702 + buff = pkg_formatted_info(pkg);
8703 + if ( buff == NULL )
8705 + if (strlen(buff)>2){
8706 + fwrite(buff, 1, strlen(buff), file);
8711 +void pkg_print_status(pkg_t * pkg, FILE * file)
8713 + if (pkg == NULL) {
8717 + /* XXX: QUESTION: Do we actually want more fields here? The
8718 + original idea was to save space by installing only what was
8719 + needed for actual computation, (package, version, status,
8720 + essential, conffiles). The assumption is that all other fields
8721 + can be found in th available file.
8723 + But, someone proposed the idea to make it possible to
8724 + reconstruct a .ipk from an installed package, (ie. for beaming
8725 + from one handheld to another). So, maybe we actually want a few
8726 + more fields here, (depends, suggests, etc.), so that that would
8727 + be guaranteed to work even in the absence of more information
8728 + from the available file.
8730 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8731 + the essential info needs to be here for all installed packages
8732 + because they may not appear in the Packages files on various
8733 + feeds. Furthermore, one should be able to install from URL or
8734 + local storage without requiring a Packages file from any feed.
8737 + pkg_print_field(pkg, file, "Package");
8738 + pkg_print_field(pkg, file, "Version");
8739 + pkg_print_field(pkg, file, "Depends");
8740 + pkg_print_field(pkg, file, "Recommends");
8741 + pkg_print_field(pkg, file, "Suggests");
8742 + pkg_print_field(pkg, file, "Provides");
8743 + pkg_print_field(pkg, file, "Replaces");
8744 + pkg_print_field(pkg, file, "Conflicts");
8745 + pkg_print_field(pkg, file, "Status");
8746 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8747 + pkg_print_field(pkg, file, "Architecture");
8748 + pkg_print_field(pkg, file, "Conffiles");
8749 + pkg_print_field(pkg, file, "Installed-Time");
8750 + fputs("\n", file);
8753 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8756 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8757 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8758 + __FUNCTION__, field);
8760 + buff = pkg_formatted_field(pkg, field);
8761 + if (strlen(buff)>2) {
8762 + fprintf(file, "%s", buff);
8770 + * libdpkg - Debian packaging suite library routines
8771 + * vercmp.c - comparison of version numbers
8773 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8775 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8779 + if (pkg->epoch > ref_pkg->epoch) {
8783 + if (pkg->epoch < ref_pkg->epoch) {
8787 + r = verrevcmp(pkg->version, ref_pkg->version);
8792 +#ifdef USE_DEBVERSION
8793 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8798 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8804 +int verrevcmp(const char *val, const char *ref)
8808 + const char *vp, *rp;
8809 + const char *vsep, *rsep;
8811 + if (!val) val= "";
8812 + if (!ref) ref= "";
8814 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8815 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8817 + vc= (val == vp) ? 0 : *val++;
8818 + rc= (ref == rp) ? 0 : *ref++;
8819 + if (!rc && !vc) break;
8820 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8821 + if (rc && !isalpha(rc)) rc += 256;
8822 + if (vc != rc) return vc - rc;
8826 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8827 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8828 + if (vl != rl) return vl - rl;
8832 + vsep = strchr(".-", vc);
8833 + rsep = strchr(".-", rc);
8834 + if (vsep && !rsep) return -1;
8835 + if (!vsep && rsep) return +1;
8837 + if (!*val && !*ref) return 0;
8838 + if (!*val) return -1;
8839 + if (!*ref) return +1;
8843 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8847 + r = pkg_compare_versions(it, ref);
8849 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8853 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8857 + if (strcmp(op, "<<") == 0) {
8861 + if (strcmp(op, ">>") == 0) {
8865 + if (strcmp(op, "=") == 0) {
8869 + fprintf(stderr, "unknown operator: %s", op);
8873 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8875 + const pkg_t *a = *(const pkg_t **)p1;
8876 + const pkg_t *b = *(const pkg_t **)p2;
8879 + if (!a->name || !b->name) {
8880 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8881 + a, a->name, b, b->name);
8885 + namecmp = strcmp(a->name, b->name);
8888 + vercmp = pkg_compare_versions(a, b);
8891 + if (!a->arch_priority || !b->arch_priority) {
8892 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8893 + a, a->arch_priority, b, b->arch_priority);
8896 + if (a->arch_priority > b->arch_priority)
8898 + if (a->arch_priority < b->arch_priority)
8903 +int abstract_pkg_name_compare(void *p1, void *p2)
8905 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8906 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8907 + if (!a->name || !b->name) {
8908 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8909 + a, a->name, b, b->name);
8912 + return strcmp(a->name, b->name);
8916 +char *pkg_version_str_alloc(pkg_t *pkg)
8918 + char *complete_version;
8920 +#ifdef USE_DEBVERSION
8921 + char *revision_str;
8922 + char *familiar_revision_str;
8926 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8928 + epoch_str = strdup("");
8931 +#ifdef USE_DEBVERSION
8932 + if (pkg->revision && strlen(pkg->revision)) {
8933 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8935 + revision_str = strdup("");
8938 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8939 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8941 + familiar_revision_str = strdup("");
8945 +#ifdef USE_DEBVERSION
8946 + sprintf_alloc(&complete_version, "%s%s%s%s",
8947 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8949 + sprintf_alloc(&complete_version, "%s%s",
8950 + epoch_str, pkg->version);
8954 +#ifdef USE_DEBVERSION
8955 + free(revision_str);
8956 + free(familiar_revision_str);
8959 + return complete_version;
8962 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8965 + char *list_file_name = NULL;
8966 + FILE *list_file = NULL;
8968 + char *installed_file_name;
8971 + pkg->installed_files_ref_cnt++;
8973 + if (pkg->installed_files) {
8974 + return pkg->installed_files;
8977 + pkg->installed_files = str_list_alloc();
8978 + if (pkg->installed_files == NULL) {
8979 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8983 + /* For uninstalled packages, get the file list firectly from the package.
8984 + For installed packages, look at the package.list file in the database.
8986 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8987 + if (pkg->local_filename == NULL) {
8988 + return pkg->installed_files;
8990 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8991 + file. In other words, change deb_extract so that it can
8992 + simply return the file list as a char *[] rather than
8993 + insisting on writing in to a FILE * as it does now. */
8994 + list_file = tmpfile();
8995 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8997 + fclose(list_file);
8998 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8999 + __FUNCTION__, pkg->local_filename, strerror(err));
9000 + return pkg->installed_files;
9002 + rewind(list_file);
9004 + sprintf_alloc(&list_file_name, "%s/%s.list",
9005 + pkg->dest->info_dir, pkg->name);
9006 + if (! file_exists(list_file_name)) {
9007 + free(list_file_name);
9008 + return pkg->installed_files;
9011 + list_file = fopen(list_file_name, "r");
9012 + if (list_file == NULL) {
9013 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
9014 + list_file_name, strerror(errno));
9015 + free(list_file_name);
9016 + return pkg->installed_files;
9018 + free(list_file_name);
9021 + rootdirlen = strlen( pkg->dest->root_dir );
9025 + line = file_read_line_alloc(list_file);
9026 + if (line == NULL) {
9032 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9033 + if( strncmp( pkg->dest->root_dir,
9036 + if (*file_name == '.') {
9039 + if (*file_name == '/') {
9043 + /* Freed in pkg_free_installed_files */
9044 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9046 + // already contains root_dir as header -> ABSOLUTE
9047 + sprintf_alloc(&installed_file_name, "%s", file_name);
9049 + str_list_append(pkg->installed_files, installed_file_name);
9053 + fclose(list_file);
9055 + return pkg->installed_files;
9058 +/* XXX: CLEANUP: This function and it's counterpart,
9059 + (pkg_get_installed_files), do not match our init/deinit naming
9060 + convention. Nor the alloc/free convention. But, then again, neither
9061 + of these conventions currrently fit the way these two functions
9063 +int pkg_free_installed_files(pkg_t *pkg)
9065 + str_list_elt_t *iter;
9067 + pkg->installed_files_ref_cnt--;
9068 + if (pkg->installed_files_ref_cnt > 0) {
9072 + if (pkg->installed_files) {
9074 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9075 + /* malloced in pkg_get_installed_files */
9076 + free (iter->data);
9077 + iter->data = NULL;
9080 + str_list_deinit(pkg->installed_files);
9083 + pkg->installed_files = NULL;
9088 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9091 + char *list_file_name;
9093 + //I don't think pkg_free_installed_files should be called here. Jamey
9094 + //pkg_free_installed_files(pkg);
9096 + sprintf_alloc(&list_file_name, "%s/%s.list",
9097 + pkg->dest->info_dir, pkg->name);
9098 + if (!conf->noaction) {
9099 + err = unlink(list_file_name);
9100 + free(list_file_name);
9109 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9111 + conffile_list_elt_t *iter;
9112 + conffile_t *conffile;
9114 + if (pkg == NULL) {
9118 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9119 + conffile = iter->data;
9121 + if (strcmp(conffile->name, file_name) == 0) {
9129 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9130 + const char *script, const char *args)
9136 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9137 + maintainer script within a chroot environment. */
9139 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9140 + have scripts in pkg->tmp_unpack_dir. */
9141 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9142 + if (pkg->dest == NULL) {
9143 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9144 + __FUNCTION__, pkg->name);
9147 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9149 + if (pkg->tmp_unpack_dir == NULL) {
9150 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9151 + __FUNCTION__, pkg->name);
9154 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9157 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9158 + if (conf->noaction) return 0;
9160 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9161 + scripts when running with offline_root mode and/or a dest other
9162 + than '/'. I've been playing around with some clever chroot
9163 + tricks and I might come up with something workable. */
9164 + if (conf->offline_root) {
9165 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9168 + setenv("PKG_ROOT",
9169 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9171 + if (! file_exists(path)) {
9176 + if (conf->offline_root) {
9177 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9182 + sprintf_alloc(&cmd, "%s %s", path, args);
9185 + err = xsystem(cmd);
9189 + fprintf(stderr, "%s script returned status %d\n", script, err);
9196 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9200 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9201 + if (pkg_state_want_map[i].value == sw) {
9202 + return strdup(pkg_state_want_map[i].str);
9206 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9207 + __FUNCTION__, sw);
9208 + return strdup("<STATE_WANT_UNKNOWN>");
9211 +pkg_state_want_t pkg_state_want_from_str(char *str)
9215 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9216 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9217 + return pkg_state_want_map[i].value;
9221 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9222 + __FUNCTION__, str);
9223 + return SW_UNKNOWN;
9226 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9229 + int len = 3; /* ok\000 is minimum */
9232 + /* clear the temporary flags before converting to string */
9233 + sf &= SF_NONVOLATILE_FLAGS;
9236 + return strdup("ok");
9239 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9240 + if (sf & pkg_state_flag_map[i].value) {
9241 + len += strlen(pkg_state_flag_map[i].str) + 1;
9244 + str = malloc(len);
9245 + if ( str == NULL ) {
9246 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9250 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9251 + if (sf & pkg_state_flag_map[i].value) {
9252 + strcat(str, pkg_state_flag_map[i].str);
9256 + len = strlen(str);
9257 + str[len-1] = 0; /* squash last comma */
9262 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9267 + if (strcmp(str, "ok") == 0) {
9270 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9271 + const char *sfname = pkg_state_flag_map[i].str;
9272 + int sfname_len = strlen(sfname);
9273 + if (strncmp(str, sfname, sfname_len) == 0) {
9274 + sf |= pkg_state_flag_map[i].value;
9275 + str += sfname_len;
9276 + if (str[0] == ',') {
9287 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9291 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9292 + if (pkg_state_status_map[i].value == ss) {
9293 + return strdup(pkg_state_status_map[i].str);
9297 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9298 + __FUNCTION__, ss);
9299 + return strdup("<STATE_STATUS_UNKNOWN>");
9302 +pkg_state_status_t pkg_state_status_from_str(char *str)
9306 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9307 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9308 + return pkg_state_status_map[i].value;
9312 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9313 + __FUNCTION__, str);
9314 + return SS_NOT_INSTALLED;
9317 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9319 + nv_pair_list_elt_t *l;
9321 + if (!pkg->architecture)
9324 + l = conf->arch_list.head;
9327 + nv_pair_t *nv = l->data;
9328 + if (strcmp(nv->name, pkg->architecture) == 0) {
9329 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9335 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9339 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9341 + nv_pair_list_elt_t *l;
9343 + l = conf->arch_list.head;
9346 + nv_pair_t *nv = l->data;
9347 + if (strcmp(nv->name, archname) == 0) {
9348 + int priority = strtol(nv->value, NULL, 0);
9356 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9359 + hash_table_t *pkg_hash = &conf->pkg_hash;
9360 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9361 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9363 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9364 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9365 + /* update arch_priority for each package */
9366 + for (i = 0; i < available_pkgs->len; i++) {
9367 + pkg_t *pkg = available_pkgs->pkgs[i];
9368 + int arch_priority = 1;
9371 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9372 + if (pkg->architecture)
9373 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9375 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9376 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9377 + pkg->arch_priority = arch_priority;
9380 + for (i = 0; i < available_pkgs->len; i++) {
9381 + pkg_t *pkg = available_pkgs->pkgs[i];
9382 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9383 + /* clear flags and want for any uninstallable package */
9384 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9385 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9386 + pkg->state_want = SW_UNKNOWN;
9387 + pkg->state_flag = 0;
9390 + pkg_vec_free(available_pkgs);
9392 + /* update the file owner data structure */
9393 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9394 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9395 + for (i = 0; i < installed_pkgs->len; i++) {
9396 + pkg_t *pkg = installed_pkgs->pkgs[i];
9397 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9398 + str_list_elt_t *iter;
9399 + if (installed_files == NULL) {
9400 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9403 + for (iter = installed_files->head; iter; iter = iter->next) {
9404 + char *installed_file = iter->data;
9405 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9406 + file_hash_set_file_owner(conf, installed_file, pkg);
9409 + pkg_vec_free(installed_pkgs);
9414 +struct pkg_write_filelist_data {
9415 + ipkg_conf_t *conf;
9420 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9422 + struct pkg_write_filelist_data *data = data_;
9423 + pkg_t *entry = entry_;
9424 + if (entry == data->pkg) {
9425 + fprintf(data->stream, "%s\n", key);
9429 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9431 + struct pkg_write_filelist_data data;
9432 + char *list_file_name = NULL;
9436 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9439 + ipkg_message(conf, IPKG_INFO,
9440 + " creating %s.list file\n", pkg->name);
9441 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9442 + if (!list_file_name) {
9443 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9446 + ipkg_message(conf, IPKG_INFO,
9447 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9448 + data.stream = fopen(list_file_name, "w");
9449 + if (!data.stream) {
9450 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9451 + list_file_name, strerror(errno));
9456 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9457 + fclose(data.stream);
9458 + free(list_file_name);
9463 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9465 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9466 + hash_table_t *pkg_hash = &conf->pkg_hash;
9469 + if (conf->noaction)
9472 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9473 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9474 + for (i = 0; i < installed_pkgs->len; i++) {
9475 + pkg_t *pkg = installed_pkgs->pkgs[i];
9476 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9477 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9478 + err = pkg_write_filelist(conf, pkg);
9480 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9485 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.h
9486 --- busybox-1.1.2-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
9487 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg.h 2006-05-09 02:12:05.000000000 +0200
9489 +/* pkg.h - the itsy package management system
9493 + Copyright (C) 2001 University of Southern California
9495 + This program is free software; you can redistribute it and/or
9496 + modify it under the terms of the GNU General Public License as
9497 + published by the Free Software Foundation; either version 2, or (at
9498 + your option) any later version.
9500 + This program is distributed in the hope that it will be useful, but
9501 + WITHOUT ANY WARRANTY; without even the implied warranty of
9502 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9503 + General Public License for more details.
9509 +#include <sys/types.h>
9510 +#include <sys/stat.h>
9511 +#include <unistd.h>
9513 +#include "pkg_vec.h"
9514 +#include "str_list.h"
9515 +#include "pkg_src.h"
9516 +#include "pkg_dest.h"
9517 +#include "ipkg_conf.h"
9518 +#include "conffile_list.h"
9523 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
9525 +/* I think "Size" is currently the shortest field name */
9526 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
9528 +enum pkg_state_want
9534 + SW_LAST_STATE_WANT
9536 +typedef enum pkg_state_want pkg_state_want_t;
9538 +enum pkg_state_flag
9542 + SF_HOLD = 2, /* do not upgrade version */
9543 + SF_REPLACE = 4, /* replace this package */
9544 + SF_NOPRUNE = 8, /* do not remove obsolete files */
9545 + SF_PREFER = 16, /* prefer this version */
9546 + SF_OBSOLETE = 32, /* old package in upgrade pair */
9547 + SF_MARKED = 64, /* temporary mark */
9548 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
9550 + SF_LAST_STATE_FLAG
9552 +typedef enum pkg_state_flag pkg_state_flag_t;
9553 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
9555 +enum pkg_state_status
9557 + SS_NOT_INSTALLED = 1,
9559 + SS_HALF_CONFIGURED,
9561 + SS_HALF_INSTALLED,
9563 + SS_POST_INST_FAILED,
9564 + SS_REMOVAL_FAILED,
9565 + SS_LAST_STATE_STATUS
9567 +typedef enum pkg_state_status pkg_state_status_t;
9569 +struct abstract_pkg{
9571 + int dependencies_checked;
9573 + pkg_state_status_t state_status;
9574 + pkg_state_flag_t state_flag;
9575 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
9576 + abstract_pkg_vec_t * provided_by;
9577 + abstract_pkg_vec_t * replaced_by;
9580 +#include "pkg_depends.h"
9582 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
9584 + The 3 version fields should go into a single version struct. (This
9585 + is especially important since, currently, pkg->version can easily
9586 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
9587 + distinct. This has been the source of multiple bugs.
9589 + The 3 state fields could possibly also go into their own struct.
9591 + All fields which deal with lists of packages, (Depends,
9592 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
9593 + be handled by a single struct in pkg_t
9595 + All string fields for which there is a small set of possible
9596 + values, (section, maintainer, architecture, maybe version?), that
9597 + are reused among different packages -- for all such packages we
9598 + should move from "char *"s to some atom datatype to share data
9599 + storage and use less memory. We might even do reference counting,
9600 + but probably not since most often we only create new pkg_t structs,
9601 + we don't often free them. */
9605 + unsigned long epoch;
9608 + char *familiar_revision;
9611 + char *architecture;
9614 + char *description;
9615 + pkg_state_want_t state_want;
9616 + pkg_state_flag_t state_flag;
9617 + pkg_state_status_t state_status;
9618 + char **depends_str;
9619 + int depends_count;
9620 + char **pre_depends_str;
9621 + int pre_depends_count;
9622 + char **recommends_str;
9623 + int recommends_count;
9624 + char **suggests_str;
9625 + int suggests_count;
9626 + compound_depend_t * depends;
9628 + /* Abhaya: new conflicts */
9629 + char **conflicts_str;
9630 + compound_depend_t * conflicts;
9631 + int conflicts_count;
9633 + char **replaces_str;
9634 + int replaces_count;
9635 + abstract_pkg_t ** replaces;
9637 + char **provides_str;
9638 + int provides_count;
9639 + abstract_pkg_t ** provides;
9641 + abstract_pkg_t *parent;
9643 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
9646 + char *local_filename;
9648 + char *tmp_unpack_dir;
9651 + char *installed_size;
9654 + conffile_list_t conffiles;
9655 + time_t installed_time;
9656 + /* As pointer for lazy evaluation */
9657 + str_list_t *installed_files;
9658 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
9659 + mechanism to avoid the problem here, (which is that the
9660 + installed_files list was being freed from an inner loop while
9661 + still being used within an outer loop. */
9662 + int installed_files_ref_cnt;
9664 + int arch_priority;
9665 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
9666 + int provided_by_hand;
9669 +pkg_t *pkg_new(void);
9670 +int pkg_init(pkg_t *pkg);
9671 +void pkg_deinit(pkg_t *pkg);
9672 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
9673 +abstract_pkg_t *abstract_pkg_new(void);
9674 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
9677 + * merges fields from newpkg into oldpkg.
9678 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
9680 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
9682 +char *pkg_version_str_alloc(pkg_t *pkg);
9684 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
9685 +int pkg_name_version_and_architecture_compare(void *a, void *b);
9686 +int abstract_pkg_name_compare(void *a, void *b);
9688 +char * pkg_formatted_info(pkg_t *pkg );
9689 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
9691 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
9693 +void pkg_print_info(pkg_t *pkg, FILE *file);
9694 +void pkg_print_status(pkg_t * pkg, FILE * file);
9695 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
9696 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
9697 +int pkg_free_installed_files(pkg_t *pkg);
9698 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
9699 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
9700 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
9701 + const char *script, const char *args);
9703 +/* enum mappings */
9704 +char *pkg_state_want_to_str(pkg_state_want_t sw);
9705 +pkg_state_want_t pkg_state_want_from_str(char *str);
9706 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
9707 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
9708 +char *pkg_state_status_to_str(pkg_state_status_t ss);
9709 +pkg_state_status_t pkg_state_status_from_str(char *str);
9711 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
9713 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
9714 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
9715 +int pkg_free_installed_files(pkg_t *pkg);
9717 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
9718 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
9721 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_depends.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.c
9722 --- busybox-1.1.2-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9723 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-05-09 02:12:05.000000000 +0200
9725 +/* pkg_depends.c - the itsy package management system
9729 + Copyright (C) 2002 Compaq Computer Corporation
9731 + This program is free software; you can redistribute it and/or
9732 + modify it under the terms of the GNU General Public License as
9733 + published by the Free Software Foundation; either version 2, or (at
9734 + your option) any later version.
9736 + This program is distributed in the hope that it will be useful, but
9737 + WITHOUT ANY WARRANTY; without even the implied warranty of
9738 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9739 + General Public License for more details.
9747 +#include "ipkg_utils.h"
9748 +#include "pkg_hash.h"
9749 +#include "ipkg_message.h"
9750 +#include "pkg_parse.h"
9751 +#include "hash_table.h"
9753 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9754 +static depend_t * depend_init(void);
9755 +static void depend_deinit(depend_t *d);
9756 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9757 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9758 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9760 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9762 + depend_t *depend = (depend_t *)cdata;
9763 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9769 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9771 + depend_t *depend = (depend_t *)cdata;
9773 + pkg_t * temp = pkg_new();
9775 + parseVersion(temp, depend->version);
9776 + comparison = pkg_compare_versions(pkg, temp);
9779 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9780 + __FUNCTION__, pkg->name, pkg->version,
9781 + depend, depend->constraint, depend->version,
9782 + comparison, version_constraints_satisfied(depend, pkg));
9784 + if (version_constraints_satisfied(depend, pkg))
9790 +/* returns ndependences or negative error value */
9791 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9792 + pkg_vec_t *unsatisfied, char *** unresolved)
9794 + pkg_t * satisfier_entry_pkg;
9795 + register int i, j, k;
9798 + abstract_pkg_t * ab_pkg;
9801 + * this is a setup to check for redundant/cyclic dependency checks,
9802 + * which are marked at the abstract_pkg level
9804 + if (!(ab_pkg = pkg->parent)) {
9805 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9806 + *unresolved = NULL;
9809 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9810 + *unresolved = NULL;
9813 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9817 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9819 + *unresolved = NULL;
9825 + /* foreach dependency */
9826 + for (i = 0; i < count; i++) {
9827 + compound_depend_t * compound_depend = &pkg->depends[i];
9828 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9830 + satisfier_entry_pkg = NULL;
9832 + if (compound_depend->type == GREEDY_DEPEND) {
9833 + /* foreach possible satisfier */
9834 + for (j = 0; j < compound_depend->possibility_count; j++) {
9835 + /* foreach provided_by, which includes the abstract_pkg itself */
9836 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9837 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9838 + int nposs = ab_provider_vec->len;
9839 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9841 + for (l = 0; l < nposs; l++) {
9842 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9843 + /* if no depends on this one, try the first package that Provides this one */
9844 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9848 + /* cruise this possiblity's pkg_vec looking for an installed version */
9849 + for (k = 0; k < test_vec->len; k++) {
9850 + pkg_t *pkg_scout = test_vec->pkgs[k];
9851 + /* not installed, and not already known about? */
9852 + if ((pkg_scout->state_want != SW_INSTALL)
9853 + && !pkg_scout->parent->dependencies_checked
9854 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9855 + char ** newstuff = NULL;
9857 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9858 + /* check for not-already-installed dependencies */
9859 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9863 + if (newstuff == NULL) {
9866 + for (i = 0; i < rc; i++) {
9867 + pkg_t *p = tmp_vec->pkgs[i];
9868 + if (p->state_want == SW_INSTALL)
9870 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9874 + pkg_vec_free (tmp_vec);
9876 + /* mark this one for installation */
9877 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9878 + pkg_vec_insert(unsatisfied, pkg_scout);
9881 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9892 + /* foreach possible satisfier, look for installed package */
9893 + for (j = 0; j < compound_depend->possibility_count; j++) {
9894 + /* foreach provided_by, which includes the abstract_pkg itself */
9895 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9896 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9897 + pkg_t *satisfying_pkg =
9898 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9899 + pkg_installed_and_constraint_satisfied,
9900 + dependence_to_satisfy, 1);
9901 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9902 + if (satisfying_pkg != NULL) {
9903 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9904 + satisfying_pkg = NULL;
9907 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9908 + if (satisfying_pkg != NULL) {
9914 + /* if nothing installed matches, then look for uninstalled satisfier */
9916 + /* foreach possible satisfier, look for installed package */
9917 + for (j = 0; j < compound_depend->possibility_count; j++) {
9918 + /* foreach provided_by, which includes the abstract_pkg itself */
9919 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9920 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9921 + pkg_t *satisfying_pkg =
9922 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9923 + pkg_constraint_satisfied,
9924 + dependence_to_satisfy, 1);
9925 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9926 + if (satisfying_pkg != NULL) {
9927 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9928 + satisfying_pkg = NULL;
9932 + /* user request overrides package recommendation */
9933 + if (satisfying_pkg != NULL
9934 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9935 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9936 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9937 + pkg->name, satisfying_pkg->name);
9941 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9942 + if (satisfying_pkg != NULL) {
9943 + satisfier_entry_pkg = satisfying_pkg;
9949 + /* we didn't find one, add something to the unsatisfied vector */
9951 + if (!satisfier_entry_pkg) {
9952 + /* failure to meet recommendations is not an error */
9953 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9954 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9956 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9957 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9960 + if (compound_depend->type == SUGGEST) {
9961 + /* just mention it politely */
9962 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9963 + pkg->name, satisfier_entry_pkg->name);
9965 + char ** newstuff = NULL;
9967 + if (satisfier_entry_pkg != pkg &&
9968 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9969 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9970 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9971 + satisfier_entry_pkg,
9974 + the_lost = merge_unresolved(the_lost, newstuff);
9980 + *unresolved = the_lost;
9982 + return unsatisfied->len;
9985 +/*checking for conflicts !in replaces
9986 + If a packages conflicts with another but is also replacing it, I should not consider it a
9988 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9990 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9993 + int replaces_count = pkg->replaces_count;
9994 + abstract_pkg_t **replaces;
9996 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9999 + replaces = pkg->replaces;
10001 + for (i = 0; i < replaces_count; i++) {
10002 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
10003 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
10012 +/* Abhaya: added support for conflicts */
10013 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
10015 + pkg_vec_t * installed_conflicts, * test_vec;
10016 + compound_depend_t * conflicts;
10017 + depend_t ** possible_satisfiers;
10018 + depend_t * possible_satisfier;
10019 + register int i, j, k;
10021 + abstract_pkg_t * ab_pkg;
10022 + pkg_t **pkg_scouts;
10023 + pkg_t *pkg_scout;
10026 + * this is a setup to check for redundant/cyclic dependency checks,
10027 + * which are marked at the abstract_pkg level
10029 + if(!(ab_pkg = pkg->parent)){
10030 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
10031 + return (pkg_vec_t *)NULL;
10034 + conflicts = pkg->conflicts;
10036 + return (pkg_vec_t *)NULL;
10038 + installed_conflicts = pkg_vec_alloc();
10040 + count = pkg->conflicts_count;
10044 + /* foreach conflict */
10045 + for(i = 0; i < pkg->conflicts_count; i++){
10047 + possible_satisfiers = conflicts->possibilities;
10049 + /* foreach possible satisfier */
10050 + for(j = 0; j < conflicts->possibility_count; j++){
10051 + possible_satisfier = possible_satisfiers[j];
10052 + if (!possible_satisfier)
10053 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
10054 + if (!possible_satisfier->pkg)
10055 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
10056 + test_vec = possible_satisfier->pkg->pkgs;
10058 + /* pkg_vec found, it is an actual package conflict
10059 + * cruise this possiblity's pkg_vec looking for an installed version */
10060 + pkg_scouts = test_vec->pkgs;
10061 + for(k = 0; k < test_vec->len; k++){
10062 + pkg_scout = pkg_scouts[k];
10063 + if (!pkg_scout) {
10064 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
10067 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
10068 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
10069 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
10070 + pkg_vec_insert(installed_conflicts, pkg_scout);
10079 + if (installed_conflicts->len)
10080 + return installed_conflicts;
10081 + pkg_vec_free(installed_conflicts);
10082 + return (pkg_vec_t *)NULL;
10085 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
10090 + if(depends->constraint == NONE)
10093 + temp = pkg_new();
10095 + parseVersion(temp, depends->version);
10097 + comparison = pkg_compare_versions(pkg, temp);
10101 + if((depends->constraint == EARLIER) &&
10102 + (comparison < 0))
10104 + else if((depends->constraint == LATER) &&
10105 + (comparison > 0))
10107 + else if(comparison == 0)
10109 + else if((depends->constraint == LATER_EQUAL) &&
10110 + (comparison >= 0))
10112 + else if((depends->constraint == EARLIER_EQUAL) &&
10113 + (comparison <= 0))
10119 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
10121 + abstract_pkg_t *apkg = depend->pkg;
10122 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
10123 + int n_providers = provider_apkgs->len;
10124 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
10125 + pkg_vec_t *pkg_vec;
10130 + for (i = 0; i < n_providers; i++) {
10131 + abstract_pkg_t *papkg = apkgs[i];
10132 + pkg_vec = papkg->pkgs;
10134 + n_pkgs = pkg_vec->len;
10135 + for (j = 0; j < n_pkgs; j++) {
10136 + pkg_t *pkg = pkg_vec->pkgs[j];
10137 + if (version_constraints_satisfied(depend, pkg)) {
10146 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
10148 + abstract_pkg_t *apkg = depend->pkg;
10149 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
10150 + int n_providers = provider_apkgs->len;
10151 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
10156 + for (i = 0; i < n_providers; i++) {
10157 + abstract_pkg_t *papkg = apkgs[i];
10158 + pkg_vec_t *pkg_vec = papkg->pkgs;
10160 + n_pkgs = pkg_vec->len;
10161 + for (j = 0; j < n_pkgs; j++) {
10162 + pkg_t *pkg = pkg_vec->pkgs[j];
10163 + if (version_constraints_satisfied(depend, pkg)) {
10164 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
10173 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
10176 + pkg_t ** pkgs = vec->pkgs;
10178 + for(i = 0; i < vec->len; i++)
10179 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
10180 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
10181 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
10189 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10190 + * the same abstract package and 0 otherwise.
10192 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
10194 + abstract_pkg_t **provides = pkg->provides;
10195 + int provides_count = pkg->provides_count;
10196 + abstract_pkg_t **replacee_provides = replacee->provides;
10197 + int replacee_provides_count = replacee->provides_count;
10199 + for (i = 0; i < provides_count; i++) {
10200 + abstract_pkg_t *apkg = provides[i];
10201 + for (j = 0; j < replacee_provides_count; j++) {
10202 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
10203 + if (apkg == replacee_apkg)
10212 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
10213 + * and 0 otherwise.
10215 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
10217 + abstract_pkg_t **provides = pkg->provides;
10218 + int provides_count = pkg->provides_count;
10220 + for (i = 0; i < provides_count; i++) {
10221 + if (provides[i] == providee)
10228 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10231 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
10233 + abstract_pkg_t **replaces = pkg->replaces;
10234 + int replaces_count = pkg->replaces_count;
10235 + /* abstract_pkg_t **replacee_provides = pkg->provides;
10236 + int replacee_provides_count = pkg->provides_count; */
10238 + for (i = 0; i < replaces_count; i++) {
10239 + abstract_pkg_t *abstract_replacee = replaces[i];
10240 + for (j = 0; j < replaces_count; j++) {
10241 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
10242 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
10243 + if (replacee->provides[j] == abstract_replacee)
10252 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10255 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10257 + compound_depend_t *conflicts = pkg->conflicts;
10258 + int conflicts_count = pkg->conflicts_count;
10260 + for (i = 0; i < conflicts_count; i++) {
10261 + int possibility_count = conflicts[i].possibility_count;
10262 + struct depend **possibilities = conflicts[i].possibilities;
10263 + for (j = 0; j < possibility_count; j++) {
10264 + if (possibilities[j]->pkg == conflictee) {
10273 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10274 + * conflictee's provides and 0 otherwise.
10276 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10278 + compound_depend_t *conflicts = pkg->conflicts;
10279 + int conflicts_count = pkg->conflicts_count;
10280 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10281 + int conflictee_provides_count = conflictee->provides_count;
10283 + int possibility_count;
10284 + struct depend **possibilities;
10285 + abstract_pkg_t *possibility ;
10287 + for (i = 0; i < conflicts_count; i++) {
10288 + possibility_count = conflicts[i].possibility_count;
10289 + possibilities = conflicts[i].possibilities;
10290 + for (j = 0; j < possibility_count; j++) {
10291 + possibility = possibilities[j]->pkg;
10292 + for (k = 0; k < conflictee_provides_count; k++) {
10293 + if (possibility == conflictee_provides[k]) {
10302 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10304 + int oldlen = 0, newlen = 0;
10306 + register int i, j;
10311 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10312 + while(newstuff && newstuff[newlen]) newlen++;
10314 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10315 + if (result == NULL) {
10316 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10320 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10321 + *(result + i) = *(newstuff + j);
10323 + *(result + i) = NULL;
10329 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10330 + * this is null terminated, no count is carried around
10332 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10336 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10339 + while(the_lost && the_lost[count]) count++;
10341 + count++; /* need one to hold the null */
10342 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10343 + if (resized == NULL) {
10344 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10347 + resized[count - 1] = strdup(depend_str);
10348 + resized[count] = NULL;
10353 +void printDepends(pkg_t * pkg)
10355 + register int i, j;
10356 + compound_depend_t * depend;
10359 + count = pkg->pre_depends_count + pkg->depends_count;
10361 + depend = pkg->depends;
10363 + fprintf(stderr, "Depends pointer is NULL\n");
10366 + for(i = 0; i < count; i++){
10367 + fprintf(stderr, "%s has %d possibilities:\n",
10368 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10369 + depend->possibility_count);
10370 + for(j = 0; j < depend->possibility_count; j++)
10371 + fprintf(stderr, "\t%s version %s (%d)\n",
10372 + depend->possibilities[j]->pkg->name,
10373 + depend->possibilities[j]->version,
10374 + depend->possibilities[j]->constraint);
10379 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10381 + register int i, j;
10383 + /* every pkg provides itself */
10384 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10386 + if (!pkg->provides_count)
10389 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10390 + if (pkg->provides == NULL) {
10391 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10394 + pkg->provides[0] = ab_pkg;
10396 + // if (strcmp(ab_pkg->name, pkg->name))
10397 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10399 + for(i = 0; i < pkg->provides_count; i++){
10400 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10402 + pkg->provides[i+1] = provided_abpkg;
10405 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10410 +/* Abhaya: added conflicts support */
10411 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10414 + compound_depend_t * conflicts;
10416 + if (!pkg->conflicts_count)
10419 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10420 + pkg->conflicts_count);
10421 + if (conflicts == NULL) {
10422 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10425 + for (i = 0; i < pkg->conflicts_count; i++) {
10426 + conflicts->type = CONFLICTS;
10427 + parseDepends(conflicts, hash,
10428 + pkg->conflicts_str[i]);
10430 + for (j = 0; j < conflicts->possibility_count; j++) {
10431 + depend_t *possibility = conflicts->possibilities[j];
10432 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10433 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10441 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10443 + register int i, j;
10445 + if (!pkg->replaces_count)
10448 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10449 + if (pkg->replaces == NULL) {
10450 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10454 + // if (strcmp(ab_pkg->name, pkg->name))
10455 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10457 + for(i = 0; i < pkg->replaces_count; i++){
10458 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10460 + pkg->replaces[i] = old_abpkg;
10463 + if (!old_abpkg->replaced_by)
10464 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10465 + if ( old_abpkg->replaced_by == NULL ){
10468 + /* if a package pkg both replaces and conflicts old_abpkg,
10469 + * then add it to the replaced_by vector so that old_abpkg
10470 + * will be upgraded to ab_pkg automatically */
10471 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10472 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10477 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10481 + compound_depend_t * depends;
10483 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10486 + if (0 && pkg->pre_depends_count)
10487 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10488 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10489 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10490 + if (depends == NULL) {
10491 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10496 + for(i = 0; i < pkg->pre_depends_count; i++){
10497 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10498 + if (0 && pkg->pre_depends_count)
10499 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10500 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10501 + depends->type = PREDEPEND;
10505 + for(i = 0; i < pkg->recommends_count; i++){
10506 + parseDepends(depends, hash, pkg->recommends_str[i]);
10507 + if (0 && pkg->recommends_count)
10508 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10509 + pkg->recommends_str[i], depends, depends->possibility_count);
10510 + depends->type = RECOMMEND;
10514 + for(i = 0; i < pkg->suggests_count; i++){
10515 + parseDepends(depends, hash, pkg->suggests_str[i]);
10516 + if (0 && pkg->suggests_count)
10517 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10518 + pkg->suggests_str[i], depends, depends->possibility_count);
10519 + depends->type = SUGGEST;
10523 + for(i = 0; i < pkg->depends_count; i++){
10524 + parseDepends(depends, hash, pkg->depends_str[i]);
10525 + if (0 && pkg->depends_count)
10526 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10527 + pkg->depends_str[i], depends, depends->possibility_count);
10534 + * pkg_depend_string: returns the depends string specified by index.
10535 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10536 + * [0,npredepends) -> returns pre_depends_str[index]
10537 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10538 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10539 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10541 +char *pkg_depend_str(pkg_t *pkg, int index)
10543 + if (index < pkg->pre_depends_count) {
10544 + return pkg->pre_depends_str[index];
10546 + index -= pkg->pre_depends_count;
10548 + if (index < pkg->recommends_count) {
10549 + return pkg->recommends_str[index];
10551 + index -= pkg->recommends_count;
10553 + if (index < pkg->suggests_count) {
10554 + return pkg->suggests_str[index];
10556 + index -= pkg->suggests_count;
10558 + if (index < pkg->depends_count) {
10559 + return pkg->depends_str[index];
10561 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10565 +void freeDepends(pkg_t *pkg)
10569 + if (pkg == NULL || pkg->depends == NULL) {
10573 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10574 + for (i=0; i < pkg->depends->possibility_count; i++) {
10575 + depend_deinit(pkg->depends->possibilities[i]);
10577 + free(pkg->depends->possibilities);
10578 + free(pkg->depends);
10579 + pkg->depends = NULL;
10582 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10584 + compound_depend_t * depends;
10585 + int count, othercount;
10586 + register int i, j;
10587 + abstract_pkg_t * ab_depend;
10588 + abstract_pkg_t ** temp;
10590 + count = pkg->pre_depends_count + pkg->depends_count;
10591 + depends = pkg->depends;
10593 + if (0 && pkg->pre_depends_count)
10594 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10595 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10596 + for (i = 0; i < count; i++) {
10597 + if (0 && pkg->pre_depends_count)
10598 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10599 + for (j = 0; j < depends->possibility_count; j++){
10600 + ab_depend = depends->possibilities[j]->pkg;
10601 + if(!ab_depend->depended_upon_by)
10602 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10604 + temp = ab_depend->depended_upon_by;
10612 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10613 + (othercount + 1) * sizeof(abstract_pkg_t *));
10614 + /* the array may have moved */
10615 + temp = ab_depend->depended_upon_by + othercount;
10622 +static depend_t * depend_init(void)
10624 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10626 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10629 + d->constraint = NONE;
10630 + d->version = NULL;
10636 +static void depend_deinit(depend_t *d)
10641 +static int parseDepends(compound_depend_t *compound_depend,
10642 + hash_table_t * hash, char * depend_str)
10644 + char * pkg_name, buffer[2048];
10645 + int num_of_ors = 0;
10647 + register char * src, * dest;
10648 + depend_t ** possibilities;
10650 + /* first count the number of ored possibilities for satisfying dependency */
10651 + src = depend_str;
10653 + if(*src++ == '|')
10656 + compound_depend->type = DEPEND;
10658 + compound_depend->possibility_count = num_of_ors + 1;
10659 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10660 + if (!possibilities)
10662 + compound_depend->possibilities = possibilities;
10664 + src = depend_str;
10665 + for(i = 0; i < num_of_ors + 1; i++){
10666 + possibilities[i] = depend_init();
10667 + if (!possibilities[i])
10669 + /* gobble up just the name first */
10672 + !isspace(*src) &&
10676 + *dest++ = *src++;
10678 + pkg_name = trim_alloc(buffer);
10679 + if (pkg_name == NULL )
10682 + /* now look at possible version info */
10684 + /* skip to next chars */
10685 + if(isspace(*src))
10686 + while(*src && isspace(*src)) src++;
10688 + /* extract constraint and version */
10691 + if(!strncmp(src, "<<", 2)){
10692 + possibilities[i]->constraint = EARLIER;
10695 + else if(!strncmp(src, "<=", 2)){
10696 + possibilities[i]->constraint = EARLIER_EQUAL;
10699 + else if(!strncmp(src, ">=", 2)){
10700 + possibilities[i]->constraint = LATER_EQUAL;
10703 + else if(!strncmp(src, ">>", 2)){
10704 + possibilities[i]->constraint = LATER;
10707 + else if(!strncmp(src, "=", 1)){
10708 + possibilities[i]->constraint = EQUAL;
10711 + /* should these be here to support deprecated designations; dpkg does */
10712 + else if(!strncmp(src, "<", 1)){
10713 + possibilities[i]->constraint = EARLIER_EQUAL;
10716 + else if(!strncmp(src, ">", 1)){
10717 + possibilities[i]->constraint = LATER_EQUAL;
10721 + /* now we have any constraint, pass space to version string */
10722 + while(isspace(*src)) src++;
10724 + /* this would be the version string */
10726 + while(*src && *src != ')')
10727 + *dest++ = *src++;
10730 + possibilities[i]->version = trim_alloc(buffer);
10731 + /* fprintf(stderr, "let's print the depends version string:");
10732 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10733 + if (possibilities[i]->version == NULL )
10738 + /* hook up the dependency to its abstract pkg */
10739 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10743 + /* now get past the ) and any possible | chars */
10745 + (isspace(*src) ||
10751 + compound_depend->type = GREEDY_DEPEND;
10758 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_depends.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.h
10759 --- busybox-1.1.2-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10760 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-05-09 02:06:48.000000000 +0200
10762 +/* pkg_depends.h - the itsy package management system
10766 + Copyright (C) 2002 Compaq Computer Corporation
10768 + This program is free software; you can redistribute it and/or
10769 + modify it under the terms of the GNU General Public License as
10770 + published by the Free Software Foundation; either version 2, or (at
10771 + your option) any later version.
10773 + This program is distributed in the hope that it will be useful, but
10774 + WITHOUT ANY WARRANTY; without even the implied warranty of
10775 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10776 + General Public License for more details.
10779 +#ifndef PKG_DEPENDS_H
10780 +#define PKG_DEPENDS_H
10783 +#include "pkg_hash.h"
10785 +enum depend_type {
10793 +typedef enum depend_type depend_type_t;
10795 +enum version_constraint {
10803 +typedef enum version_constraint version_constraint_t;
10806 + version_constraint_t constraint;
10808 + abstract_pkg_t * pkg;
10810 +typedef struct depend depend_t;
10812 +struct compound_depend{
10813 + depend_type_t type;
10814 + int possibility_count;
10815 + struct depend ** possibilities;
10817 +typedef struct compound_depend compound_depend_t;
10819 +#include "hash_table.h"
10821 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10822 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10823 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10824 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10827 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10828 + * the same abstract package and 0 otherwise.
10830 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10833 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10836 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10839 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10842 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10845 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10848 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10851 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10854 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10856 +char *pkg_depend_str(pkg_t *pkg, int index);
10857 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10858 +void freeDepends(pkg_t *pkg);
10859 +void printDepends(pkg_t * pkg);
10860 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10861 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10862 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10863 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10864 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10867 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.c
10868 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10869 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-05-09 02:06:48.000000000 +0200
10871 +/* pkg_dest.c - the itsy package management system
10875 + Copyright (C) 2001 University of Southern California
10877 + This program is free software; you can redistribute it and/or
10878 + modify it under the terms of the GNU General Public License as
10879 + published by the Free Software Foundation; either version 2, or (at
10880 + your option) any later version.
10882 + This program is distributed in the hope that it will be useful, but
10883 + WITHOUT ANY WARRANTY; without even the implied warranty of
10884 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10885 + General Public License for more details.
10890 +#include "pkg_dest.h"
10891 +#include "file_util.h"
10892 +#include "str_util.h"
10893 +#include "sprintf_alloc.h"
10895 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10897 + dest->name = strdup(name);
10899 + /* Guarantee that dest->root_dir ends with a '/' */
10900 + if (str_ends_with(root_dir, "/")) {
10901 + dest->root_dir = strdup(root_dir);
10903 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10905 + file_mkdir_hier(dest->root_dir, 0755);
10907 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10908 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10909 + file_mkdir_hier(dest->ipkg_dir, 0755);
10911 + if (str_starts_with (lists_dir, "/"))
10912 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10914 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10916 + file_mkdir_hier(dest->lists_dir, 0755);
10918 + sprintf_alloc(&dest->info_dir, "%s/%s",
10919 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10920 + file_mkdir_hier(dest->info_dir, 0755);
10922 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10923 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10925 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10926 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10928 + dest->status_file = NULL;
10933 +void pkg_dest_deinit(pkg_dest_t *dest)
10935 + free(dest->name);
10936 + dest->name = NULL;
10938 + free(dest->root_dir);
10939 + dest->root_dir = NULL;
10941 + free(dest->ipkg_dir);
10942 + dest->ipkg_dir = NULL;
10944 + free(dest->lists_dir);
10945 + dest->lists_dir = NULL;
10947 + free(dest->info_dir);
10948 + dest->info_dir = NULL;
10950 + free(dest->status_file_name);
10951 + dest->status_file_name = NULL;
10953 + free(dest->status_file_tmp_name);
10954 + dest->status_file_tmp_name = NULL;
10956 + if (dest->status_file) {
10957 + fclose(dest->status_file);
10959 + dest->status_file = NULL;
10961 + dest->root_dir = NULL;
10963 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.h
10964 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10965 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-05-09 02:06:48.000000000 +0200
10967 +/* pkg_dest.h - the itsy package management system
10971 + Copyright (C) 2001 University of Southern California
10973 + This program is free software; you can redistribute it and/or
10974 + modify it under the terms of the GNU General Public License as
10975 + published by the Free Software Foundation; either version 2, or (at
10976 + your option) any later version.
10978 + This program is distributed in the hope that it will be useful, but
10979 + WITHOUT ANY WARRANTY; without even the implied warranty of
10980 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10981 + General Public License for more details.
10984 +#ifndef PKG_DEST_H
10985 +#define PKG_DEST_H
10987 +typedef struct pkg_dest pkg_dest_t;
10995 + char *status_file_name;
10996 + char *status_file_tmp_name;
10997 + FILE *status_file;
11000 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
11001 +void pkg_dest_deinit(pkg_dest_t *dest);
11005 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c
11006 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
11007 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-05-09 02:06:48.000000000 +0200
11009 +/* pkg_dest_list.c - the itsy package management system
11013 + Copyright (C) 2001 University of Southern California
11015 + This program is free software; you can redistribute it and/or
11016 + modify it under the terms of the GNU General Public License as
11017 + published by the Free Software Foundation; either version 2, or (at
11018 + your option) any later version.
11020 + This program is distributed in the hope that it will be useful, but
11021 + WITHOUT ANY WARRANTY; without even the implied warranty of
11022 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11023 + General Public License for more details.
11028 +#include "pkg_dest.h"
11029 +#include "void_list.h"
11030 +#include "pkg_dest_list.h"
11032 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
11034 + return void_list_elt_init((void_list_elt_t *) elt, data);
11037 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
11039 + void_list_elt_deinit((void_list_elt_t *) elt);
11042 +int pkg_dest_list_init(pkg_dest_list_t *list)
11044 + return void_list_init((void_list_t *) list);
11047 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
11049 + pkg_dest_list_elt_t *iter;
11050 + pkg_dest_t *pkg_dest;
11052 + for (iter = list->head; iter; iter = iter->next) {
11053 + pkg_dest = iter->data;
11054 + pkg_dest_deinit(pkg_dest);
11056 + /* malloced in pkg_dest_list_append */
11058 + iter->data = NULL;
11060 + void_list_deinit((void_list_t *) list);
11063 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
11064 + const char *root_dir,const char *lists_dir)
11067 + pkg_dest_t *pkg_dest;
11069 + /* freed in plg_dest_list_deinit */
11070 + pkg_dest = malloc(sizeof(pkg_dest_t));
11071 + if (pkg_dest == NULL) {
11072 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
11076 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
11077 + err = void_list_append((void_list_t *) list, pkg_dest);
11085 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
11087 + return void_list_push((void_list_t *) list, data);
11090 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
11092 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
11094 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h
11095 --- busybox-1.1.2-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
11096 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-05-09 02:06:48.000000000 +0200
11098 +/* pkg_dest_list.h - the itsy package management system
11102 + Copyright (C) 2001 University of Southern California
11104 + This program is free software; you can redistribute it and/or
11105 + modify it under the terms of the GNU General Public License as
11106 + published by the Free Software Foundation; either version 2, or (at
11107 + your option) any later version.
11109 + This program is distributed in the hope that it will be useful, but
11110 + WITHOUT ANY WARRANTY; without even the implied warranty of
11111 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11112 + General Public License for more details.
11115 +#ifndef PKG_DEST_LIST_H
11116 +#define PKG_DEST_LIST_H
11118 +#include "pkg_dest.h"
11120 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
11121 +struct pkg_dest_list_elt
11123 + pkg_dest_list_elt_t *next;
11124 + pkg_dest_t *data;
11127 +typedef struct pkg_dest_list pkg_dest_list_t;
11128 +struct pkg_dest_list
11130 + pkg_dest_list_elt_t pre_head;
11131 + pkg_dest_list_elt_t *head;
11132 + pkg_dest_list_elt_t *tail;
11135 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
11136 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
11138 +int pkg_dest_list_init(pkg_dest_list_t *list);
11139 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
11141 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
11142 + const char *root_dir,const char* lists_dir);
11143 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
11144 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
11148 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_extract.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.c
11149 --- busybox-1.1.2-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
11150 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-05-09 02:06:48.000000000 +0200
11152 +/* pkg_extract.c - the itsy package management system
11156 + Copyright (C) 2001 University of Southern California
11158 + This program is free software; you can redistribute it and/or
11159 + modify it under the terms of the GNU General Public License as
11160 + published by the Free Software Foundation; either version 2, or (at
11161 + your option) any later version.
11163 + This program is distributed in the hope that it will be useful, but
11164 + WITHOUT ANY WARRANTY; without even the implied warranty of
11165 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11166 + General Public License for more details.
11170 +#include <errno.h>
11171 +#include <fcntl.h>
11172 +#include <stdio.h>
11174 +#include "pkg_extract.h"
11176 +#include "libbb.h"
11177 +#include "file_util.h"
11178 +#include "sprintf_alloc.h"
11179 +#include "unarchive.h"
11181 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
11182 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
11183 +#define IPKG_CONTROL_FILE "control"
11185 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
11187 + archive_handle_t *archive;
11190 + sprintf_alloc(&path, "%s/", dir);
11191 + archive = init_handle();
11192 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
11193 + archive->filter = filter_accept_list;
11194 + archive->accept = llist_add_to(NULL, (char *)filename);
11195 + archive->buffer = path;
11196 + archive->action_data = data_extract_all_prefix;
11197 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
11198 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11199 + close(archive->src_fd);
11200 + free(archive->accept);
11205 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
11207 + unsigned int size = strlen(archive->file_header->name) + 2;
11209 + if (archive->buffer == NULL) {
11210 + archive->buffer = xmalloc(size);
11211 + strcpy(archive->buffer, archive->file_header->name);
11213 + size += strlen(archive->buffer);
11214 + archive->buffer = xrealloc(archive->buffer, size);
11215 + strcat(archive->buffer, archive->file_header->name);
11217 + strcat(archive->buffer, "\n");
11218 + data_skip(archive);
11221 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
11223 + archive_handle_t *archive;
11226 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11227 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11228 + archive = init_handle();
11229 + archive->src_fd = bb_xopen(name, O_RDONLY);
11230 + archive->filter = filter_accept_list;
11231 + archive->accept = llist_add_to(NULL, "./" IPKG_CONTROL_FILE);
11232 + archive->action_data = data_extract_to_buffer;
11233 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11234 + close(archive->src_fd);
11235 + fputs(archive->buffer, stream);
11236 + free(archive->buffer);
11237 + free(archive->accept);
11244 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
11246 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
11249 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
11251 + archive_handle_t *archive;
11255 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11256 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11257 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11258 + archive = init_handle();
11259 + archive->src_fd = bb_xopen(name, O_RDONLY);
11260 + archive->filter = filter_accept_all;
11261 + archive->buffer = path;
11262 + archive->action_data = data_extract_all_prefix;
11263 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11264 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11265 + close(archive->src_fd);
11273 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11275 + archive_handle_t *archive;
11279 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11280 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11281 + sprintf_alloc(&path, "%s/", dir);
11282 + archive = init_handle();
11283 + archive->src_fd = bb_xopen(name, O_RDONLY);
11284 + archive->filter = filter_accept_all;
11285 + archive->buffer = path;
11286 + archive->action_data = data_extract_all_prefix;
11287 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11288 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11289 + close(archive->src_fd);
11297 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11300 + char *line, *data_file;
11304 + file = fopen(file_name, "w");
11305 + if (file == NULL) {
11306 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11307 + __FUNCTION__, file_name);
11312 + if (pkg->installed_files) {
11313 + str_list_elt_t *elt;
11314 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11315 + fprintf(file, "%s\n", elt->data);
11318 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11325 + /* Fixup data file names by removing the initial '.' */
11328 + line = file_read_line_alloc(tmp);
11329 + if (line == NULL) {
11333 + data_file = line;
11334 + if (*data_file == '.') {
11338 + if (*data_file != '/') {
11339 + fputs("/", file);
11342 + /* I have no idea why, but this is what dpkg does */
11343 + if (strcmp(data_file, "/\n") == 0) {
11344 + fputs("/.\n", file);
11346 + fputs(data_file, file);
11356 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11358 + archive_handle_t *archive;
11361 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11362 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11363 + archive = init_handle();
11364 + archive->src_fd = bb_xopen(name, O_RDONLY);
11365 + archive->filter = filter_accept_all;
11366 + archive->action_data = data_extract_file_name_to_buffer;
11367 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11368 + close(archive->src_fd);
11369 + fputs(archive->buffer, file);
11370 + free(archive->buffer);
11376 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_extract.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.h
11377 --- busybox-1.1.2-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11378 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-05-09 02:06:48.000000000 +0200
11380 +/* pkg_extract.c - the itsy package management system
11384 + Copyright (C) 2001 University of Southern California
11386 + This program is free software; you can redistribute it and/or
11387 + modify it under the terms of the GNU General Public License as
11388 + published by the Free Software Foundation; either version 2, or (at
11389 + your option) any later version.
11391 + This program is distributed in the hope that it will be useful, but
11392 + WITHOUT ANY WARRANTY; without even the implied warranty of
11393 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11394 + General Public License for more details.
11397 +#ifndef PKG_EXTRACT_H
11398 +#define PKG_EXTRACT_H
11402 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11403 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11404 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11406 + const char *prefix);
11407 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11408 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11409 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11412 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_hash.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.c
11413 --- busybox-1.1.2-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11414 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-05-09 02:12:05.000000000 +0200
11416 +/* ipkg_hash.c - the itsy package management system
11420 + Copyright (C) 2002 Compaq Computer Corporation
11422 + This program is free software; you can redistribute it and/or
11423 + modify it under the terms of the GNU General Public License as
11424 + published by the Free Software Foundation; either version 2, or (at
11425 + your option) any later version.
11427 + This program is distributed in the hope that it will be useful, but
11428 + WITHOUT ANY WARRANTY; without even the implied warranty of
11429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11430 + General Public License for more details.
11434 +#include <errno.h>
11435 +#include <ctype.h>
11436 +#include <stdlib.h>
11437 +#include <string.h>
11439 +#include "hash_table.h"
11441 +#include "ipkg_message.h"
11442 +#include "pkg_vec.h"
11443 +#include "pkg_hash.h"
11444 +#include "pkg_parse.h"
11445 +#include "ipkg_utils.h"
11447 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11450 + * this will talk to both feeds-lists files and installed status files
11453 + * hash_table_t hash;
11454 + * pkg_hash_init(name, &hash, 1000);
11455 + * pkg_hash_add_from_file(<feed filename>);
11457 + * the query function is just there as a shell to prove to me that this
11458 + * sort of works, but isn't far from doing something useful
11461 + * modified: CDW 3 Jan. 2002
11466 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11468 + return hash_table_init(name, hash, len);
11471 +void pkg_hash_deinit(hash_table_t *hash)
11473 + hash_table_deinit(hash);
11477 +/* Find the default arch for a given package status file if none is given. */
11478 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11480 + nv_pair_list_elt_t *l;
11481 + char *def_arch = HOST_CPU_STR; /* Default arch */
11482 + int def_prio = 0; /* Other archs override this */
11484 + l = conf->arch_list.head;
11487 + nv_pair_t *nv = l->data;
11488 + int priority = strtol(nv->value, NULL, 0);
11490 + /* Check if this arch has higher priority, and is valid */
11491 + if ((priority > def_prio) &&
11492 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11493 + /* Our new default */
11494 + def_prio = priority;
11495 + def_arch = nv->name;
11500 + return strdup(def_arch);
11503 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11504 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11506 + hash_table_t *hash = &conf->pkg_hash;
11508 + char **raw_start;
11511 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11515 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11520 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11521 + if (!pkg->architecture) {
11522 + char *version_str = pkg_version_str_alloc(pkg);
11523 + pkg->architecture = pkg_get_default_arch(conf);
11524 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11525 + pkg->name, version_str, pkg->architecture);
11526 + free(version_str);
11528 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11534 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11535 + memory after read_raw_pkgs_from_file */
11544 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11546 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11549 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11551 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11554 + return apkg->provided_by;
11558 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11559 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11562 + int nprovides = 0;
11563 + int nmatching = 0;
11564 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11565 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11566 + abstract_pkg_vec_t *provided_apkg_vec;
11567 + abstract_pkg_t **provided_apkgs;
11568 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11569 + pkg_t *latest_installed_parent = NULL;
11570 + pkg_t *latest_matching = NULL;
11571 + pkg_t *held_pkg = NULL;
11572 + pkg_t *good_pkg_by_name = NULL;
11574 + if (matching_apkgs == NULL || providers == NULL ||
11575 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11578 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11580 + provided_apkg_vec = apkg->provided_by;
11581 + nprovides = provided_apkg_vec->len;
11582 + provided_apkgs = provided_apkg_vec->pkgs;
11583 + if (nprovides > 1)
11584 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11586 + /* accumulate all the providers */
11587 + for (i = 0; i < nprovides; i++) {
11588 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11589 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11590 + abstract_pkg_vec_insert(providers, provider_apkg);
11592 + nprovides = providers->len;
11594 + for (i = 0; i < nprovides; i++) {
11595 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11596 + abstract_pkg_t *replacement_apkg = NULL;
11599 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11600 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11601 + if (provider_apkg->replaced_by->len > 1) {
11602 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11603 + provider_apkg->name, replacement_apkg->name);
11607 + if (replacement_apkg)
11608 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11609 + replacement_apkg->name, provider_apkg->name);
11611 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11612 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11615 + provider_apkg = replacement_apkg;
11618 + if (!(vec = provider_apkg->pkgs)) {
11619 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11624 + /* now check for supported architecture */
11626 + int max_count = 0;
11629 + /* count packages matching max arch priority and keep track of last one */
11630 + for (i = 0; i < vec->len; i++) {
11631 + pkg_t *maybe = vec->pkgs[i];
11632 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11633 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11634 + if (maybe->arch_priority > 0) {
11636 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11637 + pkg_vec_insert(matching_pkgs, maybe);
11643 + if (matching_pkgs->len > 1)
11644 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11645 + if (matching_apkgs->len > 1)
11646 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11648 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11649 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11650 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11651 + Until now I always got the latest, but that breaks the downgrade option.
11652 + If I stop at the first one, I would probably miss the new ones
11653 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11654 + or from a Packages feed.
11655 + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
11658 + for (i = 0; i < matching_pkgs->len; i++) {
11659 + pkg_t *matching = matching_pkgs->pkgs[i];
11660 + if (constraint_fcn(matching, cdata)) { /* We found it */
11661 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11662 + good_pkg_by_name = matching;
11663 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11669 + for (i = 0; i < matching_pkgs->len; i++) {
11670 + pkg_t *matching = matching_pkgs->pkgs[i];
11671 + latest_matching = matching;
11672 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11673 + latest_installed_parent = matching;
11674 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11676 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11677 + held_pkg->name, matching->name);
11678 + held_pkg = matching;
11682 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11683 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11684 + apkg->name, matching_apkgs->len);
11685 + for (i = 0; i < matching_apkgs->len; i++) {
11686 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11687 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11689 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11692 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11693 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11694 + __FUNCTION__, apkg->name, matching_pkgs->len);
11695 + for (i = 0; i < matching_pkgs->len; i++) {
11696 + pkg_t *matching = matching_pkgs->pkgs[i];
11697 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11698 + matching->name, matching->version, matching->architecture);
11702 + nmatching = matching_apkgs->len;
11704 + pkg_vec_free(matching_pkgs);
11705 + abstract_pkg_vec_free(matching_apkgs);
11706 + abstract_pkg_vec_free(providers);
11708 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11709 + return good_pkg_by_name;
11712 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11715 + if (latest_installed_parent) {
11716 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11717 + return latest_installed_parent;
11719 + if (nmatching > 1) {
11720 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11723 + if (latest_matching) {
11724 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11725 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11726 + return latest_matching;
11731 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11733 + const char *name = (const char *)cdata;
11734 + if (strcmp(pkg->name, name) == 0)
11740 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11742 + hash_table_t *hash = &conf->pkg_hash;
11743 + abstract_pkg_t *apkg = NULL;
11745 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11748 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11752 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11753 + const char *pkg_name,
11754 + const char * version)
11758 + char *version_str = NULL;
11760 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11763 + for(i = 0; i < vec->len; i++) {
11764 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11765 + if(!strcmp(version_str, version)) {
11766 + free(version_str);
11769 + free(version_str);
11772 + if(i == vec->len)
11775 + return vec->pkgs[i];
11778 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11779 + const char *pkg_name,
11780 + pkg_dest_t *dest)
11785 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11789 + for(i = 0; i < vec->len; i++)
11790 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11791 + return vec->pkgs[i];
11796 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11797 + const char *pkg_name)
11802 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11806 + for(i = 0; i < vec->len; i++)
11807 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11808 + return vec->pkgs[i];
11814 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11816 + abstract_pkg_t * ab_pkg;
11818 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11822 + if (ab_pkg->pkgs) {
11823 + return ab_pkg->pkgs;
11824 + } else if (ab_pkg->provided_by) {
11825 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11826 + if (abpkg != NULL){
11827 + return abpkg->pkgs;
11829 + return ab_pkg->pkgs;
11836 +static int pkg_compare_names(const void *p1, const void *p2)
11838 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11839 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11840 + if (pkg1->name == NULL)
11842 + if (pkg2->name == NULL)
11844 + return(strcmp(pkg1->name, pkg2->name));
11848 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11851 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11852 + pkg_vec_t *all = (pkg_vec_t *)data;
11853 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11855 + for (j = 0; j < pkg_vec->len; j++) {
11856 + pkg_t *pkg = pkg_vec->pkgs[j];
11857 + pkg_vec_insert(all, pkg);
11862 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11864 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11865 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11868 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11870 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11871 + pkg_vec_t *all = (pkg_vec_t *)data;
11872 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11875 + for (j = 0; j < pkg_vec->len; j++) {
11876 + pkg_t *pkg = pkg_vec->pkgs[j];
11877 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11878 + pkg_vec_insert(all, pkg);
11883 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11885 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11886 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11889 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11893 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11894 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11895 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11896 + fprintf(stdout, "%s\n", ab_pkg->name);
11898 + if (dependents != NULL)
11899 + while (dependents [i] != NULL)
11900 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11901 + dependents = ab_pkg->provided_by->pkgs;
11903 + if (dependents != NULL)
11904 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11905 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11906 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11909 + while (i < pkg->depends_count)
11910 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11913 +void pkg_hash_dump(hash_table_t *hash, void *data)
11916 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11917 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11918 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11921 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11923 + abstract_pkg_t * ab_pkg;
11925 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11926 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11931 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11933 + abstract_pkg_t * ab_pkg;
11934 + int arch_priority;
11939 + arch_priority = pkg->arch_priority;
11941 + if (buildDepends(hash, pkg)<0){
11942 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11945 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11947 + if (set_status) {
11948 + if (pkg->state_status == SS_INSTALLED) {
11949 + ab_pkg->state_status = SS_INSTALLED;
11950 + } else if (pkg->state_status == SS_UNPACKED) {
11951 + ab_pkg->state_status = SS_UNPACKED;
11955 + if(!ab_pkg->pkgs)
11956 + ab_pkg->pkgs = pkg_vec_alloc();
11958 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11959 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11960 + pkg->parent = ab_pkg;
11962 + if (buildProvides(hash, ab_pkg, pkg)<0){
11963 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11966 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11967 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11968 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11971 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11972 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11976 + buildDependedUponBy(pkg, ab_pkg);
11981 + * this will assume that we've already determined that
11982 + * the abstract pkg doesn't exist, 'cause we should know these things...
11984 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11986 + abstract_pkg_t * ab_pkg;
11988 + ab_pkg = abstract_pkg_new();
11989 + if (ab_pkg == NULL) { return NULL; }
11991 + ab_pkg->name = strdup(pkg_name);
11992 + hash_table_insert(hash, pkg_name, ab_pkg);
11998 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
12000 + hash_table_t *file_hash = &conf->file_hash;
12002 + return hash_table_get(file_hash, file_name);
12005 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
12007 + hash_table_t *file_hash = &conf->file_hash;
12008 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
12009 + int file_name_len = strlen(file_name);
12011 + if (file_name[file_name_len -1] == '/')
12014 + if (conf->offline_root) {
12015 + int len = strlen(conf->offline_root);
12016 + if (strncmp(file_name, conf->offline_root, len) == 0) {
12017 + file_name += len;
12021 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
12022 + hash_table_insert(file_hash, file_name, owning_pkg);
12023 + if (old_owning_pkg) {
12024 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12025 + /* mark this package to have its filelist written */
12026 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12027 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12033 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_hash.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.h
12034 --- busybox-1.1.2-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12035 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-05-09 02:06:48.000000000 +0200
12037 +/* pkg_hash.h - the itsy package management system
12041 + Copyright (C) 2002 Compaq Computer Corporation
12043 + This program is free software; you can redistribute it and/or
12044 + modify it under the terms of the GNU General Public License as
12045 + published by the Free Software Foundation; either version 2, or (at
12046 + your option) any later version.
12048 + This program is distributed in the hope that it will be useful, but
12049 + WITHOUT ANY WARRANTY; without even the implied warranty of
12050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12051 + General Public License for more details.
12054 +#ifndef PKG_HASH_H
12055 +#define PKG_HASH_H
12058 +#include "pkg_vec.h"
12059 +#include "hash_table.h"
12062 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12063 +void pkg_hash_deinit(hash_table_t *hash);
12064 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12066 +void pkg_hash_dump(hash_table_t *hash, void *data);
12067 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12069 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12070 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12071 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12073 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12074 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12075 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12076 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12077 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12078 + const char *pkg_name,
12079 + const char * version);
12080 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12081 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12082 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12083 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12084 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12085 + const char *pkg_name);
12086 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12087 + const char *pkg_name,
12088 + pkg_dest_t *dest);
12090 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12091 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12093 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12094 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12098 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_parse.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.c
12099 --- busybox-1.1.2-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12100 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-05-09 02:06:48.000000000 +0200
12102 +/* pkg_parse.c - the itsy package management system
12106 + Copyright (C) 2002 Compaq Computer Corporation
12108 + This program is free software; you can redistribute it and/or
12109 + modify it under the terms of the GNU General Public License as
12110 + published by the Free Software Foundation; either version 2, or (at
12111 + your option) any later version.
12113 + This program is distributed in the hope that it will be useful, but
12114 + WITHOUT ANY WARRANTY; without even the implied warranty of
12115 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12116 + General Public License for more details.
12120 +#include <errno.h>
12121 +#include <ctype.h>
12124 +#include "ipkg_utils.h"
12125 +#include "pkg_parse.h"
12127 +int isGenericFieldType(char * type, char * line)
12129 + if(!strncmp(line, type, strlen(type)))
12134 +char * parseGenericFieldType(char * type, char * raw)
12136 + char * field_value = raw + (strlen(type) + 1);
12137 + return trim_alloc(field_value);
12140 +void parseStatus(pkg_t *pkg, char * raw)
12142 + char sw_str[64], sf_str[64], ss_str[64];
12144 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12145 + pkg->state_want = pkg_state_want_from_str(sw_str);
12146 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12147 + pkg->state_status = pkg_state_status_from_str(ss_str);
12150 +char ** parseDependsString(char * raw, int * depends_count)
12152 + char ** depends = NULL;
12153 + int line_count = 0;
12154 + char buff[2048], * dest;
12156 + while(raw && *raw && !isspace(*raw)) {
12160 + if(line_is_blank(raw)){
12161 + *depends_count = line_count;
12164 + while(raw && *raw){
12165 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12167 + while(isspace(*raw)) raw++;
12170 + while((*raw != ',') && *raw)
12171 + *dest++ = *raw++;
12174 + depends[line_count] = trim_alloc(buff);
12175 + if(depends[line_count] ==NULL)
12181 + *depends_count = line_count;
12185 +void parseConffiles(pkg_t * pkg, char * raw)
12187 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12189 + if(!strncmp(raw, "Conffiles:", 10))
12190 + raw += strlen("Conffiles:");
12192 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12193 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12194 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12195 + while (*raw && isspace(*raw)) {
12198 + raw += strlen(file_name);
12199 + while (*raw && isspace(*raw)) {
12202 + raw += strlen(md5sum);
12206 +int parseVersion(pkg_t *pkg, char *raw)
12208 + char *colon, *eepochcolon;
12209 +#ifdef USE_DEBVERSION
12212 + unsigned long epoch;
12215 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12219 + if (strncmp(raw, "Version:", 8) == 0) {
12222 + while (*raw && isspace(*raw)) {
12226 + colon= strchr(raw,':');
12228 + epoch= strtoul(raw,&eepochcolon,10);
12229 + if (colon != eepochcolon) {
12230 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12234 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12238 + pkg->epoch= epoch;
12243 + pkg->revision = "";
12244 + pkg->familiar_revision = "";
12246 + pkg->version= malloc(strlen(raw)+1);
12247 + if ( pkg->version == NULL ) {
12248 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12251 + strcpy(pkg->version, raw);
12253 +#ifdef USE_DEBVERSION
12254 + hyphen= strrchr(pkg->version,'-');
12258 + if (strncmp("fam", hyphen, 3) == 0) {
12259 + pkg->familiar_revision=hyphen+3;
12260 + hyphen= strrchr(pkg->version,'-');
12263 + pkg->revision = hyphen;
12266 + pkg->revision = hyphen;
12272 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12276 + pkg->familiar_revision);
12283 +/* This code is needed to insert in first position the keyword for the aligning bug */
12285 +int alterProvidesLine(char *raw, char *temp)
12290 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12294 + if ( temp == NULL ) {
12295 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12299 + if (strncmp(raw, "Provides:", 9) == 0) {
12302 + while (*raw && isspace(*raw)) {
12306 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12308 + strncat( temp, raw++, 1);
12314 +/* Some random thoughts from Carl:
12316 + This function could be considerably simplified if we just kept
12317 + an array of all the generic string-valued field names, and looped
12318 + through those looking for a match. Also, these fields could perhaps
12319 + be stored in the package as an array as well, (or, probably better,
12320 + as an nv_pair_list_t).
12322 + Fields which require special parsing or storage, (such as Depends:
12323 + and Status:) could be handled as they are now.
12325 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12326 + to a dependency list. And, since we already have
12327 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12328 + Enhances, perhaps we could generalize all of these and save some
12329 + code duplication.
12331 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12333 + int reading_conffiles, reading_description;
12334 + int pkg_false_provides=1;
12336 + char * provide=NULL;
12339 + pkg->dest = dest;
12341 + reading_conffiles = reading_description = 0;
12343 + for (lines = *raw; *lines; lines++) {
12344 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12345 + if(isGenericFieldType("Package:", *lines))
12346 + pkg->name = parseGenericFieldType("Package", *lines);
12347 + else if(isGenericFieldType("Architecture:", *lines))
12348 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12349 + else if(isGenericFieldType("Filename:", *lines))
12350 + pkg->filename = parseGenericFieldType("Filename", *lines);
12351 + else if(isGenericFieldType("Section:", *lines))
12352 + pkg->section = parseGenericFieldType("Section", *lines);
12353 + else if(isGenericFieldType("MD5sum:", *lines))
12354 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12355 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12356 + let's parse it either way */
12357 + else if(isGenericFieldType("MD5Sum:", *lines))
12358 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12359 + else if(isGenericFieldType("Size:", *lines))
12360 + pkg->size = parseGenericFieldType("Size", *lines);
12361 + else if(isGenericFieldType("Source:", *lines))
12362 + pkg->source = parseGenericFieldType("Source", *lines);
12363 + else if(isGenericFieldType("Installed-Size:", *lines))
12364 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12365 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12366 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12367 + pkg->installed_time = strtoul(time_str, NULL, 0);
12368 + } else if(isGenericFieldType("Priority:", *lines))
12369 + pkg->priority = parseGenericFieldType("Priority", *lines);
12370 + else if(isGenericFieldType("Essential:", *lines)) {
12371 + char *essential_value;
12372 + essential_value = parseGenericFieldType("Essential", *lines);
12373 + if (strcmp(essential_value, "yes") == 0) {
12374 + pkg->essential = 1;
12376 + free(essential_value);
12378 + else if(isGenericFieldType("Status", *lines))
12379 + parseStatus(pkg, *lines);
12380 + else if(isGenericFieldType("Version", *lines))
12381 + parseVersion(pkg, *lines);
12382 + else if(isGenericFieldType("Maintainer", *lines))
12383 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12384 + else if(isGenericFieldType("Conffiles", *lines)){
12385 + parseConffiles(pkg, *lines);
12386 + reading_conffiles = 1;
12388 + else if(isGenericFieldType("Description", *lines)) {
12389 + pkg->description = parseGenericFieldType("Description", *lines);
12390 + reading_conffiles = 0;
12391 + reading_description = 1;
12394 + else if(isGenericFieldType("Provides", *lines)){
12395 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12396 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12397 + if ( alterProvidesLine(*lines,provide) ){
12400 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12401 +/* Let's try to hack a bit here.
12402 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12403 + in alot of other places. We will remove it before writing down the status database */
12404 + pkg_false_provides=0;
12408 + else if(isGenericFieldType("Depends", *lines))
12409 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12410 + else if(isGenericFieldType("Pre-Depends", *lines))
12411 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12412 + else if(isGenericFieldType("Recommends", *lines))
12413 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12414 + else if(isGenericFieldType("Suggests", *lines))
12415 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12416 + /* Abhaya: support for conflicts */
12417 + else if(isGenericFieldType("Conflicts", *lines))
12418 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12419 + else if(isGenericFieldType("Replaces", *lines))
12420 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12421 + else if(line_is_blank(*lines)) {
12425 + else if(**lines == ' '){
12426 + if(reading_description) {
12427 + /* we already know it's not blank, so the rest of description */
12428 + pkg->description = realloc(pkg->description,
12429 + strlen(pkg->description)
12430 + + 1 + strlen(*lines) + 1);
12431 + strcat(pkg->description, "\n");
12432 + strcat(pkg->description, (*lines));
12434 + else if(reading_conffiles)
12435 + parseConffiles(pkg, *lines);
12439 +/* If the ipk has not a Provides line, we insert our false line */
12440 + if ( pkg_false_provides==1)
12441 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12450 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12454 + for (lines = *raw; *lines; lines++) {
12455 + if(isGenericFieldType("Essential:", *lines)) {
12456 + char *essential_value;
12457 + essential_value = parseGenericFieldType("Essential", *lines);
12458 + if (strcmp(essential_value, "yes") == 0) {
12459 + pkg->essential = 1;
12461 + free(essential_value);
12468 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_parse.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.h
12469 --- busybox-1.1.2-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12470 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-05-09 02:06:48.000000000 +0200
12472 +/* pkg_parse.h - the itsy package management system
12476 + Copyright (C) 2002 Compaq Computer Corporation
12478 + This program is free software; you can redistribute it and/or
12479 + modify it under the terms of the GNU General Public License as
12480 + published by the Free Software Foundation; either version 2, or (at
12481 + your option) any later version.
12483 + This program is distributed in the hope that it will be useful, but
12484 + WITHOUT ANY WARRANTY; without even the implied warranty of
12485 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12486 + General Public License for more details.
12489 +#ifndef PKG_PARSE_H
12490 +#define PKG_PARSE_H
12492 +int isGenericFieldType(char * type, char * line);
12493 +char * parseGenericFieldType(char * type, char * raw);
12494 +void parseStatus(pkg_t *pkg, char * raw);
12495 +int parseVersion(pkg_t *pkg, char *raw);
12496 +char ** parseDependsString(char * raw, int * depends_count);
12497 +int parseVersion(pkg_t *pkg, char *raw);
12498 +void parseConffiles(pkg_t * pkg, char * raw);
12499 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12500 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12503 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.c
12504 --- busybox-1.1.2-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12505 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-05-09 02:06:48.000000000 +0200
12507 +/* pkg_src.c - the itsy package management system
12511 + Copyright (C) 2001 University of Southern California
12513 + This program is free software; you can redistribute it and/or
12514 + modify it under the terms of the GNU General Public License as
12515 + published by the Free Software Foundation; either version 2, or (at
12516 + your option) any later version.
12518 + This program is distributed in the hope that it will be useful, but
12519 + WITHOUT ANY WARRANTY; without even the implied warranty of
12520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12521 + General Public License for more details.
12526 +#include "pkg_src.h"
12527 +#include "str_util.h"
12529 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12531 + src->gzip = gzip;
12532 + src->name = str_dup_safe (name);
12533 + src->value = str_dup_safe (base_url);
12535 + src->extra_data = str_dup_safe (extra_data);
12537 + src->extra_data = NULL;
12541 +void pkg_src_deinit(pkg_src_t *src)
12543 + free (src->name);
12544 + free (src->value);
12545 + if (src->extra_data)
12546 + free (src->extra_data);
12550 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.h
12551 --- busybox-1.1.2-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12552 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-05-09 02:06:48.000000000 +0200
12554 +/* pkg_src.h - the itsy package management system
12558 + Copyright (C) 2001 University of Southern California
12560 + This program is free software; you can redistribute it and/or
12561 + modify it under the terms of the GNU General Public License as
12562 + published by the Free Software Foundation; either version 2, or (at
12563 + your option) any later version.
12565 + This program is distributed in the hope that it will be useful, but
12566 + WITHOUT ANY WARRANTY; without even the implied warranty of
12567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12568 + General Public License for more details.
12574 +#include "nv_pair.h"
12580 + char *extra_data;
12584 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12585 +void pkg_src_deinit(pkg_src_t *src);
12588 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.c
12589 --- busybox-1.1.2-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12590 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-05-09 02:06:48.000000000 +0200
12592 +/* pkg_src_list.c - the itsy package management system
12596 + Copyright (C) 2001 University of Southern California
12598 + This program is free software; you can redistribute it and/or
12599 + modify it under the terms of the GNU General Public License as
12600 + published by the Free Software Foundation; either version 2, or (at
12601 + your option) any later version.
12603 + This program is distributed in the hope that it will be useful, but
12604 + WITHOUT ANY WARRANTY; without even the implied warranty of
12605 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12606 + General Public License for more details.
12611 +#include "pkg_src_list.h"
12612 +#include "void_list.h"
12614 +int pkg_src_list_init(pkg_src_list_t *list)
12616 + return void_list_init((void_list_t *) list);
12619 +void pkg_src_list_deinit(pkg_src_list_t *list)
12621 + pkg_src_list_elt_t *iter;
12622 + pkg_src_t *pkg_src;
12624 + for (iter = list->head; iter; iter = iter->next) {
12625 + pkg_src = iter->data;
12626 + pkg_src_deinit(pkg_src);
12628 + /* malloced in pkg_src_list_append */
12630 + iter->data = NULL;
12632 + void_list_deinit((void_list_t *) list);
12635 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12636 + const char *name, const char *base_url, const char *extra_data,
12641 + /* freed in pkg_src_list_deinit */
12642 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12644 + if (pkg_src == NULL) {
12645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12648 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12650 + err = void_list_append((void_list_t *) list, pkg_src);
12658 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12660 + return void_list_push((void_list_t *) list, data);
12663 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12665 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12667 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_src_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.h
12668 --- busybox-1.1.2-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12669 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-05-09 02:06:48.000000000 +0200
12671 +/* pkg_src_list.h - the itsy package management system
12675 + Copyright (C) 2001 University of Southern California
12677 + This program is free software; you can redistribute it and/or
12678 + modify it under the terms of the GNU General Public License as
12679 + published by the Free Software Foundation; either version 2, or (at
12680 + your option) any later version.
12682 + This program is distributed in the hope that it will be useful, but
12683 + WITHOUT ANY WARRANTY; without even the implied warranty of
12684 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12685 + General Public License for more details.
12688 +#ifndef PKG_SRC_LIST_H
12689 +#define PKG_SRC_LIST_H
12691 +#include "pkg_src.h"
12693 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12694 +struct pkg_src_list_elt
12696 + pkg_src_list_elt_t *next;
12700 +typedef struct pkg_src_list pkg_src_list_t;
12701 +struct pkg_src_list
12703 + pkg_src_list_elt_t pre_head;
12704 + pkg_src_list_elt_t *head;
12705 + pkg_src_list_elt_t *tail;
12708 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12710 + if (list->head == NULL)
12716 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12717 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12719 +int pkg_src_list_init(pkg_src_list_t *list);
12720 +void pkg_src_list_deinit(pkg_src_list_t *list);
12722 +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);
12723 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12724 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12728 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_vec.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.c
12729 --- busybox-1.1.2-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12730 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-05-09 02:12:05.000000000 +0200
12732 +/* pkg_vec.c - the itsy package management system
12736 + Copyright (C) 2002 Compaq Computer Corporation
12738 + This program is free software; you can redistribute it and/or
12739 + modify it under the terms of the GNU General Public License as
12740 + published by the Free Software Foundation; either version 2, or (at
12741 + your option) any later version.
12743 + This program is distributed in the hope that it will be useful, but
12744 + WITHOUT ANY WARRANTY; without even the implied warranty of
12745 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12746 + General Public License for more details.
12749 +#include <stdlib.h>
12750 +#include <fnmatch.h>
12751 +#include "xregex.h"
12755 +pkg_vec_t * pkg_vec_alloc(void)
12757 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12759 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12762 + vec->pkgs = NULL;
12768 +void pkg_vec_free(pkg_vec_t *vec)
12775 + * assumption: all names in a vector are identical
12776 + * assumption: all version strings are trimmed,
12777 + * so identical versions have identical version strings,
12778 + * implying identical packages; let's marry these
12780 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12785 + /* look for a duplicate pkg by name, version, and architecture */
12786 + for (i = 0; i < vec->len; i++){
12787 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12788 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12789 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12790 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12791 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12792 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12794 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12795 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12800 + /* we didn't find one, add it */
12802 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12803 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12805 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12806 + vec->pkgs[vec->len] = pkg;
12810 + /* update the one that we have */
12812 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12813 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12814 + if (set_status) {
12815 + /* this is from the status file, so need to merge with existing database */
12816 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12817 + pkg_merge(vec->pkgs[i], pkg, set_status);
12818 + /* XXX: CLEANUP: It's not so polite to free something here
12819 + that was passed in from above. */
12823 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12824 + /* just overwrite the old one */
12825 + pkg_deinit(vec->pkgs[i]);
12826 + free(vec->pkgs[i]);
12827 + vec->pkgs[i] = pkg;
12829 + return vec->pkgs[i];
12833 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12838 + /* look for a duplicate pkg by name, version, and architecture */
12839 + for (i = 0; i < vec->len; i++)
12840 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12841 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12842 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12847 + /* we didn't find one, add it */
12849 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12850 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12855 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12858 + for (i = 0; i < vec->len; i++)
12859 + if (vec->pkgs[i] == apkg)
12864 +typedef int (*compare_fcn_t)(const void *, const void *);
12865 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12867 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12870 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12872 + int npkgs = vec->len;
12874 + for (i = 0; i < npkgs; i++) {
12875 + pkg_t *pkg = vec->pkgs[i];
12876 + pkg->state_flag &= ~SF_MARKED;
12881 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12883 + int matching_count = 0;
12884 + pkg_t **pkgs = vec->pkgs;
12885 + int npkgs = vec->len;
12887 + for (i = 0; i < npkgs; i++) {
12888 + pkg_t *pkg = pkgs[i];
12889 + if (fnmatch(pattern, pkg->name, 0)==0) {
12890 + pkg->state_flag |= SF_MARKED;
12891 + matching_count++;
12894 + return matching_count;
12898 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12900 + abstract_pkg_vec_t * vec ;
12901 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12903 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12906 + vec->pkgs = NULL;
12912 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12919 + * assumption: all names in a vector are unique
12921 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12925 + /* look for a duplicate pkg by name */
12926 + for(i = 0; i < vec->len; i++)
12927 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12930 + /* we didn't find one, add it */
12931 + if(i == vec->len){
12933 + (abstract_pkg_t **)
12934 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12935 + vec->pkgs[vec->len] = pkg;
12940 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12942 + if (vec->len > i)
12943 + return vec->pkgs[i];
12948 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12951 + for (i = 0; i < vec->len; i++)
12952 + if (vec->pkgs[i] == apkg)
12957 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12959 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12962 diff -ruN busybox-1.1.2-orig/archival/libipkg/pkg_vec.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.h
12963 --- busybox-1.1.2-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12964 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-05-09 02:06:48.000000000 +0200
12966 +/* pkg_vec.h - the itsy package management system
12970 + Copyright (C) 2002 Compaq Computer Corporation
12972 + This program is free software; you can redistribute it and/or
12973 + modify it under the terms of the GNU General Public License as
12974 + published by the Free Software Foundation; either version 2, or (at
12975 + your option) any later version.
12977 + This program is distributed in the hope that it will be useful, but
12978 + WITHOUT ANY WARRANTY; without even the implied warranty of
12979 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12980 + General Public License for more details.
12986 +typedef struct pkg pkg_t;
12987 +typedef struct abstract_pkg abstract_pkg_t;
12994 +typedef struct pkg_vec pkg_vec_t;
12996 +struct abstract_pkg_vec
12998 + abstract_pkg_t **pkgs;
13001 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
13004 +pkg_vec_t * pkg_vec_alloc(void);
13005 +void pkg_vec_free(pkg_vec_t *vec);
13006 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
13008 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
13009 +/* pkg_vec_insert_merge: might munge pkg.
13010 +* returns the pkg that is in the pkg graph */
13011 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
13012 +/* this one never munges pkg */
13013 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
13014 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
13015 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
13017 +int pkg_vec_clear_marks(pkg_vec_t *vec);
13018 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
13020 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
13021 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
13022 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
13023 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13024 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13025 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13028 diff -ruN busybox-1.1.2-orig/archival/libipkg/sprintf_alloc.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h
13029 --- busybox-1.1.2-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13030 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-05-09 02:06:48.000000000 +0200
13032 +/* sprintf_alloca.c -- like sprintf with memory allocation
13036 + Copyright (C) 2001 University of Southern California
13038 + This program is free software; you can redistribute it and/or modify
13039 + it under the terms of the GNU General Public License as published by
13040 + the Free Software Foundation; either version 2, or (at your option)
13041 + any later version.
13043 + This program is distributed in the hope that it will be useful,
13044 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13045 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13046 + GNU General Public License for more details.
13049 +#ifndef SPRINTF_ALLOC_H
13050 +#define SPRINTF_ALLOC_H
13052 +#include "libbb.h"
13054 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13057 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.c
13058 --- busybox-1.1.2-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13059 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.c 2006-05-09 02:06:48.000000000 +0200
13061 +/* str_list.c - the itsy package management system
13065 + Copyright (C) 2001 University of Southern California
13067 + This program is free software; you can redistribute it and/or
13068 + modify it under the terms of the GNU General Public License as
13069 + published by the Free Software Foundation; either version 2, or (at
13070 + your option) any later version.
13072 + This program is distributed in the hope that it will be useful, but
13073 + WITHOUT ANY WARRANTY; without even the implied warranty of
13074 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13075 + General Public License for more details.
13080 +#include "str_list.h"
13082 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13084 + return void_list_elt_init((void_list_elt_t *) elt, data);
13087 +void str_list_elt_deinit(str_list_elt_t *elt)
13089 + void_list_elt_deinit((void_list_elt_t *) elt);
13092 +str_list_t *str_list_alloc()
13094 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13096 + str_list_init(list);
13100 +int str_list_init(str_list_t *list)
13102 + return void_list_init((void_list_t *) list);
13105 +void str_list_deinit(str_list_t *list)
13107 + void_list_deinit((void_list_t *) list);
13110 +int str_list_append(str_list_t *list, char *data)
13112 + return void_list_append((void_list_t *) list, data);
13115 +int str_list_push(str_list_t *list, char *data)
13117 + return void_list_push((void_list_t *) list, data);
13120 +str_list_elt_t *str_list_pop(str_list_t *list)
13122 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13125 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13127 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13128 + (void_list_elt_t **) iter);
13131 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13133 + return (char *)void_list_remove_elt((void_list_t *) list,
13134 + (void *)target_str,
13135 + (void_list_cmp_t)strcmp);
13137 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.h
13138 --- busybox-1.1.2-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13139 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_list.h 2006-05-09 02:06:48.000000000 +0200
13141 +/* str_list.h - the itsy package management system
13145 + Copyright (C) 2001 University of Southern California
13147 + This program is free software; you can redistribute it and/or
13148 + modify it under the terms of the GNU General Public License as
13149 + published by the Free Software Foundation; either version 2, or (at
13150 + your option) any later version.
13152 + This program is distributed in the hope that it will be useful, but
13153 + WITHOUT ANY WARRANTY; without even the implied warranty of
13154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13155 + General Public License for more details.
13158 +#ifndef STR_LIST_H
13159 +#define STR_LIST_H
13161 +#include "void_list.h"
13163 +typedef struct str_list_elt str_list_elt_t;
13164 +struct str_list_elt
13166 + str_list_elt_t *next;
13170 +typedef struct xstr_list str_list_t;
13173 + str_list_elt_t pre_head;
13174 + str_list_elt_t *head;
13175 + str_list_elt_t *tail;
13178 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13179 +void str_list_elt_deinit(str_list_elt_t *elt);
13181 +str_list_t *str_list_alloc(void);
13182 +int str_list_init(str_list_t *list);
13183 +void str_list_deinit(str_list_t *list);
13185 +int str_list_append(str_list_t *list, char *data);
13186 +int str_list_push(str_list_t *list, char *data);
13187 +str_list_elt_t *str_list_pop(str_list_t *list);
13188 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13189 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13192 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_util.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.c
13193 --- busybox-1.1.2-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13194 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.c 2006-05-09 02:06:48.000000000 +0200
13196 +/* str_utils.c - the itsy package management system
13200 + Copyright (C) 2001 University of Southern California
13202 + This program is free software; you can redistribute it and/or
13203 + modify it under the terms of the GNU General Public License as
13204 + published by the Free Software Foundation; either version 2, or (at
13205 + your option) any later version.
13207 + This program is distributed in the hope that it will be useful, but
13208 + WITHOUT ANY WARRANTY; without even the implied warranty of
13209 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13210 + General Public License for more details.
13215 +int str_starts_with(const char *str, const char *prefix)
13217 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13220 +int str_ends_with(const char *str, const char *suffix)
13225 + str_len = strlen(str);
13226 + suffix_len = strlen(suffix);
13228 + if (str_len < suffix_len) {
13232 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13235 +int str_chomp(char *str)
13237 + if (str[strlen(str) - 1] == '\n') {
13238 + str[strlen(str) - 1] = '\0';
13244 +int str_tolower(char *str)
13247 + *str = tolower(*str);
13254 +int str_toupper(char *str)
13257 + *str = toupper(*str);
13264 +char *str_dup_safe(const char *str)
13266 + return str ? strdup(str) : NULL;
13269 diff -ruN busybox-1.1.2-orig/archival/libipkg/str_util.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.h
13270 --- busybox-1.1.2-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13271 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/str_util.h 2006-05-09 02:06:48.000000000 +0200
13273 +/* str_utils.h - the itsy package management system
13277 + Copyright (C) 2001 University of Southern California
13279 + This program is free software; you can redistribute it and/or
13280 + modify it under the terms of the GNU General Public License as
13281 + published by the Free Software Foundation; either version 2, or (at
13282 + your option) any later version.
13284 + This program is distributed in the hope that it will be useful, but
13285 + WITHOUT ANY WARRANTY; without even the implied warranty of
13286 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13287 + General Public License for more details.
13290 +#ifndef STR_UTILS_H
13291 +#define STR_UTILS_H
13293 +int str_starts_with(const char *str, const char *prefix);
13294 +int str_ends_with(const char *str, const char *suffix);
13295 +int str_chomp(char *str);
13296 +int str_tolower(char *str);
13297 +int str_toupper(char *str);
13298 +char *str_dup_safe(const char *str);
13301 diff -ruN busybox-1.1.2-orig/archival/libipkg/user.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.c
13302 --- busybox-1.1.2-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13303 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.c 2006-05-09 02:06:48.000000000 +0200
13305 +/* user.c - the itsy package management system
13309 + Copyright (C) 2002 Hewlett Packard Company
13310 + Copyright (C) 2001 University of Southern California
13312 + This program is free software; you can redistribute it and/or
13313 + modify it under the terms of the GNU General Public License as
13314 + published by the Free Software Foundation; either version 2, or (at
13315 + your option) any later version.
13317 + This program is distributed in the hope that it will be useful, but
13318 + WITHOUT ANY WARRANTY; without even the implied warranty of
13319 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13320 + General Public License for more details.
13323 +#include <stdio.h>
13324 +#include <stdarg.h>
13325 +#include "file_util.h"
13326 +#include "str_util.h"
13328 +#include "libipkg.h"
13333 +static char *question = NULL;
13334 +static int question_len = 255;
13336 +char *get_user_response(const char *format, ...)
13338 + int len = question_len;
13341 + va_start(ap, format);
13344 + vprintf(format, ap);
13346 + response = file_read_line_alloc(stdin);
13347 + } while (response == NULL);
13350 + if (question == NULL || len > question_len) {
13351 + question = realloc(question, len + 1);
13352 + question_len = len;
13354 + len = vsnprintf(question,question_len,format,ap);
13355 + } while (len > question_len);
13356 + response = strdup(ipkg_cb_response(question));
13358 + str_chomp(response);
13359 + str_tolower(response);
13363 diff -ruN busybox-1.1.2-orig/archival/libipkg/user.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.h
13364 --- busybox-1.1.2-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13365 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/user.h 2006-05-09 02:06:48.000000000 +0200
13367 +/* user.c - the itsy package management system
13371 + Copyright (C) 2002 Hewlett Packard Company
13372 + Copyright (C) 2001 University of Southern California
13374 + This program is free software; you can redistribute it and/or
13375 + modify it under the terms of the GNU General Public License as
13376 + published by the Free Software Foundation; either version 2, or (at
13377 + your option) any later version.
13379 + This program is distributed in the hope that it will be useful, but
13380 + WITHOUT ANY WARRANTY; without even the implied warranty of
13381 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13382 + General Public License for more details.
13385 +#include <stdio.h>
13386 +#include <stdarg.h>
13388 +char *get_user_response(const char *format, ...);
13390 diff -ruN busybox-1.1.2-orig/archival/libipkg/void_list.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.c
13391 --- busybox-1.1.2-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13392 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.c 2006-05-09 02:06:48.000000000 +0200
13394 +/* void_list.c - the itsy package management system
13398 + Copyright (C) 2001 University of Southern California
13400 + This program is free software; you can redistribute it and/or
13401 + modify it under the terms of the GNU General Public License as
13402 + published by the Free Software Foundation; either version 2, or (at
13403 + your option) any later version.
13405 + This program is distributed in the hope that it will be useful, but
13406 + WITHOUT ANY WARRANTY; without even the implied warranty of
13407 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13408 + General Public License for more details.
13412 +#include <errno.h>
13414 +#include "void_list.h"
13416 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13418 + elt->next = NULL;
13419 + elt->data = data;
13424 +void void_list_elt_deinit(void_list_elt_t *elt)
13426 + void_list_elt_init(elt, NULL);
13429 +int void_list_init(void_list_t *list)
13431 + void_list_elt_init(&list->pre_head, NULL);
13432 + list->head = NULL;
13433 + list->pre_head.next = list->head;
13434 + list->tail = NULL;
13439 +void void_list_deinit(void_list_t *list)
13441 + void_list_elt_t *elt;
13443 + while (list->head) {
13444 + elt = void_list_pop(list);
13445 + void_list_elt_deinit(elt);
13446 + /* malloced in void_list_append */
13451 +int void_list_append(void_list_t *list, void *data)
13453 + void_list_elt_t *elt;
13455 + /* freed in void_list_deinit */
13456 + elt = malloc(sizeof(void_list_elt_t));
13457 + if (elt == NULL) {
13458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13462 + void_list_elt_init(elt, data);
13464 + if (list->tail) {
13465 + list->tail->next = elt;
13466 + list->tail = elt;
13468 + list->head = elt;
13469 + list->pre_head.next = list->head;
13470 + list->tail = elt;
13476 +int void_list_push(void_list_t *list, void *data)
13478 + void_list_elt_t *elt;
13480 + elt = malloc(sizeof(void_list_elt_t));
13481 + if (elt == NULL) {
13482 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13486 + void_list_elt_init(elt, data);
13488 + elt->next = list->head;
13489 + list->head->next = elt;
13490 + if (list->tail == NULL) {
13491 + list->tail = list->head;
13497 +void_list_elt_t *void_list_pop(void_list_t *list)
13499 + void_list_elt_t *elt;
13501 + elt = list->head;
13503 + if (list->head) {
13504 + list->head = list->head->next;
13505 + list->pre_head.next = list->head;
13506 + if (list->head == NULL) {
13507 + list->tail = NULL;
13514 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13516 + void_list_elt_t *prior;
13517 + void_list_elt_t *old_elt;
13521 + old_data = old_elt->data;
13523 + if (old_elt == list->head) {
13524 + prior = &list->pre_head;
13525 + void_list_pop(list);
13527 + for (prior = list->head; prior; prior = prior->next) {
13528 + if (prior->next == old_elt) {
13532 + if (prior == NULL || prior->next != old_elt) {
13533 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13536 + prior->next = old_elt->next;
13538 + if (old_elt == list->tail) {
13539 + list->tail = prior;
13543 + void_list_elt_deinit(old_elt);
13549 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13550 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13552 + void_list_elt_t *prior;
13553 + void_list_elt_t *old_elt = NULL;
13554 + void *old_data = NULL;
13556 + /* first element */
13557 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13558 + old_elt = list->head;
13559 + old_data = list->head->data;
13560 + void_list_pop(list);
13563 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13564 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13565 + old_elt = prior->next;
13566 + old_data = old_elt->data;
13574 + prior->next = old_elt->next;
13576 + if (old_elt == list->tail) {
13577 + list->tail = prior;
13581 + void_list_elt_deinit(old_elt);
13588 diff -ruN busybox-1.1.2-orig/archival/libipkg/void_list.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.h
13589 --- busybox-1.1.2-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13590 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/void_list.h 2006-05-09 02:06:48.000000000 +0200
13592 +/* void_list.h - the itsy package management system
13596 + Copyright (C) 2001 University of Southern California
13598 + This program is free software; you can redistribute it and/or
13599 + modify it under the terms of the GNU General Public License as
13600 + published by the Free Software Foundation; either version 2, or (at
13601 + your option) any later version.
13603 + This program is distributed in the hope that it will be useful, but
13604 + WITHOUT ANY WARRANTY; without even the implied warranty of
13605 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13606 + General Public License for more details.
13609 +#ifndef VOID_LIST_H
13610 +#define VOID_LIST_H
13612 +typedef struct void_list_elt void_list_elt_t;
13613 +struct void_list_elt
13615 + void_list_elt_t *next;
13619 +typedef struct void_list void_list_t;
13622 + void_list_elt_t pre_head;
13623 + void_list_elt_t *head;
13624 + void_list_elt_t *tail;
13627 +static inline int void_list_empty(void_list_t *list)
13629 + if (list->head == NULL)
13635 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13636 +void void_list_elt_deinit(void_list_elt_t *elt);
13638 +int void_list_init(void_list_t *list);
13639 +void void_list_deinit(void_list_t *list);
13641 +int void_list_append(void_list_t *list, void *data);
13642 +int void_list_push(void_list_t *list, void *data);
13643 +void_list_elt_t *void_list_pop(void_list_t *list);
13645 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13646 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13647 +typedef int (*void_list_cmp_t)(const void *, const void *);
13648 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13651 diff -ruN busybox-1.1.2-orig/archival/libipkg/xsystem.c busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.c
13652 --- busybox-1.1.2-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13653 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-05-09 02:06:48.000000000 +0200
13655 +/* xsystem.c - system(3) with error messages
13659 + Copyright (C) 2001 University of Southern California
13661 + This program is free software; you can redistribute it and/or
13662 + modify it under the terms of the GNU General Public License as
13663 + published by the Free Software Foundation; either version 2, or (at
13664 + your option) any later version.
13666 + This program is distributed in the hope that it will be useful, but
13667 + WITHOUT ANY WARRANTY; without even the implied warranty of
13668 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13669 + General Public License for more details.
13673 +#include <sys/wait.h>
13675 +#include "xsystem.h"
13677 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13678 + really need the /bin/sh invocation which takes resources and
13679 + introduces security problems. I should switch all of this to a sort
13680 + of execl() or execv() interface/implementation.
13683 +/* Like system(3), but with error messages printed if the fork fails
13684 + or if the child process dies due to an uncaught signal. Also, the
13685 + return value is a bit simpler:
13687 + -1 if there was any problem
13688 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13689 + as defined in <sys/wait.h>.
13691 +int xsystem(const char *cmd)
13695 + err = system(cmd);
13698 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13699 + __FUNCTION__, cmd);
13703 + if (WIFSIGNALED(err)) {
13704 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13705 + __FUNCTION__, WTERMSIG(err), cmd);
13709 + if (WIFEXITED(err)) {
13710 + /* Normal child exit */
13711 + return WEXITSTATUS(err);
13714 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13715 + __FUNCTION__, err);
13719 diff -ruN busybox-1.1.2-orig/archival/libipkg/xsystem.h busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.h
13720 --- busybox-1.1.2-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13721 +++ busybox-1.1.2+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-05-09 02:06:48.000000000 +0200
13723 +/* xsystem.h - system(3) with error messages
13727 + Copyright (C) 2001 University of Southern California
13729 + This program is free software; you can redistribute it and/or
13730 + modify it under the terms of the GNU General Public License as
13731 + published by the Free Software Foundation; either version 2, or (at
13732 + your option) any later version.
13734 + This program is distributed in the hope that it will be useful, but
13735 + WITHOUT ANY WARRANTY; without even the implied warranty of
13736 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13737 + General Public License for more details.
13743 +#include <stdlib.h>
13745 +/* Like system(3), but with error messages printed if the fork fails
13746 + or if the child process dies due to an uncaught signal. Also, the
13747 + return value is a bit simpler:
13749 + -1 if there was any problem
13750 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13751 + as defined in <sys/wait.h>.
13753 +int xsystem(const char *cmd);
13757 diff -ruN busybox-1.1.2-orig/archival/libunarchive/Makefile.in busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/Makefile.in
13758 --- busybox-1.1.2-orig/archival/libunarchive/Makefile.in 2006-03-22 22:16:20.000000000 +0100
13759 +++ busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-05-09 02:06:48.000000000 +0200
13761 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13762 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13763 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13764 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13765 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13766 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13767 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13768 diff -ruN busybox-1.1.2-orig/archival/libunarchive/data_extract_all.c busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/data_extract_all.c
13769 --- busybox-1.1.2-orig/archival/libunarchive/data_extract_all.c 2006-03-22 22:16:20.000000000 +0100
13770 +++ busybox-1.1.2+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-05-09 02:06:48.000000000 +0200
13771 @@ -126,3 +126,17 @@
13772 utime(file_header->name, &t);
13776 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13778 + char *name_ptr = archive_handle->file_header->name;
13780 + name_ptr += strspn(name_ptr, "./");
13781 + if (name_ptr[0] != '\0') {
13782 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13783 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13784 + strcat(archive_handle->file_header->name, name_ptr);
13785 + data_extract_all(archive_handle);
13789 diff -ruN busybox-1.1.2-orig/include/applets.h busybox-1.1.2+ipkg-0.99.162/include/applets.h
13790 --- busybox-1.1.2-orig/include/applets.h 2006-03-22 22:16:24.000000000 +0100
13791 +++ busybox-1.1.2+ipkg-0.99.162/include/applets.h 2006-05-09 02:06:48.000000000 +0200
13792 @@ -149,6 +149,7 @@
13793 USE_IPCALC(APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13794 USE_IPCRM(APPLET(ipcrm, ipcrm_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13795 USE_IPCS(APPLET(ipcs, ipcs_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13796 +USE_IPKG(APPLET(ipkg, ipkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13797 USE_IPLINK(APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13798 USE_IPROUTE(APPLET(iproute, iproute_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13799 USE_IPTUNNEL(APPLET(iptunnel, iptunnel_main, _BB_DIR_BIN, _BB_SUID_NEVER))
13800 diff -ruN busybox-1.1.2-orig/include/unarchive.h busybox-1.1.2+ipkg-0.99.162/include/unarchive.h
13801 --- busybox-1.1.2-orig/include/unarchive.h 2006-03-22 22:16:24.000000000 +0100
13802 +++ busybox-1.1.2+ipkg-0.99.162/include/unarchive.h 2006-05-09 02:06:48.000000000 +0200
13805 extern void data_skip(archive_handle_t *archive_handle);
13806 extern void data_extract_all(archive_handle_t *archive_handle);
13807 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13808 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13809 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13811 diff -ruN busybox-1.1.2-orig/include/usage.h busybox-1.1.2+ipkg-0.99.162/include/usage.h
13812 --- busybox-1.1.2-orig/include/usage.h 2006-03-22 22:16:24.000000000 +0100
13813 +++ busybox-1.1.2+ipkg-0.99.162/include/usage.h 2006-05-09 02:06:48.000000000 +0200
13814 @@ -1013,6 +1013,82 @@
13815 "$ ls -la /tmp/busybox*\n" \
13816 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13818 +#define ipkg_trivial_usage \
13819 + "[options]... sub-command [arguments]..."
13820 +#define ipkg_full_usage \
13821 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13823 + "Sub-commands:\n" \
13824 + "\nPackage Manipulation:\n" \
13825 + "\tupdate Update list of available packages\n" \
13826 + "\tupgrade Upgrade all installed packages to latest version\n" \
13827 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13828 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13829 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13830 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13831 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13832 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13834 + "Informational Commands:\n" \
13835 + "\tlist List available packages and descriptions\n" \
13836 + "\tlist_installed List all and only the installed packages and description \n" \
13837 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13838 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13839 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13840 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13841 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13842 + "\tcompare_versions <v1> <op> <v2>\n" \
13843 + "\t compare versions using <= < > >= = << >>\n" \
13844 + "\tprint_architecture prints the architecture.\n" \
13845 + "\tprint_installation_architecture\n" \
13846 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13847 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13848 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13849 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13850 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13851 + "\t prints the installation architecture.\n" \
13854 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13855 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13856 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13857 + "\t 0 errors only\n" \
13858 + "\t 1 normal messages (default)\n" \
13859 + "\t 2 informative messages\n" \
13860 + "\t 3 debug output\n" \
13861 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13862 + "\t-conf <conf_file> Default configuration file location\n" \
13863 + " is /etc/ipkg.conf\n" \
13864 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13865 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13866 + " <dest_name> should be a defined dest name from\n" \
13867 + " the configuration file, (but can also be a\n" \
13868 + " directory name in a pinch).\n" \
13869 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13870 + "\t-offline <offline_root> offline installation of packages.\n" \
13871 + "\t-verbose_wget more wget messages\n" \
13873 + "Force Options (use when ipkg is too smart for its own good):\n" \
13874 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13875 + "\t Install/remove package in spite of failed dependences\n" \
13876 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13877 + " (no prompts). Note that this will not prevent\n" \
13878 + " package installation scripts from prompting.\n" \
13879 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13880 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13881 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13882 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13883 + "\t-noaction No action -- test only\n" \
13884 + "\t-nodeps Do not follow dependences\n" \
13885 + "\t-force-removal-of-dependent-packages\n" \
13886 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13887 + "\t-test No action -- test only\n" \
13888 + "\t-t Specify tmp-dir.\n" \
13889 + "\t--tmp-dir Specify tmp-dir.\n" \
13891 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13892 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13894 #define halt_trivial_usage \
13895 "[-d<delay>] [-n<nosync>] [-f<force>]"
13896 #define halt_full_usage \