1 Index: busybox-1.7.2/archival/Config.in
2 ===================================================================
3 --- busybox-1.7.2.orig/archival/Config.in 2007-10-30 15:34:59.000000000 -0500
4 +++ busybox-1.7.2/archival/Config.in 2007-10-30 15:35:05.000000000 -0500
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.7.2/archival/dpkg.c
22 ===================================================================
23 --- busybox-1.7.2.orig/archival/dpkg.c 2007-10-30 15:34:59.000000000 -0500
24 +++ busybox-1.7.2/archival/dpkg.c 2007-10-30 15:35:05.000000000 -0500
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.7.2/archival/ipkg.c
46 ===================================================================
47 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
48 +++ busybox-1.7.2/archival/ipkg.c 2007-10-30 15:35:05.000000000 -0500
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
70 +#include "libipkg/libipkg.h"
72 +int ipkg_main(int argc, char **argv)
74 + return ipkg_op(argc, argv);
76 Index: busybox-1.7.2/archival/Kbuild
77 ===================================================================
78 --- busybox-1.7.2.orig/archival/Kbuild 2007-10-30 15:34:59.000000000 -0500
79 +++ busybox-1.7.2/archival/Kbuild 2007-10-30 15:35:05.000000000 -0500
81 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
82 lib-$(CONFIG_GUNZIP) += bbunzip.o
83 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
84 +lib-$(CONFIG_IPKG) += ipkg.o
85 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
86 lib-$(CONFIG_RPM) += rpm.o
87 lib-$(CONFIG_TAR) += tar.o
88 Index: busybox-1.7.2/archival/libipkg/args.c
89 ===================================================================
90 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
91 +++ busybox-1.7.2/archival/libipkg/args.c 2007-10-30 15:35:05.000000000 -0500
93 +/* args.c - parse command-line args
97 + Copyright 2001 University of Southern California
99 + This program is free software; you can redistribute it and/or modify
100 + it under the terms of the GNU General Public License as published by
101 + the Free Software Foundation; either version 2, or (at your option)
104 + This program is distributed in the hope that it will be useful,
105 + but WITHOUT ANY WARRANTY; without even the implied warranty of
106 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107 + GNU General Public License for more details.
116 +#include "ipkg_message.h"
119 +#include "sprintf_alloc.h"
124 +static void print_version(void);
128 + ARGS_OPT_FORCE_DEFAULTS = 129,
129 + ARGS_OPT_FORCE_DEPENDS,
130 + ARGS_OPT_FORCE_OVERWRITE,
131 + ARGS_OPT_FORCE_DOWNGRADE,
132 + ARGS_OPT_FORCE_REINSTALL,
133 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
134 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
135 + ARGS_OPT_FORCE_SPACE,
138 + ARGS_OPT_VERBOSE_WGET,
139 + ARGS_OPT_VERBOSITY,
140 + ARGS_OPT_MULTIPLE_PROVIDERS
143 +int args_init(args_t *args)
145 + char *conf_file_dir;
147 + memset(args, 0, sizeof(args_t));
149 + args->dest = ARGS_DEFAULT_DEST;
151 + conf_file_dir = getenv("IPKG_CONF_DIR");
152 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
153 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
155 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
156 + ARGS_DEFAULT_CONF_FILE_NAME);
158 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
159 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
160 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
161 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
162 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
163 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
164 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
165 + args->noaction = ARGS_DEFAULT_NOACTION;
166 + args->nodeps = ARGS_DEFAULT_NODEPS;
167 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
168 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
169 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
170 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
171 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
172 + args->multiple_providers = 0;
173 + args->nocheckfordirorfile = 0;
174 + args->noreadfeedsfile = 0;
179 +void args_deinit(args_t *args)
181 + free(args->conf_file);
182 + args->conf_file = NULL;
185 +int args_parse(args_t *args, int argc, char *argv[])
188 + int option_index = 0;
190 + static struct option long_options[] = {
191 + {"query-all", 0, 0, 'A'},
192 + {"conf-file", 1, 0, 'f'},
193 + {"conf", 1, 0, 'f'},
194 + {"dest", 1, 0, 'd'},
195 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
196 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
197 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
198 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
199 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
200 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
201 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
202 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
203 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
204 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
205 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
206 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
207 + {"recursive", 0, 0,
208 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
209 + {"force-removal-of-dependent-packages", 0, 0,
210 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
211 + {"force_removal_of_dependent_packages", 0, 0,
212 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
213 + {"force-removal-of-essential-packages", 0, 0,
214 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
215 + {"force_removal_of_essential_packages", 0, 0,
216 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
217 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
218 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
219 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
220 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
221 + {"offline", 1, 0, 'o'},
222 + {"offline-root", 1, 0, 'o'},
223 + {"test", 0, 0, ARGS_OPT_NOACTION},
224 + {"tmp-dir", 1, 0, 't'},
225 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
226 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
227 + {"verbosity", 2, 0, 'V'},
228 + {"version", 0, 0, 'v'},
233 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
239 + args->query_all = 1;
242 + args->dest = optarg;
245 + free(args->conf_file);
246 + args->conf_file = strdup(optarg);
249 + args->offline_root = optarg;
252 + args->noaction = 1;
255 + args->tmp_dir = strdup(optarg);
261 + case ARGS_OPT_VERBOSITY:
263 + args->verbosity = atoi(optarg);
265 + args->verbosity += 1;
267 + case ARGS_OPT_FORCE_DEFAULTS:
268 + args->force_defaults = 1;
270 + case ARGS_OPT_FORCE_DEPENDS:
271 + args->force_depends = 1;
273 + case ARGS_OPT_FORCE_OVERWRITE:
274 + args->force_overwrite = 1;
276 + case ARGS_OPT_FORCE_DOWNGRADE:
277 + args->force_downgrade = 1;
279 + case ARGS_OPT_FORCE_REINSTALL:
280 + args->force_reinstall = 1;
282 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
283 + args->force_removal_of_essential_packages = 1;
285 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
286 + args->force_removal_of_dependent_packages = 1;
288 + case ARGS_OPT_FORCE_SPACE:
289 + args->force_space = 1;
291 + case ARGS_OPT_VERBOSE_WGET:
292 + args->verbose_wget = 1;
294 + case ARGS_OPT_MULTIPLE_PROVIDERS:
295 + args->multiple_providers = 1;
297 + case ARGS_OPT_NODEPS:
300 + case ARGS_OPT_NOACTION:
301 + args->noaction = 1;
310 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
321 +void args_usage(char *complaint)
324 + bb_error_msg("%s\n", complaint);
331 +static void print_version(void)
333 + bb_error_msg("version %s\n", IPKG_VERSION);
335 Index: busybox-1.7.2/archival/libipkg/args.h
336 ===================================================================
337 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
338 +++ busybox-1.7.2/archival/libipkg/args.h 2007-10-30 15:35:05.000000000 -0500
340 +/* args.h - parse command-line args
344 + Copyright 2001 University of Southern California
346 + This program is free software; you can redistribute it and/or modify
347 + it under the terms of the GNU General Public License as published by
348 + the Free Software Foundation; either version 2, or (at your option)
351 + This program is distributed in the hope that it will be useful,
352 + but WITHOUT ANY WARRANTY; without even the implied warranty of
353 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
354 + GNU General Public License for more details.
365 + int force_defaults;
367 + int force_overwrite;
368 + int force_downgrade;
369 + int force_reinstall;
370 + int force_removal_of_essential_packages;
371 + int force_removal_of_dependent_packages;
375 + int multiple_providers;
379 + int nocheckfordirorfile;
380 + int noreadfeedsfile;
381 + char *offline_root;
382 + char *offline_root_pre_script_cmd;
383 + char *offline_root_post_script_cmd;
385 +typedef struct args args_t;
387 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
388 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
389 +#define ARGS_DEFAULT_DEST NULL
390 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
391 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
392 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
393 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
394 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
395 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
396 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
397 +#define ARGS_DEFAULT_FORCE_SPACE 0
398 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
399 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
400 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
401 +#define ARGS_DEFAULT_NOACTION 0
402 +#define ARGS_DEFAULT_NODEPS 0
403 +#define ARGS_DEFAULT_VERBOSE_WGET 0
404 +#define ARGS_DEFAULT_VERBOSITY 1
406 +int args_init(args_t *args);
407 +void args_deinit(args_t *args);
408 +int args_parse(args_t *args, int argc, char *argv[]);
409 +void args_usage(char *complaint);
412 Index: busybox-1.7.2/archival/libipkg/conffile.c
413 ===================================================================
414 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
415 +++ busybox-1.7.2/archival/libipkg/conffile.c 2007-10-30 15:35:05.000000000 -0500
417 +/* conffile.c - the itsy package management system
421 + Copyright (C) 2001 University of Southern California
423 + This program is free software; you can redistribute it and/or
424 + modify it under the terms of the GNU General Public License as
425 + published by the Free Software Foundation; either version 2, or (at
426 + your option) any later version.
428 + This program is distributed in the hope that it will be useful, but
429 + WITHOUT ANY WARRANTY; without even the implied warranty of
430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
431 + General Public License for more details.
438 +#include "ipkg_message.h"
440 +#include "conffile.h"
441 +#include "file_util.h"
442 +#include "sprintf_alloc.h"
444 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
446 + return nv_pair_init(conffile, file_name, md5sum);
449 +void conffile_deinit(conffile_t *conffile)
451 + nv_pair_deinit(conffile);
454 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
457 + char *filename = conffile->name;
458 + char *root_filename;
461 + if (conffile->value == NULL) {
462 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
466 + root_filename = root_filename_alloc(conf, filename);
468 + md5sum = file_md5sum_alloc(root_filename);
470 + ret = strcmp(md5sum, conffile->value);
472 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
473 + conffile->name, md5sum, conffile->value);
476 + free(root_filename);
481 Index: busybox-1.7.2/archival/libipkg/conffile.h
482 ===================================================================
483 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
484 +++ busybox-1.7.2/archival/libipkg/conffile.h 2007-10-30 15:35:05.000000000 -0500
486 +/* conffile.h - the itsy package management system
490 + Copyright (C) 2001 University of Southern California
492 + This program is free software; you can redistribute it and/or
493 + modify it under the terms of the GNU General Public License as
494 + published by the Free Software Foundation; either version 2, or (at
495 + your option) any later version.
497 + This program is distributed in the hope that it will be useful, but
498 + WITHOUT ANY WARRANTY; without even the implied warranty of
499 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
500 + General Public License for more details.
506 +#include "nv_pair.h"
508 +typedef struct nv_pair conffile_t;
510 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
511 +void conffile_deinit(conffile_t *conffile);
512 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
516 Index: busybox-1.7.2/archival/libipkg/conffile_list.c
517 ===================================================================
518 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
519 +++ busybox-1.7.2/archival/libipkg/conffile_list.c 2007-10-30 15:35:05.000000000 -0500
521 +/* conffile_list.c - the itsy package management system
525 + Copyright (C) 2001 University of Southern California
527 + This program is free software; you can redistribute it and/or
528 + modify it under the terms of the GNU General Public License as
529 + published by the Free Software Foundation; either version 2, or (at
530 + your option) any later version.
532 + This program is distributed in the hope that it will be useful, but
533 + WITHOUT ANY WARRANTY; without even the implied warranty of
534 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
535 + General Public License for more details.
540 +#include "conffile_list.h"
542 +int conffile_list_init(conffile_list_t *list)
544 + return nv_pair_list_init(list);
547 +void conffile_list_deinit(conffile_list_t *list)
549 + nv_pair_list_deinit(list);
552 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
553 + const char *md5sum)
555 + return nv_pair_list_append(list, file_name, md5sum);
558 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
560 + return nv_pair_list_push(list, data);
563 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
565 + return nv_pair_list_pop(list);
568 Index: busybox-1.7.2/archival/libipkg/conffile_list.h
569 ===================================================================
570 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
571 +++ busybox-1.7.2/archival/libipkg/conffile_list.h 2007-10-30 15:35:05.000000000 -0500
573 +/* conffile_list.h - the itsy package management system
577 + Copyright (C) 2001 University of Southern California
579 + This program is free software; you can redistribute it and/or
580 + modify it under the terms of the GNU General Public License as
581 + published by the Free Software Foundation; either version 2, or (at
582 + your option) any later version.
584 + This program is distributed in the hope that it will be useful, but
585 + WITHOUT ANY WARRANTY; without even the implied warranty of
586 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
587 + General Public License for more details.
590 +#ifndef CONFFILE_LIST_H
591 +#define CONFFILE_LIST_H
593 +#include "conffile.h"
594 +#include "nv_pair_list.h"
596 +typedef struct nv_pair_list_elt conffile_list_elt_t;
597 +typedef struct nv_pair_list conffile_list_t;
599 +int conffile_list_init(conffile_list_t *list);
600 +void conffile_list_deinit(conffile_list_t *list);
602 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
603 + const char *root_dir);
604 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
605 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
609 Index: busybox-1.7.2/archival/libipkg/file_util.c
610 ===================================================================
611 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
612 +++ busybox-1.7.2/archival/libipkg/file_util.c 2007-10-30 15:35:05.000000000 -0500
614 +/* file_util.c - convenience routines for common stat operations
618 + Copyright (C) 2001 University of Southern California
620 + This program is free software; you can redistribute it and/or
621 + modify it under the terms of the GNU General Public License as
622 + published by the Free Software Foundation; either version 2, or (at
623 + your option) any later version.
625 + This program is distributed in the hope that it will be useful, but
626 + WITHOUT ANY WARRANTY; without even the implied warranty of
627 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
628 + General Public License for more details.
632 +#include <sys/types.h>
633 +#include <sys/stat.h>
635 +#include "sprintf_alloc.h"
636 +#include "file_util.h"
640 +int file_exists(const char *file_name)
643 + struct stat stat_buf;
645 + err = stat(file_name, &stat_buf);
653 +int file_is_dir(const char *file_name)
656 + struct stat stat_buf;
658 + err = stat(file_name, &stat_buf);
663 + return S_ISDIR(stat_buf.st_mode);
666 +/* read a single line from a file, stopping at a newline or EOF.
667 + If a newline is read, it will appear in the resulting string.
668 + Return value is a malloc'ed char * which should be freed at
669 + some point by the caller.
671 + Return value is NULL if the file is at EOF when called.
673 +#define FILE_READ_LINE_BUF_SIZE 1024
674 +char *file_read_line_alloc(FILE *file)
676 + char buf[FILE_READ_LINE_BUF_SIZE];
681 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
682 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
683 + buf_len = strlen(buf);
685 + line_size += buf_len;
686 + line = realloc(line, line_size);
687 + if (line == NULL) {
688 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
693 + line_size = buf_len + 1;
694 + line = strdup(buf);
696 + if (buf[buf_len - 1] == '\n') {
704 +int file_move(const char *src, const char *dest)
708 + err = rename(src, dest);
710 + if (err && errno == EXDEV) {
711 + err = file_copy(src, dest);
714 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
715 + __FUNCTION__, src, dest, strerror(errno));
721 +/* I put these here to keep libbb dependencies from creeping all over
723 +int file_copy(const char *src, const char *dest)
727 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
729 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
730 + __FUNCTION__, src, dest);
736 +int file_mkdir_hier(const char *path, long mode)
738 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
741 +char *file_md5sum_alloc(const char *file_name)
743 + return hash_file(file_name, HASH_MD5);
746 Index: busybox-1.7.2/archival/libipkg/file_util.h
747 ===================================================================
748 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
749 +++ busybox-1.7.2/archival/libipkg/file_util.h 2007-10-30 15:35:05.000000000 -0500
751 +/* file_util.h - convenience routines for common file operations
755 + Copyright (C) 2001 University of Southern California
757 + This program is free software; you can redistribute it and/or
758 + modify it under the terms of the GNU General Public License as
759 + published by the Free Software Foundation; either version 2, or (at
760 + your option) any later version.
762 + This program is distributed in the hope that it will be useful, but
763 + WITHOUT ANY WARRANTY; without even the implied warranty of
764 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
765 + General Public License for more details.
771 +int file_exists(const char *file_name);
772 +int file_is_dir(const char *file_name);
773 +char *file_read_line_alloc(FILE *file);
774 +int file_move(const char *src, const char *dest);
775 +int file_copy(const char *src, const char *dest);
776 +int file_mkdir_hier(const char *path, long mode);
777 +char *file_md5sum_alloc(const char *file_name);
780 Index: busybox-1.7.2/archival/libipkg/hash_table.c
781 ===================================================================
782 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
783 +++ busybox-1.7.2/archival/libipkg/hash_table.c 2007-10-30 15:35:05.000000000 -0500
785 +/* hash.c - hash tables for ipkg
787 + Steven M. Ayer, Jamey Hicks
789 + Copyright (C) 2002 Compaq Computer Corporation
791 + This program is free software; you can redistribute it and/or
792 + modify it under the terms of the GNU General Public License as
793 + published by the Free Software Foundation; either version 2, or (at
794 + your option) any later version.
796 + This program is distributed in the hope that it will be useful, but
797 + WITHOUT ANY WARRANTY; without even the implied warranty of
798 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
799 + General Public License for more details.
806 +#include "hash_table.h"
807 +#include "ipkg_message.h"
810 +static int hash_index(hash_table_t *hash, const char *pkg_name);
811 +static int rotating(const char *key, int len, int prime);
813 +static int hash_index(hash_table_t *hash, const char *pkg_name)
815 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
818 +static int rotating(const char *key, int len, int prime)
820 + unsigned int hash, i;
821 + for (hash=len, i=0; i<len; ++i)
822 + hash = (hash<<4)^(hash>>28)^key[i];
823 + return (hash % prime);
828 + * this is an open table keyed by strings
830 +int hash_table_init(const char *name, hash_table_t *hash, int len)
832 + static int primes_table[] = {
833 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
834 + 19471, 23143, 33961, 46499, 49727, 99529, 0
838 + if (hash->entries != NULL) {
839 + /* we have been here already */
844 + hash->entries = NULL;
845 + hash->n_entries = 0;
846 + hash->hash_entry_key = NULL;
848 + picker = primes_table;
849 + while(*picker && (*picker++ < len));
851 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
854 + hash->n_entries = *picker;
855 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
856 + if (hash->entries == NULL) {
857 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
863 +void hash_table_deinit(hash_table_t *hash)
865 + free(hash->entries);
866 + hash->entries = NULL;
867 + hash->n_entries = 0;
870 +void *hash_table_get(hash_table_t *hash, const char *key)
872 + int ndx= hash_index(hash, key);
873 + hash_entry_t *hash_entry = hash->entries + ndx;
876 + if (hash_entry->key)
878 + if (strcmp(key, hash_entry->key) == 0) {
879 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
880 + return hash_entry->data;
883 + hash_entry = hash_entry->next;
888 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
890 + int ndx= hash_index(hash, key);
891 + hash_entry_t *hash_entry = hash->entries + ndx;
892 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
893 + if (hash_entry->key) {
894 + if (strcmp(hash_entry->key, key) == 0) {
895 + /* alread in table, update the value */
896 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
897 + hash_entry->data = value;
901 + * if this is a collision, we have to go to the end of the ll,
902 + * then add a new entry
903 + * before we can hook up the value
905 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
906 + while (hash_entry->next)
907 + hash_entry = hash_entry->next;
908 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
909 + if (!hash_entry->next) {
912 + hash_entry = hash_entry->next;
913 + hash_entry->next = NULL;
916 + hash->n_elements++;
917 + hash_entry->key = strdup(key);
918 + hash_entry->data = value;
924 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
930 + for (i = 0; i < hash->n_entries; i++) {
931 + hash_entry_t *hash_entry = (hash->entries + i);
933 + if(hash_entry->key) {
934 + f(hash_entry->key, hash_entry->data, data);
936 + } while((hash_entry = hash_entry->next));
940 Index: busybox-1.7.2/archival/libipkg/hash_table.h
941 ===================================================================
942 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
943 +++ busybox-1.7.2/archival/libipkg/hash_table.h 2007-10-30 15:35:05.000000000 -0500
945 +/* hash.h - hash tables for ipkg
947 + Steven M. Ayer, Jamey Hicks
949 + Copyright (C) 2002 Compaq Computer Corporation
951 + This program is free software; you can redistribute it and/or
952 + modify it under the terms of the GNU General Public License as
953 + published by the Free Software Foundation; either version 2, or (at
954 + your option) any later version.
956 + This program is distributed in the hope that it will be useful, but
957 + WITHOUT ANY WARRANTY; without even the implied warranty of
958 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
959 + General Public License for more details.
962 +#ifndef _HASH_TABLE_H_
963 +#define _HASH_TABLE_H_
965 +typedef struct hash_entry hash_entry_t;
966 +typedef struct hash_table hash_table_t;
971 + struct hash_entry * next;
976 + hash_entry_t * entries;
977 + int n_entries; /* number of buckets */
979 + const char * (*hash_entry_key)(void * data);
982 +int hash_table_init(const char *name, hash_table_t *hash, int len);
983 +void hash_table_deinit(hash_table_t *hash);
984 +void *hash_table_get(hash_table_t *hash, const char *key);
985 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
986 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
988 +#endif /* _HASH_TABLE_H_ */
989 Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.c
990 ===================================================================
991 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
992 +++ busybox-1.7.2/archival/libipkg/ipkg_cmd.c 2007-10-30 15:35:05.000000000 -0500
994 +/* ipkg_cmd.c - the itsy package management system
998 + Copyright (C) 2001 University of Southern California
1000 + This program is free software; you can redistribute it and/or
1001 + modify it under the terms of the GNU General Public License as
1002 + published by the Free Software Foundation; either version 2, or (at
1003 + your option) any later version.
1005 + This program is distributed in the hope that it will be useful, but
1006 + WITHOUT ANY WARRANTY; without even the implied warranty of
1007 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1008 + General Public License for more details.
1011 +#include <string.h>
1014 +#include <libgen.h>
1017 +#include <stdlib.h>
1018 +#include <unistd.h>
1019 +#include <signal.h>
1021 +#include <dirent.h>
1023 +#include "ipkg_conf.h"
1024 +#include "ipkg_cmd.h"
1025 +#include "ipkg_message.h"
1027 +#include "pkg_dest.h"
1028 +#include "pkg_parse.h"
1029 +#include "sprintf_alloc.h"
1031 +#include "file_util.h"
1032 +#include "str_util.h"
1034 +#include "unarchive.h"
1036 +#include <fnmatch.h>
1039 +#include "ipkg_download.h"
1040 +#include "ipkg_install.h"
1041 +#include "ipkg_upgrade.h"
1042 +#include "ipkg_remove.h"
1043 +#include "ipkg_configure.h"
1044 +#include "ipkg_message.h"
1047 +#include "libipkg.h"
1048 +static void *p_userdata = NULL;
1051 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1052 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1060 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1062 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1063 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1064 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1065 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1066 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1067 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1068 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1069 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1077 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1078 + array for easier maintenance */
1079 +static ipkg_cmd_t cmds[] = {
1080 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1081 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1082 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1083 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1084 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1085 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1086 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1087 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1088 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1089 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1090 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1091 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1092 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1093 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1094 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1095 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1096 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1097 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1098 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1099 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1100 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1101 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1102 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1103 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1104 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1105 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1106 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1107 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1108 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1111 +int ipkg_state_changed;
1112 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1114 + if (ipkg_state_changed && !conf->noaction) {
1115 + ipkg_message(conf, IPKG_INFO,
1116 + " writing status file\n");
1117 + ipkg_conf_write_status_files(conf);
1118 + pkg_write_changed_filelists(conf);
1120 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1125 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1127 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1132 + for (i=0; i < num_cmds; i++) {
1134 + if (strcmp(name, cmd->name) == 0) {
1143 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1146 + p_userdata = userdata;
1149 + result = (cmd->fun)(conf, argc, argv);
1150 + if ( result == 0 ) {
1151 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1153 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1156 + if ( error_list ) {
1157 + reverse_error_list(&error_list);
1159 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1160 + /* Here we print the errors collected and free the list */
1161 + while (error_list != NULL) {
1162 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1163 + error_list = error_list->next;
1166 + free_error_list(&error_list);
1170 + p_userdata = NULL;
1174 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1176 + return (cmd->fun)(conf, argc, argv);
1180 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1185 + pkg_src_list_elt_t *iter;
1189 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1191 + if (! file_is_dir(lists_dir)) {
1192 + if (file_exists(lists_dir)) {
1193 + ipkg_message(conf, IPKG_ERROR,
1194 + "%s: ERROR: %s exists, but is not a directory\n",
1195 + __FUNCTION__, lists_dir);
1199 + err = file_mkdir_hier(lists_dir, 0755);
1201 + ipkg_message(conf, IPKG_ERROR,
1202 + "%s: ERROR: failed to make directory %s: %s\n",
1203 + __FUNCTION__, lists_dir, strerror(errno));
1210 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1211 + char *url, *list_file_name;
1215 + if (src->extra_data) /* debian style? */
1216 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1217 + src->gzip ? "Packages.gz" : "Packages");
1219 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1221 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1224 + char *tmp_file_name;
1227 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1229 + if (mkdtemp (tmp) == NULL) {
1230 + perror ("mkdtemp");
1235 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1236 + err = ipkg_download(conf, url, tmp_file_name);
1238 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1239 + in = fopen (tmp_file_name, "r");
1240 + out = fopen (list_file_name, "w");
1242 + inflate_unzip_result res;
1243 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1250 + unlink (tmp_file_name);
1255 + err = ipkg_download(conf, url, list_file_name);
1259 + ipkg_message(conf, IPKG_NOTICE,
1260 + "Updated list of available packages in %s\n",
1264 + free(list_file_name);
1268 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1270 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1271 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1277 + pkg_vec_t *available = pkg_vec_alloc();
1278 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1279 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1280 + for (i = 0; i < available->len; i++) {
1281 + pkg_t *pkg = available->pkgs[i];
1282 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1283 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1284 + pkg->state_want = SW_UNKNOWN;
1288 + pkg_vec_free(available);
1290 + write_status_files_if_changed(conf);
1299 +/* scan the args passed and cache the local filenames of the packages */
1300 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1306 + * First scan through package names/urls
1307 + * For any urls, download the packages and install in database.
1308 + * For any files, install package info in database.
1310 + for (i = 0; i < argc; i ++) {
1311 + char *filename = argv [i];
1312 + //char *tmp = basename (tmp);
1313 + //int tmplen = strlen (tmp);
1315 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1317 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1320 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1322 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1329 +struct ipkg_intercept
1335 +typedef struct ipkg_intercept *ipkg_intercept_t;
1337 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1339 + ipkg_intercept_t ctx;
1343 + ctx = malloc (sizeof (*ctx));
1344 + ctx->oldpath = strdup (getenv ("PATH"));
1346 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1347 + setenv ("PATH", newpath, 1);
1352 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1353 + if (mkdir (ctx->statedir, 0770) < 0) {
1354 + if (errno == EEXIST) {
1355 + free (ctx->statedir);
1359 + perror (ctx->statedir);
1362 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1366 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1372 + setenv ("PATH", ctx->oldpath, 1);
1373 + free (ctx->oldpath);
1375 + dir = opendir (ctx->statedir);
1377 + struct dirent *de;
1378 + while (de = readdir (dir), de != NULL) {
1381 + if (de->d_name[0] == '.')
1384 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1385 + if (access (path, X_OK) == 0) {
1386 + if (system (path)) {
1388 + perror (de->d_name);
1394 + perror (ctx->statedir);
1396 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1400 + free (ctx->statedir);
1406 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1411 + ipkg_intercept_t ic;
1414 + ipkg_message(conf, IPKG_INFO,
1415 + "Configuring unpacked packages\n");
1418 + all = pkg_vec_alloc();
1419 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1421 + ic = ipkg_prep_intercepts (conf);
1423 + for(i = 0; i < all->len; i++) {
1424 + pkg = all->pkgs[i];
1426 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1429 + if (pkg->state_status == SS_UNPACKED) {
1430 + ipkg_message(conf, IPKG_NOTICE,
1431 + "Configuring %s\n", pkg->name);
1433 + r = ipkg_configure(conf, pkg);
1435 + pkg->state_status = SS_INSTALLED;
1436 + pkg->parent->state_status = SS_INSTALLED;
1437 + pkg->state_flag &= ~SF_PREFER;
1445 + r = ipkg_finalize_intercepts (ic);
1449 + pkg_vec_free(all);
1453 +static void sigint_handler(int sig)
1455 + signal(sig, SIG_DFL);
1456 + ipkg_message(NULL, IPKG_NOTICE,
1457 + "ipkg: interrupted. writing out status database\n");
1458 + write_status_files_if_changed(global_conf);
1462 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1468 + global_conf = conf;
1469 + signal(SIGINT, sigint_handler);
1472 + * Now scan through package names and install
1474 + for (i=0; i < argc; i++) {
1477 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1478 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1479 + if (err != EINVAL && err != 0)
1482 + pkg_info_preinstall_check(conf);
1484 + for (i=0; i < argc; i++) {
1486 + if (conf->multiple_providers)
1487 + err = ipkg_install_multi_by_name(conf, arg);
1489 + err = ipkg_install_by_name(conf, arg);
1491 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1492 + ipkg_message(conf, IPKG_ERROR,
1493 + "Cannot find package %s.\n"
1494 + "Check the spelling or perhaps run 'ipkg update'\n",
1499 + /* recheck to verify that all dependences are satisfied */
1500 + if (0) ipkg_satisfy_all_dependences(conf);
1502 + ipkg_configure_packages(conf, NULL);
1504 + write_status_files_if_changed(conf);
1509 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1515 + global_conf = conf;
1516 + signal(SIGINT, sigint_handler);
1519 + for (i=0; i < argc; i++) {
1520 + char *arg = argv[i];
1522 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1523 + if (err != EINVAL && err != 0)
1526 + pkg_info_preinstall_check(conf);
1528 + for (i=0; i < argc; i++) {
1529 + char *arg = argv[i];
1530 + if (conf->restrict_to_default_dest) {
1531 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1533 + conf->default_dest);
1534 + if (pkg == NULL) {
1535 + ipkg_message(conf, IPKG_NOTICE,
1536 + "Package %s not installed in %s\n",
1537 + argv[i], conf->default_dest->name);
1541 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1545 + ipkg_upgrade_pkg(conf, pkg);
1547 + ipkg_install_by_name(conf, arg);
1551 + pkg_vec_t *installed = pkg_vec_alloc();
1553 + pkg_info_preinstall_check(conf);
1555 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1556 + for (i = 0; i < installed->len; i++) {
1557 + pkg = installed->pkgs[i];
1558 + ipkg_upgrade_pkg(conf, pkg);
1560 + pkg_vec_free(installed);
1563 + /* recheck to verify that all dependences are satisfied */
1564 + if (0) ipkg_satisfy_all_dependences(conf);
1566 + ipkg_configure_packages(conf, NULL);
1568 + write_status_files_if_changed(conf);
1573 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1579 + pkg_info_preinstall_check(conf);
1580 + for (i = 0; i < argc; i++) {
1583 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1584 + if (pkg == NULL) {
1585 + ipkg_message(conf, IPKG_ERROR,
1586 + "Cannot find package %s.\n"
1587 + "Check the spelling or perhaps run 'ipkg update'\n",
1592 + err = ipkg_download_pkg(conf, pkg, ".");
1595 + ipkg_message(conf, IPKG_ERROR,
1596 + "Failed to download %s\n", pkg->name);
1598 + ipkg_message(conf, IPKG_NOTICE,
1599 + "Downloaded %s as %s\n",
1600 + pkg->name, pkg->local_filename);
1608 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1611 + pkg_vec_t *available;
1613 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1615 + char *pkg_name = NULL;
1616 + char *version_str;
1619 + pkg_name = argv[0];
1621 + available = pkg_vec_alloc();
1622 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1623 + for (i=0; i < available->len; i++) {
1624 + pkg = available->pkgs[i];
1625 + /* if we have package name or pattern and pkg does not match, then skip it */
1626 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1628 + if (pkg->description) {
1629 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1631 + desc_short[0] = '\0';
1633 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1634 + newline = strchr(desc_short, '\n');
1639 + printf("%s - %s\n", pkg->name, desc_short);
1641 + if (ipkg_cb_list) {
1642 + version_str = pkg_version_str_alloc(pkg);
1643 + ipkg_cb_list(pkg->name,desc_short,
1645 + pkg->state_status,
1647 + free(version_str);
1651 + pkg_vec_free(available);
1657 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1660 + pkg_vec_t *available;
1662 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1664 + char *pkg_name = NULL;
1665 + char *version_str;
1668 + pkg_name = argv[0];
1670 + available = pkg_vec_alloc();
1671 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1672 + for (i=0; i < available->len; i++) {
1673 + pkg = available->pkgs[i];
1674 + /* if we have package name or pattern and pkg does not match, then skip it */
1675 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1677 + if (pkg->description) {
1678 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1680 + desc_short[0] = '\0';
1682 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1683 + newline = strchr(desc_short, '\n');
1688 + printf("%s - %s\n", pkg->name, desc_short);
1690 + if (ipkg_cb_list) {
1691 + version_str = pkg_version_str_alloc(pkg);
1692 + ipkg_cb_list(pkg->name,desc_short,
1694 + pkg->state_status,
1696 + free(version_str);
1704 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1707 + pkg_vec_t *available;
1709 + char *pkg_name = NULL;
1710 + char **pkg_fields = NULL;
1712 + char *buff ; // = (char *)malloc(1);
1715 + pkg_name = argv[0];
1718 + pkg_fields = &argv[1];
1719 + n_fields = argc - 1;
1722 + available = pkg_vec_alloc();
1723 + if (installed_only)
1724 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1726 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1727 + for (i=0; i < available->len; i++) {
1728 + pkg = available->pkgs[i];
1729 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1734 + for (j = 0; j < n_fields; j++)
1735 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1737 + pkg_print_info(pkg, stdout);
1741 + buff = pkg_formatted_info(pkg);
1743 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1744 + pkg->state_status,
1748 + We should not forget that actually the pointer is allocated.
1749 + We need to free it :) ( Thanks florian for seeing the error )
1754 + if (conf->verbosity > 1) {
1755 + conffile_list_elt_t *iter;
1756 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1757 + conffile_t *cf = iter->data;
1758 + int modified = conffile_has_been_modified(conf, cf);
1759 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1760 + cf->name, cf->value, modified);
1768 + pkg_vec_free(available);
1773 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1775 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1778 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1780 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1783 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1788 + char *pkg_name = NULL;
1790 + pkg_name = argv[0];
1792 + err = ipkg_configure_packages (conf, pkg_name);
1795 + err = ipkg_configure_packages (conf, NULL);
1798 + write_status_files_if_changed(conf);
1803 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1806 + char *globpattern;
1809 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1810 + err = glob(globpattern, 0, NULL, &globbuf);
1811 + free(globpattern);
1816 + ipkg_message(conf, IPKG_NOTICE,
1817 + "The following packages in %s will now be installed.\n",
1818 + conf->pending_dir);
1819 + for (i = 0; i < globbuf.gl_pathc; i++) {
1820 + ipkg_message(conf, IPKG_NOTICE,
1821 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1823 + ipkg_message(conf, IPKG_NOTICE, "\n");
1824 + for (i = 0; i < globbuf.gl_pathc; i++) {
1825 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1827 + err = unlink(globbuf.gl_pathv[i]);
1829 + ipkg_message(conf, IPKG_ERROR,
1830 + "%s: ERROR: failed to unlink %s: %s\n",
1831 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1836 + globfree(&globbuf);
1841 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1845 + pkg_t *pkg_to_remove;
1846 + pkg_vec_t *available;
1847 + char *pkg_name = NULL;
1848 + global_conf = conf;
1849 + signal(SIGINT, sigint_handler);
1851 +// ENH: Add the "no pkg removed" just in case.
1855 + available = pkg_vec_alloc();
1856 + pkg_info_preinstall_check(conf);
1858 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1859 + for (i=0; i < argc; i++) {
1860 + pkg_name = malloc(strlen(argv[i])+2);
1861 + strcpy(pkg_name,argv[i]);
1862 + for (a=0; a < available->len; a++) {
1863 + pkg = available->pkgs[a];
1864 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1867 + if (conf->restrict_to_default_dest) {
1868 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1870 + conf->default_dest);
1872 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1875 + if (pkg == NULL) {
1876 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1879 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1880 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1883 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1888 + pkg_vec_free(available);
1890 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1891 + int flagged_pkg_count = 0;
1894 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1896 + for (i = 0; i < installed_pkgs->len; i++) {
1897 + pkg = installed_pkgs->pkgs[i];
1898 + if (pkg->state_flag & SF_USER) {
1899 + flagged_pkg_count++;
1901 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1902 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1905 + if (!flagged_pkg_count) {
1906 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1907 + "so refusing to uninstall unflagged non-leaf packages\n");
1911 + /* find packages not flagged SF_USER (i.e., installed to
1912 + * satisfy a dependence) and not having any dependents, and
1916 + for (i = 0; i < installed_pkgs->len; i++) {
1917 + pkg = installed_pkgs->pkgs[i];
1918 + if (!(pkg->state_flag & SF_USER)
1919 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1921 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1922 + ipkg_remove_pkg(conf, pkg,0);
1926 + } while (removed);
1927 + pkg_vec_free(installed_pkgs);
1931 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1933 + write_status_files_if_changed(conf);
1937 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1942 + global_conf = conf;
1943 + signal(SIGINT, sigint_handler);
1945 + pkg_info_preinstall_check(conf);
1947 + for (i=0; i < argc; i++) {
1948 + if (conf->restrict_to_default_dest) {
1949 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1951 + conf->default_dest);
1953 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1956 + if (pkg == NULL) {
1957 + ipkg_message(conf, IPKG_ERROR,
1958 + "Package %s is not installed.\n", argv[i]);
1961 + ipkg_purge_pkg(conf, pkg);
1964 + write_status_files_if_changed(conf);
1968 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1972 + char *flags = argv[0];
1974 + global_conf = conf;
1975 + signal(SIGINT, sigint_handler);
1977 + for (i=1; i < argc; i++) {
1978 + if (conf->restrict_to_default_dest) {
1979 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1981 + conf->default_dest);
1983 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1986 + if (pkg == NULL) {
1987 + ipkg_message(conf, IPKG_ERROR,
1988 + "Package %s is not installed.\n", argv[i]);
1991 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1992 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1993 + pkg->state_flag = pkg_state_flag_from_str(flags);
1995 +/* pb_ asked this feature 03292004 */
1996 +/* Actually I will use only this two, but this is an open for various status */
1997 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1998 + pkg->state_status = pkg_state_status_from_str(flags);
2000 + ipkg_state_changed++;
2001 + ipkg_message(conf, IPKG_NOTICE,
2002 + "Setting flags for package %s to %s\n",
2003 + pkg->name, flags);
2006 + write_status_files_if_changed(conf);
2010 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2013 + str_list_t *installed_files;
2014 + str_list_elt_t *iter;
2015 + char *pkg_version;
2016 + size_t buff_len = 8192;
2020 + buff = (char *)malloc(buff_len);
2021 + if ( buff == NULL ) {
2022 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2030 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2032 + if (pkg == NULL) {
2033 + ipkg_message(conf, IPKG_ERROR,
2034 + "Package %s not installed.\n", argv[0]);
2038 + installed_files = pkg_get_installed_files(pkg);
2039 + pkg_version = pkg_version_str_alloc(pkg);
2042 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2043 + pkg->name, pkg_version, pkg->dest->name);
2044 + for (iter = installed_files->head; iter; iter = iter->next) {
2050 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2051 + pkg->name, pkg_version, pkg->dest->name) + 1;
2052 + if (used_len > buff_len) {
2054 + buff = realloc (buff, buff_len);
2057 + for (iter = installed_files->head; iter; iter = iter->next) {
2058 + used_len += strlen (iter->data) + 1;
2059 + while (buff_len <= used_len) {
2061 + buff = realloc (buff, buff_len);
2063 + strncat(buff, iter->data, buff_len);
2064 + strncat(buff, "\n", buff_len);
2066 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2068 + pkg_version_str_alloc(pkg),
2069 + pkg->state_status,
2075 + free(pkg_version);
2076 + pkg_free_installed_files(pkg);
2081 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2085 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2086 + const char *rel_str = "depends on";
2089 + pkg_info_preinstall_check(conf);
2091 + if (conf->query_all)
2092 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2094 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2095 + for (i = 0; i < argc; i++) {
2096 + const char *target = argv[i];
2099 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2101 + for (j = 0; j < available_pkgs->len; j++) {
2102 + pkg_t *pkg = available_pkgs->pkgs[j];
2103 + if (fnmatch(target, pkg->name, 0) == 0) {
2105 + int count = pkg->depends_count + pkg->pre_depends_count;
2106 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2107 + target, pkg->architecture, rel_str);
2108 + for (k = 0; k < count; k++) {
2109 + compound_depend_t *cdepend = &pkg->depends[k];
2111 + for (l = 0; l < cdepend->possibility_count; l++) {
2112 + depend_t *possibility = cdepend->possibilities[l];
2113 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2114 + if (conf->verbosity > 0) {
2115 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2116 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2117 + if (possibility->version) {
2118 + char *typestr = NULL;
2119 + switch (possibility->constraint) {
2120 + case NONE: typestr = "none"; break;
2121 + case EARLIER: typestr = "<"; break;
2122 + case EARLIER_EQUAL: typestr = "<="; break;
2123 + case EQUAL: typestr = "="; break;
2124 + case LATER_EQUAL: typestr = ">="; break;
2125 + case LATER: typestr = ">"; break;
2127 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2131 + ipkg_message(conf, IPKG_ERROR, "\n");
2137 + pkg_vec_free(available_pkgs);
2142 +enum what_field_type {
2151 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2155 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2156 + const char *rel_str = NULL;
2160 + switch (what_field_type) {
2161 + case WHATDEPENDS: rel_str = "depends on"; break;
2162 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2163 + case WHATSUGGESTS: rel_str = "suggests"; break;
2164 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2165 + case WHATPROVIDES: rel_str = "provides"; break;
2166 + case WHATREPLACES: rel_str = "replaces"; break;
2169 + if (conf->query_all)
2170 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2172 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2174 + /* mark the root set */
2175 + pkg_vec_clear_marks(available_pkgs);
2176 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2177 + for (i = 0; i < argc; i++) {
2178 + const char *dependee_pattern = argv[i];
2179 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2181 + for (i = 0; i < available_pkgs->len; i++) {
2182 + pkg_t *pkg = available_pkgs->pkgs[i];
2183 + if (pkg->state_flag & SF_MARKED) {
2184 + /* mark the parent (abstract) package */
2185 + pkg_mark_provides(pkg);
2186 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2190 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2195 + for (j = 0; j < available_pkgs->len; j++) {
2196 + pkg_t *pkg = available_pkgs->pkgs[j];
2198 + int count = ((what_field_type == WHATCONFLICTS)
2199 + ? pkg->conflicts_count
2200 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2201 + /* skip this package if it is already marked */
2202 + if (pkg->parent->state_flag & SF_MARKED) {
2205 + for (k = 0; k < count; k++) {
2206 + compound_depend_t *cdepend =
2207 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2209 + for (l = 0; l < cdepend->possibility_count; l++) {
2210 + depend_t *possibility = cdepend->possibilities[l];
2211 + if (possibility->pkg->state_flag & SF_MARKED) {
2212 + /* mark the depending package so we won't visit it again */
2213 + pkg->state_flag |= SF_MARKED;
2214 + pkg_mark_provides(pkg);
2217 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2218 + if (conf->verbosity > 0) {
2219 + char *ver = pkg_version_str_alloc(pkg);
2220 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2221 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2222 + if (possibility->version) {
2223 + char *typestr = NULL;
2224 + switch (possibility->constraint) {
2225 + case NONE: typestr = "none"; break;
2226 + case EARLIER: typestr = "<"; break;
2227 + case EARLIER_EQUAL: typestr = "<="; break;
2228 + case EQUAL: typestr = "="; break;
2229 + case LATER_EQUAL: typestr = ">="; break;
2230 + case LATER: typestr = ">"; break;
2232 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2235 + if (!pkg_dependence_satisfiable(conf, possibility))
2236 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2238 + ipkg_message(conf, IPKG_NOTICE, "\n");
2239 + goto next_package;
2246 + } while (changed && recursive);
2247 + pkg_vec_free(available_pkgs);
2253 +int pkg_mark_provides(pkg_t *pkg)
2255 + int provides_count = pkg->provides_count;
2256 + abstract_pkg_t **provides = pkg->provides;
2258 + pkg->parent->state_flag |= SF_MARKED;
2259 + for (i = 0; i < provides_count; i++) {
2260 + provides[i]->state_flag |= SF_MARKED;
2265 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2267 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2269 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2271 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2274 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2276 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2279 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2281 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2284 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2286 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2289 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2293 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2294 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2297 + pkg_info_preinstall_check(conf);
2299 + if (conf->query_all)
2300 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2302 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2303 + for (i = 0; i < argc; i++) {
2304 + const char *target = argv[i];
2307 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2309 + for (j = 0; j < available_pkgs->len; j++) {
2310 + pkg_t *pkg = available_pkgs->pkgs[j];
2312 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2313 + for (k = 0; k < count; k++) {
2314 + abstract_pkg_t *apkg =
2315 + ((what_field_type == WHATPROVIDES)
2316 + ? pkg->provides[k]
2317 + : pkg->replaces[k]);
2318 + if (fnmatch(target, apkg->name, 0) == 0) {
2319 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2320 + if (strcmp(target, apkg->name) != 0)
2321 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2322 + ipkg_message(conf, IPKG_ERROR, "\n");
2327 + pkg_vec_free(available_pkgs);
2332 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2334 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2337 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2339 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2342 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2346 + pkg_vec_t *installed;
2348 + str_list_t *installed_files;
2349 + str_list_elt_t *iter;
2350 + char *installed_file;
2356 + installed = pkg_vec_alloc();
2357 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2359 + for (i=0; i < installed->len; i++) {
2360 + pkg = installed->pkgs[i];
2362 + installed_files = pkg_get_installed_files(pkg);
2364 + for (iter = installed_files->head; iter; iter = iter->next) {
2365 + installed_file = iter->data;
2366 + if (fnmatch(argv[0], installed_file, 0)==0) {
2368 + printf("%s: %s\n", pkg->name, installed_file);
2370 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2372 + pkg_version_str_alloc(pkg),
2373 + pkg->state_status, p_userdata);
2378 + pkg_free_installed_files(pkg);
2381 + /* XXX: CLEANUP: It's not obvious from the name of
2382 + pkg_hash_fetch_all_installed that we need to call
2383 + pkg_vec_free to avoid a memory leak. */
2384 + pkg_vec_free(installed);
2389 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2392 + /* this is a bit gross */
2393 + struct pkg p1, p2;
2394 + parseVersion(&p1, argv[0]);
2395 + parseVersion(&p2, argv[2]);
2396 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2398 + ipkg_message(conf, IPKG_ERROR,
2399 + "ipkg compare_versions <v1> <op> <v2>\n"
2400 + "<op> is one of <= >= << >> =\n");
2405 +#ifndef HOST_CPU_STR
2406 +#define HOST_CPU_STR__(X) #X
2407 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2408 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2411 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2413 + nv_pair_list_elt_t *l;
2415 + l = conf->arch_list.head;
2417 + nv_pair_t *nv = l->data;
2418 + printf("arch %s %s\n", nv->name, nv->value);
2425 Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.h
2426 ===================================================================
2427 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2428 +++ busybox-1.7.2/archival/libipkg/ipkg_cmd.h 2007-10-30 15:35:05.000000000 -0500
2430 +/* ipkg_cmd.h - the itsy package management system
2434 + Copyright (C) 2001 University of Southern California
2436 + This program is free software; you can redistribute it and/or
2437 + modify it under the terms of the GNU General Public License as
2438 + published by the Free Software Foundation; either version 2, or (at
2439 + your option) any later version.
2441 + This program is distributed in the hope that it will be useful, but
2442 + WITHOUT ANY WARRANTY; without even the implied warranty of
2443 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2444 + General Public License for more details.
2450 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2455 + int requires_args;
2456 + ipkg_cmd_fun_t fun;
2458 +typedef struct ipkg_cmd ipkg_cmd_t;
2460 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2462 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2463 + const char **argv, void *userdata);
2465 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2467 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2468 +/* install any packges with state_want == SW_INSTALL */
2469 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2470 +/* ensure that all dependences are satisfied */
2471 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2473 +int pkg_mark_provides(pkg_t *pkg);
2476 Index: busybox-1.7.2/archival/libipkg/ipkg_conf.c
2477 ===================================================================
2478 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2479 +++ busybox-1.7.2/archival/libipkg/ipkg_conf.c 2007-10-30 15:35:05.000000000 -0500
2481 +/* ipkg_conf.c - the itsy package management system
2485 + Copyright (C) 2001 University of Southern California
2487 + This program is free software; you can redistribute it and/or
2488 + modify it under the terms of the GNU General Public License as
2489 + published by the Free Software Foundation; either version 2, or (at
2490 + your option) any later version.
2492 + This program is distributed in the hope that it will be useful, but
2493 + WITHOUT ANY WARRANTY; without even the implied warranty of
2494 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2495 + General Public License for more details.
2501 +#include "ipkg_conf.h"
2503 +#include "xregex.h"
2504 +#include "sprintf_alloc.h"
2505 +#include "ipkg_conf.h"
2506 +#include "ipkg_message.h"
2507 +#include "file_util.h"
2508 +#include "str_util.h"
2509 +#include "xsystem.h"
2512 +ipkg_conf_t *global_conf;
2514 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2515 + pkg_src_list_t *pkg_src_list,
2516 + nv_pair_list_t *tmp_dest_nv_pair_list,
2517 + char **tmp_lists_dir);
2518 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2519 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2520 + const char *name, const char *value);
2521 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2522 + const char *default_dest_name);
2523 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2524 + pkg_src_list_t *nv_pair_list);
2525 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2526 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2528 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2530 + ipkg_option_t tmp[] = {
2531 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2532 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2533 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2534 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2535 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2536 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2537 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2538 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2539 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2540 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2541 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2542 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2543 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2544 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2545 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2546 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2547 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2548 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2549 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2550 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2551 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2555 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2556 + if ( options == NULL ){
2557 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2561 + memcpy(*options, tmp, sizeof(tmp));
2565 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2571 + *conf_str = strdup(arg_str);
2575 +static void ipkg_conf_free_string(char **conf_str)
2583 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2586 + char *tmp_dir_base;
2587 + nv_pair_list_t tmp_dest_nv_pair_list;
2588 + char * lists_dir =NULL;
2590 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2591 + char *pending_dir =NULL;
2593 + memset(conf, 0, sizeof(ipkg_conf_t));
2595 + pkg_src_list_init(&conf->pkg_src_list);
2597 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2598 + pkg_dest_list_init(&conf->pkg_dest_list);
2600 + nv_pair_list_init(&conf->arch_list);
2602 + conf->restrict_to_default_dest = 0;
2603 + conf->default_dest = NULL;
2606 + if (args->tmp_dir)
2607 + tmp_dir_base = args->tmp_dir;
2609 + tmp_dir_base = getenv("TMPDIR");
2610 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2611 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2612 + IPKG_CONF_TMP_DIR_SUFFIX);
2613 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2614 + if (conf->tmp_dir == NULL) {
2615 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2616 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2620 + conf->force_depends = 0;
2621 + conf->force_defaults = 0;
2622 + conf->force_overwrite = 0;
2623 + conf->force_downgrade = 0;
2624 + conf->force_reinstall = 0;
2625 + conf->force_space = 0;
2626 + conf->force_removal_of_essential_packages = 0;
2627 + conf->force_removal_of_dependent_packages = 0;
2629 + conf->verbose_wget = 0;
2630 + conf->offline_root = NULL;
2631 + conf->offline_root_pre_script_cmd = NULL;
2632 + conf->offline_root_post_script_cmd = NULL;
2633 + conf->multiple_providers = 0;
2634 + conf->verbosity = 1;
2635 + conf->noaction = 0;
2637 + conf->http_proxy = NULL;
2638 + conf->ftp_proxy = NULL;
2639 + conf->no_proxy = NULL;
2640 + conf->proxy_user = NULL;
2641 + conf->proxy_passwd = NULL;
2643 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2644 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2645 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2646 + lists_dir=(char *)malloc(1);
2647 + lists_dir[0]='\0';
2648 + if (args->conf_file) {
2649 + struct stat stat_buf;
2650 + err = stat(args->conf_file, &stat_buf);
2652 + if (ipkg_conf_parse_file(conf, args->conf_file,
2653 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2654 + /* Memory leakage from ipkg_conf_parse-file */
2660 + /* if (!lists_dir ){*/
2661 + if (strlen(lists_dir)<=1 ){
2662 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2663 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2666 + if (args->offline_root) {
2667 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2668 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2673 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2674 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2676 + conf->lists_dir = strdup(lists_dir);
2677 + conf->pending_dir = strdup(pending_dir);
2679 + if (args->offline_root)
2680 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2681 + memset(&globbuf, 0, sizeof(globbuf));
2682 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2685 + for (i = 0; i < globbuf.gl_pathc; i++) {
2686 + if (globbuf.gl_pathv[i])
2687 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2688 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2689 + /* Memory leakage from ipkg_conf_parse-file */
2694 + globfree(&globbuf);
2696 + /* if no architectures were defined, then default all, noarch, and host architecture */
2697 + if (nv_pair_list_empty(&conf->arch_list)) {
2698 + nv_pair_list_append(&conf->arch_list, "all", "1");
2699 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2700 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2703 + /* Even if there is no conf file, we'll need at least one dest. */
2704 + if (tmp_dest_nv_pair_list.head == NULL) {
2705 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2706 + IPKG_CONF_DEFAULT_DEST_NAME,
2707 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2710 + /* After parsing the file, set options from command-line, (so that
2711 + command-line arguments take precedence) */
2712 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2713 + really needs to be cleaned up. There is so much duplication
2714 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2715 + a pointer to args_t (which could then not be freed), rather
2716 + than duplicating every field here? */
2717 + if (args->force_depends) {
2718 + conf->force_depends = 1;
2720 + if (args->force_defaults) {
2721 + conf->force_defaults = 1;
2723 + if (args->force_overwrite) {
2724 + conf->force_overwrite = 1;
2726 + if (args->force_downgrade) {
2727 + conf->force_downgrade = 1;
2729 + if (args->force_reinstall) {
2730 + conf->force_reinstall = 1;
2732 + if (args->force_removal_of_dependent_packages) {
2733 + conf->force_removal_of_dependent_packages = 1;
2735 + if (args->force_removal_of_essential_packages) {
2736 + conf->force_removal_of_essential_packages = 1;
2738 + if (args->nodeps) {
2741 + if (args->noaction) {
2742 + conf->noaction = 1;
2744 + if (args->query_all) {
2745 + conf->query_all = 1;
2747 + if (args->verbose_wget) {
2748 + conf->verbose_wget = 1;
2750 + if (args->multiple_providers) {
2751 + conf->multiple_providers = 1;
2753 + if (args->verbosity != conf->verbosity) {
2754 + conf->verbosity = args->verbosity;
2757 + ipkg_conf_override_string(&conf->offline_root,
2758 + args->offline_root);
2759 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2760 + args->offline_root_pre_script_cmd);
2761 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2762 + args->offline_root_post_script_cmd);
2764 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2765 + read anything from there.
2767 + if ( !(args->nocheckfordirorfile)){
2768 + /* need to run load the source list before dest list -Jamey */
2769 + if ( !(args->noreadfeedsfile))
2770 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2772 + /* Now that we have resolved conf->offline_root, we can commit to
2773 + the directory names for the dests and load in all the package
2775 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2778 + err = ipkg_conf_set_default_dest(conf, args->dest);
2784 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2786 + free(pending_dir);
2791 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2793 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2795 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2796 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2797 + __FUNCTION__, conf->tmp_dir);
2801 + err = rmdir(conf->tmp_dir);
2803 + if (errno == ENOTEMPTY) {
2805 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2806 + err = xsystem(cmd);
2810 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2812 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2814 + free(conf->tmp_dir); /*XXX*/
2816 + pkg_src_list_deinit(&conf->pkg_src_list);
2817 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2818 + nv_pair_list_deinit(&conf->arch_list);
2819 + if (&conf->pkg_hash)
2820 + pkg_hash_deinit(&conf->pkg_hash);
2821 + if (&conf->file_hash)
2822 + hash_table_deinit(&conf->file_hash);
2823 + if (&conf->obs_file_hash)
2824 + hash_table_deinit(&conf->obs_file_hash);
2826 + ipkg_conf_free_string(&conf->offline_root);
2827 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2828 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2830 + if (conf->verbosity > 1) {
2832 + hash_table_t *hashes[] = {
2835 + &conf->obs_file_hash };
2836 + for (i = 0; i < 3; i++) {
2837 + hash_table_t *hash = hashes[i];
2839 + int n_conflicts = 0;
2841 + for (j = 0; j < hash->n_entries; j++) {
2843 + hash_entry_t *e = &hash->entries[j];
2846 + while (e && e->key) {
2853 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2854 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2855 + hash_table_deinit(hash);
2860 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2861 + const char *default_dest_name)
2863 + pkg_dest_list_elt_t *iter;
2866 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2867 + dest = iter->data;
2868 + if (strcmp(dest->name, default_dest_name) == 0) {
2869 + conf->default_dest = dest;
2870 + conf->restrict_to_default_dest = 1;
2875 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2880 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2882 + pkg_src_list_elt_t *iter;
2886 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2888 + if (src == NULL) {
2892 + sprintf_alloc(&list_file, "%s/%s",
2893 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2896 + if (file_exists(list_file)) {
2897 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2905 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2907 + nv_pair_list_elt_t *iter;
2908 + nv_pair_t *nv_pair;
2912 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2913 + nv_pair = iter->data;
2915 + if (conf->offline_root) {
2916 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2918 + root_dir = strdup(nv_pair->value);
2920 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2922 + if (dest == NULL) {
2925 + if (conf->default_dest == NULL) {
2926 + conf->default_dest = dest;
2928 + if (file_exists(dest->status_file_name)) {
2929 + pkg_hash_add_from_file(conf, dest->status_file_name,
2937 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2938 + pkg_src_list_t *pkg_src_list,
2939 + nv_pair_list_t *tmp_dest_nv_pair_list,
2942 + ipkg_option_t * options;
2943 + FILE *file = fopen(filename, "r");
2944 + regex_t valid_line_re, comment_re;
2945 +#define regmatch_size 12
2946 + regmatch_t regmatch[regmatch_size];
2948 + if (ipkg_init_options_array(conf, &options)<0)
2951 + if (file == NULL) {
2952 + fprintf(stderr, "%s: failed to open %s: %s\n",
2953 + __FUNCTION__, filename, strerror(errno));
2957 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2959 + xregcomp(&comment_re,
2960 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2962 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2967 + char *type, *name, *value, *extra;
2969 + line = file_read_line_alloc(file);
2971 + if (line == NULL) {
2977 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2981 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2983 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2984 + filename, line_num, line);
2988 + /* This has to be so ugly to deal with optional quotation marks */
2989 + if (regmatch[2].rm_so > 0) {
2990 + type = strndup(line + regmatch[2].rm_so,
2991 + regmatch[2].rm_eo - regmatch[2].rm_so);
2993 + type = strndup(line + regmatch[3].rm_so,
2994 + regmatch[3].rm_eo - regmatch[3].rm_so);
2996 + if (regmatch[5].rm_so > 0) {
2997 + name = strndup(line + regmatch[5].rm_so,
2998 + regmatch[5].rm_eo - regmatch[5].rm_so);
3000 + name = strndup(line + regmatch[6].rm_so,
3001 + regmatch[6].rm_eo - regmatch[6].rm_so);
3003 + if (regmatch[8].rm_so > 0) {
3004 + value = strndup(line + regmatch[8].rm_so,
3005 + regmatch[8].rm_eo - regmatch[8].rm_so);
3007 + value = strndup(line + regmatch[9].rm_so,
3008 + regmatch[9].rm_eo - regmatch[9].rm_so);
3011 + if (regmatch[11].rm_so > 0) {
3012 + extra = strndup (line + regmatch[11].rm_so,
3013 + regmatch[11].rm_eo - regmatch[11].rm_so);
3016 + /* We use the tmp_dest_nv_pair_list below instead of
3017 + conf->pkg_dest_list because we might encounter an
3018 + offline_root option later and that would invalidate the
3019 + directories we would have computed in
3020 + pkg_dest_list_init. (We do a similar thing with
3021 + tmp_src_nv_pair_list for sake of symmetry.) */
3022 + if (strcmp(type, "option") == 0) {
3023 + ipkg_conf_set_option(options, name, value);
3024 + } else if (strcmp(type, "src") == 0) {
3025 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3026 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3028 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3031 + } else if (strcmp(type, "src/gz") == 0) {
3032 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3033 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3035 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3038 + } else if (strcmp(type, "dest") == 0) {
3039 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3040 + } else if (strcmp(type, "lists_dir") == 0) {
3041 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3042 + if (*lists_dir == NULL) {
3043 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3047 + sprintf (*lists_dir,"%s",value);
3048 + } else if (strcmp(type, "arch") == 0) {
3049 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3051 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3052 + value = strdup("10");
3054 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3056 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3057 + "parameter: %s %s %s\n", type, name, value);
3073 + regfree(&comment_re);
3074 + regfree(&valid_line_re);
3080 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3081 + const char *name, const char *value)
3084 + while (options[i].name) {
3085 + if (strcmp(options[i].name, name) == 0) {
3086 + switch (options[i].type) {
3087 + case IPKG_OPT_TYPE_BOOL:
3088 + *((int *)options[i].value) = 1;
3090 + case IPKG_OPT_TYPE_INT:
3092 + *((int *)options[i].value) = atoi(value);
3095 + printf("%s: Option %s need an argument\n",
3096 + __FUNCTION__, name);
3099 + case IPKG_OPT_TYPE_STRING:
3101 + *((char **)options[i].value) = strdup(value);
3104 + printf("%s: Option %s need an argument\n",
3105 + __FUNCTION__, name);
3113 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3114 + __FUNCTION__, name, value);
3118 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3120 + pkg_dest_list_elt_t *iter;
3127 + if (conf->noaction)
3129 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3130 + dest = iter->data;
3131 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3132 + if (dest->status_file == NULL) {
3133 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3134 + __FUNCTION__, dest->status_file_name, strerror(errno));
3138 + all = pkg_vec_alloc();
3139 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3141 + for(i = 0; i < all->len; i++) {
3142 + pkg = all->pkgs[i];
3143 + /* We don't need most uninstalled packages in the status file */
3144 + if (pkg->state_status == SS_NOT_INSTALLED
3145 + && (pkg->state_want == SW_UNKNOWN
3146 + || pkg->state_want == SW_DEINSTALL
3147 + || pkg->state_want == SW_PURGE)) {
3151 + fprintf(stderr, "Null package\n");
3153 + if (pkg->dest == NULL) {
3154 + fprintf(stderr, "%s: ERROR: Can't write status for "
3155 + "package %s since it has a NULL dest\n",
3156 + __FUNCTION__, pkg->name);
3159 + if (pkg->dest->status_file) {
3160 + pkg_print_status(pkg, pkg->dest->status_file);
3164 + pkg_vec_free(all);
3166 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3167 + dest = iter->data;
3168 + if (dest->status_file) {
3169 + err = ferror(dest->status_file);
3170 + fclose(dest->status_file);
3171 + dest->status_file = NULL;
3173 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3175 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3176 + "retaining old %s\n", __FUNCTION__,
3177 + dest->status_file_tmp_name, dest->status_file_name);
3186 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3188 + char *root_filename;
3189 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3190 + return root_filename;
3192 Index: busybox-1.7.2/archival/libipkg/ipkg_conf.h
3193 ===================================================================
3194 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3195 +++ busybox-1.7.2/archival/libipkg/ipkg_conf.h 2007-10-30 15:35:05.000000000 -0500
3197 +/* ipkg_conf.h - the itsy package management system
3201 + Copyright (C) 2001 University of Southern California
3203 + This program is free software; you can redistribute it and/or
3204 + modify it under the terms of the GNU General Public License as
3205 + published by the Free Software Foundation; either version 2, or (at
3206 + your option) any later version.
3208 + This program is distributed in the hope that it will be useful, but
3209 + WITHOUT ANY WARRANTY; without even the implied warranty of
3210 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3211 + General Public License for more details.
3214 +#ifndef IPKG_CONF_H
3215 +#define IPKG_CONF_H
3217 +typedef struct ipkg_conf ipkg_conf_t;
3219 +#include "hash_table.h"
3223 +#include "pkg_hash.h"
3224 +#include "pkg_src_list.h"
3225 +#include "pkg_dest_list.h"
3226 +#include "nv_pair_list.h"
3228 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3229 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3230 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3231 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3233 +/* In case the config file defines no dest */
3234 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3235 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3237 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3241 + pkg_src_list_t pkg_src_list;
3242 + pkg_dest_list_t pkg_dest_list;
3243 + nv_pair_list_t arch_list;
3245 + int restrict_to_default_dest;
3246 + pkg_dest_t *default_dest;
3249 + const char *lists_dir;
3250 + const char *pending_dir;
3253 + int force_depends;
3254 + int force_defaults;
3255 + int force_overwrite;
3256 + int force_downgrade;
3257 + int force_reinstall;
3259 + int force_removal_of_dependent_packages;
3260 + int force_removal_of_essential_packages;
3261 + int nodeps; /* do not follow dependences */
3263 + int multiple_providers;
3264 + char *offline_root;
3265 + char *offline_root_pre_script_cmd;
3266 + char *offline_root_post_script_cmd;
3271 + /* proxy options */
3276 + char *proxy_passwd;
3278 + hash_table_t pkg_hash;
3279 + hash_table_t file_hash;
3280 + hash_table_t obs_file_hash;
3283 +enum ipkg_option_type {
3284 + IPKG_OPT_TYPE_BOOL,
3285 + IPKG_OPT_TYPE_INT,
3286 + IPKG_OPT_TYPE_STRING
3288 +typedef enum ipkg_option_type ipkg_option_type_t;
3290 +typedef struct ipkg_option ipkg_option_t;
3291 +struct ipkg_option {
3293 + const ipkg_option_type_t type;
3294 + const void *value;
3297 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3298 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3300 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3301 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3304 Index: busybox-1.7.2/archival/libipkg/ipkg_configure.c
3305 ===================================================================
3306 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3307 +++ busybox-1.7.2/archival/libipkg/ipkg_configure.c 2007-10-30 15:35:05.000000000 -0500
3309 +/* ipkg_configure.c - the itsy package management system
3313 + Copyright (C) 2001 University of Southern California
3315 + This program is free software; you can redistribute it and/or
3316 + modify it under the terms of the GNU General Public License as
3317 + published by the Free Software Foundation; either version 2, or (at
3318 + your option) any later version.
3320 + This program is distributed in the hope that it will be useful, but
3321 + WITHOUT ANY WARRANTY; without even the implied warranty of
3322 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3323 + General Public License for more details.
3328 +#include "ipkg_configure.h"
3330 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3334 + /* DPKG_INCOMPATIBILITY:
3335 + dpkg actually does some conffile handling here, rather than at the
3336 + end of ipkg_install(). Do we care? */
3337 + /* DPKG_INCOMPATIBILITY:
3338 + dpkg actually includes a version number to this script call */
3339 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3341 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3345 + ipkg_state_changed++;
3349 Index: busybox-1.7.2/archival/libipkg/ipkg_configure.h
3350 ===================================================================
3351 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3352 +++ busybox-1.7.2/archival/libipkg/ipkg_configure.h 2007-10-30 15:35:05.000000000 -0500
3354 +/* ipkg_configure.h - the itsy package management system
3358 + Copyright (C) 2001 University of Southern California
3360 + This program is free software; you can redistribute it and/or
3361 + modify it under the terms of the GNU General Public License as
3362 + published by the Free Software Foundation; either version 2, or (at
3363 + your option) any later version.
3365 + This program is distributed in the hope that it will be useful, but
3366 + WITHOUT ANY WARRANTY; without even the implied warranty of
3367 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3368 + General Public License for more details.
3371 +#ifndef IPKG_CONFIGURE_H
3372 +#define IPKG_CONFIGURE_H
3374 +#include "ipkg_conf.h"
3376 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3379 Index: busybox-1.7.2/archival/libipkg/ipkg_download.c
3380 ===================================================================
3381 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3382 +++ busybox-1.7.2/archival/libipkg/ipkg_download.c 2007-10-30 15:35:05.000000000 -0500
3384 +/* ipkg_download.c - the itsy package management system
3388 + Copyright (C) 2001 University of Southern California
3390 + This program is free software; you can redistribute it and/or
3391 + modify it under the terms of the GNU General Public License as
3392 + published by the Free Software Foundation; either version 2, or (at
3393 + your option) any later version.
3395 + This program is distributed in the hope that it will be useful, but
3396 + WITHOUT ANY WARRANTY; without even the implied warranty of
3397 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3398 + General Public License for more details.
3402 +#include "ipkg_download.h"
3403 +#include "ipkg_message.h"
3405 +#include "sprintf_alloc.h"
3406 +#include "xsystem.h"
3407 +#include "file_util.h"
3408 +#include "str_util.h"
3410 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3414 + char *src_basec = strdup(src);
3415 + char *src_base = basename(src_basec);
3416 + char *tmp_file_location;
3419 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3423 + if (str_starts_with(src, "file:")) {
3425 + const char *file_src = src + 5;
3426 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3427 + ret = file_copy(src + 5, dest_file_name);
3428 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3432 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3433 + err = unlink(tmp_file_location);
3434 + if (err && errno != ENOENT) {
3435 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3436 + __FUNCTION__, tmp_file_location, strerror(errno));
3437 + free(tmp_file_location);
3441 + if (conf->http_proxy) {
3442 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3443 + setenv("http_proxy", conf->http_proxy, 1);
3445 + if (conf->ftp_proxy) {
3446 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3447 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3449 + if (conf->no_proxy) {
3450 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3451 + setenv("no_proxy", conf->no_proxy, 1);
3454 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3455 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3456 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3457 + conf->proxy_user ? "--proxy-user=" : "",
3458 + conf->proxy_user ? conf->proxy_user : "",
3459 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3460 + conf->proxy_passwd ? conf->proxy_passwd : "",
3461 + conf->verbose_wget ? "" : "-q",
3464 + err = xsystem(cmd);
3467 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3468 + __FUNCTION__, err, cmd);
3470 + unlink(tmp_file_location);
3471 + free(tmp_file_location);
3478 + err = file_move(tmp_file_location, dest_file_name);
3480 + free(tmp_file_location);
3490 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3495 + if (pkg->src == NULL) {
3496 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3497 + pkg->name, pkg->parent->name);
3501 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3503 + /* XXX: BUG: The pkg->filename might be something like
3504 + "../../foo.ipk". While this is correct, and exactly what we
3505 + want to use to construct url above, here we actually need to
3506 + use just the filename part, without any directory. */
3507 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3509 + err = ipkg_download(conf, url, pkg->local_filename);
3516 + * Downloads file from url, installs in package database, return package name.
3518 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3526 + if (str_starts_with(url, "http://")
3527 + || str_starts_with(url, "ftp://")) {
3529 + char *file_basec = strdup(url);
3530 + char *file_base = basename(file_basec);
3532 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3533 + err = ipkg_download(conf, url, tmp_file);
3537 + err = pkg_init_from_file(pkg, tmp_file);
3540 + pkg->local_filename = strdup(tmp_file);
3545 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3546 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3548 + err = pkg_init_from_file(pkg, url);
3551 + pkg->local_filename = strdup(url);
3552 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3553 + pkg->provided_by_hand = 1;
3561 + if (!pkg->architecture) {
3562 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3566 + pkg->dest = conf->default_dest;
3567 + pkg->state_want = SW_INSTALL;
3568 + pkg->state_flag |= SF_PREFER;
3569 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3570 + if ( pkg == NULL ){
3571 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3575 + *namep = strdup(pkg->name);
3579 Index: busybox-1.7.2/archival/libipkg/ipkg_download.h
3580 ===================================================================
3581 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3582 +++ busybox-1.7.2/archival/libipkg/ipkg_download.h 2007-10-30 15:35:05.000000000 -0500
3584 +/* ipkg_download.h - the itsy package management system
3588 + Copyright (C) 2001 University of Southern California
3590 + This program is free software; you can redistribute it and/or
3591 + modify it under the terms of the GNU General Public License as
3592 + published by the Free Software Foundation; either version 2, or (at
3593 + your option) any later version.
3595 + This program is distributed in the hope that it will be useful, but
3596 + WITHOUT ANY WARRANTY; without even the implied warranty of
3597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3598 + General Public License for more details.
3601 +#ifndef IPKG_DOWNLOAD_H
3602 +#define IPKG_DOWNLOAD_H
3604 +#include "ipkg_conf.h"
3606 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3607 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3609 + * Downloads file from url, installs in package database, return package name.
3611 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3614 Index: busybox-1.7.2/archival/libipkg/ipkg.h
3615 ===================================================================
3616 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3617 +++ busybox-1.7.2/archival/libipkg/ipkg.h 2007-10-30 15:35:05.000000000 -0500
3619 +/* ipkg.h - the itsy package management system
3623 + Copyright (C) 2001 University of Southern California
3625 + This program is free software; you can redistribute it and/or
3626 + modify it under the terms of the GNU General Public License as
3627 + published by the Free Software Foundation; either version 2, or (at
3628 + your option) any later version.
3630 + This program is distributed in the hope that it will be useful, but
3631 + WITHOUT ANY WARRANTY; without even the implied warranty of
3632 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3633 + General Public License for more details.
3640 +#ifdef HAVE_CONFIG_H
3641 +#include "config.h"
3646 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3649 +#include "ipkg_includes.h"
3650 +#include "ipkg_conf.h"
3651 +#include "ipkg_message.h"
3653 +#define IPKG_PKG_EXTENSION ".ipk"
3654 +#define DPKG_PKG_EXTENSION ".deb"
3656 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3657 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3659 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3660 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3661 +#define IPKG_INFO_DIR_SUFFIX "info"
3662 +#define IPKG_STATUS_FILE_SUFFIX "status"
3664 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3666 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3668 +#define IPKG_VERSION "0.99.162"
3673 + IPKG_PKG_DEPS_UNSATISFIED,
3674 + IPKG_PKG_IS_ESSENTIAL,
3675 + IPKG_PKG_HAS_DEPENDENTS,
3676 + IPKG_PKG_HAS_NO_CANDIDATE
3678 +typedef enum ipkg_error ipkg_error_t;
3680 +extern int ipkg_state_changed;
3685 + struct errlist * next;
3688 +extern struct errlist* error_list;
3690 +extern ipkg_conf_t *global_conf;
3693 Index: busybox-1.7.2/archival/libipkg/ipkg_includes.h
3694 ===================================================================
3695 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3696 +++ busybox-1.7.2/archival/libipkg/ipkg_includes.h 2007-10-30 15:35:05.000000000 -0500
3698 +#ifndef IPKG_INCLUDES_H
3699 +#define IPKG_INCLUDES_H
3701 +/* Define to 1 if you have the <memory.h> header file. */
3702 +#define HAVE_MEMORY_H 1
3704 +/* Define to 1 if you have the <regex.h> header file. */
3705 +#define HAVE_REGEX_H 1
3707 +/* Define to 1 if you have the <stdlib.h> header file. */
3708 +#define HAVE_STDLIB_H 1
3710 +/* Define to 1 if you have the <strings.h> header file. */
3711 +#define HAVE_STRINGS_H 1
3713 +/* Define to 1 if you have the <string.h> header file. */
3714 +#define HAVE_STRING_H 1
3716 +/* Define to 1 if you have the <sys/stat.h> header file. */
3717 +#define HAVE_SYS_STAT_H 1
3719 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3720 +#define HAVE_SYS_WAIT_H 1
3722 +/* Define to 1 if you have the <unistd.h> header file. */
3723 +#define HAVE_UNISTD_H 1
3725 +/* Define to 1 if you have the ANSI C header files. */
3726 +#define STDC_HEADERS 1
3732 +# include <stdlib.h>
3733 +# include <stdarg.h>
3734 +# include <stddef.h>
3735 +# include <ctype.h>
3736 +# include <errno.h>
3739 +# include <stdlib.h>
3744 +# include <regex.h>
3748 +# if !STDC_HEADERS && HAVE_MEMORY_H
3749 +# include <memory.h>
3751 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3753 +# define __USE_GNU 1
3755 +# include <string.h>
3760 +# include <strings.h>
3763 +#if HAVE_SYS_STAT_H
3764 +# include <sys/stat.h>
3767 +#if HAVE_SYS_WAIT_H
3768 +# include <sys/wait.h>
3772 +# include <sys/types.h>
3773 +# include <unistd.h>
3776 +#endif /* IPKG_INCLUDES_H */
3777 Index: busybox-1.7.2/archival/libipkg/ipkg_install.c
3778 ===================================================================
3779 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3780 +++ busybox-1.7.2/archival/libipkg/ipkg_install.c 2007-10-30 15:35:05.000000000 -0500
3782 +/* ipkg_install.c - the itsy package management system
3786 + Copyright (C) 2001 University of Southern California
3788 + This program is free software; you can redistribute it and/or
3789 + modify it under the terms of the GNU General Public License as
3790 + published by the Free Software Foundation; either version 2, or (at
3791 + your option) any later version.
3793 + This program is distributed in the hope that it will be useful, but
3794 + WITHOUT ANY WARRANTY; without even the implied warranty of
3795 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3796 + General Public License for more details.
3801 +#include <dirent.h>
3804 +#include <signal.h>
3805 +typedef void (*sighandler_t)(int);
3808 +#include "pkg_hash.h"
3809 +#include "pkg_extract.h"
3811 +#include "ipkg_install.h"
3812 +#include "ipkg_configure.h"
3813 +#include "ipkg_download.h"
3814 +#include "ipkg_remove.h"
3816 +#include "ipkg_utils.h"
3817 +#include "ipkg_message.h"
3819 +#include "sprintf_alloc.h"
3820 +#include "file_util.h"
3821 +#include "str_util.h"
3822 +#include "xsystem.h"
3825 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3826 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3827 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3829 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3830 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3831 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3832 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3833 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3834 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3835 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3836 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3837 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3843 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3846 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3847 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3849 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3851 +static int user_prefers_old_conffile(const char *file, const char *backup);
3853 +static char *backup_filename_alloc(const char *file_name);
3854 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3855 +static int backup_exists_for(const char *file_name);
3856 +static int backup_remove(const char *file_name);
3859 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3863 + char *old_version, *new_version;
3866 + if (pkg == NULL) {
3870 + err = pkg_init_from_file(pkg, filename);
3875 + if (!pkg->architecture) {
3876 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3880 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3881 + freeing the pkg that we pass in. It might be nice to clean this up
3883 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3884 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3886 + pkg->local_filename = strdup(filename);
3889 + old_version = pkg_version_str_alloc(old);
3890 + new_version = pkg_version_str_alloc(pkg);
3892 + cmp = pkg_compare_versions(old, pkg);
3893 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3894 + cmp = -1 ; /* then we force ipkg to downgrade */
3895 + /* We need to use a value < 0 because in the 0 case we are asking to */
3896 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3899 + ipkg_message(conf, IPKG_NOTICE,
3900 + "Not downgrading package %s on %s from %s to %s.\n",
3901 + old->name, old->dest->name, old_version, new_version);
3902 + pkg->state_want = SW_DEINSTALL;
3903 + pkg->state_flag |= SF_OBSOLETE;
3904 + free(old_version);
3905 + free(new_version);
3908 + free(old_version);
3909 + free(new_version);
3913 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3914 + return ipkg_install_pkg(conf, pkg,0);
3917 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3921 + char *old_version, *new_version;
3923 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3924 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3926 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3928 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3929 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3931 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3933 +/* Pigi Basically here is broken the version stuff.
3934 + What's happening is that nothing provide the version to differents
3935 + functions, so the returned struct is always the latest.
3936 + That's why the install by name don't work.
3938 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3941 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3943 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3944 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3946 + if (new == NULL) {
3947 + return IPKG_PKG_HAS_NO_CANDIDATE;
3950 + new->state_flag |= SF_USER;
3952 + old_version = pkg_version_str_alloc(old);
3953 + new_version = pkg_version_str_alloc(new);
3955 + cmp = pkg_compare_versions(old, new);
3956 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3957 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3958 + cmp = -1 ; /* then we force ipkg to downgrade */
3959 + /* We need to use a value < 0 because in the 0 case we are asking to */
3960 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3962 + ipkg_message(conf, IPKG_DEBUG,
3963 + "Comparing visible versions of pkg %s:"
3964 + "\n\t%s is installed "
3965 + "\n\t%s is available "
3966 + "\n\t%d was comparison result\n",
3967 + pkg_name, old_version, new_version, cmp);
3968 + if (cmp == 0 && !conf->force_reinstall) {
3969 + ipkg_message(conf, IPKG_NOTICE,
3970 + "Package %s (%s) installed in %s is up to date.\n",
3971 + old->name, old_version, old->dest->name);
3972 + free(old_version);
3973 + free(new_version);
3975 + } else if (cmp > 0) {
3976 + ipkg_message(conf, IPKG_NOTICE,
3977 + "Not downgrading package %s on %s from %s to %s.\n",
3978 + old->name, old->dest->name, old_version, new_version);
3979 + free(old_version);
3980 + free(new_version);
3982 + } else if (cmp < 0) {
3983 + new->dest = old->dest;
3984 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3988 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3989 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3990 + return any kind of integer, (might be errno from a syscall,
3991 + etc.). This is a real mess and will need to be cleaned up if
3992 + anyone ever wants to make a nice libipkg. */
3994 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3995 + return ipkg_install_pkg(conf, new,0);
3998 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4000 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4003 + abstract_pkg_t *ppkg ;
4005 + if (providers == NULL)
4006 + return IPKG_PKG_HAS_NO_CANDIDATE;
4008 + for (i = 0; i < providers->len; i++) {
4009 + ppkg = abstract_pkg_vec_get(providers, i);
4010 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4011 + err = ipkg_install_by_name(conf, ppkg->name);
4014 +/* XXX Maybe ppkg should be freed ? */
4020 + * Walk dependence graph starting with pkg, collect packages to be
4021 + * installed into pkgs_needed, in dependence order.
4023 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4026 + pkg_vec_t *depends = pkg_vec_alloc();
4027 + char **unresolved = NULL;
4030 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4035 + ipkg_message(conf, IPKG_ERROR,
4036 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4037 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4038 + while (*unresolved) {
4039 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4042 + ipkg_message(conf, IPKG_ERROR, "\n");
4043 + if (! conf->force_depends) {
4044 + ipkg_message(conf, IPKG_INFO,
4045 + "This could mean that your package list is out of date or that the packages\n"
4046 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4047 + "of this problem try again with the '-force-depends' option.\n");
4048 + pkg_vec_free(depends);
4049 + return IPKG_PKG_DEPS_UNSATISFIED;
4053 + if (ndepends <= 0) {
4054 + pkg_vec_free(depends);
4058 + for (i = 0; i < depends->len; i++) {
4059 + pkg_t *dep = depends->pkgs[i];
4060 + /* The package was uninstalled when we started, but another
4061 + dep earlier in this loop may have depended on it and pulled
4062 + it in, so check first. */
4063 + if ((dep->state_status != SS_INSTALLED)
4064 + && (dep->state_status != SS_UNPACKED)
4065 + && (dep->state_want != SW_INSTALL)) {
4067 + /* Mark packages as to-be-installed */
4068 + dep->state_want = SW_INSTALL;
4070 + /* Dependencies should be installed the same place as pkg */
4071 + if (dep->dest == NULL) {
4072 + dep->dest = pkg->dest;
4075 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4077 + pkg_vec_free(depends);
4083 + pkg_vec_insert(pkgs_needed, pkg);
4085 + pkg_vec_free(depends);
4090 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4094 + char *old_version, *new_version;
4096 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4098 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4099 + if (new == NULL) {
4100 + return IPKG_PKG_HAS_NO_CANDIDATE;
4103 + old_version = pkg_version_str_alloc(old);
4104 + new_version = pkg_version_str_alloc(new);
4106 + cmp = pkg_compare_versions(old, new);
4107 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4108 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4109 + cmp = -1 ; /* then we force ipkg to downgrade */
4110 + /* We need to use a value < 0 because in the 0 case we are asking to */
4111 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4113 + ipkg_message(conf, IPKG_DEBUG,
4114 + "comparing visible versions of pkg %s:"
4115 + "\n\t%s is installed "
4116 + "\n\t%s is available "
4117 + "\n\t%d was comparison result\n",
4118 + pkg_name, old_version, new_version, cmp);
4119 + if (cmp == 0 && !conf->force_reinstall) {
4120 + ipkg_message(conf, IPKG_NOTICE,
4121 + "Package %s (%s) installed in %s is up to date.\n",
4122 + old->name, old_version, old->dest->name);
4123 + free(old_version);
4124 + free(new_version);
4126 + } else if (cmp > 0) {
4127 + ipkg_message(conf, IPKG_NOTICE,
4128 + "Not downgrading package %s on %s from %s to %s.\n",
4129 + old->name, old->dest->name, old_version, new_version);
4130 + free(old_version);
4131 + free(new_version);
4133 + } else if (cmp < 0) {
4134 + new->dest = old->dest;
4135 + old->state_want = SW_DEINSTALL;
4136 + old->state_flag |= SF_OBSOLETE;
4139 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4144 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4147 + pkg_vec_t *depends = pkg_vec_alloc();
4149 + char **unresolved = NULL;
4152 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4157 + ipkg_message(conf, IPKG_ERROR,
4158 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4159 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4160 + while (*unresolved) {
4161 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4164 + ipkg_message(conf, IPKG_ERROR, "\n");
4165 + if (! conf->force_depends) {
4166 + ipkg_message(conf, IPKG_INFO,
4167 + "This could mean that your package list is out of date or that the packages\n"
4168 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4169 + "of this problem try again with the '-force-depends' option.\n");
4170 + pkg_vec_free(depends);
4171 + return IPKG_PKG_DEPS_UNSATISFIED;
4175 + if (ndepends <= 0) {
4179 + /* Mark packages as to-be-installed */
4180 + for (i=0; i < depends->len; i++) {
4181 + /* Dependencies should be installed the same place as pkg */
4182 + if (depends->pkgs[i]->dest == NULL) {
4183 + depends->pkgs[i]->dest = pkg->dest;
4185 + depends->pkgs[i]->state_want = SW_INSTALL;
4188 + for (i = 0; i < depends->len; i++) {
4189 + dep = depends->pkgs[i];
4190 + /* The package was uninstalled when we started, but another
4191 + dep earlier in this loop may have depended on it and pulled
4192 + it in, so check first. */
4193 + if ((dep->state_status != SS_INSTALLED)
4194 + && (dep->state_status != SS_UNPACKED)) {
4195 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4196 + err = ipkg_install_pkg(conf, dep,0);
4198 + pkg_vec_free(depends);
4204 + pkg_vec_free(depends);
4210 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4211 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4213 + if (conf->nodeps == 0) {
4215 + pkg_vec_t *installed = pkg_vec_alloc();
4216 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4217 + for (i = 0; i < installed->len; i++) {
4218 + pkg_t *pkg = installed->pkgs[i];
4219 + satisfy_dependencies_for(conf, pkg);
4221 + pkg_vec_free(installed);
4228 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4231 + pkg_vec_t *conflicts = NULL;
4233 + const char *prefix;
4234 + if (conf->force_depends) {
4235 + level = IPKG_NOTICE;
4236 + prefix = "Warning";
4238 + level = IPKG_ERROR;
4242 + if (!conf->force_depends)
4243 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4246 + ipkg_message(conf, level,
4247 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4249 + while (i < conflicts->len)
4250 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4251 + ipkg_message(conf, level, "\n");
4252 + pkg_vec_free(conflicts);
4253 + return IPKG_PKG_DEPS_UNSATISFIED;
4258 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4260 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4261 + str_list_elt_t *iter;
4263 + for (iter = new_list->head; iter; iter = iter->next) {
4264 + char *new_file = iter->data;
4265 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4267 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4268 + if (!owner || (owner == old_pkg))
4269 + file_hash_set_file_owner(conf, new_file, new_pkg);
4272 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4273 + for (iter = old_list->head; iter; iter = iter->next) {
4274 + char *old_file = iter->data;
4275 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4276 + if (owner == old_pkg) {
4278 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4285 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4287 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4289 + /* sma 6.20.02: yup; here's the first bit */
4291 + * XXX: BUG easy for cworth
4292 + * 1) please point the call below to the correct current root destination
4293 + * 2) we need to resolve how to check the required space for a pending pkg,
4294 + * my diddling with the .ipk file size below isn't going to cut it.
4295 + * 3) return a proper error code instead of 1
4297 + int comp_size, blocks_available;
4299 + if (!conf->force_space && pkg->installed_size != NULL) {
4300 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4302 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4303 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4304 + comp_size = (int)((comp_size + 1023) / 1024);
4306 + if (comp_size >= blocks_available) {
4307 + ipkg_message(conf, IPKG_ERROR,
4308 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4309 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4316 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4319 + char *conffiles_file_name;
4321 + FILE *conffiles_file;
4323 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4325 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4326 + if (pkg->tmp_unpack_dir == NULL) {
4327 + ipkg_message(conf, IPKG_ERROR,
4328 + "%s: Failed to create temporary directory '%s': %s\n",
4329 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4333 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4338 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4339 + conffiles. Seems like I should be able to get everything to go
4340 + through pkg_init_from_file. If so, maybe it would make sense to
4341 + move all of unpack_pkg_control_files to that function. */
4343 + /* Don't need to re-read conffiles if we already have it */
4344 + if (pkg->conffiles.head) {
4348 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4349 + if (! file_exists(conffiles_file_name)) {
4350 + free(conffiles_file_name);
4354 + conffiles_file = fopen(conffiles_file_name, "r");
4355 + if (conffiles_file == NULL) {
4356 + fprintf(stderr, "%s: failed to open %s: %s\n",
4357 + __FUNCTION__, conffiles_file_name, strerror(errno));
4358 + free(conffiles_file_name);
4361 + free(conffiles_file_name);
4365 + char *cf_name_in_dest;
4367 + cf_name = file_read_line_alloc(conffiles_file);
4368 + if (cf_name == NULL) {
4371 + str_chomp(cf_name);
4372 + if (cf_name[0] == '\0') {
4376 + /* Prepend dest->root_dir to conffile name.
4377 + Take pains to avoid multiple slashes. */
4378 + root_dir = pkg->dest->root_dir;
4379 + if (conf->offline_root)
4380 + /* skip the offline_root prefix */
4381 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4382 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4383 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4385 + /* Can't get an md5sum now, (file isn't extracted yet).
4386 + We'll wait until resolve_conffiles */
4387 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4390 + free(cf_name_in_dest);
4393 + fclose(conffiles_file);
4398 +/* returns number of installed replacees */
4399 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4401 + abstract_pkg_t **replaces = pkg->replaces;
4402 + int replaces_count = pkg->replaces_count;
4404 + for (i = 0; i < replaces_count; i++) {
4405 + abstract_pkg_t *ab_pkg = replaces[i];
4406 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4408 + for (j = 0; j < pkg_vec->len; j++) {
4409 + pkg_t *replacee = pkg_vec->pkgs[j];
4410 + if (!pkg_conflicts(pkg, replacee))
4412 + if (replacee->state_status == SS_INSTALLED) {
4413 + pkg_vec_insert(installed_replacees, replacee);
4418 + return installed_replacees->len;
4421 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4424 + int replaces_count = replacees->len;
4425 + for (i = 0; i < replaces_count; i++) {
4426 + pkg_t *replacee = replacees->pkgs[i];
4428 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4429 + err = ipkg_remove_pkg(conf, replacee,0);
4436 +/* to unwind the removal: make sure they are installed */
4437 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4440 + int replaces_count = replacees->len;
4441 + for (i = 0; i < replaces_count; i++) {
4442 + pkg_t *replacee = replacees->pkgs[i];
4443 + if (replacee->state_status != SS_INSTALLED) {
4444 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4445 + err = ipkg_install_pkg(conf, replacee,0);
4453 +int caught_sigint = 0;
4454 +static void ipkg_install_pkg_sigint_handler(int sig)
4456 + caught_sigint = sig;
4459 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4460 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4463 + char message_out[15];
4464 + char *old_version = pkg_version_str_alloc(old_pkg);
4465 + char *new_version = pkg_version_str_alloc(pkg);
4466 + int cmp = pkg_compare_versions(old_pkg, pkg);
4469 + memset(message_out,'\x0',15);
4470 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4471 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4472 + cmp = -1 ; /* then we force ipkg to downgrade */
4473 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4474 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4478 + ipkg_message(conf, IPKG_NOTICE,
4479 + "Not downgrading package %s on %s from %s to %s.\n",
4480 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4482 + } else if (cmp < 0) {
4483 + ipkg_message(conf, IPKG_NOTICE,
4484 + "%s%s on %s from %s to %s...\n",
4485 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4486 + pkg->dest = old_pkg->dest;
4488 + } else /* cmp == 0 */ {
4489 + if (conf->force_reinstall) {
4490 + ipkg_message(conf, IPKG_NOTICE,
4491 + "Reinstalling %s (%s) on %s...\n",
4492 + pkg->name, new_version, old_pkg->dest->name);
4493 + pkg->dest = old_pkg->dest;
4496 + ipkg_message(conf, IPKG_NOTICE,
4497 + "Not installing %s (%s) on %s -- already installed.\n",
4498 + pkg->name, new_version, old_pkg->dest->name);
4502 + free(old_version);
4503 + free(new_version);
4506 + char message_out[15], *version ;
4507 + memset(message_out,'\x0',15);
4509 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4511 + strncpy( message_out,"Installing ",strlen("Installing ") );
4512 + version = pkg_version_str_alloc(pkg);
4514 + ipkg_message(conf, IPKG_NOTICE,
4515 + "%s%s (%s) to %s...\n", message_out,
4516 + pkg->name, version, pkg->dest->name);
4522 +/* and now the meat... */
4523 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4527 + pkg_t *old_pkg = NULL;
4528 + pkg_vec_t *replacees;
4529 + abstract_pkg_t *ab_pkg = NULL;
4530 + int old_state_flag;
4534 + if ( from_upgrade )
4535 + message = 1; /* Coming from an upgrade, and should change the output message */
4538 + ipkg_message(conf, IPKG_ERROR,
4539 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4543 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4545 + if (!pkg_arch_supported(conf, pkg)) {
4546 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4547 + pkg->architecture, pkg->name);
4550 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4551 + err = satisfy_dependencies_for(conf, pkg);
4552 + if (err) { return err; }
4554 + ipkg_message(conf, IPKG_NOTICE,
4555 + "Package %s is already installed in %s.\n",
4556 + pkg->name, pkg->dest->name);
4560 + if (pkg->dest == NULL) {
4561 + pkg->dest = conf->default_dest;
4564 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4566 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4567 + if (err) { return err; }
4569 + pkg->state_want = SW_INSTALL;
4571 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4575 + /* Abhaya: conflicts check */
4576 + err = check_conflicts_for(conf, pkg);
4577 + if (err) { return err; }
4579 + /* this setup is to remove the upgrade scenario in the end when
4580 + installing pkg A, A deps B & B deps on A. So both B and A are
4581 + installed. Then A's installation is started resulting in an
4582 + uncecessary upgrade */
4583 + if (pkg->state_status == SS_INSTALLED
4584 + && conf->force_reinstall == 0) return 0;
4586 + err = verify_pkg_installable(conf, pkg);
4587 + if (err) { return err; }
4589 + if (pkg->local_filename == NULL) {
4590 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4592 + ipkg_message(conf, IPKG_ERROR,
4593 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4599 +/* Check for md5 values */
4602 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4603 + if (strcmp(file_md5, pkg->md5sum))
4605 + ipkg_message(conf, IPKG_ERROR,
4606 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4614 + if (pkg->tmp_unpack_dir == NULL) {
4615 + unpack_pkg_control_files(conf, pkg);
4618 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4619 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4620 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4621 + err = update_file_ownership(conf, pkg, old_pkg);
4622 + if (err) { return err; }
4624 + if (conf->nodeps == 0) {
4625 + err = satisfy_dependencies_for(conf, pkg);
4626 + if (err) { return err; }
4629 + replacees = pkg_vec_alloc();
4630 + pkg_get_installed_replacees(conf, pkg, replacees);
4632 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4634 + sigset_t newset, oldset;
4635 + sighandler_t old_handler = NULL;
4636 + int use_signal = 0;
4637 + caught_sigint = 0;
4639 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4641 + sigemptyset(&newset);
4642 + sigaddset(&newset, SIGINT);
4643 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4646 + ipkg_state_changed++;
4647 + pkg->state_flag |= SF_FILELIST_CHANGED;
4649 + /* XXX: BUG: we really should treat replacement more like an upgrade
4650 + * Instead, we're going to remove the replacees
4652 + err = pkg_remove_installed_replacees(conf, replacees);
4653 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4655 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4656 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4658 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4659 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4661 + err = preinst_configure(conf, pkg, old_pkg);
4662 + if (err) goto UNWIND_PREINST_CONFIGURE;
4664 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4665 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4667 + err = check_data_file_clashes(conf, pkg, old_pkg);
4668 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4670 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4673 + if (conf->noaction) return 0;
4675 + /* point of no return: no unwinding after this */
4676 + if (old_pkg && !conf->force_reinstall) {
4677 + old_pkg->state_want = SW_DEINSTALL;
4679 + if (old_pkg->state_flag & SF_NOPRUNE) {
4680 + ipkg_message(conf, IPKG_INFO,
4681 + " not removing obsolesced files because package marked noprune\n");
4683 + ipkg_message(conf, IPKG_INFO,
4684 + " removing obsolesced files\n");
4685 + remove_obsolesced_files(conf, pkg, old_pkg);
4687 + /* removing files from old package, to avoid ghost files */
4688 + remove_data_files_and_list(conf, old_pkg);
4689 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4690 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4691 + remove_postrm(conf, old_pkg);
4697 + ipkg_message(conf, IPKG_INFO,
4698 + " installing maintainer scripts\n");
4699 + install_maintainer_scripts(conf, pkg, old_pkg);
4701 + /* the following just returns 0 */
4702 + remove_disappeared(conf, pkg);
4704 + ipkg_message(conf, IPKG_INFO,
4705 + " installing data files\n");
4706 + install_data_files(conf, pkg);
4708 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4709 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4711 + ipkg_message(conf, IPKG_INFO,
4712 + " resolving conf files\n");
4713 + resolve_conffiles(conf, pkg);
4715 + pkg->state_status = SS_UNPACKED;
4716 + old_state_flag = pkg->state_flag;
4717 + pkg->state_flag &= ~SF_PREFER;
4718 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4720 + if (old_pkg && !conf->force_reinstall) {
4721 + old_pkg->state_status = SS_NOT_INSTALLED;
4724 + time(&pkg->installed_time);
4726 + ipkg_message(conf, IPKG_INFO,
4727 + " cleanup temp files\n");
4728 + cleanup_temporary_files(conf, pkg);
4730 + ab_pkg = pkg->parent;
4732 + ab_pkg->state_status = pkg->state_status;
4734 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4737 + signal(SIGINT, old_handler);
4739 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4744 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4745 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4746 + UNWIND_CHECK_DATA_FILE_CLASHES:
4747 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4748 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4749 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4750 + UNWIND_PREINST_CONFIGURE:
4751 + preinst_configure_unwind(conf, pkg, old_pkg);
4752 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4753 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4754 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4755 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4756 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4757 + pkg_remove_installed_replacees_unwind(conf, replacees);
4759 + ipkg_message(conf, IPKG_INFO,
4760 + " cleanup temp files\n");
4761 + cleanup_temporary_files(conf, pkg);
4763 + ipkg_message(conf, IPKG_INFO,
4766 + signal(SIGINT, old_handler);
4768 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4774 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4776 + /* DPKG_INCOMPATIBILITY:
4777 + dpkg does some things here that we don't do yet. Do we care?
4779 + 1. If a version of the package is already installed, call
4780 + old-prerm upgrade new-version
4781 + 2. If the script runs but exits with a non-zero exit status
4782 + new-prerm failed-upgrade old-version
4783 + Error unwind, for both the above cases:
4784 + old-postinst abort-upgrade new-version
4789 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4793 + (See prerm_upgrade_old_package for details)
4798 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4800 + /* DPKG_INCOMPATIBILITY:
4801 + dpkg does some things here that we don't do yet. Do we care?
4802 + 2. If a 'conflicting' package is being removed at the same time:
4803 + 1. If any packages depended on that conflicting package and
4804 + --auto-deconfigure is specified, call, for each such package:
4805 + deconfigured's-prerm deconfigure \
4806 + in-favour package-being-installed version \
4807 + removing conflicting-package version
4809 + deconfigured's-postinst abort-deconfigure \
4810 + in-favour package-being-installed-but-failed version \
4811 + removing conflicting-package version
4813 + The deconfigured packages are marked as requiring
4814 + configuration, so that if --install is used they will be
4815 + configured again if possible.
4816 + 2. To prepare for removal of the conflicting package, call:
4817 + conflictor's-prerm remove in-favour package new-version
4819 + conflictor's-postinst abort-remove in-favour package new-version
4824 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4826 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4827 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4832 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4835 + char *preinst_args;
4838 + char *old_version = pkg_version_str_alloc(old_pkg);
4839 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4840 + free(old_version);
4841 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4842 + char *pkg_version = pkg_version_str_alloc(pkg);
4843 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4844 + free(pkg_version);
4846 + preinst_args = strdup("install");
4849 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4851 + ipkg_message(conf, IPKG_ERROR,
4852 + "Aborting installation of %s\n", pkg->name);
4856 + free(preinst_args);
4861 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4863 + /* DPKG_INCOMPATIBILITY:
4864 + dpkg does the following error unwind, should we?
4865 + pkg->postrm abort-upgrade old-version
4866 + OR pkg->postrm abort-install old-version
4867 + OR pkg->postrm abort-install
4872 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4875 + conffile_list_elt_t *iter;
4878 + if (conf->noaction) return 0;
4880 + /* Backup all modified conffiles */
4882 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4886 + cf_name = root_filename_alloc(conf, cf->name);
4888 + /* Don't worry if the conffile is just plain gone */
4889 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4890 + err = backup_make_backup(conf, cf_name);
4899 + /* Backup all conffiles that were not conffiles in old_pkg */
4900 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4903 + cf_name = root_filename_alloc(conf, cf->name);
4904 + /* Ignore if this was a conffile in old_pkg as well */
4905 + if (pkg_get_conffile(old_pkg, cf->name)) {
4909 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4910 + err = backup_make_backup(conf, cf_name);
4921 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4923 + conffile_list_elt_t *iter;
4926 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4927 + backup_remove(iter->data->name);
4931 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4932 + backup_remove(iter->data->name);
4939 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4941 + /* DPKG_INCOMPATIBILITY:
4942 + ipkg takes a slightly different approach than dpkg at this
4943 + point. dpkg installs each file in the new package while
4944 + creating a backup for any file that is replaced, (so that it
4945 + can unwind if necessary). To avoid complexity and redundant
4946 + storage, ipkg doesn't do any installation until later, (at the
4947 + point at which dpkg removes the backups.
4949 + But, we do have to check for data file clashes, since after
4950 + installing a package with a file clash, removing either of the
4951 + packages involved in the clash has the potential to break the
4954 + str_list_t *files_list;
4955 + str_list_elt_t *iter;
4959 + files_list = pkg_get_installed_files(pkg);
4960 + for (iter = files_list->head; iter; iter = iter->next) {
4961 + char *root_filename;
4962 + char *filename = iter->data;
4963 + root_filename = root_filename_alloc(conf, filename);
4964 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4967 + /* Pre-existing conffiles are OK */
4968 + /* @@@@ should have way to check that it is a conffile -Jamey */
4969 + if (backup_exists_for(root_filename)) {
4973 + /* Pre-existing files are OK if force-overwrite was asserted. */
4974 + if (conf->force_overwrite) {
4975 + /* but we need to change who owns this file */
4976 + file_hash_set_file_owner(conf, filename, pkg);
4980 + owner = file_hash_get_file_owner(conf, filename);
4982 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4983 + if (owner && old_pkg) {
4984 + if (strcmp(owner->name, old_pkg->name) == 0) {
4989 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4991 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4992 + if (pkg_replaces(pkg, owner)) {
4995 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4996 + then it's ok to overwrite. */
4997 + if (strcmp(owner->name,pkg->name)==0){
4998 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5003 + /* Pre-existing files are OK if they are obsolete */
5004 + obs = hash_table_get(&conf->obs_file_hash, filename);
5006 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5010 + /* We have found a clash. */
5011 + ipkg_message(conf, IPKG_ERROR,
5012 + "Package %s wants to install file %s\n"
5013 + "\tBut that file is already provided by package ",
5014 + pkg->name, filename);
5016 + ipkg_message(conf, IPKG_ERROR,
5017 + "%s\n", owner->name);
5019 + ipkg_message(conf, IPKG_ERROR,
5020 + "<no package>\nPlease move this file out of the way and try again.\n");
5024 + free(root_filename);
5026 + pkg_free_installed_files(pkg);
5031 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5033 + /* Basically that's the worst hack I could do to be able to change ownership of
5034 + file list, but, being that we have no way to unwind the mods, due to structure
5035 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5036 + What we do here is change the ownership of file in hash if a replace ( or similar events
5038 + Only the action that are needed to change name should be considered.
5039 + @@@ To change after 1.0 release.
5041 + str_list_t *files_list;
5042 + str_list_elt_t *iter;
5046 + files_list = pkg_get_installed_files(pkg);
5047 + for (iter = files_list->head; iter; iter = iter->next) {
5048 + char *root_filename;
5049 + char *filename = iter->data;
5050 + root_filename = root_filename_alloc(conf, filename);
5051 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5054 + if (conf->force_overwrite) {
5055 + /* but we need to change who owns this file */
5056 + file_hash_set_file_owner(conf, filename, pkg);
5060 + owner = file_hash_get_file_owner(conf, filename);
5062 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5064 + if (pkg_replaces(pkg, owner)) {
5065 +/* It's now time to change the owner of that file.
5066 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5067 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5068 + file_hash_set_file_owner(conf, filename, pkg);
5074 + free(root_filename);
5076 + pkg_free_installed_files(pkg);
5081 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5083 + /* Nothing to do since check_data_file_clashes doesn't change state */
5087 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5089 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5090 + 1. If the package is being upgraded, call
5091 + old-postrm upgrade new-version
5092 + 2. If this fails, attempt:
5093 + new-postrm failed-upgrade old-version
5094 + Error unwind, for both cases:
5095 + old-preinst abort-upgrade new-version */
5099 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5101 + /* DPKG_INCOMPATIBILITY:
5102 + dpkg does some things here that we don't do yet. Do we care?
5103 + (See postrm_upgrade_old_pkg for details)
5108 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5111 + str_list_t *old_files;
5112 + str_list_elt_t *of;
5113 + str_list_t *new_files;
5114 + str_list_elt_t *nf;
5116 + if (old_pkg == NULL) {
5120 + old_files = pkg_get_installed_files(old_pkg);
5121 + new_files = pkg_get_installed_files(pkg);
5123 + for (of = old_files->head; of; of = of->next) {
5127 + for (nf = new_files->head; nf; nf = nf->next) {
5129 + if (strcmp(old, new) == 0) {
5130 + goto NOT_OBSOLETE;
5133 + if (file_is_dir(old)) {
5136 + owner = file_hash_get_file_owner(conf, old);
5137 + if (owner != old_pkg) {
5138 + /* in case obsolete file no longer belongs to old_pkg */
5142 + /* old file is obsolete */
5143 + ipkg_message(conf, IPKG_INFO,
5144 + " removing obsolete file %s\n", old);
5145 + if (!conf->noaction) {
5146 + err = unlink(old);
5148 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5157 + pkg_free_installed_files(old_pkg);
5158 + pkg_free_installed_files(pkg);
5163 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5167 + char *globpattern;
5171 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5174 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5175 + err = glob(globpattern, 0, NULL, &globbuf);
5176 + free(globpattern);
5180 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5181 + for (i = 0; i < globbuf.gl_pathc; i++) {
5182 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5183 + globbuf.gl_pathv[i], old_pkg->name);
5184 + if (!conf->noaction)
5185 + unlink(globbuf.gl_pathv[i]);
5187 + globfree(&globbuf);
5192 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5198 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5199 + sprintf_alloc(&prefix, "%s.", pkg->name);
5200 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5201 + pkg->dest->info_dir,
5207 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5209 + /* DPKG_INCOMPATIBILITY:
5210 + This is a fairly sophisticated dpkg operation. Shall we
5213 + /* Any packages all of whose files have been overwritten during the
5214 + installation, and which aren't required for dependencies, are
5215 + considered to have been removed. For each such package
5216 + 1. disappearer's-postrm disappear overwriter overwriter-version
5217 + 2. The package's maintainer scripts are removed
5218 + 3. It is noted in the status database as being in a sane state,
5219 + namely not installed (any conffiles it may have are ignored,
5220 + rather than being removed by dpkg). Note that disappearing
5221 + packages do not have their prerm called, because dpkg doesn't
5222 + know in advance that the package is going to vanish.
5227 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5231 + /* ipkg takes a slightly different approach to data file backups
5232 + than dpkg. Rather than removing backups at this point, we
5233 + actually do the data file installation now. See comments in
5234 + check_data_file_clashes() for more details. */
5236 + ipkg_message(conf, IPKG_INFO,
5237 + " extracting data files to %s\n", pkg->dest->root_dir);
5238 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5243 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5244 + so we can't save ourself from removing important packages
5245 + At this point we (should) have extracted the .control file, so it
5246 + would be a good idea to reload the data in it, and set the Essential
5247 + state in *pkg. From now on the Essential is back in status file and
5248 + we can protect again.
5249 + We should operate this way:
5250 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5251 + check for "Essential" in it
5252 + set the value in pkg->essential.
5253 + This new routine could be useful also for every other flag
5254 + Pigi: 16/03/2004 */
5255 + set_flags_from_control(conf, pkg) ;
5257 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5258 + err = pkg_write_filelist(conf, pkg);
5262 + /* XXX: FEATURE: ipkg should identify any files which existed
5263 + before installation and which were overwritten, (see
5264 + check_data_file_clashes()). What it must do is remove any such
5265 + files from the filelist of the old package which provided the
5266 + file. Otherwise, if the old package were removed at some point
5267 + it would break the new package. Removing the new package will
5268 + also break the old one, but this cannot be helped since the old
5269 + package's file has already been deleted. This is the importance
5270 + of check_data_file_clashes(), and only allowing ipkg to install
5271 + a clashing package with a user force. */
5276 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5278 + conffile_list_elt_t *iter;
5285 + if (conf->noaction) return 0;
5287 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5288 + char *root_filename;
5290 + root_filename = root_filename_alloc(conf, cf->name);
5292 + /* Might need to initialize the md5sum for each conffile */
5293 + if (cf->value == NULL) {
5294 + cf->value = file_md5sum_alloc(root_filename);
5297 + if (!file_exists(root_filename)) {
5298 + free(root_filename);
5302 + cf_backup = backup_filename_alloc(root_filename);
5305 + if (file_exists(cf_backup)) {
5306 + /* Let's compute md5 to test if files are changed */
5307 + md5sum = file_md5sum_alloc(cf_backup);
5308 + if (strcmp( cf->value,md5sum) != 0 ) {
5309 + if (conf->force_defaults
5310 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5311 + rename(cf_backup, root_filename);
5314 + unlink(cf_backup);
5319 + free(root_filename);
5325 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5328 + const char *short_file_name;
5330 + short_file_name = strrchr(file_name, '/');
5331 + if (short_file_name) {
5332 + short_file_name++;
5334 + short_file_name = file_name;
5338 + response = get_user_response(" Configuration file '%s'\n"
5339 + " ==> File on system created by you or by a script.\n"
5340 + " ==> File also in package provided by package maintainer.\n"
5341 + " What would you like to do about it ? Your options are:\n"
5342 + " Y or I : install the package maintainer's version\n"
5343 + " N or O : keep your currently-installed version\n"
5344 + " D : show the differences between the versions (if diff is installed)\n"
5345 + " The default action is to keep your current version.\n"
5346 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5347 + if (strcmp(response, "y") == 0
5348 + || strcmp(response, "i") == 0
5349 + || strcmp(response, "yes") == 0) {
5354 + if (strcmp(response, "d") == 0) {
5358 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5359 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5362 + printf(" [Press ENTER to continue]\n");
5363 + response = file_read_line_alloc(stdin);
5373 +/* XXX: CLEANUP: I'd like to move all of the code for
5374 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5375 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5376 + pkg_deinit for example). */
5377 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5380 + struct dirent *dirent;
5383 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5385 + ipkg_message(conf, IPKG_DEBUG,
5386 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5387 + __FUNCTION__, pkg->tmp_unpack_dir);
5391 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5392 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5395 + dirent = readdir(tmp_dir);
5396 + if (dirent == NULL) {
5399 + sprintf_alloc(&tmp_file, "%s/%s",
5400 + pkg->tmp_unpack_dir, dirent->d_name);
5401 + if (! file_is_dir(tmp_file)) {
5406 + closedir(tmp_dir);
5407 + rmdir(pkg->tmp_unpack_dir);
5408 + free(pkg->tmp_unpack_dir);
5409 + pkg->tmp_unpack_dir = NULL;
5413 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5414 + pkg->name, pkg->local_filename, conf->tmp_dir);
5415 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5416 + unlink(pkg->local_filename);
5417 + free(pkg->local_filename);
5418 + pkg->local_filename = NULL;
5424 +static char *backup_filename_alloc(const char *file_name)
5428 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5433 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5438 + backup = backup_filename_alloc(file_name);
5439 + err = file_copy(file_name, backup);
5441 + ipkg_message(conf, IPKG_ERROR,
5442 + "%s: Failed to copy %s to %s\n",
5443 + __FUNCTION__, file_name, backup);
5451 +static int backup_exists_for(const char *file_name)
5456 + backup = backup_filename_alloc(file_name);
5458 + ret = file_exists(backup);
5465 +static int backup_remove(const char *file_name)
5469 + backup = backup_filename_alloc(file_name);
5478 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5480 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5482 + /* first, remove the packages that need removing */
5483 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5484 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5485 + err = ipkg_remove_pkg(conf, pkg,0);
5486 + if (err) return err;
5491 +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)
5494 + /* now one more pass checking on the ones that need to be installed */
5495 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5496 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5497 + if (pkg->dest == NULL)
5498 + pkg->dest = conf->default_dest;
5500 + pkg->state_want = SW_INSTALL;
5502 + /* Abhaya: conflicts check */
5503 + err = check_conflicts_for(conf, pkg);
5504 + if (err) { return err; }
5509 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5512 + /* now one more pass checking on the ones that need to be installed */
5513 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5514 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5516 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5517 + pkg_vec_t *replacees = pkg_vec_alloc();
5518 + pkg_get_installed_replacees(conf, pkg, replacees);
5520 + /* XXX: BUG: we really should treat replacement more like an upgrade
5521 + * Instead, we're going to remove the replacees
5523 + err = pkg_remove_installed_replacees(conf, replacees);
5524 + if (err) return err;
5525 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5530 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5533 + /* now one more pass checking on the ones that need to be installed */
5534 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5535 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5536 + if (pkg->local_filename == NULL) {
5537 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5539 + ipkg_message(conf, IPKG_ERROR,
5540 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5545 + if (pkg->tmp_unpack_dir == NULL) {
5546 + err = unpack_pkg_control_files(conf, pkg);
5547 + if (err) return err;
5553 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5556 + /* now one more pass checking on the ones that need to be installed */
5557 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5558 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5559 + pkg_t *old_pkg = pkg->old_pkg;
5561 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5562 + if (err) return err;
5564 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5565 + if (err) return err;
5567 + err = preinst_configure(conf, pkg, old_pkg);
5568 + if (err) return err;
5570 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5571 + if (err) return err;
5573 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5574 + if (err) return err;
5579 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5582 + /* now one more pass checking on the ones that need to be installed */
5583 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5584 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5585 + pkg_t *old_pkg = pkg->old_pkg;
5588 + old_pkg->state_want = SW_DEINSTALL;
5590 + if (old_pkg->state_flag & SF_NOPRUNE) {
5591 + ipkg_message(conf, IPKG_INFO,
5592 + " not removing obsolesced files because package marked noprune\n");
5594 + ipkg_message(conf, IPKG_INFO,
5595 + " removing obsolesced files\n");
5596 + remove_obsolesced_files(conf, pkg, old_pkg);
5600 + ipkg_message(conf, IPKG_INFO,
5601 + " installing maintainer scripts\n");
5602 + install_maintainer_scripts(conf, pkg, old_pkg);
5604 + /* the following just returns 0 */
5605 + remove_disappeared(conf, pkg);
5607 + ipkg_message(conf, IPKG_INFO,
5608 + " installing data files\n");
5609 + install_data_files(conf, pkg);
5611 + ipkg_message(conf, IPKG_INFO,
5612 + " resolving conf files\n");
5613 + resolve_conffiles(conf, pkg);
5615 + pkg->state_status = SS_UNPACKED;
5618 + old_pkg->state_status = SS_NOT_INSTALLED;
5621 + time(&pkg->installed_time);
5623 + ipkg_message(conf, IPKG_INFO,
5624 + " cleanup temp files\n");
5625 + cleanup_temporary_files(conf, pkg);
5628 + pkg->parent->state_status = pkg->state_status;
5633 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5636 + /* now one more pass checking on the ones that need to be installed */
5637 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5638 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5639 + pkg_t *old_pkg = pkg->old_pkg;
5642 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5643 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5644 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5645 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5646 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5647 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5648 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5649 + preinst_configure_unwind(conf, pkg, old_pkg);
5650 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5651 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5652 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5653 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5655 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5656 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5664 + * Perform all the actions.
5666 + * pkgs_to_remove are packages marked for removal.
5667 + * pkgs_superseded are the old packages being replaced by upgrades.
5669 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5671 +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)
5676 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5677 + if (err) return err;
5679 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5680 + if (err) return err;
5682 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5683 + if (err) goto UNWIND;
5685 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5686 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5687 + if (err) goto UNWIND;
5690 + * Now that we have the packages unpacked, we can look for data
5691 + * file clashes. First, we mark the files from the superseded
5692 + * packages as obsolete. Then we scan the files in
5693 + * pkgs_to_install, and only complain about clashes with
5694 + * non-obsolete files.
5697 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5698 + if (err) goto UNWIND;
5700 + /* this was before checking data file clashes */
5701 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5702 + if (err) goto UNWIND;
5704 + /* point of no return: no unwinding after this */
5705 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5706 + if (err) return err;
5708 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5712 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5714 + ipkg_message(conf, IPKG_INFO,
5715 + " cleanup temp files\n");
5716 + cleanup_temporary_files(conf, pkg);
5718 + ipkg_message(conf, IPKG_INFO,
5724 Index: busybox-1.7.2/archival/libipkg/ipkg_install.h
5725 ===================================================================
5726 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5727 +++ busybox-1.7.2/archival/libipkg/ipkg_install.h 2007-10-30 15:35:05.000000000 -0500
5729 +/* ipkg_install.h - the itsy package management system
5733 + Copyright (C) 2001 University of Southern California
5735 + This program is free software; you can redistribute it and/or
5736 + modify it under the terms of the GNU General Public License as
5737 + published by the Free Software Foundation; either version 2, or (at
5738 + your option) any later version.
5740 + This program is distributed in the hope that it will be useful, but
5741 + WITHOUT ANY WARRANTY; without even the implied warranty of
5742 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5743 + General Public License for more details.
5746 +#ifndef IPKG_INSTALL_H
5747 +#define IPKG_INSTALL_H
5750 +#include "ipkg_conf.h"
5752 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5753 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5754 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5755 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5756 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5758 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5760 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5761 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5764 Index: busybox-1.7.2/archival/libipkg/ipkg_message.c
5765 ===================================================================
5766 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5767 +++ busybox-1.7.2/archival/libipkg/ipkg_message.c 2007-10-30 15:35:05.000000000 -0500
5769 +/* ipkg_message.c - the itsy package management system
5771 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5773 + This program is free software; you can redistribute it and/or
5774 + modify it under the terms of the GNU General Public License as
5775 + published by the Free Software Foundation; either version 2, or (at
5776 + your option) any later version.
5778 + This program is distributed in the hope that it will be useful, but
5779 + WITHOUT ANY WARRANTY; without even the implied warranty of
5780 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5781 + General Public License for more details.
5786 +#include "ipkg_conf.h"
5787 +#include "ipkg_message.h"
5792 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5796 + if (conf && (conf->verbosity < level))
5803 + va_start (ap, fmt);
5804 + vprintf (fmt, ap);
5811 +#include "libipkg.h"
5813 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5816 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5821 + if (ipkg_cb_message)
5823 + va_start (ap, fmt);
5824 + vsnprintf (ts,256,fmt, ap);
5826 + ipkg_cb_message(conf,level,ts);
5830 Index: busybox-1.7.2/archival/libipkg/ipkg_message.h
5831 ===================================================================
5832 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5833 +++ busybox-1.7.2/archival/libipkg/ipkg_message.h 2007-10-30 15:35:05.000000000 -0500
5835 +/* ipkg_message.h - the itsy package management system
5837 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5839 + This program is free software; you can redistribute it and/or
5840 + modify it under the terms of the GNU General Public License as
5841 + published by the Free Software Foundation; either version 2, or (at
5842 + your option) any later version.
5844 + This program is distributed in the hope that it will be useful, but
5845 + WITHOUT ANY WARRANTY; without even the implied warranty of
5846 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5847 + General Public License for more details.
5850 +#ifndef _IPKG_MESSAGE_H_
5851 +#define _IPKG_MESSAGE_H_
5854 +#include "ipkg_conf.h"
5857 + IPKG_ERROR, /* error conditions */
5858 + IPKG_NOTICE, /* normal but significant condition */
5859 + IPKG_INFO, /* informational message */
5860 + IPKG_DEBUG, /* debug level message */
5861 + IPKG_DEBUG2, /* more debug level message */
5864 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
5866 +#endif /* _IPKG_MESSAGE_H_ */
5867 Index: busybox-1.7.2/archival/libipkg/ipkg_remove.c
5868 ===================================================================
5869 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5870 +++ busybox-1.7.2/archival/libipkg/ipkg_remove.c 2007-10-30 15:35:05.000000000 -0500
5872 +/* ipkg_remove.c - the itsy package management system
5876 + Copyright (C) 2001 University of Southern California
5878 + This program is free software; you can redistribute it and/or
5879 + modify it under the terms of the GNU General Public License as
5880 + published by the Free Software Foundation; either version 2, or (at
5881 + your option) any later version.
5883 + This program is distributed in the hope that it will be useful, but
5884 + WITHOUT ANY WARRANTY; without even the implied warranty of
5885 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5886 + General Public License for more details.
5890 +#include "ipkg_message.h"
5894 +#include "ipkg_remove.h"
5896 +#include "file_util.h"
5897 +#include "sprintf_alloc.h"
5898 +#include "str_util.h"
5900 +#include "ipkg_cmd.h"
5903 + * Returns number of the number of packages depending on the packages provided by this package.
5904 + * Every package implicitly provides itself.
5906 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5908 + int nprovides = pkg->provides_count;
5909 + abstract_pkg_t **provides = pkg->provides;
5910 + int n_installed_dependents = 0;
5912 + for (i = 0; i <= nprovides; i++) {
5913 + abstract_pkg_t *providee = provides[i];
5914 + abstract_pkg_t **dependers = providee->depended_upon_by;
5915 + abstract_pkg_t *dep_ab_pkg;
5916 + if (dependers == NULL)
5918 + while ((dep_ab_pkg = *dependers++) != NULL) {
5919 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5920 + n_installed_dependents++;
5925 + /* if caller requested the set of installed dependents */
5926 + if (pdependents) {
5928 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5930 + if ( dependents == NULL ){
5931 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5935 + *pdependents = dependents;
5936 + for (i = 0; i <= nprovides; i++) {
5937 + abstract_pkg_t *providee = provides[i];
5938 + abstract_pkg_t **dependers = providee->depended_upon_by;
5939 + abstract_pkg_t *dep_ab_pkg;
5940 + if (dependers == NULL)
5942 + while ((dep_ab_pkg = *dependers++) != NULL) {
5943 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5944 + dependents[p++] = dep_ab_pkg;
5945 + dep_ab_pkg->state_flag |= SF_MARKED;
5949 + dependents[p] = NULL;
5950 + /* now clear the marks */
5951 + for (i = 0; i < p; i++) {
5952 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5953 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5956 + return n_installed_dependents;
5959 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5964 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5965 + abstract_pkg_t * ab_pkg;
5967 + if((ab_pkg = pkg->parent) == NULL){
5968 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5969 + __FUNCTION__, pkg->name);
5973 + if (dependents == NULL)
5976 + // here i am using the dependencies_checked
5977 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5978 + return 0; // has already been encountered in the process
5979 + // of marking packages for removal - Karthik
5980 + ab_pkg->dependencies_checked = 2;
5984 + while (dependents [i] != NULL) {
5985 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5987 + if (dep_ab_pkg->dependencies_checked == 2){
5991 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5992 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5993 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5994 + if (dep_pkg->state_status == SS_INSTALLED) {
5995 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6001 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6002 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6009 + for (i = 0; i < dependent_pkgs->len; i++) {
6010 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6017 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6019 + abstract_pkg_t *dep_ab_pkg;
6020 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6021 + while ((dep_ab_pkg = *dependents++) != NULL) {
6022 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6023 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6025 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6026 + ipkg_message(conf, IPKG_ERROR, "");
6027 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6028 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6029 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6030 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6031 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6035 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6037 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6038 + thus I wan't check for essential, as I'm upgrading.
6039 + I hope it won't break anything :)
6042 + abstract_pkg_t *parent_pkg = NULL;
6044 + if (pkg->essential && !message) {
6045 + if (conf->force_removal_of_essential_packages) {
6046 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6047 + "\tIf your system breaks, you get to keep both pieces\n",
6050 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6051 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6052 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6053 + "\tits will with the option: -force-removal-of-essential-packages\n",
6055 + return IPKG_PKG_IS_ESSENTIAL;
6059 + if ((parent_pkg = pkg->parent) == NULL)
6062 + /* only attempt to remove dependent installed packages if
6063 + * force_depends is not specified or the package is being
6066 + if (!conf->force_depends
6067 + && !(pkg->state_flag & SF_REPLACE)) {
6068 + abstract_pkg_t **dependents;
6069 + int has_installed_dependents =
6070 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6072 + if (has_installed_dependents) {
6074 + * if this package is depended up by others, then either we should
6075 + * not remove it or we should remove it and all of its dependents
6078 + if (!conf->force_removal_of_dependent_packages
6079 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6080 + return IPKG_PKG_HAS_DEPENDENTS;
6083 + /* remove packages depending on this package - Karthik */
6084 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6086 + if (err) return err;
6090 + if ( message==0 ){
6091 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6094 + pkg->state_flag |= SF_FILELIST_CHANGED;
6096 + pkg->state_want = SW_DEINSTALL;
6097 + ipkg_state_changed++;
6099 + pkg_run_script(conf, pkg, "prerm", "remove");
6101 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6102 + maintains an empty filelist rather than deleting it. That seems
6103 + like a big pain, and I don't see that that should make a big
6104 + difference, but for anyone who wants tighter compatibility,
6105 + feel free to fix this. */
6106 + remove_data_files_and_list(conf, pkg);
6108 + pkg_run_script(conf, pkg, "postrm", "remove");
6110 + remove_maintainer_scripts_except_postrm(conf, pkg);
6112 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6113 + * space, it doesn't make sense to leave extra configurations, files,
6114 + * and maintainer scripts left around. So, we make remove like purge,
6115 + * and take out all the crap :) */
6117 + remove_postrm(conf, pkg);
6118 + pkg->state_status = SS_NOT_INSTALLED;
6121 + parent_pkg->state_status = SS_NOT_INSTALLED;
6126 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6128 + ipkg_remove_pkg(conf, pkg,0);
6132 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6134 + str_list_t installed_dirs;
6135 + str_list_t *installed_files;
6136 + str_list_elt_t *iter;
6138 + conffile_t *conffile;
6139 + int removed_a_dir;
6142 + str_list_init(&installed_dirs);
6143 + installed_files = pkg_get_installed_files(pkg);
6145 + for (iter = installed_files->head; iter; iter = iter->next) {
6146 + file_name = iter->data;
6148 + if (file_is_dir(file_name)) {
6149 + str_list_append(&installed_dirs, strdup(file_name));
6153 + conffile = pkg_get_conffile(pkg, file_name);
6155 + /* XXX: QUESTION: Is this right? I figure we only need to
6156 + save the conffile if it has been modified. Is that what
6157 + dpkg does? Or does dpkg preserve all conffiles? If so,
6158 + this seems like a better thing to do to conserve
6160 + if (conffile_has_been_modified(conf, conffile)) {
6161 + printf(" not deleting modified conffile %s\n", file_name);
6167 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6168 + if (!conf->noaction)
6169 + unlink(file_name);
6172 + if (!conf->noaction) {
6174 + removed_a_dir = 0;
6175 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6176 + file_name = iter->data;
6178 + if (rmdir(file_name) == 0) {
6179 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6180 + removed_a_dir = 1;
6181 + str_list_remove(&installed_dirs, &iter);
6184 + } while (removed_a_dir);
6187 + pkg_free_installed_files(pkg);
6188 + /* We have to remove the file list now, so that
6189 + find_pkg_owning_file does not always just report this package */
6190 + pkg_remove_installed_files_list(conf, pkg);
6192 + /* Don't print warning for dirs that are provided by other packages */
6193 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6194 + file_name = iter->data;
6196 + owner = file_hash_get_file_owner(conf, file_name);
6199 + iter->data = NULL;
6200 + str_list_remove(&installed_dirs, &iter);
6205 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6207 + iter->data = NULL;
6209 + str_list_deinit(&installed_dirs);
6214 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6217 + char *globpattern;
6220 + if (conf->noaction) return 0;
6222 + sprintf_alloc(&globpattern, "%s/%s.*",
6223 + pkg->dest->info_dir, pkg->name);
6224 + err = glob(globpattern, 0, NULL, &globbuf);
6225 + free(globpattern);
6230 + for (i = 0; i < globbuf.gl_pathc; i++) {
6231 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6234 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6235 + unlink(globbuf.gl_pathv[i]);
6237 + globfree(&globbuf);
6242 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6244 + char *postrm_file_name;
6246 + if (conf->noaction) return 0;
6248 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6249 + pkg->dest->info_dir, pkg->name);
6250 + unlink(postrm_file_name);
6251 + free(postrm_file_name);
6255 Index: busybox-1.7.2/archival/libipkg/ipkg_remove.h
6256 ===================================================================
6257 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6258 +++ busybox-1.7.2/archival/libipkg/ipkg_remove.h 2007-10-30 15:35:05.000000000 -0500
6260 +/* ipkg_remove.h - the itsy package management system
6264 + Copyright (C) 2001 University of Southern California
6266 + This program is free software; you can redistribute it and/or
6267 + modify it under the terms of the GNU General Public License as
6268 + published by the Free Software Foundation; either version 2, or (at
6269 + your option) any later version.
6271 + This program is distributed in the hope that it will be useful, but
6272 + WITHOUT ANY WARRANTY; without even the implied warranty of
6273 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6274 + General Public License for more details.
6277 +#ifndef IPKG_REMOVE_H
6278 +#define IPKG_REMOVE_H
6281 +#include "ipkg_conf.h"
6283 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6284 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6285 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6286 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6287 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6288 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6289 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6293 Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.c
6294 ===================================================================
6295 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6296 +++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.c 2007-10-30 15:35:05.000000000 -0500
6298 +/* ipkg_upgrade.c - the itsy package management system
6301 + Copyright (C) 2001 University of Southern California
6303 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6305 + This program is free software; you can redistribute it and/or
6306 + modify it under the terms of the GNU General Public License as
6307 + published by the Free Software Foundation; either version 2, or (at
6308 + your option) any later version.
6310 + This program is distributed in the hope that it will be useful, but
6311 + WITHOUT ANY WARRANTY; without even the implied warranty of
6312 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6313 + General Public License for more details.
6317 +#include "ipkg_install.h"
6318 +#include "ipkg_message.h"
6320 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6324 + char *old_version, *new_version;
6326 + if (old->state_flag & SF_HOLD) {
6327 + ipkg_message(conf, IPKG_NOTICE,
6328 + "Not upgrading package %s which is marked "
6329 + "hold (flags=%#x)\n", old->name, old->state_flag);
6333 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6334 + if (new == NULL) {
6335 + old_version = pkg_version_str_alloc(old);
6336 + ipkg_message(conf, IPKG_NOTICE,
6337 + "Assuming locally installed package %s (%s) "
6338 + "is up to date.\n", old->name, old_version);
6339 + free(old_version);
6343 + old_version = pkg_version_str_alloc(old);
6344 + new_version = pkg_version_str_alloc(new);
6346 + cmp = pkg_compare_versions(old, new);
6347 + ipkg_message(conf, IPKG_DEBUG,
6348 + "comparing visible versions of pkg %s:"
6349 + "\n\t%s is installed "
6350 + "\n\t%s is available "
6351 + "\n\t%d was comparison result\n",
6352 + old->name, old_version, new_version, cmp);
6354 + ipkg_message(conf, IPKG_INFO,
6355 + "Package %s (%s) installed in %s is up to date.\n",
6356 + old->name, old_version, old->dest->name);
6357 + free(old_version);
6358 + free(new_version);
6360 + } else if (cmp > 0) {
6361 + ipkg_message(conf, IPKG_NOTICE,
6362 + "Not downgrading package %s on %s from %s to %s.\n",
6363 + old->name, old->dest->name, old_version, new_version);
6364 + free(old_version);
6365 + free(new_version);
6367 + } else if (cmp < 0) {
6368 + new->dest = old->dest;
6369 + old->state_want = SW_DEINSTALL;
6372 + new->state_flag |= SF_USER;
6373 + return ipkg_install_pkg(conf, new,1);
6375 Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.h
6376 ===================================================================
6377 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6378 +++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.h 2007-10-30 15:35:05.000000000 -0500
6380 +/* ipkg_upgrade.c - the itsy package management system
6382 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6384 + This program is free software; you can redistribute it and/or
6385 + modify it under the terms of the GNU General Public License as
6386 + published by the Free Software Foundation; either version 2, or (at
6387 + your option) any later version.
6389 + This program is distributed in the hope that it will be useful, but
6390 + WITHOUT ANY WARRANTY; without even the implied warranty of
6391 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6392 + General Public License for more details.
6397 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6398 Index: busybox-1.7.2/archival/libipkg/ipkg_utils.c
6399 ===================================================================
6400 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6401 +++ busybox-1.7.2/archival/libipkg/ipkg_utils.c 2007-10-30 15:35:05.000000000 -0500
6403 +/* ipkg_utils.c - the itsy package management system
6407 + Copyright (C) 2002 Compaq Computer Corporation
6409 + This program is free software; you can redistribute it and/or
6410 + modify it under the terms of the GNU General Public License as
6411 + published by the Free Software Foundation; either version 2, or (at
6412 + your option) any later version.
6414 + This program is distributed in the hope that it will be useful, but
6415 + WITHOUT ANY WARRANTY; without even the implied warranty of
6416 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6417 + General Public License for more details.
6423 +#include <sys/vfs.h>
6425 +#include "ipkg_utils.h"
6427 +#include "pkg_hash.h"
6429 +struct errlist* error_list;
6431 +int get_available_blocks(char * filesystem)
6433 + struct statfs sfs;
6435 + if(statfs(filesystem, &sfs)){
6436 + fprintf(stderr, "bad statfs\n");
6439 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6440 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6443 +char **read_raw_pkgs_from_file(const char *file_name)
6448 + if(!(fp = fopen(file_name, "r"))){
6449 + fprintf(stderr, "can't get %s open for read\n", file_name);
6453 + ret = read_raw_pkgs_from_stream(fp);
6460 +char **read_raw_pkgs_from_stream(FILE *fp)
6462 + char **raw = NULL, *buf, *scout;
6464 + size_t size = 512;
6466 + buf = malloc (size);
6468 + while (fgets(buf, size, fp)) {
6469 + while (strlen (buf) == (size - 1)
6470 + && buf[size-2] != '\n') {
6471 + size_t o = size - 1;
6473 + buf = realloc (buf, size);
6474 + if (fgets (buf + o, size - o, fp) == NULL)
6479 + raw = realloc(raw, (count + 50) * sizeof(char *));
6481 + if((scout = strchr(buf, '\n')))
6484 + raw[count++] = strdup(buf);
6487 + raw = realloc(raw, (count + 1) * sizeof(char *));
6488 + raw[count] = NULL;
6495 +/* something to remove whitespace, a hash pooper */
6496 +char *trim_alloc(char *line)
6499 + char *dest, *src, *end;
6501 + new = malloc(strlen(line) + 1);
6502 + if ( new == NULL ){
6503 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6506 + dest = new, src = line, end = line + (strlen(line) - 1);
6508 + /* remove it from the front */
6513 + /* and now from the back */
6514 + while((end > src) &&
6520 + /* this does from the first space
6521 + * blasting away any versions stuff in depends
6532 +int line_is_blank(const char *line)
6536 + for (s = line; *s; s++) {
6543 +void push_error_list(struct errlist ** errors, char * msg){
6544 + struct errlist *err_lst_tmp;
6547 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6548 + err_lst_tmp->errmsg=strdup(msg) ;
6549 + err_lst_tmp->next = *errors;
6550 + *errors = err_lst_tmp;
6554 +void reverse_error_list(struct errlist **errors){
6555 + struct errlist *result=NULL;
6556 + struct errlist *current= *errors;
6557 + struct errlist *next;
6559 + while ( current != NULL ) {
6560 + next = current->next;
6561 + current->next=result;
6570 +void free_error_list(struct errlist **errors){
6571 + struct errlist *current = *errors;
6573 + while (current != NULL) {
6574 + free(current->errmsg);
6575 + current = (*errors)->next;
6577 + *errors = current;
6584 Index: busybox-1.7.2/archival/libipkg/ipkg_utils.h
6585 ===================================================================
6586 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6587 +++ busybox-1.7.2/archival/libipkg/ipkg_utils.h 2007-10-30 15:35:05.000000000 -0500
6589 +/* ipkg_utils.h - the itsy package management system
6593 + Copyright (C) 2002 Compaq Computer Corporation
6595 + This program is free software; you can redistribute it and/or
6596 + modify it under the terms of the GNU General Public License as
6597 + published by the Free Software Foundation; either version 2, or (at
6598 + your option) any later version.
6600 + This program is distributed in the hope that it will be useful, but
6601 + WITHOUT ANY WARRANTY; without even the implied warranty of
6602 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6603 + General Public License for more details.
6606 +#ifndef IPKG_UTILS_H
6607 +#define IPKG_UTILS_H
6611 +int get_available_blocks(char * filesystem);
6612 +char **read_raw_pkgs_from_file(const char *file_name);
6613 +char **read_raw_pkgs_from_stream(FILE *fp);
6614 +char *trim_alloc(char * line);
6615 +int line_is_blank(const char *line);
6618 Index: busybox-1.7.2/archival/libipkg/Kbuild
6619 ===================================================================
6620 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6621 +++ busybox-1.7.2/archival/libipkg/Kbuild 2007-10-30 15:35:05.000000000 -0500
6623 +# Makefile for busybox
6625 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6626 +# Copyright (C) 2006 OpenWrt.org
6628 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6630 +LIBIPKG_CORE_OBJS:= \
6635 +LIBIPKG_CMD_OBJS:= \
6637 + ipkg_configure.o \
6643 +LIBIPKG_DB_OBJS:= \
6654 +LIBIPKG_LIST_OBJS:= \
6666 +LIBIPKG_UTIL_OBJS:= \
6673 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6674 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6675 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6676 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6677 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6679 +ifeq ($(strip $(IPKG_ARCH)),)
6680 +IPKG_ARCH:=$(TARGET_ARCH)
6682 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6683 Index: busybox-1.7.2/archival/libipkg/libipkg.c
6684 ===================================================================
6685 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
6686 +++ busybox-1.7.2/archival/libipkg/libipkg.c 2007-10-30 15:35:05.000000000 -0500
6688 +/* ipkglib.c - the itsy package management system
6692 + Copyright (C) 2003 kernel concepts
6694 + This program is free software; you can redistribute it and/or
6695 + modify it under the terms of the GNU General Public License as
6696 + published by the Free Software Foundation; either version 2, or (at
6697 + your option) any later version.
6699 + This program is distributed in the hope that it will be useful, but
6700 + WITHOUT ANY WARRANTY; without even the implied warranty of
6701 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6702 + General Public License for more details.
6708 +#include "ipkg_includes.h"
6709 +#include "libipkg.h"
6712 +#include "ipkg_conf.h"
6713 +#include "ipkg_cmd.h"
6714 +#include "file_util.h"
6718 +ipkg_message_callback ipkg_cb_message = NULL;
6719 +ipkg_response_callback ipkg_cb_response = NULL;
6720 +ipkg_status_callback ipkg_cb_status = NULL;
6721 +ipkg_list_callback ipkg_cb_list = NULL;
6725 +ipkg_init (ipkg_message_callback mcall,
6726 + ipkg_response_callback rcall,
6729 + ipkg_cb_message = mcall;
6730 + ipkg_cb_response = rcall;
6739 +ipkg_deinit (args_t * args)
6741 + args_deinit (args);
6742 + ipkg_cb_message = NULL;
6743 + ipkg_cb_response = NULL;
6745 + /* place other cleanup stuff here */
6752 +ipkg_packages_list(args_t *args,
6753 + const char *packages,
6754 + ipkg_list_callback cblist,
6758 + ipkg_conf_t ipkg_conf;
6761 + err = ipkg_conf_init (&ipkg_conf, args);
6767 + ipkg_cb_list = cblist;
6768 + /* we need to do this because of static declarations,
6769 + * maybe a good idea to change */
6770 + cmd = ipkg_cmd_find ("list");
6772 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6774 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6775 + ipkg_cb_list = NULL;
6776 + ipkg_conf_deinit (&ipkg_conf);
6782 +ipkg_packages_status(args_t *args,
6783 + const char *packages,
6784 + ipkg_status_callback cbstatus,
6788 + ipkg_conf_t ipkg_conf;
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6797 + ipkg_cb_status = cbstatus;
6799 + /* we need to do this because of static declarations,
6800 + * maybe a good idea to change */
6801 + cmd = ipkg_cmd_find ("status");
6803 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6805 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6807 + ipkg_cb_status = NULL;
6808 + ipkg_conf_deinit (&ipkg_conf);
6814 +ipkg_packages_info(args_t *args,
6815 + const char *packages,
6816 + ipkg_status_callback cbstatus,
6820 + ipkg_conf_t ipkg_conf;
6823 + err = ipkg_conf_init (&ipkg_conf, args);
6829 + ipkg_cb_status = cbstatus;
6831 + /* we need to do this because of static declarations,
6832 + * maybe a good idea to change */
6833 + cmd = ipkg_cmd_find ("info");
6835 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6837 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6839 + ipkg_cb_status = NULL;
6840 + ipkg_conf_deinit (&ipkg_conf);
6846 +ipkg_packages_install (args_t * args, const char *name)
6849 + ipkg_conf_t ipkg_conf;
6852 + /* this error should be handled in application */
6853 + if (!name || !strlen (name))
6856 + err = ipkg_conf_init (&ipkg_conf, args);
6862 + /* we need to do this because of static declarations,
6863 + * maybe a good idea to change */
6864 + cmd = ipkg_cmd_find ("install");
6865 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6867 + ipkg_conf_deinit(&ipkg_conf);
6873 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6876 + ipkg_conf_t ipkg_conf;
6879 + /* this error should be handled in application */
6880 + if (!name || !strlen (name))
6883 + err = ipkg_conf_init (&ipkg_conf, args);
6889 + /* we need to do this because of static declarations,
6890 + * maybe a good idea to change */
6892 + cmd = ipkg_cmd_find ("purge");
6894 + cmd = ipkg_cmd_find ("remove");
6896 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6898 + ipkg_conf_deinit(&ipkg_conf);
6904 +ipkg_lists_update(args_t *args)
6907 + ipkg_conf_t ipkg_conf;
6910 + err = ipkg_conf_init (&ipkg_conf, args);
6916 + /* we need to do this because of static declarations,
6917 + * maybe a good idea to change */
6918 + cmd = ipkg_cmd_find ("update");
6920 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6922 + ipkg_conf_deinit(&ipkg_conf);
6928 +ipkg_packages_upgrade(args_t *args)
6931 + ipkg_conf_t ipkg_conf;
6934 + err = ipkg_conf_init (&ipkg_conf, args);
6940 + /* we need to do this because of static declarations,
6941 + * maybe a good idea to change */
6942 + cmd = ipkg_cmd_find ("upgrade");
6944 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6946 + ipkg_conf_deinit(&ipkg_conf);
6952 +ipkg_packages_download (args_t * args, const char *name)
6955 + ipkg_conf_t ipkg_conf;
6958 + /* this error should be handled in application */
6959 + if (!name || !strlen (name))
6962 + err = ipkg_conf_init (&ipkg_conf, args);
6968 + /* we need to do this because of static declarations,
6969 + * maybe a good idea to change */
6970 + cmd = ipkg_cmd_find ("download");
6971 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6973 + ipkg_conf_deinit(&ipkg_conf);
6979 +ipkg_package_files(args_t *args,
6981 + ipkg_list_callback cblist,
6985 + ipkg_conf_t ipkg_conf;
6988 + /* this error should be handled in application */
6989 + if (!name || !strlen (name))
6992 + err = ipkg_conf_init (&ipkg_conf, args);
6998 + ipkg_cb_list = cblist;
7000 + /* we need to do this because of static declarations,
7001 + * maybe a good idea to change */
7002 + cmd = ipkg_cmd_find ("files");
7004 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
7006 + ipkg_cb_list = NULL;
7007 + ipkg_conf_deinit(&ipkg_conf);
7013 +ipkg_file_search(args_t *args,
7015 + ipkg_list_callback cblist,
7019 + ipkg_conf_t ipkg_conf;
7022 + /* this error should be handled in application */
7023 + if (!file || !strlen (file))
7026 + err = ipkg_conf_init (&ipkg_conf, args);
7032 + ipkg_cb_list = cblist;
7034 + /* we need to do this because of static declarations,
7035 + * maybe a good idea to change */
7036 + cmd = ipkg_cmd_find ("search");
7037 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7039 + ipkg_cb_list = NULL;
7040 + ipkg_conf_deinit(&ipkg_conf);
7046 +ipkg_file_what(args_t *args, const char *file, const char* command)
7049 + ipkg_conf_t ipkg_conf;
7052 + /* this error should be handled in application */
7053 + if (!file || !strlen (file))
7056 + err = ipkg_conf_init (&ipkg_conf, args);
7062 + /* we need to do this because of static declarations,
7063 + * maybe a good idea to change */
7064 + cmd = ipkg_cmd_find (command);
7065 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7067 + ipkg_conf_deinit(&ipkg_conf);
7071 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7072 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7073 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7074 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7075 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7078 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7081 + if (conf && (conf->verbosity < level)) {
7085 + if ( level == IPKG_ERROR ){
7086 + push_error_list(&error_list, msg);
7095 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7096 + pkg_state_status_t status, void *userdata)
7099 + printf("%s - %s - %s\n", name, version, desc);
7101 + printf("%s - %s\n", name, version);
7105 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7106 + pkg_state_status_t status, void *userdata)
7109 + printf("%s\n", desc);
7113 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7116 + printf("%s\n", desc);
7120 +char* default_ipkg_response_callback(char *question)
7122 + char *response = NULL;
7126 + response = (char *)file_read_line_alloc(stdin);
7127 + } while (response == NULL);
7131 +/* This is used for backward compatibility */
7133 +ipkg_op (int argc, char *argv[])
7135 + int err, opt_index;
7139 + ipkg_conf_t ipkg_conf;
7141 + args_init (&args);
7143 + opt_index = args_parse (&args, argc, argv);
7144 + if (opt_index == argc || opt_index < 0)
7146 + args_usage ("ipkg must have one sub-command argument");
7149 + cmd_name = argv[opt_index++];
7150 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7151 + read anything from there.
7153 + if ( !strcmp(cmd_name,"print-architecture") ||
7154 + !strcmp(cmd_name,"print_architecture") ||
7155 + !strcmp(cmd_name,"print-installation-architecture") ||
7156 + !strcmp(cmd_name,"print_installation_architecture") )
7157 + args.nocheckfordirorfile = 1;
7159 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7160 + read anything from there.
7162 + if ( !strcmp(cmd_name,"flag") ||
7163 + !strcmp(cmd_name,"configure") ||
7164 + !strcmp(cmd_name,"remove") ||
7165 + !strcmp(cmd_name,"files") ||
7166 + !strcmp(cmd_name,"search") ||
7167 + !strcmp(cmd_name,"compare_versions") ||
7168 + !strcmp(cmd_name,"compare-versions") ||
7169 + !strcmp(cmd_name,"list_installed") ||
7170 + !strcmp(cmd_name,"list-installed") ||
7171 + !strcmp(cmd_name,"status") )
7172 + args.noreadfeedsfile = 1;
7175 + err = ipkg_conf_init (&ipkg_conf, &args);
7181 + args_deinit (&args);
7183 + ipkg_cb_message = default_ipkg_message_callback;
7184 + ipkg_cb_response = default_ipkg_response_callback;
7185 + ipkg_cb_status = default_ipkg_status_callback;
7186 + if ( strcmp(cmd_name, "files")==0)
7187 + ipkg_cb_list = default_ipkg_files_callback;
7189 + ipkg_cb_list = default_ipkg_list_callback;
7191 + cmd = ipkg_cmd_find (cmd_name);
7194 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7196 + args_usage (NULL);
7199 + if (cmd->requires_args && opt_index == argc)
7202 + "%s: the ``%s'' command requires at least one argument\n",
7203 + __FUNCTION__, cmd_name);
7204 + args_usage (NULL);
7207 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7209 + ipkg_conf_deinit (&ipkg_conf);
7214 +#endif /* IPKG_LIB */
7215 Index: busybox-1.7.2/archival/libipkg/libipkg.h
7216 ===================================================================
7217 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7218 +++ busybox-1.7.2/archival/libipkg/libipkg.h 2007-10-30 15:35:05.000000000 -0500
7220 +/* ipkglib.h - the itsy package management system
7222 + Florian Boor <florian.boor@kernelconcepts.de>
7224 + This program is free software; you can redistribute it and/or
7225 + modify it under the terms of the GNU General Public License as
7226 + published by the Free Software Foundation; either version 2, or (at
7227 + your option) any later version.
7229 + This program is distributed in the hope that it will be useful, but
7230 + WITHOUT ANY WARRANTY; without even the implied warranty of
7231 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7232 + General Public License for more details.
7240 +#include "ipkg_conf.h"
7241 +#include "ipkg_message.h"
7247 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7249 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7250 + pkg_state_status_t status, void *userdata);
7251 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7253 +typedef char* (*ipkg_response_callback)(char *question);
7255 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7256 +extern int ipkg_init (ipkg_message_callback mcall,
7257 + ipkg_response_callback rcall,
7260 +extern int ipkg_deinit (args_t *args);
7261 +extern int ipkg_packages_list(args_t *args,
7262 + const char *packages,
7263 + ipkg_list_callback cblist,
7265 +extern int ipkg_packages_status(args_t *args,
7266 + const char *packages,
7267 + ipkg_status_callback cbstatus,
7269 +extern int ipkg_packages_info(args_t *args,
7270 + const char *packages,
7271 + ipkg_status_callback cbstatus,
7273 +extern int ipkg_packages_install(args_t *args, const char *name);
7274 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7275 +extern int ipkg_lists_update(args_t *args);
7276 +extern int ipkg_packages_upgrade(args_t *args);
7277 +extern int ipkg_packages_download(args_t *args, const char *name);
7278 +extern int ipkg_package_files(args_t *args,
7280 + ipkg_list_callback cblist,
7282 +extern int ipkg_file_search(args_t *args,
7284 + ipkg_list_callback cblist,
7286 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7287 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7288 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7289 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7290 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7292 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7293 +extern ipkg_response_callback ipkg_cb_response;
7294 +extern ipkg_status_callback ipkg_cb_status;
7295 +extern ipkg_list_callback ipkg_cb_list;
7296 +extern void push_error_list(struct errlist **errors,char * msg);
7297 +extern void reverse_error_list(struct errlist **errors);
7298 +extern void free_error_list(struct errlist **errors);
7302 +extern int ipkg_op(int argc, char *argv[]);
7308 Index: busybox-1.7.2/archival/libipkg/nv_pair.c
7309 ===================================================================
7310 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7311 +++ busybox-1.7.2/archival/libipkg/nv_pair.c 2007-10-30 15:35:05.000000000 -0500
7313 +/* nv_pair.c - the itsy package management system
7317 + Copyright (C) 2001 University of Southern California
7319 + This program is free software; you can redistribute it and/or
7320 + modify it under the terms of the GNU General Public License as
7321 + published by the Free Software Foundation; either version 2, or (at
7322 + your option) any later version.
7324 + This program is distributed in the hope that it will be useful, but
7325 + WITHOUT ANY WARRANTY; without even the implied warranty of
7326 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7327 + General Public License for more details.
7332 +#include "nv_pair.h"
7333 +#include "str_util.h"
7335 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7337 + nv_pair->name = str_dup_safe(name);
7338 + nv_pair->value = str_dup_safe(value);
7343 +void nv_pair_deinit(nv_pair_t *nv_pair)
7345 + free(nv_pair->name);
7346 + nv_pair->name = NULL;
7348 + free(nv_pair->value);
7349 + nv_pair->value = NULL;
7353 Index: busybox-1.7.2/archival/libipkg/nv_pair.h
7354 ===================================================================
7355 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7356 +++ busybox-1.7.2/archival/libipkg/nv_pair.h 2007-10-30 15:35:05.000000000 -0500
7358 +/* nv_pair.h - the itsy package management system
7362 + Copyright (C) 2001 University of Southern California
7364 + This program is free software; you can redistribute it and/or
7365 + modify it under the terms of the GNU General Public License as
7366 + published by the Free Software Foundation; either version 2, or (at
7367 + your option) any later version.
7369 + This program is distributed in the hope that it will be useful, but
7370 + WITHOUT ANY WARRANTY; without even the implied warranty of
7371 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7372 + General Public License for more details.
7378 +typedef struct nv_pair nv_pair_t;
7385 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7386 +void nv_pair_deinit(nv_pair_t *nv_pair);
7390 Index: busybox-1.7.2/archival/libipkg/nv_pair_list.c
7391 ===================================================================
7392 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7393 +++ busybox-1.7.2/archival/libipkg/nv_pair_list.c 2007-10-30 15:35:05.000000000 -0500
7395 +/* nv_pair_list.c - the itsy package management system
7399 + Copyright (C) 2001 University of Southern California
7401 + This program is free software; you can redistribute it and/or
7402 + modify it under the terms of the GNU General Public License as
7403 + published by the Free Software Foundation; either version 2, or (at
7404 + your option) any later version.
7406 + This program is distributed in the hope that it will be useful, but
7407 + WITHOUT ANY WARRANTY; without even the implied warranty of
7408 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7409 + General Public License for more details.
7414 +#include "nv_pair.h"
7415 +#include "void_list.h"
7416 +#include "nv_pair_list.h"
7418 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7420 + return void_list_elt_init((void_list_elt_t *) elt, data);
7423 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7425 + void_list_elt_deinit((void_list_elt_t *) elt);
7428 +int nv_pair_list_init(nv_pair_list_t *list)
7430 + return void_list_init((void_list_t *) list);
7433 +void nv_pair_list_deinit(nv_pair_list_t *list)
7435 + nv_pair_list_elt_t *iter;
7436 + nv_pair_t *nv_pair;
7438 + for (iter = list->head; iter; iter = iter->next) {
7439 + nv_pair = iter->data;
7440 + nv_pair_deinit(nv_pair);
7442 + /* malloced in nv_pair_list_append */
7444 + iter->data = NULL;
7446 + void_list_deinit((void_list_t *) list);
7449 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7453 + /* freed in nv_pair_list_deinit */
7454 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7456 + if (nv_pair == NULL) {
7457 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7460 + nv_pair_init(nv_pair, name, value);
7462 + err = void_list_append((void_list_t *) list, nv_pair);
7470 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7472 + return void_list_push((void_list_t *) list, data);
7475 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7477 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7480 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7482 + nv_pair_list_elt_t *iter;
7483 + nv_pair_t *nv_pair;
7485 + for (iter = list->head; iter; iter = iter->next) {
7486 + nv_pair = iter->data;
7487 + if (strcmp(nv_pair->name, name) == 0) {
7488 + return nv_pair->value;
7493 Index: busybox-1.7.2/archival/libipkg/nv_pair_list.h
7494 ===================================================================
7495 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7496 +++ busybox-1.7.2/archival/libipkg/nv_pair_list.h 2007-10-30 15:35:05.000000000 -0500
7498 +/* nv_pair_list.h - the itsy package management system
7502 + Copyright (C) 2001 University of Southern California
7504 + This program is free software; you can redistribute it and/or
7505 + modify it under the terms of the GNU General Public License as
7506 + published by the Free Software Foundation; either version 2, or (at
7507 + your option) any later version.
7509 + This program is distributed in the hope that it will be useful, but
7510 + WITHOUT ANY WARRANTY; without even the implied warranty of
7511 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7512 + General Public License for more details.
7515 +#ifndef NV_PAIR_LIST_H
7516 +#define NV_PAIR_LIST_H
7518 +#include "nv_pair.h"
7519 +#include "void_list.h"
7521 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7522 +struct nv_pair_list_elt
7524 + nv_pair_list_elt_t *next;
7528 +typedef struct nv_pair_list nv_pair_list_t;
7529 +struct nv_pair_list
7531 + nv_pair_list_elt_t pre_head;
7532 + nv_pair_list_elt_t *head;
7533 + nv_pair_list_elt_t *tail;
7536 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7538 + if (list->head == NULL)
7544 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7545 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7547 +int nv_pair_list_init(nv_pair_list_t *list);
7548 +void nv_pair_list_deinit(nv_pair_list_t *list);
7550 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7551 + const char *name, const char *value);
7552 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7553 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7554 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7558 Index: busybox-1.7.2/archival/libipkg/pkg.c
7559 ===================================================================
7560 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
7561 +++ busybox-1.7.2/archival/libipkg/pkg.c 2007-10-30 15:35:05.000000000 -0500
7563 +/* pkg.c - the itsy package management system
7567 + Copyright (C) 2001 University of Southern California
7569 + This program is free software; you can redistribute it and/or
7570 + modify it under the terms of the GNU General Public License as
7571 + published by the Free Software Foundation; either version 2, or (at
7572 + your option) any later version.
7574 + This program is distributed in the hope that it will be useful, but
7575 + WITHOUT ANY WARRANTY; without even the implied warranty of
7576 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7577 + General Public License for more details.
7582 +#include <string.h>
7587 +#include "pkg_parse.h"
7588 +#include "pkg_extract.h"
7589 +#include "ipkg_message.h"
7590 +#include "ipkg_utils.h"
7592 +#include "sprintf_alloc.h"
7593 +#include "file_util.h"
7594 +#include "str_util.h"
7595 +#include "xsystem.h"
7596 +#include "ipkg_conf.h"
7598 +typedef struct enum_map enum_map_t;
7605 +static const enum_map_t pkg_state_want_map[] = {
7606 + { SW_UNKNOWN, "unknown"},
7607 + { SW_INSTALL, "install"},
7608 + { SW_DEINSTALL, "deinstall"},
7609 + { SW_PURGE, "purge"}
7612 +static const enum_map_t pkg_state_flag_map[] = {
7614 + { SF_REINSTREQ, "reinstreq"},
7615 + { SF_HOLD, "hold"},
7616 + { SF_REPLACE, "replace"},
7617 + { SF_NOPRUNE, "noprune"},
7618 + { SF_PREFER, "prefer"},
7619 + { SF_OBSOLETE, "obsolete"},
7620 + { SF_USER, "user"},
7623 +static const enum_map_t pkg_state_status_map[] = {
7624 + { SS_NOT_INSTALLED, "not-installed" },
7625 + { SS_UNPACKED, "unpacked" },
7626 + { SS_HALF_CONFIGURED, "half-configured" },
7627 + { SS_INSTALLED, "installed" },
7628 + { SS_HALF_INSTALLED, "half-installed" },
7629 + { SS_CONFIG_FILES, "config-files" },
7630 + { SS_POST_INST_FAILED, "post-inst-failed" },
7631 + { SS_REMOVAL_FAILED, "removal-failed" }
7634 +static int verrevcmp(const char *val, const char *ref);
7637 +pkg_t *pkg_new(void)
7641 + pkg = malloc(sizeof(pkg_t));
7642 + if (pkg == NULL) {
7643 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7652 +int pkg_init(pkg_t *pkg)
7654 + memset(pkg, 0, sizeof(pkg_t));
7657 + pkg->version = NULL;
7658 + pkg->revision = NULL;
7659 + pkg->familiar_revision = NULL;
7662 + pkg->architecture = NULL;
7663 + pkg->maintainer = NULL;
7664 + pkg->section = NULL;
7665 + pkg->description = NULL;
7666 + pkg->state_want = SW_UNKNOWN;
7667 + pkg->state_flag = SF_OK;
7668 + pkg->state_status = SS_NOT_INSTALLED;
7669 + pkg->depends_str = NULL;
7670 + pkg->provides_str = NULL;
7671 + pkg->depends_count = 0;
7672 + pkg->depends = NULL;
7673 + pkg->suggests_str = NULL;
7674 + pkg->recommends_str = NULL;
7675 + pkg->suggests_count = 0;
7676 + pkg->recommends_count = 0;
7678 + /* Abhaya: added init for conflicts fields */
7679 + pkg->conflicts = NULL;
7680 + pkg->conflicts_count = 0;
7682 + /* added for replaces. Jamey 7/23/2002 */
7683 + pkg->replaces = NULL;
7684 + pkg->replaces_count = 0;
7686 + pkg->pre_depends_count = 0;
7687 + pkg->pre_depends_str = NULL;
7688 + pkg->provides_count = 0;
7689 + pkg->provides = NULL;
7690 + pkg->filename = NULL;
7691 + pkg->local_filename = NULL;
7692 + pkg->tmp_unpack_dir = NULL;
7693 + pkg->md5sum = NULL;
7695 + pkg->installed_size = NULL;
7696 + pkg->priority = NULL;
7697 + pkg->source = NULL;
7698 + conffile_list_init(&pkg->conffiles);
7699 + pkg->installed_files = NULL;
7700 + pkg->installed_files_ref_cnt = 0;
7701 + pkg->essential = 0;
7702 + pkg->provided_by_hand = 0;
7707 +void pkg_deinit(pkg_t *pkg)
7712 + free(pkg->version);
7713 + pkg->version = NULL;
7714 + /* revision and familiar_revision share storage with version, so
7716 + pkg->revision = NULL;
7717 + pkg->familiar_revision = NULL;
7718 + /* owned by ipkg_conf_t */
7720 + /* owned by ipkg_conf_t */
7722 + free(pkg->architecture);
7723 + pkg->architecture = NULL;
7724 + free(pkg->maintainer);
7725 + pkg->maintainer = NULL;
7726 + free(pkg->section);
7727 + pkg->section = NULL;
7728 + free(pkg->description);
7729 + pkg->description = NULL;
7730 + pkg->state_want = SW_UNKNOWN;
7731 + pkg->state_flag = SF_OK;
7732 + pkg->state_status = SS_NOT_INSTALLED;
7733 + free(pkg->depends_str);
7734 + pkg->depends_str = NULL;
7735 + free(pkg->provides_str);
7736 + pkg->provides_str = NULL;
7737 + pkg->depends_count = 0;
7738 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7739 + pkg->pre_depends_count = 0;
7740 + free(pkg->pre_depends_str);
7741 + pkg->pre_depends_str = NULL;
7742 + pkg->provides_count = 0;
7743 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7744 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7745 + free(pkg->filename);
7746 + pkg->filename = NULL;
7747 + free(pkg->local_filename);
7748 + pkg->local_filename = NULL;
7749 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7750 + ipkg_install.c here. See comment in
7751 + ipkg_install.c:cleanup_temporary_files */
7752 + free(pkg->tmp_unpack_dir);
7753 + pkg->tmp_unpack_dir = NULL;
7754 + free(pkg->md5sum);
7755 + pkg->md5sum = NULL;
7758 + free(pkg->installed_size);
7759 + pkg->installed_size = NULL;
7760 + free(pkg->priority);
7761 + pkg->priority = NULL;
7762 + free(pkg->source);
7763 + pkg->source = NULL;
7764 + conffile_list_deinit(&pkg->conffiles);
7765 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7766 + since if they are calling deinit, they should know. Maybe do an
7767 + assertion here instead? */
7768 + pkg->installed_files_ref_cnt = 1;
7769 + pkg_free_installed_files(pkg);
7770 + pkg->essential = 0;
7773 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7777 + FILE *control_file;
7779 + err = pkg_init(pkg);
7780 + if (err) { return err; }
7782 + pkg->local_filename = strdup(filename);
7784 + control_file = tmpfile();
7785 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7786 + if (err) { return err; }
7788 + rewind(control_file);
7789 + raw = read_raw_pkgs_from_stream(control_file);
7790 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7792 + fclose(control_file);
7797 +/* Merge any new information in newpkg into oldpkg */
7798 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7799 + newpkg, but should leave it usable. This rework is so that
7800 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7802 + * uh, i thought that i had originally written this so that it took
7803 + * two pkgs and returned a new one? we can do that again... -sma
7805 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7807 + if (oldpkg == newpkg) {
7812 + oldpkg->src = newpkg->src;
7813 + if (!oldpkg->dest)
7814 + oldpkg->dest = newpkg->dest;
7815 + if (!oldpkg->architecture)
7816 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7817 + if (!oldpkg->arch_priority)
7818 + oldpkg->arch_priority = newpkg->arch_priority;
7819 + if (!oldpkg->section)
7820 + oldpkg->section = str_dup_safe(newpkg->section);
7821 + if(!oldpkg->maintainer)
7822 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7823 + if(!oldpkg->description)
7824 + oldpkg->description = str_dup_safe(newpkg->description);
7826 + /* merge the state_flags from the new package */
7827 + oldpkg->state_want = newpkg->state_want;
7828 + oldpkg->state_status = newpkg->state_status;
7829 + oldpkg->state_flag = newpkg->state_flag;
7831 + if (oldpkg->state_want == SW_UNKNOWN)
7832 + oldpkg->state_want = newpkg->state_want;
7833 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7834 + oldpkg->state_status = newpkg->state_status;
7835 + oldpkg->state_flag |= newpkg->state_flag;
7838 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7839 + oldpkg->depends_str = newpkg->depends_str;
7840 + newpkg->depends_str = NULL;
7841 + oldpkg->depends_count = newpkg->depends_count;
7842 + newpkg->depends_count = 0;
7844 + oldpkg->depends = newpkg->depends;
7845 + newpkg->depends = NULL;
7847 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7848 + newpkg->pre_depends_str = NULL;
7849 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7850 + newpkg->pre_depends_count = 0;
7852 + oldpkg->recommends_str = newpkg->recommends_str;
7853 + newpkg->recommends_str = NULL;
7854 + oldpkg->recommends_count = newpkg->recommends_count;
7855 + newpkg->recommends_count = 0;
7857 + oldpkg->suggests_str = newpkg->suggests_str;
7858 + newpkg->suggests_str = NULL;
7859 + oldpkg->suggests_count = newpkg->suggests_count;
7860 + newpkg->suggests_count = 0;
7863 + if (!oldpkg->provides_str) {
7864 + oldpkg->provides_str = newpkg->provides_str;
7865 + newpkg->provides_str = NULL;
7866 + oldpkg->provides_count = newpkg->provides_count;
7867 + newpkg->provides_count = 0;
7869 + oldpkg->provides = newpkg->provides;
7870 + newpkg->provides = NULL;
7873 + if (!oldpkg->conflicts_str) {
7874 + oldpkg->conflicts_str = newpkg->conflicts_str;
7875 + newpkg->conflicts_str = NULL;
7876 + oldpkg->conflicts_count = newpkg->conflicts_count;
7877 + newpkg->conflicts_count = 0;
7879 + oldpkg->conflicts = newpkg->conflicts;
7880 + newpkg->conflicts = NULL;
7883 + if (!oldpkg->replaces_str) {
7884 + oldpkg->replaces_str = newpkg->replaces_str;
7885 + newpkg->replaces_str = NULL;
7886 + oldpkg->replaces_count = newpkg->replaces_count;
7887 + newpkg->replaces_count = 0;
7889 + oldpkg->replaces = newpkg->replaces;
7890 + newpkg->replaces = NULL;
7893 + if (!oldpkg->filename)
7894 + oldpkg->filename = str_dup_safe(newpkg->filename);
7896 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7897 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7898 + if (!oldpkg->local_filename)
7899 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7900 + if (!oldpkg->tmp_unpack_dir)
7901 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7902 + if (!oldpkg->md5sum)
7903 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7904 + if (!oldpkg->size)
7905 + oldpkg->size = str_dup_safe(newpkg->size);
7906 + if (!oldpkg->installed_size)
7907 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7908 + if (!oldpkg->priority)
7909 + oldpkg->priority = str_dup_safe(newpkg->priority);
7910 + if (!oldpkg->source)
7911 + oldpkg->source = str_dup_safe(newpkg->source);
7912 + if (oldpkg->conffiles.head == NULL){
7913 + oldpkg->conffiles = newpkg->conffiles;
7914 + conffile_list_init(&newpkg->conffiles);
7916 + if (!oldpkg->installed_files){
7917 + oldpkg->installed_files = newpkg->installed_files;
7918 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7919 + newpkg->installed_files = NULL;
7921 + if (!oldpkg->essential)
7922 + oldpkg->essential = newpkg->essential;
7924 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7929 +abstract_pkg_t *abstract_pkg_new(void)
7931 + abstract_pkg_t * ab_pkg;
7933 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7935 + if (ab_pkg == NULL) {
7936 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7940 + if ( abstract_pkg_init(ab_pkg) < 0 )
7946 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7948 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7950 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7951 + if (ab_pkg->provided_by==NULL){
7954 + ab_pkg->dependencies_checked = 0;
7955 + ab_pkg->state_status = SS_NOT_INSTALLED;
7960 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7963 + char **raw_start=NULL;
7965 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7966 + if (temp_str == NULL ){
7967 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7970 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7972 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7973 + if (raw == NULL ){
7974 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7979 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7980 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7996 +char * pkg_formatted_info(pkg_t *pkg )
8001 + buff = malloc(8192);
8002 + if (buff == NULL) {
8003 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8009 + line = pkg_formatted_field(pkg, "Package");
8010 + strncat(buff ,line, strlen(line));
8013 + line = pkg_formatted_field(pkg, "Version");
8014 + strncat(buff ,line, strlen(line));
8017 + line = pkg_formatted_field(pkg, "Depends");
8018 + strncat(buff ,line, strlen(line));
8021 + line = pkg_formatted_field(pkg, "Recommends");
8022 + strncat(buff ,line, strlen(line));
8025 + line = pkg_formatted_field(pkg, "Suggests");
8026 + strncat(buff ,line, strlen(line));
8029 + line = pkg_formatted_field(pkg, "Provides");
8030 + strncat(buff ,line, strlen(line));
8033 + line = pkg_formatted_field(pkg, "Replaces");
8034 + strncat(buff ,line, strlen(line));
8037 + line = pkg_formatted_field(pkg, "Conflicts");
8038 + strncat(buff ,line, strlen(line));
8041 + line = pkg_formatted_field(pkg, "Status");
8042 + strncat(buff ,line, strlen(line));
8045 + line = pkg_formatted_field(pkg, "Section");
8046 + strncat(buff ,line, strlen(line));
8049 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8050 + strncat(buff ,line, strlen(line));
8053 + line = pkg_formatted_field(pkg, "Architecture");
8054 + strncat(buff ,line, strlen(line));
8057 + line = pkg_formatted_field(pkg, "Maintainer");
8058 + strncat(buff ,line, strlen(line));
8061 + line = pkg_formatted_field(pkg, "MD5sum");
8062 + strncat(buff ,line, strlen(line));
8065 + line = pkg_formatted_field(pkg, "Size");
8066 + strncat(buff ,line, strlen(line));
8069 + line = pkg_formatted_field(pkg, "Filename");
8070 + strncat(buff ,line, strlen(line));
8073 + line = pkg_formatted_field(pkg, "Conffiles");
8074 + strncat(buff ,line, strlen(line));
8077 + line = pkg_formatted_field(pkg, "Source");
8078 + strncat(buff ,line, strlen(line));
8081 + line = pkg_formatted_field(pkg, "Description");
8082 + strncat(buff ,line, strlen(line));
8085 + line = pkg_formatted_field(pkg, "Installed-Time");
8086 + strncat(buff ,line, strlen(line));
8092 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8094 + static size_t LINE_LEN = 128;
8095 + char line_str[LINE_LEN];
8096 + char * temp = (char *)malloc(1);
8098 + int flag_provide_false = 0;
8101 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8102 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8105 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8106 + goto UNKNOWN_FMT_FIELD;
8115 + if (strcasecmp(field, "Architecture") == 0) {
8116 + /* Architecture */
8117 + if (pkg->architecture) {
8118 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8119 + if ( temp == NULL ){
8120 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8124 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8127 + goto UNKNOWN_FMT_FIELD;
8132 + if (strcasecmp(field, "Conffiles") == 0) {
8134 + conffile_list_elt_t *iter;
8136 + if (pkg->conffiles.head == NULL) {
8141 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8142 + if (iter->data->name && iter->data->value) {
8143 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8146 + temp = (char *)realloc(temp,len);
8147 + if ( temp == NULL ){
8148 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8152 + strncpy(temp, "Conffiles:\n", 12);
8153 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8154 + if (iter->data->name && iter->data->value) {
8155 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8156 + strncat(temp, line_str, strlen(line_str));
8159 + } else if (strcasecmp(field, "Conflicts") == 0) {
8162 + if (pkg->conflicts_count) {
8164 + for(i = 0; i < pkg->conflicts_count; i++) {
8165 + len = len + (strlen(pkg->conflicts_str[i])+5);
8167 + temp = (char *)realloc(temp,len);
8168 + if ( temp == NULL ){
8169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8173 + strncpy(temp, "Conflicts:", 11);
8174 + for(i = 0; i < pkg->conflicts_count; i++) {
8175 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8176 + strncat(temp, line_str, strlen(line_str));
8178 + strncat(temp, "\n", strlen("\n"));
8181 + goto UNKNOWN_FMT_FIELD;
8186 + if (strcasecmp(field, "Depends") == 0) {
8190 + if (pkg->depends_count) {
8192 + for(i = 0; i < pkg->depends_count; i++) {
8193 + len = len + (strlen(pkg->depends_str[i])+4);
8195 + temp = (char *)realloc(temp,len);
8196 + if ( temp == NULL ){
8197 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8201 + strncpy(temp, "Depends:", 10);
8202 + for(i = 0; i < pkg->depends_count; i++) {
8203 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8204 + strncat(temp, line_str, strlen(line_str));
8206 + strncat(temp, "\n", strlen("\n"));
8208 + } else if (strcasecmp(field, "Description") == 0) {
8210 + if (pkg->description) {
8211 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8212 + if ( temp == NULL ){
8213 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8217 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8220 + goto UNKNOWN_FMT_FIELD;
8226 + if (pkg->essential) {
8227 + temp = (char *)realloc(temp,16);
8228 + if ( temp == NULL ){
8229 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8233 + snprintf(temp, (16), "Essential: yes\n");
8240 + if (pkg->filename) {
8241 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8242 + if ( temp == NULL ){
8243 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8247 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8253 + if (strcasecmp(field, "Installed-Size") == 0) {
8254 + /* Installed-Size */
8255 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8256 + if ( temp == NULL ){
8257 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8261 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8262 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8263 + temp = (char *)realloc(temp,29);
8264 + if ( temp == NULL ){
8265 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8269 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8275 + /* Maintainer | MD5sum */
8276 + if (strcasecmp(field, "Maintainer") == 0) {
8278 + if (pkg->maintainer) {
8279 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8280 + if ( temp == NULL ){
8281 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8285 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8287 + } else if (strcasecmp(field, "MD5sum") == 0) {
8289 + if (pkg->md5sum) {
8290 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8291 + if ( temp == NULL ){
8292 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8296 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8299 + goto UNKNOWN_FMT_FIELD;
8305 + if (strcasecmp(field, "Package") == 0) {
8307 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8308 + if ( temp == NULL ){
8309 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8313 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8314 + } else if (strcasecmp(field, "Priority") == 0) {
8316 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8317 + if ( temp == NULL ){
8318 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8322 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8323 + } else if (strcasecmp(field, "Provides") == 0) {
8327 + if (pkg->provides_count) {
8328 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8329 + for ( i=0; i < pkg->provides_count; i++ ){
8330 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8331 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8332 + flag_provide_false = 1;
8335 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8336 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8337 + char provstr[LINE_LEN];
8339 + for(i = 0; i < pkg->provides_count; i++) {
8340 + len = len + (strlen(pkg->provides_str[i])+5);
8342 + temp = (char *)realloc(temp,len);
8343 + if ( temp == NULL ){
8344 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8348 + strncpy(temp, "Provides:", 12);
8349 + for(i = 0; i < pkg->provides_count; i++) {
8350 + if (strlen(pkg->provides_str[i])>0){;
8351 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8352 + strncat(temp, provstr, strlen(provstr));
8355 + strncat(temp, "\n", strlen("\n"));
8359 + goto UNKNOWN_FMT_FIELD;
8366 + /* Replaces | Recommends*/
8367 + if (strcasecmp (field, "Replaces") == 0) {
8368 + if (pkg->replaces_count) {
8370 + for (i = 0; i < pkg->replaces_count; i++) {
8371 + len = len + (strlen(pkg->replaces_str[i])+5);
8373 + temp = (char *)realloc(temp,len);
8374 + if ( temp == NULL ){
8375 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8379 + strncpy(temp, "Replaces:", 12);
8380 + for (i = 0; i < pkg->replaces_count; i++) {
8381 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8382 + strncat(temp, line_str, strlen(line_str));
8384 + strncat(temp, "\n", strlen("\n"));
8386 + } else if (strcasecmp (field, "Recommends") == 0) {
8387 + if (pkg->recommends_count) {
8389 + for(i = 0; i < pkg->recommends_count; i++) {
8390 + len = len + (strlen( pkg->recommends_str[i])+5);
8392 + temp = (char *)realloc(temp,len);
8393 + if ( temp == NULL ){
8394 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8398 + strncpy(temp, "Recommends:", 13);
8399 + for(i = 0; i < pkg->recommends_count; i++) {
8400 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8401 + strncat(temp, line_str, strlen(line_str));
8403 + strncat(temp, "\n", strlen("\n"));
8406 + goto UNKNOWN_FMT_FIELD;
8412 + /* Section | Size | Source | Status | Suggests */
8413 + if (strcasecmp(field, "Section") == 0) {
8415 + if (pkg->section) {
8416 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8417 + if ( temp == NULL ){
8418 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8422 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8424 + } else if (strcasecmp(field, "Size") == 0) {
8427 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8428 + if ( temp == NULL ){
8429 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8433 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8435 + } else if (strcasecmp(field, "Source") == 0) {
8437 + if (pkg->source) {
8438 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8439 + if ( temp == NULL ){
8440 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8444 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8446 + } else if (strcasecmp(field, "Status") == 0) {
8448 + /* Benjamin Pineau note: we should avoid direct usage of
8449 + * strlen(arg) without keeping "arg" for later free()
8451 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8452 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8453 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8455 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8456 + temp = (char *)realloc(temp,sum_of_sizes);
8457 + if ( temp == NULL ){
8458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8462 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8465 + if(pstat) /* pfstat can be NULL if ENOMEM */
8467 + } else if (strcasecmp(field, "Suggests") == 0) {
8468 + if (pkg->suggests_count) {
8471 + for(i = 0; i < pkg->suggests_count; i++) {
8472 + len = len + (strlen(pkg->suggests_str[i])+5);
8474 + temp = (char *)realloc(temp,len);
8475 + if ( temp == NULL ){
8476 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8480 + strncpy(temp, "Suggests:", 10);
8481 + for(i = 0; i < pkg->suggests_count; i++) {
8482 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8483 + strncat(temp, line_str, strlen(line_str));
8485 + strncat(temp, "\n", strlen("\n"));
8488 + goto UNKNOWN_FMT_FIELD;
8495 + char *version = pkg_version_str_alloc(pkg);
8496 + temp = (char *)realloc(temp,strlen(version)+14);
8497 + if ( temp == NULL ){
8498 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8502 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8507 + goto UNKNOWN_FMT_FIELD;
8510 + if ( strlen(temp)<2 ) {
8515 + UNKNOWN_FMT_FIELD:
8516 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8517 + if ( strlen(temp)<2 ) {
8524 +void pkg_print_info(pkg_t *pkg, FILE *file)
8527 + if (pkg == NULL) {
8531 + buff = pkg_formatted_info(pkg);
8532 + if ( buff == NULL )
8534 + if (strlen(buff)>2){
8535 + fwrite(buff, 1, strlen(buff), file);
8540 +void pkg_print_status(pkg_t * pkg, FILE * file)
8542 + if (pkg == NULL) {
8546 + /* XXX: QUESTION: Do we actually want more fields here? The
8547 + original idea was to save space by installing only what was
8548 + needed for actual computation, (package, version, status,
8549 + essential, conffiles). The assumption is that all other fields
8550 + can be found in th available file.
8552 + But, someone proposed the idea to make it possible to
8553 + reconstruct a .ipk from an installed package, (ie. for beaming
8554 + from one handheld to another). So, maybe we actually want a few
8555 + more fields here, (depends, suggests, etc.), so that that would
8556 + be guaranteed to work even in the absence of more information
8557 + from the available file.
8559 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8560 + the essential info needs to be here for all installed packages
8561 + because they may not appear in the Packages files on various
8562 + feeds. Furthermore, one should be able to install from URL or
8563 + local storage without requiring a Packages file from any feed.
8566 + pkg_print_field(pkg, file, "Package");
8567 + pkg_print_field(pkg, file, "Version");
8568 + pkg_print_field(pkg, file, "Depends");
8569 + pkg_print_field(pkg, file, "Recommends");
8570 + pkg_print_field(pkg, file, "Suggests");
8571 + pkg_print_field(pkg, file, "Provides");
8572 + pkg_print_field(pkg, file, "Replaces");
8573 + pkg_print_field(pkg, file, "Conflicts");
8574 + pkg_print_field(pkg, file, "Status");
8575 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8576 + pkg_print_field(pkg, file, "Architecture");
8577 + pkg_print_field(pkg, file, "Conffiles");
8578 + pkg_print_field(pkg, file, "Installed-Time");
8579 + fputs("\n", file);
8582 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8585 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8586 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8587 + __FUNCTION__, field);
8589 + buff = pkg_formatted_field(pkg, field);
8590 + if (strlen(buff)>2) {
8591 + fprintf(file, "%s", buff);
8599 + * libdpkg - Debian packaging suite library routines
8600 + * vercmp.c - comparison of version numbers
8602 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8604 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8608 + if (pkg->epoch > ref_pkg->epoch) {
8612 + if (pkg->epoch < ref_pkg->epoch) {
8616 + r = verrevcmp(pkg->version, ref_pkg->version);
8621 +#ifdef USE_DEBVERSION
8622 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8627 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8633 +int verrevcmp(const char *val, const char *ref)
8637 + const char *vp, *rp;
8638 + const char *vsep, *rsep;
8640 + if (!val) val= "";
8641 + if (!ref) ref= "";
8643 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8644 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8646 + vc= (val == vp) ? 0 : *val++;
8647 + rc= (ref == rp) ? 0 : *ref++;
8648 + if (!rc && !vc) break;
8649 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8650 + if (rc && !isalpha(rc)) rc += 256;
8651 + if (vc != rc) return vc - rc;
8655 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8656 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8657 + if (vl != rl) return vl - rl;
8661 + vsep = strchr(".-", vc);
8662 + rsep = strchr(".-", rc);
8663 + if (vsep && !rsep) return -1;
8664 + if (!vsep && rsep) return +1;
8666 + if (!*val && !*ref) return 0;
8667 + if (!*val) return -1;
8668 + if (!*ref) return +1;
8672 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8676 + r = pkg_compare_versions(it, ref);
8678 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8682 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8686 + if (strcmp(op, "<<") == 0) {
8690 + if (strcmp(op, ">>") == 0) {
8694 + if (strcmp(op, "=") == 0) {
8698 + fprintf(stderr, "unknown operator: %s", op);
8702 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8706 + if (!a->name || !b->name) {
8707 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8708 + a, a->name, b, b->name);
8712 + namecmp = strcmp(a->name, b->name);
8715 + vercmp = pkg_compare_versions(a, b);
8718 + if (!a->arch_priority || !b->arch_priority) {
8719 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8720 + a, a->arch_priority, b, b->arch_priority);
8723 + if (a->arch_priority > b->arch_priority)
8725 + if (a->arch_priority < b->arch_priority)
8730 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8732 + if (!a->name || !b->name) {
8733 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8734 + a, a->name, b, b->name);
8737 + return strcmp(a->name, b->name);
8741 +char *pkg_version_str_alloc(pkg_t *pkg)
8743 + char *complete_version;
8745 +#ifdef USE_DEBVERSION
8746 + char *revision_str;
8747 + char *familiar_revision_str;
8751 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8753 + epoch_str = strdup("");
8756 +#ifdef USE_DEBVERSION
8757 + if (pkg->revision && strlen(pkg->revision)) {
8758 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8760 + revision_str = strdup("");
8763 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8764 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8766 + familiar_revision_str = strdup("");
8770 +#ifdef USE_DEBVERSION
8771 + sprintf_alloc(&complete_version, "%s%s%s%s",
8772 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8774 + sprintf_alloc(&complete_version, "%s%s",
8775 + epoch_str, pkg->version);
8779 +#ifdef USE_DEBVERSION
8780 + free(revision_str);
8781 + free(familiar_revision_str);
8784 + return complete_version;
8787 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8790 + char *list_file_name = NULL;
8791 + FILE *list_file = NULL;
8793 + char *installed_file_name;
8796 + pkg->installed_files_ref_cnt++;
8798 + if (pkg->installed_files) {
8799 + return pkg->installed_files;
8802 + pkg->installed_files = str_list_alloc();
8803 + if (pkg->installed_files == NULL) {
8804 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8808 + /* For uninstalled packages, get the file list firectly from the package.
8809 + For installed packages, look at the package.list file in the database.
8811 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8812 + if (pkg->local_filename == NULL) {
8813 + return pkg->installed_files;
8815 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8816 + file. In other words, change deb_extract so that it can
8817 + simply return the file list as a char *[] rather than
8818 + insisting on writing in to a FILE * as it does now. */
8819 + list_file = tmpfile();
8820 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8822 + fclose(list_file);
8823 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8824 + __FUNCTION__, pkg->local_filename, strerror(err));
8825 + return pkg->installed_files;
8827 + rewind(list_file);
8829 + sprintf_alloc(&list_file_name, "%s/%s.list",
8830 + pkg->dest->info_dir, pkg->name);
8831 + if (! file_exists(list_file_name)) {
8832 + free(list_file_name);
8833 + return pkg->installed_files;
8836 + list_file = fopen(list_file_name, "r");
8837 + if (list_file == NULL) {
8838 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8839 + list_file_name, strerror(errno));
8840 + free(list_file_name);
8841 + return pkg->installed_files;
8843 + free(list_file_name);
8846 + rootdirlen = strlen( pkg->dest->root_dir );
8850 + line = file_read_line_alloc(list_file);
8851 + if (line == NULL) {
8857 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8858 + if( strncmp( pkg->dest->root_dir,
8861 + if (*file_name == '.') {
8864 + if (*file_name == '/') {
8868 + /* Freed in pkg_free_installed_files */
8869 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8871 + // already contains root_dir as header -> ABSOLUTE
8872 + sprintf_alloc(&installed_file_name, "%s", file_name);
8874 + str_list_append(pkg->installed_files, installed_file_name);
8878 + fclose(list_file);
8880 + return pkg->installed_files;
8883 +/* XXX: CLEANUP: This function and it's counterpart,
8884 + (pkg_get_installed_files), do not match our init/deinit naming
8885 + convention. Nor the alloc/free convention. But, then again, neither
8886 + of these conventions currrently fit the way these two functions
8888 +int pkg_free_installed_files(pkg_t *pkg)
8890 + str_list_elt_t *iter;
8892 + pkg->installed_files_ref_cnt--;
8893 + if (pkg->installed_files_ref_cnt > 0) {
8897 + if (pkg->installed_files) {
8899 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8900 + /* malloced in pkg_get_installed_files */
8901 + free (iter->data);
8902 + iter->data = NULL;
8905 + str_list_deinit(pkg->installed_files);
8908 + pkg->installed_files = NULL;
8913 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8916 + char *list_file_name;
8918 + //I don't think pkg_free_installed_files should be called here. Jamey
8919 + //pkg_free_installed_files(pkg);
8921 + sprintf_alloc(&list_file_name, "%s/%s.list",
8922 + pkg->dest->info_dir, pkg->name);
8923 + if (!conf->noaction) {
8924 + err = unlink(list_file_name);
8925 + free(list_file_name);
8934 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8936 + conffile_list_elt_t *iter;
8937 + conffile_t *conffile;
8939 + if (pkg == NULL) {
8943 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8944 + conffile = iter->data;
8946 + if (strcmp(conffile->name, file_name) == 0) {
8954 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8955 + const char *script, const char *args)
8961 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8962 + maintainer script within a chroot environment. */
8964 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8965 + have scripts in pkg->tmp_unpack_dir. */
8966 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8967 + if (pkg->dest == NULL) {
8968 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8969 + __FUNCTION__, pkg->name);
8972 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8974 + if (pkg->tmp_unpack_dir == NULL) {
8975 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8976 + __FUNCTION__, pkg->name);
8979 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8982 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8983 + if (conf->noaction) return 0;
8985 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8986 + scripts when running with offline_root mode and/or a dest other
8987 + than '/'. I've been playing around with some clever chroot
8988 + tricks and I might come up with something workable. */
8989 + if (conf->offline_root) {
8990 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8993 + setenv("PKG_ROOT",
8994 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8996 + if (! file_exists(path)) {
9001 + if (conf->offline_root) {
9002 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9007 + sprintf_alloc(&cmd, "%s %s", path, args);
9010 + err = xsystem(cmd);
9014 + fprintf(stderr, "%s script returned status %d\n", script, err);
9021 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9025 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9026 + if (pkg_state_want_map[i].value == sw) {
9027 + return strdup(pkg_state_want_map[i].str);
9031 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9032 + __FUNCTION__, sw);
9033 + return strdup("<STATE_WANT_UNKNOWN>");
9036 +pkg_state_want_t pkg_state_want_from_str(char *str)
9040 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9041 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9042 + return pkg_state_want_map[i].value;
9046 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9047 + __FUNCTION__, str);
9048 + return SW_UNKNOWN;
9051 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9054 + int len = 3; /* ok\000 is minimum */
9057 + /* clear the temporary flags before converting to string */
9058 + sf &= SF_NONVOLATILE_FLAGS;
9061 + return strdup("ok");
9064 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9065 + if (sf & pkg_state_flag_map[i].value) {
9066 + len += strlen(pkg_state_flag_map[i].str) + 1;
9069 + str = malloc(len);
9070 + if ( str == NULL ) {
9071 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9075 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9076 + if (sf & pkg_state_flag_map[i].value) {
9077 + strcat(str, pkg_state_flag_map[i].str);
9081 + len = strlen(str);
9082 + str[len-1] = 0; /* squash last comma */
9087 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9092 + if (strcmp(str, "ok") == 0) {
9095 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9096 + const char *sfname = pkg_state_flag_map[i].str;
9097 + int sfname_len = strlen(sfname);
9098 + if (strncmp(str, sfname, sfname_len) == 0) {
9099 + sf |= pkg_state_flag_map[i].value;
9100 + str += sfname_len;
9101 + if (str[0] == ',') {
9112 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9116 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9117 + if (pkg_state_status_map[i].value == ss) {
9118 + return strdup(pkg_state_status_map[i].str);
9122 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9123 + __FUNCTION__, ss);
9124 + return strdup("<STATE_STATUS_UNKNOWN>");
9127 +pkg_state_status_t pkg_state_status_from_str(char *str)
9131 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9132 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9133 + return pkg_state_status_map[i].value;
9137 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9138 + __FUNCTION__, str);
9139 + return SS_NOT_INSTALLED;
9142 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9144 + nv_pair_list_elt_t *l;
9146 + if (!pkg->architecture)
9149 + l = conf->arch_list.head;
9152 + nv_pair_t *nv = l->data;
9153 + if (strcmp(nv->name, pkg->architecture) == 0) {
9154 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9160 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9164 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9166 + nv_pair_list_elt_t *l;
9168 + l = conf->arch_list.head;
9171 + nv_pair_t *nv = l->data;
9172 + if (strcmp(nv->name, archname) == 0) {
9173 + int priority = strtol(nv->value, NULL, 0);
9181 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9184 + hash_table_t *pkg_hash = &conf->pkg_hash;
9185 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9186 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9188 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9189 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9190 + /* update arch_priority for each package */
9191 + for (i = 0; i < available_pkgs->len; i++) {
9192 + pkg_t *pkg = available_pkgs->pkgs[i];
9193 + int arch_priority = 1;
9196 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9197 + if (pkg->architecture)
9198 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9200 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9201 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9202 + pkg->arch_priority = arch_priority;
9205 + for (i = 0; i < available_pkgs->len; i++) {
9206 + pkg_t *pkg = available_pkgs->pkgs[i];
9207 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9208 + /* clear flags and want for any uninstallable package */
9209 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9210 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9211 + pkg->state_want = SW_UNKNOWN;
9212 + pkg->state_flag = 0;
9215 + pkg_vec_free(available_pkgs);
9217 + /* update the file owner data structure */
9218 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9219 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9220 + for (i = 0; i < installed_pkgs->len; i++) {
9221 + pkg_t *pkg = installed_pkgs->pkgs[i];
9222 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9223 + str_list_elt_t *iter;
9224 + if (installed_files == NULL) {
9225 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9228 + for (iter = installed_files->head; iter; iter = iter->next) {
9229 + char *installed_file = iter->data;
9230 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9231 + file_hash_set_file_owner(conf, installed_file, pkg);
9234 + pkg_vec_free(installed_pkgs);
9239 +struct pkg_write_filelist_data {
9240 + ipkg_conf_t *conf;
9245 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9247 + struct pkg_write_filelist_data *data = data_;
9248 + pkg_t *entry = entry_;
9249 + if (entry == data->pkg) {
9250 + fprintf(data->stream, "%s\n", key);
9254 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9256 + struct pkg_write_filelist_data data;
9257 + char *list_file_name = NULL;
9261 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9264 + ipkg_message(conf, IPKG_INFO,
9265 + " creating %s.list file\n", pkg->name);
9266 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9267 + if (!list_file_name) {
9268 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9271 + ipkg_message(conf, IPKG_INFO,
9272 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9273 + data.stream = fopen(list_file_name, "w");
9274 + if (!data.stream) {
9275 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9276 + list_file_name, strerror(errno));
9281 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9282 + fclose(data.stream);
9283 + free(list_file_name);
9288 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9290 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9291 + hash_table_t *pkg_hash = &conf->pkg_hash;
9294 + if (conf->noaction)
9297 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9298 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9299 + for (i = 0; i < installed_pkgs->len; i++) {
9300 + pkg_t *pkg = installed_pkgs->pkgs[i];
9301 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9302 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9303 + err = pkg_write_filelist(conf, pkg);
9305 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9310 Index: busybox-1.7.2/archival/libipkg/pkg_depends.c
9311 ===================================================================
9312 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
9313 +++ busybox-1.7.2/archival/libipkg/pkg_depends.c 2007-10-30 15:35:05.000000000 -0500
9315 +/* pkg_depends.c - the itsy package management system
9319 + Copyright (C) 2002 Compaq Computer Corporation
9321 + This program is free software; you can redistribute it and/or
9322 + modify it under the terms of the GNU General Public License as
9323 + published by the Free Software Foundation; either version 2, or (at
9324 + your option) any later version.
9326 + This program is distributed in the hope that it will be useful, but
9327 + WITHOUT ANY WARRANTY; without even the implied warranty of
9328 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9329 + General Public License for more details.
9337 +#include "ipkg_utils.h"
9338 +#include "pkg_hash.h"
9339 +#include "ipkg_message.h"
9340 +#include "pkg_parse.h"
9341 +#include "hash_table.h"
9343 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9344 +static depend_t * depend_init(void);
9345 +static void depend_deinit(depend_t *d);
9346 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9347 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9348 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9350 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9352 + depend_t *depend = (depend_t *)cdata;
9353 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9359 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9361 + depend_t *depend = (depend_t *)cdata;
9363 + pkg_t * temp = pkg_new();
9365 + parseVersion(temp, depend->version);
9366 + comparison = pkg_compare_versions(pkg, temp);
9369 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9370 + __FUNCTION__, pkg->name, pkg->version,
9371 + depend, depend->constraint, depend->version,
9372 + comparison, version_constraints_satisfied(depend, pkg));
9374 + if (version_constraints_satisfied(depend, pkg))
9380 +/* returns ndependences or negative error value */
9381 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9382 + pkg_vec_t *unsatisfied, char *** unresolved)
9384 + pkg_t * satisfier_entry_pkg;
9385 + register int i, j, k, l;
9388 + abstract_pkg_t * ab_pkg;
9391 + * this is a setup to check for redundant/cyclic dependency checks,
9392 + * which are marked at the abstract_pkg level
9394 + if (!(ab_pkg = pkg->parent)) {
9395 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9396 + *unresolved = NULL;
9399 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9400 + *unresolved = NULL;
9403 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9407 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9409 + *unresolved = NULL;
9415 + /* foreach dependency */
9416 + for (i = 0; i < count; i++) {
9417 + compound_depend_t * compound_depend = &pkg->depends[i];
9418 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9420 + satisfier_entry_pkg = NULL;
9422 + if (compound_depend->type == GREEDY_DEPEND) {
9423 + /* foreach possible satisfier */
9424 + for (j = 0; j < compound_depend->possibility_count; j++) {
9425 + /* foreach provided_by, which includes the abstract_pkg itself */
9426 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9427 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9428 + int nposs = ab_provider_vec->len;
9429 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9430 + for (l = 0; l < nposs; l++) {
9431 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9432 + /* if no depends on this one, try the first package that Provides this one */
9433 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9437 + /* cruise this possiblity's pkg_vec looking for an installed version */
9438 + for (k = 0; k < test_vec->len; k++) {
9439 + pkg_t *pkg_scout = test_vec->pkgs[k];
9440 + /* not installed, and not already known about? */
9441 + if ((pkg_scout->state_want != SW_INSTALL)
9442 + && !pkg_scout->parent->dependencies_checked
9443 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9444 + char ** newstuff = NULL;
9446 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9447 + /* check for not-already-installed dependencies */
9448 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9452 + if (newstuff == NULL) {
9454 + for (l = 0; l < rc; l++) {
9455 + pkg_t *p = tmp_vec->pkgs[l];
9456 + if (p->state_want == SW_INSTALL)
9458 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9462 + pkg_vec_free (tmp_vec);
9464 + /* mark this one for installation */
9465 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9466 + pkg_vec_insert(unsatisfied, pkg_scout);
9469 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9480 + /* foreach possible satisfier, look for installed package */
9481 + for (j = 0; j < compound_depend->possibility_count; j++) {
9482 + /* foreach provided_by, which includes the abstract_pkg itself */
9483 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9484 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9485 + pkg_t *satisfying_pkg =
9486 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9487 + pkg_installed_and_constraint_satisfied,
9488 + dependence_to_satisfy, 1);
9489 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9490 + if (satisfying_pkg != NULL) {
9491 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9492 + satisfying_pkg = NULL;
9495 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9496 + if (satisfying_pkg != NULL) {
9502 + /* if nothing installed matches, then look for uninstalled satisfier */
9504 + /* foreach possible satisfier, look for installed package */
9505 + for (j = 0; j < compound_depend->possibility_count; j++) {
9506 + /* foreach provided_by, which includes the abstract_pkg itself */
9507 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9508 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9509 + pkg_t *satisfying_pkg =
9510 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9511 + pkg_constraint_satisfied,
9512 + dependence_to_satisfy, 1);
9513 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9514 + if (satisfying_pkg != NULL) {
9515 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9516 + satisfying_pkg = NULL;
9520 + /* user request overrides package recommendation */
9521 + if (satisfying_pkg != NULL
9522 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9523 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9524 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9525 + pkg->name, satisfying_pkg->name);
9529 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9530 + if (satisfying_pkg != NULL) {
9531 + satisfier_entry_pkg = satisfying_pkg;
9537 + /* we didn't find one, add something to the unsatisfied vector */
9539 + if (!satisfier_entry_pkg) {
9540 + /* failure to meet recommendations is not an error */
9541 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9542 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9544 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9545 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9548 + if (compound_depend->type == SUGGEST) {
9549 + /* just mention it politely */
9550 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9551 + pkg->name, satisfier_entry_pkg->name);
9553 + char ** newstuff = NULL;
9555 + if (satisfier_entry_pkg != pkg &&
9556 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9557 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9558 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9559 + satisfier_entry_pkg,
9562 + the_lost = merge_unresolved(the_lost, newstuff);
9568 + *unresolved = the_lost;
9570 + return unsatisfied->len;
9573 +/*checking for conflicts !in replaces
9574 + If a packages conflicts with another but is also replacing it, I should not consider it a
9576 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9578 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9581 + int replaces_count = pkg->replaces_count;
9582 + abstract_pkg_t **replaces;
9584 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9587 + replaces = pkg->replaces;
9589 + for (i = 0; i < replaces_count; i++) {
9590 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9591 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9600 +/* Abhaya: added support for conflicts */
9601 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9603 + pkg_vec_t * installed_conflicts, * test_vec;
9604 + compound_depend_t * conflicts;
9605 + depend_t ** possible_satisfiers;
9606 + depend_t * possible_satisfier;
9607 + register int i, j, k;
9609 + abstract_pkg_t * ab_pkg;
9610 + pkg_t **pkg_scouts;
9614 + * this is a setup to check for redundant/cyclic dependency checks,
9615 + * which are marked at the abstract_pkg level
9617 + if(!(ab_pkg = pkg->parent)){
9618 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9619 + return (pkg_vec_t *)NULL;
9622 + conflicts = pkg->conflicts;
9624 + return (pkg_vec_t *)NULL;
9626 + installed_conflicts = pkg_vec_alloc();
9628 + count = pkg->conflicts_count;
9632 + /* foreach conflict */
9633 + for(i = 0; i < pkg->conflicts_count; i++){
9635 + possible_satisfiers = conflicts->possibilities;
9637 + /* foreach possible satisfier */
9638 + for(j = 0; j < conflicts->possibility_count; j++){
9639 + possible_satisfier = possible_satisfiers[j];
9640 + if (!possible_satisfier)
9641 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9642 + if (!possible_satisfier->pkg)
9643 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9644 + test_vec = possible_satisfier->pkg->pkgs;
9646 + /* pkg_vec found, it is an actual package conflict
9647 + * cruise this possiblity's pkg_vec looking for an installed version */
9648 + pkg_scouts = test_vec->pkgs;
9649 + for(k = 0; k < test_vec->len; k++){
9650 + pkg_scout = pkg_scouts[k];
9652 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9655 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9656 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9657 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9658 + pkg_vec_insert(installed_conflicts, pkg_scout);
9667 + if (installed_conflicts->len)
9668 + return installed_conflicts;
9669 + pkg_vec_free(installed_conflicts);
9670 + return (pkg_vec_t *)NULL;
9673 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9678 + if(depends->constraint == NONE)
9683 + parseVersion(temp, depends->version);
9685 + comparison = pkg_compare_versions(pkg, temp);
9689 + if((depends->constraint == EARLIER) &&
9692 + else if((depends->constraint == LATER) &&
9695 + else if(comparison == 0)
9697 + else if((depends->constraint == LATER_EQUAL) &&
9698 + (comparison >= 0))
9700 + else if((depends->constraint == EARLIER_EQUAL) &&
9701 + (comparison <= 0))
9707 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9709 + abstract_pkg_t *apkg = depend->pkg;
9710 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9711 + int n_providers = provider_apkgs->len;
9712 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9713 + pkg_vec_t *pkg_vec;
9718 + for (i = 0; i < n_providers; i++) {
9719 + abstract_pkg_t *papkg = apkgs[i];
9720 + pkg_vec = papkg->pkgs;
9722 + n_pkgs = pkg_vec->len;
9723 + for (j = 0; j < n_pkgs; j++) {
9724 + pkg_t *pkg = pkg_vec->pkgs[j];
9725 + if (version_constraints_satisfied(depend, pkg)) {
9734 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9736 + abstract_pkg_t *apkg = depend->pkg;
9737 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9738 + int n_providers = provider_apkgs->len;
9739 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9744 + for (i = 0; i < n_providers; i++) {
9745 + abstract_pkg_t *papkg = apkgs[i];
9746 + pkg_vec_t *pkg_vec = papkg->pkgs;
9748 + n_pkgs = pkg_vec->len;
9749 + for (j = 0; j < n_pkgs; j++) {
9750 + pkg_t *pkg = pkg_vec->pkgs[j];
9751 + if (version_constraints_satisfied(depend, pkg)) {
9752 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9761 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9764 + pkg_t ** pkgs = vec->pkgs;
9766 + for(i = 0; i < vec->len; i++)
9767 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9768 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9769 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9777 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9778 + * the same abstract package and 0 otherwise.
9780 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9782 + abstract_pkg_t **provides = pkg->provides;
9783 + int provides_count = pkg->provides_count;
9784 + abstract_pkg_t **replacee_provides = replacee->provides;
9785 + int replacee_provides_count = replacee->provides_count;
9787 + for (i = 0; i < provides_count; i++) {
9788 + abstract_pkg_t *apkg = provides[i];
9789 + for (j = 0; j < replacee_provides_count; j++) {
9790 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9791 + if (apkg == replacee_apkg)
9800 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9801 + * and 0 otherwise.
9803 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9805 + abstract_pkg_t **provides = pkg->provides;
9806 + int provides_count = pkg->provides_count;
9808 + for (i = 0; i < provides_count; i++) {
9809 + if (provides[i] == providee)
9816 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9819 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9821 + abstract_pkg_t **replaces = pkg->replaces;
9822 + int replaces_count = pkg->replaces_count;
9823 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9824 + int replacee_provides_count = pkg->provides_count; */
9826 + for (i = 0; i < replaces_count; i++) {
9827 + abstract_pkg_t *abstract_replacee = replaces[i];
9828 + for (j = 0; j < replaces_count; j++) {
9829 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9830 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9831 + if (replacee->provides[j] == abstract_replacee)
9840 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9843 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9845 + compound_depend_t *conflicts = pkg->conflicts;
9846 + int conflicts_count = pkg->conflicts_count;
9848 + for (i = 0; i < conflicts_count; i++) {
9849 + int possibility_count = conflicts[i].possibility_count;
9850 + struct depend **possibilities = conflicts[i].possibilities;
9851 + for (j = 0; j < possibility_count; j++) {
9852 + if (possibilities[j]->pkg == conflictee) {
9861 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9862 + * conflictee's provides and 0 otherwise.
9864 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9866 + compound_depend_t *conflicts = pkg->conflicts;
9867 + int conflicts_count = pkg->conflicts_count;
9868 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9869 + int conflictee_provides_count = conflictee->provides_count;
9871 + int possibility_count;
9872 + struct depend **possibilities;
9873 + abstract_pkg_t *possibility ;
9875 + for (i = 0; i < conflicts_count; i++) {
9876 + possibility_count = conflicts[i].possibility_count;
9877 + possibilities = conflicts[i].possibilities;
9878 + for (j = 0; j < possibility_count; j++) {
9879 + possibility = possibilities[j]->pkg;
9880 + for (k = 0; k < conflictee_provides_count; k++) {
9881 + if (possibility == conflictee_provides[k]) {
9890 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9892 + int oldlen = 0, newlen = 0;
9894 + register int i, j;
9899 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9900 + while(newstuff && newstuff[newlen]) newlen++;
9902 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9903 + if (result == NULL) {
9904 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9908 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9909 + *(result + i) = *(newstuff + j);
9911 + *(result + i) = NULL;
9917 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9918 + * this is null terminated, no count is carried around
9920 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9924 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9927 + while(the_lost && the_lost[count]) count++;
9929 + count++; /* need one to hold the null */
9930 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9931 + if (resized == NULL) {
9932 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9935 + resized[count - 1] = strdup(depend_str);
9936 + resized[count] = NULL;
9941 +void printDepends(pkg_t * pkg)
9943 + register int i, j;
9944 + compound_depend_t * depend;
9947 + count = pkg->pre_depends_count + pkg->depends_count;
9949 + depend = pkg->depends;
9951 + fprintf(stderr, "Depends pointer is NULL\n");
9954 + for(i = 0; i < count; i++){
9955 + fprintf(stderr, "%s has %d possibilities:\n",
9956 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9957 + depend->possibility_count);
9958 + for(j = 0; j < depend->possibility_count; j++)
9959 + fprintf(stderr, "\t%s version %s (%d)\n",
9960 + depend->possibilities[j]->pkg->name,
9961 + depend->possibilities[j]->version,
9962 + depend->possibilities[j]->constraint);
9967 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9969 + register int i, j;
9971 + /* every pkg provides itself */
9972 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9974 + if (!pkg->provides_count)
9977 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9978 + if (pkg->provides == NULL) {
9979 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9982 + pkg->provides[0] = ab_pkg;
9984 + // if (strcmp(ab_pkg->name, pkg->name))
9985 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9987 + for(i = 0; i < pkg->provides_count; i++){
9988 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9990 + pkg->provides[i+1] = provided_abpkg;
9993 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9998 +/* Abhaya: added conflicts support */
9999 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10002 + compound_depend_t * conflicts;
10004 + if (!pkg->conflicts_count)
10007 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10008 + pkg->conflicts_count);
10009 + if (conflicts == NULL) {
10010 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10013 + for (i = 0; i < pkg->conflicts_count; i++) {
10014 + conflicts->type = CONFLICTS;
10015 + parseDepends(conflicts, hash,
10016 + pkg->conflicts_str[i]);
10018 + for (j = 0; j < conflicts->possibility_count; j++) {
10019 + depend_t *possibility = conflicts->possibilities[j];
10020 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10021 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10029 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10031 + register int i, j;
10033 + if (!pkg->replaces_count)
10036 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10037 + if (pkg->replaces == NULL) {
10038 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10042 + // if (strcmp(ab_pkg->name, pkg->name))
10043 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10045 + for(i = 0; i < pkg->replaces_count; i++){
10046 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10048 + pkg->replaces[i] = old_abpkg;
10051 + if (!old_abpkg->replaced_by)
10052 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10053 + if ( old_abpkg->replaced_by == NULL ){
10056 + /* if a package pkg both replaces and conflicts old_abpkg,
10057 + * then add it to the replaced_by vector so that old_abpkg
10058 + * will be upgraded to ab_pkg automatically */
10059 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10060 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10065 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10069 + compound_depend_t * depends;
10071 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10074 + if (0 && pkg->pre_depends_count)
10075 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10076 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10077 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10078 + if (depends == NULL) {
10079 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10084 + for(i = 0; i < pkg->pre_depends_count; i++){
10085 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10086 + if (0 && pkg->pre_depends_count)
10087 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10088 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10089 + depends->type = PREDEPEND;
10093 + for(i = 0; i < pkg->recommends_count; i++){
10094 + parseDepends(depends, hash, pkg->recommends_str[i]);
10095 + if (0 && pkg->recommends_count)
10096 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10097 + pkg->recommends_str[i], depends, depends->possibility_count);
10098 + depends->type = RECOMMEND;
10102 + for(i = 0; i < pkg->suggests_count; i++){
10103 + parseDepends(depends, hash, pkg->suggests_str[i]);
10104 + if (0 && pkg->suggests_count)
10105 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10106 + pkg->suggests_str[i], depends, depends->possibility_count);
10107 + depends->type = SUGGEST;
10111 + for(i = 0; i < pkg->depends_count; i++){
10112 + parseDepends(depends, hash, pkg->depends_str[i]);
10113 + if (0 && pkg->depends_count)
10114 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10115 + pkg->depends_str[i], depends, depends->possibility_count);
10122 + * pkg_depend_string: returns the depends string specified by index.
10123 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10124 + * [0,npredepends) -> returns pre_depends_str[index]
10125 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10126 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10127 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10129 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10131 + if (pkg_index < pkg->pre_depends_count) {
10132 + return pkg->pre_depends_str[pkg_index];
10134 + pkg_index -= pkg->pre_depends_count;
10136 + if (pkg_index < pkg->recommends_count) {
10137 + return pkg->recommends_str[pkg_index];
10139 + pkg_index -= pkg->recommends_count;
10141 + if (pkg_index < pkg->suggests_count) {
10142 + return pkg->suggests_str[pkg_index];
10144 + pkg_index -= pkg->suggests_count;
10146 + if (pkg_index < pkg->depends_count) {
10147 + return pkg->depends_str[pkg_index];
10149 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10153 +void freeDepends(pkg_t *pkg)
10157 + if (pkg == NULL || pkg->depends == NULL) {
10161 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10162 + for (i=0; i < pkg->depends->possibility_count; i++) {
10163 + depend_deinit(pkg->depends->possibilities[i]);
10165 + free(pkg->depends->possibilities);
10166 + free(pkg->depends);
10167 + pkg->depends = NULL;
10170 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10172 + compound_depend_t * depends;
10173 + int count, othercount;
10174 + register int i, j;
10175 + abstract_pkg_t * ab_depend;
10176 + abstract_pkg_t ** temp;
10178 + count = pkg->pre_depends_count + pkg->depends_count;
10179 + depends = pkg->depends;
10181 + if (0 && pkg->pre_depends_count)
10182 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10183 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10184 + for (i = 0; i < count; i++) {
10185 + if (0 && pkg->pre_depends_count)
10186 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10187 + for (j = 0; j < depends->possibility_count; j++){
10188 + ab_depend = depends->possibilities[j]->pkg;
10189 + if(!ab_depend->depended_upon_by)
10190 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10192 + temp = ab_depend->depended_upon_by;
10200 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10201 + (othercount + 1) * sizeof(abstract_pkg_t *));
10202 + /* the array may have moved */
10203 + temp = ab_depend->depended_upon_by + othercount;
10210 +static depend_t * depend_init(void)
10212 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10214 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10217 + d->constraint = NONE;
10218 + d->version = NULL;
10224 +static void depend_deinit(depend_t *d)
10229 +static int parseDepends(compound_depend_t *compound_depend,
10230 + hash_table_t * hash, char * depend_str)
10232 + char * pkg_name, buffer[2048];
10233 + int num_of_ors = 0;
10235 + register char * src, * dest;
10236 + depend_t ** possibilities;
10238 + /* first count the number of ored possibilities for satisfying dependency */
10239 + src = depend_str;
10241 + if(*src++ == '|')
10244 + compound_depend->type = DEPEND;
10246 + compound_depend->possibility_count = num_of_ors + 1;
10247 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10248 + if (!possibilities)
10250 + compound_depend->possibilities = possibilities;
10252 + src = depend_str;
10253 + for(i = 0; i < num_of_ors + 1; i++){
10254 + possibilities[i] = depend_init();
10255 + if (!possibilities[i])
10257 + /* gobble up just the name first */
10260 + !isspace(*src) &&
10264 + *dest++ = *src++;
10266 + pkg_name = trim_alloc(buffer);
10267 + if (pkg_name == NULL )
10270 + /* now look at possible version info */
10272 + /* skip to next chars */
10273 + if(isspace(*src))
10274 + while(*src && isspace(*src)) src++;
10276 + /* extract constraint and version */
10279 + if(!strncmp(src, "<<", 2)){
10280 + possibilities[i]->constraint = EARLIER;
10283 + else if(!strncmp(src, "<=", 2)){
10284 + possibilities[i]->constraint = EARLIER_EQUAL;
10287 + else if(!strncmp(src, ">=", 2)){
10288 + possibilities[i]->constraint = LATER_EQUAL;
10291 + else if(!strncmp(src, ">>", 2)){
10292 + possibilities[i]->constraint = LATER;
10295 + else if(!strncmp(src, "=", 1)){
10296 + possibilities[i]->constraint = EQUAL;
10299 + /* should these be here to support deprecated designations; dpkg does */
10300 + else if(!strncmp(src, "<", 1)){
10301 + possibilities[i]->constraint = EARLIER_EQUAL;
10304 + else if(!strncmp(src, ">", 1)){
10305 + possibilities[i]->constraint = LATER_EQUAL;
10309 + /* now we have any constraint, pass space to version string */
10310 + while(isspace(*src)) src++;
10312 + /* this would be the version string */
10314 + while(*src && *src != ')')
10315 + *dest++ = *src++;
10318 + possibilities[i]->version = trim_alloc(buffer);
10319 + /* fprintf(stderr, "let's print the depends version string:");
10320 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10321 + if (possibilities[i]->version == NULL )
10326 + /* hook up the dependency to its abstract pkg */
10327 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10331 + /* now get past the ) and any possible | chars */
10333 + (isspace(*src) ||
10339 + compound_depend->type = GREEDY_DEPEND;
10346 Index: busybox-1.7.2/archival/libipkg/pkg_depends.h
10347 ===================================================================
10348 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10349 +++ busybox-1.7.2/archival/libipkg/pkg_depends.h 2007-10-30 15:35:05.000000000 -0500
10351 +/* pkg_depends.h - the itsy package management system
10355 + Copyright (C) 2002 Compaq Computer Corporation
10357 + This program is free software; you can redistribute it and/or
10358 + modify it under the terms of the GNU General Public License as
10359 + published by the Free Software Foundation; either version 2, or (at
10360 + your option) any later version.
10362 + This program is distributed in the hope that it will be useful, but
10363 + WITHOUT ANY WARRANTY; without even the implied warranty of
10364 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10365 + General Public License for more details.
10368 +#ifndef PKG_DEPENDS_H
10369 +#define PKG_DEPENDS_H
10372 +#include "pkg_hash.h"
10374 +enum depend_type {
10382 +typedef enum depend_type depend_type_t;
10384 +enum version_constraint {
10392 +typedef enum version_constraint version_constraint_t;
10395 + version_constraint_t constraint;
10397 + abstract_pkg_t * pkg;
10399 +typedef struct depend depend_t;
10401 +struct compound_depend{
10402 + depend_type_t type;
10403 + int possibility_count;
10404 + struct depend ** possibilities;
10406 +typedef struct compound_depend compound_depend_t;
10408 +#include "hash_table.h"
10410 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10411 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10412 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10413 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10416 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10417 + * the same abstract package and 0 otherwise.
10419 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10422 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10425 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10428 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10431 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10434 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10437 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10440 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10443 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10445 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10446 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10447 +void freeDepends(pkg_t *pkg);
10448 +void printDepends(pkg_t * pkg);
10449 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10450 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10451 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10452 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10453 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10456 Index: busybox-1.7.2/archival/libipkg/pkg_dest.c
10457 ===================================================================
10458 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10459 +++ busybox-1.7.2/archival/libipkg/pkg_dest.c 2007-10-30 15:35:05.000000000 -0500
10461 +/* pkg_dest.c - the itsy package management system
10465 + Copyright (C) 2001 University of Southern California
10467 + This program is free software; you can redistribute it and/or
10468 + modify it under the terms of the GNU General Public License as
10469 + published by the Free Software Foundation; either version 2, or (at
10470 + your option) any later version.
10472 + This program is distributed in the hope that it will be useful, but
10473 + WITHOUT ANY WARRANTY; without even the implied warranty of
10474 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10475 + General Public License for more details.
10480 +#include "pkg_dest.h"
10481 +#include "file_util.h"
10482 +#include "str_util.h"
10483 +#include "sprintf_alloc.h"
10485 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10487 + dest->name = strdup(name);
10489 + /* Guarantee that dest->root_dir ends with a '/' */
10490 + if (str_ends_with(root_dir, "/")) {
10491 + dest->root_dir = strdup(root_dir);
10493 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10495 + file_mkdir_hier(dest->root_dir, 0755);
10497 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10498 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10499 + file_mkdir_hier(dest->ipkg_dir, 0755);
10501 + if (str_starts_with (lists_dir, "/"))
10502 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10504 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10506 + file_mkdir_hier(dest->lists_dir, 0755);
10508 + sprintf_alloc(&dest->info_dir, "%s/%s",
10509 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10510 + file_mkdir_hier(dest->info_dir, 0755);
10512 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10513 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10515 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10516 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10518 + dest->status_file = NULL;
10523 +void pkg_dest_deinit(pkg_dest_t *dest)
10525 + free(dest->name);
10526 + dest->name = NULL;
10528 + free(dest->root_dir);
10529 + dest->root_dir = NULL;
10531 + free(dest->ipkg_dir);
10532 + dest->ipkg_dir = NULL;
10534 + free(dest->lists_dir);
10535 + dest->lists_dir = NULL;
10537 + free(dest->info_dir);
10538 + dest->info_dir = NULL;
10540 + free(dest->status_file_name);
10541 + dest->status_file_name = NULL;
10543 + free(dest->status_file_tmp_name);
10544 + dest->status_file_tmp_name = NULL;
10546 + if (dest->status_file) {
10547 + fclose(dest->status_file);
10549 + dest->status_file = NULL;
10551 + dest->root_dir = NULL;
10553 Index: busybox-1.7.2/archival/libipkg/pkg_dest.h
10554 ===================================================================
10555 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10556 +++ busybox-1.7.2/archival/libipkg/pkg_dest.h 2007-10-30 15:35:05.000000000 -0500
10558 +/* pkg_dest.h - the itsy package management system
10562 + Copyright (C) 2001 University of Southern California
10564 + This program is free software; you can redistribute it and/or
10565 + modify it under the terms of the GNU General Public License as
10566 + published by the Free Software Foundation; either version 2, or (at
10567 + your option) any later version.
10569 + This program is distributed in the hope that it will be useful, but
10570 + WITHOUT ANY WARRANTY; without even the implied warranty of
10571 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10572 + General Public License for more details.
10575 +#ifndef PKG_DEST_H
10576 +#define PKG_DEST_H
10578 +typedef struct pkg_dest pkg_dest_t;
10586 + char *status_file_name;
10587 + char *status_file_tmp_name;
10588 + FILE *status_file;
10591 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10592 +void pkg_dest_deinit(pkg_dest_t *dest);
10596 Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.c
10597 ===================================================================
10598 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10599 +++ busybox-1.7.2/archival/libipkg/pkg_dest_list.c 2007-10-30 15:35:05.000000000 -0500
10601 +/* pkg_dest_list.c - the itsy package management system
10605 + Copyright (C) 2001 University of Southern California
10607 + This program is free software; you can redistribute it and/or
10608 + modify it under the terms of the GNU General Public License as
10609 + published by the Free Software Foundation; either version 2, or (at
10610 + your option) any later version.
10612 + This program is distributed in the hope that it will be useful, but
10613 + WITHOUT ANY WARRANTY; without even the implied warranty of
10614 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10615 + General Public License for more details.
10620 +#include "pkg_dest.h"
10621 +#include "void_list.h"
10622 +#include "pkg_dest_list.h"
10624 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10626 + return void_list_elt_init((void_list_elt_t *) elt, data);
10629 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10631 + void_list_elt_deinit((void_list_elt_t *) elt);
10634 +int pkg_dest_list_init(pkg_dest_list_t *list)
10636 + return void_list_init((void_list_t *) list);
10639 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10641 + pkg_dest_list_elt_t *iter;
10642 + pkg_dest_t *pkg_dest;
10644 + for (iter = list->head; iter; iter = iter->next) {
10645 + pkg_dest = iter->data;
10646 + pkg_dest_deinit(pkg_dest);
10648 + /* malloced in pkg_dest_list_append */
10650 + iter->data = NULL;
10652 + void_list_deinit((void_list_t *) list);
10655 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10656 + const char *root_dir,const char *lists_dir)
10659 + pkg_dest_t *pkg_dest;
10661 + /* freed in plg_dest_list_deinit */
10662 + pkg_dest = malloc(sizeof(pkg_dest_t));
10663 + if (pkg_dest == NULL) {
10664 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10668 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10669 + err = void_list_append((void_list_t *) list, pkg_dest);
10677 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10679 + return void_list_push((void_list_t *) list, data);
10682 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10684 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10686 Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.h
10687 ===================================================================
10688 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10689 +++ busybox-1.7.2/archival/libipkg/pkg_dest_list.h 2007-10-30 15:35:05.000000000 -0500
10691 +/* pkg_dest_list.h - the itsy package management system
10695 + Copyright (C) 2001 University of Southern California
10697 + This program is free software; you can redistribute it and/or
10698 + modify it under the terms of the GNU General Public License as
10699 + published by the Free Software Foundation; either version 2, or (at
10700 + your option) any later version.
10702 + This program is distributed in the hope that it will be useful, but
10703 + WITHOUT ANY WARRANTY; without even the implied warranty of
10704 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10705 + General Public License for more details.
10708 +#ifndef PKG_DEST_LIST_H
10709 +#define PKG_DEST_LIST_H
10711 +#include "pkg_dest.h"
10713 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10714 +struct pkg_dest_list_elt
10716 + pkg_dest_list_elt_t *next;
10717 + pkg_dest_t *data;
10720 +typedef struct pkg_dest_list pkg_dest_list_t;
10721 +struct pkg_dest_list
10723 + pkg_dest_list_elt_t pre_head;
10724 + pkg_dest_list_elt_t *head;
10725 + pkg_dest_list_elt_t *tail;
10728 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10729 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10731 +int pkg_dest_list_init(pkg_dest_list_t *list);
10732 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10734 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10735 + const char *root_dir,const char* lists_dir);
10736 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10737 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10741 Index: busybox-1.7.2/archival/libipkg/pkg_extract.c
10742 ===================================================================
10743 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10744 +++ busybox-1.7.2/archival/libipkg/pkg_extract.c 2007-10-30 15:35:05.000000000 -0500
10746 +/* pkg_extract.c - the itsy package management system
10750 + Copyright (C) 2001 University of Southern California
10752 + This program is free software; you can redistribute it and/or
10753 + modify it under the terms of the GNU General Public License as
10754 + published by the Free Software Foundation; either version 2, or (at
10755 + your option) any later version.
10757 + This program is distributed in the hope that it will be useful, but
10758 + WITHOUT ANY WARRANTY; without even the implied warranty of
10759 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10760 + General Public License for more details.
10764 +#include <errno.h>
10765 +#include <fcntl.h>
10766 +#include <stdio.h>
10768 +#include "pkg_extract.h"
10770 +#include "libbb.h"
10771 +#include "file_util.h"
10772 +#include "sprintf_alloc.h"
10773 +#include "unarchive.h"
10775 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10776 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10777 +#define IPKG_CONTROL_FILE "control"
10779 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10781 + archive_handle_t *archive;
10784 + sprintf_alloc(&path, "%s/", dir);
10785 + archive = init_handle();
10786 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10787 + archive->filter = filter_accept_list;
10788 + llist_add_to(&(archive->accept), (char *)filename);
10789 + archive->buffer = path;
10790 + archive->action_data = data_extract_all_prefix;
10791 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10792 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10793 + close(archive->src_fd);
10794 + free(archive->accept);
10799 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10801 + unsigned int size = strlen(archive->file_header->name) + 2;
10803 + if (archive->buffer == NULL) {
10804 + archive->buffer = xmalloc(size);
10805 + strcpy(archive->buffer, archive->file_header->name);
10807 + size += strlen(archive->buffer);
10808 + archive->buffer = xrealloc(archive->buffer, size);
10809 + strcat(archive->buffer, archive->file_header->name);
10811 + strcat(archive->buffer, "\n");
10812 + data_skip(archive);
10815 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10817 + archive_handle_t *archive;
10820 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10821 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10822 + archive = init_handle();
10823 + archive->src_fd = xopen(name, O_RDONLY);
10824 + archive->filter = filter_accept_list;
10825 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10826 + archive->action_data = data_extract_to_buffer;
10827 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10828 + close(archive->src_fd);
10829 + fputs(archive->buffer, stream);
10830 + free(archive->buffer);
10831 + free(archive->accept);
10838 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10840 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10843 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10845 + archive_handle_t *archive;
10849 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10850 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10851 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10852 + archive = init_handle();
10853 + archive->src_fd = xopen(name, O_RDONLY);
10854 + archive->filter = filter_accept_all;
10855 + archive->buffer = path;
10856 + archive->action_data = data_extract_all_prefix;
10857 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10858 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10859 + close(archive->src_fd);
10867 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10869 + archive_handle_t *archive;
10873 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10874 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10875 + sprintf_alloc(&path, "%s/", dir);
10876 + archive = init_handle();
10877 + archive->src_fd = xopen(name, O_RDONLY);
10878 + archive->filter = filter_accept_all;
10879 + archive->buffer = path;
10880 + archive->action_data = data_extract_all_prefix;
10881 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10882 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10883 + close(archive->src_fd);
10891 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10894 + char *line, *data_file;
10898 + file = fopen(file_name, "w");
10899 + if (file == NULL) {
10900 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10901 + __FUNCTION__, file_name);
10906 + if (pkg->installed_files) {
10907 + str_list_elt_t *elt;
10908 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10909 + fprintf(file, "%s\n", elt->data);
10912 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10919 + /* Fixup data file names by removing the initial '.' */
10922 + line = file_read_line_alloc(tmp);
10923 + if (line == NULL) {
10927 + data_file = line;
10928 + if (*data_file == '.') {
10932 + if (*data_file != '/') {
10933 + fputs("/", file);
10936 + /* I have no idea why, but this is what dpkg does */
10937 + if (strcmp(data_file, "/\n") == 0) {
10938 + fputs("/.\n", file);
10940 + fputs(data_file, file);
10950 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10952 + archive_handle_t *archive;
10955 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10956 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10957 + archive = init_handle();
10958 + archive->src_fd = xopen(name, O_RDONLY);
10959 + archive->filter = filter_accept_all;
10960 + archive->action_data = data_extract_file_name_to_buffer;
10961 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10962 + close(archive->src_fd);
10963 + fputs(archive->buffer, file);
10964 + free(archive->buffer);
10970 Index: busybox-1.7.2/archival/libipkg/pkg_extract.h
10971 ===================================================================
10972 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10973 +++ busybox-1.7.2/archival/libipkg/pkg_extract.h 2007-10-30 15:35:05.000000000 -0500
10975 +/* pkg_extract.c - the itsy package management system
10979 + Copyright (C) 2001 University of Southern California
10981 + This program is free software; you can redistribute it and/or
10982 + modify it under the terms of the GNU General Public License as
10983 + published by the Free Software Foundation; either version 2, or (at
10984 + your option) any later version.
10986 + This program is distributed in the hope that it will be useful, but
10987 + WITHOUT ANY WARRANTY; without even the implied warranty of
10988 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10989 + General Public License for more details.
10992 +#ifndef PKG_EXTRACT_H
10993 +#define PKG_EXTRACT_H
10997 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10998 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10999 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11001 + const char *prefix);
11002 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11003 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11004 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11007 Index: busybox-1.7.2/archival/libipkg/pkg.h
11008 ===================================================================
11009 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11010 +++ busybox-1.7.2/archival/libipkg/pkg.h 2007-10-30 15:35:05.000000000 -0500
11012 +/* pkg.h - the itsy package management system
11016 + Copyright (C) 2001 University of Southern California
11018 + This program is free software; you can redistribute it and/or
11019 + modify it under the terms of the GNU General Public License as
11020 + published by the Free Software Foundation; either version 2, or (at
11021 + your option) any later version.
11023 + This program is distributed in the hope that it will be useful, but
11024 + WITHOUT ANY WARRANTY; without even the implied warranty of
11025 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11026 + General Public License for more details.
11032 +#include <sys/types.h>
11033 +#include <sys/stat.h>
11034 +#include <unistd.h>
11036 +#include "pkg_vec.h"
11037 +#include "str_list.h"
11038 +#include "pkg_src.h"
11039 +#include "pkg_dest.h"
11040 +#include "ipkg_conf.h"
11041 +#include "conffile_list.h"
11045 +/* I think "Size" is currently the shortest field name */
11046 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11048 +enum pkg_state_want
11054 + SW_LAST_STATE_WANT
11056 +typedef enum pkg_state_want pkg_state_want_t;
11058 +enum pkg_state_flag
11061 + SF_REINSTREQ = 1,
11062 + SF_HOLD = 2, /* do not upgrade version */
11063 + SF_REPLACE = 4, /* replace this package */
11064 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11065 + SF_PREFER = 16, /* prefer this version */
11066 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11067 + SF_MARKED = 64, /* temporary mark */
11068 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11070 + SF_LAST_STATE_FLAG
11072 +typedef enum pkg_state_flag pkg_state_flag_t;
11073 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11075 +enum pkg_state_status
11077 + SS_NOT_INSTALLED = 1,
11079 + SS_HALF_CONFIGURED,
11081 + SS_HALF_INSTALLED,
11083 + SS_POST_INST_FAILED,
11084 + SS_REMOVAL_FAILED,
11085 + SS_LAST_STATE_STATUS
11087 +typedef enum pkg_state_status pkg_state_status_t;
11089 +struct abstract_pkg{
11091 + int dependencies_checked;
11092 + pkg_vec_t * pkgs;
11093 + pkg_state_status_t state_status;
11094 + pkg_state_flag_t state_flag;
11095 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11096 + abstract_pkg_vec_t * provided_by;
11097 + abstract_pkg_vec_t * replaced_by;
11100 +#include "pkg_depends.h"
11102 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11104 + The 3 version fields should go into a single version struct. (This
11105 + is especially important since, currently, pkg->version can easily
11106 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11107 + distinct. This has been the source of multiple bugs.
11109 + The 3 state fields could possibly also go into their own struct.
11111 + All fields which deal with lists of packages, (Depends,
11112 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11113 + be handled by a single struct in pkg_t
11115 + All string fields for which there is a small set of possible
11116 + values, (section, maintainer, architecture, maybe version?), that
11117 + are reused among different packages -- for all such packages we
11118 + should move from "char *"s to some atom datatype to share data
11119 + storage and use less memory. We might even do reference counting,
11120 + but probably not since most often we only create new pkg_t structs,
11121 + we don't often free them. */
11125 + unsigned long epoch;
11128 + char *familiar_revision;
11130 + pkg_dest_t *dest;
11131 + char *architecture;
11133 + char *maintainer;
11134 + char *description;
11135 + pkg_state_want_t state_want;
11136 + pkg_state_flag_t state_flag;
11137 + pkg_state_status_t state_status;
11138 + char **depends_str;
11139 + int depends_count;
11140 + char **pre_depends_str;
11141 + int pre_depends_count;
11142 + char **recommends_str;
11143 + int recommends_count;
11144 + char **suggests_str;
11145 + int suggests_count;
11146 + compound_depend_t * depends;
11148 + /* Abhaya: new conflicts */
11149 + char **conflicts_str;
11150 + compound_depend_t * conflicts;
11151 + int conflicts_count;
11153 + char **replaces_str;
11154 + int replaces_count;
11155 + abstract_pkg_t ** replaces;
11157 + char **provides_str;
11158 + int provides_count;
11159 + abstract_pkg_t ** provides;
11161 + abstract_pkg_t *parent;
11163 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11166 + char *local_filename;
11168 + char *tmp_unpack_dir;
11171 + char *installed_size;
11174 + conffile_list_t conffiles;
11175 + time_t installed_time;
11176 + /* As pointer for lazy evaluation */
11177 + str_list_t *installed_files;
11178 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11179 + mechanism to avoid the problem here, (which is that the
11180 + installed_files list was being freed from an inner loop while
11181 + still being used within an outer loop. */
11182 + int installed_files_ref_cnt;
11184 + int arch_priority;
11185 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11186 + int provided_by_hand;
11189 +pkg_t *pkg_new(void);
11190 +int pkg_init(pkg_t *pkg);
11191 +void pkg_deinit(pkg_t *pkg);
11192 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11193 +abstract_pkg_t *abstract_pkg_new(void);
11194 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11197 + * merges fields from newpkg into oldpkg.
11198 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11200 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11202 +char *pkg_version_str_alloc(pkg_t *pkg);
11204 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11205 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11206 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11208 +char * pkg_formatted_info(pkg_t *pkg );
11209 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11211 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11213 +void pkg_print_info(pkg_t *pkg, FILE *file);
11214 +void pkg_print_status(pkg_t * pkg, FILE * file);
11215 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11216 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11217 +int pkg_free_installed_files(pkg_t *pkg);
11218 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11219 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11220 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11221 + const char *script, const char *args);
11223 +/* enum mappings */
11224 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11225 +pkg_state_want_t pkg_state_want_from_str(char *str);
11226 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11227 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11228 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11229 +pkg_state_status_t pkg_state_status_from_str(char *str);
11231 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11233 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11234 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11235 +int pkg_free_installed_files(pkg_t *pkg);
11237 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11238 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11241 Index: busybox-1.7.2/archival/libipkg/pkg_hash.c
11242 ===================================================================
11243 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11244 +++ busybox-1.7.2/archival/libipkg/pkg_hash.c 2007-10-30 15:35:05.000000000 -0500
11246 +/* ipkg_hash.c - the itsy package management system
11250 + Copyright (C) 2002 Compaq Computer Corporation
11252 + This program is free software; you can redistribute it and/or
11253 + modify it under the terms of the GNU General Public License as
11254 + published by the Free Software Foundation; either version 2, or (at
11255 + your option) any later version.
11257 + This program is distributed in the hope that it will be useful, but
11258 + WITHOUT ANY WARRANTY; without even the implied warranty of
11259 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11260 + General Public License for more details.
11264 +#include <errno.h>
11265 +#include <ctype.h>
11266 +#include <stdlib.h>
11267 +#include <string.h>
11269 +#include "hash_table.h"
11271 +#include "ipkg_message.h"
11272 +#include "pkg_vec.h"
11273 +#include "pkg_hash.h"
11274 +#include "pkg_parse.h"
11275 +#include "ipkg_utils.h"
11277 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11280 + * this will talk to both feeds-lists files and installed status files
11283 + * hash_table_t hash;
11284 + * pkg_hash_init(name, &hash, 1000);
11285 + * pkg_hash_add_from_file(<feed filename>);
11287 + * the query function is just there as a shell to prove to me that this
11288 + * sort of works, but isn't far from doing something useful
11291 + * modified: CDW 3 Jan. 2002
11296 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11298 + return hash_table_init(name, hash, len);
11301 +void pkg_hash_deinit(hash_table_t *hash)
11303 + hash_table_deinit(hash);
11307 +/* Find the default arch for a given package status file if none is given. */
11308 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11310 + nv_pair_list_elt_t *l;
11311 + char *def_arch = HOST_CPU_STR; /* Default arch */
11312 + int def_prio = 0; /* Other archs override this */
11314 + l = conf->arch_list.head;
11317 + nv_pair_t *nv = l->data;
11318 + int priority = strtol(nv->value, NULL, 0);
11320 + /* Check if this arch has higher priority, and is valid */
11321 + if ((priority > def_prio) &&
11322 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11323 + /* Our new default */
11324 + def_prio = priority;
11325 + def_arch = nv->name;
11330 + return strdup(def_arch);
11333 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11334 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11336 + hash_table_t *hash = &conf->pkg_hash;
11338 + char **raw_start;
11341 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11345 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11350 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11351 + if (!pkg->architecture) {
11352 + char *version_str = pkg_version_str_alloc(pkg);
11353 + pkg->architecture = pkg_get_default_arch(conf);
11354 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11355 + pkg->name, version_str, pkg->architecture);
11356 + free(version_str);
11358 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11364 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11365 + memory after read_raw_pkgs_from_file */
11374 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11376 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11379 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11381 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11384 + return apkg->provided_by;
11388 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11389 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11392 + int nprovides = 0;
11393 + int nmatching = 0;
11394 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11395 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11396 + abstract_pkg_vec_t *provided_apkg_vec;
11397 + abstract_pkg_t **provided_apkgs;
11398 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11399 + pkg_t *latest_installed_parent = NULL;
11400 + pkg_t *latest_matching = NULL;
11401 + pkg_t *held_pkg = NULL;
11402 + pkg_t *good_pkg_by_name = NULL;
11404 + if (matching_apkgs == NULL || providers == NULL ||
11405 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11408 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11410 + provided_apkg_vec = apkg->provided_by;
11411 + nprovides = provided_apkg_vec->len;
11412 + provided_apkgs = provided_apkg_vec->pkgs;
11413 + if (nprovides > 1)
11414 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11416 + /* accumulate all the providers */
11417 + for (i = 0; i < nprovides; i++) {
11418 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11419 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11420 + abstract_pkg_vec_insert(providers, provider_apkg);
11422 + nprovides = providers->len;
11424 + for (i = 0; i < nprovides; i++) {
11425 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11426 + abstract_pkg_t *replacement_apkg = NULL;
11429 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11430 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11431 + if (provider_apkg->replaced_by->len > 1) {
11432 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11433 + provider_apkg->name, replacement_apkg->name);
11437 + if (replacement_apkg)
11438 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11439 + replacement_apkg->name, provider_apkg->name);
11441 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11442 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11445 + provider_apkg = replacement_apkg;
11448 + if (!(vec = provider_apkg->pkgs)) {
11449 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11454 + /* now check for supported architecture */
11456 + int max_count = 0;
11458 + /* count packages matching max arch priority and keep track of last one */
11459 + for (j = 0; j < vec->len; j++) {
11460 + pkg_t *maybe = vec->pkgs[j];
11461 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11462 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11463 + if (maybe->arch_priority > 0) {
11465 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11466 + pkg_vec_insert(matching_pkgs, maybe);
11472 + if (matching_pkgs->len > 1)
11473 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11474 + if (matching_apkgs->len > 1)
11475 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11477 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11478 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11479 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11480 + Until now I always got the latest, but that breaks the downgrade option.
11481 + If I stop at the first one, I would probably miss the new ones
11482 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11483 + or from a Packages feed.
11484 + 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*/
11487 + for (i = 0; i < matching_pkgs->len; i++) {
11488 + pkg_t *matching = matching_pkgs->pkgs[i];
11489 + if (constraint_fcn(matching, cdata)) { /* We found it */
11490 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11491 + good_pkg_by_name = matching;
11492 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11498 + for (i = 0; i < matching_pkgs->len; i++) {
11499 + pkg_t *matching = matching_pkgs->pkgs[i];
11500 + latest_matching = matching;
11501 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11502 + latest_installed_parent = matching;
11503 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11505 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11506 + held_pkg->name, matching->name);
11507 + held_pkg = matching;
11511 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11512 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11513 + apkg->name, matching_apkgs->len);
11514 + for (i = 0; i < matching_apkgs->len; i++) {
11515 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11516 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11518 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11521 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11522 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11523 + __FUNCTION__, apkg->name, matching_pkgs->len);
11524 + for (i = 0; i < matching_pkgs->len; i++) {
11525 + pkg_t *matching = matching_pkgs->pkgs[i];
11526 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11527 + matching->name, matching->version, matching->architecture);
11531 + nmatching = matching_apkgs->len;
11533 + pkg_vec_free(matching_pkgs);
11534 + abstract_pkg_vec_free(matching_apkgs);
11535 + abstract_pkg_vec_free(providers);
11537 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11538 + return good_pkg_by_name;
11541 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11544 + if (latest_installed_parent) {
11545 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11546 + return latest_installed_parent;
11548 + if (nmatching > 1) {
11549 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11552 + if (latest_matching) {
11553 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11554 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11555 + return latest_matching;
11560 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11562 + const char *name = (const char *)cdata;
11563 + if (strcmp(pkg->name, name) == 0)
11569 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11571 + hash_table_t *hash = &conf->pkg_hash;
11572 + abstract_pkg_t *apkg = NULL;
11574 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11577 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11581 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11582 + const char *pkg_name,
11583 + const char * version)
11587 + char *version_str = NULL;
11589 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11592 + for(i = 0; i < vec->len; i++) {
11593 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11594 + if(!strcmp(version_str, version)) {
11595 + free(version_str);
11598 + free(version_str);
11601 + if(i == vec->len)
11604 + return vec->pkgs[i];
11607 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11608 + const char *pkg_name,
11609 + pkg_dest_t *dest)
11614 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11618 + for(i = 0; i < vec->len; i++)
11619 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11620 + return vec->pkgs[i];
11625 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11626 + const char *pkg_name)
11631 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11635 + for(i = 0; i < vec->len; i++)
11636 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11637 + return vec->pkgs[i];
11643 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11645 + abstract_pkg_t * ab_pkg;
11647 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11651 + if (ab_pkg->pkgs) {
11652 + return ab_pkg->pkgs;
11653 + } else if (ab_pkg->provided_by) {
11654 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11655 + if (abpkg != NULL){
11656 + return abpkg->pkgs;
11658 + return ab_pkg->pkgs;
11665 +static int pkg_compare_names(const void *p1, const void *p2)
11667 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11668 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11669 + if (pkg1->name == NULL)
11671 + if (pkg2->name == NULL)
11673 + return(strcmp(pkg1->name, pkg2->name));
11677 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11680 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11681 + pkg_vec_t *all = (pkg_vec_t *)data;
11682 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11684 + for (j = 0; j < pkg_vec->len; j++) {
11685 + pkg_t *pkg = pkg_vec->pkgs[j];
11686 + pkg_vec_insert(all, pkg);
11691 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11693 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11694 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11697 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11699 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11700 + pkg_vec_t *all = (pkg_vec_t *)data;
11701 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11704 + for (j = 0; j < pkg_vec->len; j++) {
11705 + pkg_t *pkg = pkg_vec->pkgs[j];
11706 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11707 + pkg_vec_insert(all, pkg);
11712 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11714 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11715 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11718 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11722 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11723 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11724 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11725 + fprintf(stdout, "%s\n", ab_pkg->name);
11727 + if (dependents != NULL)
11728 + while (dependents [i] != NULL)
11729 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11730 + dependents = ab_pkg->provided_by->pkgs;
11732 + if (dependents != NULL)
11733 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11734 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11735 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11738 + while (i < pkg->depends_count)
11739 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11742 +void pkg_hash_dump(hash_table_t *hash, void *data)
11745 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11746 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11747 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11750 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11752 + abstract_pkg_t * ab_pkg;
11754 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11755 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11760 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11762 + abstract_pkg_t * ab_pkg;
11763 + int arch_priority;
11768 + arch_priority = pkg->arch_priority;
11770 + if (buildDepends(hash, pkg)<0){
11771 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11774 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11776 + if (set_status) {
11777 + if (pkg->state_status == SS_INSTALLED) {
11778 + ab_pkg->state_status = SS_INSTALLED;
11779 + } else if (pkg->state_status == SS_UNPACKED) {
11780 + ab_pkg->state_status = SS_UNPACKED;
11784 + if(!ab_pkg->pkgs)
11785 + ab_pkg->pkgs = pkg_vec_alloc();
11787 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11788 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11789 + pkg->parent = ab_pkg;
11791 + if (buildProvides(hash, ab_pkg, pkg)<0){
11792 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11795 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11796 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11797 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11800 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11801 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11805 + buildDependedUponBy(pkg, ab_pkg);
11810 + * this will assume that we've already determined that
11811 + * the abstract pkg doesn't exist, 'cause we should know these things...
11813 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11815 + abstract_pkg_t * ab_pkg;
11817 + ab_pkg = abstract_pkg_new();
11818 + if (ab_pkg == NULL) { return NULL; }
11820 + ab_pkg->name = strdup(pkg_name);
11821 + hash_table_insert(hash, pkg_name, ab_pkg);
11827 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11829 + hash_table_t *file_hash = &conf->file_hash;
11831 + return hash_table_get(file_hash, file_name);
11834 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11836 + hash_table_t *file_hash = &conf->file_hash;
11837 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11838 + int file_name_len = strlen(file_name);
11840 + if (file_name[file_name_len -1] == '/')
11843 + if (conf->offline_root) {
11844 + int len = strlen(conf->offline_root);
11845 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11846 + file_name += len;
11850 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11851 + hash_table_insert(file_hash, file_name, owning_pkg);
11852 + if (old_owning_pkg) {
11853 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11854 + /* mark this package to have its filelist written */
11855 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11856 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11862 Index: busybox-1.7.2/archival/libipkg/pkg_hash.h
11863 ===================================================================
11864 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11865 +++ busybox-1.7.2/archival/libipkg/pkg_hash.h 2007-10-30 15:35:05.000000000 -0500
11867 +/* pkg_hash.h - the itsy package management system
11871 + Copyright (C) 2002 Compaq Computer Corporation
11873 + This program is free software; you can redistribute it and/or
11874 + modify it under the terms of the GNU General Public License as
11875 + published by the Free Software Foundation; either version 2, or (at
11876 + your option) any later version.
11878 + This program is distributed in the hope that it will be useful, but
11879 + WITHOUT ANY WARRANTY; without even the implied warranty of
11880 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11881 + General Public License for more details.
11884 +#ifndef PKG_HASH_H
11885 +#define PKG_HASH_H
11888 +#include "pkg_vec.h"
11889 +#include "hash_table.h"
11892 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11893 +void pkg_hash_deinit(hash_table_t *hash);
11894 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11896 +void pkg_hash_dump(hash_table_t *hash, void *data);
11897 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11899 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11900 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11901 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11903 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11904 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11905 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11906 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11907 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11908 + const char *pkg_name,
11909 + const char * version);
11910 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11911 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11912 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11913 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11914 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11915 + const char *pkg_name);
11916 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11917 + const char *pkg_name,
11918 + pkg_dest_t *dest);
11920 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11921 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11923 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11924 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11928 Index: busybox-1.7.2/archival/libipkg/pkg_parse.c
11929 ===================================================================
11930 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
11931 +++ busybox-1.7.2/archival/libipkg/pkg_parse.c 2007-10-30 15:35:05.000000000 -0500
11933 +/* pkg_parse.c - the itsy package management system
11937 + Copyright (C) 2002 Compaq Computer Corporation
11939 + This program is free software; you can redistribute it and/or
11940 + modify it under the terms of the GNU General Public License as
11941 + published by the Free Software Foundation; either version 2, or (at
11942 + your option) any later version.
11944 + This program is distributed in the hope that it will be useful, but
11945 + WITHOUT ANY WARRANTY; without even the implied warranty of
11946 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11947 + General Public License for more details.
11951 +#include <errno.h>
11952 +#include <ctype.h>
11955 +#include "ipkg_utils.h"
11956 +#include "pkg_parse.h"
11958 +int isGenericFieldType(char * type, char * line)
11960 + if(!strncmp(line, type, strlen(type)))
11965 +char * parseGenericFieldType(char * type, char * raw)
11967 + char * field_value = raw + (strlen(type) + 1);
11968 + return trim_alloc(field_value);
11971 +void parseStatus(pkg_t *pkg, char * raw)
11973 + char sw_str[64], sf_str[64], ss_str[64];
11975 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11976 + pkg->state_want = pkg_state_want_from_str(sw_str);
11977 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11978 + pkg->state_status = pkg_state_status_from_str(ss_str);
11981 +char ** parseDependsString(char * raw, int * depends_count)
11983 + char ** depends = NULL;
11984 + int line_count = 0;
11985 + char buff[2048], * dest;
11987 + while(raw && *raw && !isspace(*raw)) {
11991 + if(line_is_blank(raw)){
11992 + *depends_count = line_count;
11995 + while(raw && *raw){
11996 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11998 + while(isspace(*raw)) raw++;
12001 + while((*raw != ',') && *raw)
12002 + *dest++ = *raw++;
12005 + depends[line_count] = trim_alloc(buff);
12006 + if(depends[line_count] ==NULL)
12012 + *depends_count = line_count;
12016 +void parseConffiles(pkg_t * pkg, char * raw)
12018 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12020 + if(!strncmp(raw, "Conffiles:", 10))
12021 + raw += strlen("Conffiles:");
12023 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12024 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12025 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12026 + while (*raw && isspace(*raw)) {
12029 + raw += strlen(file_name);
12030 + while (*raw && isspace(*raw)) {
12033 + raw += strlen(md5sum);
12037 +int parseVersion(pkg_t *pkg, char *raw)
12039 + char *colon, *eepochcolon;
12040 +#ifdef USE_DEBVERSION
12043 + unsigned long epoch;
12046 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12050 + if (strncmp(raw, "Version:", 8) == 0) {
12053 + while (*raw && isspace(*raw)) {
12057 + colon= strchr(raw,':');
12059 + epoch= strtoul(raw,&eepochcolon,10);
12060 + if (colon != eepochcolon) {
12061 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12065 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12069 + pkg->epoch= epoch;
12074 + pkg->revision = "";
12075 + pkg->familiar_revision = "";
12077 + pkg->version= malloc(strlen(raw)+1);
12078 + if ( pkg->version == NULL ) {
12079 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12082 + strcpy(pkg->version, raw);
12084 +#ifdef USE_DEBVERSION
12085 + hyphen= strrchr(pkg->version,'-');
12089 + if (strncmp("fam", hyphen, 3) == 0) {
12090 + pkg->familiar_revision=hyphen+3;
12091 + hyphen= strrchr(pkg->version,'-');
12094 + pkg->revision = hyphen;
12097 + pkg->revision = hyphen;
12103 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12107 + pkg->familiar_revision);
12114 +/* This code is needed to insert in first position the keyword for the aligning bug */
12116 +int alterProvidesLine(char *raw, char *temp)
12121 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12125 + if ( temp == NULL ) {
12126 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12130 + if (strncmp(raw, "Provides:", 9) == 0) {
12133 + while (*raw && isspace(*raw)) {
12137 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12139 + strncat( temp, raw++, 1);
12145 +/* Some random thoughts from Carl:
12147 + This function could be considerably simplified if we just kept
12148 + an array of all the generic string-valued field names, and looped
12149 + through those looking for a match. Also, these fields could perhaps
12150 + be stored in the package as an array as well, (or, probably better,
12151 + as an nv_pair_list_t).
12153 + Fields which require special parsing or storage, (such as Depends:
12154 + and Status:) could be handled as they are now.
12156 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12157 + to a dependency list. And, since we already have
12158 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12159 + Enhances, perhaps we could generalize all of these and save some
12160 + code duplication.
12162 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12164 + int reading_conffiles, reading_description;
12165 + int pkg_false_provides=1;
12167 + char * provide=NULL;
12170 + pkg->dest = dest;
12172 + reading_conffiles = reading_description = 0;
12174 + for (lines = *raw; *lines; lines++) {
12175 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12176 + if(isGenericFieldType("Package:", *lines))
12177 + pkg->name = parseGenericFieldType("Package", *lines);
12178 + else if(isGenericFieldType("Architecture:", *lines))
12179 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12180 + else if(isGenericFieldType("Filename:", *lines))
12181 + pkg->filename = parseGenericFieldType("Filename", *lines);
12182 + else if(isGenericFieldType("Section:", *lines))
12183 + pkg->section = parseGenericFieldType("Section", *lines);
12184 + else if(isGenericFieldType("MD5sum:", *lines))
12185 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12186 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12187 + let's parse it either way */
12188 + else if(isGenericFieldType("MD5Sum:", *lines))
12189 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12190 + else if(isGenericFieldType("Size:", *lines))
12191 + pkg->size = parseGenericFieldType("Size", *lines);
12192 + else if(isGenericFieldType("Source:", *lines))
12193 + pkg->source = parseGenericFieldType("Source", *lines);
12194 + else if(isGenericFieldType("Installed-Size:", *lines))
12195 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12196 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12197 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12198 + pkg->installed_time = strtoul(time_str, NULL, 0);
12199 + } else if(isGenericFieldType("Priority:", *lines))
12200 + pkg->priority = parseGenericFieldType("Priority", *lines);
12201 + else if(isGenericFieldType("Essential:", *lines)) {
12202 + char *essential_value;
12203 + essential_value = parseGenericFieldType("Essential", *lines);
12204 + if (strcmp(essential_value, "yes") == 0) {
12205 + pkg->essential = 1;
12207 + free(essential_value);
12209 + else if(isGenericFieldType("Status", *lines))
12210 + parseStatus(pkg, *lines);
12211 + else if(isGenericFieldType("Version", *lines))
12212 + parseVersion(pkg, *lines);
12213 + else if(isGenericFieldType("Maintainer", *lines))
12214 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12215 + else if(isGenericFieldType("Conffiles", *lines)){
12216 + parseConffiles(pkg, *lines);
12217 + reading_conffiles = 1;
12219 + else if(isGenericFieldType("Description", *lines)) {
12220 + pkg->description = parseGenericFieldType("Description", *lines);
12221 + reading_conffiles = 0;
12222 + reading_description = 1;
12225 + else if(isGenericFieldType("Provides", *lines)){
12226 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12227 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12228 + if ( alterProvidesLine(*lines,provide) ){
12231 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12232 +/* Let's try to hack a bit here.
12233 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12234 + in alot of other places. We will remove it before writing down the status database */
12235 + pkg_false_provides=0;
12239 + else if(isGenericFieldType("Depends", *lines))
12240 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12241 + else if(isGenericFieldType("Pre-Depends", *lines))
12242 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12243 + else if(isGenericFieldType("Recommends", *lines))
12244 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12245 + else if(isGenericFieldType("Suggests", *lines))
12246 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12247 + /* Abhaya: support for conflicts */
12248 + else if(isGenericFieldType("Conflicts", *lines))
12249 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12250 + else if(isGenericFieldType("Replaces", *lines))
12251 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12252 + else if(line_is_blank(*lines)) {
12256 + else if(**lines == ' '){
12257 + if(reading_description) {
12258 + /* we already know it's not blank, so the rest of description */
12259 + pkg->description = realloc(pkg->description,
12260 + strlen(pkg->description)
12261 + + 1 + strlen(*lines) + 1);
12262 + strcat(pkg->description, "\n");
12263 + strcat(pkg->description, (*lines));
12265 + else if(reading_conffiles)
12266 + parseConffiles(pkg, *lines);
12270 +/* If the ipk has not a Provides line, we insert our false line */
12271 + if ( pkg_false_provides==1)
12272 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12281 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12285 + for (lines = *raw; *lines; lines++) {
12286 + if(isGenericFieldType("Essential:", *lines)) {
12287 + char *essential_value;
12288 + essential_value = parseGenericFieldType("Essential", *lines);
12289 + if (strcmp(essential_value, "yes") == 0) {
12290 + pkg->essential = 1;
12292 + free(essential_value);
12299 Index: busybox-1.7.2/archival/libipkg/pkg_parse.h
12300 ===================================================================
12301 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12302 +++ busybox-1.7.2/archival/libipkg/pkg_parse.h 2007-10-30 15:35:05.000000000 -0500
12304 +/* pkg_parse.h - the itsy package management system
12308 + Copyright (C) 2002 Compaq Computer Corporation
12310 + This program is free software; you can redistribute it and/or
12311 + modify it under the terms of the GNU General Public License as
12312 + published by the Free Software Foundation; either version 2, or (at
12313 + your option) any later version.
12315 + This program is distributed in the hope that it will be useful, but
12316 + WITHOUT ANY WARRANTY; without even the implied warranty of
12317 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12318 + General Public License for more details.
12321 +#ifndef PKG_PARSE_H
12322 +#define PKG_PARSE_H
12324 +int isGenericFieldType(char * type, char * line);
12325 +char * parseGenericFieldType(char * type, char * raw);
12326 +void parseStatus(pkg_t *pkg, char * raw);
12327 +int parseVersion(pkg_t *pkg, char *raw);
12328 +char ** parseDependsString(char * raw, int * depends_count);
12329 +int parseVersion(pkg_t *pkg, char *raw);
12330 +void parseConffiles(pkg_t * pkg, char * raw);
12331 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12332 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12335 Index: busybox-1.7.2/archival/libipkg/pkg_src.c
12336 ===================================================================
12337 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12338 +++ busybox-1.7.2/archival/libipkg/pkg_src.c 2007-10-30 15:35:05.000000000 -0500
12340 +/* pkg_src.c - the itsy package management system
12344 + Copyright (C) 2001 University of Southern California
12346 + This program is free software; you can redistribute it and/or
12347 + modify it under the terms of the GNU General Public License as
12348 + published by the Free Software Foundation; either version 2, or (at
12349 + your option) any later version.
12351 + This program is distributed in the hope that it will be useful, but
12352 + WITHOUT ANY WARRANTY; without even the implied warranty of
12353 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12354 + General Public License for more details.
12359 +#include "pkg_src.h"
12360 +#include "str_util.h"
12362 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12364 + src->gzip = gzip;
12365 + src->name = str_dup_safe (name);
12366 + src->value = str_dup_safe (base_url);
12368 + src->extra_data = str_dup_safe (extra_data);
12370 + src->extra_data = NULL;
12374 +void pkg_src_deinit(pkg_src_t *src)
12376 + free (src->name);
12377 + free (src->value);
12378 + if (src->extra_data)
12379 + free (src->extra_data);
12383 Index: busybox-1.7.2/archival/libipkg/pkg_src.h
12384 ===================================================================
12385 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12386 +++ busybox-1.7.2/archival/libipkg/pkg_src.h 2007-10-30 15:35:05.000000000 -0500
12388 +/* pkg_src.h - the itsy package management system
12392 + Copyright (C) 2001 University of Southern California
12394 + This program is free software; you can redistribute it and/or
12395 + modify it under the terms of the GNU General Public License as
12396 + published by the Free Software Foundation; either version 2, or (at
12397 + your option) any later version.
12399 + This program is distributed in the hope that it will be useful, but
12400 + WITHOUT ANY WARRANTY; without even the implied warranty of
12401 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12402 + General Public License for more details.
12408 +#include "nv_pair.h"
12414 + char *extra_data;
12418 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12419 +void pkg_src_deinit(pkg_src_t *src);
12422 Index: busybox-1.7.2/archival/libipkg/pkg_src_list.c
12423 ===================================================================
12424 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12425 +++ busybox-1.7.2/archival/libipkg/pkg_src_list.c 2007-10-30 15:35:05.000000000 -0500
12427 +/* pkg_src_list.c - the itsy package management system
12431 + Copyright (C) 2001 University of Southern California
12433 + This program is free software; you can redistribute it and/or
12434 + modify it under the terms of the GNU General Public License as
12435 + published by the Free Software Foundation; either version 2, or (at
12436 + your option) any later version.
12438 + This program is distributed in the hope that it will be useful, but
12439 + WITHOUT ANY WARRANTY; without even the implied warranty of
12440 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12441 + General Public License for more details.
12446 +#include "pkg_src_list.h"
12447 +#include "void_list.h"
12449 +int pkg_src_list_init(pkg_src_list_t *list)
12451 + return void_list_init((void_list_t *) list);
12454 +void pkg_src_list_deinit(pkg_src_list_t *list)
12456 + pkg_src_list_elt_t *iter;
12457 + pkg_src_t *pkg_src;
12459 + for (iter = list->head; iter; iter = iter->next) {
12460 + pkg_src = iter->data;
12461 + pkg_src_deinit(pkg_src);
12463 + /* malloced in pkg_src_list_append */
12465 + iter->data = NULL;
12467 + void_list_deinit((void_list_t *) list);
12470 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12471 + const char *name, const char *base_url, const char *extra_data,
12476 + /* freed in pkg_src_list_deinit */
12477 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12479 + if (pkg_src == NULL) {
12480 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12483 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12485 + err = void_list_append((void_list_t *) list, pkg_src);
12493 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12495 + return void_list_push((void_list_t *) list, data);
12498 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12500 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12502 Index: busybox-1.7.2/archival/libipkg/pkg_src_list.h
12503 ===================================================================
12504 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12505 +++ busybox-1.7.2/archival/libipkg/pkg_src_list.h 2007-10-30 15:35:05.000000000 -0500
12507 +/* pkg_src_list.h - the itsy package management system
12511 + Copyright (C) 2001 University of Southern California
12513 + This program is free software; you can redistribute it and/or
12514 + modify it under the terms of the GNU General Public License as
12515 + published by the Free Software Foundation; either version 2, or (at
12516 + your option) any later version.
12518 + This program is distributed in the hope that it will be useful, but
12519 + WITHOUT ANY WARRANTY; without even the implied warranty of
12520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12521 + General Public License for more details.
12524 +#ifndef PKG_SRC_LIST_H
12525 +#define PKG_SRC_LIST_H
12527 +#include "pkg_src.h"
12529 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12530 +struct pkg_src_list_elt
12532 + pkg_src_list_elt_t *next;
12536 +typedef struct pkg_src_list pkg_src_list_t;
12537 +struct pkg_src_list
12539 + pkg_src_list_elt_t pre_head;
12540 + pkg_src_list_elt_t *head;
12541 + pkg_src_list_elt_t *tail;
12544 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12546 + if (list->head == NULL)
12552 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12553 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12555 +int pkg_src_list_init(pkg_src_list_t *list);
12556 +void pkg_src_list_deinit(pkg_src_list_t *list);
12558 +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);
12559 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12560 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12564 Index: busybox-1.7.2/archival/libipkg/pkg_vec.c
12565 ===================================================================
12566 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12567 +++ busybox-1.7.2/archival/libipkg/pkg_vec.c 2007-10-30 15:35:05.000000000 -0500
12569 +/* pkg_vec.c - the itsy package management system
12573 + Copyright (C) 2002 Compaq Computer Corporation
12575 + This program is free software; you can redistribute it and/or
12576 + modify it under the terms of the GNU General Public License as
12577 + published by the Free Software Foundation; either version 2, or (at
12578 + your option) any later version.
12580 + This program is distributed in the hope that it will be useful, but
12581 + WITHOUT ANY WARRANTY; without even the implied warranty of
12582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12583 + General Public License for more details.
12586 +#include <stdlib.h>
12587 +#include <fnmatch.h>
12588 +#include "xregex.h"
12592 +pkg_vec_t * pkg_vec_alloc(void)
12594 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12596 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12599 + vec->pkgs = NULL;
12605 +void pkg_vec_free(pkg_vec_t *vec)
12612 + * assumption: all names in a vector are identical
12613 + * assumption: all version strings are trimmed,
12614 + * so identical versions have identical version strings,
12615 + * implying identical packages; let's marry these
12617 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12622 + /* look for a duplicate pkg by name, version, and architecture */
12623 + for (i = 0; i < vec->len; i++){
12624 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12625 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12626 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12627 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12628 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12629 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12631 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12632 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12637 + /* we didn't find one, add it */
12639 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12640 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12642 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12643 + vec->pkgs[vec->len] = pkg;
12647 + /* update the one that we have */
12649 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12650 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12651 + if (set_status) {
12652 + /* this is from the status file, so need to merge with existing database */
12653 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12654 + pkg_merge(vec->pkgs[i], pkg, set_status);
12655 + /* XXX: CLEANUP: It's not so polite to free something here
12656 + that was passed in from above. */
12660 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12661 + /* just overwrite the old one */
12662 + pkg_deinit(vec->pkgs[i]);
12663 + free(vec->pkgs[i]);
12664 + vec->pkgs[i] = pkg;
12666 + return vec->pkgs[i];
12670 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12675 + /* look for a duplicate pkg by name, version, and architecture */
12676 + for (i = 0; i < vec->len; i++)
12677 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12678 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12679 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12684 + /* we didn't find one, add it */
12686 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12687 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12692 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12695 + for (i = 0; i < vec->len; i++)
12696 + if (vec->pkgs[i] == apkg)
12701 +typedef int (*compare_fcn_t)(const void *, const void *);
12702 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12704 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12707 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12709 + int npkgs = vec->len;
12711 + for (i = 0; i < npkgs; i++) {
12712 + pkg_t *pkg = vec->pkgs[i];
12713 + pkg->state_flag &= ~SF_MARKED;
12718 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12720 + int matching_count = 0;
12721 + pkg_t **pkgs = vec->pkgs;
12722 + int npkgs = vec->len;
12724 + for (i = 0; i < npkgs; i++) {
12725 + pkg_t *pkg = pkgs[i];
12726 + if (fnmatch(pattern, pkg->name, 0)==0) {
12727 + pkg->state_flag |= SF_MARKED;
12728 + matching_count++;
12731 + return matching_count;
12735 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12737 + abstract_pkg_vec_t * vec ;
12738 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12740 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12743 + vec->pkgs = NULL;
12749 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12756 + * assumption: all names in a vector are unique
12758 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12762 + /* look for a duplicate pkg by name */
12763 + for(i = 0; i < vec->len; i++)
12764 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12767 + /* we didn't find one, add it */
12768 + if(i == vec->len){
12770 + (abstract_pkg_t **)
12771 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12772 + vec->pkgs[vec->len] = pkg;
12777 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12779 + if (vec->len > i)
12780 + return vec->pkgs[i];
12785 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12788 + for (i = 0; i < vec->len; i++)
12789 + if (vec->pkgs[i] == apkg)
12794 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12796 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12799 Index: busybox-1.7.2/archival/libipkg/pkg_vec.h
12800 ===================================================================
12801 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12802 +++ busybox-1.7.2/archival/libipkg/pkg_vec.h 2007-10-30 15:35:05.000000000 -0500
12804 +/* pkg_vec.h - the itsy package management system
12808 + Copyright (C) 2002 Compaq Computer Corporation
12810 + This program is free software; you can redistribute it and/or
12811 + modify it under the terms of the GNU General Public License as
12812 + published by the Free Software Foundation; either version 2, or (at
12813 + your option) any later version.
12815 + This program is distributed in the hope that it will be useful, but
12816 + WITHOUT ANY WARRANTY; without even the implied warranty of
12817 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12818 + General Public License for more details.
12824 +typedef struct pkg pkg_t;
12825 +typedef struct abstract_pkg abstract_pkg_t;
12832 +typedef struct pkg_vec pkg_vec_t;
12834 +struct abstract_pkg_vec
12836 + abstract_pkg_t **pkgs;
12839 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12841 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12842 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12844 +pkg_vec_t * pkg_vec_alloc(void);
12845 +void pkg_vec_free(pkg_vec_t *vec);
12846 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12848 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12849 +/* pkg_vec_insert_merge: might munge pkg.
12850 +* returns the pkg that is in the pkg graph */
12851 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12852 +/* this one never munges pkg */
12853 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12854 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12855 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12857 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12858 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12860 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12861 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12862 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12863 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12864 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12865 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12868 Index: busybox-1.7.2/archival/libipkg/sprintf_alloc.h
12869 ===================================================================
12870 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12871 +++ busybox-1.7.2/archival/libipkg/sprintf_alloc.h 2007-10-30 15:35:05.000000000 -0500
12873 +/* sprintf_alloca.c -- like sprintf with memory allocation
12877 + Copyright (C) 2001 University of Southern California
12879 + This program is free software; you can redistribute it and/or modify
12880 + it under the terms of the GNU General Public License as published by
12881 + the Free Software Foundation; either version 2, or (at your option)
12882 + any later version.
12884 + This program is distributed in the hope that it will be useful,
12885 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12886 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12887 + GNU General Public License for more details.
12890 +#ifndef SPRINTF_ALLOC_H
12891 +#define SPRINTF_ALLOC_H
12893 +#include "libbb.h"
12895 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12898 Index: busybox-1.7.2/archival/libipkg/str_list.c
12899 ===================================================================
12900 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12901 +++ busybox-1.7.2/archival/libipkg/str_list.c 2007-10-30 15:35:05.000000000 -0500
12903 +/* str_list.c - the itsy package management system
12907 + Copyright (C) 2001 University of Southern California
12909 + This program is free software; you can redistribute it and/or
12910 + modify it under the terms of the GNU General Public License as
12911 + published by the Free Software Foundation; either version 2, or (at
12912 + your option) any later version.
12914 + This program is distributed in the hope that it will be useful, but
12915 + WITHOUT ANY WARRANTY; without even the implied warranty of
12916 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12917 + General Public License for more details.
12922 +#include "str_list.h"
12924 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12926 + return void_list_elt_init((void_list_elt_t *) elt, data);
12929 +void str_list_elt_deinit(str_list_elt_t *elt)
12931 + void_list_elt_deinit((void_list_elt_t *) elt);
12934 +str_list_t *str_list_alloc()
12936 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12938 + str_list_init(list);
12942 +int str_list_init(str_list_t *list)
12944 + return void_list_init((void_list_t *) list);
12947 +void str_list_deinit(str_list_t *list)
12949 + void_list_deinit((void_list_t *) list);
12952 +int str_list_append(str_list_t *list, char *data)
12954 + return void_list_append((void_list_t *) list, data);
12957 +int str_list_push(str_list_t *list, char *data)
12959 + return void_list_push((void_list_t *) list, data);
12962 +str_list_elt_t *str_list_pop(str_list_t *list)
12964 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12967 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12969 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12970 + (void_list_elt_t **) iter);
12973 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12975 + return (char *)void_list_remove_elt((void_list_t *) list,
12976 + (void *)target_str,
12977 + (void_list_cmp_t)strcmp);
12979 Index: busybox-1.7.2/archival/libipkg/str_list.h
12980 ===================================================================
12981 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12982 +++ busybox-1.7.2/archival/libipkg/str_list.h 2007-10-30 15:35:05.000000000 -0500
12984 +/* str_list.h - the itsy package management system
12988 + Copyright (C) 2001 University of Southern California
12990 + This program is free software; you can redistribute it and/or
12991 + modify it under the terms of the GNU General Public License as
12992 + published by the Free Software Foundation; either version 2, or (at
12993 + your option) any later version.
12995 + This program is distributed in the hope that it will be useful, but
12996 + WITHOUT ANY WARRANTY; without even the implied warranty of
12997 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12998 + General Public License for more details.
13001 +#ifndef STR_LIST_H
13002 +#define STR_LIST_H
13004 +#include "void_list.h"
13006 +typedef struct str_list_elt str_list_elt_t;
13007 +struct str_list_elt
13009 + str_list_elt_t *next;
13013 +typedef struct xstr_list str_list_t;
13016 + str_list_elt_t pre_head;
13017 + str_list_elt_t *head;
13018 + str_list_elt_t *tail;
13021 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13022 +void str_list_elt_deinit(str_list_elt_t *elt);
13024 +str_list_t *str_list_alloc(void);
13025 +int str_list_init(str_list_t *list);
13026 +void str_list_deinit(str_list_t *list);
13028 +int str_list_append(str_list_t *list, char *data);
13029 +int str_list_push(str_list_t *list, char *data);
13030 +str_list_elt_t *str_list_pop(str_list_t *list);
13031 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13032 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13035 Index: busybox-1.7.2/archival/libipkg/str_util.c
13036 ===================================================================
13037 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13038 +++ busybox-1.7.2/archival/libipkg/str_util.c 2007-10-30 15:35:05.000000000 -0500
13040 +/* str_utils.c - the itsy package management system
13044 + Copyright (C) 2001 University of Southern California
13046 + This program is free software; you can redistribute it and/or
13047 + modify it under the terms of the GNU General Public License as
13048 + published by the Free Software Foundation; either version 2, or (at
13049 + your option) any later version.
13051 + This program is distributed in the hope that it will be useful, but
13052 + WITHOUT ANY WARRANTY; without even the implied warranty of
13053 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13054 + General Public License for more details.
13059 +int str_starts_with(const char *str, const char *prefix)
13061 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13064 +int str_ends_with(const char *str, const char *suffix)
13069 + str_len = strlen(str);
13070 + suffix_len = strlen(suffix);
13072 + if (str_len < suffix_len) {
13076 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13079 +int str_chomp(char *str)
13081 + if (str[strlen(str) - 1] == '\n') {
13082 + str[strlen(str) - 1] = '\0';
13088 +int str_toupper(char *str)
13091 + *str = toupper(*str);
13098 +char *str_dup_safe(const char *str)
13100 + return str ? strdup(str) : NULL;
13103 Index: busybox-1.7.2/archival/libipkg/str_util.h
13104 ===================================================================
13105 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13106 +++ busybox-1.7.2/archival/libipkg/str_util.h 2007-10-30 15:35:05.000000000 -0500
13108 +/* str_utils.h - the itsy package management system
13112 + Copyright (C) 2001 University of Southern California
13114 + This program is free software; you can redistribute it and/or
13115 + modify it under the terms of the GNU General Public License as
13116 + published by the Free Software Foundation; either version 2, or (at
13117 + your option) any later version.
13119 + This program is distributed in the hope that it will be useful, but
13120 + WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13122 + General Public License for more details.
13125 +#ifndef STR_UTILS_H
13126 +#define STR_UTILS_H
13128 +int str_starts_with(const char *str, const char *prefix);
13129 +int str_ends_with(const char *str, const char *suffix);
13130 +int str_chomp(char *str);
13131 +int str_toupper(char *str);
13132 +char *str_dup_safe(const char *str);
13135 Index: busybox-1.7.2/archival/libipkg/user.c
13136 ===================================================================
13137 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13138 +++ busybox-1.7.2/archival/libipkg/user.c 2007-10-30 15:35:05.000000000 -0500
13140 +/* user.c - the itsy package management system
13144 + Copyright (C) 2002 Hewlett Packard Company
13145 + Copyright (C) 2001 University of Southern California
13147 + This program is free software; you can redistribute it and/or
13148 + modify it under the terms of the GNU General Public License as
13149 + published by the Free Software Foundation; either version 2, or (at
13150 + your option) any later version.
13152 + This program is distributed in the hope that it will be useful, but
13153 + WITHOUT ANY WARRANTY; without even the implied warranty of
13154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13155 + General Public License for more details.
13158 +#include <stdio.h>
13159 +#include <stdarg.h>
13160 +#include "file_util.h"
13161 +#include "str_util.h"
13163 +#include "libipkg.h"
13168 +static char *question = NULL;
13169 +static int question_len = 255;
13171 +char *get_user_response(const char *format, ...)
13173 + int len = question_len;
13176 + va_start(ap, format);
13179 + vprintf(format, ap);
13181 + response = file_read_line_alloc(stdin);
13182 + } while (response == NULL);
13185 + if (question == NULL || len > question_len) {
13186 + question = realloc(question, len + 1);
13187 + question_len = len;
13189 + len = vsnprintf(question,question_len,format,ap);
13190 + } while (len > question_len);
13191 + response = strdup(ipkg_cb_response(question));
13193 + str_chomp(response);
13194 + str_tolower(response);
13198 Index: busybox-1.7.2/archival/libipkg/user.h
13199 ===================================================================
13200 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13201 +++ busybox-1.7.2/archival/libipkg/user.h 2007-10-30 15:35:05.000000000 -0500
13203 +/* user.c - the itsy package management system
13207 + Copyright (C) 2002 Hewlett Packard Company
13208 + Copyright (C) 2001 University of Southern California
13210 + This program is free software; you can redistribute it and/or
13211 + modify it under the terms of the GNU General Public License as
13212 + published by the Free Software Foundation; either version 2, or (at
13213 + your option) any later version.
13215 + This program is distributed in the hope that it will be useful, but
13216 + WITHOUT ANY WARRANTY; without even the implied warranty of
13217 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13218 + General Public License for more details.
13221 +#include <stdio.h>
13222 +#include <stdarg.h>
13224 +char *get_user_response(const char *format, ...);
13226 Index: busybox-1.7.2/archival/libipkg/void_list.c
13227 ===================================================================
13228 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13229 +++ busybox-1.7.2/archival/libipkg/void_list.c 2007-10-30 15:35:05.000000000 -0500
13231 +/* void_list.c - the itsy package management system
13235 + Copyright (C) 2001 University of Southern California
13237 + This program is free software; you can redistribute it and/or
13238 + modify it under the terms of the GNU General Public License as
13239 + published by the Free Software Foundation; either version 2, or (at
13240 + your option) any later version.
13242 + This program is distributed in the hope that it will be useful, but
13243 + WITHOUT ANY WARRANTY; without even the implied warranty of
13244 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13245 + General Public License for more details.
13249 +#include <errno.h>
13251 +#include "void_list.h"
13253 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13255 + elt->next = NULL;
13256 + elt->data = data;
13261 +void void_list_elt_deinit(void_list_elt_t *elt)
13263 + void_list_elt_init(elt, NULL);
13266 +int void_list_init(void_list_t *list)
13268 + void_list_elt_init(&list->pre_head, NULL);
13269 + list->head = NULL;
13270 + list->pre_head.next = list->head;
13271 + list->tail = NULL;
13276 +void void_list_deinit(void_list_t *list)
13278 + void_list_elt_t *elt;
13280 + while (list->head) {
13281 + elt = void_list_pop(list);
13282 + void_list_elt_deinit(elt);
13283 + /* malloced in void_list_append */
13288 +int void_list_append(void_list_t *list, void *data)
13290 + void_list_elt_t *elt;
13292 + /* freed in void_list_deinit */
13293 + elt = malloc(sizeof(void_list_elt_t));
13294 + if (elt == NULL) {
13295 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13299 + void_list_elt_init(elt, data);
13301 + if (list->tail) {
13302 + list->tail->next = elt;
13303 + list->tail = elt;
13305 + list->head = elt;
13306 + list->pre_head.next = list->head;
13307 + list->tail = elt;
13313 +int void_list_push(void_list_t *list, void *data)
13315 + void_list_elt_t *elt;
13317 + elt = malloc(sizeof(void_list_elt_t));
13318 + if (elt == NULL) {
13319 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13323 + void_list_elt_init(elt, data);
13325 + elt->next = list->head;
13326 + list->head->next = elt;
13327 + if (list->tail == NULL) {
13328 + list->tail = list->head;
13334 +void_list_elt_t *void_list_pop(void_list_t *list)
13336 + void_list_elt_t *elt;
13338 + elt = list->head;
13340 + if (list->head) {
13341 + list->head = list->head->next;
13342 + list->pre_head.next = list->head;
13343 + if (list->head == NULL) {
13344 + list->tail = NULL;
13351 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13353 + void_list_elt_t *prior;
13354 + void_list_elt_t *old_elt;
13358 + old_data = old_elt->data;
13360 + if (old_elt == list->head) {
13361 + prior = &list->pre_head;
13362 + void_list_pop(list);
13364 + for (prior = list->head; prior; prior = prior->next) {
13365 + if (prior->next == old_elt) {
13369 + if (prior == NULL || prior->next != old_elt) {
13370 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13373 + prior->next = old_elt->next;
13375 + if (old_elt == list->tail) {
13376 + list->tail = prior;
13380 + void_list_elt_deinit(old_elt);
13386 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13387 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13389 + void_list_elt_t *prior;
13390 + void_list_elt_t *old_elt = NULL;
13391 + void *old_data = NULL;
13393 + /* first element */
13394 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13395 + old_elt = list->head;
13396 + old_data = list->head->data;
13397 + void_list_pop(list);
13400 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13401 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13402 + old_elt = prior->next;
13403 + old_data = old_elt->data;
13411 + prior->next = old_elt->next;
13413 + if (old_elt == list->tail) {
13414 + list->tail = prior;
13418 + void_list_elt_deinit(old_elt);
13425 Index: busybox-1.7.2/archival/libipkg/void_list.h
13426 ===================================================================
13427 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13428 +++ busybox-1.7.2/archival/libipkg/void_list.h 2007-10-30 15:35:05.000000000 -0500
13430 +/* void_list.h - the itsy package management system
13434 + Copyright (C) 2001 University of Southern California
13436 + This program is free software; you can redistribute it and/or
13437 + modify it under the terms of the GNU General Public License as
13438 + published by the Free Software Foundation; either version 2, or (at
13439 + your option) any later version.
13441 + This program is distributed in the hope that it will be useful, but
13442 + WITHOUT ANY WARRANTY; without even the implied warranty of
13443 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13444 + General Public License for more details.
13447 +#ifndef VOID_LIST_H
13448 +#define VOID_LIST_H
13450 +typedef struct void_list_elt void_list_elt_t;
13451 +struct void_list_elt
13453 + void_list_elt_t *next;
13457 +typedef struct void_list void_list_t;
13460 + void_list_elt_t pre_head;
13461 + void_list_elt_t *head;
13462 + void_list_elt_t *tail;
13465 +static inline int void_list_empty(void_list_t *list)
13467 + if (list->head == NULL)
13473 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13474 +void void_list_elt_deinit(void_list_elt_t *elt);
13476 +int void_list_init(void_list_t *list);
13477 +void void_list_deinit(void_list_t *list);
13479 +int void_list_append(void_list_t *list, void *data);
13480 +int void_list_push(void_list_t *list, void *data);
13481 +void_list_elt_t *void_list_pop(void_list_t *list);
13483 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13484 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13485 +typedef int (*void_list_cmp_t)(const void *, const void *);
13486 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13489 Index: busybox-1.7.2/archival/libipkg/xsystem.c
13490 ===================================================================
13491 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13492 +++ busybox-1.7.2/archival/libipkg/xsystem.c 2007-10-30 15:35:05.000000000 -0500
13494 +/* xsystem.c - system(3) with error messages
13498 + Copyright (C) 2001 University of Southern California
13500 + This program is free software; you can redistribute it and/or
13501 + modify it under the terms of the GNU General Public License as
13502 + published by the Free Software Foundation; either version 2, or (at
13503 + your option) any later version.
13505 + This program is distributed in the hope that it will be useful, but
13506 + WITHOUT ANY WARRANTY; without even the implied warranty of
13507 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13508 + General Public License for more details.
13512 +#include <sys/wait.h>
13514 +#include "xsystem.h"
13516 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13517 + really need the /bin/sh invocation which takes resources and
13518 + introduces security problems. I should switch all of this to a sort
13519 + of execl() or execv() interface/implementation.
13522 +/* Like system(3), but with error messages printed if the fork fails
13523 + or if the child process dies due to an uncaught signal. Also, the
13524 + return value is a bit simpler:
13526 + -1 if there was any problem
13527 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13528 + as defined in <sys/wait.h>.
13530 +int xsystem(const char *cmd)
13534 + err = system(cmd);
13537 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13538 + __FUNCTION__, cmd);
13542 + if (WIFSIGNALED(err)) {
13543 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13544 + __FUNCTION__, WTERMSIG(err), cmd);
13548 + if (WIFEXITED(err)) {
13549 + /* Normal child exit */
13550 + return WEXITSTATUS(err);
13553 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13554 + __FUNCTION__, err);
13558 Index: busybox-1.7.2/archival/libipkg/xsystem.h
13559 ===================================================================
13560 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
13561 +++ busybox-1.7.2/archival/libipkg/xsystem.h 2007-10-30 15:35:05.000000000 -0500
13563 +/* xsystem.h - system(3) with error messages
13567 + Copyright (C) 2001 University of Southern California
13569 + This program is free software; you can redistribute it and/or
13570 + modify it under the terms of the GNU General Public License as
13571 + published by the Free Software Foundation; either version 2, or (at
13572 + your option) any later version.
13574 + This program is distributed in the hope that it will be useful, but
13575 + WITHOUT ANY WARRANTY; without even the implied warranty of
13576 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13577 + General Public License for more details.
13583 +#include <stdlib.h>
13585 +/* Like system(3), but with error messages printed if the fork fails
13586 + or if the child process dies due to an uncaught signal. Also, the
13587 + return value is a bit simpler:
13589 + -1 if there was any problem
13590 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13591 + as defined in <sys/wait.h>.
13593 +int xsystem(const char *cmd);
13597 Index: busybox-1.7.2/archival/libunarchive/data_extract_all.c
13598 ===================================================================
13599 --- busybox-1.7.2.orig/archival/libunarchive/data_extract_all.c 2007-10-30 15:34:59.000000000 -0500
13600 +++ busybox-1.7.2/archival/libunarchive/data_extract_all.c 2007-10-30 15:35:05.000000000 -0500
13601 @@ -129,3 +129,17 @@
13606 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13608 + char *name_ptr = archive_handle->file_header->name;
13610 + name_ptr += strspn(name_ptr, "./");
13611 + if (name_ptr[0] != '\0') {
13612 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13613 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13614 + strcat(archive_handle->file_header->name, name_ptr);
13615 + data_extract_all(archive_handle);
13619 Index: busybox-1.7.2/archival/libunarchive/Kbuild
13620 ===================================================================
13621 --- busybox-1.7.2.orig/archival/libunarchive/Kbuild 2007-10-30 15:34:59.000000000 -0500
13622 +++ busybox-1.7.2/archival/libunarchive/Kbuild 2007-10-30 15:35:05.000000000 -0500
13624 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13625 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13626 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13627 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13628 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13629 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13630 lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
13631 Index: busybox-1.7.2/include/applets.h
13632 ===================================================================
13633 --- busybox-1.7.2.orig/include/applets.h 2007-10-30 15:35:03.000000000 -0500
13634 +++ busybox-1.7.2/include/applets.h 2007-10-30 15:35:05.000000000 -0500
13635 @@ -190,6 +190,7 @@
13636 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13637 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13638 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13639 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13640 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13641 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13642 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13643 Index: busybox-1.7.2/include/unarchive.h
13644 ===================================================================
13645 --- busybox-1.7.2.orig/include/unarchive.h 2007-10-30 15:34:59.000000000 -0500
13646 +++ busybox-1.7.2/include/unarchive.h 2007-10-30 15:35:05.000000000 -0500
13649 extern void data_skip(archive_handle_t *archive_handle);
13650 extern void data_extract_all(archive_handle_t *archive_handle);
13651 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13652 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13653 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13655 Index: busybox-1.7.2/include/usage.h
13656 ===================================================================
13657 --- busybox-1.7.2.orig/include/usage.h 2007-10-30 15:35:03.000000000 -0500
13658 +++ busybox-1.7.2/include/usage.h 2007-10-30 15:35:05.000000000 -0500
13659 @@ -1226,6 +1226,82 @@
13660 "$ ls -la /tmp/busybox*\n" \
13661 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13663 +#define ipkg_trivial_usage \
13664 + "[options]... sub-command [arguments]..."
13665 +#define ipkg_full_usage \
13666 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13668 + "Sub-commands:\n" \
13669 + "\nPackage Manipulation:\n" \
13670 + "\tupdate Update list of available packages\n" \
13671 + "\tupgrade Upgrade all installed packages to latest version\n" \
13672 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13673 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13674 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13675 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13676 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13677 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13679 + "Informational Commands:\n" \
13680 + "\tlist List available packages and descriptions\n" \
13681 + "\tlist_installed List all and only the installed packages and description \n" \
13682 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13683 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13684 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13685 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13686 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13687 + "\tcompare_versions <v1> <op> <v2>\n" \
13688 + "\t compare versions using <= < > >= = << >>\n" \
13689 + "\tprint_architecture prints the architecture.\n" \
13690 + "\tprint_installation_architecture\n" \
13691 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13692 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13693 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13694 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13695 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13696 + "\t prints the installation architecture.\n" \
13699 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13700 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13701 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13702 + "\t 0 errors only\n" \
13703 + "\t 1 normal messages (default)\n" \
13704 + "\t 2 informative messages\n" \
13705 + "\t 3 debug output\n" \
13706 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13707 + "\t-conf <conf_file> Default configuration file location\n" \
13708 + " is /etc/ipkg.conf\n" \
13709 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13710 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13711 + " <dest_name> should be a defined dest name from\n" \
13712 + " the configuration file, (but can also be a\n" \
13713 + " directory name in a pinch).\n" \
13714 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13715 + "\t-offline <offline_root> offline installation of packages.\n" \
13716 + "\t-verbose_wget more wget messages\n" \
13718 + "Force Options (use when ipkg is too smart for its own good):\n" \
13719 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13720 + "\t Install/remove package in spite of failed dependences\n" \
13721 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13722 + " (no prompts). Note that this will not prevent\n" \
13723 + " package installation scripts from prompting.\n" \
13724 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13725 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13726 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13727 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13728 + "\t-noaction No action -- test only\n" \
13729 + "\t-nodeps Do not follow dependences\n" \
13730 + "\t-force-removal-of-dependent-packages\n" \
13731 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13732 + "\t-test No action -- test only\n" \
13733 + "\t-t Specify tmp-dir.\n" \
13734 + "\t--tmp-dir Specify tmp-dir.\n" \
13736 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13737 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13739 #define halt_trivial_usage \
13740 "[-d delay] [-n] [-f]"
13741 #define halt_full_usage \
13742 Index: busybox-1.7.2/Makefile
13743 ===================================================================
13744 --- busybox-1.7.2.orig/Makefile 2007-10-30 15:34:59.000000000 -0500
13745 +++ busybox-1.7.2/Makefile 2007-10-30 15:35:05.000000000 -0500
13746 @@ -428,6 +428,7 @@
13750 + archival/libipkg/ \
13751 archival/libunarchive/ \