1 Index: busybox-1.4.2/archival/Config.in
2 ===================================================================
3 --- busybox-1.4.2.orig/archival/Config.in 2007-06-04 13:21:31.573176816 +0200
4 +++ busybox-1.4.2/archival/Config.in 2007-06-04 13:21:36.706396448 +0200
6 gzip is used to compress files.
7 It's probably the most widely used UNIX compression program.
15 + ipkg is the itsy package management system.
20 Index: busybox-1.4.2/archival/dpkg.c
21 ===================================================================
22 --- busybox-1.4.2.orig/archival/dpkg.c 2007-06-04 13:21:31.579175904 +0200
23 +++ busybox-1.4.2/archival/dpkg.c 2007-06-04 13:21:36.706396448 +0200
24 @@ -1463,6 +1463,10 @@
25 return ar_handle->sub_archive->buffer;
30 +// moved to data_extract_all.c
32 static void data_extract_all_prefix(archive_handle_t *archive_handle)
34 char *name_ptr = archive_handle->file_header->name;
41 static void unpack_package(deb_file_t *deb_file)
43 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
44 Index: busybox-1.4.2/archival/ipkg.c
45 ===================================================================
46 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
47 +++ busybox-1.4.2/archival/ipkg.c 2007-06-04 13:21:36.707396296 +0200
49 +/* ipkg.c - the itsy package management system
53 + Copyright (C) 2003 kernel concepts
55 + This program is free software; you can redistribute it and/or
56 + modify it under the terms of the GNU General Public License as
57 + published by the Free Software Foundation; either version 2, or (at
58 + your option) any later version.
60 + This program is distributed in the hope that it will be useful, but
61 + WITHOUT ANY WARRANTY; without even the implied warranty of
62 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63 + General Public License for more details.
65 + ipkg command line frontend using libipkg
69 +#include "libipkg/libipkg.h"
71 +int ipkg_main(int argc, char **argv)
73 + return ipkg_op(argc, argv);
75 Index: busybox-1.4.2/archival/Kbuild
76 ===================================================================
77 --- busybox-1.4.2.orig/archival/Kbuild 2007-06-04 13:21:31.588174536 +0200
78 +++ busybox-1.4.2/archival/Kbuild 2007-06-04 13:21:36.707396296 +0200
80 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
81 lib-$(CONFIG_GUNZIP) += gunzip.o
82 lib-$(CONFIG_GZIP) += gzip.o
83 +lib-$(CONFIG_IPKG) += ipkg.o
84 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
85 lib-$(CONFIG_RPM) += rpm.o
86 lib-$(CONFIG_TAR) += tar.o
87 Index: busybox-1.4.2/archival/libipkg/args.c
88 ===================================================================
89 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
90 +++ busybox-1.4.2/archival/libipkg/args.c 2007-06-04 13:21:36.707396296 +0200
92 +/* args.c - parse command-line args
96 + Copyright 2001 University of Southern California
98 + This program is free software; you can redistribute it and/or modify
99 + it under the terms of the GNU General Public License as published by
100 + the Free Software Foundation; either version 2, or (at your option)
103 + This program is distributed in the hope that it will be useful,
104 + but WITHOUT ANY WARRANTY; without even the implied warranty of
105 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106 + GNU General Public License for more details.
115 +#include "ipkg_message.h"
118 +#include "sprintf_alloc.h"
123 +static void print_version(void);
127 + ARGS_OPT_FORCE_DEFAULTS = 129,
128 + ARGS_OPT_FORCE_DEPENDS,
129 + ARGS_OPT_FORCE_OVERWRITE,
130 + ARGS_OPT_FORCE_DOWNGRADE,
131 + ARGS_OPT_FORCE_REINSTALL,
132 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
133 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
134 + ARGS_OPT_FORCE_SPACE,
137 + ARGS_OPT_VERBOSE_WGET,
138 + ARGS_OPT_VERBOSITY,
139 + ARGS_OPT_MULTIPLE_PROVIDERS
142 +int args_init(args_t *args)
144 + char *conf_file_dir;
146 + memset(args, 0, sizeof(args_t));
148 + args->dest = ARGS_DEFAULT_DEST;
150 + conf_file_dir = getenv("IPKG_CONF_DIR");
151 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
152 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
154 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
155 + ARGS_DEFAULT_CONF_FILE_NAME);
157 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
158 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
159 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
160 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
161 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
162 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
163 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
164 + args->noaction = ARGS_DEFAULT_NOACTION;
165 + args->nodeps = ARGS_DEFAULT_NODEPS;
166 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
167 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
168 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
169 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
170 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
171 + args->multiple_providers = 0;
172 + args->nocheckfordirorfile = 0;
173 + args->noreadfeedsfile = 0;
178 +void args_deinit(args_t *args)
180 + free(args->conf_file);
181 + args->conf_file = NULL;
184 +int args_parse(args_t *args, int argc, char *argv[])
187 + int option_index = 0;
189 + static struct option long_options[] = {
190 + {"query-all", 0, 0, 'A'},
191 + {"conf-file", 1, 0, 'f'},
192 + {"conf", 1, 0, 'f'},
193 + {"dest", 1, 0, 'd'},
194 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
195 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
196 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
197 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
198 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
199 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
200 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
201 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
202 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
203 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
204 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
205 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
206 + {"recursive", 0, 0,
207 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
208 + {"force-removal-of-dependent-packages", 0, 0,
209 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
210 + {"force_removal_of_dependent_packages", 0, 0,
211 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
212 + {"force-removal-of-essential-packages", 0, 0,
213 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
214 + {"force_removal_of_essential_packages", 0, 0,
215 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
216 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
217 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
218 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
219 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
220 + {"offline", 1, 0, 'o'},
221 + {"offline-root", 1, 0, 'o'},
222 + {"test", 0, 0, ARGS_OPT_NOACTION},
223 + {"tmp-dir", 1, 0, 't'},
224 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
225 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
226 + {"verbosity", 2, 0, 'V'},
227 + {"version", 0, 0, 'v'},
232 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
238 + args->query_all = 1;
241 + args->dest = optarg;
244 + free(args->conf_file);
245 + args->conf_file = strdup(optarg);
248 + args->offline_root = optarg;
251 + args->noaction = 1;
254 + args->tmp_dir = strdup(optarg);
260 + case ARGS_OPT_VERBOSITY:
262 + args->verbosity = atoi(optarg);
264 + args->verbosity += 1;
266 + case ARGS_OPT_FORCE_DEFAULTS:
267 + args->force_defaults = 1;
269 + case ARGS_OPT_FORCE_DEPENDS:
270 + args->force_depends = 1;
272 + case ARGS_OPT_FORCE_OVERWRITE:
273 + args->force_overwrite = 1;
275 + case ARGS_OPT_FORCE_DOWNGRADE:
276 + args->force_downgrade = 1;
278 + case ARGS_OPT_FORCE_REINSTALL:
279 + args->force_reinstall = 1;
281 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
282 + args->force_removal_of_essential_packages = 1;
284 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
285 + args->force_removal_of_dependent_packages = 1;
287 + case ARGS_OPT_FORCE_SPACE:
288 + args->force_space = 1;
290 + case ARGS_OPT_VERBOSE_WGET:
291 + args->verbose_wget = 1;
293 + case ARGS_OPT_MULTIPLE_PROVIDERS:
294 + args->multiple_providers = 1;
296 + case ARGS_OPT_NODEPS:
299 + case ARGS_OPT_NOACTION:
300 + args->noaction = 1;
309 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
320 +void args_usage(char *complaint)
323 + bb_error_msg("%s\n", complaint);
330 +static void print_version(void)
332 + bb_error_msg("version %s\n", IPKG_VERSION);
334 Index: busybox-1.4.2/archival/libipkg/args.h
335 ===================================================================
336 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
337 +++ busybox-1.4.2/archival/libipkg/args.h 2007-06-04 13:21:36.707396296 +0200
339 +/* args.h - parse command-line args
343 + Copyright 2001 University of Southern California
345 + This program is free software; you can redistribute it and/or modify
346 + it under the terms of the GNU General Public License as published by
347 + the Free Software Foundation; either version 2, or (at your option)
350 + This program is distributed in the hope that it will be useful,
351 + but WITHOUT ANY WARRANTY; without even the implied warranty of
352 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
353 + GNU General Public License for more details.
364 + int force_defaults;
366 + int force_overwrite;
367 + int force_downgrade;
368 + int force_reinstall;
369 + int force_removal_of_essential_packages;
370 + int force_removal_of_dependent_packages;
374 + int multiple_providers;
378 + int nocheckfordirorfile;
379 + int noreadfeedsfile;
380 + char *offline_root;
381 + char *offline_root_pre_script_cmd;
382 + char *offline_root_post_script_cmd;
384 +typedef struct args args_t;
386 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
387 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
388 +#define ARGS_DEFAULT_DEST NULL
389 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
390 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
391 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
392 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
393 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
394 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
395 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
396 +#define ARGS_DEFAULT_FORCE_SPACE 0
397 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
398 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
399 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
400 +#define ARGS_DEFAULT_NOACTION 0
401 +#define ARGS_DEFAULT_NODEPS 0
402 +#define ARGS_DEFAULT_VERBOSE_WGET 0
403 +#define ARGS_DEFAULT_VERBOSITY 1
405 +int args_init(args_t *args);
406 +void args_deinit(args_t *args);
407 +int args_parse(args_t *args, int argc, char *argv[]);
408 +void args_usage(char *complaint);
411 Index: busybox-1.4.2/archival/libipkg/conffile.c
412 ===================================================================
413 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
414 +++ busybox-1.4.2/archival/libipkg/conffile.c 2007-06-04 13:21:36.708396144 +0200
416 +/* conffile.c - the itsy package management system
420 + Copyright (C) 2001 University of Southern California
422 + This program is free software; you can redistribute it and/or
423 + modify it under the terms of the GNU General Public License as
424 + published by the Free Software Foundation; either version 2, or (at
425 + your option) any later version.
427 + This program is distributed in the hope that it will be useful, but
428 + WITHOUT ANY WARRANTY; without even the implied warranty of
429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
430 + General Public License for more details.
437 +#include "ipkg_message.h"
439 +#include "conffile.h"
440 +#include "file_util.h"
441 +#include "sprintf_alloc.h"
443 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
445 + return nv_pair_init(conffile, file_name, md5sum);
448 +void conffile_deinit(conffile_t *conffile)
450 + nv_pair_deinit(conffile);
453 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
456 + char *filename = conffile->name;
457 + char *root_filename;
460 + if (conffile->value == NULL) {
461 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
465 + root_filename = root_filename_alloc(conf, filename);
467 + md5sum = file_md5sum_alloc(root_filename);
469 + ret = strcmp(md5sum, conffile->value);
471 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
472 + conffile->name, md5sum, conffile->value);
475 + free(root_filename);
480 Index: busybox-1.4.2/archival/libipkg/conffile.h
481 ===================================================================
482 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
483 +++ busybox-1.4.2/archival/libipkg/conffile.h 2007-06-04 13:21:36.708396144 +0200
485 +/* conffile.h - the itsy package management system
489 + Copyright (C) 2001 University of Southern California
491 + This program is free software; you can redistribute it and/or
492 + modify it under the terms of the GNU General Public License as
493 + published by the Free Software Foundation; either version 2, or (at
494 + your option) any later version.
496 + This program is distributed in the hope that it will be useful, but
497 + WITHOUT ANY WARRANTY; without even the implied warranty of
498 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
499 + General Public License for more details.
505 +#include "nv_pair.h"
507 +typedef struct nv_pair conffile_t;
509 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
510 +void conffile_deinit(conffile_t *conffile);
511 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
515 Index: busybox-1.4.2/archival/libipkg/conffile_list.c
516 ===================================================================
517 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
518 +++ busybox-1.4.2/archival/libipkg/conffile_list.c 2007-06-04 13:21:36.708396144 +0200
520 +/* conffile_list.c - the itsy package management system
524 + Copyright (C) 2001 University of Southern California
526 + This program is free software; you can redistribute it and/or
527 + modify it under the terms of the GNU General Public License as
528 + published by the Free Software Foundation; either version 2, or (at
529 + your option) any later version.
531 + This program is distributed in the hope that it will be useful, but
532 + WITHOUT ANY WARRANTY; without even the implied warranty of
533 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
534 + General Public License for more details.
539 +#include "conffile_list.h"
541 +int conffile_list_init(conffile_list_t *list)
543 + return nv_pair_list_init(list);
546 +void conffile_list_deinit(conffile_list_t *list)
548 + nv_pair_list_deinit(list);
551 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
552 + const char *md5sum)
554 + return nv_pair_list_append(list, file_name, md5sum);
557 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
559 + return nv_pair_list_push(list, data);
562 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
564 + return nv_pair_list_pop(list);
567 Index: busybox-1.4.2/archival/libipkg/conffile_list.h
568 ===================================================================
569 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
570 +++ busybox-1.4.2/archival/libipkg/conffile_list.h 2007-06-04 13:21:36.708396144 +0200
572 +/* conffile_list.h - the itsy package management system
576 + Copyright (C) 2001 University of Southern California
578 + This program is free software; you can redistribute it and/or
579 + modify it under the terms of the GNU General Public License as
580 + published by the Free Software Foundation; either version 2, or (at
581 + your option) any later version.
583 + This program is distributed in the hope that it will be useful, but
584 + WITHOUT ANY WARRANTY; without even the implied warranty of
585 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
586 + General Public License for more details.
589 +#ifndef CONFFILE_LIST_H
590 +#define CONFFILE_LIST_H
592 +#include "conffile.h"
593 +#include "nv_pair_list.h"
595 +typedef struct nv_pair_list_elt conffile_list_elt_t;
596 +typedef struct nv_pair_list conffile_list_t;
598 +int conffile_list_init(conffile_list_t *list);
599 +void conffile_list_deinit(conffile_list_t *list);
601 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
602 + const char *root_dir);
603 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
604 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
608 Index: busybox-1.4.2/archival/libipkg/file_util.c
609 ===================================================================
610 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
611 +++ busybox-1.4.2/archival/libipkg/file_util.c 2007-06-04 13:21:36.708396144 +0200
613 +/* file_util.c - convenience routines for common stat operations
617 + Copyright (C) 2001 University of Southern California
619 + This program is free software; you can redistribute it and/or
620 + modify it under the terms of the GNU General Public License as
621 + published by the Free Software Foundation; either version 2, or (at
622 + your option) any later version.
624 + This program is distributed in the hope that it will be useful, but
625 + WITHOUT ANY WARRANTY; without even the implied warranty of
626 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
627 + General Public License for more details.
631 +#include <sys/types.h>
632 +#include <sys/stat.h>
634 +#include "sprintf_alloc.h"
635 +#include "file_util.h"
639 +int file_exists(const char *file_name)
642 + struct stat stat_buf;
644 + err = stat(file_name, &stat_buf);
652 +int file_is_dir(const char *file_name)
655 + struct stat stat_buf;
657 + err = stat(file_name, &stat_buf);
662 + return S_ISDIR(stat_buf.st_mode);
665 +/* read a single line from a file, stopping at a newline or EOF.
666 + If a newline is read, it will appear in the resulting string.
667 + Return value is a malloc'ed char * which should be freed at
668 + some point by the caller.
670 + Return value is NULL if the file is at EOF when called.
672 +#define FILE_READ_LINE_BUF_SIZE 1024
673 +char *file_read_line_alloc(FILE *file)
675 + char buf[FILE_READ_LINE_BUF_SIZE];
680 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
681 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
682 + buf_len = strlen(buf);
684 + line_size += buf_len;
685 + line = realloc(line, line_size);
686 + if (line == NULL) {
687 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
692 + line_size = buf_len + 1;
693 + line = strdup(buf);
695 + if (buf[buf_len - 1] == '\n') {
703 +int file_move(const char *src, const char *dest)
707 + err = rename(src, dest);
709 + if (err && errno == EXDEV) {
710 + err = file_copy(src, dest);
713 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
714 + __FUNCTION__, src, dest, strerror(errno));
720 +/* I put these here to keep libbb dependencies from creeping all over
722 +int file_copy(const char *src, const char *dest)
726 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
728 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
729 + __FUNCTION__, src, dest);
735 +int file_mkdir_hier(const char *path, long mode)
737 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
740 +char *file_md5sum_alloc(const char *file_name)
742 + return hash_file(file_name, HASH_MD5);
745 Index: busybox-1.4.2/archival/libipkg/file_util.h
746 ===================================================================
747 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
748 +++ busybox-1.4.2/archival/libipkg/file_util.h 2007-06-04 13:21:36.708396144 +0200
750 +/* file_util.h - convenience routines for common file operations
754 + Copyright (C) 2001 University of Southern California
756 + This program is free software; you can redistribute it and/or
757 + modify it under the terms of the GNU General Public License as
758 + published by the Free Software Foundation; either version 2, or (at
759 + your option) any later version.
761 + This program is distributed in the hope that it will be useful, but
762 + WITHOUT ANY WARRANTY; without even the implied warranty of
763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
764 + General Public License for more details.
770 +int file_exists(const char *file_name);
771 +int file_is_dir(const char *file_name);
772 +char *file_read_line_alloc(FILE *file);
773 +int file_move(const char *src, const char *dest);
774 +int file_copy(const char *src, const char *dest);
775 +int file_mkdir_hier(const char *path, long mode);
776 +char *file_md5sum_alloc(const char *file_name);
779 Index: busybox-1.4.2/archival/libipkg/hash_table.c
780 ===================================================================
781 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
782 +++ busybox-1.4.2/archival/libipkg/hash_table.c 2007-06-04 13:21:36.709395992 +0200
784 +/* hash.c - hash tables for ipkg
786 + Steven M. Ayer, Jamey Hicks
788 + Copyright (C) 2002 Compaq Computer Corporation
790 + This program is free software; you can redistribute it and/or
791 + modify it under the terms of the GNU General Public License as
792 + published by the Free Software Foundation; either version 2, or (at
793 + your option) any later version.
795 + This program is distributed in the hope that it will be useful, but
796 + WITHOUT ANY WARRANTY; without even the implied warranty of
797 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
798 + General Public License for more details.
805 +#include "hash_table.h"
806 +#include "ipkg_message.h"
809 +static int hash_index(hash_table_t *hash, const char *pkg_name);
810 +static int rotating(const char *key, int len, int prime);
812 +static int hash_index(hash_table_t *hash, const char *pkg_name)
814 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
817 +static int rotating(const char *key, int len, int prime)
819 + unsigned int hash, i;
820 + for (hash=len, i=0; i<len; ++i)
821 + hash = (hash<<4)^(hash>>28)^key[i];
822 + return (hash % prime);
827 + * this is an open table keyed by strings
829 +int hash_table_init(const char *name, hash_table_t *hash, int len)
831 + static int primes_table[] = {
832 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
833 + 19471, 23143, 33961, 46499, 49727, 99529, 0
837 + if (hash->entries != NULL) {
838 + /* we have been here already */
843 + hash->entries = NULL;
844 + hash->n_entries = 0;
845 + hash->hash_entry_key = NULL;
847 + picker = primes_table;
848 + while(*picker && (*picker++ < len));
850 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
853 + hash->n_entries = *picker;
854 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
855 + if (hash->entries == NULL) {
856 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
862 +void hash_table_deinit(hash_table_t *hash)
864 + free(hash->entries);
865 + hash->entries = NULL;
866 + hash->n_entries = 0;
869 +void *hash_table_get(hash_table_t *hash, const char *key)
871 + int ndx= hash_index(hash, key);
872 + hash_entry_t *hash_entry = hash->entries + ndx;
875 + if (hash_entry->key)
877 + if (strcmp(key, hash_entry->key) == 0) {
878 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
879 + return hash_entry->data;
882 + hash_entry = hash_entry->next;
887 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
889 + int ndx= hash_index(hash, key);
890 + hash_entry_t *hash_entry = hash->entries + ndx;
891 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
892 + if (hash_entry->key) {
893 + if (strcmp(hash_entry->key, key) == 0) {
894 + /* alread in table, update the value */
895 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
896 + hash_entry->data = value;
900 + * if this is a collision, we have to go to the end of the ll,
901 + * then add a new entry
902 + * before we can hook up the value
904 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
905 + while (hash_entry->next)
906 + hash_entry = hash_entry->next;
907 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
908 + if (!hash_entry->next) {
911 + hash_entry = hash_entry->next;
912 + hash_entry->next = NULL;
915 + hash->n_elements++;
916 + hash_entry->key = strdup(key);
917 + hash_entry->data = value;
923 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
929 + for (i = 0; i < hash->n_entries; i++) {
930 + hash_entry_t *hash_entry = (hash->entries + i);
932 + if(hash_entry->key) {
933 + f(hash_entry->key, hash_entry->data, data);
935 + } while((hash_entry = hash_entry->next));
939 Index: busybox-1.4.2/archival/libipkg/hash_table.h
940 ===================================================================
941 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
942 +++ busybox-1.4.2/archival/libipkg/hash_table.h 2007-06-04 13:21:36.709395992 +0200
944 +/* hash.h - hash tables for ipkg
946 + Steven M. Ayer, Jamey Hicks
948 + Copyright (C) 2002 Compaq Computer Corporation
950 + This program is free software; you can redistribute it and/or
951 + modify it under the terms of the GNU General Public License as
952 + published by the Free Software Foundation; either version 2, or (at
953 + your option) any later version.
955 + This program is distributed in the hope that it will be useful, but
956 + WITHOUT ANY WARRANTY; without even the implied warranty of
957 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
958 + General Public License for more details.
961 +#ifndef _HASH_TABLE_H_
962 +#define _HASH_TABLE_H_
964 +typedef struct hash_entry hash_entry_t;
965 +typedef struct hash_table hash_table_t;
970 + struct hash_entry * next;
975 + hash_entry_t * entries;
976 + int n_entries; /* number of buckets */
978 + const char * (*hash_entry_key)(void * data);
981 +int hash_table_init(const char *name, hash_table_t *hash, int len);
982 +void hash_table_deinit(hash_table_t *hash);
983 +void *hash_table_get(hash_table_t *hash, const char *key);
984 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
985 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
987 +#endif /* _HASH_TABLE_H_ */
988 Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.c
989 ===================================================================
990 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
991 +++ busybox-1.4.2/archival/libipkg/ipkg_cmd.c 2007-06-04 13:21:36.710395840 +0200
993 +/* ipkg_cmd.c - the itsy package management system
997 + Copyright (C) 2001 University of Southern California
999 + This program is free software; you can redistribute it and/or
1000 + modify it under the terms of the GNU General Public License as
1001 + published by the Free Software Foundation; either version 2, or (at
1002 + your option) any later version.
1004 + This program is distributed in the hope that it will be useful, but
1005 + WITHOUT ANY WARRANTY; without even the implied warranty of
1006 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1007 + General Public License for more details.
1010 +#include <string.h>
1013 +#include <libgen.h>
1016 +#include <stdlib.h>
1017 +#include <unistd.h>
1018 +#include <signal.h>
1020 +#include <dirent.h>
1022 +#include "ipkg_conf.h"
1023 +#include "ipkg_cmd.h"
1024 +#include "ipkg_message.h"
1026 +#include "pkg_dest.h"
1027 +#include "pkg_parse.h"
1028 +#include "sprintf_alloc.h"
1030 +#include "file_util.h"
1031 +#include "str_util.h"
1033 +#include "unarchive.h"
1035 +#include <fnmatch.h>
1038 +#include "ipkg_download.h"
1039 +#include "ipkg_install.h"
1040 +#include "ipkg_upgrade.h"
1041 +#include "ipkg_remove.h"
1042 +#include "ipkg_configure.h"
1043 +#include "ipkg_message.h"
1046 +#include "libipkg.h"
1047 +static void *p_userdata = NULL;
1050 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1051 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1052 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1076 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1077 + array for easier maintenance */
1078 +static ipkg_cmd_t cmds[] = {
1079 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1080 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1081 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1082 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1083 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1084 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1085 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1086 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1087 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1088 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1089 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1090 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1091 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1092 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1093 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1094 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1095 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1096 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1097 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1098 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1101 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1102 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1103 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1104 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1105 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1106 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1107 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1110 +int ipkg_state_changed;
1111 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1113 + if (ipkg_state_changed && !conf->noaction) {
1114 + ipkg_message(conf, IPKG_INFO,
1115 + " writing status file\n");
1116 + ipkg_conf_write_status_files(conf);
1117 + pkg_write_changed_filelists(conf);
1119 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1124 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1126 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1131 + for (i=0; i < num_cmds; i++) {
1133 + if (strcmp(name, cmd->name) == 0) {
1142 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1145 + p_userdata = userdata;
1148 + result = (cmd->fun)(conf, argc, argv);
1149 + if ( result == 0 ) {
1150 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1152 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1155 + if ( error_list ) {
1156 + reverse_error_list(&error_list);
1158 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1159 + /* Here we print the errors collected and free the list */
1160 + while (error_list != NULL) {
1161 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1162 + error_list = error_list->next;
1165 + free_error_list(&error_list);
1169 + p_userdata = NULL;
1173 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1175 + return (cmd->fun)(conf, argc, argv);
1179 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1184 + pkg_src_list_elt_t *iter;
1188 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1190 + if (! file_is_dir(lists_dir)) {
1191 + if (file_exists(lists_dir)) {
1192 + ipkg_message(conf, IPKG_ERROR,
1193 + "%s: ERROR: %s exists, but is not a directory\n",
1194 + __FUNCTION__, lists_dir);
1198 + err = file_mkdir_hier(lists_dir, 0755);
1200 + ipkg_message(conf, IPKG_ERROR,
1201 + "%s: ERROR: failed to make directory %s: %s\n",
1202 + __FUNCTION__, lists_dir, strerror(errno));
1209 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1210 + char *url, *list_file_name;
1214 + if (src->extra_data) /* debian style? */
1215 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1216 + src->gzip ? "Packages.gz" : "Packages");
1218 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1220 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1223 + char *tmp_file_name;
1226 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1228 + if (mkdtemp (tmp) == NULL) {
1229 + perror ("mkdtemp");
1234 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1235 + err = ipkg_download(conf, url, tmp_file_name);
1237 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1238 + in = fopen (tmp_file_name, "r");
1239 + out = fopen (list_file_name, "w");
1241 + inflate_unzip_result res;
1242 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1249 + unlink (tmp_file_name);
1254 + err = ipkg_download(conf, url, list_file_name);
1258 + ipkg_message(conf, IPKG_NOTICE,
1259 + "Updated list of available packages in %s\n",
1263 + free(list_file_name);
1267 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1269 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1270 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1276 + pkg_vec_t *available = pkg_vec_alloc();
1277 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1278 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1279 + for (i = 0; i < available->len; i++) {
1280 + pkg_t *pkg = available->pkgs[i];
1281 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1282 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1283 + pkg->state_want = SW_UNKNOWN;
1287 + pkg_vec_free(available);
1289 + write_status_files_if_changed(conf);
1298 +/* scan the args passed and cache the local filenames of the packages */
1299 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1305 + * First scan through package names/urls
1306 + * For any urls, download the packages and install in database.
1307 + * For any files, install package info in database.
1309 + for (i = 0; i < argc; i ++) {
1310 + char *filename = argv [i];
1311 + //char *tmp = basename (tmp);
1312 + //int tmplen = strlen (tmp);
1314 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1316 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1319 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1321 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1328 +struct ipkg_intercept
1334 +typedef struct ipkg_intercept *ipkg_intercept_t;
1336 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1338 + ipkg_intercept_t ctx;
1342 + ctx = malloc (sizeof (*ctx));
1343 + ctx->oldpath = strdup (getenv ("PATH"));
1345 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1346 + setenv ("PATH", newpath, 1);
1351 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1352 + if (mkdir (ctx->statedir, 0770) < 0) {
1353 + if (errno == EEXIST) {
1354 + free (ctx->statedir);
1358 + perror (ctx->statedir);
1361 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1365 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1371 + setenv ("PATH", ctx->oldpath, 1);
1372 + free (ctx->oldpath);
1374 + dir = opendir (ctx->statedir);
1376 + struct dirent *de;
1377 + while (de = readdir (dir), de != NULL) {
1380 + if (de->d_name[0] == '.')
1383 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1384 + if (access (path, X_OK) == 0) {
1385 + if (system (path)) {
1387 + perror (de->d_name);
1393 + perror (ctx->statedir);
1395 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1399 + free (ctx->statedir);
1405 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1410 + ipkg_intercept_t ic;
1413 + ipkg_message(conf, IPKG_INFO,
1414 + "Configuring unpacked packages\n");
1417 + all = pkg_vec_alloc();
1418 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1420 + ic = ipkg_prep_intercepts (conf);
1422 + for(i = 0; i < all->len; i++) {
1423 + pkg = all->pkgs[i];
1425 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1428 + if (pkg->state_status == SS_UNPACKED) {
1429 + ipkg_message(conf, IPKG_NOTICE,
1430 + "Configuring %s\n", pkg->name);
1432 + r = ipkg_configure(conf, pkg);
1434 + pkg->state_status = SS_INSTALLED;
1435 + pkg->parent->state_status = SS_INSTALLED;
1436 + pkg->state_flag &= ~SF_PREFER;
1444 + r = ipkg_finalize_intercepts (ic);
1448 + pkg_vec_free(all);
1452 +static void sigint_handler(int sig)
1454 + signal(sig, SIG_DFL);
1455 + ipkg_message(NULL, IPKG_NOTICE,
1456 + "ipkg: interrupted. writing out status database\n");
1457 + write_status_files_if_changed(global_conf);
1461 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1467 + global_conf = conf;
1468 + signal(SIGINT, sigint_handler);
1471 + * Now scan through package names and install
1473 + for (i=0; i < argc; i++) {
1476 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1477 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1478 + if (err != EINVAL && err != 0)
1481 + pkg_info_preinstall_check(conf);
1483 + for (i=0; i < argc; i++) {
1485 + if (conf->multiple_providers)
1486 + err = ipkg_install_multi_by_name(conf, arg);
1488 + err = ipkg_install_by_name(conf, arg);
1490 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1491 + ipkg_message(conf, IPKG_ERROR,
1492 + "Cannot find package %s.\n"
1493 + "Check the spelling or perhaps run 'ipkg update'\n",
1498 + /* recheck to verify that all dependences are satisfied */
1499 + if (0) ipkg_satisfy_all_dependences(conf);
1501 + ipkg_configure_packages(conf, NULL);
1503 + write_status_files_if_changed(conf);
1508 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1514 + global_conf = conf;
1515 + signal(SIGINT, sigint_handler);
1518 + for (i=0; i < argc; i++) {
1519 + char *arg = argv[i];
1521 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1522 + if (err != EINVAL && err != 0)
1525 + pkg_info_preinstall_check(conf);
1527 + for (i=0; i < argc; i++) {
1528 + char *arg = argv[i];
1529 + if (conf->restrict_to_default_dest) {
1530 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1532 + conf->default_dest);
1533 + if (pkg == NULL) {
1534 + ipkg_message(conf, IPKG_NOTICE,
1535 + "Package %s not installed in %s\n",
1536 + argv[i], conf->default_dest->name);
1540 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1544 + ipkg_upgrade_pkg(conf, pkg);
1546 + ipkg_install_by_name(conf, arg);
1550 + pkg_vec_t *installed = pkg_vec_alloc();
1552 + pkg_info_preinstall_check(conf);
1554 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1555 + for (i = 0; i < installed->len; i++) {
1556 + pkg = installed->pkgs[i];
1557 + ipkg_upgrade_pkg(conf, pkg);
1559 + pkg_vec_free(installed);
1562 + /* recheck to verify that all dependences are satisfied */
1563 + if (0) ipkg_satisfy_all_dependences(conf);
1565 + ipkg_configure_packages(conf, NULL);
1567 + write_status_files_if_changed(conf);
1572 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1578 + pkg_info_preinstall_check(conf);
1579 + for (i = 0; i < argc; i++) {
1582 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1583 + if (pkg == NULL) {
1584 + ipkg_message(conf, IPKG_ERROR,
1585 + "Cannot find package %s.\n"
1586 + "Check the spelling or perhaps run 'ipkg update'\n",
1591 + err = ipkg_download_pkg(conf, pkg, ".");
1594 + ipkg_message(conf, IPKG_ERROR,
1595 + "Failed to download %s\n", pkg->name);
1597 + ipkg_message(conf, IPKG_NOTICE,
1598 + "Downloaded %s as %s\n",
1599 + pkg->name, pkg->local_filename);
1607 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1610 + pkg_vec_t *available;
1612 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1614 + char *pkg_name = NULL;
1615 + char *version_str;
1618 + pkg_name = argv[0];
1620 + available = pkg_vec_alloc();
1621 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1622 + for (i=0; i < available->len; i++) {
1623 + pkg = available->pkgs[i];
1624 + /* if we have package name or pattern and pkg does not match, then skip it */
1625 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1627 + if (pkg->description) {
1628 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1630 + desc_short[0] = '\0';
1632 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1633 + newline = strchr(desc_short, '\n');
1638 + printf("%s - %s\n", pkg->name, desc_short);
1640 + if (ipkg_cb_list) {
1641 + version_str = pkg_version_str_alloc(pkg);
1642 + ipkg_cb_list(pkg->name,desc_short,
1644 + pkg->state_status,
1646 + free(version_str);
1650 + pkg_vec_free(available);
1656 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1659 + pkg_vec_t *available;
1661 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1663 + char *pkg_name = NULL;
1664 + char *version_str;
1667 + pkg_name = argv[0];
1669 + available = pkg_vec_alloc();
1670 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1671 + for (i=0; i < available->len; i++) {
1672 + pkg = available->pkgs[i];
1673 + /* if we have package name or pattern and pkg does not match, then skip it */
1674 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1676 + if (pkg->description) {
1677 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1679 + desc_short[0] = '\0';
1681 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1682 + newline = strchr(desc_short, '\n');
1687 + printf("%s - %s\n", pkg->name, desc_short);
1689 + if (ipkg_cb_list) {
1690 + version_str = pkg_version_str_alloc(pkg);
1691 + ipkg_cb_list(pkg->name,desc_short,
1693 + pkg->state_status,
1695 + free(version_str);
1703 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1706 + pkg_vec_t *available;
1708 + char *pkg_name = NULL;
1709 + char **pkg_fields = NULL;
1711 + char *buff ; // = (char *)malloc(1);
1714 + pkg_name = argv[0];
1717 + pkg_fields = &argv[1];
1718 + n_fields = argc - 1;
1721 + available = pkg_vec_alloc();
1722 + if (installed_only)
1723 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1725 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1726 + for (i=0; i < available->len; i++) {
1727 + pkg = available->pkgs[i];
1728 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1733 + for (j = 0; j < n_fields; j++)
1734 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1736 + pkg_print_info(pkg, stdout);
1740 + buff = pkg_formatted_info(pkg);
1742 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1743 + pkg->state_status,
1747 + We should not forget that actually the pointer is allocated.
1748 + We need to free it :) ( Thanks florian for seeing the error )
1753 + if (conf->verbosity > 1) {
1754 + conffile_list_elt_t *iter;
1755 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1756 + conffile_t *cf = iter->data;
1757 + int modified = conffile_has_been_modified(conf, cf);
1758 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1759 + cf->name, cf->value, modified);
1767 + pkg_vec_free(available);
1772 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1774 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1777 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1779 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1782 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1787 + char *pkg_name = NULL;
1789 + pkg_name = argv[0];
1791 + err = ipkg_configure_packages (conf, pkg_name);
1794 + err = ipkg_configure_packages (conf, NULL);
1797 + write_status_files_if_changed(conf);
1802 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1805 + char *globpattern;
1808 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1809 + err = glob(globpattern, 0, NULL, &globbuf);
1810 + free(globpattern);
1815 + ipkg_message(conf, IPKG_NOTICE,
1816 + "The following packages in %s will now be installed.\n",
1817 + conf->pending_dir);
1818 + for (i = 0; i < globbuf.gl_pathc; i++) {
1819 + ipkg_message(conf, IPKG_NOTICE,
1820 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1822 + ipkg_message(conf, IPKG_NOTICE, "\n");
1823 + for (i = 0; i < globbuf.gl_pathc; i++) {
1824 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1826 + err = unlink(globbuf.gl_pathv[i]);
1828 + ipkg_message(conf, IPKG_ERROR,
1829 + "%s: ERROR: failed to unlink %s: %s\n",
1830 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1835 + globfree(&globbuf);
1840 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1844 + pkg_t *pkg_to_remove;
1845 + pkg_vec_t *available;
1846 + char *pkg_name = NULL;
1847 + global_conf = conf;
1848 + signal(SIGINT, sigint_handler);
1850 +// ENH: Add the "no pkg removed" just in case.
1854 + available = pkg_vec_alloc();
1855 + pkg_info_preinstall_check(conf);
1857 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1858 + for (i=0; i < argc; i++) {
1859 + pkg_name = malloc(strlen(argv[i])+2);
1860 + strcpy(pkg_name,argv[i]);
1861 + for (a=0; a < available->len; a++) {
1862 + pkg = available->pkgs[a];
1863 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1866 + if (conf->restrict_to_default_dest) {
1867 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1869 + conf->default_dest);
1871 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1874 + if (pkg == NULL) {
1875 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1878 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1879 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1882 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1887 + pkg_vec_free(available);
1889 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1890 + int flagged_pkg_count = 0;
1893 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1895 + for (i = 0; i < installed_pkgs->len; i++) {
1896 + pkg = installed_pkgs->pkgs[i];
1897 + if (pkg->state_flag & SF_USER) {
1898 + flagged_pkg_count++;
1900 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1901 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1904 + if (!flagged_pkg_count) {
1905 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1906 + "so refusing to uninstall unflagged non-leaf packages\n");
1910 + /* find packages not flagged SF_USER (i.e., installed to
1911 + * satisfy a dependence) and not having any dependents, and
1915 + for (i = 0; i < installed_pkgs->len; i++) {
1916 + pkg = installed_pkgs->pkgs[i];
1917 + if (!(pkg->state_flag & SF_USER)
1918 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1920 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1921 + ipkg_remove_pkg(conf, pkg,0);
1925 + } while (removed);
1926 + pkg_vec_free(installed_pkgs);
1930 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1932 + write_status_files_if_changed(conf);
1936 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1941 + global_conf = conf;
1942 + signal(SIGINT, sigint_handler);
1944 + pkg_info_preinstall_check(conf);
1946 + for (i=0; i < argc; i++) {
1947 + if (conf->restrict_to_default_dest) {
1948 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1950 + conf->default_dest);
1952 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1955 + if (pkg == NULL) {
1956 + ipkg_message(conf, IPKG_ERROR,
1957 + "Package %s is not installed.\n", argv[i]);
1960 + ipkg_purge_pkg(conf, pkg);
1963 + write_status_files_if_changed(conf);
1967 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1971 + char *flags = argv[0];
1973 + global_conf = conf;
1974 + signal(SIGINT, sigint_handler);
1976 + for (i=1; i < argc; i++) {
1977 + if (conf->restrict_to_default_dest) {
1978 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1980 + conf->default_dest);
1982 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1985 + if (pkg == NULL) {
1986 + ipkg_message(conf, IPKG_ERROR,
1987 + "Package %s is not installed.\n", argv[i]);
1990 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1991 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1992 + pkg->state_flag = pkg_state_flag_from_str(flags);
1994 +/* pb_ asked this feature 03292004 */
1995 +/* Actually I will use only this two, but this is an open for various status */
1996 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1997 + pkg->state_status = pkg_state_status_from_str(flags);
1999 + ipkg_state_changed++;
2000 + ipkg_message(conf, IPKG_NOTICE,
2001 + "Setting flags for package %s to %s\n",
2002 + pkg->name, flags);
2005 + write_status_files_if_changed(conf);
2009 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2012 + str_list_t *installed_files;
2013 + str_list_elt_t *iter;
2014 + char *pkg_version;
2015 + size_t buff_len = 8192;
2019 + buff = (char *)malloc(buff_len);
2020 + if ( buff == NULL ) {
2021 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2029 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2031 + if (pkg == NULL) {
2032 + ipkg_message(conf, IPKG_ERROR,
2033 + "Package %s not installed.\n", argv[0]);
2037 + installed_files = pkg_get_installed_files(pkg);
2038 + pkg_version = pkg_version_str_alloc(pkg);
2041 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2042 + pkg->name, pkg_version, pkg->dest->name);
2043 + for (iter = installed_files->head; iter; iter = iter->next) {
2049 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2050 + pkg->name, pkg_version, pkg->dest->name) + 1;
2051 + if (used_len > buff_len) {
2053 + buff = realloc (buff, buff_len);
2056 + for (iter = installed_files->head; iter; iter = iter->next) {
2057 + used_len += strlen (iter->data) + 1;
2058 + while (buff_len <= used_len) {
2060 + buff = realloc (buff, buff_len);
2062 + strncat(buff, iter->data, buff_len);
2063 + strncat(buff, "\n", buff_len);
2065 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2067 + pkg_version_str_alloc(pkg),
2068 + pkg->state_status,
2074 + free(pkg_version);
2075 + pkg_free_installed_files(pkg);
2080 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2084 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2085 + const char *rel_str = "depends on";
2088 + pkg_info_preinstall_check(conf);
2090 + if (conf->query_all)
2091 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2093 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2094 + for (i = 0; i < argc; i++) {
2095 + const char *target = argv[i];
2098 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2100 + for (j = 0; j < available_pkgs->len; j++) {
2101 + pkg_t *pkg = available_pkgs->pkgs[j];
2102 + if (fnmatch(target, pkg->name, 0) == 0) {
2104 + int count = pkg->depends_count + pkg->pre_depends_count;
2105 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2106 + target, pkg->architecture, rel_str);
2107 + for (k = 0; k < count; k++) {
2108 + compound_depend_t *cdepend = &pkg->depends[k];
2110 + for (l = 0; l < cdepend->possibility_count; l++) {
2111 + depend_t *possibility = cdepend->possibilities[l];
2112 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2113 + if (conf->verbosity > 0) {
2114 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2115 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2116 + if (possibility->version) {
2117 + char *typestr = NULL;
2118 + switch (possibility->constraint) {
2119 + case NONE: typestr = "none"; break;
2120 + case EARLIER: typestr = "<"; break;
2121 + case EARLIER_EQUAL: typestr = "<="; break;
2122 + case EQUAL: typestr = "="; break;
2123 + case LATER_EQUAL: typestr = ">="; break;
2124 + case LATER: typestr = ">"; break;
2126 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2130 + ipkg_message(conf, IPKG_ERROR, "\n");
2136 + pkg_vec_free(available_pkgs);
2141 +enum what_field_type {
2150 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2154 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2155 + const char *rel_str = NULL;
2159 + switch (what_field_type) {
2160 + case WHATDEPENDS: rel_str = "depends on"; break;
2161 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2162 + case WHATSUGGESTS: rel_str = "suggests"; break;
2163 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2164 + case WHATPROVIDES: rel_str = "provides"; break;
2165 + case WHATREPLACES: rel_str = "replaces"; break;
2168 + if (conf->query_all)
2169 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2171 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2173 + /* mark the root set */
2174 + pkg_vec_clear_marks(available_pkgs);
2175 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2176 + for (i = 0; i < argc; i++) {
2177 + const char *dependee_pattern = argv[i];
2178 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2180 + for (i = 0; i < available_pkgs->len; i++) {
2181 + pkg_t *pkg = available_pkgs->pkgs[i];
2182 + if (pkg->state_flag & SF_MARKED) {
2183 + /* mark the parent (abstract) package */
2184 + pkg_mark_provides(pkg);
2185 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2189 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2194 + for (j = 0; j < available_pkgs->len; j++) {
2195 + pkg_t *pkg = available_pkgs->pkgs[j];
2197 + int count = ((what_field_type == WHATCONFLICTS)
2198 + ? pkg->conflicts_count
2199 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2200 + /* skip this package if it is already marked */
2201 + if (pkg->parent->state_flag & SF_MARKED) {
2204 + for (k = 0; k < count; k++) {
2205 + compound_depend_t *cdepend =
2206 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2208 + for (l = 0; l < cdepend->possibility_count; l++) {
2209 + depend_t *possibility = cdepend->possibilities[l];
2210 + if (possibility->pkg->state_flag & SF_MARKED) {
2211 + /* mark the depending package so we won't visit it again */
2212 + pkg->state_flag |= SF_MARKED;
2213 + pkg_mark_provides(pkg);
2216 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2217 + if (conf->verbosity > 0) {
2218 + char *ver = pkg_version_str_alloc(pkg);
2219 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2220 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2221 + if (possibility->version) {
2222 + char *typestr = NULL;
2223 + switch (possibility->constraint) {
2224 + case NONE: typestr = "none"; break;
2225 + case EARLIER: typestr = "<"; break;
2226 + case EARLIER_EQUAL: typestr = "<="; break;
2227 + case EQUAL: typestr = "="; break;
2228 + case LATER_EQUAL: typestr = ">="; break;
2229 + case LATER: typestr = ">"; break;
2231 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2234 + if (!pkg_dependence_satisfiable(conf, possibility))
2235 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2237 + ipkg_message(conf, IPKG_NOTICE, "\n");
2238 + goto next_package;
2245 + } while (changed && recursive);
2246 + pkg_vec_free(available_pkgs);
2252 +int pkg_mark_provides(pkg_t *pkg)
2254 + int provides_count = pkg->provides_count;
2255 + abstract_pkg_t **provides = pkg->provides;
2257 + pkg->parent->state_flag |= SF_MARKED;
2258 + for (i = 0; i < provides_count; i++) {
2259 + provides[i]->state_flag |= SF_MARKED;
2264 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2266 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2268 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2270 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2273 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2275 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2278 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2280 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2283 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2285 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2288 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2292 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2293 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2296 + pkg_info_preinstall_check(conf);
2298 + if (conf->query_all)
2299 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2301 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2302 + for (i = 0; i < argc; i++) {
2303 + const char *target = argv[i];
2306 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2308 + for (j = 0; j < available_pkgs->len; j++) {
2309 + pkg_t *pkg = available_pkgs->pkgs[j];
2311 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2312 + for (k = 0; k < count; k++) {
2313 + abstract_pkg_t *apkg =
2314 + ((what_field_type == WHATPROVIDES)
2315 + ? pkg->provides[k]
2316 + : pkg->replaces[k]);
2317 + if (fnmatch(target, apkg->name, 0) == 0) {
2318 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2319 + if (strcmp(target, apkg->name) != 0)
2320 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2321 + ipkg_message(conf, IPKG_ERROR, "\n");
2326 + pkg_vec_free(available_pkgs);
2331 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2333 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2336 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2338 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2341 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2345 + pkg_vec_t *installed;
2347 + str_list_t *installed_files;
2348 + str_list_elt_t *iter;
2349 + char *installed_file;
2355 + installed = pkg_vec_alloc();
2356 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2358 + for (i=0; i < installed->len; i++) {
2359 + pkg = installed->pkgs[i];
2361 + installed_files = pkg_get_installed_files(pkg);
2363 + for (iter = installed_files->head; iter; iter = iter->next) {
2364 + installed_file = iter->data;
2365 + if (fnmatch(argv[0], installed_file, 0)==0) {
2367 + printf("%s: %s\n", pkg->name, installed_file);
2369 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2371 + pkg_version_str_alloc(pkg),
2372 + pkg->state_status, p_userdata);
2377 + pkg_free_installed_files(pkg);
2380 + /* XXX: CLEANUP: It's not obvious from the name of
2381 + pkg_hash_fetch_all_installed that we need to call
2382 + pkg_vec_free to avoid a memory leak. */
2383 + pkg_vec_free(installed);
2388 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2391 + /* this is a bit gross */
2392 + struct pkg p1, p2;
2393 + parseVersion(&p1, argv[0]);
2394 + parseVersion(&p2, argv[2]);
2395 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2397 + ipkg_message(conf, IPKG_ERROR,
2398 + "ipkg compare_versions <v1> <op> <v2>\n"
2399 + "<op> is one of <= >= << >> =\n");
2404 +#ifndef HOST_CPU_STR
2405 +#define HOST_CPU_STR__(X) #X
2406 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2407 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2410 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2412 + nv_pair_list_elt_t *l;
2414 + l = conf->arch_list.head;
2416 + nv_pair_t *nv = l->data;
2417 + printf("arch %s %s\n", nv->name, nv->value);
2424 Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.h
2425 ===================================================================
2426 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2427 +++ busybox-1.4.2/archival/libipkg/ipkg_cmd.h 2007-06-04 13:21:36.710395840 +0200
2429 +/* ipkg_cmd.h - the itsy package management system
2433 + Copyright (C) 2001 University of Southern California
2435 + This program is free software; you can redistribute it and/or
2436 + modify it under the terms of the GNU General Public License as
2437 + published by the Free Software Foundation; either version 2, or (at
2438 + your option) any later version.
2440 + This program is distributed in the hope that it will be useful, but
2441 + WITHOUT ANY WARRANTY; without even the implied warranty of
2442 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2443 + General Public License for more details.
2449 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2454 + int requires_args;
2455 + ipkg_cmd_fun_t fun;
2457 +typedef struct ipkg_cmd ipkg_cmd_t;
2459 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2461 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2462 + const char **argv, void *userdata);
2464 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2466 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2467 +/* install any packges with state_want == SW_INSTALL */
2468 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2469 +/* ensure that all dependences are satisfied */
2470 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2472 +int pkg_mark_provides(pkg_t *pkg);
2475 Index: busybox-1.4.2/archival/libipkg/ipkg_conf.c
2476 ===================================================================
2477 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2478 +++ busybox-1.4.2/archival/libipkg/ipkg_conf.c 2007-06-04 13:21:36.711395688 +0200
2480 +/* ipkg_conf.c - the itsy package management system
2484 + Copyright (C) 2001 University of Southern California
2486 + This program is free software; you can redistribute it and/or
2487 + modify it under the terms of the GNU General Public License as
2488 + published by the Free Software Foundation; either version 2, or (at
2489 + your option) any later version.
2491 + This program is distributed in the hope that it will be useful, but
2492 + WITHOUT ANY WARRANTY; without even the implied warranty of
2493 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2494 + General Public License for more details.
2500 +#include "ipkg_conf.h"
2502 +#include "xregex.h"
2503 +#include "sprintf_alloc.h"
2504 +#include "ipkg_conf.h"
2505 +#include "ipkg_message.h"
2506 +#include "file_util.h"
2507 +#include "str_util.h"
2508 +#include "xsystem.h"
2511 +ipkg_conf_t *global_conf;
2513 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2514 + pkg_src_list_t *pkg_src_list,
2515 + nv_pair_list_t *tmp_dest_nv_pair_list,
2516 + char **tmp_lists_dir);
2517 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2518 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2519 + const char *name, const char *value);
2520 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2521 + const char *default_dest_name);
2522 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2523 + pkg_src_list_t *nv_pair_list);
2524 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2525 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2527 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2529 + ipkg_option_t tmp[] = {
2530 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2531 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2532 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2533 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2534 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2535 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2536 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2537 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2538 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2539 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2540 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2541 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2542 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2543 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2544 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2545 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2546 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2547 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2548 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2549 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2550 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2554 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2555 + if ( options == NULL ){
2556 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2560 + memcpy(*options, tmp, sizeof(tmp));
2564 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2570 + *conf_str = strdup(arg_str);
2574 +static void ipkg_conf_free_string(char **conf_str)
2582 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2585 + char *tmp_dir_base;
2586 + nv_pair_list_t tmp_dest_nv_pair_list;
2587 + char * lists_dir =NULL;
2589 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2590 + char *pending_dir =NULL;
2592 + memset(conf, 0, sizeof(ipkg_conf_t));
2594 + pkg_src_list_init(&conf->pkg_src_list);
2596 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2597 + pkg_dest_list_init(&conf->pkg_dest_list);
2599 + nv_pair_list_init(&conf->arch_list);
2601 + conf->restrict_to_default_dest = 0;
2602 + conf->default_dest = NULL;
2605 + if (args->tmp_dir)
2606 + tmp_dir_base = args->tmp_dir;
2608 + tmp_dir_base = getenv("TMPDIR");
2609 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2610 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2611 + IPKG_CONF_TMP_DIR_SUFFIX);
2612 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2613 + if (conf->tmp_dir == NULL) {
2614 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2615 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2619 + conf->force_depends = 0;
2620 + conf->force_defaults = 0;
2621 + conf->force_overwrite = 0;
2622 + conf->force_downgrade = 0;
2623 + conf->force_reinstall = 0;
2624 + conf->force_space = 0;
2625 + conf->force_removal_of_essential_packages = 0;
2626 + conf->force_removal_of_dependent_packages = 0;
2628 + conf->verbose_wget = 0;
2629 + conf->offline_root = NULL;
2630 + conf->offline_root_pre_script_cmd = NULL;
2631 + conf->offline_root_post_script_cmd = NULL;
2632 + conf->multiple_providers = 0;
2633 + conf->verbosity = 1;
2634 + conf->noaction = 0;
2636 + conf->http_proxy = NULL;
2637 + conf->ftp_proxy = NULL;
2638 + conf->no_proxy = NULL;
2639 + conf->proxy_user = NULL;
2640 + conf->proxy_passwd = NULL;
2642 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2643 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2644 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + lists_dir=(char *)malloc(1);
2646 + lists_dir[0]='\0';
2647 + if (args->conf_file) {
2648 + struct stat stat_buf;
2649 + err = stat(args->conf_file, &stat_buf);
2651 + if (ipkg_conf_parse_file(conf, args->conf_file,
2652 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2653 + /* Memory leakage from ipkg_conf_parse-file */
2659 + /* if (!lists_dir ){*/
2660 + if (strlen(lists_dir)<=1 ){
2661 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2662 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2665 + if (args->offline_root) {
2666 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2667 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2672 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2673 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2675 + conf->lists_dir = strdup(lists_dir);
2676 + conf->pending_dir = strdup(pending_dir);
2678 + if (args->offline_root)
2679 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2680 + memset(&globbuf, 0, sizeof(globbuf));
2681 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2684 + for (i = 0; i < globbuf.gl_pathc; i++) {
2685 + if (globbuf.gl_pathv[i])
2686 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2687 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2688 + /* Memory leakage from ipkg_conf_parse-file */
2693 + globfree(&globbuf);
2695 + /* if no architectures were defined, then default all, noarch, and host architecture */
2696 + if (nv_pair_list_empty(&conf->arch_list)) {
2697 + nv_pair_list_append(&conf->arch_list, "all", "1");
2698 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2699 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2702 + /* Even if there is no conf file, we'll need at least one dest. */
2703 + if (tmp_dest_nv_pair_list.head == NULL) {
2704 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2705 + IPKG_CONF_DEFAULT_DEST_NAME,
2706 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2709 + /* After parsing the file, set options from command-line, (so that
2710 + command-line arguments take precedence) */
2711 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2712 + really needs to be cleaned up. There is so much duplication
2713 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2714 + a pointer to args_t (which could then not be freed), rather
2715 + than duplicating every field here? */
2716 + if (args->force_depends) {
2717 + conf->force_depends = 1;
2719 + if (args->force_defaults) {
2720 + conf->force_defaults = 1;
2722 + if (args->force_overwrite) {
2723 + conf->force_overwrite = 1;
2725 + if (args->force_downgrade) {
2726 + conf->force_downgrade = 1;
2728 + if (args->force_reinstall) {
2729 + conf->force_reinstall = 1;
2731 + if (args->force_removal_of_dependent_packages) {
2732 + conf->force_removal_of_dependent_packages = 1;
2734 + if (args->force_removal_of_essential_packages) {
2735 + conf->force_removal_of_essential_packages = 1;
2737 + if (args->nodeps) {
2740 + if (args->noaction) {
2741 + conf->noaction = 1;
2743 + if (args->query_all) {
2744 + conf->query_all = 1;
2746 + if (args->verbose_wget) {
2747 + conf->verbose_wget = 1;
2749 + if (args->multiple_providers) {
2750 + conf->multiple_providers = 1;
2752 + if (args->verbosity != conf->verbosity) {
2753 + conf->verbosity = args->verbosity;
2756 + ipkg_conf_override_string(&conf->offline_root,
2757 + args->offline_root);
2758 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2759 + args->offline_root_pre_script_cmd);
2760 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2761 + args->offline_root_post_script_cmd);
2763 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2764 + read anything from there.
2766 + if ( !(args->nocheckfordirorfile)){
2767 + /* need to run load the source list before dest list -Jamey */
2768 + if ( !(args->noreadfeedsfile))
2769 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2771 + /* Now that we have resolved conf->offline_root, we can commit to
2772 + the directory names for the dests and load in all the package
2774 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2777 + err = ipkg_conf_set_default_dest(conf, args->dest);
2783 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2785 + free(pending_dir);
2790 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2792 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2794 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2795 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2796 + __FUNCTION__, conf->tmp_dir);
2800 + err = rmdir(conf->tmp_dir);
2802 + if (errno == ENOTEMPTY) {
2804 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2805 + err = xsystem(cmd);
2809 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2811 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2813 + free(conf->tmp_dir); /*XXX*/
2815 + pkg_src_list_deinit(&conf->pkg_src_list);
2816 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2817 + nv_pair_list_deinit(&conf->arch_list);
2818 + if (&conf->pkg_hash)
2819 + pkg_hash_deinit(&conf->pkg_hash);
2820 + if (&conf->file_hash)
2821 + hash_table_deinit(&conf->file_hash);
2822 + if (&conf->obs_file_hash)
2823 + hash_table_deinit(&conf->obs_file_hash);
2825 + ipkg_conf_free_string(&conf->offline_root);
2826 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2827 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2829 + if (conf->verbosity > 1) {
2831 + hash_table_t *hashes[] = {
2834 + &conf->obs_file_hash };
2835 + for (i = 0; i < 3; i++) {
2836 + hash_table_t *hash = hashes[i];
2838 + int n_conflicts = 0;
2840 + for (j = 0; j < hash->n_entries; j++) {
2842 + hash_entry_t *e = &hash->entries[j];
2845 + while (e && e->key) {
2852 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2853 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2854 + hash_table_deinit(hash);
2859 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2860 + const char *default_dest_name)
2862 + pkg_dest_list_elt_t *iter;
2865 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2866 + dest = iter->data;
2867 + if (strcmp(dest->name, default_dest_name) == 0) {
2868 + conf->default_dest = dest;
2869 + conf->restrict_to_default_dest = 1;
2874 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2879 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2881 + pkg_src_list_elt_t *iter;
2885 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2887 + if (src == NULL) {
2891 + sprintf_alloc(&list_file, "%s/%s",
2892 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2895 + if (file_exists(list_file)) {
2896 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2904 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2906 + nv_pair_list_elt_t *iter;
2907 + nv_pair_t *nv_pair;
2911 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2912 + nv_pair = iter->data;
2914 + if (conf->offline_root) {
2915 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2917 + root_dir = strdup(nv_pair->value);
2919 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2921 + if (dest == NULL) {
2924 + if (conf->default_dest == NULL) {
2925 + conf->default_dest = dest;
2927 + if (file_exists(dest->status_file_name)) {
2928 + pkg_hash_add_from_file(conf, dest->status_file_name,
2936 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2937 + pkg_src_list_t *pkg_src_list,
2938 + nv_pair_list_t *tmp_dest_nv_pair_list,
2941 + ipkg_option_t * options;
2942 + FILE *file = fopen(filename, "r");
2943 + regex_t valid_line_re, comment_re;
2944 +#define regmatch_size 12
2945 + regmatch_t regmatch[regmatch_size];
2947 + if (ipkg_init_options_array(conf, &options)<0)
2950 + if (file == NULL) {
2951 + fprintf(stderr, "%s: failed to open %s: %s\n",
2952 + __FUNCTION__, filename, strerror(errno));
2956 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2958 + xregcomp(&comment_re,
2959 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2961 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2966 + char *type, *name, *value, *extra;
2968 + line = file_read_line_alloc(file);
2970 + if (line == NULL) {
2976 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2980 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2982 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2983 + filename, line_num, line);
2987 + /* This has to be so ugly to deal with optional quotation marks */
2988 + if (regmatch[2].rm_so > 0) {
2989 + type = strndup(line + regmatch[2].rm_so,
2990 + regmatch[2].rm_eo - regmatch[2].rm_so);
2992 + type = strndup(line + regmatch[3].rm_so,
2993 + regmatch[3].rm_eo - regmatch[3].rm_so);
2995 + if (regmatch[5].rm_so > 0) {
2996 + name = strndup(line + regmatch[5].rm_so,
2997 + regmatch[5].rm_eo - regmatch[5].rm_so);
2999 + name = strndup(line + regmatch[6].rm_so,
3000 + regmatch[6].rm_eo - regmatch[6].rm_so);
3002 + if (regmatch[8].rm_so > 0) {
3003 + value = strndup(line + regmatch[8].rm_so,
3004 + regmatch[8].rm_eo - regmatch[8].rm_so);
3006 + value = strndup(line + regmatch[9].rm_so,
3007 + regmatch[9].rm_eo - regmatch[9].rm_so);
3010 + if (regmatch[11].rm_so > 0) {
3011 + extra = strndup (line + regmatch[11].rm_so,
3012 + regmatch[11].rm_eo - regmatch[11].rm_so);
3015 + /* We use the tmp_dest_nv_pair_list below instead of
3016 + conf->pkg_dest_list because we might encounter an
3017 + offline_root option later and that would invalidate the
3018 + directories we would have computed in
3019 + pkg_dest_list_init. (We do a similar thing with
3020 + tmp_src_nv_pair_list for sake of symmetry.) */
3021 + if (strcmp(type, "option") == 0) {
3022 + ipkg_conf_set_option(options, name, value);
3023 + } else if (strcmp(type, "src") == 0) {
3024 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3025 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3027 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3030 + } else if (strcmp(type, "src/gz") == 0) {
3031 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3032 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3034 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3037 + } else if (strcmp(type, "dest") == 0) {
3038 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3039 + } else if (strcmp(type, "lists_dir") == 0) {
3040 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3041 + if (*lists_dir == NULL) {
3042 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3046 + sprintf (*lists_dir,"%s",value);
3047 + } else if (strcmp(type, "arch") == 0) {
3048 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3050 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3051 + value = strdup("10");
3053 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3055 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3056 + "parameter: %s %s %s\n", type, name, value);
3072 + regfree(&comment_re);
3073 + regfree(&valid_line_re);
3079 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3080 + const char *name, const char *value)
3083 + while (options[i].name) {
3084 + if (strcmp(options[i].name, name) == 0) {
3085 + switch (options[i].type) {
3086 + case IPKG_OPT_TYPE_BOOL:
3087 + *((int *)options[i].value) = 1;
3089 + case IPKG_OPT_TYPE_INT:
3091 + *((int *)options[i].value) = atoi(value);
3094 + printf("%s: Option %s need an argument\n",
3095 + __FUNCTION__, name);
3098 + case IPKG_OPT_TYPE_STRING:
3100 + *((char **)options[i].value) = strdup(value);
3103 + printf("%s: Option %s need an argument\n",
3104 + __FUNCTION__, name);
3112 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3113 + __FUNCTION__, name, value);
3117 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3119 + pkg_dest_list_elt_t *iter;
3126 + if (conf->noaction)
3128 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3129 + dest = iter->data;
3130 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3131 + if (dest->status_file == NULL) {
3132 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3133 + __FUNCTION__, dest->status_file_name, strerror(errno));
3137 + all = pkg_vec_alloc();
3138 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3140 + for(i = 0; i < all->len; i++) {
3141 + pkg = all->pkgs[i];
3142 + /* We don't need most uninstalled packages in the status file */
3143 + if (pkg->state_status == SS_NOT_INSTALLED
3144 + && (pkg->state_want == SW_UNKNOWN
3145 + || pkg->state_want == SW_DEINSTALL
3146 + || pkg->state_want == SW_PURGE)) {
3150 + fprintf(stderr, "Null package\n");
3152 + if (pkg->dest == NULL) {
3153 + fprintf(stderr, "%s: ERROR: Can't write status for "
3154 + "package %s since it has a NULL dest\n",
3155 + __FUNCTION__, pkg->name);
3158 + if (pkg->dest->status_file) {
3159 + pkg_print_status(pkg, pkg->dest->status_file);
3163 + pkg_vec_free(all);
3165 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3166 + dest = iter->data;
3167 + if (dest->status_file) {
3168 + err = ferror(dest->status_file);
3169 + fclose(dest->status_file);
3170 + dest->status_file = NULL;
3172 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3174 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3175 + "retaining old %s\n", __FUNCTION__,
3176 + dest->status_file_tmp_name, dest->status_file_name);
3185 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3187 + char *root_filename;
3188 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3189 + return root_filename;
3191 Index: busybox-1.4.2/archival/libipkg/ipkg_conf.h
3192 ===================================================================
3193 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3194 +++ busybox-1.4.2/archival/libipkg/ipkg_conf.h 2007-06-04 13:21:36.711395688 +0200
3196 +/* ipkg_conf.h - the itsy package management system
3200 + Copyright (C) 2001 University of Southern California
3202 + This program is free software; you can redistribute it and/or
3203 + modify it under the terms of the GNU General Public License as
3204 + published by the Free Software Foundation; either version 2, or (at
3205 + your option) any later version.
3207 + This program is distributed in the hope that it will be useful, but
3208 + WITHOUT ANY WARRANTY; without even the implied warranty of
3209 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3210 + General Public License for more details.
3213 +#ifndef IPKG_CONF_H
3214 +#define IPKG_CONF_H
3216 +typedef struct ipkg_conf ipkg_conf_t;
3218 +#include "hash_table.h"
3222 +#include "pkg_hash.h"
3223 +#include "pkg_src_list.h"
3224 +#include "pkg_dest_list.h"
3225 +#include "nv_pair_list.h"
3227 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3228 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3229 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3230 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3232 +/* In case the config file defines no dest */
3233 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3234 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3236 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3240 + pkg_src_list_t pkg_src_list;
3241 + pkg_dest_list_t pkg_dest_list;
3242 + nv_pair_list_t arch_list;
3244 + int restrict_to_default_dest;
3245 + pkg_dest_t *default_dest;
3248 + const char *lists_dir;
3249 + const char *pending_dir;
3252 + int force_depends;
3253 + int force_defaults;
3254 + int force_overwrite;
3255 + int force_downgrade;
3256 + int force_reinstall;
3258 + int force_removal_of_dependent_packages;
3259 + int force_removal_of_essential_packages;
3260 + int nodeps; /* do not follow dependences */
3262 + int multiple_providers;
3263 + char *offline_root;
3264 + char *offline_root_pre_script_cmd;
3265 + char *offline_root_post_script_cmd;
3270 + /* proxy options */
3275 + char *proxy_passwd;
3277 + hash_table_t pkg_hash;
3278 + hash_table_t file_hash;
3279 + hash_table_t obs_file_hash;
3282 +enum ipkg_option_type {
3283 + IPKG_OPT_TYPE_BOOL,
3284 + IPKG_OPT_TYPE_INT,
3285 + IPKG_OPT_TYPE_STRING
3287 +typedef enum ipkg_option_type ipkg_option_type_t;
3289 +typedef struct ipkg_option ipkg_option_t;
3290 +struct ipkg_option {
3292 + const ipkg_option_type_t type;
3293 + const void *value;
3296 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3297 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3299 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3300 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3303 Index: busybox-1.4.2/archival/libipkg/ipkg_configure.c
3304 ===================================================================
3305 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3306 +++ busybox-1.4.2/archival/libipkg/ipkg_configure.c 2007-06-04 13:21:36.712395536 +0200
3308 +/* ipkg_configure.c - the itsy package management system
3312 + Copyright (C) 2001 University of Southern California
3314 + This program is free software; you can redistribute it and/or
3315 + modify it under the terms of the GNU General Public License as
3316 + published by the Free Software Foundation; either version 2, or (at
3317 + your option) any later version.
3319 + This program is distributed in the hope that it will be useful, but
3320 + WITHOUT ANY WARRANTY; without even the implied warranty of
3321 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3322 + General Public License for more details.
3327 +#include "ipkg_configure.h"
3329 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3333 + /* DPKG_INCOMPATIBILITY:
3334 + dpkg actually does some conffile handling here, rather than at the
3335 + end of ipkg_install(). Do we care? */
3336 + /* DPKG_INCOMPATIBILITY:
3337 + dpkg actually includes a version number to this script call */
3338 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3340 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3344 + ipkg_state_changed++;
3348 Index: busybox-1.4.2/archival/libipkg/ipkg_configure.h
3349 ===================================================================
3350 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3351 +++ busybox-1.4.2/archival/libipkg/ipkg_configure.h 2007-06-04 13:21:36.712395536 +0200
3353 +/* ipkg_configure.h - the itsy package management system
3357 + Copyright (C) 2001 University of Southern California
3359 + This program is free software; you can redistribute it and/or
3360 + modify it under the terms of the GNU General Public License as
3361 + published by the Free Software Foundation; either version 2, or (at
3362 + your option) any later version.
3364 + This program is distributed in the hope that it will be useful, but
3365 + WITHOUT ANY WARRANTY; without even the implied warranty of
3366 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3367 + General Public License for more details.
3370 +#ifndef IPKG_CONFIGURE_H
3371 +#define IPKG_CONFIGURE_H
3373 +#include "ipkg_conf.h"
3375 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3378 Index: busybox-1.4.2/archival/libipkg/ipkg_download.c
3379 ===================================================================
3380 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3381 +++ busybox-1.4.2/archival/libipkg/ipkg_download.c 2007-06-04 13:21:36.712395536 +0200
3383 +/* ipkg_download.c - the itsy package management system
3387 + Copyright (C) 2001 University of Southern California
3389 + This program is free software; you can redistribute it and/or
3390 + modify it under the terms of the GNU General Public License as
3391 + published by the Free Software Foundation; either version 2, or (at
3392 + your option) any later version.
3394 + This program is distributed in the hope that it will be useful, but
3395 + WITHOUT ANY WARRANTY; without even the implied warranty of
3396 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3397 + General Public License for more details.
3401 +#include "ipkg_download.h"
3402 +#include "ipkg_message.h"
3404 +#include "sprintf_alloc.h"
3405 +#include "xsystem.h"
3406 +#include "file_util.h"
3407 +#include "str_util.h"
3409 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3413 + char *src_basec = strdup(src);
3414 + char *src_base = basename(src_basec);
3415 + char *tmp_file_location;
3418 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3422 + if (str_starts_with(src, "file:")) {
3424 + const char *file_src = src + 5;
3425 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3426 + ret = file_copy(src + 5, dest_file_name);
3427 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3431 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3432 + err = unlink(tmp_file_location);
3433 + if (err && errno != ENOENT) {
3434 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3435 + __FUNCTION__, tmp_file_location, strerror(errno));
3436 + free(tmp_file_location);
3440 + if (conf->http_proxy) {
3441 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3442 + setenv("http_proxy", conf->http_proxy, 1);
3444 + if (conf->ftp_proxy) {
3445 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3446 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3448 + if (conf->no_proxy) {
3449 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3450 + setenv("no_proxy", conf->no_proxy, 1);
3453 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3454 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3455 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3456 + conf->proxy_user ? "--proxy-user=" : "",
3457 + conf->proxy_user ? conf->proxy_user : "",
3458 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3459 + conf->proxy_passwd ? conf->proxy_passwd : "",
3460 + conf->verbose_wget ? "" : "-q",
3463 + err = xsystem(cmd);
3466 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3467 + __FUNCTION__, err, cmd);
3469 + unlink(tmp_file_location);
3470 + free(tmp_file_location);
3477 + err = file_move(tmp_file_location, dest_file_name);
3479 + free(tmp_file_location);
3489 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3494 + if (pkg->src == NULL) {
3495 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3496 + pkg->name, pkg->parent->name);
3500 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3502 + /* XXX: BUG: The pkg->filename might be something like
3503 + "../../foo.ipk". While this is correct, and exactly what we
3504 + want to use to construct url above, here we actually need to
3505 + use just the filename part, without any directory. */
3506 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3508 + err = ipkg_download(conf, url, pkg->local_filename);
3515 + * Downloads file from url, installs in package database, return package name.
3517 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3525 + if (str_starts_with(url, "http://")
3526 + || str_starts_with(url, "ftp://")) {
3528 + char *file_basec = strdup(url);
3529 + char *file_base = basename(file_basec);
3531 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3532 + err = ipkg_download(conf, url, tmp_file);
3536 + err = pkg_init_from_file(pkg, tmp_file);
3539 + pkg->local_filename = strdup(tmp_file);
3544 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3545 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3547 + err = pkg_init_from_file(pkg, url);
3550 + pkg->local_filename = strdup(url);
3551 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3552 + pkg->provided_by_hand = 1;
3560 + if (!pkg->architecture) {
3561 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3565 + pkg->dest = conf->default_dest;
3566 + pkg->state_want = SW_INSTALL;
3567 + pkg->state_flag |= SF_PREFER;
3568 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3569 + if ( pkg == NULL ){
3570 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3574 + *namep = strdup(pkg->name);
3578 Index: busybox-1.4.2/archival/libipkg/ipkg_download.h
3579 ===================================================================
3580 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3581 +++ busybox-1.4.2/archival/libipkg/ipkg_download.h 2007-06-04 13:21:36.712395536 +0200
3583 +/* ipkg_download.h - the itsy package management system
3587 + Copyright (C) 2001 University of Southern California
3589 + This program is free software; you can redistribute it and/or
3590 + modify it under the terms of the GNU General Public License as
3591 + published by the Free Software Foundation; either version 2, or (at
3592 + your option) any later version.
3594 + This program is distributed in the hope that it will be useful, but
3595 + WITHOUT ANY WARRANTY; without even the implied warranty of
3596 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3597 + General Public License for more details.
3600 +#ifndef IPKG_DOWNLOAD_H
3601 +#define IPKG_DOWNLOAD_H
3603 +#include "ipkg_conf.h"
3605 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3606 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3608 + * Downloads file from url, installs in package database, return package name.
3610 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3613 Index: busybox-1.4.2/archival/libipkg/ipkg.h
3614 ===================================================================
3615 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3616 +++ busybox-1.4.2/archival/libipkg/ipkg.h 2007-06-04 13:21:36.712395536 +0200
3618 +/* ipkg.h - the itsy package management system
3622 + Copyright (C) 2001 University of Southern California
3624 + This program is free software; you can redistribute it and/or
3625 + modify it under the terms of the GNU General Public License as
3626 + published by the Free Software Foundation; either version 2, or (at
3627 + your option) any later version.
3629 + This program is distributed in the hope that it will be useful, but
3630 + WITHOUT ANY WARRANTY; without even the implied warranty of
3631 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3632 + General Public License for more details.
3639 +#ifdef HAVE_CONFIG_H
3640 +#include "config.h"
3645 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3648 +#include "ipkg_includes.h"
3649 +#include "ipkg_conf.h"
3650 +#include "ipkg_message.h"
3652 +#define IPKG_PKG_EXTENSION ".ipk"
3653 +#define DPKG_PKG_EXTENSION ".deb"
3655 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3656 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3658 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3659 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3660 +#define IPKG_INFO_DIR_SUFFIX "info"
3661 +#define IPKG_STATUS_FILE_SUFFIX "status"
3663 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3665 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3667 +#define IPKG_VERSION "0.99.162"
3672 + IPKG_PKG_DEPS_UNSATISFIED,
3673 + IPKG_PKG_IS_ESSENTIAL,
3674 + IPKG_PKG_HAS_DEPENDENTS,
3675 + IPKG_PKG_HAS_NO_CANDIDATE
3677 +typedef enum ipkg_error ipkg_error_t;
3679 +extern int ipkg_state_changed;
3684 + struct errlist * next;
3687 +extern struct errlist* error_list;
3689 +extern ipkg_conf_t *global_conf;
3692 Index: busybox-1.4.2/archival/libipkg/ipkg_includes.h
3693 ===================================================================
3694 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3695 +++ busybox-1.4.2/archival/libipkg/ipkg_includes.h 2007-06-04 13:21:36.713395384 +0200
3697 +#ifndef IPKG_INCLUDES_H
3698 +#define IPKG_INCLUDES_H
3700 +/* Define to 1 if you have the <memory.h> header file. */
3701 +#define HAVE_MEMORY_H 1
3703 +/* Define to 1 if you have the <regex.h> header file. */
3704 +#define HAVE_REGEX_H 1
3706 +/* Define to 1 if you have the <stdlib.h> header file. */
3707 +#define HAVE_STDLIB_H 1
3709 +/* Define to 1 if you have the <strings.h> header file. */
3710 +#define HAVE_STRINGS_H 1
3712 +/* Define to 1 if you have the <string.h> header file. */
3713 +#define HAVE_STRING_H 1
3715 +/* Define to 1 if you have the <sys/stat.h> header file. */
3716 +#define HAVE_SYS_STAT_H 1
3718 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3719 +#define HAVE_SYS_WAIT_H 1
3721 +/* Define to 1 if you have the <unistd.h> header file. */
3722 +#define HAVE_UNISTD_H 1
3724 +/* Define to 1 if you have the ANSI C header files. */
3725 +#define STDC_HEADERS 1
3731 +# include <stdlib.h>
3732 +# include <stdarg.h>
3733 +# include <stddef.h>
3734 +# include <ctype.h>
3735 +# include <errno.h>
3738 +# include <stdlib.h>
3743 +# include <regex.h>
3747 +# if !STDC_HEADERS && HAVE_MEMORY_H
3748 +# include <memory.h>
3750 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3752 +# define __USE_GNU 1
3754 +# include <string.h>
3759 +# include <strings.h>
3762 +#if HAVE_SYS_STAT_H
3763 +# include <sys/stat.h>
3766 +#if HAVE_SYS_WAIT_H
3767 +# include <sys/wait.h>
3771 +# include <sys/types.h>
3772 +# include <unistd.h>
3775 +#endif /* IPKG_INCLUDES_H */
3776 Index: busybox-1.4.2/archival/libipkg/ipkg_install.c
3777 ===================================================================
3778 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3779 +++ busybox-1.4.2/archival/libipkg/ipkg_install.c 2007-06-04 13:21:36.714395232 +0200
3781 +/* ipkg_install.c - the itsy package management system
3785 + Copyright (C) 2001 University of Southern California
3787 + This program is free software; you can redistribute it and/or
3788 + modify it under the terms of the GNU General Public License as
3789 + published by the Free Software Foundation; either version 2, or (at
3790 + your option) any later version.
3792 + This program is distributed in the hope that it will be useful, but
3793 + WITHOUT ANY WARRANTY; without even the implied warranty of
3794 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3795 + General Public License for more details.
3800 +#include <dirent.h>
3803 +#include <signal.h>
3804 +typedef void (*sighandler_t)(int);
3807 +#include "pkg_hash.h"
3808 +#include "pkg_extract.h"
3810 +#include "ipkg_install.h"
3811 +#include "ipkg_configure.h"
3812 +#include "ipkg_download.h"
3813 +#include "ipkg_remove.h"
3815 +#include "ipkg_utils.h"
3816 +#include "ipkg_message.h"
3818 +#include "sprintf_alloc.h"
3819 +#include "file_util.h"
3820 +#include "str_util.h"
3821 +#include "xsystem.h"
3824 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3825 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3826 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3828 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3829 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3830 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3831 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3832 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3833 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3834 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3842 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3843 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3845 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3846 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3848 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3850 +static int user_prefers_old_conffile(const char *file, const char *backup);
3852 +static char *backup_filename_alloc(const char *file_name);
3853 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3854 +static int backup_exists_for(const char *file_name);
3855 +static int backup_remove(const char *file_name);
3858 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3862 + char *old_version, *new_version;
3865 + if (pkg == NULL) {
3869 + err = pkg_init_from_file(pkg, filename);
3874 + if (!pkg->architecture) {
3875 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3879 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3880 + freeing the pkg that we pass in. It might be nice to clean this up
3882 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3883 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3885 + pkg->local_filename = strdup(filename);
3888 + old_version = pkg_version_str_alloc(old);
3889 + new_version = pkg_version_str_alloc(pkg);
3891 + cmp = pkg_compare_versions(old, pkg);
3892 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3893 + cmp = -1 ; /* then we force ipkg to downgrade */
3894 + /* We need to use a value < 0 because in the 0 case we are asking to */
3895 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3898 + ipkg_message(conf, IPKG_NOTICE,
3899 + "Not downgrading package %s on %s from %s to %s.\n",
3900 + old->name, old->dest->name, old_version, new_version);
3901 + pkg->state_want = SW_DEINSTALL;
3902 + pkg->state_flag |= SF_OBSOLETE;
3903 + free(old_version);
3904 + free(new_version);
3907 + free(old_version);
3908 + free(new_version);
3912 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3913 + return ipkg_install_pkg(conf, pkg,0);
3916 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3920 + char *old_version, *new_version;
3922 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3923 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3925 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3927 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3928 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3930 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3932 +/* Pigi Basically here is broken the version stuff.
3933 + What's happening is that nothing provide the version to differents
3934 + functions, so the returned struct is always the latest.
3935 + That's why the install by name don't work.
3937 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3940 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3942 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3943 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3945 + if (new == NULL) {
3946 + return IPKG_PKG_HAS_NO_CANDIDATE;
3949 + new->state_flag |= SF_USER;
3951 + old_version = pkg_version_str_alloc(old);
3952 + new_version = pkg_version_str_alloc(new);
3954 + cmp = pkg_compare_versions(old, new);
3955 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3956 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3957 + cmp = -1 ; /* then we force ipkg to downgrade */
3958 + /* We need to use a value < 0 because in the 0 case we are asking to */
3959 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3961 + ipkg_message(conf, IPKG_DEBUG,
3962 + "Comparing visible versions of pkg %s:"
3963 + "\n\t%s is installed "
3964 + "\n\t%s is available "
3965 + "\n\t%d was comparison result\n",
3966 + pkg_name, old_version, new_version, cmp);
3967 + if (cmp == 0 && !conf->force_reinstall) {
3968 + ipkg_message(conf, IPKG_NOTICE,
3969 + "Package %s (%s) installed in %s is up to date.\n",
3970 + old->name, old_version, old->dest->name);
3971 + free(old_version);
3972 + free(new_version);
3974 + } else if (cmp > 0) {
3975 + ipkg_message(conf, IPKG_NOTICE,
3976 + "Not downgrading package %s on %s from %s to %s.\n",
3977 + old->name, old->dest->name, old_version, new_version);
3978 + free(old_version);
3979 + free(new_version);
3981 + } else if (cmp < 0) {
3982 + new->dest = old->dest;
3983 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3987 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3988 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3989 + return any kind of integer, (might be errno from a syscall,
3990 + etc.). This is a real mess and will need to be cleaned up if
3991 + anyone ever wants to make a nice libipkg. */
3993 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3994 + return ipkg_install_pkg(conf, new,0);
3997 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
3999 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4002 + abstract_pkg_t *ppkg ;
4004 + if (providers == NULL)
4005 + return IPKG_PKG_HAS_NO_CANDIDATE;
4007 + for (i = 0; i < providers->len; i++) {
4008 + ppkg = abstract_pkg_vec_get(providers, i);
4009 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4010 + err = ipkg_install_by_name(conf, ppkg->name);
4013 +/* XXX Maybe ppkg should be freed ? */
4019 + * Walk dependence graph starting with pkg, collect packages to be
4020 + * installed into pkgs_needed, in dependence order.
4022 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4025 + pkg_vec_t *depends = pkg_vec_alloc();
4026 + char **unresolved = NULL;
4029 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4034 + ipkg_message(conf, IPKG_ERROR,
4035 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4036 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4037 + while (*unresolved) {
4038 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4041 + ipkg_message(conf, IPKG_ERROR, "\n");
4042 + if (! conf->force_depends) {
4043 + ipkg_message(conf, IPKG_INFO,
4044 + "This could mean that your package list is out of date or that the packages\n"
4045 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4046 + "of this problem try again with the '-force-depends' option.\n");
4047 + pkg_vec_free(depends);
4048 + return IPKG_PKG_DEPS_UNSATISFIED;
4052 + if (ndepends <= 0) {
4053 + pkg_vec_free(depends);
4057 + for (i = 0; i < depends->len; i++) {
4058 + pkg_t *dep = depends->pkgs[i];
4059 + /* The package was uninstalled when we started, but another
4060 + dep earlier in this loop may have depended on it and pulled
4061 + it in, so check first. */
4062 + if ((dep->state_status != SS_INSTALLED)
4063 + && (dep->state_status != SS_UNPACKED)
4064 + && (dep->state_want != SW_INSTALL)) {
4066 + /* Mark packages as to-be-installed */
4067 + dep->state_want = SW_INSTALL;
4069 + /* Dependencies should be installed the same place as pkg */
4070 + if (dep->dest == NULL) {
4071 + dep->dest = pkg->dest;
4074 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4076 + pkg_vec_free(depends);
4082 + pkg_vec_insert(pkgs_needed, pkg);
4084 + pkg_vec_free(depends);
4089 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4093 + char *old_version, *new_version;
4095 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4097 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4098 + if (new == NULL) {
4099 + return IPKG_PKG_HAS_NO_CANDIDATE;
4102 + old_version = pkg_version_str_alloc(old);
4103 + new_version = pkg_version_str_alloc(new);
4105 + cmp = pkg_compare_versions(old, new);
4106 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4107 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4108 + cmp = -1 ; /* then we force ipkg to downgrade */
4109 + /* We need to use a value < 0 because in the 0 case we are asking to */
4110 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4112 + ipkg_message(conf, IPKG_DEBUG,
4113 + "comparing visible versions of pkg %s:"
4114 + "\n\t%s is installed "
4115 + "\n\t%s is available "
4116 + "\n\t%d was comparison result\n",
4117 + pkg_name, old_version, new_version, cmp);
4118 + if (cmp == 0 && !conf->force_reinstall) {
4119 + ipkg_message(conf, IPKG_NOTICE,
4120 + "Package %s (%s) installed in %s is up to date.\n",
4121 + old->name, old_version, old->dest->name);
4122 + free(old_version);
4123 + free(new_version);
4125 + } else if (cmp > 0) {
4126 + ipkg_message(conf, IPKG_NOTICE,
4127 + "Not downgrading package %s on %s from %s to %s.\n",
4128 + old->name, old->dest->name, old_version, new_version);
4129 + free(old_version);
4130 + free(new_version);
4132 + } else if (cmp < 0) {
4133 + new->dest = old->dest;
4134 + old->state_want = SW_DEINSTALL;
4135 + old->state_flag |= SF_OBSOLETE;
4138 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4143 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4146 + pkg_vec_t *depends = pkg_vec_alloc();
4148 + char **unresolved = NULL;
4151 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4156 + ipkg_message(conf, IPKG_ERROR,
4157 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4158 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4159 + while (*unresolved) {
4160 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4163 + ipkg_message(conf, IPKG_ERROR, "\n");
4164 + if (! conf->force_depends) {
4165 + ipkg_message(conf, IPKG_INFO,
4166 + "This could mean that your package list is out of date or that the packages\n"
4167 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4168 + "of this problem try again with the '-force-depends' option.\n");
4169 + pkg_vec_free(depends);
4170 + return IPKG_PKG_DEPS_UNSATISFIED;
4174 + if (ndepends <= 0) {
4178 + /* Mark packages as to-be-installed */
4179 + for (i=0; i < depends->len; i++) {
4180 + /* Dependencies should be installed the same place as pkg */
4181 + if (depends->pkgs[i]->dest == NULL) {
4182 + depends->pkgs[i]->dest = pkg->dest;
4184 + depends->pkgs[i]->state_want = SW_INSTALL;
4187 + for (i = 0; i < depends->len; i++) {
4188 + dep = depends->pkgs[i];
4189 + /* The package was uninstalled when we started, but another
4190 + dep earlier in this loop may have depended on it and pulled
4191 + it in, so check first. */
4192 + if ((dep->state_status != SS_INSTALLED)
4193 + && (dep->state_status != SS_UNPACKED)) {
4194 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4195 + err = ipkg_install_pkg(conf, dep,0);
4197 + pkg_vec_free(depends);
4203 + pkg_vec_free(depends);
4209 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4210 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4212 + if (conf->nodeps == 0) {
4214 + pkg_vec_t *installed = pkg_vec_alloc();
4215 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4216 + for (i = 0; i < installed->len; i++) {
4217 + pkg_t *pkg = installed->pkgs[i];
4218 + satisfy_dependencies_for(conf, pkg);
4220 + pkg_vec_free(installed);
4227 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4230 + pkg_vec_t *conflicts = NULL;
4232 + const char *prefix;
4233 + if (conf->force_depends) {
4234 + level = IPKG_NOTICE;
4235 + prefix = "Warning";
4237 + level = IPKG_ERROR;
4241 + if (!conf->force_depends)
4242 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4245 + ipkg_message(conf, level,
4246 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4248 + while (i < conflicts->len)
4249 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4250 + ipkg_message(conf, level, "\n");
4251 + pkg_vec_free(conflicts);
4252 + return IPKG_PKG_DEPS_UNSATISFIED;
4257 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4259 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4260 + str_list_elt_t *iter;
4262 + for (iter = new_list->head; iter; iter = iter->next) {
4263 + char *new_file = iter->data;
4264 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4266 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4267 + if (!owner || (owner == old_pkg))
4268 + file_hash_set_file_owner(conf, new_file, new_pkg);
4271 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4272 + for (iter = old_list->head; iter; iter = iter->next) {
4273 + char *old_file = iter->data;
4274 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4275 + if (owner == old_pkg) {
4277 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4284 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4286 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4288 + /* sma 6.20.02: yup; here's the first bit */
4290 + * XXX: BUG easy for cworth
4291 + * 1) please point the call below to the correct current root destination
4292 + * 2) we need to resolve how to check the required space for a pending pkg,
4293 + * my diddling with the .ipk file size below isn't going to cut it.
4294 + * 3) return a proper error code instead of 1
4296 + int comp_size, blocks_available;
4298 + if (!conf->force_space && pkg->installed_size != NULL) {
4299 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4301 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4302 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4303 + comp_size = (int)((comp_size + 1023) / 1024);
4305 + if (comp_size >= blocks_available) {
4306 + ipkg_message(conf, IPKG_ERROR,
4307 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4308 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4315 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4318 + char *conffiles_file_name;
4320 + FILE *conffiles_file;
4322 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4324 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4325 + if (pkg->tmp_unpack_dir == NULL) {
4326 + ipkg_message(conf, IPKG_ERROR,
4327 + "%s: Failed to create temporary directory '%s': %s\n",
4328 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4332 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4337 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4338 + conffiles. Seems like I should be able to get everything to go
4339 + through pkg_init_from_file. If so, maybe it would make sense to
4340 + move all of unpack_pkg_control_files to that function. */
4342 + /* Don't need to re-read conffiles if we already have it */
4343 + if (pkg->conffiles.head) {
4347 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4348 + if (! file_exists(conffiles_file_name)) {
4349 + free(conffiles_file_name);
4353 + conffiles_file = fopen(conffiles_file_name, "r");
4354 + if (conffiles_file == NULL) {
4355 + fprintf(stderr, "%s: failed to open %s: %s\n",
4356 + __FUNCTION__, conffiles_file_name, strerror(errno));
4357 + free(conffiles_file_name);
4360 + free(conffiles_file_name);
4364 + char *cf_name_in_dest;
4366 + cf_name = file_read_line_alloc(conffiles_file);
4367 + if (cf_name == NULL) {
4370 + str_chomp(cf_name);
4371 + if (cf_name[0] == '\0') {
4375 + /* Prepend dest->root_dir to conffile name.
4376 + Take pains to avoid multiple slashes. */
4377 + root_dir = pkg->dest->root_dir;
4378 + if (conf->offline_root)
4379 + /* skip the offline_root prefix */
4380 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4381 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4382 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4384 + /* Can't get an md5sum now, (file isn't extracted yet).
4385 + We'll wait until resolve_conffiles */
4386 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4389 + free(cf_name_in_dest);
4392 + fclose(conffiles_file);
4397 +/* returns number of installed replacees */
4398 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4400 + abstract_pkg_t **replaces = pkg->replaces;
4401 + int replaces_count = pkg->replaces_count;
4403 + for (i = 0; i < replaces_count; i++) {
4404 + abstract_pkg_t *ab_pkg = replaces[i];
4405 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4407 + for (j = 0; j < pkg_vec->len; j++) {
4408 + pkg_t *replacee = pkg_vec->pkgs[j];
4409 + if (!pkg_conflicts(pkg, replacee))
4411 + if (replacee->state_status == SS_INSTALLED) {
4412 + pkg_vec_insert(installed_replacees, replacee);
4417 + return installed_replacees->len;
4420 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4423 + int replaces_count = replacees->len;
4424 + for (i = 0; i < replaces_count; i++) {
4425 + pkg_t *replacee = replacees->pkgs[i];
4427 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4428 + err = ipkg_remove_pkg(conf, replacee,0);
4435 +/* to unwind the removal: make sure they are installed */
4436 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4439 + int replaces_count = replacees->len;
4440 + for (i = 0; i < replaces_count; i++) {
4441 + pkg_t *replacee = replacees->pkgs[i];
4442 + if (replacee->state_status != SS_INSTALLED) {
4443 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4444 + err = ipkg_install_pkg(conf, replacee,0);
4452 +int caught_sigint = 0;
4453 +static void ipkg_install_pkg_sigint_handler(int sig)
4455 + caught_sigint = sig;
4458 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4459 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4462 + char message_out[15];
4463 + char *old_version = pkg_version_str_alloc(old_pkg);
4464 + char *new_version = pkg_version_str_alloc(pkg);
4465 + int cmp = pkg_compare_versions(old_pkg, pkg);
4468 + memset(message_out,'\x0',15);
4469 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4470 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4471 + cmp = -1 ; /* then we force ipkg to downgrade */
4472 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4473 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4477 + ipkg_message(conf, IPKG_NOTICE,
4478 + "Not downgrading package %s on %s from %s to %s.\n",
4479 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4481 + } else if (cmp < 0) {
4482 + ipkg_message(conf, IPKG_NOTICE,
4483 + "%s%s on %s from %s to %s...\n",
4484 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4485 + pkg->dest = old_pkg->dest;
4487 + } else /* cmp == 0 */ {
4488 + if (conf->force_reinstall) {
4489 + ipkg_message(conf, IPKG_NOTICE,
4490 + "Reinstalling %s (%s) on %s...\n",
4491 + pkg->name, new_version, old_pkg->dest->name);
4492 + pkg->dest = old_pkg->dest;
4495 + ipkg_message(conf, IPKG_NOTICE,
4496 + "Not installing %s (%s) on %s -- already installed.\n",
4497 + pkg->name, new_version, old_pkg->dest->name);
4501 + free(old_version);
4502 + free(new_version);
4505 + char message_out[15], *version ;
4506 + memset(message_out,'\x0',15);
4508 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4510 + strncpy( message_out,"Installing ",strlen("Installing ") );
4511 + version = pkg_version_str_alloc(pkg);
4513 + ipkg_message(conf, IPKG_NOTICE,
4514 + "%s%s (%s) to %s...\n", message_out,
4515 + pkg->name, version, pkg->dest->name);
4521 +/* and now the meat... */
4522 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4526 + pkg_t *old_pkg = NULL;
4527 + pkg_vec_t *replacees;
4528 + abstract_pkg_t *ab_pkg = NULL;
4529 + int old_state_flag;
4533 + if ( from_upgrade )
4534 + message = 1; /* Coming from an upgrade, and should change the output message */
4537 + ipkg_message(conf, IPKG_ERROR,
4538 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4542 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4544 + if (!pkg_arch_supported(conf, pkg)) {
4545 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4546 + pkg->architecture, pkg->name);
4549 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4550 + err = satisfy_dependencies_for(conf, pkg);
4551 + if (err) { return err; }
4553 + ipkg_message(conf, IPKG_NOTICE,
4554 + "Package %s is already installed in %s.\n",
4555 + pkg->name, pkg->dest->name);
4559 + if (pkg->dest == NULL) {
4560 + pkg->dest = conf->default_dest;
4563 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4565 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4566 + if (err) { return err; }
4568 + pkg->state_want = SW_INSTALL;
4570 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4574 + /* Abhaya: conflicts check */
4575 + err = check_conflicts_for(conf, pkg);
4576 + if (err) { return err; }
4578 + /* this setup is to remove the upgrade scenario in the end when
4579 + installing pkg A, A deps B & B deps on A. So both B and A are
4580 + installed. Then A's installation is started resulting in an
4581 + uncecessary upgrade */
4582 + if (pkg->state_status == SS_INSTALLED
4583 + && conf->force_reinstall == 0) return 0;
4585 + err = verify_pkg_installable(conf, pkg);
4586 + if (err) { return err; }
4588 + if (pkg->local_filename == NULL) {
4589 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4591 + ipkg_message(conf, IPKG_ERROR,
4592 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4598 +/* Check for md5 values */
4601 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4602 + if (strcmp(file_md5, pkg->md5sum))
4604 + ipkg_message(conf, IPKG_ERROR,
4605 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4613 + if (pkg->tmp_unpack_dir == NULL) {
4614 + unpack_pkg_control_files(conf, pkg);
4617 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4618 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4619 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4620 + err = update_file_ownership(conf, pkg, old_pkg);
4621 + if (err) { return err; }
4623 + if (conf->nodeps == 0) {
4624 + err = satisfy_dependencies_for(conf, pkg);
4625 + if (err) { return err; }
4628 + replacees = pkg_vec_alloc();
4629 + pkg_get_installed_replacees(conf, pkg, replacees);
4631 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4633 + sigset_t newset, oldset;
4634 + sighandler_t old_handler = NULL;
4635 + int use_signal = 0;
4636 + caught_sigint = 0;
4638 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4640 + sigemptyset(&newset);
4641 + sigaddset(&newset, SIGINT);
4642 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4645 + ipkg_state_changed++;
4646 + pkg->state_flag |= SF_FILELIST_CHANGED;
4648 + /* XXX: BUG: we really should treat replacement more like an upgrade
4649 + * Instead, we're going to remove the replacees
4651 + err = pkg_remove_installed_replacees(conf, replacees);
4652 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4654 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4655 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4657 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4658 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4660 + err = preinst_configure(conf, pkg, old_pkg);
4661 + if (err) goto UNWIND_PREINST_CONFIGURE;
4663 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4664 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4666 + err = check_data_file_clashes(conf, pkg, old_pkg);
4667 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4669 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4670 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4672 + if (conf->noaction) return 0;
4674 + /* point of no return: no unwinding after this */
4675 + if (old_pkg && !conf->force_reinstall) {
4676 + old_pkg->state_want = SW_DEINSTALL;
4678 + if (old_pkg->state_flag & SF_NOPRUNE) {
4679 + ipkg_message(conf, IPKG_INFO,
4680 + " not removing obsolesced files because package marked noprune\n");
4682 + ipkg_message(conf, IPKG_INFO,
4683 + " removing obsolesced files\n");
4684 + remove_obsolesced_files(conf, pkg, old_pkg);
4686 + /* removing files from old package, to avoid ghost files */
4687 + remove_data_files_and_list(conf, old_pkg);
4688 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4689 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4690 + remove_postrm(conf, old_pkg);
4696 + ipkg_message(conf, IPKG_INFO,
4697 + " installing maintainer scripts\n");
4698 + install_maintainer_scripts(conf, pkg, old_pkg);
4700 + /* the following just returns 0 */
4701 + remove_disappeared(conf, pkg);
4703 + ipkg_message(conf, IPKG_INFO,
4704 + " installing data files\n");
4705 + install_data_files(conf, pkg);
4707 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4708 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4710 + ipkg_message(conf, IPKG_INFO,
4711 + " resolving conf files\n");
4712 + resolve_conffiles(conf, pkg);
4714 + pkg->state_status = SS_UNPACKED;
4715 + old_state_flag = pkg->state_flag;
4716 + pkg->state_flag &= ~SF_PREFER;
4717 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4719 + if (old_pkg && !conf->force_reinstall) {
4720 + old_pkg->state_status = SS_NOT_INSTALLED;
4723 + time(&pkg->installed_time);
4725 + ipkg_message(conf, IPKG_INFO,
4726 + " cleanup temp files\n");
4727 + cleanup_temporary_files(conf, pkg);
4729 + ab_pkg = pkg->parent;
4731 + ab_pkg->state_status = pkg->state_status;
4733 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4736 + signal(SIGINT, old_handler);
4738 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4743 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4744 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4745 + UNWIND_CHECK_DATA_FILE_CLASHES:
4746 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4747 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4748 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4749 + UNWIND_PREINST_CONFIGURE:
4750 + preinst_configure_unwind(conf, pkg, old_pkg);
4751 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4752 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4753 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4754 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4755 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4756 + pkg_remove_installed_replacees_unwind(conf, replacees);
4758 + ipkg_message(conf, IPKG_INFO,
4759 + " cleanup temp files\n");
4760 + cleanup_temporary_files(conf, pkg);
4762 + ipkg_message(conf, IPKG_INFO,
4765 + signal(SIGINT, old_handler);
4767 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4773 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4775 + /* DPKG_INCOMPATIBILITY:
4776 + dpkg does some things here that we don't do yet. Do we care?
4778 + 1. If a version of the package is already installed, call
4779 + old-prerm upgrade new-version
4780 + 2. If the script runs but exits with a non-zero exit status
4781 + new-prerm failed-upgrade old-version
4782 + Error unwind, for both the above cases:
4783 + old-postinst abort-upgrade new-version
4788 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4790 + /* DPKG_INCOMPATIBILITY:
4791 + dpkg does some things here that we don't do yet. Do we care?
4792 + (See prerm_upgrade_old_package for details)
4797 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4799 + /* DPKG_INCOMPATIBILITY:
4800 + dpkg does some things here that we don't do yet. Do we care?
4801 + 2. If a 'conflicting' package is being removed at the same time:
4802 + 1. If any packages depended on that conflicting package and
4803 + --auto-deconfigure is specified, call, for each such package:
4804 + deconfigured's-prerm deconfigure \
4805 + in-favour package-being-installed version \
4806 + removing conflicting-package version
4808 + deconfigured's-postinst abort-deconfigure \
4809 + in-favour package-being-installed-but-failed version \
4810 + removing conflicting-package version
4812 + The deconfigured packages are marked as requiring
4813 + configuration, so that if --install is used they will be
4814 + configured again if possible.
4815 + 2. To prepare for removal of the conflicting package, call:
4816 + conflictor's-prerm remove in-favour package new-version
4818 + conflictor's-postinst abort-remove in-favour package new-version
4823 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4825 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4826 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4831 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4834 + char *preinst_args;
4837 + char *old_version = pkg_version_str_alloc(old_pkg);
4838 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4839 + free(old_version);
4840 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4841 + char *pkg_version = pkg_version_str_alloc(pkg);
4842 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4843 + free(pkg_version);
4845 + preinst_args = strdup("install");
4848 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4850 + ipkg_message(conf, IPKG_ERROR,
4851 + "Aborting installation of %s\n", pkg->name);
4855 + free(preinst_args);
4860 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4862 + /* DPKG_INCOMPATIBILITY:
4863 + dpkg does the following error unwind, should we?
4864 + pkg->postrm abort-upgrade old-version
4865 + OR pkg->postrm abort-install old-version
4866 + OR pkg->postrm abort-install
4871 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4874 + conffile_list_elt_t *iter;
4877 + if (conf->noaction) return 0;
4879 + /* Backup all modified conffiles */
4881 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4885 + cf_name = root_filename_alloc(conf, cf->name);
4887 + /* Don't worry if the conffile is just plain gone */
4888 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4889 + err = backup_make_backup(conf, cf_name);
4898 + /* Backup all conffiles that were not conffiles in old_pkg */
4899 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4902 + cf_name = root_filename_alloc(conf, cf->name);
4903 + /* Ignore if this was a conffile in old_pkg as well */
4904 + if (pkg_get_conffile(old_pkg, cf->name)) {
4908 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4909 + err = backup_make_backup(conf, cf_name);
4920 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4922 + conffile_list_elt_t *iter;
4925 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4926 + backup_remove(iter->data->name);
4930 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4931 + backup_remove(iter->data->name);
4938 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4940 + /* DPKG_INCOMPATIBILITY:
4941 + ipkg takes a slightly different approach than dpkg at this
4942 + point. dpkg installs each file in the new package while
4943 + creating a backup for any file that is replaced, (so that it
4944 + can unwind if necessary). To avoid complexity and redundant
4945 + storage, ipkg doesn't do any installation until later, (at the
4946 + point at which dpkg removes the backups.
4948 + But, we do have to check for data file clashes, since after
4949 + installing a package with a file clash, removing either of the
4950 + packages involved in the clash has the potential to break the
4953 + str_list_t *files_list;
4954 + str_list_elt_t *iter;
4958 + files_list = pkg_get_installed_files(pkg);
4959 + for (iter = files_list->head; iter; iter = iter->next) {
4960 + char *root_filename;
4961 + char *filename = iter->data;
4962 + root_filename = root_filename_alloc(conf, filename);
4963 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4966 + /* Pre-existing conffiles are OK */
4967 + /* @@@@ should have way to check that it is a conffile -Jamey */
4968 + if (backup_exists_for(root_filename)) {
4972 + /* Pre-existing files are OK if force-overwrite was asserted. */
4973 + if (conf->force_overwrite) {
4974 + /* but we need to change who owns this file */
4975 + file_hash_set_file_owner(conf, filename, pkg);
4979 + owner = file_hash_get_file_owner(conf, filename);
4981 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4982 + if (owner && old_pkg) {
4983 + if (strcmp(owner->name, old_pkg->name) == 0) {
4988 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4990 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4991 + if (pkg_replaces(pkg, owner)) {
4994 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4995 + then it's ok to overwrite. */
4996 + if (strcmp(owner->name,pkg->name)==0){
4997 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5002 + /* Pre-existing files are OK if they are obsolete */
5003 + obs = hash_table_get(&conf->obs_file_hash, filename);
5005 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5009 + /* We have found a clash. */
5010 + ipkg_message(conf, IPKG_ERROR,
5011 + "Package %s wants to install file %s\n"
5012 + "\tBut that file is already provided by package ",
5013 + pkg->name, filename);
5015 + ipkg_message(conf, IPKG_ERROR,
5016 + "%s\n", owner->name);
5018 + ipkg_message(conf, IPKG_ERROR,
5019 + "<no package>\nPlease move this file out of the way and try again.\n");
5023 + free(root_filename);
5025 + pkg_free_installed_files(pkg);
5030 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5032 + /* Basically that's the worst hack I could do to be able to change ownership of
5033 + file list, but, being that we have no way to unwind the mods, due to structure
5034 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5035 + What we do here is change the ownership of file in hash if a replace ( or similar events
5037 + Only the action that are needed to change name should be considered.
5038 + @@@ To change after 1.0 release.
5040 + str_list_t *files_list;
5041 + str_list_elt_t *iter;
5045 + files_list = pkg_get_installed_files(pkg);
5046 + for (iter = files_list->head; iter; iter = iter->next) {
5047 + char *root_filename;
5048 + char *filename = iter->data;
5049 + root_filename = root_filename_alloc(conf, filename);
5050 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5053 + if (conf->force_overwrite) {
5054 + /* but we need to change who owns this file */
5055 + file_hash_set_file_owner(conf, filename, pkg);
5059 + owner = file_hash_get_file_owner(conf, filename);
5061 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5063 + if (pkg_replaces(pkg, owner)) {
5064 +/* It's now time to change the owner of that file.
5065 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5066 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5067 + file_hash_set_file_owner(conf, filename, pkg);
5073 + free(root_filename);
5075 + pkg_free_installed_files(pkg);
5080 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5082 + /* Nothing to do since check_data_file_clashes doesn't change state */
5086 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5088 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5089 + 1. If the package is being upgraded, call
5090 + old-postrm upgrade new-version
5091 + 2. If this fails, attempt:
5092 + new-postrm failed-upgrade old-version
5093 + Error unwind, for both cases:
5094 + old-preinst abort-upgrade new-version */
5098 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5100 + /* DPKG_INCOMPATIBILITY:
5101 + dpkg does some things here that we don't do yet. Do we care?
5102 + (See postrm_upgrade_old_pkg for details)
5107 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5110 + str_list_t *old_files;
5111 + str_list_elt_t *of;
5112 + str_list_t *new_files;
5113 + str_list_elt_t *nf;
5115 + if (old_pkg == NULL) {
5119 + old_files = pkg_get_installed_files(old_pkg);
5120 + new_files = pkg_get_installed_files(pkg);
5122 + for (of = old_files->head; of; of = of->next) {
5126 + for (nf = new_files->head; nf; nf = nf->next) {
5128 + if (strcmp(old, new) == 0) {
5129 + goto NOT_OBSOLETE;
5132 + if (file_is_dir(old)) {
5135 + owner = file_hash_get_file_owner(conf, old);
5136 + if (owner != old_pkg) {
5137 + /* in case obsolete file no longer belongs to old_pkg */
5141 + /* old file is obsolete */
5142 + ipkg_message(conf, IPKG_INFO,
5143 + " removing obsolete file %s\n", old);
5144 + if (!conf->noaction) {
5145 + err = unlink(old);
5147 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5156 + pkg_free_installed_files(old_pkg);
5157 + pkg_free_installed_files(pkg);
5162 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5166 + char *globpattern;
5170 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5173 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5174 + err = glob(globpattern, 0, NULL, &globbuf);
5175 + free(globpattern);
5179 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5180 + for (i = 0; i < globbuf.gl_pathc; i++) {
5181 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5182 + globbuf.gl_pathv[i], old_pkg->name);
5183 + if (!conf->noaction)
5184 + unlink(globbuf.gl_pathv[i]);
5186 + globfree(&globbuf);
5191 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5197 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5198 + sprintf_alloc(&prefix, "%s.", pkg->name);
5199 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5200 + pkg->dest->info_dir,
5206 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5208 + /* DPKG_INCOMPATIBILITY:
5209 + This is a fairly sophisticated dpkg operation. Shall we
5212 + /* Any packages all of whose files have been overwritten during the
5213 + installation, and which aren't required for dependencies, are
5214 + considered to have been removed. For each such package
5215 + 1. disappearer's-postrm disappear overwriter overwriter-version
5216 + 2. The package's maintainer scripts are removed
5217 + 3. It is noted in the status database as being in a sane state,
5218 + namely not installed (any conffiles it may have are ignored,
5219 + rather than being removed by dpkg). Note that disappearing
5220 + packages do not have their prerm called, because dpkg doesn't
5221 + know in advance that the package is going to vanish.
5226 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5230 + /* ipkg takes a slightly different approach to data file backups
5231 + than dpkg. Rather than removing backups at this point, we
5232 + actually do the data file installation now. See comments in
5233 + check_data_file_clashes() for more details. */
5235 + ipkg_message(conf, IPKG_INFO,
5236 + " extracting data files to %s\n", pkg->dest->root_dir);
5237 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5242 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5243 + so we can't save ourself from removing important packages
5244 + At this point we (should) have extracted the .control file, so it
5245 + would be a good idea to reload the data in it, and set the Essential
5246 + state in *pkg. From now on the Essential is back in status file and
5247 + we can protect again.
5248 + We should operate this way:
5249 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5250 + check for "Essential" in it
5251 + set the value in pkg->essential.
5252 + This new routine could be useful also for every other flag
5253 + Pigi: 16/03/2004 */
5254 + set_flags_from_control(conf, pkg) ;
5256 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5257 + err = pkg_write_filelist(conf, pkg);
5261 + /* XXX: FEATURE: ipkg should identify any files which existed
5262 + before installation and which were overwritten, (see
5263 + check_data_file_clashes()). What it must do is remove any such
5264 + files from the filelist of the old package which provided the
5265 + file. Otherwise, if the old package were removed at some point
5266 + it would break the new package. Removing the new package will
5267 + also break the old one, but this cannot be helped since the old
5268 + package's file has already been deleted. This is the importance
5269 + of check_data_file_clashes(), and only allowing ipkg to install
5270 + a clashing package with a user force. */
5275 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5277 + conffile_list_elt_t *iter;
5284 + if (conf->noaction) return 0;
5286 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5287 + char *root_filename;
5289 + root_filename = root_filename_alloc(conf, cf->name);
5291 + /* Might need to initialize the md5sum for each conffile */
5292 + if (cf->value == NULL) {
5293 + cf->value = file_md5sum_alloc(root_filename);
5296 + if (!file_exists(root_filename)) {
5297 + free(root_filename);
5301 + cf_backup = backup_filename_alloc(root_filename);
5304 + if (file_exists(cf_backup)) {
5305 + /* Let's compute md5 to test if files are changed */
5306 + md5sum = file_md5sum_alloc(cf_backup);
5307 + if (strcmp( cf->value,md5sum) != 0 ) {
5308 + if (conf->force_defaults
5309 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5310 + rename(cf_backup, root_filename);
5313 + unlink(cf_backup);
5318 + free(root_filename);
5324 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5327 + const char *short_file_name;
5329 + short_file_name = strrchr(file_name, '/');
5330 + if (short_file_name) {
5331 + short_file_name++;
5333 + short_file_name = file_name;
5337 + response = get_user_response(" Configuration file '%s'\n"
5338 + " ==> File on system created by you or by a script.\n"
5339 + " ==> File also in package provided by package maintainer.\n"
5340 + " What would you like to do about it ? Your options are:\n"
5341 + " Y or I : install the package maintainer's version\n"
5342 + " N or O : keep your currently-installed version\n"
5343 + " D : show the differences between the versions (if diff is installed)\n"
5344 + " The default action is to keep your current version.\n"
5345 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5346 + if (strcmp(response, "y") == 0
5347 + || strcmp(response, "i") == 0
5348 + || strcmp(response, "yes") == 0) {
5353 + if (strcmp(response, "d") == 0) {
5357 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5358 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5361 + printf(" [Press ENTER to continue]\n");
5362 + response = file_read_line_alloc(stdin);
5372 +/* XXX: CLEANUP: I'd like to move all of the code for
5373 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5374 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5375 + pkg_deinit for example). */
5376 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5379 + struct dirent *dirent;
5382 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5384 + ipkg_message(conf, IPKG_DEBUG,
5385 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5386 + __FUNCTION__, pkg->tmp_unpack_dir);
5390 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5391 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5394 + dirent = readdir(tmp_dir);
5395 + if (dirent == NULL) {
5398 + sprintf_alloc(&tmp_file, "%s/%s",
5399 + pkg->tmp_unpack_dir, dirent->d_name);
5400 + if (! file_is_dir(tmp_file)) {
5405 + closedir(tmp_dir);
5406 + rmdir(pkg->tmp_unpack_dir);
5407 + free(pkg->tmp_unpack_dir);
5408 + pkg->tmp_unpack_dir = NULL;
5412 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5413 + pkg->name, pkg->local_filename, conf->tmp_dir);
5414 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5415 + unlink(pkg->local_filename);
5416 + free(pkg->local_filename);
5417 + pkg->local_filename = NULL;
5423 +static char *backup_filename_alloc(const char *file_name)
5427 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5432 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5437 + backup = backup_filename_alloc(file_name);
5438 + err = file_copy(file_name, backup);
5440 + ipkg_message(conf, IPKG_ERROR,
5441 + "%s: Failed to copy %s to %s\n",
5442 + __FUNCTION__, file_name, backup);
5450 +static int backup_exists_for(const char *file_name)
5455 + backup = backup_filename_alloc(file_name);
5457 + ret = file_exists(backup);
5464 +static int backup_remove(const char *file_name)
5468 + backup = backup_filename_alloc(file_name);
5477 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5479 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5481 + /* first, remove the packages that need removing */
5482 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5483 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5484 + err = ipkg_remove_pkg(conf, pkg,0);
5485 + if (err) return err;
5490 +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5493 + /* now one more pass checking on the ones that need to be installed */
5494 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5495 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5496 + if (pkg->dest == NULL)
5497 + pkg->dest = conf->default_dest;
5499 + pkg->state_want = SW_INSTALL;
5501 + /* Abhaya: conflicts check */
5502 + err = check_conflicts_for(conf, pkg);
5503 + if (err) { return err; }
5508 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5511 + /* now one more pass checking on the ones that need to be installed */
5512 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5513 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5515 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5516 + pkg_vec_t *replacees = pkg_vec_alloc();
5517 + pkg_get_installed_replacees(conf, pkg, replacees);
5519 + /* XXX: BUG: we really should treat replacement more like an upgrade
5520 + * Instead, we're going to remove the replacees
5522 + err = pkg_remove_installed_replacees(conf, replacees);
5523 + if (err) return err;
5524 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5529 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5532 + /* now one more pass checking on the ones that need to be installed */
5533 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5534 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5535 + if (pkg->local_filename == NULL) {
5536 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5538 + ipkg_message(conf, IPKG_ERROR,
5539 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5544 + if (pkg->tmp_unpack_dir == NULL) {
5545 + err = unpack_pkg_control_files(conf, pkg);
5546 + if (err) return err;
5552 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5555 + /* now one more pass checking on the ones that need to be installed */
5556 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5557 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5558 + pkg_t *old_pkg = pkg->old_pkg;
5560 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5561 + if (err) return err;
5563 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5564 + if (err) return err;
5566 + err = preinst_configure(conf, pkg, old_pkg);
5567 + if (err) return err;
5569 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5570 + if (err) return err;
5572 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5573 + if (err) return err;
5578 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5581 + /* now one more pass checking on the ones that need to be installed */
5582 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5583 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5584 + pkg_t *old_pkg = pkg->old_pkg;
5587 + old_pkg->state_want = SW_DEINSTALL;
5589 + if (old_pkg->state_flag & SF_NOPRUNE) {
5590 + ipkg_message(conf, IPKG_INFO,
5591 + " not removing obsolesced files because package marked noprune\n");
5593 + ipkg_message(conf, IPKG_INFO,
5594 + " removing obsolesced files\n");
5595 + remove_obsolesced_files(conf, pkg, old_pkg);
5599 + ipkg_message(conf, IPKG_INFO,
5600 + " installing maintainer scripts\n");
5601 + install_maintainer_scripts(conf, pkg, old_pkg);
5603 + /* the following just returns 0 */
5604 + remove_disappeared(conf, pkg);
5606 + ipkg_message(conf, IPKG_INFO,
5607 + " installing data files\n");
5608 + install_data_files(conf, pkg);
5610 + ipkg_message(conf, IPKG_INFO,
5611 + " resolving conf files\n");
5612 + resolve_conffiles(conf, pkg);
5614 + pkg->state_status = SS_UNPACKED;
5617 + old_pkg->state_status = SS_NOT_INSTALLED;
5620 + time(&pkg->installed_time);
5622 + ipkg_message(conf, IPKG_INFO,
5623 + " cleanup temp files\n");
5624 + cleanup_temporary_files(conf, pkg);
5627 + pkg->parent->state_status = pkg->state_status;
5632 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5635 + /* now one more pass checking on the ones that need to be installed */
5636 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5637 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5638 + pkg_t *old_pkg = pkg->old_pkg;
5641 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5642 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5643 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5644 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5645 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5646 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5647 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5648 + preinst_configure_unwind(conf, pkg, old_pkg);
5649 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5650 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5651 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5652 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5654 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5655 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5663 + * Perform all the actions.
5665 + * pkgs_to_remove are packages marked for removal.
5666 + * pkgs_superseded are the old packages being replaced by upgrades.
5668 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5670 +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
5675 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5676 + if (err) return err;
5678 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5679 + if (err) return err;
5681 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5682 + if (err) goto UNWIND;
5684 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5685 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5686 + if (err) goto UNWIND;
5689 + * Now that we have the packages unpacked, we can look for data
5690 + * file clashes. First, we mark the files from the superseded
5691 + * packages as obsolete. Then we scan the files in
5692 + * pkgs_to_install, and only complain about clashes with
5693 + * non-obsolete files.
5696 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5697 + if (err) goto UNWIND;
5699 + /* this was before checking data file clashes */
5700 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5701 + if (err) goto UNWIND;
5703 + /* point of no return: no unwinding after this */
5704 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5705 + if (err) return err;
5707 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5711 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5713 + ipkg_message(conf, IPKG_INFO,
5714 + " cleanup temp files\n");
5715 + cleanup_temporary_files(conf, pkg);
5717 + ipkg_message(conf, IPKG_INFO,
5723 Index: busybox-1.4.2/archival/libipkg/ipkg_install.h
5724 ===================================================================
5725 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5726 +++ busybox-1.4.2/archival/libipkg/ipkg_install.h 2007-06-04 13:21:36.715395080 +0200
5728 +/* ipkg_install.h - the itsy package management system
5732 + Copyright (C) 2001 University of Southern California
5734 + This program is free software; you can redistribute it and/or
5735 + modify it under the terms of the GNU General Public License as
5736 + published by the Free Software Foundation; either version 2, or (at
5737 + your option) any later version.
5739 + This program is distributed in the hope that it will be useful, but
5740 + WITHOUT ANY WARRANTY; without even the implied warranty of
5741 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5742 + General Public License for more details.
5745 +#ifndef IPKG_INSTALL_H
5746 +#define IPKG_INSTALL_H
5749 +#include "ipkg_conf.h"
5751 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5752 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5753 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5754 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5755 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5757 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5759 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5760 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5763 Index: busybox-1.4.2/archival/libipkg/ipkg_message.c
5764 ===================================================================
5765 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5766 +++ busybox-1.4.2/archival/libipkg/ipkg_message.c 2007-06-04 13:21:36.715395080 +0200
5768 +/* ipkg_message.c - the itsy package management system
5770 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5772 + This program is free software; you can redistribute it and/or
5773 + modify it under the terms of the GNU General Public License as
5774 + published by the Free Software Foundation; either version 2, or (at
5775 + your option) any later version.
5777 + This program is distributed in the hope that it will be useful, but
5778 + WITHOUT ANY WARRANTY; without even the implied warranty of
5779 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5780 + General Public License for more details.
5785 +#include "ipkg_conf.h"
5786 +#include "ipkg_message.h"
5791 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5795 + if (conf && (conf->verbosity < level))
5802 + va_start (ap, fmt);
5803 + vprintf (fmt, ap);
5810 +#include "libipkg.h"
5812 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5815 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5820 + if (ipkg_cb_message)
5822 + va_start (ap, fmt);
5823 + vsnprintf (ts,256,fmt, ap);
5825 + ipkg_cb_message(conf,level,ts);
5829 Index: busybox-1.4.2/archival/libipkg/ipkg_message.h
5830 ===================================================================
5831 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5832 +++ busybox-1.4.2/archival/libipkg/ipkg_message.h 2007-06-04 13:21:36.715395080 +0200
5834 +/* ipkg_message.h - the itsy package management system
5836 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5838 + This program is free software; you can redistribute it and/or
5839 + modify it under the terms of the GNU General Public License as
5840 + published by the Free Software Foundation; either version 2, or (at
5841 + your option) any later version.
5843 + This program is distributed in the hope that it will be useful, but
5844 + WITHOUT ANY WARRANTY; without even the implied warranty of
5845 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5846 + General Public License for more details.
5849 +#ifndef _IPKG_MESSAGE_H_
5850 +#define _IPKG_MESSAGE_H_
5853 +#include "ipkg_conf.h"
5856 + IPKG_ERROR, /* error conditions */
5857 + IPKG_NOTICE, /* normal but significant condition */
5858 + IPKG_INFO, /* informational message */
5859 + IPKG_DEBUG, /* debug level message */
5860 + IPKG_DEBUG2, /* more debug level message */
5863 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5865 +#endif /* _IPKG_MESSAGE_H_ */
5866 Index: busybox-1.4.2/archival/libipkg/ipkg_remove.c
5867 ===================================================================
5868 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5869 +++ busybox-1.4.2/archival/libipkg/ipkg_remove.c 2007-06-04 13:21:36.716394928 +0200
5871 +/* ipkg_remove.c - the itsy package management system
5875 + Copyright (C) 2001 University of Southern California
5877 + This program is free software; you can redistribute it and/or
5878 + modify it under the terms of the GNU General Public License as
5879 + published by the Free Software Foundation; either version 2, or (at
5880 + your option) any later version.
5882 + This program is distributed in the hope that it will be useful, but
5883 + WITHOUT ANY WARRANTY; without even the implied warranty of
5884 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5885 + General Public License for more details.
5889 +#include "ipkg_message.h"
5893 +#include "ipkg_remove.h"
5895 +#include "file_util.h"
5896 +#include "sprintf_alloc.h"
5897 +#include "str_util.h"
5899 +#include "ipkg_cmd.h"
5902 + * Returns number of the number of packages depending on the packages provided by this package.
5903 + * Every package implicitly provides itself.
5905 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5907 + int nprovides = pkg->provides_count;
5908 + abstract_pkg_t **provides = pkg->provides;
5909 + int n_installed_dependents = 0;
5911 + for (i = 0; i <= nprovides; i++) {
5912 + abstract_pkg_t *providee = provides[i];
5913 + abstract_pkg_t **dependers = providee->depended_upon_by;
5914 + abstract_pkg_t *dep_ab_pkg;
5915 + if (dependers == NULL)
5917 + while ((dep_ab_pkg = *dependers++) != NULL) {
5918 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5919 + n_installed_dependents++;
5924 + /* if caller requested the set of installed dependents */
5925 + if (pdependents) {
5927 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5929 + if ( dependents == NULL ){
5930 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5934 + *pdependents = dependents;
5935 + for (i = 0; i <= nprovides; i++) {
5936 + abstract_pkg_t *providee = provides[i];
5937 + abstract_pkg_t **dependers = providee->depended_upon_by;
5938 + abstract_pkg_t *dep_ab_pkg;
5939 + if (dependers == NULL)
5941 + while ((dep_ab_pkg = *dependers++) != NULL) {
5942 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5943 + dependents[p++] = dep_ab_pkg;
5944 + dep_ab_pkg->state_flag |= SF_MARKED;
5948 + dependents[p] = NULL;
5949 + /* now clear the marks */
5950 + for (i = 0; i < p; i++) {
5951 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5952 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5955 + return n_installed_dependents;
5958 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5963 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5964 + abstract_pkg_t * ab_pkg;
5966 + if((ab_pkg = pkg->parent) == NULL){
5967 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5968 + __FUNCTION__, pkg->name);
5972 + if (dependents == NULL)
5975 + // here i am using the dependencies_checked
5976 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5977 + return 0; // has already been encountered in the process
5978 + // of marking packages for removal - Karthik
5979 + ab_pkg->dependencies_checked = 2;
5983 + while (dependents [i] != NULL) {
5984 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5986 + if (dep_ab_pkg->dependencies_checked == 2){
5990 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5991 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5992 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5993 + if (dep_pkg->state_status == SS_INSTALLED) {
5994 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6000 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6001 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6008 + for (i = 0; i < dependent_pkgs->len; i++) {
6009 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6016 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6018 + abstract_pkg_t *dep_ab_pkg;
6019 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6020 + while ((dep_ab_pkg = *dependents++) != NULL) {
6021 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6022 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6024 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6025 + ipkg_message(conf, IPKG_ERROR, "");
6026 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6027 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6028 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6029 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6030 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6034 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6036 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6037 + thus I wan't check for essential, as I'm upgrading.
6038 + I hope it won't break anything :)
6041 + abstract_pkg_t *parent_pkg = NULL;
6043 + if (pkg->essential && !message) {
6044 + if (conf->force_removal_of_essential_packages) {
6045 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6046 + "\tIf your system breaks, you get to keep both pieces\n",
6049 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6050 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6051 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6052 + "\tits will with the option: -force-removal-of-essential-packages\n",
6054 + return IPKG_PKG_IS_ESSENTIAL;
6058 + if ((parent_pkg = pkg->parent) == NULL)
6061 + /* only attempt to remove dependent installed packages if
6062 + * force_depends is not specified or the package is being
6065 + if (!conf->force_depends
6066 + && !(pkg->state_flag & SF_REPLACE)) {
6067 + abstract_pkg_t **dependents;
6068 + int has_installed_dependents =
6069 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6071 + if (has_installed_dependents) {
6073 + * if this package is depended up by others, then either we should
6074 + * not remove it or we should remove it and all of its dependents
6077 + if (!conf->force_removal_of_dependent_packages
6078 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6079 + return IPKG_PKG_HAS_DEPENDENTS;
6082 + /* remove packages depending on this package - Karthik */
6083 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6085 + if (err) return err;
6089 + if ( message==0 ){
6090 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6093 + pkg->state_flag |= SF_FILELIST_CHANGED;
6095 + pkg->state_want = SW_DEINSTALL;
6096 + ipkg_state_changed++;
6098 + pkg_run_script(conf, pkg, "prerm", "remove");
6100 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6101 + maintains an empty filelist rather than deleting it. That seems
6102 + like a big pain, and I don't see that that should make a big
6103 + difference, but for anyone who wants tighter compatibility,
6104 + feel free to fix this. */
6105 + remove_data_files_and_list(conf, pkg);
6107 + pkg_run_script(conf, pkg, "postrm", "remove");
6109 + remove_maintainer_scripts_except_postrm(conf, pkg);
6111 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6112 + * space, it doesn't make sense to leave extra configurations, files,
6113 + * and maintainer scripts left around. So, we make remove like purge,
6114 + * and take out all the crap :) */
6116 + remove_postrm(conf, pkg);
6117 + pkg->state_status = SS_NOT_INSTALLED;
6120 + parent_pkg->state_status = SS_NOT_INSTALLED;
6125 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6127 + ipkg_remove_pkg(conf, pkg,0);
6131 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6133 + str_list_t installed_dirs;
6134 + str_list_t *installed_files;
6135 + str_list_elt_t *iter;
6137 + conffile_t *conffile;
6138 + int removed_a_dir;
6141 + str_list_init(&installed_dirs);
6142 + installed_files = pkg_get_installed_files(pkg);
6144 + for (iter = installed_files->head; iter; iter = iter->next) {
6145 + file_name = iter->data;
6147 + if (file_is_dir(file_name)) {
6148 + str_list_append(&installed_dirs, strdup(file_name));
6152 + conffile = pkg_get_conffile(pkg, file_name);
6154 + /* XXX: QUESTION: Is this right? I figure we only need to
6155 + save the conffile if it has been modified. Is that what
6156 + dpkg does? Or does dpkg preserve all conffiles? If so,
6157 + this seems like a better thing to do to conserve
6159 + if (conffile_has_been_modified(conf, conffile)) {
6160 + printf(" not deleting modified conffile %s\n", file_name);
6166 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6167 + if (!conf->noaction)
6168 + unlink(file_name);
6171 + if (!conf->noaction) {
6173 + removed_a_dir = 0;
6174 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6175 + file_name = iter->data;
6177 + if (rmdir(file_name) == 0) {
6178 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6179 + removed_a_dir = 1;
6180 + str_list_remove(&installed_dirs, &iter);
6183 + } while (removed_a_dir);
6186 + pkg_free_installed_files(pkg);
6187 + /* We have to remove the file list now, so that
6188 + find_pkg_owning_file does not always just report this package */
6189 + pkg_remove_installed_files_list(conf, pkg);
6191 + /* Don't print warning for dirs that are provided by other packages */
6192 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6193 + file_name = iter->data;
6195 + owner = file_hash_get_file_owner(conf, file_name);
6198 + iter->data = NULL;
6199 + str_list_remove(&installed_dirs, &iter);
6204 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6206 + iter->data = NULL;
6208 + str_list_deinit(&installed_dirs);
6213 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6216 + char *globpattern;
6219 + if (conf->noaction) return 0;
6221 + sprintf_alloc(&globpattern, "%s/%s.*",
6222 + pkg->dest->info_dir, pkg->name);
6223 + err = glob(globpattern, 0, NULL, &globbuf);
6224 + free(globpattern);
6229 + for (i = 0; i < globbuf.gl_pathc; i++) {
6230 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6233 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6234 + unlink(globbuf.gl_pathv[i]);
6236 + globfree(&globbuf);
6241 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6243 + char *postrm_file_name;
6245 + if (conf->noaction) return 0;
6247 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6248 + pkg->dest->info_dir, pkg->name);
6249 + unlink(postrm_file_name);
6250 + free(postrm_file_name);
6254 Index: busybox-1.4.2/archival/libipkg/ipkg_remove.h
6255 ===================================================================
6256 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6257 +++ busybox-1.4.2/archival/libipkg/ipkg_remove.h 2007-06-04 13:21:36.716394928 +0200
6259 +/* ipkg_remove.h - the itsy package management system
6263 + Copyright (C) 2001 University of Southern California
6265 + This program is free software; you can redistribute it and/or
6266 + modify it under the terms of the GNU General Public License as
6267 + published by the Free Software Foundation; either version 2, or (at
6268 + your option) any later version.
6270 + This program is distributed in the hope that it will be useful, but
6271 + WITHOUT ANY WARRANTY; without even the implied warranty of
6272 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6273 + General Public License for more details.
6276 +#ifndef IPKG_REMOVE_H
6277 +#define IPKG_REMOVE_H
6280 +#include "ipkg_conf.h"
6282 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6283 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6284 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6285 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6286 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6287 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6288 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6292 Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.c
6293 ===================================================================
6294 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6295 +++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.c 2007-06-04 13:21:36.716394928 +0200
6297 +/* ipkg_upgrade.c - the itsy package management system
6300 + Copyright (C) 2001 University of Southern California
6302 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6304 + This program is free software; you can redistribute it and/or
6305 + modify it under the terms of the GNU General Public License as
6306 + published by the Free Software Foundation; either version 2, or (at
6307 + your option) any later version.
6309 + This program is distributed in the hope that it will be useful, but
6310 + WITHOUT ANY WARRANTY; without even the implied warranty of
6311 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6312 + General Public License for more details.
6316 +#include "ipkg_install.h"
6317 +#include "ipkg_message.h"
6319 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6323 + char *old_version, *new_version;
6325 + if (old->state_flag & SF_HOLD) {
6326 + ipkg_message(conf, IPKG_NOTICE,
6327 + "Not upgrading package %s which is marked "
6328 + "hold (flags=%#x)\n", old->name, old->state_flag);
6332 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6333 + if (new == NULL) {
6334 + old_version = pkg_version_str_alloc(old);
6335 + ipkg_message(conf, IPKG_NOTICE,
6336 + "Assuming locally installed package %s (%s) "
6337 + "is up to date.\n", old->name, old_version);
6338 + free(old_version);
6342 + old_version = pkg_version_str_alloc(old);
6343 + new_version = pkg_version_str_alloc(new);
6345 + cmp = pkg_compare_versions(old, new);
6346 + ipkg_message(conf, IPKG_DEBUG,
6347 + "comparing visible versions of pkg %s:"
6348 + "\n\t%s is installed "
6349 + "\n\t%s is available "
6350 + "\n\t%d was comparison result\n",
6351 + old->name, old_version, new_version, cmp);
6353 + ipkg_message(conf, IPKG_INFO,
6354 + "Package %s (%s) installed in %s is up to date.\n",
6355 + old->name, old_version, old->dest->name);
6356 + free(old_version);
6357 + free(new_version);
6359 + } else if (cmp > 0) {
6360 + ipkg_message(conf, IPKG_NOTICE,
6361 + "Not downgrading package %s on %s from %s to %s.\n",
6362 + old->name, old->dest->name, old_version, new_version);
6363 + free(old_version);
6364 + free(new_version);
6366 + } else if (cmp < 0) {
6367 + new->dest = old->dest;
6368 + old->state_want = SW_DEINSTALL;
6371 + new->state_flag |= SF_USER;
6372 + return ipkg_install_pkg(conf, new,1);
6374 Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.h
6375 ===================================================================
6376 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6377 +++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.h 2007-06-04 13:21:36.716394928 +0200
6379 +/* ipkg_upgrade.c - the itsy package management system
6381 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6383 + This program is free software; you can redistribute it and/or
6384 + modify it under the terms of the GNU General Public License as
6385 + published by the Free Software Foundation; either version 2, or (at
6386 + your option) any later version.
6388 + This program is distributed in the hope that it will be useful, but
6389 + WITHOUT ANY WARRANTY; without even the implied warranty of
6390 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6391 + General Public License for more details.
6396 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6397 Index: busybox-1.4.2/archival/libipkg/ipkg_utils.c
6398 ===================================================================
6399 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6400 +++ busybox-1.4.2/archival/libipkg/ipkg_utils.c 2007-06-04 13:21:36.716394928 +0200
6402 +/* ipkg_utils.c - the itsy package management system
6406 + Copyright (C) 2002 Compaq Computer Corporation
6408 + This program is free software; you can redistribute it and/or
6409 + modify it under the terms of the GNU General Public License as
6410 + published by the Free Software Foundation; either version 2, or (at
6411 + your option) any later version.
6413 + This program is distributed in the hope that it will be useful, but
6414 + WITHOUT ANY WARRANTY; without even the implied warranty of
6415 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6416 + General Public License for more details.
6422 +#include <sys/vfs.h>
6424 +#include "ipkg_utils.h"
6426 +#include "pkg_hash.h"
6428 +struct errlist* error_list;
6430 +int get_available_blocks(char * filesystem)
6432 + struct statfs sfs;
6434 + if(statfs(filesystem, &sfs)){
6435 + fprintf(stderr, "bad statfs\n");
6438 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6439 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6442 +char **read_raw_pkgs_from_file(const char *file_name)
6447 + if(!(fp = fopen(file_name, "r"))){
6448 + fprintf(stderr, "can't get %s open for read\n", file_name);
6452 + ret = read_raw_pkgs_from_stream(fp);
6459 +char **read_raw_pkgs_from_stream(FILE *fp)
6461 + char **raw = NULL, *buf, *scout;
6463 + size_t size = 512;
6465 + buf = malloc (size);
6467 + while (fgets(buf, size, fp)) {
6468 + while (strlen (buf) == (size - 1)
6469 + && buf[size-2] != '\n') {
6470 + size_t o = size - 1;
6472 + buf = realloc (buf, size);
6473 + if (fgets (buf + o, size - o, fp) == NULL)
6478 + raw = realloc(raw, (count + 50) * sizeof(char *));
6480 + if((scout = strchr(buf, '\n')))
6483 + raw[count++] = strdup(buf);
6486 + raw = realloc(raw, (count + 1) * sizeof(char *));
6487 + raw[count] = NULL;
6494 +/* something to remove whitespace, a hash pooper */
6495 +char *trim_alloc(char *line)
6498 + char *dest, *src, *end;
6500 + new = malloc(strlen(line) + 1);
6501 + if ( new == NULL ){
6502 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6505 + dest = new, src = line, end = line + (strlen(line) - 1);
6507 + /* remove it from the front */
6512 + /* and now from the back */
6513 + while((end > src) &&
6519 + /* this does from the first space
6520 + * blasting away any versions stuff in depends
6531 +int line_is_blank(const char *line)
6535 + for (s = line; *s; s++) {
6542 +void push_error_list(struct errlist ** errors, char * msg){
6543 + struct errlist *err_lst_tmp;
6546 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6547 + err_lst_tmp->errmsg=strdup(msg) ;
6548 + err_lst_tmp->next = *errors;
6549 + *errors = err_lst_tmp;
6553 +void reverse_error_list(struct errlist **errors){
6554 + struct errlist *result=NULL;
6555 + struct errlist *current= *errors;
6556 + struct errlist *next;
6558 + while ( current != NULL ) {
6559 + next = current->next;
6560 + current->next=result;
6569 +void free_error_list(struct errlist **errors){
6570 + struct errlist *current = *errors;
6572 + while (current != NULL) {
6573 + free(current->errmsg);
6574 + current = (*errors)->next;
6576 + *errors = current;
6583 Index: busybox-1.4.2/archival/libipkg/ipkg_utils.h
6584 ===================================================================
6585 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6586 +++ busybox-1.4.2/archival/libipkg/ipkg_utils.h 2007-06-04 13:21:36.717394776 +0200
6588 +/* ipkg_utils.h - the itsy package management system
6592 + Copyright (C) 2002 Compaq Computer Corporation
6594 + This program is free software; you can redistribute it and/or
6595 + modify it under the terms of the GNU General Public License as
6596 + published by the Free Software Foundation; either version 2, or (at
6597 + your option) any later version.
6599 + This program is distributed in the hope that it will be useful, but
6600 + WITHOUT ANY WARRANTY; without even the implied warranty of
6601 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6602 + General Public License for more details.
6605 +#ifndef IPKG_UTILS_H
6606 +#define IPKG_UTILS_H
6610 +int get_available_blocks(char * filesystem);
6611 +char **read_raw_pkgs_from_file(const char *file_name);
6612 +char **read_raw_pkgs_from_stream(FILE *fp);
6613 +char *trim_alloc(char * line);
6614 +int line_is_blank(const char *line);
6617 Index: busybox-1.4.2/archival/libipkg/Kbuild
6618 ===================================================================
6619 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6620 +++ busybox-1.4.2/archival/libipkg/Kbuild 2007-06-04 13:21:36.717394776 +0200
6622 +# Makefile for busybox
6624 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6625 +# Copyright (C) 2006 OpenWrt.org
6627 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6629 +LIBIPKG_CORE_OBJS:= \
6634 +LIBIPKG_CMD_OBJS:= \
6636 + ipkg_configure.o \
6642 +LIBIPKG_DB_OBJS:= \
6653 +LIBIPKG_LIST_OBJS:= \
6665 +LIBIPKG_UTIL_OBJS:= \
6672 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6673 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6678 +ifeq ($(strip $(IPKG_ARCH)),)
6679 +IPKG_ARCH:=$(TARGET_ARCH)
6681 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6682 Index: busybox-1.4.2/archival/libipkg/libipkg.c
6683 ===================================================================
6684 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6685 +++ busybox-1.4.2/archival/libipkg/libipkg.c 2007-06-04 13:21:36.717394776 +0200
6687 +/* ipkglib.c - the itsy package management system
6691 + Copyright (C) 2003 kernel concepts
6693 + This program is free software; you can redistribute it and/or
6694 + modify it under the terms of the GNU General Public License as
6695 + published by the Free Software Foundation; either version 2, or (at
6696 + your option) any later version.
6698 + This program is distributed in the hope that it will be useful, but
6699 + WITHOUT ANY WARRANTY; without even the implied warranty of
6700 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6701 + General Public License for more details.
6707 +#include "ipkg_includes.h"
6708 +#include "libipkg.h"
6711 +#include "ipkg_conf.h"
6712 +#include "ipkg_cmd.h"
6713 +#include "file_util.h"
6717 +ipkg_message_callback ipkg_cb_message = NULL;
6718 +ipkg_response_callback ipkg_cb_response = NULL;
6719 +ipkg_status_callback ipkg_cb_status = NULL;
6720 +ipkg_list_callback ipkg_cb_list = NULL;
6724 +ipkg_init (ipkg_message_callback mcall,
6725 + ipkg_response_callback rcall,
6728 + ipkg_cb_message = mcall;
6729 + ipkg_cb_response = rcall;
6738 +ipkg_deinit (args_t * args)
6740 + args_deinit (args);
6741 + ipkg_cb_message = NULL;
6742 + ipkg_cb_response = NULL;
6744 + /* place other cleanup stuff here */
6751 +ipkg_packages_list(args_t *args,
6752 + const char *packages,
6753 + ipkg_list_callback cblist,
6757 + ipkg_conf_t ipkg_conf;
6760 + err = ipkg_conf_init (&ipkg_conf, args);
6766 + ipkg_cb_list = cblist;
6767 + /* we need to do this because of static declarations,
6768 + * maybe a good idea to change */
6769 + cmd = ipkg_cmd_find ("list");
6771 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6773 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6774 + ipkg_cb_list = NULL;
6775 + ipkg_conf_deinit (&ipkg_conf);
6781 +ipkg_packages_status(args_t *args,
6782 + const char *packages,
6783 + ipkg_status_callback cbstatus,
6787 + ipkg_conf_t ipkg_conf;
6790 + err = ipkg_conf_init (&ipkg_conf, args);
6796 + ipkg_cb_status = cbstatus;
6798 + /* we need to do this because of static declarations,
6799 + * maybe a good idea to change */
6800 + cmd = ipkg_cmd_find ("status");
6802 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6804 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6806 + ipkg_cb_status = NULL;
6807 + ipkg_conf_deinit (&ipkg_conf);
6813 +ipkg_packages_info(args_t *args,
6814 + const char *packages,
6815 + ipkg_status_callback cbstatus,
6819 + ipkg_conf_t ipkg_conf;
6822 + err = ipkg_conf_init (&ipkg_conf, args);
6828 + ipkg_cb_status = cbstatus;
6830 + /* we need to do this because of static declarations,
6831 + * maybe a good idea to change */
6832 + cmd = ipkg_cmd_find ("info");
6834 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6836 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6838 + ipkg_cb_status = NULL;
6839 + ipkg_conf_deinit (&ipkg_conf);
6845 +ipkg_packages_install (args_t * args, const char *name)
6848 + ipkg_conf_t ipkg_conf;
6851 + /* this error should be handled in application */
6852 + if (!name || !strlen (name))
6855 + err = ipkg_conf_init (&ipkg_conf, args);
6861 + /* we need to do this because of static declarations,
6862 + * maybe a good idea to change */
6863 + cmd = ipkg_cmd_find ("install");
6864 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6866 + ipkg_conf_deinit(&ipkg_conf);
6872 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6875 + ipkg_conf_t ipkg_conf;
6878 + /* this error should be handled in application */
6879 + if (!name || !strlen (name))
6882 + err = ipkg_conf_init (&ipkg_conf, args);
6888 + /* we need to do this because of static declarations,
6889 + * maybe a good idea to change */
6891 + cmd = ipkg_cmd_find ("purge");
6893 + cmd = ipkg_cmd_find ("remove");
6895 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6897 + ipkg_conf_deinit(&ipkg_conf);
6903 +ipkg_lists_update(args_t *args)
6906 + ipkg_conf_t ipkg_conf;
6909 + err = ipkg_conf_init (&ipkg_conf, args);
6915 + /* we need to do this because of static declarations,
6916 + * maybe a good idea to change */
6917 + cmd = ipkg_cmd_find ("update");
6919 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6921 + ipkg_conf_deinit(&ipkg_conf);
6927 +ipkg_packages_upgrade(args_t *args)
6930 + ipkg_conf_t ipkg_conf;
6933 + err = ipkg_conf_init (&ipkg_conf, args);
6939 + /* we need to do this because of static declarations,
6940 + * maybe a good idea to change */
6941 + cmd = ipkg_cmd_find ("upgrade");
6943 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6945 + ipkg_conf_deinit(&ipkg_conf);
6951 +ipkg_packages_download (args_t * args, const char *name)
6954 + ipkg_conf_t ipkg_conf;
6957 + /* this error should be handled in application */
6958 + if (!name || !strlen (name))
6961 + err = ipkg_conf_init (&ipkg_conf, args);
6967 + /* we need to do this because of static declarations,
6968 + * maybe a good idea to change */
6969 + cmd = ipkg_cmd_find ("download");
6970 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6972 + ipkg_conf_deinit(&ipkg_conf);
6978 +ipkg_package_files(args_t *args,
6980 + ipkg_list_callback cblist,
6984 + ipkg_conf_t ipkg_conf;
6987 + /* this error should be handled in application */
6988 + if (!name || !strlen (name))
6991 + err = ipkg_conf_init (&ipkg_conf, args);
6997 + ipkg_cb_list = cblist;
6999 + /* we need to do this because of static declarations,
7000 + * maybe a good idea to change */
7001 + cmd = ipkg_cmd_find ("files");
7003 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7005 + ipkg_cb_list = NULL;
7006 + ipkg_conf_deinit(&ipkg_conf);
7012 +ipkg_file_search(args_t *args,
7014 + ipkg_list_callback cblist,
7018 + ipkg_conf_t ipkg_conf;
7021 + /* this error should be handled in application */
7022 + if (!file || !strlen (file))
7025 + err = ipkg_conf_init (&ipkg_conf, args);
7031 + ipkg_cb_list = cblist;
7033 + /* we need to do this because of static declarations,
7034 + * maybe a good idea to change */
7035 + cmd = ipkg_cmd_find ("search");
7036 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7038 + ipkg_cb_list = NULL;
7039 + ipkg_conf_deinit(&ipkg_conf);
7045 +ipkg_file_what(args_t *args, const char *file, const char* command)
7048 + ipkg_conf_t ipkg_conf;
7051 + /* this error should be handled in application */
7052 + if (!file || !strlen (file))
7055 + err = ipkg_conf_init (&ipkg_conf, args);
7061 + /* we need to do this because of static declarations,
7062 + * maybe a good idea to change */
7063 + cmd = ipkg_cmd_find (command);
7064 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7066 + ipkg_conf_deinit(&ipkg_conf);
7070 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7071 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7072 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7073 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7074 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7077 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7080 + if (conf && (conf->verbosity < level)) {
7084 + if ( level == IPKG_ERROR ){
7085 + push_error_list(&error_list, msg);
7094 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7095 + pkg_state_status_t status, void *userdata)
7098 + printf("%s - %s - %s\n", name, version, desc);
7100 + printf("%s - %s\n", name, version);
7104 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7105 + pkg_state_status_t status, void *userdata)
7108 + printf("%s\n", desc);
7112 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7115 + printf("%s\n", desc);
7119 +char* default_ipkg_response_callback(char *question)
7121 + char *response = NULL;
7125 + response = (char *)file_read_line_alloc(stdin);
7126 + } while (response == NULL);
7130 +/* This is used for backward compatibility */
7132 +ipkg_op (int argc, char *argv[])
7134 + int err, opt_index;
7138 + ipkg_conf_t ipkg_conf;
7140 + args_init (&args);
7142 + opt_index = args_parse (&args, argc, argv);
7143 + if (opt_index == argc || opt_index < 0)
7145 + args_usage ("ipkg must have one sub-command argument");
7148 + cmd_name = argv[opt_index++];
7149 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7150 + read anything from there.
7152 + if ( !strcmp(cmd_name,"print-architecture") ||
7153 + !strcmp(cmd_name,"print_architecture") ||
7154 + !strcmp(cmd_name,"print-installation-architecture") ||
7155 + !strcmp(cmd_name,"print_installation_architecture") )
7156 + args.nocheckfordirorfile = 1;
7158 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7159 + read anything from there.
7161 + if ( !strcmp(cmd_name,"flag") ||
7162 + !strcmp(cmd_name,"configure") ||
7163 + !strcmp(cmd_name,"remove") ||
7164 + !strcmp(cmd_name,"files") ||
7165 + !strcmp(cmd_name,"search") ||
7166 + !strcmp(cmd_name,"compare_versions") ||
7167 + !strcmp(cmd_name,"compare-versions") ||
7168 + !strcmp(cmd_name,"list_installed") ||
7169 + !strcmp(cmd_name,"list-installed") ||
7170 + !strcmp(cmd_name,"status") )
7171 + args.noreadfeedsfile = 1;
7174 + err = ipkg_conf_init (&ipkg_conf, &args);
7180 + args_deinit (&args);
7182 + ipkg_cb_message = default_ipkg_message_callback;
7183 + ipkg_cb_response = default_ipkg_response_callback;
7184 + ipkg_cb_status = default_ipkg_status_callback;
7185 + if ( strcmp(cmd_name, "files")==0)
7186 + ipkg_cb_list = default_ipkg_files_callback;
7188 + ipkg_cb_list = default_ipkg_list_callback;
7190 + cmd = ipkg_cmd_find (cmd_name);
7193 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7195 + args_usage (NULL);
7198 + if (cmd->requires_args && opt_index == argc)
7201 + "%s: the ``%s'' command requires at least one argument\n",
7202 + __FUNCTION__, cmd_name);
7203 + args_usage (NULL);
7206 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7208 + ipkg_conf_deinit (&ipkg_conf);
7213 +#endif /* IPKG_LIB */
7214 Index: busybox-1.4.2/archival/libipkg/libipkg.h
7215 ===================================================================
7216 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7217 +++ busybox-1.4.2/archival/libipkg/libipkg.h 2007-06-04 13:21:36.718394624 +0200
7219 +/* ipkglib.h - the itsy package management system
7221 + Florian Boor <florian.boor@kernelconcepts.de>
7223 + This program is free software; you can redistribute it and/or
7224 + modify it under the terms of the GNU General Public License as
7225 + published by the Free Software Foundation; either version 2, or (at
7226 + your option) any later version.
7228 + This program is distributed in the hope that it will be useful, but
7229 + WITHOUT ANY WARRANTY; without even the implied warranty of
7230 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7231 + General Public License for more details.
7239 +#include "ipkg_conf.h"
7240 +#include "ipkg_message.h"
7245 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7247 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7248 + pkg_state_status_t status, void *userdata);
7249 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7251 +typedef char* (*ipkg_response_callback)(char *question);
7253 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7254 +extern int ipkg_init (ipkg_message_callback mcall,
7255 + ipkg_response_callback rcall,
7258 +extern int ipkg_deinit (args_t *args);
7259 +extern int ipkg_packages_list(args_t *args,
7260 + const char *packages,
7261 + ipkg_list_callback cblist,
7263 +extern int ipkg_packages_status(args_t *args,
7264 + const char *packages,
7265 + ipkg_status_callback cbstatus,
7267 +extern int ipkg_packages_info(args_t *args,
7268 + const char *packages,
7269 + ipkg_status_callback cbstatus,
7271 +extern int ipkg_packages_install(args_t *args, const char *name);
7272 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7273 +extern int ipkg_lists_update(args_t *args);
7274 +extern int ipkg_packages_upgrade(args_t *args);
7275 +extern int ipkg_packages_download(args_t *args, const char *name);
7276 +extern int ipkg_package_files(args_t *args,
7278 + ipkg_list_callback cblist,
7280 +extern int ipkg_file_search(args_t *args,
7282 + ipkg_list_callback cblist,
7284 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7285 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7286 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7287 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7288 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7290 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7291 +extern ipkg_response_callback ipkg_cb_response;
7292 +extern ipkg_status_callback ipkg_cb_status;
7293 +extern ipkg_list_callback ipkg_cb_list;
7294 +extern void push_error_list(struct errlist **errors,char * msg);
7295 +extern void reverse_error_list(struct errlist **errors);
7296 +extern void free_error_list(struct errlist **errors);
7300 +extern int ipkg_op(int argc, char *argv[]);
7306 Index: busybox-1.4.2/archival/libipkg/nv_pair.c
7307 ===================================================================
7308 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7309 +++ busybox-1.4.2/archival/libipkg/nv_pair.c 2007-06-04 13:21:36.718394624 +0200
7311 +/* nv_pair.c - the itsy package management system
7315 + Copyright (C) 2001 University of Southern California
7317 + This program is free software; you can redistribute it and/or
7318 + modify it under the terms of the GNU General Public License as
7319 + published by the Free Software Foundation; either version 2, or (at
7320 + your option) any later version.
7322 + This program is distributed in the hope that it will be useful, but
7323 + WITHOUT ANY WARRANTY; without even the implied warranty of
7324 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7325 + General Public License for more details.
7330 +#include "nv_pair.h"
7331 +#include "str_util.h"
7333 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7335 + nv_pair->name = str_dup_safe(name);
7336 + nv_pair->value = str_dup_safe(value);
7341 +void nv_pair_deinit(nv_pair_t *nv_pair)
7343 + free(nv_pair->name);
7344 + nv_pair->name = NULL;
7346 + free(nv_pair->value);
7347 + nv_pair->value = NULL;
7351 Index: busybox-1.4.2/archival/libipkg/nv_pair.h
7352 ===================================================================
7353 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7354 +++ busybox-1.4.2/archival/libipkg/nv_pair.h 2007-06-04 13:21:36.718394624 +0200
7356 +/* nv_pair.h - the itsy package management system
7360 + Copyright (C) 2001 University of Southern California
7362 + This program is free software; you can redistribute it and/or
7363 + modify it under the terms of the GNU General Public License as
7364 + published by the Free Software Foundation; either version 2, or (at
7365 + your option) any later version.
7367 + This program is distributed in the hope that it will be useful, but
7368 + WITHOUT ANY WARRANTY; without even the implied warranty of
7369 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7370 + General Public License for more details.
7376 +typedef struct nv_pair nv_pair_t;
7383 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7384 +void nv_pair_deinit(nv_pair_t *nv_pair);
7388 Index: busybox-1.4.2/archival/libipkg/nv_pair_list.c
7389 ===================================================================
7390 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7391 +++ busybox-1.4.2/archival/libipkg/nv_pair_list.c 2007-06-04 13:21:36.718394624 +0200
7393 +/* nv_pair_list.c - the itsy package management system
7397 + Copyright (C) 2001 University of Southern California
7399 + This program is free software; you can redistribute it and/or
7400 + modify it under the terms of the GNU General Public License as
7401 + published by the Free Software Foundation; either version 2, or (at
7402 + your option) any later version.
7404 + This program is distributed in the hope that it will be useful, but
7405 + WITHOUT ANY WARRANTY; without even the implied warranty of
7406 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7407 + General Public License for more details.
7412 +#include "nv_pair.h"
7413 +#include "void_list.h"
7414 +#include "nv_pair_list.h"
7416 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7418 + return void_list_elt_init((void_list_elt_t *) elt, data);
7421 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7423 + void_list_elt_deinit((void_list_elt_t *) elt);
7426 +int nv_pair_list_init(nv_pair_list_t *list)
7428 + return void_list_init((void_list_t *) list);
7431 +void nv_pair_list_deinit(nv_pair_list_t *list)
7433 + nv_pair_list_elt_t *iter;
7434 + nv_pair_t *nv_pair;
7436 + for (iter = list->head; iter; iter = iter->next) {
7437 + nv_pair = iter->data;
7438 + nv_pair_deinit(nv_pair);
7440 + /* malloced in nv_pair_list_append */
7442 + iter->data = NULL;
7444 + void_list_deinit((void_list_t *) list);
7447 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7451 + /* freed in nv_pair_list_deinit */
7452 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7454 + if (nv_pair == NULL) {
7455 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7458 + nv_pair_init(nv_pair, name, value);
7460 + err = void_list_append((void_list_t *) list, nv_pair);
7468 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7470 + return void_list_push((void_list_t *) list, data);
7473 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7475 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7478 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7480 + nv_pair_list_elt_t *iter;
7481 + nv_pair_t *nv_pair;
7483 + for (iter = list->head; iter; iter = iter->next) {
7484 + nv_pair = iter->data;
7485 + if (strcmp(nv_pair->name, name) == 0) {
7486 + return nv_pair->value;
7491 Index: busybox-1.4.2/archival/libipkg/nv_pair_list.h
7492 ===================================================================
7493 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7494 +++ busybox-1.4.2/archival/libipkg/nv_pair_list.h 2007-06-04 13:21:36.718394624 +0200
7496 +/* nv_pair_list.h - the itsy package management system
7500 + Copyright (C) 2001 University of Southern California
7502 + This program is free software; you can redistribute it and/or
7503 + modify it under the terms of the GNU General Public License as
7504 + published by the Free Software Foundation; either version 2, or (at
7505 + your option) any later version.
7507 + This program is distributed in the hope that it will be useful, but
7508 + WITHOUT ANY WARRANTY; without even the implied warranty of
7509 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7510 + General Public License for more details.
7513 +#ifndef NV_PAIR_LIST_H
7514 +#define NV_PAIR_LIST_H
7516 +#include "nv_pair.h"
7517 +#include "void_list.h"
7519 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7520 +struct nv_pair_list_elt
7522 + nv_pair_list_elt_t *next;
7526 +typedef struct nv_pair_list nv_pair_list_t;
7527 +struct nv_pair_list
7529 + nv_pair_list_elt_t pre_head;
7530 + nv_pair_list_elt_t *head;
7531 + nv_pair_list_elt_t *tail;
7534 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7536 + if (list->head == NULL)
7542 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7543 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7545 +int nv_pair_list_init(nv_pair_list_t *list);
7546 +void nv_pair_list_deinit(nv_pair_list_t *list);
7548 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7549 + const char *name, const char *value);
7550 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7551 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7552 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7556 Index: busybox-1.4.2/archival/libipkg/pkg.c
7557 ===================================================================
7558 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7559 +++ busybox-1.4.2/archival/libipkg/pkg.c 2007-06-04 13:21:36.720394320 +0200
7561 +/* pkg.c - the itsy package management system
7565 + Copyright (C) 2001 University of Southern California
7567 + This program is free software; you can redistribute it and/or
7568 + modify it under the terms of the GNU General Public License as
7569 + published by the Free Software Foundation; either version 2, or (at
7570 + your option) any later version.
7572 + This program is distributed in the hope that it will be useful, but
7573 + WITHOUT ANY WARRANTY; without even the implied warranty of
7574 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7575 + General Public License for more details.
7580 +#include <string.h>
7585 +#include "pkg_parse.h"
7586 +#include "pkg_extract.h"
7587 +#include "ipkg_message.h"
7588 +#include "ipkg_utils.h"
7590 +#include "sprintf_alloc.h"
7591 +#include "file_util.h"
7592 +#include "str_util.h"
7593 +#include "xsystem.h"
7594 +#include "ipkg_conf.h"
7596 +typedef struct enum_map enum_map_t;
7603 +static const enum_map_t pkg_state_want_map[] = {
7604 + { SW_UNKNOWN, "unknown"},
7605 + { SW_INSTALL, "install"},
7606 + { SW_DEINSTALL, "deinstall"},
7607 + { SW_PURGE, "purge"}
7610 +static const enum_map_t pkg_state_flag_map[] = {
7612 + { SF_REINSTREQ, "reinstreq"},
7613 + { SF_HOLD, "hold"},
7614 + { SF_REPLACE, "replace"},
7615 + { SF_NOPRUNE, "noprune"},
7616 + { SF_PREFER, "prefer"},
7617 + { SF_OBSOLETE, "obsolete"},
7618 + { SF_USER, "user"},
7621 +static const enum_map_t pkg_state_status_map[] = {
7622 + { SS_NOT_INSTALLED, "not-installed" },
7623 + { SS_UNPACKED, "unpacked" },
7624 + { SS_HALF_CONFIGURED, "half-configured" },
7625 + { SS_INSTALLED, "installed" },
7626 + { SS_HALF_INSTALLED, "half-installed" },
7627 + { SS_CONFIG_FILES, "config-files" },
7628 + { SS_POST_INST_FAILED, "post-inst-failed" },
7629 + { SS_REMOVAL_FAILED, "removal-failed" }
7632 +static int verrevcmp(const char *val, const char *ref);
7635 +pkg_t *pkg_new(void)
7639 + pkg = malloc(sizeof(pkg_t));
7640 + if (pkg == NULL) {
7641 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7650 +int pkg_init(pkg_t *pkg)
7652 + memset(pkg, 0, sizeof(pkg_t));
7655 + pkg->version = NULL;
7656 + pkg->revision = NULL;
7657 + pkg->familiar_revision = NULL;
7660 + pkg->architecture = NULL;
7661 + pkg->maintainer = NULL;
7662 + pkg->section = NULL;
7663 + pkg->description = NULL;
7664 + pkg->state_want = SW_UNKNOWN;
7665 + pkg->state_flag = SF_OK;
7666 + pkg->state_status = SS_NOT_INSTALLED;
7667 + pkg->depends_str = NULL;
7668 + pkg->provides_str = NULL;
7669 + pkg->depends_count = 0;
7670 + pkg->depends = NULL;
7671 + pkg->suggests_str = NULL;
7672 + pkg->recommends_str = NULL;
7673 + pkg->suggests_count = 0;
7674 + pkg->recommends_count = 0;
7676 + /* Abhaya: added init for conflicts fields */
7677 + pkg->conflicts = NULL;
7678 + pkg->conflicts_count = 0;
7680 + /* added for replaces. Jamey 7/23/2002 */
7681 + pkg->replaces = NULL;
7682 + pkg->replaces_count = 0;
7684 + pkg->pre_depends_count = 0;
7685 + pkg->pre_depends_str = NULL;
7686 + pkg->provides_count = 0;
7687 + pkg->provides = NULL;
7688 + pkg->filename = NULL;
7689 + pkg->local_filename = NULL;
7690 + pkg->tmp_unpack_dir = NULL;
7691 + pkg->md5sum = NULL;
7693 + pkg->installed_size = NULL;
7694 + pkg->priority = NULL;
7695 + pkg->source = NULL;
7696 + conffile_list_init(&pkg->conffiles);
7697 + pkg->installed_files = NULL;
7698 + pkg->installed_files_ref_cnt = 0;
7699 + pkg->essential = 0;
7700 + pkg->provided_by_hand = 0;
7705 +void pkg_deinit(pkg_t *pkg)
7710 + free(pkg->version);
7711 + pkg->version = NULL;
7712 + /* revision and familiar_revision share storage with version, so
7714 + pkg->revision = NULL;
7715 + pkg->familiar_revision = NULL;
7716 + /* owned by ipkg_conf_t */
7718 + /* owned by ipkg_conf_t */
7720 + free(pkg->architecture);
7721 + pkg->architecture = NULL;
7722 + free(pkg->maintainer);
7723 + pkg->maintainer = NULL;
7724 + free(pkg->section);
7725 + pkg->section = NULL;
7726 + free(pkg->description);
7727 + pkg->description = NULL;
7728 + pkg->state_want = SW_UNKNOWN;
7729 + pkg->state_flag = SF_OK;
7730 + pkg->state_status = SS_NOT_INSTALLED;
7731 + free(pkg->depends_str);
7732 + pkg->depends_str = NULL;
7733 + free(pkg->provides_str);
7734 + pkg->provides_str = NULL;
7735 + pkg->depends_count = 0;
7736 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7737 + pkg->pre_depends_count = 0;
7738 + free(pkg->pre_depends_str);
7739 + pkg->pre_depends_str = NULL;
7740 + pkg->provides_count = 0;
7741 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7742 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7743 + free(pkg->filename);
7744 + pkg->filename = NULL;
7745 + free(pkg->local_filename);
7746 + pkg->local_filename = NULL;
7747 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7748 + ipkg_install.c here. See comment in
7749 + ipkg_install.c:cleanup_temporary_files */
7750 + free(pkg->tmp_unpack_dir);
7751 + pkg->tmp_unpack_dir = NULL;
7752 + free(pkg->md5sum);
7753 + pkg->md5sum = NULL;
7756 + free(pkg->installed_size);
7757 + pkg->installed_size = NULL;
7758 + free(pkg->priority);
7759 + pkg->priority = NULL;
7760 + free(pkg->source);
7761 + pkg->source = NULL;
7762 + conffile_list_deinit(&pkg->conffiles);
7763 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7764 + since if they are calling deinit, they should know. Maybe do an
7765 + assertion here instead? */
7766 + pkg->installed_files_ref_cnt = 1;
7767 + pkg_free_installed_files(pkg);
7768 + pkg->essential = 0;
7771 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7775 + FILE *control_file;
7777 + err = pkg_init(pkg);
7778 + if (err) { return err; }
7780 + pkg->local_filename = strdup(filename);
7782 + control_file = tmpfile();
7783 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7784 + if (err) { return err; }
7786 + rewind(control_file);
7787 + raw = read_raw_pkgs_from_stream(control_file);
7788 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7790 + fclose(control_file);
7795 +/* Merge any new information in newpkg into oldpkg */
7796 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7797 + newpkg, but should leave it usable. This rework is so that
7798 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7800 + * uh, i thought that i had originally written this so that it took
7801 + * two pkgs and returned a new one? we can do that again... -sma
7803 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7805 + if (oldpkg == newpkg) {
7810 + oldpkg->src = newpkg->src;
7811 + if (!oldpkg->dest)
7812 + oldpkg->dest = newpkg->dest;
7813 + if (!oldpkg->architecture)
7814 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7815 + if (!oldpkg->arch_priority)
7816 + oldpkg->arch_priority = newpkg->arch_priority;
7817 + if (!oldpkg->section)
7818 + oldpkg->section = str_dup_safe(newpkg->section);
7819 + if(!oldpkg->maintainer)
7820 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7821 + if(!oldpkg->description)
7822 + oldpkg->description = str_dup_safe(newpkg->description);
7824 + /* merge the state_flags from the new package */
7825 + oldpkg->state_want = newpkg->state_want;
7826 + oldpkg->state_status = newpkg->state_status;
7827 + oldpkg->state_flag = newpkg->state_flag;
7829 + if (oldpkg->state_want == SW_UNKNOWN)
7830 + oldpkg->state_want = newpkg->state_want;
7831 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7832 + oldpkg->state_status = newpkg->state_status;
7833 + oldpkg->state_flag |= newpkg->state_flag;
7836 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7837 + oldpkg->depends_str = newpkg->depends_str;
7838 + newpkg->depends_str = NULL;
7839 + oldpkg->depends_count = newpkg->depends_count;
7840 + newpkg->depends_count = 0;
7842 + oldpkg->depends = newpkg->depends;
7843 + newpkg->depends = NULL;
7845 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7846 + newpkg->pre_depends_str = NULL;
7847 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7848 + newpkg->pre_depends_count = 0;
7850 + oldpkg->recommends_str = newpkg->recommends_str;
7851 + newpkg->recommends_str = NULL;
7852 + oldpkg->recommends_count = newpkg->recommends_count;
7853 + newpkg->recommends_count = 0;
7855 + oldpkg->suggests_str = newpkg->suggests_str;
7856 + newpkg->suggests_str = NULL;
7857 + oldpkg->suggests_count = newpkg->suggests_count;
7858 + newpkg->suggests_count = 0;
7861 + if (!oldpkg->provides_str) {
7862 + oldpkg->provides_str = newpkg->provides_str;
7863 + newpkg->provides_str = NULL;
7864 + oldpkg->provides_count = newpkg->provides_count;
7865 + newpkg->provides_count = 0;
7867 + oldpkg->provides = newpkg->provides;
7868 + newpkg->provides = NULL;
7871 + if (!oldpkg->conflicts_str) {
7872 + oldpkg->conflicts_str = newpkg->conflicts_str;
7873 + newpkg->conflicts_str = NULL;
7874 + oldpkg->conflicts_count = newpkg->conflicts_count;
7875 + newpkg->conflicts_count = 0;
7877 + oldpkg->conflicts = newpkg->conflicts;
7878 + newpkg->conflicts = NULL;
7881 + if (!oldpkg->replaces_str) {
7882 + oldpkg->replaces_str = newpkg->replaces_str;
7883 + newpkg->replaces_str = NULL;
7884 + oldpkg->replaces_count = newpkg->replaces_count;
7885 + newpkg->replaces_count = 0;
7887 + oldpkg->replaces = newpkg->replaces;
7888 + newpkg->replaces = NULL;
7891 + if (!oldpkg->filename)
7892 + oldpkg->filename = str_dup_safe(newpkg->filename);
7894 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7895 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7896 + if (!oldpkg->local_filename)
7897 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7898 + if (!oldpkg->tmp_unpack_dir)
7899 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7900 + if (!oldpkg->md5sum)
7901 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7902 + if (!oldpkg->size)
7903 + oldpkg->size = str_dup_safe(newpkg->size);
7904 + if (!oldpkg->installed_size)
7905 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7906 + if (!oldpkg->priority)
7907 + oldpkg->priority = str_dup_safe(newpkg->priority);
7908 + if (!oldpkg->source)
7909 + oldpkg->source = str_dup_safe(newpkg->source);
7910 + if (oldpkg->conffiles.head == NULL){
7911 + oldpkg->conffiles = newpkg->conffiles;
7912 + conffile_list_init(&newpkg->conffiles);
7914 + if (!oldpkg->installed_files){
7915 + oldpkg->installed_files = newpkg->installed_files;
7916 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7917 + newpkg->installed_files = NULL;
7919 + if (!oldpkg->essential)
7920 + oldpkg->essential = newpkg->essential;
7922 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7927 +abstract_pkg_t *abstract_pkg_new(void)
7929 + abstract_pkg_t * ab_pkg;
7931 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7933 + if (ab_pkg == NULL) {
7934 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7938 + if ( abstract_pkg_init(ab_pkg) < 0 )
7944 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7946 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7948 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7949 + if (ab_pkg->provided_by==NULL){
7952 + ab_pkg->dependencies_checked = 0;
7953 + ab_pkg->state_status = SS_NOT_INSTALLED;
7958 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7961 + char **raw_start=NULL;
7963 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7964 + if (temp_str == NULL ){
7965 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7968 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7970 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7971 + if (raw == NULL ){
7972 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7977 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7978 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7994 +char * pkg_formatted_info(pkg_t *pkg )
7999 + buff = malloc(8192);
8000 + if (buff == NULL) {
8001 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8007 + line = pkg_formatted_field(pkg, "Package");
8008 + strncat(buff ,line, strlen(line));
8011 + line = pkg_formatted_field(pkg, "Version");
8012 + strncat(buff ,line, strlen(line));
8015 + line = pkg_formatted_field(pkg, "Depends");
8016 + strncat(buff ,line, strlen(line));
8019 + line = pkg_formatted_field(pkg, "Recommends");
8020 + strncat(buff ,line, strlen(line));
8023 + line = pkg_formatted_field(pkg, "Suggests");
8024 + strncat(buff ,line, strlen(line));
8027 + line = pkg_formatted_field(pkg, "Provides");
8028 + strncat(buff ,line, strlen(line));
8031 + line = pkg_formatted_field(pkg, "Replaces");
8032 + strncat(buff ,line, strlen(line));
8035 + line = pkg_formatted_field(pkg, "Conflicts");
8036 + strncat(buff ,line, strlen(line));
8039 + line = pkg_formatted_field(pkg, "Status");
8040 + strncat(buff ,line, strlen(line));
8043 + line = pkg_formatted_field(pkg, "Section");
8044 + strncat(buff ,line, strlen(line));
8047 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8048 + strncat(buff ,line, strlen(line));
8051 + line = pkg_formatted_field(pkg, "Architecture");
8052 + strncat(buff ,line, strlen(line));
8055 + line = pkg_formatted_field(pkg, "Maintainer");
8056 + strncat(buff ,line, strlen(line));
8059 + line = pkg_formatted_field(pkg, "MD5sum");
8060 + strncat(buff ,line, strlen(line));
8063 + line = pkg_formatted_field(pkg, "Size");
8064 + strncat(buff ,line, strlen(line));
8067 + line = pkg_formatted_field(pkg, "Filename");
8068 + strncat(buff ,line, strlen(line));
8071 + line = pkg_formatted_field(pkg, "Conffiles");
8072 + strncat(buff ,line, strlen(line));
8075 + line = pkg_formatted_field(pkg, "Source");
8076 + strncat(buff ,line, strlen(line));
8079 + line = pkg_formatted_field(pkg, "Description");
8080 + strncat(buff ,line, strlen(line));
8083 + line = pkg_formatted_field(pkg, "Installed-Time");
8084 + strncat(buff ,line, strlen(line));
8090 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8092 + static size_t LINE_LEN = 128;
8093 + char line_str[LINE_LEN];
8094 + char * temp = (char *)malloc(1);
8096 + int flag_provide_false = 0;
8099 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8100 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8103 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8104 + goto UNKNOWN_FMT_FIELD;
8113 + if (strcasecmp(field, "Architecture") == 0) {
8114 + /* Architecture */
8115 + if (pkg->architecture) {
8116 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8117 + if ( temp == NULL ){
8118 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8122 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8125 + goto UNKNOWN_FMT_FIELD;
8130 + if (strcasecmp(field, "Conffiles") == 0) {
8132 + conffile_list_elt_t *iter;
8134 + if (pkg->conffiles.head == NULL) {
8139 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8140 + if (iter->data->name && iter->data->value) {
8141 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8144 + temp = (char *)realloc(temp,len);
8145 + if ( temp == NULL ){
8146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8150 + strncpy(temp, "Conffiles:\n", 12);
8151 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8152 + if (iter->data->name && iter->data->value) {
8153 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8154 + strncat(temp, line_str, strlen(line_str));
8157 + } else if (strcasecmp(field, "Conflicts") == 0) {
8160 + if (pkg->conflicts_count) {
8162 + for(i = 0; i < pkg->conflicts_count; i++) {
8163 + len = len + (strlen(pkg->conflicts_str[i])+5);
8165 + temp = (char *)realloc(temp,len);
8166 + if ( temp == NULL ){
8167 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8171 + strncpy(temp, "Conflicts:", 11);
8172 + for(i = 0; i < pkg->conflicts_count; i++) {
8173 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8174 + strncat(temp, line_str, strlen(line_str));
8176 + strncat(temp, "\n", strlen("\n"));
8179 + goto UNKNOWN_FMT_FIELD;
8184 + if (strcasecmp(field, "Depends") == 0) {
8188 + if (pkg->depends_count) {
8190 + for(i = 0; i < pkg->depends_count; i++) {
8191 + len = len + (strlen(pkg->depends_str[i])+4);
8193 + temp = (char *)realloc(temp,len);
8194 + if ( temp == NULL ){
8195 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8199 + strncpy(temp, "Depends:", 10);
8200 + for(i = 0; i < pkg->depends_count; i++) {
8201 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8202 + strncat(temp, line_str, strlen(line_str));
8204 + strncat(temp, "\n", strlen("\n"));
8206 + } else if (strcasecmp(field, "Description") == 0) {
8208 + if (pkg->description) {
8209 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8210 + if ( temp == NULL ){
8211 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8215 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8218 + goto UNKNOWN_FMT_FIELD;
8224 + if (pkg->essential) {
8225 + temp = (char *)realloc(temp,16);
8226 + if ( temp == NULL ){
8227 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8231 + snprintf(temp, (16), "Essential: yes\n");
8238 + if (pkg->filename) {
8239 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8240 + if ( temp == NULL ){
8241 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8245 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8251 + if (strcasecmp(field, "Installed-Size") == 0) {
8252 + /* Installed-Size */
8253 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8254 + if ( temp == NULL ){
8255 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8259 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8260 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8261 + temp = (char *)realloc(temp,29);
8262 + if ( temp == NULL ){
8263 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8267 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8273 + /* Maintainer | MD5sum */
8274 + if (strcasecmp(field, "Maintainer") == 0) {
8276 + if (pkg->maintainer) {
8277 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8278 + if ( temp == NULL ){
8279 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8283 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8285 + } else if (strcasecmp(field, "MD5sum") == 0) {
8287 + if (pkg->md5sum) {
8288 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8289 + if ( temp == NULL ){
8290 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8294 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8297 + goto UNKNOWN_FMT_FIELD;
8303 + if (strcasecmp(field, "Package") == 0) {
8305 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8306 + if ( temp == NULL ){
8307 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8311 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8312 + } else if (strcasecmp(field, "Priority") == 0) {
8314 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8315 + if ( temp == NULL ){
8316 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8320 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8321 + } else if (strcasecmp(field, "Provides") == 0) {
8325 + if (pkg->provides_count) {
8326 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8327 + for ( i=0; i < pkg->provides_count; i++ ){
8328 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8329 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8330 + flag_provide_false = 1;
8333 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8334 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8335 + char provstr[LINE_LEN];
8337 + for(i = 0; i < pkg->provides_count; i++) {
8338 + len = len + (strlen(pkg->provides_str[i])+5);
8340 + temp = (char *)realloc(temp,len);
8341 + if ( temp == NULL ){
8342 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8346 + strncpy(temp, "Provides:", 12);
8347 + for(i = 0; i < pkg->provides_count; i++) {
8348 + if (strlen(pkg->provides_str[i])>0){;
8349 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8350 + strncat(temp, provstr, strlen(provstr));
8353 + strncat(temp, "\n", strlen("\n"));
8357 + goto UNKNOWN_FMT_FIELD;
8364 + /* Replaces | Recommends*/
8365 + if (strcasecmp (field, "Replaces") == 0) {
8366 + if (pkg->replaces_count) {
8368 + for (i = 0; i < pkg->replaces_count; i++) {
8369 + len = len + (strlen(pkg->replaces_str[i])+5);
8371 + temp = (char *)realloc(temp,len);
8372 + if ( temp == NULL ){
8373 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8377 + strncpy(temp, "Replaces:", 12);
8378 + for (i = 0; i < pkg->replaces_count; i++) {
8379 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8380 + strncat(temp, line_str, strlen(line_str));
8382 + strncat(temp, "\n", strlen("\n"));
8384 + } else if (strcasecmp (field, "Recommends") == 0) {
8385 + if (pkg->recommends_count) {
8387 + for(i = 0; i < pkg->recommends_count; i++) {
8388 + len = len + (strlen( pkg->recommends_str[i])+5);
8390 + temp = (char *)realloc(temp,len);
8391 + if ( temp == NULL ){
8392 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8396 + strncpy(temp, "Recommends:", 13);
8397 + for(i = 0; i < pkg->recommends_count; i++) {
8398 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8399 + strncat(temp, line_str, strlen(line_str));
8401 + strncat(temp, "\n", strlen("\n"));
8404 + goto UNKNOWN_FMT_FIELD;
8410 + /* Section | Size | Source | Status | Suggests */
8411 + if (strcasecmp(field, "Section") == 0) {
8413 + if (pkg->section) {
8414 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8415 + if ( temp == NULL ){
8416 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8420 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8422 + } else if (strcasecmp(field, "Size") == 0) {
8425 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8426 + if ( temp == NULL ){
8427 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8431 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8433 + } else if (strcasecmp(field, "Source") == 0) {
8435 + if (pkg->source) {
8436 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8437 + if ( temp == NULL ){
8438 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8442 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8444 + } else if (strcasecmp(field, "Status") == 0) {
8446 + /* Benjamin Pineau note: we should avoid direct usage of
8447 + * strlen(arg) without keeping "arg" for later free()
8449 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8450 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8451 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8453 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8454 + temp = (char *)realloc(temp,sum_of_sizes);
8455 + if ( temp == NULL ){
8456 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8460 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8463 + if(pstat) /* pfstat can be NULL if ENOMEM */
8465 + } else if (strcasecmp(field, "Suggests") == 0) {
8466 + if (pkg->suggests_count) {
8469 + for(i = 0; i < pkg->suggests_count; i++) {
8470 + len = len + (strlen(pkg->suggests_str[i])+5);
8472 + temp = (char *)realloc(temp,len);
8473 + if ( temp == NULL ){
8474 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8478 + strncpy(temp, "Suggests:", 10);
8479 + for(i = 0; i < pkg->suggests_count; i++) {
8480 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8481 + strncat(temp, line_str, strlen(line_str));
8483 + strncat(temp, "\n", strlen("\n"));
8486 + goto UNKNOWN_FMT_FIELD;
8493 + char *version = pkg_version_str_alloc(pkg);
8494 + temp = (char *)realloc(temp,strlen(version)+14);
8495 + if ( temp == NULL ){
8496 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8500 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8505 + goto UNKNOWN_FMT_FIELD;
8508 + if ( strlen(temp)<2 ) {
8513 + UNKNOWN_FMT_FIELD:
8514 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8515 + if ( strlen(temp)<2 ) {
8522 +void pkg_print_info(pkg_t *pkg, FILE *file)
8525 + if (pkg == NULL) {
8529 + buff = pkg_formatted_info(pkg);
8530 + if ( buff == NULL )
8532 + if (strlen(buff)>2){
8533 + fwrite(buff, 1, strlen(buff), file);
8538 +void pkg_print_status(pkg_t * pkg, FILE * file)
8540 + if (pkg == NULL) {
8544 + /* XXX: QUESTION: Do we actually want more fields here? The
8545 + original idea was to save space by installing only what was
8546 + needed for actual computation, (package, version, status,
8547 + essential, conffiles). The assumption is that all other fields
8548 + can be found in th available file.
8550 + But, someone proposed the idea to make it possible to
8551 + reconstruct a .ipk from an installed package, (ie. for beaming
8552 + from one handheld to another). So, maybe we actually want a few
8553 + more fields here, (depends, suggests, etc.), so that that would
8554 + be guaranteed to work even in the absence of more information
8555 + from the available file.
8557 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8558 + the essential info needs to be here for all installed packages
8559 + because they may not appear in the Packages files on various
8560 + feeds. Furthermore, one should be able to install from URL or
8561 + local storage without requiring a Packages file from any feed.
8564 + pkg_print_field(pkg, file, "Package");
8565 + pkg_print_field(pkg, file, "Version");
8566 + pkg_print_field(pkg, file, "Depends");
8567 + pkg_print_field(pkg, file, "Recommends");
8568 + pkg_print_field(pkg, file, "Suggests");
8569 + pkg_print_field(pkg, file, "Provides");
8570 + pkg_print_field(pkg, file, "Replaces");
8571 + pkg_print_field(pkg, file, "Conflicts");
8572 + pkg_print_field(pkg, file, "Status");
8573 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8574 + pkg_print_field(pkg, file, "Architecture");
8575 + pkg_print_field(pkg, file, "Conffiles");
8576 + pkg_print_field(pkg, file, "Installed-Time");
8577 + fputs("\n", file);
8580 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8583 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8584 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8585 + __FUNCTION__, field);
8587 + buff = pkg_formatted_field(pkg, field);
8588 + if (strlen(buff)>2) {
8589 + fprintf(file, "%s", buff);
8597 + * libdpkg - Debian packaging suite library routines
8598 + * vercmp.c - comparison of version numbers
8600 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8602 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8606 + if (pkg->epoch > ref_pkg->epoch) {
8610 + if (pkg->epoch < ref_pkg->epoch) {
8614 + r = verrevcmp(pkg->version, ref_pkg->version);
8619 +#ifdef USE_DEBVERSION
8620 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8625 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8631 +int verrevcmp(const char *val, const char *ref)
8635 + const char *vp, *rp;
8636 + const char *vsep, *rsep;
8638 + if (!val) val= "";
8639 + if (!ref) ref= "";
8641 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8642 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8644 + vc= (val == vp) ? 0 : *val++;
8645 + rc= (ref == rp) ? 0 : *ref++;
8646 + if (!rc && !vc) break;
8647 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8648 + if (rc && !isalpha(rc)) rc += 256;
8649 + if (vc != rc) return vc - rc;
8653 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8654 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8655 + if (vl != rl) return vl - rl;
8659 + vsep = strchr(".-", vc);
8660 + rsep = strchr(".-", rc);
8661 + if (vsep && !rsep) return -1;
8662 + if (!vsep && rsep) return +1;
8664 + if (!*val && !*ref) return 0;
8665 + if (!*val) return -1;
8666 + if (!*ref) return +1;
8670 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8674 + r = pkg_compare_versions(it, ref);
8676 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8680 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8684 + if (strcmp(op, "<<") == 0) {
8688 + if (strcmp(op, ">>") == 0) {
8692 + if (strcmp(op, "=") == 0) {
8696 + fprintf(stderr, "unknown operator: %s", op);
8700 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8704 + if (!a->name || !b->name) {
8705 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8706 + a, a->name, b, b->name);
8710 + namecmp = strcmp(a->name, b->name);
8713 + vercmp = pkg_compare_versions(a, b);
8716 + if (!a->arch_priority || !b->arch_priority) {
8717 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8718 + a, a->arch_priority, b, b->arch_priority);
8721 + if (a->arch_priority > b->arch_priority)
8723 + if (a->arch_priority < b->arch_priority)
8728 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8730 + if (!a->name || !b->name) {
8731 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8732 + a, a->name, b, b->name);
8735 + return strcmp(a->name, b->name);
8739 +char *pkg_version_str_alloc(pkg_t *pkg)
8741 + char *complete_version;
8743 +#ifdef USE_DEBVERSION
8744 + char *revision_str;
8745 + char *familiar_revision_str;
8749 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8751 + epoch_str = strdup("");
8754 +#ifdef USE_DEBVERSION
8755 + if (pkg->revision && strlen(pkg->revision)) {
8756 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8758 + revision_str = strdup("");
8761 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8762 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8764 + familiar_revision_str = strdup("");
8768 +#ifdef USE_DEBVERSION
8769 + sprintf_alloc(&complete_version, "%s%s%s%s",
8770 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8772 + sprintf_alloc(&complete_version, "%s%s",
8773 + epoch_str, pkg->version);
8777 +#ifdef USE_DEBVERSION
8778 + free(revision_str);
8779 + free(familiar_revision_str);
8782 + return complete_version;
8785 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8788 + char *list_file_name = NULL;
8789 + FILE *list_file = NULL;
8791 + char *installed_file_name;
8794 + pkg->installed_files_ref_cnt++;
8796 + if (pkg->installed_files) {
8797 + return pkg->installed_files;
8800 + pkg->installed_files = str_list_alloc();
8801 + if (pkg->installed_files == NULL) {
8802 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8806 + /* For uninstalled packages, get the file list firectly from the package.
8807 + For installed packages, look at the package.list file in the database.
8809 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8810 + if (pkg->local_filename == NULL) {
8811 + return pkg->installed_files;
8813 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8814 + file. In other words, change deb_extract so that it can
8815 + simply return the file list as a char *[] rather than
8816 + insisting on writing in to a FILE * as it does now. */
8817 + list_file = tmpfile();
8818 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8820 + fclose(list_file);
8821 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8822 + __FUNCTION__, pkg->local_filename, strerror(err));
8823 + return pkg->installed_files;
8825 + rewind(list_file);
8827 + sprintf_alloc(&list_file_name, "%s/%s.list",
8828 + pkg->dest->info_dir, pkg->name);
8829 + if (! file_exists(list_file_name)) {
8830 + free(list_file_name);
8831 + return pkg->installed_files;
8834 + list_file = fopen(list_file_name, "r");
8835 + if (list_file == NULL) {
8836 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8837 + list_file_name, strerror(errno));
8838 + free(list_file_name);
8839 + return pkg->installed_files;
8841 + free(list_file_name);
8844 + rootdirlen = strlen( pkg->dest->root_dir );
8848 + line = file_read_line_alloc(list_file);
8849 + if (line == NULL) {
8855 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8856 + if( strncmp( pkg->dest->root_dir,
8859 + if (*file_name == '.') {
8862 + if (*file_name == '/') {
8866 + /* Freed in pkg_free_installed_files */
8867 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8869 + // already contains root_dir as header -> ABSOLUTE
8870 + sprintf_alloc(&installed_file_name, "%s", file_name);
8872 + str_list_append(pkg->installed_files, installed_file_name);
8876 + fclose(list_file);
8878 + return pkg->installed_files;
8881 +/* XXX: CLEANUP: This function and it's counterpart,
8882 + (pkg_get_installed_files), do not match our init/deinit naming
8883 + convention. Nor the alloc/free convention. But, then again, neither
8884 + of these conventions currrently fit the way these two functions
8886 +int pkg_free_installed_files(pkg_t *pkg)
8888 + str_list_elt_t *iter;
8890 + pkg->installed_files_ref_cnt--;
8891 + if (pkg->installed_files_ref_cnt > 0) {
8895 + if (pkg->installed_files) {
8897 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8898 + /* malloced in pkg_get_installed_files */
8899 + free (iter->data);
8900 + iter->data = NULL;
8903 + str_list_deinit(pkg->installed_files);
8906 + pkg->installed_files = NULL;
8911 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8914 + char *list_file_name;
8916 + //I don't think pkg_free_installed_files should be called here. Jamey
8917 + //pkg_free_installed_files(pkg);
8919 + sprintf_alloc(&list_file_name, "%s/%s.list",
8920 + pkg->dest->info_dir, pkg->name);
8921 + if (!conf->noaction) {
8922 + err = unlink(list_file_name);
8923 + free(list_file_name);
8932 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8934 + conffile_list_elt_t *iter;
8935 + conffile_t *conffile;
8937 + if (pkg == NULL) {
8941 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8942 + conffile = iter->data;
8944 + if (strcmp(conffile->name, file_name) == 0) {
8952 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8953 + const char *script, const char *args)
8959 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8960 + maintainer script within a chroot environment. */
8962 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8963 + have scripts in pkg->tmp_unpack_dir. */
8964 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8965 + if (pkg->dest == NULL) {
8966 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8967 + __FUNCTION__, pkg->name);
8970 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8972 + if (pkg->tmp_unpack_dir == NULL) {
8973 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8974 + __FUNCTION__, pkg->name);
8977 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8980 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8981 + if (conf->noaction) return 0;
8983 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8984 + scripts when running with offline_root mode and/or a dest other
8985 + than '/'. I've been playing around with some clever chroot
8986 + tricks and I might come up with something workable. */
8987 + if (conf->offline_root) {
8988 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8991 + setenv("PKG_ROOT",
8992 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8994 + if (! file_exists(path)) {
8999 + if (conf->offline_root) {
9000 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9005 + sprintf_alloc(&cmd, "%s %s", path, args);
9008 + err = xsystem(cmd);
9012 + fprintf(stderr, "%s script returned status %d\n", script, err);
9019 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9023 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9024 + if (pkg_state_want_map[i].value == sw) {
9025 + return strdup(pkg_state_want_map[i].str);
9029 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9030 + __FUNCTION__, sw);
9031 + return strdup("<STATE_WANT_UNKNOWN>");
9034 +pkg_state_want_t pkg_state_want_from_str(char *str)
9038 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9039 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9040 + return pkg_state_want_map[i].value;
9044 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9045 + __FUNCTION__, str);
9046 + return SW_UNKNOWN;
9049 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9052 + int len = 3; /* ok\000 is minimum */
9055 + /* clear the temporary flags before converting to string */
9056 + sf &= SF_NONVOLATILE_FLAGS;
9059 + return strdup("ok");
9062 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9063 + if (sf & pkg_state_flag_map[i].value) {
9064 + len += strlen(pkg_state_flag_map[i].str) + 1;
9067 + str = malloc(len);
9068 + if ( str == NULL ) {
9069 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9073 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9074 + if (sf & pkg_state_flag_map[i].value) {
9075 + strcat(str, pkg_state_flag_map[i].str);
9079 + len = strlen(str);
9080 + str[len-1] = 0; /* squash last comma */
9085 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9090 + if (strcmp(str, "ok") == 0) {
9093 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9094 + const char *sfname = pkg_state_flag_map[i].str;
9095 + int sfname_len = strlen(sfname);
9096 + if (strncmp(str, sfname, sfname_len) == 0) {
9097 + sf |= pkg_state_flag_map[i].value;
9098 + str += sfname_len;
9099 + if (str[0] == ',') {
9110 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9114 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9115 + if (pkg_state_status_map[i].value == ss) {
9116 + return strdup(pkg_state_status_map[i].str);
9120 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9121 + __FUNCTION__, ss);
9122 + return strdup("<STATE_STATUS_UNKNOWN>");
9125 +pkg_state_status_t pkg_state_status_from_str(char *str)
9129 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9130 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9131 + return pkg_state_status_map[i].value;
9135 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9136 + __FUNCTION__, str);
9137 + return SS_NOT_INSTALLED;
9140 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9142 + nv_pair_list_elt_t *l;
9144 + if (!pkg->architecture)
9147 + l = conf->arch_list.head;
9150 + nv_pair_t *nv = l->data;
9151 + if (strcmp(nv->name, pkg->architecture) == 0) {
9152 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9158 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9162 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9164 + nv_pair_list_elt_t *l;
9166 + l = conf->arch_list.head;
9169 + nv_pair_t *nv = l->data;
9170 + if (strcmp(nv->name, archname) == 0) {
9171 + int priority = strtol(nv->value, NULL, 0);
9179 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9182 + hash_table_t *pkg_hash = &conf->pkg_hash;
9183 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9184 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9186 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9187 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9188 + /* update arch_priority for each package */
9189 + for (i = 0; i < available_pkgs->len; i++) {
9190 + pkg_t *pkg = available_pkgs->pkgs[i];
9191 + int arch_priority = 1;
9194 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9195 + if (pkg->architecture)
9196 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9198 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9199 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9200 + pkg->arch_priority = arch_priority;
9203 + for (i = 0; i < available_pkgs->len; i++) {
9204 + pkg_t *pkg = available_pkgs->pkgs[i];
9205 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9206 + /* clear flags and want for any uninstallable package */
9207 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9208 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9209 + pkg->state_want = SW_UNKNOWN;
9210 + pkg->state_flag = 0;
9213 + pkg_vec_free(available_pkgs);
9215 + /* update the file owner data structure */
9216 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9217 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9218 + for (i = 0; i < installed_pkgs->len; i++) {
9219 + pkg_t *pkg = installed_pkgs->pkgs[i];
9220 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9221 + str_list_elt_t *iter;
9222 + if (installed_files == NULL) {
9223 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9226 + for (iter = installed_files->head; iter; iter = iter->next) {
9227 + char *installed_file = iter->data;
9228 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9229 + file_hash_set_file_owner(conf, installed_file, pkg);
9232 + pkg_vec_free(installed_pkgs);
9237 +struct pkg_write_filelist_data {
9238 + ipkg_conf_t *conf;
9243 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9245 + struct pkg_write_filelist_data *data = data_;
9246 + pkg_t *entry = entry_;
9247 + if (entry == data->pkg) {
9248 + fprintf(data->stream, "%s\n", key);
9252 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9254 + struct pkg_write_filelist_data data;
9255 + char *list_file_name = NULL;
9259 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9262 + ipkg_message(conf, IPKG_INFO,
9263 + " creating %s.list file\n", pkg->name);
9264 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9265 + if (!list_file_name) {
9266 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9269 + ipkg_message(conf, IPKG_INFO,
9270 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9271 + data.stream = fopen(list_file_name, "w");
9272 + if (!data.stream) {
9273 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9274 + list_file_name, strerror(errno));
9279 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9280 + fclose(data.stream);
9281 + free(list_file_name);
9286 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9288 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9289 + hash_table_t *pkg_hash = &conf->pkg_hash;
9292 + if (conf->noaction)
9295 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9296 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9297 + for (i = 0; i < installed_pkgs->len; i++) {
9298 + pkg_t *pkg = installed_pkgs->pkgs[i];
9299 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9300 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9301 + err = pkg_write_filelist(conf, pkg);
9303 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9308 Index: busybox-1.4.2/archival/libipkg/pkg_depends.c
9309 ===================================================================
9310 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9311 +++ busybox-1.4.2/archival/libipkg/pkg_depends.c 2007-06-04 13:21:36.724393712 +0200
9313 +/* pkg_depends.c - the itsy package management system
9317 + Copyright (C) 2002 Compaq Computer Corporation
9319 + This program is free software; you can redistribute it and/or
9320 + modify it under the terms of the GNU General Public License as
9321 + published by the Free Software Foundation; either version 2, or (at
9322 + your option) any later version.
9324 + This program is distributed in the hope that it will be useful, but
9325 + WITHOUT ANY WARRANTY; without even the implied warranty of
9326 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9327 + General Public License for more details.
9335 +#include "ipkg_utils.h"
9336 +#include "pkg_hash.h"
9337 +#include "ipkg_message.h"
9338 +#include "pkg_parse.h"
9339 +#include "hash_table.h"
9341 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9342 +static depend_t * depend_init(void);
9343 +static void depend_deinit(depend_t *d);
9344 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9345 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9346 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9348 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9350 + depend_t *depend = (depend_t *)cdata;
9351 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9357 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9359 + depend_t *depend = (depend_t *)cdata;
9361 + pkg_t * temp = pkg_new();
9363 + parseVersion(temp, depend->version);
9364 + comparison = pkg_compare_versions(pkg, temp);
9367 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9368 + __FUNCTION__, pkg->name, pkg->version,
9369 + depend, depend->constraint, depend->version,
9370 + comparison, version_constraints_satisfied(depend, pkg));
9372 + if (version_constraints_satisfied(depend, pkg))
9378 +/* returns ndependences or negative error value */
9379 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9380 + pkg_vec_t *unsatisfied, char *** unresolved)
9382 + pkg_t * satisfier_entry_pkg;
9383 + register int i, j, k, l;
9386 + abstract_pkg_t * ab_pkg;
9389 + * this is a setup to check for redundant/cyclic dependency checks,
9390 + * which are marked at the abstract_pkg level
9392 + if (!(ab_pkg = pkg->parent)) {
9393 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9394 + *unresolved = NULL;
9397 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9398 + *unresolved = NULL;
9401 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9405 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9407 + *unresolved = NULL;
9413 + /* foreach dependency */
9414 + for (i = 0; i < count; i++) {
9415 + compound_depend_t * compound_depend = &pkg->depends[i];
9416 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9418 + satisfier_entry_pkg = NULL;
9420 + if (compound_depend->type == GREEDY_DEPEND) {
9421 + /* foreach possible satisfier */
9422 + for (j = 0; j < compound_depend->possibility_count; j++) {
9423 + /* foreach provided_by, which includes the abstract_pkg itself */
9424 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9425 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9426 + int nposs = ab_provider_vec->len;
9427 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9428 + for (l = 0; l < nposs; l++) {
9429 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9430 + /* if no depends on this one, try the first package that Provides this one */
9431 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9435 + /* cruise this possiblity's pkg_vec looking for an installed version */
9436 + for (k = 0; k < test_vec->len; k++) {
9437 + pkg_t *pkg_scout = test_vec->pkgs[k];
9438 + /* not installed, and not already known about? */
9439 + if ((pkg_scout->state_want != SW_INSTALL)
9440 + && !pkg_scout->parent->dependencies_checked
9441 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9442 + char ** newstuff = NULL;
9444 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9445 + /* check for not-already-installed dependencies */
9446 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9450 + if (newstuff == NULL) {
9452 + for (l = 0; l < rc; l++) {
9453 + pkg_t *p = tmp_vec->pkgs[l];
9454 + if (p->state_want == SW_INSTALL)
9456 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9460 + pkg_vec_free (tmp_vec);
9462 + /* mark this one for installation */
9463 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9464 + pkg_vec_insert(unsatisfied, pkg_scout);
9467 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9478 + /* foreach possible satisfier, look for installed package */
9479 + for (j = 0; j < compound_depend->possibility_count; j++) {
9480 + /* foreach provided_by, which includes the abstract_pkg itself */
9481 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9482 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9483 + pkg_t *satisfying_pkg =
9484 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9485 + pkg_installed_and_constraint_satisfied,
9486 + dependence_to_satisfy, 1);
9487 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9488 + if (satisfying_pkg != NULL) {
9489 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9490 + satisfying_pkg = NULL;
9493 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9494 + if (satisfying_pkg != NULL) {
9500 + /* if nothing installed matches, then look for uninstalled satisfier */
9502 + /* foreach possible satisfier, look for installed package */
9503 + for (j = 0; j < compound_depend->possibility_count; j++) {
9504 + /* foreach provided_by, which includes the abstract_pkg itself */
9505 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9506 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9507 + pkg_t *satisfying_pkg =
9508 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9509 + pkg_constraint_satisfied,
9510 + dependence_to_satisfy, 1);
9511 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9512 + if (satisfying_pkg != NULL) {
9513 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9514 + satisfying_pkg = NULL;
9518 + /* user request overrides package recommendation */
9519 + if (satisfying_pkg != NULL
9520 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9521 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9522 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9523 + pkg->name, satisfying_pkg->name);
9527 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9528 + if (satisfying_pkg != NULL) {
9529 + satisfier_entry_pkg = satisfying_pkg;
9535 + /* we didn't find one, add something to the unsatisfied vector */
9537 + if (!satisfier_entry_pkg) {
9538 + /* failure to meet recommendations is not an error */
9539 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9540 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9542 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9543 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9546 + if (compound_depend->type == SUGGEST) {
9547 + /* just mention it politely */
9548 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9549 + pkg->name, satisfier_entry_pkg->name);
9551 + char ** newstuff = NULL;
9553 + if (satisfier_entry_pkg != pkg &&
9554 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9555 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9556 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9557 + satisfier_entry_pkg,
9560 + the_lost = merge_unresolved(the_lost, newstuff);
9566 + *unresolved = the_lost;
9568 + return unsatisfied->len;
9571 +/*checking for conflicts !in replaces
9572 + If a packages conflicts with another but is also replacing it, I should not consider it a
9574 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9576 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9579 + int replaces_count = pkg->replaces_count;
9580 + abstract_pkg_t **replaces;
9582 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9585 + replaces = pkg->replaces;
9587 + for (i = 0; i < replaces_count; i++) {
9588 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9589 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9598 +/* Abhaya: added support for conflicts */
9599 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9601 + pkg_vec_t * installed_conflicts, * test_vec;
9602 + compound_depend_t * conflicts;
9603 + depend_t ** possible_satisfiers;
9604 + depend_t * possible_satisfier;
9605 + register int i, j, k;
9607 + abstract_pkg_t * ab_pkg;
9608 + pkg_t **pkg_scouts;
9612 + * this is a setup to check for redundant/cyclic dependency checks,
9613 + * which are marked at the abstract_pkg level
9615 + if(!(ab_pkg = pkg->parent)){
9616 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9617 + return (pkg_vec_t *)NULL;
9620 + conflicts = pkg->conflicts;
9622 + return (pkg_vec_t *)NULL;
9624 + installed_conflicts = pkg_vec_alloc();
9626 + count = pkg->conflicts_count;
9630 + /* foreach conflict */
9631 + for(i = 0; i < pkg->conflicts_count; i++){
9633 + possible_satisfiers = conflicts->possibilities;
9635 + /* foreach possible satisfier */
9636 + for(j = 0; j < conflicts->possibility_count; j++){
9637 + possible_satisfier = possible_satisfiers[j];
9638 + if (!possible_satisfier)
9639 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9640 + if (!possible_satisfier->pkg)
9641 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9642 + test_vec = possible_satisfier->pkg->pkgs;
9644 + /* pkg_vec found, it is an actual package conflict
9645 + * cruise this possiblity's pkg_vec looking for an installed version */
9646 + pkg_scouts = test_vec->pkgs;
9647 + for(k = 0; k < test_vec->len; k++){
9648 + pkg_scout = pkg_scouts[k];
9650 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9653 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9654 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9655 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9656 + pkg_vec_insert(installed_conflicts, pkg_scout);
9665 + if (installed_conflicts->len)
9666 + return installed_conflicts;
9667 + pkg_vec_free(installed_conflicts);
9668 + return (pkg_vec_t *)NULL;
9671 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9676 + if(depends->constraint == NONE)
9681 + parseVersion(temp, depends->version);
9683 + comparison = pkg_compare_versions(pkg, temp);
9687 + if((depends->constraint == EARLIER) &&
9690 + else if((depends->constraint == LATER) &&
9693 + else if(comparison == 0)
9695 + else if((depends->constraint == LATER_EQUAL) &&
9696 + (comparison >= 0))
9698 + else if((depends->constraint == EARLIER_EQUAL) &&
9699 + (comparison <= 0))
9705 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9707 + abstract_pkg_t *apkg = depend->pkg;
9708 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9709 + int n_providers = provider_apkgs->len;
9710 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9711 + pkg_vec_t *pkg_vec;
9716 + for (i = 0; i < n_providers; i++) {
9717 + abstract_pkg_t *papkg = apkgs[i];
9718 + pkg_vec = papkg->pkgs;
9720 + n_pkgs = pkg_vec->len;
9721 + for (j = 0; j < n_pkgs; j++) {
9722 + pkg_t *pkg = pkg_vec->pkgs[j];
9723 + if (version_constraints_satisfied(depend, pkg)) {
9732 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9734 + abstract_pkg_t *apkg = depend->pkg;
9735 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9736 + int n_providers = provider_apkgs->len;
9737 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9742 + for (i = 0; i < n_providers; i++) {
9743 + abstract_pkg_t *papkg = apkgs[i];
9744 + pkg_vec_t *pkg_vec = papkg->pkgs;
9746 + n_pkgs = pkg_vec->len;
9747 + for (j = 0; j < n_pkgs; j++) {
9748 + pkg_t *pkg = pkg_vec->pkgs[j];
9749 + if (version_constraints_satisfied(depend, pkg)) {
9750 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9759 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9762 + pkg_t ** pkgs = vec->pkgs;
9764 + for(i = 0; i < vec->len; i++)
9765 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9766 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9767 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9775 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9776 + * the same abstract package and 0 otherwise.
9778 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9780 + abstract_pkg_t **provides = pkg->provides;
9781 + int provides_count = pkg->provides_count;
9782 + abstract_pkg_t **replacee_provides = replacee->provides;
9783 + int replacee_provides_count = replacee->provides_count;
9785 + for (i = 0; i < provides_count; i++) {
9786 + abstract_pkg_t *apkg = provides[i];
9787 + for (j = 0; j < replacee_provides_count; j++) {
9788 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9789 + if (apkg == replacee_apkg)
9798 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9799 + * and 0 otherwise.
9801 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9803 + abstract_pkg_t **provides = pkg->provides;
9804 + int provides_count = pkg->provides_count;
9806 + for (i = 0; i < provides_count; i++) {
9807 + if (provides[i] == providee)
9814 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9817 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9819 + abstract_pkg_t **replaces = pkg->replaces;
9820 + int replaces_count = pkg->replaces_count;
9821 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9822 + int replacee_provides_count = pkg->provides_count; */
9824 + for (i = 0; i < replaces_count; i++) {
9825 + abstract_pkg_t *abstract_replacee = replaces[i];
9826 + for (j = 0; j < replaces_count; j++) {
9827 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9828 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9829 + if (replacee->provides[j] == abstract_replacee)
9838 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9841 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9843 + compound_depend_t *conflicts = pkg->conflicts;
9844 + int conflicts_count = pkg->conflicts_count;
9846 + for (i = 0; i < conflicts_count; i++) {
9847 + int possibility_count = conflicts[i].possibility_count;
9848 + struct depend **possibilities = conflicts[i].possibilities;
9849 + for (j = 0; j < possibility_count; j++) {
9850 + if (possibilities[j]->pkg == conflictee) {
9859 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9860 + * conflictee's provides and 0 otherwise.
9862 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9864 + compound_depend_t *conflicts = pkg->conflicts;
9865 + int conflicts_count = pkg->conflicts_count;
9866 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9867 + int conflictee_provides_count = conflictee->provides_count;
9869 + int possibility_count;
9870 + struct depend **possibilities;
9871 + abstract_pkg_t *possibility ;
9873 + for (i = 0; i < conflicts_count; i++) {
9874 + possibility_count = conflicts[i].possibility_count;
9875 + possibilities = conflicts[i].possibilities;
9876 + for (j = 0; j < possibility_count; j++) {
9877 + possibility = possibilities[j]->pkg;
9878 + for (k = 0; k < conflictee_provides_count; k++) {
9879 + if (possibility == conflictee_provides[k]) {
9888 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9890 + int oldlen = 0, newlen = 0;
9892 + register int i, j;
9897 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9898 + while(newstuff && newstuff[newlen]) newlen++;
9900 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9901 + if (result == NULL) {
9902 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9906 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9907 + *(result + i) = *(newstuff + j);
9909 + *(result + i) = NULL;
9915 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9916 + * this is null terminated, no count is carried around
9918 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9922 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9925 + while(the_lost && the_lost[count]) count++;
9927 + count++; /* need one to hold the null */
9928 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9929 + if (resized == NULL) {
9930 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9933 + resized[count - 1] = strdup(depend_str);
9934 + resized[count] = NULL;
9939 +void printDepends(pkg_t * pkg)
9941 + register int i, j;
9942 + compound_depend_t * depend;
9945 + count = pkg->pre_depends_count + pkg->depends_count;
9947 + depend = pkg->depends;
9949 + fprintf(stderr, "Depends pointer is NULL\n");
9952 + for(i = 0; i < count; i++){
9953 + fprintf(stderr, "%s has %d possibilities:\n",
9954 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9955 + depend->possibility_count);
9956 + for(j = 0; j < depend->possibility_count; j++)
9957 + fprintf(stderr, "\t%s version %s (%d)\n",
9958 + depend->possibilities[j]->pkg->name,
9959 + depend->possibilities[j]->version,
9960 + depend->possibilities[j]->constraint);
9965 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9967 + register int i, j;
9969 + /* every pkg provides itself */
9970 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9972 + if (!pkg->provides_count)
9975 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9976 + if (pkg->provides == NULL) {
9977 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9980 + pkg->provides[0] = ab_pkg;
9982 + // if (strcmp(ab_pkg->name, pkg->name))
9983 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9985 + for(i = 0; i < pkg->provides_count; i++){
9986 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9988 + pkg->provides[i+1] = provided_abpkg;
9991 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9996 +/* Abhaya: added conflicts support */
9997 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10000 + compound_depend_t * conflicts;
10002 + if (!pkg->conflicts_count)
10005 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10006 + pkg->conflicts_count);
10007 + if (conflicts == NULL) {
10008 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10011 + for (i = 0; i < pkg->conflicts_count; i++) {
10012 + conflicts->type = CONFLICTS;
10013 + parseDepends(conflicts, hash,
10014 + pkg->conflicts_str[i]);
10016 + for (j = 0; j < conflicts->possibility_count; j++) {
10017 + depend_t *possibility = conflicts->possibilities[j];
10018 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10019 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10027 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10029 + register int i, j;
10031 + if (!pkg->replaces_count)
10034 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10035 + if (pkg->replaces == NULL) {
10036 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10040 + // if (strcmp(ab_pkg->name, pkg->name))
10041 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10043 + for(i = 0; i < pkg->replaces_count; i++){
10044 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10046 + pkg->replaces[i] = old_abpkg;
10049 + if (!old_abpkg->replaced_by)
10050 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10051 + if ( old_abpkg->replaced_by == NULL ){
10054 + /* if a package pkg both replaces and conflicts old_abpkg,
10055 + * then add it to the replaced_by vector so that old_abpkg
10056 + * will be upgraded to ab_pkg automatically */
10057 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10058 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10063 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10067 + compound_depend_t * depends;
10069 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10072 + if (0 && pkg->pre_depends_count)
10073 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10074 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10075 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10076 + if (depends == NULL) {
10077 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10082 + for(i = 0; i < pkg->pre_depends_count; i++){
10083 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10084 + if (0 && pkg->pre_depends_count)
10085 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10086 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10087 + depends->type = PREDEPEND;
10091 + for(i = 0; i < pkg->recommends_count; i++){
10092 + parseDepends(depends, hash, pkg->recommends_str[i]);
10093 + if (0 && pkg->recommends_count)
10094 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10095 + pkg->recommends_str[i], depends, depends->possibility_count);
10096 + depends->type = RECOMMEND;
10100 + for(i = 0; i < pkg->suggests_count; i++){
10101 + parseDepends(depends, hash, pkg->suggests_str[i]);
10102 + if (0 && pkg->suggests_count)
10103 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10104 + pkg->suggests_str[i], depends, depends->possibility_count);
10105 + depends->type = SUGGEST;
10109 + for(i = 0; i < pkg->depends_count; i++){
10110 + parseDepends(depends, hash, pkg->depends_str[i]);
10111 + if (0 && pkg->depends_count)
10112 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10113 + pkg->depends_str[i], depends, depends->possibility_count);
10120 + * pkg_depend_string: returns the depends string specified by index.
10121 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10122 + * [0,npredepends) -> returns pre_depends_str[index]
10123 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10124 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10125 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10127 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10129 + if (pkg_index < pkg->pre_depends_count) {
10130 + return pkg->pre_depends_str[pkg_index];
10132 + pkg_index -= pkg->pre_depends_count;
10134 + if (pkg_index < pkg->recommends_count) {
10135 + return pkg->recommends_str[pkg_index];
10137 + pkg_index -= pkg->recommends_count;
10139 + if (pkg_index < pkg->suggests_count) {
10140 + return pkg->suggests_str[pkg_index];
10142 + pkg_index -= pkg->suggests_count;
10144 + if (pkg_index < pkg->depends_count) {
10145 + return pkg->depends_str[pkg_index];
10147 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10151 +void freeDepends(pkg_t *pkg)
10155 + if (pkg == NULL || pkg->depends == NULL) {
10159 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10160 + for (i=0; i < pkg->depends->possibility_count; i++) {
10161 + depend_deinit(pkg->depends->possibilities[i]);
10163 + free(pkg->depends->possibilities);
10164 + free(pkg->depends);
10165 + pkg->depends = NULL;
10168 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10170 + compound_depend_t * depends;
10171 + int count, othercount;
10172 + register int i, j;
10173 + abstract_pkg_t * ab_depend;
10174 + abstract_pkg_t ** temp;
10176 + count = pkg->pre_depends_count + pkg->depends_count;
10177 + depends = pkg->depends;
10179 + if (0 && pkg->pre_depends_count)
10180 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10181 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10182 + for (i = 0; i < count; i++) {
10183 + if (0 && pkg->pre_depends_count)
10184 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10185 + for (j = 0; j < depends->possibility_count; j++){
10186 + ab_depend = depends->possibilities[j]->pkg;
10187 + if(!ab_depend->depended_upon_by)
10188 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10190 + temp = ab_depend->depended_upon_by;
10198 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10199 + (othercount + 1) * sizeof(abstract_pkg_t *));
10200 + /* the array may have moved */
10201 + temp = ab_depend->depended_upon_by + othercount;
10208 +static depend_t * depend_init(void)
10210 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10212 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10215 + d->constraint = NONE;
10216 + d->version = NULL;
10222 +static void depend_deinit(depend_t *d)
10227 +static int parseDepends(compound_depend_t *compound_depend,
10228 + hash_table_t * hash, char * depend_str)
10230 + char * pkg_name, buffer[2048];
10231 + int num_of_ors = 0;
10233 + register char * src, * dest;
10234 + depend_t ** possibilities;
10236 + /* first count the number of ored possibilities for satisfying dependency */
10237 + src = depend_str;
10239 + if(*src++ == '|')
10242 + compound_depend->type = DEPEND;
10244 + compound_depend->possibility_count = num_of_ors + 1;
10245 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10246 + if (!possibilities)
10248 + compound_depend->possibilities = possibilities;
10250 + src = depend_str;
10251 + for(i = 0; i < num_of_ors + 1; i++){
10252 + possibilities[i] = depend_init();
10253 + if (!possibilities[i])
10255 + /* gobble up just the name first */
10258 + !isspace(*src) &&
10262 + *dest++ = *src++;
10264 + pkg_name = trim_alloc(buffer);
10265 + if (pkg_name == NULL )
10268 + /* now look at possible version info */
10270 + /* skip to next chars */
10271 + if(isspace(*src))
10272 + while(*src && isspace(*src)) src++;
10274 + /* extract constraint and version */
10277 + if(!strncmp(src, "<<", 2)){
10278 + possibilities[i]->constraint = EARLIER;
10281 + else if(!strncmp(src, "<=", 2)){
10282 + possibilities[i]->constraint = EARLIER_EQUAL;
10285 + else if(!strncmp(src, ">=", 2)){
10286 + possibilities[i]->constraint = LATER_EQUAL;
10289 + else if(!strncmp(src, ">>", 2)){
10290 + possibilities[i]->constraint = LATER;
10293 + else if(!strncmp(src, "=", 1)){
10294 + possibilities[i]->constraint = EQUAL;
10297 + /* should these be here to support deprecated designations; dpkg does */
10298 + else if(!strncmp(src, "<", 1)){
10299 + possibilities[i]->constraint = EARLIER_EQUAL;
10302 + else if(!strncmp(src, ">", 1)){
10303 + possibilities[i]->constraint = LATER_EQUAL;
10307 + /* now we have any constraint, pass space to version string */
10308 + while(isspace(*src)) src++;
10310 + /* this would be the version string */
10312 + while(*src && *src != ')')
10313 + *dest++ = *src++;
10316 + possibilities[i]->version = trim_alloc(buffer);
10317 + /* fprintf(stderr, "let's print the depends version string:");
10318 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10319 + if (possibilities[i]->version == NULL )
10324 + /* hook up the dependency to its abstract pkg */
10325 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10329 + /* now get past the ) and any possible | chars */
10331 + (isspace(*src) ||
10337 + compound_depend->type = GREEDY_DEPEND;
10344 Index: busybox-1.4.2/archival/libipkg/pkg_depends.h
10345 ===================================================================
10346 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10347 +++ busybox-1.4.2/archival/libipkg/pkg_depends.h 2007-06-04 13:21:36.724393712 +0200
10349 +/* pkg_depends.h - the itsy package management system
10353 + Copyright (C) 2002 Compaq Computer Corporation
10355 + This program is free software; you can redistribute it and/or
10356 + modify it under the terms of the GNU General Public License as
10357 + published by the Free Software Foundation; either version 2, or (at
10358 + your option) any later version.
10360 + This program is distributed in the hope that it will be useful, but
10361 + WITHOUT ANY WARRANTY; without even the implied warranty of
10362 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10363 + General Public License for more details.
10366 +#ifndef PKG_DEPENDS_H
10367 +#define PKG_DEPENDS_H
10370 +#include "pkg_hash.h"
10372 +enum depend_type {
10380 +typedef enum depend_type depend_type_t;
10382 +enum version_constraint {
10390 +typedef enum version_constraint version_constraint_t;
10393 + version_constraint_t constraint;
10395 + abstract_pkg_t * pkg;
10397 +typedef struct depend depend_t;
10399 +struct compound_depend{
10400 + depend_type_t type;
10401 + int possibility_count;
10402 + struct depend ** possibilities;
10404 +typedef struct compound_depend compound_depend_t;
10406 +#include "hash_table.h"
10408 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10409 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10410 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10411 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10414 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10415 + * the same abstract package and 0 otherwise.
10417 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10420 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10423 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10426 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10429 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10432 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10435 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10438 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10441 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10443 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10444 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10445 +void freeDepends(pkg_t *pkg);
10446 +void printDepends(pkg_t * pkg);
10447 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10448 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10449 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10450 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10451 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10454 Index: busybox-1.4.2/archival/libipkg/pkg_dest.c
10455 ===================================================================
10456 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10457 +++ busybox-1.4.2/archival/libipkg/pkg_dest.c 2007-06-04 13:21:36.725393560 +0200
10459 +/* pkg_dest.c - the itsy package management system
10463 + Copyright (C) 2001 University of Southern California
10465 + This program is free software; you can redistribute it and/or
10466 + modify it under the terms of the GNU General Public License as
10467 + published by the Free Software Foundation; either version 2, or (at
10468 + your option) any later version.
10470 + This program is distributed in the hope that it will be useful, but
10471 + WITHOUT ANY WARRANTY; without even the implied warranty of
10472 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10473 + General Public License for more details.
10478 +#include "pkg_dest.h"
10479 +#include "file_util.h"
10480 +#include "str_util.h"
10481 +#include "sprintf_alloc.h"
10483 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10485 + dest->name = strdup(name);
10487 + /* Guarantee that dest->root_dir ends with a '/' */
10488 + if (str_ends_with(root_dir, "/")) {
10489 + dest->root_dir = strdup(root_dir);
10491 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10493 + file_mkdir_hier(dest->root_dir, 0755);
10495 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10496 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10497 + file_mkdir_hier(dest->ipkg_dir, 0755);
10499 + if (str_starts_with (lists_dir, "/"))
10500 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10502 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10504 + file_mkdir_hier(dest->lists_dir, 0755);
10506 + sprintf_alloc(&dest->info_dir, "%s/%s",
10507 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10508 + file_mkdir_hier(dest->info_dir, 0755);
10510 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10511 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10513 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10514 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10516 + dest->status_file = NULL;
10521 +void pkg_dest_deinit(pkg_dest_t *dest)
10523 + free(dest->name);
10524 + dest->name = NULL;
10526 + free(dest->root_dir);
10527 + dest->root_dir = NULL;
10529 + free(dest->ipkg_dir);
10530 + dest->ipkg_dir = NULL;
10532 + free(dest->lists_dir);
10533 + dest->lists_dir = NULL;
10535 + free(dest->info_dir);
10536 + dest->info_dir = NULL;
10538 + free(dest->status_file_name);
10539 + dest->status_file_name = NULL;
10541 + free(dest->status_file_tmp_name);
10542 + dest->status_file_tmp_name = NULL;
10544 + if (dest->status_file) {
10545 + fclose(dest->status_file);
10547 + dest->status_file = NULL;
10549 + dest->root_dir = NULL;
10551 Index: busybox-1.4.2/archival/libipkg/pkg_dest.h
10552 ===================================================================
10553 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10554 +++ busybox-1.4.2/archival/libipkg/pkg_dest.h 2007-06-04 13:21:36.725393560 +0200
10556 +/* pkg_dest.h - the itsy package management system
10560 + Copyright (C) 2001 University of Southern California
10562 + This program is free software; you can redistribute it and/or
10563 + modify it under the terms of the GNU General Public License as
10564 + published by the Free Software Foundation; either version 2, or (at
10565 + your option) any later version.
10567 + This program is distributed in the hope that it will be useful, but
10568 + WITHOUT ANY WARRANTY; without even the implied warranty of
10569 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10570 + General Public License for more details.
10573 +#ifndef PKG_DEST_H
10574 +#define PKG_DEST_H
10576 +typedef struct pkg_dest pkg_dest_t;
10584 + char *status_file_name;
10585 + char *status_file_tmp_name;
10586 + FILE *status_file;
10589 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10590 +void pkg_dest_deinit(pkg_dest_t *dest);
10594 Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.c
10595 ===================================================================
10596 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10597 +++ busybox-1.4.2/archival/libipkg/pkg_dest_list.c 2007-06-04 13:21:36.725393560 +0200
10599 +/* pkg_dest_list.c - the itsy package management system
10603 + Copyright (C) 2001 University of Southern California
10605 + This program is free software; you can redistribute it and/or
10606 + modify it under the terms of the GNU General Public License as
10607 + published by the Free Software Foundation; either version 2, or (at
10608 + your option) any later version.
10610 + This program is distributed in the hope that it will be useful, but
10611 + WITHOUT ANY WARRANTY; without even the implied warranty of
10612 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10613 + General Public License for more details.
10618 +#include "pkg_dest.h"
10619 +#include "void_list.h"
10620 +#include "pkg_dest_list.h"
10622 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10624 + return void_list_elt_init((void_list_elt_t *) elt, data);
10627 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10629 + void_list_elt_deinit((void_list_elt_t *) elt);
10632 +int pkg_dest_list_init(pkg_dest_list_t *list)
10634 + return void_list_init((void_list_t *) list);
10637 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10639 + pkg_dest_list_elt_t *iter;
10640 + pkg_dest_t *pkg_dest;
10642 + for (iter = list->head; iter; iter = iter->next) {
10643 + pkg_dest = iter->data;
10644 + pkg_dest_deinit(pkg_dest);
10646 + /* malloced in pkg_dest_list_append */
10648 + iter->data = NULL;
10650 + void_list_deinit((void_list_t *) list);
10653 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10654 + const char *root_dir,const char *lists_dir)
10657 + pkg_dest_t *pkg_dest;
10659 + /* freed in plg_dest_list_deinit */
10660 + pkg_dest = malloc(sizeof(pkg_dest_t));
10661 + if (pkg_dest == NULL) {
10662 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10666 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10667 + err = void_list_append((void_list_t *) list, pkg_dest);
10675 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10677 + return void_list_push((void_list_t *) list, data);
10680 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10682 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10684 Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.h
10685 ===================================================================
10686 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10687 +++ busybox-1.4.2/archival/libipkg/pkg_dest_list.h 2007-06-04 13:21:36.725393560 +0200
10689 +/* pkg_dest_list.h - the itsy package management system
10693 + Copyright (C) 2001 University of Southern California
10695 + This program is free software; you can redistribute it and/or
10696 + modify it under the terms of the GNU General Public License as
10697 + published by the Free Software Foundation; either version 2, or (at
10698 + your option) any later version.
10700 + This program is distributed in the hope that it will be useful, but
10701 + WITHOUT ANY WARRANTY; without even the implied warranty of
10702 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10703 + General Public License for more details.
10706 +#ifndef PKG_DEST_LIST_H
10707 +#define PKG_DEST_LIST_H
10709 +#include "pkg_dest.h"
10711 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10712 +struct pkg_dest_list_elt
10714 + pkg_dest_list_elt_t *next;
10715 + pkg_dest_t *data;
10718 +typedef struct pkg_dest_list pkg_dest_list_t;
10719 +struct pkg_dest_list
10721 + pkg_dest_list_elt_t pre_head;
10722 + pkg_dest_list_elt_t *head;
10723 + pkg_dest_list_elt_t *tail;
10726 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10727 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10729 +int pkg_dest_list_init(pkg_dest_list_t *list);
10730 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10732 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10733 + const char *root_dir,const char* lists_dir);
10734 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10735 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10739 Index: busybox-1.4.2/archival/libipkg/pkg_extract.c
10740 ===================================================================
10741 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10742 +++ busybox-1.4.2/archival/libipkg/pkg_extract.c 2007-06-04 13:21:36.726393408 +0200
10744 +/* pkg_extract.c - the itsy package management system
10748 + Copyright (C) 2001 University of Southern California
10750 + This program is free software; you can redistribute it and/or
10751 + modify it under the terms of the GNU General Public License as
10752 + published by the Free Software Foundation; either version 2, or (at
10753 + your option) any later version.
10755 + This program is distributed in the hope that it will be useful, but
10756 + WITHOUT ANY WARRANTY; without even the implied warranty of
10757 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10758 + General Public License for more details.
10762 +#include <errno.h>
10763 +#include <fcntl.h>
10764 +#include <stdio.h>
10766 +#include "pkg_extract.h"
10768 +#include "libbb.h"
10769 +#include "file_util.h"
10770 +#include "sprintf_alloc.h"
10771 +#include "unarchive.h"
10773 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10774 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10775 +#define IPKG_CONTROL_FILE "control"
10777 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10779 + archive_handle_t *archive;
10782 + sprintf_alloc(&path, "%s/", dir);
10783 + archive = init_handle();
10784 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10785 + archive->filter = filter_accept_list;
10786 + llist_add_to(&(archive->accept), (char *)filename);
10787 + archive->buffer = path;
10788 + archive->action_data = data_extract_all_prefix;
10789 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10790 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10791 + close(archive->src_fd);
10792 + free(archive->accept);
10797 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10799 + unsigned int size = strlen(archive->file_header->name) + 2;
10801 + if (archive->buffer == NULL) {
10802 + archive->buffer = xmalloc(size);
10803 + strcpy(archive->buffer, archive->file_header->name);
10805 + size += strlen(archive->buffer);
10806 + archive->buffer = xrealloc(archive->buffer, size);
10807 + strcat(archive->buffer, archive->file_header->name);
10809 + strcat(archive->buffer, "\n");
10810 + data_skip(archive);
10813 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10815 + archive_handle_t *archive;
10818 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10819 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10820 + archive = init_handle();
10821 + archive->src_fd = xopen(name, O_RDONLY);
10822 + archive->filter = filter_accept_list;
10823 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10824 + archive->action_data = data_extract_to_buffer;
10825 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10826 + close(archive->src_fd);
10827 + fputs(archive->buffer, stream);
10828 + free(archive->buffer);
10829 + free(archive->accept);
10836 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10838 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10841 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10843 + archive_handle_t *archive;
10847 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10848 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10849 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10850 + archive = init_handle();
10851 + archive->src_fd = xopen(name, O_RDONLY);
10852 + archive->filter = filter_accept_all;
10853 + archive->buffer = path;
10854 + archive->action_data = data_extract_all_prefix;
10855 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10856 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10857 + close(archive->src_fd);
10865 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10867 + archive_handle_t *archive;
10871 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10872 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10873 + sprintf_alloc(&path, "%s/", dir);
10874 + archive = init_handle();
10875 + archive->src_fd = xopen(name, O_RDONLY);
10876 + archive->filter = filter_accept_all;
10877 + archive->buffer = path;
10878 + archive->action_data = data_extract_all_prefix;
10879 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10880 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10881 + close(archive->src_fd);
10889 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10892 + char *line, *data_file;
10896 + file = fopen(file_name, "w");
10897 + if (file == NULL) {
10898 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10899 + __FUNCTION__, file_name);
10904 + if (pkg->installed_files) {
10905 + str_list_elt_t *elt;
10906 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10907 + fprintf(file, "%s\n", elt->data);
10910 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10917 + /* Fixup data file names by removing the initial '.' */
10920 + line = file_read_line_alloc(tmp);
10921 + if (line == NULL) {
10925 + data_file = line;
10926 + if (*data_file == '.') {
10930 + if (*data_file != '/') {
10931 + fputs("/", file);
10934 + /* I have no idea why, but this is what dpkg does */
10935 + if (strcmp(data_file, "/\n") == 0) {
10936 + fputs("/.\n", file);
10938 + fputs(data_file, file);
10948 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10950 + archive_handle_t *archive;
10953 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10954 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10955 + archive = init_handle();
10956 + archive->src_fd = xopen(name, O_RDONLY);
10957 + archive->filter = filter_accept_all;
10958 + archive->action_data = data_extract_file_name_to_buffer;
10959 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10960 + close(archive->src_fd);
10961 + fputs(archive->buffer, file);
10962 + free(archive->buffer);
10968 Index: busybox-1.4.2/archival/libipkg/pkg_extract.h
10969 ===================================================================
10970 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10971 +++ busybox-1.4.2/archival/libipkg/pkg_extract.h 2007-06-04 13:21:36.726393408 +0200
10973 +/* pkg_extract.c - the itsy package management system
10977 + Copyright (C) 2001 University of Southern California
10979 + This program is free software; you can redistribute it and/or
10980 + modify it under the terms of the GNU General Public License as
10981 + published by the Free Software Foundation; either version 2, or (at
10982 + your option) any later version.
10984 + This program is distributed in the hope that it will be useful, but
10985 + WITHOUT ANY WARRANTY; without even the implied warranty of
10986 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10987 + General Public License for more details.
10990 +#ifndef PKG_EXTRACT_H
10991 +#define PKG_EXTRACT_H
10995 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10996 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10997 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
10999 + const char *prefix);
11000 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11001 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11002 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11005 Index: busybox-1.4.2/archival/libipkg/pkg.h
11006 ===================================================================
11007 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11008 +++ busybox-1.4.2/archival/libipkg/pkg.h 2007-06-04 13:21:36.726393408 +0200
11010 +/* pkg.h - the itsy package management system
11014 + Copyright (C) 2001 University of Southern California
11016 + This program is free software; you can redistribute it and/or
11017 + modify it under the terms of the GNU General Public License as
11018 + published by the Free Software Foundation; either version 2, or (at
11019 + your option) any later version.
11021 + This program is distributed in the hope that it will be useful, but
11022 + WITHOUT ANY WARRANTY; without even the implied warranty of
11023 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11024 + General Public License for more details.
11030 +#include <sys/types.h>
11031 +#include <sys/stat.h>
11032 +#include <unistd.h>
11034 +#include "pkg_vec.h"
11035 +#include "str_list.h"
11036 +#include "pkg_src.h"
11037 +#include "pkg_dest.h"
11038 +#include "ipkg_conf.h"
11039 +#include "conffile_list.h"
11044 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11046 +/* I think "Size" is currently the shortest field name */
11047 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11049 +enum pkg_state_want
11055 + SW_LAST_STATE_WANT
11057 +typedef enum pkg_state_want pkg_state_want_t;
11059 +enum pkg_state_flag
11062 + SF_REINSTREQ = 1,
11063 + SF_HOLD = 2, /* do not upgrade version */
11064 + SF_REPLACE = 4, /* replace this package */
11065 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11066 + SF_PREFER = 16, /* prefer this version */
11067 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11068 + SF_MARKED = 64, /* temporary mark */
11069 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11071 + SF_LAST_STATE_FLAG
11073 +typedef enum pkg_state_flag pkg_state_flag_t;
11074 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11076 +enum pkg_state_status
11078 + SS_NOT_INSTALLED = 1,
11080 + SS_HALF_CONFIGURED,
11082 + SS_HALF_INSTALLED,
11084 + SS_POST_INST_FAILED,
11085 + SS_REMOVAL_FAILED,
11086 + SS_LAST_STATE_STATUS
11088 +typedef enum pkg_state_status pkg_state_status_t;
11090 +struct abstract_pkg{
11092 + int dependencies_checked;
11093 + pkg_vec_t * pkgs;
11094 + pkg_state_status_t state_status;
11095 + pkg_state_flag_t state_flag;
11096 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11097 + abstract_pkg_vec_t * provided_by;
11098 + abstract_pkg_vec_t * replaced_by;
11101 +#include "pkg_depends.h"
11103 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11105 + The 3 version fields should go into a single version struct. (This
11106 + is especially important since, currently, pkg->version can easily
11107 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11108 + distinct. This has been the source of multiple bugs.
11110 + The 3 state fields could possibly also go into their own struct.
11112 + All fields which deal with lists of packages, (Depends,
11113 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11114 + be handled by a single struct in pkg_t
11116 + All string fields for which there is a small set of possible
11117 + values, (section, maintainer, architecture, maybe version?), that
11118 + are reused among different packages -- for all such packages we
11119 + should move from "char *"s to some atom datatype to share data
11120 + storage and use less memory. We might even do reference counting,
11121 + but probably not since most often we only create new pkg_t structs,
11122 + we don't often free them. */
11126 + unsigned long epoch;
11129 + char *familiar_revision;
11131 + pkg_dest_t *dest;
11132 + char *architecture;
11134 + char *maintainer;
11135 + char *description;
11136 + pkg_state_want_t state_want;
11137 + pkg_state_flag_t state_flag;
11138 + pkg_state_status_t state_status;
11139 + char **depends_str;
11140 + int depends_count;
11141 + char **pre_depends_str;
11142 + int pre_depends_count;
11143 + char **recommends_str;
11144 + int recommends_count;
11145 + char **suggests_str;
11146 + int suggests_count;
11147 + compound_depend_t * depends;
11149 + /* Abhaya: new conflicts */
11150 + char **conflicts_str;
11151 + compound_depend_t * conflicts;
11152 + int conflicts_count;
11154 + char **replaces_str;
11155 + int replaces_count;
11156 + abstract_pkg_t ** replaces;
11158 + char **provides_str;
11159 + int provides_count;
11160 + abstract_pkg_t ** provides;
11162 + abstract_pkg_t *parent;
11164 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11167 + char *local_filename;
11169 + char *tmp_unpack_dir;
11172 + char *installed_size;
11175 + conffile_list_t conffiles;
11176 + time_t installed_time;
11177 + /* As pointer for lazy evaluation */
11178 + str_list_t *installed_files;
11179 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11180 + mechanism to avoid the problem here, (which is that the
11181 + installed_files list was being freed from an inner loop while
11182 + still being used within an outer loop. */
11183 + int installed_files_ref_cnt;
11185 + int arch_priority;
11186 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11187 + int provided_by_hand;
11190 +pkg_t *pkg_new(void);
11191 +int pkg_init(pkg_t *pkg);
11192 +void pkg_deinit(pkg_t *pkg);
11193 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11194 +abstract_pkg_t *abstract_pkg_new(void);
11195 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11198 + * merges fields from newpkg into oldpkg.
11199 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11201 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11203 +char *pkg_version_str_alloc(pkg_t *pkg);
11205 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11206 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11207 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11209 +char * pkg_formatted_info(pkg_t *pkg );
11210 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11212 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11214 +void pkg_print_info(pkg_t *pkg, FILE *file);
11215 +void pkg_print_status(pkg_t * pkg, FILE * file);
11216 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11217 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11218 +int pkg_free_installed_files(pkg_t *pkg);
11219 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11220 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11221 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11222 + const char *script, const char *args);
11224 +/* enum mappings */
11225 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11226 +pkg_state_want_t pkg_state_want_from_str(char *str);
11227 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11228 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11229 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11230 +pkg_state_status_t pkg_state_status_from_str(char *str);
11232 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11234 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11235 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11236 +int pkg_free_installed_files(pkg_t *pkg);
11238 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11239 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11242 Index: busybox-1.4.2/archival/libipkg/pkg_hash.c
11243 ===================================================================
11244 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11245 +++ busybox-1.4.2/archival/libipkg/pkg_hash.c 2007-06-04 13:21:36.727393256 +0200
11247 +/* ipkg_hash.c - the itsy package management system
11251 + Copyright (C) 2002 Compaq Computer Corporation
11253 + This program is free software; you can redistribute it and/or
11254 + modify it under the terms of the GNU General Public License as
11255 + published by the Free Software Foundation; either version 2, or (at
11256 + your option) any later version.
11258 + This program is distributed in the hope that it will be useful, but
11259 + WITHOUT ANY WARRANTY; without even the implied warranty of
11260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11261 + General Public License for more details.
11265 +#include <errno.h>
11266 +#include <ctype.h>
11267 +#include <stdlib.h>
11268 +#include <string.h>
11270 +#include "hash_table.h"
11272 +#include "ipkg_message.h"
11273 +#include "pkg_vec.h"
11274 +#include "pkg_hash.h"
11275 +#include "pkg_parse.h"
11276 +#include "ipkg_utils.h"
11278 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11281 + * this will talk to both feeds-lists files and installed status files
11284 + * hash_table_t hash;
11285 + * pkg_hash_init(name, &hash, 1000);
11286 + * pkg_hash_add_from_file(<feed filename>);
11288 + * the query function is just there as a shell to prove to me that this
11289 + * sort of works, but isn't far from doing something useful
11292 + * modified: CDW 3 Jan. 2002
11297 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11299 + return hash_table_init(name, hash, len);
11302 +void pkg_hash_deinit(hash_table_t *hash)
11304 + hash_table_deinit(hash);
11308 +/* Find the default arch for a given package status file if none is given. */
11309 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11311 + nv_pair_list_elt_t *l;
11312 + char *def_arch = HOST_CPU_STR; /* Default arch */
11313 + int def_prio = 0; /* Other archs override this */
11315 + l = conf->arch_list.head;
11318 + nv_pair_t *nv = l->data;
11319 + int priority = strtol(nv->value, NULL, 0);
11321 + /* Check if this arch has higher priority, and is valid */
11322 + if ((priority > def_prio) &&
11323 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11324 + /* Our new default */
11325 + def_prio = priority;
11326 + def_arch = nv->name;
11331 + return strdup(def_arch);
11334 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11335 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11337 + hash_table_t *hash = &conf->pkg_hash;
11339 + char **raw_start;
11342 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11346 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11351 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11352 + if (!pkg->architecture) {
11353 + char *version_str = pkg_version_str_alloc(pkg);
11354 + pkg->architecture = pkg_get_default_arch(conf);
11355 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11356 + pkg->name, version_str, pkg->architecture);
11357 + free(version_str);
11359 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11365 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11366 + memory after read_raw_pkgs_from_file */
11375 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11377 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11380 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11382 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11385 + return apkg->provided_by;
11389 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11390 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11393 + int nprovides = 0;
11394 + int nmatching = 0;
11395 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11396 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11397 + abstract_pkg_vec_t *provided_apkg_vec;
11398 + abstract_pkg_t **provided_apkgs;
11399 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11400 + pkg_t *latest_installed_parent = NULL;
11401 + pkg_t *latest_matching = NULL;
11402 + pkg_t *held_pkg = NULL;
11403 + pkg_t *good_pkg_by_name = NULL;
11405 + if (matching_apkgs == NULL || providers == NULL ||
11406 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11409 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11411 + provided_apkg_vec = apkg->provided_by;
11412 + nprovides = provided_apkg_vec->len;
11413 + provided_apkgs = provided_apkg_vec->pkgs;
11414 + if (nprovides > 1)
11415 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11417 + /* accumulate all the providers */
11418 + for (i = 0; i < nprovides; i++) {
11419 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11420 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11421 + abstract_pkg_vec_insert(providers, provider_apkg);
11423 + nprovides = providers->len;
11425 + for (i = 0; i < nprovides; i++) {
11426 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11427 + abstract_pkg_t *replacement_apkg = NULL;
11430 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11431 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11432 + if (provider_apkg->replaced_by->len > 1) {
11433 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11434 + provider_apkg->name, replacement_apkg->name);
11438 + if (replacement_apkg)
11439 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11440 + replacement_apkg->name, provider_apkg->name);
11442 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11443 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11446 + provider_apkg = replacement_apkg;
11449 + if (!(vec = provider_apkg->pkgs)) {
11450 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11455 + /* now check for supported architecture */
11457 + int max_count = 0;
11459 + /* count packages matching max arch priority and keep track of last one */
11460 + for (j = 0; j < vec->len; j++) {
11461 + pkg_t *maybe = vec->pkgs[j];
11462 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11463 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11464 + if (maybe->arch_priority > 0) {
11466 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11467 + pkg_vec_insert(matching_pkgs, maybe);
11473 + if (matching_pkgs->len > 1)
11474 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11475 + if (matching_apkgs->len > 1)
11476 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11478 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11479 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11480 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11481 + Until now I always got the latest, but that breaks the downgrade option.
11482 + If I stop at the first one, I would probably miss the new ones
11483 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11484 + or from a Packages feed.
11485 + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
11488 + for (i = 0; i < matching_pkgs->len; i++) {
11489 + pkg_t *matching = matching_pkgs->pkgs[i];
11490 + if (constraint_fcn(matching, cdata)) { /* We found it */
11491 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11492 + good_pkg_by_name = matching;
11493 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11499 + for (i = 0; i < matching_pkgs->len; i++) {
11500 + pkg_t *matching = matching_pkgs->pkgs[i];
11501 + latest_matching = matching;
11502 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11503 + latest_installed_parent = matching;
11504 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11506 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11507 + held_pkg->name, matching->name);
11508 + held_pkg = matching;
11512 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11513 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11514 + apkg->name, matching_apkgs->len);
11515 + for (i = 0; i < matching_apkgs->len; i++) {
11516 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11517 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11519 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11522 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11523 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11524 + __FUNCTION__, apkg->name, matching_pkgs->len);
11525 + for (i = 0; i < matching_pkgs->len; i++) {
11526 + pkg_t *matching = matching_pkgs->pkgs[i];
11527 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11528 + matching->name, matching->version, matching->architecture);
11532 + nmatching = matching_apkgs->len;
11534 + pkg_vec_free(matching_pkgs);
11535 + abstract_pkg_vec_free(matching_apkgs);
11536 + abstract_pkg_vec_free(providers);
11538 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11539 + return good_pkg_by_name;
11542 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11545 + if (latest_installed_parent) {
11546 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11547 + return latest_installed_parent;
11549 + if (nmatching > 1) {
11550 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11553 + if (latest_matching) {
11554 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11555 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11556 + return latest_matching;
11561 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11563 + const char *name = (const char *)cdata;
11564 + if (strcmp(pkg->name, name) == 0)
11570 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11572 + hash_table_t *hash = &conf->pkg_hash;
11573 + abstract_pkg_t *apkg = NULL;
11575 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11578 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11582 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11583 + const char *pkg_name,
11584 + const char * version)
11588 + char *version_str = NULL;
11590 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11593 + for(i = 0; i < vec->len; i++) {
11594 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11595 + if(!strcmp(version_str, version)) {
11596 + free(version_str);
11599 + free(version_str);
11602 + if(i == vec->len)
11605 + return vec->pkgs[i];
11608 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11609 + const char *pkg_name,
11610 + pkg_dest_t *dest)
11615 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11619 + for(i = 0; i < vec->len; i++)
11620 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11621 + return vec->pkgs[i];
11626 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11627 + const char *pkg_name)
11632 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11636 + for(i = 0; i < vec->len; i++)
11637 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11638 + return vec->pkgs[i];
11644 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11646 + abstract_pkg_t * ab_pkg;
11648 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11652 + if (ab_pkg->pkgs) {
11653 + return ab_pkg->pkgs;
11654 + } else if (ab_pkg->provided_by) {
11655 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11656 + if (abpkg != NULL){
11657 + return abpkg->pkgs;
11659 + return ab_pkg->pkgs;
11666 +static int pkg_compare_names(const void *p1, const void *p2)
11668 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11669 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11670 + if (pkg1->name == NULL)
11672 + if (pkg2->name == NULL)
11674 + return(strcmp(pkg1->name, pkg2->name));
11678 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11681 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11682 + pkg_vec_t *all = (pkg_vec_t *)data;
11683 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11685 + for (j = 0; j < pkg_vec->len; j++) {
11686 + pkg_t *pkg = pkg_vec->pkgs[j];
11687 + pkg_vec_insert(all, pkg);
11692 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11694 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11695 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11698 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11700 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11701 + pkg_vec_t *all = (pkg_vec_t *)data;
11702 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11705 + for (j = 0; j < pkg_vec->len; j++) {
11706 + pkg_t *pkg = pkg_vec->pkgs[j];
11707 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11708 + pkg_vec_insert(all, pkg);
11713 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11715 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11716 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11719 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11723 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11724 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11725 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11726 + fprintf(stdout, "%s\n", ab_pkg->name);
11728 + if (dependents != NULL)
11729 + while (dependents [i] != NULL)
11730 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11731 + dependents = ab_pkg->provided_by->pkgs;
11733 + if (dependents != NULL)
11734 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11735 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11736 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11739 + while (i < pkg->depends_count)
11740 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11743 +void pkg_hash_dump(hash_table_t *hash, void *data)
11746 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11747 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11748 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11751 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11753 + abstract_pkg_t * ab_pkg;
11755 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11756 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11761 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11763 + abstract_pkg_t * ab_pkg;
11764 + int arch_priority;
11769 + arch_priority = pkg->arch_priority;
11771 + if (buildDepends(hash, pkg)<0){
11772 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11775 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11777 + if (set_status) {
11778 + if (pkg->state_status == SS_INSTALLED) {
11779 + ab_pkg->state_status = SS_INSTALLED;
11780 + } else if (pkg->state_status == SS_UNPACKED) {
11781 + ab_pkg->state_status = SS_UNPACKED;
11785 + if(!ab_pkg->pkgs)
11786 + ab_pkg->pkgs = pkg_vec_alloc();
11788 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11789 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11790 + pkg->parent = ab_pkg;
11792 + if (buildProvides(hash, ab_pkg, pkg)<0){
11793 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11796 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11797 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11798 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11801 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11802 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11806 + buildDependedUponBy(pkg, ab_pkg);
11811 + * this will assume that we've already determined that
11812 + * the abstract pkg doesn't exist, 'cause we should know these things...
11814 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11816 + abstract_pkg_t * ab_pkg;
11818 + ab_pkg = abstract_pkg_new();
11819 + if (ab_pkg == NULL) { return NULL; }
11821 + ab_pkg->name = strdup(pkg_name);
11822 + hash_table_insert(hash, pkg_name, ab_pkg);
11828 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11830 + hash_table_t *file_hash = &conf->file_hash;
11832 + return hash_table_get(file_hash, file_name);
11835 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11837 + hash_table_t *file_hash = &conf->file_hash;
11838 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11839 + int file_name_len = strlen(file_name);
11841 + if (file_name[file_name_len -1] == '/')
11844 + if (conf->offline_root) {
11845 + int len = strlen(conf->offline_root);
11846 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11847 + file_name += len;
11851 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11852 + hash_table_insert(file_hash, file_name, owning_pkg);
11853 + if (old_owning_pkg) {
11854 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11855 + /* mark this package to have its filelist written */
11856 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11857 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11863 Index: busybox-1.4.2/archival/libipkg/pkg_hash.h
11864 ===================================================================
11865 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11866 +++ busybox-1.4.2/archival/libipkg/pkg_hash.h 2007-06-04 13:21:36.727393256 +0200
11868 +/* pkg_hash.h - the itsy package management system
11872 + Copyright (C) 2002 Compaq Computer Corporation
11874 + This program is free software; you can redistribute it and/or
11875 + modify it under the terms of the GNU General Public License as
11876 + published by the Free Software Foundation; either version 2, or (at
11877 + your option) any later version.
11879 + This program is distributed in the hope that it will be useful, but
11880 + WITHOUT ANY WARRANTY; without even the implied warranty of
11881 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11882 + General Public License for more details.
11885 +#ifndef PKG_HASH_H
11886 +#define PKG_HASH_H
11889 +#include "pkg_vec.h"
11890 +#include "hash_table.h"
11893 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11894 +void pkg_hash_deinit(hash_table_t *hash);
11895 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11897 +void pkg_hash_dump(hash_table_t *hash, void *data);
11898 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11900 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11901 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11902 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11904 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11905 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11906 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11907 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11908 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11909 + const char *pkg_name,
11910 + const char * version);
11911 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11912 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11913 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11914 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11915 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11916 + const char *pkg_name);
11917 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11918 + const char *pkg_name,
11919 + pkg_dest_t *dest);
11921 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11922 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11924 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11925 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11929 Index: busybox-1.4.2/archival/libipkg/pkg_parse.c
11930 ===================================================================
11931 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11932 +++ busybox-1.4.2/archival/libipkg/pkg_parse.c 2007-06-04 13:21:36.727393256 +0200
11934 +/* pkg_parse.c - the itsy package management system
11938 + Copyright (C) 2002 Compaq Computer Corporation
11940 + This program is free software; you can redistribute it and/or
11941 + modify it under the terms of the GNU General Public License as
11942 + published by the Free Software Foundation; either version 2, or (at
11943 + your option) any later version.
11945 + This program is distributed in the hope that it will be useful, but
11946 + WITHOUT ANY WARRANTY; without even the implied warranty of
11947 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11948 + General Public License for more details.
11952 +#include <errno.h>
11953 +#include <ctype.h>
11956 +#include "ipkg_utils.h"
11957 +#include "pkg_parse.h"
11959 +int isGenericFieldType(char * type, char * line)
11961 + if(!strncmp(line, type, strlen(type)))
11966 +char * parseGenericFieldType(char * type, char * raw)
11968 + char * field_value = raw + (strlen(type) + 1);
11969 + return trim_alloc(field_value);
11972 +void parseStatus(pkg_t *pkg, char * raw)
11974 + char sw_str[64], sf_str[64], ss_str[64];
11976 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11977 + pkg->state_want = pkg_state_want_from_str(sw_str);
11978 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11979 + pkg->state_status = pkg_state_status_from_str(ss_str);
11982 +char ** parseDependsString(char * raw, int * depends_count)
11984 + char ** depends = NULL;
11985 + int line_count = 0;
11986 + char buff[2048], * dest;
11988 + while(raw && *raw && !isspace(*raw)) {
11992 + if(line_is_blank(raw)){
11993 + *depends_count = line_count;
11996 + while(raw && *raw){
11997 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11999 + while(isspace(*raw)) raw++;
12002 + while((*raw != ',') && *raw)
12003 + *dest++ = *raw++;
12006 + depends[line_count] = trim_alloc(buff);
12007 + if(depends[line_count] ==NULL)
12013 + *depends_count = line_count;
12017 +void parseConffiles(pkg_t * pkg, char * raw)
12019 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12021 + if(!strncmp(raw, "Conffiles:", 10))
12022 + raw += strlen("Conffiles:");
12024 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12025 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12026 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12027 + while (*raw && isspace(*raw)) {
12030 + raw += strlen(file_name);
12031 + while (*raw && isspace(*raw)) {
12034 + raw += strlen(md5sum);
12038 +int parseVersion(pkg_t *pkg, char *raw)
12040 + char *colon, *eepochcolon;
12041 +#ifdef USE_DEBVERSION
12044 + unsigned long epoch;
12047 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12051 + if (strncmp(raw, "Version:", 8) == 0) {
12054 + while (*raw && isspace(*raw)) {
12058 + colon= strchr(raw,':');
12060 + epoch= strtoul(raw,&eepochcolon,10);
12061 + if (colon != eepochcolon) {
12062 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12066 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12070 + pkg->epoch= epoch;
12075 + pkg->revision = "";
12076 + pkg->familiar_revision = "";
12078 + pkg->version= malloc(strlen(raw)+1);
12079 + if ( pkg->version == NULL ) {
12080 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12083 + strcpy(pkg->version, raw);
12085 +#ifdef USE_DEBVERSION
12086 + hyphen= strrchr(pkg->version,'-');
12090 + if (strncmp("fam", hyphen, 3) == 0) {
12091 + pkg->familiar_revision=hyphen+3;
12092 + hyphen= strrchr(pkg->version,'-');
12095 + pkg->revision = hyphen;
12098 + pkg->revision = hyphen;
12104 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12108 + pkg->familiar_revision);
12115 +/* This code is needed to insert in first position the keyword for the aligning bug */
12117 +int alterProvidesLine(char *raw, char *temp)
12122 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12126 + if ( temp == NULL ) {
12127 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12131 + if (strncmp(raw, "Provides:", 9) == 0) {
12134 + while (*raw && isspace(*raw)) {
12138 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12140 + strncat( temp, raw++, 1);
12146 +/* Some random thoughts from Carl:
12148 + This function could be considerably simplified if we just kept
12149 + an array of all the generic string-valued field names, and looped
12150 + through those looking for a match. Also, these fields could perhaps
12151 + be stored in the package as an array as well, (or, probably better,
12152 + as an nv_pair_list_t).
12154 + Fields which require special parsing or storage, (such as Depends:
12155 + and Status:) could be handled as they are now.
12157 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12158 + to a dependency list. And, since we already have
12159 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12160 + Enhances, perhaps we could generalize all of these and save some
12161 + code duplication.
12163 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12165 + int reading_conffiles, reading_description;
12166 + int pkg_false_provides=1;
12168 + char * provide=NULL;
12171 + pkg->dest = dest;
12173 + reading_conffiles = reading_description = 0;
12175 + for (lines = *raw; *lines; lines++) {
12176 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12177 + if(isGenericFieldType("Package:", *lines))
12178 + pkg->name = parseGenericFieldType("Package", *lines);
12179 + else if(isGenericFieldType("Architecture:", *lines))
12180 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12181 + else if(isGenericFieldType("Filename:", *lines))
12182 + pkg->filename = parseGenericFieldType("Filename", *lines);
12183 + else if(isGenericFieldType("Section:", *lines))
12184 + pkg->section = parseGenericFieldType("Section", *lines);
12185 + else if(isGenericFieldType("MD5sum:", *lines))
12186 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12187 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12188 + let's parse it either way */
12189 + else if(isGenericFieldType("MD5Sum:", *lines))
12190 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12191 + else if(isGenericFieldType("Size:", *lines))
12192 + pkg->size = parseGenericFieldType("Size", *lines);
12193 + else if(isGenericFieldType("Source:", *lines))
12194 + pkg->source = parseGenericFieldType("Source", *lines);
12195 + else if(isGenericFieldType("Installed-Size:", *lines))
12196 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12197 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12198 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12199 + pkg->installed_time = strtoul(time_str, NULL, 0);
12200 + } else if(isGenericFieldType("Priority:", *lines))
12201 + pkg->priority = parseGenericFieldType("Priority", *lines);
12202 + else if(isGenericFieldType("Essential:", *lines)) {
12203 + char *essential_value;
12204 + essential_value = parseGenericFieldType("Essential", *lines);
12205 + if (strcmp(essential_value, "yes") == 0) {
12206 + pkg->essential = 1;
12208 + free(essential_value);
12210 + else if(isGenericFieldType("Status", *lines))
12211 + parseStatus(pkg, *lines);
12212 + else if(isGenericFieldType("Version", *lines))
12213 + parseVersion(pkg, *lines);
12214 + else if(isGenericFieldType("Maintainer", *lines))
12215 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12216 + else if(isGenericFieldType("Conffiles", *lines)){
12217 + parseConffiles(pkg, *lines);
12218 + reading_conffiles = 1;
12220 + else if(isGenericFieldType("Description", *lines)) {
12221 + pkg->description = parseGenericFieldType("Description", *lines);
12222 + reading_conffiles = 0;
12223 + reading_description = 1;
12226 + else if(isGenericFieldType("Provides", *lines)){
12227 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12228 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12229 + if ( alterProvidesLine(*lines,provide) ){
12232 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12233 +/* Let's try to hack a bit here.
12234 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12235 + in alot of other places. We will remove it before writing down the status database */
12236 + pkg_false_provides=0;
12240 + else if(isGenericFieldType("Depends", *lines))
12241 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12242 + else if(isGenericFieldType("Pre-Depends", *lines))
12243 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12244 + else if(isGenericFieldType("Recommends", *lines))
12245 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12246 + else if(isGenericFieldType("Suggests", *lines))
12247 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12248 + /* Abhaya: support for conflicts */
12249 + else if(isGenericFieldType("Conflicts", *lines))
12250 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12251 + else if(isGenericFieldType("Replaces", *lines))
12252 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12253 + else if(line_is_blank(*lines)) {
12257 + else if(**lines == ' '){
12258 + if(reading_description) {
12259 + /* we already know it's not blank, so the rest of description */
12260 + pkg->description = realloc(pkg->description,
12261 + strlen(pkg->description)
12262 + + 1 + strlen(*lines) + 1);
12263 + strcat(pkg->description, "\n");
12264 + strcat(pkg->description, (*lines));
12266 + else if(reading_conffiles)
12267 + parseConffiles(pkg, *lines);
12271 +/* If the ipk has not a Provides line, we insert our false line */
12272 + if ( pkg_false_provides==1)
12273 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12282 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12286 + for (lines = *raw; *lines; lines++) {
12287 + if(isGenericFieldType("Essential:", *lines)) {
12288 + char *essential_value;
12289 + essential_value = parseGenericFieldType("Essential", *lines);
12290 + if (strcmp(essential_value, "yes") == 0) {
12291 + pkg->essential = 1;
12293 + free(essential_value);
12300 Index: busybox-1.4.2/archival/libipkg/pkg_parse.h
12301 ===================================================================
12302 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12303 +++ busybox-1.4.2/archival/libipkg/pkg_parse.h 2007-06-04 13:21:36.728393104 +0200
12305 +/* pkg_parse.h - the itsy package management system
12309 + Copyright (C) 2002 Compaq Computer Corporation
12311 + This program is free software; you can redistribute it and/or
12312 + modify it under the terms of the GNU General Public License as
12313 + published by the Free Software Foundation; either version 2, or (at
12314 + your option) any later version.
12316 + This program is distributed in the hope that it will be useful, but
12317 + WITHOUT ANY WARRANTY; without even the implied warranty of
12318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12319 + General Public License for more details.
12322 +#ifndef PKG_PARSE_H
12323 +#define PKG_PARSE_H
12325 +int isGenericFieldType(char * type, char * line);
12326 +char * parseGenericFieldType(char * type, char * raw);
12327 +void parseStatus(pkg_t *pkg, char * raw);
12328 +int parseVersion(pkg_t *pkg, char *raw);
12329 +char ** parseDependsString(char * raw, int * depends_count);
12330 +int parseVersion(pkg_t *pkg, char *raw);
12331 +void parseConffiles(pkg_t * pkg, char * raw);
12332 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12333 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12336 Index: busybox-1.4.2/archival/libipkg/pkg_src.c
12337 ===================================================================
12338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12339 +++ busybox-1.4.2/archival/libipkg/pkg_src.c 2007-06-04 13:21:36.728393104 +0200
12341 +/* pkg_src.c - the itsy package management system
12345 + Copyright (C) 2001 University of Southern California
12347 + This program is free software; you can redistribute it and/or
12348 + modify it under the terms of the GNU General Public License as
12349 + published by the Free Software Foundation; either version 2, or (at
12350 + your option) any later version.
12352 + This program is distributed in the hope that it will be useful, but
12353 + WITHOUT ANY WARRANTY; without even the implied warranty of
12354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12355 + General Public License for more details.
12360 +#include "pkg_src.h"
12361 +#include "str_util.h"
12363 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12365 + src->gzip = gzip;
12366 + src->name = str_dup_safe (name);
12367 + src->value = str_dup_safe (base_url);
12369 + src->extra_data = str_dup_safe (extra_data);
12371 + src->extra_data = NULL;
12375 +void pkg_src_deinit(pkg_src_t *src)
12377 + free (src->name);
12378 + free (src->value);
12379 + if (src->extra_data)
12380 + free (src->extra_data);
12384 Index: busybox-1.4.2/archival/libipkg/pkg_src.h
12385 ===================================================================
12386 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12387 +++ busybox-1.4.2/archival/libipkg/pkg_src.h 2007-06-04 13:21:36.728393104 +0200
12389 +/* pkg_src.h - the itsy package management system
12393 + Copyright (C) 2001 University of Southern California
12395 + This program is free software; you can redistribute it and/or
12396 + modify it under the terms of the GNU General Public License as
12397 + published by the Free Software Foundation; either version 2, or (at
12398 + your option) any later version.
12400 + This program is distributed in the hope that it will be useful, but
12401 + WITHOUT ANY WARRANTY; without even the implied warranty of
12402 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12403 + General Public License for more details.
12409 +#include "nv_pair.h"
12415 + char *extra_data;
12419 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12420 +void pkg_src_deinit(pkg_src_t *src);
12423 Index: busybox-1.4.2/archival/libipkg/pkg_src_list.c
12424 ===================================================================
12425 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12426 +++ busybox-1.4.2/archival/libipkg/pkg_src_list.c 2007-06-04 13:21:36.728393104 +0200
12428 +/* pkg_src_list.c - the itsy package management system
12432 + Copyright (C) 2001 University of Southern California
12434 + This program is free software; you can redistribute it and/or
12435 + modify it under the terms of the GNU General Public License as
12436 + published by the Free Software Foundation; either version 2, or (at
12437 + your option) any later version.
12439 + This program is distributed in the hope that it will be useful, but
12440 + WITHOUT ANY WARRANTY; without even the implied warranty of
12441 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12442 + General Public License for more details.
12447 +#include "pkg_src_list.h"
12448 +#include "void_list.h"
12450 +int pkg_src_list_init(pkg_src_list_t *list)
12452 + return void_list_init((void_list_t *) list);
12455 +void pkg_src_list_deinit(pkg_src_list_t *list)
12457 + pkg_src_list_elt_t *iter;
12458 + pkg_src_t *pkg_src;
12460 + for (iter = list->head; iter; iter = iter->next) {
12461 + pkg_src = iter->data;
12462 + pkg_src_deinit(pkg_src);
12464 + /* malloced in pkg_src_list_append */
12466 + iter->data = NULL;
12468 + void_list_deinit((void_list_t *) list);
12471 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12472 + const char *name, const char *base_url, const char *extra_data,
12477 + /* freed in pkg_src_list_deinit */
12478 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12480 + if (pkg_src == NULL) {
12481 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12484 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12486 + err = void_list_append((void_list_t *) list, pkg_src);
12494 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12496 + return void_list_push((void_list_t *) list, data);
12499 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12501 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12503 Index: busybox-1.4.2/archival/libipkg/pkg_src_list.h
12504 ===================================================================
12505 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12506 +++ busybox-1.4.2/archival/libipkg/pkg_src_list.h 2007-06-04 13:21:36.728393104 +0200
12508 +/* pkg_src_list.h - the itsy package management system
12512 + Copyright (C) 2001 University of Southern California
12514 + This program is free software; you can redistribute it and/or
12515 + modify it under the terms of the GNU General Public License as
12516 + published by the Free Software Foundation; either version 2, or (at
12517 + your option) any later version.
12519 + This program is distributed in the hope that it will be useful, but
12520 + WITHOUT ANY WARRANTY; without even the implied warranty of
12521 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12522 + General Public License for more details.
12525 +#ifndef PKG_SRC_LIST_H
12526 +#define PKG_SRC_LIST_H
12528 +#include "pkg_src.h"
12530 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12531 +struct pkg_src_list_elt
12533 + pkg_src_list_elt_t *next;
12537 +typedef struct pkg_src_list pkg_src_list_t;
12538 +struct pkg_src_list
12540 + pkg_src_list_elt_t pre_head;
12541 + pkg_src_list_elt_t *head;
12542 + pkg_src_list_elt_t *tail;
12545 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12547 + if (list->head == NULL)
12553 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12554 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12556 +int pkg_src_list_init(pkg_src_list_t *list);
12557 +void pkg_src_list_deinit(pkg_src_list_t *list);
12559 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
12560 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12561 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12565 Index: busybox-1.4.2/archival/libipkg/pkg_vec.c
12566 ===================================================================
12567 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12568 +++ busybox-1.4.2/archival/libipkg/pkg_vec.c 2007-06-04 13:21:36.729392952 +0200
12570 +/* pkg_vec.c - the itsy package management system
12574 + Copyright (C) 2002 Compaq Computer Corporation
12576 + This program is free software; you can redistribute it and/or
12577 + modify it under the terms of the GNU General Public License as
12578 + published by the Free Software Foundation; either version 2, or (at
12579 + your option) any later version.
12581 + This program is distributed in the hope that it will be useful, but
12582 + WITHOUT ANY WARRANTY; without even the implied warranty of
12583 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12584 + General Public License for more details.
12587 +#include <stdlib.h>
12588 +#include <fnmatch.h>
12589 +#include "xregex.h"
12593 +pkg_vec_t * pkg_vec_alloc(void)
12595 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12597 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12600 + vec->pkgs = NULL;
12606 +void pkg_vec_free(pkg_vec_t *vec)
12613 + * assumption: all names in a vector are identical
12614 + * assumption: all version strings are trimmed,
12615 + * so identical versions have identical version strings,
12616 + * implying identical packages; let's marry these
12618 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12623 + /* look for a duplicate pkg by name, version, and architecture */
12624 + for (i = 0; i < vec->len; i++){
12625 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12626 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12627 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12628 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12629 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12630 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12632 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12633 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12638 + /* we didn't find one, add it */
12640 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12641 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12643 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12644 + vec->pkgs[vec->len] = pkg;
12648 + /* update the one that we have */
12650 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12651 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12652 + if (set_status) {
12653 + /* this is from the status file, so need to merge with existing database */
12654 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12655 + pkg_merge(vec->pkgs[i], pkg, set_status);
12656 + /* XXX: CLEANUP: It's not so polite to free something here
12657 + that was passed in from above. */
12661 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12662 + /* just overwrite the old one */
12663 + pkg_deinit(vec->pkgs[i]);
12664 + free(vec->pkgs[i]);
12665 + vec->pkgs[i] = pkg;
12667 + return vec->pkgs[i];
12671 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12676 + /* look for a duplicate pkg by name, version, and architecture */
12677 + for (i = 0; i < vec->len; i++)
12678 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12679 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12680 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12685 + /* we didn't find one, add it */
12687 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12688 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12693 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12696 + for (i = 0; i < vec->len; i++)
12697 + if (vec->pkgs[i] == apkg)
12702 +typedef int (*compare_fcn_t)(const void *, const void *);
12703 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12705 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12708 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12710 + int npkgs = vec->len;
12712 + for (i = 0; i < npkgs; i++) {
12713 + pkg_t *pkg = vec->pkgs[i];
12714 + pkg->state_flag &= ~SF_MARKED;
12719 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12721 + int matching_count = 0;
12722 + pkg_t **pkgs = vec->pkgs;
12723 + int npkgs = vec->len;
12725 + for (i = 0; i < npkgs; i++) {
12726 + pkg_t *pkg = pkgs[i];
12727 + if (fnmatch(pattern, pkg->name, 0)==0) {
12728 + pkg->state_flag |= SF_MARKED;
12729 + matching_count++;
12732 + return matching_count;
12736 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12738 + abstract_pkg_vec_t * vec ;
12739 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12741 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12744 + vec->pkgs = NULL;
12750 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12757 + * assumption: all names in a vector are unique
12759 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12763 + /* look for a duplicate pkg by name */
12764 + for(i = 0; i < vec->len; i++)
12765 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12768 + /* we didn't find one, add it */
12769 + if(i == vec->len){
12771 + (abstract_pkg_t **)
12772 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12773 + vec->pkgs[vec->len] = pkg;
12778 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12780 + if (vec->len > i)
12781 + return vec->pkgs[i];
12786 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12789 + for (i = 0; i < vec->len; i++)
12790 + if (vec->pkgs[i] == apkg)
12795 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12797 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12800 Index: busybox-1.4.2/archival/libipkg/pkg_vec.h
12801 ===================================================================
12802 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12803 +++ busybox-1.4.2/archival/libipkg/pkg_vec.h 2007-06-04 13:21:36.729392952 +0200
12805 +/* pkg_vec.h - the itsy package management system
12809 + Copyright (C) 2002 Compaq Computer Corporation
12811 + This program is free software; you can redistribute it and/or
12812 + modify it under the terms of the GNU General Public License as
12813 + published by the Free Software Foundation; either version 2, or (at
12814 + your option) any later version.
12816 + This program is distributed in the hope that it will be useful, but
12817 + WITHOUT ANY WARRANTY; without even the implied warranty of
12818 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12819 + General Public License for more details.
12825 +typedef struct pkg pkg_t;
12826 +typedef struct abstract_pkg abstract_pkg_t;
12833 +typedef struct pkg_vec pkg_vec_t;
12835 +struct abstract_pkg_vec
12837 + abstract_pkg_t **pkgs;
12840 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12842 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12843 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12845 +pkg_vec_t * pkg_vec_alloc(void);
12846 +void pkg_vec_free(pkg_vec_t *vec);
12847 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12849 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12850 +/* pkg_vec_insert_merge: might munge pkg.
12851 +* returns the pkg that is in the pkg graph */
12852 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12853 +/* this one never munges pkg */
12854 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12855 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12856 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12858 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12859 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12861 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12862 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12863 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12864 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12865 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12866 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12869 Index: busybox-1.4.2/archival/libipkg/sprintf_alloc.h
12870 ===================================================================
12871 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12872 +++ busybox-1.4.2/archival/libipkg/sprintf_alloc.h 2007-06-04 13:21:36.729392952 +0200
12874 +/* sprintf_alloca.c -- like sprintf with memory allocation
12878 + Copyright (C) 2001 University of Southern California
12880 + This program is free software; you can redistribute it and/or modify
12881 + it under the terms of the GNU General Public License as published by
12882 + the Free Software Foundation; either version 2, or (at your option)
12883 + any later version.
12885 + This program is distributed in the hope that it will be useful,
12886 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12887 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12888 + GNU General Public License for more details.
12891 +#ifndef SPRINTF_ALLOC_H
12892 +#define SPRINTF_ALLOC_H
12894 +#include "libbb.h"
12896 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12899 Index: busybox-1.4.2/archival/libipkg/str_list.c
12900 ===================================================================
12901 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12902 +++ busybox-1.4.2/archival/libipkg/str_list.c 2007-06-04 13:21:36.729392952 +0200
12904 +/* str_list.c - the itsy package management system
12908 + Copyright (C) 2001 University of Southern California
12910 + This program is free software; you can redistribute it and/or
12911 + modify it under the terms of the GNU General Public License as
12912 + published by the Free Software Foundation; either version 2, or (at
12913 + your option) any later version.
12915 + This program is distributed in the hope that it will be useful, but
12916 + WITHOUT ANY WARRANTY; without even the implied warranty of
12917 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12918 + General Public License for more details.
12923 +#include "str_list.h"
12925 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12927 + return void_list_elt_init((void_list_elt_t *) elt, data);
12930 +void str_list_elt_deinit(str_list_elt_t *elt)
12932 + void_list_elt_deinit((void_list_elt_t *) elt);
12935 +str_list_t *str_list_alloc()
12937 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12939 + str_list_init(list);
12943 +int str_list_init(str_list_t *list)
12945 + return void_list_init((void_list_t *) list);
12948 +void str_list_deinit(str_list_t *list)
12950 + void_list_deinit((void_list_t *) list);
12953 +int str_list_append(str_list_t *list, char *data)
12955 + return void_list_append((void_list_t *) list, data);
12958 +int str_list_push(str_list_t *list, char *data)
12960 + return void_list_push((void_list_t *) list, data);
12963 +str_list_elt_t *str_list_pop(str_list_t *list)
12965 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12968 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12970 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12971 + (void_list_elt_t **) iter);
12974 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12976 + return (char *)void_list_remove_elt((void_list_t *) list,
12977 + (void *)target_str,
12978 + (void_list_cmp_t)strcmp);
12980 Index: busybox-1.4.2/archival/libipkg/str_list.h
12981 ===================================================================
12982 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12983 +++ busybox-1.4.2/archival/libipkg/str_list.h 2007-06-04 13:21:36.729392952 +0200
12985 +/* str_list.h - the itsy package management system
12989 + Copyright (C) 2001 University of Southern California
12991 + This program is free software; you can redistribute it and/or
12992 + modify it under the terms of the GNU General Public License as
12993 + published by the Free Software Foundation; either version 2, or (at
12994 + your option) any later version.
12996 + This program is distributed in the hope that it will be useful, but
12997 + WITHOUT ANY WARRANTY; without even the implied warranty of
12998 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12999 + General Public License for more details.
13002 +#ifndef STR_LIST_H
13003 +#define STR_LIST_H
13005 +#include "void_list.h"
13007 +typedef struct str_list_elt str_list_elt_t;
13008 +struct str_list_elt
13010 + str_list_elt_t *next;
13014 +typedef struct xstr_list str_list_t;
13017 + str_list_elt_t pre_head;
13018 + str_list_elt_t *head;
13019 + str_list_elt_t *tail;
13022 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13023 +void str_list_elt_deinit(str_list_elt_t *elt);
13025 +str_list_t *str_list_alloc(void);
13026 +int str_list_init(str_list_t *list);
13027 +void str_list_deinit(str_list_t *list);
13029 +int str_list_append(str_list_t *list, char *data);
13030 +int str_list_push(str_list_t *list, char *data);
13031 +str_list_elt_t *str_list_pop(str_list_t *list);
13032 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13033 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13036 Index: busybox-1.4.2/archival/libipkg/str_util.c
13037 ===================================================================
13038 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13039 +++ busybox-1.4.2/archival/libipkg/str_util.c 2007-06-04 13:21:36.730392800 +0200
13041 +/* str_utils.c - the itsy package management system
13045 + Copyright (C) 2001 University of Southern California
13047 + This program is free software; you can redistribute it and/or
13048 + modify it under the terms of the GNU General Public License as
13049 + published by the Free Software Foundation; either version 2, or (at
13050 + your option) any later version.
13052 + This program is distributed in the hope that it will be useful, but
13053 + WITHOUT ANY WARRANTY; without even the implied warranty of
13054 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13055 + General Public License for more details.
13060 +int str_starts_with(const char *str, const char *prefix)
13062 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13065 +int str_ends_with(const char *str, const char *suffix)
13070 + str_len = strlen(str);
13071 + suffix_len = strlen(suffix);
13073 + if (str_len < suffix_len) {
13077 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13080 +int str_chomp(char *str)
13082 + if (str[strlen(str) - 1] == '\n') {
13083 + str[strlen(str) - 1] = '\0';
13089 +int str_tolower(char *str)
13092 + *str = tolower(*str);
13099 +int str_toupper(char *str)
13102 + *str = toupper(*str);
13109 +char *str_dup_safe(const char *str)
13111 + return str ? strdup(str) : NULL;
13114 Index: busybox-1.4.2/archival/libipkg/str_util.h
13115 ===================================================================
13116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13117 +++ busybox-1.4.2/archival/libipkg/str_util.h 2007-06-04 13:21:36.730392800 +0200
13119 +/* str_utils.h - the itsy package management system
13123 + Copyright (C) 2001 University of Southern California
13125 + This program is free software; you can redistribute it and/or
13126 + modify it under the terms of the GNU General Public License as
13127 + published by the Free Software Foundation; either version 2, or (at
13128 + your option) any later version.
13130 + This program is distributed in the hope that it will be useful, but
13131 + WITHOUT ANY WARRANTY; without even the implied warranty of
13132 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13133 + General Public License for more details.
13136 +#ifndef STR_UTILS_H
13137 +#define STR_UTILS_H
13139 +int str_starts_with(const char *str, const char *prefix);
13140 +int str_ends_with(const char *str, const char *suffix);
13141 +int str_chomp(char *str);
13142 +int str_tolower(char *str);
13143 +int str_toupper(char *str);
13144 +char *str_dup_safe(const char *str);
13147 Index: busybox-1.4.2/archival/libipkg/user.c
13148 ===================================================================
13149 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13150 +++ busybox-1.4.2/archival/libipkg/user.c 2007-06-04 13:21:36.730392800 +0200
13152 +/* user.c - the itsy package management system
13156 + Copyright (C) 2002 Hewlett Packard Company
13157 + Copyright (C) 2001 University of Southern California
13159 + This program is free software; you can redistribute it and/or
13160 + modify it under the terms of the GNU General Public License as
13161 + published by the Free Software Foundation; either version 2, or (at
13162 + your option) any later version.
13164 + This program is distributed in the hope that it will be useful, but
13165 + WITHOUT ANY WARRANTY; without even the implied warranty of
13166 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13167 + General Public License for more details.
13170 +#include <stdio.h>
13171 +#include <stdarg.h>
13172 +#include "file_util.h"
13173 +#include "str_util.h"
13175 +#include "libipkg.h"
13180 +static char *question = NULL;
13181 +static int question_len = 255;
13183 +char *get_user_response(const char *format, ...)
13185 + int len = question_len;
13188 + va_start(ap, format);
13191 + vprintf(format, ap);
13193 + response = file_read_line_alloc(stdin);
13194 + } while (response == NULL);
13197 + if (question == NULL || len > question_len) {
13198 + question = realloc(question, len + 1);
13199 + question_len = len;
13201 + len = vsnprintf(question,question_len,format,ap);
13202 + } while (len > question_len);
13203 + response = strdup(ipkg_cb_response(question));
13205 + str_chomp(response);
13206 + str_tolower(response);
13210 Index: busybox-1.4.2/archival/libipkg/user.h
13211 ===================================================================
13212 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13213 +++ busybox-1.4.2/archival/libipkg/user.h 2007-06-04 13:21:36.730392800 +0200
13215 +/* user.c - the itsy package management system
13219 + Copyright (C) 2002 Hewlett Packard Company
13220 + Copyright (C) 2001 University of Southern California
13222 + This program is free software; you can redistribute it and/or
13223 + modify it under the terms of the GNU General Public License as
13224 + published by the Free Software Foundation; either version 2, or (at
13225 + your option) any later version.
13227 + This program is distributed in the hope that it will be useful, but
13228 + WITHOUT ANY WARRANTY; without even the implied warranty of
13229 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13230 + General Public License for more details.
13233 +#include <stdio.h>
13234 +#include <stdarg.h>
13236 +char *get_user_response(const char *format, ...);
13238 Index: busybox-1.4.2/archival/libipkg/void_list.c
13239 ===================================================================
13240 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13241 +++ busybox-1.4.2/archival/libipkg/void_list.c 2007-06-04 13:21:36.731392648 +0200
13243 +/* void_list.c - the itsy package management system
13247 + Copyright (C) 2001 University of Southern California
13249 + This program is free software; you can redistribute it and/or
13250 + modify it under the terms of the GNU General Public License as
13251 + published by the Free Software Foundation; either version 2, or (at
13252 + your option) any later version.
13254 + This program is distributed in the hope that it will be useful, but
13255 + WITHOUT ANY WARRANTY; without even the implied warranty of
13256 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13257 + General Public License for more details.
13261 +#include <errno.h>
13263 +#include "void_list.h"
13265 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13267 + elt->next = NULL;
13268 + elt->data = data;
13273 +void void_list_elt_deinit(void_list_elt_t *elt)
13275 + void_list_elt_init(elt, NULL);
13278 +int void_list_init(void_list_t *list)
13280 + void_list_elt_init(&list->pre_head, NULL);
13281 + list->head = NULL;
13282 + list->pre_head.next = list->head;
13283 + list->tail = NULL;
13288 +void void_list_deinit(void_list_t *list)
13290 + void_list_elt_t *elt;
13292 + while (list->head) {
13293 + elt = void_list_pop(list);
13294 + void_list_elt_deinit(elt);
13295 + /* malloced in void_list_append */
13300 +int void_list_append(void_list_t *list, void *data)
13302 + void_list_elt_t *elt;
13304 + /* freed in void_list_deinit */
13305 + elt = malloc(sizeof(void_list_elt_t));
13306 + if (elt == NULL) {
13307 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13311 + void_list_elt_init(elt, data);
13313 + if (list->tail) {
13314 + list->tail->next = elt;
13315 + list->tail = elt;
13317 + list->head = elt;
13318 + list->pre_head.next = list->head;
13319 + list->tail = elt;
13325 +int void_list_push(void_list_t *list, void *data)
13327 + void_list_elt_t *elt;
13329 + elt = malloc(sizeof(void_list_elt_t));
13330 + if (elt == NULL) {
13331 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13335 + void_list_elt_init(elt, data);
13337 + elt->next = list->head;
13338 + list->head->next = elt;
13339 + if (list->tail == NULL) {
13340 + list->tail = list->head;
13346 +void_list_elt_t *void_list_pop(void_list_t *list)
13348 + void_list_elt_t *elt;
13350 + elt = list->head;
13352 + if (list->head) {
13353 + list->head = list->head->next;
13354 + list->pre_head.next = list->head;
13355 + if (list->head == NULL) {
13356 + list->tail = NULL;
13363 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13365 + void_list_elt_t *prior;
13366 + void_list_elt_t *old_elt;
13370 + old_data = old_elt->data;
13372 + if (old_elt == list->head) {
13373 + prior = &list->pre_head;
13374 + void_list_pop(list);
13376 + for (prior = list->head; prior; prior = prior->next) {
13377 + if (prior->next == old_elt) {
13381 + if (prior == NULL || prior->next != old_elt) {
13382 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13385 + prior->next = old_elt->next;
13387 + if (old_elt == list->tail) {
13388 + list->tail = prior;
13392 + void_list_elt_deinit(old_elt);
13398 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13399 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13401 + void_list_elt_t *prior;
13402 + void_list_elt_t *old_elt = NULL;
13403 + void *old_data = NULL;
13405 + /* first element */
13406 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13407 + old_elt = list->head;
13408 + old_data = list->head->data;
13409 + void_list_pop(list);
13412 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13413 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13414 + old_elt = prior->next;
13415 + old_data = old_elt->data;
13423 + prior->next = old_elt->next;
13425 + if (old_elt == list->tail) {
13426 + list->tail = prior;
13430 + void_list_elt_deinit(old_elt);
13437 Index: busybox-1.4.2/archival/libipkg/void_list.h
13438 ===================================================================
13439 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13440 +++ busybox-1.4.2/archival/libipkg/void_list.h 2007-06-04 13:21:36.731392648 +0200
13442 +/* void_list.h - the itsy package management system
13446 + Copyright (C) 2001 University of Southern California
13448 + This program is free software; you can redistribute it and/or
13449 + modify it under the terms of the GNU General Public License as
13450 + published by the Free Software Foundation; either version 2, or (at
13451 + your option) any later version.
13453 + This program is distributed in the hope that it will be useful, but
13454 + WITHOUT ANY WARRANTY; without even the implied warranty of
13455 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13456 + General Public License for more details.
13459 +#ifndef VOID_LIST_H
13460 +#define VOID_LIST_H
13462 +typedef struct void_list_elt void_list_elt_t;
13463 +struct void_list_elt
13465 + void_list_elt_t *next;
13469 +typedef struct void_list void_list_t;
13472 + void_list_elt_t pre_head;
13473 + void_list_elt_t *head;
13474 + void_list_elt_t *tail;
13477 +static inline int void_list_empty(void_list_t *list)
13479 + if (list->head == NULL)
13485 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13486 +void void_list_elt_deinit(void_list_elt_t *elt);
13488 +int void_list_init(void_list_t *list);
13489 +void void_list_deinit(void_list_t *list);
13491 +int void_list_append(void_list_t *list, void *data);
13492 +int void_list_push(void_list_t *list, void *data);
13493 +void_list_elt_t *void_list_pop(void_list_t *list);
13495 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13496 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13497 +typedef int (*void_list_cmp_t)(const void *, const void *);
13498 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13501 Index: busybox-1.4.2/archival/libipkg/xsystem.c
13502 ===================================================================
13503 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13504 +++ busybox-1.4.2/archival/libipkg/xsystem.c 2007-06-04 13:21:36.731392648 +0200
13506 +/* xsystem.c - system(3) with error messages
13510 + Copyright (C) 2001 University of Southern California
13512 + This program is free software; you can redistribute it and/or
13513 + modify it under the terms of the GNU General Public License as
13514 + published by the Free Software Foundation; either version 2, or (at
13515 + your option) any later version.
13517 + This program is distributed in the hope that it will be useful, but
13518 + WITHOUT ANY WARRANTY; without even the implied warranty of
13519 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13520 + General Public License for more details.
13524 +#include <sys/wait.h>
13526 +#include "xsystem.h"
13528 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13529 + really need the /bin/sh invocation which takes resources and
13530 + introduces security problems. I should switch all of this to a sort
13531 + of execl() or execv() interface/implementation.
13534 +/* Like system(3), but with error messages printed if the fork fails
13535 + or if the child process dies due to an uncaught signal. Also, the
13536 + return value is a bit simpler:
13538 + -1 if there was any problem
13539 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13540 + as defined in <sys/wait.h>.
13542 +int xsystem(const char *cmd)
13546 + err = system(cmd);
13549 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13550 + __FUNCTION__, cmd);
13554 + if (WIFSIGNALED(err)) {
13555 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13556 + __FUNCTION__, WTERMSIG(err), cmd);
13560 + if (WIFEXITED(err)) {
13561 + /* Normal child exit */
13562 + return WEXITSTATUS(err);
13565 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13566 + __FUNCTION__, err);
13570 Index: busybox-1.4.2/archival/libipkg/xsystem.h
13571 ===================================================================
13572 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13573 +++ busybox-1.4.2/archival/libipkg/xsystem.h 2007-06-04 13:21:36.731392648 +0200
13575 +/* xsystem.h - system(3) with error messages
13579 + Copyright (C) 2001 University of Southern California
13581 + This program is free software; you can redistribute it and/or
13582 + modify it under the terms of the GNU General Public License as
13583 + published by the Free Software Foundation; either version 2, or (at
13584 + your option) any later version.
13586 + This program is distributed in the hope that it will be useful, but
13587 + WITHOUT ANY WARRANTY; without even the implied warranty of
13588 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13589 + General Public License for more details.
13595 +#include <stdlib.h>
13597 +/* Like system(3), but with error messages printed if the fork fails
13598 + or if the child process dies due to an uncaught signal. Also, the
13599 + return value is a bit simpler:
13601 + -1 if there was any problem
13602 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13603 + as defined in <sys/wait.h>.
13605 +int xsystem(const char *cmd);
13609 Index: busybox-1.4.2/archival/libunarchive/data_extract_all.c
13610 ===================================================================
13611 --- busybox-1.4.2.orig/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:31.879130304 +0200
13612 +++ busybox-1.4.2/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:36.731392648 +0200
13613 @@ -117,3 +117,17 @@
13614 utime(file_header->name, &t);
13618 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13620 + char *name_ptr = archive_handle->file_header->name;
13622 + name_ptr += strspn(name_ptr, "./");
13623 + if (name_ptr[0] != '\0') {
13624 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13625 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13626 + strcat(archive_handle->file_header->name, name_ptr);
13627 + data_extract_all(archive_handle);
13631 Index: busybox-1.4.2/archival/libunarchive/Kbuild
13632 ===================================================================
13633 --- busybox-1.4.2.orig/archival/libunarchive/Kbuild 2007-06-04 13:21:31.886129240 +0200
13634 +++ busybox-1.4.2/archival/libunarchive/Kbuild 2007-06-04 13:21:36.732392496 +0200
13636 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13637 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13638 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13639 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13640 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13641 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13642 lib-$(CONFIG_TAR) += get_header_tar.o
13643 Index: busybox-1.4.2/include/applets.h
13644 ===================================================================
13645 --- busybox-1.4.2.orig/include/applets.h 2007-06-04 13:21:34.786688288 +0200
13646 +++ busybox-1.4.2/include/applets.h 2007-06-04 13:21:36.732392496 +0200
13647 @@ -160,6 +160,7 @@
13648 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13649 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13650 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13651 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13652 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13653 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13654 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13655 Index: busybox-1.4.2/include/unarchive.h
13656 ===================================================================
13657 --- busybox-1.4.2.orig/include/unarchive.h 2007-06-04 13:21:31.897127568 +0200
13658 +++ busybox-1.4.2/include/unarchive.h 2007-06-04 13:21:36.732392496 +0200
13661 extern void data_skip(archive_handle_t *archive_handle);
13662 extern void data_extract_all(archive_handle_t *archive_handle);
13663 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13664 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13665 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13667 Index: busybox-1.4.2/include/usage.h
13668 ===================================================================
13669 --- busybox-1.4.2.orig/include/usage.h 2007-06-04 13:21:35.005655000 +0200
13670 +++ busybox-1.4.2/include/usage.h 2007-06-04 13:21:36.734392192 +0200
13671 @@ -1133,6 +1133,82 @@
13672 "$ ls -la /tmp/busybox*\n" \
13673 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13675 +#define ipkg_trivial_usage \
13676 + "[options]... sub-command [arguments]..."
13677 +#define ipkg_full_usage \
13678 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13680 + "Sub-commands:\n" \
13681 + "\nPackage Manipulation:\n" \
13682 + "\tupdate Update list of available packages\n" \
13683 + "\tupgrade Upgrade all installed packages to latest version\n" \
13684 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13685 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13686 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13687 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13688 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13689 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13691 + "Informational Commands:\n" \
13692 + "\tlist List available packages and descriptions\n" \
13693 + "\tlist_installed List all and only the installed packages and description \n" \
13694 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13695 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13696 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13697 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13698 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13699 + "\tcompare_versions <v1> <op> <v2>\n" \
13700 + "\t compare versions using <= < > >= = << >>\n" \
13701 + "\tprint_architecture prints the architecture.\n" \
13702 + "\tprint_installation_architecture\n" \
13703 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13704 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13705 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13706 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13707 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13708 + "\t prints the installation architecture.\n" \
13711 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13712 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13713 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13714 + "\t 0 errors only\n" \
13715 + "\t 1 normal messages (default)\n" \
13716 + "\t 2 informative messages\n" \
13717 + "\t 3 debug output\n" \
13718 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13719 + "\t-conf <conf_file> Default configuration file location\n" \
13720 + " is /etc/ipkg.conf\n" \
13721 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13722 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13723 + " <dest_name> should be a defined dest name from\n" \
13724 + " the configuration file, (but can also be a\n" \
13725 + " directory name in a pinch).\n" \
13726 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13727 + "\t-offline <offline_root> offline installation of packages.\n" \
13728 + "\t-verbose_wget more wget messages\n" \
13730 + "Force Options (use when ipkg is too smart for its own good):\n" \
13731 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13732 + "\t Install/remove package in spite of failed dependences\n" \
13733 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13734 + " (no prompts). Note that this will not prevent\n" \
13735 + " package installation scripts from prompting.\n" \
13736 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13737 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13738 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13739 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13740 + "\t-noaction No action -- test only\n" \
13741 + "\t-nodeps Do not follow dependences\n" \
13742 + "\t-force-removal-of-dependent-packages\n" \
13743 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13744 + "\t-test No action -- test only\n" \
13745 + "\t-t Specify tmp-dir.\n" \
13746 + "\t--tmp-dir Specify tmp-dir.\n" \
13748 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13749 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13751 #define halt_trivial_usage \
13752 "[-d<delay>] [-n<nosync>] [-f<force>]"
13753 #define halt_full_usage \
13754 Index: busybox-1.4.2/Makefile
13755 ===================================================================
13756 --- busybox-1.4.2.orig/Makefile 2007-06-04 13:21:31.910125592 +0200
13757 +++ busybox-1.4.2/Makefile 2007-06-04 13:21:36.734392192 +0200
13758 @@ -423,6 +423,7 @@
13762 + archival/libipkg/ \
13763 archival/libunarchive/ \