1 Index: busybox-1.8.1/archival/Config.in
2 ===================================================================
3 --- busybox-1.8.1.orig/archival/Config.in 2007-11-10 17:39:21.063504932 +0100
4 +++ busybox-1.8.1/archival/Config.in 2007-11-10 17:40:53.320762376 +0100
6 gzip is used to compress files.
7 It's probably the most widely used UNIX compression program.
16 + ipkg is the itsy package management system.
21 Index: busybox-1.8.1/archival/dpkg.c
22 ===================================================================
23 --- busybox-1.8.1.orig/archival/dpkg.c 2007-11-10 17:39:21.071505389 +0100
24 +++ busybox-1.8.1/archival/dpkg.c 2007-11-10 17:40:53.320762376 +0100
25 @@ -1455,6 +1455,10 @@
26 return ar_handle->sub_archive->buffer;
31 +// moved to data_extract_all.c
33 static void data_extract_all_prefix(archive_handle_t *archive_handle)
35 char *name_ptr = archive_handle->file_header->name;
42 static void unpack_package(deb_file_t *deb_file)
44 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
45 Index: busybox-1.8.1/archival/ipkg.c
46 ===================================================================
47 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
48 +++ busybox-1.8.1/archival/ipkg.c 2007-11-10 17:41:16.866104145 +0100
50 +/* ipkg.c - the itsy package management system
54 + Copyright (C) 2003 kernel concepts
56 + This program is free software; you can redistribute it and/or
57 + modify it under the terms of the GNU General Public License as
58 + published by the Free Software Foundation; either version 2, or (at
59 + your option) any later version.
61 + This program is distributed in the hope that it will be useful, but
62 + WITHOUT ANY WARRANTY; without even the implied warranty of
63 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64 + General Public License for more details.
66 + ipkg command line frontend using libipkg
69 +#include "libipkg/libipkg.h"
72 +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
73 +int ipkg_main(int argc, char **argv)
75 + return ipkg_op(argc, argv);
77 Index: busybox-1.8.1/archival/Kbuild
78 ===================================================================
79 --- busybox-1.8.1.orig/archival/Kbuild 2007-11-10 17:39:21.083506071 +0100
80 +++ busybox-1.8.1/archival/Kbuild 2007-11-10 17:40:53.332763058 +0100
82 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
83 lib-$(CONFIG_GUNZIP) += bbunzip.o
84 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
85 +lib-$(CONFIG_IPKG) += ipkg.o
86 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
87 lib-$(CONFIG_RPM) += rpm.o
88 lib-$(CONFIG_TAR) += tar.o
89 Index: busybox-1.8.1/archival/libipkg/args.c
90 ===================================================================
91 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
92 +++ busybox-1.8.1/archival/libipkg/args.c 2007-11-10 17:40:53.336763287 +0100
94 +/* args.c - parse command-line args
98 + Copyright 2001 University of Southern California
100 + This program is free software; you can redistribute it and/or modify
101 + it under the terms of the GNU General Public License as published by
102 + the Free Software Foundation; either version 2, or (at your option)
105 + This program is distributed in the hope that it will be useful,
106 + but WITHOUT ANY WARRANTY; without even the implied warranty of
107 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108 + GNU General Public License for more details.
117 +#include "ipkg_message.h"
120 +#include "sprintf_alloc.h"
125 +static void print_version(void);
129 + ARGS_OPT_FORCE_DEFAULTS = 129,
130 + ARGS_OPT_FORCE_DEPENDS,
131 + ARGS_OPT_FORCE_OVERWRITE,
132 + ARGS_OPT_FORCE_DOWNGRADE,
133 + ARGS_OPT_FORCE_REINSTALL,
134 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
135 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
136 + ARGS_OPT_FORCE_SPACE,
139 + ARGS_OPT_VERBOSE_WGET,
140 + ARGS_OPT_VERBOSITY,
141 + ARGS_OPT_MULTIPLE_PROVIDERS
144 +int args_init(args_t *args)
146 + char *conf_file_dir;
148 + memset(args, 0, sizeof(args_t));
150 + args->dest = ARGS_DEFAULT_DEST;
152 + conf_file_dir = getenv("IPKG_CONF_DIR");
153 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
154 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
156 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
157 + ARGS_DEFAULT_CONF_FILE_NAME);
159 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
160 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
161 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
162 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
163 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
164 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
165 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
166 + args->noaction = ARGS_DEFAULT_NOACTION;
167 + args->nodeps = ARGS_DEFAULT_NODEPS;
168 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
169 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
170 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
171 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
172 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
173 + args->multiple_providers = 0;
174 + args->nocheckfordirorfile = 0;
175 + args->noreadfeedsfile = 0;
180 +void args_deinit(args_t *args)
182 + free(args->conf_file);
183 + args->conf_file = NULL;
186 +int args_parse(args_t *args, int argc, char *argv[])
189 + int option_index = 0;
191 + static struct option long_options[] = {
192 + {"query-all", 0, 0, 'A'},
193 + {"conf-file", 1, 0, 'f'},
194 + {"conf", 1, 0, 'f'},
195 + {"dest", 1, 0, 'd'},
196 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
197 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
198 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
199 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
200 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
201 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
202 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
203 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
204 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
205 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
206 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
207 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
208 + {"recursive", 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_dependent_packages", 0, 0,
213 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
214 + {"force-removal-of-essential-packages", 0, 0,
215 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
216 + {"force_removal_of_essential_packages", 0, 0,
217 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
218 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
219 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
220 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
221 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
222 + {"offline", 1, 0, 'o'},
223 + {"offline-root", 1, 0, 'o'},
224 + {"test", 0, 0, ARGS_OPT_NOACTION},
225 + {"tmp-dir", 1, 0, 't'},
226 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
227 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
228 + {"verbosity", 2, 0, 'V'},
229 + {"version", 0, 0, 'v'},
234 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
240 + args->query_all = 1;
243 + args->dest = optarg;
246 + free(args->conf_file);
247 + args->conf_file = strdup(optarg);
250 + args->offline_root = optarg;
253 + args->noaction = 1;
256 + args->tmp_dir = strdup(optarg);
262 + case ARGS_OPT_VERBOSITY:
264 + args->verbosity = atoi(optarg);
266 + args->verbosity += 1;
268 + case ARGS_OPT_FORCE_DEFAULTS:
269 + args->force_defaults = 1;
271 + case ARGS_OPT_FORCE_DEPENDS:
272 + args->force_depends = 1;
274 + case ARGS_OPT_FORCE_OVERWRITE:
275 + args->force_overwrite = 1;
277 + case ARGS_OPT_FORCE_DOWNGRADE:
278 + args->force_downgrade = 1;
280 + case ARGS_OPT_FORCE_REINSTALL:
281 + args->force_reinstall = 1;
283 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
284 + args->force_removal_of_essential_packages = 1;
286 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
287 + args->force_removal_of_dependent_packages = 1;
289 + case ARGS_OPT_FORCE_SPACE:
290 + args->force_space = 1;
292 + case ARGS_OPT_VERBOSE_WGET:
293 + args->verbose_wget = 1;
295 + case ARGS_OPT_MULTIPLE_PROVIDERS:
296 + args->multiple_providers = 1;
298 + case ARGS_OPT_NODEPS:
301 + case ARGS_OPT_NOACTION:
302 + args->noaction = 1;
311 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
322 +void args_usage(char *complaint)
325 + bb_error_msg("%s\n", complaint);
332 +static void print_version(void)
334 + bb_error_msg("version %s\n", IPKG_VERSION);
336 Index: busybox-1.8.1/archival/libipkg/args.h
337 ===================================================================
338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
339 +++ busybox-1.8.1/archival/libipkg/args.h 2007-11-10 17:40:53.340763516 +0100
341 +/* args.h - parse command-line args
345 + Copyright 2001 University of Southern California
347 + This program is free software; you can redistribute it and/or modify
348 + it under the terms of the GNU General Public License as published by
349 + the Free Software Foundation; either version 2, or (at your option)
352 + This program is distributed in the hope that it will be useful,
353 + but WITHOUT ANY WARRANTY; without even the implied warranty of
354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355 + GNU General Public License for more details.
366 + int force_defaults;
368 + int force_overwrite;
369 + int force_downgrade;
370 + int force_reinstall;
371 + int force_removal_of_essential_packages;
372 + int force_removal_of_dependent_packages;
376 + int multiple_providers;
380 + int nocheckfordirorfile;
381 + int noreadfeedsfile;
382 + char *offline_root;
383 + char *offline_root_pre_script_cmd;
384 + char *offline_root_post_script_cmd;
386 +typedef struct args args_t;
388 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
389 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
390 +#define ARGS_DEFAULT_DEST NULL
391 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
392 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
393 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
394 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
395 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
396 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
397 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
398 +#define ARGS_DEFAULT_FORCE_SPACE 0
399 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
400 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
401 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
402 +#define ARGS_DEFAULT_NOACTION 0
403 +#define ARGS_DEFAULT_NODEPS 0
404 +#define ARGS_DEFAULT_VERBOSE_WGET 0
405 +#define ARGS_DEFAULT_VERBOSITY 1
407 +int args_init(args_t *args);
408 +void args_deinit(args_t *args);
409 +int args_parse(args_t *args, int argc, char *argv[]);
410 +void args_usage(char *complaint);
413 Index: busybox-1.8.1/archival/libipkg/conffile.c
414 ===================================================================
415 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
416 +++ busybox-1.8.1/archival/libipkg/conffile.c 2007-11-10 17:40:53.340763516 +0100
418 +/* conffile.c - the itsy package management system
422 + Copyright (C) 2001 University of Southern California
424 + This program is free software; you can redistribute it and/or
425 + modify it under the terms of the GNU General Public License as
426 + published by the Free Software Foundation; either version 2, or (at
427 + your option) any later version.
429 + This program is distributed in the hope that it will be useful, but
430 + WITHOUT ANY WARRANTY; without even the implied warranty of
431 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
432 + General Public License for more details.
439 +#include "ipkg_message.h"
441 +#include "conffile.h"
442 +#include "file_util.h"
443 +#include "sprintf_alloc.h"
445 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
447 + return nv_pair_init(conffile, file_name, md5sum);
450 +void conffile_deinit(conffile_t *conffile)
452 + nv_pair_deinit(conffile);
455 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
458 + char *filename = conffile->name;
459 + char *root_filename;
462 + if (conffile->value == NULL) {
463 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
467 + root_filename = root_filename_alloc(conf, filename);
469 + md5sum = file_md5sum_alloc(root_filename);
471 + ret = strcmp(md5sum, conffile->value);
473 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
474 + conffile->name, md5sum, conffile->value);
477 + free(root_filename);
482 Index: busybox-1.8.1/archival/libipkg/conffile.h
483 ===================================================================
484 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
485 +++ busybox-1.8.1/archival/libipkg/conffile.h 2007-11-10 17:40:53.340763516 +0100
487 +/* conffile.h - the itsy package management system
491 + Copyright (C) 2001 University of Southern California
493 + This program is free software; you can redistribute it and/or
494 + modify it under the terms of the GNU General Public License as
495 + published by the Free Software Foundation; either version 2, or (at
496 + your option) any later version.
498 + This program is distributed in the hope that it will be useful, but
499 + WITHOUT ANY WARRANTY; without even the implied warranty of
500 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
501 + General Public License for more details.
507 +#include "nv_pair.h"
509 +typedef struct nv_pair conffile_t;
511 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
512 +void conffile_deinit(conffile_t *conffile);
513 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
517 Index: busybox-1.8.1/archival/libipkg/conffile_list.c
518 ===================================================================
519 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
520 +++ busybox-1.8.1/archival/libipkg/conffile_list.c 2007-11-10 17:40:53.340763516 +0100
522 +/* conffile_list.c - the itsy package management system
526 + Copyright (C) 2001 University of Southern California
528 + This program is free software; you can redistribute it and/or
529 + modify it under the terms of the GNU General Public License as
530 + published by the Free Software Foundation; either version 2, or (at
531 + your option) any later version.
533 + This program is distributed in the hope that it will be useful, but
534 + WITHOUT ANY WARRANTY; without even the implied warranty of
535 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
536 + General Public License for more details.
541 +#include "conffile_list.h"
543 +int conffile_list_init(conffile_list_t *list)
545 + return nv_pair_list_init(list);
548 +void conffile_list_deinit(conffile_list_t *list)
550 + nv_pair_list_deinit(list);
553 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
554 + const char *md5sum)
556 + return nv_pair_list_append(list, file_name, md5sum);
559 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
561 + return nv_pair_list_push(list, data);
564 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
566 + return nv_pair_list_pop(list);
569 Index: busybox-1.8.1/archival/libipkg/conffile_list.h
570 ===================================================================
571 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
572 +++ busybox-1.8.1/archival/libipkg/conffile_list.h 2007-11-10 17:40:53.340763516 +0100
574 +/* conffile_list.h - the itsy package management system
578 + Copyright (C) 2001 University of Southern California
580 + This program is free software; you can redistribute it and/or
581 + modify it under the terms of the GNU General Public License as
582 + published by the Free Software Foundation; either version 2, or (at
583 + your option) any later version.
585 + This program is distributed in the hope that it will be useful, but
586 + WITHOUT ANY WARRANTY; without even the implied warranty of
587 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
588 + General Public License for more details.
591 +#ifndef CONFFILE_LIST_H
592 +#define CONFFILE_LIST_H
594 +#include "conffile.h"
595 +#include "nv_pair_list.h"
597 +typedef struct nv_pair_list_elt conffile_list_elt_t;
598 +typedef struct nv_pair_list conffile_list_t;
600 +int conffile_list_init(conffile_list_t *list);
601 +void conffile_list_deinit(conffile_list_t *list);
603 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
604 + const char *root_dir);
605 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
606 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
610 Index: busybox-1.8.1/archival/libipkg/file_util.c
611 ===================================================================
612 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
613 +++ busybox-1.8.1/archival/libipkg/file_util.c 2007-11-10 17:40:53.340763516 +0100
615 +/* file_util.c - convenience routines for common stat operations
619 + Copyright (C) 2001 University of Southern California
621 + This program is free software; you can redistribute it and/or
622 + modify it under the terms of the GNU General Public License as
623 + published by the Free Software Foundation; either version 2, or (at
624 + your option) any later version.
626 + This program is distributed in the hope that it will be useful, but
627 + WITHOUT ANY WARRANTY; without even the implied warranty of
628 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
629 + General Public License for more details.
633 +#include <sys/types.h>
634 +#include <sys/stat.h>
636 +#include "sprintf_alloc.h"
637 +#include "file_util.h"
641 +int file_exists(const char *file_name)
644 + struct stat stat_buf;
646 + err = stat(file_name, &stat_buf);
654 +int file_is_dir(const char *file_name)
657 + struct stat stat_buf;
659 + err = stat(file_name, &stat_buf);
664 + return S_ISDIR(stat_buf.st_mode);
667 +/* read a single line from a file, stopping at a newline or EOF.
668 + If a newline is read, it will appear in the resulting string.
669 + Return value is a malloc'ed char * which should be freed at
670 + some point by the caller.
672 + Return value is NULL if the file is at EOF when called.
674 +#define FILE_READ_LINE_BUF_SIZE 1024
675 +char *file_read_line_alloc(FILE *file)
677 + char buf[FILE_READ_LINE_BUF_SIZE];
682 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
683 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
684 + buf_len = strlen(buf);
686 + line_size += buf_len;
687 + line = realloc(line, line_size);
688 + if (line == NULL) {
689 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
694 + line_size = buf_len + 1;
695 + line = strdup(buf);
697 + if (buf[buf_len - 1] == '\n') {
705 +int file_move(const char *src, const char *dest)
709 + err = rename(src, dest);
711 + if (err && errno == EXDEV) {
712 + err = file_copy(src, dest);
715 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
716 + __FUNCTION__, src, dest, strerror(errno));
722 +/* I put these here to keep libbb dependencies from creeping all over
724 +int file_copy(const char *src, const char *dest)
728 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
730 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
731 + __FUNCTION__, src, dest);
737 +int file_mkdir_hier(const char *path, long mode)
739 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
742 +char *file_md5sum_alloc(const char *file_name)
744 + return hash_file(file_name, HASH_MD5);
747 Index: busybox-1.8.1/archival/libipkg/file_util.h
748 ===================================================================
749 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
750 +++ busybox-1.8.1/archival/libipkg/file_util.h 2007-11-10 17:40:53.344763742 +0100
752 +/* file_util.h - convenience routines for common file operations
756 + Copyright (C) 2001 University of Southern California
758 + This program is free software; you can redistribute it and/or
759 + modify it under the terms of the GNU General Public License as
760 + published by the Free Software Foundation; either version 2, or (at
761 + your option) any later version.
763 + This program is distributed in the hope that it will be useful, but
764 + WITHOUT ANY WARRANTY; without even the implied warranty of
765 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
766 + General Public License for more details.
772 +int file_exists(const char *file_name);
773 +int file_is_dir(const char *file_name);
774 +char *file_read_line_alloc(FILE *file);
775 +int file_move(const char *src, const char *dest);
776 +int file_copy(const char *src, const char *dest);
777 +int file_mkdir_hier(const char *path, long mode);
778 +char *file_md5sum_alloc(const char *file_name);
781 Index: busybox-1.8.1/archival/libipkg/hash_table.c
782 ===================================================================
783 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
784 +++ busybox-1.8.1/archival/libipkg/hash_table.c 2007-11-10 17:40:53.344763742 +0100
786 +/* hash.c - hash tables for ipkg
788 + Steven M. Ayer, Jamey Hicks
790 + Copyright (C) 2002 Compaq Computer Corporation
792 + This program is free software; you can redistribute it and/or
793 + modify it under the terms of the GNU General Public License as
794 + published by the Free Software Foundation; either version 2, or (at
795 + your option) any later version.
797 + This program is distributed in the hope that it will be useful, but
798 + WITHOUT ANY WARRANTY; without even the implied warranty of
799 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
800 + General Public License for more details.
807 +#include "hash_table.h"
808 +#include "ipkg_message.h"
811 +static int hash_index(hash_table_t *hash, const char *pkg_name);
812 +static int rotating(const char *key, int len, int prime);
814 +static int hash_index(hash_table_t *hash, const char *pkg_name)
816 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
819 +static int rotating(const char *key, int len, int prime)
821 + unsigned int hash, i;
822 + for (hash=len, i=0; i<len; ++i)
823 + hash = (hash<<4)^(hash>>28)^key[i];
824 + return (hash % prime);
829 + * this is an open table keyed by strings
831 +int hash_table_init(const char *name, hash_table_t *hash, int len)
833 + static int primes_table[] = {
834 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
835 + 19471, 23143, 33961, 46499, 49727, 99529, 0
839 + if (hash->entries != NULL) {
840 + /* we have been here already */
845 + hash->entries = NULL;
846 + hash->n_entries = 0;
847 + hash->hash_entry_key = NULL;
849 + picker = primes_table;
850 + while(*picker && (*picker++ < len));
852 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
855 + hash->n_entries = *picker;
856 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
857 + if (hash->entries == NULL) {
858 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
864 +void hash_table_deinit(hash_table_t *hash)
866 + free(hash->entries);
867 + hash->entries = NULL;
868 + hash->n_entries = 0;
871 +void *hash_table_get(hash_table_t *hash, const char *key)
873 + int ndx= hash_index(hash, key);
874 + hash_entry_t *hash_entry = hash->entries + ndx;
877 + if (hash_entry->key)
879 + if (strcmp(key, hash_entry->key) == 0) {
880 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
881 + return hash_entry->data;
884 + hash_entry = hash_entry->next;
889 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
891 + int ndx= hash_index(hash, key);
892 + hash_entry_t *hash_entry = hash->entries + ndx;
893 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
894 + if (hash_entry->key) {
895 + if (strcmp(hash_entry->key, key) == 0) {
896 + /* alread in table, update the value */
897 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
898 + hash_entry->data = value;
902 + * if this is a collision, we have to go to the end of the ll,
903 + * then add a new entry
904 + * before we can hook up the value
906 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
907 + while (hash_entry->next)
908 + hash_entry = hash_entry->next;
909 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
910 + if (!hash_entry->next) {
913 + hash_entry = hash_entry->next;
914 + hash_entry->next = NULL;
917 + hash->n_elements++;
918 + hash_entry->key = strdup(key);
919 + hash_entry->data = value;
925 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
931 + for (i = 0; i < hash->n_entries; i++) {
932 + hash_entry_t *hash_entry = (hash->entries + i);
934 + if(hash_entry->key) {
935 + f(hash_entry->key, hash_entry->data, data);
937 + } while((hash_entry = hash_entry->next));
941 Index: busybox-1.8.1/archival/libipkg/hash_table.h
942 ===================================================================
943 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
944 +++ busybox-1.8.1/archival/libipkg/hash_table.h 2007-11-10 17:40:53.344763742 +0100
946 +/* hash.h - hash tables for ipkg
948 + Steven M. Ayer, Jamey Hicks
950 + Copyright (C) 2002 Compaq Computer Corporation
952 + This program is free software; you can redistribute it and/or
953 + modify it under the terms of the GNU General Public License as
954 + published by the Free Software Foundation; either version 2, or (at
955 + your option) any later version.
957 + This program is distributed in the hope that it will be useful, but
958 + WITHOUT ANY WARRANTY; without even the implied warranty of
959 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
960 + General Public License for more details.
963 +#ifndef _HASH_TABLE_H_
964 +#define _HASH_TABLE_H_
966 +typedef struct hash_entry hash_entry_t;
967 +typedef struct hash_table hash_table_t;
972 + struct hash_entry * next;
977 + hash_entry_t * entries;
978 + int n_entries; /* number of buckets */
980 + const char * (*hash_entry_key)(void * data);
983 +int hash_table_init(const char *name, hash_table_t *hash, int len);
984 +void hash_table_deinit(hash_table_t *hash);
985 +void *hash_table_get(hash_table_t *hash, const char *key);
986 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
987 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
989 +#endif /* _HASH_TABLE_H_ */
990 Index: busybox-1.8.1/archival/libipkg/ipkg_cmd.c
991 ===================================================================
992 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
993 +++ busybox-1.8.1/archival/libipkg/ipkg_cmd.c 2007-11-10 17:40:53.344763742 +0100
995 +/* ipkg_cmd.c - the itsy package management system
999 + Copyright (C) 2001 University of Southern California
1001 + This program is free software; you can redistribute it and/or
1002 + modify it under the terms of the GNU General Public License as
1003 + published by the Free Software Foundation; either version 2, or (at
1004 + your option) any later version.
1006 + This program is distributed in the hope that it will be useful, but
1007 + WITHOUT ANY WARRANTY; without even the implied warranty of
1008 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1009 + General Public License for more details.
1012 +#include <string.h>
1015 +#include <libgen.h>
1018 +#include <stdlib.h>
1019 +#include <unistd.h>
1020 +#include <signal.h>
1022 +#include <dirent.h>
1024 +#include "ipkg_conf.h"
1025 +#include "ipkg_cmd.h"
1026 +#include "ipkg_message.h"
1028 +#include "pkg_dest.h"
1029 +#include "pkg_parse.h"
1030 +#include "sprintf_alloc.h"
1032 +#include "file_util.h"
1033 +#include "str_util.h"
1035 +#include "unarchive.h"
1037 +#include <fnmatch.h>
1040 +#include "ipkg_download.h"
1041 +#include "ipkg_install.h"
1042 +#include "ipkg_upgrade.h"
1043 +#include "ipkg_remove.h"
1044 +#include "ipkg_configure.h"
1045 +#include "ipkg_message.h"
1048 +#include "libipkg.h"
1049 +static void *p_userdata = NULL;
1052 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1076 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1078 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1079 + array for easier maintenance */
1080 +static ipkg_cmd_t cmds[] = {
1081 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1082 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1083 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1084 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1085 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1086 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1087 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1088 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1089 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1090 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1091 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1092 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1093 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1094 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1095 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1096 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1097 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1098 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1101 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1102 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1103 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1104 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1105 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1106 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1107 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1108 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1109 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1112 +int ipkg_state_changed;
1113 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1115 + if (ipkg_state_changed && !conf->noaction) {
1116 + ipkg_message(conf, IPKG_INFO,
1117 + " writing status file\n");
1118 + ipkg_conf_write_status_files(conf);
1119 + pkg_write_changed_filelists(conf);
1121 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1126 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1128 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1133 + for (i=0; i < num_cmds; i++) {
1135 + if (strcmp(name, cmd->name) == 0) {
1144 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1147 + p_userdata = userdata;
1150 + result = (cmd->fun)(conf, argc, argv);
1151 + if ( result == 0 ) {
1152 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1154 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1157 + if ( error_list ) {
1158 + reverse_error_list(&error_list);
1160 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1161 + /* Here we print the errors collected and free the list */
1162 + while (error_list != NULL) {
1163 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1164 + error_list = error_list->next;
1167 + free_error_list(&error_list);
1171 + p_userdata = NULL;
1175 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1177 + return (cmd->fun)(conf, argc, argv);
1181 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1186 + pkg_src_list_elt_t *iter;
1190 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1192 + if (! file_is_dir(lists_dir)) {
1193 + if (file_exists(lists_dir)) {
1194 + ipkg_message(conf, IPKG_ERROR,
1195 + "%s: ERROR: %s exists, but is not a directory\n",
1196 + __FUNCTION__, lists_dir);
1200 + err = file_mkdir_hier(lists_dir, 0755);
1202 + ipkg_message(conf, IPKG_ERROR,
1203 + "%s: ERROR: failed to make directory %s: %s\n",
1204 + __FUNCTION__, lists_dir, strerror(errno));
1211 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1212 + char *url, *list_file_name;
1216 + if (src->extra_data) /* debian style? */
1217 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1218 + src->gzip ? "Packages.gz" : "Packages");
1220 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1222 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1225 + char *tmp_file_name;
1228 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1230 + if (mkdtemp (tmp) == NULL) {
1231 + perror ("mkdtemp");
1236 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1237 + err = ipkg_download(conf, url, tmp_file_name);
1239 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1240 + in = fopen (tmp_file_name, "r");
1241 + out = fopen (list_file_name, "w");
1243 + inflate_unzip_result res;
1244 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1251 + unlink (tmp_file_name);
1256 + err = ipkg_download(conf, url, list_file_name);
1260 + ipkg_message(conf, IPKG_NOTICE,
1261 + "Updated list of available packages in %s\n",
1265 + free(list_file_name);
1269 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1271 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1272 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1278 + pkg_vec_t *available = pkg_vec_alloc();
1279 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1280 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1281 + for (i = 0; i < available->len; i++) {
1282 + pkg_t *pkg = available->pkgs[i];
1283 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1284 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1285 + pkg->state_want = SW_UNKNOWN;
1289 + pkg_vec_free(available);
1291 + write_status_files_if_changed(conf);
1300 +/* scan the args passed and cache the local filenames of the packages */
1301 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1307 + * First scan through package names/urls
1308 + * For any urls, download the packages and install in database.
1309 + * For any files, install package info in database.
1311 + for (i = 0; i < argc; i ++) {
1312 + char *filename = argv [i];
1313 + //char *tmp = basename (tmp);
1314 + //int tmplen = strlen (tmp);
1316 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1318 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1321 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1323 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1330 +struct ipkg_intercept
1336 +typedef struct ipkg_intercept *ipkg_intercept_t;
1338 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1340 + ipkg_intercept_t ctx;
1344 + ctx = malloc (sizeof (*ctx));
1345 + ctx->oldpath = strdup (getenv ("PATH"));
1347 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1348 + setenv ("PATH", newpath, 1);
1353 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1354 + if (mkdir (ctx->statedir, 0770) < 0) {
1355 + if (errno == EEXIST) {
1356 + free (ctx->statedir);
1360 + perror (ctx->statedir);
1363 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1367 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1373 + setenv ("PATH", ctx->oldpath, 1);
1374 + free (ctx->oldpath);
1376 + dir = opendir (ctx->statedir);
1378 + struct dirent *de;
1379 + while (de = readdir (dir), de != NULL) {
1382 + if (de->d_name[0] == '.')
1385 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1386 + if (access (path, X_OK) == 0) {
1387 + if (system (path)) {
1389 + perror (de->d_name);
1395 + perror (ctx->statedir);
1397 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1401 + free (ctx->statedir);
1407 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1412 + ipkg_intercept_t ic;
1415 + ipkg_message(conf, IPKG_INFO,
1416 + "Configuring unpacked packages\n");
1419 + all = pkg_vec_alloc();
1420 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1422 + ic = ipkg_prep_intercepts (conf);
1424 + for(i = 0; i < all->len; i++) {
1425 + pkg = all->pkgs[i];
1427 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1430 + if (pkg->state_status == SS_UNPACKED) {
1431 + ipkg_message(conf, IPKG_NOTICE,
1432 + "Configuring %s\n", pkg->name);
1434 + r = ipkg_configure(conf, pkg);
1436 + pkg->state_status = SS_INSTALLED;
1437 + pkg->parent->state_status = SS_INSTALLED;
1438 + pkg->state_flag &= ~SF_PREFER;
1446 + r = ipkg_finalize_intercepts (ic);
1450 + pkg_vec_free(all);
1454 +static void sigint_handler(int sig)
1456 + signal(sig, SIG_DFL);
1457 + ipkg_message(NULL, IPKG_NOTICE,
1458 + "ipkg: interrupted. writing out status database\n");
1459 + write_status_files_if_changed(global_conf);
1463 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1469 + global_conf = conf;
1470 + signal(SIGINT, sigint_handler);
1473 + * Now scan through package names and install
1475 + for (i=0; i < argc; i++) {
1478 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1479 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1480 + if (err != EINVAL && err != 0)
1483 + pkg_info_preinstall_check(conf);
1485 + for (i=0; i < argc; i++) {
1487 + if (conf->multiple_providers)
1488 + err = ipkg_install_multi_by_name(conf, arg);
1490 + err = ipkg_install_by_name(conf, arg);
1492 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1493 + ipkg_message(conf, IPKG_ERROR,
1494 + "Cannot find package %s.\n"
1495 + "Check the spelling or perhaps run 'ipkg update'\n",
1500 + /* recheck to verify that all dependences are satisfied */
1501 + if (0) ipkg_satisfy_all_dependences(conf);
1503 + ipkg_configure_packages(conf, NULL);
1505 + write_status_files_if_changed(conf);
1510 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1516 + global_conf = conf;
1517 + signal(SIGINT, sigint_handler);
1520 + for (i=0; i < argc; i++) {
1521 + char *arg = argv[i];
1523 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1524 + if (err != EINVAL && err != 0)
1527 + pkg_info_preinstall_check(conf);
1529 + for (i=0; i < argc; i++) {
1530 + char *arg = argv[i];
1531 + if (conf->restrict_to_default_dest) {
1532 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1534 + conf->default_dest);
1535 + if (pkg == NULL) {
1536 + ipkg_message(conf, IPKG_NOTICE,
1537 + "Package %s not installed in %s\n",
1538 + argv[i], conf->default_dest->name);
1542 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1546 + ipkg_upgrade_pkg(conf, pkg);
1548 + ipkg_install_by_name(conf, arg);
1552 + pkg_vec_t *installed = pkg_vec_alloc();
1554 + pkg_info_preinstall_check(conf);
1556 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1557 + for (i = 0; i < installed->len; i++) {
1558 + pkg = installed->pkgs[i];
1559 + ipkg_upgrade_pkg(conf, pkg);
1561 + pkg_vec_free(installed);
1564 + /* recheck to verify that all dependences are satisfied */
1565 + if (0) ipkg_satisfy_all_dependences(conf);
1567 + ipkg_configure_packages(conf, NULL);
1569 + write_status_files_if_changed(conf);
1574 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1580 + pkg_info_preinstall_check(conf);
1581 + for (i = 0; i < argc; i++) {
1584 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1585 + if (pkg == NULL) {
1586 + ipkg_message(conf, IPKG_ERROR,
1587 + "Cannot find package %s.\n"
1588 + "Check the spelling or perhaps run 'ipkg update'\n",
1593 + err = ipkg_download_pkg(conf, pkg, ".");
1596 + ipkg_message(conf, IPKG_ERROR,
1597 + "Failed to download %s\n", pkg->name);
1599 + ipkg_message(conf, IPKG_NOTICE,
1600 + "Downloaded %s as %s\n",
1601 + pkg->name, pkg->local_filename);
1609 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1612 + pkg_vec_t *available;
1614 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1616 + char *pkg_name = NULL;
1617 + char *version_str;
1620 + pkg_name = argv[0];
1622 + available = pkg_vec_alloc();
1623 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1624 + for (i=0; i < available->len; i++) {
1625 + pkg = available->pkgs[i];
1626 + /* if we have package name or pattern and pkg does not match, then skip it */
1627 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1629 + if (pkg->description) {
1630 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1632 + desc_short[0] = '\0';
1634 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1635 + newline = strchr(desc_short, '\n');
1640 + printf("%s - %s\n", pkg->name, desc_short);
1642 + if (ipkg_cb_list) {
1643 + version_str = pkg_version_str_alloc(pkg);
1644 + ipkg_cb_list(pkg->name,desc_short,
1646 + pkg->state_status,
1648 + free(version_str);
1652 + pkg_vec_free(available);
1658 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1661 + pkg_vec_t *available;
1663 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1665 + char *pkg_name = NULL;
1666 + char *version_str;
1669 + pkg_name = argv[0];
1671 + available = pkg_vec_alloc();
1672 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1673 + for (i=0; i < available->len; i++) {
1674 + pkg = available->pkgs[i];
1675 + /* if we have package name or pattern and pkg does not match, then skip it */
1676 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1678 + if (pkg->description) {
1679 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1681 + desc_short[0] = '\0';
1683 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1684 + newline = strchr(desc_short, '\n');
1689 + printf("%s - %s\n", pkg->name, desc_short);
1691 + if (ipkg_cb_list) {
1692 + version_str = pkg_version_str_alloc(pkg);
1693 + ipkg_cb_list(pkg->name,desc_short,
1695 + pkg->state_status,
1697 + free(version_str);
1705 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1708 + pkg_vec_t *available;
1710 + char *pkg_name = NULL;
1711 + char **pkg_fields = NULL;
1713 + char *buff ; // = (char *)malloc(1);
1716 + pkg_name = argv[0];
1719 + pkg_fields = &argv[1];
1720 + n_fields = argc - 1;
1723 + available = pkg_vec_alloc();
1724 + if (installed_only)
1725 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1727 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1728 + for (i=0; i < available->len; i++) {
1729 + pkg = available->pkgs[i];
1730 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1735 + for (j = 0; j < n_fields; j++)
1736 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1738 + pkg_print_info(pkg, stdout);
1742 + buff = pkg_formatted_info(pkg);
1744 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1745 + pkg->state_status,
1749 + We should not forget that actually the pointer is allocated.
1750 + We need to free it :) ( Thanks florian for seeing the error )
1755 + if (conf->verbosity > 1) {
1756 + conffile_list_elt_t *iter;
1757 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1758 + conffile_t *cf = iter->data;
1759 + int modified = conffile_has_been_modified(conf, cf);
1760 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1761 + cf->name, cf->value, modified);
1769 + pkg_vec_free(available);
1774 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1776 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1779 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1781 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1784 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1789 + char *pkg_name = NULL;
1791 + pkg_name = argv[0];
1793 + err = ipkg_configure_packages (conf, pkg_name);
1796 + err = ipkg_configure_packages (conf, NULL);
1799 + write_status_files_if_changed(conf);
1804 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1807 + char *globpattern;
1810 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1811 + err = glob(globpattern, 0, NULL, &globbuf);
1812 + free(globpattern);
1817 + ipkg_message(conf, IPKG_NOTICE,
1818 + "The following packages in %s will now be installed.\n",
1819 + conf->pending_dir);
1820 + for (i = 0; i < globbuf.gl_pathc; i++) {
1821 + ipkg_message(conf, IPKG_NOTICE,
1822 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1824 + ipkg_message(conf, IPKG_NOTICE, "\n");
1825 + for (i = 0; i < globbuf.gl_pathc; i++) {
1826 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1828 + err = unlink(globbuf.gl_pathv[i]);
1830 + ipkg_message(conf, IPKG_ERROR,
1831 + "%s: ERROR: failed to unlink %s: %s\n",
1832 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1837 + globfree(&globbuf);
1842 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1846 + pkg_t *pkg_to_remove;
1847 + pkg_vec_t *available;
1848 + char *pkg_name = NULL;
1849 + global_conf = conf;
1850 + signal(SIGINT, sigint_handler);
1852 +// ENH: Add the "no pkg removed" just in case.
1856 + available = pkg_vec_alloc();
1857 + pkg_info_preinstall_check(conf);
1859 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1860 + for (i=0; i < argc; i++) {
1861 + pkg_name = malloc(strlen(argv[i])+2);
1862 + strcpy(pkg_name,argv[i]);
1863 + for (a=0; a < available->len; a++) {
1864 + pkg = available->pkgs[a];
1865 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1868 + if (conf->restrict_to_default_dest) {
1869 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1871 + conf->default_dest);
1873 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1876 + if (pkg == NULL) {
1877 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1880 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1881 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1884 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1889 + pkg_vec_free(available);
1891 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1892 + int flagged_pkg_count = 0;
1895 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1897 + for (i = 0; i < installed_pkgs->len; i++) {
1898 + pkg = installed_pkgs->pkgs[i];
1899 + if (pkg->state_flag & SF_USER) {
1900 + flagged_pkg_count++;
1902 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1903 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1906 + if (!flagged_pkg_count) {
1907 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1908 + "so refusing to uninstall unflagged non-leaf packages\n");
1912 + /* find packages not flagged SF_USER (i.e., installed to
1913 + * satisfy a dependence) and not having any dependents, and
1917 + for (i = 0; i < installed_pkgs->len; i++) {
1918 + pkg = installed_pkgs->pkgs[i];
1919 + if (!(pkg->state_flag & SF_USER)
1920 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1922 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1923 + ipkg_remove_pkg(conf, pkg,0);
1927 + } while (removed);
1928 + pkg_vec_free(installed_pkgs);
1932 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1934 + write_status_files_if_changed(conf);
1938 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1943 + global_conf = conf;
1944 + signal(SIGINT, sigint_handler);
1946 + pkg_info_preinstall_check(conf);
1948 + for (i=0; i < argc; i++) {
1949 + if (conf->restrict_to_default_dest) {
1950 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1952 + conf->default_dest);
1954 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1957 + if (pkg == NULL) {
1958 + ipkg_message(conf, IPKG_ERROR,
1959 + "Package %s is not installed.\n", argv[i]);
1962 + ipkg_purge_pkg(conf, pkg);
1965 + write_status_files_if_changed(conf);
1969 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1973 + char *flags = argv[0];
1975 + global_conf = conf;
1976 + signal(SIGINT, sigint_handler);
1978 + for (i=1; i < argc; i++) {
1979 + if (conf->restrict_to_default_dest) {
1980 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1982 + conf->default_dest);
1984 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1987 + if (pkg == NULL) {
1988 + ipkg_message(conf, IPKG_ERROR,
1989 + "Package %s is not installed.\n", argv[i]);
1992 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1993 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1994 + pkg->state_flag = pkg_state_flag_from_str(flags);
1996 +/* pb_ asked this feature 03292004 */
1997 +/* Actually I will use only this two, but this is an open for various status */
1998 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1999 + pkg->state_status = pkg_state_status_from_str(flags);
2001 + ipkg_state_changed++;
2002 + ipkg_message(conf, IPKG_NOTICE,
2003 + "Setting flags for package %s to %s\n",
2004 + pkg->name, flags);
2007 + write_status_files_if_changed(conf);
2011 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2014 + str_list_t *installed_files;
2015 + str_list_elt_t *iter;
2016 + char *pkg_version;
2017 + size_t buff_len = 8192;
2021 + buff = (char *)malloc(buff_len);
2022 + if ( buff == NULL ) {
2023 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2031 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2033 + if (pkg == NULL) {
2034 + ipkg_message(conf, IPKG_ERROR,
2035 + "Package %s not installed.\n", argv[0]);
2039 + installed_files = pkg_get_installed_files(pkg);
2040 + pkg_version = pkg_version_str_alloc(pkg);
2043 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2044 + pkg->name, pkg_version, pkg->dest->name);
2045 + for (iter = installed_files->head; iter; iter = iter->next) {
2051 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2052 + pkg->name, pkg_version, pkg->dest->name) + 1;
2053 + if (used_len > buff_len) {
2055 + buff = realloc (buff, buff_len);
2058 + for (iter = installed_files->head; iter; iter = iter->next) {
2059 + used_len += strlen (iter->data) + 1;
2060 + while (buff_len <= used_len) {
2062 + buff = realloc (buff, buff_len);
2064 + strncat(buff, iter->data, buff_len);
2065 + strncat(buff, "\n", buff_len);
2067 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2069 + pkg_version_str_alloc(pkg),
2070 + pkg->state_status,
2076 + free(pkg_version);
2077 + pkg_free_installed_files(pkg);
2082 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2086 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2087 + const char *rel_str = "depends on";
2090 + pkg_info_preinstall_check(conf);
2092 + if (conf->query_all)
2093 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2095 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2096 + for (i = 0; i < argc; i++) {
2097 + const char *target = argv[i];
2100 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2102 + for (j = 0; j < available_pkgs->len; j++) {
2103 + pkg_t *pkg = available_pkgs->pkgs[j];
2104 + if (fnmatch(target, pkg->name, 0) == 0) {
2106 + int count = pkg->depends_count + pkg->pre_depends_count;
2107 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2108 + target, pkg->architecture, rel_str);
2109 + for (k = 0; k < count; k++) {
2110 + compound_depend_t *cdepend = &pkg->depends[k];
2112 + for (l = 0; l < cdepend->possibility_count; l++) {
2113 + depend_t *possibility = cdepend->possibilities[l];
2114 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2115 + if (conf->verbosity > 0) {
2116 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2117 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2118 + if (possibility->version) {
2119 + char *typestr = NULL;
2120 + switch (possibility->constraint) {
2121 + case NONE: typestr = "none"; break;
2122 + case EARLIER: typestr = "<"; break;
2123 + case EARLIER_EQUAL: typestr = "<="; break;
2124 + case EQUAL: typestr = "="; break;
2125 + case LATER_EQUAL: typestr = ">="; break;
2126 + case LATER: typestr = ">"; break;
2128 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2132 + ipkg_message(conf, IPKG_ERROR, "\n");
2138 + pkg_vec_free(available_pkgs);
2143 +enum what_field_type {
2152 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2156 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2157 + const char *rel_str = NULL;
2161 + switch (what_field_type) {
2162 + case WHATDEPENDS: rel_str = "depends on"; break;
2163 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2164 + case WHATSUGGESTS: rel_str = "suggests"; break;
2165 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2166 + case WHATPROVIDES: rel_str = "provides"; break;
2167 + case WHATREPLACES: rel_str = "replaces"; break;
2170 + if (conf->query_all)
2171 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2173 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2175 + /* mark the root set */
2176 + pkg_vec_clear_marks(available_pkgs);
2177 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2178 + for (i = 0; i < argc; i++) {
2179 + const char *dependee_pattern = argv[i];
2180 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2182 + for (i = 0; i < available_pkgs->len; i++) {
2183 + pkg_t *pkg = available_pkgs->pkgs[i];
2184 + if (pkg->state_flag & SF_MARKED) {
2185 + /* mark the parent (abstract) package */
2186 + pkg_mark_provides(pkg);
2187 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2191 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2196 + for (j = 0; j < available_pkgs->len; j++) {
2197 + pkg_t *pkg = available_pkgs->pkgs[j];
2199 + int count = ((what_field_type == WHATCONFLICTS)
2200 + ? pkg->conflicts_count
2201 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2202 + /* skip this package if it is already marked */
2203 + if (pkg->parent->state_flag & SF_MARKED) {
2206 + for (k = 0; k < count; k++) {
2207 + compound_depend_t *cdepend =
2208 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2210 + for (l = 0; l < cdepend->possibility_count; l++) {
2211 + depend_t *possibility = cdepend->possibilities[l];
2212 + if (possibility->pkg->state_flag & SF_MARKED) {
2213 + /* mark the depending package so we won't visit it again */
2214 + pkg->state_flag |= SF_MARKED;
2215 + pkg_mark_provides(pkg);
2218 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2219 + if (conf->verbosity > 0) {
2220 + char *ver = pkg_version_str_alloc(pkg);
2221 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2222 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2223 + if (possibility->version) {
2224 + char *typestr = NULL;
2225 + switch (possibility->constraint) {
2226 + case NONE: typestr = "none"; break;
2227 + case EARLIER: typestr = "<"; break;
2228 + case EARLIER_EQUAL: typestr = "<="; break;
2229 + case EQUAL: typestr = "="; break;
2230 + case LATER_EQUAL: typestr = ">="; break;
2231 + case LATER: typestr = ">"; break;
2233 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2236 + if (!pkg_dependence_satisfiable(conf, possibility))
2237 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2239 + ipkg_message(conf, IPKG_NOTICE, "\n");
2240 + goto next_package;
2247 + } while (changed && recursive);
2248 + pkg_vec_free(available_pkgs);
2254 +int pkg_mark_provides(pkg_t *pkg)
2256 + int provides_count = pkg->provides_count;
2257 + abstract_pkg_t **provides = pkg->provides;
2259 + pkg->parent->state_flag |= SF_MARKED;
2260 + for (i = 0; i < provides_count; i++) {
2261 + provides[i]->state_flag |= SF_MARKED;
2266 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2268 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2270 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2272 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2275 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2277 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2280 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2282 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2285 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2287 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2290 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2294 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2295 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2298 + pkg_info_preinstall_check(conf);
2300 + if (conf->query_all)
2301 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2303 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2304 + for (i = 0; i < argc; i++) {
2305 + const char *target = argv[i];
2308 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2310 + for (j = 0; j < available_pkgs->len; j++) {
2311 + pkg_t *pkg = available_pkgs->pkgs[j];
2313 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2314 + for (k = 0; k < count; k++) {
2315 + abstract_pkg_t *apkg =
2316 + ((what_field_type == WHATPROVIDES)
2317 + ? pkg->provides[k]
2318 + : pkg->replaces[k]);
2319 + if (fnmatch(target, apkg->name, 0) == 0) {
2320 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2321 + if (strcmp(target, apkg->name) != 0)
2322 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2323 + ipkg_message(conf, IPKG_ERROR, "\n");
2328 + pkg_vec_free(available_pkgs);
2333 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2335 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2338 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2340 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2343 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2347 + pkg_vec_t *installed;
2349 + str_list_t *installed_files;
2350 + str_list_elt_t *iter;
2351 + char *installed_file;
2357 + installed = pkg_vec_alloc();
2358 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2360 + for (i=0; i < installed->len; i++) {
2361 + pkg = installed->pkgs[i];
2363 + installed_files = pkg_get_installed_files(pkg);
2365 + for (iter = installed_files->head; iter; iter = iter->next) {
2366 + installed_file = iter->data;
2367 + if (fnmatch(argv[0], installed_file, 0)==0) {
2369 + printf("%s: %s\n", pkg->name, installed_file);
2371 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2373 + pkg_version_str_alloc(pkg),
2374 + pkg->state_status, p_userdata);
2379 + pkg_free_installed_files(pkg);
2382 + /* XXX: CLEANUP: It's not obvious from the name of
2383 + pkg_hash_fetch_all_installed that we need to call
2384 + pkg_vec_free to avoid a memory leak. */
2385 + pkg_vec_free(installed);
2390 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2393 + /* this is a bit gross */
2394 + struct pkg p1, p2;
2395 + parseVersion(&p1, argv[0]);
2396 + parseVersion(&p2, argv[2]);
2397 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2399 + ipkg_message(conf, IPKG_ERROR,
2400 + "ipkg compare_versions <v1> <op> <v2>\n"
2401 + "<op> is one of <= >= << >> =\n");
2406 +#ifndef HOST_CPU_STR
2407 +#define HOST_CPU_STR__(X) #X
2408 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2409 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2412 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2414 + nv_pair_list_elt_t *l;
2416 + l = conf->arch_list.head;
2418 + nv_pair_t *nv = l->data;
2419 + printf("arch %s %s\n", nv->name, nv->value);
2426 Index: busybox-1.8.1/archival/libipkg/ipkg_cmd.h
2427 ===================================================================
2428 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2429 +++ busybox-1.8.1/archival/libipkg/ipkg_cmd.h 2007-11-10 17:40:53.348763971 +0100
2431 +/* ipkg_cmd.h - the itsy package management system
2435 + Copyright (C) 2001 University of Southern California
2437 + This program is free software; you can redistribute it and/or
2438 + modify it under the terms of the GNU General Public License as
2439 + published by the Free Software Foundation; either version 2, or (at
2440 + your option) any later version.
2442 + This program is distributed in the hope that it will be useful, but
2443 + WITHOUT ANY WARRANTY; without even the implied warranty of
2444 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2445 + General Public License for more details.
2451 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2456 + int requires_args;
2457 + ipkg_cmd_fun_t fun;
2459 +typedef struct ipkg_cmd ipkg_cmd_t;
2461 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2463 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2464 + const char **argv, void *userdata);
2466 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2468 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2469 +/* install any packges with state_want == SW_INSTALL */
2470 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2471 +/* ensure that all dependences are satisfied */
2472 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2474 +int pkg_mark_provides(pkg_t *pkg);
2477 Index: busybox-1.8.1/archival/libipkg/ipkg_conf.c
2478 ===================================================================
2479 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2480 +++ busybox-1.8.1/archival/libipkg/ipkg_conf.c 2007-11-10 17:40:53.348763971 +0100
2482 +/* ipkg_conf.c - the itsy package management system
2486 + Copyright (C) 2001 University of Southern California
2488 + This program is free software; you can redistribute it and/or
2489 + modify it under the terms of the GNU General Public License as
2490 + published by the Free Software Foundation; either version 2, or (at
2491 + your option) any later version.
2493 + This program is distributed in the hope that it will be useful, but
2494 + WITHOUT ANY WARRANTY; without even the implied warranty of
2495 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2496 + General Public License for more details.
2502 +#include "ipkg_conf.h"
2504 +#include "xregex.h"
2505 +#include "sprintf_alloc.h"
2506 +#include "ipkg_conf.h"
2507 +#include "ipkg_message.h"
2508 +#include "file_util.h"
2509 +#include "str_util.h"
2510 +#include "xsystem.h"
2513 +ipkg_conf_t *global_conf;
2515 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2516 + pkg_src_list_t *pkg_src_list,
2517 + nv_pair_list_t *tmp_dest_nv_pair_list,
2518 + char **tmp_lists_dir);
2519 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2520 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2521 + const char *name, const char *value);
2522 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2523 + const char *default_dest_name);
2524 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2525 + pkg_src_list_t *nv_pair_list);
2526 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2527 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2529 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2531 + ipkg_option_t tmp[] = {
2532 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2533 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2534 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2535 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2536 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2537 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2538 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2539 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2540 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2541 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2542 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2543 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2544 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2545 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2546 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2547 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2548 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2549 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2550 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2551 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2552 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2556 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2557 + if ( options == NULL ){
2558 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2562 + memcpy(*options, tmp, sizeof(tmp));
2566 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2572 + *conf_str = strdup(arg_str);
2576 +static void ipkg_conf_free_string(char **conf_str)
2584 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2587 + char *tmp_dir_base;
2588 + nv_pair_list_t tmp_dest_nv_pair_list;
2589 + char * lists_dir =NULL;
2591 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2592 + char *pending_dir =NULL;
2594 + memset(conf, 0, sizeof(ipkg_conf_t));
2596 + pkg_src_list_init(&conf->pkg_src_list);
2598 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2599 + pkg_dest_list_init(&conf->pkg_dest_list);
2601 + nv_pair_list_init(&conf->arch_list);
2603 + conf->restrict_to_default_dest = 0;
2604 + conf->default_dest = NULL;
2607 + if (args->tmp_dir)
2608 + tmp_dir_base = args->tmp_dir;
2610 + tmp_dir_base = getenv("TMPDIR");
2611 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2612 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2613 + IPKG_CONF_TMP_DIR_SUFFIX);
2614 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2615 + if (conf->tmp_dir == NULL) {
2616 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2617 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2621 + conf->force_depends = 0;
2622 + conf->force_defaults = 0;
2623 + conf->force_overwrite = 0;
2624 + conf->force_downgrade = 0;
2625 + conf->force_reinstall = 0;
2626 + conf->force_space = 0;
2627 + conf->force_removal_of_essential_packages = 0;
2628 + conf->force_removal_of_dependent_packages = 0;
2630 + conf->verbose_wget = 0;
2631 + conf->offline_root = NULL;
2632 + conf->offline_root_pre_script_cmd = NULL;
2633 + conf->offline_root_post_script_cmd = NULL;
2634 + conf->multiple_providers = 0;
2635 + conf->verbosity = 1;
2636 + conf->noaction = 0;
2638 + conf->http_proxy = NULL;
2639 + conf->ftp_proxy = NULL;
2640 + conf->no_proxy = NULL;
2641 + conf->proxy_user = NULL;
2642 + conf->proxy_passwd = NULL;
2644 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2646 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2647 + lists_dir=(char *)malloc(1);
2648 + lists_dir[0]='\0';
2649 + if (args->conf_file) {
2650 + struct stat stat_buf;
2651 + err = stat(args->conf_file, &stat_buf);
2653 + if (ipkg_conf_parse_file(conf, args->conf_file,
2654 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2655 + /* Memory leakage from ipkg_conf_parse-file */
2661 + /* if (!lists_dir ){*/
2662 + if (strlen(lists_dir)<=1 ){
2663 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2664 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2667 + if (args->offline_root) {
2668 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2669 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2674 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2675 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2677 + conf->lists_dir = strdup(lists_dir);
2678 + conf->pending_dir = strdup(pending_dir);
2680 + if (args->offline_root)
2681 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2682 + memset(&globbuf, 0, sizeof(globbuf));
2683 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2686 + for (i = 0; i < globbuf.gl_pathc; i++) {
2687 + if (globbuf.gl_pathv[i])
2688 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2689 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2690 + /* Memory leakage from ipkg_conf_parse-file */
2695 + globfree(&globbuf);
2697 + /* if no architectures were defined, then default all, noarch, and host architecture */
2698 + if (nv_pair_list_empty(&conf->arch_list)) {
2699 + nv_pair_list_append(&conf->arch_list, "all", "1");
2700 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2701 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2704 + /* Even if there is no conf file, we'll need at least one dest. */
2705 + if (tmp_dest_nv_pair_list.head == NULL) {
2706 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2707 + IPKG_CONF_DEFAULT_DEST_NAME,
2708 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2711 + /* After parsing the file, set options from command-line, (so that
2712 + command-line arguments take precedence) */
2713 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2714 + really needs to be cleaned up. There is so much duplication
2715 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2716 + a pointer to args_t (which could then not be freed), rather
2717 + than duplicating every field here? */
2718 + if (args->force_depends) {
2719 + conf->force_depends = 1;
2721 + if (args->force_defaults) {
2722 + conf->force_defaults = 1;
2724 + if (args->force_overwrite) {
2725 + conf->force_overwrite = 1;
2727 + if (args->force_downgrade) {
2728 + conf->force_downgrade = 1;
2730 + if (args->force_reinstall) {
2731 + conf->force_reinstall = 1;
2733 + if (args->force_removal_of_dependent_packages) {
2734 + conf->force_removal_of_dependent_packages = 1;
2736 + if (args->force_removal_of_essential_packages) {
2737 + conf->force_removal_of_essential_packages = 1;
2739 + if (args->nodeps) {
2742 + if (args->noaction) {
2743 + conf->noaction = 1;
2745 + if (args->query_all) {
2746 + conf->query_all = 1;
2748 + if (args->verbose_wget) {
2749 + conf->verbose_wget = 1;
2751 + if (args->multiple_providers) {
2752 + conf->multiple_providers = 1;
2754 + if (args->verbosity != conf->verbosity) {
2755 + conf->verbosity = args->verbosity;
2758 + ipkg_conf_override_string(&conf->offline_root,
2759 + args->offline_root);
2760 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2761 + args->offline_root_pre_script_cmd);
2762 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2763 + args->offline_root_post_script_cmd);
2765 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2766 + read anything from there.
2768 + if ( !(args->nocheckfordirorfile)){
2769 + /* need to run load the source list before dest list -Jamey */
2770 + if ( !(args->noreadfeedsfile))
2771 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2773 + /* Now that we have resolved conf->offline_root, we can commit to
2774 + the directory names for the dests and load in all the package
2776 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2779 + err = ipkg_conf_set_default_dest(conf, args->dest);
2785 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2787 + free(pending_dir);
2792 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2794 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2796 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2797 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2798 + __FUNCTION__, conf->tmp_dir);
2802 + err = rmdir(conf->tmp_dir);
2804 + if (errno == ENOTEMPTY) {
2806 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2807 + err = xsystem(cmd);
2811 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2813 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2815 + free(conf->tmp_dir); /*XXX*/
2817 + pkg_src_list_deinit(&conf->pkg_src_list);
2818 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2819 + nv_pair_list_deinit(&conf->arch_list);
2820 + if (&conf->pkg_hash)
2821 + pkg_hash_deinit(&conf->pkg_hash);
2822 + if (&conf->file_hash)
2823 + hash_table_deinit(&conf->file_hash);
2824 + if (&conf->obs_file_hash)
2825 + hash_table_deinit(&conf->obs_file_hash);
2827 + ipkg_conf_free_string(&conf->offline_root);
2828 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2829 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2831 + if (conf->verbosity > 1) {
2833 + hash_table_t *hashes[] = {
2836 + &conf->obs_file_hash };
2837 + for (i = 0; i < 3; i++) {
2838 + hash_table_t *hash = hashes[i];
2840 + int n_conflicts = 0;
2842 + for (j = 0; j < hash->n_entries; j++) {
2844 + hash_entry_t *e = &hash->entries[j];
2847 + while (e && e->key) {
2854 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2855 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2856 + hash_table_deinit(hash);
2861 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2862 + const char *default_dest_name)
2864 + pkg_dest_list_elt_t *iter;
2867 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2868 + dest = iter->data;
2869 + if (strcmp(dest->name, default_dest_name) == 0) {
2870 + conf->default_dest = dest;
2871 + conf->restrict_to_default_dest = 1;
2876 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2881 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2883 + pkg_src_list_elt_t *iter;
2887 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2889 + if (src == NULL) {
2893 + sprintf_alloc(&list_file, "%s/%s",
2894 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2897 + if (file_exists(list_file)) {
2898 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2906 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2908 + nv_pair_list_elt_t *iter;
2909 + nv_pair_t *nv_pair;
2913 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2914 + nv_pair = iter->data;
2916 + if (conf->offline_root) {
2917 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2919 + root_dir = strdup(nv_pair->value);
2921 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2923 + if (dest == NULL) {
2926 + if (conf->default_dest == NULL) {
2927 + conf->default_dest = dest;
2929 + if (file_exists(dest->status_file_name)) {
2930 + pkg_hash_add_from_file(conf, dest->status_file_name,
2938 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2939 + pkg_src_list_t *pkg_src_list,
2940 + nv_pair_list_t *tmp_dest_nv_pair_list,
2943 + ipkg_option_t * options;
2944 + FILE *file = fopen(filename, "r");
2945 + regex_t valid_line_re, comment_re;
2946 +#define regmatch_size 12
2947 + regmatch_t regmatch[regmatch_size];
2949 + if (ipkg_init_options_array(conf, &options)<0)
2952 + if (file == NULL) {
2953 + fprintf(stderr, "%s: failed to open %s: %s\n",
2954 + __FUNCTION__, filename, strerror(errno));
2958 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2960 + xregcomp(&comment_re,
2961 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2963 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2968 + char *type, *name, *value, *extra;
2970 + line = file_read_line_alloc(file);
2972 + if (line == NULL) {
2978 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2982 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2984 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2985 + filename, line_num, line);
2989 + /* This has to be so ugly to deal with optional quotation marks */
2990 + if (regmatch[2].rm_so > 0) {
2991 + type = strndup(line + regmatch[2].rm_so,
2992 + regmatch[2].rm_eo - regmatch[2].rm_so);
2994 + type = strndup(line + regmatch[3].rm_so,
2995 + regmatch[3].rm_eo - regmatch[3].rm_so);
2997 + if (regmatch[5].rm_so > 0) {
2998 + name = strndup(line + regmatch[5].rm_so,
2999 + regmatch[5].rm_eo - regmatch[5].rm_so);
3001 + name = strndup(line + regmatch[6].rm_so,
3002 + regmatch[6].rm_eo - regmatch[6].rm_so);
3004 + if (regmatch[8].rm_so > 0) {
3005 + value = strndup(line + regmatch[8].rm_so,
3006 + regmatch[8].rm_eo - regmatch[8].rm_so);
3008 + value = strndup(line + regmatch[9].rm_so,
3009 + regmatch[9].rm_eo - regmatch[9].rm_so);
3012 + if (regmatch[11].rm_so > 0) {
3013 + extra = strndup (line + regmatch[11].rm_so,
3014 + regmatch[11].rm_eo - regmatch[11].rm_so);
3017 + /* We use the tmp_dest_nv_pair_list below instead of
3018 + conf->pkg_dest_list because we might encounter an
3019 + offline_root option later and that would invalidate the
3020 + directories we would have computed in
3021 + pkg_dest_list_init. (We do a similar thing with
3022 + tmp_src_nv_pair_list for sake of symmetry.) */
3023 + if (strcmp(type, "option") == 0) {
3024 + ipkg_conf_set_option(options, name, value);
3025 + } else if (strcmp(type, "src") == 0) {
3026 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3027 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3029 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3032 + } else if (strcmp(type, "src/gz") == 0) {
3033 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3034 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3036 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3039 + } else if (strcmp(type, "dest") == 0) {
3040 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3041 + } else if (strcmp(type, "lists_dir") == 0) {
3042 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3043 + if (*lists_dir == NULL) {
3044 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3048 + sprintf (*lists_dir,"%s",value);
3049 + } else if (strcmp(type, "arch") == 0) {
3050 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3052 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3053 + value = strdup("10");
3055 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3057 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3058 + "parameter: %s %s %s\n", type, name, value);
3074 + regfree(&comment_re);
3075 + regfree(&valid_line_re);
3081 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3082 + const char *name, const char *value)
3085 + while (options[i].name) {
3086 + if (strcmp(options[i].name, name) == 0) {
3087 + switch (options[i].type) {
3088 + case IPKG_OPT_TYPE_BOOL:
3089 + *((int *)options[i].value) = 1;
3091 + case IPKG_OPT_TYPE_INT:
3093 + *((int *)options[i].value) = atoi(value);
3096 + printf("%s: Option %s need an argument\n",
3097 + __FUNCTION__, name);
3100 + case IPKG_OPT_TYPE_STRING:
3102 + *((char **)options[i].value) = strdup(value);
3105 + printf("%s: Option %s need an argument\n",
3106 + __FUNCTION__, name);
3114 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3115 + __FUNCTION__, name, value);
3119 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3121 + pkg_dest_list_elt_t *iter;
3128 + if (conf->noaction)
3130 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3131 + dest = iter->data;
3132 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3133 + if (dest->status_file == NULL) {
3134 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3135 + __FUNCTION__, dest->status_file_name, strerror(errno));
3139 + all = pkg_vec_alloc();
3140 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3142 + for(i = 0; i < all->len; i++) {
3143 + pkg = all->pkgs[i];
3144 + /* We don't need most uninstalled packages in the status file */
3145 + if (pkg->state_status == SS_NOT_INSTALLED
3146 + && (pkg->state_want == SW_UNKNOWN
3147 + || pkg->state_want == SW_DEINSTALL
3148 + || pkg->state_want == SW_PURGE)) {
3152 + fprintf(stderr, "Null package\n");
3154 + if (pkg->dest == NULL) {
3155 + fprintf(stderr, "%s: ERROR: Can't write status for "
3156 + "package %s since it has a NULL dest\n",
3157 + __FUNCTION__, pkg->name);
3160 + if (pkg->dest->status_file) {
3161 + pkg_print_status(pkg, pkg->dest->status_file);
3165 + pkg_vec_free(all);
3167 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3168 + dest = iter->data;
3169 + if (dest->status_file) {
3170 + err = ferror(dest->status_file);
3171 + fclose(dest->status_file);
3172 + dest->status_file = NULL;
3174 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3176 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3177 + "retaining old %s\n", __FUNCTION__,
3178 + dest->status_file_tmp_name, dest->status_file_name);
3187 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3189 + char *root_filename;
3190 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3191 + return root_filename;
3193 Index: busybox-1.8.1/archival/libipkg/ipkg_conf.h
3194 ===================================================================
3195 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3196 +++ busybox-1.8.1/archival/libipkg/ipkg_conf.h 2007-11-10 17:40:53.348763971 +0100
3198 +/* ipkg_conf.h - the itsy package management system
3202 + Copyright (C) 2001 University of Southern California
3204 + This program is free software; you can redistribute it and/or
3205 + modify it under the terms of the GNU General Public License as
3206 + published by the Free Software Foundation; either version 2, or (at
3207 + your option) any later version.
3209 + This program is distributed in the hope that it will be useful, but
3210 + WITHOUT ANY WARRANTY; without even the implied warranty of
3211 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3212 + General Public License for more details.
3215 +#ifndef IPKG_CONF_H
3216 +#define IPKG_CONF_H
3218 +typedef struct ipkg_conf ipkg_conf_t;
3220 +#include "hash_table.h"
3224 +#include "pkg_hash.h"
3225 +#include "pkg_src_list.h"
3226 +#include "pkg_dest_list.h"
3227 +#include "nv_pair_list.h"
3229 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3230 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3231 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3232 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3234 +/* In case the config file defines no dest */
3235 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3236 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3238 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3242 + pkg_src_list_t pkg_src_list;
3243 + pkg_dest_list_t pkg_dest_list;
3244 + nv_pair_list_t arch_list;
3246 + int restrict_to_default_dest;
3247 + pkg_dest_t *default_dest;
3250 + const char *lists_dir;
3251 + const char *pending_dir;
3254 + int force_depends;
3255 + int force_defaults;
3256 + int force_overwrite;
3257 + int force_downgrade;
3258 + int force_reinstall;
3260 + int force_removal_of_dependent_packages;
3261 + int force_removal_of_essential_packages;
3262 + int nodeps; /* do not follow dependences */
3264 + int multiple_providers;
3265 + char *offline_root;
3266 + char *offline_root_pre_script_cmd;
3267 + char *offline_root_post_script_cmd;
3272 + /* proxy options */
3277 + char *proxy_passwd;
3279 + hash_table_t pkg_hash;
3280 + hash_table_t file_hash;
3281 + hash_table_t obs_file_hash;
3284 +enum ipkg_option_type {
3285 + IPKG_OPT_TYPE_BOOL,
3286 + IPKG_OPT_TYPE_INT,
3287 + IPKG_OPT_TYPE_STRING
3289 +typedef enum ipkg_option_type ipkg_option_type_t;
3291 +typedef struct ipkg_option ipkg_option_t;
3292 +struct ipkg_option {
3294 + const ipkg_option_type_t type;
3295 + const void *value;
3298 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3299 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3301 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3302 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3305 Index: busybox-1.8.1/archival/libipkg/ipkg_configure.c
3306 ===================================================================
3307 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3308 +++ busybox-1.8.1/archival/libipkg/ipkg_configure.c 2007-11-10 17:40:53.348763971 +0100
3310 +/* ipkg_configure.c - the itsy package management system
3314 + Copyright (C) 2001 University of Southern California
3316 + This program is free software; you can redistribute it and/or
3317 + modify it under the terms of the GNU General Public License as
3318 + published by the Free Software Foundation; either version 2, or (at
3319 + your option) any later version.
3321 + This program is distributed in the hope that it will be useful, but
3322 + WITHOUT ANY WARRANTY; without even the implied warranty of
3323 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3324 + General Public License for more details.
3329 +#include "ipkg_configure.h"
3331 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3335 + /* DPKG_INCOMPATIBILITY:
3336 + dpkg actually does some conffile handling here, rather than at the
3337 + end of ipkg_install(). Do we care? */
3338 + /* DPKG_INCOMPATIBILITY:
3339 + dpkg actually includes a version number to this script call */
3340 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3342 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3346 + ipkg_state_changed++;
3350 Index: busybox-1.8.1/archival/libipkg/ipkg_configure.h
3351 ===================================================================
3352 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3353 +++ busybox-1.8.1/archival/libipkg/ipkg_configure.h 2007-11-10 17:40:53.348763971 +0100
3355 +/* ipkg_configure.h - the itsy package management system
3359 + Copyright (C) 2001 University of Southern California
3361 + This program is free software; you can redistribute it and/or
3362 + modify it under the terms of the GNU General Public License as
3363 + published by the Free Software Foundation; either version 2, or (at
3364 + your option) any later version.
3366 + This program is distributed in the hope that it will be useful, but
3367 + WITHOUT ANY WARRANTY; without even the implied warranty of
3368 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3369 + General Public License for more details.
3372 +#ifndef IPKG_CONFIGURE_H
3373 +#define IPKG_CONFIGURE_H
3375 +#include "ipkg_conf.h"
3377 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3380 Index: busybox-1.8.1/archival/libipkg/ipkg_download.c
3381 ===================================================================
3382 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3383 +++ busybox-1.8.1/archival/libipkg/ipkg_download.c 2007-11-10 17:40:53.352764197 +0100
3385 +/* ipkg_download.c - the itsy package management system
3389 + Copyright (C) 2001 University of Southern California
3391 + This program is free software; you can redistribute it and/or
3392 + modify it under the terms of the GNU General Public License as
3393 + published by the Free Software Foundation; either version 2, or (at
3394 + your option) any later version.
3396 + This program is distributed in the hope that it will be useful, but
3397 + WITHOUT ANY WARRANTY; without even the implied warranty of
3398 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3399 + General Public License for more details.
3403 +#include "ipkg_download.h"
3404 +#include "ipkg_message.h"
3406 +#include "sprintf_alloc.h"
3407 +#include "xsystem.h"
3408 +#include "file_util.h"
3409 +#include "str_util.h"
3411 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3415 + char *src_basec = strdup(src);
3416 + char *src_base = basename(src_basec);
3417 + char *tmp_file_location;
3420 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3424 + if (str_starts_with(src, "file:")) {
3426 + const char *file_src = src + 5;
3427 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3428 + ret = file_copy(src + 5, dest_file_name);
3429 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3433 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3434 + err = unlink(tmp_file_location);
3435 + if (err && errno != ENOENT) {
3436 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3437 + __FUNCTION__, tmp_file_location, strerror(errno));
3438 + free(tmp_file_location);
3442 + if (conf->http_proxy) {
3443 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3444 + setenv("http_proxy", conf->http_proxy, 1);
3446 + if (conf->ftp_proxy) {
3447 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3448 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3450 + if (conf->no_proxy) {
3451 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3452 + setenv("no_proxy", conf->no_proxy, 1);
3455 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3456 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3457 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3458 + conf->proxy_user ? "--proxy-user=" : "",
3459 + conf->proxy_user ? conf->proxy_user : "",
3460 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3461 + conf->proxy_passwd ? conf->proxy_passwd : "",
3462 + conf->verbose_wget ? "" : "-q",
3465 + err = xsystem(cmd);
3468 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3469 + __FUNCTION__, err, cmd);
3471 + unlink(tmp_file_location);
3472 + free(tmp_file_location);
3479 + err = file_move(tmp_file_location, dest_file_name);
3481 + free(tmp_file_location);
3491 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3496 + if (pkg->src == NULL) {
3497 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3498 + pkg->name, pkg->parent->name);
3502 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3504 + /* XXX: BUG: The pkg->filename might be something like
3505 + "../../foo.ipk". While this is correct, and exactly what we
3506 + want to use to construct url above, here we actually need to
3507 + use just the filename part, without any directory. */
3508 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3510 + err = ipkg_download(conf, url, pkg->local_filename);
3517 + * Downloads file from url, installs in package database, return package name.
3519 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3527 + if (str_starts_with(url, "http://")
3528 + || str_starts_with(url, "ftp://")) {
3530 + char *file_basec = strdup(url);
3531 + char *file_base = basename(file_basec);
3533 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3534 + err = ipkg_download(conf, url, tmp_file);
3538 + err = pkg_init_from_file(pkg, tmp_file);
3541 + pkg->local_filename = strdup(tmp_file);
3546 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3547 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3549 + err = pkg_init_from_file(pkg, url);
3552 + pkg->local_filename = strdup(url);
3553 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3554 + pkg->provided_by_hand = 1;
3562 + if (!pkg->architecture) {
3563 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3567 + pkg->dest = conf->default_dest;
3568 + pkg->state_want = SW_INSTALL;
3569 + pkg->state_flag |= SF_PREFER;
3570 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3571 + if ( pkg == NULL ){
3572 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3576 + *namep = strdup(pkg->name);
3580 Index: busybox-1.8.1/archival/libipkg/ipkg_download.h
3581 ===================================================================
3582 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3583 +++ busybox-1.8.1/archival/libipkg/ipkg_download.h 2007-11-10 17:40:53.352764197 +0100
3585 +/* ipkg_download.h - the itsy package management system
3589 + Copyright (C) 2001 University of Southern California
3591 + This program is free software; you can redistribute it and/or
3592 + modify it under the terms of the GNU General Public License as
3593 + published by the Free Software Foundation; either version 2, or (at
3594 + your option) any later version.
3596 + This program is distributed in the hope that it will be useful, but
3597 + WITHOUT ANY WARRANTY; without even the implied warranty of
3598 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3599 + General Public License for more details.
3602 +#ifndef IPKG_DOWNLOAD_H
3603 +#define IPKG_DOWNLOAD_H
3605 +#include "ipkg_conf.h"
3607 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3608 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3610 + * Downloads file from url, installs in package database, return package name.
3612 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3615 Index: busybox-1.8.1/archival/libipkg/ipkg.h
3616 ===================================================================
3617 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3618 +++ busybox-1.8.1/archival/libipkg/ipkg.h 2007-11-10 17:40:53.352764197 +0100
3620 +/* ipkg.h - the itsy package management system
3624 + Copyright (C) 2001 University of Southern California
3626 + This program is free software; you can redistribute it and/or
3627 + modify it under the terms of the GNU General Public License as
3628 + published by the Free Software Foundation; either version 2, or (at
3629 + your option) any later version.
3631 + This program is distributed in the hope that it will be useful, but
3632 + WITHOUT ANY WARRANTY; without even the implied warranty of
3633 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3634 + General Public License for more details.
3641 +#ifdef HAVE_CONFIG_H
3642 +#include "config.h"
3647 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3650 +#include "ipkg_includes.h"
3651 +#include "ipkg_conf.h"
3652 +#include "ipkg_message.h"
3654 +#define IPKG_PKG_EXTENSION ".ipk"
3655 +#define DPKG_PKG_EXTENSION ".deb"
3657 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3658 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3660 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3661 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3662 +#define IPKG_INFO_DIR_SUFFIX "info"
3663 +#define IPKG_STATUS_FILE_SUFFIX "status"
3665 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3667 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3669 +#define IPKG_VERSION "0.99.162"
3674 + IPKG_PKG_DEPS_UNSATISFIED,
3675 + IPKG_PKG_IS_ESSENTIAL,
3676 + IPKG_PKG_HAS_DEPENDENTS,
3677 + IPKG_PKG_HAS_NO_CANDIDATE
3679 +typedef enum ipkg_error ipkg_error_t;
3681 +extern int ipkg_state_changed;
3686 + struct errlist * next;
3689 +extern struct errlist* error_list;
3691 +extern ipkg_conf_t *global_conf;
3694 Index: busybox-1.8.1/archival/libipkg/ipkg_includes.h
3695 ===================================================================
3696 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3697 +++ busybox-1.8.1/archival/libipkg/ipkg_includes.h 2007-11-10 17:40:53.352764197 +0100
3699 +#ifndef IPKG_INCLUDES_H
3700 +#define IPKG_INCLUDES_H
3702 +/* Define to 1 if you have the <memory.h> header file. */
3703 +#define HAVE_MEMORY_H 1
3705 +/* Define to 1 if you have the <regex.h> header file. */
3706 +#define HAVE_REGEX_H 1
3708 +/* Define to 1 if you have the <stdlib.h> header file. */
3709 +#define HAVE_STDLIB_H 1
3711 +/* Define to 1 if you have the <strings.h> header file. */
3712 +#define HAVE_STRINGS_H 1
3714 +/* Define to 1 if you have the <string.h> header file. */
3715 +#define HAVE_STRING_H 1
3717 +/* Define to 1 if you have the <sys/stat.h> header file. */
3718 +#define HAVE_SYS_STAT_H 1
3720 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3721 +#define HAVE_SYS_WAIT_H 1
3723 +/* Define to 1 if you have the <unistd.h> header file. */
3724 +#define HAVE_UNISTD_H 1
3726 +/* Define to 1 if you have the ANSI C header files. */
3727 +#define STDC_HEADERS 1
3733 +# include <stdlib.h>
3734 +# include <stdarg.h>
3735 +# include <stddef.h>
3736 +# include <ctype.h>
3737 +# include <errno.h>
3740 +# include <stdlib.h>
3745 +# include <regex.h>
3749 +# if !STDC_HEADERS && HAVE_MEMORY_H
3750 +# include <memory.h>
3752 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3754 +# define __USE_GNU 1
3756 +# include <string.h>
3761 +# include <strings.h>
3764 +#if HAVE_SYS_STAT_H
3765 +# include <sys/stat.h>
3768 +#if HAVE_SYS_WAIT_H
3769 +# include <sys/wait.h>
3773 +# include <sys/types.h>
3774 +# include <unistd.h>
3777 +#endif /* IPKG_INCLUDES_H */
3778 Index: busybox-1.8.1/archival/libipkg/ipkg_install.c
3779 ===================================================================
3780 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3781 +++ busybox-1.8.1/archival/libipkg/ipkg_install.c 2007-11-10 17:40:53.356764426 +0100
3783 +/* ipkg_install.c - the itsy package management system
3787 + Copyright (C) 2001 University of Southern California
3789 + This program is free software; you can redistribute it and/or
3790 + modify it under the terms of the GNU General Public License as
3791 + published by the Free Software Foundation; either version 2, or (at
3792 + your option) any later version.
3794 + This program is distributed in the hope that it will be useful, but
3795 + WITHOUT ANY WARRANTY; without even the implied warranty of
3796 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3797 + General Public License for more details.
3802 +#include <dirent.h>
3805 +#include <signal.h>
3806 +typedef void (*sighandler_t)(int);
3809 +#include "pkg_hash.h"
3810 +#include "pkg_extract.h"
3812 +#include "ipkg_install.h"
3813 +#include "ipkg_configure.h"
3814 +#include "ipkg_download.h"
3815 +#include "ipkg_remove.h"
3817 +#include "ipkg_utils.h"
3818 +#include "ipkg_message.h"
3820 +#include "sprintf_alloc.h"
3821 +#include "file_util.h"
3822 +#include "str_util.h"
3823 +#include "xsystem.h"
3826 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3827 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3828 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3830 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3831 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3832 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3833 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3834 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3842 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3847 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3848 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3850 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3852 +static int user_prefers_old_conffile(const char *file, const char *backup);
3854 +static char *backup_filename_alloc(const char *file_name);
3855 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3856 +static int backup_exists_for(const char *file_name);
3857 +static int backup_remove(const char *file_name);
3860 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3864 + char *old_version, *new_version;
3867 + if (pkg == NULL) {
3871 + err = pkg_init_from_file(pkg, filename);
3876 + if (!pkg->architecture) {
3877 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3881 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3882 + freeing the pkg that we pass in. It might be nice to clean this up
3884 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3885 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3887 + pkg->local_filename = strdup(filename);
3890 + old_version = pkg_version_str_alloc(old);
3891 + new_version = pkg_version_str_alloc(pkg);
3893 + cmp = pkg_compare_versions(old, pkg);
3894 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3895 + cmp = -1 ; /* then we force ipkg to downgrade */
3896 + /* We need to use a value < 0 because in the 0 case we are asking to */
3897 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3900 + ipkg_message(conf, IPKG_NOTICE,
3901 + "Not downgrading package %s on %s from %s to %s.\n",
3902 + old->name, old->dest->name, old_version, new_version);
3903 + pkg->state_want = SW_DEINSTALL;
3904 + pkg->state_flag |= SF_OBSOLETE;
3905 + free(old_version);
3906 + free(new_version);
3909 + free(old_version);
3910 + free(new_version);
3914 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3915 + return ipkg_install_pkg(conf, pkg,0);
3918 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3922 + char *old_version, *new_version;
3924 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3925 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3927 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3929 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3930 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3932 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3934 +/* Pigi Basically here is broken the version stuff.
3935 + What's happening is that nothing provide the version to differents
3936 + functions, so the returned struct is always the latest.
3937 + That's why the install by name don't work.
3939 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3942 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3944 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3945 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3947 + if (new == NULL) {
3948 + return IPKG_PKG_HAS_NO_CANDIDATE;
3951 + new->state_flag |= SF_USER;
3953 + old_version = pkg_version_str_alloc(old);
3954 + new_version = pkg_version_str_alloc(new);
3956 + cmp = pkg_compare_versions(old, new);
3957 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3958 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3959 + cmp = -1 ; /* then we force ipkg to downgrade */
3960 + /* We need to use a value < 0 because in the 0 case we are asking to */
3961 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3963 + ipkg_message(conf, IPKG_DEBUG,
3964 + "Comparing visible versions of pkg %s:"
3965 + "\n\t%s is installed "
3966 + "\n\t%s is available "
3967 + "\n\t%d was comparison result\n",
3968 + pkg_name, old_version, new_version, cmp);
3969 + if (cmp == 0 && !conf->force_reinstall) {
3970 + ipkg_message(conf, IPKG_NOTICE,
3971 + "Package %s (%s) installed in %s is up to date.\n",
3972 + old->name, old_version, old->dest->name);
3973 + free(old_version);
3974 + free(new_version);
3976 + } else if (cmp > 0) {
3977 + ipkg_message(conf, IPKG_NOTICE,
3978 + "Not downgrading package %s on %s from %s to %s.\n",
3979 + old->name, old->dest->name, old_version, new_version);
3980 + free(old_version);
3981 + free(new_version);
3983 + } else if (cmp < 0) {
3984 + new->dest = old->dest;
3985 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3989 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3990 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3991 + return any kind of integer, (might be errno from a syscall,
3992 + etc.). This is a real mess and will need to be cleaned up if
3993 + anyone ever wants to make a nice libipkg. */
3995 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3996 + return ipkg_install_pkg(conf, new,0);
3999 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4001 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4004 + abstract_pkg_t *ppkg ;
4006 + if (providers == NULL)
4007 + return IPKG_PKG_HAS_NO_CANDIDATE;
4009 + for (i = 0; i < providers->len; i++) {
4010 + ppkg = abstract_pkg_vec_get(providers, i);
4011 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4012 + err = ipkg_install_by_name(conf, ppkg->name);
4015 +/* XXX Maybe ppkg should be freed ? */
4021 + * Walk dependence graph starting with pkg, collect packages to be
4022 + * installed into pkgs_needed, in dependence order.
4024 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4027 + pkg_vec_t *depends = pkg_vec_alloc();
4028 + char **unresolved = NULL;
4031 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4036 + ipkg_message(conf, IPKG_ERROR,
4037 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4038 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4039 + while (*unresolved) {
4040 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4043 + ipkg_message(conf, IPKG_ERROR, "\n");
4044 + if (! conf->force_depends) {
4045 + ipkg_message(conf, IPKG_INFO,
4046 + "This could mean that your package list is out of date or that the packages\n"
4047 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4048 + "of this problem try again with the '-force-depends' option.\n");
4049 + pkg_vec_free(depends);
4050 + return IPKG_PKG_DEPS_UNSATISFIED;
4054 + if (ndepends <= 0) {
4055 + pkg_vec_free(depends);
4059 + for (i = 0; i < depends->len; i++) {
4060 + pkg_t *dep = depends->pkgs[i];
4061 + /* The package was uninstalled when we started, but another
4062 + dep earlier in this loop may have depended on it and pulled
4063 + it in, so check first. */
4064 + if ((dep->state_status != SS_INSTALLED)
4065 + && (dep->state_status != SS_UNPACKED)
4066 + && (dep->state_want != SW_INSTALL)) {
4068 + /* Mark packages as to-be-installed */
4069 + dep->state_want = SW_INSTALL;
4071 + /* Dependencies should be installed the same place as pkg */
4072 + if (dep->dest == NULL) {
4073 + dep->dest = pkg->dest;
4076 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4078 + pkg_vec_free(depends);
4084 + pkg_vec_insert(pkgs_needed, pkg);
4086 + pkg_vec_free(depends);
4091 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4095 + char *old_version, *new_version;
4097 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4099 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4100 + if (new == NULL) {
4101 + return IPKG_PKG_HAS_NO_CANDIDATE;
4104 + old_version = pkg_version_str_alloc(old);
4105 + new_version = pkg_version_str_alloc(new);
4107 + cmp = pkg_compare_versions(old, new);
4108 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4109 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4110 + cmp = -1 ; /* then we force ipkg to downgrade */
4111 + /* We need to use a value < 0 because in the 0 case we are asking to */
4112 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4114 + ipkg_message(conf, IPKG_DEBUG,
4115 + "comparing visible versions of pkg %s:"
4116 + "\n\t%s is installed "
4117 + "\n\t%s is available "
4118 + "\n\t%d was comparison result\n",
4119 + pkg_name, old_version, new_version, cmp);
4120 + if (cmp == 0 && !conf->force_reinstall) {
4121 + ipkg_message(conf, IPKG_NOTICE,
4122 + "Package %s (%s) installed in %s is up to date.\n",
4123 + old->name, old_version, old->dest->name);
4124 + free(old_version);
4125 + free(new_version);
4127 + } else if (cmp > 0) {
4128 + ipkg_message(conf, IPKG_NOTICE,
4129 + "Not downgrading package %s on %s from %s to %s.\n",
4130 + old->name, old->dest->name, old_version, new_version);
4131 + free(old_version);
4132 + free(new_version);
4134 + } else if (cmp < 0) {
4135 + new->dest = old->dest;
4136 + old->state_want = SW_DEINSTALL;
4137 + old->state_flag |= SF_OBSOLETE;
4140 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4145 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4148 + pkg_vec_t *depends = pkg_vec_alloc();
4150 + char **unresolved = NULL;
4153 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4158 + ipkg_message(conf, IPKG_ERROR,
4159 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4160 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4161 + while (*unresolved) {
4162 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4165 + ipkg_message(conf, IPKG_ERROR, "\n");
4166 + if (! conf->force_depends) {
4167 + ipkg_message(conf, IPKG_INFO,
4168 + "This could mean that your package list is out of date or that the packages\n"
4169 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4170 + "of this problem try again with the '-force-depends' option.\n");
4171 + pkg_vec_free(depends);
4172 + return IPKG_PKG_DEPS_UNSATISFIED;
4176 + if (ndepends <= 0) {
4180 + /* Mark packages as to-be-installed */
4181 + for (i=0; i < depends->len; i++) {
4182 + /* Dependencies should be installed the same place as pkg */
4183 + if (depends->pkgs[i]->dest == NULL) {
4184 + depends->pkgs[i]->dest = pkg->dest;
4186 + depends->pkgs[i]->state_want = SW_INSTALL;
4189 + for (i = 0; i < depends->len; i++) {
4190 + dep = depends->pkgs[i];
4191 + /* The package was uninstalled when we started, but another
4192 + dep earlier in this loop may have depended on it and pulled
4193 + it in, so check first. */
4194 + if ((dep->state_status != SS_INSTALLED)
4195 + && (dep->state_status != SS_UNPACKED)) {
4196 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4197 + err = ipkg_install_pkg(conf, dep,0);
4199 + pkg_vec_free(depends);
4205 + pkg_vec_free(depends);
4211 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4212 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4214 + if (conf->nodeps == 0) {
4216 + pkg_vec_t *installed = pkg_vec_alloc();
4217 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4218 + for (i = 0; i < installed->len; i++) {
4219 + pkg_t *pkg = installed->pkgs[i];
4220 + satisfy_dependencies_for(conf, pkg);
4222 + pkg_vec_free(installed);
4229 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4232 + pkg_vec_t *conflicts = NULL;
4234 + const char *prefix;
4235 + if (conf->force_depends) {
4236 + level = IPKG_NOTICE;
4237 + prefix = "Warning";
4239 + level = IPKG_ERROR;
4243 + if (!conf->force_depends)
4244 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4247 + ipkg_message(conf, level,
4248 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4250 + while (i < conflicts->len)
4251 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4252 + ipkg_message(conf, level, "\n");
4253 + pkg_vec_free(conflicts);
4254 + return IPKG_PKG_DEPS_UNSATISFIED;
4259 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4261 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4262 + str_list_elt_t *iter;
4264 + for (iter = new_list->head; iter; iter = iter->next) {
4265 + char *new_file = iter->data;
4266 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4268 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4269 + if (!owner || (owner == old_pkg))
4270 + file_hash_set_file_owner(conf, new_file, new_pkg);
4273 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4274 + for (iter = old_list->head; iter; iter = iter->next) {
4275 + char *old_file = iter->data;
4276 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4277 + if (owner == old_pkg) {
4279 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4286 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4288 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4290 + /* sma 6.20.02: yup; here's the first bit */
4292 + * XXX: BUG easy for cworth
4293 + * 1) please point the call below to the correct current root destination
4294 + * 2) we need to resolve how to check the required space for a pending pkg,
4295 + * my diddling with the .ipk file size below isn't going to cut it.
4296 + * 3) return a proper error code instead of 1
4298 + int comp_size, blocks_available;
4300 + if (!conf->force_space && pkg->installed_size != NULL) {
4301 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4303 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4304 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4305 + comp_size = (int)((comp_size + 1023) / 1024);
4307 + if (comp_size >= blocks_available) {
4308 + ipkg_message(conf, IPKG_ERROR,
4309 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4310 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4317 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4320 + char *conffiles_file_name;
4322 + FILE *conffiles_file;
4324 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4326 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4327 + if (pkg->tmp_unpack_dir == NULL) {
4328 + ipkg_message(conf, IPKG_ERROR,
4329 + "%s: Failed to create temporary directory '%s': %s\n",
4330 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4334 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4339 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4340 + conffiles. Seems like I should be able to get everything to go
4341 + through pkg_init_from_file. If so, maybe it would make sense to
4342 + move all of unpack_pkg_control_files to that function. */
4344 + /* Don't need to re-read conffiles if we already have it */
4345 + if (pkg->conffiles.head) {
4349 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4350 + if (! file_exists(conffiles_file_name)) {
4351 + free(conffiles_file_name);
4355 + conffiles_file = fopen(conffiles_file_name, "r");
4356 + if (conffiles_file == NULL) {
4357 + fprintf(stderr, "%s: failed to open %s: %s\n",
4358 + __FUNCTION__, conffiles_file_name, strerror(errno));
4359 + free(conffiles_file_name);
4362 + free(conffiles_file_name);
4366 + char *cf_name_in_dest;
4368 + cf_name = file_read_line_alloc(conffiles_file);
4369 + if (cf_name == NULL) {
4372 + str_chomp(cf_name);
4373 + if (cf_name[0] == '\0') {
4377 + /* Prepend dest->root_dir to conffile name.
4378 + Take pains to avoid multiple slashes. */
4379 + root_dir = pkg->dest->root_dir;
4380 + if (conf->offline_root)
4381 + /* skip the offline_root prefix */
4382 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4383 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4384 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4386 + /* Can't get an md5sum now, (file isn't extracted yet).
4387 + We'll wait until resolve_conffiles */
4388 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4391 + free(cf_name_in_dest);
4394 + fclose(conffiles_file);
4399 +/* returns number of installed replacees */
4400 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4402 + abstract_pkg_t **replaces = pkg->replaces;
4403 + int replaces_count = pkg->replaces_count;
4405 + for (i = 0; i < replaces_count; i++) {
4406 + abstract_pkg_t *ab_pkg = replaces[i];
4407 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4409 + for (j = 0; j < pkg_vec->len; j++) {
4410 + pkg_t *replacee = pkg_vec->pkgs[j];
4411 + if (!pkg_conflicts(pkg, replacee))
4413 + if (replacee->state_status == SS_INSTALLED) {
4414 + pkg_vec_insert(installed_replacees, replacee);
4419 + return installed_replacees->len;
4422 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4425 + int replaces_count = replacees->len;
4426 + for (i = 0; i < replaces_count; i++) {
4427 + pkg_t *replacee = replacees->pkgs[i];
4429 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4430 + err = ipkg_remove_pkg(conf, replacee,0);
4437 +/* to unwind the removal: make sure they are installed */
4438 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4441 + int replaces_count = replacees->len;
4442 + for (i = 0; i < replaces_count; i++) {
4443 + pkg_t *replacee = replacees->pkgs[i];
4444 + if (replacee->state_status != SS_INSTALLED) {
4445 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4446 + err = ipkg_install_pkg(conf, replacee,0);
4454 +int caught_sigint = 0;
4455 +static void ipkg_install_pkg_sigint_handler(int sig)
4457 + caught_sigint = sig;
4460 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4461 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4464 + char message_out[15];
4465 + char *old_version = pkg_version_str_alloc(old_pkg);
4466 + char *new_version = pkg_version_str_alloc(pkg);
4467 + int cmp = pkg_compare_versions(old_pkg, pkg);
4470 + memset(message_out,'\x0',15);
4471 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4472 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4473 + cmp = -1 ; /* then we force ipkg to downgrade */
4474 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4475 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4479 + ipkg_message(conf, IPKG_NOTICE,
4480 + "Not downgrading package %s on %s from %s to %s.\n",
4481 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4483 + } else if (cmp < 0) {
4484 + ipkg_message(conf, IPKG_NOTICE,
4485 + "%s%s on %s from %s to %s...\n",
4486 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4487 + pkg->dest = old_pkg->dest;
4489 + } else /* cmp == 0 */ {
4490 + if (conf->force_reinstall) {
4491 + ipkg_message(conf, IPKG_NOTICE,
4492 + "Reinstalling %s (%s) on %s...\n",
4493 + pkg->name, new_version, old_pkg->dest->name);
4494 + pkg->dest = old_pkg->dest;
4497 + ipkg_message(conf, IPKG_NOTICE,
4498 + "Not installing %s (%s) on %s -- already installed.\n",
4499 + pkg->name, new_version, old_pkg->dest->name);
4503 + free(old_version);
4504 + free(new_version);
4507 + char message_out[15], *version ;
4508 + memset(message_out,'\x0',15);
4510 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4512 + strncpy( message_out,"Installing ",strlen("Installing ") );
4513 + version = pkg_version_str_alloc(pkg);
4515 + ipkg_message(conf, IPKG_NOTICE,
4516 + "%s%s (%s) to %s...\n", message_out,
4517 + pkg->name, version, pkg->dest->name);
4523 +/* and now the meat... */
4524 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4528 + pkg_t *old_pkg = NULL;
4529 + pkg_vec_t *replacees;
4530 + abstract_pkg_t *ab_pkg = NULL;
4531 + int old_state_flag;
4535 + if ( from_upgrade )
4536 + message = 1; /* Coming from an upgrade, and should change the output message */
4539 + ipkg_message(conf, IPKG_ERROR,
4540 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4544 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4546 + if (!pkg_arch_supported(conf, pkg)) {
4547 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4548 + pkg->architecture, pkg->name);
4551 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4552 + err = satisfy_dependencies_for(conf, pkg);
4553 + if (err) { return err; }
4555 + ipkg_message(conf, IPKG_NOTICE,
4556 + "Package %s is already installed in %s.\n",
4557 + pkg->name, pkg->dest->name);
4561 + if (pkg->dest == NULL) {
4562 + pkg->dest = conf->default_dest;
4565 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4567 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4568 + if (err) { return err; }
4570 + pkg->state_want = SW_INSTALL;
4572 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4576 + /* Abhaya: conflicts check */
4577 + err = check_conflicts_for(conf, pkg);
4578 + if (err) { return err; }
4580 + /* this setup is to remove the upgrade scenario in the end when
4581 + installing pkg A, A deps B & B deps on A. So both B and A are
4582 + installed. Then A's installation is started resulting in an
4583 + uncecessary upgrade */
4584 + if (pkg->state_status == SS_INSTALLED
4585 + && conf->force_reinstall == 0) return 0;
4587 + err = verify_pkg_installable(conf, pkg);
4588 + if (err) { return err; }
4590 + if (pkg->local_filename == NULL) {
4591 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4593 + ipkg_message(conf, IPKG_ERROR,
4594 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4600 +/* Check for md5 values */
4603 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4604 + if (strcmp(file_md5, pkg->md5sum))
4606 + ipkg_message(conf, IPKG_ERROR,
4607 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4615 + if (pkg->tmp_unpack_dir == NULL) {
4616 + unpack_pkg_control_files(conf, pkg);
4619 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4620 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4621 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4622 + err = update_file_ownership(conf, pkg, old_pkg);
4623 + if (err) { return err; }
4625 + if (conf->nodeps == 0) {
4626 + err = satisfy_dependencies_for(conf, pkg);
4627 + if (err) { return err; }
4630 + replacees = pkg_vec_alloc();
4631 + pkg_get_installed_replacees(conf, pkg, replacees);
4633 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4635 + sigset_t newset, oldset;
4636 + sighandler_t old_handler = NULL;
4637 + int use_signal = 0;
4638 + caught_sigint = 0;
4640 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4642 + sigemptyset(&newset);
4643 + sigaddset(&newset, SIGINT);
4644 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4647 + ipkg_state_changed++;
4648 + pkg->state_flag |= SF_FILELIST_CHANGED;
4650 + /* XXX: BUG: we really should treat replacement more like an upgrade
4651 + * Instead, we're going to remove the replacees
4653 + err = pkg_remove_installed_replacees(conf, replacees);
4654 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4656 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4657 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4659 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4660 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4662 + err = preinst_configure(conf, pkg, old_pkg);
4663 + if (err) goto UNWIND_PREINST_CONFIGURE;
4665 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4666 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4668 + err = check_data_file_clashes(conf, pkg, old_pkg);
4669 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4671 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4672 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4674 + if (conf->noaction) return 0;
4676 + /* point of no return: no unwinding after this */
4677 + if (old_pkg && !conf->force_reinstall) {
4678 + old_pkg->state_want = SW_DEINSTALL;
4680 + if (old_pkg->state_flag & SF_NOPRUNE) {
4681 + ipkg_message(conf, IPKG_INFO,
4682 + " not removing obsolesced files because package marked noprune\n");
4684 + ipkg_message(conf, IPKG_INFO,
4685 + " removing obsolesced files\n");
4686 + remove_obsolesced_files(conf, pkg, old_pkg);
4688 + /* removing files from old package, to avoid ghost files */
4689 + remove_data_files_and_list(conf, old_pkg);
4690 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4691 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4692 + remove_postrm(conf, old_pkg);
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " installing maintainer scripts\n");
4700 + install_maintainer_scripts(conf, pkg, old_pkg);
4702 + /* the following just returns 0 */
4703 + remove_disappeared(conf, pkg);
4705 + ipkg_message(conf, IPKG_INFO,
4706 + " installing data files\n");
4707 + install_data_files(conf, pkg);
4709 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4710 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4712 + ipkg_message(conf, IPKG_INFO,
4713 + " resolving conf files\n");
4714 + resolve_conffiles(conf, pkg);
4716 + pkg->state_status = SS_UNPACKED;
4717 + old_state_flag = pkg->state_flag;
4718 + pkg->state_flag &= ~SF_PREFER;
4719 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4721 + if (old_pkg && !conf->force_reinstall) {
4722 + old_pkg->state_status = SS_NOT_INSTALLED;
4725 + time(&pkg->installed_time);
4727 + ipkg_message(conf, IPKG_INFO,
4728 + " cleanup temp files\n");
4729 + cleanup_temporary_files(conf, pkg);
4731 + ab_pkg = pkg->parent;
4733 + ab_pkg->state_status = pkg->state_status;
4735 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4738 + signal(SIGINT, old_handler);
4740 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4745 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4746 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4747 + UNWIND_CHECK_DATA_FILE_CLASHES:
4748 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4749 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4750 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4751 + UNWIND_PREINST_CONFIGURE:
4752 + preinst_configure_unwind(conf, pkg, old_pkg);
4753 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4754 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4755 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4756 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4757 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4758 + pkg_remove_installed_replacees_unwind(conf, replacees);
4760 + ipkg_message(conf, IPKG_INFO,
4761 + " cleanup temp files\n");
4762 + cleanup_temporary_files(conf, pkg);
4764 + ipkg_message(conf, IPKG_INFO,
4767 + signal(SIGINT, old_handler);
4769 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4775 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4777 + /* DPKG_INCOMPATIBILITY:
4778 + dpkg does some things here that we don't do yet. Do we care?
4780 + 1. If a version of the package is already installed, call
4781 + old-prerm upgrade new-version
4782 + 2. If the script runs but exits with a non-zero exit status
4783 + new-prerm failed-upgrade old-version
4784 + Error unwind, for both the above cases:
4785 + old-postinst abort-upgrade new-version
4790 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4792 + /* DPKG_INCOMPATIBILITY:
4793 + dpkg does some things here that we don't do yet. Do we care?
4794 + (See prerm_upgrade_old_package for details)
4799 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4801 + /* DPKG_INCOMPATIBILITY:
4802 + dpkg does some things here that we don't do yet. Do we care?
4803 + 2. If a 'conflicting' package is being removed at the same time:
4804 + 1. If any packages depended on that conflicting package and
4805 + --auto-deconfigure is specified, call, for each such package:
4806 + deconfigured's-prerm deconfigure \
4807 + in-favour package-being-installed version \
4808 + removing conflicting-package version
4810 + deconfigured's-postinst abort-deconfigure \
4811 + in-favour package-being-installed-but-failed version \
4812 + removing conflicting-package version
4814 + The deconfigured packages are marked as requiring
4815 + configuration, so that if --install is used they will be
4816 + configured again if possible.
4817 + 2. To prepare for removal of the conflicting package, call:
4818 + conflictor's-prerm remove in-favour package new-version
4820 + conflictor's-postinst abort-remove in-favour package new-version
4825 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4827 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4828 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4833 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4836 + char *preinst_args;
4839 + char *old_version = pkg_version_str_alloc(old_pkg);
4840 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4841 + free(old_version);
4842 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4843 + char *pkg_version = pkg_version_str_alloc(pkg);
4844 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4845 + free(pkg_version);
4847 + preinst_args = strdup("install");
4850 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4852 + ipkg_message(conf, IPKG_ERROR,
4853 + "Aborting installation of %s\n", pkg->name);
4857 + free(preinst_args);
4862 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4864 + /* DPKG_INCOMPATIBILITY:
4865 + dpkg does the following error unwind, should we?
4866 + pkg->postrm abort-upgrade old-version
4867 + OR pkg->postrm abort-install old-version
4868 + OR pkg->postrm abort-install
4873 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4876 + conffile_list_elt_t *iter;
4879 + if (conf->noaction) return 0;
4881 + /* Backup all modified conffiles */
4883 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4887 + cf_name = root_filename_alloc(conf, cf->name);
4889 + /* Don't worry if the conffile is just plain gone */
4890 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4891 + err = backup_make_backup(conf, cf_name);
4900 + /* Backup all conffiles that were not conffiles in old_pkg */
4901 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4904 + cf_name = root_filename_alloc(conf, cf->name);
4905 + /* Ignore if this was a conffile in old_pkg as well */
4906 + if (pkg_get_conffile(old_pkg, cf->name)) {
4910 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4911 + err = backup_make_backup(conf, cf_name);
4922 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4924 + conffile_list_elt_t *iter;
4927 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4928 + backup_remove(iter->data->name);
4932 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4933 + backup_remove(iter->data->name);
4940 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4942 + /* DPKG_INCOMPATIBILITY:
4943 + ipkg takes a slightly different approach than dpkg at this
4944 + point. dpkg installs each file in the new package while
4945 + creating a backup for any file that is replaced, (so that it
4946 + can unwind if necessary). To avoid complexity and redundant
4947 + storage, ipkg doesn't do any installation until later, (at the
4948 + point at which dpkg removes the backups.
4950 + But, we do have to check for data file clashes, since after
4951 + installing a package with a file clash, removing either of the
4952 + packages involved in the clash has the potential to break the
4955 + str_list_t *files_list;
4956 + str_list_elt_t *iter;
4960 + files_list = pkg_get_installed_files(pkg);
4961 + for (iter = files_list->head; iter; iter = iter->next) {
4962 + char *root_filename;
4963 + char *filename = iter->data;
4964 + root_filename = root_filename_alloc(conf, filename);
4965 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4968 + /* Pre-existing conffiles are OK */
4969 + /* @@@@ should have way to check that it is a conffile -Jamey */
4970 + if (backup_exists_for(root_filename)) {
4974 + /* Pre-existing files are OK if force-overwrite was asserted. */
4975 + if (conf->force_overwrite) {
4976 + /* but we need to change who owns this file */
4977 + file_hash_set_file_owner(conf, filename, pkg);
4981 + owner = file_hash_get_file_owner(conf, filename);
4983 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4984 + if (owner && old_pkg) {
4985 + if (strcmp(owner->name, old_pkg->name) == 0) {
4990 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4992 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4993 + if (pkg_replaces(pkg, owner)) {
4996 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4997 + then it's ok to overwrite. */
4998 + if (strcmp(owner->name,pkg->name)==0){
4999 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5004 + /* Pre-existing files are OK if they are obsolete */
5005 + obs = hash_table_get(&conf->obs_file_hash, filename);
5007 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5011 + /* We have found a clash. */
5012 + ipkg_message(conf, IPKG_ERROR,
5013 + "Package %s wants to install file %s\n"
5014 + "\tBut that file is already provided by package ",
5015 + pkg->name, filename);
5017 + ipkg_message(conf, IPKG_ERROR,
5018 + "%s\n", owner->name);
5020 + ipkg_message(conf, IPKG_ERROR,
5021 + "<no package>\nPlease move this file out of the way and try again.\n");
5025 + free(root_filename);
5027 + pkg_free_installed_files(pkg);
5032 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5034 + /* Basically that's the worst hack I could do to be able to change ownership of
5035 + file list, but, being that we have no way to unwind the mods, due to structure
5036 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5037 + What we do here is change the ownership of file in hash if a replace ( or similar events
5039 + Only the action that are needed to change name should be considered.
5040 + @@@ To change after 1.0 release.
5042 + str_list_t *files_list;
5043 + str_list_elt_t *iter;
5047 + files_list = pkg_get_installed_files(pkg);
5048 + for (iter = files_list->head; iter; iter = iter->next) {
5049 + char *root_filename;
5050 + char *filename = iter->data;
5051 + root_filename = root_filename_alloc(conf, filename);
5052 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5055 + if (conf->force_overwrite) {
5056 + /* but we need to change who owns this file */
5057 + file_hash_set_file_owner(conf, filename, pkg);
5061 + owner = file_hash_get_file_owner(conf, filename);
5063 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5065 + if (pkg_replaces(pkg, owner)) {
5066 +/* It's now time to change the owner of that file.
5067 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5068 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5069 + file_hash_set_file_owner(conf, filename, pkg);
5075 + free(root_filename);
5077 + pkg_free_installed_files(pkg);
5082 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5084 + /* Nothing to do since check_data_file_clashes doesn't change state */
5088 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5090 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5091 + 1. If the package is being upgraded, call
5092 + old-postrm upgrade new-version
5093 + 2. If this fails, attempt:
5094 + new-postrm failed-upgrade old-version
5095 + Error unwind, for both cases:
5096 + old-preinst abort-upgrade new-version */
5100 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5102 + /* DPKG_INCOMPATIBILITY:
5103 + dpkg does some things here that we don't do yet. Do we care?
5104 + (See postrm_upgrade_old_pkg for details)
5109 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5112 + str_list_t *old_files;
5113 + str_list_elt_t *of;
5114 + str_list_t *new_files;
5115 + str_list_elt_t *nf;
5117 + if (old_pkg == NULL) {
5121 + old_files = pkg_get_installed_files(old_pkg);
5122 + new_files = pkg_get_installed_files(pkg);
5124 + for (of = old_files->head; of; of = of->next) {
5128 + for (nf = new_files->head; nf; nf = nf->next) {
5130 + if (strcmp(old, new) == 0) {
5131 + goto NOT_OBSOLETE;
5134 + if (file_is_dir(old)) {
5137 + owner = file_hash_get_file_owner(conf, old);
5138 + if (owner != old_pkg) {
5139 + /* in case obsolete file no longer belongs to old_pkg */
5143 + /* old file is obsolete */
5144 + ipkg_message(conf, IPKG_INFO,
5145 + " removing obsolete file %s\n", old);
5146 + if (!conf->noaction) {
5147 + err = unlink(old);
5149 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5158 + pkg_free_installed_files(old_pkg);
5159 + pkg_free_installed_files(pkg);
5164 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5168 + char *globpattern;
5172 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5175 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5176 + err = glob(globpattern, 0, NULL, &globbuf);
5177 + free(globpattern);
5181 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5182 + for (i = 0; i < globbuf.gl_pathc; i++) {
5183 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5184 + globbuf.gl_pathv[i], old_pkg->name);
5185 + if (!conf->noaction)
5186 + unlink(globbuf.gl_pathv[i]);
5188 + globfree(&globbuf);
5193 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5199 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5200 + sprintf_alloc(&prefix, "%s.", pkg->name);
5201 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5202 + pkg->dest->info_dir,
5208 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5210 + /* DPKG_INCOMPATIBILITY:
5211 + This is a fairly sophisticated dpkg operation. Shall we
5214 + /* Any packages all of whose files have been overwritten during the
5215 + installation, and which aren't required for dependencies, are
5216 + considered to have been removed. For each such package
5217 + 1. disappearer's-postrm disappear overwriter overwriter-version
5218 + 2. The package's maintainer scripts are removed
5219 + 3. It is noted in the status database as being in a sane state,
5220 + namely not installed (any conffiles it may have are ignored,
5221 + rather than being removed by dpkg). Note that disappearing
5222 + packages do not have their prerm called, because dpkg doesn't
5223 + know in advance that the package is going to vanish.
5228 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5232 + /* ipkg takes a slightly different approach to data file backups
5233 + than dpkg. Rather than removing backups at this point, we
5234 + actually do the data file installation now. See comments in
5235 + check_data_file_clashes() for more details. */
5237 + ipkg_message(conf, IPKG_INFO,
5238 + " extracting data files to %s\n", pkg->dest->root_dir);
5239 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5244 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5245 + so we can't save ourself from removing important packages
5246 + At this point we (should) have extracted the .control file, so it
5247 + would be a good idea to reload the data in it, and set the Essential
5248 + state in *pkg. From now on the Essential is back in status file and
5249 + we can protect again.
5250 + We should operate this way:
5251 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5252 + check for "Essential" in it
5253 + set the value in pkg->essential.
5254 + This new routine could be useful also for every other flag
5255 + Pigi: 16/03/2004 */
5256 + set_flags_from_control(conf, pkg) ;
5258 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5259 + err = pkg_write_filelist(conf, pkg);
5263 + /* XXX: FEATURE: ipkg should identify any files which existed
5264 + before installation and which were overwritten, (see
5265 + check_data_file_clashes()). What it must do is remove any such
5266 + files from the filelist of the old package which provided the
5267 + file. Otherwise, if the old package were removed at some point
5268 + it would break the new package. Removing the new package will
5269 + also break the old one, but this cannot be helped since the old
5270 + package's file has already been deleted. This is the importance
5271 + of check_data_file_clashes(), and only allowing ipkg to install
5272 + a clashing package with a user force. */
5277 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5279 + conffile_list_elt_t *iter;
5286 + if (conf->noaction) return 0;
5288 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5289 + char *root_filename;
5291 + root_filename = root_filename_alloc(conf, cf->name);
5293 + /* Might need to initialize the md5sum for each conffile */
5294 + if (cf->value == NULL) {
5295 + cf->value = file_md5sum_alloc(root_filename);
5298 + if (!file_exists(root_filename)) {
5299 + free(root_filename);
5303 + cf_backup = backup_filename_alloc(root_filename);
5306 + if (file_exists(cf_backup)) {
5307 + /* Let's compute md5 to test if files are changed */
5308 + md5sum = file_md5sum_alloc(cf_backup);
5309 + if (strcmp( cf->value,md5sum) != 0 ) {
5310 + if (conf->force_defaults
5311 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5312 + rename(cf_backup, root_filename);
5315 + unlink(cf_backup);
5320 + free(root_filename);
5326 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5329 + const char *short_file_name;
5331 + short_file_name = strrchr(file_name, '/');
5332 + if (short_file_name) {
5333 + short_file_name++;
5335 + short_file_name = file_name;
5339 + response = get_user_response(" Configuration file '%s'\n"
5340 + " ==> File on system created by you or by a script.\n"
5341 + " ==> File also in package provided by package maintainer.\n"
5342 + " What would you like to do about it ? Your options are:\n"
5343 + " Y or I : install the package maintainer's version\n"
5344 + " N or O : keep your currently-installed version\n"
5345 + " D : show the differences between the versions (if diff is installed)\n"
5346 + " The default action is to keep your current version.\n"
5347 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5348 + if (strcmp(response, "y") == 0
5349 + || strcmp(response, "i") == 0
5350 + || strcmp(response, "yes") == 0) {
5355 + if (strcmp(response, "d") == 0) {
5359 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5360 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5363 + printf(" [Press ENTER to continue]\n");
5364 + response = file_read_line_alloc(stdin);
5374 +/* XXX: CLEANUP: I'd like to move all of the code for
5375 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5376 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5377 + pkg_deinit for example). */
5378 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5381 + struct dirent *dirent;
5384 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5386 + ipkg_message(conf, IPKG_DEBUG,
5387 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5388 + __FUNCTION__, pkg->tmp_unpack_dir);
5392 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5393 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5396 + dirent = readdir(tmp_dir);
5397 + if (dirent == NULL) {
5400 + sprintf_alloc(&tmp_file, "%s/%s",
5401 + pkg->tmp_unpack_dir, dirent->d_name);
5402 + if (! file_is_dir(tmp_file)) {
5407 + closedir(tmp_dir);
5408 + rmdir(pkg->tmp_unpack_dir);
5409 + free(pkg->tmp_unpack_dir);
5410 + pkg->tmp_unpack_dir = NULL;
5414 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5415 + pkg->name, pkg->local_filename, conf->tmp_dir);
5416 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5417 + unlink(pkg->local_filename);
5418 + free(pkg->local_filename);
5419 + pkg->local_filename = NULL;
5425 +static char *backup_filename_alloc(const char *file_name)
5429 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5434 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5439 + backup = backup_filename_alloc(file_name);
5440 + err = file_copy(file_name, backup);
5442 + ipkg_message(conf, IPKG_ERROR,
5443 + "%s: Failed to copy %s to %s\n",
5444 + __FUNCTION__, file_name, backup);
5452 +static int backup_exists_for(const char *file_name)
5457 + backup = backup_filename_alloc(file_name);
5459 + ret = file_exists(backup);
5466 +static int backup_remove(const char *file_name)
5470 + backup = backup_filename_alloc(file_name);
5479 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5481 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5483 + /* first, remove the packages that need removing */
5484 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5485 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5486 + err = ipkg_remove_pkg(conf, pkg,0);
5487 + if (err) return err;
5492 +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)
5495 + /* now one more pass checking on the ones that need to be installed */
5496 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5497 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5498 + if (pkg->dest == NULL)
5499 + pkg->dest = conf->default_dest;
5501 + pkg->state_want = SW_INSTALL;
5503 + /* Abhaya: conflicts check */
5504 + err = check_conflicts_for(conf, pkg);
5505 + if (err) { return err; }
5510 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5513 + /* now one more pass checking on the ones that need to be installed */
5514 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5515 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5517 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5518 + pkg_vec_t *replacees = pkg_vec_alloc();
5519 + pkg_get_installed_replacees(conf, pkg, replacees);
5521 + /* XXX: BUG: we really should treat replacement more like an upgrade
5522 + * Instead, we're going to remove the replacees
5524 + err = pkg_remove_installed_replacees(conf, replacees);
5525 + if (err) return err;
5526 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5531 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5534 + /* now one more pass checking on the ones that need to be installed */
5535 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5536 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5537 + if (pkg->local_filename == NULL) {
5538 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5540 + ipkg_message(conf, IPKG_ERROR,
5541 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5546 + if (pkg->tmp_unpack_dir == NULL) {
5547 + err = unpack_pkg_control_files(conf, pkg);
5548 + if (err) return err;
5554 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5557 + /* now one more pass checking on the ones that need to be installed */
5558 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5559 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5560 + pkg_t *old_pkg = pkg->old_pkg;
5562 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5563 + if (err) return err;
5565 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5566 + if (err) return err;
5568 + err = preinst_configure(conf, pkg, old_pkg);
5569 + if (err) return err;
5571 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5572 + if (err) return err;
5574 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5575 + if (err) return err;
5580 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5583 + /* now one more pass checking on the ones that need to be installed */
5584 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5585 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5586 + pkg_t *old_pkg = pkg->old_pkg;
5589 + old_pkg->state_want = SW_DEINSTALL;
5591 + if (old_pkg->state_flag & SF_NOPRUNE) {
5592 + ipkg_message(conf, IPKG_INFO,
5593 + " not removing obsolesced files because package marked noprune\n");
5595 + ipkg_message(conf, IPKG_INFO,
5596 + " removing obsolesced files\n");
5597 + remove_obsolesced_files(conf, pkg, old_pkg);
5601 + ipkg_message(conf, IPKG_INFO,
5602 + " installing maintainer scripts\n");
5603 + install_maintainer_scripts(conf, pkg, old_pkg);
5605 + /* the following just returns 0 */
5606 + remove_disappeared(conf, pkg);
5608 + ipkg_message(conf, IPKG_INFO,
5609 + " installing data files\n");
5610 + install_data_files(conf, pkg);
5612 + ipkg_message(conf, IPKG_INFO,
5613 + " resolving conf files\n");
5614 + resolve_conffiles(conf, pkg);
5616 + pkg->state_status = SS_UNPACKED;
5619 + old_pkg->state_status = SS_NOT_INSTALLED;
5622 + time(&pkg->installed_time);
5624 + ipkg_message(conf, IPKG_INFO,
5625 + " cleanup temp files\n");
5626 + cleanup_temporary_files(conf, pkg);
5629 + pkg->parent->state_status = pkg->state_status;
5634 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5637 + /* now one more pass checking on the ones that need to be installed */
5638 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5639 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5640 + pkg_t *old_pkg = pkg->old_pkg;
5643 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5644 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5645 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5646 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5647 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5648 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5649 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5650 + preinst_configure_unwind(conf, pkg, old_pkg);
5651 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5652 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5653 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5654 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5656 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5657 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5665 + * Perform all the actions.
5667 + * pkgs_to_remove are packages marked for removal.
5668 + * pkgs_superseded are the old packages being replaced by upgrades.
5670 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5672 +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)
5677 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5678 + if (err) return err;
5680 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5681 + if (err) return err;
5683 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5684 + if (err) goto UNWIND;
5686 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5687 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5688 + if (err) goto UNWIND;
5691 + * Now that we have the packages unpacked, we can look for data
5692 + * file clashes. First, we mark the files from the superseded
5693 + * packages as obsolete. Then we scan the files in
5694 + * pkgs_to_install, and only complain about clashes with
5695 + * non-obsolete files.
5698 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5699 + if (err) goto UNWIND;
5701 + /* this was before checking data file clashes */
5702 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5703 + if (err) goto UNWIND;
5705 + /* point of no return: no unwinding after this */
5706 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5707 + if (err) return err;
5709 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5713 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5715 + ipkg_message(conf, IPKG_INFO,
5716 + " cleanup temp files\n");
5717 + cleanup_temporary_files(conf, pkg);
5719 + ipkg_message(conf, IPKG_INFO,
5725 Index: busybox-1.8.1/archival/libipkg/ipkg_install.h
5726 ===================================================================
5727 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5728 +++ busybox-1.8.1/archival/libipkg/ipkg_install.h 2007-11-10 17:40:53.356764426 +0100
5730 +/* ipkg_install.h - the itsy package management system
5734 + Copyright (C) 2001 University of Southern California
5736 + This program is free software; you can redistribute it and/or
5737 + modify it under the terms of the GNU General Public License as
5738 + published by the Free Software Foundation; either version 2, or (at
5739 + your option) any later version.
5741 + This program is distributed in the hope that it will be useful, but
5742 + WITHOUT ANY WARRANTY; without even the implied warranty of
5743 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5744 + General Public License for more details.
5747 +#ifndef IPKG_INSTALL_H
5748 +#define IPKG_INSTALL_H
5751 +#include "ipkg_conf.h"
5753 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5754 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5755 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5756 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5757 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5759 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5761 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5762 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5765 Index: busybox-1.8.1/archival/libipkg/ipkg_message.c
5766 ===================================================================
5767 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5768 +++ busybox-1.8.1/archival/libipkg/ipkg_message.c 2007-11-10 17:40:53.356764426 +0100
5770 +/* ipkg_message.c - the itsy package management system
5772 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5774 + This program is free software; you can redistribute it and/or
5775 + modify it under the terms of the GNU General Public License as
5776 + published by the Free Software Foundation; either version 2, or (at
5777 + your option) any later version.
5779 + This program is distributed in the hope that it will be useful, but
5780 + WITHOUT ANY WARRANTY; without even the implied warranty of
5781 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5782 + General Public License for more details.
5787 +#include "ipkg_conf.h"
5788 +#include "ipkg_message.h"
5793 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5797 + if (conf && (conf->verbosity < level))
5804 + va_start (ap, fmt);
5805 + vprintf (fmt, ap);
5812 +#include "libipkg.h"
5814 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5817 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5822 + if (ipkg_cb_message)
5824 + va_start (ap, fmt);
5825 + vsnprintf (ts,256,fmt, ap);
5827 + ipkg_cb_message(conf,level,ts);
5831 Index: busybox-1.8.1/archival/libipkg/ipkg_message.h
5832 ===================================================================
5833 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5834 +++ busybox-1.8.1/archival/libipkg/ipkg_message.h 2007-11-10 17:40:53.356764426 +0100
5836 +/* ipkg_message.h - the itsy package management system
5838 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5840 + This program is free software; you can redistribute it and/or
5841 + modify it under the terms of the GNU General Public License as
5842 + published by the Free Software Foundation; either version 2, or (at
5843 + your option) any later version.
5845 + This program is distributed in the hope that it will be useful, but
5846 + WITHOUT ANY WARRANTY; without even the implied warranty of
5847 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5848 + General Public License for more details.
5851 +#ifndef _IPKG_MESSAGE_H_
5852 +#define _IPKG_MESSAGE_H_
5855 +#include "ipkg_conf.h"
5858 + IPKG_ERROR, /* error conditions */
5859 + IPKG_NOTICE, /* normal but significant condition */
5860 + IPKG_INFO, /* informational message */
5861 + IPKG_DEBUG, /* debug level message */
5862 + IPKG_DEBUG2, /* more debug level message */
5865 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
5867 +#endif /* _IPKG_MESSAGE_H_ */
5868 Index: busybox-1.8.1/archival/libipkg/ipkg_remove.c
5869 ===================================================================
5870 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5871 +++ busybox-1.8.1/archival/libipkg/ipkg_remove.c 2007-11-10 17:40:53.360764656 +0100
5873 +/* ipkg_remove.c - the itsy package management system
5877 + Copyright (C) 2001 University of Southern California
5879 + This program is free software; you can redistribute it and/or
5880 + modify it under the terms of the GNU General Public License as
5881 + published by the Free Software Foundation; either version 2, or (at
5882 + your option) any later version.
5884 + This program is distributed in the hope that it will be useful, but
5885 + WITHOUT ANY WARRANTY; without even the implied warranty of
5886 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5887 + General Public License for more details.
5891 +#include "ipkg_message.h"
5895 +#include "ipkg_remove.h"
5897 +#include "file_util.h"
5898 +#include "sprintf_alloc.h"
5899 +#include "str_util.h"
5901 +#include "ipkg_cmd.h"
5904 + * Returns number of the number of packages depending on the packages provided by this package.
5905 + * Every package implicitly provides itself.
5907 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5909 + int nprovides = pkg->provides_count;
5910 + abstract_pkg_t **provides = pkg->provides;
5911 + int n_installed_dependents = 0;
5913 + for (i = 0; i <= nprovides; i++) {
5914 + abstract_pkg_t *providee = provides[i];
5915 + abstract_pkg_t **dependers = providee->depended_upon_by;
5916 + abstract_pkg_t *dep_ab_pkg;
5917 + if (dependers == NULL)
5919 + while ((dep_ab_pkg = *dependers++) != NULL) {
5920 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5921 + n_installed_dependents++;
5926 + /* if caller requested the set of installed dependents */
5927 + if (pdependents) {
5929 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5931 + if ( dependents == NULL ){
5932 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5936 + *pdependents = dependents;
5937 + for (i = 0; i <= nprovides; i++) {
5938 + abstract_pkg_t *providee = provides[i];
5939 + abstract_pkg_t **dependers = providee->depended_upon_by;
5940 + abstract_pkg_t *dep_ab_pkg;
5941 + if (dependers == NULL)
5943 + while ((dep_ab_pkg = *dependers++) != NULL) {
5944 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5945 + dependents[p++] = dep_ab_pkg;
5946 + dep_ab_pkg->state_flag |= SF_MARKED;
5950 + dependents[p] = NULL;
5951 + /* now clear the marks */
5952 + for (i = 0; i < p; i++) {
5953 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5954 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5957 + return n_installed_dependents;
5960 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5965 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5966 + abstract_pkg_t * ab_pkg;
5968 + if((ab_pkg = pkg->parent) == NULL){
5969 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5970 + __FUNCTION__, pkg->name);
5974 + if (dependents == NULL)
5977 + // here i am using the dependencies_checked
5978 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5979 + return 0; // has already been encountered in the process
5980 + // of marking packages for removal - Karthik
5981 + ab_pkg->dependencies_checked = 2;
5985 + while (dependents [i] != NULL) {
5986 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5988 + if (dep_ab_pkg->dependencies_checked == 2){
5992 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5993 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5994 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5995 + if (dep_pkg->state_status == SS_INSTALLED) {
5996 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6002 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6003 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6010 + for (i = 0; i < dependent_pkgs->len; i++) {
6011 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6018 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6020 + abstract_pkg_t *dep_ab_pkg;
6021 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6022 + while ((dep_ab_pkg = *dependents++) != NULL) {
6023 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6024 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6026 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6027 + ipkg_message(conf, IPKG_ERROR, "");
6028 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6029 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6030 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6031 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6032 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6036 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6038 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6039 + thus I wan't check for essential, as I'm upgrading.
6040 + I hope it won't break anything :)
6043 + abstract_pkg_t *parent_pkg = NULL;
6045 + if (pkg->essential && !message) {
6046 + if (conf->force_removal_of_essential_packages) {
6047 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6048 + "\tIf your system breaks, you get to keep both pieces\n",
6051 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6052 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6053 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6054 + "\tits will with the option: -force-removal-of-essential-packages\n",
6056 + return IPKG_PKG_IS_ESSENTIAL;
6060 + if ((parent_pkg = pkg->parent) == NULL)
6063 + /* only attempt to remove dependent installed packages if
6064 + * force_depends is not specified or the package is being
6067 + if (!conf->force_depends
6068 + && !(pkg->state_flag & SF_REPLACE)) {
6069 + abstract_pkg_t **dependents;
6070 + int has_installed_dependents =
6071 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6073 + if (has_installed_dependents) {
6075 + * if this package is depended up by others, then either we should
6076 + * not remove it or we should remove it and all of its dependents
6079 + if (!conf->force_removal_of_dependent_packages
6080 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6081 + return IPKG_PKG_HAS_DEPENDENTS;
6084 + /* remove packages depending on this package - Karthik */
6085 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6087 + if (err) return err;
6091 + if ( message==0 ){
6092 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6095 + pkg->state_flag |= SF_FILELIST_CHANGED;
6097 + pkg->state_want = SW_DEINSTALL;
6098 + ipkg_state_changed++;
6100 + pkg_run_script(conf, pkg, "prerm", "remove");
6102 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6103 + maintains an empty filelist rather than deleting it. That seems
6104 + like a big pain, and I don't see that that should make a big
6105 + difference, but for anyone who wants tighter compatibility,
6106 + feel free to fix this. */
6107 + remove_data_files_and_list(conf, pkg);
6109 + pkg_run_script(conf, pkg, "postrm", "remove");
6111 + remove_maintainer_scripts_except_postrm(conf, pkg);
6113 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6114 + * space, it doesn't make sense to leave extra configurations, files,
6115 + * and maintainer scripts left around. So, we make remove like purge,
6116 + * and take out all the crap :) */
6118 + remove_postrm(conf, pkg);
6119 + pkg->state_status = SS_NOT_INSTALLED;
6122 + parent_pkg->state_status = SS_NOT_INSTALLED;
6127 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6129 + ipkg_remove_pkg(conf, pkg,0);
6133 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6135 + str_list_t installed_dirs;
6136 + str_list_t *installed_files;
6137 + str_list_elt_t *iter;
6139 + conffile_t *conffile;
6140 + int removed_a_dir;
6143 + str_list_init(&installed_dirs);
6144 + installed_files = pkg_get_installed_files(pkg);
6146 + for (iter = installed_files->head; iter; iter = iter->next) {
6147 + file_name = iter->data;
6149 + if (file_is_dir(file_name)) {
6150 + str_list_append(&installed_dirs, strdup(file_name));
6154 + conffile = pkg_get_conffile(pkg, file_name);
6156 + /* XXX: QUESTION: Is this right? I figure we only need to
6157 + save the conffile if it has been modified. Is that what
6158 + dpkg does? Or does dpkg preserve all conffiles? If so,
6159 + this seems like a better thing to do to conserve
6161 + if (conffile_has_been_modified(conf, conffile)) {
6162 + printf(" not deleting modified conffile %s\n", file_name);
6168 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6169 + if (!conf->noaction)
6170 + unlink(file_name);
6173 + if (!conf->noaction) {
6175 + removed_a_dir = 0;
6176 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6177 + file_name = iter->data;
6179 + if (rmdir(file_name) == 0) {
6180 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6181 + removed_a_dir = 1;
6182 + str_list_remove(&installed_dirs, &iter);
6185 + } while (removed_a_dir);
6188 + pkg_free_installed_files(pkg);
6189 + /* We have to remove the file list now, so that
6190 + find_pkg_owning_file does not always just report this package */
6191 + pkg_remove_installed_files_list(conf, pkg);
6193 + /* Don't print warning for dirs that are provided by other packages */
6194 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6195 + file_name = iter->data;
6197 + owner = file_hash_get_file_owner(conf, file_name);
6200 + iter->data = NULL;
6201 + str_list_remove(&installed_dirs, &iter);
6206 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6208 + iter->data = NULL;
6210 + str_list_deinit(&installed_dirs);
6215 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6218 + char *globpattern;
6221 + if (conf->noaction) return 0;
6223 + sprintf_alloc(&globpattern, "%s/%s.*",
6224 + pkg->dest->info_dir, pkg->name);
6225 + err = glob(globpattern, 0, NULL, &globbuf);
6226 + free(globpattern);
6231 + for (i = 0; i < globbuf.gl_pathc; i++) {
6232 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6235 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6236 + unlink(globbuf.gl_pathv[i]);
6238 + globfree(&globbuf);
6243 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6245 + char *postrm_file_name;
6247 + if (conf->noaction) return 0;
6249 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6250 + pkg->dest->info_dir, pkg->name);
6251 + unlink(postrm_file_name);
6252 + free(postrm_file_name);
6256 Index: busybox-1.8.1/archival/libipkg/ipkg_remove.h
6257 ===================================================================
6258 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6259 +++ busybox-1.8.1/archival/libipkg/ipkg_remove.h 2007-11-10 17:40:53.360764656 +0100
6261 +/* ipkg_remove.h - the itsy package management system
6265 + Copyright (C) 2001 University of Southern California
6267 + This program is free software; you can redistribute it and/or
6268 + modify it under the terms of the GNU General Public License as
6269 + published by the Free Software Foundation; either version 2, or (at
6270 + your option) any later version.
6272 + This program is distributed in the hope that it will be useful, but
6273 + WITHOUT ANY WARRANTY; without even the implied warranty of
6274 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6275 + General Public License for more details.
6278 +#ifndef IPKG_REMOVE_H
6279 +#define IPKG_REMOVE_H
6282 +#include "ipkg_conf.h"
6284 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6285 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6286 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6287 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6288 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6289 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6290 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6294 Index: busybox-1.8.1/archival/libipkg/ipkg_upgrade.c
6295 ===================================================================
6296 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6297 +++ busybox-1.8.1/archival/libipkg/ipkg_upgrade.c 2007-11-10 17:40:53.360764656 +0100
6299 +/* ipkg_upgrade.c - the itsy package management system
6302 + Copyright (C) 2001 University of Southern California
6304 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6306 + This program is free software; you can redistribute it and/or
6307 + modify it under the terms of the GNU General Public License as
6308 + published by the Free Software Foundation; either version 2, or (at
6309 + your option) any later version.
6311 + This program is distributed in the hope that it will be useful, but
6312 + WITHOUT ANY WARRANTY; without even the implied warranty of
6313 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6314 + General Public License for more details.
6318 +#include "ipkg_install.h"
6319 +#include "ipkg_message.h"
6321 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6325 + char *old_version, *new_version;
6327 + if (old->state_flag & SF_HOLD) {
6328 + ipkg_message(conf, IPKG_NOTICE,
6329 + "Not upgrading package %s which is marked "
6330 + "hold (flags=%#x)\n", old->name, old->state_flag);
6334 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6335 + if (new == NULL) {
6336 + old_version = pkg_version_str_alloc(old);
6337 + ipkg_message(conf, IPKG_NOTICE,
6338 + "Assuming locally installed package %s (%s) "
6339 + "is up to date.\n", old->name, old_version);
6340 + free(old_version);
6344 + old_version = pkg_version_str_alloc(old);
6345 + new_version = pkg_version_str_alloc(new);
6347 + cmp = pkg_compare_versions(old, new);
6348 + ipkg_message(conf, IPKG_DEBUG,
6349 + "comparing visible versions of pkg %s:"
6350 + "\n\t%s is installed "
6351 + "\n\t%s is available "
6352 + "\n\t%d was comparison result\n",
6353 + old->name, old_version, new_version, cmp);
6355 + ipkg_message(conf, IPKG_INFO,
6356 + "Package %s (%s) installed in %s is up to date.\n",
6357 + old->name, old_version, old->dest->name);
6358 + free(old_version);
6359 + free(new_version);
6361 + } else if (cmp > 0) {
6362 + ipkg_message(conf, IPKG_NOTICE,
6363 + "Not downgrading package %s on %s from %s to %s.\n",
6364 + old->name, old->dest->name, old_version, new_version);
6365 + free(old_version);
6366 + free(new_version);
6368 + } else if (cmp < 0) {
6369 + new->dest = old->dest;
6370 + old->state_want = SW_DEINSTALL;
6373 + new->state_flag |= SF_USER;
6374 + return ipkg_install_pkg(conf, new,1);
6376 Index: busybox-1.8.1/archival/libipkg/ipkg_upgrade.h
6377 ===================================================================
6378 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6379 +++ busybox-1.8.1/archival/libipkg/ipkg_upgrade.h 2007-11-10 17:40:53.360764656 +0100
6381 +/* ipkg_upgrade.c - the itsy package management system
6383 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6385 + This program is free software; you can redistribute it and/or
6386 + modify it under the terms of the GNU General Public License as
6387 + published by the Free Software Foundation; either version 2, or (at
6388 + your option) any later version.
6390 + This program is distributed in the hope that it will be useful, but
6391 + WITHOUT ANY WARRANTY; without even the implied warranty of
6392 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6393 + General Public License for more details.
6398 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6399 Index: busybox-1.8.1/archival/libipkg/ipkg_utils.c
6400 ===================================================================
6401 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6402 +++ busybox-1.8.1/archival/libipkg/ipkg_utils.c 2007-11-10 17:40:53.360764656 +0100
6404 +/* ipkg_utils.c - the itsy package management system
6408 + Copyright (C) 2002 Compaq Computer Corporation
6410 + This program is free software; you can redistribute it and/or
6411 + modify it under the terms of the GNU General Public License as
6412 + published by the Free Software Foundation; either version 2, or (at
6413 + your option) any later version.
6415 + This program is distributed in the hope that it will be useful, but
6416 + WITHOUT ANY WARRANTY; without even the implied warranty of
6417 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6418 + General Public License for more details.
6424 +#include <sys/vfs.h>
6426 +#include "ipkg_utils.h"
6428 +#include "pkg_hash.h"
6430 +struct errlist* error_list;
6432 +int get_available_blocks(char * filesystem)
6434 + struct statfs sfs;
6436 + if(statfs(filesystem, &sfs)){
6437 + fprintf(stderr, "bad statfs\n");
6440 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6441 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6444 +char **read_raw_pkgs_from_file(const char *file_name)
6449 + if(!(fp = fopen(file_name, "r"))){
6450 + fprintf(stderr, "can't get %s open for read\n", file_name);
6454 + ret = read_raw_pkgs_from_stream(fp);
6461 +char **read_raw_pkgs_from_stream(FILE *fp)
6463 + char **raw = NULL, *buf, *scout;
6465 + size_t size = 512;
6467 + buf = malloc (size);
6469 + while (fgets(buf, size, fp)) {
6470 + while (strlen (buf) == (size - 1)
6471 + && buf[size-2] != '\n') {
6472 + size_t o = size - 1;
6474 + buf = realloc (buf, size);
6475 + if (fgets (buf + o, size - o, fp) == NULL)
6480 + raw = realloc(raw, (count + 50) * sizeof(char *));
6482 + if((scout = strchr(buf, '\n')))
6485 + raw[count++] = strdup(buf);
6488 + raw = realloc(raw, (count + 1) * sizeof(char *));
6489 + raw[count] = NULL;
6496 +/* something to remove whitespace, a hash pooper */
6497 +char *trim_alloc(char *line)
6500 + char *dest, *src, *end;
6502 + new = malloc(strlen(line) + 1);
6503 + if ( new == NULL ){
6504 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6507 + dest = new, src = line, end = line + (strlen(line) - 1);
6509 + /* remove it from the front */
6514 + /* and now from the back */
6515 + while((end > src) &&
6521 + /* this does from the first space
6522 + * blasting away any versions stuff in depends
6533 +int line_is_blank(const char *line)
6537 + for (s = line; *s; s++) {
6544 +void push_error_list(struct errlist ** errors, char * msg){
6545 + struct errlist *err_lst_tmp;
6548 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6549 + err_lst_tmp->errmsg=strdup(msg) ;
6550 + err_lst_tmp->next = *errors;
6551 + *errors = err_lst_tmp;
6555 +void reverse_error_list(struct errlist **errors){
6556 + struct errlist *result=NULL;
6557 + struct errlist *current= *errors;
6558 + struct errlist *next;
6560 + while ( current != NULL ) {
6561 + next = current->next;
6562 + current->next=result;
6571 +void free_error_list(struct errlist **errors){
6572 + struct errlist *current = *errors;
6574 + while (current != NULL) {
6575 + free(current->errmsg);
6576 + current = (*errors)->next;
6578 + *errors = current;
6585 Index: busybox-1.8.1/archival/libipkg/ipkg_utils.h
6586 ===================================================================
6587 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6588 +++ busybox-1.8.1/archival/libipkg/ipkg_utils.h 2007-11-10 17:40:53.360764656 +0100
6590 +/* ipkg_utils.h - the itsy package management system
6594 + Copyright (C) 2002 Compaq Computer Corporation
6596 + This program is free software; you can redistribute it and/or
6597 + modify it under the terms of the GNU General Public License as
6598 + published by the Free Software Foundation; either version 2, or (at
6599 + your option) any later version.
6601 + This program is distributed in the hope that it will be useful, but
6602 + WITHOUT ANY WARRANTY; without even the implied warranty of
6603 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6604 + General Public License for more details.
6607 +#ifndef IPKG_UTILS_H
6608 +#define IPKG_UTILS_H
6612 +int get_available_blocks(char * filesystem);
6613 +char **read_raw_pkgs_from_file(const char *file_name);
6614 +char **read_raw_pkgs_from_stream(FILE *fp);
6615 +char *trim_alloc(char * line);
6616 +int line_is_blank(const char *line);
6619 Index: busybox-1.8.1/archival/libipkg/Kbuild
6620 ===================================================================
6621 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6622 +++ busybox-1.8.1/archival/libipkg/Kbuild 2007-11-10 17:40:53.364764882 +0100
6624 +# Makefile for busybox
6626 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6627 +# Copyright (C) 2006 OpenWrt.org
6629 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6631 +LIBIPKG_CORE_OBJS:= \
6636 +LIBIPKG_CMD_OBJS:= \
6638 + ipkg_configure.o \
6644 +LIBIPKG_DB_OBJS:= \
6655 +LIBIPKG_LIST_OBJS:= \
6667 +LIBIPKG_UTIL_OBJS:= \
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6677 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6678 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6680 +ifeq ($(strip $(IPKG_ARCH)),)
6681 +IPKG_ARCH:=$(TARGET_ARCH)
6683 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6684 Index: busybox-1.8.1/archival/libipkg/libipkg.c
6685 ===================================================================
6686 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6687 +++ busybox-1.8.1/archival/libipkg/libipkg.c 2007-11-10 17:40:53.364764882 +0100
6689 +/* ipkglib.c - the itsy package management system
6693 + Copyright (C) 2003 kernel concepts
6695 + This program is free software; you can redistribute it and/or
6696 + modify it under the terms of the GNU General Public License as
6697 + published by the Free Software Foundation; either version 2, or (at
6698 + your option) any later version.
6700 + This program is distributed in the hope that it will be useful, but
6701 + WITHOUT ANY WARRANTY; without even the implied warranty of
6702 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6703 + General Public License for more details.
6709 +#include "ipkg_includes.h"
6710 +#include "libipkg.h"
6713 +#include "ipkg_conf.h"
6714 +#include "ipkg_cmd.h"
6715 +#include "file_util.h"
6719 +ipkg_message_callback ipkg_cb_message = NULL;
6720 +ipkg_response_callback ipkg_cb_response = NULL;
6721 +ipkg_status_callback ipkg_cb_status = NULL;
6722 +ipkg_list_callback ipkg_cb_list = NULL;
6726 +ipkg_init (ipkg_message_callback mcall,
6727 + ipkg_response_callback rcall,
6730 + ipkg_cb_message = mcall;
6731 + ipkg_cb_response = rcall;
6740 +ipkg_deinit (args_t * args)
6742 + args_deinit (args);
6743 + ipkg_cb_message = NULL;
6744 + ipkg_cb_response = NULL;
6746 + /* place other cleanup stuff here */
6753 +ipkg_packages_list(args_t *args,
6754 + const char *packages,
6755 + ipkg_list_callback cblist,
6759 + ipkg_conf_t ipkg_conf;
6762 + err = ipkg_conf_init (&ipkg_conf, args);
6768 + ipkg_cb_list = cblist;
6769 + /* we need to do this because of static declarations,
6770 + * maybe a good idea to change */
6771 + cmd = ipkg_cmd_find ("list");
6773 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6775 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6776 + ipkg_cb_list = NULL;
6777 + ipkg_conf_deinit (&ipkg_conf);
6783 +ipkg_packages_status(args_t *args,
6784 + const char *packages,
6785 + ipkg_status_callback cbstatus,
6789 + ipkg_conf_t ipkg_conf;
6792 + err = ipkg_conf_init (&ipkg_conf, args);
6798 + ipkg_cb_status = cbstatus;
6800 + /* we need to do this because of static declarations,
6801 + * maybe a good idea to change */
6802 + cmd = ipkg_cmd_find ("status");
6804 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6806 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6808 + ipkg_cb_status = NULL;
6809 + ipkg_conf_deinit (&ipkg_conf);
6815 +ipkg_packages_info(args_t *args,
6816 + const char *packages,
6817 + ipkg_status_callback cbstatus,
6821 + ipkg_conf_t ipkg_conf;
6824 + err = ipkg_conf_init (&ipkg_conf, args);
6830 + ipkg_cb_status = cbstatus;
6832 + /* we need to do this because of static declarations,
6833 + * maybe a good idea to change */
6834 + cmd = ipkg_cmd_find ("info");
6836 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6838 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6840 + ipkg_cb_status = NULL;
6841 + ipkg_conf_deinit (&ipkg_conf);
6847 +ipkg_packages_install (args_t * args, const char *name)
6850 + ipkg_conf_t ipkg_conf;
6853 + /* this error should be handled in application */
6854 + if (!name || !strlen (name))
6857 + err = ipkg_conf_init (&ipkg_conf, args);
6863 + /* we need to do this because of static declarations,
6864 + * maybe a good idea to change */
6865 + cmd = ipkg_cmd_find ("install");
6866 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6868 + ipkg_conf_deinit(&ipkg_conf);
6874 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6877 + ipkg_conf_t ipkg_conf;
6880 + /* this error should be handled in application */
6881 + if (!name || !strlen (name))
6884 + err = ipkg_conf_init (&ipkg_conf, args);
6890 + /* we need to do this because of static declarations,
6891 + * maybe a good idea to change */
6893 + cmd = ipkg_cmd_find ("purge");
6895 + cmd = ipkg_cmd_find ("remove");
6897 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6899 + ipkg_conf_deinit(&ipkg_conf);
6905 +ipkg_lists_update(args_t *args)
6908 + ipkg_conf_t ipkg_conf;
6911 + err = ipkg_conf_init (&ipkg_conf, args);
6917 + /* we need to do this because of static declarations,
6918 + * maybe a good idea to change */
6919 + cmd = ipkg_cmd_find ("update");
6921 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6923 + ipkg_conf_deinit(&ipkg_conf);
6929 +ipkg_packages_upgrade(args_t *args)
6932 + ipkg_conf_t ipkg_conf;
6935 + err = ipkg_conf_init (&ipkg_conf, args);
6941 + /* we need to do this because of static declarations,
6942 + * maybe a good idea to change */
6943 + cmd = ipkg_cmd_find ("upgrade");
6945 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6947 + ipkg_conf_deinit(&ipkg_conf);
6953 +ipkg_packages_download (args_t * args, const char *name)
6956 + ipkg_conf_t ipkg_conf;
6959 + /* this error should be handled in application */
6960 + if (!name || !strlen (name))
6963 + err = ipkg_conf_init (&ipkg_conf, args);
6969 + /* we need to do this because of static declarations,
6970 + * maybe a good idea to change */
6971 + cmd = ipkg_cmd_find ("download");
6972 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6974 + ipkg_conf_deinit(&ipkg_conf);
6980 +ipkg_package_files(args_t *args,
6982 + ipkg_list_callback cblist,
6986 + ipkg_conf_t ipkg_conf;
6989 + /* this error should be handled in application */
6990 + if (!name || !strlen (name))
6993 + err = ipkg_conf_init (&ipkg_conf, args);
6999 + ipkg_cb_list = cblist;
7001 + /* we need to do this because of static declarations,
7002 + * maybe a good idea to change */
7003 + cmd = ipkg_cmd_find ("files");
7005 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7007 + ipkg_cb_list = NULL;
7008 + ipkg_conf_deinit(&ipkg_conf);
7014 +ipkg_file_search(args_t *args,
7016 + ipkg_list_callback cblist,
7020 + ipkg_conf_t ipkg_conf;
7023 + /* this error should be handled in application */
7024 + if (!file || !strlen (file))
7027 + err = ipkg_conf_init (&ipkg_conf, args);
7033 + ipkg_cb_list = cblist;
7035 + /* we need to do this because of static declarations,
7036 + * maybe a good idea to change */
7037 + cmd = ipkg_cmd_find ("search");
7038 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7040 + ipkg_cb_list = NULL;
7041 + ipkg_conf_deinit(&ipkg_conf);
7047 +ipkg_file_what(args_t *args, const char *file, const char* command)
7050 + ipkg_conf_t ipkg_conf;
7053 + /* this error should be handled in application */
7054 + if (!file || !strlen (file))
7057 + err = ipkg_conf_init (&ipkg_conf, args);
7063 + /* we need to do this because of static declarations,
7064 + * maybe a good idea to change */
7065 + cmd = ipkg_cmd_find (command);
7066 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7068 + ipkg_conf_deinit(&ipkg_conf);
7072 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7073 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7074 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7075 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7076 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7079 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7082 + if (conf && (conf->verbosity < level)) {
7086 + if ( level == IPKG_ERROR ){
7087 + push_error_list(&error_list, msg);
7096 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7097 + pkg_state_status_t status, void *userdata)
7100 + printf("%s - %s - %s\n", name, version, desc);
7102 + printf("%s - %s\n", name, version);
7106 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7107 + pkg_state_status_t status, void *userdata)
7110 + printf("%s\n", desc);
7114 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7117 + printf("%s\n", desc);
7121 +char* default_ipkg_response_callback(char *question)
7123 + char *response = NULL;
7127 + response = (char *)file_read_line_alloc(stdin);
7128 + } while (response == NULL);
7132 +/* This is used for backward compatibility */
7134 +ipkg_op (int argc, char *argv[])
7136 + int err, opt_index;
7140 + ipkg_conf_t ipkg_conf;
7142 + args_init (&args);
7144 + opt_index = args_parse (&args, argc, argv);
7145 + if (opt_index == argc || opt_index < 0)
7147 + args_usage ("ipkg must have one sub-command argument");
7150 + cmd_name = argv[opt_index++];
7151 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7152 + read anything from there.
7154 + if ( !strcmp(cmd_name,"print-architecture") ||
7155 + !strcmp(cmd_name,"print_architecture") ||
7156 + !strcmp(cmd_name,"print-installation-architecture") ||
7157 + !strcmp(cmd_name,"print_installation_architecture") )
7158 + args.nocheckfordirorfile = 1;
7160 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7161 + read anything from there.
7163 + if ( !strcmp(cmd_name,"flag") ||
7164 + !strcmp(cmd_name,"configure") ||
7165 + !strcmp(cmd_name,"remove") ||
7166 + !strcmp(cmd_name,"files") ||
7167 + !strcmp(cmd_name,"search") ||
7168 + !strcmp(cmd_name,"compare_versions") ||
7169 + !strcmp(cmd_name,"compare-versions") ||
7170 + !strcmp(cmd_name,"list_installed") ||
7171 + !strcmp(cmd_name,"list-installed") ||
7172 + !strcmp(cmd_name,"status") )
7173 + args.noreadfeedsfile = 1;
7176 + err = ipkg_conf_init (&ipkg_conf, &args);
7182 + args_deinit (&args);
7184 + ipkg_cb_message = default_ipkg_message_callback;
7185 + ipkg_cb_response = default_ipkg_response_callback;
7186 + ipkg_cb_status = default_ipkg_status_callback;
7187 + if ( strcmp(cmd_name, "files")==0)
7188 + ipkg_cb_list = default_ipkg_files_callback;
7190 + ipkg_cb_list = default_ipkg_list_callback;
7192 + cmd = ipkg_cmd_find (cmd_name);
7195 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7197 + args_usage (NULL);
7200 + if (cmd->requires_args && opt_index == argc)
7203 + "%s: the ``%s'' command requires at least one argument\n",
7204 + __FUNCTION__, cmd_name);
7205 + args_usage (NULL);
7208 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7210 + ipkg_conf_deinit (&ipkg_conf);
7215 +#endif /* IPKG_LIB */
7216 Index: busybox-1.8.1/archival/libipkg/libipkg.h
7217 ===================================================================
7218 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7219 +++ busybox-1.8.1/archival/libipkg/libipkg.h 2007-11-10 17:40:53.364764882 +0100
7221 +/* ipkglib.h - the itsy package management system
7223 + Florian Boor <florian.boor@kernelconcepts.de>
7225 + This program is free software; you can redistribute it and/or
7226 + modify it under the terms of the GNU General Public License as
7227 + published by the Free Software Foundation; either version 2, or (at
7228 + your option) any later version.
7230 + This program is distributed in the hope that it will be useful, but
7231 + WITHOUT ANY WARRANTY; without even the implied warranty of
7232 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7233 + General Public License for more details.
7241 +#include "ipkg_conf.h"
7242 +#include "ipkg_message.h"
7248 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7250 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7251 + pkg_state_status_t status, void *userdata);
7252 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7254 +typedef char* (*ipkg_response_callback)(char *question);
7256 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7257 +extern int ipkg_init (ipkg_message_callback mcall,
7258 + ipkg_response_callback rcall,
7261 +extern int ipkg_deinit (args_t *args);
7262 +extern int ipkg_packages_list(args_t *args,
7263 + const char *packages,
7264 + ipkg_list_callback cblist,
7266 +extern int ipkg_packages_status(args_t *args,
7267 + const char *packages,
7268 + ipkg_status_callback cbstatus,
7270 +extern int ipkg_packages_info(args_t *args,
7271 + const char *packages,
7272 + ipkg_status_callback cbstatus,
7274 +extern int ipkg_packages_install(args_t *args, const char *name);
7275 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7276 +extern int ipkg_lists_update(args_t *args);
7277 +extern int ipkg_packages_upgrade(args_t *args);
7278 +extern int ipkg_packages_download(args_t *args, const char *name);
7279 +extern int ipkg_package_files(args_t *args,
7281 + ipkg_list_callback cblist,
7283 +extern int ipkg_file_search(args_t *args,
7285 + ipkg_list_callback cblist,
7287 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7288 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7289 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7290 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7291 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7293 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7294 +extern ipkg_response_callback ipkg_cb_response;
7295 +extern ipkg_status_callback ipkg_cb_status;
7296 +extern ipkg_list_callback ipkg_cb_list;
7297 +extern void push_error_list(struct errlist **errors,char * msg);
7298 +extern void reverse_error_list(struct errlist **errors);
7299 +extern void free_error_list(struct errlist **errors);
7303 +extern int ipkg_op(int argc, char *argv[]);
7309 Index: busybox-1.8.1/archival/libipkg/nv_pair.c
7310 ===================================================================
7311 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7312 +++ busybox-1.8.1/archival/libipkg/nv_pair.c 2007-11-10 17:40:53.364764882 +0100
7314 +/* nv_pair.c - the itsy package management system
7318 + Copyright (C) 2001 University of Southern California
7320 + This program is free software; you can redistribute it and/or
7321 + modify it under the terms of the GNU General Public License as
7322 + published by the Free Software Foundation; either version 2, or (at
7323 + your option) any later version.
7325 + This program is distributed in the hope that it will be useful, but
7326 + WITHOUT ANY WARRANTY; without even the implied warranty of
7327 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7328 + General Public License for more details.
7333 +#include "nv_pair.h"
7334 +#include "str_util.h"
7336 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7338 + nv_pair->name = str_dup_safe(name);
7339 + nv_pair->value = str_dup_safe(value);
7344 +void nv_pair_deinit(nv_pair_t *nv_pair)
7346 + free(nv_pair->name);
7347 + nv_pair->name = NULL;
7349 + free(nv_pair->value);
7350 + nv_pair->value = NULL;
7354 Index: busybox-1.8.1/archival/libipkg/nv_pair.h
7355 ===================================================================
7356 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7357 +++ busybox-1.8.1/archival/libipkg/nv_pair.h 2007-11-10 17:40:53.372765337 +0100
7359 +/* nv_pair.h - the itsy package management system
7363 + Copyright (C) 2001 University of Southern California
7365 + This program is free software; you can redistribute it and/or
7366 + modify it under the terms of the GNU General Public License as
7367 + published by the Free Software Foundation; either version 2, or (at
7368 + your option) any later version.
7370 + This program is distributed in the hope that it will be useful, but
7371 + WITHOUT ANY WARRANTY; without even the implied warranty of
7372 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7373 + General Public License for more details.
7379 +typedef struct nv_pair nv_pair_t;
7386 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7387 +void nv_pair_deinit(nv_pair_t *nv_pair);
7391 Index: busybox-1.8.1/archival/libipkg/nv_pair_list.c
7392 ===================================================================
7393 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7394 +++ busybox-1.8.1/archival/libipkg/nv_pair_list.c 2007-11-10 17:40:53.372765337 +0100
7396 +/* nv_pair_list.c - the itsy package management system
7400 + Copyright (C) 2001 University of Southern California
7402 + This program is free software; you can redistribute it and/or
7403 + modify it under the terms of the GNU General Public License as
7404 + published by the Free Software Foundation; either version 2, or (at
7405 + your option) any later version.
7407 + This program is distributed in the hope that it will be useful, but
7408 + WITHOUT ANY WARRANTY; without even the implied warranty of
7409 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7410 + General Public License for more details.
7415 +#include "nv_pair.h"
7416 +#include "void_list.h"
7417 +#include "nv_pair_list.h"
7419 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7421 + return void_list_elt_init((void_list_elt_t *) elt, data);
7424 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7426 + void_list_elt_deinit((void_list_elt_t *) elt);
7429 +int nv_pair_list_init(nv_pair_list_t *list)
7431 + return void_list_init((void_list_t *) list);
7434 +void nv_pair_list_deinit(nv_pair_list_t *list)
7436 + nv_pair_list_elt_t *iter;
7437 + nv_pair_t *nv_pair;
7439 + for (iter = list->head; iter; iter = iter->next) {
7440 + nv_pair = iter->data;
7441 + nv_pair_deinit(nv_pair);
7443 + /* malloced in nv_pair_list_append */
7445 + iter->data = NULL;
7447 + void_list_deinit((void_list_t *) list);
7450 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7454 + /* freed in nv_pair_list_deinit */
7455 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7457 + if (nv_pair == NULL) {
7458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7461 + nv_pair_init(nv_pair, name, value);
7463 + err = void_list_append((void_list_t *) list, nv_pair);
7471 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7473 + return void_list_push((void_list_t *) list, data);
7476 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7478 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7481 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7483 + nv_pair_list_elt_t *iter;
7484 + nv_pair_t *nv_pair;
7486 + for (iter = list->head; iter; iter = iter->next) {
7487 + nv_pair = iter->data;
7488 + if (strcmp(nv_pair->name, name) == 0) {
7489 + return nv_pair->value;
7494 Index: busybox-1.8.1/archival/libipkg/nv_pair_list.h
7495 ===================================================================
7496 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7497 +++ busybox-1.8.1/archival/libipkg/nv_pair_list.h 2007-11-10 17:40:53.372765337 +0100
7499 +/* nv_pair_list.h - the itsy package management system
7503 + Copyright (C) 2001 University of Southern California
7505 + This program is free software; you can redistribute it and/or
7506 + modify it under the terms of the GNU General Public License as
7507 + published by the Free Software Foundation; either version 2, or (at
7508 + your option) any later version.
7510 + This program is distributed in the hope that it will be useful, but
7511 + WITHOUT ANY WARRANTY; without even the implied warranty of
7512 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7513 + General Public License for more details.
7516 +#ifndef NV_PAIR_LIST_H
7517 +#define NV_PAIR_LIST_H
7519 +#include "nv_pair.h"
7520 +#include "void_list.h"
7522 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7523 +struct nv_pair_list_elt
7525 + nv_pair_list_elt_t *next;
7529 +typedef struct nv_pair_list nv_pair_list_t;
7530 +struct nv_pair_list
7532 + nv_pair_list_elt_t pre_head;
7533 + nv_pair_list_elt_t *head;
7534 + nv_pair_list_elt_t *tail;
7537 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7539 + if (list->head == NULL)
7545 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7546 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7548 +int nv_pair_list_init(nv_pair_list_t *list);
7549 +void nv_pair_list_deinit(nv_pair_list_t *list);
7551 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7552 + const char *name, const char *value);
7553 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7554 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7555 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7559 Index: busybox-1.8.1/archival/libipkg/pkg.c
7560 ===================================================================
7561 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7562 +++ busybox-1.8.1/archival/libipkg/pkg.c 2007-11-10 17:40:53.376765566 +0100
7564 +/* pkg.c - the itsy package management system
7568 + Copyright (C) 2001 University of Southern California
7570 + This program is free software; you can redistribute it and/or
7571 + modify it under the terms of the GNU General Public License as
7572 + published by the Free Software Foundation; either version 2, or (at
7573 + your option) any later version.
7575 + This program is distributed in the hope that it will be useful, but
7576 + WITHOUT ANY WARRANTY; without even the implied warranty of
7577 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7578 + General Public License for more details.
7583 +#include <string.h>
7588 +#include "pkg_parse.h"
7589 +#include "pkg_extract.h"
7590 +#include "ipkg_message.h"
7591 +#include "ipkg_utils.h"
7593 +#include "sprintf_alloc.h"
7594 +#include "file_util.h"
7595 +#include "str_util.h"
7596 +#include "xsystem.h"
7597 +#include "ipkg_conf.h"
7599 +typedef struct enum_map enum_map_t;
7606 +static const enum_map_t pkg_state_want_map[] = {
7607 + { SW_UNKNOWN, "unknown"},
7608 + { SW_INSTALL, "install"},
7609 + { SW_DEINSTALL, "deinstall"},
7610 + { SW_PURGE, "purge"}
7613 +static const enum_map_t pkg_state_flag_map[] = {
7615 + { SF_REINSTREQ, "reinstreq"},
7616 + { SF_HOLD, "hold"},
7617 + { SF_REPLACE, "replace"},
7618 + { SF_NOPRUNE, "noprune"},
7619 + { SF_PREFER, "prefer"},
7620 + { SF_OBSOLETE, "obsolete"},
7621 + { SF_USER, "user"},
7624 +static const enum_map_t pkg_state_status_map[] = {
7625 + { SS_NOT_INSTALLED, "not-installed" },
7626 + { SS_UNPACKED, "unpacked" },
7627 + { SS_HALF_CONFIGURED, "half-configured" },
7628 + { SS_INSTALLED, "installed" },
7629 + { SS_HALF_INSTALLED, "half-installed" },
7630 + { SS_CONFIG_FILES, "config-files" },
7631 + { SS_POST_INST_FAILED, "post-inst-failed" },
7632 + { SS_REMOVAL_FAILED, "removal-failed" }
7635 +static int verrevcmp(const char *val, const char *ref);
7638 +pkg_t *pkg_new(void)
7642 + pkg = malloc(sizeof(pkg_t));
7643 + if (pkg == NULL) {
7644 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7653 +int pkg_init(pkg_t *pkg)
7655 + memset(pkg, 0, sizeof(pkg_t));
7658 + pkg->version = NULL;
7659 + pkg->revision = NULL;
7660 + pkg->familiar_revision = NULL;
7663 + pkg->architecture = NULL;
7664 + pkg->maintainer = NULL;
7665 + pkg->section = NULL;
7666 + pkg->description = NULL;
7667 + pkg->state_want = SW_UNKNOWN;
7668 + pkg->state_flag = SF_OK;
7669 + pkg->state_status = SS_NOT_INSTALLED;
7670 + pkg->depends_str = NULL;
7671 + pkg->provides_str = NULL;
7672 + pkg->depends_count = 0;
7673 + pkg->depends = NULL;
7674 + pkg->suggests_str = NULL;
7675 + pkg->recommends_str = NULL;
7676 + pkg->suggests_count = 0;
7677 + pkg->recommends_count = 0;
7679 + /* Abhaya: added init for conflicts fields */
7680 + pkg->conflicts = NULL;
7681 + pkg->conflicts_count = 0;
7683 + /* added for replaces. Jamey 7/23/2002 */
7684 + pkg->replaces = NULL;
7685 + pkg->replaces_count = 0;
7687 + pkg->pre_depends_count = 0;
7688 + pkg->pre_depends_str = NULL;
7689 + pkg->provides_count = 0;
7690 + pkg->provides = NULL;
7691 + pkg->filename = NULL;
7692 + pkg->local_filename = NULL;
7693 + pkg->tmp_unpack_dir = NULL;
7694 + pkg->md5sum = NULL;
7696 + pkg->installed_size = NULL;
7697 + pkg->priority = NULL;
7698 + pkg->source = NULL;
7699 + conffile_list_init(&pkg->conffiles);
7700 + pkg->installed_files = NULL;
7701 + pkg->installed_files_ref_cnt = 0;
7702 + pkg->essential = 0;
7703 + pkg->provided_by_hand = 0;
7708 +void pkg_deinit(pkg_t *pkg)
7713 + free(pkg->version);
7714 + pkg->version = NULL;
7715 + /* revision and familiar_revision share storage with version, so
7717 + pkg->revision = NULL;
7718 + pkg->familiar_revision = NULL;
7719 + /* owned by ipkg_conf_t */
7721 + /* owned by ipkg_conf_t */
7723 + free(pkg->architecture);
7724 + pkg->architecture = NULL;
7725 + free(pkg->maintainer);
7726 + pkg->maintainer = NULL;
7727 + free(pkg->section);
7728 + pkg->section = NULL;
7729 + free(pkg->description);
7730 + pkg->description = NULL;
7731 + pkg->state_want = SW_UNKNOWN;
7732 + pkg->state_flag = SF_OK;
7733 + pkg->state_status = SS_NOT_INSTALLED;
7734 + free(pkg->depends_str);
7735 + pkg->depends_str = NULL;
7736 + free(pkg->provides_str);
7737 + pkg->provides_str = NULL;
7738 + pkg->depends_count = 0;
7739 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7740 + pkg->pre_depends_count = 0;
7741 + free(pkg->pre_depends_str);
7742 + pkg->pre_depends_str = NULL;
7743 + pkg->provides_count = 0;
7744 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7745 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7746 + free(pkg->filename);
7747 + pkg->filename = NULL;
7748 + free(pkg->local_filename);
7749 + pkg->local_filename = NULL;
7750 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7751 + ipkg_install.c here. See comment in
7752 + ipkg_install.c:cleanup_temporary_files */
7753 + free(pkg->tmp_unpack_dir);
7754 + pkg->tmp_unpack_dir = NULL;
7755 + free(pkg->md5sum);
7756 + pkg->md5sum = NULL;
7759 + free(pkg->installed_size);
7760 + pkg->installed_size = NULL;
7761 + free(pkg->priority);
7762 + pkg->priority = NULL;
7763 + free(pkg->source);
7764 + pkg->source = NULL;
7765 + conffile_list_deinit(&pkg->conffiles);
7766 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7767 + since if they are calling deinit, they should know. Maybe do an
7768 + assertion here instead? */
7769 + pkg->installed_files_ref_cnt = 1;
7770 + pkg_free_installed_files(pkg);
7771 + pkg->essential = 0;
7774 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7778 + FILE *control_file;
7780 + err = pkg_init(pkg);
7781 + if (err) { return err; }
7783 + pkg->local_filename = strdup(filename);
7785 + control_file = tmpfile();
7786 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7787 + if (err) { return err; }
7789 + rewind(control_file);
7790 + raw = read_raw_pkgs_from_stream(control_file);
7791 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7793 + fclose(control_file);
7798 +/* Merge any new information in newpkg into oldpkg */
7799 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7800 + newpkg, but should leave it usable. This rework is so that
7801 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7803 + * uh, i thought that i had originally written this so that it took
7804 + * two pkgs and returned a new one? we can do that again... -sma
7806 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7808 + if (oldpkg == newpkg) {
7813 + oldpkg->src = newpkg->src;
7814 + if (!oldpkg->dest)
7815 + oldpkg->dest = newpkg->dest;
7816 + if (!oldpkg->architecture)
7817 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7818 + if (!oldpkg->arch_priority)
7819 + oldpkg->arch_priority = newpkg->arch_priority;
7820 + if (!oldpkg->section)
7821 + oldpkg->section = str_dup_safe(newpkg->section);
7822 + if(!oldpkg->maintainer)
7823 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7824 + if(!oldpkg->description)
7825 + oldpkg->description = str_dup_safe(newpkg->description);
7827 + /* merge the state_flags from the new package */
7828 + oldpkg->state_want = newpkg->state_want;
7829 + oldpkg->state_status = newpkg->state_status;
7830 + oldpkg->state_flag = newpkg->state_flag;
7832 + if (oldpkg->state_want == SW_UNKNOWN)
7833 + oldpkg->state_want = newpkg->state_want;
7834 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7835 + oldpkg->state_status = newpkg->state_status;
7836 + oldpkg->state_flag |= newpkg->state_flag;
7839 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7840 + oldpkg->depends_str = newpkg->depends_str;
7841 + newpkg->depends_str = NULL;
7842 + oldpkg->depends_count = newpkg->depends_count;
7843 + newpkg->depends_count = 0;
7845 + oldpkg->depends = newpkg->depends;
7846 + newpkg->depends = NULL;
7848 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7849 + newpkg->pre_depends_str = NULL;
7850 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7851 + newpkg->pre_depends_count = 0;
7853 + oldpkg->recommends_str = newpkg->recommends_str;
7854 + newpkg->recommends_str = NULL;
7855 + oldpkg->recommends_count = newpkg->recommends_count;
7856 + newpkg->recommends_count = 0;
7858 + oldpkg->suggests_str = newpkg->suggests_str;
7859 + newpkg->suggests_str = NULL;
7860 + oldpkg->suggests_count = newpkg->suggests_count;
7861 + newpkg->suggests_count = 0;
7864 + if (!oldpkg->provides_str) {
7865 + oldpkg->provides_str = newpkg->provides_str;
7866 + newpkg->provides_str = NULL;
7867 + oldpkg->provides_count = newpkg->provides_count;
7868 + newpkg->provides_count = 0;
7870 + oldpkg->provides = newpkg->provides;
7871 + newpkg->provides = NULL;
7874 + if (!oldpkg->conflicts_str) {
7875 + oldpkg->conflicts_str = newpkg->conflicts_str;
7876 + newpkg->conflicts_str = NULL;
7877 + oldpkg->conflicts_count = newpkg->conflicts_count;
7878 + newpkg->conflicts_count = 0;
7880 + oldpkg->conflicts = newpkg->conflicts;
7881 + newpkg->conflicts = NULL;
7884 + if (!oldpkg->replaces_str) {
7885 + oldpkg->replaces_str = newpkg->replaces_str;
7886 + newpkg->replaces_str = NULL;
7887 + oldpkg->replaces_count = newpkg->replaces_count;
7888 + newpkg->replaces_count = 0;
7890 + oldpkg->replaces = newpkg->replaces;
7891 + newpkg->replaces = NULL;
7894 + if (!oldpkg->filename)
7895 + oldpkg->filename = str_dup_safe(newpkg->filename);
7897 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7898 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7899 + if (!oldpkg->local_filename)
7900 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7901 + if (!oldpkg->tmp_unpack_dir)
7902 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7903 + if (!oldpkg->md5sum)
7904 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7905 + if (!oldpkg->size)
7906 + oldpkg->size = str_dup_safe(newpkg->size);
7907 + if (!oldpkg->installed_size)
7908 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7909 + if (!oldpkg->priority)
7910 + oldpkg->priority = str_dup_safe(newpkg->priority);
7911 + if (!oldpkg->source)
7912 + oldpkg->source = str_dup_safe(newpkg->source);
7913 + if (oldpkg->conffiles.head == NULL){
7914 + oldpkg->conffiles = newpkg->conffiles;
7915 + conffile_list_init(&newpkg->conffiles);
7917 + if (!oldpkg->installed_files){
7918 + oldpkg->installed_files = newpkg->installed_files;
7919 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7920 + newpkg->installed_files = NULL;
7922 + if (!oldpkg->essential)
7923 + oldpkg->essential = newpkg->essential;
7925 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7930 +abstract_pkg_t *abstract_pkg_new(void)
7932 + abstract_pkg_t * ab_pkg;
7934 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7936 + if (ab_pkg == NULL) {
7937 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7941 + if ( abstract_pkg_init(ab_pkg) < 0 )
7947 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7949 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7951 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7952 + if (ab_pkg->provided_by==NULL){
7955 + ab_pkg->dependencies_checked = 0;
7956 + ab_pkg->state_status = SS_NOT_INSTALLED;
7961 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7964 + char **raw_start=NULL;
7966 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7967 + if (temp_str == NULL ){
7968 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7971 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7973 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7974 + if (raw == NULL ){
7975 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7980 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7981 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7997 +char * pkg_formatted_info(pkg_t *pkg )
8002 + buff = malloc(8192);
8003 + if (buff == NULL) {
8004 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8010 + line = pkg_formatted_field(pkg, "Package");
8011 + strncat(buff ,line, strlen(line));
8014 + line = pkg_formatted_field(pkg, "Version");
8015 + strncat(buff ,line, strlen(line));
8018 + line = pkg_formatted_field(pkg, "Depends");
8019 + strncat(buff ,line, strlen(line));
8022 + line = pkg_formatted_field(pkg, "Recommends");
8023 + strncat(buff ,line, strlen(line));
8026 + line = pkg_formatted_field(pkg, "Suggests");
8027 + strncat(buff ,line, strlen(line));
8030 + line = pkg_formatted_field(pkg, "Provides");
8031 + strncat(buff ,line, strlen(line));
8034 + line = pkg_formatted_field(pkg, "Replaces");
8035 + strncat(buff ,line, strlen(line));
8038 + line = pkg_formatted_field(pkg, "Conflicts");
8039 + strncat(buff ,line, strlen(line));
8042 + line = pkg_formatted_field(pkg, "Status");
8043 + strncat(buff ,line, strlen(line));
8046 + line = pkg_formatted_field(pkg, "Section");
8047 + strncat(buff ,line, strlen(line));
8050 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8051 + strncat(buff ,line, strlen(line));
8054 + line = pkg_formatted_field(pkg, "Architecture");
8055 + strncat(buff ,line, strlen(line));
8058 + line = pkg_formatted_field(pkg, "Maintainer");
8059 + strncat(buff ,line, strlen(line));
8062 + line = pkg_formatted_field(pkg, "MD5sum");
8063 + strncat(buff ,line, strlen(line));
8066 + line = pkg_formatted_field(pkg, "Size");
8067 + strncat(buff ,line, strlen(line));
8070 + line = pkg_formatted_field(pkg, "Filename");
8071 + strncat(buff ,line, strlen(line));
8074 + line = pkg_formatted_field(pkg, "Conffiles");
8075 + strncat(buff ,line, strlen(line));
8078 + line = pkg_formatted_field(pkg, "Source");
8079 + strncat(buff ,line, strlen(line));
8082 + line = pkg_formatted_field(pkg, "Description");
8083 + strncat(buff ,line, strlen(line));
8086 + line = pkg_formatted_field(pkg, "Installed-Time");
8087 + strncat(buff ,line, strlen(line));
8093 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8095 + static size_t LINE_LEN = 128;
8096 + char line_str[LINE_LEN];
8097 + char * temp = (char *)malloc(1);
8099 + int flag_provide_false = 0;
8102 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8103 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8106 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8107 + goto UNKNOWN_FMT_FIELD;
8116 + if (strcasecmp(field, "Architecture") == 0) {
8117 + /* Architecture */
8118 + if (pkg->architecture) {
8119 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8120 + if ( temp == NULL ){
8121 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8125 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8128 + goto UNKNOWN_FMT_FIELD;
8133 + if (strcasecmp(field, "Conffiles") == 0) {
8135 + conffile_list_elt_t *iter;
8137 + if (pkg->conffiles.head == NULL) {
8142 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8143 + if (iter->data->name && iter->data->value) {
8144 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8147 + temp = (char *)realloc(temp,len);
8148 + if ( temp == NULL ){
8149 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8153 + strncpy(temp, "Conffiles:\n", 12);
8154 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8155 + if (iter->data->name && iter->data->value) {
8156 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8157 + strncat(temp, line_str, strlen(line_str));
8160 + } else if (strcasecmp(field, "Conflicts") == 0) {
8163 + if (pkg->conflicts_count) {
8165 + for(i = 0; i < pkg->conflicts_count; i++) {
8166 + len = len + (strlen(pkg->conflicts_str[i])+5);
8168 + temp = (char *)realloc(temp,len);
8169 + if ( temp == NULL ){
8170 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8174 + strncpy(temp, "Conflicts:", 11);
8175 + for(i = 0; i < pkg->conflicts_count; i++) {
8176 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8177 + strncat(temp, line_str, strlen(line_str));
8179 + strncat(temp, "\n", strlen("\n"));
8182 + goto UNKNOWN_FMT_FIELD;
8187 + if (strcasecmp(field, "Depends") == 0) {
8191 + if (pkg->depends_count) {
8193 + for(i = 0; i < pkg->depends_count; i++) {
8194 + len = len + (strlen(pkg->depends_str[i])+4);
8196 + temp = (char *)realloc(temp,len);
8197 + if ( temp == NULL ){
8198 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8202 + strncpy(temp, "Depends:", 10);
8203 + for(i = 0; i < pkg->depends_count; i++) {
8204 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8205 + strncat(temp, line_str, strlen(line_str));
8207 + strncat(temp, "\n", strlen("\n"));
8209 + } else if (strcasecmp(field, "Description") == 0) {
8211 + if (pkg->description) {
8212 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8213 + if ( temp == NULL ){
8214 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8218 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8221 + goto UNKNOWN_FMT_FIELD;
8227 + if (pkg->essential) {
8228 + temp = (char *)realloc(temp,16);
8229 + if ( temp == NULL ){
8230 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8234 + snprintf(temp, (16), "Essential: yes\n");
8241 + if (pkg->filename) {
8242 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8243 + if ( temp == NULL ){
8244 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8248 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8254 + if (strcasecmp(field, "Installed-Size") == 0) {
8255 + /* Installed-Size */
8256 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8257 + if ( temp == NULL ){
8258 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8262 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8263 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8264 + temp = (char *)realloc(temp,29);
8265 + if ( temp == NULL ){
8266 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8270 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8276 + /* Maintainer | MD5sum */
8277 + if (strcasecmp(field, "Maintainer") == 0) {
8279 + if (pkg->maintainer) {
8280 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8281 + if ( temp == NULL ){
8282 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8286 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8288 + } else if (strcasecmp(field, "MD5sum") == 0) {
8290 + if (pkg->md5sum) {
8291 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8292 + if ( temp == NULL ){
8293 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8297 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8300 + goto UNKNOWN_FMT_FIELD;
8306 + if (strcasecmp(field, "Package") == 0) {
8308 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8309 + if ( temp == NULL ){
8310 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8314 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8315 + } else if (strcasecmp(field, "Priority") == 0) {
8317 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8318 + if ( temp == NULL ){
8319 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8323 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8324 + } else if (strcasecmp(field, "Provides") == 0) {
8328 + if (pkg->provides_count) {
8329 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8330 + for ( i=0; i < pkg->provides_count; i++ ){
8331 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8332 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8333 + flag_provide_false = 1;
8336 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8337 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8338 + char provstr[LINE_LEN];
8340 + for(i = 0; i < pkg->provides_count; i++) {
8341 + len = len + (strlen(pkg->provides_str[i])+5);
8343 + temp = (char *)realloc(temp,len);
8344 + if ( temp == NULL ){
8345 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8349 + strncpy(temp, "Provides:", 12);
8350 + for(i = 0; i < pkg->provides_count; i++) {
8351 + if (strlen(pkg->provides_str[i])>0){;
8352 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8353 + strncat(temp, provstr, strlen(provstr));
8356 + strncat(temp, "\n", strlen("\n"));
8360 + goto UNKNOWN_FMT_FIELD;
8367 + /* Replaces | Recommends*/
8368 + if (strcasecmp (field, "Replaces") == 0) {
8369 + if (pkg->replaces_count) {
8371 + for (i = 0; i < pkg->replaces_count; i++) {
8372 + len = len + (strlen(pkg->replaces_str[i])+5);
8374 + temp = (char *)realloc(temp,len);
8375 + if ( temp == NULL ){
8376 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8380 + strncpy(temp, "Replaces:", 12);
8381 + for (i = 0; i < pkg->replaces_count; i++) {
8382 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8383 + strncat(temp, line_str, strlen(line_str));
8385 + strncat(temp, "\n", strlen("\n"));
8387 + } else if (strcasecmp (field, "Recommends") == 0) {
8388 + if (pkg->recommends_count) {
8390 + for(i = 0; i < pkg->recommends_count; i++) {
8391 + len = len + (strlen( pkg->recommends_str[i])+5);
8393 + temp = (char *)realloc(temp,len);
8394 + if ( temp == NULL ){
8395 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8399 + strncpy(temp, "Recommends:", 13);
8400 + for(i = 0; i < pkg->recommends_count; i++) {
8401 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8402 + strncat(temp, line_str, strlen(line_str));
8404 + strncat(temp, "\n", strlen("\n"));
8407 + goto UNKNOWN_FMT_FIELD;
8413 + /* Section | Size | Source | Status | Suggests */
8414 + if (strcasecmp(field, "Section") == 0) {
8416 + if (pkg->section) {
8417 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8418 + if ( temp == NULL ){
8419 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8423 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8425 + } else if (strcasecmp(field, "Size") == 0) {
8428 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8429 + if ( temp == NULL ){
8430 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8434 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8436 + } else if (strcasecmp(field, "Source") == 0) {
8438 + if (pkg->source) {
8439 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8440 + if ( temp == NULL ){
8441 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8445 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8447 + } else if (strcasecmp(field, "Status") == 0) {
8449 + /* Benjamin Pineau note: we should avoid direct usage of
8450 + * strlen(arg) without keeping "arg" for later free()
8452 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8453 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8454 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8456 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8457 + temp = (char *)realloc(temp,sum_of_sizes);
8458 + if ( temp == NULL ){
8459 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8463 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8466 + if(pstat) /* pfstat can be NULL if ENOMEM */
8468 + } else if (strcasecmp(field, "Suggests") == 0) {
8469 + if (pkg->suggests_count) {
8472 + for(i = 0; i < pkg->suggests_count; i++) {
8473 + len = len + (strlen(pkg->suggests_str[i])+5);
8475 + temp = (char *)realloc(temp,len);
8476 + if ( temp == NULL ){
8477 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8481 + strncpy(temp, "Suggests:", 10);
8482 + for(i = 0; i < pkg->suggests_count; i++) {
8483 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8484 + strncat(temp, line_str, strlen(line_str));
8486 + strncat(temp, "\n", strlen("\n"));
8489 + goto UNKNOWN_FMT_FIELD;
8496 + char *version = pkg_version_str_alloc(pkg);
8497 + temp = (char *)realloc(temp,strlen(version)+14);
8498 + if ( temp == NULL ){
8499 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8503 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8508 + goto UNKNOWN_FMT_FIELD;
8511 + if ( strlen(temp)<2 ) {
8516 + UNKNOWN_FMT_FIELD:
8517 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8518 + if ( strlen(temp)<2 ) {
8525 +void pkg_print_info(pkg_t *pkg, FILE *file)
8528 + if (pkg == NULL) {
8532 + buff = pkg_formatted_info(pkg);
8533 + if ( buff == NULL )
8535 + if (strlen(buff)>2){
8536 + fwrite(buff, 1, strlen(buff), file);
8541 +void pkg_print_status(pkg_t * pkg, FILE * file)
8543 + if (pkg == NULL) {
8547 + /* XXX: QUESTION: Do we actually want more fields here? The
8548 + original idea was to save space by installing only what was
8549 + needed for actual computation, (package, version, status,
8550 + essential, conffiles). The assumption is that all other fields
8551 + can be found in th available file.
8553 + But, someone proposed the idea to make it possible to
8554 + reconstruct a .ipk from an installed package, (ie. for beaming
8555 + from one handheld to another). So, maybe we actually want a few
8556 + more fields here, (depends, suggests, etc.), so that that would
8557 + be guaranteed to work even in the absence of more information
8558 + from the available file.
8560 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8561 + the essential info needs to be here for all installed packages
8562 + because they may not appear in the Packages files on various
8563 + feeds. Furthermore, one should be able to install from URL or
8564 + local storage without requiring a Packages file from any feed.
8567 + pkg_print_field(pkg, file, "Package");
8568 + pkg_print_field(pkg, file, "Version");
8569 + pkg_print_field(pkg, file, "Depends");
8570 + pkg_print_field(pkg, file, "Recommends");
8571 + pkg_print_field(pkg, file, "Suggests");
8572 + pkg_print_field(pkg, file, "Provides");
8573 + pkg_print_field(pkg, file, "Replaces");
8574 + pkg_print_field(pkg, file, "Conflicts");
8575 + pkg_print_field(pkg, file, "Status");
8576 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8577 + pkg_print_field(pkg, file, "Architecture");
8578 + pkg_print_field(pkg, file, "Conffiles");
8579 + pkg_print_field(pkg, file, "Installed-Time");
8580 + fputs("\n", file);
8583 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8586 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8587 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8588 + __FUNCTION__, field);
8590 + buff = pkg_formatted_field(pkg, field);
8591 + if (strlen(buff)>2) {
8592 + fprintf(file, "%s", buff);
8600 + * libdpkg - Debian packaging suite library routines
8601 + * vercmp.c - comparison of version numbers
8603 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8605 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8609 + if (pkg->epoch > ref_pkg->epoch) {
8613 + if (pkg->epoch < ref_pkg->epoch) {
8617 + r = verrevcmp(pkg->version, ref_pkg->version);
8622 +#ifdef USE_DEBVERSION
8623 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8628 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8634 +int verrevcmp(const char *val, const char *ref)
8638 + const char *vp, *rp;
8639 + const char *vsep, *rsep;
8641 + if (!val) val= "";
8642 + if (!ref) ref= "";
8644 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8645 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8647 + vc= (val == vp) ? 0 : *val++;
8648 + rc= (ref == rp) ? 0 : *ref++;
8649 + if (!rc && !vc) break;
8650 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8651 + if (rc && !isalpha(rc)) rc += 256;
8652 + if (vc != rc) return vc - rc;
8656 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8657 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8658 + if (vl != rl) return vl - rl;
8662 + vsep = strchr(".-", vc);
8663 + rsep = strchr(".-", rc);
8664 + if (vsep && !rsep) return -1;
8665 + if (!vsep && rsep) return +1;
8667 + if (!*val && !*ref) return 0;
8668 + if (!*val) return -1;
8669 + if (!*ref) return +1;
8673 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8677 + r = pkg_compare_versions(it, ref);
8679 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8683 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8687 + if (strcmp(op, "<<") == 0) {
8691 + if (strcmp(op, ">>") == 0) {
8695 + if (strcmp(op, "=") == 0) {
8699 + fprintf(stderr, "unknown operator: %s", op);
8703 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8707 + if (!a->name || !b->name) {
8708 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8709 + a, a->name, b, b->name);
8713 + namecmp = strcmp(a->name, b->name);
8716 + vercmp = pkg_compare_versions(a, b);
8719 + if (!a->arch_priority || !b->arch_priority) {
8720 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8721 + a, a->arch_priority, b, b->arch_priority);
8724 + if (a->arch_priority > b->arch_priority)
8726 + if (a->arch_priority < b->arch_priority)
8731 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8733 + if (!a->name || !b->name) {
8734 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8735 + a, a->name, b, b->name);
8738 + return strcmp(a->name, b->name);
8742 +char *pkg_version_str_alloc(pkg_t *pkg)
8744 + char *complete_version;
8746 +#ifdef USE_DEBVERSION
8747 + char *revision_str;
8748 + char *familiar_revision_str;
8752 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8754 + epoch_str = strdup("");
8757 +#ifdef USE_DEBVERSION
8758 + if (pkg->revision && strlen(pkg->revision)) {
8759 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8761 + revision_str = strdup("");
8764 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8765 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8767 + familiar_revision_str = strdup("");
8771 +#ifdef USE_DEBVERSION
8772 + sprintf_alloc(&complete_version, "%s%s%s%s",
8773 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8775 + sprintf_alloc(&complete_version, "%s%s",
8776 + epoch_str, pkg->version);
8780 +#ifdef USE_DEBVERSION
8781 + free(revision_str);
8782 + free(familiar_revision_str);
8785 + return complete_version;
8788 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8791 + char *list_file_name = NULL;
8792 + FILE *list_file = NULL;
8794 + char *installed_file_name;
8797 + pkg->installed_files_ref_cnt++;
8799 + if (pkg->installed_files) {
8800 + return pkg->installed_files;
8803 + pkg->installed_files = str_list_alloc();
8804 + if (pkg->installed_files == NULL) {
8805 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8809 + /* For uninstalled packages, get the file list firectly from the package.
8810 + For installed packages, look at the package.list file in the database.
8812 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8813 + if (pkg->local_filename == NULL) {
8814 + return pkg->installed_files;
8816 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8817 + file. In other words, change deb_extract so that it can
8818 + simply return the file list as a char *[] rather than
8819 + insisting on writing in to a FILE * as it does now. */
8820 + list_file = tmpfile();
8821 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8823 + fclose(list_file);
8824 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8825 + __FUNCTION__, pkg->local_filename, strerror(err));
8826 + return pkg->installed_files;
8828 + rewind(list_file);
8830 + sprintf_alloc(&list_file_name, "%s/%s.list",
8831 + pkg->dest->info_dir, pkg->name);
8832 + if (! file_exists(list_file_name)) {
8833 + free(list_file_name);
8834 + return pkg->installed_files;
8837 + list_file = fopen(list_file_name, "r");
8838 + if (list_file == NULL) {
8839 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8840 + list_file_name, strerror(errno));
8841 + free(list_file_name);
8842 + return pkg->installed_files;
8844 + free(list_file_name);
8847 + rootdirlen = strlen( pkg->dest->root_dir );
8851 + line = file_read_line_alloc(list_file);
8852 + if (line == NULL) {
8858 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8859 + if( strncmp( pkg->dest->root_dir,
8862 + if (*file_name == '.') {
8865 + if (*file_name == '/') {
8869 + /* Freed in pkg_free_installed_files */
8870 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8872 + // already contains root_dir as header -> ABSOLUTE
8873 + sprintf_alloc(&installed_file_name, "%s", file_name);
8875 + str_list_append(pkg->installed_files, installed_file_name);
8879 + fclose(list_file);
8881 + return pkg->installed_files;
8884 +/* XXX: CLEANUP: This function and it's counterpart,
8885 + (pkg_get_installed_files), do not match our init/deinit naming
8886 + convention. Nor the alloc/free convention. But, then again, neither
8887 + of these conventions currrently fit the way these two functions
8889 +int pkg_free_installed_files(pkg_t *pkg)
8891 + str_list_elt_t *iter;
8893 + pkg->installed_files_ref_cnt--;
8894 + if (pkg->installed_files_ref_cnt > 0) {
8898 + if (pkg->installed_files) {
8900 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8901 + /* malloced in pkg_get_installed_files */
8902 + free (iter->data);
8903 + iter->data = NULL;
8906 + str_list_deinit(pkg->installed_files);
8909 + pkg->installed_files = NULL;
8914 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8917 + char *list_file_name;
8919 + //I don't think pkg_free_installed_files should be called here. Jamey
8920 + //pkg_free_installed_files(pkg);
8922 + sprintf_alloc(&list_file_name, "%s/%s.list",
8923 + pkg->dest->info_dir, pkg->name);
8924 + if (!conf->noaction) {
8925 + err = unlink(list_file_name);
8926 + free(list_file_name);
8935 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8937 + conffile_list_elt_t *iter;
8938 + conffile_t *conffile;
8940 + if (pkg == NULL) {
8944 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8945 + conffile = iter->data;
8947 + if (strcmp(conffile->name, file_name) == 0) {
8955 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8956 + const char *script, const char *args)
8962 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8963 + maintainer script within a chroot environment. */
8965 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8966 + have scripts in pkg->tmp_unpack_dir. */
8967 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8968 + if (pkg->dest == NULL) {
8969 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8970 + __FUNCTION__, pkg->name);
8973 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8975 + if (pkg->tmp_unpack_dir == NULL) {
8976 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8977 + __FUNCTION__, pkg->name);
8980 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8983 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8984 + if (conf->noaction) return 0;
8986 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8987 + scripts when running with offline_root mode and/or a dest other
8988 + than '/'. I've been playing around with some clever chroot
8989 + tricks and I might come up with something workable. */
8990 + if (conf->offline_root) {
8991 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8994 + setenv("PKG_ROOT",
8995 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8997 + if (! file_exists(path)) {
9002 + if (conf->offline_root) {
9003 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9008 + sprintf_alloc(&cmd, "%s %s", path, args);
9011 + err = xsystem(cmd);
9015 + fprintf(stderr, "%s script returned status %d\n", script, err);
9022 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9026 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9027 + if (pkg_state_want_map[i].value == sw) {
9028 + return strdup(pkg_state_want_map[i].str);
9032 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9033 + __FUNCTION__, sw);
9034 + return strdup("<STATE_WANT_UNKNOWN>");
9037 +pkg_state_want_t pkg_state_want_from_str(char *str)
9041 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9042 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9043 + return pkg_state_want_map[i].value;
9047 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9048 + __FUNCTION__, str);
9049 + return SW_UNKNOWN;
9052 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9055 + int len = 3; /* ok\000 is minimum */
9058 + /* clear the temporary flags before converting to string */
9059 + sf &= SF_NONVOLATILE_FLAGS;
9062 + return strdup("ok");
9065 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9066 + if (sf & pkg_state_flag_map[i].value) {
9067 + len += strlen(pkg_state_flag_map[i].str) + 1;
9070 + str = malloc(len);
9071 + if ( str == NULL ) {
9072 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9076 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9077 + if (sf & pkg_state_flag_map[i].value) {
9078 + strcat(str, pkg_state_flag_map[i].str);
9082 + len = strlen(str);
9083 + str[len-1] = 0; /* squash last comma */
9088 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9093 + if (strcmp(str, "ok") == 0) {
9096 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9097 + const char *sfname = pkg_state_flag_map[i].str;
9098 + int sfname_len = strlen(sfname);
9099 + if (strncmp(str, sfname, sfname_len) == 0) {
9100 + sf |= pkg_state_flag_map[i].value;
9101 + str += sfname_len;
9102 + if (str[0] == ',') {
9113 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9117 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9118 + if (pkg_state_status_map[i].value == ss) {
9119 + return strdup(pkg_state_status_map[i].str);
9123 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9124 + __FUNCTION__, ss);
9125 + return strdup("<STATE_STATUS_UNKNOWN>");
9128 +pkg_state_status_t pkg_state_status_from_str(char *str)
9132 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9133 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9134 + return pkg_state_status_map[i].value;
9138 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9139 + __FUNCTION__, str);
9140 + return SS_NOT_INSTALLED;
9143 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9145 + nv_pair_list_elt_t *l;
9147 + if (!pkg->architecture)
9150 + l = conf->arch_list.head;
9153 + nv_pair_t *nv = l->data;
9154 + if (strcmp(nv->name, pkg->architecture) == 0) {
9155 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9161 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9165 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9167 + nv_pair_list_elt_t *l;
9169 + l = conf->arch_list.head;
9172 + nv_pair_t *nv = l->data;
9173 + if (strcmp(nv->name, archname) == 0) {
9174 + int priority = strtol(nv->value, NULL, 0);
9182 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9185 + hash_table_t *pkg_hash = &conf->pkg_hash;
9186 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9187 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9189 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9190 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9191 + /* update arch_priority for each package */
9192 + for (i = 0; i < available_pkgs->len; i++) {
9193 + pkg_t *pkg = available_pkgs->pkgs[i];
9194 + int arch_priority = 1;
9197 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9198 + if (pkg->architecture)
9199 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9201 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9202 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9203 + pkg->arch_priority = arch_priority;
9206 + for (i = 0; i < available_pkgs->len; i++) {
9207 + pkg_t *pkg = available_pkgs->pkgs[i];
9208 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9209 + /* clear flags and want for any uninstallable package */
9210 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9211 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9212 + pkg->state_want = SW_UNKNOWN;
9213 + pkg->state_flag = 0;
9216 + pkg_vec_free(available_pkgs);
9218 + /* update the file owner data structure */
9219 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9220 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9221 + for (i = 0; i < installed_pkgs->len; i++) {
9222 + pkg_t *pkg = installed_pkgs->pkgs[i];
9223 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9224 + str_list_elt_t *iter;
9225 + if (installed_files == NULL) {
9226 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9229 + for (iter = installed_files->head; iter; iter = iter->next) {
9230 + char *installed_file = iter->data;
9231 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9232 + file_hash_set_file_owner(conf, installed_file, pkg);
9235 + pkg_vec_free(installed_pkgs);
9240 +struct pkg_write_filelist_data {
9241 + ipkg_conf_t *conf;
9246 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9248 + struct pkg_write_filelist_data *data = data_;
9249 + pkg_t *entry = entry_;
9250 + if (entry == data->pkg) {
9251 + fprintf(data->stream, "%s\n", key);
9255 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9257 + struct pkg_write_filelist_data data;
9258 + char *list_file_name = NULL;
9262 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9265 + ipkg_message(conf, IPKG_INFO,
9266 + " creating %s.list file\n", pkg->name);
9267 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9268 + if (!list_file_name) {
9269 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9272 + ipkg_message(conf, IPKG_INFO,
9273 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9274 + data.stream = fopen(list_file_name, "w");
9275 + if (!data.stream) {
9276 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9277 + list_file_name, strerror(errno));
9282 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9283 + fclose(data.stream);
9284 + free(list_file_name);
9289 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9291 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9292 + hash_table_t *pkg_hash = &conf->pkg_hash;
9295 + if (conf->noaction)
9298 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9299 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9300 + for (i = 0; i < installed_pkgs->len; i++) {
9301 + pkg_t *pkg = installed_pkgs->pkgs[i];
9302 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9303 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9304 + err = pkg_write_filelist(conf, pkg);
9306 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9311 Index: busybox-1.8.1/archival/libipkg/pkg_depends.c
9312 ===================================================================
9313 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9314 +++ busybox-1.8.1/archival/libipkg/pkg_depends.c 2007-11-10 17:40:53.376765566 +0100
9316 +/* pkg_depends.c - the itsy package management system
9320 + Copyright (C) 2002 Compaq Computer Corporation
9322 + This program is free software; you can redistribute it and/or
9323 + modify it under the terms of the GNU General Public License as
9324 + published by the Free Software Foundation; either version 2, or (at
9325 + your option) any later version.
9327 + This program is distributed in the hope that it will be useful, but
9328 + WITHOUT ANY WARRANTY; without even the implied warranty of
9329 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9330 + General Public License for more details.
9338 +#include "ipkg_utils.h"
9339 +#include "pkg_hash.h"
9340 +#include "ipkg_message.h"
9341 +#include "pkg_parse.h"
9342 +#include "hash_table.h"
9344 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9345 +static depend_t * depend_init(void);
9346 +static void depend_deinit(depend_t *d);
9347 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9348 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9349 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9351 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9353 + depend_t *depend = (depend_t *)cdata;
9354 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9360 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9362 + depend_t *depend = (depend_t *)cdata;
9364 + pkg_t * temp = pkg_new();
9366 + parseVersion(temp, depend->version);
9367 + comparison = pkg_compare_versions(pkg, temp);
9370 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9371 + __FUNCTION__, pkg->name, pkg->version,
9372 + depend, depend->constraint, depend->version,
9373 + comparison, version_constraints_satisfied(depend, pkg));
9375 + if (version_constraints_satisfied(depend, pkg))
9381 +/* returns ndependences or negative error value */
9382 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9383 + pkg_vec_t *unsatisfied, char *** unresolved)
9385 + pkg_t * satisfier_entry_pkg;
9386 + register int i, j, k, l;
9389 + abstract_pkg_t * ab_pkg;
9392 + * this is a setup to check for redundant/cyclic dependency checks,
9393 + * which are marked at the abstract_pkg level
9395 + if (!(ab_pkg = pkg->parent)) {
9396 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9397 + *unresolved = NULL;
9400 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9401 + *unresolved = NULL;
9404 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9408 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9410 + *unresolved = NULL;
9416 + /* foreach dependency */
9417 + for (i = 0; i < count; i++) {
9418 + compound_depend_t * compound_depend = &pkg->depends[i];
9419 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9421 + satisfier_entry_pkg = NULL;
9423 + if (compound_depend->type == GREEDY_DEPEND) {
9424 + /* foreach possible satisfier */
9425 + for (j = 0; j < compound_depend->possibility_count; j++) {
9426 + /* foreach provided_by, which includes the abstract_pkg itself */
9427 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9428 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9429 + int nposs = ab_provider_vec->len;
9430 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9431 + for (l = 0; l < nposs; l++) {
9432 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9433 + /* if no depends on this one, try the first package that Provides this one */
9434 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9438 + /* cruise this possiblity's pkg_vec looking for an installed version */
9439 + for (k = 0; k < test_vec->len; k++) {
9440 + pkg_t *pkg_scout = test_vec->pkgs[k];
9441 + /* not installed, and not already known about? */
9442 + if ((pkg_scout->state_want != SW_INSTALL)
9443 + && !pkg_scout->parent->dependencies_checked
9444 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9445 + char ** newstuff = NULL;
9447 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9448 + /* check for not-already-installed dependencies */
9449 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9453 + if (newstuff == NULL) {
9455 + for (l = 0; l < rc; l++) {
9456 + pkg_t *p = tmp_vec->pkgs[l];
9457 + if (p->state_want == SW_INSTALL)
9459 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9463 + pkg_vec_free (tmp_vec);
9465 + /* mark this one for installation */
9466 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9467 + pkg_vec_insert(unsatisfied, pkg_scout);
9470 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9481 + /* foreach possible satisfier, look for installed package */
9482 + for (j = 0; j < compound_depend->possibility_count; j++) {
9483 + /* foreach provided_by, which includes the abstract_pkg itself */
9484 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9485 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9486 + pkg_t *satisfying_pkg =
9487 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9488 + pkg_installed_and_constraint_satisfied,
9489 + dependence_to_satisfy, 1);
9490 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9491 + if (satisfying_pkg != NULL) {
9492 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9493 + satisfying_pkg = NULL;
9496 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9497 + if (satisfying_pkg != NULL) {
9503 + /* if nothing installed matches, then look for uninstalled satisfier */
9505 + /* foreach possible satisfier, look for installed package */
9506 + for (j = 0; j < compound_depend->possibility_count; j++) {
9507 + /* foreach provided_by, which includes the abstract_pkg itself */
9508 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9509 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9510 + pkg_t *satisfying_pkg =
9511 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9512 + pkg_constraint_satisfied,
9513 + dependence_to_satisfy, 1);
9514 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9515 + if (satisfying_pkg != NULL) {
9516 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9517 + satisfying_pkg = NULL;
9521 + /* user request overrides package recommendation */
9522 + if (satisfying_pkg != NULL
9523 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9524 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9525 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9526 + pkg->name, satisfying_pkg->name);
9530 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9531 + if (satisfying_pkg != NULL) {
9532 + satisfier_entry_pkg = satisfying_pkg;
9538 + /* we didn't find one, add something to the unsatisfied vector */
9540 + if (!satisfier_entry_pkg) {
9541 + /* failure to meet recommendations is not an error */
9542 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9543 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9545 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9546 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9549 + if (compound_depend->type == SUGGEST) {
9550 + /* just mention it politely */
9551 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9552 + pkg->name, satisfier_entry_pkg->name);
9554 + char ** newstuff = NULL;
9556 + if (satisfier_entry_pkg != pkg &&
9557 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9558 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9559 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9560 + satisfier_entry_pkg,
9563 + the_lost = merge_unresolved(the_lost, newstuff);
9569 + *unresolved = the_lost;
9571 + return unsatisfied->len;
9574 +/*checking for conflicts !in replaces
9575 + If a packages conflicts with another but is also replacing it, I should not consider it a
9577 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9579 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9582 + int replaces_count = pkg->replaces_count;
9583 + abstract_pkg_t **replaces;
9585 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9588 + replaces = pkg->replaces;
9590 + for (i = 0; i < replaces_count; i++) {
9591 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9592 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9601 +/* Abhaya: added support for conflicts */
9602 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9604 + pkg_vec_t * installed_conflicts, * test_vec;
9605 + compound_depend_t * conflicts;
9606 + depend_t ** possible_satisfiers;
9607 + depend_t * possible_satisfier;
9608 + register int i, j, k;
9610 + abstract_pkg_t * ab_pkg;
9611 + pkg_t **pkg_scouts;
9615 + * this is a setup to check for redundant/cyclic dependency checks,
9616 + * which are marked at the abstract_pkg level
9618 + if(!(ab_pkg = pkg->parent)){
9619 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9620 + return (pkg_vec_t *)NULL;
9623 + conflicts = pkg->conflicts;
9625 + return (pkg_vec_t *)NULL;
9627 + installed_conflicts = pkg_vec_alloc();
9629 + count = pkg->conflicts_count;
9633 + /* foreach conflict */
9634 + for(i = 0; i < pkg->conflicts_count; i++){
9636 + possible_satisfiers = conflicts->possibilities;
9638 + /* foreach possible satisfier */
9639 + for(j = 0; j < conflicts->possibility_count; j++){
9640 + possible_satisfier = possible_satisfiers[j];
9641 + if (!possible_satisfier)
9642 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9643 + if (!possible_satisfier->pkg)
9644 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9645 + test_vec = possible_satisfier->pkg->pkgs;
9647 + /* pkg_vec found, it is an actual package conflict
9648 + * cruise this possiblity's pkg_vec looking for an installed version */
9649 + pkg_scouts = test_vec->pkgs;
9650 + for(k = 0; k < test_vec->len; k++){
9651 + pkg_scout = pkg_scouts[k];
9653 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9656 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9657 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9658 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9659 + pkg_vec_insert(installed_conflicts, pkg_scout);
9668 + if (installed_conflicts->len)
9669 + return installed_conflicts;
9670 + pkg_vec_free(installed_conflicts);
9671 + return (pkg_vec_t *)NULL;
9674 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9679 + if(depends->constraint == NONE)
9684 + parseVersion(temp, depends->version);
9686 + comparison = pkg_compare_versions(pkg, temp);
9690 + if((depends->constraint == EARLIER) &&
9693 + else if((depends->constraint == LATER) &&
9696 + else if(comparison == 0)
9698 + else if((depends->constraint == LATER_EQUAL) &&
9699 + (comparison >= 0))
9701 + else if((depends->constraint == EARLIER_EQUAL) &&
9702 + (comparison <= 0))
9708 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9710 + abstract_pkg_t *apkg = depend->pkg;
9711 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9712 + int n_providers = provider_apkgs->len;
9713 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9714 + pkg_vec_t *pkg_vec;
9719 + for (i = 0; i < n_providers; i++) {
9720 + abstract_pkg_t *papkg = apkgs[i];
9721 + pkg_vec = papkg->pkgs;
9723 + n_pkgs = pkg_vec->len;
9724 + for (j = 0; j < n_pkgs; j++) {
9725 + pkg_t *pkg = pkg_vec->pkgs[j];
9726 + if (version_constraints_satisfied(depend, pkg)) {
9735 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9737 + abstract_pkg_t *apkg = depend->pkg;
9738 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9739 + int n_providers = provider_apkgs->len;
9740 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9745 + for (i = 0; i < n_providers; i++) {
9746 + abstract_pkg_t *papkg = apkgs[i];
9747 + pkg_vec_t *pkg_vec = papkg->pkgs;
9749 + n_pkgs = pkg_vec->len;
9750 + for (j = 0; j < n_pkgs; j++) {
9751 + pkg_t *pkg = pkg_vec->pkgs[j];
9752 + if (version_constraints_satisfied(depend, pkg)) {
9753 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9762 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9765 + pkg_t ** pkgs = vec->pkgs;
9767 + for(i = 0; i < vec->len; i++)
9768 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9769 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9770 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9778 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9779 + * the same abstract package and 0 otherwise.
9781 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9783 + abstract_pkg_t **provides = pkg->provides;
9784 + int provides_count = pkg->provides_count;
9785 + abstract_pkg_t **replacee_provides = replacee->provides;
9786 + int replacee_provides_count = replacee->provides_count;
9788 + for (i = 0; i < provides_count; i++) {
9789 + abstract_pkg_t *apkg = provides[i];
9790 + for (j = 0; j < replacee_provides_count; j++) {
9791 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9792 + if (apkg == replacee_apkg)
9801 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9802 + * and 0 otherwise.
9804 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9806 + abstract_pkg_t **provides = pkg->provides;
9807 + int provides_count = pkg->provides_count;
9809 + for (i = 0; i < provides_count; i++) {
9810 + if (provides[i] == providee)
9817 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9820 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9822 + abstract_pkg_t **replaces = pkg->replaces;
9823 + int replaces_count = pkg->replaces_count;
9824 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9825 + int replacee_provides_count = pkg->provides_count; */
9827 + for (i = 0; i < replaces_count; i++) {
9828 + abstract_pkg_t *abstract_replacee = replaces[i];
9829 + for (j = 0; j < replaces_count; j++) {
9830 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9831 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9832 + if (replacee->provides[j] == abstract_replacee)
9841 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9844 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9846 + compound_depend_t *conflicts = pkg->conflicts;
9847 + int conflicts_count = pkg->conflicts_count;
9849 + for (i = 0; i < conflicts_count; i++) {
9850 + int possibility_count = conflicts[i].possibility_count;
9851 + struct depend **possibilities = conflicts[i].possibilities;
9852 + for (j = 0; j < possibility_count; j++) {
9853 + if (possibilities[j]->pkg == conflictee) {
9862 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9863 + * conflictee's provides and 0 otherwise.
9865 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9867 + compound_depend_t *conflicts = pkg->conflicts;
9868 + int conflicts_count = pkg->conflicts_count;
9869 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9870 + int conflictee_provides_count = conflictee->provides_count;
9872 + int possibility_count;
9873 + struct depend **possibilities;
9874 + abstract_pkg_t *possibility ;
9876 + for (i = 0; i < conflicts_count; i++) {
9877 + possibility_count = conflicts[i].possibility_count;
9878 + possibilities = conflicts[i].possibilities;
9879 + for (j = 0; j < possibility_count; j++) {
9880 + possibility = possibilities[j]->pkg;
9881 + for (k = 0; k < conflictee_provides_count; k++) {
9882 + if (possibility == conflictee_provides[k]) {
9891 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9893 + int oldlen = 0, newlen = 0;
9895 + register int i, j;
9900 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9901 + while(newstuff && newstuff[newlen]) newlen++;
9903 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9904 + if (result == NULL) {
9905 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9909 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9910 + *(result + i) = *(newstuff + j);
9912 + *(result + i) = NULL;
9918 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9919 + * this is null terminated, no count is carried around
9921 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9925 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9928 + while(the_lost && the_lost[count]) count++;
9930 + count++; /* need one to hold the null */
9931 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9932 + if (resized == NULL) {
9933 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9936 + resized[count - 1] = strdup(depend_str);
9937 + resized[count] = NULL;
9942 +void printDepends(pkg_t * pkg)
9944 + register int i, j;
9945 + compound_depend_t * depend;
9948 + count = pkg->pre_depends_count + pkg->depends_count;
9950 + depend = pkg->depends;
9952 + fprintf(stderr, "Depends pointer is NULL\n");
9955 + for(i = 0; i < count; i++){
9956 + fprintf(stderr, "%s has %d possibilities:\n",
9957 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9958 + depend->possibility_count);
9959 + for(j = 0; j < depend->possibility_count; j++)
9960 + fprintf(stderr, "\t%s version %s (%d)\n",
9961 + depend->possibilities[j]->pkg->name,
9962 + depend->possibilities[j]->version,
9963 + depend->possibilities[j]->constraint);
9968 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9970 + register int i, j;
9972 + /* every pkg provides itself */
9973 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9975 + if (!pkg->provides_count)
9978 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9979 + if (pkg->provides == NULL) {
9980 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9983 + pkg->provides[0] = ab_pkg;
9985 + // if (strcmp(ab_pkg->name, pkg->name))
9986 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9988 + for(i = 0; i < pkg->provides_count; i++){
9989 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9991 + pkg->provides[i+1] = provided_abpkg;
9994 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9999 +/* Abhaya: added conflicts support */
10000 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10003 + compound_depend_t * conflicts;
10005 + if (!pkg->conflicts_count)
10008 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10009 + pkg->conflicts_count);
10010 + if (conflicts == NULL) {
10011 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10014 + for (i = 0; i < pkg->conflicts_count; i++) {
10015 + conflicts->type = CONFLICTS;
10016 + parseDepends(conflicts, hash,
10017 + pkg->conflicts_str[i]);
10019 + for (j = 0; j < conflicts->possibility_count; j++) {
10020 + depend_t *possibility = conflicts->possibilities[j];
10021 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10022 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10030 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10032 + register int i, j;
10034 + if (!pkg->replaces_count)
10037 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10038 + if (pkg->replaces == NULL) {
10039 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10043 + // if (strcmp(ab_pkg->name, pkg->name))
10044 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10046 + for(i = 0; i < pkg->replaces_count; i++){
10047 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10049 + pkg->replaces[i] = old_abpkg;
10052 + if (!old_abpkg->replaced_by)
10053 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10054 + if ( old_abpkg->replaced_by == NULL ){
10057 + /* if a package pkg both replaces and conflicts old_abpkg,
10058 + * then add it to the replaced_by vector so that old_abpkg
10059 + * will be upgraded to ab_pkg automatically */
10060 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10061 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10066 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10070 + compound_depend_t * depends;
10072 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10075 + if (0 && pkg->pre_depends_count)
10076 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10077 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10078 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10079 + if (depends == NULL) {
10080 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10085 + for(i = 0; i < pkg->pre_depends_count; i++){
10086 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10087 + if (0 && pkg->pre_depends_count)
10088 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10089 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10090 + depends->type = PREDEPEND;
10094 + for(i = 0; i < pkg->recommends_count; i++){
10095 + parseDepends(depends, hash, pkg->recommends_str[i]);
10096 + if (0 && pkg->recommends_count)
10097 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10098 + pkg->recommends_str[i], depends, depends->possibility_count);
10099 + depends->type = RECOMMEND;
10103 + for(i = 0; i < pkg->suggests_count; i++){
10104 + parseDepends(depends, hash, pkg->suggests_str[i]);
10105 + if (0 && pkg->suggests_count)
10106 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10107 + pkg->suggests_str[i], depends, depends->possibility_count);
10108 + depends->type = SUGGEST;
10112 + for(i = 0; i < pkg->depends_count; i++){
10113 + parseDepends(depends, hash, pkg->depends_str[i]);
10114 + if (0 && pkg->depends_count)
10115 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10116 + pkg->depends_str[i], depends, depends->possibility_count);
10123 + * pkg_depend_string: returns the depends string specified by index.
10124 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10125 + * [0,npredepends) -> returns pre_depends_str[index]
10126 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10127 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10128 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10130 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10132 + if (pkg_index < pkg->pre_depends_count) {
10133 + return pkg->pre_depends_str[pkg_index];
10135 + pkg_index -= pkg->pre_depends_count;
10137 + if (pkg_index < pkg->recommends_count) {
10138 + return pkg->recommends_str[pkg_index];
10140 + pkg_index -= pkg->recommends_count;
10142 + if (pkg_index < pkg->suggests_count) {
10143 + return pkg->suggests_str[pkg_index];
10145 + pkg_index -= pkg->suggests_count;
10147 + if (pkg_index < pkg->depends_count) {
10148 + return pkg->depends_str[pkg_index];
10150 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10154 +void freeDepends(pkg_t *pkg)
10158 + if (pkg == NULL || pkg->depends == NULL) {
10162 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10163 + for (i=0; i < pkg->depends->possibility_count; i++) {
10164 + depend_deinit(pkg->depends->possibilities[i]);
10166 + free(pkg->depends->possibilities);
10167 + free(pkg->depends);
10168 + pkg->depends = NULL;
10171 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10173 + compound_depend_t * depends;
10174 + int count, othercount;
10175 + register int i, j;
10176 + abstract_pkg_t * ab_depend;
10177 + abstract_pkg_t ** temp;
10179 + count = pkg->pre_depends_count + pkg->depends_count;
10180 + depends = pkg->depends;
10182 + if (0 && pkg->pre_depends_count)
10183 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10184 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10185 + for (i = 0; i < count; i++) {
10186 + if (0 && pkg->pre_depends_count)
10187 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10188 + for (j = 0; j < depends->possibility_count; j++){
10189 + ab_depend = depends->possibilities[j]->pkg;
10190 + if(!ab_depend->depended_upon_by)
10191 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10193 + temp = ab_depend->depended_upon_by;
10201 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10202 + (othercount + 1) * sizeof(abstract_pkg_t *));
10203 + /* the array may have moved */
10204 + temp = ab_depend->depended_upon_by + othercount;
10211 +static depend_t * depend_init(void)
10213 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10215 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10218 + d->constraint = NONE;
10219 + d->version = NULL;
10225 +static void depend_deinit(depend_t *d)
10230 +static int parseDepends(compound_depend_t *compound_depend,
10231 + hash_table_t * hash, char * depend_str)
10233 + char * pkg_name, buffer[2048];
10234 + int num_of_ors = 0;
10236 + register char * src, * dest;
10237 + depend_t ** possibilities;
10239 + /* first count the number of ored possibilities for satisfying dependency */
10240 + src = depend_str;
10242 + if(*src++ == '|')
10245 + compound_depend->type = DEPEND;
10247 + compound_depend->possibility_count = num_of_ors + 1;
10248 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10249 + if (!possibilities)
10251 + compound_depend->possibilities = possibilities;
10253 + src = depend_str;
10254 + for(i = 0; i < num_of_ors + 1; i++){
10255 + possibilities[i] = depend_init();
10256 + if (!possibilities[i])
10258 + /* gobble up just the name first */
10261 + !isspace(*src) &&
10265 + *dest++ = *src++;
10267 + pkg_name = trim_alloc(buffer);
10268 + if (pkg_name == NULL )
10271 + /* now look at possible version info */
10273 + /* skip to next chars */
10274 + if(isspace(*src))
10275 + while(*src && isspace(*src)) src++;
10277 + /* extract constraint and version */
10280 + if(!strncmp(src, "<<", 2)){
10281 + possibilities[i]->constraint = EARLIER;
10284 + else if(!strncmp(src, "<=", 2)){
10285 + possibilities[i]->constraint = EARLIER_EQUAL;
10288 + else if(!strncmp(src, ">=", 2)){
10289 + possibilities[i]->constraint = LATER_EQUAL;
10292 + else if(!strncmp(src, ">>", 2)){
10293 + possibilities[i]->constraint = LATER;
10296 + else if(!strncmp(src, "=", 1)){
10297 + possibilities[i]->constraint = EQUAL;
10300 + /* should these be here to support deprecated designations; dpkg does */
10301 + else if(!strncmp(src, "<", 1)){
10302 + possibilities[i]->constraint = EARLIER_EQUAL;
10305 + else if(!strncmp(src, ">", 1)){
10306 + possibilities[i]->constraint = LATER_EQUAL;
10310 + /* now we have any constraint, pass space to version string */
10311 + while(isspace(*src)) src++;
10313 + /* this would be the version string */
10315 + while(*src && *src != ')')
10316 + *dest++ = *src++;
10319 + possibilities[i]->version = trim_alloc(buffer);
10320 + /* fprintf(stderr, "let's print the depends version string:");
10321 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10322 + if (possibilities[i]->version == NULL )
10327 + /* hook up the dependency to its abstract pkg */
10328 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10332 + /* now get past the ) and any possible | chars */
10334 + (isspace(*src) ||
10340 + compound_depend->type = GREEDY_DEPEND;
10347 Index: busybox-1.8.1/archival/libipkg/pkg_depends.h
10348 ===================================================================
10349 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10350 +++ busybox-1.8.1/archival/libipkg/pkg_depends.h 2007-11-10 17:40:53.376765566 +0100
10352 +/* pkg_depends.h - the itsy package management system
10356 + Copyright (C) 2002 Compaq Computer Corporation
10358 + This program is free software; you can redistribute it and/or
10359 + modify it under the terms of the GNU General Public License as
10360 + published by the Free Software Foundation; either version 2, or (at
10361 + your option) any later version.
10363 + This program is distributed in the hope that it will be useful, but
10364 + WITHOUT ANY WARRANTY; without even the implied warranty of
10365 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10366 + General Public License for more details.
10369 +#ifndef PKG_DEPENDS_H
10370 +#define PKG_DEPENDS_H
10373 +#include "pkg_hash.h"
10375 +enum depend_type {
10383 +typedef enum depend_type depend_type_t;
10385 +enum version_constraint {
10393 +typedef enum version_constraint version_constraint_t;
10396 + version_constraint_t constraint;
10398 + abstract_pkg_t * pkg;
10400 +typedef struct depend depend_t;
10402 +struct compound_depend{
10403 + depend_type_t type;
10404 + int possibility_count;
10405 + struct depend ** possibilities;
10407 +typedef struct compound_depend compound_depend_t;
10409 +#include "hash_table.h"
10411 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10412 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10413 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10414 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10417 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10418 + * the same abstract package and 0 otherwise.
10420 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10423 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10426 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10429 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10432 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10435 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10438 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10441 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10444 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10446 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10447 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10448 +void freeDepends(pkg_t *pkg);
10449 +void printDepends(pkg_t * pkg);
10450 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10451 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10452 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10453 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10454 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10457 Index: busybox-1.8.1/archival/libipkg/pkg_dest.c
10458 ===================================================================
10459 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10460 +++ busybox-1.8.1/archival/libipkg/pkg_dest.c 2007-11-10 17:40:53.376765566 +0100
10462 +/* pkg_dest.c - the itsy package management system
10466 + Copyright (C) 2001 University of Southern California
10468 + This program is free software; you can redistribute it and/or
10469 + modify it under the terms of the GNU General Public License as
10470 + published by the Free Software Foundation; either version 2, or (at
10471 + your option) any later version.
10473 + This program is distributed in the hope that it will be useful, but
10474 + WITHOUT ANY WARRANTY; without even the implied warranty of
10475 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10476 + General Public License for more details.
10481 +#include "pkg_dest.h"
10482 +#include "file_util.h"
10483 +#include "str_util.h"
10484 +#include "sprintf_alloc.h"
10486 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10488 + dest->name = strdup(name);
10490 + /* Guarantee that dest->root_dir ends with a '/' */
10491 + if (str_ends_with(root_dir, "/")) {
10492 + dest->root_dir = strdup(root_dir);
10494 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10496 + file_mkdir_hier(dest->root_dir, 0755);
10498 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10499 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10500 + file_mkdir_hier(dest->ipkg_dir, 0755);
10502 + if (str_starts_with (lists_dir, "/"))
10503 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10505 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10507 + file_mkdir_hier(dest->lists_dir, 0755);
10509 + sprintf_alloc(&dest->info_dir, "%s/%s",
10510 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10511 + file_mkdir_hier(dest->info_dir, 0755);
10513 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10514 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10516 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10517 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10519 + dest->status_file = NULL;
10524 +void pkg_dest_deinit(pkg_dest_t *dest)
10526 + free(dest->name);
10527 + dest->name = NULL;
10529 + free(dest->root_dir);
10530 + dest->root_dir = NULL;
10532 + free(dest->ipkg_dir);
10533 + dest->ipkg_dir = NULL;
10535 + free(dest->lists_dir);
10536 + dest->lists_dir = NULL;
10538 + free(dest->info_dir);
10539 + dest->info_dir = NULL;
10541 + free(dest->status_file_name);
10542 + dest->status_file_name = NULL;
10544 + free(dest->status_file_tmp_name);
10545 + dest->status_file_tmp_name = NULL;
10547 + if (dest->status_file) {
10548 + fclose(dest->status_file);
10550 + dest->status_file = NULL;
10552 + dest->root_dir = NULL;
10554 Index: busybox-1.8.1/archival/libipkg/pkg_dest.h
10555 ===================================================================
10556 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10557 +++ busybox-1.8.1/archival/libipkg/pkg_dest.h 2007-11-10 17:40:53.380765796 +0100
10559 +/* pkg_dest.h - the itsy package management system
10563 + Copyright (C) 2001 University of Southern California
10565 + This program is free software; you can redistribute it and/or
10566 + modify it under the terms of the GNU General Public License as
10567 + published by the Free Software Foundation; either version 2, or (at
10568 + your option) any later version.
10570 + This program is distributed in the hope that it will be useful, but
10571 + WITHOUT ANY WARRANTY; without even the implied warranty of
10572 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10573 + General Public License for more details.
10576 +#ifndef PKG_DEST_H
10577 +#define PKG_DEST_H
10579 +typedef struct pkg_dest pkg_dest_t;
10587 + char *status_file_name;
10588 + char *status_file_tmp_name;
10589 + FILE *status_file;
10592 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10593 +void pkg_dest_deinit(pkg_dest_t *dest);
10597 Index: busybox-1.8.1/archival/libipkg/pkg_dest_list.c
10598 ===================================================================
10599 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10600 +++ busybox-1.8.1/archival/libipkg/pkg_dest_list.c 2007-11-10 17:40:53.380765796 +0100
10602 +/* pkg_dest_list.c - the itsy package management system
10606 + Copyright (C) 2001 University of Southern California
10608 + This program is free software; you can redistribute it and/or
10609 + modify it under the terms of the GNU General Public License as
10610 + published by the Free Software Foundation; either version 2, or (at
10611 + your option) any later version.
10613 + This program is distributed in the hope that it will be useful, but
10614 + WITHOUT ANY WARRANTY; without even the implied warranty of
10615 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10616 + General Public License for more details.
10621 +#include "pkg_dest.h"
10622 +#include "void_list.h"
10623 +#include "pkg_dest_list.h"
10625 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10627 + return void_list_elt_init((void_list_elt_t *) elt, data);
10630 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10632 + void_list_elt_deinit((void_list_elt_t *) elt);
10635 +int pkg_dest_list_init(pkg_dest_list_t *list)
10637 + return void_list_init((void_list_t *) list);
10640 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10642 + pkg_dest_list_elt_t *iter;
10643 + pkg_dest_t *pkg_dest;
10645 + for (iter = list->head; iter; iter = iter->next) {
10646 + pkg_dest = iter->data;
10647 + pkg_dest_deinit(pkg_dest);
10649 + /* malloced in pkg_dest_list_append */
10651 + iter->data = NULL;
10653 + void_list_deinit((void_list_t *) list);
10656 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10657 + const char *root_dir,const char *lists_dir)
10660 + pkg_dest_t *pkg_dest;
10662 + /* freed in plg_dest_list_deinit */
10663 + pkg_dest = malloc(sizeof(pkg_dest_t));
10664 + if (pkg_dest == NULL) {
10665 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10669 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10670 + err = void_list_append((void_list_t *) list, pkg_dest);
10678 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10680 + return void_list_push((void_list_t *) list, data);
10683 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10685 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10687 Index: busybox-1.8.1/archival/libipkg/pkg_dest_list.h
10688 ===================================================================
10689 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10690 +++ busybox-1.8.1/archival/libipkg/pkg_dest_list.h 2007-11-10 17:40:53.380765796 +0100
10692 +/* pkg_dest_list.h - the itsy package management system
10696 + Copyright (C) 2001 University of Southern California
10698 + This program is free software; you can redistribute it and/or
10699 + modify it under the terms of the GNU General Public License as
10700 + published by the Free Software Foundation; either version 2, or (at
10701 + your option) any later version.
10703 + This program is distributed in the hope that it will be useful, but
10704 + WITHOUT ANY WARRANTY; without even the implied warranty of
10705 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10706 + General Public License for more details.
10709 +#ifndef PKG_DEST_LIST_H
10710 +#define PKG_DEST_LIST_H
10712 +#include "pkg_dest.h"
10714 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10715 +struct pkg_dest_list_elt
10717 + pkg_dest_list_elt_t *next;
10718 + pkg_dest_t *data;
10721 +typedef struct pkg_dest_list pkg_dest_list_t;
10722 +struct pkg_dest_list
10724 + pkg_dest_list_elt_t pre_head;
10725 + pkg_dest_list_elt_t *head;
10726 + pkg_dest_list_elt_t *tail;
10729 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10730 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10732 +int pkg_dest_list_init(pkg_dest_list_t *list);
10733 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10735 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10736 + const char *root_dir,const char* lists_dir);
10737 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10738 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10742 Index: busybox-1.8.1/archival/libipkg/pkg_extract.c
10743 ===================================================================
10744 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10745 +++ busybox-1.8.1/archival/libipkg/pkg_extract.c 2007-11-10 17:40:53.380765796 +0100
10747 +/* pkg_extract.c - the itsy package management system
10751 + Copyright (C) 2001 University of Southern California
10753 + This program is free software; you can redistribute it and/or
10754 + modify it under the terms of the GNU General Public License as
10755 + published by the Free Software Foundation; either version 2, or (at
10756 + your option) any later version.
10758 + This program is distributed in the hope that it will be useful, but
10759 + WITHOUT ANY WARRANTY; without even the implied warranty of
10760 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10761 + General Public License for more details.
10765 +#include <errno.h>
10766 +#include <fcntl.h>
10767 +#include <stdio.h>
10769 +#include "pkg_extract.h"
10771 +#include "libbb.h"
10772 +#include "file_util.h"
10773 +#include "sprintf_alloc.h"
10774 +#include "unarchive.h"
10776 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10777 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10778 +#define IPKG_CONTROL_FILE "control"
10780 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10782 + archive_handle_t *archive;
10785 + sprintf_alloc(&path, "%s/", dir);
10786 + archive = init_handle();
10787 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10788 + archive->filter = filter_accept_list;
10789 + llist_add_to(&(archive->accept), (char *)filename);
10790 + archive->buffer = path;
10791 + archive->action_data = data_extract_all_prefix;
10792 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10793 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10794 + close(archive->src_fd);
10795 + free(archive->accept);
10800 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10802 + unsigned int size = strlen(archive->file_header->name) + 2;
10804 + if (archive->buffer == NULL) {
10805 + archive->buffer = xmalloc(size);
10806 + strcpy(archive->buffer, archive->file_header->name);
10808 + size += strlen(archive->buffer);
10809 + archive->buffer = xrealloc(archive->buffer, size);
10810 + strcat(archive->buffer, archive->file_header->name);
10812 + strcat(archive->buffer, "\n");
10813 + data_skip(archive);
10816 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10818 + archive_handle_t *archive;
10821 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10822 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10823 + archive = init_handle();
10824 + archive->src_fd = xopen(name, O_RDONLY);
10825 + archive->filter = filter_accept_list;
10826 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10827 + archive->action_data = data_extract_to_buffer;
10828 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10829 + close(archive->src_fd);
10830 + fputs(archive->buffer, stream);
10831 + free(archive->buffer);
10832 + free(archive->accept);
10839 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10841 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10844 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10846 + archive_handle_t *archive;
10850 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10851 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10852 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10853 + archive = init_handle();
10854 + archive->src_fd = xopen(name, O_RDONLY);
10855 + archive->filter = filter_accept_all;
10856 + archive->buffer = path;
10857 + archive->action_data = data_extract_all_prefix;
10858 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10859 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10860 + close(archive->src_fd);
10868 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10870 + archive_handle_t *archive;
10874 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10875 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10876 + sprintf_alloc(&path, "%s/", dir);
10877 + archive = init_handle();
10878 + archive->src_fd = xopen(name, O_RDONLY);
10879 + archive->filter = filter_accept_all;
10880 + archive->buffer = path;
10881 + archive->action_data = data_extract_all_prefix;
10882 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10883 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10884 + close(archive->src_fd);
10892 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10895 + char *line, *data_file;
10899 + file = fopen(file_name, "w");
10900 + if (file == NULL) {
10901 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10902 + __FUNCTION__, file_name);
10907 + if (pkg->installed_files) {
10908 + str_list_elt_t *elt;
10909 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10910 + fprintf(file, "%s\n", elt->data);
10913 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10920 + /* Fixup data file names by removing the initial '.' */
10923 + line = file_read_line_alloc(tmp);
10924 + if (line == NULL) {
10928 + data_file = line;
10929 + if (*data_file == '.') {
10933 + if (*data_file != '/') {
10934 + fputs("/", file);
10937 + /* I have no idea why, but this is what dpkg does */
10938 + if (strcmp(data_file, "/\n") == 0) {
10939 + fputs("/.\n", file);
10941 + fputs(data_file, file);
10951 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10953 + archive_handle_t *archive;
10956 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10957 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10958 + archive = init_handle();
10959 + archive->src_fd = xopen(name, O_RDONLY);
10960 + archive->filter = filter_accept_all;
10961 + archive->action_data = data_extract_file_name_to_buffer;
10962 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10963 + close(archive->src_fd);
10964 + fputs(archive->buffer, file);
10965 + free(archive->buffer);
10971 Index: busybox-1.8.1/archival/libipkg/pkg_extract.h
10972 ===================================================================
10973 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10974 +++ busybox-1.8.1/archival/libipkg/pkg_extract.h 2007-11-10 17:40:53.380765796 +0100
10976 +/* pkg_extract.c - the itsy package management system
10980 + Copyright (C) 2001 University of Southern California
10982 + This program is free software; you can redistribute it and/or
10983 + modify it under the terms of the GNU General Public License as
10984 + published by the Free Software Foundation; either version 2, or (at
10985 + your option) any later version.
10987 + This program is distributed in the hope that it will be useful, but
10988 + WITHOUT ANY WARRANTY; without even the implied warranty of
10989 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10990 + General Public License for more details.
10993 +#ifndef PKG_EXTRACT_H
10994 +#define PKG_EXTRACT_H
10998 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10999 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11000 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11002 + const char *prefix);
11003 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11004 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11005 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11008 Index: busybox-1.8.1/archival/libipkg/pkg.h
11009 ===================================================================
11010 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11011 +++ busybox-1.8.1/archival/libipkg/pkg.h 2007-11-10 17:40:53.384766022 +0100
11013 +/* pkg.h - the itsy package management system
11017 + Copyright (C) 2001 University of Southern California
11019 + This program is free software; you can redistribute it and/or
11020 + modify it under the terms of the GNU General Public License as
11021 + published by the Free Software Foundation; either version 2, or (at
11022 + your option) any later version.
11024 + This program is distributed in the hope that it will be useful, but
11025 + WITHOUT ANY WARRANTY; without even the implied warranty of
11026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11027 + General Public License for more details.
11033 +#include <sys/types.h>
11034 +#include <sys/stat.h>
11035 +#include <unistd.h>
11037 +#include "pkg_vec.h"
11038 +#include "str_list.h"
11039 +#include "pkg_src.h"
11040 +#include "pkg_dest.h"
11041 +#include "ipkg_conf.h"
11042 +#include "conffile_list.h"
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.8.1/archival/libipkg/pkg_hash.c
11243 ===================================================================
11244 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11245 +++ busybox-1.8.1/archival/libipkg/pkg_hash.c 2007-11-10 17:40:53.388766251 +0100
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.8.1/archival/libipkg/pkg_hash.h
11864 ===================================================================
11865 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11866 +++ busybox-1.8.1/archival/libipkg/pkg_hash.h 2007-11-10 17:40:53.388766251 +0100
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.8.1/archival/libipkg/pkg_parse.c
11930 ===================================================================
11931 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11932 +++ busybox-1.8.1/archival/libipkg/pkg_parse.c 2007-11-10 17:40:53.388766251 +0100
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.8.1/archival/libipkg/pkg_parse.h
12301 ===================================================================
12302 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12303 +++ busybox-1.8.1/archival/libipkg/pkg_parse.h 2007-11-10 17:40:53.392766477 +0100
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.8.1/archival/libipkg/pkg_src.c
12337 ===================================================================
12338 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12339 +++ busybox-1.8.1/archival/libipkg/pkg_src.c 2007-11-10 17:40:53.392766477 +0100
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.8.1/archival/libipkg/pkg_src.h
12385 ===================================================================
12386 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12387 +++ busybox-1.8.1/archival/libipkg/pkg_src.h 2007-11-10 17:40:53.392766477 +0100
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.8.1/archival/libipkg/pkg_src_list.c
12424 ===================================================================
12425 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12426 +++ busybox-1.8.1/archival/libipkg/pkg_src_list.c 2007-11-10 17:40:53.392766477 +0100
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.8.1/archival/libipkg/pkg_src_list.h
12504 ===================================================================
12505 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12506 +++ busybox-1.8.1/archival/libipkg/pkg_src_list.h 2007-11-10 17:40:53.396766706 +0100
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.8.1/archival/libipkg/pkg_vec.c
12566 ===================================================================
12567 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12568 +++ busybox-1.8.1/archival/libipkg/pkg_vec.c 2007-11-10 17:40:53.396766706 +0100
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.8.1/archival/libipkg/pkg_vec.h
12801 ===================================================================
12802 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12803 +++ busybox-1.8.1/archival/libipkg/pkg_vec.h 2007-11-10 17:40:53.396766706 +0100
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.8.1/archival/libipkg/sprintf_alloc.h
12870 ===================================================================
12871 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12872 +++ busybox-1.8.1/archival/libipkg/sprintf_alloc.h 2007-11-10 17:40:53.396766706 +0100
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.8.1/archival/libipkg/str_list.c
12900 ===================================================================
12901 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12902 +++ busybox-1.8.1/archival/libipkg/str_list.c 2007-11-10 17:40:53.396766706 +0100
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.8.1/archival/libipkg/str_list.h
12981 ===================================================================
12982 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12983 +++ busybox-1.8.1/archival/libipkg/str_list.h 2007-11-10 17:40:53.400766935 +0100
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.8.1/archival/libipkg/str_util.c
13037 ===================================================================
13038 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13039 +++ busybox-1.8.1/archival/libipkg/str_util.c 2007-11-10 17:40:53.400766935 +0100
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_toupper(char *str)
13092 + *str = toupper(*str);
13099 +char *str_dup_safe(const char *str)
13101 + return str ? strdup(str) : NULL;
13104 Index: busybox-1.8.1/archival/libipkg/str_util.h
13105 ===================================================================
13106 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13107 +++ busybox-1.8.1/archival/libipkg/str_util.h 2007-11-10 17:40:53.400766935 +0100
13109 +/* str_utils.h - the itsy package management system
13113 + Copyright (C) 2001 University of Southern California
13115 + This program is free software; you can redistribute it and/or
13116 + modify it under the terms of the GNU General Public License as
13117 + published by the Free Software Foundation; either version 2, or (at
13118 + your option) any later version.
13120 + This program is distributed in the hope that it will be useful, but
13121 + WITHOUT ANY WARRANTY; without even the implied warranty of
13122 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13123 + General Public License for more details.
13126 +#ifndef STR_UTILS_H
13127 +#define STR_UTILS_H
13129 +int str_starts_with(const char *str, const char *prefix);
13130 +int str_ends_with(const char *str, const char *suffix);
13131 +int str_chomp(char *str);
13132 +int str_toupper(char *str);
13133 +char *str_dup_safe(const char *str);
13136 Index: busybox-1.8.1/archival/libipkg/user.c
13137 ===================================================================
13138 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13139 +++ busybox-1.8.1/archival/libipkg/user.c 2007-11-10 17:40:53.400766935 +0100
13141 +/* user.c - the itsy package management system
13145 + Copyright (C) 2002 Hewlett Packard Company
13146 + Copyright (C) 2001 University of Southern California
13148 + This program is free software; you can redistribute it and/or
13149 + modify it under the terms of the GNU General Public License as
13150 + published by the Free Software Foundation; either version 2, or (at
13151 + your option) any later version.
13153 + This program is distributed in the hope that it will be useful, but
13154 + WITHOUT ANY WARRANTY; without even the implied warranty of
13155 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13156 + General Public License for more details.
13159 +#include <stdio.h>
13160 +#include <stdarg.h>
13161 +#include "file_util.h"
13162 +#include "str_util.h"
13164 +#include "libipkg.h"
13169 +static char *question = NULL;
13170 +static int question_len = 255;
13172 +char *get_user_response(const char *format, ...)
13174 + int len = question_len;
13177 + va_start(ap, format);
13180 + vprintf(format, ap);
13182 + response = file_read_line_alloc(stdin);
13183 + } while (response == NULL);
13186 + if (question == NULL || len > question_len) {
13187 + question = realloc(question, len + 1);
13188 + question_len = len;
13190 + len = vsnprintf(question,question_len,format,ap);
13191 + } while (len > question_len);
13192 + response = strdup(ipkg_cb_response(question));
13194 + str_chomp(response);
13195 + str_tolower(response);
13199 Index: busybox-1.8.1/archival/libipkg/user.h
13200 ===================================================================
13201 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13202 +++ busybox-1.8.1/archival/libipkg/user.h 2007-11-10 17:40:53.400766935 +0100
13204 +/* user.c - the itsy package management system
13208 + Copyright (C) 2002 Hewlett Packard Company
13209 + Copyright (C) 2001 University of Southern California
13211 + This program is free software; you can redistribute it and/or
13212 + modify it under the terms of the GNU General Public License as
13213 + published by the Free Software Foundation; either version 2, or (at
13214 + your option) any later version.
13216 + This program is distributed in the hope that it will be useful, but
13217 + WITHOUT ANY WARRANTY; without even the implied warranty of
13218 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13219 + General Public License for more details.
13222 +#include <stdio.h>
13223 +#include <stdarg.h>
13225 +char *get_user_response(const char *format, ...);
13227 Index: busybox-1.8.1/archival/libipkg/void_list.c
13228 ===================================================================
13229 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13230 +++ busybox-1.8.1/archival/libipkg/void_list.c 2007-11-10 17:40:53.404767161 +0100
13232 +/* void_list.c - the itsy package management system
13236 + Copyright (C) 2001 University of Southern California
13238 + This program is free software; you can redistribute it and/or
13239 + modify it under the terms of the GNU General Public License as
13240 + published by the Free Software Foundation; either version 2, or (at
13241 + your option) any later version.
13243 + This program is distributed in the hope that it will be useful, but
13244 + WITHOUT ANY WARRANTY; without even the implied warranty of
13245 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13246 + General Public License for more details.
13250 +#include <errno.h>
13252 +#include "void_list.h"
13254 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13256 + elt->next = NULL;
13257 + elt->data = data;
13262 +void void_list_elt_deinit(void_list_elt_t *elt)
13264 + void_list_elt_init(elt, NULL);
13267 +int void_list_init(void_list_t *list)
13269 + void_list_elt_init(&list->pre_head, NULL);
13270 + list->head = NULL;
13271 + list->pre_head.next = list->head;
13272 + list->tail = NULL;
13277 +void void_list_deinit(void_list_t *list)
13279 + void_list_elt_t *elt;
13281 + while (list->head) {
13282 + elt = void_list_pop(list);
13283 + void_list_elt_deinit(elt);
13284 + /* malloced in void_list_append */
13289 +int void_list_append(void_list_t *list, void *data)
13291 + void_list_elt_t *elt;
13293 + /* freed in void_list_deinit */
13294 + elt = malloc(sizeof(void_list_elt_t));
13295 + if (elt == NULL) {
13296 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13300 + void_list_elt_init(elt, data);
13302 + if (list->tail) {
13303 + list->tail->next = elt;
13304 + list->tail = elt;
13306 + list->head = elt;
13307 + list->pre_head.next = list->head;
13308 + list->tail = elt;
13314 +int void_list_push(void_list_t *list, void *data)
13316 + void_list_elt_t *elt;
13318 + elt = malloc(sizeof(void_list_elt_t));
13319 + if (elt == NULL) {
13320 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13324 + void_list_elt_init(elt, data);
13326 + elt->next = list->head;
13327 + list->head->next = elt;
13328 + if (list->tail == NULL) {
13329 + list->tail = list->head;
13335 +void_list_elt_t *void_list_pop(void_list_t *list)
13337 + void_list_elt_t *elt;
13339 + elt = list->head;
13341 + if (list->head) {
13342 + list->head = list->head->next;
13343 + list->pre_head.next = list->head;
13344 + if (list->head == NULL) {
13345 + list->tail = NULL;
13352 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13354 + void_list_elt_t *prior;
13355 + void_list_elt_t *old_elt;
13359 + old_data = old_elt->data;
13361 + if (old_elt == list->head) {
13362 + prior = &list->pre_head;
13363 + void_list_pop(list);
13365 + for (prior = list->head; prior; prior = prior->next) {
13366 + if (prior->next == old_elt) {
13370 + if (prior == NULL || prior->next != old_elt) {
13371 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13374 + prior->next = old_elt->next;
13376 + if (old_elt == list->tail) {
13377 + list->tail = prior;
13381 + void_list_elt_deinit(old_elt);
13387 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13388 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13390 + void_list_elt_t *prior;
13391 + void_list_elt_t *old_elt = NULL;
13392 + void *old_data = NULL;
13394 + /* first element */
13395 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13396 + old_elt = list->head;
13397 + old_data = list->head->data;
13398 + void_list_pop(list);
13401 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13402 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13403 + old_elt = prior->next;
13404 + old_data = old_elt->data;
13412 + prior->next = old_elt->next;
13414 + if (old_elt == list->tail) {
13415 + list->tail = prior;
13419 + void_list_elt_deinit(old_elt);
13426 Index: busybox-1.8.1/archival/libipkg/void_list.h
13427 ===================================================================
13428 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13429 +++ busybox-1.8.1/archival/libipkg/void_list.h 2007-11-10 17:40:53.404767161 +0100
13431 +/* void_list.h - the itsy package management system
13435 + Copyright (C) 2001 University of Southern California
13437 + This program is free software; you can redistribute it and/or
13438 + modify it under the terms of the GNU General Public License as
13439 + published by the Free Software Foundation; either version 2, or (at
13440 + your option) any later version.
13442 + This program is distributed in the hope that it will be useful, but
13443 + WITHOUT ANY WARRANTY; without even the implied warranty of
13444 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13445 + General Public License for more details.
13448 +#ifndef VOID_LIST_H
13449 +#define VOID_LIST_H
13451 +typedef struct void_list_elt void_list_elt_t;
13452 +struct void_list_elt
13454 + void_list_elt_t *next;
13458 +typedef struct void_list void_list_t;
13461 + void_list_elt_t pre_head;
13462 + void_list_elt_t *head;
13463 + void_list_elt_t *tail;
13466 +static inline int void_list_empty(void_list_t *list)
13468 + if (list->head == NULL)
13474 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13475 +void void_list_elt_deinit(void_list_elt_t *elt);
13477 +int void_list_init(void_list_t *list);
13478 +void void_list_deinit(void_list_t *list);
13480 +int void_list_append(void_list_t *list, void *data);
13481 +int void_list_push(void_list_t *list, void *data);
13482 +void_list_elt_t *void_list_pop(void_list_t *list);
13484 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13485 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13486 +typedef int (*void_list_cmp_t)(const void *, const void *);
13487 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13490 Index: busybox-1.8.1/archival/libipkg/xsystem.c
13491 ===================================================================
13492 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13493 +++ busybox-1.8.1/archival/libipkg/xsystem.c 2007-11-10 17:40:53.404767161 +0100
13495 +/* xsystem.c - system(3) with error messages
13499 + Copyright (C) 2001 University of Southern California
13501 + This program is free software; you can redistribute it and/or
13502 + modify it under the terms of the GNU General Public License as
13503 + published by the Free Software Foundation; either version 2, or (at
13504 + your option) any later version.
13506 + This program is distributed in the hope that it will be useful, but
13507 + WITHOUT ANY WARRANTY; without even the implied warranty of
13508 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13509 + General Public License for more details.
13513 +#include <sys/wait.h>
13515 +#include "xsystem.h"
13517 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13518 + really need the /bin/sh invocation which takes resources and
13519 + introduces security problems. I should switch all of this to a sort
13520 + of execl() or execv() interface/implementation.
13523 +/* Like system(3), but with error messages printed if the fork fails
13524 + or if the child process dies due to an uncaught signal. Also, the
13525 + return value is a bit simpler:
13527 + -1 if there was any problem
13528 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13529 + as defined in <sys/wait.h>.
13531 +int xsystem(const char *cmd)
13535 + err = system(cmd);
13538 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13539 + __FUNCTION__, cmd);
13543 + if (WIFSIGNALED(err)) {
13544 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13545 + __FUNCTION__, WTERMSIG(err), cmd);
13549 + if (WIFEXITED(err)) {
13550 + /* Normal child exit */
13551 + return WEXITSTATUS(err);
13554 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13555 + __FUNCTION__, err);
13559 Index: busybox-1.8.1/archival/libipkg/xsystem.h
13560 ===================================================================
13561 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13562 +++ busybox-1.8.1/archival/libipkg/xsystem.h 2007-11-10 17:40:53.404767161 +0100
13564 +/* xsystem.h - system(3) with error messages
13568 + Copyright (C) 2001 University of Southern California
13570 + This program is free software; you can redistribute it and/or
13571 + modify it under the terms of the GNU General Public License as
13572 + published by the Free Software Foundation; either version 2, or (at
13573 + your option) any later version.
13575 + This program is distributed in the hope that it will be useful, but
13576 + WITHOUT ANY WARRANTY; without even the implied warranty of
13577 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13578 + General Public License for more details.
13584 +#include <stdlib.h>
13586 +/* Like system(3), but with error messages printed if the fork fails
13587 + or if the child process dies due to an uncaught signal. Also, the
13588 + return value is a bit simpler:
13590 + -1 if there was any problem
13591 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13592 + as defined in <sys/wait.h>.
13594 +int xsystem(const char *cmd);
13598 Index: busybox-1.8.1/archival/libunarchive/data_extract_all.c
13599 ===================================================================
13600 --- busybox-1.8.1.orig/archival/libunarchive/data_extract_all.c 2007-11-10 17:39:21.471528185 +0100
13601 +++ busybox-1.8.1/archival/libunarchive/data_extract_all.c 2007-11-10 17:40:53.404767161 +0100
13602 @@ -129,3 +129,17 @@
13607 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13609 + char *name_ptr = archive_handle->file_header->name;
13611 + name_ptr += strspn(name_ptr, "./");
13612 + if (name_ptr[0] != '\0') {
13613 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13614 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13615 + strcat(archive_handle->file_header->name, name_ptr);
13616 + data_extract_all(archive_handle);
13620 Index: busybox-1.8.1/archival/libunarchive/Kbuild
13621 ===================================================================
13622 --- busybox-1.8.1.orig/archival/libunarchive/Kbuild 2007-11-10 17:39:21.479528641 +0100
13623 +++ busybox-1.8.1/archival/libunarchive/Kbuild 2007-11-10 17:40:53.408767391 +0100
13625 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13626 lib-$(CONFIG_GUNZIP) += decompress_unzip.o
13627 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13628 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13629 lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
13630 lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
13631 lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
13632 Index: busybox-1.8.1/include/applets.h
13633 ===================================================================
13634 --- busybox-1.8.1.orig/include/applets.h 2007-11-10 17:39:21.487529096 +0100
13635 +++ busybox-1.8.1/include/applets.h 2007-11-10 17:40:53.408767391 +0100
13636 @@ -198,6 +198,7 @@
13637 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13638 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13639 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13640 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13641 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13642 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13643 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13644 Index: busybox-1.8.1/include/unarchive.h
13645 ===================================================================
13646 --- busybox-1.8.1.orig/include/unarchive.h 2007-11-10 17:39:21.495529554 +0100
13647 +++ busybox-1.8.1/include/unarchive.h 2007-11-10 17:40:53.408767391 +0100
13650 extern void data_skip(archive_handle_t *archive_handle);
13651 extern void data_extract_all(archive_handle_t *archive_handle);
13652 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13653 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13654 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13656 Index: busybox-1.8.1/include/usage.h
13657 ===================================================================
13658 --- busybox-1.8.1.orig/include/usage.h 2007-11-10 17:40:53.208755993 +0100
13659 +++ busybox-1.8.1/include/usage.h 2007-11-10 17:40:53.412767617 +0100
13660 @@ -1294,6 +1294,82 @@
13661 "$ ls -la /tmp/busybox*\n" \
13662 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13664 +#define ipkg_trivial_usage \
13665 + "[options]... sub-command [arguments]..."
13666 +#define ipkg_full_usage \
13667 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13669 + "Sub-commands:\n" \
13670 + "\nPackage Manipulation:\n" \
13671 + "\tupdate Update list of available packages\n" \
13672 + "\tupgrade Upgrade all installed packages to latest version\n" \
13673 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13674 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13675 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13676 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13677 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13678 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13680 + "Informational Commands:\n" \
13681 + "\tlist List available packages and descriptions\n" \
13682 + "\tlist_installed List all and only the installed packages and description \n" \
13683 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13684 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13685 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13686 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13687 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13688 + "\tcompare_versions <v1> <op> <v2>\n" \
13689 + "\t compare versions using <= < > >= = << >>\n" \
13690 + "\tprint_architecture prints the architecture.\n" \
13691 + "\tprint_installation_architecture\n" \
13692 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13693 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13694 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13695 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13696 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13697 + "\t prints the installation architecture.\n" \
13700 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13701 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13702 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13703 + "\t 0 errors only\n" \
13704 + "\t 1 normal messages (default)\n" \
13705 + "\t 2 informative messages\n" \
13706 + "\t 3 debug output\n" \
13707 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13708 + "\t-conf <conf_file> Default configuration file location\n" \
13709 + " is /etc/ipkg.conf\n" \
13710 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13711 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13712 + " <dest_name> should be a defined dest name from\n" \
13713 + " the configuration file, (but can also be a\n" \
13714 + " directory name in a pinch).\n" \
13715 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13716 + "\t-offline <offline_root> offline installation of packages.\n" \
13717 + "\t-verbose_wget more wget messages\n" \
13719 + "Force Options (use when ipkg is too smart for its own good):\n" \
13720 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13721 + "\t Install/remove package in spite of failed dependences\n" \
13722 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13723 + " (no prompts). Note that this will not prevent\n" \
13724 + " package installation scripts from prompting.\n" \
13725 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13726 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13727 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13728 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13729 + "\t-noaction No action -- test only\n" \
13730 + "\t-nodeps Do not follow dependences\n" \
13731 + "\t-force-removal-of-dependent-packages\n" \
13732 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13733 + "\t-test No action -- test only\n" \
13734 + "\t-t Specify tmp-dir.\n" \
13735 + "\t--tmp-dir Specify tmp-dir.\n" \
13737 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13738 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13740 #define halt_trivial_usage \
13741 "[-d delay] [-n] [-f]"
13742 #define halt_full_usage \
13743 Index: busybox-1.8.1/Makefile
13744 ===================================================================
13745 --- busybox-1.8.1.orig/Makefile 2007-11-10 17:39:21.511530465 +0100
13746 +++ busybox-1.8.1/Makefile 2007-11-10 17:40:53.412767617 +0100
13747 @@ -428,6 +428,7 @@
13751 + archival/libipkg/ \
13752 archival/libunarchive/ \