1 diff -urN busybox.old/archival/Config.in busybox.dev/archival/Config.in
2 --- busybox.old/archival/Config.in 2007-01-19 22:23:02.000000000 +0100
3 +++ busybox.dev/archival/Config.in 2007-01-22 13:41:03.000000000 +0100
5 gzip is used to compress files.
6 It's probably the most widely used UNIX compression program.
14 + ipkg is the itsy package management system.
19 diff -urN busybox.old/archival/dpkg.c busybox.dev/archival/dpkg.c
20 --- busybox.old/archival/dpkg.c 2007-01-19 22:23:02.000000000 +0100
21 +++ busybox.dev/archival/dpkg.c 2007-01-22 13:41:03.000000000 +0100
22 @@ -1463,6 +1463,10 @@
23 return ar_handle->sub_archive->buffer;
28 +// moved to data_extract_all.c
30 static void data_extract_all_prefix(archive_handle_t *archive_handle)
32 char *name_ptr = archive_handle->file_header->name;
39 static void unpack_package(deb_file_t *deb_file)
41 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
42 diff -urN busybox.old/archival/ipkg.c busybox.dev/archival/ipkg.c
43 --- busybox.old/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
44 +++ busybox.dev/archival/ipkg.c 2007-01-22 13:41:03.000000000 +0100
46 +/* ipkg.c - the itsy package management system
50 + Copyright (C) 2003 kernel concepts
52 + This program is free software; you can redistribute it and/or
53 + modify it under the terms of the GNU General Public License as
54 + published by the Free Software Foundation; either version 2, or (at
55 + your option) any later version.
57 + This program is distributed in the hope that it will be useful, but
58 + WITHOUT ANY WARRANTY; without even the implied warranty of
59 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60 + General Public License for more details.
62 + ipkg command line frontend using libipkg
66 +#include "libipkg/libipkg.h"
68 +int ipkg_main(int argc, char **argv)
70 + return ipkg_op(argc, argv);
72 diff -urN busybox.old/archival/Kbuild busybox.dev/archival/Kbuild
73 --- busybox.old/archival/Kbuild 2007-01-19 22:23:02.000000000 +0100
74 +++ busybox.dev/archival/Kbuild 2007-01-22 13:41:03.000000000 +0100
76 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
77 lib-$(CONFIG_GUNZIP) += gunzip.o
78 lib-$(CONFIG_GZIP) += gzip.o
79 +lib-$(CONFIG_IPKG) += ipkg.o
80 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
81 lib-$(CONFIG_RPM) += rpm.o
82 lib-$(CONFIG_TAR) += tar.o
83 diff -urN busybox.old/archival/libipkg/args.c busybox.dev/archival/libipkg/args.c
84 --- busybox.old/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
85 +++ busybox.dev/archival/libipkg/args.c 2007-01-22 13:41:03.000000000 +0100
87 +/* args.c - parse command-line args
91 + Copyright 2001 University of Southern California
93 + This program is free software; you can redistribute it and/or modify
94 + it under the terms of the GNU General Public License as published by
95 + the Free Software Foundation; either version 2, or (at your option)
98 + This program is distributed in the hope that it will be useful,
99 + but WITHOUT ANY WARRANTY; without even the implied warranty of
100 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 + GNU General Public License for more details.
110 +#include "ipkg_message.h"
113 +#include "sprintf_alloc.h"
118 +static void print_version(void);
122 + ARGS_OPT_FORCE_DEFAULTS = 129,
123 + ARGS_OPT_FORCE_DEPENDS,
124 + ARGS_OPT_FORCE_OVERWRITE,
125 + ARGS_OPT_FORCE_DOWNGRADE,
126 + ARGS_OPT_FORCE_REINSTALL,
127 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
128 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
129 + ARGS_OPT_FORCE_SPACE,
132 + ARGS_OPT_VERBOSE_WGET,
133 + ARGS_OPT_VERBOSITY,
134 + ARGS_OPT_MULTIPLE_PROVIDERS
137 +int args_init(args_t *args)
139 + char *conf_file_dir;
141 + memset(args, 0, sizeof(args_t));
143 + args->dest = ARGS_DEFAULT_DEST;
145 + conf_file_dir = getenv("IPKG_CONF_DIR");
146 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
147 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
149 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
150 + ARGS_DEFAULT_CONF_FILE_NAME);
152 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
153 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
154 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
155 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
156 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
157 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
158 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
159 + args->noaction = ARGS_DEFAULT_NOACTION;
160 + args->nodeps = ARGS_DEFAULT_NODEPS;
161 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
162 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
163 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
164 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
165 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
166 + args->multiple_providers = 0;
167 + args->nocheckfordirorfile = 0;
168 + args->noreadfeedsfile = 0;
173 +void args_deinit(args_t *args)
175 + free(args->conf_file);
176 + args->conf_file = NULL;
179 +int args_parse(args_t *args, int argc, char *argv[])
182 + int option_index = 0;
184 + static struct option long_options[] = {
185 + {"query-all", 0, 0, 'A'},
186 + {"conf-file", 1, 0, 'f'},
187 + {"conf", 1, 0, 'f'},
188 + {"dest", 1, 0, 'd'},
189 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
190 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
191 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
192 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
193 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
194 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
195 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
196 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
197 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
198 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
199 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
200 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
201 + {"recursive", 0, 0,
202 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
203 + {"force-removal-of-dependent-packages", 0, 0,
204 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
205 + {"force_removal_of_dependent_packages", 0, 0,
206 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
207 + {"force-removal-of-essential-packages", 0, 0,
208 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
209 + {"force_removal_of_essential_packages", 0, 0,
210 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
211 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
212 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
213 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
214 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
215 + {"offline", 1, 0, 'o'},
216 + {"offline-root", 1, 0, 'o'},
217 + {"test", 0, 0, ARGS_OPT_NOACTION},
218 + {"tmp-dir", 1, 0, 't'},
219 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
220 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
221 + {"verbosity", 2, 0, 'V'},
222 + {"version", 0, 0, 'v'},
227 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
233 + args->query_all = 1;
236 + args->dest = optarg;
239 + free(args->conf_file);
240 + args->conf_file = strdup(optarg);
243 + args->offline_root = optarg;
246 + args->noaction = 1;
249 + args->tmp_dir = strdup(optarg);
255 + case ARGS_OPT_VERBOSITY:
257 + args->verbosity = atoi(optarg);
259 + args->verbosity += 1;
261 + case ARGS_OPT_FORCE_DEFAULTS:
262 + args->force_defaults = 1;
264 + case ARGS_OPT_FORCE_DEPENDS:
265 + args->force_depends = 1;
267 + case ARGS_OPT_FORCE_OVERWRITE:
268 + args->force_overwrite = 1;
270 + case ARGS_OPT_FORCE_DOWNGRADE:
271 + args->force_downgrade = 1;
273 + case ARGS_OPT_FORCE_REINSTALL:
274 + args->force_reinstall = 1;
276 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
277 + args->force_removal_of_essential_packages = 1;
279 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
280 + args->force_removal_of_dependent_packages = 1;
282 + case ARGS_OPT_FORCE_SPACE:
283 + args->force_space = 1;
285 + case ARGS_OPT_VERBOSE_WGET:
286 + args->verbose_wget = 1;
288 + case ARGS_OPT_MULTIPLE_PROVIDERS:
289 + args->multiple_providers = 1;
291 + case ARGS_OPT_NODEPS:
294 + case ARGS_OPT_NOACTION:
295 + args->noaction = 1;
304 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
315 +void args_usage(char *complaint)
318 + bb_error_msg("%s\n", complaint);
325 +static void print_version(void)
327 + bb_error_msg("version %s\n", IPKG_VERSION);
329 diff -urN busybox.old/archival/libipkg/args.h busybox.dev/archival/libipkg/args.h
330 --- busybox.old/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
331 +++ busybox.dev/archival/libipkg/args.h 2007-01-22 13:41:03.000000000 +0100
333 +/* args.h - parse command-line args
337 + Copyright 2001 University of Southern California
339 + This program is free software; you can redistribute it and/or modify
340 + it under the terms of the GNU General Public License as published by
341 + the Free Software Foundation; either version 2, or (at your option)
344 + This program is distributed in the hope that it will be useful,
345 + but WITHOUT ANY WARRANTY; without even the implied warranty of
346 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
347 + GNU General Public License for more details.
358 + int force_defaults;
360 + int force_overwrite;
361 + int force_downgrade;
362 + int force_reinstall;
363 + int force_removal_of_essential_packages;
364 + int force_removal_of_dependent_packages;
368 + int multiple_providers;
372 + int nocheckfordirorfile;
373 + int noreadfeedsfile;
374 + char *offline_root;
375 + char *offline_root_pre_script_cmd;
376 + char *offline_root_post_script_cmd;
378 +typedef struct args args_t;
380 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
381 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
382 +#define ARGS_DEFAULT_DEST NULL
383 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
384 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
385 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
386 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
387 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
388 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
389 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
390 +#define ARGS_DEFAULT_FORCE_SPACE 0
391 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
392 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
393 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
394 +#define ARGS_DEFAULT_NOACTION 0
395 +#define ARGS_DEFAULT_NODEPS 0
396 +#define ARGS_DEFAULT_VERBOSE_WGET 0
397 +#define ARGS_DEFAULT_VERBOSITY 1
399 +int args_init(args_t *args);
400 +void args_deinit(args_t *args);
401 +int args_parse(args_t *args, int argc, char *argv[]);
402 +void args_usage(char *complaint);
405 diff -urN busybox.old/archival/libipkg/conffile.c busybox.dev/archival/libipkg/conffile.c
406 --- busybox.old/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
407 +++ busybox.dev/archival/libipkg/conffile.c 2007-01-22 13:41:03.000000000 +0100
409 +/* conffile.c - the itsy package management system
413 + Copyright (C) 2001 University of Southern California
415 + This program is free software; you can redistribute it and/or
416 + modify it under the terms of the GNU General Public License as
417 + published by the Free Software Foundation; either version 2, or (at
418 + your option) any later version.
420 + This program is distributed in the hope that it will be useful, but
421 + WITHOUT ANY WARRANTY; without even the implied warranty of
422 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
423 + General Public License for more details.
430 +#include "ipkg_message.h"
432 +#include "conffile.h"
433 +#include "file_util.h"
434 +#include "sprintf_alloc.h"
436 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
438 + return nv_pair_init(conffile, file_name, md5sum);
441 +void conffile_deinit(conffile_t *conffile)
443 + nv_pair_deinit(conffile);
446 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
449 + char *filename = conffile->name;
450 + char *root_filename;
453 + if (conffile->value == NULL) {
454 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
458 + root_filename = root_filename_alloc(conf, filename);
460 + md5sum = file_md5sum_alloc(root_filename);
462 + ret = strcmp(md5sum, conffile->value);
464 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
465 + conffile->name, md5sum, conffile->value);
468 + free(root_filename);
473 diff -urN busybox.old/archival/libipkg/conffile.h busybox.dev/archival/libipkg/conffile.h
474 --- busybox.old/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
475 +++ busybox.dev/archival/libipkg/conffile.h 2007-01-22 13:41:03.000000000 +0100
477 +/* conffile.h - the itsy package management system
481 + Copyright (C) 2001 University of Southern California
483 + This program is free software; you can redistribute it and/or
484 + modify it under the terms of the GNU General Public License as
485 + published by the Free Software Foundation; either version 2, or (at
486 + your option) any later version.
488 + This program is distributed in the hope that it will be useful, but
489 + WITHOUT ANY WARRANTY; without even the implied warranty of
490 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
491 + General Public License for more details.
497 +#include "nv_pair.h"
499 +typedef struct nv_pair conffile_t;
501 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
502 +void conffile_deinit(conffile_t *conffile);
503 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
507 diff -urN busybox.old/archival/libipkg/conffile_list.c busybox.dev/archival/libipkg/conffile_list.c
508 --- busybox.old/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
509 +++ busybox.dev/archival/libipkg/conffile_list.c 2007-01-22 13:41:03.000000000 +0100
511 +/* conffile_list.c - the itsy package management system
515 + Copyright (C) 2001 University of Southern California
517 + This program is free software; you can redistribute it and/or
518 + modify it under the terms of the GNU General Public License as
519 + published by the Free Software Foundation; either version 2, or (at
520 + your option) any later version.
522 + This program is distributed in the hope that it will be useful, but
523 + WITHOUT ANY WARRANTY; without even the implied warranty of
524 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
525 + General Public License for more details.
530 +#include "conffile_list.h"
532 +int conffile_list_init(conffile_list_t *list)
534 + return nv_pair_list_init(list);
537 +void conffile_list_deinit(conffile_list_t *list)
539 + nv_pair_list_deinit(list);
542 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
543 + const char *md5sum)
545 + return nv_pair_list_append(list, file_name, md5sum);
548 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
550 + return nv_pair_list_push(list, data);
553 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
555 + return nv_pair_list_pop(list);
558 diff -urN busybox.old/archival/libipkg/conffile_list.h busybox.dev/archival/libipkg/conffile_list.h
559 --- busybox.old/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
560 +++ busybox.dev/archival/libipkg/conffile_list.h 2007-01-22 13:41:03.000000000 +0100
562 +/* conffile_list.h - the itsy package management system
566 + Copyright (C) 2001 University of Southern California
568 + This program is free software; you can redistribute it and/or
569 + modify it under the terms of the GNU General Public License as
570 + published by the Free Software Foundation; either version 2, or (at
571 + your option) any later version.
573 + This program is distributed in the hope that it will be useful, but
574 + WITHOUT ANY WARRANTY; without even the implied warranty of
575 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
576 + General Public License for more details.
579 +#ifndef CONFFILE_LIST_H
580 +#define CONFFILE_LIST_H
582 +#include "conffile.h"
583 +#include "nv_pair_list.h"
585 +typedef struct nv_pair_list_elt conffile_list_elt_t;
586 +typedef struct nv_pair_list conffile_list_t;
588 +int conffile_list_init(conffile_list_t *list);
589 +void conffile_list_deinit(conffile_list_t *list);
591 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
592 + const char *root_dir);
593 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
594 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
598 diff -urN busybox.old/archival/libipkg/file_util.c busybox.dev/archival/libipkg/file_util.c
599 --- busybox.old/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
600 +++ busybox.dev/archival/libipkg/file_util.c 2007-01-22 14:00:52.000000000 +0100
602 +/* file_util.c - convenience routines for common stat operations
606 + Copyright (C) 2001 University of Southern California
608 + This program is free software; you can redistribute it and/or
609 + modify it under the terms of the GNU General Public License as
610 + published by the Free Software Foundation; either version 2, or (at
611 + your option) any later version.
613 + This program is distributed in the hope that it will be useful, but
614 + WITHOUT ANY WARRANTY; without even the implied warranty of
615 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
616 + General Public License for more details.
620 +#include <sys/types.h>
621 +#include <sys/stat.h>
623 +#include "sprintf_alloc.h"
624 +#include "file_util.h"
628 +int file_exists(const char *file_name)
631 + struct stat stat_buf;
633 + err = stat(file_name, &stat_buf);
641 +int file_is_dir(const char *file_name)
644 + struct stat stat_buf;
646 + err = stat(file_name, &stat_buf);
651 + return S_ISDIR(stat_buf.st_mode);
654 +/* read a single line from a file, stopping at a newline or EOF.
655 + If a newline is read, it will appear in the resulting string.
656 + Return value is a malloc'ed char * which should be freed at
657 + some point by the caller.
659 + Return value is NULL if the file is at EOF when called.
661 +#define FILE_READ_LINE_BUF_SIZE 1024
662 +char *file_read_line_alloc(FILE *file)
664 + char buf[FILE_READ_LINE_BUF_SIZE];
669 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
670 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
671 + buf_len = strlen(buf);
673 + line_size += buf_len;
674 + line = realloc(line, line_size);
675 + if (line == NULL) {
676 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
681 + line_size = buf_len + 1;
682 + line = strdup(buf);
684 + if (buf[buf_len - 1] == '\n') {
692 +int file_move(const char *src, const char *dest)
696 + err = rename(src, dest);
698 + if (err && errno == EXDEV) {
699 + err = file_copy(src, dest);
702 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
703 + __FUNCTION__, src, dest, strerror(errno));
709 +/* I put these here to keep libbb dependencies from creeping all over
711 +int file_copy(const char *src, const char *dest)
715 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
717 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
718 + __FUNCTION__, src, dest);
724 +int file_mkdir_hier(const char *path, long mode)
726 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
729 +char *file_md5sum_alloc(const char *file_name)
731 + return hash_file(file_name, HASH_MD5);
734 diff -urN busybox.old/archival/libipkg/file_util.h busybox.dev/archival/libipkg/file_util.h
735 --- busybox.old/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
736 +++ busybox.dev/archival/libipkg/file_util.h 2007-01-22 13:41:03.000000000 +0100
738 +/* file_util.h - convenience routines for common file operations
742 + Copyright (C) 2001 University of Southern California
744 + This program is free software; you can redistribute it and/or
745 + modify it under the terms of the GNU General Public License as
746 + published by the Free Software Foundation; either version 2, or (at
747 + your option) any later version.
749 + This program is distributed in the hope that it will be useful, but
750 + WITHOUT ANY WARRANTY; without even the implied warranty of
751 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
752 + General Public License for more details.
758 +int file_exists(const char *file_name);
759 +int file_is_dir(const char *file_name);
760 +char *file_read_line_alloc(FILE *file);
761 +int file_move(const char *src, const char *dest);
762 +int file_copy(const char *src, const char *dest);
763 +int file_mkdir_hier(const char *path, long mode);
764 +char *file_md5sum_alloc(const char *file_name);
767 diff -urN busybox.old/archival/libipkg/hash_table.c busybox.dev/archival/libipkg/hash_table.c
768 --- busybox.old/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
769 +++ busybox.dev/archival/libipkg/hash_table.c 2007-01-22 13:41:03.000000000 +0100
771 +/* hash.c - hash tables for ipkg
773 + Steven M. Ayer, Jamey Hicks
775 + Copyright (C) 2002 Compaq Computer Corporation
777 + This program is free software; you can redistribute it and/or
778 + modify it under the terms of the GNU General Public License as
779 + published by the Free Software Foundation; either version 2, or (at
780 + your option) any later version.
782 + This program is distributed in the hope that it will be useful, but
783 + WITHOUT ANY WARRANTY; without even the implied warranty of
784 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
785 + General Public License for more details.
792 +#include "hash_table.h"
793 +#include "ipkg_message.h"
796 +static int hash_index(hash_table_t *hash, const char *pkg_name);
797 +static int rotating(const char *key, int len, int prime);
799 +static int hash_index(hash_table_t *hash, const char *pkg_name)
801 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
804 +static int rotating(const char *key, int len, int prime)
806 + unsigned int hash, i;
807 + for (hash=len, i=0; i<len; ++i)
808 + hash = (hash<<4)^(hash>>28)^key[i];
809 + return (hash % prime);
814 + * this is an open table keyed by strings
816 +int hash_table_init(const char *name, hash_table_t *hash, int len)
818 + static int primes_table[] = {
819 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
820 + 19471, 23143, 33961, 46499, 49727, 99529, 0
824 + if (hash->entries != NULL) {
825 + /* we have been here already */
830 + hash->entries = NULL;
831 + hash->n_entries = 0;
832 + hash->hash_entry_key = NULL;
834 + picker = primes_table;
835 + while(*picker && (*picker++ < len));
837 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
840 + hash->n_entries = *picker;
841 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
842 + if (hash->entries == NULL) {
843 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
849 +void hash_table_deinit(hash_table_t *hash)
851 + free(hash->entries);
852 + hash->entries = NULL;
853 + hash->n_entries = 0;
856 +void *hash_table_get(hash_table_t *hash, const char *key)
858 + int ndx= hash_index(hash, key);
859 + hash_entry_t *hash_entry = hash->entries + ndx;
862 + if (hash_entry->key)
864 + if (strcmp(key, hash_entry->key) == 0) {
865 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
866 + return hash_entry->data;
869 + hash_entry = hash_entry->next;
874 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
876 + int ndx= hash_index(hash, key);
877 + hash_entry_t *hash_entry = hash->entries + ndx;
878 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
879 + if (hash_entry->key) {
880 + if (strcmp(hash_entry->key, key) == 0) {
881 + /* alread in table, update the value */
882 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
883 + hash_entry->data = value;
887 + * if this is a collision, we have to go to the end of the ll,
888 + * then add a new entry
889 + * before we can hook up the value
891 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
892 + while (hash_entry->next)
893 + hash_entry = hash_entry->next;
894 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
895 + if (!hash_entry->next) {
898 + hash_entry = hash_entry->next;
899 + hash_entry->next = NULL;
902 + hash->n_elements++;
903 + hash_entry->key = strdup(key);
904 + hash_entry->data = value;
910 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
916 + for (i = 0; i < hash->n_entries; i++) {
917 + hash_entry_t *hash_entry = (hash->entries + i);
919 + if(hash_entry->key) {
920 + f(hash_entry->key, hash_entry->data, data);
922 + } while((hash_entry = hash_entry->next));
926 diff -urN busybox.old/archival/libipkg/hash_table.h busybox.dev/archival/libipkg/hash_table.h
927 --- busybox.old/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
928 +++ busybox.dev/archival/libipkg/hash_table.h 2007-01-22 13:41:03.000000000 +0100
930 +/* hash.h - hash tables for ipkg
932 + Steven M. Ayer, Jamey Hicks
934 + Copyright (C) 2002 Compaq Computer Corporation
936 + This program is free software; you can redistribute it and/or
937 + modify it under the terms of the GNU General Public License as
938 + published by the Free Software Foundation; either version 2, or (at
939 + your option) any later version.
941 + This program is distributed in the hope that it will be useful, but
942 + WITHOUT ANY WARRANTY; without even the implied warranty of
943 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
944 + General Public License for more details.
947 +#ifndef _HASH_TABLE_H_
948 +#define _HASH_TABLE_H_
950 +typedef struct hash_entry hash_entry_t;
951 +typedef struct hash_table hash_table_t;
956 + struct hash_entry * next;
961 + hash_entry_t * entries;
962 + int n_entries; /* number of buckets */
964 + const char * (*hash_entry_key)(void * data);
967 +int hash_table_init(const char *name, hash_table_t *hash, int len);
968 +void hash_table_deinit(hash_table_t *hash);
969 +void *hash_table_get(hash_table_t *hash, const char *key);
970 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
971 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
973 +#endif /* _HASH_TABLE_H_ */
974 diff -urN busybox.old/archival/libipkg/ipkg_cmd.c busybox.dev/archival/libipkg/ipkg_cmd.c
975 --- busybox.old/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
976 +++ busybox.dev/archival/libipkg/ipkg_cmd.c 2007-01-22 13:47:47.000000000 +0100
978 +/* ipkg_cmd.c - the itsy package management system
982 + Copyright (C) 2001 University of Southern California
984 + This program is free software; you can redistribute it and/or
985 + modify it under the terms of the GNU General Public License as
986 + published by the Free Software Foundation; either version 2, or (at
987 + your option) any later version.
989 + This program is distributed in the hope that it will be useful, but
990 + WITHOUT ANY WARRANTY; without even the implied warranty of
991 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
992 + General Public License for more details.
1001 +#include <stdlib.h>
1002 +#include <unistd.h>
1003 +#include <signal.h>
1005 +#include <dirent.h>
1007 +#include "ipkg_conf.h"
1008 +#include "ipkg_cmd.h"
1009 +#include "ipkg_message.h"
1011 +#include "pkg_dest.h"
1012 +#include "pkg_parse.h"
1013 +#include "sprintf_alloc.h"
1015 +#include "file_util.h"
1016 +#include "str_util.h"
1018 +#include "unarchive.h"
1020 +#include <fnmatch.h>
1023 +#include "ipkg_download.h"
1024 +#include "ipkg_install.h"
1025 +#include "ipkg_upgrade.h"
1026 +#include "ipkg_remove.h"
1027 +#include "ipkg_configure.h"
1028 +#include "ipkg_message.h"
1031 +#include "libipkg.h"
1032 +static void *p_userdata = NULL;
1035 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1036 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1037 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1038 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1039 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1040 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1041 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1042 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1043 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1044 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1045 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1046 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1047 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1048 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1049 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1050 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1051 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1052 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1053 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1054 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1055 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1056 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1057 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1058 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1059 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1061 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1062 + array for easier maintenance */
1063 +static ipkg_cmd_t cmds[] = {
1064 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1065 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1066 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1067 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1068 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1069 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1070 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1071 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1072 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1073 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1074 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1075 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1076 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1077 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1078 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1079 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1080 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1081 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1082 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1083 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1084 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1085 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1086 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1087 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1088 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1089 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1090 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1091 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1092 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1095 +int ipkg_state_changed;
1096 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1098 + if (ipkg_state_changed && !conf->noaction) {
1099 + ipkg_message(conf, IPKG_INFO,
1100 + " writing status file\n");
1101 + ipkg_conf_write_status_files(conf);
1102 + pkg_write_changed_filelists(conf);
1104 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1109 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1111 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1116 + for (i=0; i < num_cmds; i++) {
1118 + if (strcmp(name, cmd->name) == 0) {
1127 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1130 + p_userdata = userdata;
1133 + result = (cmd->fun)(conf, argc, argv);
1134 + if ( result == 0 ) {
1135 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1137 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1140 + if ( error_list ) {
1141 + reverse_error_list(&error_list);
1143 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1144 + /* Here we print the errors collected and free the list */
1145 + while (error_list != NULL) {
1146 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1147 + error_list = error_list->next;
1150 + free_error_list(&error_list);
1154 + p_userdata = NULL;
1158 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1160 + return (cmd->fun)(conf, argc, argv);
1164 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1169 + pkg_src_list_elt_t *iter;
1173 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1175 + if (! file_is_dir(lists_dir)) {
1176 + if (file_exists(lists_dir)) {
1177 + ipkg_message(conf, IPKG_ERROR,
1178 + "%s: ERROR: %s exists, but is not a directory\n",
1179 + __FUNCTION__, lists_dir);
1183 + err = file_mkdir_hier(lists_dir, 0755);
1185 + ipkg_message(conf, IPKG_ERROR,
1186 + "%s: ERROR: failed to make directory %s: %s\n",
1187 + __FUNCTION__, lists_dir, strerror(errno));
1194 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1195 + char *url, *list_file_name;
1199 + if (src->extra_data) /* debian style? */
1200 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1201 + src->gzip ? "Packages.gz" : "Packages");
1203 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1205 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1208 + char *tmp_file_name;
1211 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1213 + if (mkdtemp (tmp) == NULL) {
1214 + perror ("mkdtemp");
1219 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1220 + err = ipkg_download(conf, url, tmp_file_name);
1222 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1223 + in = fopen (tmp_file_name, "r");
1224 + out = fopen (list_file_name, "w");
1226 + inflate_unzip_result res;
1227 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1234 + unlink (tmp_file_name);
1239 + err = ipkg_download(conf, url, list_file_name);
1243 + ipkg_message(conf, IPKG_NOTICE,
1244 + "Updated list of available packages in %s\n",
1248 + free(list_file_name);
1252 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1254 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1255 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1261 + pkg_vec_t *available = pkg_vec_alloc();
1262 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1263 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1264 + for (i = 0; i < available->len; i++) {
1265 + pkg_t *pkg = available->pkgs[i];
1266 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1267 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1268 + pkg->state_want = SW_UNKNOWN;
1272 + pkg_vec_free(available);
1274 + write_status_files_if_changed(conf);
1283 +/* scan the args passed and cache the local filenames of the packages */
1284 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1290 + * First scan through package names/urls
1291 + * For any urls, download the packages and install in database.
1292 + * For any files, install package info in database.
1294 + for (i = 0; i < argc; i ++) {
1295 + char *filename = argv [i];
1296 + //char *tmp = basename (tmp);
1297 + //int tmplen = strlen (tmp);
1299 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1301 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1304 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1306 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1313 +struct ipkg_intercept
1319 +typedef struct ipkg_intercept *ipkg_intercept_t;
1321 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1323 + ipkg_intercept_t ctx;
1327 + ctx = malloc (sizeof (*ctx));
1328 + ctx->oldpath = strdup (getenv ("PATH"));
1330 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1331 + setenv ("PATH", newpath, 1);
1336 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1337 + if (mkdir (ctx->statedir, 0770) < 0) {
1338 + if (errno == EEXIST) {
1339 + free (ctx->statedir);
1343 + perror (ctx->statedir);
1346 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1350 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1356 + setenv ("PATH", ctx->oldpath, 1);
1357 + free (ctx->oldpath);
1359 + dir = opendir (ctx->statedir);
1361 + struct dirent *de;
1362 + while (de = readdir (dir), de != NULL) {
1365 + if (de->d_name[0] == '.')
1368 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1369 + if (access (path, X_OK) == 0) {
1370 + if (system (path)) {
1372 + perror (de->d_name);
1378 + perror (ctx->statedir);
1380 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1384 + free (ctx->statedir);
1390 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1395 + ipkg_intercept_t ic;
1398 + ipkg_message(conf, IPKG_INFO,
1399 + "Configuring unpacked packages\n");
1402 + all = pkg_vec_alloc();
1403 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1405 + ic = ipkg_prep_intercepts (conf);
1407 + for(i = 0; i < all->len; i++) {
1408 + pkg = all->pkgs[i];
1410 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1413 + if (pkg->state_status == SS_UNPACKED) {
1414 + ipkg_message(conf, IPKG_NOTICE,
1415 + "Configuring %s\n", pkg->name);
1417 + r = ipkg_configure(conf, pkg);
1419 + pkg->state_status = SS_INSTALLED;
1420 + pkg->parent->state_status = SS_INSTALLED;
1421 + pkg->state_flag &= ~SF_PREFER;
1429 + r = ipkg_finalize_intercepts (ic);
1433 + pkg_vec_free(all);
1437 +static void sigint_handler(int sig)
1439 + signal(sig, SIG_DFL);
1440 + ipkg_message(NULL, IPKG_NOTICE,
1441 + "ipkg: interrupted. writing out status database\n");
1442 + write_status_files_if_changed(global_conf);
1446 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1452 + global_conf = conf;
1453 + signal(SIGINT, sigint_handler);
1456 + * Now scan through package names and install
1458 + for (i=0; i < argc; i++) {
1461 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1462 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1463 + if (err != EINVAL && err != 0)
1466 + pkg_info_preinstall_check(conf);
1468 + for (i=0; i < argc; i++) {
1470 + if (conf->multiple_providers)
1471 + err = ipkg_install_multi_by_name(conf, arg);
1473 + err = ipkg_install_by_name(conf, arg);
1475 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1476 + ipkg_message(conf, IPKG_ERROR,
1477 + "Cannot find package %s.\n"
1478 + "Check the spelling or perhaps run 'ipkg update'\n",
1483 + /* recheck to verify that all dependences are satisfied */
1484 + if (0) ipkg_satisfy_all_dependences(conf);
1486 + ipkg_configure_packages(conf, NULL);
1488 + write_status_files_if_changed(conf);
1493 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1499 + global_conf = conf;
1500 + signal(SIGINT, sigint_handler);
1503 + for (i=0; i < argc; i++) {
1504 + char *arg = argv[i];
1506 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1507 + if (err != EINVAL && err != 0)
1510 + pkg_info_preinstall_check(conf);
1512 + for (i=0; i < argc; i++) {
1513 + char *arg = argv[i];
1514 + if (conf->restrict_to_default_dest) {
1515 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1517 + conf->default_dest);
1518 + if (pkg == NULL) {
1519 + ipkg_message(conf, IPKG_NOTICE,
1520 + "Package %s not installed in %s\n",
1521 + argv[i], conf->default_dest->name);
1525 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1529 + ipkg_upgrade_pkg(conf, pkg);
1531 + ipkg_install_by_name(conf, arg);
1535 + pkg_vec_t *installed = pkg_vec_alloc();
1537 + pkg_info_preinstall_check(conf);
1539 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1540 + for (i = 0; i < installed->len; i++) {
1541 + pkg = installed->pkgs[i];
1542 + ipkg_upgrade_pkg(conf, pkg);
1544 + pkg_vec_free(installed);
1547 + /* recheck to verify that all dependences are satisfied */
1548 + if (0) ipkg_satisfy_all_dependences(conf);
1550 + ipkg_configure_packages(conf, NULL);
1552 + write_status_files_if_changed(conf);
1557 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1563 + pkg_info_preinstall_check(conf);
1564 + for (i = 0; i < argc; i++) {
1567 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1568 + if (pkg == NULL) {
1569 + ipkg_message(conf, IPKG_ERROR,
1570 + "Cannot find package %s.\n"
1571 + "Check the spelling or perhaps run 'ipkg update'\n",
1576 + err = ipkg_download_pkg(conf, pkg, ".");
1579 + ipkg_message(conf, IPKG_ERROR,
1580 + "Failed to download %s\n", pkg->name);
1582 + ipkg_message(conf, IPKG_NOTICE,
1583 + "Downloaded %s as %s\n",
1584 + pkg->name, pkg->local_filename);
1592 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1595 + pkg_vec_t *available;
1597 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1599 + char *pkg_name = NULL;
1600 + char *version_str;
1603 + pkg_name = argv[0];
1605 + available = pkg_vec_alloc();
1606 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1607 + for (i=0; i < available->len; i++) {
1608 + pkg = available->pkgs[i];
1609 + /* if we have package name or pattern and pkg does not match, then skip it */
1610 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1612 + if (pkg->description) {
1613 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1615 + desc_short[0] = '\0';
1617 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1618 + newline = strchr(desc_short, '\n');
1623 + printf("%s - %s\n", pkg->name, desc_short);
1625 + if (ipkg_cb_list) {
1626 + version_str = pkg_version_str_alloc(pkg);
1627 + ipkg_cb_list(pkg->name,desc_short,
1629 + pkg->state_status,
1631 + free(version_str);
1635 + pkg_vec_free(available);
1641 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1644 + pkg_vec_t *available;
1646 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1648 + char *pkg_name = NULL;
1649 + char *version_str;
1652 + pkg_name = argv[0];
1654 + available = pkg_vec_alloc();
1655 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1656 + for (i=0; i < available->len; i++) {
1657 + pkg = available->pkgs[i];
1658 + /* if we have package name or pattern and pkg does not match, then skip it */
1659 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1661 + if (pkg->description) {
1662 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1664 + desc_short[0] = '\0';
1666 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1667 + newline = strchr(desc_short, '\n');
1672 + printf("%s - %s\n", pkg->name, desc_short);
1674 + if (ipkg_cb_list) {
1675 + version_str = pkg_version_str_alloc(pkg);
1676 + ipkg_cb_list(pkg->name,desc_short,
1678 + pkg->state_status,
1680 + free(version_str);
1688 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1691 + pkg_vec_t *available;
1693 + char *pkg_name = NULL;
1694 + char **pkg_fields = NULL;
1696 + char *buff ; // = (char *)malloc(1);
1699 + pkg_name = argv[0];
1702 + pkg_fields = &argv[1];
1703 + n_fields = argc - 1;
1706 + available = pkg_vec_alloc();
1707 + if (installed_only)
1708 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1710 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1711 + for (i=0; i < available->len; i++) {
1712 + pkg = available->pkgs[i];
1713 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1718 + for (j = 0; j < n_fields; j++)
1719 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1721 + pkg_print_info(pkg, stdout);
1725 + buff = pkg_formatted_info(pkg);
1727 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1728 + pkg->state_status,
1732 + We should not forget that actually the pointer is allocated.
1733 + We need to free it :) ( Thanks florian for seeing the error )
1738 + if (conf->verbosity > 1) {
1739 + conffile_list_elt_t *iter;
1740 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1741 + conffile_t *cf = iter->data;
1742 + int modified = conffile_has_been_modified(conf, cf);
1743 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1744 + cf->name, cf->value, modified);
1752 + pkg_vec_free(available);
1757 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1759 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1762 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1764 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1767 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1772 + char *pkg_name = NULL;
1774 + pkg_name = argv[0];
1776 + err = ipkg_configure_packages (conf, pkg_name);
1779 + err = ipkg_configure_packages (conf, NULL);
1782 + write_status_files_if_changed(conf);
1787 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1790 + char *globpattern;
1793 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1794 + err = glob(globpattern, 0, NULL, &globbuf);
1795 + free(globpattern);
1800 + ipkg_message(conf, IPKG_NOTICE,
1801 + "The following packages in %s will now be installed.\n",
1802 + conf->pending_dir);
1803 + for (i = 0; i < globbuf.gl_pathc; i++) {
1804 + ipkg_message(conf, IPKG_NOTICE,
1805 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1807 + ipkg_message(conf, IPKG_NOTICE, "\n");
1808 + for (i = 0; i < globbuf.gl_pathc; i++) {
1809 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1811 + err = unlink(globbuf.gl_pathv[i]);
1813 + ipkg_message(conf, IPKG_ERROR,
1814 + "%s: ERROR: failed to unlink %s: %s\n",
1815 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1820 + globfree(&globbuf);
1825 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1829 + pkg_t *pkg_to_remove;
1830 + pkg_vec_t *available;
1831 + char *pkg_name = NULL;
1832 + global_conf = conf;
1833 + signal(SIGINT, sigint_handler);
1835 +// ENH: Add the "no pkg removed" just in case.
1839 + available = pkg_vec_alloc();
1840 + pkg_info_preinstall_check(conf);
1842 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1843 + for (i=0; i < argc; i++) {
1844 + pkg_name = malloc(strlen(argv[i])+2);
1845 + strcpy(pkg_name,argv[i]);
1846 + for (a=0; a < available->len; a++) {
1847 + pkg = available->pkgs[a];
1848 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1851 + if (conf->restrict_to_default_dest) {
1852 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1854 + conf->default_dest);
1856 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1859 + if (pkg == NULL) {
1860 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1863 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1864 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1867 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1872 + pkg_vec_free(available);
1874 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1875 + int flagged_pkg_count = 0;
1878 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1880 + for (i = 0; i < installed_pkgs->len; i++) {
1881 + pkg = installed_pkgs->pkgs[i];
1882 + if (pkg->state_flag & SF_USER) {
1883 + flagged_pkg_count++;
1885 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1886 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1889 + if (!flagged_pkg_count) {
1890 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1891 + "so refusing to uninstall unflagged non-leaf packages\n");
1895 + /* find packages not flagged SF_USER (i.e., installed to
1896 + * satisfy a dependence) and not having any dependents, and
1900 + for (i = 0; i < installed_pkgs->len; i++) {
1901 + pkg = installed_pkgs->pkgs[i];
1902 + if (!(pkg->state_flag & SF_USER)
1903 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1905 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1906 + ipkg_remove_pkg(conf, pkg,0);
1910 + } while (removed);
1911 + pkg_vec_free(installed_pkgs);
1915 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1917 + write_status_files_if_changed(conf);
1921 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1926 + global_conf = conf;
1927 + signal(SIGINT, sigint_handler);
1929 + pkg_info_preinstall_check(conf);
1931 + for (i=0; i < argc; i++) {
1932 + if (conf->restrict_to_default_dest) {
1933 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1935 + conf->default_dest);
1937 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1940 + if (pkg == NULL) {
1941 + ipkg_message(conf, IPKG_ERROR,
1942 + "Package %s is not installed.\n", argv[i]);
1945 + ipkg_purge_pkg(conf, pkg);
1948 + write_status_files_if_changed(conf);
1952 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1956 + char *flags = argv[0];
1958 + global_conf = conf;
1959 + signal(SIGINT, sigint_handler);
1961 + for (i=1; i < argc; i++) {
1962 + if (conf->restrict_to_default_dest) {
1963 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1965 + conf->default_dest);
1967 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1970 + if (pkg == NULL) {
1971 + ipkg_message(conf, IPKG_ERROR,
1972 + "Package %s is not installed.\n", argv[i]);
1975 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1976 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1977 + pkg->state_flag = pkg_state_flag_from_str(flags);
1979 +/* pb_ asked this feature 03292004 */
1980 +/* Actually I will use only this two, but this is an open for various status */
1981 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1982 + pkg->state_status = pkg_state_status_from_str(flags);
1984 + ipkg_state_changed++;
1985 + ipkg_message(conf, IPKG_NOTICE,
1986 + "Setting flags for package %s to %s\n",
1987 + pkg->name, flags);
1990 + write_status_files_if_changed(conf);
1994 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
1997 + str_list_t *installed_files;
1998 + str_list_elt_t *iter;
1999 + char *pkg_version;
2000 + size_t buff_len = 8192;
2004 + buff = (char *)malloc(buff_len);
2005 + if ( buff == NULL ) {
2006 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2014 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2016 + if (pkg == NULL) {
2017 + ipkg_message(conf, IPKG_ERROR,
2018 + "Package %s not installed.\n", argv[0]);
2022 + installed_files = pkg_get_installed_files(pkg);
2023 + pkg_version = pkg_version_str_alloc(pkg);
2026 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2027 + pkg->name, pkg_version, pkg->dest->name);
2028 + for (iter = installed_files->head; iter; iter = iter->next) {
2034 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2035 + pkg->name, pkg_version, pkg->dest->name) + 1;
2036 + if (used_len > buff_len) {
2038 + buff = realloc (buff, buff_len);
2041 + for (iter = installed_files->head; iter; iter = iter->next) {
2042 + used_len += strlen (iter->data) + 1;
2043 + while (buff_len <= used_len) {
2045 + buff = realloc (buff, buff_len);
2047 + strncat(buff, iter->data, buff_len);
2048 + strncat(buff, "\n", buff_len);
2050 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2052 + pkg_version_str_alloc(pkg),
2053 + pkg->state_status,
2059 + free(pkg_version);
2060 + pkg_free_installed_files(pkg);
2065 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2069 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2070 + const char *rel_str = "depends on";
2073 + pkg_info_preinstall_check(conf);
2075 + if (conf->query_all)
2076 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2078 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2079 + for (i = 0; i < argc; i++) {
2080 + const char *target = argv[i];
2083 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2085 + for (j = 0; j < available_pkgs->len; j++) {
2086 + pkg_t *pkg = available_pkgs->pkgs[j];
2087 + if (fnmatch(target, pkg->name, 0) == 0) {
2089 + int count = pkg->depends_count + pkg->pre_depends_count;
2090 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2091 + target, pkg->architecture, rel_str);
2092 + for (k = 0; k < count; k++) {
2093 + compound_depend_t *cdepend = &pkg->depends[k];
2095 + for (l = 0; l < cdepend->possibility_count; l++) {
2096 + depend_t *possibility = cdepend->possibilities[l];
2097 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2098 + if (conf->verbosity > 0) {
2099 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2100 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2101 + if (possibility->version) {
2102 + char *typestr = NULL;
2103 + switch (possibility->constraint) {
2104 + case NONE: typestr = "none"; break;
2105 + case EARLIER: typestr = "<"; break;
2106 + case EARLIER_EQUAL: typestr = "<="; break;
2107 + case EQUAL: typestr = "="; break;
2108 + case LATER_EQUAL: typestr = ">="; break;
2109 + case LATER: typestr = ">"; break;
2111 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2115 + ipkg_message(conf, IPKG_ERROR, "\n");
2121 + pkg_vec_free(available_pkgs);
2126 +enum what_field_type {
2135 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2139 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2140 + const char *rel_str = NULL;
2144 + switch (what_field_type) {
2145 + case WHATDEPENDS: rel_str = "depends on"; break;
2146 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2147 + case WHATSUGGESTS: rel_str = "suggests"; break;
2148 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2149 + case WHATPROVIDES: rel_str = "provides"; break;
2150 + case WHATREPLACES: rel_str = "replaces"; break;
2153 + if (conf->query_all)
2154 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2156 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2158 + /* mark the root set */
2159 + pkg_vec_clear_marks(available_pkgs);
2160 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2161 + for (i = 0; i < argc; i++) {
2162 + const char *dependee_pattern = argv[i];
2163 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2165 + for (i = 0; i < available_pkgs->len; i++) {
2166 + pkg_t *pkg = available_pkgs->pkgs[i];
2167 + if (pkg->state_flag & SF_MARKED) {
2168 + /* mark the parent (abstract) package */
2169 + pkg_mark_provides(pkg);
2170 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2174 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2179 + for (j = 0; j < available_pkgs->len; j++) {
2180 + pkg_t *pkg = available_pkgs->pkgs[j];
2182 + int count = ((what_field_type == WHATCONFLICTS)
2183 + ? pkg->conflicts_count
2184 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2185 + /* skip this package if it is already marked */
2186 + if (pkg->parent->state_flag & SF_MARKED) {
2189 + for (k = 0; k < count; k++) {
2190 + compound_depend_t *cdepend =
2191 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2193 + for (l = 0; l < cdepend->possibility_count; l++) {
2194 + depend_t *possibility = cdepend->possibilities[l];
2195 + if (possibility->pkg->state_flag & SF_MARKED) {
2196 + /* mark the depending package so we won't visit it again */
2197 + pkg->state_flag |= SF_MARKED;
2198 + pkg_mark_provides(pkg);
2201 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2202 + if (conf->verbosity > 0) {
2203 + char *ver = pkg_version_str_alloc(pkg);
2204 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2205 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2206 + if (possibility->version) {
2207 + char *typestr = NULL;
2208 + switch (possibility->constraint) {
2209 + case NONE: typestr = "none"; break;
2210 + case EARLIER: typestr = "<"; break;
2211 + case EARLIER_EQUAL: typestr = "<="; break;
2212 + case EQUAL: typestr = "="; break;
2213 + case LATER_EQUAL: typestr = ">="; break;
2214 + case LATER: typestr = ">"; break;
2216 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2219 + if (!pkg_dependence_satisfiable(conf, possibility))
2220 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2222 + ipkg_message(conf, IPKG_NOTICE, "\n");
2223 + goto next_package;
2230 + } while (changed && recursive);
2231 + pkg_vec_free(available_pkgs);
2237 +int pkg_mark_provides(pkg_t *pkg)
2239 + int provides_count = pkg->provides_count;
2240 + abstract_pkg_t **provides = pkg->provides;
2242 + pkg->parent->state_flag |= SF_MARKED;
2243 + for (i = 0; i < provides_count; i++) {
2244 + provides[i]->state_flag |= SF_MARKED;
2249 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2251 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2253 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2255 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2258 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2260 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2263 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2265 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2268 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2270 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2273 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2277 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2278 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2281 + pkg_info_preinstall_check(conf);
2283 + if (conf->query_all)
2284 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2286 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2287 + for (i = 0; i < argc; i++) {
2288 + const char *target = argv[i];
2291 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2293 + for (j = 0; j < available_pkgs->len; j++) {
2294 + pkg_t *pkg = available_pkgs->pkgs[j];
2296 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2297 + for (k = 0; k < count; k++) {
2298 + abstract_pkg_t *apkg =
2299 + ((what_field_type == WHATPROVIDES)
2300 + ? pkg->provides[k]
2301 + : pkg->replaces[k]);
2302 + if (fnmatch(target, apkg->name, 0) == 0) {
2303 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2304 + if (strcmp(target, apkg->name) != 0)
2305 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2306 + ipkg_message(conf, IPKG_ERROR, "\n");
2311 + pkg_vec_free(available_pkgs);
2316 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2318 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2321 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2323 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2326 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2330 + pkg_vec_t *installed;
2332 + str_list_t *installed_files;
2333 + str_list_elt_t *iter;
2334 + char *installed_file;
2340 + installed = pkg_vec_alloc();
2341 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2343 + for (i=0; i < installed->len; i++) {
2344 + pkg = installed->pkgs[i];
2346 + installed_files = pkg_get_installed_files(pkg);
2348 + for (iter = installed_files->head; iter; iter = iter->next) {
2349 + installed_file = iter->data;
2350 + if (fnmatch(argv[0], installed_file, 0)==0) {
2352 + printf("%s: %s\n", pkg->name, installed_file);
2354 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2356 + pkg_version_str_alloc(pkg),
2357 + pkg->state_status, p_userdata);
2362 + pkg_free_installed_files(pkg);
2365 + /* XXX: CLEANUP: It's not obvious from the name of
2366 + pkg_hash_fetch_all_installed that we need to call
2367 + pkg_vec_free to avoid a memory leak. */
2368 + pkg_vec_free(installed);
2373 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2376 + /* this is a bit gross */
2377 + struct pkg p1, p2;
2378 + parseVersion(&p1, argv[0]);
2379 + parseVersion(&p2, argv[2]);
2380 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2382 + ipkg_message(conf, IPKG_ERROR,
2383 + "ipkg compare_versions <v1> <op> <v2>\n"
2384 + "<op> is one of <= >= << >> =\n");
2389 +#ifndef HOST_CPU_STR
2390 +#define HOST_CPU_STR__(X) #X
2391 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2392 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2395 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2397 + nv_pair_list_elt_t *l;
2399 + l = conf->arch_list.head;
2401 + nv_pair_t *nv = l->data;
2402 + printf("arch %s %s\n", nv->name, nv->value);
2409 diff -urN busybox.old/archival/libipkg/ipkg_cmd.h busybox.dev/archival/libipkg/ipkg_cmd.h
2410 --- busybox.old/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2411 +++ busybox.dev/archival/libipkg/ipkg_cmd.h 2007-01-22 13:41:03.000000000 +0100
2413 +/* ipkg_cmd.h - the itsy package management system
2417 + Copyright (C) 2001 University of Southern California
2419 + This program is free software; you can redistribute it and/or
2420 + modify it under the terms of the GNU General Public License as
2421 + published by the Free Software Foundation; either version 2, or (at
2422 + your option) any later version.
2424 + This program is distributed in the hope that it will be useful, but
2425 + WITHOUT ANY WARRANTY; without even the implied warranty of
2426 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2427 + General Public License for more details.
2433 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2438 + int requires_args;
2439 + ipkg_cmd_fun_t fun;
2441 +typedef struct ipkg_cmd ipkg_cmd_t;
2443 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2445 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2446 + const char **argv, void *userdata);
2448 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2450 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2451 +/* install any packges with state_want == SW_INSTALL */
2452 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2453 +/* ensure that all dependences are satisfied */
2454 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2456 +int pkg_mark_provides(pkg_t *pkg);
2459 diff -urN busybox.old/archival/libipkg/ipkg_conf.c busybox.dev/archival/libipkg/ipkg_conf.c
2460 --- busybox.old/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2461 +++ busybox.dev/archival/libipkg/ipkg_conf.c 2007-01-22 13:41:06.000000000 +0100
2463 +/* ipkg_conf.c - the itsy package management system
2467 + Copyright (C) 2001 University of Southern California
2469 + This program is free software; you can redistribute it and/or
2470 + modify it under the terms of the GNU General Public License as
2471 + published by the Free Software Foundation; either version 2, or (at
2472 + your option) any later version.
2474 + This program is distributed in the hope that it will be useful, but
2475 + WITHOUT ANY WARRANTY; without even the implied warranty of
2476 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2477 + General Public License for more details.
2483 +#include "ipkg_conf.h"
2485 +#include "xregex.h"
2486 +#include "sprintf_alloc.h"
2487 +#include "ipkg_conf.h"
2488 +#include "ipkg_message.h"
2489 +#include "file_util.h"
2490 +#include "str_util.h"
2491 +#include "xsystem.h"
2494 +ipkg_conf_t *global_conf;
2496 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2497 + pkg_src_list_t *pkg_src_list,
2498 + nv_pair_list_t *tmp_dest_nv_pair_list,
2499 + char **tmp_lists_dir);
2500 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2501 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2502 + const char *name, const char *value);
2503 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2504 + const char *default_dest_name);
2505 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2506 + pkg_src_list_t *nv_pair_list);
2507 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2508 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2510 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2512 + ipkg_option_t tmp[] = {
2513 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2514 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2515 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2516 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2517 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2518 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2519 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2520 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2521 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2522 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2523 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2524 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2525 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2526 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2527 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2528 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2529 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2530 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2531 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2532 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2533 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2537 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2538 + if ( options == NULL ){
2539 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2543 + memcpy(*options, tmp, sizeof(tmp));
2547 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2553 + *conf_str = strdup(arg_str);
2557 +static void ipkg_conf_free_string(char **conf_str)
2565 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2568 + char *tmp_dir_base;
2569 + nv_pair_list_t tmp_dest_nv_pair_list;
2570 + char * lists_dir =NULL;
2572 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2573 + char *pending_dir =NULL;
2575 + memset(conf, 0, sizeof(ipkg_conf_t));
2577 + pkg_src_list_init(&conf->pkg_src_list);
2579 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2580 + pkg_dest_list_init(&conf->pkg_dest_list);
2582 + nv_pair_list_init(&conf->arch_list);
2584 + conf->restrict_to_default_dest = 0;
2585 + conf->default_dest = NULL;
2588 + if (args->tmp_dir)
2589 + tmp_dir_base = args->tmp_dir;
2591 + tmp_dir_base = getenv("TMPDIR");
2592 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2593 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2594 + IPKG_CONF_TMP_DIR_SUFFIX);
2595 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2596 + if (conf->tmp_dir == NULL) {
2597 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2598 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2602 + conf->force_depends = 0;
2603 + conf->force_defaults = 0;
2604 + conf->force_overwrite = 0;
2605 + conf->force_downgrade = 0;
2606 + conf->force_reinstall = 0;
2607 + conf->force_space = 0;
2608 + conf->force_removal_of_essential_packages = 0;
2609 + conf->force_removal_of_dependent_packages = 0;
2611 + conf->verbose_wget = 0;
2612 + conf->offline_root = NULL;
2613 + conf->offline_root_pre_script_cmd = NULL;
2614 + conf->offline_root_post_script_cmd = NULL;
2615 + conf->multiple_providers = 0;
2616 + conf->verbosity = 1;
2617 + conf->noaction = 0;
2619 + conf->http_proxy = NULL;
2620 + conf->ftp_proxy = NULL;
2621 + conf->no_proxy = NULL;
2622 + conf->proxy_user = NULL;
2623 + conf->proxy_passwd = NULL;
2625 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2626 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2627 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2628 + lists_dir=(char *)malloc(1);
2629 + lists_dir[0]='\0';
2630 + if (args->conf_file) {
2631 + struct stat stat_buf;
2632 + err = stat(args->conf_file, &stat_buf);
2634 + if (ipkg_conf_parse_file(conf, args->conf_file,
2635 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2636 + /* Memory leakage from ipkg_conf_parse-file */
2642 + /* if (!lists_dir ){*/
2643 + if (strlen(lists_dir)<=1 ){
2644 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2645 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2648 + if (args->offline_root) {
2649 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2650 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2655 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2656 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2658 + conf->lists_dir = strdup(lists_dir);
2659 + conf->pending_dir = strdup(pending_dir);
2661 + if (args->offline_root)
2662 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2663 + memset(&globbuf, 0, sizeof(globbuf));
2664 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2667 + for (i = 0; i < globbuf.gl_pathc; i++) {
2668 + if (globbuf.gl_pathv[i])
2669 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2670 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2671 + /* Memory leakage from ipkg_conf_parse-file */
2676 + globfree(&globbuf);
2678 + /* if no architectures were defined, then default all, noarch, and host architecture */
2679 + if (nv_pair_list_empty(&conf->arch_list)) {
2680 + nv_pair_list_append(&conf->arch_list, "all", "1");
2681 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2682 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2685 + /* Even if there is no conf file, we'll need at least one dest. */
2686 + if (tmp_dest_nv_pair_list.head == NULL) {
2687 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2688 + IPKG_CONF_DEFAULT_DEST_NAME,
2689 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2692 + /* After parsing the file, set options from command-line, (so that
2693 + command-line arguments take precedence) */
2694 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2695 + really needs to be cleaned up. There is so much duplication
2696 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2697 + a pointer to args_t (which could then not be freed), rather
2698 + than duplicating every field here? */
2699 + if (args->force_depends) {
2700 + conf->force_depends = 1;
2702 + if (args->force_defaults) {
2703 + conf->force_defaults = 1;
2705 + if (args->force_overwrite) {
2706 + conf->force_overwrite = 1;
2708 + if (args->force_downgrade) {
2709 + conf->force_downgrade = 1;
2711 + if (args->force_reinstall) {
2712 + conf->force_reinstall = 1;
2714 + if (args->force_removal_of_dependent_packages) {
2715 + conf->force_removal_of_dependent_packages = 1;
2717 + if (args->force_removal_of_essential_packages) {
2718 + conf->force_removal_of_essential_packages = 1;
2720 + if (args->nodeps) {
2723 + if (args->noaction) {
2724 + conf->noaction = 1;
2726 + if (args->query_all) {
2727 + conf->query_all = 1;
2729 + if (args->verbose_wget) {
2730 + conf->verbose_wget = 1;
2732 + if (args->multiple_providers) {
2733 + conf->multiple_providers = 1;
2735 + if (args->verbosity != conf->verbosity) {
2736 + conf->verbosity = args->verbosity;
2739 + ipkg_conf_override_string(&conf->offline_root,
2740 + args->offline_root);
2741 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2742 + args->offline_root_pre_script_cmd);
2743 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2744 + args->offline_root_post_script_cmd);
2746 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2747 + read anything from there.
2749 + if ( !(args->nocheckfordirorfile)){
2750 + /* need to run load the source list before dest list -Jamey */
2751 + if ( !(args->noreadfeedsfile))
2752 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2754 + /* Now that we have resolved conf->offline_root, we can commit to
2755 + the directory names for the dests and load in all the package
2757 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2760 + err = ipkg_conf_set_default_dest(conf, args->dest);
2766 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2768 + free(pending_dir);
2773 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2775 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2777 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2778 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2779 + __FUNCTION__, conf->tmp_dir);
2783 + err = rmdir(conf->tmp_dir);
2785 + if (errno == ENOTEMPTY) {
2787 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2788 + err = xsystem(cmd);
2792 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2794 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2796 + free(conf->tmp_dir); /*XXX*/
2798 + pkg_src_list_deinit(&conf->pkg_src_list);
2799 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2800 + nv_pair_list_deinit(&conf->arch_list);
2801 + if (&conf->pkg_hash)
2802 + pkg_hash_deinit(&conf->pkg_hash);
2803 + if (&conf->file_hash)
2804 + hash_table_deinit(&conf->file_hash);
2805 + if (&conf->obs_file_hash)
2806 + hash_table_deinit(&conf->obs_file_hash);
2808 + ipkg_conf_free_string(&conf->offline_root);
2809 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2810 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2812 + if (conf->verbosity > 1) {
2814 + hash_table_t *hashes[] = {
2817 + &conf->obs_file_hash };
2818 + for (i = 0; i < 3; i++) {
2819 + hash_table_t *hash = hashes[i];
2821 + int n_conflicts = 0;
2823 + for (j = 0; j < hash->n_entries; j++) {
2825 + hash_entry_t *e = &hash->entries[j];
2828 + while (e && e->key) {
2835 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2836 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2837 + hash_table_deinit(hash);
2842 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2843 + const char *default_dest_name)
2845 + pkg_dest_list_elt_t *iter;
2848 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2849 + dest = iter->data;
2850 + if (strcmp(dest->name, default_dest_name) == 0) {
2851 + conf->default_dest = dest;
2852 + conf->restrict_to_default_dest = 1;
2857 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2862 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2864 + pkg_src_list_elt_t *iter;
2868 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2870 + if (src == NULL) {
2874 + sprintf_alloc(&list_file, "%s/%s",
2875 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2878 + if (file_exists(list_file)) {
2879 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2887 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2889 + nv_pair_list_elt_t *iter;
2890 + nv_pair_t *nv_pair;
2894 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2895 + nv_pair = iter->data;
2897 + if (conf->offline_root) {
2898 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2900 + root_dir = strdup(nv_pair->value);
2902 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2904 + if (dest == NULL) {
2907 + if (conf->default_dest == NULL) {
2908 + conf->default_dest = dest;
2910 + if (file_exists(dest->status_file_name)) {
2911 + pkg_hash_add_from_file(conf, dest->status_file_name,
2919 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2920 + pkg_src_list_t *pkg_src_list,
2921 + nv_pair_list_t *tmp_dest_nv_pair_list,
2924 + ipkg_option_t * options;
2925 + FILE *file = fopen(filename, "r");
2926 + regex_t valid_line_re, comment_re;
2927 +#define regmatch_size 12
2928 + regmatch_t regmatch[regmatch_size];
2930 + if (ipkg_init_options_array(conf, &options)<0)
2933 + if (file == NULL) {
2934 + fprintf(stderr, "%s: failed to open %s: %s\n",
2935 + __FUNCTION__, filename, strerror(errno));
2939 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2941 + xregcomp(&comment_re,
2942 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2944 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2949 + char *type, *name, *value, *extra;
2951 + line = file_read_line_alloc(file);
2953 + if (line == NULL) {
2959 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2963 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2965 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2966 + filename, line_num, line);
2970 + /* This has to be so ugly to deal with optional quotation marks */
2971 + if (regmatch[2].rm_so > 0) {
2972 + type = strndup(line + regmatch[2].rm_so,
2973 + regmatch[2].rm_eo - regmatch[2].rm_so);
2975 + type = strndup(line + regmatch[3].rm_so,
2976 + regmatch[3].rm_eo - regmatch[3].rm_so);
2978 + if (regmatch[5].rm_so > 0) {
2979 + name = strndup(line + regmatch[5].rm_so,
2980 + regmatch[5].rm_eo - regmatch[5].rm_so);
2982 + name = strndup(line + regmatch[6].rm_so,
2983 + regmatch[6].rm_eo - regmatch[6].rm_so);
2985 + if (regmatch[8].rm_so > 0) {
2986 + value = strndup(line + regmatch[8].rm_so,
2987 + regmatch[8].rm_eo - regmatch[8].rm_so);
2989 + value = strndup(line + regmatch[9].rm_so,
2990 + regmatch[9].rm_eo - regmatch[9].rm_so);
2993 + if (regmatch[11].rm_so > 0) {
2994 + extra = strndup (line + regmatch[11].rm_so,
2995 + regmatch[11].rm_eo - regmatch[11].rm_so);
2998 + /* We use the tmp_dest_nv_pair_list below instead of
2999 + conf->pkg_dest_list because we might encounter an
3000 + offline_root option later and that would invalidate the
3001 + directories we would have computed in
3002 + pkg_dest_list_init. (We do a similar thing with
3003 + tmp_src_nv_pair_list for sake of symmetry.) */
3004 + if (strcmp(type, "option") == 0) {
3005 + ipkg_conf_set_option(options, name, value);
3006 + } else if (strcmp(type, "src") == 0) {
3007 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3008 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3010 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3013 + } else if (strcmp(type, "src/gz") == 0) {
3014 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3015 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3017 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3020 + } else if (strcmp(type, "dest") == 0) {
3021 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3022 + } else if (strcmp(type, "lists_dir") == 0) {
3023 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3024 + if (*lists_dir == NULL) {
3025 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3029 + sprintf (*lists_dir,"%s",value);
3030 + } else if (strcmp(type, "arch") == 0) {
3031 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3033 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3034 + value = strdup("10");
3036 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3038 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3039 + "parameter: %s %s %s\n", type, name, value);
3055 + regfree(&comment_re);
3056 + regfree(&valid_line_re);
3062 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3063 + const char *name, const char *value)
3066 + while (options[i].name) {
3067 + if (strcmp(options[i].name, name) == 0) {
3068 + switch (options[i].type) {
3069 + case IPKG_OPT_TYPE_BOOL:
3070 + *((int *)options[i].value) = 1;
3072 + case IPKG_OPT_TYPE_INT:
3074 + *((int *)options[i].value) = atoi(value);
3077 + printf("%s: Option %s need an argument\n",
3078 + __FUNCTION__, name);
3081 + case IPKG_OPT_TYPE_STRING:
3083 + *((char **)options[i].value) = strdup(value);
3086 + printf("%s: Option %s need an argument\n",
3087 + __FUNCTION__, name);
3095 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3096 + __FUNCTION__, name, value);
3100 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3102 + pkg_dest_list_elt_t *iter;
3109 + if (conf->noaction)
3111 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3112 + dest = iter->data;
3113 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3114 + if (dest->status_file == NULL) {
3115 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3116 + __FUNCTION__, dest->status_file_name, strerror(errno));
3120 + all = pkg_vec_alloc();
3121 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3123 + for(i = 0; i < all->len; i++) {
3124 + pkg = all->pkgs[i];
3125 + /* We don't need most uninstalled packages in the status file */
3126 + if (pkg->state_status == SS_NOT_INSTALLED
3127 + && (pkg->state_want == SW_UNKNOWN
3128 + || pkg->state_want == SW_DEINSTALL
3129 + || pkg->state_want == SW_PURGE)) {
3133 + fprintf(stderr, "Null package\n");
3135 + if (pkg->dest == NULL) {
3136 + fprintf(stderr, "%s: ERROR: Can't write status for "
3137 + "package %s since it has a NULL dest\n",
3138 + __FUNCTION__, pkg->name);
3141 + if (pkg->dest->status_file) {
3142 + pkg_print_status(pkg, pkg->dest->status_file);
3146 + pkg_vec_free(all);
3148 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3149 + dest = iter->data;
3150 + if (dest->status_file) {
3151 + err = ferror(dest->status_file);
3152 + fclose(dest->status_file);
3153 + dest->status_file = NULL;
3155 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3157 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3158 + "retaining old %s\n", __FUNCTION__,
3159 + dest->status_file_tmp_name, dest->status_file_name);
3168 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3170 + char *root_filename;
3171 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3172 + return root_filename;
3174 diff -urN busybox.old/archival/libipkg/ipkg_conf.h busybox.dev/archival/libipkg/ipkg_conf.h
3175 --- busybox.old/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3176 +++ busybox.dev/archival/libipkg/ipkg_conf.h 2007-01-22 13:41:03.000000000 +0100
3178 +/* ipkg_conf.h - the itsy package management system
3182 + Copyright (C) 2001 University of Southern California
3184 + This program is free software; you can redistribute it and/or
3185 + modify it under the terms of the GNU General Public License as
3186 + published by the Free Software Foundation; either version 2, or (at
3187 + your option) any later version.
3189 + This program is distributed in the hope that it will be useful, but
3190 + WITHOUT ANY WARRANTY; without even the implied warranty of
3191 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3192 + General Public License for more details.
3195 +#ifndef IPKG_CONF_H
3196 +#define IPKG_CONF_H
3198 +typedef struct ipkg_conf ipkg_conf_t;
3200 +#include "hash_table.h"
3204 +#include "pkg_hash.h"
3205 +#include "pkg_src_list.h"
3206 +#include "pkg_dest_list.h"
3207 +#include "nv_pair_list.h"
3209 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3210 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3211 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3212 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3214 +/* In case the config file defines no dest */
3215 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3216 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3218 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3222 + pkg_src_list_t pkg_src_list;
3223 + pkg_dest_list_t pkg_dest_list;
3224 + nv_pair_list_t arch_list;
3226 + int restrict_to_default_dest;
3227 + pkg_dest_t *default_dest;
3230 + const char *lists_dir;
3231 + const char *pending_dir;
3234 + int force_depends;
3235 + int force_defaults;
3236 + int force_overwrite;
3237 + int force_downgrade;
3238 + int force_reinstall;
3240 + int force_removal_of_dependent_packages;
3241 + int force_removal_of_essential_packages;
3242 + int nodeps; /* do not follow dependences */
3244 + int multiple_providers;
3245 + char *offline_root;
3246 + char *offline_root_pre_script_cmd;
3247 + char *offline_root_post_script_cmd;
3252 + /* proxy options */
3257 + char *proxy_passwd;
3259 + hash_table_t pkg_hash;
3260 + hash_table_t file_hash;
3261 + hash_table_t obs_file_hash;
3264 +enum ipkg_option_type {
3265 + IPKG_OPT_TYPE_BOOL,
3266 + IPKG_OPT_TYPE_INT,
3267 + IPKG_OPT_TYPE_STRING
3269 +typedef enum ipkg_option_type ipkg_option_type_t;
3271 +typedef struct ipkg_option ipkg_option_t;
3272 +struct ipkg_option {
3274 + const ipkg_option_type_t type;
3275 + const void *value;
3278 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3279 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3281 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3282 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3285 diff -urN busybox.old/archival/libipkg/ipkg_configure.c busybox.dev/archival/libipkg/ipkg_configure.c
3286 --- busybox.old/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3287 +++ busybox.dev/archival/libipkg/ipkg_configure.c 2007-01-22 13:41:03.000000000 +0100
3289 +/* ipkg_configure.c - the itsy package management system
3293 + Copyright (C) 2001 University of Southern California
3295 + This program is free software; you can redistribute it and/or
3296 + modify it under the terms of the GNU General Public License as
3297 + published by the Free Software Foundation; either version 2, or (at
3298 + your option) any later version.
3300 + This program is distributed in the hope that it will be useful, but
3301 + WITHOUT ANY WARRANTY; without even the implied warranty of
3302 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3303 + General Public License for more details.
3308 +#include "ipkg_configure.h"
3310 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3314 + /* DPKG_INCOMPATIBILITY:
3315 + dpkg actually does some conffile handling here, rather than at the
3316 + end of ipkg_install(). Do we care? */
3317 + /* DPKG_INCOMPATIBILITY:
3318 + dpkg actually includes a version number to this script call */
3319 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3321 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3325 + ipkg_state_changed++;
3329 diff -urN busybox.old/archival/libipkg/ipkg_configure.h busybox.dev/archival/libipkg/ipkg_configure.h
3330 --- busybox.old/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3331 +++ busybox.dev/archival/libipkg/ipkg_configure.h 2007-01-22 13:41:03.000000000 +0100
3333 +/* ipkg_configure.h - the itsy package management system
3337 + Copyright (C) 2001 University of Southern California
3339 + This program is free software; you can redistribute it and/or
3340 + modify it under the terms of the GNU General Public License as
3341 + published by the Free Software Foundation; either version 2, or (at
3342 + your option) any later version.
3344 + This program is distributed in the hope that it will be useful, but
3345 + WITHOUT ANY WARRANTY; without even the implied warranty of
3346 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3347 + General Public License for more details.
3350 +#ifndef IPKG_CONFIGURE_H
3351 +#define IPKG_CONFIGURE_H
3353 +#include "ipkg_conf.h"
3355 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3358 diff -urN busybox.old/archival/libipkg/ipkg_download.c busybox.dev/archival/libipkg/ipkg_download.c
3359 --- busybox.old/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3360 +++ busybox.dev/archival/libipkg/ipkg_download.c 2007-01-22 13:41:06.000000000 +0100
3362 +/* ipkg_download.c - the itsy package management system
3366 + Copyright (C) 2001 University of Southern California
3368 + This program is free software; you can redistribute it and/or
3369 + modify it under the terms of the GNU General Public License as
3370 + published by the Free Software Foundation; either version 2, or (at
3371 + your option) any later version.
3373 + This program is distributed in the hope that it will be useful, but
3374 + WITHOUT ANY WARRANTY; without even the implied warranty of
3375 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3376 + General Public License for more details.
3380 +#include "ipkg_download.h"
3381 +#include "ipkg_message.h"
3383 +#include "sprintf_alloc.h"
3384 +#include "xsystem.h"
3385 +#include "file_util.h"
3386 +#include "str_util.h"
3388 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3392 + char *src_basec = strdup(src);
3393 + char *src_base = basename(src_basec);
3394 + char *tmp_file_location;
3397 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3401 + if (str_starts_with(src, "file:")) {
3403 + const char *file_src = src + 5;
3404 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3405 + ret = file_copy(src + 5, dest_file_name);
3406 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3410 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3411 + err = unlink(tmp_file_location);
3412 + if (err && errno != ENOENT) {
3413 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3414 + __FUNCTION__, tmp_file_location, strerror(errno));
3415 + free(tmp_file_location);
3419 + if (conf->http_proxy) {
3420 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3421 + setenv("http_proxy", conf->http_proxy, 1);
3423 + if (conf->ftp_proxy) {
3424 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3425 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3427 + if (conf->no_proxy) {
3428 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3429 + setenv("no_proxy", conf->no_proxy, 1);
3432 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3433 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3434 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3435 + conf->proxy_user ? "--proxy-user=" : "",
3436 + conf->proxy_user ? conf->proxy_user : "",
3437 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3438 + conf->proxy_passwd ? conf->proxy_passwd : "",
3439 + conf->verbose_wget ? "" : "-q",
3442 + err = xsystem(cmd);
3445 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3446 + __FUNCTION__, err, cmd);
3448 + unlink(tmp_file_location);
3449 + free(tmp_file_location);
3456 + err = file_move(tmp_file_location, dest_file_name);
3458 + free(tmp_file_location);
3468 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3473 + if (pkg->src == NULL) {
3474 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3475 + pkg->name, pkg->parent->name);
3479 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3481 + /* XXX: BUG: The pkg->filename might be something like
3482 + "../../foo.ipk". While this is correct, and exactly what we
3483 + want to use to construct url above, here we actually need to
3484 + use just the filename part, without any directory. */
3485 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3487 + err = ipkg_download(conf, url, pkg->local_filename);
3494 + * Downloads file from url, installs in package database, return package name.
3496 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3504 + if (str_starts_with(url, "http://")
3505 + || str_starts_with(url, "ftp://")) {
3507 + char *file_basec = strdup(url);
3508 + char *file_base = basename(file_basec);
3510 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3511 + err = ipkg_download(conf, url, tmp_file);
3515 + err = pkg_init_from_file(pkg, tmp_file);
3518 + pkg->local_filename = strdup(tmp_file);
3523 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3524 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3526 + err = pkg_init_from_file(pkg, url);
3529 + pkg->local_filename = strdup(url);
3530 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3531 + pkg->provided_by_hand = 1;
3539 + if (!pkg->architecture) {
3540 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3544 + pkg->dest = conf->default_dest;
3545 + pkg->state_want = SW_INSTALL;
3546 + pkg->state_flag |= SF_PREFER;
3547 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3548 + if ( pkg == NULL ){
3549 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3553 + *namep = strdup(pkg->name);
3557 diff -urN busybox.old/archival/libipkg/ipkg_download.h busybox.dev/archival/libipkg/ipkg_download.h
3558 --- busybox.old/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3559 +++ busybox.dev/archival/libipkg/ipkg_download.h 2007-01-22 13:41:03.000000000 +0100
3561 +/* ipkg_download.h - the itsy package management system
3565 + Copyright (C) 2001 University of Southern California
3567 + This program is free software; you can redistribute it and/or
3568 + modify it under the terms of the GNU General Public License as
3569 + published by the Free Software Foundation; either version 2, or (at
3570 + your option) any later version.
3572 + This program is distributed in the hope that it will be useful, but
3573 + WITHOUT ANY WARRANTY; without even the implied warranty of
3574 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3575 + General Public License for more details.
3578 +#ifndef IPKG_DOWNLOAD_H
3579 +#define IPKG_DOWNLOAD_H
3581 +#include "ipkg_conf.h"
3583 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3584 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3586 + * Downloads file from url, installs in package database, return package name.
3588 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3591 diff -urN busybox.old/archival/libipkg/ipkg.h busybox.dev/archival/libipkg/ipkg.h
3592 --- busybox.old/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3593 +++ busybox.dev/archival/libipkg/ipkg.h 2007-01-22 13:41:03.000000000 +0100
3595 +/* ipkg.h - the itsy package management system
3599 + Copyright (C) 2001 University of Southern California
3601 + This program is free software; you can redistribute it and/or
3602 + modify it under the terms of the GNU General Public License as
3603 + published by the Free Software Foundation; either version 2, or (at
3604 + your option) any later version.
3606 + This program is distributed in the hope that it will be useful, but
3607 + WITHOUT ANY WARRANTY; without even the implied warranty of
3608 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3609 + General Public License for more details.
3616 +#ifdef HAVE_CONFIG_H
3617 +#include "config.h"
3622 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3625 +#include "ipkg_includes.h"
3626 +#include "ipkg_conf.h"
3627 +#include "ipkg_message.h"
3629 +#define IPKG_PKG_EXTENSION ".ipk"
3630 +#define DPKG_PKG_EXTENSION ".deb"
3632 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3633 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3635 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3636 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3637 +#define IPKG_INFO_DIR_SUFFIX "info"
3638 +#define IPKG_STATUS_FILE_SUFFIX "status"
3640 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3642 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3644 +#define IPKG_VERSION "0.99.162"
3649 + IPKG_PKG_DEPS_UNSATISFIED,
3650 + IPKG_PKG_IS_ESSENTIAL,
3651 + IPKG_PKG_HAS_DEPENDENTS,
3652 + IPKG_PKG_HAS_NO_CANDIDATE
3654 +typedef enum ipkg_error ipkg_error_t;
3656 +extern int ipkg_state_changed;
3661 + struct errlist * next;
3664 +extern struct errlist* error_list;
3666 +extern ipkg_conf_t *global_conf;
3669 diff -urN busybox.old/archival/libipkg/ipkg_includes.h busybox.dev/archival/libipkg/ipkg_includes.h
3670 --- busybox.old/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3671 +++ busybox.dev/archival/libipkg/ipkg_includes.h 2007-01-22 13:41:03.000000000 +0100
3673 +#ifndef IPKG_INCLUDES_H
3674 +#define IPKG_INCLUDES_H
3676 +/* Define to 1 if you have the <memory.h> header file. */
3677 +#define HAVE_MEMORY_H 1
3679 +/* Define to 1 if you have the <regex.h> header file. */
3680 +#define HAVE_REGEX_H 1
3682 +/* Define to 1 if you have the <stdlib.h> header file. */
3683 +#define HAVE_STDLIB_H 1
3685 +/* Define to 1 if you have the <strings.h> header file. */
3686 +#define HAVE_STRINGS_H 1
3688 +/* Define to 1 if you have the <string.h> header file. */
3689 +#define HAVE_STRING_H 1
3691 +/* Define to 1 if you have the <sys/stat.h> header file. */
3692 +#define HAVE_SYS_STAT_H 1
3694 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3695 +#define HAVE_SYS_WAIT_H 1
3697 +/* Define to 1 if you have the <unistd.h> header file. */
3698 +#define HAVE_UNISTD_H 1
3700 +/* Define to 1 if you have the ANSI C header files. */
3701 +#define STDC_HEADERS 1
3707 +# include <stdlib.h>
3708 +# include <stdarg.h>
3709 +# include <stddef.h>
3710 +# include <ctype.h>
3711 +# include <errno.h>
3714 +# include <stdlib.h>
3719 +# include <regex.h>
3723 +# if !STDC_HEADERS && HAVE_MEMORY_H
3724 +# include <memory.h>
3726 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3728 +# define __USE_GNU 1
3730 +# include <string.h>
3735 +# include <strings.h>
3738 +#if HAVE_SYS_STAT_H
3739 +# include <sys/stat.h>
3742 +#if HAVE_SYS_WAIT_H
3743 +# include <sys/wait.h>
3747 +# include <sys/types.h>
3748 +# include <unistd.h>
3751 +#endif /* IPKG_INCLUDES_H */
3752 diff -urN busybox.old/archival/libipkg/ipkg_install.c busybox.dev/archival/libipkg/ipkg_install.c
3753 --- busybox.old/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3754 +++ busybox.dev/archival/libipkg/ipkg_install.c 2007-01-22 13:41:03.000000000 +0100
3756 +/* ipkg_install.c - the itsy package management system
3760 + Copyright (C) 2001 University of Southern California
3762 + This program is free software; you can redistribute it and/or
3763 + modify it under the terms of the GNU General Public License as
3764 + published by the Free Software Foundation; either version 2, or (at
3765 + your option) any later version.
3767 + This program is distributed in the hope that it will be useful, but
3768 + WITHOUT ANY WARRANTY; without even the implied warranty of
3769 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3770 + General Public License for more details.
3775 +#include <dirent.h>
3778 +#include <signal.h>
3779 +typedef void (*sighandler_t)(int);
3782 +#include "pkg_hash.h"
3783 +#include "pkg_extract.h"
3785 +#include "ipkg_install.h"
3786 +#include "ipkg_configure.h"
3787 +#include "ipkg_download.h"
3788 +#include "ipkg_remove.h"
3790 +#include "ipkg_utils.h"
3791 +#include "ipkg_message.h"
3793 +#include "sprintf_alloc.h"
3794 +#include "file_util.h"
3795 +#include "str_util.h"
3796 +#include "xsystem.h"
3799 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3800 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3801 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3803 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3804 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3805 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3806 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3807 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3808 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3809 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3810 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3811 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3812 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3813 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3814 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3815 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3817 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3818 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3819 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3820 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3821 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3823 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3825 +static int user_prefers_old_conffile(const char *file, const char *backup);
3827 +static char *backup_filename_alloc(const char *file_name);
3828 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3829 +static int backup_exists_for(const char *file_name);
3830 +static int backup_remove(const char *file_name);
3833 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3837 + char *old_version, *new_version;
3840 + if (pkg == NULL) {
3844 + err = pkg_init_from_file(pkg, filename);
3849 + if (!pkg->architecture) {
3850 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3854 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3855 + freeing the pkg that we pass in. It might be nice to clean this up
3857 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3858 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3860 + pkg->local_filename = strdup(filename);
3863 + old_version = pkg_version_str_alloc(old);
3864 + new_version = pkg_version_str_alloc(pkg);
3866 + cmp = pkg_compare_versions(old, pkg);
3867 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3868 + cmp = -1 ; /* then we force ipkg to downgrade */
3869 + /* We need to use a value < 0 because in the 0 case we are asking to */
3870 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3873 + ipkg_message(conf, IPKG_NOTICE,
3874 + "Not downgrading package %s on %s from %s to %s.\n",
3875 + old->name, old->dest->name, old_version, new_version);
3876 + pkg->state_want = SW_DEINSTALL;
3877 + pkg->state_flag |= SF_OBSOLETE;
3878 + free(old_version);
3879 + free(new_version);
3882 + free(old_version);
3883 + free(new_version);
3887 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3888 + return ipkg_install_pkg(conf, pkg,0);
3891 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3895 + char *old_version, *new_version;
3897 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3898 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3900 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3902 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3903 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3905 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3907 +/* Pigi Basically here is broken the version stuff.
3908 + What's happening is that nothing provide the version to differents
3909 + functions, so the returned struct is always the latest.
3910 + That's why the install by name don't work.
3912 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3915 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3917 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3918 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3920 + if (new == NULL) {
3921 + return IPKG_PKG_HAS_NO_CANDIDATE;
3924 + new->state_flag |= SF_USER;
3926 + old_version = pkg_version_str_alloc(old);
3927 + new_version = pkg_version_str_alloc(new);
3929 + cmp = pkg_compare_versions(old, new);
3930 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3931 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3932 + cmp = -1 ; /* then we force ipkg to downgrade */
3933 + /* We need to use a value < 0 because in the 0 case we are asking to */
3934 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3936 + ipkg_message(conf, IPKG_DEBUG,
3937 + "Comparing visible versions of pkg %s:"
3938 + "\n\t%s is installed "
3939 + "\n\t%s is available "
3940 + "\n\t%d was comparison result\n",
3941 + pkg_name, old_version, new_version, cmp);
3942 + if (cmp == 0 && !conf->force_reinstall) {
3943 + ipkg_message(conf, IPKG_NOTICE,
3944 + "Package %s (%s) installed in %s is up to date.\n",
3945 + old->name, old_version, old->dest->name);
3946 + free(old_version);
3947 + free(new_version);
3949 + } else if (cmp > 0) {
3950 + ipkg_message(conf, IPKG_NOTICE,
3951 + "Not downgrading package %s on %s from %s to %s.\n",
3952 + old->name, old->dest->name, old_version, new_version);
3953 + free(old_version);
3954 + free(new_version);
3956 + } else if (cmp < 0) {
3957 + new->dest = old->dest;
3958 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3962 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3963 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3964 + return any kind of integer, (might be errno from a syscall,
3965 + etc.). This is a real mess and will need to be cleaned up if
3966 + anyone ever wants to make a nice libipkg. */
3968 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3969 + return ipkg_install_pkg(conf, new,0);
3972 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
3974 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
3977 + abstract_pkg_t *ppkg ;
3979 + if (providers == NULL)
3980 + return IPKG_PKG_HAS_NO_CANDIDATE;
3982 + for (i = 0; i < providers->len; i++) {
3983 + ppkg = abstract_pkg_vec_get(providers, i);
3984 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
3985 + err = ipkg_install_by_name(conf, ppkg->name);
3988 +/* XXX Maybe ppkg should be freed ? */
3994 + * Walk dependence graph starting with pkg, collect packages to be
3995 + * installed into pkgs_needed, in dependence order.
3997 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4000 + pkg_vec_t *depends = pkg_vec_alloc();
4001 + char **unresolved = NULL;
4004 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4009 + ipkg_message(conf, IPKG_ERROR,
4010 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4011 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4012 + while (*unresolved) {
4013 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4016 + ipkg_message(conf, IPKG_ERROR, "\n");
4017 + if (! conf->force_depends) {
4018 + ipkg_message(conf, IPKG_INFO,
4019 + "This could mean that your package list is out of date or that the packages\n"
4020 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4021 + "of this problem try again with the '-force-depends' option.\n");
4022 + pkg_vec_free(depends);
4023 + return IPKG_PKG_DEPS_UNSATISFIED;
4027 + if (ndepends <= 0) {
4028 + pkg_vec_free(depends);
4032 + for (i = 0; i < depends->len; i++) {
4033 + pkg_t *dep = depends->pkgs[i];
4034 + /* The package was uninstalled when we started, but another
4035 + dep earlier in this loop may have depended on it and pulled
4036 + it in, so check first. */
4037 + if ((dep->state_status != SS_INSTALLED)
4038 + && (dep->state_status != SS_UNPACKED)
4039 + && (dep->state_want != SW_INSTALL)) {
4041 + /* Mark packages as to-be-installed */
4042 + dep->state_want = SW_INSTALL;
4044 + /* Dependencies should be installed the same place as pkg */
4045 + if (dep->dest == NULL) {
4046 + dep->dest = pkg->dest;
4049 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4051 + pkg_vec_free(depends);
4057 + pkg_vec_insert(pkgs_needed, pkg);
4059 + pkg_vec_free(depends);
4064 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4068 + char *old_version, *new_version;
4070 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4072 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4073 + if (new == NULL) {
4074 + return IPKG_PKG_HAS_NO_CANDIDATE;
4077 + old_version = pkg_version_str_alloc(old);
4078 + new_version = pkg_version_str_alloc(new);
4080 + cmp = pkg_compare_versions(old, new);
4081 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4082 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4083 + cmp = -1 ; /* then we force ipkg to downgrade */
4084 + /* We need to use a value < 0 because in the 0 case we are asking to */
4085 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4087 + ipkg_message(conf, IPKG_DEBUG,
4088 + "comparing visible versions of pkg %s:"
4089 + "\n\t%s is installed "
4090 + "\n\t%s is available "
4091 + "\n\t%d was comparison result\n",
4092 + pkg_name, old_version, new_version, cmp);
4093 + if (cmp == 0 && !conf->force_reinstall) {
4094 + ipkg_message(conf, IPKG_NOTICE,
4095 + "Package %s (%s) installed in %s is up to date.\n",
4096 + old->name, old_version, old->dest->name);
4097 + free(old_version);
4098 + free(new_version);
4100 + } else if (cmp > 0) {
4101 + ipkg_message(conf, IPKG_NOTICE,
4102 + "Not downgrading package %s on %s from %s to %s.\n",
4103 + old->name, old->dest->name, old_version, new_version);
4104 + free(old_version);
4105 + free(new_version);
4107 + } else if (cmp < 0) {
4108 + new->dest = old->dest;
4109 + old->state_want = SW_DEINSTALL;
4110 + old->state_flag |= SF_OBSOLETE;
4113 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4118 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4121 + pkg_vec_t *depends = pkg_vec_alloc();
4123 + char **unresolved = NULL;
4126 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4131 + ipkg_message(conf, IPKG_ERROR,
4132 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4133 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4134 + while (*unresolved) {
4135 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4138 + ipkg_message(conf, IPKG_ERROR, "\n");
4139 + if (! conf->force_depends) {
4140 + ipkg_message(conf, IPKG_INFO,
4141 + "This could mean that your package list is out of date or that the packages\n"
4142 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4143 + "of this problem try again with the '-force-depends' option.\n");
4144 + pkg_vec_free(depends);
4145 + return IPKG_PKG_DEPS_UNSATISFIED;
4149 + if (ndepends <= 0) {
4153 + /* Mark packages as to-be-installed */
4154 + for (i=0; i < depends->len; i++) {
4155 + /* Dependencies should be installed the same place as pkg */
4156 + if (depends->pkgs[i]->dest == NULL) {
4157 + depends->pkgs[i]->dest = pkg->dest;
4159 + depends->pkgs[i]->state_want = SW_INSTALL;
4162 + for (i = 0; i < depends->len; i++) {
4163 + dep = depends->pkgs[i];
4164 + /* The package was uninstalled when we started, but another
4165 + dep earlier in this loop may have depended on it and pulled
4166 + it in, so check first. */
4167 + if ((dep->state_status != SS_INSTALLED)
4168 + && (dep->state_status != SS_UNPACKED)) {
4169 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4170 + err = ipkg_install_pkg(conf, dep,0);
4172 + pkg_vec_free(depends);
4178 + pkg_vec_free(depends);
4184 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4185 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4187 + if (conf->nodeps == 0) {
4189 + pkg_vec_t *installed = pkg_vec_alloc();
4190 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4191 + for (i = 0; i < installed->len; i++) {
4192 + pkg_t *pkg = installed->pkgs[i];
4193 + satisfy_dependencies_for(conf, pkg);
4195 + pkg_vec_free(installed);
4202 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4205 + pkg_vec_t *conflicts = NULL;
4207 + const char *prefix;
4208 + if (conf->force_depends) {
4209 + level = IPKG_NOTICE;
4210 + prefix = "Warning";
4212 + level = IPKG_ERROR;
4216 + if (!conf->force_depends)
4217 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4220 + ipkg_message(conf, level,
4221 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4223 + while (i < conflicts->len)
4224 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4225 + ipkg_message(conf, level, "\n");
4226 + pkg_vec_free(conflicts);
4227 + return IPKG_PKG_DEPS_UNSATISFIED;
4232 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4234 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4235 + str_list_elt_t *iter;
4237 + for (iter = new_list->head; iter; iter = iter->next) {
4238 + char *new_file = iter->data;
4239 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4241 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4242 + if (!owner || (owner == old_pkg))
4243 + file_hash_set_file_owner(conf, new_file, new_pkg);
4246 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4247 + for (iter = old_list->head; iter; iter = iter->next) {
4248 + char *old_file = iter->data;
4249 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4250 + if (owner == old_pkg) {
4252 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4259 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4261 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4263 + /* sma 6.20.02: yup; here's the first bit */
4265 + * XXX: BUG easy for cworth
4266 + * 1) please point the call below to the correct current root destination
4267 + * 2) we need to resolve how to check the required space for a pending pkg,
4268 + * my diddling with the .ipk file size below isn't going to cut it.
4269 + * 3) return a proper error code instead of 1
4271 + int comp_size, blocks_available;
4273 + if (!conf->force_space && pkg->installed_size != NULL) {
4274 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4276 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4277 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4278 + comp_size = (int)((comp_size + 1023) / 1024);
4280 + if (comp_size >= blocks_available) {
4281 + ipkg_message(conf, IPKG_ERROR,
4282 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4283 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4290 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4293 + char *conffiles_file_name;
4295 + FILE *conffiles_file;
4297 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4299 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4300 + if (pkg->tmp_unpack_dir == NULL) {
4301 + ipkg_message(conf, IPKG_ERROR,
4302 + "%s: Failed to create temporary directory '%s': %s\n",
4303 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4307 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4312 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4313 + conffiles. Seems like I should be able to get everything to go
4314 + through pkg_init_from_file. If so, maybe it would make sense to
4315 + move all of unpack_pkg_control_files to that function. */
4317 + /* Don't need to re-read conffiles if we already have it */
4318 + if (pkg->conffiles.head) {
4322 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4323 + if (! file_exists(conffiles_file_name)) {
4324 + free(conffiles_file_name);
4328 + conffiles_file = fopen(conffiles_file_name, "r");
4329 + if (conffiles_file == NULL) {
4330 + fprintf(stderr, "%s: failed to open %s: %s\n",
4331 + __FUNCTION__, conffiles_file_name, strerror(errno));
4332 + free(conffiles_file_name);
4335 + free(conffiles_file_name);
4339 + char *cf_name_in_dest;
4341 + cf_name = file_read_line_alloc(conffiles_file);
4342 + if (cf_name == NULL) {
4345 + str_chomp(cf_name);
4346 + if (cf_name[0] == '\0') {
4350 + /* Prepend dest->root_dir to conffile name.
4351 + Take pains to avoid multiple slashes. */
4352 + root_dir = pkg->dest->root_dir;
4353 + if (conf->offline_root)
4354 + /* skip the offline_root prefix */
4355 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4356 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4357 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4359 + /* Can't get an md5sum now, (file isn't extracted yet).
4360 + We'll wait until resolve_conffiles */
4361 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4364 + free(cf_name_in_dest);
4367 + fclose(conffiles_file);
4372 +/* returns number of installed replacees */
4373 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4375 + abstract_pkg_t **replaces = pkg->replaces;
4376 + int replaces_count = pkg->replaces_count;
4378 + for (i = 0; i < replaces_count; i++) {
4379 + abstract_pkg_t *ab_pkg = replaces[i];
4380 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4382 + for (j = 0; j < pkg_vec->len; j++) {
4383 + pkg_t *replacee = pkg_vec->pkgs[j];
4384 + if (!pkg_conflicts(pkg, replacee))
4386 + if (replacee->state_status == SS_INSTALLED) {
4387 + pkg_vec_insert(installed_replacees, replacee);
4392 + return installed_replacees->len;
4395 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4398 + int replaces_count = replacees->len;
4399 + for (i = 0; i < replaces_count; i++) {
4400 + pkg_t *replacee = replacees->pkgs[i];
4402 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4403 + err = ipkg_remove_pkg(conf, replacee,0);
4410 +/* to unwind the removal: make sure they are installed */
4411 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4414 + int replaces_count = replacees->len;
4415 + for (i = 0; i < replaces_count; i++) {
4416 + pkg_t *replacee = replacees->pkgs[i];
4417 + if (replacee->state_status != SS_INSTALLED) {
4418 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4419 + err = ipkg_install_pkg(conf, replacee,0);
4427 +int caught_sigint = 0;
4428 +static void ipkg_install_pkg_sigint_handler(int sig)
4430 + caught_sigint = sig;
4433 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4434 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4437 + char message_out[15];
4438 + char *old_version = pkg_version_str_alloc(old_pkg);
4439 + char *new_version = pkg_version_str_alloc(pkg);
4440 + int cmp = pkg_compare_versions(old_pkg, pkg);
4443 + memset(message_out,'\x0',15);
4444 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4445 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4446 + cmp = -1 ; /* then we force ipkg to downgrade */
4447 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4448 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4452 + ipkg_message(conf, IPKG_NOTICE,
4453 + "Not downgrading package %s on %s from %s to %s.\n",
4454 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4456 + } else if (cmp < 0) {
4457 + ipkg_message(conf, IPKG_NOTICE,
4458 + "%s%s on %s from %s to %s...\n",
4459 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4460 + pkg->dest = old_pkg->dest;
4462 + } else /* cmp == 0 */ {
4463 + if (conf->force_reinstall) {
4464 + ipkg_message(conf, IPKG_NOTICE,
4465 + "Reinstalling %s (%s) on %s...\n",
4466 + pkg->name, new_version, old_pkg->dest->name);
4467 + pkg->dest = old_pkg->dest;
4470 + ipkg_message(conf, IPKG_NOTICE,
4471 + "Not installing %s (%s) on %s -- already installed.\n",
4472 + pkg->name, new_version, old_pkg->dest->name);
4476 + free(old_version);
4477 + free(new_version);
4480 + char message_out[15], *version ;
4481 + memset(message_out,'\x0',15);
4483 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4485 + strncpy( message_out,"Installing ",strlen("Installing ") );
4486 + version = pkg_version_str_alloc(pkg);
4488 + ipkg_message(conf, IPKG_NOTICE,
4489 + "%s%s (%s) to %s...\n", message_out,
4490 + pkg->name, version, pkg->dest->name);
4496 +/* and now the meat... */
4497 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4501 + pkg_t *old_pkg = NULL;
4502 + pkg_vec_t *replacees;
4503 + abstract_pkg_t *ab_pkg = NULL;
4504 + int old_state_flag;
4508 + if ( from_upgrade )
4509 + message = 1; /* Coming from an upgrade, and should change the output message */
4512 + ipkg_message(conf, IPKG_ERROR,
4513 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4517 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4519 + if (!pkg_arch_supported(conf, pkg)) {
4520 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4521 + pkg->architecture, pkg->name);
4524 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4525 + err = satisfy_dependencies_for(conf, pkg);
4526 + if (err) { return err; }
4528 + ipkg_message(conf, IPKG_NOTICE,
4529 + "Package %s is already installed in %s.\n",
4530 + pkg->name, pkg->dest->name);
4534 + if (pkg->dest == NULL) {
4535 + pkg->dest = conf->default_dest;
4538 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4540 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4541 + if (err) { return err; }
4543 + pkg->state_want = SW_INSTALL;
4545 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4549 + /* Abhaya: conflicts check */
4550 + err = check_conflicts_for(conf, pkg);
4551 + if (err) { return err; }
4553 + /* this setup is to remove the upgrade scenario in the end when
4554 + installing pkg A, A deps B & B deps on A. So both B and A are
4555 + installed. Then A's installation is started resulting in an
4556 + uncecessary upgrade */
4557 + if (pkg->state_status == SS_INSTALLED
4558 + && conf->force_reinstall == 0) return 0;
4560 + err = verify_pkg_installable(conf, pkg);
4561 + if (err) { return err; }
4563 + if (pkg->local_filename == NULL) {
4564 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4566 + ipkg_message(conf, IPKG_ERROR,
4567 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4573 +/* Check for md5 values */
4576 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4577 + if (strcmp(file_md5, pkg->md5sum))
4579 + ipkg_message(conf, IPKG_ERROR,
4580 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4588 + if (pkg->tmp_unpack_dir == NULL) {
4589 + unpack_pkg_control_files(conf, pkg);
4592 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4593 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4594 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4595 + err = update_file_ownership(conf, pkg, old_pkg);
4596 + if (err) { return err; }
4598 + if (conf->nodeps == 0) {
4599 + err = satisfy_dependencies_for(conf, pkg);
4600 + if (err) { return err; }
4603 + replacees = pkg_vec_alloc();
4604 + pkg_get_installed_replacees(conf, pkg, replacees);
4606 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4608 + sigset_t newset, oldset;
4609 + sighandler_t old_handler = NULL;
4610 + int use_signal = 0;
4611 + caught_sigint = 0;
4613 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4615 + sigemptyset(&newset);
4616 + sigaddset(&newset, SIGINT);
4617 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4620 + ipkg_state_changed++;
4621 + pkg->state_flag |= SF_FILELIST_CHANGED;
4623 + /* XXX: BUG: we really should treat replacement more like an upgrade
4624 + * Instead, we're going to remove the replacees
4626 + err = pkg_remove_installed_replacees(conf, replacees);
4627 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4629 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4630 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4632 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4633 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4635 + err = preinst_configure(conf, pkg, old_pkg);
4636 + if (err) goto UNWIND_PREINST_CONFIGURE;
4638 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4639 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4641 + err = check_data_file_clashes(conf, pkg, old_pkg);
4642 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4644 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4645 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4647 + if (conf->noaction) return 0;
4649 + /* point of no return: no unwinding after this */
4650 + if (old_pkg && !conf->force_reinstall) {
4651 + old_pkg->state_want = SW_DEINSTALL;
4653 + if (old_pkg->state_flag & SF_NOPRUNE) {
4654 + ipkg_message(conf, IPKG_INFO,
4655 + " not removing obsolesced files because package marked noprune\n");
4657 + ipkg_message(conf, IPKG_INFO,
4658 + " removing obsolesced files\n");
4659 + remove_obsolesced_files(conf, pkg, old_pkg);
4661 + /* removing files from old package, to avoid ghost files */
4662 + remove_data_files_and_list(conf, old_pkg);
4663 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4664 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4665 + remove_postrm(conf, old_pkg);
4671 + ipkg_message(conf, IPKG_INFO,
4672 + " installing maintainer scripts\n");
4673 + install_maintainer_scripts(conf, pkg, old_pkg);
4675 + /* the following just returns 0 */
4676 + remove_disappeared(conf, pkg);
4678 + ipkg_message(conf, IPKG_INFO,
4679 + " installing data files\n");
4680 + install_data_files(conf, pkg);
4682 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4683 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4685 + ipkg_message(conf, IPKG_INFO,
4686 + " resolving conf files\n");
4687 + resolve_conffiles(conf, pkg);
4689 + pkg->state_status = SS_UNPACKED;
4690 + old_state_flag = pkg->state_flag;
4691 + pkg->state_flag &= ~SF_PREFER;
4692 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4694 + if (old_pkg && !conf->force_reinstall) {
4695 + old_pkg->state_status = SS_NOT_INSTALLED;
4698 + time(&pkg->installed_time);
4700 + ipkg_message(conf, IPKG_INFO,
4701 + " cleanup temp files\n");
4702 + cleanup_temporary_files(conf, pkg);
4704 + ab_pkg = pkg->parent;
4706 + ab_pkg->state_status = pkg->state_status;
4708 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4711 + signal(SIGINT, old_handler);
4713 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4718 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4719 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4720 + UNWIND_CHECK_DATA_FILE_CLASHES:
4721 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4722 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4723 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4724 + UNWIND_PREINST_CONFIGURE:
4725 + preinst_configure_unwind(conf, pkg, old_pkg);
4726 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4727 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4728 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4729 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4730 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4731 + pkg_remove_installed_replacees_unwind(conf, replacees);
4733 + ipkg_message(conf, IPKG_INFO,
4734 + " cleanup temp files\n");
4735 + cleanup_temporary_files(conf, pkg);
4737 + ipkg_message(conf, IPKG_INFO,
4740 + signal(SIGINT, old_handler);
4742 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4748 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4750 + /* DPKG_INCOMPATIBILITY:
4751 + dpkg does some things here that we don't do yet. Do we care?
4753 + 1. If a version of the package is already installed, call
4754 + old-prerm upgrade new-version
4755 + 2. If the script runs but exits with a non-zero exit status
4756 + new-prerm failed-upgrade old-version
4757 + Error unwind, for both the above cases:
4758 + old-postinst abort-upgrade new-version
4763 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4765 + /* DPKG_INCOMPATIBILITY:
4766 + dpkg does some things here that we don't do yet. Do we care?
4767 + (See prerm_upgrade_old_package for details)
4772 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4774 + /* DPKG_INCOMPATIBILITY:
4775 + dpkg does some things here that we don't do yet. Do we care?
4776 + 2. If a 'conflicting' package is being removed at the same time:
4777 + 1. If any packages depended on that conflicting package and
4778 + --auto-deconfigure is specified, call, for each such package:
4779 + deconfigured's-prerm deconfigure \
4780 + in-favour package-being-installed version \
4781 + removing conflicting-package version
4783 + deconfigured's-postinst abort-deconfigure \
4784 + in-favour package-being-installed-but-failed version \
4785 + removing conflicting-package version
4787 + The deconfigured packages are marked as requiring
4788 + configuration, so that if --install is used they will be
4789 + configured again if possible.
4790 + 2. To prepare for removal of the conflicting package, call:
4791 + conflictor's-prerm remove in-favour package new-version
4793 + conflictor's-postinst abort-remove in-favour package new-version
4798 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4800 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4801 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4806 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4809 + char *preinst_args;
4812 + char *old_version = pkg_version_str_alloc(old_pkg);
4813 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4814 + free(old_version);
4815 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4816 + char *pkg_version = pkg_version_str_alloc(pkg);
4817 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4818 + free(pkg_version);
4820 + preinst_args = strdup("install");
4823 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4825 + ipkg_message(conf, IPKG_ERROR,
4826 + "Aborting installation of %s\n", pkg->name);
4830 + free(preinst_args);
4835 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4837 + /* DPKG_INCOMPATIBILITY:
4838 + dpkg does the following error unwind, should we?
4839 + pkg->postrm abort-upgrade old-version
4840 + OR pkg->postrm abort-install old-version
4841 + OR pkg->postrm abort-install
4846 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4849 + conffile_list_elt_t *iter;
4852 + if (conf->noaction) return 0;
4854 + /* Backup all modified conffiles */
4856 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4860 + cf_name = root_filename_alloc(conf, cf->name);
4862 + /* Don't worry if the conffile is just plain gone */
4863 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4864 + err = backup_make_backup(conf, cf_name);
4873 + /* Backup all conffiles that were not conffiles in old_pkg */
4874 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4877 + cf_name = root_filename_alloc(conf, cf->name);
4878 + /* Ignore if this was a conffile in old_pkg as well */
4879 + if (pkg_get_conffile(old_pkg, cf->name)) {
4883 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4884 + err = backup_make_backup(conf, cf_name);
4895 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4897 + conffile_list_elt_t *iter;
4900 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4901 + backup_remove(iter->data->name);
4905 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4906 + backup_remove(iter->data->name);
4913 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4915 + /* DPKG_INCOMPATIBILITY:
4916 + ipkg takes a slightly different approach than dpkg at this
4917 + point. dpkg installs each file in the new package while
4918 + creating a backup for any file that is replaced, (so that it
4919 + can unwind if necessary). To avoid complexity and redundant
4920 + storage, ipkg doesn't do any installation until later, (at the
4921 + point at which dpkg removes the backups.
4923 + But, we do have to check for data file clashes, since after
4924 + installing a package with a file clash, removing either of the
4925 + packages involved in the clash has the potential to break the
4928 + str_list_t *files_list;
4929 + str_list_elt_t *iter;
4933 + files_list = pkg_get_installed_files(pkg);
4934 + for (iter = files_list->head; iter; iter = iter->next) {
4935 + char *root_filename;
4936 + char *filename = iter->data;
4937 + root_filename = root_filename_alloc(conf, filename);
4938 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4941 + /* Pre-existing conffiles are OK */
4942 + /* @@@@ should have way to check that it is a conffile -Jamey */
4943 + if (backup_exists_for(root_filename)) {
4947 + /* Pre-existing files are OK if force-overwrite was asserted. */
4948 + if (conf->force_overwrite) {
4949 + /* but we need to change who owns this file */
4950 + file_hash_set_file_owner(conf, filename, pkg);
4954 + owner = file_hash_get_file_owner(conf, filename);
4956 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4957 + if (owner && old_pkg) {
4958 + if (strcmp(owner->name, old_pkg->name) == 0) {
4963 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4965 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4966 + if (pkg_replaces(pkg, owner)) {
4969 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4970 + then it's ok to overwrite. */
4971 + if (strcmp(owner->name,pkg->name)==0){
4972 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4977 + /* Pre-existing files are OK if they are obsolete */
4978 + obs = hash_table_get(&conf->obs_file_hash, filename);
4980 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
4984 + /* We have found a clash. */
4985 + ipkg_message(conf, IPKG_ERROR,
4986 + "Package %s wants to install file %s\n"
4987 + "\tBut that file is already provided by package ",
4988 + pkg->name, filename);
4990 + ipkg_message(conf, IPKG_ERROR,
4991 + "%s\n", owner->name);
4993 + ipkg_message(conf, IPKG_ERROR,
4994 + "<no package>\nPlease move this file out of the way and try again.\n");
4998 + free(root_filename);
5000 + pkg_free_installed_files(pkg);
5005 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5007 + /* Basically that's the worst hack I could do to be able to change ownership of
5008 + file list, but, being that we have no way to unwind the mods, due to structure
5009 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5010 + What we do here is change the ownership of file in hash if a replace ( or similar events
5012 + Only the action that are needed to change name should be considered.
5013 + @@@ To change after 1.0 release.
5015 + str_list_t *files_list;
5016 + str_list_elt_t *iter;
5020 + files_list = pkg_get_installed_files(pkg);
5021 + for (iter = files_list->head; iter; iter = iter->next) {
5022 + char *root_filename;
5023 + char *filename = iter->data;
5024 + root_filename = root_filename_alloc(conf, filename);
5025 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5028 + if (conf->force_overwrite) {
5029 + /* but we need to change who owns this file */
5030 + file_hash_set_file_owner(conf, filename, pkg);
5034 + owner = file_hash_get_file_owner(conf, filename);
5036 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5038 + if (pkg_replaces(pkg, owner)) {
5039 +/* It's now time to change the owner of that file.
5040 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5041 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5042 + file_hash_set_file_owner(conf, filename, pkg);
5048 + free(root_filename);
5050 + pkg_free_installed_files(pkg);
5055 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5057 + /* Nothing to do since check_data_file_clashes doesn't change state */
5061 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5063 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5064 + 1. If the package is being upgraded, call
5065 + old-postrm upgrade new-version
5066 + 2. If this fails, attempt:
5067 + new-postrm failed-upgrade old-version
5068 + Error unwind, for both cases:
5069 + old-preinst abort-upgrade new-version */
5073 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5075 + /* DPKG_INCOMPATIBILITY:
5076 + dpkg does some things here that we don't do yet. Do we care?
5077 + (See postrm_upgrade_old_pkg for details)
5082 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5085 + str_list_t *old_files;
5086 + str_list_elt_t *of;
5087 + str_list_t *new_files;
5088 + str_list_elt_t *nf;
5090 + if (old_pkg == NULL) {
5094 + old_files = pkg_get_installed_files(old_pkg);
5095 + new_files = pkg_get_installed_files(pkg);
5097 + for (of = old_files->head; of; of = of->next) {
5101 + for (nf = new_files->head; nf; nf = nf->next) {
5103 + if (strcmp(old, new) == 0) {
5104 + goto NOT_OBSOLETE;
5107 + if (file_is_dir(old)) {
5110 + owner = file_hash_get_file_owner(conf, old);
5111 + if (owner != old_pkg) {
5112 + /* in case obsolete file no longer belongs to old_pkg */
5116 + /* old file is obsolete */
5117 + ipkg_message(conf, IPKG_INFO,
5118 + " removing obsolete file %s\n", old);
5119 + if (!conf->noaction) {
5120 + err = unlink(old);
5122 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5131 + pkg_free_installed_files(old_pkg);
5132 + pkg_free_installed_files(pkg);
5137 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5141 + char *globpattern;
5145 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5148 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5149 + err = glob(globpattern, 0, NULL, &globbuf);
5150 + free(globpattern);
5154 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5155 + for (i = 0; i < globbuf.gl_pathc; i++) {
5156 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5157 + globbuf.gl_pathv[i], old_pkg->name);
5158 + if (!conf->noaction)
5159 + unlink(globbuf.gl_pathv[i]);
5161 + globfree(&globbuf);
5166 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5172 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5173 + sprintf_alloc(&prefix, "%s.", pkg->name);
5174 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5175 + pkg->dest->info_dir,
5181 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5183 + /* DPKG_INCOMPATIBILITY:
5184 + This is a fairly sophisticated dpkg operation. Shall we
5187 + /* Any packages all of whose files have been overwritten during the
5188 + installation, and which aren't required for dependencies, are
5189 + considered to have been removed. For each such package
5190 + 1. disappearer's-postrm disappear overwriter overwriter-version
5191 + 2. The package's maintainer scripts are removed
5192 + 3. It is noted in the status database as being in a sane state,
5193 + namely not installed (any conffiles it may have are ignored,
5194 + rather than being removed by dpkg). Note that disappearing
5195 + packages do not have their prerm called, because dpkg doesn't
5196 + know in advance that the package is going to vanish.
5201 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5205 + /* ipkg takes a slightly different approach to data file backups
5206 + than dpkg. Rather than removing backups at this point, we
5207 + actually do the data file installation now. See comments in
5208 + check_data_file_clashes() for more details. */
5210 + ipkg_message(conf, IPKG_INFO,
5211 + " extracting data files to %s\n", pkg->dest->root_dir);
5212 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5217 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5218 + so we can't save ourself from removing important packages
5219 + At this point we (should) have extracted the .control file, so it
5220 + would be a good idea to reload the data in it, and set the Essential
5221 + state in *pkg. From now on the Essential is back in status file and
5222 + we can protect again.
5223 + We should operate this way:
5224 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5225 + check for "Essential" in it
5226 + set the value in pkg->essential.
5227 + This new routine could be useful also for every other flag
5228 + Pigi: 16/03/2004 */
5229 + set_flags_from_control(conf, pkg) ;
5231 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5232 + err = pkg_write_filelist(conf, pkg);
5236 + /* XXX: FEATURE: ipkg should identify any files which existed
5237 + before installation and which were overwritten, (see
5238 + check_data_file_clashes()). What it must do is remove any such
5239 + files from the filelist of the old package which provided the
5240 + file. Otherwise, if the old package were removed at some point
5241 + it would break the new package. Removing the new package will
5242 + also break the old one, but this cannot be helped since the old
5243 + package's file has already been deleted. This is the importance
5244 + of check_data_file_clashes(), and only allowing ipkg to install
5245 + a clashing package with a user force. */
5250 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5252 + conffile_list_elt_t *iter;
5259 + if (conf->noaction) return 0;
5261 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5262 + char *root_filename;
5264 + root_filename = root_filename_alloc(conf, cf->name);
5266 + /* Might need to initialize the md5sum for each conffile */
5267 + if (cf->value == NULL) {
5268 + cf->value = file_md5sum_alloc(root_filename);
5271 + if (!file_exists(root_filename)) {
5272 + free(root_filename);
5276 + cf_backup = backup_filename_alloc(root_filename);
5279 + if (file_exists(cf_backup)) {
5280 + /* Let's compute md5 to test if files are changed */
5281 + md5sum = file_md5sum_alloc(cf_backup);
5282 + if (strcmp( cf->value,md5sum) != 0 ) {
5283 + if (conf->force_defaults
5284 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5285 + rename(cf_backup, root_filename);
5288 + unlink(cf_backup);
5293 + free(root_filename);
5299 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5302 + const char *short_file_name;
5304 + short_file_name = strrchr(file_name, '/');
5305 + if (short_file_name) {
5306 + short_file_name++;
5308 + short_file_name = file_name;
5312 + response = get_user_response(" Configuration file '%s'\n"
5313 + " ==> File on system created by you or by a script.\n"
5314 + " ==> File also in package provided by package maintainer.\n"
5315 + " What would you like to do about it ? Your options are:\n"
5316 + " Y or I : install the package maintainer's version\n"
5317 + " N or O : keep your currently-installed version\n"
5318 + " D : show the differences between the versions (if diff is installed)\n"
5319 + " The default action is to keep your current version.\n"
5320 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5321 + if (strcmp(response, "y") == 0
5322 + || strcmp(response, "i") == 0
5323 + || strcmp(response, "yes") == 0) {
5328 + if (strcmp(response, "d") == 0) {
5332 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5333 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5336 + printf(" [Press ENTER to continue]\n");
5337 + response = file_read_line_alloc(stdin);
5347 +/* XXX: CLEANUP: I'd like to move all of the code for
5348 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5349 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5350 + pkg_deinit for example). */
5351 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5354 + struct dirent *dirent;
5357 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5359 + ipkg_message(conf, IPKG_DEBUG,
5360 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5361 + __FUNCTION__, pkg->tmp_unpack_dir);
5365 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5366 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5369 + dirent = readdir(tmp_dir);
5370 + if (dirent == NULL) {
5373 + sprintf_alloc(&tmp_file, "%s/%s",
5374 + pkg->tmp_unpack_dir, dirent->d_name);
5375 + if (! file_is_dir(tmp_file)) {
5380 + closedir(tmp_dir);
5381 + rmdir(pkg->tmp_unpack_dir);
5382 + free(pkg->tmp_unpack_dir);
5383 + pkg->tmp_unpack_dir = NULL;
5387 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5388 + pkg->name, pkg->local_filename, conf->tmp_dir);
5389 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5390 + unlink(pkg->local_filename);
5391 + free(pkg->local_filename);
5392 + pkg->local_filename = NULL;
5398 +static char *backup_filename_alloc(const char *file_name)
5402 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5407 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5412 + backup = backup_filename_alloc(file_name);
5413 + err = file_copy(file_name, backup);
5415 + ipkg_message(conf, IPKG_ERROR,
5416 + "%s: Failed to copy %s to %s\n",
5417 + __FUNCTION__, file_name, backup);
5425 +static int backup_exists_for(const char *file_name)
5430 + backup = backup_filename_alloc(file_name);
5432 + ret = file_exists(backup);
5439 +static int backup_remove(const char *file_name)
5443 + backup = backup_filename_alloc(file_name);
5452 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5454 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5456 + /* first, remove the packages that need removing */
5457 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5458 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5459 + err = ipkg_remove_pkg(conf, pkg,0);
5460 + if (err) return err;
5465 +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)
5468 + /* now one more pass checking on the ones that need to be installed */
5469 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5470 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5471 + if (pkg->dest == NULL)
5472 + pkg->dest = conf->default_dest;
5474 + pkg->state_want = SW_INSTALL;
5476 + /* Abhaya: conflicts check */
5477 + err = check_conflicts_for(conf, pkg);
5478 + if (err) { return err; }
5483 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5486 + /* now one more pass checking on the ones that need to be installed */
5487 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5488 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5490 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5491 + pkg_vec_t *replacees = pkg_vec_alloc();
5492 + pkg_get_installed_replacees(conf, pkg, replacees);
5494 + /* XXX: BUG: we really should treat replacement more like an upgrade
5495 + * Instead, we're going to remove the replacees
5497 + err = pkg_remove_installed_replacees(conf, replacees);
5498 + if (err) return err;
5499 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5504 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5507 + /* now one more pass checking on the ones that need to be installed */
5508 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5509 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5510 + if (pkg->local_filename == NULL) {
5511 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5513 + ipkg_message(conf, IPKG_ERROR,
5514 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5519 + if (pkg->tmp_unpack_dir == NULL) {
5520 + err = unpack_pkg_control_files(conf, pkg);
5521 + if (err) return err;
5527 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5530 + /* now one more pass checking on the ones that need to be installed */
5531 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5532 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5533 + pkg_t *old_pkg = pkg->old_pkg;
5535 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5536 + if (err) return err;
5538 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5539 + if (err) return err;
5541 + err = preinst_configure(conf, pkg, old_pkg);
5542 + if (err) return err;
5544 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5545 + if (err) return err;
5547 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5548 + if (err) return err;
5553 +int ipkg_process_actions_install(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;
5562 + old_pkg->state_want = SW_DEINSTALL;
5564 + if (old_pkg->state_flag & SF_NOPRUNE) {
5565 + ipkg_message(conf, IPKG_INFO,
5566 + " not removing obsolesced files because package marked noprune\n");
5568 + ipkg_message(conf, IPKG_INFO,
5569 + " removing obsolesced files\n");
5570 + remove_obsolesced_files(conf, pkg, old_pkg);
5574 + ipkg_message(conf, IPKG_INFO,
5575 + " installing maintainer scripts\n");
5576 + install_maintainer_scripts(conf, pkg, old_pkg);
5578 + /* the following just returns 0 */
5579 + remove_disappeared(conf, pkg);
5581 + ipkg_message(conf, IPKG_INFO,
5582 + " installing data files\n");
5583 + install_data_files(conf, pkg);
5585 + ipkg_message(conf, IPKG_INFO,
5586 + " resolving conf files\n");
5587 + resolve_conffiles(conf, pkg);
5589 + pkg->state_status = SS_UNPACKED;
5592 + old_pkg->state_status = SS_NOT_INSTALLED;
5595 + time(&pkg->installed_time);
5597 + ipkg_message(conf, IPKG_INFO,
5598 + " cleanup temp files\n");
5599 + cleanup_temporary_files(conf, pkg);
5602 + pkg->parent->state_status = pkg->state_status;
5607 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5610 + /* now one more pass checking on the ones that need to be installed */
5611 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5612 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5613 + pkg_t *old_pkg = pkg->old_pkg;
5616 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5617 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5618 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5619 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5620 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5621 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5622 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5623 + preinst_configure_unwind(conf, pkg, old_pkg);
5624 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5625 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5626 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5627 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5629 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5630 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5638 + * Perform all the actions.
5640 + * pkgs_to_remove are packages marked for removal.
5641 + * pkgs_superseded are the old packages being replaced by upgrades.
5643 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5645 +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)
5650 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5651 + if (err) return err;
5653 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5654 + if (err) return err;
5656 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5657 + if (err) goto UNWIND;
5659 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5660 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5661 + if (err) goto UNWIND;
5664 + * Now that we have the packages unpacked, we can look for data
5665 + * file clashes. First, we mark the files from the superseded
5666 + * packages as obsolete. Then we scan the files in
5667 + * pkgs_to_install, and only complain about clashes with
5668 + * non-obsolete files.
5671 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5672 + if (err) goto UNWIND;
5674 + /* this was before checking data file clashes */
5675 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5676 + if (err) goto UNWIND;
5678 + /* point of no return: no unwinding after this */
5679 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5680 + if (err) return err;
5682 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5686 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5688 + ipkg_message(conf, IPKG_INFO,
5689 + " cleanup temp files\n");
5690 + cleanup_temporary_files(conf, pkg);
5692 + ipkg_message(conf, IPKG_INFO,
5698 diff -urN busybox.old/archival/libipkg/ipkg_install.h busybox.dev/archival/libipkg/ipkg_install.h
5699 --- busybox.old/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5700 +++ busybox.dev/archival/libipkg/ipkg_install.h 2007-01-22 13:41:03.000000000 +0100
5702 +/* ipkg_install.h - the itsy package management system
5706 + Copyright (C) 2001 University of Southern California
5708 + This program is free software; you can redistribute it and/or
5709 + modify it under the terms of the GNU General Public License as
5710 + published by the Free Software Foundation; either version 2, or (at
5711 + your option) any later version.
5713 + This program is distributed in the hope that it will be useful, but
5714 + WITHOUT ANY WARRANTY; without even the implied warranty of
5715 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5716 + General Public License for more details.
5719 +#ifndef IPKG_INSTALL_H
5720 +#define IPKG_INSTALL_H
5723 +#include "ipkg_conf.h"
5725 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5726 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5727 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5728 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5729 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5731 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5733 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5734 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5737 diff -urN busybox.old/archival/libipkg/ipkg_message.c busybox.dev/archival/libipkg/ipkg_message.c
5738 --- busybox.old/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5739 +++ busybox.dev/archival/libipkg/ipkg_message.c 2007-01-22 13:41:03.000000000 +0100
5741 +/* ipkg_message.c - the itsy package management system
5743 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5745 + This program is free software; you can redistribute it and/or
5746 + modify it under the terms of the GNU General Public License as
5747 + published by the Free Software Foundation; either version 2, or (at
5748 + your option) any later version.
5750 + This program is distributed in the hope that it will be useful, but
5751 + WITHOUT ANY WARRANTY; without even the implied warranty of
5752 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5753 + General Public License for more details.
5758 +#include "ipkg_conf.h"
5759 +#include "ipkg_message.h"
5764 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5768 + if (conf && (conf->verbosity < level))
5775 + va_start (ap, fmt);
5776 + vprintf (fmt, ap);
5783 +#include "libipkg.h"
5785 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5788 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5793 + if (ipkg_cb_message)
5795 + va_start (ap, fmt);
5796 + vsnprintf (ts,256,fmt, ap);
5798 + ipkg_cb_message(conf,level,ts);
5802 diff -urN busybox.old/archival/libipkg/ipkg_message.h busybox.dev/archival/libipkg/ipkg_message.h
5803 --- busybox.old/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5804 +++ busybox.dev/archival/libipkg/ipkg_message.h 2007-01-22 13:41:03.000000000 +0100
5806 +/* ipkg_message.h - the itsy package management system
5808 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5810 + This program is free software; you can redistribute it and/or
5811 + modify it under the terms of the GNU General Public License as
5812 + published by the Free Software Foundation; either version 2, or (at
5813 + your option) any later version.
5815 + This program is distributed in the hope that it will be useful, but
5816 + WITHOUT ANY WARRANTY; without even the implied warranty of
5817 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5818 + General Public License for more details.
5821 +#ifndef _IPKG_MESSAGE_H_
5822 +#define _IPKG_MESSAGE_H_
5825 +#include "ipkg_conf.h"
5828 + IPKG_ERROR, /* error conditions */
5829 + IPKG_NOTICE, /* normal but significant condition */
5830 + IPKG_INFO, /* informational message */
5831 + IPKG_DEBUG, /* debug level message */
5832 + IPKG_DEBUG2, /* more debug level message */
5835 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5837 +#endif /* _IPKG_MESSAGE_H_ */
5838 diff -urN busybox.old/archival/libipkg/ipkg_remove.c busybox.dev/archival/libipkg/ipkg_remove.c
5839 --- busybox.old/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5840 +++ busybox.dev/archival/libipkg/ipkg_remove.c 2007-01-22 13:41:03.000000000 +0100
5842 +/* ipkg_remove.c - the itsy package management system
5846 + Copyright (C) 2001 University of Southern California
5848 + This program is free software; you can redistribute it and/or
5849 + modify it under the terms of the GNU General Public License as
5850 + published by the Free Software Foundation; either version 2, or (at
5851 + your option) any later version.
5853 + This program is distributed in the hope that it will be useful, but
5854 + WITHOUT ANY WARRANTY; without even the implied warranty of
5855 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5856 + General Public License for more details.
5860 +#include "ipkg_message.h"
5864 +#include "ipkg_remove.h"
5866 +#include "file_util.h"
5867 +#include "sprintf_alloc.h"
5868 +#include "str_util.h"
5870 +#include "ipkg_cmd.h"
5873 + * Returns number of the number of packages depending on the packages provided by this package.
5874 + * Every package implicitly provides itself.
5876 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5878 + int nprovides = pkg->provides_count;
5879 + abstract_pkg_t **provides = pkg->provides;
5880 + int n_installed_dependents = 0;
5882 + for (i = 0; i <= nprovides; i++) {
5883 + abstract_pkg_t *providee = provides[i];
5884 + abstract_pkg_t **dependers = providee->depended_upon_by;
5885 + abstract_pkg_t *dep_ab_pkg;
5886 + if (dependers == NULL)
5888 + while ((dep_ab_pkg = *dependers++) != NULL) {
5889 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5890 + n_installed_dependents++;
5895 + /* if caller requested the set of installed dependents */
5896 + if (pdependents) {
5898 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5900 + if ( dependents == NULL ){
5901 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5905 + *pdependents = dependents;
5906 + for (i = 0; i <= nprovides; i++) {
5907 + abstract_pkg_t *providee = provides[i];
5908 + abstract_pkg_t **dependers = providee->depended_upon_by;
5909 + abstract_pkg_t *dep_ab_pkg;
5910 + if (dependers == NULL)
5912 + while ((dep_ab_pkg = *dependers++) != NULL) {
5913 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5914 + dependents[p++] = dep_ab_pkg;
5915 + dep_ab_pkg->state_flag |= SF_MARKED;
5919 + dependents[p] = NULL;
5920 + /* now clear the marks */
5921 + for (i = 0; i < p; i++) {
5922 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5923 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5926 + return n_installed_dependents;
5929 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5934 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5935 + abstract_pkg_t * ab_pkg;
5937 + if((ab_pkg = pkg->parent) == NULL){
5938 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5939 + __FUNCTION__, pkg->name);
5943 + if (dependents == NULL)
5946 + // here i am using the dependencies_checked
5947 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5948 + return 0; // has already been encountered in the process
5949 + // of marking packages for removal - Karthik
5950 + ab_pkg->dependencies_checked = 2;
5954 + while (dependents [i] != NULL) {
5955 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5957 + if (dep_ab_pkg->dependencies_checked == 2){
5961 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5962 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5963 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5964 + if (dep_pkg->state_status == SS_INSTALLED) {
5965 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5971 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5972 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5979 + for (i = 0; i < dependent_pkgs->len; i++) {
5980 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
5987 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5989 + abstract_pkg_t *dep_ab_pkg;
5990 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5991 + while ((dep_ab_pkg = *dependents++) != NULL) {
5992 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5993 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5995 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5996 + ipkg_message(conf, IPKG_ERROR, "");
5997 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5998 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5999 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6000 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6001 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6005 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6007 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6008 + thus I wan't check for essential, as I'm upgrading.
6009 + I hope it won't break anything :)
6012 + abstract_pkg_t *parent_pkg = NULL;
6014 + if (pkg->essential && !message) {
6015 + if (conf->force_removal_of_essential_packages) {
6016 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6017 + "\tIf your system breaks, you get to keep both pieces\n",
6020 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6021 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6022 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6023 + "\tits will with the option: -force-removal-of-essential-packages\n",
6025 + return IPKG_PKG_IS_ESSENTIAL;
6029 + if ((parent_pkg = pkg->parent) == NULL)
6032 + /* only attempt to remove dependent installed packages if
6033 + * force_depends is not specified or the package is being
6036 + if (!conf->force_depends
6037 + && !(pkg->state_flag & SF_REPLACE)) {
6038 + abstract_pkg_t **dependents;
6039 + int has_installed_dependents =
6040 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6042 + if (has_installed_dependents) {
6044 + * if this package is depended up by others, then either we should
6045 + * not remove it or we should remove it and all of its dependents
6048 + if (!conf->force_removal_of_dependent_packages
6049 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6050 + return IPKG_PKG_HAS_DEPENDENTS;
6053 + /* remove packages depending on this package - Karthik */
6054 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6056 + if (err) return err;
6060 + if ( message==0 ){
6061 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6064 + pkg->state_flag |= SF_FILELIST_CHANGED;
6066 + pkg->state_want = SW_DEINSTALL;
6067 + ipkg_state_changed++;
6069 + pkg_run_script(conf, pkg, "prerm", "remove");
6071 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6072 + maintains an empty filelist rather than deleting it. That seems
6073 + like a big pain, and I don't see that that should make a big
6074 + difference, but for anyone who wants tighter compatibility,
6075 + feel free to fix this. */
6076 + remove_data_files_and_list(conf, pkg);
6078 + pkg_run_script(conf, pkg, "postrm", "remove");
6080 + remove_maintainer_scripts_except_postrm(conf, pkg);
6082 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6083 + * space, it doesn't make sense to leave extra configurations, files,
6084 + * and maintainer scripts left around. So, we make remove like purge,
6085 + * and take out all the crap :) */
6087 + remove_postrm(conf, pkg);
6088 + pkg->state_status = SS_NOT_INSTALLED;
6091 + parent_pkg->state_status = SS_NOT_INSTALLED;
6096 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6098 + ipkg_remove_pkg(conf, pkg,0);
6102 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6104 + str_list_t installed_dirs;
6105 + str_list_t *installed_files;
6106 + str_list_elt_t *iter;
6108 + conffile_t *conffile;
6109 + int removed_a_dir;
6112 + str_list_init(&installed_dirs);
6113 + installed_files = pkg_get_installed_files(pkg);
6115 + for (iter = installed_files->head; iter; iter = iter->next) {
6116 + file_name = iter->data;
6118 + if (file_is_dir(file_name)) {
6119 + str_list_append(&installed_dirs, strdup(file_name));
6123 + conffile = pkg_get_conffile(pkg, file_name);
6125 + /* XXX: QUESTION: Is this right? I figure we only need to
6126 + save the conffile if it has been modified. Is that what
6127 + dpkg does? Or does dpkg preserve all conffiles? If so,
6128 + this seems like a better thing to do to conserve
6130 + if (conffile_has_been_modified(conf, conffile)) {
6131 + printf(" not deleting modified conffile %s\n", file_name);
6137 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6138 + if (!conf->noaction)
6139 + unlink(file_name);
6142 + if (!conf->noaction) {
6144 + removed_a_dir = 0;
6145 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6146 + file_name = iter->data;
6148 + if (rmdir(file_name) == 0) {
6149 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6150 + removed_a_dir = 1;
6151 + str_list_remove(&installed_dirs, &iter);
6154 + } while (removed_a_dir);
6157 + pkg_free_installed_files(pkg);
6158 + /* We have to remove the file list now, so that
6159 + find_pkg_owning_file does not always just report this package */
6160 + pkg_remove_installed_files_list(conf, pkg);
6162 + /* Don't print warning for dirs that are provided by other packages */
6163 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6164 + file_name = iter->data;
6166 + owner = file_hash_get_file_owner(conf, file_name);
6169 + iter->data = NULL;
6170 + str_list_remove(&installed_dirs, &iter);
6175 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6177 + iter->data = NULL;
6179 + str_list_deinit(&installed_dirs);
6184 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6187 + char *globpattern;
6190 + if (conf->noaction) return 0;
6192 + sprintf_alloc(&globpattern, "%s/%s.*",
6193 + pkg->dest->info_dir, pkg->name);
6194 + err = glob(globpattern, 0, NULL, &globbuf);
6195 + free(globpattern);
6200 + for (i = 0; i < globbuf.gl_pathc; i++) {
6201 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6204 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6205 + unlink(globbuf.gl_pathv[i]);
6207 + globfree(&globbuf);
6212 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6214 + char *postrm_file_name;
6216 + if (conf->noaction) return 0;
6218 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6219 + pkg->dest->info_dir, pkg->name);
6220 + unlink(postrm_file_name);
6221 + free(postrm_file_name);
6225 diff -urN busybox.old/archival/libipkg/ipkg_remove.h busybox.dev/archival/libipkg/ipkg_remove.h
6226 --- busybox.old/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6227 +++ busybox.dev/archival/libipkg/ipkg_remove.h 2007-01-22 13:41:03.000000000 +0100
6229 +/* ipkg_remove.h - the itsy package management system
6233 + Copyright (C) 2001 University of Southern California
6235 + This program is free software; you can redistribute it and/or
6236 + modify it under the terms of the GNU General Public License as
6237 + published by the Free Software Foundation; either version 2, or (at
6238 + your option) any later version.
6240 + This program is distributed in the hope that it will be useful, but
6241 + WITHOUT ANY WARRANTY; without even the implied warranty of
6242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6243 + General Public License for more details.
6246 +#ifndef IPKG_REMOVE_H
6247 +#define IPKG_REMOVE_H
6250 +#include "ipkg_conf.h"
6252 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6253 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6254 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6255 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6256 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6257 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6258 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6262 diff -urN busybox.old/archival/libipkg/ipkg_upgrade.c busybox.dev/archival/libipkg/ipkg_upgrade.c
6263 --- busybox.old/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6264 +++ busybox.dev/archival/libipkg/ipkg_upgrade.c 2007-01-22 13:41:03.000000000 +0100
6266 +/* ipkg_upgrade.c - the itsy package management system
6269 + Copyright (C) 2001 University of Southern California
6271 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6273 + This program is free software; you can redistribute it and/or
6274 + modify it under the terms of the GNU General Public License as
6275 + published by the Free Software Foundation; either version 2, or (at
6276 + your option) any later version.
6278 + This program is distributed in the hope that it will be useful, but
6279 + WITHOUT ANY WARRANTY; without even the implied warranty of
6280 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6281 + General Public License for more details.
6285 +#include "ipkg_install.h"
6286 +#include "ipkg_message.h"
6288 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6292 + char *old_version, *new_version;
6294 + if (old->state_flag & SF_HOLD) {
6295 + ipkg_message(conf, IPKG_NOTICE,
6296 + "Not upgrading package %s which is marked "
6297 + "hold (flags=%#x)\n", old->name, old->state_flag);
6301 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6302 + if (new == NULL) {
6303 + old_version = pkg_version_str_alloc(old);
6304 + ipkg_message(conf, IPKG_NOTICE,
6305 + "Assuming locally installed package %s (%s) "
6306 + "is up to date.\n", old->name, old_version);
6307 + free(old_version);
6311 + old_version = pkg_version_str_alloc(old);
6312 + new_version = pkg_version_str_alloc(new);
6314 + cmp = pkg_compare_versions(old, new);
6315 + ipkg_message(conf, IPKG_DEBUG,
6316 + "comparing visible versions of pkg %s:"
6317 + "\n\t%s is installed "
6318 + "\n\t%s is available "
6319 + "\n\t%d was comparison result\n",
6320 + old->name, old_version, new_version, cmp);
6322 + ipkg_message(conf, IPKG_INFO,
6323 + "Package %s (%s) installed in %s is up to date.\n",
6324 + old->name, old_version, old->dest->name);
6325 + free(old_version);
6326 + free(new_version);
6328 + } else if (cmp > 0) {
6329 + ipkg_message(conf, IPKG_NOTICE,
6330 + "Not downgrading package %s on %s from %s to %s.\n",
6331 + old->name, old->dest->name, old_version, new_version);
6332 + free(old_version);
6333 + free(new_version);
6335 + } else if (cmp < 0) {
6336 + new->dest = old->dest;
6337 + old->state_want = SW_DEINSTALL;
6340 + new->state_flag |= SF_USER;
6341 + return ipkg_install_pkg(conf, new,1);
6343 diff -urN busybox.old/archival/libipkg/ipkg_upgrade.h busybox.dev/archival/libipkg/ipkg_upgrade.h
6344 --- busybox.old/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6345 +++ busybox.dev/archival/libipkg/ipkg_upgrade.h 2007-01-22 13:41:03.000000000 +0100
6347 +/* ipkg_upgrade.c - the itsy package management system
6349 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6351 + This program is free software; you can redistribute it and/or
6352 + modify it under the terms of the GNU General Public License as
6353 + published by the Free Software Foundation; either version 2, or (at
6354 + your option) any later version.
6356 + This program is distributed in the hope that it will be useful, but
6357 + WITHOUT ANY WARRANTY; without even the implied warranty of
6358 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6359 + General Public License for more details.
6364 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6365 diff -urN busybox.old/archival/libipkg/ipkg_utils.c busybox.dev/archival/libipkg/ipkg_utils.c
6366 --- busybox.old/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6367 +++ busybox.dev/archival/libipkg/ipkg_utils.c 2007-01-22 13:41:03.000000000 +0100
6369 +/* ipkg_utils.c - the itsy package management system
6373 + Copyright (C) 2002 Compaq Computer Corporation
6375 + This program is free software; you can redistribute it and/or
6376 + modify it under the terms of the GNU General Public License as
6377 + published by the Free Software Foundation; either version 2, or (at
6378 + your option) any later version.
6380 + This program is distributed in the hope that it will be useful, but
6381 + WITHOUT ANY WARRANTY; without even the implied warranty of
6382 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6383 + General Public License for more details.
6389 +#include <sys/vfs.h>
6391 +#include "ipkg_utils.h"
6393 +#include "pkg_hash.h"
6395 +struct errlist* error_list;
6397 +int get_available_blocks(char * filesystem)
6399 + struct statfs sfs;
6401 + if(statfs(filesystem, &sfs)){
6402 + fprintf(stderr, "bad statfs\n");
6405 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6406 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6409 +char **read_raw_pkgs_from_file(const char *file_name)
6414 + if(!(fp = fopen(file_name, "r"))){
6415 + fprintf(stderr, "can't get %s open for read\n", file_name);
6419 + ret = read_raw_pkgs_from_stream(fp);
6426 +char **read_raw_pkgs_from_stream(FILE *fp)
6428 + char **raw = NULL, *buf, *scout;
6430 + size_t size = 512;
6432 + buf = malloc (size);
6434 + while (fgets(buf, size, fp)) {
6435 + while (strlen (buf) == (size - 1)
6436 + && buf[size-2] != '\n') {
6437 + size_t o = size - 1;
6439 + buf = realloc (buf, size);
6440 + if (fgets (buf + o, size - o, fp) == NULL)
6445 + raw = realloc(raw, (count + 50) * sizeof(char *));
6447 + if((scout = strchr(buf, '\n')))
6450 + raw[count++] = strdup(buf);
6453 + raw = realloc(raw, (count + 1) * sizeof(char *));
6454 + raw[count] = NULL;
6461 +/* something to remove whitespace, a hash pooper */
6462 +char *trim_alloc(char *line)
6465 + char *dest, *src, *end;
6467 + new = malloc(strlen(line) + 1);
6468 + if ( new == NULL ){
6469 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6472 + dest = new, src = line, end = line + (strlen(line) - 1);
6474 + /* remove it from the front */
6479 + /* and now from the back */
6480 + while((end > src) &&
6486 + /* this does from the first space
6487 + * blasting away any versions stuff in depends
6498 +int line_is_blank(const char *line)
6502 + for (s = line; *s; s++) {
6509 +void push_error_list(struct errlist ** errors, char * msg){
6510 + struct errlist *err_lst_tmp;
6513 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6514 + err_lst_tmp->errmsg=strdup(msg) ;
6515 + err_lst_tmp->next = *errors;
6516 + *errors = err_lst_tmp;
6520 +void reverse_error_list(struct errlist **errors){
6521 + struct errlist *result=NULL;
6522 + struct errlist *current= *errors;
6523 + struct errlist *next;
6525 + while ( current != NULL ) {
6526 + next = current->next;
6527 + current->next=result;
6536 +void free_error_list(struct errlist **errors){
6537 + struct errlist *current = *errors;
6539 + while (current != NULL) {
6540 + free(current->errmsg);
6541 + current = (*errors)->next;
6543 + *errors = current;
6550 diff -urN busybox.old/archival/libipkg/ipkg_utils.h busybox.dev/archival/libipkg/ipkg_utils.h
6551 --- busybox.old/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6552 +++ busybox.dev/archival/libipkg/ipkg_utils.h 2007-01-22 13:41:03.000000000 +0100
6554 +/* ipkg_utils.h - the itsy package management system
6558 + Copyright (C) 2002 Compaq Computer Corporation
6560 + This program is free software; you can redistribute it and/or
6561 + modify it under the terms of the GNU General Public License as
6562 + published by the Free Software Foundation; either version 2, or (at
6563 + your option) any later version.
6565 + This program is distributed in the hope that it will be useful, but
6566 + WITHOUT ANY WARRANTY; without even the implied warranty of
6567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6568 + General Public License for more details.
6571 +#ifndef IPKG_UTILS_H
6572 +#define IPKG_UTILS_H
6576 +int get_available_blocks(char * filesystem);
6577 +char **read_raw_pkgs_from_file(const char *file_name);
6578 +char **read_raw_pkgs_from_stream(FILE *fp);
6579 +char *trim_alloc(char * line);
6580 +int line_is_blank(const char *line);
6583 diff -urN busybox.old/archival/libipkg/Kbuild busybox.dev/archival/libipkg/Kbuild
6584 --- busybox.old/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
6585 +++ busybox.dev/archival/libipkg/Kbuild 2007-01-22 14:01:06.000000000 +0100
6587 +# Makefile for busybox
6589 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6590 +# Copyright (C) 2006 OpenWrt.org
6592 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6594 +LIBIPKG_CORE_OBJS:= \
6599 +LIBIPKG_CMD_OBJS:= \
6601 + ipkg_configure.o \
6607 +LIBIPKG_DB_OBJS:= \
6618 +LIBIPKG_LIST_OBJS:= \
6630 +LIBIPKG_UTIL_OBJS:= \
6637 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6638 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6639 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6640 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6641 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6643 +ifeq ($(strip $(IPKG_ARCH)),)
6644 +IPKG_ARCH:=$(TARGET_ARCH)
6646 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6647 diff -urN busybox.old/archival/libipkg/libipkg.c busybox.dev/archival/libipkg/libipkg.c
6648 --- busybox.old/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6649 +++ busybox.dev/archival/libipkg/libipkg.c 2007-01-22 13:41:06.000000000 +0100
6651 +/* ipkglib.c - the itsy package management system
6655 + Copyright (C) 2003 kernel concepts
6657 + This program is free software; you can redistribute it and/or
6658 + modify it under the terms of the GNU General Public License as
6659 + published by the Free Software Foundation; either version 2, or (at
6660 + your option) any later version.
6662 + This program is distributed in the hope that it will be useful, but
6663 + WITHOUT ANY WARRANTY; without even the implied warranty of
6664 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6665 + General Public License for more details.
6671 +#include "ipkg_includes.h"
6672 +#include "libipkg.h"
6675 +#include "ipkg_conf.h"
6676 +#include "ipkg_cmd.h"
6677 +#include "file_util.h"
6681 +ipkg_message_callback ipkg_cb_message = NULL;
6682 +ipkg_response_callback ipkg_cb_response = NULL;
6683 +ipkg_status_callback ipkg_cb_status = NULL;
6684 +ipkg_list_callback ipkg_cb_list = NULL;
6688 +ipkg_init (ipkg_message_callback mcall,
6689 + ipkg_response_callback rcall,
6692 + ipkg_cb_message = mcall;
6693 + ipkg_cb_response = rcall;
6702 +ipkg_deinit (args_t * args)
6704 + args_deinit (args);
6705 + ipkg_cb_message = NULL;
6706 + ipkg_cb_response = NULL;
6708 + /* place other cleanup stuff here */
6715 +ipkg_packages_list(args_t *args,
6716 + const char *packages,
6717 + ipkg_list_callback cblist,
6721 + ipkg_conf_t ipkg_conf;
6724 + err = ipkg_conf_init (&ipkg_conf, args);
6730 + ipkg_cb_list = cblist;
6731 + /* we need to do this because of static declarations,
6732 + * maybe a good idea to change */
6733 + cmd = ipkg_cmd_find ("list");
6735 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6737 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6738 + ipkg_cb_list = NULL;
6739 + ipkg_conf_deinit (&ipkg_conf);
6745 +ipkg_packages_status(args_t *args,
6746 + const char *packages,
6747 + ipkg_status_callback cbstatus,
6751 + ipkg_conf_t ipkg_conf;
6754 + err = ipkg_conf_init (&ipkg_conf, args);
6760 + ipkg_cb_status = cbstatus;
6762 + /* we need to do this because of static declarations,
6763 + * maybe a good idea to change */
6764 + cmd = ipkg_cmd_find ("status");
6766 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6768 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6770 + ipkg_cb_status = NULL;
6771 + ipkg_conf_deinit (&ipkg_conf);
6777 +ipkg_packages_info(args_t *args,
6778 + const char *packages,
6779 + ipkg_status_callback cbstatus,
6783 + ipkg_conf_t ipkg_conf;
6786 + err = ipkg_conf_init (&ipkg_conf, args);
6792 + ipkg_cb_status = cbstatus;
6794 + /* we need to do this because of static declarations,
6795 + * maybe a good idea to change */
6796 + cmd = ipkg_cmd_find ("info");
6798 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6800 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6802 + ipkg_cb_status = NULL;
6803 + ipkg_conf_deinit (&ipkg_conf);
6809 +ipkg_packages_install (args_t * args, const char *name)
6812 + ipkg_conf_t ipkg_conf;
6815 + /* this error should be handled in application */
6816 + if (!name || !strlen (name))
6819 + err = ipkg_conf_init (&ipkg_conf, args);
6825 + /* we need to do this because of static declarations,
6826 + * maybe a good idea to change */
6827 + cmd = ipkg_cmd_find ("install");
6828 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6830 + ipkg_conf_deinit(&ipkg_conf);
6836 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6839 + ipkg_conf_t ipkg_conf;
6842 + /* this error should be handled in application */
6843 + if (!name || !strlen (name))
6846 + err = ipkg_conf_init (&ipkg_conf, args);
6852 + /* we need to do this because of static declarations,
6853 + * maybe a good idea to change */
6855 + cmd = ipkg_cmd_find ("purge");
6857 + cmd = ipkg_cmd_find ("remove");
6859 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6861 + ipkg_conf_deinit(&ipkg_conf);
6867 +ipkg_lists_update(args_t *args)
6870 + ipkg_conf_t ipkg_conf;
6873 + err = ipkg_conf_init (&ipkg_conf, args);
6879 + /* we need to do this because of static declarations,
6880 + * maybe a good idea to change */
6881 + cmd = ipkg_cmd_find ("update");
6883 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6885 + ipkg_conf_deinit(&ipkg_conf);
6891 +ipkg_packages_upgrade(args_t *args)
6894 + ipkg_conf_t ipkg_conf;
6897 + err = ipkg_conf_init (&ipkg_conf, args);
6903 + /* we need to do this because of static declarations,
6904 + * maybe a good idea to change */
6905 + cmd = ipkg_cmd_find ("upgrade");
6907 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6909 + ipkg_conf_deinit(&ipkg_conf);
6915 +ipkg_packages_download (args_t * args, const char *name)
6918 + ipkg_conf_t ipkg_conf;
6921 + /* this error should be handled in application */
6922 + if (!name || !strlen (name))
6925 + err = ipkg_conf_init (&ipkg_conf, args);
6931 + /* we need to do this because of static declarations,
6932 + * maybe a good idea to change */
6933 + cmd = ipkg_cmd_find ("download");
6934 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6936 + ipkg_conf_deinit(&ipkg_conf);
6942 +ipkg_package_files(args_t *args,
6944 + ipkg_list_callback cblist,
6948 + ipkg_conf_t ipkg_conf;
6951 + /* this error should be handled in application */
6952 + if (!name || !strlen (name))
6955 + err = ipkg_conf_init (&ipkg_conf, args);
6961 + ipkg_cb_list = cblist;
6963 + /* we need to do this because of static declarations,
6964 + * maybe a good idea to change */
6965 + cmd = ipkg_cmd_find ("files");
6967 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6969 + ipkg_cb_list = NULL;
6970 + ipkg_conf_deinit(&ipkg_conf);
6976 +ipkg_file_search(args_t *args,
6978 + ipkg_list_callback cblist,
6982 + ipkg_conf_t ipkg_conf;
6985 + /* this error should be handled in application */
6986 + if (!file || !strlen (file))
6989 + err = ipkg_conf_init (&ipkg_conf, args);
6995 + ipkg_cb_list = cblist;
6997 + /* we need to do this because of static declarations,
6998 + * maybe a good idea to change */
6999 + cmd = ipkg_cmd_find ("search");
7000 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
7002 + ipkg_cb_list = NULL;
7003 + ipkg_conf_deinit(&ipkg_conf);
7009 +ipkg_file_what(args_t *args, const char *file, const char* command)
7012 + ipkg_conf_t ipkg_conf;
7015 + /* this error should be handled in application */
7016 + if (!file || !strlen (file))
7019 + err = ipkg_conf_init (&ipkg_conf, args);
7025 + /* we need to do this because of static declarations,
7026 + * maybe a good idea to change */
7027 + cmd = ipkg_cmd_find (command);
7028 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7030 + ipkg_conf_deinit(&ipkg_conf);
7034 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7035 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7036 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7037 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7038 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7041 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7044 + if (conf && (conf->verbosity < level)) {
7048 + if ( level == IPKG_ERROR ){
7049 + push_error_list(&error_list, msg);
7058 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7059 + pkg_state_status_t status, void *userdata)
7062 + printf("%s - %s - %s\n", name, version, desc);
7064 + printf("%s - %s\n", name, version);
7068 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7069 + pkg_state_status_t status, void *userdata)
7072 + printf("%s\n", desc);
7076 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7079 + printf("%s\n", desc);
7083 +char* default_ipkg_response_callback(char *question)
7085 + char *response = NULL;
7089 + response = (char *)file_read_line_alloc(stdin);
7090 + } while (response == NULL);
7094 +/* This is used for backward compatibility */
7096 +ipkg_op (int argc, char *argv[])
7098 + int err, opt_index;
7102 + ipkg_conf_t ipkg_conf;
7104 + args_init (&args);
7106 + opt_index = args_parse (&args, argc, argv);
7107 + if (opt_index == argc || opt_index < 0)
7109 + args_usage ("ipkg must have one sub-command argument");
7112 + cmd_name = argv[opt_index++];
7113 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7114 + read anything from there.
7116 + if ( !strcmp(cmd_name,"print-architecture") ||
7117 + !strcmp(cmd_name,"print_architecture") ||
7118 + !strcmp(cmd_name,"print-installation-architecture") ||
7119 + !strcmp(cmd_name,"print_installation_architecture") )
7120 + args.nocheckfordirorfile = 1;
7122 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7123 + read anything from there.
7125 + if ( !strcmp(cmd_name,"flag") ||
7126 + !strcmp(cmd_name,"configure") ||
7127 + !strcmp(cmd_name,"remove") ||
7128 + !strcmp(cmd_name,"files") ||
7129 + !strcmp(cmd_name,"search") ||
7130 + !strcmp(cmd_name,"compare_versions") ||
7131 + !strcmp(cmd_name,"compare-versions") ||
7132 + !strcmp(cmd_name,"list_installed") ||
7133 + !strcmp(cmd_name,"list-installed") ||
7134 + !strcmp(cmd_name,"status") )
7135 + args.noreadfeedsfile = 1;
7138 + err = ipkg_conf_init (&ipkg_conf, &args);
7144 + args_deinit (&args);
7146 + ipkg_cb_message = default_ipkg_message_callback;
7147 + ipkg_cb_response = default_ipkg_response_callback;
7148 + ipkg_cb_status = default_ipkg_status_callback;
7149 + if ( strcmp(cmd_name, "files")==0)
7150 + ipkg_cb_list = default_ipkg_files_callback;
7152 + ipkg_cb_list = default_ipkg_list_callback;
7154 + cmd = ipkg_cmd_find (cmd_name);
7157 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7159 + args_usage (NULL);
7162 + if (cmd->requires_args && opt_index == argc)
7165 + "%s: the ``%s'' command requires at least one argument\n",
7166 + __FUNCTION__, cmd_name);
7167 + args_usage (NULL);
7170 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7172 + ipkg_conf_deinit (&ipkg_conf);
7177 +#endif /* IPKG_LIB */
7178 diff -urN busybox.old/archival/libipkg/libipkg.h busybox.dev/archival/libipkg/libipkg.h
7179 --- busybox.old/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7180 +++ busybox.dev/archival/libipkg/libipkg.h 2007-01-22 13:41:03.000000000 +0100
7182 +/* ipkglib.h - the itsy package management system
7184 + Florian Boor <florian.boor@kernelconcepts.de>
7186 + This program is free software; you can redistribute it and/or
7187 + modify it under the terms of the GNU General Public License as
7188 + published by the Free Software Foundation; either version 2, or (at
7189 + your option) any later version.
7191 + This program is distributed in the hope that it will be useful, but
7192 + WITHOUT ANY WARRANTY; without even the implied warranty of
7193 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7194 + General Public License for more details.
7202 +#include "ipkg_conf.h"
7203 +#include "ipkg_message.h"
7208 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7210 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7211 + pkg_state_status_t status, void *userdata);
7212 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7214 +typedef char* (*ipkg_response_callback)(char *question);
7216 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7217 +extern int ipkg_init (ipkg_message_callback mcall,
7218 + ipkg_response_callback rcall,
7221 +extern int ipkg_deinit (args_t *args);
7222 +extern int ipkg_packages_list(args_t *args,
7223 + const char *packages,
7224 + ipkg_list_callback cblist,
7226 +extern int ipkg_packages_status(args_t *args,
7227 + const char *packages,
7228 + ipkg_status_callback cbstatus,
7230 +extern int ipkg_packages_info(args_t *args,
7231 + const char *packages,
7232 + ipkg_status_callback cbstatus,
7234 +extern int ipkg_packages_install(args_t *args, const char *name);
7235 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7236 +extern int ipkg_lists_update(args_t *args);
7237 +extern int ipkg_packages_upgrade(args_t *args);
7238 +extern int ipkg_packages_download(args_t *args, const char *name);
7239 +extern int ipkg_package_files(args_t *args,
7241 + ipkg_list_callback cblist,
7243 +extern int ipkg_file_search(args_t *args,
7245 + ipkg_list_callback cblist,
7247 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7248 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7249 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7250 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7251 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7253 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7254 +extern ipkg_response_callback ipkg_cb_response;
7255 +extern ipkg_status_callback ipkg_cb_status;
7256 +extern ipkg_list_callback ipkg_cb_list;
7257 +extern void push_error_list(struct errlist **errors,char * msg);
7258 +extern void reverse_error_list(struct errlist **errors);
7259 +extern void free_error_list(struct errlist **errors);
7263 +extern int ipkg_op(int argc, char *argv[]);
7269 diff -urN busybox.old/archival/libipkg/nv_pair.c busybox.dev/archival/libipkg/nv_pair.c
7270 --- busybox.old/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7271 +++ busybox.dev/archival/libipkg/nv_pair.c 2007-01-22 13:41:03.000000000 +0100
7273 +/* nv_pair.c - the itsy package management system
7277 + Copyright (C) 2001 University of Southern California
7279 + This program is free software; you can redistribute it and/or
7280 + modify it under the terms of the GNU General Public License as
7281 + published by the Free Software Foundation; either version 2, or (at
7282 + your option) any later version.
7284 + This program is distributed in the hope that it will be useful, but
7285 + WITHOUT ANY WARRANTY; without even the implied warranty of
7286 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7287 + General Public License for more details.
7292 +#include "nv_pair.h"
7293 +#include "str_util.h"
7295 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7297 + nv_pair->name = str_dup_safe(name);
7298 + nv_pair->value = str_dup_safe(value);
7303 +void nv_pair_deinit(nv_pair_t *nv_pair)
7305 + free(nv_pair->name);
7306 + nv_pair->name = NULL;
7308 + free(nv_pair->value);
7309 + nv_pair->value = NULL;
7313 diff -urN busybox.old/archival/libipkg/nv_pair.h busybox.dev/archival/libipkg/nv_pair.h
7314 --- busybox.old/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7315 +++ busybox.dev/archival/libipkg/nv_pair.h 2007-01-22 13:41:03.000000000 +0100
7317 +/* nv_pair.h - the itsy package management system
7321 + Copyright (C) 2001 University of Southern California
7323 + This program is free software; you can redistribute it and/or
7324 + modify it under the terms of the GNU General Public License as
7325 + published by the Free Software Foundation; either version 2, or (at
7326 + your option) any later version.
7328 + This program is distributed in the hope that it will be useful, but
7329 + WITHOUT ANY WARRANTY; without even the implied warranty of
7330 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7331 + General Public License for more details.
7337 +typedef struct nv_pair nv_pair_t;
7344 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7345 +void nv_pair_deinit(nv_pair_t *nv_pair);
7349 diff -urN busybox.old/archival/libipkg/nv_pair_list.c busybox.dev/archival/libipkg/nv_pair_list.c
7350 --- busybox.old/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7351 +++ busybox.dev/archival/libipkg/nv_pair_list.c 2007-01-22 13:41:03.000000000 +0100
7353 +/* nv_pair_list.c - the itsy package management system
7357 + Copyright (C) 2001 University of Southern California
7359 + This program is free software; you can redistribute it and/or
7360 + modify it under the terms of the GNU General Public License as
7361 + published by the Free Software Foundation; either version 2, or (at
7362 + your option) any later version.
7364 + This program is distributed in the hope that it will be useful, but
7365 + WITHOUT ANY WARRANTY; without even the implied warranty of
7366 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7367 + General Public License for more details.
7372 +#include "nv_pair.h"
7373 +#include "void_list.h"
7374 +#include "nv_pair_list.h"
7376 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7378 + return void_list_elt_init((void_list_elt_t *) elt, data);
7381 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7383 + void_list_elt_deinit((void_list_elt_t *) elt);
7386 +int nv_pair_list_init(nv_pair_list_t *list)
7388 + return void_list_init((void_list_t *) list);
7391 +void nv_pair_list_deinit(nv_pair_list_t *list)
7393 + nv_pair_list_elt_t *iter;
7394 + nv_pair_t *nv_pair;
7396 + for (iter = list->head; iter; iter = iter->next) {
7397 + nv_pair = iter->data;
7398 + nv_pair_deinit(nv_pair);
7400 + /* malloced in nv_pair_list_append */
7402 + iter->data = NULL;
7404 + void_list_deinit((void_list_t *) list);
7407 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7411 + /* freed in nv_pair_list_deinit */
7412 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7414 + if (nv_pair == NULL) {
7415 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7418 + nv_pair_init(nv_pair, name, value);
7420 + err = void_list_append((void_list_t *) list, nv_pair);
7428 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7430 + return void_list_push((void_list_t *) list, data);
7433 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7435 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7438 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7440 + nv_pair_list_elt_t *iter;
7441 + nv_pair_t *nv_pair;
7443 + for (iter = list->head; iter; iter = iter->next) {
7444 + nv_pair = iter->data;
7445 + if (strcmp(nv_pair->name, name) == 0) {
7446 + return nv_pair->value;
7451 diff -urN busybox.old/archival/libipkg/nv_pair_list.h busybox.dev/archival/libipkg/nv_pair_list.h
7452 --- busybox.old/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7453 +++ busybox.dev/archival/libipkg/nv_pair_list.h 2007-01-22 13:41:03.000000000 +0100
7455 +/* nv_pair_list.h - the itsy package management system
7459 + Copyright (C) 2001 University of Southern California
7461 + This program is free software; you can redistribute it and/or
7462 + modify it under the terms of the GNU General Public License as
7463 + published by the Free Software Foundation; either version 2, or (at
7464 + your option) any later version.
7466 + This program is distributed in the hope that it will be useful, but
7467 + WITHOUT ANY WARRANTY; without even the implied warranty of
7468 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7469 + General Public License for more details.
7472 +#ifndef NV_PAIR_LIST_H
7473 +#define NV_PAIR_LIST_H
7475 +#include "nv_pair.h"
7476 +#include "void_list.h"
7478 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7479 +struct nv_pair_list_elt
7481 + nv_pair_list_elt_t *next;
7485 +typedef struct nv_pair_list nv_pair_list_t;
7486 +struct nv_pair_list
7488 + nv_pair_list_elt_t pre_head;
7489 + nv_pair_list_elt_t *head;
7490 + nv_pair_list_elt_t *tail;
7493 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7495 + if (list->head == NULL)
7501 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7502 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7504 +int nv_pair_list_init(nv_pair_list_t *list);
7505 +void nv_pair_list_deinit(nv_pair_list_t *list);
7507 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7508 + const char *name, const char *value);
7509 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7510 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7511 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7515 diff -urN busybox.old/archival/libipkg/pkg.c busybox.dev/archival/libipkg/pkg.c
7516 --- busybox.old/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7517 +++ busybox.dev/archival/libipkg/pkg.c 2007-01-22 13:41:10.000000000 +0100
7519 +/* pkg.c - the itsy package management system
7523 + Copyright (C) 2001 University of Southern California
7525 + This program is free software; you can redistribute it and/or
7526 + modify it under the terms of the GNU General Public License as
7527 + published by the Free Software Foundation; either version 2, or (at
7528 + your option) any later version.
7530 + This program is distributed in the hope that it will be useful, but
7531 + WITHOUT ANY WARRANTY; without even the implied warranty of
7532 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7533 + General Public License for more details.
7538 +#include <string.h>
7543 +#include "pkg_parse.h"
7544 +#include "pkg_extract.h"
7545 +#include "ipkg_message.h"
7546 +#include "ipkg_utils.h"
7548 +#include "sprintf_alloc.h"
7549 +#include "file_util.h"
7550 +#include "str_util.h"
7551 +#include "xsystem.h"
7552 +#include "ipkg_conf.h"
7554 +typedef struct enum_map enum_map_t;
7561 +static const enum_map_t pkg_state_want_map[] = {
7562 + { SW_UNKNOWN, "unknown"},
7563 + { SW_INSTALL, "install"},
7564 + { SW_DEINSTALL, "deinstall"},
7565 + { SW_PURGE, "purge"}
7568 +static const enum_map_t pkg_state_flag_map[] = {
7570 + { SF_REINSTREQ, "reinstreq"},
7571 + { SF_HOLD, "hold"},
7572 + { SF_REPLACE, "replace"},
7573 + { SF_NOPRUNE, "noprune"},
7574 + { SF_PREFER, "prefer"},
7575 + { SF_OBSOLETE, "obsolete"},
7576 + { SF_USER, "user"},
7579 +static const enum_map_t pkg_state_status_map[] = {
7580 + { SS_NOT_INSTALLED, "not-installed" },
7581 + { SS_UNPACKED, "unpacked" },
7582 + { SS_HALF_CONFIGURED, "half-configured" },
7583 + { SS_INSTALLED, "installed" },
7584 + { SS_HALF_INSTALLED, "half-installed" },
7585 + { SS_CONFIG_FILES, "config-files" },
7586 + { SS_POST_INST_FAILED, "post-inst-failed" },
7587 + { SS_REMOVAL_FAILED, "removal-failed" }
7590 +static int verrevcmp(const char *val, const char *ref);
7593 +pkg_t *pkg_new(void)
7597 + pkg = malloc(sizeof(pkg_t));
7598 + if (pkg == NULL) {
7599 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7608 +int pkg_init(pkg_t *pkg)
7610 + memset(pkg, 0, sizeof(pkg_t));
7613 + pkg->version = NULL;
7614 + pkg->revision = NULL;
7615 + pkg->familiar_revision = NULL;
7618 + pkg->architecture = NULL;
7619 + pkg->maintainer = NULL;
7620 + pkg->section = NULL;
7621 + pkg->description = NULL;
7622 + pkg->state_want = SW_UNKNOWN;
7623 + pkg->state_flag = SF_OK;
7624 + pkg->state_status = SS_NOT_INSTALLED;
7625 + pkg->depends_str = NULL;
7626 + pkg->provides_str = NULL;
7627 + pkg->depends_count = 0;
7628 + pkg->depends = NULL;
7629 + pkg->suggests_str = NULL;
7630 + pkg->recommends_str = NULL;
7631 + pkg->suggests_count = 0;
7632 + pkg->recommends_count = 0;
7634 + /* Abhaya: added init for conflicts fields */
7635 + pkg->conflicts = NULL;
7636 + pkg->conflicts_count = 0;
7638 + /* added for replaces. Jamey 7/23/2002 */
7639 + pkg->replaces = NULL;
7640 + pkg->replaces_count = 0;
7642 + pkg->pre_depends_count = 0;
7643 + pkg->pre_depends_str = NULL;
7644 + pkg->provides_count = 0;
7645 + pkg->provides = NULL;
7646 + pkg->filename = NULL;
7647 + pkg->local_filename = NULL;
7648 + pkg->tmp_unpack_dir = NULL;
7649 + pkg->md5sum = NULL;
7651 + pkg->installed_size = NULL;
7652 + pkg->priority = NULL;
7653 + pkg->source = NULL;
7654 + conffile_list_init(&pkg->conffiles);
7655 + pkg->installed_files = NULL;
7656 + pkg->installed_files_ref_cnt = 0;
7657 + pkg->essential = 0;
7658 + pkg->provided_by_hand = 0;
7663 +void pkg_deinit(pkg_t *pkg)
7668 + free(pkg->version);
7669 + pkg->version = NULL;
7670 + /* revision and familiar_revision share storage with version, so
7672 + pkg->revision = NULL;
7673 + pkg->familiar_revision = NULL;
7674 + /* owned by ipkg_conf_t */
7676 + /* owned by ipkg_conf_t */
7678 + free(pkg->architecture);
7679 + pkg->architecture = NULL;
7680 + free(pkg->maintainer);
7681 + pkg->maintainer = NULL;
7682 + free(pkg->section);
7683 + pkg->section = NULL;
7684 + free(pkg->description);
7685 + pkg->description = NULL;
7686 + pkg->state_want = SW_UNKNOWN;
7687 + pkg->state_flag = SF_OK;
7688 + pkg->state_status = SS_NOT_INSTALLED;
7689 + free(pkg->depends_str);
7690 + pkg->depends_str = NULL;
7691 + free(pkg->provides_str);
7692 + pkg->provides_str = NULL;
7693 + pkg->depends_count = 0;
7694 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7695 + pkg->pre_depends_count = 0;
7696 + free(pkg->pre_depends_str);
7697 + pkg->pre_depends_str = NULL;
7698 + pkg->provides_count = 0;
7699 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7700 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7701 + free(pkg->filename);
7702 + pkg->filename = NULL;
7703 + free(pkg->local_filename);
7704 + pkg->local_filename = NULL;
7705 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7706 + ipkg_install.c here. See comment in
7707 + ipkg_install.c:cleanup_temporary_files */
7708 + free(pkg->tmp_unpack_dir);
7709 + pkg->tmp_unpack_dir = NULL;
7710 + free(pkg->md5sum);
7711 + pkg->md5sum = NULL;
7714 + free(pkg->installed_size);
7715 + pkg->installed_size = NULL;
7716 + free(pkg->priority);
7717 + pkg->priority = NULL;
7718 + free(pkg->source);
7719 + pkg->source = NULL;
7720 + conffile_list_deinit(&pkg->conffiles);
7721 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7722 + since if they are calling deinit, they should know. Maybe do an
7723 + assertion here instead? */
7724 + pkg->installed_files_ref_cnt = 1;
7725 + pkg_free_installed_files(pkg);
7726 + pkg->essential = 0;
7729 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7733 + FILE *control_file;
7735 + err = pkg_init(pkg);
7736 + if (err) { return err; }
7738 + pkg->local_filename = strdup(filename);
7740 + control_file = tmpfile();
7741 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7742 + if (err) { return err; }
7744 + rewind(control_file);
7745 + raw = read_raw_pkgs_from_stream(control_file);
7746 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7748 + fclose(control_file);
7753 +/* Merge any new information in newpkg into oldpkg */
7754 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7755 + newpkg, but should leave it usable. This rework is so that
7756 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7758 + * uh, i thought that i had originally written this so that it took
7759 + * two pkgs and returned a new one? we can do that again... -sma
7761 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7763 + if (oldpkg == newpkg) {
7768 + oldpkg->src = newpkg->src;
7769 + if (!oldpkg->dest)
7770 + oldpkg->dest = newpkg->dest;
7771 + if (!oldpkg->architecture)
7772 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7773 + if (!oldpkg->arch_priority)
7774 + oldpkg->arch_priority = newpkg->arch_priority;
7775 + if (!oldpkg->section)
7776 + oldpkg->section = str_dup_safe(newpkg->section);
7777 + if(!oldpkg->maintainer)
7778 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7779 + if(!oldpkg->description)
7780 + oldpkg->description = str_dup_safe(newpkg->description);
7782 + /* merge the state_flags from the new package */
7783 + oldpkg->state_want = newpkg->state_want;
7784 + oldpkg->state_status = newpkg->state_status;
7785 + oldpkg->state_flag = newpkg->state_flag;
7787 + if (oldpkg->state_want == SW_UNKNOWN)
7788 + oldpkg->state_want = newpkg->state_want;
7789 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7790 + oldpkg->state_status = newpkg->state_status;
7791 + oldpkg->state_flag |= newpkg->state_flag;
7794 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7795 + oldpkg->depends_str = newpkg->depends_str;
7796 + newpkg->depends_str = NULL;
7797 + oldpkg->depends_count = newpkg->depends_count;
7798 + newpkg->depends_count = 0;
7800 + oldpkg->depends = newpkg->depends;
7801 + newpkg->depends = NULL;
7803 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7804 + newpkg->pre_depends_str = NULL;
7805 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7806 + newpkg->pre_depends_count = 0;
7808 + oldpkg->recommends_str = newpkg->recommends_str;
7809 + newpkg->recommends_str = NULL;
7810 + oldpkg->recommends_count = newpkg->recommends_count;
7811 + newpkg->recommends_count = 0;
7813 + oldpkg->suggests_str = newpkg->suggests_str;
7814 + newpkg->suggests_str = NULL;
7815 + oldpkg->suggests_count = newpkg->suggests_count;
7816 + newpkg->suggests_count = 0;
7819 + if (!oldpkg->provides_str) {
7820 + oldpkg->provides_str = newpkg->provides_str;
7821 + newpkg->provides_str = NULL;
7822 + oldpkg->provides_count = newpkg->provides_count;
7823 + newpkg->provides_count = 0;
7825 + oldpkg->provides = newpkg->provides;
7826 + newpkg->provides = NULL;
7829 + if (!oldpkg->conflicts_str) {
7830 + oldpkg->conflicts_str = newpkg->conflicts_str;
7831 + newpkg->conflicts_str = NULL;
7832 + oldpkg->conflicts_count = newpkg->conflicts_count;
7833 + newpkg->conflicts_count = 0;
7835 + oldpkg->conflicts = newpkg->conflicts;
7836 + newpkg->conflicts = NULL;
7839 + if (!oldpkg->replaces_str) {
7840 + oldpkg->replaces_str = newpkg->replaces_str;
7841 + newpkg->replaces_str = NULL;
7842 + oldpkg->replaces_count = newpkg->replaces_count;
7843 + newpkg->replaces_count = 0;
7845 + oldpkg->replaces = newpkg->replaces;
7846 + newpkg->replaces = NULL;
7849 + if (!oldpkg->filename)
7850 + oldpkg->filename = str_dup_safe(newpkg->filename);
7852 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7853 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7854 + if (!oldpkg->local_filename)
7855 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7856 + if (!oldpkg->tmp_unpack_dir)
7857 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7858 + if (!oldpkg->md5sum)
7859 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7860 + if (!oldpkg->size)
7861 + oldpkg->size = str_dup_safe(newpkg->size);
7862 + if (!oldpkg->installed_size)
7863 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7864 + if (!oldpkg->priority)
7865 + oldpkg->priority = str_dup_safe(newpkg->priority);
7866 + if (!oldpkg->source)
7867 + oldpkg->source = str_dup_safe(newpkg->source);
7868 + if (oldpkg->conffiles.head == NULL){
7869 + oldpkg->conffiles = newpkg->conffiles;
7870 + conffile_list_init(&newpkg->conffiles);
7872 + if (!oldpkg->installed_files){
7873 + oldpkg->installed_files = newpkg->installed_files;
7874 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7875 + newpkg->installed_files = NULL;
7877 + if (!oldpkg->essential)
7878 + oldpkg->essential = newpkg->essential;
7880 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7885 +abstract_pkg_t *abstract_pkg_new(void)
7887 + abstract_pkg_t * ab_pkg;
7889 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7891 + if (ab_pkg == NULL) {
7892 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7896 + if ( abstract_pkg_init(ab_pkg) < 0 )
7902 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7904 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7906 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7907 + if (ab_pkg->provided_by==NULL){
7910 + ab_pkg->dependencies_checked = 0;
7911 + ab_pkg->state_status = SS_NOT_INSTALLED;
7916 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7919 + char **raw_start=NULL;
7921 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7922 + if (temp_str == NULL ){
7923 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7926 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7928 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7929 + if (raw == NULL ){
7930 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7935 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7936 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7952 +char * pkg_formatted_info(pkg_t *pkg )
7957 + buff = malloc(8192);
7958 + if (buff == NULL) {
7959 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7965 + line = pkg_formatted_field(pkg, "Package");
7966 + strncat(buff ,line, strlen(line));
7969 + line = pkg_formatted_field(pkg, "Version");
7970 + strncat(buff ,line, strlen(line));
7973 + line = pkg_formatted_field(pkg, "Depends");
7974 + strncat(buff ,line, strlen(line));
7977 + line = pkg_formatted_field(pkg, "Recommends");
7978 + strncat(buff ,line, strlen(line));
7981 + line = pkg_formatted_field(pkg, "Suggests");
7982 + strncat(buff ,line, strlen(line));
7985 + line = pkg_formatted_field(pkg, "Provides");
7986 + strncat(buff ,line, strlen(line));
7989 + line = pkg_formatted_field(pkg, "Replaces");
7990 + strncat(buff ,line, strlen(line));
7993 + line = pkg_formatted_field(pkg, "Conflicts");
7994 + strncat(buff ,line, strlen(line));
7997 + line = pkg_formatted_field(pkg, "Status");
7998 + strncat(buff ,line, strlen(line));
8001 + line = pkg_formatted_field(pkg, "Section");
8002 + strncat(buff ,line, strlen(line));
8005 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8006 + strncat(buff ,line, strlen(line));
8009 + line = pkg_formatted_field(pkg, "Architecture");
8010 + strncat(buff ,line, strlen(line));
8013 + line = pkg_formatted_field(pkg, "Maintainer");
8014 + strncat(buff ,line, strlen(line));
8017 + line = pkg_formatted_field(pkg, "MD5sum");
8018 + strncat(buff ,line, strlen(line));
8021 + line = pkg_formatted_field(pkg, "Size");
8022 + strncat(buff ,line, strlen(line));
8025 + line = pkg_formatted_field(pkg, "Filename");
8026 + strncat(buff ,line, strlen(line));
8029 + line = pkg_formatted_field(pkg, "Conffiles");
8030 + strncat(buff ,line, strlen(line));
8033 + line = pkg_formatted_field(pkg, "Source");
8034 + strncat(buff ,line, strlen(line));
8037 + line = pkg_formatted_field(pkg, "Description");
8038 + strncat(buff ,line, strlen(line));
8041 + line = pkg_formatted_field(pkg, "Installed-Time");
8042 + strncat(buff ,line, strlen(line));
8048 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8050 + static size_t LINE_LEN = 128;
8051 + char line_str[LINE_LEN];
8052 + char * temp = (char *)malloc(1);
8054 + int flag_provide_false = 0;
8057 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8058 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8061 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8062 + goto UNKNOWN_FMT_FIELD;
8071 + if (strcasecmp(field, "Architecture") == 0) {
8072 + /* Architecture */
8073 + if (pkg->architecture) {
8074 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8075 + if ( temp == NULL ){
8076 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8080 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8083 + goto UNKNOWN_FMT_FIELD;
8088 + if (strcasecmp(field, "Conffiles") == 0) {
8090 + conffile_list_elt_t *iter;
8092 + if (pkg->conffiles.head == NULL) {
8097 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8098 + if (iter->data->name && iter->data->value) {
8099 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8102 + temp = (char *)realloc(temp,len);
8103 + if ( temp == NULL ){
8104 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8108 + strncpy(temp, "Conffiles:\n", 12);
8109 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8110 + if (iter->data->name && iter->data->value) {
8111 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8112 + strncat(temp, line_str, strlen(line_str));
8115 + } else if (strcasecmp(field, "Conflicts") == 0) {
8118 + if (pkg->conflicts_count) {
8120 + for(i = 0; i < pkg->conflicts_count; i++) {
8121 + len = len + (strlen(pkg->conflicts_str[i])+5);
8123 + temp = (char *)realloc(temp,len);
8124 + if ( temp == NULL ){
8125 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8129 + strncpy(temp, "Conflicts:", 11);
8130 + for(i = 0; i < pkg->conflicts_count; i++) {
8131 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8132 + strncat(temp, line_str, strlen(line_str));
8134 + strncat(temp, "\n", strlen("\n"));
8137 + goto UNKNOWN_FMT_FIELD;
8142 + if (strcasecmp(field, "Depends") == 0) {
8146 + if (pkg->depends_count) {
8148 + for(i = 0; i < pkg->depends_count; i++) {
8149 + len = len + (strlen(pkg->depends_str[i])+4);
8151 + temp = (char *)realloc(temp,len);
8152 + if ( temp == NULL ){
8153 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8157 + strncpy(temp, "Depends:", 10);
8158 + for(i = 0; i < pkg->depends_count; i++) {
8159 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8160 + strncat(temp, line_str, strlen(line_str));
8162 + strncat(temp, "\n", strlen("\n"));
8164 + } else if (strcasecmp(field, "Description") == 0) {
8166 + if (pkg->description) {
8167 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8168 + if ( temp == NULL ){
8169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8173 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8176 + goto UNKNOWN_FMT_FIELD;
8182 + if (pkg->essential) {
8183 + temp = (char *)realloc(temp,16);
8184 + if ( temp == NULL ){
8185 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8189 + snprintf(temp, (16), "Essential: yes\n");
8196 + if (pkg->filename) {
8197 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8198 + if ( temp == NULL ){
8199 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8203 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8209 + if (strcasecmp(field, "Installed-Size") == 0) {
8210 + /* Installed-Size */
8211 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8212 + if ( temp == NULL ){
8213 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8217 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8218 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8219 + temp = (char *)realloc(temp,29);
8220 + if ( temp == NULL ){
8221 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8225 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8231 + /* Maintainer | MD5sum */
8232 + if (strcasecmp(field, "Maintainer") == 0) {
8234 + if (pkg->maintainer) {
8235 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8236 + if ( temp == NULL ){
8237 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8241 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8243 + } else if (strcasecmp(field, "MD5sum") == 0) {
8245 + if (pkg->md5sum) {
8246 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8247 + if ( temp == NULL ){
8248 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8252 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8255 + goto UNKNOWN_FMT_FIELD;
8261 + if (strcasecmp(field, "Package") == 0) {
8263 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8264 + if ( temp == NULL ){
8265 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8269 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8270 + } else if (strcasecmp(field, "Priority") == 0) {
8272 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8273 + if ( temp == NULL ){
8274 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8278 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8279 + } else if (strcasecmp(field, "Provides") == 0) {
8283 + if (pkg->provides_count) {
8284 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8285 + for ( i=0; i < pkg->provides_count; i++ ){
8286 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8287 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8288 + flag_provide_false = 1;
8291 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8292 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8293 + char provstr[LINE_LEN];
8295 + for(i = 0; i < pkg->provides_count; i++) {
8296 + len = len + (strlen(pkg->provides_str[i])+5);
8298 + temp = (char *)realloc(temp,len);
8299 + if ( temp == NULL ){
8300 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8304 + strncpy(temp, "Provides:", 12);
8305 + for(i = 0; i < pkg->provides_count; i++) {
8306 + if (strlen(pkg->provides_str[i])>0){;
8307 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8308 + strncat(temp, provstr, strlen(provstr));
8311 + strncat(temp, "\n", strlen("\n"));
8315 + goto UNKNOWN_FMT_FIELD;
8322 + /* Replaces | Recommends*/
8323 + if (strcasecmp (field, "Replaces") == 0) {
8324 + if (pkg->replaces_count) {
8326 + for (i = 0; i < pkg->replaces_count; i++) {
8327 + len = len + (strlen(pkg->replaces_str[i])+5);
8329 + temp = (char *)realloc(temp,len);
8330 + if ( temp == NULL ){
8331 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8335 + strncpy(temp, "Replaces:", 12);
8336 + for (i = 0; i < pkg->replaces_count; i++) {
8337 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8338 + strncat(temp, line_str, strlen(line_str));
8340 + strncat(temp, "\n", strlen("\n"));
8342 + } else if (strcasecmp (field, "Recommends") == 0) {
8343 + if (pkg->recommends_count) {
8345 + for(i = 0; i < pkg->recommends_count; i++) {
8346 + len = len + (strlen( pkg->recommends_str[i])+5);
8348 + temp = (char *)realloc(temp,len);
8349 + if ( temp == NULL ){
8350 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8354 + strncpy(temp, "Recommends:", 13);
8355 + for(i = 0; i < pkg->recommends_count; i++) {
8356 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8357 + strncat(temp, line_str, strlen(line_str));
8359 + strncat(temp, "\n", strlen("\n"));
8362 + goto UNKNOWN_FMT_FIELD;
8368 + /* Section | Size | Source | Status | Suggests */
8369 + if (strcasecmp(field, "Section") == 0) {
8371 + if (pkg->section) {
8372 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8373 + if ( temp == NULL ){
8374 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8378 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8380 + } else if (strcasecmp(field, "Size") == 0) {
8383 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8384 + if ( temp == NULL ){
8385 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8389 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8391 + } else if (strcasecmp(field, "Source") == 0) {
8393 + if (pkg->source) {
8394 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8395 + if ( temp == NULL ){
8396 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8400 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8402 + } else if (strcasecmp(field, "Status") == 0) {
8404 + /* Benjamin Pineau note: we should avoid direct usage of
8405 + * strlen(arg) without keeping "arg" for later free()
8407 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8408 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8409 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8411 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8412 + temp = (char *)realloc(temp,sum_of_sizes);
8413 + if ( temp == NULL ){
8414 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8418 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8421 + if(pstat) /* pfstat can be NULL if ENOMEM */
8423 + } else if (strcasecmp(field, "Suggests") == 0) {
8424 + if (pkg->suggests_count) {
8427 + for(i = 0; i < pkg->suggests_count; i++) {
8428 + len = len + (strlen(pkg->suggests_str[i])+5);
8430 + temp = (char *)realloc(temp,len);
8431 + if ( temp == NULL ){
8432 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8436 + strncpy(temp, "Suggests:", 10);
8437 + for(i = 0; i < pkg->suggests_count; i++) {
8438 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8439 + strncat(temp, line_str, strlen(line_str));
8441 + strncat(temp, "\n", strlen("\n"));
8444 + goto UNKNOWN_FMT_FIELD;
8451 + char *version = pkg_version_str_alloc(pkg);
8452 + temp = (char *)realloc(temp,strlen(version)+14);
8453 + if ( temp == NULL ){
8454 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8458 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8463 + goto UNKNOWN_FMT_FIELD;
8466 + if ( strlen(temp)<2 ) {
8471 + UNKNOWN_FMT_FIELD:
8472 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8473 + if ( strlen(temp)<2 ) {
8480 +void pkg_print_info(pkg_t *pkg, FILE *file)
8483 + if (pkg == NULL) {
8487 + buff = pkg_formatted_info(pkg);
8488 + if ( buff == NULL )
8490 + if (strlen(buff)>2){
8491 + fwrite(buff, 1, strlen(buff), file);
8496 +void pkg_print_status(pkg_t * pkg, FILE * file)
8498 + if (pkg == NULL) {
8502 + /* XXX: QUESTION: Do we actually want more fields here? The
8503 + original idea was to save space by installing only what was
8504 + needed for actual computation, (package, version, status,
8505 + essential, conffiles). The assumption is that all other fields
8506 + can be found in th available file.
8508 + But, someone proposed the idea to make it possible to
8509 + reconstruct a .ipk from an installed package, (ie. for beaming
8510 + from one handheld to another). So, maybe we actually want a few
8511 + more fields here, (depends, suggests, etc.), so that that would
8512 + be guaranteed to work even in the absence of more information
8513 + from the available file.
8515 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8516 + the essential info needs to be here for all installed packages
8517 + because they may not appear in the Packages files on various
8518 + feeds. Furthermore, one should be able to install from URL or
8519 + local storage without requiring a Packages file from any feed.
8522 + pkg_print_field(pkg, file, "Package");
8523 + pkg_print_field(pkg, file, "Version");
8524 + pkg_print_field(pkg, file, "Depends");
8525 + pkg_print_field(pkg, file, "Recommends");
8526 + pkg_print_field(pkg, file, "Suggests");
8527 + pkg_print_field(pkg, file, "Provides");
8528 + pkg_print_field(pkg, file, "Replaces");
8529 + pkg_print_field(pkg, file, "Conflicts");
8530 + pkg_print_field(pkg, file, "Status");
8531 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8532 + pkg_print_field(pkg, file, "Architecture");
8533 + pkg_print_field(pkg, file, "Conffiles");
8534 + pkg_print_field(pkg, file, "Installed-Time");
8535 + fputs("\n", file);
8538 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8541 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8542 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8543 + __FUNCTION__, field);
8545 + buff = pkg_formatted_field(pkg, field);
8546 + if (strlen(buff)>2) {
8547 + fprintf(file, "%s", buff);
8555 + * libdpkg - Debian packaging suite library routines
8556 + * vercmp.c - comparison of version numbers
8558 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8560 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8564 + if (pkg->epoch > ref_pkg->epoch) {
8568 + if (pkg->epoch < ref_pkg->epoch) {
8572 + r = verrevcmp(pkg->version, ref_pkg->version);
8577 +#ifdef USE_DEBVERSION
8578 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8583 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8589 +int verrevcmp(const char *val, const char *ref)
8593 + const char *vp, *rp;
8594 + const char *vsep, *rsep;
8596 + if (!val) val= "";
8597 + if (!ref) ref= "";
8599 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8600 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8602 + vc= (val == vp) ? 0 : *val++;
8603 + rc= (ref == rp) ? 0 : *ref++;
8604 + if (!rc && !vc) break;
8605 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8606 + if (rc && !isalpha(rc)) rc += 256;
8607 + if (vc != rc) return vc - rc;
8611 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8612 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8613 + if (vl != rl) return vl - rl;
8617 + vsep = strchr(".-", vc);
8618 + rsep = strchr(".-", rc);
8619 + if (vsep && !rsep) return -1;
8620 + if (!vsep && rsep) return +1;
8622 + if (!*val && !*ref) return 0;
8623 + if (!*val) return -1;
8624 + if (!*ref) return +1;
8628 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8632 + r = pkg_compare_versions(it, ref);
8634 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8638 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8642 + if (strcmp(op, "<<") == 0) {
8646 + if (strcmp(op, ">>") == 0) {
8650 + if (strcmp(op, "=") == 0) {
8654 + fprintf(stderr, "unknown operator: %s", op);
8658 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8662 + if (!a->name || !b->name) {
8663 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8664 + a, a->name, b, b->name);
8668 + namecmp = strcmp(a->name, b->name);
8671 + vercmp = pkg_compare_versions(a, b);
8674 + if (!a->arch_priority || !b->arch_priority) {
8675 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8676 + a, a->arch_priority, b, b->arch_priority);
8679 + if (a->arch_priority > b->arch_priority)
8681 + if (a->arch_priority < b->arch_priority)
8686 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8688 + if (!a->name || !b->name) {
8689 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8690 + a, a->name, b, b->name);
8693 + return strcmp(a->name, b->name);
8697 +char *pkg_version_str_alloc(pkg_t *pkg)
8699 + char *complete_version;
8701 +#ifdef USE_DEBVERSION
8702 + char *revision_str;
8703 + char *familiar_revision_str;
8707 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8709 + epoch_str = strdup("");
8712 +#ifdef USE_DEBVERSION
8713 + if (pkg->revision && strlen(pkg->revision)) {
8714 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8716 + revision_str = strdup("");
8719 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8720 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8722 + familiar_revision_str = strdup("");
8726 +#ifdef USE_DEBVERSION
8727 + sprintf_alloc(&complete_version, "%s%s%s%s",
8728 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8730 + sprintf_alloc(&complete_version, "%s%s",
8731 + epoch_str, pkg->version);
8735 +#ifdef USE_DEBVERSION
8736 + free(revision_str);
8737 + free(familiar_revision_str);
8740 + return complete_version;
8743 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8746 + char *list_file_name = NULL;
8747 + FILE *list_file = NULL;
8749 + char *installed_file_name;
8752 + pkg->installed_files_ref_cnt++;
8754 + if (pkg->installed_files) {
8755 + return pkg->installed_files;
8758 + pkg->installed_files = str_list_alloc();
8759 + if (pkg->installed_files == NULL) {
8760 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8764 + /* For uninstalled packages, get the file list firectly from the package.
8765 + For installed packages, look at the package.list file in the database.
8767 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8768 + if (pkg->local_filename == NULL) {
8769 + return pkg->installed_files;
8771 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8772 + file. In other words, change deb_extract so that it can
8773 + simply return the file list as a char *[] rather than
8774 + insisting on writing in to a FILE * as it does now. */
8775 + list_file = tmpfile();
8776 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8778 + fclose(list_file);
8779 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8780 + __FUNCTION__, pkg->local_filename, strerror(err));
8781 + return pkg->installed_files;
8783 + rewind(list_file);
8785 + sprintf_alloc(&list_file_name, "%s/%s.list",
8786 + pkg->dest->info_dir, pkg->name);
8787 + if (! file_exists(list_file_name)) {
8788 + free(list_file_name);
8789 + return pkg->installed_files;
8792 + list_file = fopen(list_file_name, "r");
8793 + if (list_file == NULL) {
8794 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8795 + list_file_name, strerror(errno));
8796 + free(list_file_name);
8797 + return pkg->installed_files;
8799 + free(list_file_name);
8802 + rootdirlen = strlen( pkg->dest->root_dir );
8806 + line = file_read_line_alloc(list_file);
8807 + if (line == NULL) {
8813 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8814 + if( strncmp( pkg->dest->root_dir,
8817 + if (*file_name == '.') {
8820 + if (*file_name == '/') {
8824 + /* Freed in pkg_free_installed_files */
8825 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8827 + // already contains root_dir as header -> ABSOLUTE
8828 + sprintf_alloc(&installed_file_name, "%s", file_name);
8830 + str_list_append(pkg->installed_files, installed_file_name);
8834 + fclose(list_file);
8836 + return pkg->installed_files;
8839 +/* XXX: CLEANUP: This function and it's counterpart,
8840 + (pkg_get_installed_files), do not match our init/deinit naming
8841 + convention. Nor the alloc/free convention. But, then again, neither
8842 + of these conventions currrently fit the way these two functions
8844 +int pkg_free_installed_files(pkg_t *pkg)
8846 + str_list_elt_t *iter;
8848 + pkg->installed_files_ref_cnt--;
8849 + if (pkg->installed_files_ref_cnt > 0) {
8853 + if (pkg->installed_files) {
8855 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8856 + /* malloced in pkg_get_installed_files */
8857 + free (iter->data);
8858 + iter->data = NULL;
8861 + str_list_deinit(pkg->installed_files);
8864 + pkg->installed_files = NULL;
8869 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8872 + char *list_file_name;
8874 + //I don't think pkg_free_installed_files should be called here. Jamey
8875 + //pkg_free_installed_files(pkg);
8877 + sprintf_alloc(&list_file_name, "%s/%s.list",
8878 + pkg->dest->info_dir, pkg->name);
8879 + if (!conf->noaction) {
8880 + err = unlink(list_file_name);
8881 + free(list_file_name);
8890 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8892 + conffile_list_elt_t *iter;
8893 + conffile_t *conffile;
8895 + if (pkg == NULL) {
8899 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8900 + conffile = iter->data;
8902 + if (strcmp(conffile->name, file_name) == 0) {
8910 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8911 + const char *script, const char *args)
8917 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8918 + maintainer script within a chroot environment. */
8920 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8921 + have scripts in pkg->tmp_unpack_dir. */
8922 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8923 + if (pkg->dest == NULL) {
8924 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8925 + __FUNCTION__, pkg->name);
8928 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8930 + if (pkg->tmp_unpack_dir == NULL) {
8931 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8932 + __FUNCTION__, pkg->name);
8935 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8938 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8939 + if (conf->noaction) return 0;
8941 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8942 + scripts when running with offline_root mode and/or a dest other
8943 + than '/'. I've been playing around with some clever chroot
8944 + tricks and I might come up with something workable. */
8945 + if (conf->offline_root) {
8946 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8949 + setenv("PKG_ROOT",
8950 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8952 + if (! file_exists(path)) {
8957 + if (conf->offline_root) {
8958 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8963 + sprintf_alloc(&cmd, "%s %s", path, args);
8966 + err = xsystem(cmd);
8970 + fprintf(stderr, "%s script returned status %d\n", script, err);
8977 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8981 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8982 + if (pkg_state_want_map[i].value == sw) {
8983 + return strdup(pkg_state_want_map[i].str);
8987 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8988 + __FUNCTION__, sw);
8989 + return strdup("<STATE_WANT_UNKNOWN>");
8992 +pkg_state_want_t pkg_state_want_from_str(char *str)
8996 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8997 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8998 + return pkg_state_want_map[i].value;
9002 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9003 + __FUNCTION__, str);
9004 + return SW_UNKNOWN;
9007 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9010 + int len = 3; /* ok\000 is minimum */
9013 + /* clear the temporary flags before converting to string */
9014 + sf &= SF_NONVOLATILE_FLAGS;
9017 + return strdup("ok");
9020 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9021 + if (sf & pkg_state_flag_map[i].value) {
9022 + len += strlen(pkg_state_flag_map[i].str) + 1;
9025 + str = malloc(len);
9026 + if ( str == NULL ) {
9027 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9031 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9032 + if (sf & pkg_state_flag_map[i].value) {
9033 + strcat(str, pkg_state_flag_map[i].str);
9037 + len = strlen(str);
9038 + str[len-1] = 0; /* squash last comma */
9043 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9048 + if (strcmp(str, "ok") == 0) {
9051 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9052 + const char *sfname = pkg_state_flag_map[i].str;
9053 + int sfname_len = strlen(sfname);
9054 + if (strncmp(str, sfname, sfname_len) == 0) {
9055 + sf |= pkg_state_flag_map[i].value;
9056 + str += sfname_len;
9057 + if (str[0] == ',') {
9068 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9072 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9073 + if (pkg_state_status_map[i].value == ss) {
9074 + return strdup(pkg_state_status_map[i].str);
9078 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9079 + __FUNCTION__, ss);
9080 + return strdup("<STATE_STATUS_UNKNOWN>");
9083 +pkg_state_status_t pkg_state_status_from_str(char *str)
9087 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9088 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9089 + return pkg_state_status_map[i].value;
9093 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9094 + __FUNCTION__, str);
9095 + return SS_NOT_INSTALLED;
9098 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9100 + nv_pair_list_elt_t *l;
9102 + if (!pkg->architecture)
9105 + l = conf->arch_list.head;
9108 + nv_pair_t *nv = l->data;
9109 + if (strcmp(nv->name, pkg->architecture) == 0) {
9110 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9116 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9120 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9122 + nv_pair_list_elt_t *l;
9124 + l = conf->arch_list.head;
9127 + nv_pair_t *nv = l->data;
9128 + if (strcmp(nv->name, archname) == 0) {
9129 + int priority = strtol(nv->value, NULL, 0);
9137 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9140 + hash_table_t *pkg_hash = &conf->pkg_hash;
9141 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9142 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9144 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9145 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9146 + /* update arch_priority for each package */
9147 + for (i = 0; i < available_pkgs->len; i++) {
9148 + pkg_t *pkg = available_pkgs->pkgs[i];
9149 + int arch_priority = 1;
9152 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9153 + if (pkg->architecture)
9154 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9156 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9157 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9158 + pkg->arch_priority = arch_priority;
9161 + for (i = 0; i < available_pkgs->len; i++) {
9162 + pkg_t *pkg = available_pkgs->pkgs[i];
9163 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9164 + /* clear flags and want for any uninstallable package */
9165 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9166 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9167 + pkg->state_want = SW_UNKNOWN;
9168 + pkg->state_flag = 0;
9171 + pkg_vec_free(available_pkgs);
9173 + /* update the file owner data structure */
9174 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9175 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9176 + for (i = 0; i < installed_pkgs->len; i++) {
9177 + pkg_t *pkg = installed_pkgs->pkgs[i];
9178 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9179 + str_list_elt_t *iter;
9180 + if (installed_files == NULL) {
9181 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9184 + for (iter = installed_files->head; iter; iter = iter->next) {
9185 + char *installed_file = iter->data;
9186 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9187 + file_hash_set_file_owner(conf, installed_file, pkg);
9190 + pkg_vec_free(installed_pkgs);
9195 +struct pkg_write_filelist_data {
9196 + ipkg_conf_t *conf;
9201 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9203 + struct pkg_write_filelist_data *data = data_;
9204 + pkg_t *entry = entry_;
9205 + if (entry == data->pkg) {
9206 + fprintf(data->stream, "%s\n", key);
9210 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9212 + struct pkg_write_filelist_data data;
9213 + char *list_file_name = NULL;
9217 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9220 + ipkg_message(conf, IPKG_INFO,
9221 + " creating %s.list file\n", pkg->name);
9222 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9223 + if (!list_file_name) {
9224 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9227 + ipkg_message(conf, IPKG_INFO,
9228 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9229 + data.stream = fopen(list_file_name, "w");
9230 + if (!data.stream) {
9231 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9232 + list_file_name, strerror(errno));
9237 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9238 + fclose(data.stream);
9239 + free(list_file_name);
9244 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9246 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9247 + hash_table_t *pkg_hash = &conf->pkg_hash;
9250 + if (conf->noaction)
9253 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9254 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9255 + for (i = 0; i < installed_pkgs->len; i++) {
9256 + pkg_t *pkg = installed_pkgs->pkgs[i];
9257 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9258 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9259 + err = pkg_write_filelist(conf, pkg);
9261 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9266 diff -urN busybox.old/archival/libipkg/pkg_depends.c busybox.dev/archival/libipkg/pkg_depends.c
9267 --- busybox.old/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9268 +++ busybox.dev/archival/libipkg/pkg_depends.c 2007-01-22 13:41:06.000000000 +0100
9270 +/* pkg_depends.c - the itsy package management system
9274 + Copyright (C) 2002 Compaq Computer Corporation
9276 + This program is free software; you can redistribute it and/or
9277 + modify it under the terms of the GNU General Public License as
9278 + published by the Free Software Foundation; either version 2, or (at
9279 + your option) any later version.
9281 + This program is distributed in the hope that it will be useful, but
9282 + WITHOUT ANY WARRANTY; without even the implied warranty of
9283 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9284 + General Public License for more details.
9292 +#include "ipkg_utils.h"
9293 +#include "pkg_hash.h"
9294 +#include "ipkg_message.h"
9295 +#include "pkg_parse.h"
9296 +#include "hash_table.h"
9298 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9299 +static depend_t * depend_init(void);
9300 +static void depend_deinit(depend_t *d);
9301 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9302 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9303 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9305 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9307 + depend_t *depend = (depend_t *)cdata;
9308 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9314 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9316 + depend_t *depend = (depend_t *)cdata;
9318 + pkg_t * temp = pkg_new();
9320 + parseVersion(temp, depend->version);
9321 + comparison = pkg_compare_versions(pkg, temp);
9324 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9325 + __FUNCTION__, pkg->name, pkg->version,
9326 + depend, depend->constraint, depend->version,
9327 + comparison, version_constraints_satisfied(depend, pkg));
9329 + if (version_constraints_satisfied(depend, pkg))
9335 +/* returns ndependences or negative error value */
9336 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9337 + pkg_vec_t *unsatisfied, char *** unresolved)
9339 + pkg_t * satisfier_entry_pkg;
9340 + register int i, j, k, l;
9343 + abstract_pkg_t * ab_pkg;
9346 + * this is a setup to check for redundant/cyclic dependency checks,
9347 + * which are marked at the abstract_pkg level
9349 + if (!(ab_pkg = pkg->parent)) {
9350 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9351 + *unresolved = NULL;
9354 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9355 + *unresolved = NULL;
9358 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9362 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9364 + *unresolved = NULL;
9370 + /* foreach dependency */
9371 + for (i = 0; i < count; i++) {
9372 + compound_depend_t * compound_depend = &pkg->depends[i];
9373 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9375 + satisfier_entry_pkg = NULL;
9377 + if (compound_depend->type == GREEDY_DEPEND) {
9378 + /* foreach possible satisfier */
9379 + for (j = 0; j < compound_depend->possibility_count; j++) {
9380 + /* foreach provided_by, which includes the abstract_pkg itself */
9381 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9382 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9383 + int nposs = ab_provider_vec->len;
9384 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9385 + for (l = 0; l < nposs; l++) {
9386 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9387 + /* if no depends on this one, try the first package that Provides this one */
9388 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9392 + /* cruise this possiblity's pkg_vec looking for an installed version */
9393 + for (k = 0; k < test_vec->len; k++) {
9394 + pkg_t *pkg_scout = test_vec->pkgs[k];
9395 + /* not installed, and not already known about? */
9396 + if ((pkg_scout->state_want != SW_INSTALL)
9397 + && !pkg_scout->parent->dependencies_checked
9398 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9399 + char ** newstuff = NULL;
9401 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9402 + /* check for not-already-installed dependencies */
9403 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9407 + if (newstuff == NULL) {
9409 + for (l = 0; l < rc; l++) {
9410 + pkg_t *p = tmp_vec->pkgs[l];
9411 + if (p->state_want == SW_INSTALL)
9413 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9417 + pkg_vec_free (tmp_vec);
9419 + /* mark this one for installation */
9420 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9421 + pkg_vec_insert(unsatisfied, pkg_scout);
9424 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9435 + /* foreach possible satisfier, look for installed package */
9436 + for (j = 0; j < compound_depend->possibility_count; j++) {
9437 + /* foreach provided_by, which includes the abstract_pkg itself */
9438 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9439 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9440 + pkg_t *satisfying_pkg =
9441 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9442 + pkg_installed_and_constraint_satisfied,
9443 + dependence_to_satisfy, 1);
9444 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9445 + if (satisfying_pkg != NULL) {
9446 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9447 + satisfying_pkg = NULL;
9450 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9451 + if (satisfying_pkg != NULL) {
9457 + /* if nothing installed matches, then look for uninstalled satisfier */
9459 + /* foreach possible satisfier, look for installed package */
9460 + for (j = 0; j < compound_depend->possibility_count; j++) {
9461 + /* foreach provided_by, which includes the abstract_pkg itself */
9462 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9463 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9464 + pkg_t *satisfying_pkg =
9465 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9466 + pkg_constraint_satisfied,
9467 + dependence_to_satisfy, 1);
9468 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9469 + if (satisfying_pkg != NULL) {
9470 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9471 + satisfying_pkg = NULL;
9475 + /* user request overrides package recommendation */
9476 + if (satisfying_pkg != NULL
9477 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9478 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9479 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9480 + pkg->name, satisfying_pkg->name);
9484 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9485 + if (satisfying_pkg != NULL) {
9486 + satisfier_entry_pkg = satisfying_pkg;
9492 + /* we didn't find one, add something to the unsatisfied vector */
9494 + if (!satisfier_entry_pkg) {
9495 + /* failure to meet recommendations is not an error */
9496 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9497 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9499 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9500 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9503 + if (compound_depend->type == SUGGEST) {
9504 + /* just mention it politely */
9505 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9506 + pkg->name, satisfier_entry_pkg->name);
9508 + char ** newstuff = NULL;
9510 + if (satisfier_entry_pkg != pkg &&
9511 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9512 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9513 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9514 + satisfier_entry_pkg,
9517 + the_lost = merge_unresolved(the_lost, newstuff);
9523 + *unresolved = the_lost;
9525 + return unsatisfied->len;
9528 +/*checking for conflicts !in replaces
9529 + If a packages conflicts with another but is also replacing it, I should not consider it a
9531 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9533 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9536 + int replaces_count = pkg->replaces_count;
9537 + abstract_pkg_t **replaces;
9539 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9542 + replaces = pkg->replaces;
9544 + for (i = 0; i < replaces_count; i++) {
9545 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9546 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9555 +/* Abhaya: added support for conflicts */
9556 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9558 + pkg_vec_t * installed_conflicts, * test_vec;
9559 + compound_depend_t * conflicts;
9560 + depend_t ** possible_satisfiers;
9561 + depend_t * possible_satisfier;
9562 + register int i, j, k;
9564 + abstract_pkg_t * ab_pkg;
9565 + pkg_t **pkg_scouts;
9569 + * this is a setup to check for redundant/cyclic dependency checks,
9570 + * which are marked at the abstract_pkg level
9572 + if(!(ab_pkg = pkg->parent)){
9573 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9574 + return (pkg_vec_t *)NULL;
9577 + conflicts = pkg->conflicts;
9579 + return (pkg_vec_t *)NULL;
9581 + installed_conflicts = pkg_vec_alloc();
9583 + count = pkg->conflicts_count;
9587 + /* foreach conflict */
9588 + for(i = 0; i < pkg->conflicts_count; i++){
9590 + possible_satisfiers = conflicts->possibilities;
9592 + /* foreach possible satisfier */
9593 + for(j = 0; j < conflicts->possibility_count; j++){
9594 + possible_satisfier = possible_satisfiers[j];
9595 + if (!possible_satisfier)
9596 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9597 + if (!possible_satisfier->pkg)
9598 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9599 + test_vec = possible_satisfier->pkg->pkgs;
9601 + /* pkg_vec found, it is an actual package conflict
9602 + * cruise this possiblity's pkg_vec looking for an installed version */
9603 + pkg_scouts = test_vec->pkgs;
9604 + for(k = 0; k < test_vec->len; k++){
9605 + pkg_scout = pkg_scouts[k];
9607 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9610 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9611 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9612 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9613 + pkg_vec_insert(installed_conflicts, pkg_scout);
9622 + if (installed_conflicts->len)
9623 + return installed_conflicts;
9624 + pkg_vec_free(installed_conflicts);
9625 + return (pkg_vec_t *)NULL;
9628 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9633 + if(depends->constraint == NONE)
9638 + parseVersion(temp, depends->version);
9640 + comparison = pkg_compare_versions(pkg, temp);
9644 + if((depends->constraint == EARLIER) &&
9647 + else if((depends->constraint == LATER) &&
9650 + else if(comparison == 0)
9652 + else if((depends->constraint == LATER_EQUAL) &&
9653 + (comparison >= 0))
9655 + else if((depends->constraint == EARLIER_EQUAL) &&
9656 + (comparison <= 0))
9662 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9664 + abstract_pkg_t *apkg = depend->pkg;
9665 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9666 + int n_providers = provider_apkgs->len;
9667 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9668 + pkg_vec_t *pkg_vec;
9673 + for (i = 0; i < n_providers; i++) {
9674 + abstract_pkg_t *papkg = apkgs[i];
9675 + pkg_vec = papkg->pkgs;
9677 + n_pkgs = pkg_vec->len;
9678 + for (j = 0; j < n_pkgs; j++) {
9679 + pkg_t *pkg = pkg_vec->pkgs[j];
9680 + if (version_constraints_satisfied(depend, pkg)) {
9689 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9691 + abstract_pkg_t *apkg = depend->pkg;
9692 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9693 + int n_providers = provider_apkgs->len;
9694 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9699 + for (i = 0; i < n_providers; i++) {
9700 + abstract_pkg_t *papkg = apkgs[i];
9701 + pkg_vec_t *pkg_vec = papkg->pkgs;
9703 + n_pkgs = pkg_vec->len;
9704 + for (j = 0; j < n_pkgs; j++) {
9705 + pkg_t *pkg = pkg_vec->pkgs[j];
9706 + if (version_constraints_satisfied(depend, pkg)) {
9707 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9716 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9719 + pkg_t ** pkgs = vec->pkgs;
9721 + for(i = 0; i < vec->len; i++)
9722 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9723 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9724 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9732 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9733 + * the same abstract package and 0 otherwise.
9735 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9737 + abstract_pkg_t **provides = pkg->provides;
9738 + int provides_count = pkg->provides_count;
9739 + abstract_pkg_t **replacee_provides = replacee->provides;
9740 + int replacee_provides_count = replacee->provides_count;
9742 + for (i = 0; i < provides_count; i++) {
9743 + abstract_pkg_t *apkg = provides[i];
9744 + for (j = 0; j < replacee_provides_count; j++) {
9745 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9746 + if (apkg == replacee_apkg)
9755 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9756 + * and 0 otherwise.
9758 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9760 + abstract_pkg_t **provides = pkg->provides;
9761 + int provides_count = pkg->provides_count;
9763 + for (i = 0; i < provides_count; i++) {
9764 + if (provides[i] == providee)
9771 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9774 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9776 + abstract_pkg_t **replaces = pkg->replaces;
9777 + int replaces_count = pkg->replaces_count;
9778 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9779 + int replacee_provides_count = pkg->provides_count; */
9781 + for (i = 0; i < replaces_count; i++) {
9782 + abstract_pkg_t *abstract_replacee = replaces[i];
9783 + for (j = 0; j < replaces_count; j++) {
9784 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9785 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9786 + if (replacee->provides[j] == abstract_replacee)
9795 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9798 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9800 + compound_depend_t *conflicts = pkg->conflicts;
9801 + int conflicts_count = pkg->conflicts_count;
9803 + for (i = 0; i < conflicts_count; i++) {
9804 + int possibility_count = conflicts[i].possibility_count;
9805 + struct depend **possibilities = conflicts[i].possibilities;
9806 + for (j = 0; j < possibility_count; j++) {
9807 + if (possibilities[j]->pkg == conflictee) {
9816 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9817 + * conflictee's provides and 0 otherwise.
9819 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9821 + compound_depend_t *conflicts = pkg->conflicts;
9822 + int conflicts_count = pkg->conflicts_count;
9823 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9824 + int conflictee_provides_count = conflictee->provides_count;
9826 + int possibility_count;
9827 + struct depend **possibilities;
9828 + abstract_pkg_t *possibility ;
9830 + for (i = 0; i < conflicts_count; i++) {
9831 + possibility_count = conflicts[i].possibility_count;
9832 + possibilities = conflicts[i].possibilities;
9833 + for (j = 0; j < possibility_count; j++) {
9834 + possibility = possibilities[j]->pkg;
9835 + for (k = 0; k < conflictee_provides_count; k++) {
9836 + if (possibility == conflictee_provides[k]) {
9845 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9847 + int oldlen = 0, newlen = 0;
9849 + register int i, j;
9854 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9855 + while(newstuff && newstuff[newlen]) newlen++;
9857 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9858 + if (result == NULL) {
9859 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9863 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9864 + *(result + i) = *(newstuff + j);
9866 + *(result + i) = NULL;
9872 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9873 + * this is null terminated, no count is carried around
9875 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9879 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9882 + while(the_lost && the_lost[count]) count++;
9884 + count++; /* need one to hold the null */
9885 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9886 + if (resized == NULL) {
9887 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9890 + resized[count - 1] = strdup(depend_str);
9891 + resized[count] = NULL;
9896 +void printDepends(pkg_t * pkg)
9898 + register int i, j;
9899 + compound_depend_t * depend;
9902 + count = pkg->pre_depends_count + pkg->depends_count;
9904 + depend = pkg->depends;
9906 + fprintf(stderr, "Depends pointer is NULL\n");
9909 + for(i = 0; i < count; i++){
9910 + fprintf(stderr, "%s has %d possibilities:\n",
9911 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9912 + depend->possibility_count);
9913 + for(j = 0; j < depend->possibility_count; j++)
9914 + fprintf(stderr, "\t%s version %s (%d)\n",
9915 + depend->possibilities[j]->pkg->name,
9916 + depend->possibilities[j]->version,
9917 + depend->possibilities[j]->constraint);
9922 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9924 + register int i, j;
9926 + /* every pkg provides itself */
9927 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9929 + if (!pkg->provides_count)
9932 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9933 + if (pkg->provides == NULL) {
9934 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9937 + pkg->provides[0] = ab_pkg;
9939 + // if (strcmp(ab_pkg->name, pkg->name))
9940 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9942 + for(i = 0; i < pkg->provides_count; i++){
9943 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9945 + pkg->provides[i+1] = provided_abpkg;
9948 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9953 +/* Abhaya: added conflicts support */
9954 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9957 + compound_depend_t * conflicts;
9959 + if (!pkg->conflicts_count)
9962 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
9963 + pkg->conflicts_count);
9964 + if (conflicts == NULL) {
9965 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9968 + for (i = 0; i < pkg->conflicts_count; i++) {
9969 + conflicts->type = CONFLICTS;
9970 + parseDepends(conflicts, hash,
9971 + pkg->conflicts_str[i]);
9973 + for (j = 0; j < conflicts->possibility_count; j++) {
9974 + depend_t *possibility = conflicts->possibilities[j];
9975 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
9976 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
9984 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9986 + register int i, j;
9988 + if (!pkg->replaces_count)
9991 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
9992 + if (pkg->replaces == NULL) {
9993 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9997 + // if (strcmp(ab_pkg->name, pkg->name))
9998 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10000 + for(i = 0; i < pkg->replaces_count; i++){
10001 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10003 + pkg->replaces[i] = old_abpkg;
10006 + if (!old_abpkg->replaced_by)
10007 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10008 + if ( old_abpkg->replaced_by == NULL ){
10011 + /* if a package pkg both replaces and conflicts old_abpkg,
10012 + * then add it to the replaced_by vector so that old_abpkg
10013 + * will be upgraded to ab_pkg automatically */
10014 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10015 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10020 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10024 + compound_depend_t * depends;
10026 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10029 + if (0 && pkg->pre_depends_count)
10030 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10031 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10032 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10033 + if (depends == NULL) {
10034 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10039 + for(i = 0; i < pkg->pre_depends_count; i++){
10040 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10041 + if (0 && pkg->pre_depends_count)
10042 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10043 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10044 + depends->type = PREDEPEND;
10048 + for(i = 0; i < pkg->recommends_count; i++){
10049 + parseDepends(depends, hash, pkg->recommends_str[i]);
10050 + if (0 && pkg->recommends_count)
10051 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10052 + pkg->recommends_str[i], depends, depends->possibility_count);
10053 + depends->type = RECOMMEND;
10057 + for(i = 0; i < pkg->suggests_count; i++){
10058 + parseDepends(depends, hash, pkg->suggests_str[i]);
10059 + if (0 && pkg->suggests_count)
10060 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10061 + pkg->suggests_str[i], depends, depends->possibility_count);
10062 + depends->type = SUGGEST;
10066 + for(i = 0; i < pkg->depends_count; i++){
10067 + parseDepends(depends, hash, pkg->depends_str[i]);
10068 + if (0 && pkg->depends_count)
10069 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10070 + pkg->depends_str[i], depends, depends->possibility_count);
10077 + * pkg_depend_string: returns the depends string specified by index.
10078 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10079 + * [0,npredepends) -> returns pre_depends_str[index]
10080 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10081 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10082 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10084 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10086 + if (pkg_index < pkg->pre_depends_count) {
10087 + return pkg->pre_depends_str[pkg_index];
10089 + pkg_index -= pkg->pre_depends_count;
10091 + if (pkg_index < pkg->recommends_count) {
10092 + return pkg->recommends_str[pkg_index];
10094 + pkg_index -= pkg->recommends_count;
10096 + if (pkg_index < pkg->suggests_count) {
10097 + return pkg->suggests_str[pkg_index];
10099 + pkg_index -= pkg->suggests_count;
10101 + if (pkg_index < pkg->depends_count) {
10102 + return pkg->depends_str[pkg_index];
10104 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10108 +void freeDepends(pkg_t *pkg)
10112 + if (pkg == NULL || pkg->depends == NULL) {
10116 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10117 + for (i=0; i < pkg->depends->possibility_count; i++) {
10118 + depend_deinit(pkg->depends->possibilities[i]);
10120 + free(pkg->depends->possibilities);
10121 + free(pkg->depends);
10122 + pkg->depends = NULL;
10125 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10127 + compound_depend_t * depends;
10128 + int count, othercount;
10129 + register int i, j;
10130 + abstract_pkg_t * ab_depend;
10131 + abstract_pkg_t ** temp;
10133 + count = pkg->pre_depends_count + pkg->depends_count;
10134 + depends = pkg->depends;
10136 + if (0 && pkg->pre_depends_count)
10137 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10138 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10139 + for (i = 0; i < count; i++) {
10140 + if (0 && pkg->pre_depends_count)
10141 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10142 + for (j = 0; j < depends->possibility_count; j++){
10143 + ab_depend = depends->possibilities[j]->pkg;
10144 + if(!ab_depend->depended_upon_by)
10145 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10147 + temp = ab_depend->depended_upon_by;
10155 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10156 + (othercount + 1) * sizeof(abstract_pkg_t *));
10157 + /* the array may have moved */
10158 + temp = ab_depend->depended_upon_by + othercount;
10165 +static depend_t * depend_init(void)
10167 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10169 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10172 + d->constraint = NONE;
10173 + d->version = NULL;
10179 +static void depend_deinit(depend_t *d)
10184 +static int parseDepends(compound_depend_t *compound_depend,
10185 + hash_table_t * hash, char * depend_str)
10187 + char * pkg_name, buffer[2048];
10188 + int num_of_ors = 0;
10190 + register char * src, * dest;
10191 + depend_t ** possibilities;
10193 + /* first count the number of ored possibilities for satisfying dependency */
10194 + src = depend_str;
10196 + if(*src++ == '|')
10199 + compound_depend->type = DEPEND;
10201 + compound_depend->possibility_count = num_of_ors + 1;
10202 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10203 + if (!possibilities)
10205 + compound_depend->possibilities = possibilities;
10207 + src = depend_str;
10208 + for(i = 0; i < num_of_ors + 1; i++){
10209 + possibilities[i] = depend_init();
10210 + if (!possibilities[i])
10212 + /* gobble up just the name first */
10215 + !isspace(*src) &&
10219 + *dest++ = *src++;
10221 + pkg_name = trim_alloc(buffer);
10222 + if (pkg_name == NULL )
10225 + /* now look at possible version info */
10227 + /* skip to next chars */
10228 + if(isspace(*src))
10229 + while(*src && isspace(*src)) src++;
10231 + /* extract constraint and version */
10234 + if(!strncmp(src, "<<", 2)){
10235 + possibilities[i]->constraint = EARLIER;
10238 + else if(!strncmp(src, "<=", 2)){
10239 + possibilities[i]->constraint = EARLIER_EQUAL;
10242 + else if(!strncmp(src, ">=", 2)){
10243 + possibilities[i]->constraint = LATER_EQUAL;
10246 + else if(!strncmp(src, ">>", 2)){
10247 + possibilities[i]->constraint = LATER;
10250 + else if(!strncmp(src, "=", 1)){
10251 + possibilities[i]->constraint = EQUAL;
10254 + /* should these be here to support deprecated designations; dpkg does */
10255 + else if(!strncmp(src, "<", 1)){
10256 + possibilities[i]->constraint = EARLIER_EQUAL;
10259 + else if(!strncmp(src, ">", 1)){
10260 + possibilities[i]->constraint = LATER_EQUAL;
10264 + /* now we have any constraint, pass space to version string */
10265 + while(isspace(*src)) src++;
10267 + /* this would be the version string */
10269 + while(*src && *src != ')')
10270 + *dest++ = *src++;
10273 + possibilities[i]->version = trim_alloc(buffer);
10274 + /* fprintf(stderr, "let's print the depends version string:");
10275 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10276 + if (possibilities[i]->version == NULL )
10281 + /* hook up the dependency to its abstract pkg */
10282 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10286 + /* now get past the ) and any possible | chars */
10288 + (isspace(*src) ||
10294 + compound_depend->type = GREEDY_DEPEND;
10301 diff -urN busybox.old/archival/libipkg/pkg_depends.h busybox.dev/archival/libipkg/pkg_depends.h
10302 --- busybox.old/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10303 +++ busybox.dev/archival/libipkg/pkg_depends.h 2007-01-22 13:41:06.000000000 +0100
10305 +/* pkg_depends.h - the itsy package management system
10309 + Copyright (C) 2002 Compaq Computer Corporation
10311 + This program is free software; you can redistribute it and/or
10312 + modify it under the terms of the GNU General Public License as
10313 + published by the Free Software Foundation; either version 2, or (at
10314 + your option) any later version.
10316 + This program is distributed in the hope that it will be useful, but
10317 + WITHOUT ANY WARRANTY; without even the implied warranty of
10318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10319 + General Public License for more details.
10322 +#ifndef PKG_DEPENDS_H
10323 +#define PKG_DEPENDS_H
10326 +#include "pkg_hash.h"
10328 +enum depend_type {
10336 +typedef enum depend_type depend_type_t;
10338 +enum version_constraint {
10346 +typedef enum version_constraint version_constraint_t;
10349 + version_constraint_t constraint;
10351 + abstract_pkg_t * pkg;
10353 +typedef struct depend depend_t;
10355 +struct compound_depend{
10356 + depend_type_t type;
10357 + int possibility_count;
10358 + struct depend ** possibilities;
10360 +typedef struct compound_depend compound_depend_t;
10362 +#include "hash_table.h"
10364 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10365 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10366 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10367 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10370 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10371 + * the same abstract package and 0 otherwise.
10373 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10376 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10379 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10382 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10385 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10388 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10391 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10394 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10397 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10399 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10400 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10401 +void freeDepends(pkg_t *pkg);
10402 +void printDepends(pkg_t * pkg);
10403 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10404 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10405 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10406 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10407 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10410 diff -urN busybox.old/archival/libipkg/pkg_dest.c busybox.dev/archival/libipkg/pkg_dest.c
10411 --- busybox.old/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10412 +++ busybox.dev/archival/libipkg/pkg_dest.c 2007-01-22 13:41:03.000000000 +0100
10414 +/* pkg_dest.c - the itsy package management system
10418 + Copyright (C) 2001 University of Southern California
10420 + This program is free software; you can redistribute it and/or
10421 + modify it under the terms of the GNU General Public License as
10422 + published by the Free Software Foundation; either version 2, or (at
10423 + your option) any later version.
10425 + This program is distributed in the hope that it will be useful, but
10426 + WITHOUT ANY WARRANTY; without even the implied warranty of
10427 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10428 + General Public License for more details.
10433 +#include "pkg_dest.h"
10434 +#include "file_util.h"
10435 +#include "str_util.h"
10436 +#include "sprintf_alloc.h"
10438 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10440 + dest->name = strdup(name);
10442 + /* Guarantee that dest->root_dir ends with a '/' */
10443 + if (str_ends_with(root_dir, "/")) {
10444 + dest->root_dir = strdup(root_dir);
10446 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10448 + file_mkdir_hier(dest->root_dir, 0755);
10450 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10451 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10452 + file_mkdir_hier(dest->ipkg_dir, 0755);
10454 + if (str_starts_with (lists_dir, "/"))
10455 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10457 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10459 + file_mkdir_hier(dest->lists_dir, 0755);
10461 + sprintf_alloc(&dest->info_dir, "%s/%s",
10462 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10463 + file_mkdir_hier(dest->info_dir, 0755);
10465 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10466 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10468 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10469 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10471 + dest->status_file = NULL;
10476 +void pkg_dest_deinit(pkg_dest_t *dest)
10478 + free(dest->name);
10479 + dest->name = NULL;
10481 + free(dest->root_dir);
10482 + dest->root_dir = NULL;
10484 + free(dest->ipkg_dir);
10485 + dest->ipkg_dir = NULL;
10487 + free(dest->lists_dir);
10488 + dest->lists_dir = NULL;
10490 + free(dest->info_dir);
10491 + dest->info_dir = NULL;
10493 + free(dest->status_file_name);
10494 + dest->status_file_name = NULL;
10496 + free(dest->status_file_tmp_name);
10497 + dest->status_file_tmp_name = NULL;
10499 + if (dest->status_file) {
10500 + fclose(dest->status_file);
10502 + dest->status_file = NULL;
10504 + dest->root_dir = NULL;
10506 diff -urN busybox.old/archival/libipkg/pkg_dest.h busybox.dev/archival/libipkg/pkg_dest.h
10507 --- busybox.old/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10508 +++ busybox.dev/archival/libipkg/pkg_dest.h 2007-01-22 13:41:03.000000000 +0100
10510 +/* pkg_dest.h - the itsy package management system
10514 + Copyright (C) 2001 University of Southern California
10516 + This program is free software; you can redistribute it and/or
10517 + modify it under the terms of the GNU General Public License as
10518 + published by the Free Software Foundation; either version 2, or (at
10519 + your option) any later version.
10521 + This program is distributed in the hope that it will be useful, but
10522 + WITHOUT ANY WARRANTY; without even the implied warranty of
10523 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10524 + General Public License for more details.
10527 +#ifndef PKG_DEST_H
10528 +#define PKG_DEST_H
10530 +typedef struct pkg_dest pkg_dest_t;
10538 + char *status_file_name;
10539 + char *status_file_tmp_name;
10540 + FILE *status_file;
10543 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10544 +void pkg_dest_deinit(pkg_dest_t *dest);
10548 diff -urN busybox.old/archival/libipkg/pkg_dest_list.c busybox.dev/archival/libipkg/pkg_dest_list.c
10549 --- busybox.old/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10550 +++ busybox.dev/archival/libipkg/pkg_dest_list.c 2007-01-22 13:41:03.000000000 +0100
10552 +/* pkg_dest_list.c - the itsy package management system
10556 + Copyright (C) 2001 University of Southern California
10558 + This program is free software; you can redistribute it and/or
10559 + modify it under the terms of the GNU General Public License as
10560 + published by the Free Software Foundation; either version 2, or (at
10561 + your option) any later version.
10563 + This program is distributed in the hope that it will be useful, but
10564 + WITHOUT ANY WARRANTY; without even the implied warranty of
10565 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10566 + General Public License for more details.
10571 +#include "pkg_dest.h"
10572 +#include "void_list.h"
10573 +#include "pkg_dest_list.h"
10575 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10577 + return void_list_elt_init((void_list_elt_t *) elt, data);
10580 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10582 + void_list_elt_deinit((void_list_elt_t *) elt);
10585 +int pkg_dest_list_init(pkg_dest_list_t *list)
10587 + return void_list_init((void_list_t *) list);
10590 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10592 + pkg_dest_list_elt_t *iter;
10593 + pkg_dest_t *pkg_dest;
10595 + for (iter = list->head; iter; iter = iter->next) {
10596 + pkg_dest = iter->data;
10597 + pkg_dest_deinit(pkg_dest);
10599 + /* malloced in pkg_dest_list_append */
10601 + iter->data = NULL;
10603 + void_list_deinit((void_list_t *) list);
10606 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10607 + const char *root_dir,const char *lists_dir)
10610 + pkg_dest_t *pkg_dest;
10612 + /* freed in plg_dest_list_deinit */
10613 + pkg_dest = malloc(sizeof(pkg_dest_t));
10614 + if (pkg_dest == NULL) {
10615 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10619 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10620 + err = void_list_append((void_list_t *) list, pkg_dest);
10628 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10630 + return void_list_push((void_list_t *) list, data);
10633 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10635 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10637 diff -urN busybox.old/archival/libipkg/pkg_dest_list.h busybox.dev/archival/libipkg/pkg_dest_list.h
10638 --- busybox.old/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10639 +++ busybox.dev/archival/libipkg/pkg_dest_list.h 2007-01-22 13:41:03.000000000 +0100
10641 +/* pkg_dest_list.h - the itsy package management system
10645 + Copyright (C) 2001 University of Southern California
10647 + This program is free software; you can redistribute it and/or
10648 + modify it under the terms of the GNU General Public License as
10649 + published by the Free Software Foundation; either version 2, or (at
10650 + your option) any later version.
10652 + This program is distributed in the hope that it will be useful, but
10653 + WITHOUT ANY WARRANTY; without even the implied warranty of
10654 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10655 + General Public License for more details.
10658 +#ifndef PKG_DEST_LIST_H
10659 +#define PKG_DEST_LIST_H
10661 +#include "pkg_dest.h"
10663 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10664 +struct pkg_dest_list_elt
10666 + pkg_dest_list_elt_t *next;
10667 + pkg_dest_t *data;
10670 +typedef struct pkg_dest_list pkg_dest_list_t;
10671 +struct pkg_dest_list
10673 + pkg_dest_list_elt_t pre_head;
10674 + pkg_dest_list_elt_t *head;
10675 + pkg_dest_list_elt_t *tail;
10678 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10679 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10681 +int pkg_dest_list_init(pkg_dest_list_t *list);
10682 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10684 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10685 + const char *root_dir,const char* lists_dir);
10686 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10687 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10691 diff -urN busybox.old/archival/libipkg/pkg_extract.c busybox.dev/archival/libipkg/pkg_extract.c
10692 --- busybox.old/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10693 +++ busybox.dev/archival/libipkg/pkg_extract.c 2007-01-22 13:41:03.000000000 +0100
10695 +/* pkg_extract.c - the itsy package management system
10699 + Copyright (C) 2001 University of Southern California
10701 + This program is free software; you can redistribute it and/or
10702 + modify it under the terms of the GNU General Public License as
10703 + published by the Free Software Foundation; either version 2, or (at
10704 + your option) any later version.
10706 + This program is distributed in the hope that it will be useful, but
10707 + WITHOUT ANY WARRANTY; without even the implied warranty of
10708 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10709 + General Public License for more details.
10713 +#include <errno.h>
10714 +#include <fcntl.h>
10715 +#include <stdio.h>
10717 +#include "pkg_extract.h"
10719 +#include "libbb.h"
10720 +#include "file_util.h"
10721 +#include "sprintf_alloc.h"
10722 +#include "unarchive.h"
10724 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10725 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10726 +#define IPKG_CONTROL_FILE "control"
10728 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10730 + archive_handle_t *archive;
10733 + sprintf_alloc(&path, "%s/", dir);
10734 + archive = init_handle();
10735 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10736 + archive->filter = filter_accept_list;
10737 + llist_add_to(&(archive->accept), (char *)filename);
10738 + archive->buffer = path;
10739 + archive->action_data = data_extract_all_prefix;
10740 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10741 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10742 + close(archive->src_fd);
10743 + free(archive->accept);
10748 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10750 + unsigned int size = strlen(archive->file_header->name) + 2;
10752 + if (archive->buffer == NULL) {
10753 + archive->buffer = xmalloc(size);
10754 + strcpy(archive->buffer, archive->file_header->name);
10756 + size += strlen(archive->buffer);
10757 + archive->buffer = xrealloc(archive->buffer, size);
10758 + strcat(archive->buffer, archive->file_header->name);
10760 + strcat(archive->buffer, "\n");
10761 + data_skip(archive);
10764 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10766 + archive_handle_t *archive;
10769 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10770 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10771 + archive = init_handle();
10772 + archive->src_fd = xopen(name, O_RDONLY);
10773 + archive->filter = filter_accept_list;
10774 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10775 + archive->action_data = data_extract_to_buffer;
10776 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10777 + close(archive->src_fd);
10778 + fputs(archive->buffer, stream);
10779 + free(archive->buffer);
10780 + free(archive->accept);
10787 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10789 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10792 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10794 + archive_handle_t *archive;
10798 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10799 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10800 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10801 + archive = init_handle();
10802 + archive->src_fd = xopen(name, O_RDONLY);
10803 + archive->filter = filter_accept_all;
10804 + archive->buffer = path;
10805 + archive->action_data = data_extract_all_prefix;
10806 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10807 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10808 + close(archive->src_fd);
10816 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10818 + archive_handle_t *archive;
10822 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10823 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10824 + sprintf_alloc(&path, "%s/", dir);
10825 + archive = init_handle();
10826 + archive->src_fd = xopen(name, O_RDONLY);
10827 + archive->filter = filter_accept_all;
10828 + archive->buffer = path;
10829 + archive->action_data = data_extract_all_prefix;
10830 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10831 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10832 + close(archive->src_fd);
10840 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10843 + char *line, *data_file;
10847 + file = fopen(file_name, "w");
10848 + if (file == NULL) {
10849 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10850 + __FUNCTION__, file_name);
10855 + if (pkg->installed_files) {
10856 + str_list_elt_t *elt;
10857 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10858 + fprintf(file, "%s\n", elt->data);
10861 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10868 + /* Fixup data file names by removing the initial '.' */
10871 + line = file_read_line_alloc(tmp);
10872 + if (line == NULL) {
10876 + data_file = line;
10877 + if (*data_file == '.') {
10881 + if (*data_file != '/') {
10882 + fputs("/", file);
10885 + /* I have no idea why, but this is what dpkg does */
10886 + if (strcmp(data_file, "/\n") == 0) {
10887 + fputs("/.\n", file);
10889 + fputs(data_file, file);
10899 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10901 + archive_handle_t *archive;
10904 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10905 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10906 + archive = init_handle();
10907 + archive->src_fd = xopen(name, O_RDONLY);
10908 + archive->filter = filter_accept_all;
10909 + archive->action_data = data_extract_file_name_to_buffer;
10910 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10911 + close(archive->src_fd);
10912 + fputs(archive->buffer, file);
10913 + free(archive->buffer);
10919 diff -urN busybox.old/archival/libipkg/pkg_extract.h busybox.dev/archival/libipkg/pkg_extract.h
10920 --- busybox.old/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
10921 +++ busybox.dev/archival/libipkg/pkg_extract.h 2007-01-22 13:41:03.000000000 +0100
10923 +/* pkg_extract.c - the itsy package management system
10927 + Copyright (C) 2001 University of Southern California
10929 + This program is free software; you can redistribute it and/or
10930 + modify it under the terms of the GNU General Public License as
10931 + published by the Free Software Foundation; either version 2, or (at
10932 + your option) any later version.
10934 + This program is distributed in the hope that it will be useful, but
10935 + WITHOUT ANY WARRANTY; without even the implied warranty of
10936 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10937 + General Public License for more details.
10940 +#ifndef PKG_EXTRACT_H
10941 +#define PKG_EXTRACT_H
10945 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10946 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10947 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
10949 + const char *prefix);
10950 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
10951 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
10952 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
10955 diff -urN busybox.old/archival/libipkg/pkg.h busybox.dev/archival/libipkg/pkg.h
10956 --- busybox.old/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
10957 +++ busybox.dev/archival/libipkg/pkg.h 2007-01-22 13:41:06.000000000 +0100
10959 +/* pkg.h - the itsy package management system
10963 + Copyright (C) 2001 University of Southern California
10965 + This program is free software; you can redistribute it and/or
10966 + modify it under the terms of the GNU General Public License as
10967 + published by the Free Software Foundation; either version 2, or (at
10968 + your option) any later version.
10970 + This program is distributed in the hope that it will be useful, but
10971 + WITHOUT ANY WARRANTY; without even the implied warranty of
10972 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10973 + General Public License for more details.
10979 +#include <sys/types.h>
10980 +#include <sys/stat.h>
10981 +#include <unistd.h>
10983 +#include "pkg_vec.h"
10984 +#include "str_list.h"
10985 +#include "pkg_src.h"
10986 +#include "pkg_dest.h"
10987 +#include "ipkg_conf.h"
10988 +#include "conffile_list.h"
10993 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
10995 +/* I think "Size" is currently the shortest field name */
10996 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
10998 +enum pkg_state_want
11004 + SW_LAST_STATE_WANT
11006 +typedef enum pkg_state_want pkg_state_want_t;
11008 +enum pkg_state_flag
11011 + SF_REINSTREQ = 1,
11012 + SF_HOLD = 2, /* do not upgrade version */
11013 + SF_REPLACE = 4, /* replace this package */
11014 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11015 + SF_PREFER = 16, /* prefer this version */
11016 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11017 + SF_MARKED = 64, /* temporary mark */
11018 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11020 + SF_LAST_STATE_FLAG
11022 +typedef enum pkg_state_flag pkg_state_flag_t;
11023 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11025 +enum pkg_state_status
11027 + SS_NOT_INSTALLED = 1,
11029 + SS_HALF_CONFIGURED,
11031 + SS_HALF_INSTALLED,
11033 + SS_POST_INST_FAILED,
11034 + SS_REMOVAL_FAILED,
11035 + SS_LAST_STATE_STATUS
11037 +typedef enum pkg_state_status pkg_state_status_t;
11039 +struct abstract_pkg{
11041 + int dependencies_checked;
11042 + pkg_vec_t * pkgs;
11043 + pkg_state_status_t state_status;
11044 + pkg_state_flag_t state_flag;
11045 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11046 + abstract_pkg_vec_t * provided_by;
11047 + abstract_pkg_vec_t * replaced_by;
11050 +#include "pkg_depends.h"
11052 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11054 + The 3 version fields should go into a single version struct. (This
11055 + is especially important since, currently, pkg->version can easily
11056 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11057 + distinct. This has been the source of multiple bugs.
11059 + The 3 state fields could possibly also go into their own struct.
11061 + All fields which deal with lists of packages, (Depends,
11062 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11063 + be handled by a single struct in pkg_t
11065 + All string fields for which there is a small set of possible
11066 + values, (section, maintainer, architecture, maybe version?), that
11067 + are reused among different packages -- for all such packages we
11068 + should move from "char *"s to some atom datatype to share data
11069 + storage and use less memory. We might even do reference counting,
11070 + but probably not since most often we only create new pkg_t structs,
11071 + we don't often free them. */
11075 + unsigned long epoch;
11078 + char *familiar_revision;
11080 + pkg_dest_t *dest;
11081 + char *architecture;
11083 + char *maintainer;
11084 + char *description;
11085 + pkg_state_want_t state_want;
11086 + pkg_state_flag_t state_flag;
11087 + pkg_state_status_t state_status;
11088 + char **depends_str;
11089 + int depends_count;
11090 + char **pre_depends_str;
11091 + int pre_depends_count;
11092 + char **recommends_str;
11093 + int recommends_count;
11094 + char **suggests_str;
11095 + int suggests_count;
11096 + compound_depend_t * depends;
11098 + /* Abhaya: new conflicts */
11099 + char **conflicts_str;
11100 + compound_depend_t * conflicts;
11101 + int conflicts_count;
11103 + char **replaces_str;
11104 + int replaces_count;
11105 + abstract_pkg_t ** replaces;
11107 + char **provides_str;
11108 + int provides_count;
11109 + abstract_pkg_t ** provides;
11111 + abstract_pkg_t *parent;
11113 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11116 + char *local_filename;
11118 + char *tmp_unpack_dir;
11121 + char *installed_size;
11124 + conffile_list_t conffiles;
11125 + time_t installed_time;
11126 + /* As pointer for lazy evaluation */
11127 + str_list_t *installed_files;
11128 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11129 + mechanism to avoid the problem here, (which is that the
11130 + installed_files list was being freed from an inner loop while
11131 + still being used within an outer loop. */
11132 + int installed_files_ref_cnt;
11134 + int arch_priority;
11135 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11136 + int provided_by_hand;
11139 +pkg_t *pkg_new(void);
11140 +int pkg_init(pkg_t *pkg);
11141 +void pkg_deinit(pkg_t *pkg);
11142 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11143 +abstract_pkg_t *abstract_pkg_new(void);
11144 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11147 + * merges fields from newpkg into oldpkg.
11148 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11150 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11152 +char *pkg_version_str_alloc(pkg_t *pkg);
11154 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11155 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11156 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11158 +char * pkg_formatted_info(pkg_t *pkg );
11159 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11161 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11163 +void pkg_print_info(pkg_t *pkg, FILE *file);
11164 +void pkg_print_status(pkg_t * pkg, FILE * file);
11165 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11166 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11167 +int pkg_free_installed_files(pkg_t *pkg);
11168 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11169 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11170 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11171 + const char *script, const char *args);
11173 +/* enum mappings */
11174 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11175 +pkg_state_want_t pkg_state_want_from_str(char *str);
11176 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11177 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11178 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11179 +pkg_state_status_t pkg_state_status_from_str(char *str);
11181 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11183 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11184 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11185 +int pkg_free_installed_files(pkg_t *pkg);
11187 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11188 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11191 diff -urN busybox.old/archival/libipkg/pkg_hash.c busybox.dev/archival/libipkg/pkg_hash.c
11192 --- busybox.old/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11193 +++ busybox.dev/archival/libipkg/pkg_hash.c 2007-01-22 13:41:06.000000000 +0100
11195 +/* ipkg_hash.c - the itsy package management system
11199 + Copyright (C) 2002 Compaq Computer Corporation
11201 + This program is free software; you can redistribute it and/or
11202 + modify it under the terms of the GNU General Public License as
11203 + published by the Free Software Foundation; either version 2, or (at
11204 + your option) any later version.
11206 + This program is distributed in the hope that it will be useful, but
11207 + WITHOUT ANY WARRANTY; without even the implied warranty of
11208 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11209 + General Public License for more details.
11213 +#include <errno.h>
11214 +#include <ctype.h>
11215 +#include <stdlib.h>
11216 +#include <string.h>
11218 +#include "hash_table.h"
11220 +#include "ipkg_message.h"
11221 +#include "pkg_vec.h"
11222 +#include "pkg_hash.h"
11223 +#include "pkg_parse.h"
11224 +#include "ipkg_utils.h"
11226 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11229 + * this will talk to both feeds-lists files and installed status files
11232 + * hash_table_t hash;
11233 + * pkg_hash_init(name, &hash, 1000);
11234 + * pkg_hash_add_from_file(<feed filename>);
11236 + * the query function is just there as a shell to prove to me that this
11237 + * sort of works, but isn't far from doing something useful
11240 + * modified: CDW 3 Jan. 2002
11245 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11247 + return hash_table_init(name, hash, len);
11250 +void pkg_hash_deinit(hash_table_t *hash)
11252 + hash_table_deinit(hash);
11256 +/* Find the default arch for a given package status file if none is given. */
11257 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11259 + nv_pair_list_elt_t *l;
11260 + char *def_arch = HOST_CPU_STR; /* Default arch */
11261 + int def_prio = 0; /* Other archs override this */
11263 + l = conf->arch_list.head;
11266 + nv_pair_t *nv = l->data;
11267 + int priority = strtol(nv->value, NULL, 0);
11269 + /* Check if this arch has higher priority, and is valid */
11270 + if ((priority > def_prio) &&
11271 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11272 + /* Our new default */
11273 + def_prio = priority;
11274 + def_arch = nv->name;
11279 + return strdup(def_arch);
11282 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11283 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11285 + hash_table_t *hash = &conf->pkg_hash;
11287 + char **raw_start;
11290 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11294 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11299 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11300 + if (!pkg->architecture) {
11301 + char *version_str = pkg_version_str_alloc(pkg);
11302 + pkg->architecture = pkg_get_default_arch(conf);
11303 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11304 + pkg->name, version_str, pkg->architecture);
11305 + free(version_str);
11307 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11313 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11314 + memory after read_raw_pkgs_from_file */
11323 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11325 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11328 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11330 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11333 + return apkg->provided_by;
11337 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11338 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11341 + int nprovides = 0;
11342 + int nmatching = 0;
11343 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11344 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11345 + abstract_pkg_vec_t *provided_apkg_vec;
11346 + abstract_pkg_t **provided_apkgs;
11347 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11348 + pkg_t *latest_installed_parent = NULL;
11349 + pkg_t *latest_matching = NULL;
11350 + pkg_t *held_pkg = NULL;
11351 + pkg_t *good_pkg_by_name = NULL;
11353 + if (matching_apkgs == NULL || providers == NULL ||
11354 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11357 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11359 + provided_apkg_vec = apkg->provided_by;
11360 + nprovides = provided_apkg_vec->len;
11361 + provided_apkgs = provided_apkg_vec->pkgs;
11362 + if (nprovides > 1)
11363 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11365 + /* accumulate all the providers */
11366 + for (i = 0; i < nprovides; i++) {
11367 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11368 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11369 + abstract_pkg_vec_insert(providers, provider_apkg);
11371 + nprovides = providers->len;
11373 + for (i = 0; i < nprovides; i++) {
11374 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11375 + abstract_pkg_t *replacement_apkg = NULL;
11378 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11379 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11380 + if (provider_apkg->replaced_by->len > 1) {
11381 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11382 + provider_apkg->name, replacement_apkg->name);
11386 + if (replacement_apkg)
11387 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11388 + replacement_apkg->name, provider_apkg->name);
11390 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11391 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11394 + provider_apkg = replacement_apkg;
11397 + if (!(vec = provider_apkg->pkgs)) {
11398 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11403 + /* now check for supported architecture */
11405 + int max_count = 0;
11407 + /* count packages matching max arch priority and keep track of last one */
11408 + for (j = 0; j < vec->len; j++) {
11409 + pkg_t *maybe = vec->pkgs[j];
11410 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11411 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11412 + if (maybe->arch_priority > 0) {
11414 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11415 + pkg_vec_insert(matching_pkgs, maybe);
11421 + if (matching_pkgs->len > 1)
11422 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11423 + if (matching_apkgs->len > 1)
11424 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11426 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11427 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11428 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11429 + Until now I always got the latest, but that breaks the downgrade option.
11430 + If I stop at the first one, I would probably miss the new ones
11431 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11432 + or from a Packages feed.
11433 + 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*/
11436 + for (i = 0; i < matching_pkgs->len; i++) {
11437 + pkg_t *matching = matching_pkgs->pkgs[i];
11438 + if (constraint_fcn(matching, cdata)) { /* We found it */
11439 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11440 + good_pkg_by_name = matching;
11441 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11447 + for (i = 0; i < matching_pkgs->len; i++) {
11448 + pkg_t *matching = matching_pkgs->pkgs[i];
11449 + latest_matching = matching;
11450 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11451 + latest_installed_parent = matching;
11452 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11454 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11455 + held_pkg->name, matching->name);
11456 + held_pkg = matching;
11460 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11461 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11462 + apkg->name, matching_apkgs->len);
11463 + for (i = 0; i < matching_apkgs->len; i++) {
11464 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11465 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11467 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11470 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11471 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11472 + __FUNCTION__, apkg->name, matching_pkgs->len);
11473 + for (i = 0; i < matching_pkgs->len; i++) {
11474 + pkg_t *matching = matching_pkgs->pkgs[i];
11475 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11476 + matching->name, matching->version, matching->architecture);
11480 + nmatching = matching_apkgs->len;
11482 + pkg_vec_free(matching_pkgs);
11483 + abstract_pkg_vec_free(matching_apkgs);
11484 + abstract_pkg_vec_free(providers);
11486 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11487 + return good_pkg_by_name;
11490 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11493 + if (latest_installed_parent) {
11494 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11495 + return latest_installed_parent;
11497 + if (nmatching > 1) {
11498 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11501 + if (latest_matching) {
11502 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11503 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11504 + return latest_matching;
11509 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11511 + const char *name = (const char *)cdata;
11512 + if (strcmp(pkg->name, name) == 0)
11518 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11520 + hash_table_t *hash = &conf->pkg_hash;
11521 + abstract_pkg_t *apkg = NULL;
11523 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11526 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11530 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11531 + const char *pkg_name,
11532 + const char * version)
11536 + char *version_str = NULL;
11538 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11541 + for(i = 0; i < vec->len; i++) {
11542 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11543 + if(!strcmp(version_str, version)) {
11544 + free(version_str);
11547 + free(version_str);
11550 + if(i == vec->len)
11553 + return vec->pkgs[i];
11556 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11557 + const char *pkg_name,
11558 + pkg_dest_t *dest)
11563 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11567 + for(i = 0; i < vec->len; i++)
11568 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11569 + return vec->pkgs[i];
11574 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11575 + const char *pkg_name)
11580 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11584 + for(i = 0; i < vec->len; i++)
11585 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11586 + return vec->pkgs[i];
11592 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11594 + abstract_pkg_t * ab_pkg;
11596 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11600 + if (ab_pkg->pkgs) {
11601 + return ab_pkg->pkgs;
11602 + } else if (ab_pkg->provided_by) {
11603 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11604 + if (abpkg != NULL){
11605 + return abpkg->pkgs;
11607 + return ab_pkg->pkgs;
11614 +static int pkg_compare_names(const void *p1, const void *p2)
11616 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11617 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11618 + if (pkg1->name == NULL)
11620 + if (pkg2->name == NULL)
11622 + return(strcmp(pkg1->name, pkg2->name));
11626 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11629 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11630 + pkg_vec_t *all = (pkg_vec_t *)data;
11631 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11633 + for (j = 0; j < pkg_vec->len; j++) {
11634 + pkg_t *pkg = pkg_vec->pkgs[j];
11635 + pkg_vec_insert(all, pkg);
11640 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11642 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11643 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11646 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11648 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11649 + pkg_vec_t *all = (pkg_vec_t *)data;
11650 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11653 + for (j = 0; j < pkg_vec->len; j++) {
11654 + pkg_t *pkg = pkg_vec->pkgs[j];
11655 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11656 + pkg_vec_insert(all, pkg);
11661 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11663 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11664 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11667 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11671 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11672 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11673 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11674 + fprintf(stdout, "%s\n", ab_pkg->name);
11676 + if (dependents != NULL)
11677 + while (dependents [i] != NULL)
11678 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11679 + dependents = ab_pkg->provided_by->pkgs;
11681 + if (dependents != NULL)
11682 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11683 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11684 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11687 + while (i < pkg->depends_count)
11688 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11691 +void pkg_hash_dump(hash_table_t *hash, void *data)
11694 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11695 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11696 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11699 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11701 + abstract_pkg_t * ab_pkg;
11703 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11704 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11709 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11711 + abstract_pkg_t * ab_pkg;
11712 + int arch_priority;
11717 + arch_priority = pkg->arch_priority;
11719 + if (buildDepends(hash, pkg)<0){
11720 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11723 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11725 + if (set_status) {
11726 + if (pkg->state_status == SS_INSTALLED) {
11727 + ab_pkg->state_status = SS_INSTALLED;
11728 + } else if (pkg->state_status == SS_UNPACKED) {
11729 + ab_pkg->state_status = SS_UNPACKED;
11733 + if(!ab_pkg->pkgs)
11734 + ab_pkg->pkgs = pkg_vec_alloc();
11736 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11737 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11738 + pkg->parent = ab_pkg;
11740 + if (buildProvides(hash, ab_pkg, pkg)<0){
11741 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11744 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11745 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11746 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11749 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11750 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11754 + buildDependedUponBy(pkg, ab_pkg);
11759 + * this will assume that we've already determined that
11760 + * the abstract pkg doesn't exist, 'cause we should know these things...
11762 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11764 + abstract_pkg_t * ab_pkg;
11766 + ab_pkg = abstract_pkg_new();
11767 + if (ab_pkg == NULL) { return NULL; }
11769 + ab_pkg->name = strdup(pkg_name);
11770 + hash_table_insert(hash, pkg_name, ab_pkg);
11776 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11778 + hash_table_t *file_hash = &conf->file_hash;
11780 + return hash_table_get(file_hash, file_name);
11783 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11785 + hash_table_t *file_hash = &conf->file_hash;
11786 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11787 + int file_name_len = strlen(file_name);
11789 + if (file_name[file_name_len -1] == '/')
11792 + if (conf->offline_root) {
11793 + int len = strlen(conf->offline_root);
11794 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11795 + file_name += len;
11799 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11800 + hash_table_insert(file_hash, file_name, owning_pkg);
11801 + if (old_owning_pkg) {
11802 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11803 + /* mark this package to have its filelist written */
11804 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11805 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11811 diff -urN busybox.old/archival/libipkg/pkg_hash.h busybox.dev/archival/libipkg/pkg_hash.h
11812 --- busybox.old/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
11813 +++ busybox.dev/archival/libipkg/pkg_hash.h 2007-01-22 13:41:03.000000000 +0100
11815 +/* pkg_hash.h - the itsy package management system
11819 + Copyright (C) 2002 Compaq Computer Corporation
11821 + This program is free software; you can redistribute it and/or
11822 + modify it under the terms of the GNU General Public License as
11823 + published by the Free Software Foundation; either version 2, or (at
11824 + your option) any later version.
11826 + This program is distributed in the hope that it will be useful, but
11827 + WITHOUT ANY WARRANTY; without even the implied warranty of
11828 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11829 + General Public License for more details.
11832 +#ifndef PKG_HASH_H
11833 +#define PKG_HASH_H
11836 +#include "pkg_vec.h"
11837 +#include "hash_table.h"
11840 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11841 +void pkg_hash_deinit(hash_table_t *hash);
11842 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11844 +void pkg_hash_dump(hash_table_t *hash, void *data);
11845 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11847 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11848 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11849 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11851 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11852 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11853 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11854 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11855 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11856 + const char *pkg_name,
11857 + const char * version);
11858 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11859 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11860 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11861 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11862 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11863 + const char *pkg_name);
11864 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11865 + const char *pkg_name,
11866 + pkg_dest_t *dest);
11868 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11869 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11871 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11872 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11876 diff -urN busybox.old/archival/libipkg/pkg_parse.c busybox.dev/archival/libipkg/pkg_parse.c
11877 --- busybox.old/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
11878 +++ busybox.dev/archival/libipkg/pkg_parse.c 2007-01-22 13:41:03.000000000 +0100
11880 +/* pkg_parse.c - the itsy package management system
11884 + Copyright (C) 2002 Compaq Computer Corporation
11886 + This program is free software; you can redistribute it and/or
11887 + modify it under the terms of the GNU General Public License as
11888 + published by the Free Software Foundation; either version 2, or (at
11889 + your option) any later version.
11891 + This program is distributed in the hope that it will be useful, but
11892 + WITHOUT ANY WARRANTY; without even the implied warranty of
11893 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11894 + General Public License for more details.
11898 +#include <errno.h>
11899 +#include <ctype.h>
11902 +#include "ipkg_utils.h"
11903 +#include "pkg_parse.h"
11905 +int isGenericFieldType(char * type, char * line)
11907 + if(!strncmp(line, type, strlen(type)))
11912 +char * parseGenericFieldType(char * type, char * raw)
11914 + char * field_value = raw + (strlen(type) + 1);
11915 + return trim_alloc(field_value);
11918 +void parseStatus(pkg_t *pkg, char * raw)
11920 + char sw_str[64], sf_str[64], ss_str[64];
11922 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11923 + pkg->state_want = pkg_state_want_from_str(sw_str);
11924 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11925 + pkg->state_status = pkg_state_status_from_str(ss_str);
11928 +char ** parseDependsString(char * raw, int * depends_count)
11930 + char ** depends = NULL;
11931 + int line_count = 0;
11932 + char buff[2048], * dest;
11934 + while(raw && *raw && !isspace(*raw)) {
11938 + if(line_is_blank(raw)){
11939 + *depends_count = line_count;
11942 + while(raw && *raw){
11943 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11945 + while(isspace(*raw)) raw++;
11948 + while((*raw != ',') && *raw)
11949 + *dest++ = *raw++;
11952 + depends[line_count] = trim_alloc(buff);
11953 + if(depends[line_count] ==NULL)
11959 + *depends_count = line_count;
11963 +void parseConffiles(pkg_t * pkg, char * raw)
11965 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11967 + if(!strncmp(raw, "Conffiles:", 10))
11968 + raw += strlen("Conffiles:");
11970 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11971 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11972 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11973 + while (*raw && isspace(*raw)) {
11976 + raw += strlen(file_name);
11977 + while (*raw && isspace(*raw)) {
11980 + raw += strlen(md5sum);
11984 +int parseVersion(pkg_t *pkg, char *raw)
11986 + char *colon, *eepochcolon;
11987 +#ifdef USE_DEBVERSION
11990 + unsigned long epoch;
11993 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11997 + if (strncmp(raw, "Version:", 8) == 0) {
12000 + while (*raw && isspace(*raw)) {
12004 + colon= strchr(raw,':');
12006 + epoch= strtoul(raw,&eepochcolon,10);
12007 + if (colon != eepochcolon) {
12008 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12012 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12016 + pkg->epoch= epoch;
12021 + pkg->revision = "";
12022 + pkg->familiar_revision = "";
12024 + pkg->version= malloc(strlen(raw)+1);
12025 + if ( pkg->version == NULL ) {
12026 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12029 + strcpy(pkg->version, raw);
12031 +#ifdef USE_DEBVERSION
12032 + hyphen= strrchr(pkg->version,'-');
12036 + if (strncmp("fam", hyphen, 3) == 0) {
12037 + pkg->familiar_revision=hyphen+3;
12038 + hyphen= strrchr(pkg->version,'-');
12041 + pkg->revision = hyphen;
12044 + pkg->revision = hyphen;
12050 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12054 + pkg->familiar_revision);
12061 +/* This code is needed to insert in first position the keyword for the aligning bug */
12063 +int alterProvidesLine(char *raw, char *temp)
12068 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12072 + if ( temp == NULL ) {
12073 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12077 + if (strncmp(raw, "Provides:", 9) == 0) {
12080 + while (*raw && isspace(*raw)) {
12084 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12086 + strncat( temp, raw++, 1);
12092 +/* Some random thoughts from Carl:
12094 + This function could be considerably simplified if we just kept
12095 + an array of all the generic string-valued field names, and looped
12096 + through those looking for a match. Also, these fields could perhaps
12097 + be stored in the package as an array as well, (or, probably better,
12098 + as an nv_pair_list_t).
12100 + Fields which require special parsing or storage, (such as Depends:
12101 + and Status:) could be handled as they are now.
12103 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12104 + to a dependency list. And, since we already have
12105 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12106 + Enhances, perhaps we could generalize all of these and save some
12107 + code duplication.
12109 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12111 + int reading_conffiles, reading_description;
12112 + int pkg_false_provides=1;
12114 + char * provide=NULL;
12117 + pkg->dest = dest;
12119 + reading_conffiles = reading_description = 0;
12121 + for (lines = *raw; *lines; lines++) {
12122 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12123 + if(isGenericFieldType("Package:", *lines))
12124 + pkg->name = parseGenericFieldType("Package", *lines);
12125 + else if(isGenericFieldType("Architecture:", *lines))
12126 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12127 + else if(isGenericFieldType("Filename:", *lines))
12128 + pkg->filename = parseGenericFieldType("Filename", *lines);
12129 + else if(isGenericFieldType("Section:", *lines))
12130 + pkg->section = parseGenericFieldType("Section", *lines);
12131 + else if(isGenericFieldType("MD5sum:", *lines))
12132 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12133 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12134 + let's parse it either way */
12135 + else if(isGenericFieldType("MD5Sum:", *lines))
12136 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12137 + else if(isGenericFieldType("Size:", *lines))
12138 + pkg->size = parseGenericFieldType("Size", *lines);
12139 + else if(isGenericFieldType("Source:", *lines))
12140 + pkg->source = parseGenericFieldType("Source", *lines);
12141 + else if(isGenericFieldType("Installed-Size:", *lines))
12142 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12143 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12144 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12145 + pkg->installed_time = strtoul(time_str, NULL, 0);
12146 + } else if(isGenericFieldType("Priority:", *lines))
12147 + pkg->priority = parseGenericFieldType("Priority", *lines);
12148 + else if(isGenericFieldType("Essential:", *lines)) {
12149 + char *essential_value;
12150 + essential_value = parseGenericFieldType("Essential", *lines);
12151 + if (strcmp(essential_value, "yes") == 0) {
12152 + pkg->essential = 1;
12154 + free(essential_value);
12156 + else if(isGenericFieldType("Status", *lines))
12157 + parseStatus(pkg, *lines);
12158 + else if(isGenericFieldType("Version", *lines))
12159 + parseVersion(pkg, *lines);
12160 + else if(isGenericFieldType("Maintainer", *lines))
12161 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12162 + else if(isGenericFieldType("Conffiles", *lines)){
12163 + parseConffiles(pkg, *lines);
12164 + reading_conffiles = 1;
12166 + else if(isGenericFieldType("Description", *lines)) {
12167 + pkg->description = parseGenericFieldType("Description", *lines);
12168 + reading_conffiles = 0;
12169 + reading_description = 1;
12172 + else if(isGenericFieldType("Provides", *lines)){
12173 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12174 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12175 + if ( alterProvidesLine(*lines,provide) ){
12178 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12179 +/* Let's try to hack a bit here.
12180 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12181 + in alot of other places. We will remove it before writing down the status database */
12182 + pkg_false_provides=0;
12186 + else if(isGenericFieldType("Depends", *lines))
12187 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12188 + else if(isGenericFieldType("Pre-Depends", *lines))
12189 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12190 + else if(isGenericFieldType("Recommends", *lines))
12191 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12192 + else if(isGenericFieldType("Suggests", *lines))
12193 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12194 + /* Abhaya: support for conflicts */
12195 + else if(isGenericFieldType("Conflicts", *lines))
12196 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12197 + else if(isGenericFieldType("Replaces", *lines))
12198 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12199 + else if(line_is_blank(*lines)) {
12203 + else if(**lines == ' '){
12204 + if(reading_description) {
12205 + /* we already know it's not blank, so the rest of description */
12206 + pkg->description = realloc(pkg->description,
12207 + strlen(pkg->description)
12208 + + 1 + strlen(*lines) + 1);
12209 + strcat(pkg->description, "\n");
12210 + strcat(pkg->description, (*lines));
12212 + else if(reading_conffiles)
12213 + parseConffiles(pkg, *lines);
12217 +/* If the ipk has not a Provides line, we insert our false line */
12218 + if ( pkg_false_provides==1)
12219 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12228 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12232 + for (lines = *raw; *lines; lines++) {
12233 + if(isGenericFieldType("Essential:", *lines)) {
12234 + char *essential_value;
12235 + essential_value = parseGenericFieldType("Essential", *lines);
12236 + if (strcmp(essential_value, "yes") == 0) {
12237 + pkg->essential = 1;
12239 + free(essential_value);
12246 diff -urN busybox.old/archival/libipkg/pkg_parse.h busybox.dev/archival/libipkg/pkg_parse.h
12247 --- busybox.old/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12248 +++ busybox.dev/archival/libipkg/pkg_parse.h 2007-01-22 13:41:03.000000000 +0100
12250 +/* pkg_parse.h - the itsy package management system
12254 + Copyright (C) 2002 Compaq Computer Corporation
12256 + This program is free software; you can redistribute it and/or
12257 + modify it under the terms of the GNU General Public License as
12258 + published by the Free Software Foundation; either version 2, or (at
12259 + your option) any later version.
12261 + This program is distributed in the hope that it will be useful, but
12262 + WITHOUT ANY WARRANTY; without even the implied warranty of
12263 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12264 + General Public License for more details.
12267 +#ifndef PKG_PARSE_H
12268 +#define PKG_PARSE_H
12270 +int isGenericFieldType(char * type, char * line);
12271 +char * parseGenericFieldType(char * type, char * raw);
12272 +void parseStatus(pkg_t *pkg, char * raw);
12273 +int parseVersion(pkg_t *pkg, char *raw);
12274 +char ** parseDependsString(char * raw, int * depends_count);
12275 +int parseVersion(pkg_t *pkg, char *raw);
12276 +void parseConffiles(pkg_t * pkg, char * raw);
12277 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12278 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12281 diff -urN busybox.old/archival/libipkg/pkg_src.c busybox.dev/archival/libipkg/pkg_src.c
12282 --- busybox.old/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12283 +++ busybox.dev/archival/libipkg/pkg_src.c 2007-01-22 13:41:03.000000000 +0100
12285 +/* pkg_src.c - the itsy package management system
12289 + Copyright (C) 2001 University of Southern California
12291 + This program is free software; you can redistribute it and/or
12292 + modify it under the terms of the GNU General Public License as
12293 + published by the Free Software Foundation; either version 2, or (at
12294 + your option) any later version.
12296 + This program is distributed in the hope that it will be useful, but
12297 + WITHOUT ANY WARRANTY; without even the implied warranty of
12298 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12299 + General Public License for more details.
12304 +#include "pkg_src.h"
12305 +#include "str_util.h"
12307 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12309 + src->gzip = gzip;
12310 + src->name = str_dup_safe (name);
12311 + src->value = str_dup_safe (base_url);
12313 + src->extra_data = str_dup_safe (extra_data);
12315 + src->extra_data = NULL;
12319 +void pkg_src_deinit(pkg_src_t *src)
12321 + free (src->name);
12322 + free (src->value);
12323 + if (src->extra_data)
12324 + free (src->extra_data);
12328 diff -urN busybox.old/archival/libipkg/pkg_src.h busybox.dev/archival/libipkg/pkg_src.h
12329 --- busybox.old/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12330 +++ busybox.dev/archival/libipkg/pkg_src.h 2007-01-22 13:41:03.000000000 +0100
12332 +/* pkg_src.h - the itsy package management system
12336 + Copyright (C) 2001 University of Southern California
12338 + This program is free software; you can redistribute it and/or
12339 + modify it under the terms of the GNU General Public License as
12340 + published by the Free Software Foundation; either version 2, or (at
12341 + your option) any later version.
12343 + This program is distributed in the hope that it will be useful, but
12344 + WITHOUT ANY WARRANTY; without even the implied warranty of
12345 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12346 + General Public License for more details.
12352 +#include "nv_pair.h"
12358 + char *extra_data;
12362 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12363 +void pkg_src_deinit(pkg_src_t *src);
12366 diff -urN busybox.old/archival/libipkg/pkg_src_list.c busybox.dev/archival/libipkg/pkg_src_list.c
12367 --- busybox.old/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12368 +++ busybox.dev/archival/libipkg/pkg_src_list.c 2007-01-22 13:41:03.000000000 +0100
12370 +/* pkg_src_list.c - the itsy package management system
12374 + Copyright (C) 2001 University of Southern California
12376 + This program is free software; you can redistribute it and/or
12377 + modify it under the terms of the GNU General Public License as
12378 + published by the Free Software Foundation; either version 2, or (at
12379 + your option) any later version.
12381 + This program is distributed in the hope that it will be useful, but
12382 + WITHOUT ANY WARRANTY; without even the implied warranty of
12383 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12384 + General Public License for more details.
12389 +#include "pkg_src_list.h"
12390 +#include "void_list.h"
12392 +int pkg_src_list_init(pkg_src_list_t *list)
12394 + return void_list_init((void_list_t *) list);
12397 +void pkg_src_list_deinit(pkg_src_list_t *list)
12399 + pkg_src_list_elt_t *iter;
12400 + pkg_src_t *pkg_src;
12402 + for (iter = list->head; iter; iter = iter->next) {
12403 + pkg_src = iter->data;
12404 + pkg_src_deinit(pkg_src);
12406 + /* malloced in pkg_src_list_append */
12408 + iter->data = NULL;
12410 + void_list_deinit((void_list_t *) list);
12413 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12414 + const char *name, const char *base_url, const char *extra_data,
12419 + /* freed in pkg_src_list_deinit */
12420 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12422 + if (pkg_src == NULL) {
12423 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12426 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12428 + err = void_list_append((void_list_t *) list, pkg_src);
12436 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12438 + return void_list_push((void_list_t *) list, data);
12441 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12443 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12445 diff -urN busybox.old/archival/libipkg/pkg_src_list.h busybox.dev/archival/libipkg/pkg_src_list.h
12446 --- busybox.old/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12447 +++ busybox.dev/archival/libipkg/pkg_src_list.h 2007-01-22 13:41:03.000000000 +0100
12449 +/* pkg_src_list.h - the itsy package management system
12453 + Copyright (C) 2001 University of Southern California
12455 + This program is free software; you can redistribute it and/or
12456 + modify it under the terms of the GNU General Public License as
12457 + published by the Free Software Foundation; either version 2, or (at
12458 + your option) any later version.
12460 + This program is distributed in the hope that it will be useful, but
12461 + WITHOUT ANY WARRANTY; without even the implied warranty of
12462 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12463 + General Public License for more details.
12466 +#ifndef PKG_SRC_LIST_H
12467 +#define PKG_SRC_LIST_H
12469 +#include "pkg_src.h"
12471 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12472 +struct pkg_src_list_elt
12474 + pkg_src_list_elt_t *next;
12478 +typedef struct pkg_src_list pkg_src_list_t;
12479 +struct pkg_src_list
12481 + pkg_src_list_elt_t pre_head;
12482 + pkg_src_list_elt_t *head;
12483 + pkg_src_list_elt_t *tail;
12486 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12488 + if (list->head == NULL)
12494 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12495 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12497 +int pkg_src_list_init(pkg_src_list_t *list);
12498 +void pkg_src_list_deinit(pkg_src_list_t *list);
12500 +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);
12501 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12502 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12506 diff -urN busybox.old/archival/libipkg/pkg_vec.c busybox.dev/archival/libipkg/pkg_vec.c
12507 --- busybox.old/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12508 +++ busybox.dev/archival/libipkg/pkg_vec.c 2007-01-22 13:41:03.000000000 +0100
12510 +/* pkg_vec.c - the itsy package management system
12514 + Copyright (C) 2002 Compaq Computer Corporation
12516 + This program is free software; you can redistribute it and/or
12517 + modify it under the terms of the GNU General Public License as
12518 + published by the Free Software Foundation; either version 2, or (at
12519 + your option) any later version.
12521 + This program is distributed in the hope that it will be useful, but
12522 + WITHOUT ANY WARRANTY; without even the implied warranty of
12523 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12524 + General Public License for more details.
12527 +#include <stdlib.h>
12528 +#include <fnmatch.h>
12529 +#include "xregex.h"
12533 +pkg_vec_t * pkg_vec_alloc(void)
12535 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12537 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12540 + vec->pkgs = NULL;
12546 +void pkg_vec_free(pkg_vec_t *vec)
12553 + * assumption: all names in a vector are identical
12554 + * assumption: all version strings are trimmed,
12555 + * so identical versions have identical version strings,
12556 + * implying identical packages; let's marry these
12558 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12563 + /* look for a duplicate pkg by name, version, and architecture */
12564 + for (i = 0; i < vec->len; i++){
12565 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12566 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12567 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12568 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12569 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12570 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12572 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12573 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12578 + /* we didn't find one, add it */
12580 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12581 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12583 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12584 + vec->pkgs[vec->len] = pkg;
12588 + /* update the one that we have */
12590 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12591 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12592 + if (set_status) {
12593 + /* this is from the status file, so need to merge with existing database */
12594 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12595 + pkg_merge(vec->pkgs[i], pkg, set_status);
12596 + /* XXX: CLEANUP: It's not so polite to free something here
12597 + that was passed in from above. */
12601 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12602 + /* just overwrite the old one */
12603 + pkg_deinit(vec->pkgs[i]);
12604 + free(vec->pkgs[i]);
12605 + vec->pkgs[i] = pkg;
12607 + return vec->pkgs[i];
12611 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12616 + /* look for a duplicate pkg by name, version, and architecture */
12617 + for (i = 0; i < vec->len; i++)
12618 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12619 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12620 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12625 + /* we didn't find one, add it */
12627 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12628 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12633 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12636 + for (i = 0; i < vec->len; i++)
12637 + if (vec->pkgs[i] == apkg)
12642 +typedef int (*compare_fcn_t)(const void *, const void *);
12643 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12645 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12648 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12650 + int npkgs = vec->len;
12652 + for (i = 0; i < npkgs; i++) {
12653 + pkg_t *pkg = vec->pkgs[i];
12654 + pkg->state_flag &= ~SF_MARKED;
12659 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12661 + int matching_count = 0;
12662 + pkg_t **pkgs = vec->pkgs;
12663 + int npkgs = vec->len;
12665 + for (i = 0; i < npkgs; i++) {
12666 + pkg_t *pkg = pkgs[i];
12667 + if (fnmatch(pattern, pkg->name, 0)==0) {
12668 + pkg->state_flag |= SF_MARKED;
12669 + matching_count++;
12672 + return matching_count;
12676 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12678 + abstract_pkg_vec_t * vec ;
12679 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12681 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12684 + vec->pkgs = NULL;
12690 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12697 + * assumption: all names in a vector are unique
12699 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12703 + /* look for a duplicate pkg by name */
12704 + for(i = 0; i < vec->len; i++)
12705 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12708 + /* we didn't find one, add it */
12709 + if(i == vec->len){
12711 + (abstract_pkg_t **)
12712 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12713 + vec->pkgs[vec->len] = pkg;
12718 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12720 + if (vec->len > i)
12721 + return vec->pkgs[i];
12726 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12729 + for (i = 0; i < vec->len; i++)
12730 + if (vec->pkgs[i] == apkg)
12735 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12737 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12740 diff -urN busybox.old/archival/libipkg/pkg_vec.h busybox.dev/archival/libipkg/pkg_vec.h
12741 --- busybox.old/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12742 +++ busybox.dev/archival/libipkg/pkg_vec.h 2007-01-22 13:41:06.000000000 +0100
12744 +/* pkg_vec.h - the itsy package management system
12748 + Copyright (C) 2002 Compaq Computer Corporation
12750 + This program is free software; you can redistribute it and/or
12751 + modify it under the terms of the GNU General Public License as
12752 + published by the Free Software Foundation; either version 2, or (at
12753 + your option) any later version.
12755 + This program is distributed in the hope that it will be useful, but
12756 + WITHOUT ANY WARRANTY; without even the implied warranty of
12757 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12758 + General Public License for more details.
12764 +typedef struct pkg pkg_t;
12765 +typedef struct abstract_pkg abstract_pkg_t;
12772 +typedef struct pkg_vec pkg_vec_t;
12774 +struct abstract_pkg_vec
12776 + abstract_pkg_t **pkgs;
12779 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12781 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12782 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12784 +pkg_vec_t * pkg_vec_alloc(void);
12785 +void pkg_vec_free(pkg_vec_t *vec);
12786 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12788 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12789 +/* pkg_vec_insert_merge: might munge pkg.
12790 +* returns the pkg that is in the pkg graph */
12791 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12792 +/* this one never munges pkg */
12793 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12794 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12795 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12797 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12798 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12800 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12801 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12802 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12803 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12804 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12805 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12808 diff -urN busybox.old/archival/libipkg/sprintf_alloc.h busybox.dev/archival/libipkg/sprintf_alloc.h
12809 --- busybox.old/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
12810 +++ busybox.dev/archival/libipkg/sprintf_alloc.h 2007-01-22 13:41:03.000000000 +0100
12812 +/* sprintf_alloca.c -- like sprintf with memory allocation
12816 + Copyright (C) 2001 University of Southern California
12818 + This program is free software; you can redistribute it and/or modify
12819 + it under the terms of the GNU General Public License as published by
12820 + the Free Software Foundation; either version 2, or (at your option)
12821 + any later version.
12823 + This program is distributed in the hope that it will be useful,
12824 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12825 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12826 + GNU General Public License for more details.
12829 +#ifndef SPRINTF_ALLOC_H
12830 +#define SPRINTF_ALLOC_H
12832 +#include "libbb.h"
12834 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12837 diff -urN busybox.old/archival/libipkg/str_list.c busybox.dev/archival/libipkg/str_list.c
12838 --- busybox.old/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
12839 +++ busybox.dev/archival/libipkg/str_list.c 2007-01-22 13:41:03.000000000 +0100
12841 +/* str_list.c - the itsy package management system
12845 + Copyright (C) 2001 University of Southern California
12847 + This program is free software; you can redistribute it and/or
12848 + modify it under the terms of the GNU General Public License as
12849 + published by the Free Software Foundation; either version 2, or (at
12850 + your option) any later version.
12852 + This program is distributed in the hope that it will be useful, but
12853 + WITHOUT ANY WARRANTY; without even the implied warranty of
12854 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12855 + General Public License for more details.
12860 +#include "str_list.h"
12862 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12864 + return void_list_elt_init((void_list_elt_t *) elt, data);
12867 +void str_list_elt_deinit(str_list_elt_t *elt)
12869 + void_list_elt_deinit((void_list_elt_t *) elt);
12872 +str_list_t *str_list_alloc()
12874 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12876 + str_list_init(list);
12880 +int str_list_init(str_list_t *list)
12882 + return void_list_init((void_list_t *) list);
12885 +void str_list_deinit(str_list_t *list)
12887 + void_list_deinit((void_list_t *) list);
12890 +int str_list_append(str_list_t *list, char *data)
12892 + return void_list_append((void_list_t *) list, data);
12895 +int str_list_push(str_list_t *list, char *data)
12897 + return void_list_push((void_list_t *) list, data);
12900 +str_list_elt_t *str_list_pop(str_list_t *list)
12902 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12905 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12907 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12908 + (void_list_elt_t **) iter);
12911 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12913 + return (char *)void_list_remove_elt((void_list_t *) list,
12914 + (void *)target_str,
12915 + (void_list_cmp_t)strcmp);
12917 diff -urN busybox.old/archival/libipkg/str_list.h busybox.dev/archival/libipkg/str_list.h
12918 --- busybox.old/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
12919 +++ busybox.dev/archival/libipkg/str_list.h 2007-01-22 13:41:03.000000000 +0100
12921 +/* str_list.h - the itsy package management system
12925 + Copyright (C) 2001 University of Southern California
12927 + This program is free software; you can redistribute it and/or
12928 + modify it under the terms of the GNU General Public License as
12929 + published by the Free Software Foundation; either version 2, or (at
12930 + your option) any later version.
12932 + This program is distributed in the hope that it will be useful, but
12933 + WITHOUT ANY WARRANTY; without even the implied warranty of
12934 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12935 + General Public License for more details.
12938 +#ifndef STR_LIST_H
12939 +#define STR_LIST_H
12941 +#include "void_list.h"
12943 +typedef struct str_list_elt str_list_elt_t;
12944 +struct str_list_elt
12946 + str_list_elt_t *next;
12950 +typedef struct xstr_list str_list_t;
12953 + str_list_elt_t pre_head;
12954 + str_list_elt_t *head;
12955 + str_list_elt_t *tail;
12958 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12959 +void str_list_elt_deinit(str_list_elt_t *elt);
12961 +str_list_t *str_list_alloc(void);
12962 +int str_list_init(str_list_t *list);
12963 +void str_list_deinit(str_list_t *list);
12965 +int str_list_append(str_list_t *list, char *data);
12966 +int str_list_push(str_list_t *list, char *data);
12967 +str_list_elt_t *str_list_pop(str_list_t *list);
12968 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12969 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12972 diff -urN busybox.old/archival/libipkg/str_util.c busybox.dev/archival/libipkg/str_util.c
12973 --- busybox.old/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
12974 +++ busybox.dev/archival/libipkg/str_util.c 2007-01-22 13:41:03.000000000 +0100
12976 +/* str_utils.c - the itsy package management system
12980 + Copyright (C) 2001 University of Southern California
12982 + This program is free software; you can redistribute it and/or
12983 + modify it under the terms of the GNU General Public License as
12984 + published by the Free Software Foundation; either version 2, or (at
12985 + your option) any later version.
12987 + This program is distributed in the hope that it will be useful, but
12988 + WITHOUT ANY WARRANTY; without even the implied warranty of
12989 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12990 + General Public License for more details.
12995 +int str_starts_with(const char *str, const char *prefix)
12997 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13000 +int str_ends_with(const char *str, const char *suffix)
13005 + str_len = strlen(str);
13006 + suffix_len = strlen(suffix);
13008 + if (str_len < suffix_len) {
13012 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13015 +int str_chomp(char *str)
13017 + if (str[strlen(str) - 1] == '\n') {
13018 + str[strlen(str) - 1] = '\0';
13024 +int str_tolower(char *str)
13027 + *str = tolower(*str);
13034 +int str_toupper(char *str)
13037 + *str = toupper(*str);
13044 +char *str_dup_safe(const char *str)
13046 + return str ? strdup(str) : NULL;
13049 diff -urN busybox.old/archival/libipkg/str_util.h busybox.dev/archival/libipkg/str_util.h
13050 --- busybox.old/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13051 +++ busybox.dev/archival/libipkg/str_util.h 2007-01-22 13:41:03.000000000 +0100
13053 +/* str_utils.h - the itsy package management system
13057 + Copyright (C) 2001 University of Southern California
13059 + This program is free software; you can redistribute it and/or
13060 + modify it under the terms of the GNU General Public License as
13061 + published by the Free Software Foundation; either version 2, or (at
13062 + your option) any later version.
13064 + This program is distributed in the hope that it will be useful, but
13065 + WITHOUT ANY WARRANTY; without even the implied warranty of
13066 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13067 + General Public License for more details.
13070 +#ifndef STR_UTILS_H
13071 +#define STR_UTILS_H
13073 +int str_starts_with(const char *str, const char *prefix);
13074 +int str_ends_with(const char *str, const char *suffix);
13075 +int str_chomp(char *str);
13076 +int str_tolower(char *str);
13077 +int str_toupper(char *str);
13078 +char *str_dup_safe(const char *str);
13081 diff -urN busybox.old/archival/libipkg/user.c busybox.dev/archival/libipkg/user.c
13082 --- busybox.old/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13083 +++ busybox.dev/archival/libipkg/user.c 2007-01-22 13:41:03.000000000 +0100
13085 +/* user.c - the itsy package management system
13089 + Copyright (C) 2002 Hewlett Packard Company
13090 + Copyright (C) 2001 University of Southern California
13092 + This program is free software; you can redistribute it and/or
13093 + modify it under the terms of the GNU General Public License as
13094 + published by the Free Software Foundation; either version 2, or (at
13095 + your option) any later version.
13097 + This program is distributed in the hope that it will be useful, but
13098 + WITHOUT ANY WARRANTY; without even the implied warranty of
13099 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13100 + General Public License for more details.
13103 +#include <stdio.h>
13104 +#include <stdarg.h>
13105 +#include "file_util.h"
13106 +#include "str_util.h"
13108 +#include "libipkg.h"
13113 +static char *question = NULL;
13114 +static int question_len = 255;
13116 +char *get_user_response(const char *format, ...)
13118 + int len = question_len;
13121 + va_start(ap, format);
13124 + vprintf(format, ap);
13126 + response = file_read_line_alloc(stdin);
13127 + } while (response == NULL);
13130 + if (question == NULL || len > question_len) {
13131 + question = realloc(question, len + 1);
13132 + question_len = len;
13134 + len = vsnprintf(question,question_len,format,ap);
13135 + } while (len > question_len);
13136 + response = strdup(ipkg_cb_response(question));
13138 + str_chomp(response);
13139 + str_tolower(response);
13143 diff -urN busybox.old/archival/libipkg/user.h busybox.dev/archival/libipkg/user.h
13144 --- busybox.old/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13145 +++ busybox.dev/archival/libipkg/user.h 2007-01-22 13:41:03.000000000 +0100
13147 +/* user.c - the itsy package management system
13151 + Copyright (C) 2002 Hewlett Packard Company
13152 + Copyright (C) 2001 University of Southern California
13154 + This program is free software; you can redistribute it and/or
13155 + modify it under the terms of the GNU General Public License as
13156 + published by the Free Software Foundation; either version 2, or (at
13157 + your option) any later version.
13159 + This program is distributed in the hope that it will be useful, but
13160 + WITHOUT ANY WARRANTY; without even the implied warranty of
13161 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13162 + General Public License for more details.
13165 +#include <stdio.h>
13166 +#include <stdarg.h>
13168 +char *get_user_response(const char *format, ...);
13170 diff -urN busybox.old/archival/libipkg/void_list.c busybox.dev/archival/libipkg/void_list.c
13171 --- busybox.old/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13172 +++ busybox.dev/archival/libipkg/void_list.c 2007-01-22 13:41:03.000000000 +0100
13174 +/* void_list.c - the itsy package management system
13178 + Copyright (C) 2001 University of Southern California
13180 + This program is free software; you can redistribute it and/or
13181 + modify it under the terms of the GNU General Public License as
13182 + published by the Free Software Foundation; either version 2, or (at
13183 + your option) any later version.
13185 + This program is distributed in the hope that it will be useful, but
13186 + WITHOUT ANY WARRANTY; without even the implied warranty of
13187 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13188 + General Public License for more details.
13192 +#include <errno.h>
13194 +#include "void_list.h"
13196 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13198 + elt->next = NULL;
13199 + elt->data = data;
13204 +void void_list_elt_deinit(void_list_elt_t *elt)
13206 + void_list_elt_init(elt, NULL);
13209 +int void_list_init(void_list_t *list)
13211 + void_list_elt_init(&list->pre_head, NULL);
13212 + list->head = NULL;
13213 + list->pre_head.next = list->head;
13214 + list->tail = NULL;
13219 +void void_list_deinit(void_list_t *list)
13221 + void_list_elt_t *elt;
13223 + while (list->head) {
13224 + elt = void_list_pop(list);
13225 + void_list_elt_deinit(elt);
13226 + /* malloced in void_list_append */
13231 +int void_list_append(void_list_t *list, void *data)
13233 + void_list_elt_t *elt;
13235 + /* freed in void_list_deinit */
13236 + elt = malloc(sizeof(void_list_elt_t));
13237 + if (elt == NULL) {
13238 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13242 + void_list_elt_init(elt, data);
13244 + if (list->tail) {
13245 + list->tail->next = elt;
13246 + list->tail = elt;
13248 + list->head = elt;
13249 + list->pre_head.next = list->head;
13250 + list->tail = elt;
13256 +int void_list_push(void_list_t *list, void *data)
13258 + void_list_elt_t *elt;
13260 + elt = malloc(sizeof(void_list_elt_t));
13261 + if (elt == NULL) {
13262 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13266 + void_list_elt_init(elt, data);
13268 + elt->next = list->head;
13269 + list->head->next = elt;
13270 + if (list->tail == NULL) {
13271 + list->tail = list->head;
13277 +void_list_elt_t *void_list_pop(void_list_t *list)
13279 + void_list_elt_t *elt;
13281 + elt = list->head;
13283 + if (list->head) {
13284 + list->head = list->head->next;
13285 + list->pre_head.next = list->head;
13286 + if (list->head == NULL) {
13287 + list->tail = NULL;
13294 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13296 + void_list_elt_t *prior;
13297 + void_list_elt_t *old_elt;
13301 + old_data = old_elt->data;
13303 + if (old_elt == list->head) {
13304 + prior = &list->pre_head;
13305 + void_list_pop(list);
13307 + for (prior = list->head; prior; prior = prior->next) {
13308 + if (prior->next == old_elt) {
13312 + if (prior == NULL || prior->next != old_elt) {
13313 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13316 + prior->next = old_elt->next;
13318 + if (old_elt == list->tail) {
13319 + list->tail = prior;
13323 + void_list_elt_deinit(old_elt);
13329 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13330 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13332 + void_list_elt_t *prior;
13333 + void_list_elt_t *old_elt = NULL;
13334 + void *old_data = NULL;
13336 + /* first element */
13337 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13338 + old_elt = list->head;
13339 + old_data = list->head->data;
13340 + void_list_pop(list);
13343 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13344 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13345 + old_elt = prior->next;
13346 + old_data = old_elt->data;
13354 + prior->next = old_elt->next;
13356 + if (old_elt == list->tail) {
13357 + list->tail = prior;
13361 + void_list_elt_deinit(old_elt);
13368 diff -urN busybox.old/archival/libipkg/void_list.h busybox.dev/archival/libipkg/void_list.h
13369 --- busybox.old/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13370 +++ busybox.dev/archival/libipkg/void_list.h 2007-01-22 13:41:03.000000000 +0100
13372 +/* void_list.h - the itsy package management system
13376 + Copyright (C) 2001 University of Southern California
13378 + This program is free software; you can redistribute it and/or
13379 + modify it under the terms of the GNU General Public License as
13380 + published by the Free Software Foundation; either version 2, or (at
13381 + your option) any later version.
13383 + This program is distributed in the hope that it will be useful, but
13384 + WITHOUT ANY WARRANTY; without even the implied warranty of
13385 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13386 + General Public License for more details.
13389 +#ifndef VOID_LIST_H
13390 +#define VOID_LIST_H
13392 +typedef struct void_list_elt void_list_elt_t;
13393 +struct void_list_elt
13395 + void_list_elt_t *next;
13399 +typedef struct void_list void_list_t;
13402 + void_list_elt_t pre_head;
13403 + void_list_elt_t *head;
13404 + void_list_elt_t *tail;
13407 +static inline int void_list_empty(void_list_t *list)
13409 + if (list->head == NULL)
13415 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13416 +void void_list_elt_deinit(void_list_elt_t *elt);
13418 +int void_list_init(void_list_t *list);
13419 +void void_list_deinit(void_list_t *list);
13421 +int void_list_append(void_list_t *list, void *data);
13422 +int void_list_push(void_list_t *list, void *data);
13423 +void_list_elt_t *void_list_pop(void_list_t *list);
13425 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13426 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13427 +typedef int (*void_list_cmp_t)(const void *, const void *);
13428 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13431 diff -urN busybox.old/archival/libipkg/xsystem.c busybox.dev/archival/libipkg/xsystem.c
13432 --- busybox.old/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13433 +++ busybox.dev/archival/libipkg/xsystem.c 2007-01-22 13:41:03.000000000 +0100
13435 +/* xsystem.c - system(3) with error messages
13439 + Copyright (C) 2001 University of Southern California
13441 + This program is free software; you can redistribute it and/or
13442 + modify it under the terms of the GNU General Public License as
13443 + published by the Free Software Foundation; either version 2, or (at
13444 + your option) any later version.
13446 + This program is distributed in the hope that it will be useful, but
13447 + WITHOUT ANY WARRANTY; without even the implied warranty of
13448 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13449 + General Public License for more details.
13453 +#include <sys/wait.h>
13455 +#include "xsystem.h"
13457 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13458 + really need the /bin/sh invocation which takes resources and
13459 + introduces security problems. I should switch all of this to a sort
13460 + of execl() or execv() interface/implementation.
13463 +/* Like system(3), but with error messages printed if the fork fails
13464 + or if the child process dies due to an uncaught signal. Also, the
13465 + return value is a bit simpler:
13467 + -1 if there was any problem
13468 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13469 + as defined in <sys/wait.h>.
13471 +int xsystem(const char *cmd)
13475 + err = system(cmd);
13478 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13479 + __FUNCTION__, cmd);
13483 + if (WIFSIGNALED(err)) {
13484 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13485 + __FUNCTION__, WTERMSIG(err), cmd);
13489 + if (WIFEXITED(err)) {
13490 + /* Normal child exit */
13491 + return WEXITSTATUS(err);
13494 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13495 + __FUNCTION__, err);
13499 diff -urN busybox.old/archival/libipkg/xsystem.h busybox.dev/archival/libipkg/xsystem.h
13500 --- busybox.old/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13501 +++ busybox.dev/archival/libipkg/xsystem.h 2007-01-22 13:41:03.000000000 +0100
13503 +/* xsystem.h - system(3) with error messages
13507 + Copyright (C) 2001 University of Southern California
13509 + This program is free software; you can redistribute it and/or
13510 + modify it under the terms of the GNU General Public License as
13511 + published by the Free Software Foundation; either version 2, or (at
13512 + your option) any later version.
13514 + This program is distributed in the hope that it will be useful, but
13515 + WITHOUT ANY WARRANTY; without even the implied warranty of
13516 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13517 + General Public License for more details.
13523 +#include <stdlib.h>
13525 +/* Like system(3), but with error messages printed if the fork fails
13526 + or if the child process dies due to an uncaught signal. Also, the
13527 + return value is a bit simpler:
13529 + -1 if there was any problem
13530 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13531 + as defined in <sys/wait.h>.
13533 +int xsystem(const char *cmd);
13537 diff -urN busybox.old/archival/libunarchive/data_extract_all.c busybox.dev/archival/libunarchive/data_extract_all.c
13538 --- busybox.old/archival/libunarchive/data_extract_all.c 2007-01-19 22:23:02.000000000 +0100
13539 +++ busybox.dev/archival/libunarchive/data_extract_all.c 2007-01-22 13:41:03.000000000 +0100
13540 @@ -117,3 +117,17 @@
13541 utime(file_header->name, &t);
13545 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13547 + char *name_ptr = archive_handle->file_header->name;
13549 + name_ptr += strspn(name_ptr, "./");
13550 + if (name_ptr[0] != '\0') {
13551 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13552 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13553 + strcat(archive_handle->file_header->name, name_ptr);
13554 + data_extract_all(archive_handle);
13558 diff -urN busybox.old/archival/libunarchive/Kbuild busybox.dev/archival/libunarchive/Kbuild
13559 --- busybox.old/archival/libunarchive/Kbuild 2007-01-19 22:23:02.000000000 +0100
13560 +++ busybox.dev/archival/libunarchive/Kbuild 2007-01-22 13:41:03.000000000 +0100
13562 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13563 lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13564 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13565 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13566 lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13567 lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13568 lib-$(CONFIG_TAR) += get_header_tar.o
13569 diff -urN busybox.old/include/applets.h busybox.dev/include/applets.h
13570 --- busybox.old/include/applets.h 2007-01-20 16:34:47.000000000 +0100
13571 +++ busybox.dev/include/applets.h 2007-01-22 13:41:03.000000000 +0100
13572 @@ -160,6 +160,7 @@
13573 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13574 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13575 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13576 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13577 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13578 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13579 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13580 diff -urN busybox.old/include/unarchive.h busybox.dev/include/unarchive.h
13581 --- busybox.old/include/unarchive.h 2007-01-19 22:23:10.000000000 +0100
13582 +++ busybox.dev/include/unarchive.h 2007-01-22 13:41:03.000000000 +0100
13585 extern void data_skip(archive_handle_t *archive_handle);
13586 extern void data_extract_all(archive_handle_t *archive_handle);
13587 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13588 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13589 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13591 diff -urN busybox.old/include/usage.h busybox.dev/include/usage.h
13592 --- busybox.old/include/usage.h 2007-01-19 22:23:10.000000000 +0100
13593 +++ busybox.dev/include/usage.h 2007-01-22 13:41:03.000000000 +0100
13594 @@ -1133,6 +1133,82 @@
13595 "$ ls -la /tmp/busybox*\n" \
13596 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13598 +#define ipkg_trivial_usage \
13599 + "[options]... sub-command [arguments]..."
13600 +#define ipkg_full_usage \
13601 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13603 + "Sub-commands:\n" \
13604 + "\nPackage Manipulation:\n" \
13605 + "\tupdate Update list of available packages\n" \
13606 + "\tupgrade Upgrade all installed packages to latest version\n" \
13607 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13608 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13609 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13610 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13611 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13612 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13614 + "Informational Commands:\n" \
13615 + "\tlist List available packages and descriptions\n" \
13616 + "\tlist_installed List all and only the installed packages and description \n" \
13617 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13618 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13619 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13620 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13621 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13622 + "\tcompare_versions <v1> <op> <v2>\n" \
13623 + "\t compare versions using <= < > >= = << >>\n" \
13624 + "\tprint_architecture prints the architecture.\n" \
13625 + "\tprint_installation_architecture\n" \
13626 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13627 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13628 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13629 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13630 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13631 + "\t prints the installation architecture.\n" \
13634 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13635 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13636 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13637 + "\t 0 errors only\n" \
13638 + "\t 1 normal messages (default)\n" \
13639 + "\t 2 informative messages\n" \
13640 + "\t 3 debug output\n" \
13641 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13642 + "\t-conf <conf_file> Default configuration file location\n" \
13643 + " is /etc/ipkg.conf\n" \
13644 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13645 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13646 + " <dest_name> should be a defined dest name from\n" \
13647 + " the configuration file, (but can also be a\n" \
13648 + " directory name in a pinch).\n" \
13649 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13650 + "\t-offline <offline_root> offline installation of packages.\n" \
13651 + "\t-verbose_wget more wget messages\n" \
13653 + "Force Options (use when ipkg is too smart for its own good):\n" \
13654 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13655 + "\t Install/remove package in spite of failed dependences\n" \
13656 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13657 + " (no prompts). Note that this will not prevent\n" \
13658 + " package installation scripts from prompting.\n" \
13659 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13660 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13661 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13662 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13663 + "\t-noaction No action -- test only\n" \
13664 + "\t-nodeps Do not follow dependences\n" \
13665 + "\t-force-removal-of-dependent-packages\n" \
13666 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13667 + "\t-test No action -- test only\n" \
13668 + "\t-t Specify tmp-dir.\n" \
13669 + "\t--tmp-dir Specify tmp-dir.\n" \
13671 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13672 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13674 #define halt_trivial_usage \
13675 "[-d<delay>] [-n<nosync>] [-f<force>]"
13676 #define halt_full_usage \
13677 diff -urN busybox.old/Makefile busybox.dev/Makefile
13678 --- busybox.old/Makefile 2007-01-20 21:21:39.000000000 +0100
13679 +++ busybox.dev/Makefile 2007-01-22 13:41:03.000000000 +0100
13680 @@ -423,6 +423,7 @@
13684 + archival/libipkg/ \
13685 archival/libunarchive/ \