1 diff -ruN busybox-1.2.0-orig/archival/Config.in busybox-1.2.0+ipkg-0.99.162/archival/Config.in
2 --- busybox-1.2.0-orig/archival/Config.in 2006-07-01 00:42:04.000000000 +0200
3 +++ busybox-1.2.0+ipkg-0.99.162/archival/Config.in 2006-07-22 16:31:25.000000000 +0200
5 gzip is used to compress files.
6 It's probably the most widely used UNIX compression program.
11 + select CONFIG_MD5SUM
14 + ipkg is the itsy package management system.
16 config CONFIG_RPM2CPIO
19 diff -ruN busybox-1.2.0-orig/archival/dpkg.c busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c
20 --- busybox-1.2.0-orig/archival/dpkg.c 2006-07-01 00:42:04.000000000 +0200
21 +++ busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c 2006-07-22 16:31:25.000000000 +0200
22 @@ -1430,6 +1430,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 -ruN busybox-1.2.0-orig/archival/ipkg.c busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c
43 --- busybox-1.2.0-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
44 +++ busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c 2006-07-22 16:31:25.000000000 +0200
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 -ruN busybox-1.2.0-orig/archival/libipkg/args.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c
73 --- busybox-1.2.0-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
74 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c 2006-07-22 16:31:25.000000000 +0200
76 +/* args.c - parse command-line args
80 + Copyright 2001 University of Southern California
82 + This program is free software; you can redistribute it and/or modify
83 + it under the terms of the GNU General Public License as published by
84 + the Free Software Foundation; either version 2, or (at your option)
87 + This program is distributed in the hope that it will be useful,
88 + but WITHOUT ANY WARRANTY; without even the implied warranty of
89 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 + GNU General Public License for more details.
99 +#include "ipkg_message.h"
102 +#include "sprintf_alloc.h"
107 +static void print_version(void);
111 + ARGS_OPT_FORCE_DEFAULTS = 129,
112 + ARGS_OPT_FORCE_DEPENDS,
113 + ARGS_OPT_FORCE_OVERWRITE,
114 + ARGS_OPT_FORCE_DOWNGRADE,
115 + ARGS_OPT_FORCE_REINSTALL,
116 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
117 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
118 + ARGS_OPT_FORCE_SPACE,
121 + ARGS_OPT_VERBOSE_WGET,
122 + ARGS_OPT_VERBOSITY,
123 + ARGS_OPT_MULTIPLE_PROVIDERS
126 +int args_init(args_t *args)
128 + char *conf_file_dir;
130 + memset(args, 0, sizeof(args_t));
132 + args->dest = ARGS_DEFAULT_DEST;
134 + conf_file_dir = getenv("IPKG_CONF_DIR");
135 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
136 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
138 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
139 + ARGS_DEFAULT_CONF_FILE_NAME);
141 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
142 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
143 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
144 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
145 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
146 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
147 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
148 + args->noaction = ARGS_DEFAULT_NOACTION;
149 + args->nodeps = ARGS_DEFAULT_NODEPS;
150 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
151 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
152 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
153 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
154 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
155 + args->multiple_providers = 0;
156 + args->nocheckfordirorfile = 0;
157 + args->noreadfeedsfile = 0;
162 +void args_deinit(args_t *args)
164 + free(args->conf_file);
165 + args->conf_file = NULL;
168 +int args_parse(args_t *args, int argc, char *argv[])
171 + int option_index = 0;
173 + static struct option long_options[] = {
174 + {"query-all", 0, 0, 'A'},
175 + {"conf-file", 1, 0, 'f'},
176 + {"conf", 1, 0, 'f'},
177 + {"dest", 1, 0, 'd'},
178 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
179 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
180 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
181 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
182 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
183 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
184 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
185 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
186 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
187 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
188 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
189 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
190 + {"recursive", 0, 0,
191 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
192 + {"force-removal-of-dependent-packages", 0, 0,
193 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
194 + {"force_removal_of_dependent_packages", 0, 0,
195 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
196 + {"force-removal-of-essential-packages", 0, 0,
197 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
198 + {"force_removal_of_essential_packages", 0, 0,
199 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
200 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
201 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
202 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
203 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
204 + {"offline", 1, 0, 'o'},
205 + {"offline-root", 1, 0, 'o'},
206 + {"test", 0, 0, ARGS_OPT_NOACTION},
207 + {"tmp-dir", 1, 0, 't'},
208 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
209 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
210 + {"verbosity", 2, 0, 'V'},
211 + {"version", 0, 0, 'v'},
216 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
222 + args->query_all = 1;
225 + args->dest = optarg;
228 + free(args->conf_file);
229 + args->conf_file = strdup(optarg);
232 + args->offline_root = optarg;
235 + args->noaction = 1;
238 + args->tmp_dir = strdup(optarg);
244 + case ARGS_OPT_VERBOSITY:
246 + args->verbosity = atoi(optarg);
248 + args->verbosity += 1;
250 + case ARGS_OPT_FORCE_DEFAULTS:
251 + args->force_defaults = 1;
253 + case ARGS_OPT_FORCE_DEPENDS:
254 + args->force_depends = 1;
256 + case ARGS_OPT_FORCE_OVERWRITE:
257 + args->force_overwrite = 1;
259 + case ARGS_OPT_FORCE_DOWNGRADE:
260 + args->force_downgrade = 1;
262 + case ARGS_OPT_FORCE_REINSTALL:
263 + args->force_reinstall = 1;
265 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
266 + args->force_removal_of_essential_packages = 1;
268 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
269 + args->force_removal_of_dependent_packages = 1;
271 + case ARGS_OPT_FORCE_SPACE:
272 + args->force_space = 1;
274 + case ARGS_OPT_VERBOSE_WGET:
275 + args->verbose_wget = 1;
277 + case ARGS_OPT_MULTIPLE_PROVIDERS:
278 + args->multiple_providers = 1;
280 + case ARGS_OPT_NODEPS:
283 + case ARGS_OPT_NOACTION:
284 + args->noaction = 1;
293 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
304 +void args_usage(char *complaint)
307 + bb_error_msg("%s\n", complaint);
314 +static void print_version(void)
316 + bb_error_msg("version %s\n", IPKG_VERSION);
318 diff -ruN busybox-1.2.0-orig/archival/libipkg/args.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h
319 --- busybox-1.2.0-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
320 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h 2006-07-22 16:31:25.000000000 +0200
322 +/* args.h - parse command-line args
326 + Copyright 2001 University of Southern California
328 + This program is free software; you can redistribute it and/or modify
329 + it under the terms of the GNU General Public License as published by
330 + the Free Software Foundation; either version 2, or (at your option)
333 + This program is distributed in the hope that it will be useful,
334 + but WITHOUT ANY WARRANTY; without even the implied warranty of
335 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
336 + GNU General Public License for more details.
347 + int force_defaults;
349 + int force_overwrite;
350 + int force_downgrade;
351 + int force_reinstall;
352 + int force_removal_of_essential_packages;
353 + int force_removal_of_dependent_packages;
357 + int multiple_providers;
361 + int nocheckfordirorfile;
362 + int noreadfeedsfile;
363 + char *offline_root;
364 + char *offline_root_pre_script_cmd;
365 + char *offline_root_post_script_cmd;
367 +typedef struct args args_t;
369 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
370 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
371 +#define ARGS_DEFAULT_DEST NULL
372 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
373 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
374 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
375 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
376 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
377 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
378 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
379 +#define ARGS_DEFAULT_FORCE_SPACE 0
380 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
381 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
382 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
383 +#define ARGS_DEFAULT_NOACTION 0
384 +#define ARGS_DEFAULT_NODEPS 0
385 +#define ARGS_DEFAULT_VERBOSE_WGET 0
386 +#define ARGS_DEFAULT_VERBOSITY 1
388 +int args_init(args_t *args);
389 +void args_deinit(args_t *args);
390 +int args_parse(args_t *args, int argc, char *argv[]);
391 +void args_usage(char *complaint);
394 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c
395 --- busybox-1.2.0-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
396 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c 2006-07-22 16:31:25.000000000 +0200
398 +/* conffile.c - the itsy package management system
402 + Copyright (C) 2001 University of Southern California
404 + This program is free software; you can redistribute it and/or
405 + modify it under the terms of the GNU General Public License as
406 + published by the Free Software Foundation; either version 2, or (at
407 + your option) any later version.
409 + This program is distributed in the hope that it will be useful, but
410 + WITHOUT ANY WARRANTY; without even the implied warranty of
411 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
412 + General Public License for more details.
419 +#include "ipkg_message.h"
421 +#include "conffile.h"
422 +#include "file_util.h"
423 +#include "sprintf_alloc.h"
425 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
427 + return nv_pair_init(conffile, file_name, md5sum);
430 +void conffile_deinit(conffile_t *conffile)
432 + nv_pair_deinit(conffile);
435 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
438 + char *filename = conffile->name;
439 + char *root_filename;
442 + if (conffile->value == NULL) {
443 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
447 + root_filename = root_filename_alloc(conf, filename);
449 + md5sum = file_md5sum_alloc(root_filename);
451 + ret = strcmp(md5sum, conffile->value);
453 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
454 + conffile->name, md5sum, conffile->value);
457 + free(root_filename);
462 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h
463 --- busybox-1.2.0-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
464 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h 2006-07-22 16:31:25.000000000 +0200
466 +/* conffile.h - the itsy package management system
470 + Copyright (C) 2001 University of Southern California
472 + This program is free software; you can redistribute it and/or
473 + modify it under the terms of the GNU General Public License as
474 + published by the Free Software Foundation; either version 2, or (at
475 + your option) any later version.
477 + This program is distributed in the hope that it will be useful, but
478 + WITHOUT ANY WARRANTY; without even the implied warranty of
479 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
480 + General Public License for more details.
486 +#include "nv_pair.h"
488 +typedef struct nv_pair conffile_t;
490 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
491 +void conffile_deinit(conffile_t *conffile);
492 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
496 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.c
497 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
498 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.c 2006-07-22 16:31:25.000000000 +0200
500 +/* conffile_list.c - the itsy package management system
504 + Copyright (C) 2001 University of Southern California
506 + This program is free software; you can redistribute it and/or
507 + modify it under the terms of the GNU General Public License as
508 + published by the Free Software Foundation; either version 2, or (at
509 + your option) any later version.
511 + This program is distributed in the hope that it will be useful, but
512 + WITHOUT ANY WARRANTY; without even the implied warranty of
513 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
514 + General Public License for more details.
519 +#include "conffile_list.h"
521 +int conffile_list_init(conffile_list_t *list)
523 + return nv_pair_list_init(list);
526 +void conffile_list_deinit(conffile_list_t *list)
528 + nv_pair_list_deinit(list);
531 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
532 + const char *md5sum)
534 + return nv_pair_list_append(list, file_name, md5sum);
537 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
539 + return nv_pair_list_push(list, data);
542 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
544 + return nv_pair_list_pop(list);
547 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.h
548 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
549 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.h 2006-07-22 16:31:25.000000000 +0200
551 +/* conffile_list.h - the itsy package management system
555 + Copyright (C) 2001 University of Southern California
557 + This program is free software; you can redistribute it and/or
558 + modify it under the terms of the GNU General Public License as
559 + published by the Free Software Foundation; either version 2, or (at
560 + your option) any later version.
562 + This program is distributed in the hope that it will be useful, but
563 + WITHOUT ANY WARRANTY; without even the implied warranty of
564 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
565 + General Public License for more details.
568 +#ifndef CONFFILE_LIST_H
569 +#define CONFFILE_LIST_H
571 +#include "conffile.h"
572 +#include "nv_pair_list.h"
574 +typedef struct nv_pair_list_elt conffile_list_elt_t;
575 +typedef struct nv_pair_list conffile_list_t;
577 +int conffile_list_init(conffile_list_t *list);
578 +void conffile_list_deinit(conffile_list_t *list);
580 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
581 + const char *root_dir);
582 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
583 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
587 diff -ruN busybox-1.2.0-orig/archival/libipkg/file_util.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.c
588 --- busybox-1.2.0-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
589 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.c 2006-07-22 16:31:25.000000000 +0200
591 +/* file_util.c - convenience routines for common stat operations
595 + Copyright (C) 2001 University of Southern California
597 + This program is free software; you can redistribute it and/or
598 + modify it under the terms of the GNU General Public License as
599 + published by the Free Software Foundation; either version 2, or (at
600 + your option) any later version.
602 + This program is distributed in the hope that it will be useful, but
603 + WITHOUT ANY WARRANTY; without even the implied warranty of
604 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
605 + General Public License for more details.
609 +#include <sys/types.h>
610 +#include <sys/stat.h>
612 +#include "sprintf_alloc.h"
613 +#include "file_util.h"
618 +int file_exists(const char *file_name)
621 + struct stat stat_buf;
623 + err = stat(file_name, &stat_buf);
631 +int file_is_dir(const char *file_name)
634 + struct stat stat_buf;
636 + err = stat(file_name, &stat_buf);
641 + return S_ISDIR(stat_buf.st_mode);
644 +/* read a single line from a file, stopping at a newline or EOF.
645 + If a newline is read, it will appear in the resulting string.
646 + Return value is a malloc'ed char * which should be freed at
647 + some point by the caller.
649 + Return value is NULL if the file is at EOF when called.
651 +#define FILE_READ_LINE_BUF_SIZE 1024
652 +char *file_read_line_alloc(FILE *file)
654 + char buf[FILE_READ_LINE_BUF_SIZE];
659 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
660 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
661 + buf_len = strlen(buf);
663 + line_size += buf_len;
664 + line = realloc(line, line_size);
665 + if (line == NULL) {
666 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
671 + line_size = buf_len + 1;
672 + line = strdup(buf);
674 + if (buf[buf_len - 1] == '\n') {
682 +int file_move(const char *src, const char *dest)
686 + err = rename(src, dest);
688 + if (err && errno == EXDEV) {
689 + err = file_copy(src, dest);
692 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
693 + __FUNCTION__, src, dest, strerror(errno));
699 +/* I put these here to keep libbb dependencies from creeping all over
701 +int file_copy(const char *src, const char *dest)
705 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
707 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
708 + __FUNCTION__, src, dest);
714 +int file_mkdir_hier(const char *path, long mode)
716 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
719 +char *file_md5sum_alloc(const char *file_name)
721 + static const int md5sum_bin_len = 16;
722 + static const int md5sum_hex_len = 32;
724 + static const unsigned char bin2hex[16] = {
725 + '0', '1', '2', '3',
726 + '4', '5', '6', '7',
727 + '8', '9', 'a', 'b',
733 + unsigned char *md5sum_hex;
734 + unsigned char md5sum_bin[md5sum_bin_len];
736 + md5sum_hex = malloc(md5sum_hex_len + 1);
737 + if (md5sum_hex == NULL) {
738 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
742 + file = fopen(file_name, "r");
743 + if (file == NULL) {
744 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
745 + __FUNCTION__, file_name, strerror(errno));
749 + err = md5_stream(file, md5sum_bin);
751 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
752 + __FUNCTION__, file_name, strerror(err));
758 + for (i=0; i < md5sum_bin_len; i++) {
759 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
760 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
763 + md5sum_hex[md5sum_hex_len] = '\0';
768 diff -ruN busybox-1.2.0-orig/archival/libipkg/file_util.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.h
769 --- busybox-1.2.0-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
770 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.h 2006-07-22 16:31:25.000000000 +0200
772 +/* file_util.h - convenience routines for common file operations
776 + Copyright (C) 2001 University of Southern California
778 + This program is free software; you can redistribute it and/or
779 + modify it under the terms of the GNU General Public License as
780 + published by the Free Software Foundation; either version 2, or (at
781 + your option) any later version.
783 + This program is distributed in the hope that it will be useful, but
784 + WITHOUT ANY WARRANTY; without even the implied warranty of
785 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
786 + General Public License for more details.
792 +int file_exists(const char *file_name);
793 +int file_is_dir(const char *file_name);
794 +char *file_read_line_alloc(FILE *file);
795 +int file_move(const char *src, const char *dest);
796 +int file_copy(const char *src, const char *dest);
797 +int file_mkdir_hier(const char *path, long mode);
798 +char *file_md5sum_alloc(const char *file_name);
801 diff -ruN busybox-1.2.0-orig/archival/libipkg/hash_table.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.c
802 --- busybox-1.2.0-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
803 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.c 2006-07-22 16:31:25.000000000 +0200
805 +/* hash.c - hash tables for ipkg
807 + Steven M. Ayer, Jamey Hicks
809 + Copyright (C) 2002 Compaq Computer Corporation
811 + This program is free software; you can redistribute it and/or
812 + modify it under the terms of the GNU General Public License as
813 + published by the Free Software Foundation; either version 2, or (at
814 + your option) any later version.
816 + This program is distributed in the hope that it will be useful, but
817 + WITHOUT ANY WARRANTY; without even the implied warranty of
818 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
819 + General Public License for more details.
826 +#include "hash_table.h"
827 +#include "ipkg_message.h"
830 +static int hash_index(hash_table_t *hash, const char *pkg_name);
831 +static int rotating(const char *key, int len, int prime);
833 +static int hash_index(hash_table_t *hash, const char *pkg_name)
835 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
838 +static int rotating(const char *key, int len, int prime)
840 + unsigned int hash, i;
841 + for (hash=len, i=0; i<len; ++i)
842 + hash = (hash<<4)^(hash>>28)^key[i];
843 + return (hash % prime);
848 + * this is an open table keyed by strings
850 +int hash_table_init(const char *name, hash_table_t *hash, int len)
852 + static int primes_table[] = {
853 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
854 + 19471, 23143, 33961, 46499, 49727, 99529, 0
858 + if (hash->entries != NULL) {
859 + /* we have been here already */
864 + hash->entries = NULL;
865 + hash->n_entries = 0;
866 + hash->hash_entry_key = NULL;
868 + picker = primes_table;
869 + while(*picker && (*picker++ < len));
871 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
874 + hash->n_entries = *picker;
875 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
876 + if (hash->entries == NULL) {
877 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
883 +void hash_table_deinit(hash_table_t *hash)
885 + free(hash->entries);
886 + hash->entries = NULL;
887 + hash->n_entries = 0;
890 +void *hash_table_get(hash_table_t *hash, const char *key)
892 + int ndx= hash_index(hash, key);
893 + hash_entry_t *hash_entry = hash->entries + ndx;
896 + if (hash_entry->key)
898 + if (strcmp(key, hash_entry->key) == 0) {
899 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
900 + return hash_entry->data;
903 + hash_entry = hash_entry->next;
908 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
910 + int ndx= hash_index(hash, key);
911 + hash_entry_t *hash_entry = hash->entries + ndx;
912 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
913 + if (hash_entry->key) {
914 + if (strcmp(hash_entry->key, key) == 0) {
915 + /* alread in table, update the value */
916 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
917 + hash_entry->data = value;
921 + * if this is a collision, we have to go to the end of the ll,
922 + * then add a new entry
923 + * before we can hook up the value
925 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
926 + while (hash_entry->next)
927 + hash_entry = hash_entry->next;
928 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
929 + if (!hash_entry->next) {
932 + hash_entry = hash_entry->next;
933 + hash_entry->next = NULL;
936 + hash->n_elements++;
937 + hash_entry->key = strdup(key);
938 + hash_entry->data = value;
944 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
950 + for (i = 0; i < hash->n_entries; i++) {
951 + hash_entry_t *hash_entry = (hash->entries + i);
953 + if(hash_entry->key) {
954 + f(hash_entry->key, hash_entry->data, data);
956 + } while((hash_entry = hash_entry->next));
960 diff -ruN busybox-1.2.0-orig/archival/libipkg/hash_table.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.h
961 --- busybox-1.2.0-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
962 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.h 2006-07-22 16:31:25.000000000 +0200
964 +/* hash.h - hash tables for ipkg
966 + Steven M. Ayer, Jamey Hicks
968 + Copyright (C) 2002 Compaq Computer Corporation
970 + This program is free software; you can redistribute it and/or
971 + modify it under the terms of the GNU General Public License as
972 + published by the Free Software Foundation; either version 2, or (at
973 + your option) any later version.
975 + This program is distributed in the hope that it will be useful, but
976 + WITHOUT ANY WARRANTY; without even the implied warranty of
977 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
978 + General Public License for more details.
981 +#ifndef _HASH_TABLE_H_
982 +#define _HASH_TABLE_H_
984 +typedef struct hash_entry hash_entry_t;
985 +typedef struct hash_table hash_table_t;
990 + struct hash_entry * next;
995 + hash_entry_t * entries;
996 + int n_entries; /* number of buckets */
998 + const char * (*hash_entry_key)(void * data);
1001 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1002 +void hash_table_deinit(hash_table_t *hash);
1003 +void *hash_table_get(hash_table_t *hash, const char *key);
1004 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1005 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1007 +#endif /* _HASH_TABLE_H_ */
1008 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c
1009 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1010 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c 2006-07-22 16:31:25.000000000 +0200
1012 +/* ipkg_cmd.c - the itsy package management system
1016 + Copyright (C) 2001 University of Southern California
1018 + This program is free software; you can redistribute it and/or
1019 + modify it under the terms of the GNU General Public License as
1020 + published by the Free Software Foundation; either version 2, or (at
1021 + your option) any later version.
1023 + This program is distributed in the hope that it will be useful, but
1024 + WITHOUT ANY WARRANTY; without even the implied warranty of
1025 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1026 + General Public License for more details.
1029 +#include <string.h>
1032 +#include <libgen.h>
1035 +#include <stdlib.h>
1036 +#include <unistd.h>
1037 +#include <signal.h>
1039 +#include <dirent.h>
1041 +#include "ipkg_conf.h"
1042 +#include "ipkg_cmd.h"
1043 +#include "ipkg_message.h"
1045 +#include "pkg_dest.h"
1046 +#include "pkg_parse.h"
1047 +#include "sprintf_alloc.h"
1049 +#include "file_util.h"
1050 +#include "str_util.h"
1052 +#include "unarchive.h"
1054 +#include <fnmatch.h>
1057 +#include "ipkg_download.h"
1058 +#include "ipkg_install.h"
1059 +#include "ipkg_upgrade.h"
1060 +#include "ipkg_remove.h"
1061 +#include "ipkg_configure.h"
1062 +#include "ipkg_message.h"
1065 +#include "libipkg.h"
1066 +static void *p_userdata = NULL;
1069 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1070 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1071 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1072 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1073 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1074 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1075 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1076 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1077 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1078 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1079 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1080 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1081 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1082 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1083 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1084 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1085 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1086 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1087 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1088 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1089 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1090 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1091 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1092 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1093 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1095 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1096 + array for easier maintenance */
1097 +static ipkg_cmd_t cmds[] = {
1098 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1099 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1100 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1101 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1102 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1103 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1104 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1105 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1106 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1107 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1108 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1109 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1110 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1111 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1112 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1113 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1114 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1115 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1116 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1117 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1118 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1119 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1120 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1121 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1122 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1123 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1124 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1125 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1126 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1129 +int ipkg_state_changed;
1130 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1132 + if (ipkg_state_changed && !conf->noaction) {
1133 + ipkg_message(conf, IPKG_INFO,
1134 + " writing status file\n");
1135 + ipkg_conf_write_status_files(conf);
1136 + pkg_write_changed_filelists(conf);
1138 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1143 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1145 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1150 + for (i=0; i < num_cmds; i++) {
1152 + if (strcmp(name, cmd->name) == 0) {
1161 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1164 + p_userdata = userdata;
1167 + result = (cmd->fun)(conf, argc, argv);
1168 + if ( result == 0 ) {
1169 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1171 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1174 + if ( error_list ) {
1175 + reverse_error_list(&error_list);
1177 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1178 + /* Here we print the errors collected and free the list */
1179 + while (error_list != NULL) {
1180 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1181 + error_list = error_list->next;
1184 + free_error_list(&error_list);
1188 + p_userdata = NULL;
1192 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1194 + return (cmd->fun)(conf, argc, argv);
1198 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1203 + pkg_src_list_elt_t *iter;
1207 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1209 + if (! file_is_dir(lists_dir)) {
1210 + if (file_exists(lists_dir)) {
1211 + ipkg_message(conf, IPKG_ERROR,
1212 + "%s: ERROR: %s exists, but is not a directory\n",
1213 + __FUNCTION__, lists_dir);
1217 + err = file_mkdir_hier(lists_dir, 0755);
1219 + ipkg_message(conf, IPKG_ERROR,
1220 + "%s: ERROR: failed to make directory %s: %s\n",
1221 + __FUNCTION__, lists_dir, strerror(errno));
1228 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1229 + char *url, *list_file_name;
1233 + if (src->extra_data) /* debian style? */
1234 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1235 + src->gzip ? "Packages.gz" : "Packages");
1237 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1239 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1242 + char *tmp_file_name;
1245 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1247 + if (mkdtemp (tmp) == NULL) {
1248 + perror ("mkdtemp");
1253 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1254 + err = ipkg_download(conf, url, tmp_file_name);
1256 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1257 + in = fopen (tmp_file_name, "r");
1258 + out = fopen (list_file_name, "w");
1260 + inflate_unzip (in, out);
1267 + unlink (tmp_file_name);
1272 + err = ipkg_download(conf, url, list_file_name);
1276 + ipkg_message(conf, IPKG_NOTICE,
1277 + "Updated list of available packages in %s\n",
1281 + free(list_file_name);
1285 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1287 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1288 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1294 + pkg_vec_t *available = pkg_vec_alloc();
1295 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1296 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1297 + for (i = 0; i < available->len; i++) {
1298 + pkg_t *pkg = available->pkgs[i];
1299 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1300 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1301 + pkg->state_want = SW_UNKNOWN;
1305 + pkg_vec_free(available);
1307 + write_status_files_if_changed(conf);
1316 +/* scan the args passed and cache the local filenames of the packages */
1317 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1323 + * First scan through package names/urls
1324 + * For any urls, download the packages and install in database.
1325 + * For any files, install package info in database.
1327 + for (i = 0; i < argc; i ++) {
1328 + char *filename = argv [i];
1329 + //char *tmp = basename (tmp);
1330 + //int tmplen = strlen (tmp);
1332 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1334 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1337 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1339 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1346 +struct ipkg_intercept
1352 +typedef struct ipkg_intercept *ipkg_intercept_t;
1354 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1356 + ipkg_intercept_t ctx;
1360 + ctx = malloc (sizeof (*ctx));
1361 + ctx->oldpath = strdup (getenv ("PATH"));
1363 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1364 + setenv ("PATH", newpath, 1);
1369 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1370 + if (mkdir (ctx->statedir, 0770) < 0) {
1371 + if (errno == EEXIST) {
1372 + free (ctx->statedir);
1376 + perror (ctx->statedir);
1379 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1383 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1389 + setenv ("PATH", ctx->oldpath, 1);
1390 + free (ctx->oldpath);
1392 + dir = opendir (ctx->statedir);
1394 + struct dirent *de;
1395 + while (de = readdir (dir), de != NULL) {
1398 + if (de->d_name[0] == '.')
1401 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1402 + if (access (path, X_OK) == 0) {
1403 + if (system (path)) {
1405 + perror (de->d_name);
1411 + perror (ctx->statedir);
1413 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1417 + free (ctx->statedir);
1423 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1428 + ipkg_intercept_t ic;
1431 + ipkg_message(conf, IPKG_INFO,
1432 + "Configuring unpacked packages\n");
1435 + all = pkg_vec_alloc();
1436 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1438 + ic = ipkg_prep_intercepts (conf);
1440 + for(i = 0; i < all->len; i++) {
1441 + pkg = all->pkgs[i];
1443 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1446 + if (pkg->state_status == SS_UNPACKED) {
1447 + ipkg_message(conf, IPKG_NOTICE,
1448 + "Configuring %s\n", pkg->name);
1450 + r = ipkg_configure(conf, pkg);
1452 + pkg->state_status = SS_INSTALLED;
1453 + pkg->parent->state_status = SS_INSTALLED;
1454 + pkg->state_flag &= ~SF_PREFER;
1462 + r = ipkg_finalize_intercepts (ic);
1466 + pkg_vec_free(all);
1470 +static void sigint_handler(int sig)
1472 + signal(sig, SIG_DFL);
1473 + ipkg_message(NULL, IPKG_NOTICE,
1474 + "ipkg: interrupted. writing out status database\n");
1475 + write_status_files_if_changed(global_conf);
1479 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1485 + global_conf = conf;
1486 + signal(SIGINT, sigint_handler);
1489 + * Now scan through package names and install
1491 + for (i=0; i < argc; i++) {
1494 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1495 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1496 + if (err != EINVAL && err != 0)
1499 + pkg_info_preinstall_check(conf);
1501 + for (i=0; i < argc; i++) {
1503 + if (conf->multiple_providers)
1504 + err = ipkg_install_multi_by_name(conf, arg);
1506 + err = ipkg_install_by_name(conf, arg);
1508 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1509 + ipkg_message(conf, IPKG_ERROR,
1510 + "Cannot find package %s.\n"
1511 + "Check the spelling or perhaps run 'ipkg update'\n",
1516 + /* recheck to verify that all dependences are satisfied */
1517 + if (0) ipkg_satisfy_all_dependences(conf);
1519 + ipkg_configure_packages(conf, NULL);
1521 + write_status_files_if_changed(conf);
1526 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1532 + global_conf = conf;
1533 + signal(SIGINT, sigint_handler);
1536 + for (i=0; i < argc; i++) {
1537 + char *arg = argv[i];
1539 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1540 + if (err != EINVAL && err != 0)
1543 + pkg_info_preinstall_check(conf);
1545 + for (i=0; i < argc; i++) {
1546 + char *arg = argv[i];
1547 + if (conf->restrict_to_default_dest) {
1548 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1550 + conf->default_dest);
1551 + if (pkg == NULL) {
1552 + ipkg_message(conf, IPKG_NOTICE,
1553 + "Package %s not installed in %s\n",
1554 + argv[i], conf->default_dest->name);
1558 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1562 + ipkg_upgrade_pkg(conf, pkg);
1564 + ipkg_install_by_name(conf, arg);
1568 + pkg_vec_t *installed = pkg_vec_alloc();
1570 + pkg_info_preinstall_check(conf);
1572 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1573 + for (i = 0; i < installed->len; i++) {
1574 + pkg = installed->pkgs[i];
1575 + ipkg_upgrade_pkg(conf, pkg);
1577 + pkg_vec_free(installed);
1580 + /* recheck to verify that all dependences are satisfied */
1581 + if (0) ipkg_satisfy_all_dependences(conf);
1583 + ipkg_configure_packages(conf, NULL);
1585 + write_status_files_if_changed(conf);
1590 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1596 + pkg_info_preinstall_check(conf);
1597 + for (i = 0; i < argc; i++) {
1600 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1601 + if (pkg == NULL) {
1602 + ipkg_message(conf, IPKG_ERROR,
1603 + "Cannot find package %s.\n"
1604 + "Check the spelling or perhaps run 'ipkg update'\n",
1609 + err = ipkg_download_pkg(conf, pkg, ".");
1612 + ipkg_message(conf, IPKG_ERROR,
1613 + "Failed to download %s\n", pkg->name);
1615 + ipkg_message(conf, IPKG_NOTICE,
1616 + "Downloaded %s as %s\n",
1617 + pkg->name, pkg->local_filename);
1625 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1628 + pkg_vec_t *available;
1630 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1632 + char *pkg_name = NULL;
1633 + char *version_str;
1636 + pkg_name = argv[0];
1638 + available = pkg_vec_alloc();
1639 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1640 + for (i=0; i < available->len; i++) {
1641 + pkg = available->pkgs[i];
1642 + /* if we have package name or pattern and pkg does not match, then skip it */
1643 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1645 + if (pkg->description) {
1646 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1648 + desc_short[0] = '\0';
1650 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1651 + newline = strchr(desc_short, '\n');
1656 + printf("%s - %s\n", pkg->name, desc_short);
1658 + if (ipkg_cb_list) {
1659 + version_str = pkg_version_str_alloc(pkg);
1660 + ipkg_cb_list(pkg->name,desc_short,
1662 + pkg->state_status,
1664 + free(version_str);
1668 + pkg_vec_free(available);
1674 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1677 + pkg_vec_t *available;
1679 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1681 + char *pkg_name = NULL;
1682 + char *version_str;
1685 + pkg_name = argv[0];
1687 + available = pkg_vec_alloc();
1688 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1689 + for (i=0; i < available->len; i++) {
1690 + pkg = available->pkgs[i];
1691 + /* if we have package name or pattern and pkg does not match, then skip it */
1692 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1694 + if (pkg->description) {
1695 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1697 + desc_short[0] = '\0';
1699 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1700 + newline = strchr(desc_short, '\n');
1705 + printf("%s - %s\n", pkg->name, desc_short);
1707 + if (ipkg_cb_list) {
1708 + version_str = pkg_version_str_alloc(pkg);
1709 + ipkg_cb_list(pkg->name,desc_short,
1711 + pkg->state_status,
1713 + free(version_str);
1721 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1724 + pkg_vec_t *available;
1726 + char *pkg_name = NULL;
1727 + char **pkg_fields = NULL;
1729 + char *buff ; // = (char *)malloc(1);
1732 + pkg_name = argv[0];
1735 + pkg_fields = &argv[1];
1736 + n_fields = argc - 1;
1739 + available = pkg_vec_alloc();
1740 + if (installed_only)
1741 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1743 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1744 + for (i=0; i < available->len; i++) {
1745 + pkg = available->pkgs[i];
1746 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1751 + for (j = 0; j < n_fields; j++)
1752 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1754 + pkg_print_info(pkg, stdout);
1758 + buff = pkg_formatted_info(pkg);
1760 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1761 + pkg->state_status,
1765 + We should not forget that actually the pointer is allocated.
1766 + We need to free it :) ( Thanks florian for seeing the error )
1771 + if (conf->verbosity > 1) {
1772 + conffile_list_elt_t *iter;
1773 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1774 + conffile_t *cf = iter->data;
1775 + int modified = conffile_has_been_modified(conf, cf);
1776 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1777 + cf->name, cf->value, modified);
1785 + pkg_vec_free(available);
1790 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1792 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1795 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1797 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1800 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1805 + char *pkg_name = NULL;
1807 + pkg_name = argv[0];
1809 + err = ipkg_configure_packages (conf, pkg_name);
1812 + err = ipkg_configure_packages (conf, NULL);
1815 + write_status_files_if_changed(conf);
1820 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1823 + char *globpattern;
1826 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1827 + err = glob(globpattern, 0, NULL, &globbuf);
1828 + free(globpattern);
1833 + ipkg_message(conf, IPKG_NOTICE,
1834 + "The following packages in %s will now be installed.\n",
1835 + conf->pending_dir);
1836 + for (i = 0; i < globbuf.gl_pathc; i++) {
1837 + ipkg_message(conf, IPKG_NOTICE,
1838 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1840 + ipkg_message(conf, IPKG_NOTICE, "\n");
1841 + for (i = 0; i < globbuf.gl_pathc; i++) {
1842 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1844 + err = unlink(globbuf.gl_pathv[i]);
1846 + ipkg_message(conf, IPKG_ERROR,
1847 + "%s: ERROR: failed to unlink %s: %s\n",
1848 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1853 + globfree(&globbuf);
1858 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1862 + pkg_t *pkg_to_remove;
1863 + pkg_vec_t *available;
1864 + char *pkg_name = NULL;
1865 + global_conf = conf;
1866 + signal(SIGINT, sigint_handler);
1868 +// ENH: Add the "no pkg removed" just in case.
1872 + available = pkg_vec_alloc();
1873 + pkg_info_preinstall_check(conf);
1875 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1876 + for (i=0; i < argc; i++) {
1877 + pkg_name = malloc(strlen(argv[i])+2);
1878 + strcpy(pkg_name,argv[i]);
1879 + for (a=0; a < available->len; a++) {
1880 + pkg = available->pkgs[a];
1881 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1884 + if (conf->restrict_to_default_dest) {
1885 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1887 + conf->default_dest);
1889 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1892 + if (pkg == NULL) {
1893 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1896 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1897 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1900 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1905 + pkg_vec_free(available);
1907 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1909 + int flagged_pkg_count = 0;
1912 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1914 + for (i = 0; i < installed_pkgs->len; i++) {
1915 + pkg_t *pkg = installed_pkgs->pkgs[i];
1916 + if (pkg->state_flag & SF_USER) {
1917 + flagged_pkg_count++;
1919 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1920 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1923 + if (!flagged_pkg_count) {
1924 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1925 + "so refusing to uninstall unflagged non-leaf packages\n");
1929 + /* find packages not flagged SF_USER (i.e., installed to
1930 + * satisfy a dependence) and not having any dependents, and
1934 + for (i = 0; i < installed_pkgs->len; i++) {
1935 + pkg_t *pkg = installed_pkgs->pkgs[i];
1936 + if (!(pkg->state_flag & SF_USER)
1937 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1939 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1940 + ipkg_remove_pkg(conf, pkg,0);
1944 + } while (removed);
1945 + pkg_vec_free(installed_pkgs);
1949 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1951 + write_status_files_if_changed(conf);
1955 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1960 + global_conf = conf;
1961 + signal(SIGINT, sigint_handler);
1963 + pkg_info_preinstall_check(conf);
1965 + for (i=0; i < argc; i++) {
1966 + if (conf->restrict_to_default_dest) {
1967 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1969 + conf->default_dest);
1971 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1974 + if (pkg == NULL) {
1975 + ipkg_message(conf, IPKG_ERROR,
1976 + "Package %s is not installed.\n", argv[i]);
1979 + ipkg_purge_pkg(conf, pkg);
1982 + write_status_files_if_changed(conf);
1986 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1990 + const char *flags = argv[0];
1992 + global_conf = conf;
1993 + signal(SIGINT, sigint_handler);
1995 + for (i=1; i < argc; i++) {
1996 + if (conf->restrict_to_default_dest) {
1997 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1999 + conf->default_dest);
2001 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2004 + if (pkg == NULL) {
2005 + ipkg_message(conf, IPKG_ERROR,
2006 + "Package %s is not installed.\n", argv[i]);
2009 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2010 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2011 + pkg->state_flag = pkg_state_flag_from_str(flags);
2013 +/* pb_ asked this feature 03292004 */
2014 +/* Actually I will use only this two, but this is an open for various status */
2015 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2016 + pkg->state_status = pkg_state_status_from_str(flags);
2018 + ipkg_state_changed++;
2019 + ipkg_message(conf, IPKG_NOTICE,
2020 + "Setting flags for package %s to %s\n",
2021 + pkg->name, flags);
2024 + write_status_files_if_changed(conf);
2028 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2031 + str_list_t *installed_files;
2032 + str_list_elt_t *iter;
2033 + char *pkg_version;
2034 + size_t buff_len = 8192;
2038 + buff = (char *)malloc(buff_len);
2039 + if ( buff == NULL ) {
2040 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2048 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2050 + if (pkg == NULL) {
2051 + ipkg_message(conf, IPKG_ERROR,
2052 + "Package %s not installed.\n", argv[0]);
2056 + installed_files = pkg_get_installed_files(pkg);
2057 + pkg_version = pkg_version_str_alloc(pkg);
2060 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2061 + pkg->name, pkg_version, pkg->dest->name);
2062 + for (iter = installed_files->head; iter; iter = iter->next) {
2068 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2069 + pkg->name, pkg_version, pkg->dest->name) + 1;
2070 + if (used_len > buff_len) {
2072 + buff = realloc (buff, buff_len);
2075 + for (iter = installed_files->head; iter; iter = iter->next) {
2076 + used_len += strlen (iter->data) + 1;
2077 + while (buff_len <= used_len) {
2079 + buff = realloc (buff, buff_len);
2081 + strncat(buff, iter->data, buff_len);
2082 + strncat(buff, "\n", buff_len);
2084 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2086 + pkg_version_str_alloc(pkg),
2087 + pkg->state_status,
2093 + free(pkg_version);
2094 + pkg_free_installed_files(pkg);
2099 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2103 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2104 + const char *rel_str = "depends on";
2107 + pkg_info_preinstall_check(conf);
2109 + if (conf->query_all)
2110 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2112 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2113 + for (i = 0; i < argc; i++) {
2114 + const char *target = argv[i];
2117 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2119 + for (j = 0; j < available_pkgs->len; j++) {
2120 + pkg_t *pkg = available_pkgs->pkgs[j];
2121 + if (fnmatch(target, pkg->name, 0) == 0) {
2123 + int count = pkg->depends_count + pkg->pre_depends_count;
2124 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2125 + target, pkg->architecture, rel_str);
2126 + for (k = 0; k < count; k++) {
2127 + compound_depend_t *cdepend = &pkg->depends[k];
2129 + for (l = 0; l < cdepend->possibility_count; l++) {
2130 + depend_t *possibility = cdepend->possibilities[l];
2131 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2132 + if (conf->verbosity > 0) {
2133 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2134 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2135 + if (possibility->version) {
2136 + char *typestr = NULL;
2137 + switch (possibility->constraint) {
2138 + case NONE: typestr = "none"; break;
2139 + case EARLIER: typestr = "<"; break;
2140 + case EARLIER_EQUAL: typestr = "<="; break;
2141 + case EQUAL: typestr = "="; break;
2142 + case LATER_EQUAL: typestr = ">="; break;
2143 + case LATER: typestr = ">"; break;
2145 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2149 + ipkg_message(conf, IPKG_ERROR, "\n");
2155 + pkg_vec_free(available_pkgs);
2160 +enum what_field_type {
2169 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2173 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2174 + const char *rel_str = NULL;
2178 + switch (what_field_type) {
2179 + case WHATDEPENDS: rel_str = "depends on"; break;
2180 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2181 + case WHATSUGGESTS: rel_str = "suggests"; break;
2182 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2183 + case WHATPROVIDES: rel_str = "provides"; break;
2184 + case WHATREPLACES: rel_str = "replaces"; break;
2187 + if (conf->query_all)
2188 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2190 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2192 + /* mark the root set */
2193 + pkg_vec_clear_marks(available_pkgs);
2194 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2195 + for (i = 0; i < argc; i++) {
2196 + const char *dependee_pattern = argv[i];
2197 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2199 + for (i = 0; i < available_pkgs->len; i++) {
2200 + pkg_t *pkg = available_pkgs->pkgs[i];
2201 + if (pkg->state_flag & SF_MARKED) {
2202 + /* mark the parent (abstract) package */
2203 + pkg_mark_provides(pkg);
2204 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2208 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2213 + for (j = 0; j < available_pkgs->len; j++) {
2214 + pkg_t *pkg = available_pkgs->pkgs[j];
2216 + int count = ((what_field_type == WHATCONFLICTS)
2217 + ? pkg->conflicts_count
2218 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2219 + /* skip this package if it is already marked */
2220 + if (pkg->parent->state_flag & SF_MARKED) {
2223 + for (k = 0; k < count; k++) {
2224 + compound_depend_t *cdepend =
2225 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2227 + for (l = 0; l < cdepend->possibility_count; l++) {
2228 + depend_t *possibility = cdepend->possibilities[l];
2229 + if (possibility->pkg->state_flag & SF_MARKED) {
2230 + /* mark the depending package so we won't visit it again */
2231 + pkg->state_flag |= SF_MARKED;
2232 + pkg_mark_provides(pkg);
2235 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2236 + if (conf->verbosity > 0) {
2237 + char *ver = pkg_version_str_alloc(pkg);
2238 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2239 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2240 + if (possibility->version) {
2241 + char *typestr = NULL;
2242 + switch (possibility->constraint) {
2243 + case NONE: typestr = "none"; break;
2244 + case EARLIER: typestr = "<"; break;
2245 + case EARLIER_EQUAL: typestr = "<="; break;
2246 + case EQUAL: typestr = "="; break;
2247 + case LATER_EQUAL: typestr = ">="; break;
2248 + case LATER: typestr = ">"; break;
2250 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2253 + if (!pkg_dependence_satisfiable(conf, possibility))
2254 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2256 + ipkg_message(conf, IPKG_NOTICE, "\n");
2257 + goto next_package;
2264 + } while (changed && recursive);
2265 + pkg_vec_free(available_pkgs);
2271 +int pkg_mark_provides(pkg_t *pkg)
2273 + int provides_count = pkg->provides_count;
2274 + abstract_pkg_t **provides = pkg->provides;
2276 + pkg->parent->state_flag |= SF_MARKED;
2277 + for (i = 0; i < provides_count; i++) {
2278 + provides[i]->state_flag |= SF_MARKED;
2283 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2285 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2287 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2289 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2292 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2294 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2297 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2299 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2302 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2304 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2307 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2311 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2312 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2315 + pkg_info_preinstall_check(conf);
2317 + if (conf->query_all)
2318 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2320 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2321 + for (i = 0; i < argc; i++) {
2322 + const char *target = argv[i];
2325 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2327 + for (j = 0; j < available_pkgs->len; j++) {
2328 + pkg_t *pkg = available_pkgs->pkgs[j];
2330 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2331 + for (k = 0; k < count; k++) {
2332 + abstract_pkg_t *apkg =
2333 + ((what_field_type == WHATPROVIDES)
2334 + ? pkg->provides[k]
2335 + : pkg->replaces[k]);
2336 + if (fnmatch(target, apkg->name, 0) == 0) {
2337 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2338 + if (strcmp(target, apkg->name) != 0)
2339 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2340 + ipkg_message(conf, IPKG_ERROR, "\n");
2345 + pkg_vec_free(available_pkgs);
2350 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2352 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2355 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2357 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2360 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2364 + pkg_vec_t *installed;
2366 + str_list_t *installed_files;
2367 + str_list_elt_t *iter;
2368 + char *installed_file;
2374 + installed = pkg_vec_alloc();
2375 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2377 + for (i=0; i < installed->len; i++) {
2378 + pkg = installed->pkgs[i];
2380 + installed_files = pkg_get_installed_files(pkg);
2382 + for (iter = installed_files->head; iter; iter = iter->next) {
2383 + installed_file = iter->data;
2384 + if (fnmatch(argv[0], installed_file, 0)==0) {
2386 + printf("%s: %s\n", pkg->name, installed_file);
2388 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2390 + pkg_version_str_alloc(pkg),
2391 + pkg->state_status, p_userdata);
2396 + pkg_free_installed_files(pkg);
2399 + /* XXX: CLEANUP: It's not obvious from the name of
2400 + pkg_hash_fetch_all_installed that we need to call
2401 + pkg_vec_free to avoid a memory leak. */
2402 + pkg_vec_free(installed);
2407 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2410 + /* this is a bit gross */
2411 + struct pkg p1, p2;
2412 + parseVersion(&p1, argv[0]);
2413 + parseVersion(&p2, argv[2]);
2414 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2416 + ipkg_message(conf, IPKG_ERROR,
2417 + "ipkg compare_versions <v1> <op> <v2>\n"
2418 + "<op> is one of <= >= << >> =\n");
2423 +#ifndef HOST_CPU_STR
2424 +#define HOST_CPU_STR__(X) #X
2425 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2426 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2429 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2431 + nv_pair_list_elt_t *l;
2433 + l = conf->arch_list.head;
2435 + nv_pair_t *nv = l->data;
2436 + printf("arch %s %s\n", nv->name, nv->value);
2443 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h
2444 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2445 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h 2006-07-22 16:31:25.000000000 +0200
2447 +/* ipkg_cmd.h - the itsy package management system
2451 + Copyright (C) 2001 University of Southern California
2453 + This program is free software; you can redistribute it and/or
2454 + modify it under the terms of the GNU General Public License as
2455 + published by the Free Software Foundation; either version 2, or (at
2456 + your option) any later version.
2458 + This program is distributed in the hope that it will be useful, but
2459 + WITHOUT ANY WARRANTY; without even the implied warranty of
2460 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2461 + General Public License for more details.
2467 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2472 + int requires_args;
2473 + ipkg_cmd_fun_t fun;
2475 +typedef struct ipkg_cmd ipkg_cmd_t;
2477 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2479 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2480 + const char **argv, void *userdata);
2482 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2484 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2485 +/* install any packges with state_want == SW_INSTALL */
2486 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2487 +/* ensure that all dependences are satisfied */
2488 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2490 +int pkg_mark_provides(pkg_t *pkg);
2493 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_conf.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.c
2494 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2495 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.c 2006-07-22 16:31:25.000000000 +0200
2497 +/* ipkg_conf.c - the itsy package management system
2501 + Copyright (C) 2001 University of Southern California
2503 + This program is free software; you can redistribute it and/or
2504 + modify it under the terms of the GNU General Public License as
2505 + published by the Free Software Foundation; either version 2, or (at
2506 + your option) any later version.
2508 + This program is distributed in the hope that it will be useful, but
2509 + WITHOUT ANY WARRANTY; without even the implied warranty of
2510 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2511 + General Public License for more details.
2517 +#include "ipkg_conf.h"
2519 +#include "xregex.h"
2520 +#include "sprintf_alloc.h"
2521 +#include "ipkg_conf.h"
2522 +#include "ipkg_message.h"
2523 +#include "file_util.h"
2524 +#include "str_util.h"
2525 +#include "xsystem.h"
2528 +ipkg_conf_t *global_conf;
2530 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2531 + pkg_src_list_t *pkg_src_list,
2532 + nv_pair_list_t *tmp_dest_nv_pair_list,
2533 + char **tmp_lists_dir);
2534 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2535 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2536 + const char *name, const char *value);
2537 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2538 + const char *default_dest_name);
2539 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2540 + pkg_src_list_t *nv_pair_list);
2541 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2542 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2544 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2546 + ipkg_option_t tmp[] = {
2547 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2548 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2549 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2550 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2551 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2552 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2553 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2554 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2555 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2556 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2557 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2558 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2559 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2560 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2561 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2562 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2563 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2564 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2565 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2566 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2567 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2571 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2572 + if ( options == NULL ){
2573 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2577 + memcpy(*options, tmp, sizeof(tmp));
2581 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2587 + *conf_str = strdup(arg_str);
2591 +static void ipkg_conf_free_string(char **conf_str)
2599 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2602 + char *tmp_dir_base;
2603 + nv_pair_list_t tmp_dest_nv_pair_list;
2604 + char * lists_dir =NULL;
2606 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2607 + char *pending_dir =NULL;
2609 + memset(conf, 0, sizeof(ipkg_conf_t));
2611 + pkg_src_list_init(&conf->pkg_src_list);
2613 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2614 + pkg_dest_list_init(&conf->pkg_dest_list);
2616 + nv_pair_list_init(&conf->arch_list);
2618 + conf->restrict_to_default_dest = 0;
2619 + conf->default_dest = NULL;
2622 + if (args->tmp_dir)
2623 + tmp_dir_base = args->tmp_dir;
2625 + tmp_dir_base = getenv("TMPDIR");
2626 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2627 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2628 + IPKG_CONF_TMP_DIR_SUFFIX);
2629 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2630 + if (conf->tmp_dir == NULL) {
2631 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2632 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2636 + conf->force_depends = 0;
2637 + conf->force_defaults = 0;
2638 + conf->force_overwrite = 0;
2639 + conf->force_downgrade = 0;
2640 + conf->force_reinstall = 0;
2641 + conf->force_space = 0;
2642 + conf->force_removal_of_essential_packages = 0;
2643 + conf->force_removal_of_dependent_packages = 0;
2645 + conf->verbose_wget = 0;
2646 + conf->offline_root = NULL;
2647 + conf->offline_root_pre_script_cmd = NULL;
2648 + conf->offline_root_post_script_cmd = NULL;
2649 + conf->multiple_providers = 0;
2650 + conf->verbosity = 1;
2651 + conf->noaction = 0;
2653 + conf->http_proxy = NULL;
2654 + conf->ftp_proxy = NULL;
2655 + conf->no_proxy = NULL;
2656 + conf->proxy_user = NULL;
2657 + conf->proxy_passwd = NULL;
2659 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2660 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2661 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2662 + lists_dir=(char *)malloc(1);
2663 + lists_dir[0]='\0';
2664 + if (args->conf_file) {
2665 + struct stat stat_buf;
2666 + err = stat(args->conf_file, &stat_buf);
2668 + if (ipkg_conf_parse_file(conf, args->conf_file,
2669 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2670 + /* Memory leakage from ipkg_conf_parse-file */
2676 + /* if (!lists_dir ){*/
2677 + if (strlen(lists_dir)<=1 ){
2678 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2679 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2682 + if (args->offline_root) {
2683 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2684 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2689 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2690 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2692 + conf->lists_dir = strdup(lists_dir);
2693 + conf->pending_dir = strdup(pending_dir);
2695 + if (args->offline_root)
2696 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2697 + memset(&globbuf, 0, sizeof(globbuf));
2698 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2701 + for (i = 0; i < globbuf.gl_pathc; i++) {
2702 + if (globbuf.gl_pathv[i])
2703 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2704 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2705 + /* Memory leakage from ipkg_conf_parse-file */
2710 + globfree(&globbuf);
2712 + /* if no architectures were defined, then default all, noarch, and host architecture */
2713 + if (nv_pair_list_empty(&conf->arch_list)) {
2714 + nv_pair_list_append(&conf->arch_list, "all", "1");
2715 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2716 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2719 + /* Even if there is no conf file, we'll need at least one dest. */
2720 + if (tmp_dest_nv_pair_list.head == NULL) {
2721 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2722 + IPKG_CONF_DEFAULT_DEST_NAME,
2723 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2726 + /* After parsing the file, set options from command-line, (so that
2727 + command-line arguments take precedence) */
2728 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2729 + really needs to be cleaned up. There is so much duplication
2730 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2731 + a pointer to args_t (which could then not be freed), rather
2732 + than duplicating every field here? */
2733 + if (args->force_depends) {
2734 + conf->force_depends = 1;
2736 + if (args->force_defaults) {
2737 + conf->force_defaults = 1;
2739 + if (args->force_overwrite) {
2740 + conf->force_overwrite = 1;
2742 + if (args->force_downgrade) {
2743 + conf->force_downgrade = 1;
2745 + if (args->force_reinstall) {
2746 + conf->force_reinstall = 1;
2748 + if (args->force_removal_of_dependent_packages) {
2749 + conf->force_removal_of_dependent_packages = 1;
2751 + if (args->force_removal_of_essential_packages) {
2752 + conf->force_removal_of_essential_packages = 1;
2754 + if (args->nodeps) {
2757 + if (args->noaction) {
2758 + conf->noaction = 1;
2760 + if (args->query_all) {
2761 + conf->query_all = 1;
2763 + if (args->verbose_wget) {
2764 + conf->verbose_wget = 1;
2766 + if (args->multiple_providers) {
2767 + conf->multiple_providers = 1;
2769 + if (args->verbosity != conf->verbosity) {
2770 + conf->verbosity = args->verbosity;
2773 + ipkg_conf_override_string(&conf->offline_root,
2774 + args->offline_root);
2775 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2776 + args->offline_root_pre_script_cmd);
2777 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2778 + args->offline_root_post_script_cmd);
2780 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2781 + read anything from there.
2783 + if ( !(args->nocheckfordirorfile)){
2784 + /* need to run load the source list before dest list -Jamey */
2785 + if ( !(args->noreadfeedsfile))
2786 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2788 + /* Now that we have resolved conf->offline_root, we can commit to
2789 + the directory names for the dests and load in all the package
2791 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2794 + err = ipkg_conf_set_default_dest(conf, args->dest);
2800 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2802 + free(pending_dir);
2807 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2809 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2811 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2812 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2813 + __FUNCTION__, conf->tmp_dir);
2817 + err = rmdir(conf->tmp_dir);
2819 + if (errno == ENOTEMPTY) {
2821 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2822 + err = xsystem(cmd);
2826 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2828 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2830 + free(conf->tmp_dir); /*XXX*/
2832 + pkg_src_list_deinit(&conf->pkg_src_list);
2833 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2834 + nv_pair_list_deinit(&conf->arch_list);
2835 + if (&conf->pkg_hash)
2836 + pkg_hash_deinit(&conf->pkg_hash);
2837 + if (&conf->file_hash)
2838 + hash_table_deinit(&conf->file_hash);
2839 + if (&conf->obs_file_hash)
2840 + hash_table_deinit(&conf->obs_file_hash);
2842 + ipkg_conf_free_string(&conf->offline_root);
2843 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2844 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2846 + if (conf->verbosity > 1) {
2848 + hash_table_t *hashes[] = {
2851 + &conf->obs_file_hash };
2852 + for (i = 0; i < 3; i++) {
2853 + hash_table_t *hash = hashes[i];
2855 + int n_conflicts = 0;
2857 + for (j = 0; j < hash->n_entries; j++) {
2859 + hash_entry_t *e = &hash->entries[j];
2862 + while (e && e->key) {
2869 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2870 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2871 + hash_table_deinit(hash);
2876 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2877 + const char *default_dest_name)
2879 + pkg_dest_list_elt_t *iter;
2882 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2883 + dest = iter->data;
2884 + if (strcmp(dest->name, default_dest_name) == 0) {
2885 + conf->default_dest = dest;
2886 + conf->restrict_to_default_dest = 1;
2891 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2896 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2898 + pkg_src_list_elt_t *iter;
2902 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2904 + if (src == NULL) {
2908 + sprintf_alloc(&list_file, "%s/%s",
2909 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2912 + if (file_exists(list_file)) {
2913 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2921 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2923 + nv_pair_list_elt_t *iter;
2924 + nv_pair_t *nv_pair;
2928 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2929 + nv_pair = iter->data;
2931 + if (conf->offline_root) {
2932 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2934 + root_dir = strdup(nv_pair->value);
2936 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2938 + if (dest == NULL) {
2941 + if (conf->default_dest == NULL) {
2942 + conf->default_dest = dest;
2944 + if (file_exists(dest->status_file_name)) {
2945 + pkg_hash_add_from_file(conf, dest->status_file_name,
2953 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2954 + pkg_src_list_t *pkg_src_list,
2955 + nv_pair_list_t *tmp_dest_nv_pair_list,
2958 + ipkg_option_t * options;
2959 + FILE *file = fopen(filename, "r");
2960 + regex_t valid_line_re, comment_re;
2961 +#define regmatch_size 12
2962 + regmatch_t regmatch[regmatch_size];
2964 + if (ipkg_init_options_array(conf, &options)<0)
2967 + if (file == NULL) {
2968 + fprintf(stderr, "%s: failed to open %s: %s\n",
2969 + __FUNCTION__, filename, strerror(errno));
2973 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2975 + xregcomp(&comment_re,
2976 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2978 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2983 + char *type, *name, *value, *extra;
2985 + line = file_read_line_alloc(file);
2987 + if (line == NULL) {
2993 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2997 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2999 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3000 + filename, line_num, line);
3004 + /* This has to be so ugly to deal with optional quotation marks */
3005 + if (regmatch[2].rm_so > 0) {
3006 + type = strndup(line + regmatch[2].rm_so,
3007 + regmatch[2].rm_eo - regmatch[2].rm_so);
3009 + type = strndup(line + regmatch[3].rm_so,
3010 + regmatch[3].rm_eo - regmatch[3].rm_so);
3012 + if (regmatch[5].rm_so > 0) {
3013 + name = strndup(line + regmatch[5].rm_so,
3014 + regmatch[5].rm_eo - regmatch[5].rm_so);
3016 + name = strndup(line + regmatch[6].rm_so,
3017 + regmatch[6].rm_eo - regmatch[6].rm_so);
3019 + if (regmatch[8].rm_so > 0) {
3020 + value = strndup(line + regmatch[8].rm_so,
3021 + regmatch[8].rm_eo - regmatch[8].rm_so);
3023 + value = strndup(line + regmatch[9].rm_so,
3024 + regmatch[9].rm_eo - regmatch[9].rm_so);
3027 + if (regmatch[11].rm_so > 0) {
3028 + extra = strndup (line + regmatch[11].rm_so,
3029 + regmatch[11].rm_eo - regmatch[11].rm_so);
3032 + /* We use the tmp_dest_nv_pair_list below instead of
3033 + conf->pkg_dest_list because we might encounter an
3034 + offline_root option later and that would invalidate the
3035 + directories we would have computed in
3036 + pkg_dest_list_init. (We do a similar thing with
3037 + tmp_src_nv_pair_list for sake of symmetry.) */
3038 + if (strcmp(type, "option") == 0) {
3039 + ipkg_conf_set_option(options, name, value);
3040 + } else if (strcmp(type, "src") == 0) {
3041 + if (!nv_pair_list_find(pkg_src_list, name)) {
3042 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3044 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3047 + } else if (strcmp(type, "src/gz") == 0) {
3048 + if (!nv_pair_list_find(pkg_src_list, name)) {
3049 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3051 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3054 + } else if (strcmp(type, "dest") == 0) {
3055 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3056 + } else if (strcmp(type, "lists_dir") == 0) {
3057 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3058 + if (*lists_dir == NULL) {
3059 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3063 + sprintf (*lists_dir,"%s",value);
3064 + } else if (strcmp(type, "arch") == 0) {
3065 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3067 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3068 + value = strdup("10");
3070 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3072 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3073 + "parameter: %s %s %s\n", type, name, value);
3089 + regfree(&comment_re);
3090 + regfree(&valid_line_re);
3096 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3097 + const char *name, const char *value)
3100 + while (options[i].name) {
3101 + if (strcmp(options[i].name, name) == 0) {
3102 + switch (options[i].type) {
3103 + case IPKG_OPT_TYPE_BOOL:
3104 + *((int *)options[i].value) = 1;
3106 + case IPKG_OPT_TYPE_INT:
3108 + *((int *)options[i].value) = atoi(value);
3111 + printf("%s: Option %s need an argument\n",
3112 + __FUNCTION__, name);
3115 + case IPKG_OPT_TYPE_STRING:
3117 + *((char **)options[i].value) = strdup(value);
3120 + printf("%s: Option %s need an argument\n",
3121 + __FUNCTION__, name);
3129 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3130 + __FUNCTION__, name, value);
3134 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3136 + pkg_dest_list_elt_t *iter;
3143 + if (conf->noaction)
3145 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3146 + dest = iter->data;
3147 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3148 + if (dest->status_file == NULL) {
3149 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3150 + __FUNCTION__, dest->status_file_name, strerror(errno));
3154 + all = pkg_vec_alloc();
3155 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3157 + for(i = 0; i < all->len; i++) {
3158 + pkg = all->pkgs[i];
3159 + /* We don't need most uninstalled packages in the status file */
3160 + if (pkg->state_status == SS_NOT_INSTALLED
3161 + && (pkg->state_want == SW_UNKNOWN
3162 + || pkg->state_want == SW_DEINSTALL
3163 + || pkg->state_want == SW_PURGE)) {
3167 + fprintf(stderr, "Null package\n");
3169 + if (pkg->dest == NULL) {
3170 + fprintf(stderr, "%s: ERROR: Can't write status for "
3171 + "package %s since it has a NULL dest\n",
3172 + __FUNCTION__, pkg->name);
3175 + if (pkg->dest->status_file) {
3176 + pkg_print_status(pkg, pkg->dest->status_file);
3180 + pkg_vec_free(all);
3182 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3183 + dest = iter->data;
3184 + if (dest->status_file) {
3185 + err = ferror(dest->status_file);
3186 + fclose(dest->status_file);
3187 + dest->status_file = NULL;
3189 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3191 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3192 + "retaining old %s\n", __FUNCTION__,
3193 + dest->status_file_tmp_name, dest->status_file_name);
3202 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3204 + char *root_filename;
3205 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3206 + return root_filename;
3208 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_conf.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.h
3209 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3210 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.h 2006-07-22 16:31:25.000000000 +0200
3212 +/* ipkg_conf.h - the itsy package management system
3216 + Copyright (C) 2001 University of Southern California
3218 + This program is free software; you can redistribute it and/or
3219 + modify it under the terms of the GNU General Public License as
3220 + published by the Free Software Foundation; either version 2, or (at
3221 + your option) any later version.
3223 + This program is distributed in the hope that it will be useful, but
3224 + WITHOUT ANY WARRANTY; without even the implied warranty of
3225 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3226 + General Public License for more details.
3229 +#ifndef IPKG_CONF_H
3230 +#define IPKG_CONF_H
3232 +typedef struct ipkg_conf ipkg_conf_t;
3234 +#include "hash_table.h"
3238 +#include "pkg_hash.h"
3239 +#include "pkg_src_list.h"
3240 +#include "pkg_dest_list.h"
3241 +#include "nv_pair_list.h"
3243 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3244 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3245 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3246 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3248 +/* In case the config file defines no dest */
3249 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3250 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3252 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3256 + pkg_src_list_t pkg_src_list;
3257 + pkg_dest_list_t pkg_dest_list;
3258 + nv_pair_list_t arch_list;
3260 + int restrict_to_default_dest;
3261 + pkg_dest_t *default_dest;
3264 + const char *lists_dir;
3265 + const char *pending_dir;
3268 + int force_depends;
3269 + int force_defaults;
3270 + int force_overwrite;
3271 + int force_downgrade;
3272 + int force_reinstall;
3274 + int force_removal_of_dependent_packages;
3275 + int force_removal_of_essential_packages;
3276 + int nodeps; /* do not follow dependences */
3278 + int multiple_providers;
3279 + char *offline_root;
3280 + char *offline_root_pre_script_cmd;
3281 + char *offline_root_post_script_cmd;
3286 + /* proxy options */
3291 + char *proxy_passwd;
3293 + hash_table_t pkg_hash;
3294 + hash_table_t file_hash;
3295 + hash_table_t obs_file_hash;
3298 +enum ipkg_option_type {
3299 + IPKG_OPT_TYPE_BOOL,
3300 + IPKG_OPT_TYPE_INT,
3301 + IPKG_OPT_TYPE_STRING
3303 +typedef enum ipkg_option_type ipkg_option_type_t;
3305 +typedef struct ipkg_option ipkg_option_t;
3306 +struct ipkg_option {
3308 + const ipkg_option_type_t type;
3309 + const void *value;
3312 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3313 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3315 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3316 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3319 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_configure.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.c
3320 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3321 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.c 2006-07-22 16:31:25.000000000 +0200
3323 +/* ipkg_configure.c - the itsy package management system
3327 + Copyright (C) 2001 University of Southern California
3329 + This program is free software; you can redistribute it and/or
3330 + modify it under the terms of the GNU General Public License as
3331 + published by the Free Software Foundation; either version 2, or (at
3332 + your option) any later version.
3334 + This program is distributed in the hope that it will be useful, but
3335 + WITHOUT ANY WARRANTY; without even the implied warranty of
3336 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3337 + General Public License for more details.
3342 +#include "ipkg_configure.h"
3344 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3348 + /* DPKG_INCOMPATIBILITY:
3349 + dpkg actually does some conffile handling here, rather than at the
3350 + end of ipkg_install(). Do we care? */
3351 + /* DPKG_INCOMPATIBILITY:
3352 + dpkg actually includes a version number to this script call */
3353 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3355 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3359 + ipkg_state_changed++;
3363 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_configure.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.h
3364 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3365 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.h 2006-07-22 16:31:25.000000000 +0200
3367 +/* ipkg_configure.h - the itsy package management system
3371 + Copyright (C) 2001 University of Southern California
3373 + This program is free software; you can redistribute it and/or
3374 + modify it under the terms of the GNU General Public License as
3375 + published by the Free Software Foundation; either version 2, or (at
3376 + your option) any later version.
3378 + This program is distributed in the hope that it will be useful, but
3379 + WITHOUT ANY WARRANTY; without even the implied warranty of
3380 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3381 + General Public License for more details.
3384 +#ifndef IPKG_CONFIGURE_H
3385 +#define IPKG_CONFIGURE_H
3387 +#include "ipkg_conf.h"
3389 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3392 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_download.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.c
3393 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3394 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.c 2006-07-22 16:31:25.000000000 +0200
3396 +/* ipkg_download.c - the itsy package management system
3400 + Copyright (C) 2001 University of Southern California
3402 + This program is free software; you can redistribute it and/or
3403 + modify it under the terms of the GNU General Public License as
3404 + published by the Free Software Foundation; either version 2, or (at
3405 + your option) any later version.
3407 + This program is distributed in the hope that it will be useful, but
3408 + WITHOUT ANY WARRANTY; without even the implied warranty of
3409 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3410 + General Public License for more details.
3414 +#include "ipkg_download.h"
3415 +#include "ipkg_message.h"
3417 +#include "sprintf_alloc.h"
3418 +#include "xsystem.h"
3419 +#include "file_util.h"
3420 +#include "str_util.h"
3422 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3426 + char *src_basec = strdup(src);
3427 + char *src_base = basename(src_basec);
3428 + char *tmp_file_location;
3431 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3435 + if (str_starts_with(src, "file:")) {
3437 + const char *file_src = src + 5;
3438 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3439 + ret = file_copy(src + 5, dest_file_name);
3440 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3444 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3445 + err = unlink(tmp_file_location);
3446 + if (err && errno != ENOENT) {
3447 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3448 + __FUNCTION__, tmp_file_location, strerror(errno));
3449 + free(tmp_file_location);
3453 + if (conf->http_proxy) {
3454 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3455 + setenv("http_proxy", conf->http_proxy, 1);
3457 + if (conf->ftp_proxy) {
3458 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3459 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3461 + if (conf->no_proxy) {
3462 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3463 + setenv("no_proxy", conf->no_proxy, 1);
3466 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3467 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3468 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3469 + conf->proxy_user ? "--proxy-user=" : "",
3470 + conf->proxy_user ? conf->proxy_user : "",
3471 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3472 + conf->proxy_passwd ? conf->proxy_passwd : "",
3473 + conf->verbose_wget ? "" : "-q",
3476 + err = xsystem(cmd);
3479 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3480 + __FUNCTION__, err, cmd);
3482 + unlink(tmp_file_location);
3483 + free(tmp_file_location);
3490 + err = file_move(tmp_file_location, dest_file_name);
3492 + free(tmp_file_location);
3502 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3507 + if (pkg->src == NULL) {
3508 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3509 + pkg->name, pkg->parent->name);
3513 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3515 + /* XXX: BUG: The pkg->filename might be something like
3516 + "../../foo.ipk". While this is correct, and exactly what we
3517 + want to use to construct url above, here we actually need to
3518 + use just the filename part, without any directory. */
3519 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3521 + err = ipkg_download(conf, url, pkg->local_filename);
3528 + * Downloads file from url, installs in package database, return package name.
3530 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3538 + if (str_starts_with(url, "http://")
3539 + || str_starts_with(url, "ftp://")) {
3541 + char *file_basec = strdup(url);
3542 + char *file_base = basename(file_basec);
3544 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3545 + err = ipkg_download(conf, url, tmp_file);
3549 + err = pkg_init_from_file(pkg, tmp_file);
3552 + pkg->local_filename = strdup(tmp_file);
3557 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3558 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3560 + err = pkg_init_from_file(pkg, url);
3563 + pkg->local_filename = strdup(url);
3564 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3565 + pkg->provided_by_hand = 1;
3573 + if (!pkg->architecture) {
3574 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3578 + pkg->dest = conf->default_dest;
3579 + pkg->state_want = SW_INSTALL;
3580 + pkg->state_flag |= SF_PREFER;
3581 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3582 + if ( pkg == NULL ){
3583 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3587 + *namep = strdup(pkg->name);
3591 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_download.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h
3592 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3593 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-07-22 16:31:25.000000000 +0200
3595 +/* ipkg_download.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.
3612 +#ifndef IPKG_DOWNLOAD_H
3613 +#define IPKG_DOWNLOAD_H
3615 +#include "ipkg_conf.h"
3617 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3618 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3620 + * Downloads file from url, installs in package database, return package name.
3622 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3625 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h
3626 --- busybox-1.2.0-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3627 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h 2006-07-22 16:31:25.000000000 +0200
3629 +/* ipkg.h - the itsy package management system
3633 + Copyright (C) 2001 University of Southern California
3635 + This program is free software; you can redistribute it and/or
3636 + modify it under the terms of the GNU General Public License as
3637 + published by the Free Software Foundation; either version 2, or (at
3638 + your option) any later version.
3640 + This program is distributed in the hope that it will be useful, but
3641 + WITHOUT ANY WARRANTY; without even the implied warranty of
3642 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3643 + General Public License for more details.
3650 +#ifdef HAVE_CONFIG_H
3651 +#include "config.h"
3656 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3659 +#include "ipkg_includes.h"
3660 +#include "ipkg_conf.h"
3661 +#include "ipkg_message.h"
3663 +#define IPKG_PKG_EXTENSION ".ipk"
3664 +#define DPKG_PKG_EXTENSION ".deb"
3666 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3667 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3669 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3670 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3671 +#define IPKG_INFO_DIR_SUFFIX "info"
3672 +#define IPKG_STATUS_FILE_SUFFIX "status"
3674 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3676 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3678 +#define IPKG_VERSION "0.99.162"
3683 + IPKG_PKG_DEPS_UNSATISFIED,
3684 + IPKG_PKG_IS_ESSENTIAL,
3685 + IPKG_PKG_HAS_DEPENDENTS,
3686 + IPKG_PKG_HAS_NO_CANDIDATE
3688 +typedef enum ipkg_error ipkg_error_t;
3690 +extern int ipkg_state_changed;
3695 + struct errlist * next;
3698 +extern struct errlist* error_list;
3700 +extern ipkg_conf_t *global_conf;
3703 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h
3704 --- busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3705 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-07-22 16:31:25.000000000 +0200
3707 +#ifndef IPKG_INCLUDES_H
3708 +#define IPKG_INCLUDES_H
3710 +/* Define to 1 if you have the <memory.h> header file. */
3711 +#define HAVE_MEMORY_H 1
3713 +/* Define to 1 if you have the <regex.h> header file. */
3714 +#define HAVE_REGEX_H 1
3716 +/* Define to 1 if you have the <stdlib.h> header file. */
3717 +#define HAVE_STDLIB_H 1
3719 +/* Define to 1 if you have the <strings.h> header file. */
3720 +#define HAVE_STRINGS_H 1
3722 +/* Define to 1 if you have the <string.h> header file. */
3723 +#define HAVE_STRING_H 1
3725 +/* Define to 1 if you have the <sys/stat.h> header file. */
3726 +#define HAVE_SYS_STAT_H 1
3728 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3729 +#define HAVE_SYS_WAIT_H 1
3731 +/* Define to 1 if you have the <unistd.h> header file. */
3732 +#define HAVE_UNISTD_H 1
3734 +/* Define to 1 if you have the ANSI C header files. */
3735 +#define STDC_HEADERS 1
3741 +# include <stdlib.h>
3742 +# include <stdarg.h>
3743 +# include <stddef.h>
3744 +# include <ctype.h>
3745 +# include <errno.h>
3748 +# include <stdlib.h>
3753 +# include <regex.h>
3757 +# if !STDC_HEADERS && HAVE_MEMORY_H
3758 +# include <memory.h>
3760 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3762 +# define __USE_GNU 1
3764 +# include <string.h>
3769 +# include <strings.h>
3772 +#if HAVE_SYS_STAT_H
3773 +# include <sys/stat.h>
3776 +#if HAVE_SYS_WAIT_H
3777 +# include <sys/wait.h>
3781 +# include <sys/types.h>
3782 +# include <unistd.h>
3785 +#endif /* IPKG_INCLUDES_H */
3786 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_install.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c
3787 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3788 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-07-22 16:31:25.000000000 +0200
3790 +/* ipkg_install.c - the itsy package management system
3794 + Copyright (C) 2001 University of Southern California
3796 + This program is free software; you can redistribute it and/or
3797 + modify it under the terms of the GNU General Public License as
3798 + published by the Free Software Foundation; either version 2, or (at
3799 + your option) any later version.
3801 + This program is distributed in the hope that it will be useful, but
3802 + WITHOUT ANY WARRANTY; without even the implied warranty of
3803 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3804 + General Public License for more details.
3809 +#include <dirent.h>
3812 +#include <signal.h>
3813 +typedef void (*sighandler_t)(int);
3816 +#include "pkg_hash.h"
3817 +#include "pkg_extract.h"
3819 +#include "ipkg_install.h"
3820 +#include "ipkg_configure.h"
3821 +#include "ipkg_download.h"
3822 +#include "ipkg_remove.h"
3824 +#include "ipkg_utils.h"
3825 +#include "ipkg_message.h"
3827 +#include "sprintf_alloc.h"
3828 +#include "file_util.h"
3829 +#include "str_util.h"
3830 +#include "xsystem.h"
3833 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3834 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3835 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3837 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3838 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3839 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3840 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3841 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3842 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3843 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3847 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3848 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3849 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3851 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3852 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3853 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3854 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3855 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3857 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3859 +static int user_prefers_old_conffile(const char *file, const char *backup);
3861 +static char *backup_filename_alloc(const char *file_name);
3862 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3863 +static int backup_exists_for(const char *file_name);
3864 +static int backup_remove(const char *file_name);
3867 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3871 + char *old_version, *new_version;
3874 + if (pkg == NULL) {
3878 + err = pkg_init_from_file(pkg, filename);
3883 + if (!pkg->architecture) {
3884 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3888 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3889 + freeing the pkg that we pass in. It might be nice to clean this up
3891 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3892 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3894 + pkg->local_filename = strdup(filename);
3897 + old_version = pkg_version_str_alloc(old);
3898 + new_version = pkg_version_str_alloc(pkg);
3900 + cmp = pkg_compare_versions(old, pkg);
3901 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3902 + cmp = -1 ; /* then we force ipkg to downgrade */
3903 + /* We need to use a value < 0 because in the 0 case we are asking to */
3904 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3907 + ipkg_message(conf, IPKG_NOTICE,
3908 + "Not downgrading package %s on %s from %s to %s.\n",
3909 + old->name, old->dest->name, old_version, new_version);
3910 + pkg->state_want = SW_DEINSTALL;
3911 + pkg->state_flag |= SF_OBSOLETE;
3912 + free(old_version);
3913 + free(new_version);
3916 + free(old_version);
3917 + free(new_version);
3921 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3922 + return ipkg_install_pkg(conf, pkg,0);
3925 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3929 + char *old_version, *new_version;
3931 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3932 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3934 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3936 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3937 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3939 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3941 +/* Pigi Basically here is broken the version stuff.
3942 + What's happening is that nothing provide the version to differents
3943 + functions, so the returned struct is always the latest.
3944 + That's why the install by name don't work.
3946 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3949 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3951 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3952 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3954 + if (new == NULL) {
3955 + return IPKG_PKG_HAS_NO_CANDIDATE;
3958 + new->state_flag |= SF_USER;
3960 + old_version = pkg_version_str_alloc(old);
3961 + new_version = pkg_version_str_alloc(new);
3963 + cmp = pkg_compare_versions(old, new);
3964 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3965 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3966 + cmp = -1 ; /* then we force ipkg to downgrade */
3967 + /* We need to use a value < 0 because in the 0 case we are asking to */
3968 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3970 + ipkg_message(conf, IPKG_DEBUG,
3971 + "Comparing visible versions of pkg %s:"
3972 + "\n\t%s is installed "
3973 + "\n\t%s is available "
3974 + "\n\t%d was comparison result\n",
3975 + pkg_name, old_version, new_version, cmp);
3976 + if (cmp == 0 && !conf->force_reinstall) {
3977 + ipkg_message(conf, IPKG_NOTICE,
3978 + "Package %s (%s) installed in %s is up to date.\n",
3979 + old->name, old_version, old->dest->name);
3980 + free(old_version);
3981 + free(new_version);
3983 + } else if (cmp > 0) {
3984 + ipkg_message(conf, IPKG_NOTICE,
3985 + "Not downgrading package %s on %s from %s to %s.\n",
3986 + old->name, old->dest->name, old_version, new_version);
3987 + free(old_version);
3988 + free(new_version);
3990 + } else if (cmp < 0) {
3991 + new->dest = old->dest;
3992 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3996 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3997 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3998 + return any kind of integer, (might be errno from a syscall,
3999 + etc.). This is a real mess and will need to be cleaned up if
4000 + anyone ever wants to make a nice libipkg. */
4002 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4003 + return ipkg_install_pkg(conf, new,0);
4006 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4008 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4011 + abstract_pkg_t *ppkg ;
4013 + if (providers == NULL)
4014 + return IPKG_PKG_HAS_NO_CANDIDATE;
4016 + for (i = 0; i < providers->len; i++) {
4017 + ppkg = abstract_pkg_vec_get(providers, i);
4018 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4019 + err = ipkg_install_by_name(conf, ppkg->name);
4022 +/* XXX Maybe ppkg should be freed ? */
4028 + * Walk dependence graph starting with pkg, collect packages to be
4029 + * installed into pkgs_needed, in dependence order.
4031 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4034 + pkg_vec_t *depends = pkg_vec_alloc();
4035 + char **unresolved = NULL;
4038 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4043 + ipkg_message(conf, IPKG_ERROR,
4044 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4045 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4046 + while (*unresolved) {
4047 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4050 + ipkg_message(conf, IPKG_ERROR, "\n");
4051 + if (! conf->force_depends) {
4052 + ipkg_message(conf, IPKG_INFO,
4053 + "This could mean that your package list is out of date or that the packages\n"
4054 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4055 + "of this problem try again with the '-force-depends' option.\n");
4056 + pkg_vec_free(depends);
4057 + return IPKG_PKG_DEPS_UNSATISFIED;
4061 + if (ndepends <= 0) {
4062 + pkg_vec_free(depends);
4066 + for (i = 0; i < depends->len; i++) {
4067 + pkg_t *dep = depends->pkgs[i];
4068 + /* The package was uninstalled when we started, but another
4069 + dep earlier in this loop may have depended on it and pulled
4070 + it in, so check first. */
4071 + if ((dep->state_status != SS_INSTALLED)
4072 + && (dep->state_status != SS_UNPACKED)
4073 + && (dep->state_want != SW_INSTALL)) {
4075 + /* Mark packages as to-be-installed */
4076 + dep->state_want = SW_INSTALL;
4078 + /* Dependencies should be installed the same place as pkg */
4079 + if (dep->dest == NULL) {
4080 + dep->dest = pkg->dest;
4083 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4085 + pkg_vec_free(depends);
4091 + pkg_vec_insert(pkgs_needed, pkg);
4093 + pkg_vec_free(depends);
4098 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4102 + char *old_version, *new_version;
4104 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4106 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4107 + if (new == NULL) {
4108 + return IPKG_PKG_HAS_NO_CANDIDATE;
4111 + old_version = pkg_version_str_alloc(old);
4112 + new_version = pkg_version_str_alloc(new);
4114 + cmp = pkg_compare_versions(old, new);
4115 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4116 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4117 + cmp = -1 ; /* then we force ipkg to downgrade */
4118 + /* We need to use a value < 0 because in the 0 case we are asking to */
4119 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4121 + ipkg_message(conf, IPKG_DEBUG,
4122 + "comparing visible versions of pkg %s:"
4123 + "\n\t%s is installed "
4124 + "\n\t%s is available "
4125 + "\n\t%d was comparison result\n",
4126 + pkg_name, old_version, new_version, cmp);
4127 + if (cmp == 0 && !conf->force_reinstall) {
4128 + ipkg_message(conf, IPKG_NOTICE,
4129 + "Package %s (%s) installed in %s is up to date.\n",
4130 + old->name, old_version, old->dest->name);
4131 + free(old_version);
4132 + free(new_version);
4134 + } else if (cmp > 0) {
4135 + ipkg_message(conf, IPKG_NOTICE,
4136 + "Not downgrading package %s on %s from %s to %s.\n",
4137 + old->name, old->dest->name, old_version, new_version);
4138 + free(old_version);
4139 + free(new_version);
4141 + } else if (cmp < 0) {
4142 + new->dest = old->dest;
4143 + old->state_want = SW_DEINSTALL;
4144 + old->state_flag |= SF_OBSOLETE;
4147 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4152 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4155 + pkg_vec_t *depends = pkg_vec_alloc();
4157 + char **unresolved = NULL;
4160 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4165 + ipkg_message(conf, IPKG_ERROR,
4166 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4167 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4168 + while (*unresolved) {
4169 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4172 + ipkg_message(conf, IPKG_ERROR, "\n");
4173 + if (! conf->force_depends) {
4174 + ipkg_message(conf, IPKG_INFO,
4175 + "This could mean that your package list is out of date or that the packages\n"
4176 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4177 + "of this problem try again with the '-force-depends' option.\n");
4178 + pkg_vec_free(depends);
4179 + return IPKG_PKG_DEPS_UNSATISFIED;
4183 + if (ndepends <= 0) {
4187 + /* Mark packages as to-be-installed */
4188 + for (i=0; i < depends->len; i++) {
4189 + /* Dependencies should be installed the same place as pkg */
4190 + if (depends->pkgs[i]->dest == NULL) {
4191 + depends->pkgs[i]->dest = pkg->dest;
4193 + depends->pkgs[i]->state_want = SW_INSTALL;
4196 + for (i = 0; i < depends->len; i++) {
4197 + dep = depends->pkgs[i];
4198 + /* The package was uninstalled when we started, but another
4199 + dep earlier in this loop may have depended on it and pulled
4200 + it in, so check first. */
4201 + if ((dep->state_status != SS_INSTALLED)
4202 + && (dep->state_status != SS_UNPACKED)) {
4203 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4204 + err = ipkg_install_pkg(conf, dep,0);
4206 + pkg_vec_free(depends);
4212 + pkg_vec_free(depends);
4218 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4219 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4221 + if (conf->nodeps == 0) {
4223 + pkg_vec_t *installed = pkg_vec_alloc();
4224 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4225 + for (i = 0; i < installed->len; i++) {
4226 + pkg_t *pkg = installed->pkgs[i];
4227 + satisfy_dependencies_for(conf, pkg);
4229 + pkg_vec_free(installed);
4236 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4239 + pkg_vec_t *conflicts = NULL;
4241 + const char *prefix;
4242 + if (conf->force_depends) {
4243 + level = IPKG_NOTICE;
4244 + prefix = "Warning";
4246 + level = IPKG_ERROR;
4250 + if (!conf->force_depends)
4251 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4254 + ipkg_message(conf, level,
4255 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4257 + while (i < conflicts->len)
4258 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4259 + ipkg_message(conf, level, "\n");
4260 + pkg_vec_free(conflicts);
4261 + return IPKG_PKG_DEPS_UNSATISFIED;
4266 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4268 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4269 + str_list_elt_t *iter;
4271 + for (iter = new_list->head; iter; iter = iter->next) {
4272 + char *new_file = iter->data;
4273 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4275 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4276 + if (!owner || (owner == old_pkg))
4277 + file_hash_set_file_owner(conf, new_file, new_pkg);
4280 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4281 + for (iter = old_list->head; iter; iter = iter->next) {
4282 + char *old_file = iter->data;
4283 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4284 + if (owner == old_pkg) {
4286 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4293 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4295 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4297 + /* sma 6.20.02: yup; here's the first bit */
4299 + * XXX: BUG easy for cworth
4300 + * 1) please point the call below to the correct current root destination
4301 + * 2) we need to resolve how to check the required space for a pending pkg,
4302 + * my diddling with the .ipk file size below isn't going to cut it.
4303 + * 3) return a proper error code instead of 1
4305 + int comp_size, blocks_available;
4307 + if (!conf->force_space && pkg->installed_size != NULL) {
4308 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4310 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4311 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4312 + comp_size = (int)((comp_size + 1023) / 1024);
4314 + if (comp_size >= blocks_available) {
4315 + ipkg_message(conf, IPKG_ERROR,
4316 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4317 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4324 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4327 + char *conffiles_file_name;
4329 + FILE *conffiles_file;
4331 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4333 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4334 + if (pkg->tmp_unpack_dir == NULL) {
4335 + ipkg_message(conf, IPKG_ERROR,
4336 + "%s: Failed to create temporary directory '%s': %s\n",
4337 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4341 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4346 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4347 + conffiles. Seems like I should be able to get everything to go
4348 + through pkg_init_from_file. If so, maybe it would make sense to
4349 + move all of unpack_pkg_control_files to that function. */
4351 + /* Don't need to re-read conffiles if we already have it */
4352 + if (pkg->conffiles.head) {
4356 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4357 + if (! file_exists(conffiles_file_name)) {
4358 + free(conffiles_file_name);
4362 + conffiles_file = fopen(conffiles_file_name, "r");
4363 + if (conffiles_file == NULL) {
4364 + fprintf(stderr, "%s: failed to open %s: %s\n",
4365 + __FUNCTION__, conffiles_file_name, strerror(errno));
4366 + free(conffiles_file_name);
4369 + free(conffiles_file_name);
4373 + char *cf_name_in_dest;
4375 + cf_name = file_read_line_alloc(conffiles_file);
4376 + if (cf_name == NULL) {
4379 + str_chomp(cf_name);
4380 + if (cf_name[0] == '\0') {
4384 + /* Prepend dest->root_dir to conffile name.
4385 + Take pains to avoid multiple slashes. */
4386 + root_dir = pkg->dest->root_dir;
4387 + if (conf->offline_root)
4388 + /* skip the offline_root prefix */
4389 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4390 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4391 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4393 + /* Can't get an md5sum now, (file isn't extracted yet).
4394 + We'll wait until resolve_conffiles */
4395 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4398 + free(cf_name_in_dest);
4401 + fclose(conffiles_file);
4406 +/* returns number of installed replacees */
4407 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4409 + abstract_pkg_t **replaces = pkg->replaces;
4410 + int replaces_count = pkg->replaces_count;
4412 + for (i = 0; i < replaces_count; i++) {
4413 + abstract_pkg_t *ab_pkg = replaces[i];
4414 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4416 + for (j = 0; j < pkg_vec->len; j++) {
4417 + pkg_t *replacee = pkg_vec->pkgs[j];
4418 + if (!pkg_conflicts(pkg, replacee))
4420 + if (replacee->state_status == SS_INSTALLED) {
4421 + pkg_vec_insert(installed_replacees, replacee);
4426 + return installed_replacees->len;
4429 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4432 + int replaces_count = replacees->len;
4433 + for (i = 0; i < replaces_count; i++) {
4434 + pkg_t *replacee = replacees->pkgs[i];
4436 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4437 + err = ipkg_remove_pkg(conf, replacee,0);
4444 +/* to unwind the removal: make sure they are installed */
4445 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4448 + int replaces_count = replacees->len;
4449 + for (i = 0; i < replaces_count; i++) {
4450 + pkg_t *replacee = replacees->pkgs[i];
4451 + if (replacee->state_status != SS_INSTALLED) {
4452 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4453 + err = ipkg_install_pkg(conf, replacee,0);
4461 +int caught_sigint = 0;
4462 +static void ipkg_install_pkg_sigint_handler(int sig)
4464 + caught_sigint = sig;
4467 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4468 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4471 + char message_out[15];
4472 + char *old_version = pkg_version_str_alloc(old_pkg);
4473 + char *new_version = pkg_version_str_alloc(pkg);
4474 + int cmp = pkg_compare_versions(old_pkg, pkg);
4477 + memset(message_out,'\x0',15);
4478 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4479 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4480 + cmp = -1 ; /* then we force ipkg to downgrade */
4481 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4482 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4486 + ipkg_message(conf, IPKG_NOTICE,
4487 + "Not downgrading package %s on %s from %s to %s.\n",
4488 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4490 + } else if (cmp < 0) {
4491 + ipkg_message(conf, IPKG_NOTICE,
4492 + "%s%s on %s from %s to %s...\n",
4493 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4494 + pkg->dest = old_pkg->dest;
4496 + } else /* cmp == 0 */ {
4497 + if (conf->force_reinstall) {
4498 + ipkg_message(conf, IPKG_NOTICE,
4499 + "Reinstalling %s (%s) on %s...\n",
4500 + pkg->name, new_version, old_pkg->dest->name);
4501 + pkg->dest = old_pkg->dest;
4504 + ipkg_message(conf, IPKG_NOTICE,
4505 + "Not installing %s (%s) on %s -- already installed.\n",
4506 + pkg->name, new_version, old_pkg->dest->name);
4510 + free(old_version);
4511 + free(new_version);
4514 + char message_out[15] ;
4515 + memset(message_out,'\x0',15);
4517 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4519 + strncpy( message_out,"Installing ",strlen("Installing ") );
4520 + char *version = pkg_version_str_alloc(pkg);
4522 + ipkg_message(conf, IPKG_NOTICE,
4523 + "%s%s (%s) to %s...\n", message_out,
4524 + pkg->name, version, pkg->dest->name);
4530 +/* and now the meat... */
4531 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4535 + pkg_t *old_pkg = NULL;
4536 + pkg_vec_t *replacees;
4537 + abstract_pkg_t *ab_pkg = NULL;
4538 + int old_state_flag;
4542 + if ( from_upgrade )
4543 + message = 1; /* Coming from an upgrade, and should change the output message */
4546 + ipkg_message(conf, IPKG_ERROR,
4547 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4551 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4553 + if (!pkg_arch_supported(conf, pkg)) {
4554 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4555 + pkg->architecture, pkg->name);
4558 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4559 + err = satisfy_dependencies_for(conf, pkg);
4560 + if (err) { return err; }
4562 + ipkg_message(conf, IPKG_NOTICE,
4563 + "Package %s is already installed in %s.\n",
4564 + pkg->name, pkg->dest->name);
4568 + if (pkg->dest == NULL) {
4569 + pkg->dest = conf->default_dest;
4572 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4574 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4575 + if (err) { return err; }
4577 + pkg->state_want = SW_INSTALL;
4579 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4583 + /* Abhaya: conflicts check */
4584 + err = check_conflicts_for(conf, pkg);
4585 + if (err) { return err; }
4587 + /* this setup is to remove the upgrade scenario in the end when
4588 + installing pkg A, A deps B & B deps on A. So both B and A are
4589 + installed. Then A's installation is started resulting in an
4590 + uncecessary upgrade */
4591 + if (pkg->state_status == SS_INSTALLED
4592 + && conf->force_reinstall == 0) return 0;
4594 + err = verify_pkg_installable(conf, pkg);
4595 + if (err) { return err; }
4597 + if (pkg->local_filename == NULL) {
4598 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4600 + ipkg_message(conf, IPKG_ERROR,
4601 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4607 +/* Check for md5 values */
4610 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4611 + if (strcmp(file_md5, pkg->md5sum))
4613 + ipkg_message(conf, IPKG_ERROR,
4614 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4622 + if (pkg->tmp_unpack_dir == NULL) {
4623 + unpack_pkg_control_files(conf, pkg);
4626 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4627 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4628 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4629 + err = update_file_ownership(conf, pkg, old_pkg);
4630 + if (err) { return err; }
4632 + if (conf->nodeps == 0) {
4633 + err = satisfy_dependencies_for(conf, pkg);
4634 + if (err) { return err; }
4637 + replacees = pkg_vec_alloc();
4638 + pkg_get_installed_replacees(conf, pkg, replacees);
4640 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4642 + sigset_t newset, oldset;
4643 + sighandler_t old_handler = NULL;
4644 + int use_signal = 0;
4645 + caught_sigint = 0;
4647 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4649 + sigemptyset(&newset);
4650 + sigaddset(&newset, SIGINT);
4651 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4654 + ipkg_state_changed++;
4655 + pkg->state_flag |= SF_FILELIST_CHANGED;
4657 + /* XXX: BUG: we really should treat replacement more like an upgrade
4658 + * Instead, we're going to remove the replacees
4660 + err = pkg_remove_installed_replacees(conf, replacees);
4661 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4663 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4664 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4666 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4667 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4669 + err = preinst_configure(conf, pkg, old_pkg);
4670 + if (err) goto UNWIND_PREINST_CONFIGURE;
4672 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4673 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4675 + err = check_data_file_clashes(conf, pkg, old_pkg);
4676 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4678 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4679 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4681 + if (conf->noaction) return 0;
4683 + /* point of no return: no unwinding after this */
4684 + if (old_pkg && !conf->force_reinstall) {
4685 + old_pkg->state_want = SW_DEINSTALL;
4687 + if (old_pkg->state_flag & SF_NOPRUNE) {
4688 + ipkg_message(conf, IPKG_INFO,
4689 + " not removing obsolesced files because package marked noprune\n");
4691 + ipkg_message(conf, IPKG_INFO,
4692 + " removing obsolesced files\n");
4693 + remove_obsolesced_files(conf, pkg, old_pkg);
4695 + /* removing files from old package, to avoid ghost files */
4696 + remove_data_files_and_list(conf, old_pkg);
4697 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4698 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4699 + remove_postrm(conf, old_pkg);
4705 + ipkg_message(conf, IPKG_INFO,
4706 + " installing maintainer scripts\n");
4707 + install_maintainer_scripts(conf, pkg, old_pkg);
4709 + /* the following just returns 0 */
4710 + remove_disappeared(conf, pkg);
4712 + ipkg_message(conf, IPKG_INFO,
4713 + " installing data files\n");
4714 + install_data_files(conf, pkg);
4716 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4717 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4719 + ipkg_message(conf, IPKG_INFO,
4720 + " resolving conf files\n");
4721 + resolve_conffiles(conf, pkg);
4723 + pkg->state_status = SS_UNPACKED;
4724 + old_state_flag = pkg->state_flag;
4725 + pkg->state_flag &= ~SF_PREFER;
4726 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4728 + if (old_pkg && !conf->force_reinstall) {
4729 + old_pkg->state_status = SS_NOT_INSTALLED;
4732 + time(&pkg->installed_time);
4734 + ipkg_message(conf, IPKG_INFO,
4735 + " cleanup temp files\n");
4736 + cleanup_temporary_files(conf, pkg);
4738 + ab_pkg = pkg->parent;
4740 + ab_pkg->state_status = pkg->state_status;
4742 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4745 + signal(SIGINT, old_handler);
4747 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4752 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4753 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4754 + UNWIND_CHECK_DATA_FILE_CLASHES:
4755 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4756 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4757 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4758 + UNWIND_PREINST_CONFIGURE:
4759 + preinst_configure_unwind(conf, pkg, old_pkg);
4760 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4761 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4762 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4763 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4764 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4765 + pkg_remove_installed_replacees_unwind(conf, replacees);
4767 + ipkg_message(conf, IPKG_INFO,
4768 + " cleanup temp files\n");
4769 + cleanup_temporary_files(conf, pkg);
4771 + ipkg_message(conf, IPKG_INFO,
4774 + signal(SIGINT, old_handler);
4776 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4782 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4784 + /* DPKG_INCOMPATIBILITY:
4785 + dpkg does some things here that we don't do yet. Do we care?
4787 + 1. If a version of the package is already installed, call
4788 + old-prerm upgrade new-version
4789 + 2. If the script runs but exits with a non-zero exit status
4790 + new-prerm failed-upgrade old-version
4791 + Error unwind, for both the above cases:
4792 + old-postinst abort-upgrade new-version
4797 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4799 + /* DPKG_INCOMPATIBILITY:
4800 + dpkg does some things here that we don't do yet. Do we care?
4801 + (See prerm_upgrade_old_package for details)
4806 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4808 + /* DPKG_INCOMPATIBILITY:
4809 + dpkg does some things here that we don't do yet. Do we care?
4810 + 2. If a 'conflicting' package is being removed at the same time:
4811 + 1. If any packages depended on that conflicting package and
4812 + --auto-deconfigure is specified, call, for each such package:
4813 + deconfigured's-prerm deconfigure \
4814 + in-favour package-being-installed version \
4815 + removing conflicting-package version
4817 + deconfigured's-postinst abort-deconfigure \
4818 + in-favour package-being-installed-but-failed version \
4819 + removing conflicting-package version
4821 + The deconfigured packages are marked as requiring
4822 + configuration, so that if --install is used they will be
4823 + configured again if possible.
4824 + 2. To prepare for removal of the conflicting package, call:
4825 + conflictor's-prerm remove in-favour package new-version
4827 + conflictor's-postinst abort-remove in-favour package new-version
4832 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4834 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4835 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4840 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4843 + char *preinst_args;
4846 + char *old_version = pkg_version_str_alloc(old_pkg);
4847 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4848 + free(old_version);
4849 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4850 + char *pkg_version = pkg_version_str_alloc(pkg);
4851 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4852 + free(pkg_version);
4854 + preinst_args = strdup("install");
4857 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4859 + ipkg_message(conf, IPKG_ERROR,
4860 + "Aborting installation of %s\n", pkg->name);
4864 + free(preinst_args);
4869 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4871 + /* DPKG_INCOMPATIBILITY:
4872 + dpkg does the following error unwind, should we?
4873 + pkg->postrm abort-upgrade old-version
4874 + OR pkg->postrm abort-install old-version
4875 + OR pkg->postrm abort-install
4880 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4883 + conffile_list_elt_t *iter;
4886 + if (conf->noaction) return 0;
4888 + /* Backup all modified conffiles */
4890 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4894 + cf_name = root_filename_alloc(conf, cf->name);
4896 + /* Don't worry if the conffile is just plain gone */
4897 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4898 + err = backup_make_backup(conf, cf_name);
4907 + /* Backup all conffiles that were not conffiles in old_pkg */
4908 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4911 + cf_name = root_filename_alloc(conf, cf->name);
4912 + /* Ignore if this was a conffile in old_pkg as well */
4913 + if (pkg_get_conffile(old_pkg, cf->name)) {
4917 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4918 + err = backup_make_backup(conf, cf_name);
4929 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4931 + conffile_list_elt_t *iter;
4934 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4935 + backup_remove(iter->data->name);
4939 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4940 + backup_remove(iter->data->name);
4947 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4949 + /* DPKG_INCOMPATIBILITY:
4950 + ipkg takes a slightly different approach than dpkg at this
4951 + point. dpkg installs each file in the new package while
4952 + creating a backup for any file that is replaced, (so that it
4953 + can unwind if necessary). To avoid complexity and redundant
4954 + storage, ipkg doesn't do any installation until later, (at the
4955 + point at which dpkg removes the backups.
4957 + But, we do have to check for data file clashes, since after
4958 + installing a package with a file clash, removing either of the
4959 + packages involved in the clash has the potential to break the
4962 + str_list_t *files_list;
4963 + str_list_elt_t *iter;
4967 + files_list = pkg_get_installed_files(pkg);
4968 + for (iter = files_list->head; iter; iter = iter->next) {
4969 + char *root_filename;
4970 + char *filename = iter->data;
4971 + root_filename = root_filename_alloc(conf, filename);
4972 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4975 + /* Pre-existing conffiles are OK */
4976 + /* @@@@ should have way to check that it is a conffile -Jamey */
4977 + if (backup_exists_for(root_filename)) {
4981 + /* Pre-existing files are OK if force-overwrite was asserted. */
4982 + if (conf->force_overwrite) {
4983 + /* but we need to change who owns this file */
4984 + file_hash_set_file_owner(conf, filename, pkg);
4988 + owner = file_hash_get_file_owner(conf, filename);
4990 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4991 + if (owner && old_pkg) {
4992 + if (strcmp(owner->name, old_pkg->name) == 0) {
4997 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4999 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5000 + if (pkg_replaces(pkg, owner)) {
5003 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5004 + then it's ok to overwrite. */
5005 + if (strcmp(owner->name,pkg->name)==0){
5006 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5011 + /* Pre-existing files are OK if they are obsolete */
5012 + obs = hash_table_get(&conf->obs_file_hash, filename);
5014 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5018 + /* We have found a clash. */
5019 + ipkg_message(conf, IPKG_ERROR,
5020 + "Package %s wants to install file %s\n"
5021 + "\tBut that file is already provided by package ",
5022 + pkg->name, filename);
5024 + ipkg_message(conf, IPKG_ERROR,
5025 + "%s\n", owner->name);
5027 + ipkg_message(conf, IPKG_ERROR,
5028 + "<no package>\nPlease move this file out of the way and try again.\n");
5032 + free(root_filename);
5034 + pkg_free_installed_files(pkg);
5039 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5041 + /* Basically that's the worst hack I could do to be able to change ownership of
5042 + file list, but, being that we have no way to unwind the mods, due to structure
5043 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5044 + What we do here is change the ownership of file in hash if a replace ( or similar events
5046 + Only the action that are needed to change name should be considered.
5047 + @@@ To change after 1.0 release.
5049 + str_list_t *files_list;
5050 + str_list_elt_t *iter;
5054 + files_list = pkg_get_installed_files(pkg);
5055 + for (iter = files_list->head; iter; iter = iter->next) {
5056 + char *root_filename;
5057 + char *filename = iter->data;
5058 + root_filename = root_filename_alloc(conf, filename);
5059 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5062 + if (conf->force_overwrite) {
5063 + /* but we need to change who owns this file */
5064 + file_hash_set_file_owner(conf, filename, pkg);
5068 + owner = file_hash_get_file_owner(conf, filename);
5070 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5072 + if (pkg_replaces(pkg, owner)) {
5073 +/* It's now time to change the owner of that file.
5074 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5075 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5076 + file_hash_set_file_owner(conf, filename, pkg);
5082 + free(root_filename);
5084 + pkg_free_installed_files(pkg);
5089 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5091 + /* Nothing to do since check_data_file_clashes doesn't change state */
5095 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5097 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5098 + 1. If the package is being upgraded, call
5099 + old-postrm upgrade new-version
5100 + 2. If this fails, attempt:
5101 + new-postrm failed-upgrade old-version
5102 + Error unwind, for both cases:
5103 + old-preinst abort-upgrade new-version */
5107 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5109 + /* DPKG_INCOMPATIBILITY:
5110 + dpkg does some things here that we don't do yet. Do we care?
5111 + (See postrm_upgrade_old_pkg for details)
5116 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5119 + str_list_t *old_files;
5120 + str_list_elt_t *of;
5121 + str_list_t *new_files;
5122 + str_list_elt_t *nf;
5124 + if (old_pkg == NULL) {
5128 + old_files = pkg_get_installed_files(old_pkg);
5129 + new_files = pkg_get_installed_files(pkg);
5131 + for (of = old_files->head; of; of = of->next) {
5135 + for (nf = new_files->head; nf; nf = nf->next) {
5137 + if (strcmp(old, new) == 0) {
5138 + goto NOT_OBSOLETE;
5141 + if (file_is_dir(old)) {
5144 + owner = file_hash_get_file_owner(conf, old);
5145 + if (owner != old_pkg) {
5146 + /* in case obsolete file no longer belongs to old_pkg */
5150 + /* old file is obsolete */
5151 + ipkg_message(conf, IPKG_INFO,
5152 + " removing obsolete file %s\n", old);
5153 + if (!conf->noaction) {
5154 + err = unlink(old);
5156 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5165 + pkg_free_installed_files(old_pkg);
5166 + pkg_free_installed_files(pkg);
5171 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5175 + char *globpattern;
5179 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5182 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5183 + err = glob(globpattern, 0, NULL, &globbuf);
5184 + free(globpattern);
5188 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5189 + for (i = 0; i < globbuf.gl_pathc; i++) {
5190 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5191 + globbuf.gl_pathv[i], old_pkg->name);
5192 + if (!conf->noaction)
5193 + unlink(globbuf.gl_pathv[i]);
5195 + globfree(&globbuf);
5200 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5206 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5207 + sprintf_alloc(&prefix, "%s.", pkg->name);
5208 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5209 + pkg->dest->info_dir,
5215 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5217 + /* DPKG_INCOMPATIBILITY:
5218 + This is a fairly sophisticated dpkg operation. Shall we
5221 + /* Any packages all of whose files have been overwritten during the
5222 + installation, and which aren't required for dependencies, are
5223 + considered to have been removed. For each such package
5224 + 1. disappearer's-postrm disappear overwriter overwriter-version
5225 + 2. The package's maintainer scripts are removed
5226 + 3. It is noted in the status database as being in a sane state,
5227 + namely not installed (any conffiles it may have are ignored,
5228 + rather than being removed by dpkg). Note that disappearing
5229 + packages do not have their prerm called, because dpkg doesn't
5230 + know in advance that the package is going to vanish.
5235 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5239 + /* ipkg takes a slightly different approach to data file backups
5240 + than dpkg. Rather than removing backups at this point, we
5241 + actually do the data file installation now. See comments in
5242 + check_data_file_clashes() for more details. */
5244 + ipkg_message(conf, IPKG_INFO,
5245 + " extracting data files to %s\n", pkg->dest->root_dir);
5246 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5251 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5252 + so we can't save ourself from removing important packages
5253 + At this point we (should) have extracted the .control file, so it
5254 + would be a good idea to reload the data in it, and set the Essential
5255 + state in *pkg. From now on the Essential is back in status file and
5256 + we can protect again.
5257 + We should operate this way:
5258 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5259 + check for "Essential" in it
5260 + set the value in pkg->essential.
5261 + This new routine could be useful also for every other flag
5262 + Pigi: 16/03/2004 */
5263 + set_flags_from_control(conf, pkg) ;
5265 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5266 + err = pkg_write_filelist(conf, pkg);
5270 + /* XXX: FEATURE: ipkg should identify any files which existed
5271 + before installation and which were overwritten, (see
5272 + check_data_file_clashes()). What it must do is remove any such
5273 + files from the filelist of the old package which provided the
5274 + file. Otherwise, if the old package were removed at some point
5275 + it would break the new package. Removing the new package will
5276 + also break the old one, but this cannot be helped since the old
5277 + package's file has already been deleted. This is the importance
5278 + of check_data_file_clashes(), and only allowing ipkg to install
5279 + a clashing package with a user force. */
5284 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5286 + conffile_list_elt_t *iter;
5293 + if (conf->noaction) return 0;
5295 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5296 + char *root_filename;
5298 + root_filename = root_filename_alloc(conf, cf->name);
5300 + /* Might need to initialize the md5sum for each conffile */
5301 + if (cf->value == NULL) {
5302 + cf->value = file_md5sum_alloc(root_filename);
5305 + if (!file_exists(root_filename)) {
5306 + free(root_filename);
5310 + cf_backup = backup_filename_alloc(root_filename);
5313 + if (file_exists(cf_backup)) {
5314 + /* Let's compute md5 to test if files are changed */
5315 + md5sum = file_md5sum_alloc(cf_backup);
5316 + if (strcmp( cf->value,md5sum) != 0 ) {
5317 + if (conf->force_defaults
5318 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5319 + rename(cf_backup, root_filename);
5322 + unlink(cf_backup);
5327 + free(root_filename);
5333 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5336 + const char *short_file_name;
5338 + short_file_name = strrchr(file_name, '/');
5339 + if (short_file_name) {
5340 + short_file_name++;
5342 + short_file_name = file_name;
5346 + response = get_user_response(" Configuration file '%s'\n"
5347 + " ==> File on system created by you or by a script.\n"
5348 + " ==> File also in package provided by package maintainer.\n"
5349 + " What would you like to do about it ? Your options are:\n"
5350 + " Y or I : install the package maintainer's version\n"
5351 + " N or O : keep your currently-installed version\n"
5352 + " D : show the differences between the versions (if diff is installed)\n"
5353 + " The default action is to keep your current version.\n"
5354 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5355 + if (strcmp(response, "y") == 0
5356 + || strcmp(response, "i") == 0
5357 + || strcmp(response, "yes") == 0) {
5362 + if (strcmp(response, "d") == 0) {
5366 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5367 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5370 + printf(" [Press ENTER to continue]\n");
5371 + response = file_read_line_alloc(stdin);
5381 +/* XXX: CLEANUP: I'd like to move all of the code for
5382 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5383 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5384 + pkg_deinit for example). */
5385 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5388 + struct dirent *dirent;
5391 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5393 + ipkg_message(conf, IPKG_DEBUG,
5394 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5395 + __FUNCTION__, pkg->tmp_unpack_dir);
5399 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5400 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5403 + dirent = readdir(tmp_dir);
5404 + if (dirent == NULL) {
5407 + sprintf_alloc(&tmp_file, "%s/%s",
5408 + pkg->tmp_unpack_dir, dirent->d_name);
5409 + if (! file_is_dir(tmp_file)) {
5414 + closedir(tmp_dir);
5415 + rmdir(pkg->tmp_unpack_dir);
5416 + free(pkg->tmp_unpack_dir);
5417 + pkg->tmp_unpack_dir = NULL;
5421 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5422 + pkg->name, pkg->local_filename, conf->tmp_dir);
5423 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5424 + unlink(pkg->local_filename);
5425 + free(pkg->local_filename);
5426 + pkg->local_filename = NULL;
5432 +static char *backup_filename_alloc(const char *file_name)
5436 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5441 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5446 + backup = backup_filename_alloc(file_name);
5447 + err = file_copy(file_name, backup);
5449 + ipkg_message(conf, IPKG_ERROR,
5450 + "%s: Failed to copy %s to %s\n",
5451 + __FUNCTION__, file_name, backup);
5459 +static int backup_exists_for(const char *file_name)
5464 + backup = backup_filename_alloc(file_name);
5466 + ret = file_exists(backup);
5473 +static int backup_remove(const char *file_name)
5477 + backup = backup_filename_alloc(file_name);
5486 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5488 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5490 + /* first, remove the packages that need removing */
5491 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5492 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5493 + err = ipkg_remove_pkg(conf, pkg,0);
5494 + if (err) return err;
5499 +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)
5502 + /* now one more pass checking on the ones that need to be installed */
5503 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5504 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5505 + if (pkg->dest == NULL)
5506 + pkg->dest = conf->default_dest;
5508 + pkg->state_want = SW_INSTALL;
5510 + /* Abhaya: conflicts check */
5511 + err = check_conflicts_for(conf, pkg);
5512 + if (err) { return err; }
5517 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5520 + /* now one more pass checking on the ones that need to be installed */
5521 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5522 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5524 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5525 + pkg_vec_t *replacees = pkg_vec_alloc();
5526 + pkg_get_installed_replacees(conf, pkg, replacees);
5528 + /* XXX: BUG: we really should treat replacement more like an upgrade
5529 + * Instead, we're going to remove the replacees
5531 + err = pkg_remove_installed_replacees(conf, replacees);
5532 + if (err) return err;
5533 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5538 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5541 + /* now one more pass checking on the ones that need to be installed */
5542 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5543 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5544 + if (pkg->local_filename == NULL) {
5545 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5547 + ipkg_message(conf, IPKG_ERROR,
5548 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5553 + if (pkg->tmp_unpack_dir == NULL) {
5554 + err = unpack_pkg_control_files(conf, pkg);
5555 + if (err) return err;
5561 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5564 + /* now one more pass checking on the ones that need to be installed */
5565 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5566 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5567 + pkg_t *old_pkg = pkg->old_pkg;
5569 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5570 + if (err) return err;
5572 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5573 + if (err) return err;
5575 + err = preinst_configure(conf, pkg, old_pkg);
5576 + if (err) return err;
5578 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5579 + if (err) return err;
5581 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5582 + if (err) return err;
5587 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5590 + /* now one more pass checking on the ones that need to be installed */
5591 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5592 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5593 + pkg_t *old_pkg = pkg->old_pkg;
5596 + old_pkg->state_want = SW_DEINSTALL;
5598 + if (old_pkg->state_flag & SF_NOPRUNE) {
5599 + ipkg_message(conf, IPKG_INFO,
5600 + " not removing obsolesced files because package marked noprune\n");
5602 + ipkg_message(conf, IPKG_INFO,
5603 + " removing obsolesced files\n");
5604 + remove_obsolesced_files(conf, pkg, old_pkg);
5608 + ipkg_message(conf, IPKG_INFO,
5609 + " installing maintainer scripts\n");
5610 + install_maintainer_scripts(conf, pkg, old_pkg);
5612 + /* the following just returns 0 */
5613 + remove_disappeared(conf, pkg);
5615 + ipkg_message(conf, IPKG_INFO,
5616 + " installing data files\n");
5617 + install_data_files(conf, pkg);
5619 + ipkg_message(conf, IPKG_INFO,
5620 + " resolving conf files\n");
5621 + resolve_conffiles(conf, pkg);
5623 + pkg->state_status = SS_UNPACKED;
5626 + old_pkg->state_status = SS_NOT_INSTALLED;
5629 + time(&pkg->installed_time);
5631 + ipkg_message(conf, IPKG_INFO,
5632 + " cleanup temp files\n");
5633 + cleanup_temporary_files(conf, pkg);
5636 + pkg->parent->state_status = pkg->state_status;
5641 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5644 + /* now one more pass checking on the ones that need to be installed */
5645 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5646 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5647 + pkg_t *old_pkg = pkg->old_pkg;
5650 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5651 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5652 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5653 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5654 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5655 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5656 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5657 + preinst_configure_unwind(conf, pkg, old_pkg);
5658 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5659 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5660 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5661 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5663 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5664 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5672 + * Perform all the actions.
5674 + * pkgs_to_remove are packages marked for removal.
5675 + * pkgs_superseded are the old packages being replaced by upgrades.
5677 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5679 +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)
5684 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5685 + if (err) return err;
5687 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5688 + if (err) return err;
5690 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5691 + if (err) goto UNWIND;
5693 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5694 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5695 + if (err) goto UNWIND;
5698 + * Now that we have the packages unpacked, we can look for data
5699 + * file clashes. First, we mark the files from the superseded
5700 + * packages as obsolete. Then we scan the files in
5701 + * pkgs_to_install, and only complain about clashes with
5702 + * non-obsolete files.
5705 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5706 + if (err) goto UNWIND;
5708 + /* this was before checking data file clashes */
5709 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5710 + if (err) goto UNWIND;
5712 + /* point of no return: no unwinding after this */
5713 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5714 + if (err) return err;
5716 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5720 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5722 + ipkg_message(conf, IPKG_INFO,
5723 + " cleanup temp files\n");
5724 + cleanup_temporary_files(conf, pkg);
5726 + ipkg_message(conf, IPKG_INFO,
5732 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_install.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h
5733 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5734 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-07-22 16:31:25.000000000 +0200
5736 +/* ipkg_install.h - the itsy package management system
5740 + Copyright (C) 2001 University of Southern California
5742 + This program is free software; you can redistribute it and/or
5743 + modify it under the terms of the GNU General Public License as
5744 + published by the Free Software Foundation; either version 2, or (at
5745 + your option) any later version.
5747 + This program is distributed in the hope that it will be useful, but
5748 + WITHOUT ANY WARRANTY; without even the implied warranty of
5749 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5750 + General Public License for more details.
5753 +#ifndef IPKG_INSTALL_H
5754 +#define IPKG_INSTALL_H
5757 +#include "ipkg_conf.h"
5759 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5760 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5761 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5762 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5763 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5765 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5767 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5768 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5771 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_message.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c
5772 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5773 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-07-22 16:31:25.000000000 +0200
5775 +/* ipkg_message.c - the itsy package management system
5777 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5779 + This program is free software; you can redistribute it and/or
5780 + modify it under the terms of the GNU General Public License as
5781 + published by the Free Software Foundation; either version 2, or (at
5782 + your option) any later version.
5784 + This program is distributed in the hope that it will be useful, but
5785 + WITHOUT ANY WARRANTY; without even the implied warranty of
5786 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5787 + General Public License for more details.
5792 +#include "ipkg_conf.h"
5793 +#include "ipkg_message.h"
5798 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5802 + if (conf && (conf->verbosity < level))
5809 + va_start (ap, fmt);
5810 + vprintf (fmt, ap);
5817 +#include "libipkg.h"
5819 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5822 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5827 + if (ipkg_cb_message)
5829 + va_start (ap, fmt);
5830 + vsnprintf (ts,256,fmt, ap);
5832 + ipkg_cb_message(conf,level,ts);
5836 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_message.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h
5837 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5838 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-07-22 16:31:25.000000000 +0200
5840 +/* ipkg_message.h - the itsy package management system
5842 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5844 + This program is free software; you can redistribute it and/or
5845 + modify it under the terms of the GNU General Public License as
5846 + published by the Free Software Foundation; either version 2, or (at
5847 + your option) any later version.
5849 + This program is distributed in the hope that it will be useful, but
5850 + WITHOUT ANY WARRANTY; without even the implied warranty of
5851 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5852 + General Public License for more details.
5855 +#ifndef _IPKG_MESSAGE_H_
5856 +#define _IPKG_MESSAGE_H_
5859 +#include "ipkg_conf.h"
5862 + IPKG_ERROR, /* error conditions */
5863 + IPKG_NOTICE, /* normal but significant condition */
5864 + IPKG_INFO, /* informational message */
5865 + IPKG_DEBUG, /* debug level message */
5866 + IPKG_DEBUG2, /* more debug level message */
5869 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5871 +#endif /* _IPKG_MESSAGE_H_ */
5872 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c
5873 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5874 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-07-22 16:31:25.000000000 +0200
5876 +/* ipkg_remove.c - the itsy package management system
5880 + Copyright (C) 2001 University of Southern California
5882 + This program is free software; you can redistribute it and/or
5883 + modify it under the terms of the GNU General Public License as
5884 + published by the Free Software Foundation; either version 2, or (at
5885 + your option) any later version.
5887 + This program is distributed in the hope that it will be useful, but
5888 + WITHOUT ANY WARRANTY; without even the implied warranty of
5889 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5890 + General Public License for more details.
5894 +#include "ipkg_message.h"
5898 +#include "ipkg_remove.h"
5900 +#include "file_util.h"
5901 +#include "sprintf_alloc.h"
5902 +#include "str_util.h"
5904 +#include "ipkg_cmd.h"
5907 + * Returns number of the number of packages depending on the packages provided by this package.
5908 + * Every package implicitly provides itself.
5910 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5912 + int nprovides = pkg->provides_count;
5913 + abstract_pkg_t **provides = pkg->provides;
5914 + int n_installed_dependents = 0;
5916 + for (i = 0; i <= nprovides; i++) {
5917 + abstract_pkg_t *providee = provides[i];
5918 + abstract_pkg_t **dependers = providee->depended_upon_by;
5919 + abstract_pkg_t *dep_ab_pkg;
5920 + if (dependers == NULL)
5922 + while ((dep_ab_pkg = *dependers++) != NULL) {
5923 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5924 + n_installed_dependents++;
5929 + /* if caller requested the set of installed dependents */
5930 + if (pdependents) {
5932 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5934 + if ( dependents == NULL ){
5935 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5939 + *pdependents = dependents;
5940 + for (i = 0; i <= nprovides; i++) {
5941 + abstract_pkg_t *providee = provides[i];
5942 + abstract_pkg_t **dependers = providee->depended_upon_by;
5943 + abstract_pkg_t *dep_ab_pkg;
5944 + if (dependers == NULL)
5946 + while ((dep_ab_pkg = *dependers++) != NULL) {
5947 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5948 + dependents[p++] = dep_ab_pkg;
5949 + dep_ab_pkg->state_flag |= SF_MARKED;
5953 + dependents[p] = NULL;
5954 + /* now clear the marks */
5955 + for (i = 0; i < p; i++) {
5956 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5957 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5960 + return n_installed_dependents;
5963 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5968 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5969 + abstract_pkg_t * ab_pkg;
5971 + if((ab_pkg = pkg->parent) == NULL){
5972 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5973 + __FUNCTION__, pkg->name);
5977 + if (dependents == NULL)
5980 + // here i am using the dependencies_checked
5981 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5982 + return 0; // has already been encountered in the process
5983 + // of marking packages for removal - Karthik
5984 + ab_pkg->dependencies_checked = 2;
5988 + while (dependents [i] != NULL) {
5989 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5991 + if (dep_ab_pkg->dependencies_checked == 2){
5995 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5996 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5997 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5998 + if (dep_pkg->state_status == SS_INSTALLED) {
5999 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6005 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6006 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6013 + for (i = 0; i < dependent_pkgs->len; i++) {
6014 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6021 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6023 + abstract_pkg_t *dep_ab_pkg;
6024 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6025 + while ((dep_ab_pkg = *dependents++) != NULL) {
6026 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6027 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6029 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6030 + ipkg_message(conf, IPKG_ERROR, "");
6031 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6032 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6033 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6034 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6035 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6039 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6041 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6042 + thus I wan't check for essential, as I'm upgrading.
6043 + I hope it won't break anything :)
6046 + abstract_pkg_t *parent_pkg = NULL;
6048 + if (pkg->essential && !message) {
6049 + if (conf->force_removal_of_essential_packages) {
6050 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6051 + "\tIf your system breaks, you get to keep both pieces\n",
6054 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6055 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6056 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6057 + "\tits will with the option: -force-removal-of-essential-packages\n",
6059 + return IPKG_PKG_IS_ESSENTIAL;
6063 + if ((parent_pkg = pkg->parent) == NULL)
6066 + /* only attempt to remove dependent installed packages if
6067 + * force_depends is not specified or the package is being
6070 + if (!conf->force_depends
6071 + && !(pkg->state_flag & SF_REPLACE)) {
6072 + abstract_pkg_t **dependents;
6073 + int has_installed_dependents =
6074 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6076 + if (has_installed_dependents) {
6078 + * if this package is depended up by others, then either we should
6079 + * not remove it or we should remove it and all of its dependents
6082 + if (!conf->force_removal_of_dependent_packages
6083 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6084 + return IPKG_PKG_HAS_DEPENDENTS;
6087 + /* remove packages depending on this package - Karthik */
6088 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6090 + if (err) return err;
6094 + if ( message==0 ){
6095 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6098 + pkg->state_flag |= SF_FILELIST_CHANGED;
6100 + pkg->state_want = SW_DEINSTALL;
6101 + ipkg_state_changed++;
6103 + pkg_run_script(conf, pkg, "prerm", "remove");
6105 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6106 + maintains an empty filelist rather than deleting it. That seems
6107 + like a big pain, and I don't see that that should make a big
6108 + difference, but for anyone who wants tighter compatibility,
6109 + feel free to fix this. */
6110 + remove_data_files_and_list(conf, pkg);
6112 + pkg_run_script(conf, pkg, "postrm", "remove");
6114 + remove_maintainer_scripts_except_postrm(conf, pkg);
6116 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6117 + * space, it doesn't make sense to leave extra configurations, files,
6118 + * and maintainer scripts left around. So, we make remove like purge,
6119 + * and take out all the crap :) */
6121 + remove_postrm(conf, pkg);
6122 + pkg->state_status = SS_NOT_INSTALLED;
6125 + parent_pkg->state_status = SS_NOT_INSTALLED;
6130 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6132 + ipkg_remove_pkg(conf, pkg,0);
6136 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6138 + str_list_t installed_dirs;
6139 + str_list_t *installed_files;
6140 + str_list_elt_t *iter;
6142 + conffile_t *conffile;
6143 + int removed_a_dir;
6146 + str_list_init(&installed_dirs);
6147 + installed_files = pkg_get_installed_files(pkg);
6149 + for (iter = installed_files->head; iter; iter = iter->next) {
6150 + file_name = iter->data;
6152 + if (file_is_dir(file_name)) {
6153 + str_list_append(&installed_dirs, strdup(file_name));
6157 + conffile = pkg_get_conffile(pkg, file_name);
6159 + /* XXX: QUESTION: Is this right? I figure we only need to
6160 + save the conffile if it has been modified. Is that what
6161 + dpkg does? Or does dpkg preserve all conffiles? If so,
6162 + this seems like a better thing to do to conserve
6164 + if (conffile_has_been_modified(conf, conffile)) {
6165 + printf(" not deleting modified conffile %s\n", file_name);
6171 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6172 + if (!conf->noaction)
6173 + unlink(file_name);
6176 + if (!conf->noaction) {
6178 + removed_a_dir = 0;
6179 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6180 + file_name = iter->data;
6182 + if (rmdir(file_name) == 0) {
6183 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6184 + removed_a_dir = 1;
6185 + str_list_remove(&installed_dirs, &iter);
6188 + } while (removed_a_dir);
6191 + pkg_free_installed_files(pkg);
6192 + /* We have to remove the file list now, so that
6193 + find_pkg_owning_file does not always just report this package */
6194 + pkg_remove_installed_files_list(conf, pkg);
6196 + /* Don't print warning for dirs that are provided by other packages */
6197 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6198 + file_name = iter->data;
6200 + owner = file_hash_get_file_owner(conf, file_name);
6203 + iter->data = NULL;
6204 + str_list_remove(&installed_dirs, &iter);
6209 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6211 + iter->data = NULL;
6213 + str_list_deinit(&installed_dirs);
6218 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6221 + char *globpattern;
6224 + if (conf->noaction) return 0;
6226 + sprintf_alloc(&globpattern, "%s/%s.*",
6227 + pkg->dest->info_dir, pkg->name);
6228 + err = glob(globpattern, 0, NULL, &globbuf);
6229 + free(globpattern);
6234 + for (i = 0; i < globbuf.gl_pathc; i++) {
6235 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6238 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6239 + unlink(globbuf.gl_pathv[i]);
6241 + globfree(&globbuf);
6246 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6248 + char *postrm_file_name;
6250 + if (conf->noaction) return 0;
6252 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6253 + pkg->dest->info_dir, pkg->name);
6254 + unlink(postrm_file_name);
6255 + free(postrm_file_name);
6259 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h
6260 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6261 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-07-22 16:31:25.000000000 +0200
6263 +/* ipkg_remove.h - the itsy package management system
6267 + Copyright (C) 2001 University of Southern California
6269 + This program is free software; you can redistribute it and/or
6270 + modify it under the terms of the GNU General Public License as
6271 + published by the Free Software Foundation; either version 2, or (at
6272 + your option) any later version.
6274 + This program is distributed in the hope that it will be useful, but
6275 + WITHOUT ANY WARRANTY; without even the implied warranty of
6276 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6277 + General Public License for more details.
6280 +#ifndef IPKG_REMOVE_H
6281 +#define IPKG_REMOVE_H
6284 +#include "ipkg_conf.h"
6286 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6287 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6288 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6289 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6290 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6291 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6292 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6296 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c
6297 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6298 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-07-22 16:31:25.000000000 +0200
6300 +/* ipkg_upgrade.c - the itsy package management system
6303 + Copyright (C) 2001 University of Southern California
6305 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6307 + This program is free software; you can redistribute it and/or
6308 + modify it under the terms of the GNU General Public License as
6309 + published by the Free Software Foundation; either version 2, or (at
6310 + your option) any later version.
6312 + This program is distributed in the hope that it will be useful, but
6313 + WITHOUT ANY WARRANTY; without even the implied warranty of
6314 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6315 + General Public License for more details.
6319 +#include "ipkg_install.h"
6320 +#include "ipkg_message.h"
6322 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6326 + char *old_version, *new_version;
6328 + if (old->state_flag & SF_HOLD) {
6329 + ipkg_message(conf, IPKG_NOTICE,
6330 + "Not upgrading package %s which is marked "
6331 + "hold (flags=%#x)\n", old->name, old->state_flag);
6335 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6336 + if (new == NULL) {
6337 + old_version = pkg_version_str_alloc(old);
6338 + ipkg_message(conf, IPKG_NOTICE,
6339 + "Assuming locally installed package %s (%s) "
6340 + "is up to date.\n", old->name, old_version);
6341 + free(old_version);
6345 + old_version = pkg_version_str_alloc(old);
6346 + new_version = pkg_version_str_alloc(new);
6348 + cmp = pkg_compare_versions(old, new);
6349 + ipkg_message(conf, IPKG_DEBUG,
6350 + "comparing visible versions of pkg %s:"
6351 + "\n\t%s is installed "
6352 + "\n\t%s is available "
6353 + "\n\t%d was comparison result\n",
6354 + old->name, old_version, new_version, cmp);
6356 + ipkg_message(conf, IPKG_INFO,
6357 + "Package %s (%s) installed in %s is up to date.\n",
6358 + old->name, old_version, old->dest->name);
6359 + free(old_version);
6360 + free(new_version);
6362 + } else if (cmp > 0) {
6363 + ipkg_message(conf, IPKG_NOTICE,
6364 + "Not downgrading package %s on %s from %s to %s.\n",
6365 + old->name, old->dest->name, old_version, new_version);
6366 + free(old_version);
6367 + free(new_version);
6369 + } else if (cmp < 0) {
6370 + new->dest = old->dest;
6371 + old->state_want = SW_DEINSTALL;
6374 + new->state_flag |= SF_USER;
6375 + return ipkg_install_pkg(conf, new,1);
6377 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h
6378 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6379 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-07-22 16:31:25.000000000 +0200
6381 +/* ipkg_upgrade.c - the itsy package management system
6383 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6385 + This program is free software; you can redistribute it and/or
6386 + modify it under the terms of the GNU General Public License as
6387 + published by the Free Software Foundation; either version 2, or (at
6388 + your option) any later version.
6390 + This program is distributed in the hope that it will be useful, but
6391 + WITHOUT ANY WARRANTY; without even the implied warranty of
6392 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6393 + General Public License for more details.
6398 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6399 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c
6400 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6401 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-07-22 16:31:25.000000000 +0200
6403 +/* ipkg_utils.c - the itsy package management system
6407 + Copyright (C) 2002 Compaq Computer Corporation
6409 + This program is free software; you can redistribute it and/or
6410 + modify it under the terms of the GNU General Public License as
6411 + published by the Free Software Foundation; either version 2, or (at
6412 + your option) any later version.
6414 + This program is distributed in the hope that it will be useful, but
6415 + WITHOUT ANY WARRANTY; without even the implied warranty of
6416 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6417 + General Public License for more details.
6423 +#include <sys/vfs.h>
6425 +#include "ipkg_utils.h"
6427 +#include "pkg_hash.h"
6429 +struct errlist* error_list;
6431 +int get_available_blocks(char * filesystem)
6433 + struct statfs sfs;
6435 + if(statfs(filesystem, &sfs)){
6436 + fprintf(stderr, "bad statfs\n");
6439 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6440 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6443 +char **read_raw_pkgs_from_file(const char *file_name)
6448 + if(!(fp = fopen(file_name, "r"))){
6449 + fprintf(stderr, "can't get %s open for read\n", file_name);
6453 + ret = read_raw_pkgs_from_stream(fp);
6460 +char **read_raw_pkgs_from_stream(FILE *fp)
6462 + char **raw = NULL, *buf, *scout;
6464 + size_t size = 512;
6466 + buf = malloc (size);
6468 + while (fgets(buf, size, fp)) {
6469 + while (strlen (buf) == (size - 1)
6470 + && buf[size-2] != '\n') {
6471 + size_t o = size - 1;
6473 + buf = realloc (buf, size);
6474 + if (fgets (buf + o, size - o, fp) == NULL)
6479 + raw = realloc(raw, (count + 50) * sizeof(char *));
6481 + if((scout = strchr(buf, '\n')))
6484 + raw[count++] = strdup(buf);
6487 + raw = realloc(raw, (count + 1) * sizeof(char *));
6488 + raw[count] = NULL;
6495 +/* something to remove whitespace, a hash pooper */
6496 +char *trim_alloc(char *line)
6499 + char *dest, *src, *end;
6501 + new = malloc(strlen(line) + 1);
6502 + if ( new == NULL ){
6503 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6506 + dest = new, src = line, end = line + (strlen(line) - 1);
6508 + /* remove it from the front */
6513 + /* and now from the back */
6514 + while((end > src) &&
6520 + /* this does from the first space
6521 + * blasting away any versions stuff in depends
6532 +int line_is_blank(const char *line)
6536 + for (s = line; *s; s++) {
6543 +void push_error_list(struct errlist ** errors, char * msg){
6544 + struct errlist *err_lst_tmp;
6547 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6548 + err_lst_tmp->errmsg=strdup(msg) ;
6549 + err_lst_tmp->next = *errors;
6550 + *errors = err_lst_tmp;
6554 +void reverse_error_list(struct errlist **errors){
6555 + struct errlist *result=NULL;
6556 + struct errlist *current= *errors;
6557 + struct errlist *next;
6559 + while ( current != NULL ) {
6560 + next = current->next;
6561 + current->next=result;
6570 +void free_error_list(struct errlist **errors){
6571 + struct errlist *current = *errors;
6573 + while (current != NULL) {
6574 + free(current->errmsg);
6575 + current = (*errors)->next;
6577 + *errors = current;
6584 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h
6585 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6586 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-07-22 16:31:25.000000000 +0200
6588 +/* ipkg_utils.h - the itsy package management system
6592 + Copyright (C) 2002 Compaq Computer Corporation
6594 + This program is free software; you can redistribute it and/or
6595 + modify it under the terms of the GNU General Public License as
6596 + published by the Free Software Foundation; either version 2, or (at
6597 + your option) any later version.
6599 + This program is distributed in the hope that it will be useful, but
6600 + WITHOUT ANY WARRANTY; without even the implied warranty of
6601 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6602 + General Public License for more details.
6605 +#ifndef IPKG_UTILS_H
6606 +#define IPKG_UTILS_H
6610 +int get_available_blocks(char * filesystem);
6611 +char **read_raw_pkgs_from_file(const char *file_name);
6612 +char **read_raw_pkgs_from_stream(FILE *fp);
6613 +char *trim_alloc(char * line);
6614 +int line_is_blank(const char *line);
6617 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c
6618 --- busybox-1.2.0-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6619 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-07-22 16:31:25.000000000 +0200
6621 +/* ipkglib.c - the itsy package management system
6625 + Copyright (C) 2003 kernel concepts
6627 + This program is free software; you can redistribute it and/or
6628 + modify it under the terms of the GNU General Public License as
6629 + published by the Free Software Foundation; either version 2, or (at
6630 + your option) any later version.
6632 + This program is distributed in the hope that it will be useful, but
6633 + WITHOUT ANY WARRANTY; without even the implied warranty of
6634 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6635 + General Public License for more details.
6641 +#include "ipkg_includes.h"
6642 +#include "libipkg.h"
6645 +#include "ipkg_conf.h"
6646 +#include "ipkg_cmd.h"
6647 +#include "file_util.h"
6651 +ipkg_message_callback ipkg_cb_message = NULL;
6652 +ipkg_response_callback ipkg_cb_response = NULL;
6653 +ipkg_status_callback ipkg_cb_status = NULL;
6654 +ipkg_list_callback ipkg_cb_list = NULL;
6658 +ipkg_init (ipkg_message_callback mcall,
6659 + ipkg_response_callback rcall,
6662 + ipkg_cb_message = mcall;
6663 + ipkg_cb_response = rcall;
6672 +ipkg_deinit (args_t * args)
6674 + args_deinit (args);
6675 + ipkg_cb_message = NULL;
6676 + ipkg_cb_response = NULL;
6678 + /* place other cleanup stuff here */
6685 +ipkg_packages_list(args_t *args,
6686 + const char *packages,
6687 + ipkg_list_callback cblist,
6691 + ipkg_conf_t ipkg_conf;
6694 + err = ipkg_conf_init (&ipkg_conf, args);
6700 + ipkg_cb_list = cblist;
6701 + /* we need to do this because of static declarations,
6702 + * maybe a good idea to change */
6703 + cmd = ipkg_cmd_find ("list");
6705 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6707 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6708 + ipkg_cb_list = NULL;
6709 + ipkg_conf_deinit (&ipkg_conf);
6715 +ipkg_packages_status(args_t *args,
6716 + const char *packages,
6717 + ipkg_status_callback cbstatus,
6721 + ipkg_conf_t ipkg_conf;
6724 + err = ipkg_conf_init (&ipkg_conf, args);
6730 + ipkg_cb_status = cbstatus;
6732 + /* we need to do this because of static declarations,
6733 + * maybe a good idea to change */
6734 + cmd = ipkg_cmd_find ("status");
6736 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6738 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6740 + ipkg_cb_status = NULL;
6741 + ipkg_conf_deinit (&ipkg_conf);
6747 +ipkg_packages_info(args_t *args,
6748 + const char *packages,
6749 + ipkg_status_callback cbstatus,
6753 + ipkg_conf_t ipkg_conf;
6756 + err = ipkg_conf_init (&ipkg_conf, args);
6762 + ipkg_cb_status = cbstatus;
6764 + /* we need to do this because of static declarations,
6765 + * maybe a good idea to change */
6766 + cmd = ipkg_cmd_find ("info");
6768 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6770 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6772 + ipkg_cb_status = NULL;
6773 + ipkg_conf_deinit (&ipkg_conf);
6779 +ipkg_packages_install (args_t * args, const char *name)
6782 + ipkg_conf_t ipkg_conf;
6785 + /* this error should be handled in application */
6786 + if (!name || !strlen (name))
6789 + err = ipkg_conf_init (&ipkg_conf, args);
6795 + /* we need to do this because of static declarations,
6796 + * maybe a good idea to change */
6797 + cmd = ipkg_cmd_find ("install");
6798 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6800 + ipkg_conf_deinit(&ipkg_conf);
6806 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6809 + ipkg_conf_t ipkg_conf;
6812 + /* this error should be handled in application */
6813 + if (!name || !strlen (name))
6816 + err = ipkg_conf_init (&ipkg_conf, args);
6822 + /* we need to do this because of static declarations,
6823 + * maybe a good idea to change */
6825 + cmd = ipkg_cmd_find ("purge");
6827 + cmd = ipkg_cmd_find ("remove");
6829 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6831 + ipkg_conf_deinit(&ipkg_conf);
6837 +ipkg_lists_update(args_t *args)
6840 + ipkg_conf_t ipkg_conf;
6843 + err = ipkg_conf_init (&ipkg_conf, args);
6849 + /* we need to do this because of static declarations,
6850 + * maybe a good idea to change */
6851 + cmd = ipkg_cmd_find ("update");
6853 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6855 + ipkg_conf_deinit(&ipkg_conf);
6861 +ipkg_packages_upgrade(args_t *args)
6864 + ipkg_conf_t ipkg_conf;
6867 + err = ipkg_conf_init (&ipkg_conf, args);
6873 + /* we need to do this because of static declarations,
6874 + * maybe a good idea to change */
6875 + cmd = ipkg_cmd_find ("upgrade");
6877 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6879 + ipkg_conf_deinit(&ipkg_conf);
6885 +ipkg_packages_download (args_t * args, const char *name)
6888 + ipkg_conf_t ipkg_conf;
6891 + /* this error should be handled in application */
6892 + if (!name || !strlen (name))
6895 + err = ipkg_conf_init (&ipkg_conf, args);
6901 + /* we need to do this because of static declarations,
6902 + * maybe a good idea to change */
6903 + cmd = ipkg_cmd_find ("download");
6904 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6906 + ipkg_conf_deinit(&ipkg_conf);
6912 +ipkg_package_files(args_t *args,
6914 + ipkg_list_callback cblist,
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 + ipkg_cb_list = cblist;
6933 + /* we need to do this because of static declarations,
6934 + * maybe a good idea to change */
6935 + cmd = ipkg_cmd_find ("files");
6937 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6939 + ipkg_cb_list = NULL;
6940 + ipkg_conf_deinit(&ipkg_conf);
6946 +ipkg_file_search(args_t *args,
6948 + ipkg_list_callback cblist,
6952 + ipkg_conf_t ipkg_conf;
6955 + /* this error should be handled in application */
6956 + if (!file || !strlen (file))
6959 + err = ipkg_conf_init (&ipkg_conf, args);
6965 + ipkg_cb_list = cblist;
6967 + /* we need to do this because of static declarations,
6968 + * maybe a good idea to change */
6969 + cmd = ipkg_cmd_find ("search");
6970 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6972 + ipkg_cb_list = NULL;
6973 + ipkg_conf_deinit(&ipkg_conf);
6979 +ipkg_file_what(args_t *args, const char *file, const char* command)
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 + /* we need to do this because of static declarations,
6996 + * maybe a good idea to change */
6997 + cmd = ipkg_cmd_find (command);
6998 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7000 + ipkg_conf_deinit(&ipkg_conf);
7004 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7005 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7006 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7007 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7008 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7011 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7014 + if (conf && (conf->verbosity < level)) {
7018 + if ( level == IPKG_ERROR ){
7019 + push_error_list(&error_list, msg);
7028 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7029 + pkg_state_status_t status, void *userdata)
7032 + printf("%s - %s - %s\n", name, version, desc);
7034 + printf("%s - %s\n", name, version);
7038 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7039 + pkg_state_status_t status, void *userdata)
7042 + printf("%s\n", desc);
7046 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7049 + printf("%s\n", desc);
7053 +char* default_ipkg_response_callback(char *question)
7055 + char *response = NULL;
7059 + response = (char *)file_read_line_alloc(stdin);
7060 + } while (response == NULL);
7064 +/* This is used for backward compatibility */
7066 +ipkg_op (int argc, char *argv[])
7072 + ipkg_conf_t ipkg_conf;
7074 + args_init (&args);
7076 + optind = args_parse (&args, argc, argv);
7077 + if (optind == argc || optind < 0)
7079 + args_usage ("ipkg must have one sub-command argument");
7082 + cmd_name = argv[optind++];
7083 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7084 + read anything from there.
7086 + if ( !strcmp(cmd_name,"print-architecture") ||
7087 + !strcmp(cmd_name,"print_architecture") ||
7088 + !strcmp(cmd_name,"print-installation-architecture") ||
7089 + !strcmp(cmd_name,"print_installation_architecture") )
7090 + args.nocheckfordirorfile = 1;
7092 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7093 + read anything from there.
7095 + if ( !strcmp(cmd_name,"flag") ||
7096 + !strcmp(cmd_name,"configure") ||
7097 + !strcmp(cmd_name,"remove") ||
7098 + !strcmp(cmd_name,"files") ||
7099 + !strcmp(cmd_name,"search") ||
7100 + !strcmp(cmd_name,"compare_versions") ||
7101 + !strcmp(cmd_name,"compare-versions") ||
7102 + !strcmp(cmd_name,"list_installed") ||
7103 + !strcmp(cmd_name,"list-installed") ||
7104 + !strcmp(cmd_name,"status") )
7105 + args.noreadfeedsfile = 1;
7108 + err = ipkg_conf_init (&ipkg_conf, &args);
7114 + args_deinit (&args);
7116 + ipkg_cb_message = default_ipkg_message_callback;
7117 + ipkg_cb_response = default_ipkg_response_callback;
7118 + ipkg_cb_status = default_ipkg_status_callback;
7119 + if ( strcmp(cmd_name, "files")==0)
7120 + ipkg_cb_list = default_ipkg_files_callback;
7122 + ipkg_cb_list = default_ipkg_list_callback;
7124 + cmd = ipkg_cmd_find (cmd_name);
7127 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7129 + args_usage (NULL);
7132 + if (cmd->requires_args && optind == argc)
7135 + "%s: the ``%s'' command requires at least one argument\n",
7136 + __FUNCTION__, cmd_name);
7137 + args_usage (NULL);
7140 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7142 + ipkg_conf_deinit (&ipkg_conf);
7147 +#endif /* IPKG_LIB */
7148 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h
7149 --- busybox-1.2.0-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7150 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-07-22 16:31:25.000000000 +0200
7152 +/* ipkglib.h - the itsy package management system
7154 + Florian Boor <florian.boor@kernelconcepts.de>
7156 + This program is free software; you can redistribute it and/or
7157 + modify it under the terms of the GNU General Public License as
7158 + published by the Free Software Foundation; either version 2, or (at
7159 + your option) any later version.
7161 + This program is distributed in the hope that it will be useful, but
7162 + WITHOUT ANY WARRANTY; without even the implied warranty of
7163 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7164 + General Public License for more details.
7172 +#include "ipkg_conf.h"
7173 +#include "ipkg_message.h"
7178 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7180 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7181 + pkg_state_status_t status, void *userdata);
7182 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7184 +typedef char* (*ipkg_response_callback)(char *question);
7186 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7187 +extern int ipkg_init (ipkg_message_callback mcall,
7188 + ipkg_response_callback rcall,
7191 +extern int ipkg_deinit (args_t *args);
7192 +extern int ipkg_packages_list(args_t *args,
7193 + const char *packages,
7194 + ipkg_list_callback cblist,
7196 +extern int ipkg_packages_status(args_t *args,
7197 + const char *packages,
7198 + ipkg_status_callback cbstatus,
7200 +extern int ipkg_packages_info(args_t *args,
7201 + const char *packages,
7202 + ipkg_status_callback cbstatus,
7204 +extern int ipkg_packages_install(args_t *args, const char *name);
7205 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7206 +extern int ipkg_lists_update(args_t *args);
7207 +extern int ipkg_packages_upgrade(args_t *args);
7208 +extern int ipkg_packages_download(args_t *args, const char *name);
7209 +extern int ipkg_package_files(args_t *args,
7211 + ipkg_list_callback cblist,
7213 +extern int ipkg_file_search(args_t *args,
7215 + ipkg_list_callback cblist,
7217 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7218 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7219 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7220 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7221 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7223 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7224 +extern ipkg_response_callback ipkg_cb_response;
7225 +extern ipkg_status_callback ipkg_cb_status;
7226 +extern ipkg_list_callback ipkg_cb_list;
7227 +extern void push_error_list(struct errlist **errors,char * msg);
7228 +extern void reverse_error_list(struct errlist **errors);
7229 +extern void free_error_list(struct errlist **errors);
7233 +extern int ipkg_op(int argc, char *argv[]);
7239 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile
7240 --- busybox-1.2.0-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
7241 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile 2006-07-22 16:31:25.000000000 +0200
7243 +# Makefile for busybox
7245 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7247 +# This program is free software; you can redistribute it and/or modify
7248 +# it under the terms of the GNU General Public License as published by
7249 +# the Free Software Foundation; either version 2 of the License, or
7250 +# (at your option) any later version.
7252 +# This program is distributed in the hope that it will be useful,
7253 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7254 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7255 +# General Public License for more details.
7257 +# You should have received a copy of the GNU General Public License
7258 +# along with this program; if not, write to the Free Software
7259 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7264 +srcdir=$(top_srcdir)/archival/libipkg
7266 +include $(top_builddir)/Rules.mak
7267 +include $(top_builddir)/.config
7268 +include $(srcdir)/Makefile.in
7269 +all: $(libraries-y)
7270 +-include $(top_builddir)/.depend
7273 + rm -f *.o *.a $(AR_TARGET)
7275 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in
7276 --- busybox-1.2.0-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
7277 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in 2006-10-08 12:29:39.000000000 +0200
7279 +# Makefile for busybox
7281 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7283 +# This program is free software; you can redistribute it and/or modify
7284 +# it under the terms of the GNU General Public License as published by
7285 +# the Free Software Foundation; either version 2 of the License, or
7286 +# (at your option) any later version.
7288 +# This program is distributed in the hope that it will be useful,
7289 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7290 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7291 +# General Public License for more details.
7293 +# You should have received a copy of the GNU General Public License
7294 +# along with this program; if not, write to the Free Software
7295 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7298 +LIBIPKG_AR:=libipkg.a
7299 +ifndef $(LIBIPKG_DIR)
7300 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
7302 +srcdir=$(top_srcdir)/archival/libipkg
7304 +LIBIPKG_CORE_SOURCES:= \
7309 +LIBIPKG_CMD_SOURCES:= \
7311 + ipkg_configure.c \
7317 +LIBIPKG_DB_SOURCES:= \
7328 +LIBIPKG_LIST_SOURCES:= \
7340 +LIBIPKG_UTIL_SOURCES:= \
7347 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CORE_SOURCES)
7348 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CMD_SOURCES)
7349 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_DB_SOURCES)
7350 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_LIST_SOURCES)
7351 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_SOURCES)
7352 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
7354 +ifeq ($(strip $(IPKG_ARCH)),)
7355 +IPKG_ARCH:=$(TARGET_ARCH)
7357 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
7359 +libraries-$(CONFIG_IPKG) += $(LIBIPKG_DIR)$(LIBIPKG_AR)
7361 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
7364 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
7367 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c
7368 --- busybox-1.2.0-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7369 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c 2006-07-22 16:31:25.000000000 +0200
7371 +/* md5.c - wrappers to busybox md5 functions
7373 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7375 + * This program is free software; you can redistribute it and/or modify
7376 + * it under the terms of the GNU General Public License as published by
7377 + * the Free Software Foundation; either version 2, or (at your option)
7378 + * any later version.
7380 + * This program is distributed in the hope that it will be useful,
7381 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7382 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7383 + * GNU General Public License for more details.
7385 + * You should have received a copy of the GNU General Public License
7386 + * along with this program; if not, write to the Free Software Foundation,
7387 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7395 +int md5_stream(FILE *stream, void *resblock)
7400 + if( (fd = fileno(stream)) == -1 ) {
7401 + bb_error_msg("bad file descriptor");
7405 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7410 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7414 + md5_begin(&md5_cx);
7415 + md5_hash(buffer, len, &md5_cx);
7416 + return md5_end(resblock, &md5_cx);
7419 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h
7420 --- busybox-1.2.0-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7421 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h 2006-07-22 16:31:25.000000000 +0200
7423 +/* md5.h - Compute MD5 checksum of files or strings according to the
7424 + * definition of MD5 in RFC 1321 from April 1992.
7425 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7427 + * This program is free software; you can redistribute it and/or modify
7428 + * it under the terms of the GNU General Public License as published by
7429 + * the Free Software Foundation; either version 2, or (at your option)
7430 + * any later version.
7432 + * This program is distributed in the hope that it will be useful,
7433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7435 + * GNU General Public License for more details.
7437 + * You should have received a copy of the GNU General Public License
7438 + * along with this program; if not, write to the Free Software Foundation,
7439 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7445 +/* Compute MD5 message digest for bytes read from STREAM. The
7446 + resulting message digest number will be written into the 16 bytes
7447 + beginning at RESBLOCK. */
7448 +int md5_stream(FILE *stream, void *resblock);
7450 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7451 + result is always in little endian byte order, so that a byte-wise
7452 + output yields to the wanted ASCII representation of the message
7454 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7458 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c
7459 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7460 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-07-22 16:31:25.000000000 +0200
7462 +/* nv_pair.c - the itsy package management system
7466 + Copyright (C) 2001 University of Southern California
7468 + This program is free software; you can redistribute it and/or
7469 + modify it under the terms of the GNU General Public License as
7470 + published by the Free Software Foundation; either version 2, or (at
7471 + your option) any later version.
7473 + This program is distributed in the hope that it will be useful, but
7474 + WITHOUT ANY WARRANTY; without even the implied warranty of
7475 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7476 + General Public License for more details.
7481 +#include "nv_pair.h"
7482 +#include "str_util.h"
7484 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7486 + nv_pair->name = str_dup_safe(name);
7487 + nv_pair->value = str_dup_safe(value);
7492 +void nv_pair_deinit(nv_pair_t *nv_pair)
7494 + free(nv_pair->name);
7495 + nv_pair->name = NULL;
7497 + free(nv_pair->value);
7498 + nv_pair->value = NULL;
7502 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h
7503 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7504 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-07-22 16:31:25.000000000 +0200
7506 +/* nv_pair.h - the itsy package management system
7510 + Copyright (C) 2001 University of Southern California
7512 + This program is free software; you can redistribute it and/or
7513 + modify it under the terms of the GNU General Public License as
7514 + published by the Free Software Foundation; either version 2, or (at
7515 + your option) any later version.
7517 + This program is distributed in the hope that it will be useful, but
7518 + WITHOUT ANY WARRANTY; without even the implied warranty of
7519 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7520 + General Public License for more details.
7526 +typedef struct nv_pair nv_pair_t;
7533 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7534 +void nv_pair_deinit(nv_pair_t *nv_pair);
7538 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c
7539 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7540 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-07-22 16:31:25.000000000 +0200
7542 +/* nv_pair_list.c - the itsy package management system
7546 + Copyright (C) 2001 University of Southern California
7548 + This program is free software; you can redistribute it and/or
7549 + modify it under the terms of the GNU General Public License as
7550 + published by the Free Software Foundation; either version 2, or (at
7551 + your option) any later version.
7553 + This program is distributed in the hope that it will be useful, but
7554 + WITHOUT ANY WARRANTY; without even the implied warranty of
7555 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7556 + General Public License for more details.
7561 +#include "nv_pair.h"
7562 +#include "void_list.h"
7563 +#include "nv_pair_list.h"
7565 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7567 + return void_list_elt_init((void_list_elt_t *) elt, data);
7570 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7572 + void_list_elt_deinit((void_list_elt_t *) elt);
7575 +int nv_pair_list_init(nv_pair_list_t *list)
7577 + return void_list_init((void_list_t *) list);
7580 +void nv_pair_list_deinit(nv_pair_list_t *list)
7582 + nv_pair_list_elt_t *iter;
7583 + nv_pair_t *nv_pair;
7585 + for (iter = list->head; iter; iter = iter->next) {
7586 + nv_pair = iter->data;
7587 + nv_pair_deinit(nv_pair);
7589 + /* malloced in nv_pair_list_append */
7591 + iter->data = NULL;
7593 + void_list_deinit((void_list_t *) list);
7596 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7600 + /* freed in nv_pair_list_deinit */
7601 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7603 + if (nv_pair == NULL) {
7604 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7607 + nv_pair_init(nv_pair, name, value);
7609 + err = void_list_append((void_list_t *) list, nv_pair);
7617 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7619 + return void_list_push((void_list_t *) list, data);
7622 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7624 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7627 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7629 + nv_pair_list_elt_t *iter;
7630 + nv_pair_t *nv_pair;
7632 + for (iter = list->head; iter; iter = iter->next) {
7633 + nv_pair = iter->data;
7634 + if (strcmp(nv_pair->name, name) == 0) {
7635 + return nv_pair->value;
7640 diff -ruN busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h
7641 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7642 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-07-22 16:31:25.000000000 +0200
7644 +/* nv_pair_list.h - the itsy package management system
7648 + Copyright (C) 2001 University of Southern California
7650 + This program is free software; you can redistribute it and/or
7651 + modify it under the terms of the GNU General Public License as
7652 + published by the Free Software Foundation; either version 2, or (at
7653 + your option) any later version.
7655 + This program is distributed in the hope that it will be useful, but
7656 + WITHOUT ANY WARRANTY; without even the implied warranty of
7657 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7658 + General Public License for more details.
7661 +#ifndef NV_PAIR_LIST_H
7662 +#define NV_PAIR_LIST_H
7664 +#include "nv_pair.h"
7665 +#include "void_list.h"
7667 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7668 +struct nv_pair_list_elt
7670 + nv_pair_list_elt_t *next;
7674 +typedef struct nv_pair_list nv_pair_list_t;
7675 +struct nv_pair_list
7677 + nv_pair_list_elt_t pre_head;
7678 + nv_pair_list_elt_t *head;
7679 + nv_pair_list_elt_t *tail;
7682 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7684 + if (list->head == NULL)
7690 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7691 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7693 +int nv_pair_list_init(nv_pair_list_t *list);
7694 +void nv_pair_list_deinit(nv_pair_list_t *list);
7696 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7697 + const char *name, const char *value);
7698 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7699 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7700 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7704 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c
7705 --- busybox-1.2.0-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7706 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c 2006-07-22 16:31:25.000000000 +0200
7708 +/* pkg.c - the itsy package management system
7712 + Copyright (C) 2001 University of Southern California
7714 + This program is free software; you can redistribute it and/or
7715 + modify it under the terms of the GNU General Public License as
7716 + published by the Free Software Foundation; either version 2, or (at
7717 + your option) any later version.
7719 + This program is distributed in the hope that it will be useful, but
7720 + WITHOUT ANY WARRANTY; without even the implied warranty of
7721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7722 + General Public License for more details.
7727 +#include <string.h>
7732 +#include "pkg_parse.h"
7733 +#include "pkg_extract.h"
7734 +#include "ipkg_message.h"
7735 +#include "ipkg_utils.h"
7737 +#include "sprintf_alloc.h"
7738 +#include "file_util.h"
7739 +#include "str_util.h"
7740 +#include "xsystem.h"
7741 +#include "ipkg_conf.h"
7743 +typedef struct enum_map enum_map_t;
7750 +static const enum_map_t pkg_state_want_map[] = {
7751 + { SW_UNKNOWN, "unknown"},
7752 + { SW_INSTALL, "install"},
7753 + { SW_DEINSTALL, "deinstall"},
7754 + { SW_PURGE, "purge"}
7757 +static const enum_map_t pkg_state_flag_map[] = {
7759 + { SF_REINSTREQ, "reinstreq"},
7760 + { SF_HOLD, "hold"},
7761 + { SF_REPLACE, "replace"},
7762 + { SF_NOPRUNE, "noprune"},
7763 + { SF_PREFER, "prefer"},
7764 + { SF_OBSOLETE, "obsolete"},
7765 + { SF_USER, "user"},
7768 +static const enum_map_t pkg_state_status_map[] = {
7769 + { SS_NOT_INSTALLED, "not-installed" },
7770 + { SS_UNPACKED, "unpacked" },
7771 + { SS_HALF_CONFIGURED, "half-configured" },
7772 + { SS_INSTALLED, "installed" },
7773 + { SS_HALF_INSTALLED, "half-installed" },
7774 + { SS_CONFIG_FILES, "config-files" },
7775 + { SS_POST_INST_FAILED, "post-inst-failed" },
7776 + { SS_REMOVAL_FAILED, "removal-failed" }
7779 +static int verrevcmp(const char *val, const char *ref);
7782 +pkg_t *pkg_new(void)
7786 + pkg = malloc(sizeof(pkg_t));
7787 + if (pkg == NULL) {
7788 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7797 +int pkg_init(pkg_t *pkg)
7799 + memset(pkg, 0, sizeof(pkg_t));
7802 + pkg->version = NULL;
7803 + pkg->revision = NULL;
7804 + pkg->familiar_revision = NULL;
7807 + pkg->architecture = NULL;
7808 + pkg->maintainer = NULL;
7809 + pkg->section = NULL;
7810 + pkg->description = NULL;
7811 + pkg->state_want = SW_UNKNOWN;
7812 + pkg->state_flag = SF_OK;
7813 + pkg->state_status = SS_NOT_INSTALLED;
7814 + pkg->depends_str = NULL;
7815 + pkg->provides_str = NULL;
7816 + pkg->depends_count = 0;
7817 + pkg->depends = NULL;
7818 + pkg->suggests_str = NULL;
7819 + pkg->recommends_str = NULL;
7820 + pkg->suggests_count = 0;
7821 + pkg->recommends_count = 0;
7823 + /* Abhaya: added init for conflicts fields */
7824 + pkg->conflicts = NULL;
7825 + pkg->conflicts_count = 0;
7827 + /* added for replaces. Jamey 7/23/2002 */
7828 + pkg->replaces = NULL;
7829 + pkg->replaces_count = 0;
7831 + pkg->pre_depends_count = 0;
7832 + pkg->pre_depends_str = NULL;
7833 + pkg->provides_count = 0;
7834 + pkg->provides = NULL;
7835 + pkg->filename = NULL;
7836 + pkg->local_filename = NULL;
7837 + pkg->tmp_unpack_dir = NULL;
7838 + pkg->md5sum = NULL;
7840 + pkg->installed_size = NULL;
7841 + pkg->priority = NULL;
7842 + pkg->source = NULL;
7843 + conffile_list_init(&pkg->conffiles);
7844 + pkg->installed_files = NULL;
7845 + pkg->installed_files_ref_cnt = 0;
7846 + pkg->essential = 0;
7847 + pkg->provided_by_hand = 0;
7852 +void pkg_deinit(pkg_t *pkg)
7857 + free(pkg->version);
7858 + pkg->version = NULL;
7859 + /* revision and familiar_revision share storage with version, so
7861 + pkg->revision = NULL;
7862 + pkg->familiar_revision = NULL;
7863 + /* owned by ipkg_conf_t */
7865 + /* owned by ipkg_conf_t */
7867 + free(pkg->architecture);
7868 + pkg->architecture = NULL;
7869 + free(pkg->maintainer);
7870 + pkg->maintainer = NULL;
7871 + free(pkg->section);
7872 + pkg->section = NULL;
7873 + free(pkg->description);
7874 + pkg->description = NULL;
7875 + pkg->state_want = SW_UNKNOWN;
7876 + pkg->state_flag = SF_OK;
7877 + pkg->state_status = SS_NOT_INSTALLED;
7878 + free(pkg->depends_str);
7879 + pkg->depends_str = NULL;
7880 + free(pkg->provides_str);
7881 + pkg->provides_str = NULL;
7882 + pkg->depends_count = 0;
7883 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7884 + pkg->pre_depends_count = 0;
7885 + free(pkg->pre_depends_str);
7886 + pkg->pre_depends_str = NULL;
7887 + pkg->provides_count = 0;
7888 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7889 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7890 + free(pkg->filename);
7891 + pkg->filename = NULL;
7892 + free(pkg->local_filename);
7893 + pkg->local_filename = NULL;
7894 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7895 + ipkg_install.c here. See comment in
7896 + ipkg_install.c:cleanup_temporary_files */
7897 + free(pkg->tmp_unpack_dir);
7898 + pkg->tmp_unpack_dir = NULL;
7899 + free(pkg->md5sum);
7900 + pkg->md5sum = NULL;
7903 + free(pkg->installed_size);
7904 + pkg->installed_size = NULL;
7905 + free(pkg->priority);
7906 + pkg->priority = NULL;
7907 + free(pkg->source);
7908 + pkg->source = NULL;
7909 + conffile_list_deinit(&pkg->conffiles);
7910 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7911 + since if they are calling deinit, they should know. Maybe do an
7912 + assertion here instead? */
7913 + pkg->installed_files_ref_cnt = 1;
7914 + pkg_free_installed_files(pkg);
7915 + pkg->essential = 0;
7918 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7922 + FILE *control_file;
7924 + err = pkg_init(pkg);
7925 + if (err) { return err; }
7927 + pkg->local_filename = strdup(filename);
7929 + control_file = tmpfile();
7930 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7931 + if (err) { return err; }
7933 + rewind(control_file);
7934 + raw = read_raw_pkgs_from_stream(control_file);
7935 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7937 + fclose(control_file);
7942 +/* Merge any new information in newpkg into oldpkg */
7943 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7944 + newpkg, but should leave it usable. This rework is so that
7945 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7947 + * uh, i thought that i had originally written this so that it took
7948 + * two pkgs and returned a new one? we can do that again... -sma
7950 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7952 + if (oldpkg == newpkg) {
7957 + oldpkg->src = newpkg->src;
7958 + if (!oldpkg->dest)
7959 + oldpkg->dest = newpkg->dest;
7960 + if (!oldpkg->architecture)
7961 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7962 + if (!oldpkg->arch_priority)
7963 + oldpkg->arch_priority = newpkg->arch_priority;
7964 + if (!oldpkg->section)
7965 + oldpkg->section = str_dup_safe(newpkg->section);
7966 + if(!oldpkg->maintainer)
7967 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7968 + if(!oldpkg->description)
7969 + oldpkg->description = str_dup_safe(newpkg->description);
7971 + /* merge the state_flags from the new package */
7972 + oldpkg->state_want = newpkg->state_want;
7973 + oldpkg->state_status = newpkg->state_status;
7974 + oldpkg->state_flag = newpkg->state_flag;
7976 + if (oldpkg->state_want == SW_UNKNOWN)
7977 + oldpkg->state_want = newpkg->state_want;
7978 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7979 + oldpkg->state_status = newpkg->state_status;
7980 + oldpkg->state_flag |= newpkg->state_flag;
7983 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7984 + oldpkg->depends_str = newpkg->depends_str;
7985 + newpkg->depends_str = NULL;
7986 + oldpkg->depends_count = newpkg->depends_count;
7987 + newpkg->depends_count = 0;
7989 + oldpkg->depends = newpkg->depends;
7990 + newpkg->depends = NULL;
7992 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7993 + newpkg->pre_depends_str = NULL;
7994 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7995 + newpkg->pre_depends_count = 0;
7997 + oldpkg->recommends_str = newpkg->recommends_str;
7998 + newpkg->recommends_str = NULL;
7999 + oldpkg->recommends_count = newpkg->recommends_count;
8000 + newpkg->recommends_count = 0;
8002 + oldpkg->suggests_str = newpkg->suggests_str;
8003 + newpkg->suggests_str = NULL;
8004 + oldpkg->suggests_count = newpkg->suggests_count;
8005 + newpkg->suggests_count = 0;
8008 + if (!oldpkg->provides_str) {
8009 + oldpkg->provides_str = newpkg->provides_str;
8010 + newpkg->provides_str = NULL;
8011 + oldpkg->provides_count = newpkg->provides_count;
8012 + newpkg->provides_count = 0;
8014 + oldpkg->provides = newpkg->provides;
8015 + newpkg->provides = NULL;
8018 + if (!oldpkg->conflicts_str) {
8019 + oldpkg->conflicts_str = newpkg->conflicts_str;
8020 + newpkg->conflicts_str = NULL;
8021 + oldpkg->conflicts_count = newpkg->conflicts_count;
8022 + newpkg->conflicts_count = 0;
8024 + oldpkg->conflicts = newpkg->conflicts;
8025 + newpkg->conflicts = NULL;
8028 + if (!oldpkg->replaces_str) {
8029 + oldpkg->replaces_str = newpkg->replaces_str;
8030 + newpkg->replaces_str = NULL;
8031 + oldpkg->replaces_count = newpkg->replaces_count;
8032 + newpkg->replaces_count = 0;
8034 + oldpkg->replaces = newpkg->replaces;
8035 + newpkg->replaces = NULL;
8038 + if (!oldpkg->filename)
8039 + oldpkg->filename = str_dup_safe(newpkg->filename);
8041 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8042 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8043 + if (!oldpkg->local_filename)
8044 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8045 + if (!oldpkg->tmp_unpack_dir)
8046 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8047 + if (!oldpkg->md5sum)
8048 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8049 + if (!oldpkg->size)
8050 + oldpkg->size = str_dup_safe(newpkg->size);
8051 + if (!oldpkg->installed_size)
8052 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8053 + if (!oldpkg->priority)
8054 + oldpkg->priority = str_dup_safe(newpkg->priority);
8055 + if (!oldpkg->source)
8056 + oldpkg->source = str_dup_safe(newpkg->source);
8057 + if (oldpkg->conffiles.head == NULL){
8058 + oldpkg->conffiles = newpkg->conffiles;
8059 + conffile_list_init(&newpkg->conffiles);
8061 + if (!oldpkg->installed_files){
8062 + oldpkg->installed_files = newpkg->installed_files;
8063 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8064 + newpkg->installed_files = NULL;
8066 + if (!oldpkg->essential)
8067 + oldpkg->essential = newpkg->essential;
8072 +abstract_pkg_t *abstract_pkg_new(void)
8074 + abstract_pkg_t * ab_pkg;
8076 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8078 + if (ab_pkg == NULL) {
8079 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8083 + if ( abstract_pkg_init(ab_pkg) < 0 )
8089 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8091 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8093 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8094 + if (ab_pkg->provided_by==NULL){
8097 + ab_pkg->dependencies_checked = 0;
8098 + ab_pkg->state_status = SS_NOT_INSTALLED;
8103 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8106 + char **raw_start=NULL;
8108 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8109 + if (temp_str == NULL ){
8110 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8113 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8115 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8116 + if (raw == NULL ){
8117 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8122 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8123 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8139 +char * pkg_formatted_info(pkg_t *pkg )
8144 + buff = malloc(8192);
8145 + if (buff == NULL) {
8146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8152 + line = pkg_formatted_field(pkg, "Package");
8153 + strncat(buff ,line, strlen(line));
8156 + line = pkg_formatted_field(pkg, "Version");
8157 + strncat(buff ,line, strlen(line));
8160 + line = pkg_formatted_field(pkg, "Depends");
8161 + strncat(buff ,line, strlen(line));
8164 + line = pkg_formatted_field(pkg, "Recommends");
8165 + strncat(buff ,line, strlen(line));
8168 + line = pkg_formatted_field(pkg, "Suggests");
8169 + strncat(buff ,line, strlen(line));
8172 + line = pkg_formatted_field(pkg, "Provides");
8173 + strncat(buff ,line, strlen(line));
8176 + line = pkg_formatted_field(pkg, "Replaces");
8177 + strncat(buff ,line, strlen(line));
8180 + line = pkg_formatted_field(pkg, "Conflicts");
8181 + strncat(buff ,line, strlen(line));
8184 + line = pkg_formatted_field(pkg, "Status");
8185 + strncat(buff ,line, strlen(line));
8188 + line = pkg_formatted_field(pkg, "Section");
8189 + strncat(buff ,line, strlen(line));
8192 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8193 + strncat(buff ,line, strlen(line));
8196 + line = pkg_formatted_field(pkg, "Architecture");
8197 + strncat(buff ,line, strlen(line));
8200 + line = pkg_formatted_field(pkg, "Maintainer");
8201 + strncat(buff ,line, strlen(line));
8204 + line = pkg_formatted_field(pkg, "MD5sum");
8205 + strncat(buff ,line, strlen(line));
8208 + line = pkg_formatted_field(pkg, "Size");
8209 + strncat(buff ,line, strlen(line));
8212 + line = pkg_formatted_field(pkg, "Filename");
8213 + strncat(buff ,line, strlen(line));
8216 + line = pkg_formatted_field(pkg, "Conffiles");
8217 + strncat(buff ,line, strlen(line));
8220 + line = pkg_formatted_field(pkg, "Source");
8221 + strncat(buff ,line, strlen(line));
8224 + line = pkg_formatted_field(pkg, "Description");
8225 + strncat(buff ,line, strlen(line));
8228 + line = pkg_formatted_field(pkg, "Installed-Time");
8229 + strncat(buff ,line, strlen(line));
8235 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8237 + static size_t LINE_LEN = 128;
8238 + char * temp = (char *)malloc(1);
8240 + int flag_provide_false = 0;
8243 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8244 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8247 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8248 + goto UNKNOWN_FMT_FIELD;
8257 + if (strcasecmp(field, "Architecture") == 0) {
8258 + /* Architecture */
8259 + if (pkg->architecture) {
8260 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8261 + if ( temp == NULL ){
8262 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8266 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8269 + goto UNKNOWN_FMT_FIELD;
8274 + if (strcasecmp(field, "Conffiles") == 0) {
8276 + conffile_list_elt_t *iter;
8277 + char confstr[LINE_LEN];
8279 + if (pkg->conffiles.head == NULL) {
8284 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8285 + if (iter->data->name && iter->data->value) {
8286 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8289 + temp = (char *)realloc(temp,len);
8290 + if ( temp == NULL ){
8291 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8295 + strncpy(temp, "Conffiles:\n", 12);
8296 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8297 + if (iter->data->name && iter->data->value) {
8298 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8299 + strncat(temp, confstr, strlen(confstr));
8302 + } else if (strcasecmp(field, "Conflicts") == 0) {
8305 + if (pkg->conflicts_count) {
8306 + char conflictstr[LINE_LEN];
8308 + for(i = 0; i < pkg->conflicts_count; i++) {
8309 + len = len + (strlen(pkg->conflicts_str[i])+5);
8311 + temp = (char *)realloc(temp,len);
8312 + if ( temp == NULL ){
8313 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8317 + strncpy(temp, "Conflicts:", 11);
8318 + for(i = 0; i < pkg->conflicts_count; i++) {
8319 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8320 + strncat(temp, conflictstr, strlen(conflictstr));
8322 + strncat(temp, "\n", strlen("\n"));
8325 + goto UNKNOWN_FMT_FIELD;
8330 + if (strcasecmp(field, "Depends") == 0) {
8334 + if (pkg->depends_count) {
8335 + char depstr[LINE_LEN];
8337 + for(i = 0; i < pkg->depends_count; i++) {
8338 + len = len + (strlen(pkg->depends_str[i])+4);
8340 + temp = (char *)realloc(temp,len);
8341 + if ( temp == NULL ){
8342 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8346 + strncpy(temp, "Depends:", 10);
8347 + for(i = 0; i < pkg->depends_count; i++) {
8348 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8349 + strncat(temp, depstr, strlen(depstr));
8351 + strncat(temp, "\n", strlen("\n"));
8353 + } else if (strcasecmp(field, "Description") == 0) {
8355 + if (pkg->description) {
8356 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8357 + if ( temp == NULL ){
8358 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8362 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8365 + goto UNKNOWN_FMT_FIELD;
8371 + if (pkg->essential) {
8372 + temp = (char *)realloc(temp,16);
8373 + if ( temp == NULL ){
8374 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8378 + snprintf(temp, (16), "Essential: yes\n");
8385 + if (pkg->filename) {
8386 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8387 + if ( temp == NULL ){
8388 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8392 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8398 + if (strcasecmp(field, "Installed-Size") == 0) {
8399 + /* Installed-Size */
8400 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8401 + if ( temp == NULL ){
8402 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8406 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8407 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8408 + temp = (char *)realloc(temp,29);
8409 + if ( temp == NULL ){
8410 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8414 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8420 + /* Maintainer | MD5sum */
8421 + if (strcasecmp(field, "Maintainer") == 0) {
8423 + if (pkg->maintainer) {
8424 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8425 + if ( temp == NULL ){
8426 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8430 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8432 + } else if (strcasecmp(field, "MD5sum") == 0) {
8434 + if (pkg->md5sum) {
8435 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8436 + if ( temp == NULL ){
8437 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8441 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8444 + goto UNKNOWN_FMT_FIELD;
8450 + if (strcasecmp(field, "Package") == 0) {
8452 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8453 + if ( temp == NULL ){
8454 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8458 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8459 + } else if (strcasecmp(field, "Priority") == 0) {
8461 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8462 + if ( temp == NULL ){
8463 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8467 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8468 + } else if (strcasecmp(field, "Provides") == 0) {
8472 + if (pkg->provides_count) {
8473 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8474 + for ( i=0; i < pkg->provides_count; i++ ){
8475 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8476 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8477 + flag_provide_false = 1;
8480 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8481 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8482 + char provstr[LINE_LEN];
8484 + for(i = 0; i < pkg->provides_count; i++) {
8485 + len = len + (strlen(pkg->provides_str[i])+5);
8487 + temp = (char *)realloc(temp,len);
8488 + if ( temp == NULL ){
8489 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8493 + strncpy(temp, "Provides:", 12);
8494 + for(i = 0; i < pkg->provides_count; i++) {
8495 + if (strlen(pkg->provides_str[i])>0){;
8496 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8497 + strncat(temp, provstr, strlen(provstr));
8500 + strncat(temp, "\n", strlen("\n"));
8504 + goto UNKNOWN_FMT_FIELD;
8511 + /* Replaces | Recommends*/
8512 + if (strcasecmp (field, "Replaces") == 0) {
8513 + if (pkg->replaces_count) {
8514 + char replstr[LINE_LEN];
8516 + for (i = 0; i < pkg->replaces_count; i++) {
8517 + len = len + (strlen(pkg->replaces_str[i])+5);
8519 + temp = (char *)realloc(temp,len);
8520 + if ( temp == NULL ){
8521 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8525 + strncpy(temp, "Replaces:", 12);
8526 + for (i = 0; i < pkg->replaces_count; i++) {
8527 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8528 + strncat(temp, replstr, strlen(replstr));
8530 + strncat(temp, "\n", strlen("\n"));
8532 + } else if (strcasecmp (field, "Recommends") == 0) {
8533 + if (pkg->recommends_count) {
8534 + char recstr[LINE_LEN];
8536 + for(i = 0; i < pkg->recommends_count; i++) {
8537 + len = len + (strlen( pkg->recommends_str[i])+5);
8539 + temp = (char *)realloc(temp,len);
8540 + if ( temp == NULL ){
8541 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8545 + strncpy(temp, "Recommends:", 13);
8546 + for(i = 0; i < pkg->recommends_count; i++) {
8547 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8548 + strncat(temp, recstr, strlen(recstr));
8550 + strncat(temp, "\n", strlen("\n"));
8553 + goto UNKNOWN_FMT_FIELD;
8559 + /* Section | Size | Source | Status | Suggests */
8560 + if (strcasecmp(field, "Section") == 0) {
8562 + if (pkg->section) {
8563 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8564 + if ( temp == NULL ){
8565 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8569 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8571 + } else if (strcasecmp(field, "Size") == 0) {
8574 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8575 + if ( temp == NULL ){
8576 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8580 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8582 + } else if (strcasecmp(field, "Source") == 0) {
8584 + if (pkg->source) {
8585 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8586 + if ( temp == NULL ){
8587 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8591 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8593 + } else if (strcasecmp(field, "Status") == 0) {
8595 + /* Benjamin Pineau note: we should avoid direct usage of
8596 + * strlen(arg) without keeping "arg" for later free()
8598 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8599 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8600 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8602 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8603 + temp = (char *)realloc(temp,sum_of_sizes);
8604 + if ( temp == NULL ){
8605 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8609 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8612 + if(pstat) /* pfstat can be NULL if ENOMEM */
8614 + } else if (strcasecmp(field, "Suggests") == 0) {
8615 + if (pkg->suggests_count) {
8617 + char sugstr[LINE_LEN];
8619 + for(i = 0; i < pkg->suggests_count; i++) {
8620 + len = len + (strlen(pkg->suggests_str[i])+5);
8622 + temp = (char *)realloc(temp,len);
8623 + if ( temp == NULL ){
8624 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8628 + strncpy(temp, "Suggests:", 10);
8629 + for(i = 0; i < pkg->suggests_count; i++) {
8630 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8631 + strncat(temp, sugstr, strlen(sugstr));
8633 + strncat(temp, "\n", strlen("\n"));
8636 + goto UNKNOWN_FMT_FIELD;
8643 + char *version = pkg_version_str_alloc(pkg);
8644 + temp = (char *)realloc(temp,strlen(version)+14);
8645 + if ( temp == NULL ){
8646 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8650 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8655 + goto UNKNOWN_FMT_FIELD;
8658 + if ( strlen(temp)<2 ) {
8663 + UNKNOWN_FMT_FIELD:
8664 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8665 + if ( strlen(temp)<2 ) {
8672 +void pkg_print_info(pkg_t *pkg, FILE *file)
8675 + if (pkg == NULL) {
8679 + buff = pkg_formatted_info(pkg);
8680 + if ( buff == NULL )
8682 + if (strlen(buff)>2){
8683 + fwrite(buff, 1, strlen(buff), file);
8688 +void pkg_print_status(pkg_t * pkg, FILE * file)
8690 + if (pkg == NULL) {
8694 + /* XXX: QUESTION: Do we actually want more fields here? The
8695 + original idea was to save space by installing only what was
8696 + needed for actual computation, (package, version, status,
8697 + essential, conffiles). The assumption is that all other fields
8698 + can be found in th available file.
8700 + But, someone proposed the idea to make it possible to
8701 + reconstruct a .ipk from an installed package, (ie. for beaming
8702 + from one handheld to another). So, maybe we actually want a few
8703 + more fields here, (depends, suggests, etc.), so that that would
8704 + be guaranteed to work even in the absence of more information
8705 + from the available file.
8707 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8708 + the essential info needs to be here for all installed packages
8709 + because they may not appear in the Packages files on various
8710 + feeds. Furthermore, one should be able to install from URL or
8711 + local storage without requiring a Packages file from any feed.
8714 + pkg_print_field(pkg, file, "Package");
8715 + pkg_print_field(pkg, file, "Version");
8716 + pkg_print_field(pkg, file, "Depends");
8717 + pkg_print_field(pkg, file, "Recommends");
8718 + pkg_print_field(pkg, file, "Suggests");
8719 + pkg_print_field(pkg, file, "Provides");
8720 + pkg_print_field(pkg, file, "Replaces");
8721 + pkg_print_field(pkg, file, "Conflicts");
8722 + pkg_print_field(pkg, file, "Status");
8723 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8724 + pkg_print_field(pkg, file, "Architecture");
8725 + pkg_print_field(pkg, file, "Conffiles");
8726 + pkg_print_field(pkg, file, "Installed-Time");
8727 + fputs("\n", file);
8730 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8733 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8734 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8735 + __FUNCTION__, field);
8737 + buff = pkg_formatted_field(pkg, field);
8738 + if (strlen(buff)>2) {
8739 + fprintf(file, "%s", buff);
8747 + * libdpkg - Debian packaging suite library routines
8748 + * vercmp.c - comparison of version numbers
8750 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8752 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8756 + if (pkg->epoch > ref_pkg->epoch) {
8760 + if (pkg->epoch < ref_pkg->epoch) {
8764 + r = verrevcmp(pkg->version, ref_pkg->version);
8769 +#ifdef USE_DEBVERSION
8770 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8775 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8781 +int verrevcmp(const char *val, const char *ref)
8785 + const char *vp, *rp;
8786 + const char *vsep, *rsep;
8788 + if (!val) val= "";
8789 + if (!ref) ref= "";
8791 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8792 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8794 + vc= (val == vp) ? 0 : *val++;
8795 + rc= (ref == rp) ? 0 : *ref++;
8796 + if (!rc && !vc) break;
8797 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8798 + if (rc && !isalpha(rc)) rc += 256;
8799 + if (vc != rc) return vc - rc;
8803 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8804 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8805 + if (vl != rl) return vl - rl;
8809 + vsep = strchr(".-", vc);
8810 + rsep = strchr(".-", rc);
8811 + if (vsep && !rsep) return -1;
8812 + if (!vsep && rsep) return +1;
8814 + if (!*val && !*ref) return 0;
8815 + if (!*val) return -1;
8816 + if (!*ref) return +1;
8820 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8824 + r = pkg_compare_versions(it, ref);
8826 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8830 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8834 + if (strcmp(op, "<<") == 0) {
8838 + if (strcmp(op, ">>") == 0) {
8842 + if (strcmp(op, "=") == 0) {
8846 + fprintf(stderr, "unknown operator: %s", op);
8850 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8852 + const pkg_t *a = *(const pkg_t **)p1;
8853 + const pkg_t *b = *(const pkg_t **)p2;
8856 + if (!a->name || !b->name) {
8857 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8858 + a, a->name, b, b->name);
8862 + namecmp = strcmp(a->name, b->name);
8865 + vercmp = pkg_compare_versions(a, b);
8868 + if (!a->arch_priority || !b->arch_priority) {
8869 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8870 + a, a->arch_priority, b, b->arch_priority);
8873 + if (a->arch_priority > b->arch_priority)
8875 + if (a->arch_priority < b->arch_priority)
8880 +int abstract_pkg_name_compare(void *p1, void *p2)
8882 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8883 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8884 + if (!a->name || !b->name) {
8885 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8886 + a, a->name, b, b->name);
8889 + return strcmp(a->name, b->name);
8893 +char *pkg_version_str_alloc(pkg_t *pkg)
8895 + char *complete_version;
8897 +#ifdef USE_DEBVERSION
8898 + char *revision_str;
8899 + char *familiar_revision_str;
8903 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8905 + epoch_str = strdup("");
8908 +#ifdef USE_DEBVERSION
8909 + if (pkg->revision && strlen(pkg->revision)) {
8910 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8912 + revision_str = strdup("");
8915 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8916 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8918 + familiar_revision_str = strdup("");
8922 +#ifdef USE_DEBVERSION
8923 + sprintf_alloc(&complete_version, "%s%s%s%s",
8924 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8926 + sprintf_alloc(&complete_version, "%s%s",
8927 + epoch_str, pkg->version);
8931 +#ifdef USE_DEBVERSION
8932 + free(revision_str);
8933 + free(familiar_revision_str);
8936 + return complete_version;
8939 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8942 + char *list_file_name = NULL;
8943 + FILE *list_file = NULL;
8945 + char *installed_file_name;
8948 + pkg->installed_files_ref_cnt++;
8950 + if (pkg->installed_files) {
8951 + return pkg->installed_files;
8954 + pkg->installed_files = str_list_alloc();
8955 + if (pkg->installed_files == NULL) {
8956 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8960 + /* For uninstalled packages, get the file list firectly from the package.
8961 + For installed packages, look at the package.list file in the database.
8963 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8964 + if (pkg->local_filename == NULL) {
8965 + return pkg->installed_files;
8967 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8968 + file. In other words, change deb_extract so that it can
8969 + simply return the file list as a char *[] rather than
8970 + insisting on writing in to a FILE * as it does now. */
8971 + list_file = tmpfile();
8972 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8974 + fclose(list_file);
8975 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8976 + __FUNCTION__, pkg->local_filename, strerror(err));
8977 + return pkg->installed_files;
8979 + rewind(list_file);
8981 + sprintf_alloc(&list_file_name, "%s/%s.list",
8982 + pkg->dest->info_dir, pkg->name);
8983 + if (! file_exists(list_file_name)) {
8984 + free(list_file_name);
8985 + return pkg->installed_files;
8988 + list_file = fopen(list_file_name, "r");
8989 + if (list_file == NULL) {
8990 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8991 + list_file_name, strerror(errno));
8992 + free(list_file_name);
8993 + return pkg->installed_files;
8995 + free(list_file_name);
8998 + rootdirlen = strlen( pkg->dest->root_dir );
9002 + line = file_read_line_alloc(list_file);
9003 + if (line == NULL) {
9009 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9010 + if( strncmp( pkg->dest->root_dir,
9013 + if (*file_name == '.') {
9016 + if (*file_name == '/') {
9020 + /* Freed in pkg_free_installed_files */
9021 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9023 + // already contains root_dir as header -> ABSOLUTE
9024 + sprintf_alloc(&installed_file_name, "%s", file_name);
9026 + str_list_append(pkg->installed_files, installed_file_name);
9030 + fclose(list_file);
9032 + return pkg->installed_files;
9035 +/* XXX: CLEANUP: This function and it's counterpart,
9036 + (pkg_get_installed_files), do not match our init/deinit naming
9037 + convention. Nor the alloc/free convention. But, then again, neither
9038 + of these conventions currrently fit the way these two functions
9040 +int pkg_free_installed_files(pkg_t *pkg)
9042 + str_list_elt_t *iter;
9044 + pkg->installed_files_ref_cnt--;
9045 + if (pkg->installed_files_ref_cnt > 0) {
9049 + if (pkg->installed_files) {
9051 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9052 + /* malloced in pkg_get_installed_files */
9053 + free (iter->data);
9054 + iter->data = NULL;
9057 + str_list_deinit(pkg->installed_files);
9060 + pkg->installed_files = NULL;
9065 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9068 + char *list_file_name;
9070 + //I don't think pkg_free_installed_files should be called here. Jamey
9071 + //pkg_free_installed_files(pkg);
9073 + sprintf_alloc(&list_file_name, "%s/%s.list",
9074 + pkg->dest->info_dir, pkg->name);
9075 + if (!conf->noaction) {
9076 + err = unlink(list_file_name);
9077 + free(list_file_name);
9086 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9088 + conffile_list_elt_t *iter;
9089 + conffile_t *conffile;
9091 + if (pkg == NULL) {
9095 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9096 + conffile = iter->data;
9098 + if (strcmp(conffile->name, file_name) == 0) {
9106 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9107 + const char *script, const char *args)
9113 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9114 + maintainer script within a chroot environment. */
9116 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9117 + have scripts in pkg->tmp_unpack_dir. */
9118 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9119 + if (pkg->dest == NULL) {
9120 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9121 + __FUNCTION__, pkg->name);
9124 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9126 + if (pkg->tmp_unpack_dir == NULL) {
9127 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9128 + __FUNCTION__, pkg->name);
9131 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9134 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9135 + if (conf->noaction) return 0;
9137 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9138 + scripts when running with offline_root mode and/or a dest other
9139 + than '/'. I've been playing around with some clever chroot
9140 + tricks and I might come up with something workable. */
9141 + if (conf->offline_root) {
9142 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9145 + setenv("PKG_ROOT",
9146 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9148 + if (! file_exists(path)) {
9153 + if (conf->offline_root) {
9154 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9159 + sprintf_alloc(&cmd, "%s %s", path, args);
9162 + err = xsystem(cmd);
9166 + fprintf(stderr, "%s script returned status %d\n", script, err);
9173 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9177 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9178 + if (pkg_state_want_map[i].value == sw) {
9179 + return strdup(pkg_state_want_map[i].str);
9183 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9184 + __FUNCTION__, sw);
9185 + return strdup("<STATE_WANT_UNKNOWN>");
9188 +pkg_state_want_t pkg_state_want_from_str(char *str)
9192 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9193 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9194 + return pkg_state_want_map[i].value;
9198 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9199 + __FUNCTION__, str);
9200 + return SW_UNKNOWN;
9203 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9206 + int len = 3; /* ok\000 is minimum */
9209 + /* clear the temporary flags before converting to string */
9210 + sf &= SF_NONVOLATILE_FLAGS;
9213 + return strdup("ok");
9216 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9217 + if (sf & pkg_state_flag_map[i].value) {
9218 + len += strlen(pkg_state_flag_map[i].str) + 1;
9221 + str = malloc(len);
9222 + if ( str == NULL ) {
9223 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9227 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9228 + if (sf & pkg_state_flag_map[i].value) {
9229 + strcat(str, pkg_state_flag_map[i].str);
9233 + len = strlen(str);
9234 + str[len-1] = 0; /* squash last comma */
9239 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9244 + if (strcmp(str, "ok") == 0) {
9247 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9248 + const char *sfname = pkg_state_flag_map[i].str;
9249 + int sfname_len = strlen(sfname);
9250 + if (strncmp(str, sfname, sfname_len) == 0) {
9251 + sf |= pkg_state_flag_map[i].value;
9252 + str += sfname_len;
9253 + if (str[0] == ',') {
9264 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9268 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9269 + if (pkg_state_status_map[i].value == ss) {
9270 + return strdup(pkg_state_status_map[i].str);
9274 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9275 + __FUNCTION__, ss);
9276 + return strdup("<STATE_STATUS_UNKNOWN>");
9279 +pkg_state_status_t pkg_state_status_from_str(char *str)
9283 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9284 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9285 + return pkg_state_status_map[i].value;
9289 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9290 + __FUNCTION__, str);
9291 + return SS_NOT_INSTALLED;
9294 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9296 + nv_pair_list_elt_t *l;
9298 + if (!pkg->architecture)
9301 + l = conf->arch_list.head;
9304 + nv_pair_t *nv = l->data;
9305 + if (strcmp(nv->name, pkg->architecture) == 0) {
9306 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9312 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9316 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9318 + nv_pair_list_elt_t *l;
9320 + l = conf->arch_list.head;
9323 + nv_pair_t *nv = l->data;
9324 + if (strcmp(nv->name, archname) == 0) {
9325 + int priority = strtol(nv->value, NULL, 0);
9333 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9336 + hash_table_t *pkg_hash = &conf->pkg_hash;
9337 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9338 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9340 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9341 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9342 + /* update arch_priority for each package */
9343 + for (i = 0; i < available_pkgs->len; i++) {
9344 + pkg_t *pkg = available_pkgs->pkgs[i];
9345 + int arch_priority = 1;
9348 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9349 + if (pkg->architecture)
9350 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9352 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9353 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9354 + pkg->arch_priority = arch_priority;
9357 + for (i = 0; i < available_pkgs->len; i++) {
9358 + pkg_t *pkg = available_pkgs->pkgs[i];
9359 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9360 + /* clear flags and want for any uninstallable package */
9361 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9362 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9363 + pkg->state_want = SW_UNKNOWN;
9364 + pkg->state_flag = 0;
9367 + pkg_vec_free(available_pkgs);
9369 + /* update the file owner data structure */
9370 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9371 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9372 + for (i = 0; i < installed_pkgs->len; i++) {
9373 + pkg_t *pkg = installed_pkgs->pkgs[i];
9374 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9375 + str_list_elt_t *iter;
9376 + if (installed_files == NULL) {
9377 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9380 + for (iter = installed_files->head; iter; iter = iter->next) {
9381 + char *installed_file = iter->data;
9382 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9383 + file_hash_set_file_owner(conf, installed_file, pkg);
9386 + pkg_vec_free(installed_pkgs);
9391 +struct pkg_write_filelist_data {
9392 + ipkg_conf_t *conf;
9397 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9399 + struct pkg_write_filelist_data *data = data_;
9400 + pkg_t *entry = entry_;
9401 + if (entry == data->pkg) {
9402 + fprintf(data->stream, "%s\n", key);
9406 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9408 + struct pkg_write_filelist_data data;
9409 + char *list_file_name = NULL;
9413 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9416 + ipkg_message(conf, IPKG_INFO,
9417 + " creating %s.list file\n", pkg->name);
9418 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9419 + if (!list_file_name) {
9420 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9423 + ipkg_message(conf, IPKG_INFO,
9424 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9425 + data.stream = fopen(list_file_name, "w");
9426 + if (!data.stream) {
9427 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9428 + list_file_name, strerror(errno));
9433 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9434 + fclose(data.stream);
9435 + free(list_file_name);
9440 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9442 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9443 + hash_table_t *pkg_hash = &conf->pkg_hash;
9446 + if (conf->noaction)
9449 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9450 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9451 + for (i = 0; i < installed_pkgs->len; i++) {
9452 + pkg_t *pkg = installed_pkgs->pkgs[i];
9453 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9454 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9455 + err = pkg_write_filelist(conf, pkg);
9457 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9462 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_depends.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c
9463 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9464 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-07-22 16:31:25.000000000 +0200
9466 +/* pkg_depends.c - the itsy package management system
9470 + Copyright (C) 2002 Compaq Computer Corporation
9472 + This program is free software; you can redistribute it and/or
9473 + modify it under the terms of the GNU General Public License as
9474 + published by the Free Software Foundation; either version 2, or (at
9475 + your option) any later version.
9477 + This program is distributed in the hope that it will be useful, but
9478 + WITHOUT ANY WARRANTY; without even the implied warranty of
9479 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9480 + General Public License for more details.
9488 +#include "ipkg_utils.h"
9489 +#include "pkg_hash.h"
9490 +#include "ipkg_message.h"
9491 +#include "pkg_parse.h"
9492 +#include "hash_table.h"
9494 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9495 +static depend_t * depend_init(void);
9496 +static void depend_deinit(depend_t *d);
9497 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9498 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9499 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9501 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9503 + depend_t *depend = (depend_t *)cdata;
9504 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9510 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9512 + depend_t *depend = (depend_t *)cdata;
9514 + pkg_t * temp = pkg_new();
9516 + parseVersion(temp, depend->version);
9517 + comparison = pkg_compare_versions(pkg, temp);
9520 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9521 + __FUNCTION__, pkg->name, pkg->version,
9522 + depend, depend->constraint, depend->version,
9523 + comparison, version_constraints_satisfied(depend, pkg));
9525 + if (version_constraints_satisfied(depend, pkg))
9531 +/* returns ndependences or negative error value */
9532 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9533 + pkg_vec_t *unsatisfied, char *** unresolved)
9535 + pkg_t * satisfier_entry_pkg;
9536 + register int i, j, k;
9539 + abstract_pkg_t * ab_pkg;
9542 + * this is a setup to check for redundant/cyclic dependency checks,
9543 + * which are marked at the abstract_pkg level
9545 + if (!(ab_pkg = pkg->parent)) {
9546 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9547 + *unresolved = NULL;
9550 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9551 + *unresolved = NULL;
9554 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9558 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9560 + *unresolved = NULL;
9566 + /* foreach dependency */
9567 + for (i = 0; i < count; i++) {
9568 + compound_depend_t * compound_depend = &pkg->depends[i];
9569 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9571 + satisfier_entry_pkg = NULL;
9573 + if (compound_depend->type == GREEDY_DEPEND) {
9574 + /* foreach possible satisfier */
9575 + for (j = 0; j < compound_depend->possibility_count; j++) {
9576 + /* foreach provided_by, which includes the abstract_pkg itself */
9577 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9578 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9579 + int nposs = ab_provider_vec->len;
9580 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9582 + for (l = 0; l < nposs; l++) {
9583 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9584 + /* if no depends on this one, try the first package that Provides this one */
9585 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9589 + /* cruise this possiblity's pkg_vec looking for an installed version */
9590 + for (k = 0; k < test_vec->len; k++) {
9591 + pkg_t *pkg_scout = test_vec->pkgs[k];
9592 + /* not installed, and not already known about? */
9593 + if ((pkg_scout->state_want != SW_INSTALL)
9594 + && !pkg_scout->parent->dependencies_checked
9595 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9596 + char ** newstuff = NULL;
9598 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9599 + /* check for not-already-installed dependencies */
9600 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9604 + if (newstuff == NULL) {
9607 + for (i = 0; i < rc; i++) {
9608 + pkg_t *p = tmp_vec->pkgs[i];
9609 + if (p->state_want == SW_INSTALL)
9611 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9615 + pkg_vec_free (tmp_vec);
9617 + /* mark this one for installation */
9618 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9619 + pkg_vec_insert(unsatisfied, pkg_scout);
9622 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9633 + /* foreach possible satisfier, look for installed package */
9634 + for (j = 0; j < compound_depend->possibility_count; j++) {
9635 + /* foreach provided_by, which includes the abstract_pkg itself */
9636 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9637 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9638 + pkg_t *satisfying_pkg =
9639 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9640 + pkg_installed_and_constraint_satisfied,
9641 + dependence_to_satisfy, 1);
9642 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9643 + if (satisfying_pkg != NULL) {
9644 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9645 + satisfying_pkg = NULL;
9648 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9649 + if (satisfying_pkg != NULL) {
9655 + /* if nothing installed matches, then look for uninstalled satisfier */
9657 + /* foreach possible satisfier, look for installed package */
9658 + for (j = 0; j < compound_depend->possibility_count; j++) {
9659 + /* foreach provided_by, which includes the abstract_pkg itself */
9660 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9661 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9662 + pkg_t *satisfying_pkg =
9663 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9664 + pkg_constraint_satisfied,
9665 + dependence_to_satisfy, 1);
9666 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9667 + if (satisfying_pkg != NULL) {
9668 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9669 + satisfying_pkg = NULL;
9673 + /* user request overrides package recommendation */
9674 + if (satisfying_pkg != NULL
9675 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9676 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9677 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9678 + pkg->name, satisfying_pkg->name);
9682 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9683 + if (satisfying_pkg != NULL) {
9684 + satisfier_entry_pkg = satisfying_pkg;
9690 + /* we didn't find one, add something to the unsatisfied vector */
9692 + if (!satisfier_entry_pkg) {
9693 + /* failure to meet recommendations is not an error */
9694 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9695 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9697 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9698 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9701 + if (compound_depend->type == SUGGEST) {
9702 + /* just mention it politely */
9703 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9704 + pkg->name, satisfier_entry_pkg->name);
9706 + char ** newstuff = NULL;
9708 + if (satisfier_entry_pkg != pkg &&
9709 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9710 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9711 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9712 + satisfier_entry_pkg,
9715 + the_lost = merge_unresolved(the_lost, newstuff);
9721 + *unresolved = the_lost;
9723 + return unsatisfied->len;
9726 +/*checking for conflicts !in replaces
9727 + If a packages conflicts with another but is also replacing it, I should not consider it a
9729 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9731 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9734 + int replaces_count = pkg->replaces_count;
9735 + abstract_pkg_t **replaces;
9737 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9740 + replaces = pkg->replaces;
9742 + for (i = 0; i < replaces_count; i++) {
9743 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9744 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9753 +/* Abhaya: added support for conflicts */
9754 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9756 + pkg_vec_t * installed_conflicts, * test_vec;
9757 + compound_depend_t * conflicts;
9758 + depend_t ** possible_satisfiers;
9759 + depend_t * possible_satisfier;
9760 + register int i, j, k;
9762 + abstract_pkg_t * ab_pkg;
9763 + pkg_t **pkg_scouts;
9767 + * this is a setup to check for redundant/cyclic dependency checks,
9768 + * which are marked at the abstract_pkg level
9770 + if(!(ab_pkg = pkg->parent)){
9771 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9772 + return (pkg_vec_t *)NULL;
9775 + conflicts = pkg->conflicts;
9777 + return (pkg_vec_t *)NULL;
9779 + installed_conflicts = pkg_vec_alloc();
9781 + count = pkg->conflicts_count;
9785 + /* foreach conflict */
9786 + for(i = 0; i < pkg->conflicts_count; i++){
9788 + possible_satisfiers = conflicts->possibilities;
9790 + /* foreach possible satisfier */
9791 + for(j = 0; j < conflicts->possibility_count; j++){
9792 + possible_satisfier = possible_satisfiers[j];
9793 + if (!possible_satisfier)
9794 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9795 + if (!possible_satisfier->pkg)
9796 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9797 + test_vec = possible_satisfier->pkg->pkgs;
9799 + /* pkg_vec found, it is an actual package conflict
9800 + * cruise this possiblity's pkg_vec looking for an installed version */
9801 + pkg_scouts = test_vec->pkgs;
9802 + for(k = 0; k < test_vec->len; k++){
9803 + pkg_scout = pkg_scouts[k];
9805 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9808 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9809 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9810 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9811 + pkg_vec_insert(installed_conflicts, pkg_scout);
9820 + if (installed_conflicts->len)
9821 + return installed_conflicts;
9822 + pkg_vec_free(installed_conflicts);
9823 + return (pkg_vec_t *)NULL;
9826 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9831 + if(depends->constraint == NONE)
9836 + parseVersion(temp, depends->version);
9838 + comparison = pkg_compare_versions(pkg, temp);
9842 + if((depends->constraint == EARLIER) &&
9845 + else if((depends->constraint == LATER) &&
9848 + else if(comparison == 0)
9850 + else if((depends->constraint == LATER_EQUAL) &&
9851 + (comparison >= 0))
9853 + else if((depends->constraint == EARLIER_EQUAL) &&
9854 + (comparison <= 0))
9860 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9862 + abstract_pkg_t *apkg = depend->pkg;
9863 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9864 + int n_providers = provider_apkgs->len;
9865 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9866 + pkg_vec_t *pkg_vec;
9871 + for (i = 0; i < n_providers; i++) {
9872 + abstract_pkg_t *papkg = apkgs[i];
9873 + pkg_vec = papkg->pkgs;
9875 + n_pkgs = pkg_vec->len;
9876 + for (j = 0; j < n_pkgs; j++) {
9877 + pkg_t *pkg = pkg_vec->pkgs[j];
9878 + if (version_constraints_satisfied(depend, pkg)) {
9887 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9889 + abstract_pkg_t *apkg = depend->pkg;
9890 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9891 + int n_providers = provider_apkgs->len;
9892 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9897 + for (i = 0; i < n_providers; i++) {
9898 + abstract_pkg_t *papkg = apkgs[i];
9899 + pkg_vec_t *pkg_vec = papkg->pkgs;
9901 + n_pkgs = pkg_vec->len;
9902 + for (j = 0; j < n_pkgs; j++) {
9903 + pkg_t *pkg = pkg_vec->pkgs[j];
9904 + if (version_constraints_satisfied(depend, pkg)) {
9905 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9914 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9917 + pkg_t ** pkgs = vec->pkgs;
9919 + for(i = 0; i < vec->len; i++)
9920 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9921 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9922 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9930 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9931 + * the same abstract package and 0 otherwise.
9933 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9935 + abstract_pkg_t **provides = pkg->provides;
9936 + int provides_count = pkg->provides_count;
9937 + abstract_pkg_t **replacee_provides = replacee->provides;
9938 + int replacee_provides_count = replacee->provides_count;
9940 + for (i = 0; i < provides_count; i++) {
9941 + abstract_pkg_t *apkg = provides[i];
9942 + for (j = 0; j < replacee_provides_count; j++) {
9943 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9944 + if (apkg == replacee_apkg)
9953 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9954 + * and 0 otherwise.
9956 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9958 + abstract_pkg_t **provides = pkg->provides;
9959 + int provides_count = pkg->provides_count;
9961 + for (i = 0; i < provides_count; i++) {
9962 + if (provides[i] == providee)
9969 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9972 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9974 + abstract_pkg_t **replaces = pkg->replaces;
9975 + int replaces_count = pkg->replaces_count;
9976 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9977 + int replacee_provides_count = pkg->provides_count; */
9979 + for (i = 0; i < replaces_count; i++) {
9980 + abstract_pkg_t *abstract_replacee = replaces[i];
9981 + for (j = 0; j < replaces_count; j++) {
9982 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9983 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9984 + if (replacee->provides[j] == abstract_replacee)
9993 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9996 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9998 + compound_depend_t *conflicts = pkg->conflicts;
9999 + int conflicts_count = pkg->conflicts_count;
10001 + for (i = 0; i < conflicts_count; i++) {
10002 + int possibility_count = conflicts[i].possibility_count;
10003 + struct depend **possibilities = conflicts[i].possibilities;
10004 + for (j = 0; j < possibility_count; j++) {
10005 + if (possibilities[j]->pkg == conflictee) {
10014 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10015 + * conflictee's provides and 0 otherwise.
10017 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10019 + compound_depend_t *conflicts = pkg->conflicts;
10020 + int conflicts_count = pkg->conflicts_count;
10021 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10022 + int conflictee_provides_count = conflictee->provides_count;
10024 + int possibility_count;
10025 + struct depend **possibilities;
10026 + abstract_pkg_t *possibility ;
10028 + for (i = 0; i < conflicts_count; i++) {
10029 + possibility_count = conflicts[i].possibility_count;
10030 + possibilities = conflicts[i].possibilities;
10031 + for (j = 0; j < possibility_count; j++) {
10032 + possibility = possibilities[j]->pkg;
10033 + for (k = 0; k < conflictee_provides_count; k++) {
10034 + if (possibility == conflictee_provides[k]) {
10043 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10045 + int oldlen = 0, newlen = 0;
10047 + register int i, j;
10052 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10053 + while(newstuff && newstuff[newlen]) newlen++;
10055 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10056 + if (result == NULL) {
10057 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10061 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10062 + *(result + i) = *(newstuff + j);
10064 + *(result + i) = NULL;
10070 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10071 + * this is null terminated, no count is carried around
10073 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10077 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10080 + while(the_lost && the_lost[count]) count++;
10082 + count++; /* need one to hold the null */
10083 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10084 + if (resized == NULL) {
10085 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10088 + resized[count - 1] = strdup(depend_str);
10089 + resized[count] = NULL;
10094 +void printDepends(pkg_t * pkg)
10096 + register int i, j;
10097 + compound_depend_t * depend;
10100 + count = pkg->pre_depends_count + pkg->depends_count;
10102 + depend = pkg->depends;
10104 + fprintf(stderr, "Depends pointer is NULL\n");
10107 + for(i = 0; i < count; i++){
10108 + fprintf(stderr, "%s has %d possibilities:\n",
10109 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10110 + depend->possibility_count);
10111 + for(j = 0; j < depend->possibility_count; j++)
10112 + fprintf(stderr, "\t%s version %s (%d)\n",
10113 + depend->possibilities[j]->pkg->name,
10114 + depend->possibilities[j]->version,
10115 + depend->possibilities[j]->constraint);
10120 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10122 + register int i, j;
10124 + /* every pkg provides itself */
10125 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10127 + if (!pkg->provides_count)
10130 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10131 + if (pkg->provides == NULL) {
10132 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10135 + pkg->provides[0] = ab_pkg;
10137 + // if (strcmp(ab_pkg->name, pkg->name))
10138 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10140 + for(i = 0; i < pkg->provides_count; i++){
10141 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10143 + pkg->provides[i+1] = provided_abpkg;
10146 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10151 +/* Abhaya: added conflicts support */
10152 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10155 + compound_depend_t * conflicts;
10157 + if (!pkg->conflicts_count)
10160 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10161 + pkg->conflicts_count);
10162 + if (conflicts == NULL) {
10163 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10166 + for (i = 0; i < pkg->conflicts_count; i++) {
10167 + conflicts->type = CONFLICTS;
10168 + parseDepends(conflicts, hash,
10169 + pkg->conflicts_str[i]);
10171 + for (j = 0; j < conflicts->possibility_count; j++) {
10172 + depend_t *possibility = conflicts->possibilities[j];
10173 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10174 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10182 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10184 + register int i, j;
10186 + if (!pkg->replaces_count)
10189 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10190 + if (pkg->replaces == NULL) {
10191 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10195 + // if (strcmp(ab_pkg->name, pkg->name))
10196 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10198 + for(i = 0; i < pkg->replaces_count; i++){
10199 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10201 + pkg->replaces[i] = old_abpkg;
10204 + if (!old_abpkg->replaced_by)
10205 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10206 + if ( old_abpkg->replaced_by == NULL ){
10209 + /* if a package pkg both replaces and conflicts old_abpkg,
10210 + * then add it to the replaced_by vector so that old_abpkg
10211 + * will be upgraded to ab_pkg automatically */
10212 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10213 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10218 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10222 + compound_depend_t * depends;
10224 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10227 + if (0 && pkg->pre_depends_count)
10228 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10229 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10230 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10231 + if (depends == NULL) {
10232 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10237 + for(i = 0; i < pkg->pre_depends_count; i++){
10238 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10239 + if (0 && pkg->pre_depends_count)
10240 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10241 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10242 + depends->type = PREDEPEND;
10246 + for(i = 0; i < pkg->recommends_count; i++){
10247 + parseDepends(depends, hash, pkg->recommends_str[i]);
10248 + if (0 && pkg->recommends_count)
10249 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10250 + pkg->recommends_str[i], depends, depends->possibility_count);
10251 + depends->type = RECOMMEND;
10255 + for(i = 0; i < pkg->suggests_count; i++){
10256 + parseDepends(depends, hash, pkg->suggests_str[i]);
10257 + if (0 && pkg->suggests_count)
10258 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10259 + pkg->suggests_str[i], depends, depends->possibility_count);
10260 + depends->type = SUGGEST;
10264 + for(i = 0; i < pkg->depends_count; i++){
10265 + parseDepends(depends, hash, pkg->depends_str[i]);
10266 + if (0 && pkg->depends_count)
10267 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10268 + pkg->depends_str[i], depends, depends->possibility_count);
10275 + * pkg_depend_string: returns the depends string specified by index.
10276 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10277 + * [0,npredepends) -> returns pre_depends_str[index]
10278 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10279 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10280 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10282 +char *pkg_depend_str(pkg_t *pkg, int index)
10284 + if (index < pkg->pre_depends_count) {
10285 + return pkg->pre_depends_str[index];
10287 + index -= pkg->pre_depends_count;
10289 + if (index < pkg->recommends_count) {
10290 + return pkg->recommends_str[index];
10292 + index -= pkg->recommends_count;
10294 + if (index < pkg->suggests_count) {
10295 + return pkg->suggests_str[index];
10297 + index -= pkg->suggests_count;
10299 + if (index < pkg->depends_count) {
10300 + return pkg->depends_str[index];
10302 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10306 +void freeDepends(pkg_t *pkg)
10310 + if (pkg == NULL || pkg->depends == NULL) {
10314 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10315 + for (i=0; i < pkg->depends->possibility_count; i++) {
10316 + depend_deinit(pkg->depends->possibilities[i]);
10318 + free(pkg->depends->possibilities);
10319 + free(pkg->depends);
10320 + pkg->depends = NULL;
10323 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10325 + compound_depend_t * depends;
10326 + int count, othercount;
10327 + register int i, j;
10328 + abstract_pkg_t * ab_depend;
10329 + abstract_pkg_t ** temp;
10331 + count = pkg->pre_depends_count + pkg->depends_count;
10332 + depends = pkg->depends;
10334 + if (0 && pkg->pre_depends_count)
10335 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10336 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10337 + for (i = 0; i < count; i++) {
10338 + if (0 && pkg->pre_depends_count)
10339 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10340 + for (j = 0; j < depends->possibility_count; j++){
10341 + ab_depend = depends->possibilities[j]->pkg;
10342 + if(!ab_depend->depended_upon_by)
10343 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10345 + temp = ab_depend->depended_upon_by;
10353 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10354 + (othercount + 1) * sizeof(abstract_pkg_t *));
10355 + /* the array may have moved */
10356 + temp = ab_depend->depended_upon_by + othercount;
10363 +static depend_t * depend_init(void)
10365 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10367 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10370 + d->constraint = NONE;
10371 + d->version = NULL;
10377 +static void depend_deinit(depend_t *d)
10382 +static int parseDepends(compound_depend_t *compound_depend,
10383 + hash_table_t * hash, char * depend_str)
10385 + char * pkg_name, buffer[2048];
10386 + int num_of_ors = 0;
10388 + register char * src, * dest;
10389 + depend_t ** possibilities;
10391 + /* first count the number of ored possibilities for satisfying dependency */
10392 + src = depend_str;
10394 + if(*src++ == '|')
10397 + compound_depend->type = DEPEND;
10399 + compound_depend->possibility_count = num_of_ors + 1;
10400 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10401 + if (!possibilities)
10403 + compound_depend->possibilities = possibilities;
10405 + src = depend_str;
10406 + for(i = 0; i < num_of_ors + 1; i++){
10407 + possibilities[i] = depend_init();
10408 + if (!possibilities[i])
10410 + /* gobble up just the name first */
10413 + !isspace(*src) &&
10417 + *dest++ = *src++;
10419 + pkg_name = trim_alloc(buffer);
10420 + if (pkg_name == NULL )
10423 + /* now look at possible version info */
10425 + /* skip to next chars */
10426 + if(isspace(*src))
10427 + while(*src && isspace(*src)) src++;
10429 + /* extract constraint and version */
10432 + if(!strncmp(src, "<<", 2)){
10433 + possibilities[i]->constraint = EARLIER;
10436 + else if(!strncmp(src, "<=", 2)){
10437 + possibilities[i]->constraint = EARLIER_EQUAL;
10440 + else if(!strncmp(src, ">=", 2)){
10441 + possibilities[i]->constraint = LATER_EQUAL;
10444 + else if(!strncmp(src, ">>", 2)){
10445 + possibilities[i]->constraint = LATER;
10448 + else if(!strncmp(src, "=", 1)){
10449 + possibilities[i]->constraint = EQUAL;
10452 + /* should these be here to support deprecated designations; dpkg does */
10453 + else if(!strncmp(src, "<", 1)){
10454 + possibilities[i]->constraint = EARLIER_EQUAL;
10457 + else if(!strncmp(src, ">", 1)){
10458 + possibilities[i]->constraint = LATER_EQUAL;
10462 + /* now we have any constraint, pass space to version string */
10463 + while(isspace(*src)) src++;
10465 + /* this would be the version string */
10467 + while(*src && *src != ')')
10468 + *dest++ = *src++;
10471 + possibilities[i]->version = trim_alloc(buffer);
10472 + /* fprintf(stderr, "let's print the depends version string:");
10473 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10474 + if (possibilities[i]->version == NULL )
10479 + /* hook up the dependency to its abstract pkg */
10480 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10484 + /* now get past the ) and any possible | chars */
10486 + (isspace(*src) ||
10492 + compound_depend->type = GREEDY_DEPEND;
10499 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_depends.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h
10500 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10501 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-07-22 16:31:25.000000000 +0200
10503 +/* pkg_depends.h - the itsy package management system
10507 + Copyright (C) 2002 Compaq Computer Corporation
10509 + This program is free software; you can redistribute it and/or
10510 + modify it under the terms of the GNU General Public License as
10511 + published by the Free Software Foundation; either version 2, or (at
10512 + your option) any later version.
10514 + This program is distributed in the hope that it will be useful, but
10515 + WITHOUT ANY WARRANTY; without even the implied warranty of
10516 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10517 + General Public License for more details.
10520 +#ifndef PKG_DEPENDS_H
10521 +#define PKG_DEPENDS_H
10524 +#include "pkg_hash.h"
10526 +enum depend_type {
10534 +typedef enum depend_type depend_type_t;
10536 +enum version_constraint {
10544 +typedef enum version_constraint version_constraint_t;
10547 + version_constraint_t constraint;
10549 + abstract_pkg_t * pkg;
10551 +typedef struct depend depend_t;
10553 +struct compound_depend{
10554 + depend_type_t type;
10555 + int possibility_count;
10556 + struct depend ** possibilities;
10558 +typedef struct compound_depend compound_depend_t;
10560 +#include "hash_table.h"
10562 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10563 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10564 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10565 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10568 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10569 + * the same abstract package and 0 otherwise.
10571 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10574 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10577 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10580 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10583 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10586 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10589 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10592 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10595 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10597 +char *pkg_depend_str(pkg_t *pkg, int index);
10598 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10599 +void freeDepends(pkg_t *pkg);
10600 +void printDepends(pkg_t * pkg);
10601 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10602 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10603 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10604 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10605 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10608 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c
10609 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10610 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-07-22 16:31:25.000000000 +0200
10612 +/* pkg_dest.c - the itsy package management system
10616 + Copyright (C) 2001 University of Southern California
10618 + This program is free software; you can redistribute it and/or
10619 + modify it under the terms of the GNU General Public License as
10620 + published by the Free Software Foundation; either version 2, or (at
10621 + your option) any later version.
10623 + This program is distributed in the hope that it will be useful, but
10624 + WITHOUT ANY WARRANTY; without even the implied warranty of
10625 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10626 + General Public License for more details.
10631 +#include "pkg_dest.h"
10632 +#include "file_util.h"
10633 +#include "str_util.h"
10634 +#include "sprintf_alloc.h"
10636 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10638 + dest->name = strdup(name);
10640 + /* Guarantee that dest->root_dir ends with a '/' */
10641 + if (str_ends_with(root_dir, "/")) {
10642 + dest->root_dir = strdup(root_dir);
10644 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10646 + file_mkdir_hier(dest->root_dir, 0755);
10648 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10649 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10650 + file_mkdir_hier(dest->ipkg_dir, 0755);
10652 + if (str_starts_with (lists_dir, "/"))
10653 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10655 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10657 + file_mkdir_hier(dest->lists_dir, 0755);
10659 + sprintf_alloc(&dest->info_dir, "%s/%s",
10660 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10661 + file_mkdir_hier(dest->info_dir, 0755);
10663 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10664 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10666 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10667 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10669 + dest->status_file = NULL;
10674 +void pkg_dest_deinit(pkg_dest_t *dest)
10676 + free(dest->name);
10677 + dest->name = NULL;
10679 + free(dest->root_dir);
10680 + dest->root_dir = NULL;
10682 + free(dest->ipkg_dir);
10683 + dest->ipkg_dir = NULL;
10685 + free(dest->lists_dir);
10686 + dest->lists_dir = NULL;
10688 + free(dest->info_dir);
10689 + dest->info_dir = NULL;
10691 + free(dest->status_file_name);
10692 + dest->status_file_name = NULL;
10694 + free(dest->status_file_tmp_name);
10695 + dest->status_file_tmp_name = NULL;
10697 + if (dest->status_file) {
10698 + fclose(dest->status_file);
10700 + dest->status_file = NULL;
10702 + dest->root_dir = NULL;
10704 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h
10705 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10706 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-07-22 16:31:25.000000000 +0200
10708 +/* pkg_dest.h - the itsy package management system
10712 + Copyright (C) 2001 University of Southern California
10714 + This program is free software; you can redistribute it and/or
10715 + modify it under the terms of the GNU General Public License as
10716 + published by the Free Software Foundation; either version 2, or (at
10717 + your option) any later version.
10719 + This program is distributed in the hope that it will be useful, but
10720 + WITHOUT ANY WARRANTY; without even the implied warranty of
10721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10722 + General Public License for more details.
10725 +#ifndef PKG_DEST_H
10726 +#define PKG_DEST_H
10728 +typedef struct pkg_dest pkg_dest_t;
10736 + char *status_file_name;
10737 + char *status_file_tmp_name;
10738 + FILE *status_file;
10741 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10742 +void pkg_dest_deinit(pkg_dest_t *dest);
10746 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c
10747 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10748 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-07-22 16:31:25.000000000 +0200
10750 +/* pkg_dest_list.c - the itsy package management system
10754 + Copyright (C) 2001 University of Southern California
10756 + This program is free software; you can redistribute it and/or
10757 + modify it under the terms of the GNU General Public License as
10758 + published by the Free Software Foundation; either version 2, or (at
10759 + your option) any later version.
10761 + This program is distributed in the hope that it will be useful, but
10762 + WITHOUT ANY WARRANTY; without even the implied warranty of
10763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10764 + General Public License for more details.
10769 +#include "pkg_dest.h"
10770 +#include "void_list.h"
10771 +#include "pkg_dest_list.h"
10773 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10775 + return void_list_elt_init((void_list_elt_t *) elt, data);
10778 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10780 + void_list_elt_deinit((void_list_elt_t *) elt);
10783 +int pkg_dest_list_init(pkg_dest_list_t *list)
10785 + return void_list_init((void_list_t *) list);
10788 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10790 + pkg_dest_list_elt_t *iter;
10791 + pkg_dest_t *pkg_dest;
10793 + for (iter = list->head; iter; iter = iter->next) {
10794 + pkg_dest = iter->data;
10795 + pkg_dest_deinit(pkg_dest);
10797 + /* malloced in pkg_dest_list_append */
10799 + iter->data = NULL;
10801 + void_list_deinit((void_list_t *) list);
10804 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10805 + const char *root_dir,const char *lists_dir)
10808 + pkg_dest_t *pkg_dest;
10810 + /* freed in plg_dest_list_deinit */
10811 + pkg_dest = malloc(sizeof(pkg_dest_t));
10812 + if (pkg_dest == NULL) {
10813 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10817 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10818 + err = void_list_append((void_list_t *) list, pkg_dest);
10826 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10828 + return void_list_push((void_list_t *) list, data);
10831 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10833 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10835 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h
10836 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10837 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-07-22 16:31:25.000000000 +0200
10839 +/* pkg_dest_list.h - the itsy package management system
10843 + Copyright (C) 2001 University of Southern California
10845 + This program is free software; you can redistribute it and/or
10846 + modify it under the terms of the GNU General Public License as
10847 + published by the Free Software Foundation; either version 2, or (at
10848 + your option) any later version.
10850 + This program is distributed in the hope that it will be useful, but
10851 + WITHOUT ANY WARRANTY; without even the implied warranty of
10852 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10853 + General Public License for more details.
10856 +#ifndef PKG_DEST_LIST_H
10857 +#define PKG_DEST_LIST_H
10859 +#include "pkg_dest.h"
10861 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10862 +struct pkg_dest_list_elt
10864 + pkg_dest_list_elt_t *next;
10865 + pkg_dest_t *data;
10868 +typedef struct pkg_dest_list pkg_dest_list_t;
10869 +struct pkg_dest_list
10871 + pkg_dest_list_elt_t pre_head;
10872 + pkg_dest_list_elt_t *head;
10873 + pkg_dest_list_elt_t *tail;
10876 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10877 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10879 +int pkg_dest_list_init(pkg_dest_list_t *list);
10880 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10882 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10883 + const char *root_dir,const char* lists_dir);
10884 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10885 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10889 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_extract.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c
10890 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10891 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-07-30 22:47:49.000000000 +0200
10893 +/* pkg_extract.c - the itsy package management system
10897 + Copyright (C) 2001 University of Southern California
10899 + This program is free software; you can redistribute it and/or
10900 + modify it under the terms of the GNU General Public License as
10901 + published by the Free Software Foundation; either version 2, or (at
10902 + your option) any later version.
10904 + This program is distributed in the hope that it will be useful, but
10905 + WITHOUT ANY WARRANTY; without even the implied warranty of
10906 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10907 + General Public License for more details.
10911 +#include <errno.h>
10912 +#include <fcntl.h>
10913 +#include <stdio.h>
10915 +#include "pkg_extract.h"
10917 +#include "libbb.h"
10918 +#include "file_util.h"
10919 +#include "sprintf_alloc.h"
10920 +#include "unarchive.h"
10922 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10923 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10924 +#define IPKG_CONTROL_FILE "control"
10926 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10928 + archive_handle_t *archive;
10931 + sprintf_alloc(&path, "%s/", dir);
10932 + archive = init_handle();
10933 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10934 + archive->filter = filter_accept_list;
10935 + llist_add_to(&(archive->accept), (char *)filename);
10936 + archive->buffer = path;
10937 + archive->action_data = data_extract_all_prefix;
10938 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10939 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10940 + close(archive->src_fd);
10941 + free(archive->accept);
10946 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10948 + unsigned int size = strlen(archive->file_header->name) + 2;
10950 + if (archive->buffer == NULL) {
10951 + archive->buffer = xmalloc(size);
10952 + strcpy(archive->buffer, archive->file_header->name);
10954 + size += strlen(archive->buffer);
10955 + archive->buffer = xrealloc(archive->buffer, size);
10956 + strcat(archive->buffer, archive->file_header->name);
10958 + strcat(archive->buffer, "\n");
10959 + data_skip(archive);
10962 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10964 + archive_handle_t *archive;
10967 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10968 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10969 + archive = init_handle();
10970 + archive->src_fd = bb_xopen(name, O_RDONLY);
10971 + archive->filter = filter_accept_list;
10972 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10973 + archive->action_data = data_extract_to_buffer;
10974 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10975 + close(archive->src_fd);
10976 + fputs(archive->buffer, stream);
10977 + free(archive->buffer);
10978 + free(archive->accept);
10985 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10987 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10990 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10992 + archive_handle_t *archive;
10996 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10997 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10998 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10999 + archive = init_handle();
11000 + archive->src_fd = bb_xopen(name, O_RDONLY);
11001 + archive->filter = filter_accept_all;
11002 + archive->buffer = path;
11003 + archive->action_data = data_extract_all_prefix;
11004 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11005 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11006 + close(archive->src_fd);
11014 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11016 + archive_handle_t *archive;
11020 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11021 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11022 + sprintf_alloc(&path, "%s/", dir);
11023 + archive = init_handle();
11024 + archive->src_fd = bb_xopen(name, O_RDONLY);
11025 + archive->filter = filter_accept_all;
11026 + archive->buffer = path;
11027 + archive->action_data = data_extract_all_prefix;
11028 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11029 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11030 + close(archive->src_fd);
11038 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11041 + char *line, *data_file;
11045 + file = fopen(file_name, "w");
11046 + if (file == NULL) {
11047 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11048 + __FUNCTION__, file_name);
11053 + if (pkg->installed_files) {
11054 + str_list_elt_t *elt;
11055 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11056 + fprintf(file, "%s\n", elt->data);
11059 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11066 + /* Fixup data file names by removing the initial '.' */
11069 + line = file_read_line_alloc(tmp);
11070 + if (line == NULL) {
11074 + data_file = line;
11075 + if (*data_file == '.') {
11079 + if (*data_file != '/') {
11080 + fputs("/", file);
11083 + /* I have no idea why, but this is what dpkg does */
11084 + if (strcmp(data_file, "/\n") == 0) {
11085 + fputs("/.\n", file);
11087 + fputs(data_file, file);
11097 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11099 + archive_handle_t *archive;
11102 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11103 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11104 + archive = init_handle();
11105 + archive->src_fd = bb_xopen(name, O_RDONLY);
11106 + archive->filter = filter_accept_all;
11107 + archive->action_data = data_extract_file_name_to_buffer;
11108 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11109 + close(archive->src_fd);
11110 + fputs(archive->buffer, file);
11111 + free(archive->buffer);
11117 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_extract.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h
11118 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11119 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-07-22 16:31:25.000000000 +0200
11121 +/* pkg_extract.c - the itsy package management system
11125 + Copyright (C) 2001 University of Southern California
11127 + This program is free software; you can redistribute it and/or
11128 + modify it under the terms of the GNU General Public License as
11129 + published by the Free Software Foundation; either version 2, or (at
11130 + your option) any later version.
11132 + This program is distributed in the hope that it will be useful, but
11133 + WITHOUT ANY WARRANTY; without even the implied warranty of
11134 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11135 + General Public License for more details.
11138 +#ifndef PKG_EXTRACT_H
11139 +#define PKG_EXTRACT_H
11143 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11144 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11145 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11147 + const char *prefix);
11148 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11149 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11150 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11153 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h
11154 --- busybox-1.2.0-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
11155 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h 2006-07-22 16:31:25.000000000 +0200
11157 +/* pkg.h - the itsy package management system
11161 + Copyright (C) 2001 University of Southern California
11163 + This program is free software; you can redistribute it and/or
11164 + modify it under the terms of the GNU General Public License as
11165 + published by the Free Software Foundation; either version 2, or (at
11166 + your option) any later version.
11168 + This program is distributed in the hope that it will be useful, but
11169 + WITHOUT ANY WARRANTY; without even the implied warranty of
11170 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11171 + General Public License for more details.
11177 +#include <sys/types.h>
11178 +#include <sys/stat.h>
11179 +#include <unistd.h>
11181 +#include "pkg_vec.h"
11182 +#include "str_list.h"
11183 +#include "pkg_src.h"
11184 +#include "pkg_dest.h"
11185 +#include "ipkg_conf.h"
11186 +#include "conffile_list.h"
11191 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11193 +/* I think "Size" is currently the shortest field name */
11194 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11196 +enum pkg_state_want
11202 + SW_LAST_STATE_WANT
11204 +typedef enum pkg_state_want pkg_state_want_t;
11206 +enum pkg_state_flag
11209 + SF_REINSTREQ = 1,
11210 + SF_HOLD = 2, /* do not upgrade version */
11211 + SF_REPLACE = 4, /* replace this package */
11212 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11213 + SF_PREFER = 16, /* prefer this version */
11214 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11215 + SF_MARKED = 64, /* temporary mark */
11216 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11218 + SF_LAST_STATE_FLAG
11220 +typedef enum pkg_state_flag pkg_state_flag_t;
11221 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11223 +enum pkg_state_status
11225 + SS_NOT_INSTALLED = 1,
11227 + SS_HALF_CONFIGURED,
11229 + SS_HALF_INSTALLED,
11231 + SS_POST_INST_FAILED,
11232 + SS_REMOVAL_FAILED,
11233 + SS_LAST_STATE_STATUS
11235 +typedef enum pkg_state_status pkg_state_status_t;
11237 +struct abstract_pkg{
11239 + int dependencies_checked;
11240 + pkg_vec_t * pkgs;
11241 + pkg_state_status_t state_status;
11242 + pkg_state_flag_t state_flag;
11243 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11244 + abstract_pkg_vec_t * provided_by;
11245 + abstract_pkg_vec_t * replaced_by;
11248 +#include "pkg_depends.h"
11250 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11252 + The 3 version fields should go into a single version struct. (This
11253 + is especially important since, currently, pkg->version can easily
11254 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11255 + distinct. This has been the source of multiple bugs.
11257 + The 3 state fields could possibly also go into their own struct.
11259 + All fields which deal with lists of packages, (Depends,
11260 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11261 + be handled by a single struct in pkg_t
11263 + All string fields for which there is a small set of possible
11264 + values, (section, maintainer, architecture, maybe version?), that
11265 + are reused among different packages -- for all such packages we
11266 + should move from "char *"s to some atom datatype to share data
11267 + storage and use less memory. We might even do reference counting,
11268 + but probably not since most often we only create new pkg_t structs,
11269 + we don't often free them. */
11273 + unsigned long epoch;
11276 + char *familiar_revision;
11278 + pkg_dest_t *dest;
11279 + char *architecture;
11281 + char *maintainer;
11282 + char *description;
11283 + pkg_state_want_t state_want;
11284 + pkg_state_flag_t state_flag;
11285 + pkg_state_status_t state_status;
11286 + char **depends_str;
11287 + int depends_count;
11288 + char **pre_depends_str;
11289 + int pre_depends_count;
11290 + char **recommends_str;
11291 + int recommends_count;
11292 + char **suggests_str;
11293 + int suggests_count;
11294 + compound_depend_t * depends;
11296 + /* Abhaya: new conflicts */
11297 + char **conflicts_str;
11298 + compound_depend_t * conflicts;
11299 + int conflicts_count;
11301 + char **replaces_str;
11302 + int replaces_count;
11303 + abstract_pkg_t ** replaces;
11305 + char **provides_str;
11306 + int provides_count;
11307 + abstract_pkg_t ** provides;
11309 + abstract_pkg_t *parent;
11311 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11314 + char *local_filename;
11316 + char *tmp_unpack_dir;
11319 + char *installed_size;
11322 + conffile_list_t conffiles;
11323 + time_t installed_time;
11324 + /* As pointer for lazy evaluation */
11325 + str_list_t *installed_files;
11326 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11327 + mechanism to avoid the problem here, (which is that the
11328 + installed_files list was being freed from an inner loop while
11329 + still being used within an outer loop. */
11330 + int installed_files_ref_cnt;
11332 + int arch_priority;
11333 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11334 + int provided_by_hand;
11337 +pkg_t *pkg_new(void);
11338 +int pkg_init(pkg_t *pkg);
11339 +void pkg_deinit(pkg_t *pkg);
11340 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11341 +abstract_pkg_t *abstract_pkg_new(void);
11342 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11345 + * merges fields from newpkg into oldpkg.
11346 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11348 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11350 +char *pkg_version_str_alloc(pkg_t *pkg);
11352 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11353 +int pkg_name_version_and_architecture_compare(void *a, void *b);
11354 +int abstract_pkg_name_compare(void *a, void *b);
11356 +char * pkg_formatted_info(pkg_t *pkg );
11357 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11359 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11361 +void pkg_print_info(pkg_t *pkg, FILE *file);
11362 +void pkg_print_status(pkg_t * pkg, FILE * file);
11363 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11364 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11365 +int pkg_free_installed_files(pkg_t *pkg);
11366 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11367 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11368 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11369 + const char *script, const char *args);
11371 +/* enum mappings */
11372 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11373 +pkg_state_want_t pkg_state_want_from_str(char *str);
11374 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11375 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11376 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11377 +pkg_state_status_t pkg_state_status_from_str(char *str);
11379 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11381 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11382 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11383 +int pkg_free_installed_files(pkg_t *pkg);
11385 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11386 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11389 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_hash.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c
11390 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11391 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-07-22 16:31:25.000000000 +0200
11393 +/* ipkg_hash.c - the itsy package management system
11397 + Copyright (C) 2002 Compaq Computer Corporation
11399 + This program is free software; you can redistribute it and/or
11400 + modify it under the terms of the GNU General Public License as
11401 + published by the Free Software Foundation; either version 2, or (at
11402 + your option) any later version.
11404 + This program is distributed in the hope that it will be useful, but
11405 + WITHOUT ANY WARRANTY; without even the implied warranty of
11406 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11407 + General Public License for more details.
11411 +#include <errno.h>
11412 +#include <ctype.h>
11413 +#include <stdlib.h>
11414 +#include <string.h>
11416 +#include "hash_table.h"
11418 +#include "ipkg_message.h"
11419 +#include "pkg_vec.h"
11420 +#include "pkg_hash.h"
11421 +#include "pkg_parse.h"
11422 +#include "ipkg_utils.h"
11424 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11427 + * this will talk to both feeds-lists files and installed status files
11430 + * hash_table_t hash;
11431 + * pkg_hash_init(name, &hash, 1000);
11432 + * pkg_hash_add_from_file(<feed filename>);
11434 + * the query function is just there as a shell to prove to me that this
11435 + * sort of works, but isn't far from doing something useful
11438 + * modified: CDW 3 Jan. 2002
11443 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11445 + return hash_table_init(name, hash, len);
11448 +void pkg_hash_deinit(hash_table_t *hash)
11450 + hash_table_deinit(hash);
11454 +/* Find the default arch for a given package status file if none is given. */
11455 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11457 + nv_pair_list_elt_t *l;
11458 + char *def_arch = HOST_CPU_STR; /* Default arch */
11459 + int def_prio = 0; /* Other archs override this */
11461 + l = conf->arch_list.head;
11464 + nv_pair_t *nv = l->data;
11465 + int priority = strtol(nv->value, NULL, 0);
11467 + /* Check if this arch has higher priority, and is valid */
11468 + if ((priority > def_prio) &&
11469 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11470 + /* Our new default */
11471 + def_prio = priority;
11472 + def_arch = nv->name;
11477 + return strdup(def_arch);
11480 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11481 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11483 + hash_table_t *hash = &conf->pkg_hash;
11485 + char **raw_start;
11488 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11492 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11497 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11498 + if (!pkg->architecture) {
11499 + char *version_str = pkg_version_str_alloc(pkg);
11500 + pkg->architecture = pkg_get_default_arch(conf);
11501 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11502 + pkg->name, version_str, pkg->architecture);
11503 + free(version_str);
11505 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11511 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11512 + memory after read_raw_pkgs_from_file */
11521 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11523 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11526 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11528 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11531 + return apkg->provided_by;
11535 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11536 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11539 + int nprovides = 0;
11540 + int nmatching = 0;
11541 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11542 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11543 + abstract_pkg_vec_t *provided_apkg_vec;
11544 + abstract_pkg_t **provided_apkgs;
11545 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11546 + pkg_t *latest_installed_parent = NULL;
11547 + pkg_t *latest_matching = NULL;
11548 + pkg_t *held_pkg = NULL;
11549 + pkg_t *good_pkg_by_name = NULL;
11551 + if (matching_apkgs == NULL || providers == NULL ||
11552 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11555 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11557 + provided_apkg_vec = apkg->provided_by;
11558 + nprovides = provided_apkg_vec->len;
11559 + provided_apkgs = provided_apkg_vec->pkgs;
11560 + if (nprovides > 1)
11561 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11563 + /* accumulate all the providers */
11564 + for (i = 0; i < nprovides; i++) {
11565 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11566 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11567 + abstract_pkg_vec_insert(providers, provider_apkg);
11569 + nprovides = providers->len;
11571 + for (i = 0; i < nprovides; i++) {
11572 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11573 + abstract_pkg_t *replacement_apkg = NULL;
11576 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11577 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11578 + if (provider_apkg->replaced_by->len > 1) {
11579 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11580 + provider_apkg->name, replacement_apkg->name);
11584 + if (replacement_apkg)
11585 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11586 + replacement_apkg->name, provider_apkg->name);
11588 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11589 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11592 + provider_apkg = replacement_apkg;
11595 + if (!(vec = provider_apkg->pkgs)) {
11596 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11601 + /* now check for supported architecture */
11603 + int max_count = 0;
11606 + /* count packages matching max arch priority and keep track of last one */
11607 + for (i = 0; i < vec->len; i++) {
11608 + pkg_t *maybe = vec->pkgs[i];
11609 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11610 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11611 + if (maybe->arch_priority > 0) {
11613 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11614 + pkg_vec_insert(matching_pkgs, maybe);
11620 + if (matching_pkgs->len > 1)
11621 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11622 + if (matching_apkgs->len > 1)
11623 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11625 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11626 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11627 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11628 + Until now I always got the latest, but that breaks the downgrade option.
11629 + If I stop at the first one, I would probably miss the new ones
11630 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11631 + or from a Packages feed.
11632 + 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*/
11635 + for (i = 0; i < matching_pkgs->len; i++) {
11636 + pkg_t *matching = matching_pkgs->pkgs[i];
11637 + if (constraint_fcn(matching, cdata)) { /* We found it */
11638 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11639 + good_pkg_by_name = matching;
11640 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11646 + for (i = 0; i < matching_pkgs->len; i++) {
11647 + pkg_t *matching = matching_pkgs->pkgs[i];
11648 + latest_matching = matching;
11649 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11650 + latest_installed_parent = matching;
11651 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11653 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11654 + held_pkg->name, matching->name);
11655 + held_pkg = matching;
11659 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11660 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11661 + apkg->name, matching_apkgs->len);
11662 + for (i = 0; i < matching_apkgs->len; i++) {
11663 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11664 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11666 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11669 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11670 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11671 + __FUNCTION__, apkg->name, matching_pkgs->len);
11672 + for (i = 0; i < matching_pkgs->len; i++) {
11673 + pkg_t *matching = matching_pkgs->pkgs[i];
11674 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11675 + matching->name, matching->version, matching->architecture);
11679 + nmatching = matching_apkgs->len;
11681 + pkg_vec_free(matching_pkgs);
11682 + abstract_pkg_vec_free(matching_apkgs);
11683 + abstract_pkg_vec_free(providers);
11685 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11686 + return good_pkg_by_name;
11689 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11692 + if (latest_installed_parent) {
11693 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11694 + return latest_installed_parent;
11696 + if (nmatching > 1) {
11697 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11700 + if (latest_matching) {
11701 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11702 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11703 + return latest_matching;
11708 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11710 + const char *name = (const char *)cdata;
11711 + if (strcmp(pkg->name, name) == 0)
11717 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11719 + hash_table_t *hash = &conf->pkg_hash;
11720 + abstract_pkg_t *apkg = NULL;
11722 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11725 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11729 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11730 + const char *pkg_name,
11731 + const char * version)
11735 + char *version_str = NULL;
11737 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11740 + for(i = 0; i < vec->len; i++) {
11741 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11742 + if(!strcmp(version_str, version)) {
11743 + free(version_str);
11746 + free(version_str);
11749 + if(i == vec->len)
11752 + return vec->pkgs[i];
11755 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11756 + const char *pkg_name,
11757 + pkg_dest_t *dest)
11762 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11766 + for(i = 0; i < vec->len; i++)
11767 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11768 + return vec->pkgs[i];
11773 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11774 + const char *pkg_name)
11779 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11783 + for(i = 0; i < vec->len; i++)
11784 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11785 + return vec->pkgs[i];
11791 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11793 + abstract_pkg_t * ab_pkg;
11795 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11799 + if (ab_pkg->pkgs) {
11800 + return ab_pkg->pkgs;
11801 + } else if (ab_pkg->provided_by) {
11802 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11803 + if (abpkg != NULL){
11804 + return abpkg->pkgs;
11806 + return ab_pkg->pkgs;
11813 +static int pkg_compare_names(const void *p1, const void *p2)
11815 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11816 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11817 + if (pkg1->name == NULL)
11819 + if (pkg2->name == NULL)
11821 + return(strcmp(pkg1->name, pkg2->name));
11825 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11828 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11829 + pkg_vec_t *all = (pkg_vec_t *)data;
11830 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11832 + for (j = 0; j < pkg_vec->len; j++) {
11833 + pkg_t *pkg = pkg_vec->pkgs[j];
11834 + pkg_vec_insert(all, pkg);
11839 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11841 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11842 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11845 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11847 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11848 + pkg_vec_t *all = (pkg_vec_t *)data;
11849 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11852 + for (j = 0; j < pkg_vec->len; j++) {
11853 + pkg_t *pkg = pkg_vec->pkgs[j];
11854 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11855 + pkg_vec_insert(all, pkg);
11860 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11862 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11863 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11866 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11870 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11871 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11872 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11873 + fprintf(stdout, "%s\n", ab_pkg->name);
11875 + if (dependents != NULL)
11876 + while (dependents [i] != NULL)
11877 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11878 + dependents = ab_pkg->provided_by->pkgs;
11880 + if (dependents != NULL)
11881 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11882 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11883 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11886 + while (i < pkg->depends_count)
11887 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11890 +void pkg_hash_dump(hash_table_t *hash, void *data)
11893 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11894 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11895 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11898 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11900 + abstract_pkg_t * ab_pkg;
11902 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11903 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11908 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11910 + abstract_pkg_t * ab_pkg;
11911 + int arch_priority;
11916 + arch_priority = pkg->arch_priority;
11918 + if (buildDepends(hash, pkg)<0){
11919 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11922 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11924 + if (set_status) {
11925 + if (pkg->state_status == SS_INSTALLED) {
11926 + ab_pkg->state_status = SS_INSTALLED;
11927 + } else if (pkg->state_status == SS_UNPACKED) {
11928 + ab_pkg->state_status = SS_UNPACKED;
11932 + if(!ab_pkg->pkgs)
11933 + ab_pkg->pkgs = pkg_vec_alloc();
11935 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11936 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11937 + pkg->parent = ab_pkg;
11939 + if (buildProvides(hash, ab_pkg, pkg)<0){
11940 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11943 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11944 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11945 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11948 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11949 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11953 + buildDependedUponBy(pkg, ab_pkg);
11958 + * this will assume that we've already determined that
11959 + * the abstract pkg doesn't exist, 'cause we should know these things...
11961 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11963 + abstract_pkg_t * ab_pkg;
11965 + ab_pkg = abstract_pkg_new();
11966 + if (ab_pkg == NULL) { return NULL; }
11968 + ab_pkg->name = strdup(pkg_name);
11969 + hash_table_insert(hash, pkg_name, ab_pkg);
11975 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11977 + hash_table_t *file_hash = &conf->file_hash;
11979 + return hash_table_get(file_hash, file_name);
11982 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11984 + hash_table_t *file_hash = &conf->file_hash;
11985 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11986 + int file_name_len = strlen(file_name);
11988 + if (file_name[file_name_len -1] == '/')
11991 + if (conf->offline_root) {
11992 + int len = strlen(conf->offline_root);
11993 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11994 + file_name += len;
11998 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11999 + hash_table_insert(file_hash, file_name, owning_pkg);
12000 + if (old_owning_pkg) {
12001 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12002 + /* mark this package to have its filelist written */
12003 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12004 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12010 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_hash.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h
12011 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12012 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-07-22 16:31:25.000000000 +0200
12014 +/* pkg_hash.h - the itsy package management system
12018 + Copyright (C) 2002 Compaq Computer Corporation
12020 + This program is free software; you can redistribute it and/or
12021 + modify it under the terms of the GNU General Public License as
12022 + published by the Free Software Foundation; either version 2, or (at
12023 + your option) any later version.
12025 + This program is distributed in the hope that it will be useful, but
12026 + WITHOUT ANY WARRANTY; without even the implied warranty of
12027 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12028 + General Public License for more details.
12031 +#ifndef PKG_HASH_H
12032 +#define PKG_HASH_H
12035 +#include "pkg_vec.h"
12036 +#include "hash_table.h"
12039 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12040 +void pkg_hash_deinit(hash_table_t *hash);
12041 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12043 +void pkg_hash_dump(hash_table_t *hash, void *data);
12044 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12046 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12047 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12048 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12050 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12051 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12052 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12053 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12054 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12055 + const char *pkg_name,
12056 + const char * version);
12057 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12058 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12059 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12060 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12061 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12062 + const char *pkg_name);
12063 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12064 + const char *pkg_name,
12065 + pkg_dest_t *dest);
12067 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12068 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12070 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12071 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12075 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_parse.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c
12076 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12077 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-07-22 16:31:25.000000000 +0200
12079 +/* pkg_parse.c - the itsy package management system
12083 + Copyright (C) 2002 Compaq Computer Corporation
12085 + This program is free software; you can redistribute it and/or
12086 + modify it under the terms of the GNU General Public License as
12087 + published by the Free Software Foundation; either version 2, or (at
12088 + your option) any later version.
12090 + This program is distributed in the hope that it will be useful, but
12091 + WITHOUT ANY WARRANTY; without even the implied warranty of
12092 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12093 + General Public License for more details.
12097 +#include <errno.h>
12098 +#include <ctype.h>
12101 +#include "ipkg_utils.h"
12102 +#include "pkg_parse.h"
12104 +int isGenericFieldType(char * type, char * line)
12106 + if(!strncmp(line, type, strlen(type)))
12111 +char * parseGenericFieldType(char * type, char * raw)
12113 + char * field_value = raw + (strlen(type) + 1);
12114 + return trim_alloc(field_value);
12117 +void parseStatus(pkg_t *pkg, char * raw)
12119 + char sw_str[64], sf_str[64], ss_str[64];
12121 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12122 + pkg->state_want = pkg_state_want_from_str(sw_str);
12123 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12124 + pkg->state_status = pkg_state_status_from_str(ss_str);
12127 +char ** parseDependsString(char * raw, int * depends_count)
12129 + char ** depends = NULL;
12130 + int line_count = 0;
12131 + char buff[2048], * dest;
12133 + while(raw && *raw && !isspace(*raw)) {
12137 + if(line_is_blank(raw)){
12138 + *depends_count = line_count;
12141 + while(raw && *raw){
12142 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12144 + while(isspace(*raw)) raw++;
12147 + while((*raw != ',') && *raw)
12148 + *dest++ = *raw++;
12151 + depends[line_count] = trim_alloc(buff);
12152 + if(depends[line_count] ==NULL)
12158 + *depends_count = line_count;
12162 +void parseConffiles(pkg_t * pkg, char * raw)
12164 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12166 + if(!strncmp(raw, "Conffiles:", 10))
12167 + raw += strlen("Conffiles:");
12169 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12170 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12171 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12172 + while (*raw && isspace(*raw)) {
12175 + raw += strlen(file_name);
12176 + while (*raw && isspace(*raw)) {
12179 + raw += strlen(md5sum);
12183 +int parseVersion(pkg_t *pkg, char *raw)
12185 + char *colon, *eepochcolon;
12186 +#ifdef USE_DEBVERSION
12189 + unsigned long epoch;
12192 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12196 + if (strncmp(raw, "Version:", 8) == 0) {
12199 + while (*raw && isspace(*raw)) {
12203 + colon= strchr(raw,':');
12205 + epoch= strtoul(raw,&eepochcolon,10);
12206 + if (colon != eepochcolon) {
12207 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12211 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12215 + pkg->epoch= epoch;
12220 + pkg->revision = "";
12221 + pkg->familiar_revision = "";
12223 + pkg->version= malloc(strlen(raw)+1);
12224 + if ( pkg->version == NULL ) {
12225 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12228 + strcpy(pkg->version, raw);
12230 +#ifdef USE_DEBVERSION
12231 + hyphen= strrchr(pkg->version,'-');
12235 + if (strncmp("fam", hyphen, 3) == 0) {
12236 + pkg->familiar_revision=hyphen+3;
12237 + hyphen= strrchr(pkg->version,'-');
12240 + pkg->revision = hyphen;
12243 + pkg->revision = hyphen;
12249 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12253 + pkg->familiar_revision);
12260 +/* This code is needed to insert in first position the keyword for the aligning bug */
12262 +int alterProvidesLine(char *raw, char *temp)
12267 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12271 + if ( temp == NULL ) {
12272 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12276 + if (strncmp(raw, "Provides:", 9) == 0) {
12279 + while (*raw && isspace(*raw)) {
12283 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12285 + strncat( temp, raw++, 1);
12291 +/* Some random thoughts from Carl:
12293 + This function could be considerably simplified if we just kept
12294 + an array of all the generic string-valued field names, and looped
12295 + through those looking for a match. Also, these fields could perhaps
12296 + be stored in the package as an array as well, (or, probably better,
12297 + as an nv_pair_list_t).
12299 + Fields which require special parsing or storage, (such as Depends:
12300 + and Status:) could be handled as they are now.
12302 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12303 + to a dependency list. And, since we already have
12304 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12305 + Enhances, perhaps we could generalize all of these and save some
12306 + code duplication.
12308 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12310 + int reading_conffiles, reading_description;
12311 + int pkg_false_provides=1;
12313 + char * provide=NULL;
12316 + pkg->dest = dest;
12318 + reading_conffiles = reading_description = 0;
12320 + for (lines = *raw; *lines; lines++) {
12321 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12322 + if(isGenericFieldType("Package:", *lines))
12323 + pkg->name = parseGenericFieldType("Package", *lines);
12324 + else if(isGenericFieldType("Architecture:", *lines))
12325 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12326 + else if(isGenericFieldType("Filename:", *lines))
12327 + pkg->filename = parseGenericFieldType("Filename", *lines);
12328 + else if(isGenericFieldType("Section:", *lines))
12329 + pkg->section = parseGenericFieldType("Section", *lines);
12330 + else if(isGenericFieldType("MD5sum:", *lines))
12331 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12332 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12333 + let's parse it either way */
12334 + else if(isGenericFieldType("MD5Sum:", *lines))
12335 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12336 + else if(isGenericFieldType("Size:", *lines))
12337 + pkg->size = parseGenericFieldType("Size", *lines);
12338 + else if(isGenericFieldType("Source:", *lines))
12339 + pkg->source = parseGenericFieldType("Source", *lines);
12340 + else if(isGenericFieldType("Installed-Size:", *lines))
12341 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12342 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12343 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12344 + pkg->installed_time = strtoul(time_str, NULL, 0);
12345 + } else if(isGenericFieldType("Priority:", *lines))
12346 + pkg->priority = parseGenericFieldType("Priority", *lines);
12347 + else if(isGenericFieldType("Essential:", *lines)) {
12348 + char *essential_value;
12349 + essential_value = parseGenericFieldType("Essential", *lines);
12350 + if (strcmp(essential_value, "yes") == 0) {
12351 + pkg->essential = 1;
12353 + free(essential_value);
12355 + else if(isGenericFieldType("Status", *lines))
12356 + parseStatus(pkg, *lines);
12357 + else if(isGenericFieldType("Version", *lines))
12358 + parseVersion(pkg, *lines);
12359 + else if(isGenericFieldType("Maintainer", *lines))
12360 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12361 + else if(isGenericFieldType("Conffiles", *lines)){
12362 + parseConffiles(pkg, *lines);
12363 + reading_conffiles = 1;
12365 + else if(isGenericFieldType("Description", *lines)) {
12366 + pkg->description = parseGenericFieldType("Description", *lines);
12367 + reading_conffiles = 0;
12368 + reading_description = 1;
12371 + else if(isGenericFieldType("Provides", *lines)){
12372 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12373 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12374 + if ( alterProvidesLine(*lines,provide) ){
12377 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12378 +/* Let's try to hack a bit here.
12379 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12380 + in alot of other places. We will remove it before writing down the status database */
12381 + pkg_false_provides=0;
12385 + else if(isGenericFieldType("Depends", *lines))
12386 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12387 + else if(isGenericFieldType("Pre-Depends", *lines))
12388 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12389 + else if(isGenericFieldType("Recommends", *lines))
12390 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12391 + else if(isGenericFieldType("Suggests", *lines))
12392 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12393 + /* Abhaya: support for conflicts */
12394 + else if(isGenericFieldType("Conflicts", *lines))
12395 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12396 + else if(isGenericFieldType("Replaces", *lines))
12397 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12398 + else if(line_is_blank(*lines)) {
12402 + else if(**lines == ' '){
12403 + if(reading_description) {
12404 + /* we already know it's not blank, so the rest of description */
12405 + pkg->description = realloc(pkg->description,
12406 + strlen(pkg->description)
12407 + + 1 + strlen(*lines) + 1);
12408 + strcat(pkg->description, "\n");
12409 + strcat(pkg->description, (*lines));
12411 + else if(reading_conffiles)
12412 + parseConffiles(pkg, *lines);
12416 +/* If the ipk has not a Provides line, we insert our false line */
12417 + if ( pkg_false_provides==1)
12418 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12427 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12431 + for (lines = *raw; *lines; lines++) {
12432 + if(isGenericFieldType("Essential:", *lines)) {
12433 + char *essential_value;
12434 + essential_value = parseGenericFieldType("Essential", *lines);
12435 + if (strcmp(essential_value, "yes") == 0) {
12436 + pkg->essential = 1;
12438 + free(essential_value);
12445 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_parse.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h
12446 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12447 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-07-22 16:31:25.000000000 +0200
12449 +/* pkg_parse.h - the itsy package management system
12453 + Copyright (C) 2002 Compaq Computer Corporation
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_PARSE_H
12467 +#define PKG_PARSE_H
12469 +int isGenericFieldType(char * type, char * line);
12470 +char * parseGenericFieldType(char * type, char * raw);
12471 +void parseStatus(pkg_t *pkg, char * raw);
12472 +int parseVersion(pkg_t *pkg, char *raw);
12473 +char ** parseDependsString(char * raw, int * depends_count);
12474 +int parseVersion(pkg_t *pkg, char *raw);
12475 +void parseConffiles(pkg_t * pkg, char * raw);
12476 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12477 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12480 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c
12481 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12482 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-07-22 16:31:25.000000000 +0200
12484 +/* pkg_src.c - the itsy package management system
12488 + Copyright (C) 2001 University of Southern California
12490 + This program is free software; you can redistribute it and/or
12491 + modify it under the terms of the GNU General Public License as
12492 + published by the Free Software Foundation; either version 2, or (at
12493 + your option) any later version.
12495 + This program is distributed in the hope that it will be useful, but
12496 + WITHOUT ANY WARRANTY; without even the implied warranty of
12497 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12498 + General Public License for more details.
12503 +#include "pkg_src.h"
12504 +#include "str_util.h"
12506 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12508 + src->gzip = gzip;
12509 + src->name = str_dup_safe (name);
12510 + src->value = str_dup_safe (base_url);
12512 + src->extra_data = str_dup_safe (extra_data);
12514 + src->extra_data = NULL;
12518 +void pkg_src_deinit(pkg_src_t *src)
12520 + free (src->name);
12521 + free (src->value);
12522 + if (src->extra_data)
12523 + free (src->extra_data);
12527 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h
12528 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12529 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-07-22 16:31:25.000000000 +0200
12531 +/* pkg_src.h - the itsy package management system
12535 + Copyright (C) 2001 University of Southern California
12537 + This program is free software; you can redistribute it and/or
12538 + modify it under the terms of the GNU General Public License as
12539 + published by the Free Software Foundation; either version 2, or (at
12540 + your option) any later version.
12542 + This program is distributed in the hope that it will be useful, but
12543 + WITHOUT ANY WARRANTY; without even the implied warranty of
12544 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12545 + General Public License for more details.
12551 +#include "nv_pair.h"
12557 + char *extra_data;
12561 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12562 +void pkg_src_deinit(pkg_src_t *src);
12565 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c
12566 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12567 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-07-22 16:31:25.000000000 +0200
12569 +/* pkg_src_list.c - the itsy package management system
12573 + Copyright (C) 2001 University of Southern California
12575 + This program is free software; you can redistribute it and/or
12576 + modify it under the terms of the GNU General Public License as
12577 + published by the Free Software Foundation; either version 2, or (at
12578 + your option) any later version.
12580 + This program is distributed in the hope that it will be useful, but
12581 + WITHOUT ANY WARRANTY; without even the implied warranty of
12582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12583 + General Public License for more details.
12588 +#include "pkg_src_list.h"
12589 +#include "void_list.h"
12591 +int pkg_src_list_init(pkg_src_list_t *list)
12593 + return void_list_init((void_list_t *) list);
12596 +void pkg_src_list_deinit(pkg_src_list_t *list)
12598 + pkg_src_list_elt_t *iter;
12599 + pkg_src_t *pkg_src;
12601 + for (iter = list->head; iter; iter = iter->next) {
12602 + pkg_src = iter->data;
12603 + pkg_src_deinit(pkg_src);
12605 + /* malloced in pkg_src_list_append */
12607 + iter->data = NULL;
12609 + void_list_deinit((void_list_t *) list);
12612 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12613 + const char *name, const char *base_url, const char *extra_data,
12618 + /* freed in pkg_src_list_deinit */
12619 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12621 + if (pkg_src == NULL) {
12622 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12625 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12627 + err = void_list_append((void_list_t *) list, pkg_src);
12635 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12637 + return void_list_push((void_list_t *) list, data);
12640 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12642 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12644 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h
12645 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12646 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-07-22 16:31:25.000000000 +0200
12648 +/* pkg_src_list.h - the itsy package management system
12652 + Copyright (C) 2001 University of Southern California
12654 + This program is free software; you can redistribute it and/or
12655 + modify it under the terms of the GNU General Public License as
12656 + published by the Free Software Foundation; either version 2, or (at
12657 + your option) any later version.
12659 + This program is distributed in the hope that it will be useful, but
12660 + WITHOUT ANY WARRANTY; without even the implied warranty of
12661 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12662 + General Public License for more details.
12665 +#ifndef PKG_SRC_LIST_H
12666 +#define PKG_SRC_LIST_H
12668 +#include "pkg_src.h"
12670 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12671 +struct pkg_src_list_elt
12673 + pkg_src_list_elt_t *next;
12677 +typedef struct pkg_src_list pkg_src_list_t;
12678 +struct pkg_src_list
12680 + pkg_src_list_elt_t pre_head;
12681 + pkg_src_list_elt_t *head;
12682 + pkg_src_list_elt_t *tail;
12685 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12687 + if (list->head == NULL)
12693 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12694 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12696 +int pkg_src_list_init(pkg_src_list_t *list);
12697 +void pkg_src_list_deinit(pkg_src_list_t *list);
12699 +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);
12700 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12701 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12705 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_vec.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c
12706 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12707 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-07-22 16:31:26.000000000 +0200
12709 +/* pkg_vec.c - the itsy package management system
12713 + Copyright (C) 2002 Compaq Computer Corporation
12715 + This program is free software; you can redistribute it and/or
12716 + modify it under the terms of the GNU General Public License as
12717 + published by the Free Software Foundation; either version 2, or (at
12718 + your option) any later version.
12720 + This program is distributed in the hope that it will be useful, but
12721 + WITHOUT ANY WARRANTY; without even the implied warranty of
12722 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12723 + General Public License for more details.
12726 +#include <stdlib.h>
12727 +#include <fnmatch.h>
12728 +#include "xregex.h"
12732 +pkg_vec_t * pkg_vec_alloc(void)
12734 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12736 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12739 + vec->pkgs = NULL;
12745 +void pkg_vec_free(pkg_vec_t *vec)
12752 + * assumption: all names in a vector are identical
12753 + * assumption: all version strings are trimmed,
12754 + * so identical versions have identical version strings,
12755 + * implying identical packages; let's marry these
12757 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12762 + /* look for a duplicate pkg by name, version, and architecture */
12763 + for (i = 0; i < vec->len; i++){
12764 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12765 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12766 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12767 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12768 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12769 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12771 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12772 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12777 + /* we didn't find one, add it */
12779 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12780 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12782 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12783 + vec->pkgs[vec->len] = pkg;
12787 + /* update the one that we have */
12789 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12790 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12791 + if (set_status) {
12792 + /* this is from the status file, so need to merge with existing database */
12793 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12794 + pkg_merge(vec->pkgs[i], pkg, set_status);
12795 + /* XXX: CLEANUP: It's not so polite to free something here
12796 + that was passed in from above. */
12800 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12801 + /* just overwrite the old one */
12802 + pkg_deinit(vec->pkgs[i]);
12803 + free(vec->pkgs[i]);
12804 + vec->pkgs[i] = pkg;
12806 + return vec->pkgs[i];
12810 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12815 + /* look for a duplicate pkg by name, version, and architecture */
12816 + for (i = 0; i < vec->len; i++)
12817 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12818 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12819 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12824 + /* we didn't find one, add it */
12826 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12827 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12832 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12835 + for (i = 0; i < vec->len; i++)
12836 + if (vec->pkgs[i] == apkg)
12841 +typedef int (*compare_fcn_t)(const void *, const void *);
12842 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12844 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12847 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12849 + int npkgs = vec->len;
12851 + for (i = 0; i < npkgs; i++) {
12852 + pkg_t *pkg = vec->pkgs[i];
12853 + pkg->state_flag &= ~SF_MARKED;
12858 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12860 + int matching_count = 0;
12861 + pkg_t **pkgs = vec->pkgs;
12862 + int npkgs = vec->len;
12864 + for (i = 0; i < npkgs; i++) {
12865 + pkg_t *pkg = pkgs[i];
12866 + if (fnmatch(pattern, pkg->name, 0)==0) {
12867 + pkg->state_flag |= SF_MARKED;
12868 + matching_count++;
12871 + return matching_count;
12875 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12877 + abstract_pkg_vec_t * vec ;
12878 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12880 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12883 + vec->pkgs = NULL;
12889 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12896 + * assumption: all names in a vector are unique
12898 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12902 + /* look for a duplicate pkg by name */
12903 + for(i = 0; i < vec->len; i++)
12904 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12907 + /* we didn't find one, add it */
12908 + if(i == vec->len){
12910 + (abstract_pkg_t **)
12911 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12912 + vec->pkgs[vec->len] = pkg;
12917 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12919 + if (vec->len > i)
12920 + return vec->pkgs[i];
12925 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12928 + for (i = 0; i < vec->len; i++)
12929 + if (vec->pkgs[i] == apkg)
12934 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12936 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12939 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg_vec.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h
12940 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12941 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-07-22 16:31:26.000000000 +0200
12943 +/* pkg_vec.h - the itsy package management system
12947 + Copyright (C) 2002 Compaq Computer Corporation
12949 + This program is free software; you can redistribute it and/or
12950 + modify it under the terms of the GNU General Public License as
12951 + published by the Free Software Foundation; either version 2, or (at
12952 + your option) any later version.
12954 + This program is distributed in the hope that it will be useful, but
12955 + WITHOUT ANY WARRANTY; without even the implied warranty of
12956 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12957 + General Public License for more details.
12963 +typedef struct pkg pkg_t;
12964 +typedef struct abstract_pkg abstract_pkg_t;
12971 +typedef struct pkg_vec pkg_vec_t;
12973 +struct abstract_pkg_vec
12975 + abstract_pkg_t **pkgs;
12978 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12981 +pkg_vec_t * pkg_vec_alloc(void);
12982 +void pkg_vec_free(pkg_vec_t *vec);
12983 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12985 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12986 +/* pkg_vec_insert_merge: might munge pkg.
12987 +* returns the pkg that is in the pkg graph */
12988 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12989 +/* this one never munges pkg */
12990 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12991 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12992 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12994 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12995 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12997 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12998 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12999 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
13000 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13001 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13002 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13005 diff -ruN busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h
13006 --- busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13007 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-07-22 16:31:26.000000000 +0200
13009 +/* sprintf_alloca.c -- like sprintf with memory allocation
13013 + Copyright (C) 2001 University of Southern California
13015 + This program is free software; you can redistribute it and/or modify
13016 + it under the terms of the GNU General Public License as published by
13017 + the Free Software Foundation; either version 2, or (at your option)
13018 + any later version.
13020 + This program is distributed in the hope that it will be useful,
13021 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13022 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13023 + GNU General Public License for more details.
13026 +#ifndef SPRINTF_ALLOC_H
13027 +#define SPRINTF_ALLOC_H
13029 +#include "libbb.h"
13031 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13034 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c
13035 --- busybox-1.2.0-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13036 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c 2006-07-22 16:31:26.000000000 +0200
13038 +/* str_list.c - the itsy package management system
13042 + Copyright (C) 2001 University of Southern California
13044 + This program is free software; you can redistribute it and/or
13045 + modify it under the terms of the GNU General Public License as
13046 + published by the Free Software Foundation; either version 2, or (at
13047 + your option) any later version.
13049 + This program is distributed in the hope that it will be useful, but
13050 + WITHOUT ANY WARRANTY; without even the implied warranty of
13051 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13052 + General Public License for more details.
13057 +#include "str_list.h"
13059 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13061 + return void_list_elt_init((void_list_elt_t *) elt, data);
13064 +void str_list_elt_deinit(str_list_elt_t *elt)
13066 + void_list_elt_deinit((void_list_elt_t *) elt);
13069 +str_list_t *str_list_alloc()
13071 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13073 + str_list_init(list);
13077 +int str_list_init(str_list_t *list)
13079 + return void_list_init((void_list_t *) list);
13082 +void str_list_deinit(str_list_t *list)
13084 + void_list_deinit((void_list_t *) list);
13087 +int str_list_append(str_list_t *list, char *data)
13089 + return void_list_append((void_list_t *) list, data);
13092 +int str_list_push(str_list_t *list, char *data)
13094 + return void_list_push((void_list_t *) list, data);
13097 +str_list_elt_t *str_list_pop(str_list_t *list)
13099 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13102 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13104 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13105 + (void_list_elt_t **) iter);
13108 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13110 + return (char *)void_list_remove_elt((void_list_t *) list,
13111 + (void *)target_str,
13112 + (void_list_cmp_t)strcmp);
13114 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h
13115 --- busybox-1.2.0-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13116 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h 2006-07-22 16:31:26.000000000 +0200
13118 +/* str_list.h - the itsy package management system
13122 + Copyright (C) 2001 University of Southern California
13124 + This program is free software; you can redistribute it and/or
13125 + modify it under the terms of the GNU General Public License as
13126 + published by the Free Software Foundation; either version 2, or (at
13127 + your option) any later version.
13129 + This program is distributed in the hope that it will be useful, but
13130 + WITHOUT ANY WARRANTY; without even the implied warranty of
13131 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13132 + General Public License for more details.
13135 +#ifndef STR_LIST_H
13136 +#define STR_LIST_H
13138 +#include "void_list.h"
13140 +typedef struct str_list_elt str_list_elt_t;
13141 +struct str_list_elt
13143 + str_list_elt_t *next;
13147 +typedef struct xstr_list str_list_t;
13150 + str_list_elt_t pre_head;
13151 + str_list_elt_t *head;
13152 + str_list_elt_t *tail;
13155 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13156 +void str_list_elt_deinit(str_list_elt_t *elt);
13158 +str_list_t *str_list_alloc(void);
13159 +int str_list_init(str_list_t *list);
13160 +void str_list_deinit(str_list_t *list);
13162 +int str_list_append(str_list_t *list, char *data);
13163 +int str_list_push(str_list_t *list, char *data);
13164 +str_list_elt_t *str_list_pop(str_list_t *list);
13165 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13166 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13169 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_util.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c
13170 --- busybox-1.2.0-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13171 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c 2006-07-22 16:31:26.000000000 +0200
13173 +/* str_utils.c - the itsy package management system
13177 + Copyright (C) 2001 University of Southern California
13179 + This program is free software; you can redistribute it and/or
13180 + modify it under the terms of the GNU General Public License as
13181 + published by the Free Software Foundation; either version 2, or (at
13182 + your option) any later version.
13184 + This program is distributed in the hope that it will be useful, but
13185 + WITHOUT ANY WARRANTY; without even the implied warranty of
13186 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13187 + General Public License for more details.
13192 +int str_starts_with(const char *str, const char *prefix)
13194 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13197 +int str_ends_with(const char *str, const char *suffix)
13202 + str_len = strlen(str);
13203 + suffix_len = strlen(suffix);
13205 + if (str_len < suffix_len) {
13209 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13212 +int str_chomp(char *str)
13214 + if (str[strlen(str) - 1] == '\n') {
13215 + str[strlen(str) - 1] = '\0';
13221 +int str_tolower(char *str)
13224 + *str = tolower(*str);
13231 +int str_toupper(char *str)
13234 + *str = toupper(*str);
13241 +char *str_dup_safe(const char *str)
13243 + return str ? strdup(str) : NULL;
13246 diff -ruN busybox-1.2.0-orig/archival/libipkg/str_util.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h
13247 --- busybox-1.2.0-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13248 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h 2006-07-22 16:31:26.000000000 +0200
13250 +/* str_utils.h - the itsy package management system
13254 + Copyright (C) 2001 University of Southern California
13256 + This program is free software; you can redistribute it and/or
13257 + modify it under the terms of the GNU General Public License as
13258 + published by the Free Software Foundation; either version 2, or (at
13259 + your option) any later version.
13261 + This program is distributed in the hope that it will be useful, but
13262 + WITHOUT ANY WARRANTY; without even the implied warranty of
13263 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13264 + General Public License for more details.
13267 +#ifndef STR_UTILS_H
13268 +#define STR_UTILS_H
13270 +int str_starts_with(const char *str, const char *prefix);
13271 +int str_ends_with(const char *str, const char *suffix);
13272 +int str_chomp(char *str);
13273 +int str_tolower(char *str);
13274 +int str_toupper(char *str);
13275 +char *str_dup_safe(const char *str);
13278 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c
13279 --- busybox-1.2.0-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13280 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c 2006-07-22 16:31:26.000000000 +0200
13282 +/* user.c - the itsy package management system
13286 + Copyright (C) 2002 Hewlett Packard Company
13287 + Copyright (C) 2001 University of Southern California
13289 + This program is free software; you can redistribute it and/or
13290 + modify it under the terms of the GNU General Public License as
13291 + published by the Free Software Foundation; either version 2, or (at
13292 + your option) any later version.
13294 + This program is distributed in the hope that it will be useful, but
13295 + WITHOUT ANY WARRANTY; without even the implied warranty of
13296 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13297 + General Public License for more details.
13300 +#include <stdio.h>
13301 +#include <stdarg.h>
13302 +#include "file_util.h"
13303 +#include "str_util.h"
13305 +#include "libipkg.h"
13310 +static char *question = NULL;
13311 +static int question_len = 255;
13313 +char *get_user_response(const char *format, ...)
13315 + int len = question_len;
13318 + va_start(ap, format);
13321 + vprintf(format, ap);
13323 + response = file_read_line_alloc(stdin);
13324 + } while (response == NULL);
13327 + if (question == NULL || len > question_len) {
13328 + question = realloc(question, len + 1);
13329 + question_len = len;
13331 + len = vsnprintf(question,question_len,format,ap);
13332 + } while (len > question_len);
13333 + response = strdup(ipkg_cb_response(question));
13335 + str_chomp(response);
13336 + str_tolower(response);
13340 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h
13341 --- busybox-1.2.0-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13342 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h 2006-07-22 16:31:26.000000000 +0200
13344 +/* user.c - the itsy package management system
13348 + Copyright (C) 2002 Hewlett Packard Company
13349 + Copyright (C) 2001 University of Southern California
13351 + This program is free software; you can redistribute it and/or
13352 + modify it under the terms of the GNU General Public License as
13353 + published by the Free Software Foundation; either version 2, or (at
13354 + your option) any later version.
13356 + This program is distributed in the hope that it will be useful, but
13357 + WITHOUT ANY WARRANTY; without even the implied warranty of
13358 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13359 + General Public License for more details.
13362 +#include <stdio.h>
13363 +#include <stdarg.h>
13365 +char *get_user_response(const char *format, ...);
13367 diff -ruN busybox-1.2.0-orig/archival/libipkg/void_list.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c
13368 --- busybox-1.2.0-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13369 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c 2006-07-22 16:31:26.000000000 +0200
13371 +/* void_list.c - the itsy package management system
13375 + Copyright (C) 2001 University of Southern California
13377 + This program is free software; you can redistribute it and/or
13378 + modify it under the terms of the GNU General Public License as
13379 + published by the Free Software Foundation; either version 2, or (at
13380 + your option) any later version.
13382 + This program is distributed in the hope that it will be useful, but
13383 + WITHOUT ANY WARRANTY; without even the implied warranty of
13384 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13385 + General Public License for more details.
13389 +#include <errno.h>
13391 +#include "void_list.h"
13393 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13395 + elt->next = NULL;
13396 + elt->data = data;
13401 +void void_list_elt_deinit(void_list_elt_t *elt)
13403 + void_list_elt_init(elt, NULL);
13406 +int void_list_init(void_list_t *list)
13408 + void_list_elt_init(&list->pre_head, NULL);
13409 + list->head = NULL;
13410 + list->pre_head.next = list->head;
13411 + list->tail = NULL;
13416 +void void_list_deinit(void_list_t *list)
13418 + void_list_elt_t *elt;
13420 + while (list->head) {
13421 + elt = void_list_pop(list);
13422 + void_list_elt_deinit(elt);
13423 + /* malloced in void_list_append */
13428 +int void_list_append(void_list_t *list, void *data)
13430 + void_list_elt_t *elt;
13432 + /* freed in void_list_deinit */
13433 + elt = malloc(sizeof(void_list_elt_t));
13434 + if (elt == NULL) {
13435 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13439 + void_list_elt_init(elt, data);
13441 + if (list->tail) {
13442 + list->tail->next = elt;
13443 + list->tail = elt;
13445 + list->head = elt;
13446 + list->pre_head.next = list->head;
13447 + list->tail = elt;
13453 +int void_list_push(void_list_t *list, void *data)
13455 + void_list_elt_t *elt;
13457 + elt = malloc(sizeof(void_list_elt_t));
13458 + if (elt == NULL) {
13459 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13463 + void_list_elt_init(elt, data);
13465 + elt->next = list->head;
13466 + list->head->next = elt;
13467 + if (list->tail == NULL) {
13468 + list->tail = list->head;
13474 +void_list_elt_t *void_list_pop(void_list_t *list)
13476 + void_list_elt_t *elt;
13478 + elt = list->head;
13480 + if (list->head) {
13481 + list->head = list->head->next;
13482 + list->pre_head.next = list->head;
13483 + if (list->head == NULL) {
13484 + list->tail = NULL;
13491 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13493 + void_list_elt_t *prior;
13494 + void_list_elt_t *old_elt;
13498 + old_data = old_elt->data;
13500 + if (old_elt == list->head) {
13501 + prior = &list->pre_head;
13502 + void_list_pop(list);
13504 + for (prior = list->head; prior; prior = prior->next) {
13505 + if (prior->next == old_elt) {
13509 + if (prior == NULL || prior->next != old_elt) {
13510 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13513 + prior->next = old_elt->next;
13515 + if (old_elt == list->tail) {
13516 + list->tail = prior;
13520 + void_list_elt_deinit(old_elt);
13526 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13527 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13529 + void_list_elt_t *prior;
13530 + void_list_elt_t *old_elt = NULL;
13531 + void *old_data = NULL;
13533 + /* first element */
13534 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13535 + old_elt = list->head;
13536 + old_data = list->head->data;
13537 + void_list_pop(list);
13540 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13541 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13542 + old_elt = prior->next;
13543 + old_data = old_elt->data;
13551 + prior->next = old_elt->next;
13553 + if (old_elt == list->tail) {
13554 + list->tail = prior;
13558 + void_list_elt_deinit(old_elt);
13565 diff -ruN busybox-1.2.0-orig/archival/libipkg/void_list.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h
13566 --- busybox-1.2.0-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13567 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h 2006-07-22 16:31:26.000000000 +0200
13569 +/* void_list.h - the itsy package management system
13573 + Copyright (C) 2001 University of Southern California
13575 + This program is free software; you can redistribute it and/or
13576 + modify it under the terms of the GNU General Public License as
13577 + published by the Free Software Foundation; either version 2, or (at
13578 + your option) any later version.
13580 + This program is distributed in the hope that it will be useful, but
13581 + WITHOUT ANY WARRANTY; without even the implied warranty of
13582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13583 + General Public License for more details.
13586 +#ifndef VOID_LIST_H
13587 +#define VOID_LIST_H
13589 +typedef struct void_list_elt void_list_elt_t;
13590 +struct void_list_elt
13592 + void_list_elt_t *next;
13596 +typedef struct void_list void_list_t;
13599 + void_list_elt_t pre_head;
13600 + void_list_elt_t *head;
13601 + void_list_elt_t *tail;
13604 +static inline int void_list_empty(void_list_t *list)
13606 + if (list->head == NULL)
13612 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13613 +void void_list_elt_deinit(void_list_elt_t *elt);
13615 +int void_list_init(void_list_t *list);
13616 +void void_list_deinit(void_list_t *list);
13618 +int void_list_append(void_list_t *list, void *data);
13619 +int void_list_push(void_list_t *list, void *data);
13620 +void_list_elt_t *void_list_pop(void_list_t *list);
13622 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13623 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13624 +typedef int (*void_list_cmp_t)(const void *, const void *);
13625 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13628 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c
13629 --- busybox-1.2.0-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13630 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-07-22 16:31:26.000000000 +0200
13632 +/* xsystem.c - system(3) with error messages
13636 + Copyright (C) 2001 University of Southern California
13638 + This program is free software; you can redistribute it and/or
13639 + modify it under the terms of the GNU General Public License as
13640 + published by the Free Software Foundation; either version 2, or (at
13641 + your option) any later version.
13643 + This program is distributed in the hope that it will be useful, but
13644 + WITHOUT ANY WARRANTY; without even the implied warranty of
13645 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13646 + General Public License for more details.
13650 +#include <sys/wait.h>
13652 +#include "xsystem.h"
13654 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13655 + really need the /bin/sh invocation which takes resources and
13656 + introduces security problems. I should switch all of this to a sort
13657 + of execl() or execv() interface/implementation.
13660 +/* Like system(3), but with error messages printed if the fork fails
13661 + or if the child process dies due to an uncaught signal. Also, the
13662 + return value is a bit simpler:
13664 + -1 if there was any problem
13665 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13666 + as defined in <sys/wait.h>.
13668 +int xsystem(const char *cmd)
13672 + err = system(cmd);
13675 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13676 + __FUNCTION__, cmd);
13680 + if (WIFSIGNALED(err)) {
13681 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13682 + __FUNCTION__, WTERMSIG(err), cmd);
13686 + if (WIFEXITED(err)) {
13687 + /* Normal child exit */
13688 + return WEXITSTATUS(err);
13691 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13692 + __FUNCTION__, err);
13696 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h
13697 --- busybox-1.2.0-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13698 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-07-22 16:31:26.000000000 +0200
13700 +/* xsystem.h - system(3) with error messages
13704 + Copyright (C) 2001 University of Southern California
13706 + This program is free software; you can redistribute it and/or
13707 + modify it under the terms of the GNU General Public License as
13708 + published by the Free Software Foundation; either version 2, or (at
13709 + your option) any later version.
13711 + This program is distributed in the hope that it will be useful, but
13712 + WITHOUT ANY WARRANTY; without even the implied warranty of
13713 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13714 + General Public License for more details.
13720 +#include <stdlib.h>
13722 +/* Like system(3), but with error messages printed if the fork fails
13723 + or if the child process dies due to an uncaught signal. Also, the
13724 + return value is a bit simpler:
13726 + -1 if there was any problem
13727 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13728 + as defined in <sys/wait.h>.
13730 +int xsystem(const char *cmd);
13734 diff -ruN busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c
13735 --- busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c 2006-07-01 00:42:04.000000000 +0200
13736 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-07-22 16:31:26.000000000 +0200
13737 @@ -126,3 +126,17 @@
13738 utime(file_header->name, &t);
13742 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13744 + char *name_ptr = archive_handle->file_header->name;
13746 + name_ptr += strspn(name_ptr, "./");
13747 + if (name_ptr[0] != '\0') {
13748 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13749 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13750 + strcat(archive_handle->file_header->name, name_ptr);
13751 + data_extract_all(archive_handle);
13755 diff -ruN busybox-1.2.0-orig/archival/libunarchive/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in
13756 --- busybox-1.2.0-orig/archival/libunarchive/Makefile.in 2006-07-01 00:42:03.000000000 +0200
13757 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-07-22 16:31:26.000000000 +0200
13759 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13760 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13761 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13762 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13763 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13764 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13765 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13766 diff -ruN busybox-1.2.0-orig/archival/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in
13767 --- busybox-1.2.0-orig/archival/Makefile.in 2006-07-01 00:42:04.000000000 +0200
13768 +++ busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in 2006-07-22 16:31:25.000000000 +0200
13770 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
13771 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
13772 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
13773 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
13774 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
13775 ARCHIVAL-$(CONFIG_RPM) += rpm.o
13776 ARCHIVAL-$(CONFIG_TAR) += tar.o
13777 diff -ruN busybox-1.2.0-orig/include/applets.h busybox-1.2.0+ipkg-0.99.162/include/applets.h
13778 --- busybox-1.2.0-orig/include/applets.h 2006-07-01 00:42:10.000000000 +0200
13779 +++ busybox-1.2.0+ipkg-0.99.162/include/applets.h 2006-07-22 16:35:35.000000000 +0200
13780 @@ -152,6 +152,7 @@
13781 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13782 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13783 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13784 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13785 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13786 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13787 USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER))
13788 diff -ruN busybox-1.2.0-orig/include/unarchive.h busybox-1.2.0+ipkg-0.99.162/include/unarchive.h
13789 --- busybox-1.2.0-orig/include/unarchive.h 2006-07-01 00:42:10.000000000 +0200
13790 +++ busybox-1.2.0+ipkg-0.99.162/include/unarchive.h 2006-07-22 16:31:26.000000000 +0200
13793 extern void data_skip(archive_handle_t *archive_handle);
13794 extern void data_extract_all(archive_handle_t *archive_handle);
13795 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13796 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13797 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13799 diff -ruN busybox-1.2.0-orig/include/usage.h busybox-1.2.0+ipkg-0.99.162/include/usage.h
13800 --- busybox-1.2.0-orig/include/usage.h 2006-07-01 00:42:10.000000000 +0200
13801 +++ busybox-1.2.0+ipkg-0.99.162/include/usage.h 2006-07-22 16:31:26.000000000 +0200
13802 @@ -982,6 +982,82 @@
13803 "$ ls -la /tmp/busybox*\n" \
13804 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13806 +#define ipkg_trivial_usage \
13807 + "[options]... sub-command [arguments]..."
13808 +#define ipkg_full_usage \
13809 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13811 + "Sub-commands:\n" \
13812 + "\nPackage Manipulation:\n" \
13813 + "\tupdate Update list of available packages\n" \
13814 + "\tupgrade Upgrade all installed packages to latest version\n" \
13815 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13816 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13817 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13818 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13819 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13820 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13822 + "Informational Commands:\n" \
13823 + "\tlist List available packages and descriptions\n" \
13824 + "\tlist_installed List all and only the installed packages and description \n" \
13825 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13826 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13827 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13828 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13829 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13830 + "\tcompare_versions <v1> <op> <v2>\n" \
13831 + "\t compare versions using <= < > >= = << >>\n" \
13832 + "\tprint_architecture prints the architecture.\n" \
13833 + "\tprint_installation_architecture\n" \
13834 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13835 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13836 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13837 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13838 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13839 + "\t prints the installation architecture.\n" \
13842 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13843 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13844 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13845 + "\t 0 errors only\n" \
13846 + "\t 1 normal messages (default)\n" \
13847 + "\t 2 informative messages\n" \
13848 + "\t 3 debug output\n" \
13849 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13850 + "\t-conf <conf_file> Default configuration file location\n" \
13851 + " is /etc/ipkg.conf\n" \
13852 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13853 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13854 + " <dest_name> should be a defined dest name from\n" \
13855 + " the configuration file, (but can also be a\n" \
13856 + " directory name in a pinch).\n" \
13857 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13858 + "\t-offline <offline_root> offline installation of packages.\n" \
13859 + "\t-verbose_wget more wget messages\n" \
13861 + "Force Options (use when ipkg is too smart for its own good):\n" \
13862 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13863 + "\t Install/remove package in spite of failed dependences\n" \
13864 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13865 + " (no prompts). Note that this will not prevent\n" \
13866 + " package installation scripts from prompting.\n" \
13867 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13868 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13869 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13870 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13871 + "\t-noaction No action -- test only\n" \
13872 + "\t-nodeps Do not follow dependences\n" \
13873 + "\t-force-removal-of-dependent-packages\n" \
13874 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13875 + "\t-test No action -- test only\n" \
13876 + "\t-t Specify tmp-dir.\n" \
13877 + "\t--tmp-dir Specify tmp-dir.\n" \
13879 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13880 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13882 #define halt_trivial_usage \
13883 "[-d<delay>] [-n<nosync>] [-f<force>]"
13884 #define halt_full_usage \
13885 diff -ruN busybox-1.2.0-orig/Makefile busybox-1.2.0+ipkg-0.99.162/Makefile
13886 --- busybox-1.2.0-orig/Makefile 2006-07-01 00:42:13.000000000 +0200
13887 +++ busybox-1.2.0+ipkg-0.99.162/Makefile 2006-07-22 16:31:25.000000000 +0200
13889 export srctree=$(top_srcdir)
13890 vpath %/Config.in $(srctree)
13892 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
13893 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
13894 debianutils editors findutils init miscutils modutils networking \
13895 networking/libiproute networking/udhcp procps loginutils shell \
13896 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb