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,