1 # Copyright (C) 2006 OpenWrt.org
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
6 # add ipkg support to busybox
8 diff -ruN busybox-1.2.0-orig/archival/Config.in busybox-1.2.0+ipkg-0.99.162/archival/Config.in
9 --- busybox-1.2.0-orig/archival/Config.in 2006-07-01 00:42:04.000000000 +0200
10 +++ busybox-1.2.0+ipkg-0.99.162/archival/Config.in 2006-07-22 16:31:25.000000000 +0200
12 gzip is used to compress files.
13 It's probably the most widely used UNIX compression program.
18 + select CONFIG_MD5SUM
21 + ipkg is the itsy package management system.
23 config CONFIG_RPM2CPIO
26 diff -ruN busybox-1.2.0-orig/archival/dpkg.c busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c
27 --- busybox-1.2.0-orig/archival/dpkg.c 2006-07-01 00:42:04.000000000 +0200
28 +++ busybox-1.2.0+ipkg-0.99.162/archival/dpkg.c 2006-07-22 16:31:25.000000000 +0200
29 @@ -1430,6 +1430,10 @@
30 return(ar_handle->sub_archive->buffer);
35 +// moved to data_extract_all.c
37 static void data_extract_all_prefix(archive_handle_t *archive_handle)
39 char *name_ptr = archive_handle->file_header->name;
46 static void unpack_package(deb_file_t *deb_file)
48 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
49 diff -ruN busybox-1.2.0-orig/archival/ipkg.c busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c
50 --- busybox-1.2.0-orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
51 +++ busybox-1.2.0+ipkg-0.99.162/archival/ipkg.c 2006-07-22 16:31:25.000000000 +0200
53 +/* ipkg.c - the itsy package management system
57 + Copyright (C) 2003 kernel concepts
59 + This program is free software; you can redistribute it and/or
60 + modify it under the terms of the GNU General Public License as
61 + published by the Free Software Foundation; either version 2, or (at
62 + your option) any later version.
64 + This program is distributed in the hope that it will be useful, but
65 + WITHOUT ANY WARRANTY; without even the implied warranty of
66 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67 + General Public License for more details.
69 + ipkg command line frontend using libipkg
73 +#include "libipkg/libipkg.h"
75 +int ipkg_main(int argc, char **argv)
77 + return ipkg_op(argc, argv);
79 diff -ruN busybox-1.2.0-orig/archival/libipkg/args.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c
80 --- busybox-1.2.0-orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
81 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.c 2006-07-22 16:31:25.000000000 +0200
83 +/* args.c - parse command-line args
87 + Copyright 2001 University of Southern California
89 + This program is free software; you can redistribute it and/or modify
90 + it under the terms of the GNU General Public License as published by
91 + the Free Software Foundation; either version 2, or (at your option)
94 + This program is distributed in the hope that it will be useful,
95 + but WITHOUT ANY WARRANTY; without even the implied warranty of
96 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 + GNU General Public License for more details.
106 +#include "ipkg_message.h"
109 +#include "sprintf_alloc.h"
114 +static void print_version(void);
118 + ARGS_OPT_FORCE_DEFAULTS = 129,
119 + ARGS_OPT_FORCE_DEPENDS,
120 + ARGS_OPT_FORCE_OVERWRITE,
121 + ARGS_OPT_FORCE_DOWNGRADE,
122 + ARGS_OPT_FORCE_REINSTALL,
123 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
124 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
125 + ARGS_OPT_FORCE_SPACE,
128 + ARGS_OPT_VERBOSE_WGET,
129 + ARGS_OPT_VERBOSITY,
130 + ARGS_OPT_MULTIPLE_PROVIDERS
133 +int args_init(args_t *args)
135 + char *conf_file_dir;
137 + memset(args, 0, sizeof(args_t));
139 + args->dest = ARGS_DEFAULT_DEST;
141 + conf_file_dir = getenv("IPKG_CONF_DIR");
142 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
143 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
145 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
146 + ARGS_DEFAULT_CONF_FILE_NAME);
148 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
149 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
150 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
151 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
152 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
153 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
154 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
155 + args->noaction = ARGS_DEFAULT_NOACTION;
156 + args->nodeps = ARGS_DEFAULT_NODEPS;
157 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
158 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
159 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
160 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
161 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
162 + args->multiple_providers = 0;
163 + args->nocheckfordirorfile = 0;
164 + args->noreadfeedsfile = 0;
169 +void args_deinit(args_t *args)
171 + free(args->conf_file);
172 + args->conf_file = NULL;
175 +int args_parse(args_t *args, int argc, char *argv[])
178 + int option_index = 0;
180 + static struct option long_options[] = {
181 + {"query-all", 0, 0, 'A'},
182 + {"conf-file", 1, 0, 'f'},
183 + {"conf", 1, 0, 'f'},
184 + {"dest", 1, 0, 'd'},
185 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
186 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
187 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
188 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
189 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
190 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
191 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
192 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
193 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
194 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
195 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
196 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
197 + {"recursive", 0, 0,
198 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
199 + {"force-removal-of-dependent-packages", 0, 0,
200 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
201 + {"force_removal_of_dependent_packages", 0, 0,
202 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
203 + {"force-removal-of-essential-packages", 0, 0,
204 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
205 + {"force_removal_of_essential_packages", 0, 0,
206 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
207 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
208 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
209 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
210 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
211 + {"offline", 1, 0, 'o'},
212 + {"offline-root", 1, 0, 'o'},
213 + {"test", 0, 0, ARGS_OPT_NOACTION},
214 + {"tmp-dir", 1, 0, 't'},
215 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
216 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
217 + {"verbosity", 2, 0, 'V'},
218 + {"version", 0, 0, 'v'},
223 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
229 + args->query_all = 1;
232 + args->dest = optarg;
235 + free(args->conf_file);
236 + args->conf_file = strdup(optarg);
239 + args->offline_root = optarg;
242 + args->noaction = 1;
245 + args->tmp_dir = strdup(optarg);
251 + case ARGS_OPT_VERBOSITY:
253 + args->verbosity = atoi(optarg);
255 + args->verbosity += 1;
257 + case ARGS_OPT_FORCE_DEFAULTS:
258 + args->force_defaults = 1;
260 + case ARGS_OPT_FORCE_DEPENDS:
261 + args->force_depends = 1;
263 + case ARGS_OPT_FORCE_OVERWRITE:
264 + args->force_overwrite = 1;
266 + case ARGS_OPT_FORCE_DOWNGRADE:
267 + args->force_downgrade = 1;
269 + case ARGS_OPT_FORCE_REINSTALL:
270 + args->force_reinstall = 1;
272 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
273 + args->force_removal_of_essential_packages = 1;
275 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
276 + args->force_removal_of_dependent_packages = 1;
278 + case ARGS_OPT_FORCE_SPACE:
279 + args->force_space = 1;
281 + case ARGS_OPT_VERBOSE_WGET:
282 + args->verbose_wget = 1;
284 + case ARGS_OPT_MULTIPLE_PROVIDERS:
285 + args->multiple_providers = 1;
287 + case ARGS_OPT_NODEPS:
290 + case ARGS_OPT_NOACTION:
291 + args->noaction = 1;
300 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
311 +void args_usage(char *complaint)
314 + bb_error_msg("%s\n", complaint);
321 +static void print_version(void)
323 + bb_error_msg("version %s\n", IPKG_VERSION);
325 diff -ruN busybox-1.2.0-orig/archival/libipkg/args.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h
326 --- busybox-1.2.0-orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
327 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/args.h 2006-07-22 16:31:25.000000000 +0200
329 +/* args.h - parse command-line args
333 + Copyright 2001 University of Southern California
335 + This program is free software; you can redistribute it and/or modify
336 + it under the terms of the GNU General Public License as published by
337 + the Free Software Foundation; either version 2, or (at your option)
340 + This program is distributed in the hope that it will be useful,
341 + but WITHOUT ANY WARRANTY; without even the implied warranty of
342 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343 + GNU General Public License for more details.
354 + int force_defaults;
356 + int force_overwrite;
357 + int force_downgrade;
358 + int force_reinstall;
359 + int force_removal_of_essential_packages;
360 + int force_removal_of_dependent_packages;
364 + int multiple_providers;
368 + int nocheckfordirorfile;
369 + int noreadfeedsfile;
370 + char *offline_root;
371 + char *offline_root_pre_script_cmd;
372 + char *offline_root_post_script_cmd;
374 +typedef struct args args_t;
376 +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
377 +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
378 +#define ARGS_DEFAULT_DEST NULL
379 +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
380 +#define ARGS_DEFAULT_FORCE_DEPENDS 0
381 +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
382 +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
383 +#define ARGS_DEFAULT_FORCE_REINSTALL 0
384 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
385 +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
386 +#define ARGS_DEFAULT_FORCE_SPACE 0
387 +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
388 +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
389 +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
390 +#define ARGS_DEFAULT_NOACTION 0
391 +#define ARGS_DEFAULT_NODEPS 0
392 +#define ARGS_DEFAULT_VERBOSE_WGET 0
393 +#define ARGS_DEFAULT_VERBOSITY 1
395 +int args_init(args_t *args);
396 +void args_deinit(args_t *args);
397 +int args_parse(args_t *args, int argc, char *argv[]);
398 +void args_usage(char *complaint);
401 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c
402 --- busybox-1.2.0-orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
403 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.c 2006-07-22 16:31:25.000000000 +0200
405 +/* conffile.c - the itsy package management system
409 + Copyright (C) 2001 University of Southern California
411 + This program is free software; you can redistribute it and/or
412 + modify it under the terms of the GNU General Public License as
413 + published by the Free Software Foundation; either version 2, or (at
414 + your option) any later version.
416 + This program is distributed in the hope that it will be useful, but
417 + WITHOUT ANY WARRANTY; without even the implied warranty of
418 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
419 + General Public License for more details.
426 +#include "ipkg_message.h"
428 +#include "conffile.h"
429 +#include "file_util.h"
430 +#include "sprintf_alloc.h"
432 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
434 + return nv_pair_init(conffile, file_name, md5sum);
437 +void conffile_deinit(conffile_t *conffile)
439 + nv_pair_deinit(conffile);
442 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
445 + char *filename = conffile->name;
446 + char *root_filename;
449 + if (conffile->value == NULL) {
450 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
454 + root_filename = root_filename_alloc(conf, filename);
456 + md5sum = file_md5sum_alloc(root_filename);
458 + ret = strcmp(md5sum, conffile->value);
460 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
461 + conffile->name, md5sum, conffile->value);
464 + free(root_filename);
469 diff -ruN busybox-1.2.0-orig/archival/libipkg/conffile.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h
470 --- busybox-1.2.0-orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
471 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile.h 2006-07-22 16:31:25.000000000 +0200
473 +/* conffile.h - the itsy package management system
477 + Copyright (C) 2001 University of Southern California
479 + This program is free software; you can redistribute it and/or
480 + modify it under the terms of the GNU General Public License as
481 + published by the Free Software Foundation; either version 2, or (at
482 + your option) any later version.
484 + This program is distributed in the hope that it will be useful, but
485 + WITHOUT ANY WARRANTY; without even the implied warranty of
486 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
487 + General Public License for more details.
493 +#include "nv_pair.h"
495 +typedef struct nv_pair conffile_t;
497 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
498 +void conffile_deinit(conffile_t *conffile);
499 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
503 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
504 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
505 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.c 2006-07-22 16:31:25.000000000 +0200
507 +/* conffile_list.c - the itsy package management system
511 + Copyright (C) 2001 University of Southern California
513 + This program is free software; you can redistribute it and/or
514 + modify it under the terms of the GNU General Public License as
515 + published by the Free Software Foundation; either version 2, or (at
516 + your option) any later version.
518 + This program is distributed in the hope that it will be useful, but
519 + WITHOUT ANY WARRANTY; without even the implied warranty of
520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
521 + General Public License for more details.
526 +#include "conffile_list.h"
528 +int conffile_list_init(conffile_list_t *list)
530 + return nv_pair_list_init(list);
533 +void conffile_list_deinit(conffile_list_t *list)
535 + nv_pair_list_deinit(list);
538 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
539 + const char *md5sum)
541 + return nv_pair_list_append(list, file_name, md5sum);
544 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
546 + return nv_pair_list_push(list, data);
549 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
551 + return nv_pair_list_pop(list);
554 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
555 --- busybox-1.2.0-orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
556 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/conffile_list.h 2006-07-22 16:31:25.000000000 +0200
558 +/* conffile_list.h - the itsy package management system
562 + Copyright (C) 2001 University of Southern California
564 + This program is free software; you can redistribute it and/or
565 + modify it under the terms of the GNU General Public License as
566 + published by the Free Software Foundation; either version 2, or (at
567 + your option) any later version.
569 + This program is distributed in the hope that it will be useful, but
570 + WITHOUT ANY WARRANTY; without even the implied warranty of
571 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
572 + General Public License for more details.
575 +#ifndef CONFFILE_LIST_H
576 +#define CONFFILE_LIST_H
578 +#include "conffile.h"
579 +#include "nv_pair_list.h"
581 +typedef struct nv_pair_list_elt conffile_list_elt_t;
582 +typedef struct nv_pair_list conffile_list_t;
584 +int conffile_list_init(conffile_list_t *list);
585 +void conffile_list_deinit(conffile_list_t *list);
587 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
588 + const char *root_dir);
589 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
590 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
594 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
595 --- busybox-1.2.0-orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
596 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.c 2006-07-22 16:31:25.000000000 +0200
598 +/* file_util.c - convenience routines for common stat operations
602 + Copyright (C) 2001 University of Southern California
604 + This program is free software; you can redistribute it and/or
605 + modify it under the terms of the GNU General Public License as
606 + published by the Free Software Foundation; either version 2, or (at
607 + your option) any later version.
609 + This program is distributed in the hope that it will be useful, but
610 + WITHOUT ANY WARRANTY; without even the implied warranty of
611 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
612 + General Public License for more details.
616 +#include <sys/types.h>
617 +#include <sys/stat.h>
619 +#include "sprintf_alloc.h"
620 +#include "file_util.h"
625 +int file_exists(const char *file_name)
628 + struct stat stat_buf;
630 + err = stat(file_name, &stat_buf);
638 +int file_is_dir(const char *file_name)
641 + struct stat stat_buf;
643 + err = stat(file_name, &stat_buf);
648 + return S_ISDIR(stat_buf.st_mode);
651 +/* read a single line from a file, stopping at a newline or EOF.
652 + If a newline is read, it will appear in the resulting string.
653 + Return value is a malloc'ed char * which should be freed at
654 + some point by the caller.
656 + Return value is NULL if the file is at EOF when called.
658 +#define FILE_READ_LINE_BUF_SIZE 1024
659 +char *file_read_line_alloc(FILE *file)
661 + char buf[FILE_READ_LINE_BUF_SIZE];
666 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
667 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
668 + buf_len = strlen(buf);
670 + line_size += buf_len;
671 + line = realloc(line, line_size);
672 + if (line == NULL) {
673 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
678 + line_size = buf_len + 1;
679 + line = strdup(buf);
681 + if (buf[buf_len - 1] == '\n') {
689 +int file_move(const char *src, const char *dest)
693 + err = rename(src, dest);
695 + if (err && errno == EXDEV) {
696 + err = file_copy(src, dest);
699 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
700 + __FUNCTION__, src, dest, strerror(errno));
706 +/* I put these here to keep libbb dependencies from creeping all over
708 +int file_copy(const char *src, const char *dest)
712 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
714 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
715 + __FUNCTION__, src, dest);
721 +int file_mkdir_hier(const char *path, long mode)
723 + return bb_make_directory(path, mode, FILEUTILS_RECUR);
726 +char *file_md5sum_alloc(const char *file_name)
728 + static const int md5sum_bin_len = 16;
729 + static const int md5sum_hex_len = 32;
731 + static const unsigned char bin2hex[16] = {
732 + '0', '1', '2', '3',
733 + '4', '5', '6', '7',
734 + '8', '9', 'a', 'b',
740 + unsigned char *md5sum_hex;
741 + unsigned char md5sum_bin[md5sum_bin_len];
743 + md5sum_hex = malloc(md5sum_hex_len + 1);
744 + if (md5sum_hex == NULL) {
745 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
749 + file = fopen(file_name, "r");
750 + if (file == NULL) {
751 + fprintf(stderr, "%s: Failed to open file %s: %s\n",
752 + __FUNCTION__, file_name, strerror(errno));
756 + err = md5_stream(file, md5sum_bin);
758 + fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
759 + __FUNCTION__, file_name, strerror(err));
765 + for (i=0; i < md5sum_bin_len; i++) {
766 + md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
767 + md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
770 + md5sum_hex[md5sum_hex_len] = '\0';
775 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
776 --- busybox-1.2.0-orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
777 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/file_util.h 2006-07-22 16:31:25.000000000 +0200
779 +/* file_util.h - convenience routines for common file operations
783 + Copyright (C) 2001 University of Southern California
785 + This program is free software; you can redistribute it and/or
786 + modify it under the terms of the GNU General Public License as
787 + published by the Free Software Foundation; either version 2, or (at
788 + your option) any later version.
790 + This program is distributed in the hope that it will be useful, but
791 + WITHOUT ANY WARRANTY; without even the implied warranty of
792 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
793 + General Public License for more details.
799 +int file_exists(const char *file_name);
800 +int file_is_dir(const char *file_name);
801 +char *file_read_line_alloc(FILE *file);
802 +int file_move(const char *src, const char *dest);
803 +int file_copy(const char *src, const char *dest);
804 +int file_mkdir_hier(const char *path, long mode);
805 +char *file_md5sum_alloc(const char *file_name);
808 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
809 --- busybox-1.2.0-orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
810 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.c 2006-07-22 16:31:25.000000000 +0200
812 +/* hash.c - hash tables for ipkg
814 + Steven M. Ayer, Jamey Hicks
816 + Copyright (C) 2002 Compaq Computer Corporation
818 + This program is free software; you can redistribute it and/or
819 + modify it under the terms of the GNU General Public License as
820 + published by the Free Software Foundation; either version 2, or (at
821 + your option) any later version.
823 + This program is distributed in the hope that it will be useful, but
824 + WITHOUT ANY WARRANTY; without even the implied warranty of
825 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
826 + General Public License for more details.
833 +#include "hash_table.h"
834 +#include "ipkg_message.h"
837 +static int hash_index(hash_table_t *hash, const char *pkg_name);
838 +static int rotating(const char *key, int len, int prime);
840 +static int hash_index(hash_table_t *hash, const char *pkg_name)
842 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
845 +static int rotating(const char *key, int len, int prime)
847 + unsigned int hash, i;
848 + for (hash=len, i=0; i<len; ++i)
849 + hash = (hash<<4)^(hash>>28)^key[i];
850 + return (hash % prime);
855 + * this is an open table keyed by strings
857 +int hash_table_init(const char *name, hash_table_t *hash, int len)
859 + static int primes_table[] = {
860 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
861 + 19471, 23143, 33961, 46499, 49727, 99529, 0
865 + if (hash->entries != NULL) {
866 + /* we have been here already */
871 + hash->entries = NULL;
872 + hash->n_entries = 0;
873 + hash->hash_entry_key = NULL;
875 + picker = primes_table;
876 + while(*picker && (*picker++ < len));
878 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
881 + hash->n_entries = *picker;
882 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
883 + if (hash->entries == NULL) {
884 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
890 +void hash_table_deinit(hash_table_t *hash)
892 + free(hash->entries);
893 + hash->entries = NULL;
894 + hash->n_entries = 0;
897 +void *hash_table_get(hash_table_t *hash, const char *key)
899 + int ndx= hash_index(hash, key);
900 + hash_entry_t *hash_entry = hash->entries + ndx;
903 + if (hash_entry->key)
905 + if (strcmp(key, hash_entry->key) == 0) {
906 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
907 + return hash_entry->data;
910 + hash_entry = hash_entry->next;
915 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
917 + int ndx= hash_index(hash, key);
918 + hash_entry_t *hash_entry = hash->entries + ndx;
919 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
920 + if (hash_entry->key) {
921 + if (strcmp(hash_entry->key, key) == 0) {
922 + /* alread in table, update the value */
923 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
924 + hash_entry->data = value;
928 + * if this is a collision, we have to go to the end of the ll,
929 + * then add a new entry
930 + * before we can hook up the value
932 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
933 + while (hash_entry->next)
934 + hash_entry = hash_entry->next;
935 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
936 + if (!hash_entry->next) {
939 + hash_entry = hash_entry->next;
940 + hash_entry->next = NULL;
943 + hash->n_elements++;
944 + hash_entry->key = strdup(key);
945 + hash_entry->data = value;
951 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
957 + for (i = 0; i < hash->n_entries; i++) {
958 + hash_entry_t *hash_entry = (hash->entries + i);
960 + if(hash_entry->key) {
961 + f(hash_entry->key, hash_entry->data, data);
963 + } while((hash_entry = hash_entry->next));
967 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
968 --- busybox-1.2.0-orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
969 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/hash_table.h 2006-07-22 16:31:25.000000000 +0200
971 +/* hash.h - hash tables for ipkg
973 + Steven M. Ayer, Jamey Hicks
975 + Copyright (C) 2002 Compaq Computer Corporation
977 + This program is free software; you can redistribute it and/or
978 + modify it under the terms of the GNU General Public License as
979 + published by the Free Software Foundation; either version 2, or (at
980 + your option) any later version.
982 + This program is distributed in the hope that it will be useful, but
983 + WITHOUT ANY WARRANTY; without even the implied warranty of
984 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
985 + General Public License for more details.
988 +#ifndef _HASH_TABLE_H_
989 +#define _HASH_TABLE_H_
991 +typedef struct hash_entry hash_entry_t;
992 +typedef struct hash_table hash_table_t;
997 + struct hash_entry * next;
1000 +struct hash_table {
1002 + hash_entry_t * entries;
1003 + int n_entries; /* number of buckets */
1005 + const char * (*hash_entry_key)(void * data);
1008 +int hash_table_init(const char *name, hash_table_t *hash, int len);
1009 +void hash_table_deinit(hash_table_t *hash);
1010 +void *hash_table_get(hash_table_t *hash, const char *key);
1011 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
1012 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
1014 +#endif /* _HASH_TABLE_H_ */
1015 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
1016 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
1017 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.c 2006-07-22 16:31:25.000000000 +0200
1019 +/* ipkg_cmd.c - the itsy package management system
1023 + Copyright (C) 2001 University of Southern California
1025 + This program is free software; you can redistribute it and/or
1026 + modify it under the terms of the GNU General Public License as
1027 + published by the Free Software Foundation; either version 2, or (at
1028 + your option) any later version.
1030 + This program is distributed in the hope that it will be useful, but
1031 + WITHOUT ANY WARRANTY; without even the implied warranty of
1032 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1033 + General Public License for more details.
1036 +#include <string.h>
1039 +#include <libgen.h>
1042 +#include <stdlib.h>
1043 +#include <unistd.h>
1044 +#include <signal.h>
1046 +#include <dirent.h>
1048 +#include "ipkg_conf.h"
1049 +#include "ipkg_cmd.h"
1050 +#include "ipkg_message.h"
1052 +#include "pkg_dest.h"
1053 +#include "pkg_parse.h"
1054 +#include "sprintf_alloc.h"
1056 +#include "file_util.h"
1057 +#include "str_util.h"
1059 +#include "unarchive.h"
1061 +#include <fnmatch.h>
1064 +#include "ipkg_download.h"
1065 +#include "ipkg_install.h"
1066 +#include "ipkg_upgrade.h"
1067 +#include "ipkg_remove.h"
1068 +#include "ipkg_configure.h"
1069 +#include "ipkg_message.h"
1072 +#include "libipkg.h"
1073 +static void *p_userdata = NULL;
1076 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1077 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1078 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1079 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1080 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1081 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1082 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1083 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1084 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1085 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1086 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1087 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1088 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1089 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1090 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1091 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1092 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1093 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1094 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1095 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1096 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1097 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1098 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1099 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1100 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1102 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1103 + array for easier maintenance */
1104 +static ipkg_cmd_t cmds[] = {
1105 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1106 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1107 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1108 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1109 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1110 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1111 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1112 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1113 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1114 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1115 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1116 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1117 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1118 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1119 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1120 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1121 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1122 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1123 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1124 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1125 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1126 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1127 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1128 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1129 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1130 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1131 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1132 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1133 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1136 +int ipkg_state_changed;
1137 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1139 + if (ipkg_state_changed && !conf->noaction) {
1140 + ipkg_message(conf, IPKG_INFO,
1141 + " writing status file\n");
1142 + ipkg_conf_write_status_files(conf);
1143 + pkg_write_changed_filelists(conf);
1145 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1150 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1152 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1157 + for (i=0; i < num_cmds; i++) {
1159 + if (strcmp(name, cmd->name) == 0) {
1168 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1171 + p_userdata = userdata;
1174 + result = (cmd->fun)(conf, argc, argv);
1175 + if ( result == 0 ) {
1176 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1178 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1181 + if ( error_list ) {
1182 + reverse_error_list(&error_list);
1184 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1185 + /* Here we print the errors collected and free the list */
1186 + while (error_list != NULL) {
1187 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1188 + error_list = error_list->next;
1191 + free_error_list(&error_list);
1195 + p_userdata = NULL;
1199 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1201 + return (cmd->fun)(conf, argc, argv);
1205 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1210 + pkg_src_list_elt_t *iter;
1214 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1216 + if (! file_is_dir(lists_dir)) {
1217 + if (file_exists(lists_dir)) {
1218 + ipkg_message(conf, IPKG_ERROR,
1219 + "%s: ERROR: %s exists, but is not a directory\n",
1220 + __FUNCTION__, lists_dir);
1224 + err = file_mkdir_hier(lists_dir, 0755);
1226 + ipkg_message(conf, IPKG_ERROR,
1227 + "%s: ERROR: failed to make directory %s: %s\n",
1228 + __FUNCTION__, lists_dir, strerror(errno));
1235 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1236 + char *url, *list_file_name;
1240 + if (src->extra_data) /* debian style? */
1241 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1242 + src->gzip ? "Packages.gz" : "Packages");
1244 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1246 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1249 + char *tmp_file_name;
1252 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1254 + if (mkdtemp (tmp) == NULL) {
1255 + perror ("mkdtemp");
1260 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1261 + err = ipkg_download(conf, url, tmp_file_name);
1263 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1264 + in = fopen (tmp_file_name, "r");
1265 + out = fopen (list_file_name, "w");
1267 + inflate_unzip (in, out);
1274 + unlink (tmp_file_name);
1279 + err = ipkg_download(conf, url, list_file_name);
1283 + ipkg_message(conf, IPKG_NOTICE,
1284 + "Updated list of available packages in %s\n",
1288 + free(list_file_name);
1292 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1294 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1295 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1301 + pkg_vec_t *available = pkg_vec_alloc();
1302 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1303 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1304 + for (i = 0; i < available->len; i++) {
1305 + pkg_t *pkg = available->pkgs[i];
1306 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1307 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1308 + pkg->state_want = SW_UNKNOWN;
1312 + pkg_vec_free(available);
1314 + write_status_files_if_changed(conf);
1323 +/* scan the args passed and cache the local filenames of the packages */
1324 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1330 + * First scan through package names/urls
1331 + * For any urls, download the packages and install in database.
1332 + * For any files, install package info in database.
1334 + for (i = 0; i < argc; i ++) {
1335 + char *filename = argv [i];
1336 + //char *tmp = basename (tmp);
1337 + //int tmplen = strlen (tmp);
1339 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1341 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1344 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1346 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1353 +struct ipkg_intercept
1359 +typedef struct ipkg_intercept *ipkg_intercept_t;
1361 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1363 + ipkg_intercept_t ctx;
1367 + ctx = malloc (sizeof (*ctx));
1368 + ctx->oldpath = strdup (getenv ("PATH"));
1370 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1371 + setenv ("PATH", newpath, 1);
1376 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1377 + if (mkdir (ctx->statedir, 0770) < 0) {
1378 + if (errno == EEXIST) {
1379 + free (ctx->statedir);
1383 + perror (ctx->statedir);
1386 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1390 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1396 + setenv ("PATH", ctx->oldpath, 1);
1397 + free (ctx->oldpath);
1399 + dir = opendir (ctx->statedir);
1401 + struct dirent *de;
1402 + while (de = readdir (dir), de != NULL) {
1405 + if (de->d_name[0] == '.')
1408 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1409 + if (access (path, X_OK) == 0) {
1410 + if (system (path)) {
1412 + perror (de->d_name);
1418 + perror (ctx->statedir);
1420 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1424 + free (ctx->statedir);
1430 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1435 + ipkg_intercept_t ic;
1438 + ipkg_message(conf, IPKG_INFO,
1439 + "Configuring unpacked packages\n");
1442 + all = pkg_vec_alloc();
1443 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1445 + ic = ipkg_prep_intercepts (conf);
1447 + for(i = 0; i < all->len; i++) {
1448 + pkg = all->pkgs[i];
1450 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1453 + if (pkg->state_status == SS_UNPACKED) {
1454 + ipkg_message(conf, IPKG_NOTICE,
1455 + "Configuring %s\n", pkg->name);
1457 + r = ipkg_configure(conf, pkg);
1459 + pkg->state_status = SS_INSTALLED;
1460 + pkg->parent->state_status = SS_INSTALLED;
1461 + pkg->state_flag &= ~SF_PREFER;
1469 + r = ipkg_finalize_intercepts (ic);
1473 + pkg_vec_free(all);
1477 +static void sigint_handler(int sig)
1479 + signal(sig, SIG_DFL);
1480 + ipkg_message(NULL, IPKG_NOTICE,
1481 + "ipkg: interrupted. writing out status database\n");
1482 + write_status_files_if_changed(global_conf);
1486 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1492 + global_conf = conf;
1493 + signal(SIGINT, sigint_handler);
1496 + * Now scan through package names and install
1498 + for (i=0; i < argc; i++) {
1501 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1502 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1503 + if (err != EINVAL && err != 0)
1506 + pkg_info_preinstall_check(conf);
1508 + for (i=0; i < argc; i++) {
1510 + if (conf->multiple_providers)
1511 + err = ipkg_install_multi_by_name(conf, arg);
1513 + err = ipkg_install_by_name(conf, arg);
1515 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1516 + ipkg_message(conf, IPKG_ERROR,
1517 + "Cannot find package %s.\n"
1518 + "Check the spelling or perhaps run 'ipkg update'\n",
1523 + /* recheck to verify that all dependences are satisfied */
1524 + if (0) ipkg_satisfy_all_dependences(conf);
1526 + ipkg_configure_packages(conf, NULL);
1528 + write_status_files_if_changed(conf);
1533 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1539 + global_conf = conf;
1540 + signal(SIGINT, sigint_handler);
1543 + for (i=0; i < argc; i++) {
1544 + char *arg = argv[i];
1546 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1547 + if (err != EINVAL && err != 0)
1550 + pkg_info_preinstall_check(conf);
1552 + for (i=0; i < argc; i++) {
1553 + char *arg = argv[i];
1554 + if (conf->restrict_to_default_dest) {
1555 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1557 + conf->default_dest);
1558 + if (pkg == NULL) {
1559 + ipkg_message(conf, IPKG_NOTICE,
1560 + "Package %s not installed in %s\n",
1561 + argv[i], conf->default_dest->name);
1565 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1569 + ipkg_upgrade_pkg(conf, pkg);
1571 + ipkg_install_by_name(conf, arg);
1575 + pkg_vec_t *installed = pkg_vec_alloc();
1577 + pkg_info_preinstall_check(conf);
1579 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1580 + for (i = 0; i < installed->len; i++) {
1581 + pkg = installed->pkgs[i];
1582 + ipkg_upgrade_pkg(conf, pkg);
1584 + pkg_vec_free(installed);
1587 + /* recheck to verify that all dependences are satisfied */
1588 + if (0) ipkg_satisfy_all_dependences(conf);
1590 + ipkg_configure_packages(conf, NULL);
1592 + write_status_files_if_changed(conf);
1597 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1603 + pkg_info_preinstall_check(conf);
1604 + for (i = 0; i < argc; i++) {
1607 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1608 + if (pkg == NULL) {
1609 + ipkg_message(conf, IPKG_ERROR,
1610 + "Cannot find package %s.\n"
1611 + "Check the spelling or perhaps run 'ipkg update'\n",
1616 + err = ipkg_download_pkg(conf, pkg, ".");
1619 + ipkg_message(conf, IPKG_ERROR,
1620 + "Failed to download %s\n", pkg->name);
1622 + ipkg_message(conf, IPKG_NOTICE,
1623 + "Downloaded %s as %s\n",
1624 + pkg->name, pkg->local_filename);
1632 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1635 + pkg_vec_t *available;
1637 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1639 + char *pkg_name = NULL;
1640 + char *version_str;
1643 + pkg_name = argv[0];
1645 + available = pkg_vec_alloc();
1646 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1647 + for (i=0; i < available->len; i++) {
1648 + pkg = available->pkgs[i];
1649 + /* if we have package name or pattern and pkg does not match, then skip it */
1650 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1652 + if (pkg->description) {
1653 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1655 + desc_short[0] = '\0';
1657 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1658 + newline = strchr(desc_short, '\n');
1663 + printf("%s - %s\n", pkg->name, desc_short);
1665 + if (ipkg_cb_list) {
1666 + version_str = pkg_version_str_alloc(pkg);
1667 + ipkg_cb_list(pkg->name,desc_short,
1669 + pkg->state_status,
1671 + free(version_str);
1675 + pkg_vec_free(available);
1681 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1684 + pkg_vec_t *available;
1686 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1688 + char *pkg_name = NULL;
1689 + char *version_str;
1692 + pkg_name = argv[0];
1694 + available = pkg_vec_alloc();
1695 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1696 + for (i=0; i < available->len; i++) {
1697 + pkg = available->pkgs[i];
1698 + /* if we have package name or pattern and pkg does not match, then skip it */
1699 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1701 + if (pkg->description) {
1702 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1704 + desc_short[0] = '\0';
1706 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1707 + newline = strchr(desc_short, '\n');
1712 + printf("%s - %s\n", pkg->name, desc_short);
1714 + if (ipkg_cb_list) {
1715 + version_str = pkg_version_str_alloc(pkg);
1716 + ipkg_cb_list(pkg->name,desc_short,
1718 + pkg->state_status,
1720 + free(version_str);
1728 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1731 + pkg_vec_t *available;
1733 + char *pkg_name = NULL;
1734 + char **pkg_fields = NULL;
1736 + char *buff ; // = (char *)malloc(1);
1739 + pkg_name = argv[0];
1742 + pkg_fields = &argv[1];
1743 + n_fields = argc - 1;
1746 + available = pkg_vec_alloc();
1747 + if (installed_only)
1748 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1750 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1751 + for (i=0; i < available->len; i++) {
1752 + pkg = available->pkgs[i];
1753 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1758 + for (j = 0; j < n_fields; j++)
1759 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1761 + pkg_print_info(pkg, stdout);
1765 + buff = pkg_formatted_info(pkg);
1767 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1768 + pkg->state_status,
1772 + We should not forget that actually the pointer is allocated.
1773 + We need to free it :) ( Thanks florian for seeing the error )
1778 + if (conf->verbosity > 1) {
1779 + conffile_list_elt_t *iter;
1780 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1781 + conffile_t *cf = iter->data;
1782 + int modified = conffile_has_been_modified(conf, cf);
1783 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1784 + cf->name, cf->value, modified);
1792 + pkg_vec_free(available);
1797 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1799 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1802 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1804 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1807 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1812 + char *pkg_name = NULL;
1814 + pkg_name = argv[0];
1816 + err = ipkg_configure_packages (conf, pkg_name);
1819 + err = ipkg_configure_packages (conf, NULL);
1822 + write_status_files_if_changed(conf);
1827 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1830 + char *globpattern;
1833 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1834 + err = glob(globpattern, 0, NULL, &globbuf);
1835 + free(globpattern);
1840 + ipkg_message(conf, IPKG_NOTICE,
1841 + "The following packages in %s will now be installed.\n",
1842 + conf->pending_dir);
1843 + for (i = 0; i < globbuf.gl_pathc; i++) {
1844 + ipkg_message(conf, IPKG_NOTICE,
1845 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1847 + ipkg_message(conf, IPKG_NOTICE, "\n");
1848 + for (i = 0; i < globbuf.gl_pathc; i++) {
1849 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1851 + err = unlink(globbuf.gl_pathv[i]);
1853 + ipkg_message(conf, IPKG_ERROR,
1854 + "%s: ERROR: failed to unlink %s: %s\n",
1855 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1860 + globfree(&globbuf);
1865 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1869 + pkg_t *pkg_to_remove;
1870 + pkg_vec_t *available;
1871 + char *pkg_name = NULL;
1872 + global_conf = conf;
1873 + signal(SIGINT, sigint_handler);
1875 +// ENH: Add the "no pkg removed" just in case.
1879 + available = pkg_vec_alloc();
1880 + pkg_info_preinstall_check(conf);
1882 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1883 + for (i=0; i < argc; i++) {
1884 + pkg_name = malloc(strlen(argv[i])+2);
1885 + strcpy(pkg_name,argv[i]);
1886 + for (a=0; a < available->len; a++) {
1887 + pkg = available->pkgs[a];
1888 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1891 + if (conf->restrict_to_default_dest) {
1892 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1894 + conf->default_dest);
1896 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1899 + if (pkg == NULL) {
1900 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1903 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1904 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1907 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1912 + pkg_vec_free(available);
1914 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1916 + int flagged_pkg_count = 0;
1919 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1921 + for (i = 0; i < installed_pkgs->len; i++) {
1922 + pkg_t *pkg = installed_pkgs->pkgs[i];
1923 + if (pkg->state_flag & SF_USER) {
1924 + flagged_pkg_count++;
1926 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1927 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1930 + if (!flagged_pkg_count) {
1931 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1932 + "so refusing to uninstall unflagged non-leaf packages\n");
1936 + /* find packages not flagged SF_USER (i.e., installed to
1937 + * satisfy a dependence) and not having any dependents, and
1941 + for (i = 0; i < installed_pkgs->len; i++) {
1942 + pkg_t *pkg = installed_pkgs->pkgs[i];
1943 + if (!(pkg->state_flag & SF_USER)
1944 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1946 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1947 + ipkg_remove_pkg(conf, pkg,0);
1951 + } while (removed);
1952 + pkg_vec_free(installed_pkgs);
1956 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1958 + write_status_files_if_changed(conf);
1962 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1967 + global_conf = conf;
1968 + signal(SIGINT, sigint_handler);
1970 + pkg_info_preinstall_check(conf);
1972 + for (i=0; i < argc; i++) {
1973 + if (conf->restrict_to_default_dest) {
1974 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1976 + conf->default_dest);
1978 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1981 + if (pkg == NULL) {
1982 + ipkg_message(conf, IPKG_ERROR,
1983 + "Package %s is not installed.\n", argv[i]);
1986 + ipkg_purge_pkg(conf, pkg);
1989 + write_status_files_if_changed(conf);
1993 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1997 + const char *flags = argv[0];
1999 + global_conf = conf;
2000 + signal(SIGINT, sigint_handler);
2002 + for (i=1; i < argc; i++) {
2003 + if (conf->restrict_to_default_dest) {
2004 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
2006 + conf->default_dest);
2008 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
2011 + if (pkg == NULL) {
2012 + ipkg_message(conf, IPKG_ERROR,
2013 + "Package %s is not installed.\n", argv[i]);
2016 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
2017 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
2018 + pkg->state_flag = pkg_state_flag_from_str(flags);
2020 +/* pb_ asked this feature 03292004 */
2021 +/* Actually I will use only this two, but this is an open for various status */
2022 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
2023 + pkg->state_status = pkg_state_status_from_str(flags);
2025 + ipkg_state_changed++;
2026 + ipkg_message(conf, IPKG_NOTICE,
2027 + "Setting flags for package %s to %s\n",
2028 + pkg->name, flags);
2031 + write_status_files_if_changed(conf);
2035 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
2038 + str_list_t *installed_files;
2039 + str_list_elt_t *iter;
2040 + char *pkg_version;
2041 + size_t buff_len = 8192;
2045 + buff = (char *)malloc(buff_len);
2046 + if ( buff == NULL ) {
2047 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2055 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2057 + if (pkg == NULL) {
2058 + ipkg_message(conf, IPKG_ERROR,
2059 + "Package %s not installed.\n", argv[0]);
2063 + installed_files = pkg_get_installed_files(pkg);
2064 + pkg_version = pkg_version_str_alloc(pkg);
2067 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2068 + pkg->name, pkg_version, pkg->dest->name);
2069 + for (iter = installed_files->head; iter; iter = iter->next) {
2075 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2076 + pkg->name, pkg_version, pkg->dest->name) + 1;
2077 + if (used_len > buff_len) {
2079 + buff = realloc (buff, buff_len);
2082 + for (iter = installed_files->head; iter; iter = iter->next) {
2083 + used_len += strlen (iter->data) + 1;
2084 + while (buff_len <= used_len) {
2086 + buff = realloc (buff, buff_len);
2088 + strncat(buff, iter->data, buff_len);
2089 + strncat(buff, "\n", buff_len);
2091 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2093 + pkg_version_str_alloc(pkg),
2094 + pkg->state_status,
2100 + free(pkg_version);
2101 + pkg_free_installed_files(pkg);
2106 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2110 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2111 + const char *rel_str = "depends on";
2114 + pkg_info_preinstall_check(conf);
2116 + if (conf->query_all)
2117 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2119 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2120 + for (i = 0; i < argc; i++) {
2121 + const char *target = argv[i];
2124 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2126 + for (j = 0; j < available_pkgs->len; j++) {
2127 + pkg_t *pkg = available_pkgs->pkgs[j];
2128 + if (fnmatch(target, pkg->name, 0) == 0) {
2130 + int count = pkg->depends_count + pkg->pre_depends_count;
2131 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2132 + target, pkg->architecture, rel_str);
2133 + for (k = 0; k < count; k++) {
2134 + compound_depend_t *cdepend = &pkg->depends[k];
2136 + for (l = 0; l < cdepend->possibility_count; l++) {
2137 + depend_t *possibility = cdepend->possibilities[l];
2138 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2139 + if (conf->verbosity > 0) {
2140 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2141 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2142 + if (possibility->version) {
2143 + char *typestr = NULL;
2144 + switch (possibility->constraint) {
2145 + case NONE: typestr = "none"; break;
2146 + case EARLIER: typestr = "<"; break;
2147 + case EARLIER_EQUAL: typestr = "<="; break;
2148 + case EQUAL: typestr = "="; break;
2149 + case LATER_EQUAL: typestr = ">="; break;
2150 + case LATER: typestr = ">"; break;
2152 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2156 + ipkg_message(conf, IPKG_ERROR, "\n");
2162 + pkg_vec_free(available_pkgs);
2167 +enum what_field_type {
2176 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2180 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2181 + const char *rel_str = NULL;
2185 + switch (what_field_type) {
2186 + case WHATDEPENDS: rel_str = "depends on"; break;
2187 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2188 + case WHATSUGGESTS: rel_str = "suggests"; break;
2189 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2190 + case WHATPROVIDES: rel_str = "provides"; break;
2191 + case WHATREPLACES: rel_str = "replaces"; break;
2194 + if (conf->query_all)
2195 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2197 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2199 + /* mark the root set */
2200 + pkg_vec_clear_marks(available_pkgs);
2201 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2202 + for (i = 0; i < argc; i++) {
2203 + const char *dependee_pattern = argv[i];
2204 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2206 + for (i = 0; i < available_pkgs->len; i++) {
2207 + pkg_t *pkg = available_pkgs->pkgs[i];
2208 + if (pkg->state_flag & SF_MARKED) {
2209 + /* mark the parent (abstract) package */
2210 + pkg_mark_provides(pkg);
2211 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2215 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2220 + for (j = 0; j < available_pkgs->len; j++) {
2221 + pkg_t *pkg = available_pkgs->pkgs[j];
2223 + int count = ((what_field_type == WHATCONFLICTS)
2224 + ? pkg->conflicts_count
2225 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2226 + /* skip this package if it is already marked */
2227 + if (pkg->parent->state_flag & SF_MARKED) {
2230 + for (k = 0; k < count; k++) {
2231 + compound_depend_t *cdepend =
2232 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2234 + for (l = 0; l < cdepend->possibility_count; l++) {
2235 + depend_t *possibility = cdepend->possibilities[l];
2236 + if (possibility->pkg->state_flag & SF_MARKED) {
2237 + /* mark the depending package so we won't visit it again */
2238 + pkg->state_flag |= SF_MARKED;
2239 + pkg_mark_provides(pkg);
2242 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2243 + if (conf->verbosity > 0) {
2244 + char *ver = pkg_version_str_alloc(pkg);
2245 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2246 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2247 + if (possibility->version) {
2248 + char *typestr = NULL;
2249 + switch (possibility->constraint) {
2250 + case NONE: typestr = "none"; break;
2251 + case EARLIER: typestr = "<"; break;
2252 + case EARLIER_EQUAL: typestr = "<="; break;
2253 + case EQUAL: typestr = "="; break;
2254 + case LATER_EQUAL: typestr = ">="; break;
2255 + case LATER: typestr = ">"; break;
2257 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2260 + if (!pkg_dependence_satisfiable(conf, possibility))
2261 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2263 + ipkg_message(conf, IPKG_NOTICE, "\n");
2264 + goto next_package;
2271 + } while (changed && recursive);
2272 + pkg_vec_free(available_pkgs);
2278 +int pkg_mark_provides(pkg_t *pkg)
2280 + int provides_count = pkg->provides_count;
2281 + abstract_pkg_t **provides = pkg->provides;
2283 + pkg->parent->state_flag |= SF_MARKED;
2284 + for (i = 0; i < provides_count; i++) {
2285 + provides[i]->state_flag |= SF_MARKED;
2290 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2292 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2294 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2296 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2299 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2301 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2304 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2306 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2309 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2311 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2314 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2318 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2319 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2322 + pkg_info_preinstall_check(conf);
2324 + if (conf->query_all)
2325 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2327 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2328 + for (i = 0; i < argc; i++) {
2329 + const char *target = argv[i];
2332 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2334 + for (j = 0; j < available_pkgs->len; j++) {
2335 + pkg_t *pkg = available_pkgs->pkgs[j];
2337 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2338 + for (k = 0; k < count; k++) {
2339 + abstract_pkg_t *apkg =
2340 + ((what_field_type == WHATPROVIDES)
2341 + ? pkg->provides[k]
2342 + : pkg->replaces[k]);
2343 + if (fnmatch(target, apkg->name, 0) == 0) {
2344 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2345 + if (strcmp(target, apkg->name) != 0)
2346 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2347 + ipkg_message(conf, IPKG_ERROR, "\n");
2352 + pkg_vec_free(available_pkgs);
2357 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2359 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2362 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2364 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2367 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2371 + pkg_vec_t *installed;
2373 + str_list_t *installed_files;
2374 + str_list_elt_t *iter;
2375 + char *installed_file;
2381 + installed = pkg_vec_alloc();
2382 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2384 + for (i=0; i < installed->len; i++) {
2385 + pkg = installed->pkgs[i];
2387 + installed_files = pkg_get_installed_files(pkg);
2389 + for (iter = installed_files->head; iter; iter = iter->next) {
2390 + installed_file = iter->data;
2391 + if (fnmatch(argv[0], installed_file, 0)==0) {
2393 + printf("%s: %s\n", pkg->name, installed_file);
2395 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2397 + pkg_version_str_alloc(pkg),
2398 + pkg->state_status, p_userdata);
2403 + pkg_free_installed_files(pkg);
2406 + /* XXX: CLEANUP: It's not obvious from the name of
2407 + pkg_hash_fetch_all_installed that we need to call
2408 + pkg_vec_free to avoid a memory leak. */
2409 + pkg_vec_free(installed);
2414 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2417 + /* this is a bit gross */
2418 + struct pkg p1, p2;
2419 + parseVersion(&p1, argv[0]);
2420 + parseVersion(&p2, argv[2]);
2421 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2423 + ipkg_message(conf, IPKG_ERROR,
2424 + "ipkg compare_versions <v1> <op> <v2>\n"
2425 + "<op> is one of <= >= << >> =\n");
2430 +#ifndef HOST_CPU_STR
2431 +#define HOST_CPU_STR__(X) #X
2432 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2433 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2436 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2438 + nv_pair_list_elt_t *l;
2440 + l = conf->arch_list.head;
2442 + nv_pair_t *nv = l->data;
2443 + printf("arch %s %s\n", nv->name, nv->value);
2450 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
2451 --- busybox-1.2.0-orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
2452 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_cmd.h 2006-07-22 16:31:25.000000000 +0200
2454 +/* ipkg_cmd.h - the itsy package management system
2458 + Copyright (C) 2001 University of Southern California
2460 + This program is free software; you can redistribute it and/or
2461 + modify it under the terms of the GNU General Public License as
2462 + published by the Free Software Foundation; either version 2, or (at
2463 + your option) any later version.
2465 + This program is distributed in the hope that it will be useful, but
2466 + WITHOUT ANY WARRANTY; without even the implied warranty of
2467 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2468 + General Public License for more details.
2474 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2479 + int requires_args;
2480 + ipkg_cmd_fun_t fun;
2482 +typedef struct ipkg_cmd ipkg_cmd_t;
2484 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2486 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2487 + const char **argv, void *userdata);
2489 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2491 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2492 +/* install any packges with state_want == SW_INSTALL */
2493 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2494 +/* ensure that all dependences are satisfied */
2495 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2497 +int pkg_mark_provides(pkg_t *pkg);
2500 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
2501 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
2502 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.c 2006-07-22 16:31:25.000000000 +0200
2504 +/* ipkg_conf.c - the itsy package management system
2508 + Copyright (C) 2001 University of Southern California
2510 + This program is free software; you can redistribute it and/or
2511 + modify it under the terms of the GNU General Public License as
2512 + published by the Free Software Foundation; either version 2, or (at
2513 + your option) any later version.
2515 + This program is distributed in the hope that it will be useful, but
2516 + WITHOUT ANY WARRANTY; without even the implied warranty of
2517 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2518 + General Public License for more details.
2524 +#include "ipkg_conf.h"
2526 +#include "xregex.h"
2527 +#include "sprintf_alloc.h"
2528 +#include "ipkg_conf.h"
2529 +#include "ipkg_message.h"
2530 +#include "file_util.h"
2531 +#include "str_util.h"
2532 +#include "xsystem.h"
2535 +ipkg_conf_t *global_conf;
2537 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2538 + pkg_src_list_t *pkg_src_list,
2539 + nv_pair_list_t *tmp_dest_nv_pair_list,
2540 + char **tmp_lists_dir);
2541 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2542 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2543 + const char *name, const char *value);
2544 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2545 + const char *default_dest_name);
2546 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2547 + pkg_src_list_t *nv_pair_list);
2548 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2549 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2551 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2553 + ipkg_option_t tmp[] = {
2554 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2555 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2556 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2557 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2558 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2559 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2560 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2561 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2562 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2563 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2564 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2565 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2566 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2567 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2568 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2569 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2570 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2571 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2572 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2573 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2574 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2578 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2579 + if ( options == NULL ){
2580 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2584 + memcpy(*options, tmp, sizeof(tmp));
2588 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2594 + *conf_str = strdup(arg_str);
2598 +static void ipkg_conf_free_string(char **conf_str)
2606 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2609 + char *tmp_dir_base;
2610 + nv_pair_list_t tmp_dest_nv_pair_list;
2611 + char * lists_dir =NULL;
2613 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2614 + char *pending_dir =NULL;
2616 + memset(conf, 0, sizeof(ipkg_conf_t));
2618 + pkg_src_list_init(&conf->pkg_src_list);
2620 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2621 + pkg_dest_list_init(&conf->pkg_dest_list);
2623 + nv_pair_list_init(&conf->arch_list);
2625 + conf->restrict_to_default_dest = 0;
2626 + conf->default_dest = NULL;
2629 + if (args->tmp_dir)
2630 + tmp_dir_base = args->tmp_dir;
2632 + tmp_dir_base = getenv("TMPDIR");
2633 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2634 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2635 + IPKG_CONF_TMP_DIR_SUFFIX);
2636 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2637 + if (conf->tmp_dir == NULL) {
2638 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2639 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2643 + conf->force_depends = 0;
2644 + conf->force_defaults = 0;
2645 + conf->force_overwrite = 0;
2646 + conf->force_downgrade = 0;
2647 + conf->force_reinstall = 0;
2648 + conf->force_space = 0;
2649 + conf->force_removal_of_essential_packages = 0;
2650 + conf->force_removal_of_dependent_packages = 0;
2652 + conf->verbose_wget = 0;
2653 + conf->offline_root = NULL;
2654 + conf->offline_root_pre_script_cmd = NULL;
2655 + conf->offline_root_post_script_cmd = NULL;
2656 + conf->multiple_providers = 0;
2657 + conf->verbosity = 1;
2658 + conf->noaction = 0;
2660 + conf->http_proxy = NULL;
2661 + conf->ftp_proxy = NULL;
2662 + conf->no_proxy = NULL;
2663 + conf->proxy_user = NULL;
2664 + conf->proxy_passwd = NULL;
2666 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2667 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2668 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2669 + lists_dir=(char *)malloc(1);
2670 + lists_dir[0]='\0';
2671 + if (args->conf_file) {
2672 + struct stat stat_buf;
2673 + err = stat(args->conf_file, &stat_buf);
2675 + if (ipkg_conf_parse_file(conf, args->conf_file,
2676 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2677 + /* Memory leakage from ipkg_conf_parse-file */
2683 + /* if (!lists_dir ){*/
2684 + if (strlen(lists_dir)<=1 ){
2685 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2686 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2689 + if (args->offline_root) {
2690 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2691 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2696 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2697 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2699 + conf->lists_dir = strdup(lists_dir);
2700 + conf->pending_dir = strdup(pending_dir);
2702 + if (args->offline_root)
2703 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2704 + memset(&globbuf, 0, sizeof(globbuf));
2705 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2708 + for (i = 0; i < globbuf.gl_pathc; i++) {
2709 + if (globbuf.gl_pathv[i])
2710 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2711 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2712 + /* Memory leakage from ipkg_conf_parse-file */
2717 + globfree(&globbuf);
2719 + /* if no architectures were defined, then default all, noarch, and host architecture */
2720 + if (nv_pair_list_empty(&conf->arch_list)) {
2721 + nv_pair_list_append(&conf->arch_list, "all", "1");
2722 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2723 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2726 + /* Even if there is no conf file, we'll need at least one dest. */
2727 + if (tmp_dest_nv_pair_list.head == NULL) {
2728 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2729 + IPKG_CONF_DEFAULT_DEST_NAME,
2730 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2733 + /* After parsing the file, set options from command-line, (so that
2734 + command-line arguments take precedence) */
2735 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2736 + really needs to be cleaned up. There is so much duplication
2737 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2738 + a pointer to args_t (which could then not be freed), rather
2739 + than duplicating every field here? */
2740 + if (args->force_depends) {
2741 + conf->force_depends = 1;
2743 + if (args->force_defaults) {
2744 + conf->force_defaults = 1;
2746 + if (args->force_overwrite) {
2747 + conf->force_overwrite = 1;
2749 + if (args->force_downgrade) {
2750 + conf->force_downgrade = 1;
2752 + if (args->force_reinstall) {
2753 + conf->force_reinstall = 1;
2755 + if (args->force_removal_of_dependent_packages) {
2756 + conf->force_removal_of_dependent_packages = 1;
2758 + if (args->force_removal_of_essential_packages) {
2759 + conf->force_removal_of_essential_packages = 1;
2761 + if (args->nodeps) {
2764 + if (args->noaction) {
2765 + conf->noaction = 1;
2767 + if (args->query_all) {
2768 + conf->query_all = 1;
2770 + if (args->verbose_wget) {
2771 + conf->verbose_wget = 1;
2773 + if (args->multiple_providers) {
2774 + conf->multiple_providers = 1;
2776 + if (args->verbosity != conf->verbosity) {
2777 + conf->verbosity = args->verbosity;
2780 + ipkg_conf_override_string(&conf->offline_root,
2781 + args->offline_root);
2782 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2783 + args->offline_root_pre_script_cmd);
2784 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2785 + args->offline_root_post_script_cmd);
2787 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2788 + read anything from there.
2790 + if ( !(args->nocheckfordirorfile)){
2791 + /* need to run load the source list before dest list -Jamey */
2792 + if ( !(args->noreadfeedsfile))
2793 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2795 + /* Now that we have resolved conf->offline_root, we can commit to
2796 + the directory names for the dests and load in all the package
2798 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2801 + err = ipkg_conf_set_default_dest(conf, args->dest);
2807 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2809 + free(pending_dir);
2814 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2816 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2818 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2819 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2820 + __FUNCTION__, conf->tmp_dir);
2824 + err = rmdir(conf->tmp_dir);
2826 + if (errno == ENOTEMPTY) {
2828 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2829 + err = xsystem(cmd);
2833 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2835 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2837 + free(conf->tmp_dir); /*XXX*/
2839 + pkg_src_list_deinit(&conf->pkg_src_list);
2840 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2841 + nv_pair_list_deinit(&conf->arch_list);
2842 + if (&conf->pkg_hash)
2843 + pkg_hash_deinit(&conf->pkg_hash);
2844 + if (&conf->file_hash)
2845 + hash_table_deinit(&conf->file_hash);
2846 + if (&conf->obs_file_hash)
2847 + hash_table_deinit(&conf->obs_file_hash);
2849 + ipkg_conf_free_string(&conf->offline_root);
2850 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2851 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2853 + if (conf->verbosity > 1) {
2855 + hash_table_t *hashes[] = {
2858 + &conf->obs_file_hash };
2859 + for (i = 0; i < 3; i++) {
2860 + hash_table_t *hash = hashes[i];
2862 + int n_conflicts = 0;
2864 + for (j = 0; j < hash->n_entries; j++) {
2866 + hash_entry_t *e = &hash->entries[j];
2869 + while (e && e->key) {
2876 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2877 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2878 + hash_table_deinit(hash);
2883 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2884 + const char *default_dest_name)
2886 + pkg_dest_list_elt_t *iter;
2889 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2890 + dest = iter->data;
2891 + if (strcmp(dest->name, default_dest_name) == 0) {
2892 + conf->default_dest = dest;
2893 + conf->restrict_to_default_dest = 1;
2898 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2903 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2905 + pkg_src_list_elt_t *iter;
2909 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2911 + if (src == NULL) {
2915 + sprintf_alloc(&list_file, "%s/%s",
2916 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2919 + if (file_exists(list_file)) {
2920 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2928 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2930 + nv_pair_list_elt_t *iter;
2931 + nv_pair_t *nv_pair;
2935 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2936 + nv_pair = iter->data;
2938 + if (conf->offline_root) {
2939 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2941 + root_dir = strdup(nv_pair->value);
2943 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2945 + if (dest == NULL) {
2948 + if (conf->default_dest == NULL) {
2949 + conf->default_dest = dest;
2951 + if (file_exists(dest->status_file_name)) {
2952 + pkg_hash_add_from_file(conf, dest->status_file_name,
2960 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2961 + pkg_src_list_t *pkg_src_list,
2962 + nv_pair_list_t *tmp_dest_nv_pair_list,
2965 + ipkg_option_t * options;
2966 + FILE *file = fopen(filename, "r");
2967 + regex_t valid_line_re, comment_re;
2968 +#define regmatch_size 12
2969 + regmatch_t regmatch[regmatch_size];
2971 + if (ipkg_init_options_array(conf, &options)<0)
2974 + if (file == NULL) {
2975 + fprintf(stderr, "%s: failed to open %s: %s\n",
2976 + __FUNCTION__, filename, strerror(errno));
2980 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2982 + xregcomp(&comment_re,
2983 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2985 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2990 + char *type, *name, *value, *extra;
2992 + line = file_read_line_alloc(file);
2994 + if (line == NULL) {
3000 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
3004 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
3006 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
3007 + filename, line_num, line);
3011 + /* This has to be so ugly to deal with optional quotation marks */
3012 + if (regmatch[2].rm_so > 0) {
3013 + type = strndup(line + regmatch[2].rm_so,
3014 + regmatch[2].rm_eo - regmatch[2].rm_so);
3016 + type = strndup(line + regmatch[3].rm_so,
3017 + regmatch[3].rm_eo - regmatch[3].rm_so);
3019 + if (regmatch[5].rm_so > 0) {
3020 + name = strndup(line + regmatch[5].rm_so,
3021 + regmatch[5].rm_eo - regmatch[5].rm_so);
3023 + name = strndup(line + regmatch[6].rm_so,
3024 + regmatch[6].rm_eo - regmatch[6].rm_so);
3026 + if (regmatch[8].rm_so > 0) {
3027 + value = strndup(line + regmatch[8].rm_so,
3028 + regmatch[8].rm_eo - regmatch[8].rm_so);
3030 + value = strndup(line + regmatch[9].rm_so,
3031 + regmatch[9].rm_eo - regmatch[9].rm_so);
3034 + if (regmatch[11].rm_so > 0) {
3035 + extra = strndup (line + regmatch[11].rm_so,
3036 + regmatch[11].rm_eo - regmatch[11].rm_so);
3039 + /* We use the tmp_dest_nv_pair_list below instead of
3040 + conf->pkg_dest_list because we might encounter an
3041 + offline_root option later and that would invalidate the
3042 + directories we would have computed in
3043 + pkg_dest_list_init. (We do a similar thing with
3044 + tmp_src_nv_pair_list for sake of symmetry.) */
3045 + if (strcmp(type, "option") == 0) {
3046 + ipkg_conf_set_option(options, name, value);
3047 + } else if (strcmp(type, "src") == 0) {
3048 + if (!nv_pair_list_find(pkg_src_list, name)) {
3049 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
3051 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3054 + } else if (strcmp(type, "src/gz") == 0) {
3055 + if (!nv_pair_list_find(pkg_src_list, name)) {
3056 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3058 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3061 + } else if (strcmp(type, "dest") == 0) {
3062 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3063 + } else if (strcmp(type, "lists_dir") == 0) {
3064 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3065 + if (*lists_dir == NULL) {
3066 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3070 + sprintf (*lists_dir,"%s",value);
3071 + } else if (strcmp(type, "arch") == 0) {
3072 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3074 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3075 + value = strdup("10");
3077 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3079 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3080 + "parameter: %s %s %s\n", type, name, value);
3096 + regfree(&comment_re);
3097 + regfree(&valid_line_re);
3103 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3104 + const char *name, const char *value)
3107 + while (options[i].name) {
3108 + if (strcmp(options[i].name, name) == 0) {
3109 + switch (options[i].type) {
3110 + case IPKG_OPT_TYPE_BOOL:
3111 + *((int *)options[i].value) = 1;
3113 + case IPKG_OPT_TYPE_INT:
3115 + *((int *)options[i].value) = atoi(value);
3118 + printf("%s: Option %s need an argument\n",
3119 + __FUNCTION__, name);
3122 + case IPKG_OPT_TYPE_STRING:
3124 + *((char **)options[i].value) = strdup(value);
3127 + printf("%s: Option %s need an argument\n",
3128 + __FUNCTION__, name);
3136 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3137 + __FUNCTION__, name, value);
3141 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3143 + pkg_dest_list_elt_t *iter;
3150 + if (conf->noaction)
3152 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3153 + dest = iter->data;
3154 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3155 + if (dest->status_file == NULL) {
3156 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3157 + __FUNCTION__, dest->status_file_name, strerror(errno));
3161 + all = pkg_vec_alloc();
3162 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3164 + for(i = 0; i < all->len; i++) {
3165 + pkg = all->pkgs[i];
3166 + /* We don't need most uninstalled packages in the status file */
3167 + if (pkg->state_status == SS_NOT_INSTALLED
3168 + && (pkg->state_want == SW_UNKNOWN
3169 + || pkg->state_want == SW_DEINSTALL
3170 + || pkg->state_want == SW_PURGE)) {
3174 + fprintf(stderr, "Null package\n");
3176 + if (pkg->dest == NULL) {
3177 + fprintf(stderr, "%s: ERROR: Can't write status for "
3178 + "package %s since it has a NULL dest\n",
3179 + __FUNCTION__, pkg->name);
3182 + if (pkg->dest->status_file) {
3183 + pkg_print_status(pkg, pkg->dest->status_file);
3187 + pkg_vec_free(all);
3189 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3190 + dest = iter->data;
3191 + if (dest->status_file) {
3192 + err = ferror(dest->status_file);
3193 + fclose(dest->status_file);
3194 + dest->status_file = NULL;
3196 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3198 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3199 + "retaining old %s\n", __FUNCTION__,
3200 + dest->status_file_tmp_name, dest->status_file_name);
3209 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3211 + char *root_filename;
3212 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3213 + return root_filename;
3215 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
3216 --- busybox-1.2.0-orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
3217 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_conf.h 2006-07-22 16:31:25.000000000 +0200
3219 +/* ipkg_conf.h - the itsy package management system
3223 + Copyright (C) 2001 University of Southern California
3225 + This program is free software; you can redistribute it and/or
3226 + modify it under the terms of the GNU General Public License as
3227 + published by the Free Software Foundation; either version 2, or (at
3228 + your option) any later version.
3230 + This program is distributed in the hope that it will be useful, but
3231 + WITHOUT ANY WARRANTY; without even the implied warranty of
3232 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3233 + General Public License for more details.
3236 +#ifndef IPKG_CONF_H
3237 +#define IPKG_CONF_H
3239 +typedef struct ipkg_conf ipkg_conf_t;
3241 +#include "hash_table.h"
3245 +#include "pkg_hash.h"
3246 +#include "pkg_src_list.h"
3247 +#include "pkg_dest_list.h"
3248 +#include "nv_pair_list.h"
3250 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3251 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3252 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3253 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3255 +/* In case the config file defines no dest */
3256 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3257 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3259 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3263 + pkg_src_list_t pkg_src_list;
3264 + pkg_dest_list_t pkg_dest_list;
3265 + nv_pair_list_t arch_list;
3267 + int restrict_to_default_dest;
3268 + pkg_dest_t *default_dest;
3271 + const char *lists_dir;
3272 + const char *pending_dir;
3275 + int force_depends;
3276 + int force_defaults;
3277 + int force_overwrite;
3278 + int force_downgrade;
3279 + int force_reinstall;
3281 + int force_removal_of_dependent_packages;
3282 + int force_removal_of_essential_packages;
3283 + int nodeps; /* do not follow dependences */
3285 + int multiple_providers;
3286 + char *offline_root;
3287 + char *offline_root_pre_script_cmd;
3288 + char *offline_root_post_script_cmd;
3293 + /* proxy options */
3298 + char *proxy_passwd;
3300 + hash_table_t pkg_hash;
3301 + hash_table_t file_hash;
3302 + hash_table_t obs_file_hash;
3305 +enum ipkg_option_type {
3306 + IPKG_OPT_TYPE_BOOL,
3307 + IPKG_OPT_TYPE_INT,
3308 + IPKG_OPT_TYPE_STRING
3310 +typedef enum ipkg_option_type ipkg_option_type_t;
3312 +typedef struct ipkg_option ipkg_option_t;
3313 +struct ipkg_option {
3315 + const ipkg_option_type_t type;
3316 + const void *value;
3319 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3320 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3322 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3323 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3326 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
3327 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
3328 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.c 2006-07-22 16:31:25.000000000 +0200
3330 +/* ipkg_configure.c - the itsy package management system
3334 + Copyright (C) 2001 University of Southern California
3336 + This program is free software; you can redistribute it and/or
3337 + modify it under the terms of the GNU General Public License as
3338 + published by the Free Software Foundation; either version 2, or (at
3339 + your option) any later version.
3341 + This program is distributed in the hope that it will be useful, but
3342 + WITHOUT ANY WARRANTY; without even the implied warranty of
3343 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3344 + General Public License for more details.
3349 +#include "ipkg_configure.h"
3351 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3355 + /* DPKG_INCOMPATIBILITY:
3356 + dpkg actually does some conffile handling here, rather than at the
3357 + end of ipkg_install(). Do we care? */
3358 + /* DPKG_INCOMPATIBILITY:
3359 + dpkg actually includes a version number to this script call */
3360 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3362 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3366 + ipkg_state_changed++;
3370 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
3371 --- busybox-1.2.0-orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
3372 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_configure.h 2006-07-22 16:31:25.000000000 +0200
3374 +/* ipkg_configure.h - the itsy package management system
3378 + Copyright (C) 2001 University of Southern California
3380 + This program is free software; you can redistribute it and/or
3381 + modify it under the terms of the GNU General Public License as
3382 + published by the Free Software Foundation; either version 2, or (at
3383 + your option) any later version.
3385 + This program is distributed in the hope that it will be useful, but
3386 + WITHOUT ANY WARRANTY; without even the implied warranty of
3387 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3388 + General Public License for more details.
3391 +#ifndef IPKG_CONFIGURE_H
3392 +#define IPKG_CONFIGURE_H
3394 +#include "ipkg_conf.h"
3396 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3399 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
3400 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
3401 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.c 2006-07-22 16:31:25.000000000 +0200
3403 +/* ipkg_download.c - the itsy package management system
3407 + Copyright (C) 2001 University of Southern California
3409 + This program is free software; you can redistribute it and/or
3410 + modify it under the terms of the GNU General Public License as
3411 + published by the Free Software Foundation; either version 2, or (at
3412 + your option) any later version.
3414 + This program is distributed in the hope that it will be useful, but
3415 + WITHOUT ANY WARRANTY; without even the implied warranty of
3416 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3417 + General Public License for more details.
3421 +#include "ipkg_download.h"
3422 +#include "ipkg_message.h"
3424 +#include "sprintf_alloc.h"
3425 +#include "xsystem.h"
3426 +#include "file_util.h"
3427 +#include "str_util.h"
3429 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3433 + char *src_basec = strdup(src);
3434 + char *src_base = basename(src_basec);
3435 + char *tmp_file_location;
3438 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3442 + if (str_starts_with(src, "file:")) {
3444 + const char *file_src = src + 5;
3445 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3446 + ret = file_copy(src + 5, dest_file_name);
3447 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3451 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3452 + err = unlink(tmp_file_location);
3453 + if (err && errno != ENOENT) {
3454 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3455 + __FUNCTION__, tmp_file_location, strerror(errno));
3456 + free(tmp_file_location);
3460 + if (conf->http_proxy) {
3461 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3462 + setenv("http_proxy", conf->http_proxy, 1);
3464 + if (conf->ftp_proxy) {
3465 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3466 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3468 + if (conf->no_proxy) {
3469 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3470 + setenv("no_proxy", conf->no_proxy, 1);
3473 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3474 + sprintf_alloc(&cmd, "wget %s -P %s %s",
3475 + conf->verbose_wget ? "" : "-q",
3478 + err = xsystem(cmd);
3481 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3482 + __FUNCTION__, err, cmd);
3484 + unlink(tmp_file_location);
3485 + free(tmp_file_location);
3492 + err = file_move(tmp_file_location, dest_file_name);
3494 + free(tmp_file_location);
3504 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3509 + if (pkg->src == NULL) {
3510 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3511 + pkg->name, pkg->parent->name);
3515 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3517 + /* XXX: BUG: The pkg->filename might be something like
3518 + "../../foo.ipk". While this is correct, and exactly what we
3519 + want to use to construct url above, here we actually need to
3520 + use just the filename part, without any directory. */
3521 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3523 + err = ipkg_download(conf, url, pkg->local_filename);
3530 + * Downloads file from url, installs in package database, return package name.
3532 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3540 + if (str_starts_with(url, "http://")
3541 + || str_starts_with(url, "ftp://")) {
3543 + char *file_basec = strdup(url);
3544 + char *file_base = basename(file_basec);
3546 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3547 + err = ipkg_download(conf, url, tmp_file);
3551 + err = pkg_init_from_file(pkg, tmp_file);
3554 + pkg->local_filename = strdup(tmp_file);
3559 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3560 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3562 + err = pkg_init_from_file(pkg, url);
3565 + pkg->local_filename = strdup(url);
3566 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3567 + pkg->provided_by_hand = 1;
3575 + if (!pkg->architecture) {
3576 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3580 + pkg->dest = conf->default_dest;
3581 + pkg->state_want = SW_INSTALL;
3582 + pkg->state_flag |= SF_PREFER;
3583 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3584 + if ( pkg == NULL ){
3585 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3589 + *namep = strdup(pkg->name);
3593 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
3594 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3595 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-07-22 16:31:25.000000000 +0200
3597 +/* ipkg_download.h - the itsy package management system
3601 + Copyright (C) 2001 University of Southern California
3603 + This program is free software; you can redistribute it and/or
3604 + modify it under the terms of the GNU General Public License as
3605 + published by the Free Software Foundation; either version 2, or (at
3606 + your option) any later version.
3608 + This program is distributed in the hope that it will be useful, but
3609 + WITHOUT ANY WARRANTY; without even the implied warranty of
3610 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3611 + General Public License for more details.
3614 +#ifndef IPKG_DOWNLOAD_H
3615 +#define IPKG_DOWNLOAD_H
3617 +#include "ipkg_conf.h"
3619 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3620 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3622 + * Downloads file from url, installs in package database, return package name.
3624 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3627 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h
3628 --- busybox-1.2.0-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3629 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h 2006-07-22 16:31:25.000000000 +0200
3631 +/* ipkg.h - the itsy package management system
3635 + Copyright (C) 2001 University of Southern California
3637 + This program is free software; you can redistribute it and/or
3638 + modify it under the terms of the GNU General Public License as
3639 + published by the Free Software Foundation; either version 2, or (at
3640 + your option) any later version.
3642 + This program is distributed in the hope that it will be useful, but
3643 + WITHOUT ANY WARRANTY; without even the implied warranty of
3644 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3645 + General Public License for more details.
3652 +#ifdef HAVE_CONFIG_H
3653 +#include "config.h"
3658 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3661 +#include "ipkg_includes.h"
3662 +#include "ipkg_conf.h"
3663 +#include "ipkg_message.h"
3665 +#define IPKG_PKG_EXTENSION ".ipk"
3666 +#define DPKG_PKG_EXTENSION ".deb"
3668 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3669 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3671 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3672 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3673 +#define IPKG_INFO_DIR_SUFFIX "info"
3674 +#define IPKG_STATUS_FILE_SUFFIX "status"
3676 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3678 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3680 +#define IPKG_VERSION "0.99.162"
3685 + IPKG_PKG_DEPS_UNSATISFIED,
3686 + IPKG_PKG_IS_ESSENTIAL,
3687 + IPKG_PKG_HAS_DEPENDENTS,
3688 + IPKG_PKG_HAS_NO_CANDIDATE
3690 +typedef enum ipkg_error ipkg_error_t;
3692 +extern int ipkg_state_changed;
3697 + struct errlist * next;
3700 +extern struct errlist* error_list;
3702 +extern ipkg_conf_t *global_conf;
3705 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
3706 --- busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3707 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-07-22 16:31:25.000000000 +0200
3709 +#ifndef IPKG_INCLUDES_H
3710 +#define IPKG_INCLUDES_H
3712 +/* Define to 1 if you have the <memory.h> header file. */
3713 +#define HAVE_MEMORY_H 1
3715 +/* Define to 1 if you have the <regex.h> header file. */
3716 +#define HAVE_REGEX_H 1
3718 +/* Define to 1 if you have the <stdlib.h> header file. */
3719 +#define HAVE_STDLIB_H 1
3721 +/* Define to 1 if you have the <strings.h> header file. */
3722 +#define HAVE_STRINGS_H 1
3724 +/* Define to 1 if you have the <string.h> header file. */
3725 +#define HAVE_STRING_H 1
3727 +/* Define to 1 if you have the <sys/stat.h> header file. */
3728 +#define HAVE_SYS_STAT_H 1
3730 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3731 +#define HAVE_SYS_WAIT_H 1
3733 +/* Define to 1 if you have the <unistd.h> header file. */
3734 +#define HAVE_UNISTD_H 1
3736 +/* Define to 1 if you have the ANSI C header files. */
3737 +#define STDC_HEADERS 1
3743 +# include <stdlib.h>
3744 +# include <stdarg.h>
3745 +# include <stddef.h>
3746 +# include <ctype.h>
3747 +# include <errno.h>
3750 +# include <stdlib.h>
3755 +# include <regex.h>
3759 +# if !STDC_HEADERS && HAVE_MEMORY_H
3760 +# include <memory.h>
3762 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3764 +# define __USE_GNU 1
3766 +# include <string.h>
3771 +# include <strings.h>
3774 +#if HAVE_SYS_STAT_H
3775 +# include <sys/stat.h>
3778 +#if HAVE_SYS_WAIT_H
3779 +# include <sys/wait.h>
3783 +# include <sys/types.h>
3784 +# include <unistd.h>
3787 +#endif /* IPKG_INCLUDES_H */
3788 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
3789 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3790 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-07-22 16:31:25.000000000 +0200
3792 +/* ipkg_install.c - the itsy package management system
3796 + Copyright (C) 2001 University of Southern California
3798 + This program is free software; you can redistribute it and/or
3799 + modify it under the terms of the GNU General Public License as
3800 + published by the Free Software Foundation; either version 2, or (at
3801 + your option) any later version.
3803 + This program is distributed in the hope that it will be useful, but
3804 + WITHOUT ANY WARRANTY; without even the implied warranty of
3805 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3806 + General Public License for more details.
3811 +#include <dirent.h>
3814 +#include <signal.h>
3815 +typedef void (*sighandler_t)(int);
3818 +#include "pkg_hash.h"
3819 +#include "pkg_extract.h"
3821 +#include "ipkg_install.h"
3822 +#include "ipkg_configure.h"
3823 +#include "ipkg_download.h"
3824 +#include "ipkg_remove.h"
3826 +#include "ipkg_utils.h"
3827 +#include "ipkg_message.h"
3829 +#include "sprintf_alloc.h"
3830 +#include "file_util.h"
3831 +#include "str_util.h"
3832 +#include "xsystem.h"
3835 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3836 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3837 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3839 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3840 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3841 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3842 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3843 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3844 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3847 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3848 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3849 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3850 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3851 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3853 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3854 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3855 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3856 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3857 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3859 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3861 +static int user_prefers_old_conffile(const char *file, const char *backup);
3863 +static char *backup_filename_alloc(const char *file_name);
3864 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3865 +static int backup_exists_for(const char *file_name);
3866 +static int backup_remove(const char *file_name);
3869 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3873 + char *old_version, *new_version;
3876 + if (pkg == NULL) {
3880 + err = pkg_init_from_file(pkg, filename);
3885 + if (!pkg->architecture) {
3886 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3890 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3891 + freeing the pkg that we pass in. It might be nice to clean this up
3893 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3894 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3896 + pkg->local_filename = strdup(filename);
3899 + old_version = pkg_version_str_alloc(old);
3900 + new_version = pkg_version_str_alloc(pkg);
3902 + cmp = pkg_compare_versions(old, pkg);
3903 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3904 + cmp = -1 ; /* then we force ipkg to downgrade */
3905 + /* We need to use a value < 0 because in the 0 case we are asking to */
3906 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3909 + ipkg_message(conf, IPKG_NOTICE,
3910 + "Not downgrading package %s on %s from %s to %s.\n",
3911 + old->name, old->dest->name, old_version, new_version);
3912 + pkg->state_want = SW_DEINSTALL;
3913 + pkg->state_flag |= SF_OBSOLETE;
3914 + free(old_version);
3915 + free(new_version);
3918 + free(old_version);
3919 + free(new_version);
3923 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3924 + return ipkg_install_pkg(conf, pkg,0);
3927 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3931 + char *old_version, *new_version;
3933 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3934 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3936 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3938 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3939 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3941 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3943 +/* Pigi Basically here is broken the version stuff.
3944 + What's happening is that nothing provide the version to differents
3945 + functions, so the returned struct is always the latest.
3946 + That's why the install by name don't work.
3948 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3951 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3953 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3954 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3956 + if (new == NULL) {
3957 + return IPKG_PKG_HAS_NO_CANDIDATE;
3960 + new->state_flag |= SF_USER;
3962 + old_version = pkg_version_str_alloc(old);
3963 + new_version = pkg_version_str_alloc(new);
3965 + cmp = pkg_compare_versions(old, new);
3966 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3967 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3968 + cmp = -1 ; /* then we force ipkg to downgrade */
3969 + /* We need to use a value < 0 because in the 0 case we are asking to */
3970 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3972 + ipkg_message(conf, IPKG_DEBUG,
3973 + "Comparing visible versions of pkg %s:"
3974 + "\n\t%s is installed "
3975 + "\n\t%s is available "
3976 + "\n\t%d was comparison result\n",
3977 + pkg_name, old_version, new_version, cmp);
3978 + if (cmp == 0 && !conf->force_reinstall) {
3979 + ipkg_message(conf, IPKG_NOTICE,
3980 + "Package %s (%s) installed in %s is up to date.\n",
3981 + old->name, old_version, old->dest->name);
3982 + free(old_version);
3983 + free(new_version);
3985 + } else if (cmp > 0) {
3986 + ipkg_message(conf, IPKG_NOTICE,
3987 + "Not downgrading package %s on %s from %s to %s.\n",
3988 + old->name, old->dest->name, old_version, new_version);
3989 + free(old_version);
3990 + free(new_version);
3992 + } else if (cmp < 0) {
3993 + new->dest = old->dest;
3994 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3998 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3999 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4000 + return any kind of integer, (might be errno from a syscall,
4001 + etc.). This is a real mess and will need to be cleaned up if
4002 + anyone ever wants to make a nice libipkg. */
4004 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4005 + return ipkg_install_pkg(conf, new,0);
4008 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4010 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4013 + abstract_pkg_t *ppkg ;
4015 + if (providers == NULL)
4016 + return IPKG_PKG_HAS_NO_CANDIDATE;
4018 + for (i = 0; i < providers->len; i++) {
4019 + ppkg = abstract_pkg_vec_get(providers, i);
4020 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4021 + err = ipkg_install_by_name(conf, ppkg->name);
4024 +/* XXX Maybe ppkg should be freed ? */
4030 + * Walk dependence graph starting with pkg, collect packages to be
4031 + * installed into pkgs_needed, in dependence order.
4033 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4036 + pkg_vec_t *depends = pkg_vec_alloc();
4037 + char **unresolved = NULL;
4040 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4045 + ipkg_message(conf, IPKG_ERROR,
4046 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4047 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4048 + while (*unresolved) {
4049 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4052 + ipkg_message(conf, IPKG_ERROR, "\n");
4053 + if (! conf->force_depends) {
4054 + ipkg_message(conf, IPKG_INFO,
4055 + "This could mean that your package list is out of date or that the packages\n"
4056 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4057 + "of this problem try again with the '-force-depends' option.\n");
4058 + pkg_vec_free(depends);
4059 + return IPKG_PKG_DEPS_UNSATISFIED;
4063 + if (ndepends <= 0) {
4064 + pkg_vec_free(depends);
4068 + for (i = 0; i < depends->len; i++) {
4069 + pkg_t *dep = depends->pkgs[i];
4070 + /* The package was uninstalled when we started, but another
4071 + dep earlier in this loop may have depended on it and pulled
4072 + it in, so check first. */
4073 + if ((dep->state_status != SS_INSTALLED)
4074 + && (dep->state_status != SS_UNPACKED)
4075 + && (dep->state_want != SW_INSTALL)) {
4077 + /* Mark packages as to-be-installed */
4078 + dep->state_want = SW_INSTALL;
4080 + /* Dependencies should be installed the same place as pkg */
4081 + if (dep->dest == NULL) {
4082 + dep->dest = pkg->dest;
4085 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4087 + pkg_vec_free(depends);
4093 + pkg_vec_insert(pkgs_needed, pkg);
4095 + pkg_vec_free(depends);
4100 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4104 + char *old_version, *new_version;
4106 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4108 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4109 + if (new == NULL) {
4110 + return IPKG_PKG_HAS_NO_CANDIDATE;
4113 + old_version = pkg_version_str_alloc(old);
4114 + new_version = pkg_version_str_alloc(new);
4116 + cmp = pkg_compare_versions(old, new);
4117 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4118 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4119 + cmp = -1 ; /* then we force ipkg to downgrade */
4120 + /* We need to use a value < 0 because in the 0 case we are asking to */
4121 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4123 + ipkg_message(conf, IPKG_DEBUG,
4124 + "comparing visible versions of pkg %s:"
4125 + "\n\t%s is installed "
4126 + "\n\t%s is available "
4127 + "\n\t%d was comparison result\n",
4128 + pkg_name, old_version, new_version, cmp);
4129 + if (cmp == 0 && !conf->force_reinstall) {
4130 + ipkg_message(conf, IPKG_NOTICE,
4131 + "Package %s (%s) installed in %s is up to date.\n",
4132 + old->name, old_version, old->dest->name);
4133 + free(old_version);
4134 + free(new_version);
4136 + } else if (cmp > 0) {
4137 + ipkg_message(conf, IPKG_NOTICE,
4138 + "Not downgrading package %s on %s from %s to %s.\n",
4139 + old->name, old->dest->name, old_version, new_version);
4140 + free(old_version);
4141 + free(new_version);
4143 + } else if (cmp < 0) {
4144 + new->dest = old->dest;
4145 + old->state_want = SW_DEINSTALL;
4146 + old->state_flag |= SF_OBSOLETE;
4149 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4154 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4157 + pkg_vec_t *depends = pkg_vec_alloc();
4159 + char **unresolved = NULL;
4162 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4167 + ipkg_message(conf, IPKG_ERROR,
4168 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4169 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4170 + while (*unresolved) {
4171 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4174 + ipkg_message(conf, IPKG_ERROR, "\n");
4175 + if (! conf->force_depends) {
4176 + ipkg_message(conf, IPKG_INFO,
4177 + "This could mean that your package list is out of date or that the packages\n"
4178 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4179 + "of this problem try again with the '-force-depends' option.\n");
4180 + pkg_vec_free(depends);
4181 + return IPKG_PKG_DEPS_UNSATISFIED;
4185 + if (ndepends <= 0) {
4189 + /* Mark packages as to-be-installed */
4190 + for (i=0; i < depends->len; i++) {
4191 + /* Dependencies should be installed the same place as pkg */
4192 + if (depends->pkgs[i]->dest == NULL) {
4193 + depends->pkgs[i]->dest = pkg->dest;
4195 + depends->pkgs[i]->state_want = SW_INSTALL;
4198 + for (i = 0; i < depends->len; i++) {
4199 + dep = depends->pkgs[i];
4200 + /* The package was uninstalled when we started, but another
4201 + dep earlier in this loop may have depended on it and pulled
4202 + it in, so check first. */
4203 + if ((dep->state_status != SS_INSTALLED)
4204 + && (dep->state_status != SS_UNPACKED)) {
4205 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4206 + err = ipkg_install_pkg(conf, dep,0);
4208 + pkg_vec_free(depends);
4214 + pkg_vec_free(depends);
4220 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4221 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4223 + if (conf->nodeps == 0) {
4225 + pkg_vec_t *installed = pkg_vec_alloc();
4226 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4227 + for (i = 0; i < installed->len; i++) {
4228 + pkg_t *pkg = installed->pkgs[i];
4229 + satisfy_dependencies_for(conf, pkg);
4231 + pkg_vec_free(installed);
4238 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4241 + pkg_vec_t *conflicts = NULL;
4243 + const char *prefix;
4244 + if (conf->force_depends) {
4245 + level = IPKG_NOTICE;
4246 + prefix = "Warning";
4248 + level = IPKG_ERROR;
4252 + if (!conf->force_depends)
4253 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4256 + ipkg_message(conf, level,
4257 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4259 + while (i < conflicts->len)
4260 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4261 + ipkg_message(conf, level, "\n");
4262 + pkg_vec_free(conflicts);
4263 + return IPKG_PKG_DEPS_UNSATISFIED;
4268 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4270 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4271 + str_list_elt_t *iter;
4273 + for (iter = new_list->head; iter; iter = iter->next) {
4274 + char *new_file = iter->data;
4275 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4277 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4278 + if (!owner || (owner == old_pkg))
4279 + file_hash_set_file_owner(conf, new_file, new_pkg);
4282 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4283 + for (iter = old_list->head; iter; iter = iter->next) {
4284 + char *old_file = iter->data;
4285 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4286 + if (owner == old_pkg) {
4288 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4295 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4297 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4299 + /* sma 6.20.02: yup; here's the first bit */
4301 + * XXX: BUG easy for cworth
4302 + * 1) please point the call below to the correct current root destination
4303 + * 2) we need to resolve how to check the required space for a pending pkg,
4304 + * my diddling with the .ipk file size below isn't going to cut it.
4305 + * 3) return a proper error code instead of 1
4307 + int comp_size, blocks_available;
4309 + if (!conf->force_space && pkg->installed_size != NULL) {
4310 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4312 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4313 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4314 + comp_size = (int)((comp_size + 1023) / 1024);
4316 + if (comp_size >= blocks_available) {
4317 + ipkg_message(conf, IPKG_ERROR,
4318 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4319 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4326 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4329 + char *conffiles_file_name;
4331 + FILE *conffiles_file;
4333 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4335 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4336 + if (pkg->tmp_unpack_dir == NULL) {
4337 + ipkg_message(conf, IPKG_ERROR,
4338 + "%s: Failed to create temporary directory '%s': %s\n",
4339 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4343 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4348 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4349 + conffiles. Seems like I should be able to get everything to go
4350 + through pkg_init_from_file. If so, maybe it would make sense to
4351 + move all of unpack_pkg_control_files to that function. */
4353 + /* Don't need to re-read conffiles if we already have it */
4354 + if (pkg->conffiles.head) {
4358 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4359 + if (! file_exists(conffiles_file_name)) {
4360 + free(conffiles_file_name);
4364 + conffiles_file = fopen(conffiles_file_name, "r");
4365 + if (conffiles_file == NULL) {
4366 + fprintf(stderr, "%s: failed to open %s: %s\n",
4367 + __FUNCTION__, conffiles_file_name, strerror(errno));
4368 + free(conffiles_file_name);
4371 + free(conffiles_file_name);
4375 + char *cf_name_in_dest;
4377 + cf_name = file_read_line_alloc(conffiles_file);
4378 + if (cf_name == NULL) {
4381 + str_chomp(cf_name);
4382 + if (cf_name[0] == '\0') {
4386 + /* Prepend dest->root_dir to conffile name.
4387 + Take pains to avoid multiple slashes. */
4388 + root_dir = pkg->dest->root_dir;
4389 + if (conf->offline_root)
4390 + /* skip the offline_root prefix */
4391 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4392 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4393 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4395 + /* Can't get an md5sum now, (file isn't extracted yet).
4396 + We'll wait until resolve_conffiles */
4397 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4400 + free(cf_name_in_dest);
4403 + fclose(conffiles_file);
4408 +/* returns number of installed replacees */
4409 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4411 + abstract_pkg_t **replaces = pkg->replaces;
4412 + int replaces_count = pkg->replaces_count;
4414 + for (i = 0; i < replaces_count; i++) {
4415 + abstract_pkg_t *ab_pkg = replaces[i];
4416 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4418 + for (j = 0; j < pkg_vec->len; j++) {
4419 + pkg_t *replacee = pkg_vec->pkgs[j];
4420 + if (!pkg_conflicts(pkg, replacee))
4422 + if (replacee->state_status == SS_INSTALLED) {
4423 + pkg_vec_insert(installed_replacees, replacee);
4428 + return installed_replacees->len;
4431 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4434 + int replaces_count = replacees->len;
4435 + for (i = 0; i < replaces_count; i++) {
4436 + pkg_t *replacee = replacees->pkgs[i];
4438 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4439 + err = ipkg_remove_pkg(conf, replacee,0);
4446 +/* to unwind the removal: make sure they are installed */
4447 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4450 + int replaces_count = replacees->len;
4451 + for (i = 0; i < replaces_count; i++) {
4452 + pkg_t *replacee = replacees->pkgs[i];
4453 + if (replacee->state_status != SS_INSTALLED) {
4454 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4455 + err = ipkg_install_pkg(conf, replacee,0);
4463 +int caught_sigint = 0;
4464 +static void ipkg_install_pkg_sigint_handler(int sig)
4466 + caught_sigint = sig;
4469 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4470 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4473 + char message_out[15];
4474 + char *old_version = pkg_version_str_alloc(old_pkg);
4475 + char *new_version = pkg_version_str_alloc(pkg);
4476 + int cmp = pkg_compare_versions(old_pkg, pkg);
4479 + memset(message_out,'\x0',15);
4480 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4481 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4482 + cmp = -1 ; /* then we force ipkg to downgrade */
4483 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4484 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4488 + ipkg_message(conf, IPKG_NOTICE,
4489 + "Not downgrading package %s on %s from %s to %s.\n",
4490 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4492 + } else if (cmp < 0) {
4493 + ipkg_message(conf, IPKG_NOTICE,
4494 + "%s%s on %s from %s to %s...\n",
4495 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4496 + pkg->dest = old_pkg->dest;
4498 + } else /* cmp == 0 */ {
4499 + if (conf->force_reinstall) {
4500 + ipkg_message(conf, IPKG_NOTICE,
4501 + "Reinstalling %s (%s) on %s...\n",
4502 + pkg->name, new_version, old_pkg->dest->name);
4503 + pkg->dest = old_pkg->dest;
4506 + ipkg_message(conf, IPKG_NOTICE,
4507 + "Not installing %s (%s) on %s -- already installed.\n",
4508 + pkg->name, new_version, old_pkg->dest->name);
4512 + free(old_version);
4513 + free(new_version);
4516 + char message_out[15] ;
4517 + memset(message_out,'\x0',15);
4519 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4521 + strncpy( message_out,"Installing ",strlen("Installing ") );
4522 + char *version = pkg_version_str_alloc(pkg);
4524 + ipkg_message(conf, IPKG_NOTICE,
4525 + "%s%s (%s) to %s...\n", message_out,
4526 + pkg->name, version, pkg->dest->name);
4532 +/* and now the meat... */
4533 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4537 + pkg_t *old_pkg = NULL;
4538 + pkg_vec_t *replacees;
4539 + abstract_pkg_t *ab_pkg = NULL;
4540 + int old_state_flag;
4544 + if ( from_upgrade )
4545 + message = 1; /* Coming from an upgrade, and should change the output message */
4548 + ipkg_message(conf, IPKG_ERROR,
4549 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4553 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4555 + if (!pkg_arch_supported(conf, pkg)) {
4556 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4557 + pkg->architecture, pkg->name);
4560 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4561 + err = satisfy_dependencies_for(conf, pkg);
4562 + if (err) { return err; }
4564 + ipkg_message(conf, IPKG_NOTICE,
4565 + "Package %s is already installed in %s.\n",
4566 + pkg->name, pkg->dest->name);
4570 + if (pkg->dest == NULL) {
4571 + pkg->dest = conf->default_dest;
4574 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4576 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4577 + if (err) { return err; }
4579 + pkg->state_want = SW_INSTALL;
4581 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4585 + /* Abhaya: conflicts check */
4586 + err = check_conflicts_for(conf, pkg);
4587 + if (err) { return err; }
4589 + /* this setup is to remove the upgrade scenario in the end when
4590 + installing pkg A, A deps B & B deps on A. So both B and A are
4591 + installed. Then A's installation is started resulting in an
4592 + uncecessary upgrade */
4593 + if (pkg->state_status == SS_INSTALLED
4594 + && conf->force_reinstall == 0) return 0;
4596 + err = verify_pkg_installable(conf, pkg);
4597 + if (err) { return err; }
4599 + if (pkg->local_filename == NULL) {
4600 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4602 + ipkg_message(conf, IPKG_ERROR,
4603 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4609 +/* Check for md5 values */
4612 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4613 + if (strcmp(file_md5, pkg->md5sum))
4615 + ipkg_message(conf, IPKG_ERROR,
4616 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4624 + if (pkg->tmp_unpack_dir == NULL) {
4625 + unpack_pkg_control_files(conf, pkg);
4628 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4629 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4630 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4631 + err = update_file_ownership(conf, pkg, old_pkg);
4632 + if (err) { return err; }
4634 + if (conf->nodeps == 0) {
4635 + err = satisfy_dependencies_for(conf, pkg);
4636 + if (err) { return err; }
4639 + replacees = pkg_vec_alloc();
4640 + pkg_get_installed_replacees(conf, pkg, replacees);
4642 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4644 + sigset_t newset, oldset;
4645 + sighandler_t old_handler = NULL;
4646 + int use_signal = 0;
4647 + caught_sigint = 0;
4649 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4651 + sigemptyset(&newset);
4652 + sigaddset(&newset, SIGINT);
4653 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4656 + ipkg_state_changed++;
4657 + pkg->state_flag |= SF_FILELIST_CHANGED;
4659 + /* XXX: BUG: we really should treat replacement more like an upgrade
4660 + * Instead, we're going to remove the replacees
4662 + err = pkg_remove_installed_replacees(conf, replacees);
4663 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4665 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4666 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4668 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4669 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4671 + err = preinst_configure(conf, pkg, old_pkg);
4672 + if (err) goto UNWIND_PREINST_CONFIGURE;
4674 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4675 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4677 + err = check_data_file_clashes(conf, pkg, old_pkg);
4678 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4680 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4681 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4683 + if (conf->noaction) return 0;
4685 + /* point of no return: no unwinding after this */
4686 + if (old_pkg && !conf->force_reinstall) {
4687 + old_pkg->state_want = SW_DEINSTALL;
4689 + if (old_pkg->state_flag & SF_NOPRUNE) {
4690 + ipkg_message(conf, IPKG_INFO,
4691 + " not removing obsolesced files because package marked noprune\n");
4693 + ipkg_message(conf, IPKG_INFO,
4694 + " removing obsolesced files\n");
4695 + remove_obsolesced_files(conf, pkg, old_pkg);
4697 + /* removing files from old package, to avoid ghost files */
4698 + remove_data_files_and_list(conf, old_pkg);
4699 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4700 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4701 + remove_postrm(conf, old_pkg);
4707 + ipkg_message(conf, IPKG_INFO,
4708 + " installing maintainer scripts\n");
4709 + install_maintainer_scripts(conf, pkg, old_pkg);
4711 + /* the following just returns 0 */
4712 + remove_disappeared(conf, pkg);
4714 + ipkg_message(conf, IPKG_INFO,
4715 + " installing data files\n");
4716 + install_data_files(conf, pkg);
4718 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4719 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4721 + ipkg_message(conf, IPKG_INFO,
4722 + " resolving conf files\n");
4723 + resolve_conffiles(conf, pkg);
4725 + pkg->state_status = SS_UNPACKED;
4726 + old_state_flag = pkg->state_flag;
4727 + pkg->state_flag &= ~SF_PREFER;
4728 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4730 + if (old_pkg && !conf->force_reinstall) {
4731 + old_pkg->state_status = SS_NOT_INSTALLED;
4734 + time(&pkg->installed_time);
4736 + ipkg_message(conf, IPKG_INFO,
4737 + " cleanup temp files\n");
4738 + cleanup_temporary_files(conf, pkg);
4740 + ab_pkg = pkg->parent;
4742 + ab_pkg->state_status = pkg->state_status;
4744 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4747 + signal(SIGINT, old_handler);
4749 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4754 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4755 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4756 + UNWIND_CHECK_DATA_FILE_CLASHES:
4757 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4758 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4759 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4760 + UNWIND_PREINST_CONFIGURE:
4761 + preinst_configure_unwind(conf, pkg, old_pkg);
4762 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4763 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4764 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4765 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4766 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4767 + pkg_remove_installed_replacees_unwind(conf, replacees);
4769 + ipkg_message(conf, IPKG_INFO,
4770 + " cleanup temp files\n");
4771 + cleanup_temporary_files(conf, pkg);
4773 + ipkg_message(conf, IPKG_INFO,
4776 + signal(SIGINT, old_handler);
4778 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4784 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4786 + /* DPKG_INCOMPATIBILITY:
4787 + dpkg does some things here that we don't do yet. Do we care?
4789 + 1. If a version of the package is already installed, call
4790 + old-prerm upgrade new-version
4791 + 2. If the script runs but exits with a non-zero exit status
4792 + new-prerm failed-upgrade old-version
4793 + Error unwind, for both the above cases:
4794 + old-postinst abort-upgrade new-version
4799 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4801 + /* DPKG_INCOMPATIBILITY:
4802 + dpkg does some things here that we don't do yet. Do we care?
4803 + (See prerm_upgrade_old_package for details)
4808 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4810 + /* DPKG_INCOMPATIBILITY:
4811 + dpkg does some things here that we don't do yet. Do we care?
4812 + 2. If a 'conflicting' package is being removed at the same time:
4813 + 1. If any packages depended on that conflicting package and
4814 + --auto-deconfigure is specified, call, for each such package:
4815 + deconfigured's-prerm deconfigure \
4816 + in-favour package-being-installed version \
4817 + removing conflicting-package version
4819 + deconfigured's-postinst abort-deconfigure \
4820 + in-favour package-being-installed-but-failed version \
4821 + removing conflicting-package version
4823 + The deconfigured packages are marked as requiring
4824 + configuration, so that if --install is used they will be
4825 + configured again if possible.
4826 + 2. To prepare for removal of the conflicting package, call:
4827 + conflictor's-prerm remove in-favour package new-version
4829 + conflictor's-postinst abort-remove in-favour package new-version
4834 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4836 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4837 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4842 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4845 + char *preinst_args;
4848 + char *old_version = pkg_version_str_alloc(old_pkg);
4849 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4850 + free(old_version);
4851 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4852 + char *pkg_version = pkg_version_str_alloc(pkg);
4853 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4854 + free(pkg_version);
4856 + preinst_args = strdup("install");
4859 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4861 + ipkg_message(conf, IPKG_ERROR,
4862 + "Aborting installation of %s\n", pkg->name);
4866 + free(preinst_args);
4871 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4873 + /* DPKG_INCOMPATIBILITY:
4874 + dpkg does the following error unwind, should we?
4875 + pkg->postrm abort-upgrade old-version
4876 + OR pkg->postrm abort-install old-version
4877 + OR pkg->postrm abort-install
4882 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4885 + conffile_list_elt_t *iter;
4888 + if (conf->noaction) return 0;
4890 + /* Backup all modified conffiles */
4892 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4896 + cf_name = root_filename_alloc(conf, cf->name);
4898 + /* Don't worry if the conffile is just plain gone */
4899 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4900 + err = backup_make_backup(conf, cf_name);
4909 + /* Backup all conffiles that were not conffiles in old_pkg */
4910 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4913 + cf_name = root_filename_alloc(conf, cf->name);
4914 + /* Ignore if this was a conffile in old_pkg as well */
4915 + if (pkg_get_conffile(old_pkg, cf->name)) {
4919 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4920 + err = backup_make_backup(conf, cf_name);
4931 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4933 + conffile_list_elt_t *iter;
4936 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4937 + backup_remove(iter->data->name);
4941 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4942 + backup_remove(iter->data->name);
4949 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4951 + /* DPKG_INCOMPATIBILITY:
4952 + ipkg takes a slightly different approach than dpkg at this
4953 + point. dpkg installs each file in the new package while
4954 + creating a backup for any file that is replaced, (so that it
4955 + can unwind if necessary). To avoid complexity and redundant
4956 + storage, ipkg doesn't do any installation until later, (at the
4957 + point at which dpkg removes the backups.
4959 + But, we do have to check for data file clashes, since after
4960 + installing a package with a file clash, removing either of the
4961 + packages involved in the clash has the potential to break the
4964 + str_list_t *files_list;
4965 + str_list_elt_t *iter;
4969 + files_list = pkg_get_installed_files(pkg);
4970 + for (iter = files_list->head; iter; iter = iter->next) {
4971 + char *root_filename;
4972 + char *filename = iter->data;
4973 + root_filename = root_filename_alloc(conf, filename);
4974 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4977 + /* Pre-existing conffiles are OK */
4978 + /* @@@@ should have way to check that it is a conffile -Jamey */
4979 + if (backup_exists_for(root_filename)) {
4983 + /* Pre-existing files are OK if force-overwrite was asserted. */
4984 + if (conf->force_overwrite) {
4985 + /* but we need to change who owns this file */
4986 + file_hash_set_file_owner(conf, filename, pkg);
4990 + owner = file_hash_get_file_owner(conf, filename);
4992 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4993 + if (owner && old_pkg) {
4994 + if (strcmp(owner->name, old_pkg->name) == 0) {
4999 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5001 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5002 + if (pkg_replaces(pkg, owner)) {
5005 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5006 + then it's ok to overwrite. */
5007 + if (strcmp(owner->name,pkg->name)==0){
5008 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5013 + /* Pre-existing files are OK if they are obsolete */
5014 + obs = hash_table_get(&conf->obs_file_hash, filename);
5016 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5020 + /* We have found a clash. */
5021 + ipkg_message(conf, IPKG_ERROR,
5022 + "Package %s wants to install file %s\n"
5023 + "\tBut that file is already provided by package ",
5024 + pkg->name, filename);
5026 + ipkg_message(conf, IPKG_ERROR,
5027 + "%s\n", owner->name);
5029 + ipkg_message(conf, IPKG_ERROR,
5030 + "<no package>\nPlease move this file out of the way and try again.\n");
5034 + free(root_filename);
5036 + pkg_free_installed_files(pkg);
5041 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5043 + /* Basically that's the worst hack I could do to be able to change ownership of
5044 + file list, but, being that we have no way to unwind the mods, due to structure
5045 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5046 + What we do here is change the ownership of file in hash if a replace ( or similar events
5048 + Only the action that are needed to change name should be considered.
5049 + @@@ To change after 1.0 release.
5051 + str_list_t *files_list;
5052 + str_list_elt_t *iter;
5056 + files_list = pkg_get_installed_files(pkg);
5057 + for (iter = files_list->head; iter; iter = iter->next) {
5058 + char *root_filename;
5059 + char *filename = iter->data;
5060 + root_filename = root_filename_alloc(conf, filename);
5061 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5064 + if (conf->force_overwrite) {
5065 + /* but we need to change who owns this file */
5066 + file_hash_set_file_owner(conf, filename, pkg);
5070 + owner = file_hash_get_file_owner(conf, filename);
5072 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5074 + if (pkg_replaces(pkg, owner)) {
5075 +/* It's now time to change the owner of that file.
5076 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5077 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5078 + file_hash_set_file_owner(conf, filename, pkg);
5084 + free(root_filename);
5086 + pkg_free_installed_files(pkg);
5091 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5093 + /* Nothing to do since check_data_file_clashes doesn't change state */
5097 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5099 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5100 + 1. If the package is being upgraded, call
5101 + old-postrm upgrade new-version
5102 + 2. If this fails, attempt:
5103 + new-postrm failed-upgrade old-version
5104 + Error unwind, for both cases:
5105 + old-preinst abort-upgrade new-version */
5109 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5111 + /* DPKG_INCOMPATIBILITY:
5112 + dpkg does some things here that we don't do yet. Do we care?
5113 + (See postrm_upgrade_old_pkg for details)
5118 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5121 + str_list_t *old_files;
5122 + str_list_elt_t *of;
5123 + str_list_t *new_files;
5124 + str_list_elt_t *nf;
5126 + if (old_pkg == NULL) {
5130 + old_files = pkg_get_installed_files(old_pkg);
5131 + new_files = pkg_get_installed_files(pkg);
5133 + for (of = old_files->head; of; of = of->next) {
5137 + for (nf = new_files->head; nf; nf = nf->next) {
5139 + if (strcmp(old, new) == 0) {
5140 + goto NOT_OBSOLETE;
5143 + if (file_is_dir(old)) {
5146 + owner = file_hash_get_file_owner(conf, old);
5147 + if (owner != old_pkg) {
5148 + /* in case obsolete file no longer belongs to old_pkg */
5152 + /* old file is obsolete */
5153 + ipkg_message(conf, IPKG_INFO,
5154 + " removing obsolete file %s\n", old);
5155 + if (!conf->noaction) {
5156 + err = unlink(old);
5158 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5167 + pkg_free_installed_files(old_pkg);
5168 + pkg_free_installed_files(pkg);
5173 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5177 + char *globpattern;
5181 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5184 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5185 + err = glob(globpattern, 0, NULL, &globbuf);
5186 + free(globpattern);
5190 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5191 + for (i = 0; i < globbuf.gl_pathc; i++) {
5192 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5193 + globbuf.gl_pathv[i], old_pkg->name);
5194 + if (!conf->noaction)
5195 + unlink(globbuf.gl_pathv[i]);
5197 + globfree(&globbuf);
5202 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5208 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5209 + sprintf_alloc(&prefix, "%s.", pkg->name);
5210 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5211 + pkg->dest->info_dir,
5217 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5219 + /* DPKG_INCOMPATIBILITY:
5220 + This is a fairly sophisticated dpkg operation. Shall we
5223 + /* Any packages all of whose files have been overwritten during the
5224 + installation, and which aren't required for dependencies, are
5225 + considered to have been removed. For each such package
5226 + 1. disappearer's-postrm disappear overwriter overwriter-version
5227 + 2. The package's maintainer scripts are removed
5228 + 3. It is noted in the status database as being in a sane state,
5229 + namely not installed (any conffiles it may have are ignored,
5230 + rather than being removed by dpkg). Note that disappearing
5231 + packages do not have their prerm called, because dpkg doesn't
5232 + know in advance that the package is going to vanish.
5237 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5241 + /* ipkg takes a slightly different approach to data file backups
5242 + than dpkg. Rather than removing backups at this point, we
5243 + actually do the data file installation now. See comments in
5244 + check_data_file_clashes() for more details. */
5246 + ipkg_message(conf, IPKG_INFO,
5247 + " extracting data files to %s\n", pkg->dest->root_dir);
5248 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5253 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5254 + so we can't save ourself from removing important packages
5255 + At this point we (should) have extracted the .control file, so it
5256 + would be a good idea to reload the data in it, and set the Essential
5257 + state in *pkg. From now on the Essential is back in status file and
5258 + we can protect again.
5259 + We should operate this way:
5260 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5261 + check for "Essential" in it
5262 + set the value in pkg->essential.
5263 + This new routine could be useful also for every other flag
5264 + Pigi: 16/03/2004 */
5265 + set_flags_from_control(conf, pkg) ;
5267 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5268 + err = pkg_write_filelist(conf, pkg);
5272 + /* XXX: FEATURE: ipkg should identify any files which existed
5273 + before installation and which were overwritten, (see
5274 + check_data_file_clashes()). What it must do is remove any such
5275 + files from the filelist of the old package which provided the
5276 + file. Otherwise, if the old package were removed at some point
5277 + it would break the new package. Removing the new package will
5278 + also break the old one, but this cannot be helped since the old
5279 + package's file has already been deleted. This is the importance
5280 + of check_data_file_clashes(), and only allowing ipkg to install
5281 + a clashing package with a user force. */
5286 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5288 + conffile_list_elt_t *iter;
5295 + if (conf->noaction) return 0;
5297 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5298 + char *root_filename;
5300 + root_filename = root_filename_alloc(conf, cf->name);
5302 + /* Might need to initialize the md5sum for each conffile */
5303 + if (cf->value == NULL) {
5304 + cf->value = file_md5sum_alloc(root_filename);
5307 + if (!file_exists(root_filename)) {
5308 + free(root_filename);
5312 + cf_backup = backup_filename_alloc(root_filename);
5315 + if (file_exists(cf_backup)) {
5316 + /* Let's compute md5 to test if files are changed */
5317 + md5sum = file_md5sum_alloc(cf_backup);
5318 + if (strcmp( cf->value,md5sum) != 0 ) {
5319 + if (conf->force_defaults
5320 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5321 + rename(cf_backup, root_filename);
5324 + unlink(cf_backup);
5329 + free(root_filename);
5335 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5338 + const char *short_file_name;
5340 + short_file_name = strrchr(file_name, '/');
5341 + if (short_file_name) {
5342 + short_file_name++;
5344 + short_file_name = file_name;
5348 + response = get_user_response(" Configuration file '%s'\n"
5349 + " ==> File on system created by you or by a script.\n"
5350 + " ==> File also in package provided by package maintainer.\n"
5351 + " What would you like to do about it ? Your options are:\n"
5352 + " Y or I : install the package maintainer's version\n"
5353 + " N or O : keep your currently-installed version\n"
5354 + " D : show the differences between the versions (if diff is installed)\n"
5355 + " The default action is to keep your current version.\n"
5356 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5357 + if (strcmp(response, "y") == 0
5358 + || strcmp(response, "i") == 0
5359 + || strcmp(response, "yes") == 0) {
5364 + if (strcmp(response, "d") == 0) {
5368 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5369 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5372 + printf(" [Press ENTER to continue]\n");
5373 + response = file_read_line_alloc(stdin);
5383 +/* XXX: CLEANUP: I'd like to move all of the code for
5384 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5385 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5386 + pkg_deinit for example). */
5387 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5390 + struct dirent *dirent;
5393 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5395 + ipkg_message(conf, IPKG_DEBUG,
5396 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5397 + __FUNCTION__, pkg->tmp_unpack_dir);
5401 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5402 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5405 + dirent = readdir(tmp_dir);
5406 + if (dirent == NULL) {
5409 + sprintf_alloc(&tmp_file, "%s/%s",
5410 + pkg->tmp_unpack_dir, dirent->d_name);
5411 + if (! file_is_dir(tmp_file)) {
5416 + closedir(tmp_dir);
5417 + rmdir(pkg->tmp_unpack_dir);
5418 + free(pkg->tmp_unpack_dir);
5419 + pkg->tmp_unpack_dir = NULL;
5423 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5424 + pkg->name, pkg->local_filename, conf->tmp_dir);
5425 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5426 + unlink(pkg->local_filename);
5427 + free(pkg->local_filename);
5428 + pkg->local_filename = NULL;
5434 +static char *backup_filename_alloc(const char *file_name)
5438 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5443 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5448 + backup = backup_filename_alloc(file_name);
5449 + err = file_copy(file_name, backup);
5451 + ipkg_message(conf, IPKG_ERROR,
5452 + "%s: Failed to copy %s to %s\n",
5453 + __FUNCTION__, file_name, backup);
5461 +static int backup_exists_for(const char *file_name)
5466 + backup = backup_filename_alloc(file_name);
5468 + ret = file_exists(backup);
5475 +static int backup_remove(const char *file_name)
5479 + backup = backup_filename_alloc(file_name);
5488 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5490 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5492 + /* first, remove the packages that need removing */
5493 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5494 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5495 + err = ipkg_remove_pkg(conf, pkg,0);
5496 + if (err) return err;
5501 +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)
5504 + /* now one more pass checking on the ones that need to be installed */
5505 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5506 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5507 + if (pkg->dest == NULL)
5508 + pkg->dest = conf->default_dest;
5510 + pkg->state_want = SW_INSTALL;
5512 + /* Abhaya: conflicts check */
5513 + err = check_conflicts_for(conf, pkg);
5514 + if (err) { return err; }
5519 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5522 + /* now one more pass checking on the ones that need to be installed */
5523 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5524 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5526 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5527 + pkg_vec_t *replacees = pkg_vec_alloc();
5528 + pkg_get_installed_replacees(conf, pkg, replacees);
5530 + /* XXX: BUG: we really should treat replacement more like an upgrade
5531 + * Instead, we're going to remove the replacees
5533 + err = pkg_remove_installed_replacees(conf, replacees);
5534 + if (err) return err;
5535 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5540 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5543 + /* now one more pass checking on the ones that need to be installed */
5544 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5545 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5546 + if (pkg->local_filename == NULL) {
5547 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5549 + ipkg_message(conf, IPKG_ERROR,
5550 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5555 + if (pkg->tmp_unpack_dir == NULL) {
5556 + err = unpack_pkg_control_files(conf, pkg);
5557 + if (err) return err;
5563 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5566 + /* now one more pass checking on the ones that need to be installed */
5567 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5568 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5569 + pkg_t *old_pkg = pkg->old_pkg;
5571 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5572 + if (err) return err;
5574 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5575 + if (err) return err;
5577 + err = preinst_configure(conf, pkg, old_pkg);
5578 + if (err) return err;
5580 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5581 + if (err) return err;
5583 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5584 + if (err) return err;
5589 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5592 + /* now one more pass checking on the ones that need to be installed */
5593 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5594 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5595 + pkg_t *old_pkg = pkg->old_pkg;
5598 + old_pkg->state_want = SW_DEINSTALL;
5600 + if (old_pkg->state_flag & SF_NOPRUNE) {
5601 + ipkg_message(conf, IPKG_INFO,
5602 + " not removing obsolesced files because package marked noprune\n");
5604 + ipkg_message(conf, IPKG_INFO,
5605 + " removing obsolesced files\n");
5606 + remove_obsolesced_files(conf, pkg, old_pkg);
5610 + ipkg_message(conf, IPKG_INFO,
5611 + " installing maintainer scripts\n");
5612 + install_maintainer_scripts(conf, pkg, old_pkg);
5614 + /* the following just returns 0 */
5615 + remove_disappeared(conf, pkg);
5617 + ipkg_message(conf, IPKG_INFO,
5618 + " installing data files\n");
5619 + install_data_files(conf, pkg);
5621 + ipkg_message(conf, IPKG_INFO,
5622 + " resolving conf files\n");
5623 + resolve_conffiles(conf, pkg);
5625 + pkg->state_status = SS_UNPACKED;
5628 + old_pkg->state_status = SS_NOT_INSTALLED;
5631 + time(&pkg->installed_time);
5633 + ipkg_message(conf, IPKG_INFO,
5634 + " cleanup temp files\n");
5635 + cleanup_temporary_files(conf, pkg);
5638 + pkg->parent->state_status = pkg->state_status;
5643 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5646 + /* now one more pass checking on the ones that need to be installed */
5647 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5648 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5649 + pkg_t *old_pkg = pkg->old_pkg;
5652 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5653 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5654 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5655 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5656 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5657 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5658 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5659 + preinst_configure_unwind(conf, pkg, old_pkg);
5660 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5661 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5662 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5663 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5665 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5666 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5674 + * Perform all the actions.
5676 + * pkgs_to_remove are packages marked for removal.
5677 + * pkgs_superseded are the old packages being replaced by upgrades.
5679 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5681 +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)
5686 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5687 + if (err) return err;
5689 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5690 + if (err) return err;
5692 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5693 + if (err) goto UNWIND;
5695 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5696 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5697 + if (err) goto UNWIND;
5700 + * Now that we have the packages unpacked, we can look for data
5701 + * file clashes. First, we mark the files from the superseded
5702 + * packages as obsolete. Then we scan the files in
5703 + * pkgs_to_install, and only complain about clashes with
5704 + * non-obsolete files.
5707 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5708 + if (err) goto UNWIND;
5710 + /* this was before checking data file clashes */
5711 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5712 + if (err) goto UNWIND;
5714 + /* point of no return: no unwinding after this */
5715 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5716 + if (err) return err;
5718 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5722 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5724 + ipkg_message(conf, IPKG_INFO,
5725 + " cleanup temp files\n");
5726 + cleanup_temporary_files(conf, pkg);
5728 + ipkg_message(conf, IPKG_INFO,
5734 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
5735 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5736 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-07-22 16:31:25.000000000 +0200
5738 +/* ipkg_install.h - the itsy package management system
5742 + Copyright (C) 2001 University of Southern California
5744 + This program is free software; you can redistribute it and/or
5745 + modify it under the terms of the GNU General Public License as
5746 + published by the Free Software Foundation; either version 2, or (at
5747 + your option) any later version.
5749 + This program is distributed in the hope that it will be useful, but
5750 + WITHOUT ANY WARRANTY; without even the implied warranty of
5751 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5752 + General Public License for more details.
5755 +#ifndef IPKG_INSTALL_H
5756 +#define IPKG_INSTALL_H
5759 +#include "ipkg_conf.h"
5761 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5762 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5763 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5764 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5765 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5767 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5769 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5770 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5773 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
5774 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5775 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-07-22 16:31:25.000000000 +0200
5777 +/* ipkg_message.c - the itsy package management system
5779 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5781 + This program is free software; you can redistribute it and/or
5782 + modify it under the terms of the GNU General Public License as
5783 + published by the Free Software Foundation; either version 2, or (at
5784 + your option) any later version.
5786 + This program is distributed in the hope that it will be useful, but
5787 + WITHOUT ANY WARRANTY; without even the implied warranty of
5788 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5789 + General Public License for more details.
5794 +#include "ipkg_conf.h"
5795 +#include "ipkg_message.h"
5800 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5804 + if (conf && (conf->verbosity < level))
5811 + va_start (ap, fmt);
5812 + vprintf (fmt, ap);
5819 +#include "libipkg.h"
5821 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5824 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5829 + if (ipkg_cb_message)
5831 + va_start (ap, fmt);
5832 + vsnprintf (ts,256,fmt, ap);
5834 + ipkg_cb_message(conf,level,ts);
5838 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
5839 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5840 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-07-22 16:31:25.000000000 +0200
5842 +/* ipkg_message.h - the itsy package management system
5844 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5846 + This program is free software; you can redistribute it and/or
5847 + modify it under the terms of the GNU General Public License as
5848 + published by the Free Software Foundation; either version 2, or (at
5849 + your option) any later version.
5851 + This program is distributed in the hope that it will be useful, but
5852 + WITHOUT ANY WARRANTY; without even the implied warranty of
5853 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5854 + General Public License for more details.
5857 +#ifndef _IPKG_MESSAGE_H_
5858 +#define _IPKG_MESSAGE_H_
5861 +#include "ipkg_conf.h"
5864 + IPKG_ERROR, /* error conditions */
5865 + IPKG_NOTICE, /* normal but significant condition */
5866 + IPKG_INFO, /* informational message */
5867 + IPKG_DEBUG, /* debug level message */
5868 + IPKG_DEBUG2, /* more debug level message */
5871 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5873 +#endif /* _IPKG_MESSAGE_H_ */
5874 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
5875 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5876 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-07-22 16:31:25.000000000 +0200
5878 +/* ipkg_remove.c - the itsy package management system
5882 + Copyright (C) 2001 University of Southern California
5884 + This program is free software; you can redistribute it and/or
5885 + modify it under the terms of the GNU General Public License as
5886 + published by the Free Software Foundation; either version 2, or (at
5887 + your option) any later version.
5889 + This program is distributed in the hope that it will be useful, but
5890 + WITHOUT ANY WARRANTY; without even the implied warranty of
5891 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5892 + General Public License for more details.
5896 +#include "ipkg_message.h"
5900 +#include "ipkg_remove.h"
5902 +#include "file_util.h"
5903 +#include "sprintf_alloc.h"
5904 +#include "str_util.h"
5906 +#include "ipkg_cmd.h"
5909 + * Returns number of the number of packages depending on the packages provided by this package.
5910 + * Every package implicitly provides itself.
5912 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5914 + int nprovides = pkg->provides_count;
5915 + abstract_pkg_t **provides = pkg->provides;
5916 + int n_installed_dependents = 0;
5918 + for (i = 0; i <= nprovides; i++) {
5919 + abstract_pkg_t *providee = provides[i];
5920 + abstract_pkg_t **dependers = providee->depended_upon_by;
5921 + abstract_pkg_t *dep_ab_pkg;
5922 + if (dependers == NULL)
5924 + while ((dep_ab_pkg = *dependers++) != NULL) {
5925 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5926 + n_installed_dependents++;
5931 + /* if caller requested the set of installed dependents */
5932 + if (pdependents) {
5934 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5936 + if ( dependents == NULL ){
5937 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5941 + *pdependents = dependents;
5942 + for (i = 0; i <= nprovides; i++) {
5943 + abstract_pkg_t *providee = provides[i];
5944 + abstract_pkg_t **dependers = providee->depended_upon_by;
5945 + abstract_pkg_t *dep_ab_pkg;
5946 + if (dependers == NULL)
5948 + while ((dep_ab_pkg = *dependers++) != NULL) {
5949 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5950 + dependents[p++] = dep_ab_pkg;
5951 + dep_ab_pkg->state_flag |= SF_MARKED;
5955 + dependents[p] = NULL;
5956 + /* now clear the marks */
5957 + for (i = 0; i < p; i++) {
5958 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5959 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5962 + return n_installed_dependents;
5965 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5970 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5971 + abstract_pkg_t * ab_pkg;
5973 + if((ab_pkg = pkg->parent) == NULL){
5974 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5975 + __FUNCTION__, pkg->name);
5979 + if (dependents == NULL)
5982 + // here i am using the dependencies_checked
5983 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5984 + return 0; // has already been encountered in the process
5985 + // of marking packages for removal - Karthik
5986 + ab_pkg->dependencies_checked = 2;
5990 + while (dependents [i] != NULL) {
5991 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5993 + if (dep_ab_pkg->dependencies_checked == 2){
5997 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5998 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5999 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6000 + if (dep_pkg->state_status == SS_INSTALLED) {
6001 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6007 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6008 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6015 + for (i = 0; i < dependent_pkgs->len; i++) {
6016 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6023 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6025 + abstract_pkg_t *dep_ab_pkg;
6026 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6027 + while ((dep_ab_pkg = *dependents++) != NULL) {
6028 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6029 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6031 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6032 + ipkg_message(conf, IPKG_ERROR, "");
6033 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6034 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6035 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6036 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6037 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6041 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6043 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6044 + thus I wan't check for essential, as I'm upgrading.
6045 + I hope it won't break anything :)
6048 + abstract_pkg_t *parent_pkg = NULL;
6050 + if (pkg->essential && !message) {
6051 + if (conf->force_removal_of_essential_packages) {
6052 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6053 + "\tIf your system breaks, you get to keep both pieces\n",
6056 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6057 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6058 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6059 + "\tits will with the option: -force-removal-of-essential-packages\n",
6061 + return IPKG_PKG_IS_ESSENTIAL;
6065 + if ((parent_pkg = pkg->parent) == NULL)
6068 + /* only attempt to remove dependent installed packages if
6069 + * force_depends is not specified or the package is being
6072 + if (!conf->force_depends
6073 + && !(pkg->state_flag & SF_REPLACE)) {
6074 + abstract_pkg_t **dependents;
6075 + int has_installed_dependents =
6076 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6078 + if (has_installed_dependents) {
6080 + * if this package is depended up by others, then either we should
6081 + * not remove it or we should remove it and all of its dependents
6084 + if (!conf->force_removal_of_dependent_packages
6085 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6086 + return IPKG_PKG_HAS_DEPENDENTS;
6089 + /* remove packages depending on this package - Karthik */
6090 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6092 + if (err) return err;
6096 + if ( message==0 ){
6097 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6100 + pkg->state_flag |= SF_FILELIST_CHANGED;
6102 + pkg->state_want = SW_DEINSTALL;
6103 + ipkg_state_changed++;
6105 + pkg_run_script(conf, pkg, "prerm", "remove");
6107 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6108 + maintains an empty filelist rather than deleting it. That seems
6109 + like a big pain, and I don't see that that should make a big
6110 + difference, but for anyone who wants tighter compatibility,
6111 + feel free to fix this. */
6112 + remove_data_files_and_list(conf, pkg);
6114 + pkg_run_script(conf, pkg, "postrm", "remove");
6116 + remove_maintainer_scripts_except_postrm(conf, pkg);
6118 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6119 + * space, it doesn't make sense to leave extra configurations, files,
6120 + * and maintainer scripts left around. So, we make remove like purge,
6121 + * and take out all the crap :) */
6123 + remove_postrm(conf, pkg);
6124 + pkg->state_status = SS_NOT_INSTALLED;
6127 + parent_pkg->state_status = SS_NOT_INSTALLED;
6132 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6134 + ipkg_remove_pkg(conf, pkg,0);
6138 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6140 + str_list_t installed_dirs;
6141 + str_list_t *installed_files;
6142 + str_list_elt_t *iter;
6144 + conffile_t *conffile;
6145 + int removed_a_dir;
6148 + str_list_init(&installed_dirs);
6149 + installed_files = pkg_get_installed_files(pkg);
6151 + for (iter = installed_files->head; iter; iter = iter->next) {
6152 + file_name = iter->data;
6154 + if (file_is_dir(file_name)) {
6155 + str_list_append(&installed_dirs, strdup(file_name));
6159 + conffile = pkg_get_conffile(pkg, file_name);
6161 + /* XXX: QUESTION: Is this right? I figure we only need to
6162 + save the conffile if it has been modified. Is that what
6163 + dpkg does? Or does dpkg preserve all conffiles? If so,
6164 + this seems like a better thing to do to conserve
6166 + if (conffile_has_been_modified(conf, conffile)) {
6167 + printf(" not deleting modified conffile %s\n", file_name);
6173 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6174 + if (!conf->noaction)
6175 + unlink(file_name);
6178 + if (!conf->noaction) {
6180 + removed_a_dir = 0;
6181 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6182 + file_name = iter->data;
6184 + if (rmdir(file_name) == 0) {
6185 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6186 + removed_a_dir = 1;
6187 + str_list_remove(&installed_dirs, &iter);
6190 + } while (removed_a_dir);
6193 + pkg_free_installed_files(pkg);
6194 + /* We have to remove the file list now, so that
6195 + find_pkg_owning_file does not always just report this package */
6196 + pkg_remove_installed_files_list(conf, pkg);
6198 + /* Don't print warning for dirs that are provided by other packages */
6199 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6200 + file_name = iter->data;
6202 + owner = file_hash_get_file_owner(conf, file_name);
6205 + iter->data = NULL;
6206 + str_list_remove(&installed_dirs, &iter);
6211 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6213 + iter->data = NULL;
6215 + str_list_deinit(&installed_dirs);
6220 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6223 + char *globpattern;
6226 + if (conf->noaction) return 0;
6228 + sprintf_alloc(&globpattern, "%s/%s.*",
6229 + pkg->dest->info_dir, pkg->name);
6230 + err = glob(globpattern, 0, NULL, &globbuf);
6231 + free(globpattern);
6236 + for (i = 0; i < globbuf.gl_pathc; i++) {
6237 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6240 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6241 + unlink(globbuf.gl_pathv[i]);
6243 + globfree(&globbuf);
6248 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6250 + char *postrm_file_name;
6252 + if (conf->noaction) return 0;
6254 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6255 + pkg->dest->info_dir, pkg->name);
6256 + unlink(postrm_file_name);
6257 + free(postrm_file_name);
6261 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
6262 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6263 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-07-22 16:31:25.000000000 +0200
6265 +/* ipkg_remove.h - the itsy package management system
6269 + Copyright (C) 2001 University of Southern California
6271 + This program is free software; you can redistribute it and/or
6272 + modify it under the terms of the GNU General Public License as
6273 + published by the Free Software Foundation; either version 2, or (at
6274 + your option) any later version.
6276 + This program is distributed in the hope that it will be useful, but
6277 + WITHOUT ANY WARRANTY; without even the implied warranty of
6278 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6279 + General Public License for more details.
6282 +#ifndef IPKG_REMOVE_H
6283 +#define IPKG_REMOVE_H
6286 +#include "ipkg_conf.h"
6288 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6289 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6290 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6291 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6292 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6293 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6294 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6298 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
6299 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6300 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-07-22 16:31:25.000000000 +0200
6302 +/* ipkg_upgrade.c - the itsy package management system
6305 + Copyright (C) 2001 University of Southern California
6307 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6309 + This program is free software; you can redistribute it and/or
6310 + modify it under the terms of the GNU General Public License as
6311 + published by the Free Software Foundation; either version 2, or (at
6312 + your option) any later version.
6314 + This program is distributed in the hope that it will be useful, but
6315 + WITHOUT ANY WARRANTY; without even the implied warranty of
6316 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6317 + General Public License for more details.
6321 +#include "ipkg_install.h"
6322 +#include "ipkg_message.h"
6324 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6328 + char *old_version, *new_version;
6330 + if (old->state_flag & SF_HOLD) {
6331 + ipkg_message(conf, IPKG_NOTICE,
6332 + "Not upgrading package %s which is marked "
6333 + "hold (flags=%#x)\n", old->name, old->state_flag);
6337 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6338 + if (new == NULL) {
6339 + old_version = pkg_version_str_alloc(old);
6340 + ipkg_message(conf, IPKG_NOTICE,
6341 + "Assuming locally installed package %s (%s) "
6342 + "is up to date.\n", old->name, old_version);
6343 + free(old_version);
6347 + old_version = pkg_version_str_alloc(old);
6348 + new_version = pkg_version_str_alloc(new);
6350 + cmp = pkg_compare_versions(old, new);
6351 + ipkg_message(conf, IPKG_DEBUG,
6352 + "comparing visible versions of pkg %s:"
6353 + "\n\t%s is installed "
6354 + "\n\t%s is available "
6355 + "\n\t%d was comparison result\n",
6356 + old->name, old_version, new_version, cmp);
6358 + ipkg_message(conf, IPKG_INFO,
6359 + "Package %s (%s) installed in %s is up to date.\n",
6360 + old->name, old_version, old->dest->name);
6361 + free(old_version);
6362 + free(new_version);
6364 + } else if (cmp > 0) {
6365 + ipkg_message(conf, IPKG_NOTICE,
6366 + "Not downgrading package %s on %s from %s to %s.\n",
6367 + old->name, old->dest->name, old_version, new_version);
6368 + free(old_version);
6369 + free(new_version);
6371 + } else if (cmp < 0) {
6372 + new->dest = old->dest;
6373 + old->state_want = SW_DEINSTALL;
6376 + new->state_flag |= SF_USER;
6377 + return ipkg_install_pkg(conf, new,1);
6379 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
6380 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6381 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-07-22 16:31:25.000000000 +0200
6383 +/* ipkg_upgrade.c - the itsy package management system
6385 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6387 + This program is free software; you can redistribute it and/or
6388 + modify it under the terms of the GNU General Public License as
6389 + published by the Free Software Foundation; either version 2, or (at
6390 + your option) any later version.
6392 + This program is distributed in the hope that it will be useful, but
6393 + WITHOUT ANY WARRANTY; without even the implied warranty of
6394 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6395 + General Public License for more details.
6400 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6401 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
6402 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6403 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-07-22 16:31:25.000000000 +0200
6405 +/* ipkg_utils.c - the itsy package management system
6409 + Copyright (C) 2002 Compaq Computer Corporation
6411 + This program is free software; you can redistribute it and/or
6412 + modify it under the terms of the GNU General Public License as
6413 + published by the Free Software Foundation; either version 2, or (at
6414 + your option) any later version.
6416 + This program is distributed in the hope that it will be useful, but
6417 + WITHOUT ANY WARRANTY; without even the implied warranty of
6418 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6419 + General Public License for more details.
6425 +#include <sys/vfs.h>
6427 +#include "ipkg_utils.h"
6429 +#include "pkg_hash.h"
6431 +struct errlist* error_list;
6433 +int get_available_blocks(char * filesystem)
6435 + struct statfs sfs;
6437 + if(statfs(filesystem, &sfs)){
6438 + fprintf(stderr, "bad statfs\n");
6441 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6442 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6445 +char **read_raw_pkgs_from_file(const char *file_name)
6450 + if(!(fp = fopen(file_name, "r"))){
6451 + fprintf(stderr, "can't get %s open for read\n", file_name);
6455 + ret = read_raw_pkgs_from_stream(fp);
6462 +char **read_raw_pkgs_from_stream(FILE *fp)
6464 + char **raw = NULL, *buf, *scout;
6466 + size_t size = 512;
6468 + buf = malloc (size);
6470 + while (fgets(buf, size, fp)) {
6471 + while (strlen (buf) == (size - 1)
6472 + && buf[size-2] != '\n') {
6473 + size_t o = size - 1;
6475 + buf = realloc (buf, size);
6476 + if (fgets (buf + o, size - o, fp) == NULL)
6481 + raw = realloc(raw, (count + 50) * sizeof(char *));
6483 + if((scout = strchr(buf, '\n')))
6486 + raw[count++] = strdup(buf);
6489 + raw = realloc(raw, (count + 1) * sizeof(char *));
6490 + raw[count] = NULL;
6497 +/* something to remove whitespace, a hash pooper */
6498 +char *trim_alloc(char *line)
6501 + char *dest, *src, *end;
6503 + new = malloc(strlen(line) + 1);
6504 + if ( new == NULL ){
6505 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6508 + dest = new, src = line, end = line + (strlen(line) - 1);
6510 + /* remove it from the front */
6515 + /* and now from the back */
6516 + while((end > src) &&
6522 + /* this does from the first space
6523 + * blasting away any versions stuff in depends
6534 +int line_is_blank(const char *line)
6538 + for (s = line; *s; s++) {
6545 +void push_error_list(struct errlist ** errors, char * msg){
6546 + struct errlist *err_lst_tmp;
6549 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6550 + err_lst_tmp->errmsg=strdup(msg) ;
6551 + err_lst_tmp->next = *errors;
6552 + *errors = err_lst_tmp;
6556 +void reverse_error_list(struct errlist **errors){
6557 + struct errlist *result=NULL;
6558 + struct errlist *current= *errors;
6559 + struct errlist *next;
6561 + while ( current != NULL ) {
6562 + next = current->next;
6563 + current->next=result;
6572 +void free_error_list(struct errlist **errors){
6573 + struct errlist *current = *errors;
6575 + while (current != NULL) {
6576 + free(current->errmsg);
6577 + current = (*errors)->next;
6579 + *errors = current;
6586 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
6587 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6588 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-07-22 16:31:25.000000000 +0200
6590 +/* ipkg_utils.h - the itsy package management system
6594 + Copyright (C) 2002 Compaq Computer Corporation
6596 + This program is free software; you can redistribute it and/or
6597 + modify it under the terms of the GNU General Public License as
6598 + published by the Free Software Foundation; either version 2, or (at
6599 + your option) any later version.
6601 + This program is distributed in the hope that it will be useful, but
6602 + WITHOUT ANY WARRANTY; without even the implied warranty of
6603 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6604 + General Public License for more details.
6607 +#ifndef IPKG_UTILS_H
6608 +#define IPKG_UTILS_H
6612 +int get_available_blocks(char * filesystem);
6613 +char **read_raw_pkgs_from_file(const char *file_name);
6614 +char **read_raw_pkgs_from_stream(FILE *fp);
6615 +char *trim_alloc(char * line);
6616 +int line_is_blank(const char *line);
6619 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c
6620 --- busybox-1.2.0-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6621 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-07-22 16:31:25.000000000 +0200
6623 +/* ipkglib.c - the itsy package management system
6627 + Copyright (C) 2003 kernel concepts
6629 + This program is free software; you can redistribute it and/or
6630 + modify it under the terms of the GNU General Public License as
6631 + published by the Free Software Foundation; either version 2, or (at
6632 + your option) any later version.
6634 + This program is distributed in the hope that it will be useful, but
6635 + WITHOUT ANY WARRANTY; without even the implied warranty of
6636 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6637 + General Public License for more details.
6643 +#include "ipkg_includes.h"
6644 +#include "libipkg.h"
6647 +#include "ipkg_conf.h"
6648 +#include "ipkg_cmd.h"
6649 +#include "file_util.h"
6653 +ipkg_message_callback ipkg_cb_message = NULL;
6654 +ipkg_response_callback ipkg_cb_response = NULL;
6655 +ipkg_status_callback ipkg_cb_status = NULL;
6656 +ipkg_list_callback ipkg_cb_list = NULL;
6660 +ipkg_init (ipkg_message_callback mcall,
6661 + ipkg_response_callback rcall,
6664 + ipkg_cb_message = mcall;
6665 + ipkg_cb_response = rcall;
6674 +ipkg_deinit (args_t * args)
6676 + args_deinit (args);
6677 + ipkg_cb_message = NULL;
6678 + ipkg_cb_response = NULL;
6680 + /* place other cleanup stuff here */
6687 +ipkg_packages_list(args_t *args,
6688 + const char *packages,
6689 + ipkg_list_callback cblist,
6693 + ipkg_conf_t ipkg_conf;
6696 + err = ipkg_conf_init (&ipkg_conf, args);
6702 + ipkg_cb_list = cblist;
6703 + /* we need to do this because of static declarations,
6704 + * maybe a good idea to change */
6705 + cmd = ipkg_cmd_find ("list");
6707 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6709 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6710 + ipkg_cb_list = NULL;
6711 + ipkg_conf_deinit (&ipkg_conf);
6717 +ipkg_packages_status(args_t *args,
6718 + const char *packages,
6719 + ipkg_status_callback cbstatus,
6723 + ipkg_conf_t ipkg_conf;
6726 + err = ipkg_conf_init (&ipkg_conf, args);
6732 + ipkg_cb_status = cbstatus;
6734 + /* we need to do this because of static declarations,
6735 + * maybe a good idea to change */
6736 + cmd = ipkg_cmd_find ("status");
6738 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6740 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6742 + ipkg_cb_status = NULL;
6743 + ipkg_conf_deinit (&ipkg_conf);
6749 +ipkg_packages_info(args_t *args,
6750 + const char *packages,
6751 + ipkg_status_callback cbstatus,
6755 + ipkg_conf_t ipkg_conf;
6758 + err = ipkg_conf_init (&ipkg_conf, args);
6764 + ipkg_cb_status = cbstatus;
6766 + /* we need to do this because of static declarations,
6767 + * maybe a good idea to change */
6768 + cmd = ipkg_cmd_find ("info");
6770 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6772 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6774 + ipkg_cb_status = NULL;
6775 + ipkg_conf_deinit (&ipkg_conf);
6781 +ipkg_packages_install (args_t * args, const char *name)
6784 + ipkg_conf_t ipkg_conf;
6787 + /* this error should be handled in application */
6788 + if (!name || !strlen (name))
6791 + err = ipkg_conf_init (&ipkg_conf, args);
6797 + /* we need to do this because of static declarations,
6798 + * maybe a good idea to change */
6799 + cmd = ipkg_cmd_find ("install");
6800 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6802 + ipkg_conf_deinit(&ipkg_conf);
6808 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6811 + ipkg_conf_t ipkg_conf;
6814 + /* this error should be handled in application */
6815 + if (!name || !strlen (name))
6818 + err = ipkg_conf_init (&ipkg_conf, args);
6824 + /* we need to do this because of static declarations,
6825 + * maybe a good idea to change */
6827 + cmd = ipkg_cmd_find ("purge");
6829 + cmd = ipkg_cmd_find ("remove");
6831 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6833 + ipkg_conf_deinit(&ipkg_conf);
6839 +ipkg_lists_update(args_t *args)
6842 + ipkg_conf_t ipkg_conf;
6845 + err = ipkg_conf_init (&ipkg_conf, args);
6851 + /* we need to do this because of static declarations,
6852 + * maybe a good idea to change */
6853 + cmd = ipkg_cmd_find ("update");
6855 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6857 + ipkg_conf_deinit(&ipkg_conf);
6863 +ipkg_packages_upgrade(args_t *args)
6866 + ipkg_conf_t ipkg_conf;
6869 + err = ipkg_conf_init (&ipkg_conf, args);
6875 + /* we need to do this because of static declarations,
6876 + * maybe a good idea to change */
6877 + cmd = ipkg_cmd_find ("upgrade");
6879 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6881 + ipkg_conf_deinit(&ipkg_conf);
6887 +ipkg_packages_download (args_t * args, const char *name)
6890 + ipkg_conf_t ipkg_conf;
6893 + /* this error should be handled in application */
6894 + if (!name || !strlen (name))
6897 + err = ipkg_conf_init (&ipkg_conf, args);
6903 + /* we need to do this because of static declarations,
6904 + * maybe a good idea to change */
6905 + cmd = ipkg_cmd_find ("download");
6906 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6908 + ipkg_conf_deinit(&ipkg_conf);
6914 +ipkg_package_files(args_t *args,
6916 + ipkg_list_callback cblist,
6920 + ipkg_conf_t ipkg_conf;
6923 + /* this error should be handled in application */
6924 + if (!name || !strlen (name))
6927 + err = ipkg_conf_init (&ipkg_conf, args);
6933 + ipkg_cb_list = cblist;
6935 + /* we need to do this because of static declarations,
6936 + * maybe a good idea to change */
6937 + cmd = ipkg_cmd_find ("files");
6939 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6941 + ipkg_cb_list = NULL;
6942 + ipkg_conf_deinit(&ipkg_conf);
6948 +ipkg_file_search(args_t *args,
6950 + ipkg_list_callback cblist,
6954 + ipkg_conf_t ipkg_conf;
6957 + /* this error should be handled in application */
6958 + if (!file || !strlen (file))
6961 + err = ipkg_conf_init (&ipkg_conf, args);
6967 + ipkg_cb_list = cblist;
6969 + /* we need to do this because of static declarations,
6970 + * maybe a good idea to change */
6971 + cmd = ipkg_cmd_find ("search");
6972 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6974 + ipkg_cb_list = NULL;
6975 + ipkg_conf_deinit(&ipkg_conf);
6981 +ipkg_file_what(args_t *args, const char *file, const char* command)
6984 + ipkg_conf_t ipkg_conf;
6987 + /* this error should be handled in application */
6988 + if (!file || !strlen (file))
6991 + err = ipkg_conf_init (&ipkg_conf, args);
6997 + /* we need to do this because of static declarations,
6998 + * maybe a good idea to change */
6999 + cmd = ipkg_cmd_find (command);
7000 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7002 + ipkg_conf_deinit(&ipkg_conf);
7006 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7007 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7008 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7009 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7010 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7013 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7016 + if (conf && (conf->verbosity < level)) {
7020 + if ( level == IPKG_ERROR ){
7021 + push_error_list(&error_list, msg);
7030 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7031 + pkg_state_status_t status, void *userdata)
7034 + printf("%s - %s - %s\n", name, version, desc);
7036 + printf("%s - %s\n", name, version);
7040 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7041 + pkg_state_status_t status, void *userdata)
7044 + printf("%s\n", desc);
7048 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7051 + printf("%s\n", desc);
7055 +char* default_ipkg_response_callback(char *question)
7057 + char *response = NULL;
7061 + response = (char *)file_read_line_alloc(stdin);
7062 + } while (response == NULL);
7066 +/* This is used for backward compatibility */
7068 +ipkg_op (int argc, char *argv[])
7074 + ipkg_conf_t ipkg_conf;
7076 + args_init (&args);
7078 + optind = args_parse (&args, argc, argv);
7079 + if (optind == argc || optind < 0)
7081 + args_usage ("ipkg must have one sub-command argument");
7084 + cmd_name = argv[optind++];
7085 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7086 + read anything from there.
7088 + if ( !strcmp(cmd_name,"print-architecture") ||
7089 + !strcmp(cmd_name,"print_architecture") ||
7090 + !strcmp(cmd_name,"print-installation-architecture") ||
7091 + !strcmp(cmd_name,"print_installation_architecture") )
7092 + args.nocheckfordirorfile = 1;
7094 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7095 + read anything from there.
7097 + if ( !strcmp(cmd_name,"flag") ||
7098 + !strcmp(cmd_name,"configure") ||
7099 + !strcmp(cmd_name,"remove") ||
7100 + !strcmp(cmd_name,"files") ||
7101 + !strcmp(cmd_name,"search") ||
7102 + !strcmp(cmd_name,"compare_versions") ||
7103 + !strcmp(cmd_name,"compare-versions") ||
7104 + !strcmp(cmd_name,"list_installed") ||
7105 + !strcmp(cmd_name,"list-installed") ||
7106 + !strcmp(cmd_name,"status") )
7107 + args.noreadfeedsfile = 1;
7110 + err = ipkg_conf_init (&ipkg_conf, &args);
7116 + args_deinit (&args);
7118 + ipkg_cb_message = default_ipkg_message_callback;
7119 + ipkg_cb_response = default_ipkg_response_callback;
7120 + ipkg_cb_status = default_ipkg_status_callback;
7121 + if ( strcmp(cmd_name, "files")==0)
7122 + ipkg_cb_list = default_ipkg_files_callback;
7124 + ipkg_cb_list = default_ipkg_list_callback;
7126 + cmd = ipkg_cmd_find (cmd_name);
7129 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7131 + args_usage (NULL);
7134 + if (cmd->requires_args && optind == argc)
7137 + "%s: the ``%s'' command requires at least one argument\n",
7138 + __FUNCTION__, cmd_name);
7139 + args_usage (NULL);
7142 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7144 + ipkg_conf_deinit (&ipkg_conf);
7149 +#endif /* IPKG_LIB */
7150 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h
7151 --- busybox-1.2.0-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7152 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-07-22 16:31:25.000000000 +0200
7154 +/* ipkglib.h - the itsy package management system
7156 + Florian Boor <florian.boor@kernelconcepts.de>
7158 + This program is free software; you can redistribute it and/or
7159 + modify it under the terms of the GNU General Public License as
7160 + published by the Free Software Foundation; either version 2, or (at
7161 + your option) any later version.
7163 + This program is distributed in the hope that it will be useful, but
7164 + WITHOUT ANY WARRANTY; without even the implied warranty of
7165 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7166 + General Public License for more details.
7174 +#include "ipkg_conf.h"
7175 +#include "ipkg_message.h"
7180 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7182 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7183 + pkg_state_status_t status, void *userdata);
7184 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7186 +typedef char* (*ipkg_response_callback)(char *question);
7188 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7189 +extern int ipkg_init (ipkg_message_callback mcall,
7190 + ipkg_response_callback rcall,
7193 +extern int ipkg_deinit (args_t *args);
7194 +extern int ipkg_packages_list(args_t *args,
7195 + const char *packages,
7196 + ipkg_list_callback cblist,
7198 +extern int ipkg_packages_status(args_t *args,
7199 + const char *packages,
7200 + ipkg_status_callback cbstatus,
7202 +extern int ipkg_packages_info(args_t *args,
7203 + const char *packages,
7204 + ipkg_status_callback cbstatus,
7206 +extern int ipkg_packages_install(args_t *args, const char *name);
7207 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7208 +extern int ipkg_lists_update(args_t *args);
7209 +extern int ipkg_packages_upgrade(args_t *args);
7210 +extern int ipkg_packages_download(args_t *args, const char *name);
7211 +extern int ipkg_package_files(args_t *args,
7213 + ipkg_list_callback cblist,
7215 +extern int ipkg_file_search(args_t *args,
7217 + ipkg_list_callback cblist,
7219 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7220 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7221 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7222 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7223 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7225 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7226 +extern ipkg_response_callback ipkg_cb_response;
7227 +extern ipkg_status_callback ipkg_cb_status;
7228 +extern ipkg_list_callback ipkg_cb_list;
7229 +extern void push_error_list(struct errlist **errors,char * msg);
7230 +extern void reverse_error_list(struct errlist **errors);
7231 +extern void free_error_list(struct errlist **errors);
7235 +extern int ipkg_op(int argc, char *argv[]);
7241 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile
7242 --- busybox-1.2.0-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
7243 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile 2006-07-22 16:31:25.000000000 +0200
7245 +# Makefile for busybox
7247 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7249 +# This program is free software; you can redistribute it and/or modify
7250 +# it under the terms of the GNU General Public License as published by
7251 +# the Free Software Foundation; either version 2 of the License, or
7252 +# (at your option) any later version.
7254 +# This program is distributed in the hope that it will be useful,
7255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7257 +# General Public License for more details.
7259 +# You should have received a copy of the GNU General Public License
7260 +# along with this program; if not, write to the Free Software
7261 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7266 +srcdir=$(top_srcdir)/archival/libipkg
7268 +include $(top_builddir)/Rules.mak
7269 +include $(top_builddir)/.config
7270 +include $(srcdir)/Makefile.in
7271 +all: $(libraries-y)
7272 +-include $(top_builddir)/.depend
7275 + rm -f *.o *.a $(AR_TARGET)
7277 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in
7278 --- busybox-1.2.0-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
7279 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in 2006-07-22 16:31:25.000000000 +0200
7281 +# Makefile for busybox
7283 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7285 +# This program is free software; you can redistribute it and/or modify
7286 +# it under the terms of the GNU General Public License as published by
7287 +# the Free Software Foundation; either version 2 of the License, or
7288 +# (at your option) any later version.
7290 +# This program is distributed in the hope that it will be useful,
7291 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7292 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7293 +# General Public License for more details.
7295 +# You should have received a copy of the GNU General Public License
7296 +# along with this program; if not, write to the Free Software
7297 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7300 +LIBIPKG_AR:=libipkg.a
7301 +ifndef $(LIBIPKG_DIR)
7302 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
7304 +srcdir=$(top_srcdir)/archival/libipkg
7306 +LIBIPKG_CORE_SOURCES:= \
7311 +LIBIPKG_CMD_SOURCES:= \
7313 + ipkg_configure.c \
7319 +LIBIPKG_DB_SOURCES:= \
7330 +LIBIPKG_LIST_SOURCES:= \
7342 +LIBIPKG_UTIL_SOURCES:= \
7349 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CORE_SOURCES)
7350 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CMD_SOURCES)
7351 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_DB_SOURCES)
7352 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_LIST_SOURCES)
7353 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_SOURCES)
7354 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
7356 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
7358 +libraries-$(CONFIG_IPKG) += $(LIBIPKG_DIR)$(LIBIPKG_AR)
7360 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
7363 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
7366 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c
7367 --- busybox-1.2.0-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7368 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c 2006-07-22 16:31:25.000000000 +0200
7370 +/* md5.c - wrappers to busybox md5 functions
7372 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7374 + * This program is free software; you can redistribute it and/or modify
7375 + * it under the terms of the GNU General Public License as published by
7376 + * the Free Software Foundation; either version 2, or (at your option)
7377 + * any later version.
7379 + * This program is distributed in the hope that it will be useful,
7380 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7382 + * GNU General Public License for more details.
7384 + * You should have received a copy of the GNU General Public License
7385 + * along with this program; if not, write to the Free Software Foundation,
7386 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7394 +int md5_stream(FILE *stream, void *resblock)
7399 + if( (fd = fileno(stream)) == -1 ) {
7400 + bb_error_msg("bad file descriptor");
7404 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7409 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7413 + md5_begin(&md5_cx);
7414 + md5_hash(buffer, len, &md5_cx);
7415 + return md5_end(resblock, &md5_cx);
7418 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h
7419 --- busybox-1.2.0-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7420 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h 2006-07-22 16:31:25.000000000 +0200
7422 +/* md5.h - Compute MD5 checksum of files or strings according to the
7423 + * definition of MD5 in RFC 1321 from April 1992.
7424 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7426 + * This program is free software; you can redistribute it and/or modify
7427 + * it under the terms of the GNU General Public License as published by
7428 + * the Free Software Foundation; either version 2, or (at your option)
7429 + * any later version.
7431 + * This program is distributed in the hope that it will be useful,
7432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7434 + * GNU General Public License for more details.
7436 + * You should have received a copy of the GNU General Public License
7437 + * along with this program; if not, write to the Free Software Foundation,
7438 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7444 +/* Compute MD5 message digest for bytes read from STREAM. The
7445 + resulting message digest number will be written into the 16 bytes
7446 + beginning at RESBLOCK. */
7447 +int md5_stream(FILE *stream, void *resblock);
7449 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7450 + result is always in little endian byte order, so that a byte-wise
7451 + output yields to the wanted ASCII representation of the message
7453 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7457 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
7458 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7459 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-07-22 16:31:25.000000000 +0200
7461 +/* nv_pair.c - the itsy package management system
7465 + Copyright (C) 2001 University of Southern California
7467 + This program is free software; you can redistribute it and/or
7468 + modify it under the terms of the GNU General Public License as
7469 + published by the Free Software Foundation; either version 2, or (at
7470 + your option) any later version.
7472 + This program is distributed in the hope that it will be useful, but
7473 + WITHOUT ANY WARRANTY; without even the implied warranty of
7474 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7475 + General Public License for more details.
7480 +#include "nv_pair.h"
7481 +#include "str_util.h"
7483 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7485 + nv_pair->name = str_dup_safe(name);
7486 + nv_pair->value = str_dup_safe(value);
7491 +void nv_pair_deinit(nv_pair_t *nv_pair)
7493 + free(nv_pair->name);
7494 + nv_pair->name = NULL;
7496 + free(nv_pair->value);
7497 + nv_pair->value = NULL;
7501 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
7502 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7503 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-07-22 16:31:25.000000000 +0200
7505 +/* nv_pair.h - the itsy package management system
7509 + Copyright (C) 2001 University of Southern California
7511 + This program is free software; you can redistribute it and/or
7512 + modify it under the terms of the GNU General Public License as
7513 + published by the Free Software Foundation; either version 2, or (at
7514 + your option) any later version.
7516 + This program is distributed in the hope that it will be useful, but
7517 + WITHOUT ANY WARRANTY; without even the implied warranty of
7518 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7519 + General Public License for more details.
7525 +typedef struct nv_pair nv_pair_t;
7532 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7533 +void nv_pair_deinit(nv_pair_t *nv_pair);
7537 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
7538 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7539 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-07-22 16:31:25.000000000 +0200
7541 +/* nv_pair_list.c - the itsy package management system
7545 + Copyright (C) 2001 University of Southern California
7547 + This program is free software; you can redistribute it and/or
7548 + modify it under the terms of the GNU General Public License as
7549 + published by the Free Software Foundation; either version 2, or (at
7550 + your option) any later version.
7552 + This program is distributed in the hope that it will be useful, but
7553 + WITHOUT ANY WARRANTY; without even the implied warranty of
7554 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7555 + General Public License for more details.
7560 +#include "nv_pair.h"
7561 +#include "void_list.h"
7562 +#include "nv_pair_list.h"
7564 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7566 + return void_list_elt_init((void_list_elt_t *) elt, data);
7569 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7571 + void_list_elt_deinit((void_list_elt_t *) elt);
7574 +int nv_pair_list_init(nv_pair_list_t *list)
7576 + return void_list_init((void_list_t *) list);
7579 +void nv_pair_list_deinit(nv_pair_list_t *list)
7581 + nv_pair_list_elt_t *iter;
7582 + nv_pair_t *nv_pair;
7584 + for (iter = list->head; iter; iter = iter->next) {
7585 + nv_pair = iter->data;
7586 + nv_pair_deinit(nv_pair);
7588 + /* malloced in nv_pair_list_append */
7590 + iter->data = NULL;
7592 + void_list_deinit((void_list_t *) list);
7595 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7599 + /* freed in nv_pair_list_deinit */
7600 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7602 + if (nv_pair == NULL) {
7603 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7606 + nv_pair_init(nv_pair, name, value);
7608 + err = void_list_append((void_list_t *) list, nv_pair);
7616 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7618 + return void_list_push((void_list_t *) list, data);
7621 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7623 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7626 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7628 + nv_pair_list_elt_t *iter;
7629 + nv_pair_t *nv_pair;
7631 + for (iter = list->head; iter; iter = iter->next) {
7632 + nv_pair = iter->data;
7633 + if (strcmp(nv_pair->name, name) == 0) {
7634 + return nv_pair->value;
7639 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
7640 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7641 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-07-22 16:31:25.000000000 +0200
7643 +/* nv_pair_list.h - the itsy package management system
7647 + Copyright (C) 2001 University of Southern California
7649 + This program is free software; you can redistribute it and/or
7650 + modify it under the terms of the GNU General Public License as
7651 + published by the Free Software Foundation; either version 2, or (at
7652 + your option) any later version.
7654 + This program is distributed in the hope that it will be useful, but
7655 + WITHOUT ANY WARRANTY; without even the implied warranty of
7656 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7657 + General Public License for more details.
7660 +#ifndef NV_PAIR_LIST_H
7661 +#define NV_PAIR_LIST_H
7663 +#include "nv_pair.h"
7664 +#include "void_list.h"
7666 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7667 +struct nv_pair_list_elt
7669 + nv_pair_list_elt_t *next;
7673 +typedef struct nv_pair_list nv_pair_list_t;
7674 +struct nv_pair_list
7676 + nv_pair_list_elt_t pre_head;
7677 + nv_pair_list_elt_t *head;
7678 + nv_pair_list_elt_t *tail;
7681 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7683 + if (list->head == NULL)
7689 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7690 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7692 +int nv_pair_list_init(nv_pair_list_t *list);
7693 +void nv_pair_list_deinit(nv_pair_list_t *list);
7695 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7696 + const char *name, const char *value);
7697 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7698 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7699 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7703 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c
7704 --- busybox-1.2.0-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7705 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c 2006-07-22 16:31:25.000000000 +0200
7707 +/* pkg.c - the itsy package management system
7711 + Copyright (C) 2001 University of Southern California
7713 + This program is free software; you can redistribute it and/or
7714 + modify it under the terms of the GNU General Public License as
7715 + published by the Free Software Foundation; either version 2, or (at
7716 + your option) any later version.
7718 + This program is distributed in the hope that it will be useful, but
7719 + WITHOUT ANY WARRANTY; without even the implied warranty of
7720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7721 + General Public License for more details.
7726 +#include <string.h>
7731 +#include "pkg_parse.h"
7732 +#include "pkg_extract.h"
7733 +#include "ipkg_message.h"
7734 +#include "ipkg_utils.h"
7736 +#include "sprintf_alloc.h"
7737 +#include "file_util.h"
7738 +#include "str_util.h"
7739 +#include "xsystem.h"
7740 +#include "ipkg_conf.h"
7742 +typedef struct enum_map enum_map_t;
7749 +static const enum_map_t pkg_state_want_map[] = {
7750 + { SW_UNKNOWN, "unknown"},
7751 + { SW_INSTALL, "install"},
7752 + { SW_DEINSTALL, "deinstall"},
7753 + { SW_PURGE, "purge"}
7756 +static const enum_map_t pkg_state_flag_map[] = {
7758 + { SF_REINSTREQ, "reinstreq"},
7759 + { SF_HOLD, "hold"},
7760 + { SF_REPLACE, "replace"},
7761 + { SF_NOPRUNE, "noprune"},
7762 + { SF_PREFER, "prefer"},
7763 + { SF_OBSOLETE, "obsolete"},
7764 + { SF_USER, "user"},
7767 +static const enum_map_t pkg_state_status_map[] = {
7768 + { SS_NOT_INSTALLED, "not-installed" },
7769 + { SS_UNPACKED, "unpacked" },
7770 + { SS_HALF_CONFIGURED, "half-configured" },
7771 + { SS_INSTALLED, "installed" },
7772 + { SS_HALF_INSTALLED, "half-installed" },
7773 + { SS_CONFIG_FILES, "config-files" },
7774 + { SS_POST_INST_FAILED, "post-inst-failed" },
7775 + { SS_REMOVAL_FAILED, "removal-failed" }
7778 +static int verrevcmp(const char *val, const char *ref);
7781 +pkg_t *pkg_new(void)
7785 + pkg = malloc(sizeof(pkg_t));
7786 + if (pkg == NULL) {
7787 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7796 +int pkg_init(pkg_t *pkg)
7798 + memset(pkg, 0, sizeof(pkg_t));
7801 + pkg->version = NULL;
7802 + pkg->revision = NULL;
7803 + pkg->familiar_revision = NULL;
7806 + pkg->architecture = NULL;
7807 + pkg->maintainer = NULL;
7808 + pkg->section = NULL;
7809 + pkg->description = NULL;
7810 + pkg->state_want = SW_UNKNOWN;
7811 + pkg->state_flag = SF_OK;
7812 + pkg->state_status = SS_NOT_INSTALLED;
7813 + pkg->depends_str = NULL;
7814 + pkg->provides_str = NULL;
7815 + pkg->depends_count = 0;
7816 + pkg->depends = NULL;
7817 + pkg->suggests_str = NULL;
7818 + pkg->recommends_str = NULL;
7819 + pkg->suggests_count = 0;
7820 + pkg->recommends_count = 0;
7822 + /* Abhaya: added init for conflicts fields */
7823 + pkg->conflicts = NULL;
7824 + pkg->conflicts_count = 0;
7826 + /* added for replaces. Jamey 7/23/2002 */
7827 + pkg->replaces = NULL;
7828 + pkg->replaces_count = 0;
7830 + pkg->pre_depends_count = 0;
7831 + pkg->pre_depends_str = NULL;
7832 + pkg->provides_count = 0;
7833 + pkg->provides = NULL;
7834 + pkg->filename = NULL;
7835 + pkg->local_filename = NULL;
7836 + pkg->tmp_unpack_dir = NULL;
7837 + pkg->md5sum = NULL;
7839 + pkg->installed_size = NULL;
7840 + pkg->priority = NULL;
7841 + pkg->source = NULL;
7842 + conffile_list_init(&pkg->conffiles);
7843 + pkg->installed_files = NULL;
7844 + pkg->installed_files_ref_cnt = 0;
7845 + pkg->essential = 0;
7846 + pkg->provided_by_hand = 0;
7851 +void pkg_deinit(pkg_t *pkg)
7856 + free(pkg->version);
7857 + pkg->version = NULL;
7858 + /* revision and familiar_revision share storage with version, so
7860 + pkg->revision = NULL;
7861 + pkg->familiar_revision = NULL;
7862 + /* owned by ipkg_conf_t */
7864 + /* owned by ipkg_conf_t */
7866 + free(pkg->architecture);
7867 + pkg->architecture = NULL;
7868 + free(pkg->maintainer);
7869 + pkg->maintainer = NULL;
7870 + free(pkg->section);
7871 + pkg->section = NULL;
7872 + free(pkg->description);
7873 + pkg->description = NULL;
7874 + pkg->state_want = SW_UNKNOWN;
7875 + pkg->state_flag = SF_OK;
7876 + pkg->state_status = SS_NOT_INSTALLED;
7877 + free(pkg->depends_str);
7878 + pkg->depends_str = NULL;
7879 + free(pkg->provides_str);
7880 + pkg->provides_str = NULL;
7881 + pkg->depends_count = 0;
7882 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7883 + pkg->pre_depends_count = 0;
7884 + free(pkg->pre_depends_str);
7885 + pkg->pre_depends_str = NULL;
7886 + pkg->provides_count = 0;
7887 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7888 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7889 + free(pkg->filename);
7890 + pkg->filename = NULL;
7891 + free(pkg->local_filename);
7892 + pkg->local_filename = NULL;
7893 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7894 + ipkg_install.c here. See comment in
7895 + ipkg_install.c:cleanup_temporary_files */
7896 + free(pkg->tmp_unpack_dir);
7897 + pkg->tmp_unpack_dir = NULL;
7898 + free(pkg->md5sum);
7899 + pkg->md5sum = NULL;
7902 + free(pkg->installed_size);
7903 + pkg->installed_size = NULL;
7904 + free(pkg->priority);
7905 + pkg->priority = NULL;
7906 + free(pkg->source);
7907 + pkg->source = NULL;
7908 + conffile_list_deinit(&pkg->conffiles);
7909 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7910 + since if they are calling deinit, they should know. Maybe do an
7911 + assertion here instead? */
7912 + pkg->installed_files_ref_cnt = 1;
7913 + pkg_free_installed_files(pkg);
7914 + pkg->essential = 0;
7917 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7921 + FILE *control_file;
7923 + err = pkg_init(pkg);
7924 + if (err) { return err; }
7926 + pkg->local_filename = strdup(filename);
7928 + control_file = tmpfile();
7929 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7930 + if (err) { return err; }
7932 + rewind(control_file);
7933 + raw = read_raw_pkgs_from_stream(control_file);
7934 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7936 + fclose(control_file);
7941 +/* Merge any new information in newpkg into oldpkg */
7942 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7943 + newpkg, but should leave it usable. This rework is so that
7944 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7946 + * uh, i thought that i had originally written this so that it took
7947 + * two pkgs and returned a new one? we can do that again... -sma
7949 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7951 + if (oldpkg == newpkg) {
7956 + oldpkg->src = newpkg->src;
7957 + if (!oldpkg->dest)
7958 + oldpkg->dest = newpkg->dest;
7959 + if (!oldpkg->architecture)
7960 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7961 + if (!oldpkg->arch_priority)
7962 + oldpkg->arch_priority = newpkg->arch_priority;
7963 + if (!oldpkg->section)
7964 + oldpkg->section = str_dup_safe(newpkg->section);
7965 + if(!oldpkg->maintainer)
7966 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7967 + if(!oldpkg->description)
7968 + oldpkg->description = str_dup_safe(newpkg->description);
7970 + /* merge the state_flags from the new package */
7971 + oldpkg->state_want = newpkg->state_want;
7972 + oldpkg->state_status = newpkg->state_status;
7973 + oldpkg->state_flag = newpkg->state_flag;
7975 + if (oldpkg->state_want == SW_UNKNOWN)
7976 + oldpkg->state_want = newpkg->state_want;
7977 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7978 + oldpkg->state_status = newpkg->state_status;
7979 + oldpkg->state_flag |= newpkg->state_flag;
7982 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7983 + oldpkg->depends_str = newpkg->depends_str;
7984 + newpkg->depends_str = NULL;
7985 + oldpkg->depends_count = newpkg->depends_count;
7986 + newpkg->depends_count = 0;
7988 + oldpkg->depends = newpkg->depends;
7989 + newpkg->depends = NULL;
7991 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7992 + newpkg->pre_depends_str = NULL;
7993 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7994 + newpkg->pre_depends_count = 0;
7996 + oldpkg->recommends_str = newpkg->recommends_str;
7997 + newpkg->recommends_str = NULL;
7998 + oldpkg->recommends_count = newpkg->recommends_count;
7999 + newpkg->recommends_count = 0;
8001 + oldpkg->suggests_str = newpkg->suggests_str;
8002 + newpkg->suggests_str = NULL;
8003 + oldpkg->suggests_count = newpkg->suggests_count;
8004 + newpkg->suggests_count = 0;
8007 + if (!oldpkg->provides_str) {
8008 + oldpkg->provides_str = newpkg->provides_str;
8009 + newpkg->provides_str = NULL;
8010 + oldpkg->provides_count = newpkg->provides_count;
8011 + newpkg->provides_count = 0;
8013 + oldpkg->provides = newpkg->provides;
8014 + newpkg->provides = NULL;
8017 + if (!oldpkg->conflicts_str) {
8018 + oldpkg->conflicts_str = newpkg->conflicts_str;
8019 + newpkg->conflicts_str = NULL;
8020 + oldpkg->conflicts_count = newpkg->conflicts_count;
8021 + newpkg->conflicts_count = 0;
8023 + oldpkg->conflicts = newpkg->conflicts;
8024 + newpkg->conflicts = NULL;
8027 + if (!oldpkg->replaces_str) {
8028 + oldpkg->replaces_str = newpkg->replaces_str;
8029 + newpkg->replaces_str = NULL;
8030 + oldpkg->replaces_count = newpkg->replaces_count;
8031 + newpkg->replaces_count = 0;
8033 + oldpkg->replaces = newpkg->replaces;
8034 + newpkg->replaces = NULL;
8037 + if (!oldpkg->filename)
8038 + oldpkg->filename = str_dup_safe(newpkg->filename);
8040 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8041 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8042 + if (!oldpkg->local_filename)
8043 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8044 + if (!oldpkg->tmp_unpack_dir)
8045 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8046 + if (!oldpkg->md5sum)
8047 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8048 + if (!oldpkg->size)
8049 + oldpkg->size = str_dup_safe(newpkg->size);
8050 + if (!oldpkg->installed_size)
8051 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8052 + if (!oldpkg->priority)
8053 + oldpkg->priority = str_dup_safe(newpkg->priority);
8054 + if (!oldpkg->source)
8055 + oldpkg->source = str_dup_safe(newpkg->source);
8056 + if (oldpkg->conffiles.head == NULL){
8057 + oldpkg->conffiles = newpkg->conffiles;
8058 + conffile_list_init(&newpkg->conffiles);
8060 + if (!oldpkg->installed_files){
8061 + oldpkg->installed_files = newpkg->installed_files;
8062 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8063 + newpkg->installed_files = NULL;
8065 + if (!oldpkg->essential)
8066 + oldpkg->essential = newpkg->essential;
8071 +abstract_pkg_t *abstract_pkg_new(void)
8073 + abstract_pkg_t * ab_pkg;
8075 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8077 + if (ab_pkg == NULL) {
8078 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8082 + if ( abstract_pkg_init(ab_pkg) < 0 )
8088 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8090 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8092 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8093 + if (ab_pkg->provided_by==NULL){
8096 + ab_pkg->dependencies_checked = 0;
8097 + ab_pkg->state_status = SS_NOT_INSTALLED;
8102 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8105 + char **raw_start=NULL;
8107 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8108 + if (temp_str == NULL ){
8109 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8112 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8114 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8115 + if (raw == NULL ){
8116 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8121 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8122 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8138 +char * pkg_formatted_info(pkg_t *pkg )
8143 + buff = malloc(8192);
8144 + if (buff == NULL) {
8145 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8151 + line = pkg_formatted_field(pkg, "Package");
8152 + strncat(buff ,line, strlen(line));
8155 + line = pkg_formatted_field(pkg, "Version");
8156 + strncat(buff ,line, strlen(line));
8159 + line = pkg_formatted_field(pkg, "Depends");
8160 + strncat(buff ,line, strlen(line));
8163 + line = pkg_formatted_field(pkg, "Recommends");
8164 + strncat(buff ,line, strlen(line));
8167 + line = pkg_formatted_field(pkg, "Suggests");
8168 + strncat(buff ,line, strlen(line));
8171 + line = pkg_formatted_field(pkg, "Provides");
8172 + strncat(buff ,line, strlen(line));
8175 + line = pkg_formatted_field(pkg, "Replaces");
8176 + strncat(buff ,line, strlen(line));
8179 + line = pkg_formatted_field(pkg, "Conflicts");
8180 + strncat(buff ,line, strlen(line));
8183 + line = pkg_formatted_field(pkg, "Status");
8184 + strncat(buff ,line, strlen(line));
8187 + line = pkg_formatted_field(pkg, "Section");
8188 + strncat(buff ,line, strlen(line));
8191 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8192 + strncat(buff ,line, strlen(line));
8195 + line = pkg_formatted_field(pkg, "Architecture");
8196 + strncat(buff ,line, strlen(line));
8199 + line = pkg_formatted_field(pkg, "Maintainer");
8200 + strncat(buff ,line, strlen(line));
8203 + line = pkg_formatted_field(pkg, "MD5sum");
8204 + strncat(buff ,line, strlen(line));
8207 + line = pkg_formatted_field(pkg, "Size");
8208 + strncat(buff ,line, strlen(line));
8211 + line = pkg_formatted_field(pkg, "Filename");
8212 + strncat(buff ,line, strlen(line));
8215 + line = pkg_formatted_field(pkg, "Conffiles");
8216 + strncat(buff ,line, strlen(line));
8219 + line = pkg_formatted_field(pkg, "Source");
8220 + strncat(buff ,line, strlen(line));
8223 + line = pkg_formatted_field(pkg, "Description");
8224 + strncat(buff ,line, strlen(line));
8227 + line = pkg_formatted_field(pkg, "Installed-Time");
8228 + strncat(buff ,line, strlen(line));
8234 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8236 + static size_t LINE_LEN = 128;
8237 + char * temp = (char *)malloc(1);
8239 + int flag_provide_false = 0;
8242 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8243 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8246 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8247 + goto UNKNOWN_FMT_FIELD;
8256 + if (strcasecmp(field, "Architecture") == 0) {
8257 + /* Architecture */
8258 + if (pkg->architecture) {
8259 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8260 + if ( temp == NULL ){
8261 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8265 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8268 + goto UNKNOWN_FMT_FIELD;
8273 + if (strcasecmp(field, "Conffiles") == 0) {
8275 + conffile_list_elt_t *iter;
8276 + char confstr[LINE_LEN];
8278 + if (pkg->conffiles.head == NULL) {
8283 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8284 + if (iter->data->name && iter->data->value) {
8285 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8288 + temp = (char *)realloc(temp,len);
8289 + if ( temp == NULL ){
8290 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8294 + strncpy(temp, "Conffiles:\n", 12);
8295 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8296 + if (iter->data->name && iter->data->value) {
8297 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8298 + strncat(temp, confstr, strlen(confstr));
8301 + } else if (strcasecmp(field, "Conflicts") == 0) {
8304 + if (pkg->conflicts_count) {
8305 + char conflictstr[LINE_LEN];
8307 + for(i = 0; i < pkg->conflicts_count; i++) {
8308 + len = len + (strlen(pkg->conflicts_str[i])+5);
8310 + temp = (char *)realloc(temp,len);
8311 + if ( temp == NULL ){
8312 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8316 + strncpy(temp, "Conflicts:", 11);
8317 + for(i = 0; i < pkg->conflicts_count; i++) {
8318 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8319 + strncat(temp, conflictstr, strlen(conflictstr));
8321 + strncat(temp, "\n", strlen("\n"));
8324 + goto UNKNOWN_FMT_FIELD;
8329 + if (strcasecmp(field, "Depends") == 0) {
8333 + if (pkg->depends_count) {
8334 + char depstr[LINE_LEN];
8336 + for(i = 0; i < pkg->depends_count; i++) {
8337 + len = len + (strlen(pkg->depends_str[i])+4);
8339 + temp = (char *)realloc(temp,len);
8340 + if ( temp == NULL ){
8341 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8345 + strncpy(temp, "Depends:", 10);
8346 + for(i = 0; i < pkg->depends_count; i++) {
8347 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8348 + strncat(temp, depstr, strlen(depstr));
8350 + strncat(temp, "\n", strlen("\n"));
8352 + } else if (strcasecmp(field, "Description") == 0) {
8354 + if (pkg->description) {
8355 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8356 + if ( temp == NULL ){
8357 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8361 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8364 + goto UNKNOWN_FMT_FIELD;
8370 + if (pkg->essential) {
8371 + temp = (char *)realloc(temp,16);
8372 + if ( temp == NULL ){
8373 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8377 + snprintf(temp, (16), "Essential: yes\n");
8384 + if (pkg->filename) {
8385 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8386 + if ( temp == NULL ){
8387 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8391 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8397 + if (strcasecmp(field, "Installed-Size") == 0) {
8398 + /* Installed-Size */
8399 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8400 + if ( temp == NULL ){
8401 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8405 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8406 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8407 + temp = (char *)realloc(temp,29);
8408 + if ( temp == NULL ){
8409 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8413 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8419 + /* Maintainer | MD5sum */
8420 + if (strcasecmp(field, "Maintainer") == 0) {
8422 + if (pkg->maintainer) {
8423 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8424 + if ( temp == NULL ){
8425 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8429 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8431 + } else if (strcasecmp(field, "MD5sum") == 0) {
8433 + if (pkg->md5sum) {
8434 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8435 + if ( temp == NULL ){
8436 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8440 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8443 + goto UNKNOWN_FMT_FIELD;
8449 + if (strcasecmp(field, "Package") == 0) {
8451 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8452 + if ( temp == NULL ){
8453 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8457 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8458 + } else if (strcasecmp(field, "Priority") == 0) {
8460 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8461 + if ( temp == NULL ){
8462 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8466 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8467 + } else if (strcasecmp(field, "Provides") == 0) {
8471 + if (pkg->provides_count) {
8472 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8473 + for ( i=0; i < pkg->provides_count; i++ ){
8474 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8475 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8476 + flag_provide_false = 1;
8479 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8480 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8481 + char provstr[LINE_LEN];
8483 + for(i = 0; i < pkg->provides_count; i++) {
8484 + len = len + (strlen(pkg->provides_str[i])+5);
8486 + temp = (char *)realloc(temp,len);
8487 + if ( temp == NULL ){
8488 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8492 + strncpy(temp, "Provides:", 12);
8493 + for(i = 0; i < pkg->provides_count; i++) {
8494 + if (strlen(pkg->provides_str[i])>0){;
8495 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8496 + strncat(temp, provstr, strlen(provstr));
8499 + strncat(temp, "\n", strlen("\n"));
8503 + goto UNKNOWN_FMT_FIELD;
8510 + /* Replaces | Recommends*/
8511 + if (strcasecmp (field, "Replaces") == 0) {
8512 + if (pkg->replaces_count) {
8513 + char replstr[LINE_LEN];
8515 + for (i = 0; i < pkg->replaces_count; i++) {
8516 + len = len + (strlen(pkg->replaces_str[i])+5);
8518 + temp = (char *)realloc(temp,len);
8519 + if ( temp == NULL ){
8520 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8524 + strncpy(temp, "Replaces:", 12);
8525 + for (i = 0; i < pkg->replaces_count; i++) {
8526 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8527 + strncat(temp, replstr, strlen(replstr));
8529 + strncat(temp, "\n", strlen("\n"));
8531 + } else if (strcasecmp (field, "Recommends") == 0) {
8532 + if (pkg->recommends_count) {
8533 + char recstr[LINE_LEN];
8535 + for(i = 0; i < pkg->recommends_count; i++) {
8536 + len = len + (strlen( pkg->recommends_str[i])+5);
8538 + temp = (char *)realloc(temp,len);
8539 + if ( temp == NULL ){
8540 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8544 + strncpy(temp, "Recommends:", 13);
8545 + for(i = 0; i < pkg->recommends_count; i++) {
8546 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8547 + strncat(temp, recstr, strlen(recstr));
8549 + strncat(temp, "\n", strlen("\n"));
8552 + goto UNKNOWN_FMT_FIELD;
8558 + /* Section | Size | Source | Status | Suggests */
8559 + if (strcasecmp(field, "Section") == 0) {
8561 + if (pkg->section) {
8562 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8563 + if ( temp == NULL ){
8564 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8568 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8570 + } else if (strcasecmp(field, "Size") == 0) {
8573 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8574 + if ( temp == NULL ){
8575 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8579 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8581 + } else if (strcasecmp(field, "Source") == 0) {
8583 + if (pkg->source) {
8584 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8585 + if ( temp == NULL ){
8586 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8590 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8592 + } else if (strcasecmp(field, "Status") == 0) {
8594 + /* Benjamin Pineau note: we should avoid direct usage of
8595 + * strlen(arg) without keeping "arg" for later free()
8597 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8598 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8599 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8601 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8602 + temp = (char *)realloc(temp,sum_of_sizes);
8603 + if ( temp == NULL ){
8604 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8608 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8611 + if(pstat) /* pfstat can be NULL if ENOMEM */
8613 + } else if (strcasecmp(field, "Suggests") == 0) {
8614 + if (pkg->suggests_count) {
8616 + char sugstr[LINE_LEN];
8618 + for(i = 0; i < pkg->suggests_count; i++) {
8619 + len = len + (strlen(pkg->suggests_str[i])+5);
8621 + temp = (char *)realloc(temp,len);
8622 + if ( temp == NULL ){
8623 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8627 + strncpy(temp, "Suggests:", 10);
8628 + for(i = 0; i < pkg->suggests_count; i++) {
8629 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8630 + strncat(temp, sugstr, strlen(sugstr));
8632 + strncat(temp, "\n", strlen("\n"));
8635 + goto UNKNOWN_FMT_FIELD;
8642 + char *version = pkg_version_str_alloc(pkg);
8643 + temp = (char *)realloc(temp,strlen(version)+14);
8644 + if ( temp == NULL ){
8645 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8649 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8654 + goto UNKNOWN_FMT_FIELD;
8657 + if ( strlen(temp)<2 ) {
8662 + UNKNOWN_FMT_FIELD:
8663 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8664 + if ( strlen(temp)<2 ) {
8671 +void pkg_print_info(pkg_t *pkg, FILE *file)
8674 + if (pkg == NULL) {
8678 + buff = pkg_formatted_info(pkg);
8679 + if ( buff == NULL )
8681 + if (strlen(buff)>2){
8682 + fwrite(buff, 1, strlen(buff), file);
8687 +void pkg_print_status(pkg_t * pkg, FILE * file)
8689 + if (pkg == NULL) {
8693 + /* XXX: QUESTION: Do we actually want more fields here? The
8694 + original idea was to save space by installing only what was
8695 + needed for actual computation, (package, version, status,
8696 + essential, conffiles). The assumption is that all other fields
8697 + can be found in th available file.
8699 + But, someone proposed the idea to make it possible to
8700 + reconstruct a .ipk from an installed package, (ie. for beaming
8701 + from one handheld to another). So, maybe we actually want a few
8702 + more fields here, (depends, suggests, etc.), so that that would
8703 + be guaranteed to work even in the absence of more information
8704 + from the available file.
8706 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8707 + the essential info needs to be here for all installed packages
8708 + because they may not appear in the Packages files on various
8709 + feeds. Furthermore, one should be able to install from URL or
8710 + local storage without requiring a Packages file from any feed.
8713 + pkg_print_field(pkg, file, "Package");
8714 + pkg_print_field(pkg, file, "Version");
8715 + pkg_print_field(pkg, file, "Depends");
8716 + pkg_print_field(pkg, file, "Recommends");
8717 + pkg_print_field(pkg, file, "Suggests");
8718 + pkg_print_field(pkg, file, "Provides");
8719 + pkg_print_field(pkg, file, "Replaces");
8720 + pkg_print_field(pkg, file, "Conflicts");
8721 + pkg_print_field(pkg, file, "Status");
8722 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8723 + pkg_print_field(pkg, file, "Architecture");
8724 + pkg_print_field(pkg, file, "Conffiles");
8725 + pkg_print_field(pkg, file, "Installed-Time");
8726 + fputs("\n", file);
8729 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8732 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8733 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8734 + __FUNCTION__, field);
8736 + buff = pkg_formatted_field(pkg, field);
8737 + if (strlen(buff)>2) {
8738 + fprintf(file, "%s", buff);
8746 + * libdpkg - Debian packaging suite library routines
8747 + * vercmp.c - comparison of version numbers
8749 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8751 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8755 + if (pkg->epoch > ref_pkg->epoch) {
8759 + if (pkg->epoch < ref_pkg->epoch) {
8763 + r = verrevcmp(pkg->version, ref_pkg->version);
8768 +#ifdef USE_DEBVERSION
8769 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8774 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8780 +int verrevcmp(const char *val, const char *ref)
8784 + const char *vp, *rp;
8785 + const char *vsep, *rsep;
8787 + if (!val) val= "";
8788 + if (!ref) ref= "";
8790 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8791 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8793 + vc= (val == vp) ? 0 : *val++;
8794 + rc= (ref == rp) ? 0 : *ref++;
8795 + if (!rc && !vc) break;
8796 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8797 + if (rc && !isalpha(rc)) rc += 256;
8798 + if (vc != rc) return vc - rc;
8802 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8803 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8804 + if (vl != rl) return vl - rl;
8808 + vsep = strchr(".-", vc);
8809 + rsep = strchr(".-", rc);
8810 + if (vsep && !rsep) return -1;
8811 + if (!vsep && rsep) return +1;
8813 + if (!*val && !*ref) return 0;
8814 + if (!*val) return -1;
8815 + if (!*ref) return +1;
8819 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8823 + r = pkg_compare_versions(it, ref);
8825 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8829 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8833 + if (strcmp(op, "<<") == 0) {
8837 + if (strcmp(op, ">>") == 0) {
8841 + if (strcmp(op, "=") == 0) {
8845 + fprintf(stderr, "unknown operator: %s", op);
8849 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8851 + const pkg_t *a = *(const pkg_t **)p1;
8852 + const pkg_t *b = *(const pkg_t **)p2;
8855 + if (!a->name || !b->name) {
8856 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8857 + a, a->name, b, b->name);
8861 + namecmp = strcmp(a->name, b->name);
8864 + vercmp = pkg_compare_versions(a, b);
8867 + if (!a->arch_priority || !b->arch_priority) {
8868 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8869 + a, a->arch_priority, b, b->arch_priority);
8872 + if (a->arch_priority > b->arch_priority)
8874 + if (a->arch_priority < b->arch_priority)
8879 +int abstract_pkg_name_compare(void *p1, void *p2)
8881 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8882 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8883 + if (!a->name || !b->name) {
8884 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8885 + a, a->name, b, b->name);
8888 + return strcmp(a->name, b->name);
8892 +char *pkg_version_str_alloc(pkg_t *pkg)
8894 + char *complete_version;
8896 +#ifdef USE_DEBVERSION
8897 + char *revision_str;
8898 + char *familiar_revision_str;
8902 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8904 + epoch_str = strdup("");
8907 +#ifdef USE_DEBVERSION
8908 + if (pkg->revision && strlen(pkg->revision)) {
8909 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8911 + revision_str = strdup("");
8914 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8915 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8917 + familiar_revision_str = strdup("");
8921 +#ifdef USE_DEBVERSION
8922 + sprintf_alloc(&complete_version, "%s%s%s%s",
8923 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8925 + sprintf_alloc(&complete_version, "%s%s",
8926 + epoch_str, pkg->version);
8930 +#ifdef USE_DEBVERSION
8931 + free(revision_str);
8932 + free(familiar_revision_str);
8935 + return complete_version;
8938 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8941 + char *list_file_name = NULL;
8942 + FILE *list_file = NULL;
8944 + char *installed_file_name;
8947 + pkg->installed_files_ref_cnt++;
8949 + if (pkg->installed_files) {
8950 + return pkg->installed_files;
8953 + pkg->installed_files = str_list_alloc();
8954 + if (pkg->installed_files == NULL) {
8955 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8959 + /* For uninstalled packages, get the file list firectly from the package.
8960 + For installed packages, look at the package.list file in the database.
8962 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8963 + if (pkg->local_filename == NULL) {
8964 + return pkg->installed_files;
8966 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8967 + file. In other words, change deb_extract so that it can
8968 + simply return the file list as a char *[] rather than
8969 + insisting on writing in to a FILE * as it does now. */
8970 + list_file = tmpfile();
8971 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8973 + fclose(list_file);
8974 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8975 + __FUNCTION__, pkg->local_filename, strerror(err));
8976 + return pkg->installed_files;
8978 + rewind(list_file);
8980 + sprintf_alloc(&list_file_name, "%s/%s.list",
8981 + pkg->dest->info_dir, pkg->name);
8982 + if (! file_exists(list_file_name)) {
8983 + free(list_file_name);
8984 + return pkg->installed_files;
8987 + list_file = fopen(list_file_name, "r");
8988 + if (list_file == NULL) {
8989 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8990 + list_file_name, strerror(errno));
8991 + free(list_file_name);
8992 + return pkg->installed_files;
8994 + free(list_file_name);
8997 + rootdirlen = strlen( pkg->dest->root_dir );
9001 + line = file_read_line_alloc(list_file);
9002 + if (line == NULL) {
9008 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9009 + if( strncmp( pkg->dest->root_dir,
9012 + if (*file_name == '.') {
9015 + if (*file_name == '/') {
9019 + /* Freed in pkg_free_installed_files */
9020 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9022 + // already contains root_dir as header -> ABSOLUTE
9023 + sprintf_alloc(&installed_file_name, "%s", file_name);
9025 + str_list_append(pkg->installed_files, installed_file_name);
9029 + fclose(list_file);
9031 + return pkg->installed_files;
9034 +/* XXX: CLEANUP: This function and it's counterpart,
9035 + (pkg_get_installed_files), do not match our init/deinit naming
9036 + convention. Nor the alloc/free convention. But, then again, neither
9037 + of these conventions currrently fit the way these two functions
9039 +int pkg_free_installed_files(pkg_t *pkg)
9041 + str_list_elt_t *iter;
9043 + pkg->installed_files_ref_cnt--;
9044 + if (pkg->installed_files_ref_cnt > 0) {
9048 + if (pkg->installed_files) {
9050 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9051 + /* malloced in pkg_get_installed_files */
9052 + free (iter->data);
9053 + iter->data = NULL;
9056 + str_list_deinit(pkg->installed_files);
9059 + pkg->installed_files = NULL;
9064 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9067 + char *list_file_name;
9069 + //I don't think pkg_free_installed_files should be called here. Jamey
9070 + //pkg_free_installed_files(pkg);
9072 + sprintf_alloc(&list_file_name, "%s/%s.list",
9073 + pkg->dest->info_dir, pkg->name);
9074 + if (!conf->noaction) {
9075 + err = unlink(list_file_name);
9076 + free(list_file_name);
9085 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9087 + conffile_list_elt_t *iter;
9088 + conffile_t *conffile;
9090 + if (pkg == NULL) {
9094 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9095 + conffile = iter->data;
9097 + if (strcmp(conffile->name, file_name) == 0) {
9105 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9106 + const char *script, const char *args)
9112 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9113 + maintainer script within a chroot environment. */
9115 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9116 + have scripts in pkg->tmp_unpack_dir. */
9117 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9118 + if (pkg->dest == NULL) {
9119 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9120 + __FUNCTION__, pkg->name);
9123 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9125 + if (pkg->tmp_unpack_dir == NULL) {
9126 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9127 + __FUNCTION__, pkg->name);
9130 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9133 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9134 + if (conf->noaction) return 0;
9136 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9137 + scripts when running with offline_root mode and/or a dest other
9138 + than '/'. I've been playing around with some clever chroot
9139 + tricks and I might come up with something workable. */
9140 + if (conf->offline_root) {
9141 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9144 + setenv("PKG_ROOT",
9145 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9147 + if (! file_exists(path)) {
9152 + if (conf->offline_root) {
9153 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9158 + sprintf_alloc(&cmd, "%s %s", path, args);
9161 + err = xsystem(cmd);
9165 + fprintf(stderr, "%s script returned status %d\n", script, err);
9172 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9176 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9177 + if (pkg_state_want_map[i].value == sw) {
9178 + return strdup(pkg_state_want_map[i].str);
9182 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9183 + __FUNCTION__, sw);
9184 + return strdup("<STATE_WANT_UNKNOWN>");
9187 +pkg_state_want_t pkg_state_want_from_str(char *str)
9191 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9192 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9193 + return pkg_state_want_map[i].value;
9197 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9198 + __FUNCTION__, str);
9199 + return SW_UNKNOWN;
9202 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9205 + int len = 3; /* ok\000 is minimum */
9208 + /* clear the temporary flags before converting to string */
9209 + sf &= SF_NONVOLATILE_FLAGS;
9212 + return strdup("ok");
9215 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9216 + if (sf & pkg_state_flag_map[i].value) {
9217 + len += strlen(pkg_state_flag_map[i].str) + 1;
9220 + str = malloc(len);
9221 + if ( str == NULL ) {
9222 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9226 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9227 + if (sf & pkg_state_flag_map[i].value) {
9228 + strcat(str, pkg_state_flag_map[i].str);
9232 + len = strlen(str);
9233 + str[len-1] = 0; /* squash last comma */
9238 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9243 + if (strcmp(str, "ok") == 0) {
9246 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9247 + const char *sfname = pkg_state_flag_map[i].str;
9248 + int sfname_len = strlen(sfname);
9249 + if (strncmp(str, sfname, sfname_len) == 0) {
9250 + sf |= pkg_state_flag_map[i].value;
9251 + str += sfname_len;
9252 + if (str[0] == ',') {
9263 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9267 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9268 + if (pkg_state_status_map[i].value == ss) {
9269 + return strdup(pkg_state_status_map[i].str);
9273 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9274 + __FUNCTION__, ss);
9275 + return strdup("<STATE_STATUS_UNKNOWN>");
9278 +pkg_state_status_t pkg_state_status_from_str(char *str)
9282 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9283 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9284 + return pkg_state_status_map[i].value;
9288 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9289 + __FUNCTION__, str);
9290 + return SS_NOT_INSTALLED;
9293 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9295 + nv_pair_list_elt_t *l;
9297 + if (!pkg->architecture)
9300 + l = conf->arch_list.head;
9303 + nv_pair_t *nv = l->data;
9304 + if (strcmp(nv->name, pkg->architecture) == 0) {
9305 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9311 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9315 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9317 + nv_pair_list_elt_t *l;
9319 + l = conf->arch_list.head;
9322 + nv_pair_t *nv = l->data;
9323 + if (strcmp(nv->name, archname) == 0) {
9324 + int priority = strtol(nv->value, NULL, 0);
9332 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9335 + hash_table_t *pkg_hash = &conf->pkg_hash;
9336 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9337 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9339 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9340 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9341 + /* update arch_priority for each package */
9342 + for (i = 0; i < available_pkgs->len; i++) {
9343 + pkg_t *pkg = available_pkgs->pkgs[i];
9344 + int arch_priority = 1;
9347 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9348 + if (pkg->architecture)
9349 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9351 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9352 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9353 + pkg->arch_priority = arch_priority;
9356 + for (i = 0; i < available_pkgs->len; i++) {
9357 + pkg_t *pkg = available_pkgs->pkgs[i];
9358 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9359 + /* clear flags and want for any uninstallable package */
9360 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9361 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9362 + pkg->state_want = SW_UNKNOWN;
9363 + pkg->state_flag = 0;
9366 + pkg_vec_free(available_pkgs);
9368 + /* update the file owner data structure */
9369 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9370 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9371 + for (i = 0; i < installed_pkgs->len; i++) {
9372 + pkg_t *pkg = installed_pkgs->pkgs[i];
9373 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9374 + str_list_elt_t *iter;
9375 + if (installed_files == NULL) {
9376 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9379 + for (iter = installed_files->head; iter; iter = iter->next) {
9380 + char *installed_file = iter->data;
9381 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9382 + file_hash_set_file_owner(conf, installed_file, pkg);
9385 + pkg_vec_free(installed_pkgs);
9390 +struct pkg_write_filelist_data {
9391 + ipkg_conf_t *conf;
9396 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9398 + struct pkg_write_filelist_data *data = data_;
9399 + pkg_t *entry = entry_;
9400 + if (entry == data->pkg) {
9401 + fprintf(data->stream, "%s\n", key);
9405 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9407 + struct pkg_write_filelist_data data;
9408 + char *list_file_name = NULL;
9412 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9415 + ipkg_message(conf, IPKG_INFO,
9416 + " creating %s.list file\n", pkg->name);
9417 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9418 + if (!list_file_name) {
9419 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9422 + ipkg_message(conf, IPKG_INFO,
9423 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9424 + data.stream = fopen(list_file_name, "w");
9425 + if (!data.stream) {
9426 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9427 + list_file_name, strerror(errno));
9432 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9433 + fclose(data.stream);
9434 + free(list_file_name);
9439 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9441 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9442 + hash_table_t *pkg_hash = &conf->pkg_hash;
9445 + if (conf->noaction)
9448 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9449 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9450 + for (i = 0; i < installed_pkgs->len; i++) {
9451 + pkg_t *pkg = installed_pkgs->pkgs[i];
9452 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9453 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9454 + err = pkg_write_filelist(conf, pkg);
9456 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9461 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
9462 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9463 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-07-22 16:31:25.000000000 +0200
9465 +/* pkg_depends.c - the itsy package management system
9469 + Copyright (C) 2002 Compaq Computer Corporation
9471 + This program is free software; you can redistribute it and/or
9472 + modify it under the terms of the GNU General Public License as
9473 + published by the Free Software Foundation; either version 2, or (at
9474 + your option) any later version.
9476 + This program is distributed in the hope that it will be useful, but
9477 + WITHOUT ANY WARRANTY; without even the implied warranty of
9478 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9479 + General Public License for more details.
9487 +#include "ipkg_utils.h"
9488 +#include "pkg_hash.h"
9489 +#include "ipkg_message.h"
9490 +#include "pkg_parse.h"
9491 +#include "hash_table.h"
9493 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9494 +static depend_t * depend_init(void);
9495 +static void depend_deinit(depend_t *d);
9496 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9497 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9498 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9500 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9502 + depend_t *depend = (depend_t *)cdata;
9503 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9509 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9511 + depend_t *depend = (depend_t *)cdata;
9513 + pkg_t * temp = pkg_new();
9515 + parseVersion(temp, depend->version);
9516 + comparison = pkg_compare_versions(pkg, temp);
9519 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9520 + __FUNCTION__, pkg->name, pkg->version,
9521 + depend, depend->constraint, depend->version,
9522 + comparison, version_constraints_satisfied(depend, pkg));
9524 + if (version_constraints_satisfied(depend, pkg))
9530 +/* returns ndependences or negative error value */
9531 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9532 + pkg_vec_t *unsatisfied, char *** unresolved)
9534 + pkg_t * satisfier_entry_pkg;
9535 + register int i, j, k;
9538 + abstract_pkg_t * ab_pkg;
9541 + * this is a setup to check for redundant/cyclic dependency checks,
9542 + * which are marked at the abstract_pkg level
9544 + if (!(ab_pkg = pkg->parent)) {
9545 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9546 + *unresolved = NULL;
9549 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9550 + *unresolved = NULL;
9553 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9557 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9559 + *unresolved = NULL;
9565 + /* foreach dependency */
9566 + for (i = 0; i < count; i++) {
9567 + compound_depend_t * compound_depend = &pkg->depends[i];
9568 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9570 + satisfier_entry_pkg = NULL;
9572 + if (compound_depend->type == GREEDY_DEPEND) {
9573 + /* foreach possible satisfier */
9574 + for (j = 0; j < compound_depend->possibility_count; j++) {
9575 + /* foreach provided_by, which includes the abstract_pkg itself */
9576 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9577 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9578 + int nposs = ab_provider_vec->len;
9579 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9581 + for (l = 0; l < nposs; l++) {
9582 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9583 + /* if no depends on this one, try the first package that Provides this one */
9584 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9588 + /* cruise this possiblity's pkg_vec looking for an installed version */
9589 + for (k = 0; k < test_vec->len; k++) {
9590 + pkg_t *pkg_scout = test_vec->pkgs[k];
9591 + /* not installed, and not already known about? */
9592 + if ((pkg_scout->state_want != SW_INSTALL)
9593 + && !pkg_scout->parent->dependencies_checked
9594 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9595 + char ** newstuff = NULL;
9597 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9598 + /* check for not-already-installed dependencies */
9599 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9603 + if (newstuff == NULL) {
9606 + for (i = 0; i < rc; i++) {
9607 + pkg_t *p = tmp_vec->pkgs[i];
9608 + if (p->state_want == SW_INSTALL)
9610 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9614 + pkg_vec_free (tmp_vec);
9616 + /* mark this one for installation */
9617 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9618 + pkg_vec_insert(unsatisfied, pkg_scout);
9621 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9632 + /* foreach possible satisfier, look for installed package */
9633 + for (j = 0; j < compound_depend->possibility_count; j++) {
9634 + /* foreach provided_by, which includes the abstract_pkg itself */
9635 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9636 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9637 + pkg_t *satisfying_pkg =
9638 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9639 + pkg_installed_and_constraint_satisfied,
9640 + dependence_to_satisfy, 1);
9641 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9642 + if (satisfying_pkg != NULL) {
9643 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9644 + satisfying_pkg = NULL;
9647 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9648 + if (satisfying_pkg != NULL) {
9654 + /* if nothing installed matches, then look for uninstalled satisfier */
9656 + /* foreach possible satisfier, look for installed package */
9657 + for (j = 0; j < compound_depend->possibility_count; j++) {
9658 + /* foreach provided_by, which includes the abstract_pkg itself */
9659 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9660 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9661 + pkg_t *satisfying_pkg =
9662 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9663 + pkg_constraint_satisfied,
9664 + dependence_to_satisfy, 1);
9665 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9666 + if (satisfying_pkg != NULL) {
9667 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9668 + satisfying_pkg = NULL;
9672 + /* user request overrides package recommendation */
9673 + if (satisfying_pkg != NULL
9674 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9675 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9676 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9677 + pkg->name, satisfying_pkg->name);
9681 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9682 + if (satisfying_pkg != NULL) {
9683 + satisfier_entry_pkg = satisfying_pkg;
9689 + /* we didn't find one, add something to the unsatisfied vector */
9691 + if (!satisfier_entry_pkg) {
9692 + /* failure to meet recommendations is not an error */
9693 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9694 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9696 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9697 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9700 + if (compound_depend->type == SUGGEST) {
9701 + /* just mention it politely */
9702 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9703 + pkg->name, satisfier_entry_pkg->name);
9705 + char ** newstuff = NULL;
9707 + if (satisfier_entry_pkg != pkg &&
9708 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9709 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9710 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9711 + satisfier_entry_pkg,
9714 + the_lost = merge_unresolved(the_lost, newstuff);
9720 + *unresolved = the_lost;
9722 + return unsatisfied->len;
9725 +/*checking for conflicts !in replaces
9726 + If a packages conflicts with another but is also replacing it, I should not consider it a
9728 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9730 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9733 + int replaces_count = pkg->replaces_count;
9734 + abstract_pkg_t **replaces;
9736 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9739 + replaces = pkg->replaces;
9741 + for (i = 0; i < replaces_count; i++) {
9742 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9743 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9752 +/* Abhaya: added support for conflicts */
9753 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9755 + pkg_vec_t * installed_conflicts, * test_vec;
9756 + compound_depend_t * conflicts;
9757 + depend_t ** possible_satisfiers;
9758 + depend_t * possible_satisfier;
9759 + register int i, j, k;
9761 + abstract_pkg_t * ab_pkg;
9762 + pkg_t **pkg_scouts;
9766 + * this is a setup to check for redundant/cyclic dependency checks,
9767 + * which are marked at the abstract_pkg level
9769 + if(!(ab_pkg = pkg->parent)){
9770 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9771 + return (pkg_vec_t *)NULL;
9774 + conflicts = pkg->conflicts;
9776 + return (pkg_vec_t *)NULL;
9778 + installed_conflicts = pkg_vec_alloc();
9780 + count = pkg->conflicts_count;
9784 + /* foreach conflict */
9785 + for(i = 0; i < pkg->conflicts_count; i++){
9787 + possible_satisfiers = conflicts->possibilities;
9789 + /* foreach possible satisfier */
9790 + for(j = 0; j < conflicts->possibility_count; j++){
9791 + possible_satisfier = possible_satisfiers[j];
9792 + if (!possible_satisfier)
9793 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9794 + if (!possible_satisfier->pkg)
9795 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9796 + test_vec = possible_satisfier->pkg->pkgs;
9798 + /* pkg_vec found, it is an actual package conflict
9799 + * cruise this possiblity's pkg_vec looking for an installed version */
9800 + pkg_scouts = test_vec->pkgs;
9801 + for(k = 0; k < test_vec->len; k++){
9802 + pkg_scout = pkg_scouts[k];
9804 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9807 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9808 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9809 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9810 + pkg_vec_insert(installed_conflicts, pkg_scout);
9819 + if (installed_conflicts->len)
9820 + return installed_conflicts;
9821 + pkg_vec_free(installed_conflicts);
9822 + return (pkg_vec_t *)NULL;
9825 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9830 + if(depends->constraint == NONE)
9835 + parseVersion(temp, depends->version);
9837 + comparison = pkg_compare_versions(pkg, temp);
9841 + if((depends->constraint == EARLIER) &&
9844 + else if((depends->constraint == LATER) &&
9847 + else if(comparison == 0)
9849 + else if((depends->constraint == LATER_EQUAL) &&
9850 + (comparison >= 0))
9852 + else if((depends->constraint == EARLIER_EQUAL) &&
9853 + (comparison <= 0))
9859 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9861 + abstract_pkg_t *apkg = depend->pkg;
9862 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9863 + int n_providers = provider_apkgs->len;
9864 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9865 + pkg_vec_t *pkg_vec;
9870 + for (i = 0; i < n_providers; i++) {
9871 + abstract_pkg_t *papkg = apkgs[i];
9872 + pkg_vec = papkg->pkgs;
9874 + n_pkgs = pkg_vec->len;
9875 + for (j = 0; j < n_pkgs; j++) {
9876 + pkg_t *pkg = pkg_vec->pkgs[j];
9877 + if (version_constraints_satisfied(depend, pkg)) {
9886 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9888 + abstract_pkg_t *apkg = depend->pkg;
9889 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9890 + int n_providers = provider_apkgs->len;
9891 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9896 + for (i = 0; i < n_providers; i++) {
9897 + abstract_pkg_t *papkg = apkgs[i];
9898 + pkg_vec_t *pkg_vec = papkg->pkgs;
9900 + n_pkgs = pkg_vec->len;
9901 + for (j = 0; j < n_pkgs; j++) {
9902 + pkg_t *pkg = pkg_vec->pkgs[j];
9903 + if (version_constraints_satisfied(depend, pkg)) {
9904 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9913 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9916 + pkg_t ** pkgs = vec->pkgs;
9918 + for(i = 0; i < vec->len; i++)
9919 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9920 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9921 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9929 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9930 + * the same abstract package and 0 otherwise.
9932 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9934 + abstract_pkg_t **provides = pkg->provides;
9935 + int provides_count = pkg->provides_count;
9936 + abstract_pkg_t **replacee_provides = replacee->provides;
9937 + int replacee_provides_count = replacee->provides_count;
9939 + for (i = 0; i < provides_count; i++) {
9940 + abstract_pkg_t *apkg = provides[i];
9941 + for (j = 0; j < replacee_provides_count; j++) {
9942 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9943 + if (apkg == replacee_apkg)
9952 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9953 + * and 0 otherwise.
9955 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9957 + abstract_pkg_t **provides = pkg->provides;
9958 + int provides_count = pkg->provides_count;
9960 + for (i = 0; i < provides_count; i++) {
9961 + if (provides[i] == providee)
9968 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9971 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9973 + abstract_pkg_t **replaces = pkg->replaces;
9974 + int replaces_count = pkg->replaces_count;
9975 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9976 + int replacee_provides_count = pkg->provides_count; */
9978 + for (i = 0; i < replaces_count; i++) {
9979 + abstract_pkg_t *abstract_replacee = replaces[i];
9980 + for (j = 0; j < replaces_count; j++) {
9981 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9982 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9983 + if (replacee->provides[j] == abstract_replacee)
9992 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9995 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9997 + compound_depend_t *conflicts = pkg->conflicts;
9998 + int conflicts_count = pkg->conflicts_count;
10000 + for (i = 0; i < conflicts_count; i++) {
10001 + int possibility_count = conflicts[i].possibility_count;
10002 + struct depend **possibilities = conflicts[i].possibilities;
10003 + for (j = 0; j < possibility_count; j++) {
10004 + if (possibilities[j]->pkg == conflictee) {
10013 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10014 + * conflictee's provides and 0 otherwise.
10016 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10018 + compound_depend_t *conflicts = pkg->conflicts;
10019 + int conflicts_count = pkg->conflicts_count;
10020 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10021 + int conflictee_provides_count = conflictee->provides_count;
10023 + int possibility_count;
10024 + struct depend **possibilities;
10025 + abstract_pkg_t *possibility ;
10027 + for (i = 0; i < conflicts_count; i++) {
10028 + possibility_count = conflicts[i].possibility_count;
10029 + possibilities = conflicts[i].possibilities;
10030 + for (j = 0; j < possibility_count; j++) {
10031 + possibility = possibilities[j]->pkg;
10032 + for (k = 0; k < conflictee_provides_count; k++) {
10033 + if (possibility == conflictee_provides[k]) {
10042 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10044 + int oldlen = 0, newlen = 0;
10046 + register int i, j;
10051 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10052 + while(newstuff && newstuff[newlen]) newlen++;
10054 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10055 + if (result == NULL) {
10056 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10060 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10061 + *(result + i) = *(newstuff + j);
10063 + *(result + i) = NULL;
10069 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10070 + * this is null terminated, no count is carried around
10072 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10076 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10079 + while(the_lost && the_lost[count]) count++;
10081 + count++; /* need one to hold the null */
10082 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10083 + if (resized == NULL) {
10084 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10087 + resized[count - 1] = strdup(depend_str);
10088 + resized[count] = NULL;
10093 +void printDepends(pkg_t * pkg)
10095 + register int i, j;
10096 + compound_depend_t * depend;
10099 + count = pkg->pre_depends_count + pkg->depends_count;
10101 + depend = pkg->depends;
10103 + fprintf(stderr, "Depends pointer is NULL\n");
10106 + for(i = 0; i < count; i++){
10107 + fprintf(stderr, "%s has %d possibilities:\n",
10108 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10109 + depend->possibility_count);
10110 + for(j = 0; j < depend->possibility_count; j++)
10111 + fprintf(stderr, "\t%s version %s (%d)\n",
10112 + depend->possibilities[j]->pkg->name,
10113 + depend->possibilities[j]->version,
10114 + depend->possibilities[j]->constraint);
10119 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10121 + register int i, j;
10123 + /* every pkg provides itself */
10124 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10126 + if (!pkg->provides_count)
10129 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10130 + if (pkg->provides == NULL) {
10131 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10134 + pkg->provides[0] = ab_pkg;
10136 + // if (strcmp(ab_pkg->name, pkg->name))
10137 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10139 + for(i = 0; i < pkg->provides_count; i++){
10140 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10142 + pkg->provides[i+1] = provided_abpkg;
10145 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10150 +/* Abhaya: added conflicts support */
10151 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10154 + compound_depend_t * conflicts;
10156 + if (!pkg->conflicts_count)
10159 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10160 + pkg->conflicts_count);
10161 + if (conflicts == NULL) {
10162 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10165 + for (i = 0; i < pkg->conflicts_count; i++) {
10166 + conflicts->type = CONFLICTS;
10167 + parseDepends(conflicts, hash,
10168 + pkg->conflicts_str[i]);
10170 + for (j = 0; j < conflicts->possibility_count; j++) {
10171 + depend_t *possibility = conflicts->possibilities[j];
10172 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10173 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10181 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10183 + register int i, j;
10185 + if (!pkg->replaces_count)
10188 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10189 + if (pkg->replaces == NULL) {
10190 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10194 + // if (strcmp(ab_pkg->name, pkg->name))
10195 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10197 + for(i = 0; i < pkg->replaces_count; i++){
10198 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10200 + pkg->replaces[i] = old_abpkg;
10203 + if (!old_abpkg->replaced_by)
10204 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10205 + if ( old_abpkg->replaced_by == NULL ){
10208 + /* if a package pkg both replaces and conflicts old_abpkg,
10209 + * then add it to the replaced_by vector so that old_abpkg
10210 + * will be upgraded to ab_pkg automatically */
10211 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10212 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10217 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10221 + compound_depend_t * depends;
10223 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10226 + if (0 && pkg->pre_depends_count)
10227 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10228 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10229 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10230 + if (depends == NULL) {
10231 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10236 + for(i = 0; i < pkg->pre_depends_count; i++){
10237 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10238 + if (0 && pkg->pre_depends_count)
10239 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10240 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10241 + depends->type = PREDEPEND;
10245 + for(i = 0; i < pkg->recommends_count; i++){
10246 + parseDepends(depends, hash, pkg->recommends_str[i]);
10247 + if (0 && pkg->recommends_count)
10248 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10249 + pkg->recommends_str[i], depends, depends->possibility_count);
10250 + depends->type = RECOMMEND;
10254 + for(i = 0; i < pkg->suggests_count; i++){
10255 + parseDepends(depends, hash, pkg->suggests_str[i]);
10256 + if (0 && pkg->suggests_count)
10257 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10258 + pkg->suggests_str[i], depends, depends->possibility_count);
10259 + depends->type = SUGGEST;
10263 + for(i = 0; i < pkg->depends_count; i++){
10264 + parseDepends(depends, hash, pkg->depends_str[i]);
10265 + if (0 && pkg->depends_count)
10266 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10267 + pkg->depends_str[i], depends, depends->possibility_count);
10274 + * pkg_depend_string: returns the depends string specified by index.
10275 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10276 + * [0,npredepends) -> returns pre_depends_str[index]
10277 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10278 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10279 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10281 +char *pkg_depend_str(pkg_t *pkg, int index)
10283 + if (index < pkg->pre_depends_count) {
10284 + return pkg->pre_depends_str[index];
10286 + index -= pkg->pre_depends_count;
10288 + if (index < pkg->recommends_count) {
10289 + return pkg->recommends_str[index];
10291 + index -= pkg->recommends_count;
10293 + if (index < pkg->suggests_count) {
10294 + return pkg->suggests_str[index];
10296 + index -= pkg->suggests_count;
10298 + if (index < pkg->depends_count) {
10299 + return pkg->depends_str[index];
10301 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10305 +void freeDepends(pkg_t *pkg)
10309 + if (pkg == NULL || pkg->depends == NULL) {
10313 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10314 + for (i=0; i < pkg->depends->possibility_count; i++) {
10315 + depend_deinit(pkg->depends->possibilities[i]);
10317 + free(pkg->depends->possibilities);
10318 + free(pkg->depends);
10319 + pkg->depends = NULL;
10322 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10324 + compound_depend_t * depends;
10325 + int count, othercount;
10326 + register int i, j;
10327 + abstract_pkg_t * ab_depend;
10328 + abstract_pkg_t ** temp;
10330 + count = pkg->pre_depends_count + pkg->depends_count;
10331 + depends = pkg->depends;
10333 + if (0 && pkg->pre_depends_count)
10334 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10335 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10336 + for (i = 0; i < count; i++) {
10337 + if (0 && pkg->pre_depends_count)
10338 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10339 + for (j = 0; j < depends->possibility_count; j++){
10340 + ab_depend = depends->possibilities[j]->pkg;
10341 + if(!ab_depend->depended_upon_by)
10342 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10344 + temp = ab_depend->depended_upon_by;
10352 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10353 + (othercount + 1) * sizeof(abstract_pkg_t *));
10354 + /* the array may have moved */
10355 + temp = ab_depend->depended_upon_by + othercount;
10362 +static depend_t * depend_init(void)
10364 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10366 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10369 + d->constraint = NONE;
10370 + d->version = NULL;
10376 +static void depend_deinit(depend_t *d)
10381 +static int parseDepends(compound_depend_t *compound_depend,
10382 + hash_table_t * hash, char * depend_str)
10384 + char * pkg_name, buffer[2048];
10385 + int num_of_ors = 0;
10387 + register char * src, * dest;
10388 + depend_t ** possibilities;
10390 + /* first count the number of ored possibilities for satisfying dependency */
10391 + src = depend_str;
10393 + if(*src++ == '|')
10396 + compound_depend->type = DEPEND;
10398 + compound_depend->possibility_count = num_of_ors + 1;
10399 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10400 + if (!possibilities)
10402 + compound_depend->possibilities = possibilities;
10404 + src = depend_str;
10405 + for(i = 0; i < num_of_ors + 1; i++){
10406 + possibilities[i] = depend_init();
10407 + if (!possibilities[i])
10409 + /* gobble up just the name first */
10412 + !isspace(*src) &&
10416 + *dest++ = *src++;
10418 + pkg_name = trim_alloc(buffer);
10419 + if (pkg_name == NULL )
10422 + /* now look at possible version info */
10424 + /* skip to next chars */
10425 + if(isspace(*src))
10426 + while(*src && isspace(*src)) src++;
10428 + /* extract constraint and version */
10431 + if(!strncmp(src, "<<", 2)){
10432 + possibilities[i]->constraint = EARLIER;
10435 + else if(!strncmp(src, "<=", 2)){
10436 + possibilities[i]->constraint = EARLIER_EQUAL;
10439 + else if(!strncmp(src, ">=", 2)){
10440 + possibilities[i]->constraint = LATER_EQUAL;
10443 + else if(!strncmp(src, ">>", 2)){
10444 + possibilities[i]->constraint = LATER;
10447 + else if(!strncmp(src, "=", 1)){
10448 + possibilities[i]->constraint = EQUAL;
10451 + /* should these be here to support deprecated designations; dpkg does */
10452 + else if(!strncmp(src, "<", 1)){
10453 + possibilities[i]->constraint = EARLIER_EQUAL;
10456 + else if(!strncmp(src, ">", 1)){
10457 + possibilities[i]->constraint = LATER_EQUAL;
10461 + /* now we have any constraint, pass space to version string */
10462 + while(isspace(*src)) src++;
10464 + /* this would be the version string */
10466 + while(*src && *src != ')')
10467 + *dest++ = *src++;
10470 + possibilities[i]->version = trim_alloc(buffer);
10471 + /* fprintf(stderr, "let's print the depends version string:");
10472 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10473 + if (possibilities[i]->version == NULL )
10478 + /* hook up the dependency to its abstract pkg */
10479 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10483 + /* now get past the ) and any possible | chars */
10485 + (isspace(*src) ||
10491 + compound_depend->type = GREEDY_DEPEND;
10498 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
10499 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10500 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-07-22 16:31:25.000000000 +0200
10502 +/* pkg_depends.h - the itsy package management system
10506 + Copyright (C) 2002 Compaq Computer Corporation
10508 + This program is free software; you can redistribute it and/or
10509 + modify it under the terms of the GNU General Public License as
10510 + published by the Free Software Foundation; either version 2, or (at
10511 + your option) any later version.
10513 + This program is distributed in the hope that it will be useful, but
10514 + WITHOUT ANY WARRANTY; without even the implied warranty of
10515 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10516 + General Public License for more details.
10519 +#ifndef PKG_DEPENDS_H
10520 +#define PKG_DEPENDS_H
10523 +#include "pkg_hash.h"
10525 +enum depend_type {
10533 +typedef enum depend_type depend_type_t;
10535 +enum version_constraint {
10543 +typedef enum version_constraint version_constraint_t;
10546 + version_constraint_t constraint;
10548 + abstract_pkg_t * pkg;
10550 +typedef struct depend depend_t;
10552 +struct compound_depend{
10553 + depend_type_t type;
10554 + int possibility_count;
10555 + struct depend ** possibilities;
10557 +typedef struct compound_depend compound_depend_t;
10559 +#include "hash_table.h"
10561 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10562 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10563 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10564 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10567 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10568 + * the same abstract package and 0 otherwise.
10570 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10573 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10576 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10579 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10582 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10585 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10588 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10591 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10594 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10596 +char *pkg_depend_str(pkg_t *pkg, int index);
10597 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10598 +void freeDepends(pkg_t *pkg);
10599 +void printDepends(pkg_t * pkg);
10600 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10601 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10602 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10603 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10604 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10607 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
10608 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10609 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-07-22 16:31:25.000000000 +0200
10611 +/* pkg_dest.c - the itsy package management system
10615 + Copyright (C) 2001 University of Southern California
10617 + This program is free software; you can redistribute it and/or
10618 + modify it under the terms of the GNU General Public License as
10619 + published by the Free Software Foundation; either version 2, or (at
10620 + your option) any later version.
10622 + This program is distributed in the hope that it will be useful, but
10623 + WITHOUT ANY WARRANTY; without even the implied warranty of
10624 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10625 + General Public License for more details.
10630 +#include "pkg_dest.h"
10631 +#include "file_util.h"
10632 +#include "str_util.h"
10633 +#include "sprintf_alloc.h"
10635 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10637 + dest->name = strdup(name);
10639 + /* Guarantee that dest->root_dir ends with a '/' */
10640 + if (str_ends_with(root_dir, "/")) {
10641 + dest->root_dir = strdup(root_dir);
10643 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10645 + file_mkdir_hier(dest->root_dir, 0755);
10647 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10648 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10649 + file_mkdir_hier(dest->ipkg_dir, 0755);
10651 + if (str_starts_with (lists_dir, "/"))
10652 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10654 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10656 + file_mkdir_hier(dest->lists_dir, 0755);
10658 + sprintf_alloc(&dest->info_dir, "%s/%s",
10659 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10660 + file_mkdir_hier(dest->info_dir, 0755);
10662 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10663 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10665 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10666 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10668 + dest->status_file = NULL;
10673 +void pkg_dest_deinit(pkg_dest_t *dest)
10675 + free(dest->name);
10676 + dest->name = NULL;
10678 + free(dest->root_dir);
10679 + dest->root_dir = NULL;
10681 + free(dest->ipkg_dir);
10682 + dest->ipkg_dir = NULL;
10684 + free(dest->lists_dir);
10685 + dest->lists_dir = NULL;
10687 + free(dest->info_dir);
10688 + dest->info_dir = NULL;
10690 + free(dest->status_file_name);
10691 + dest->status_file_name = NULL;
10693 + free(dest->status_file_tmp_name);
10694 + dest->status_file_tmp_name = NULL;
10696 + if (dest->status_file) {
10697 + fclose(dest->status_file);
10699 + dest->status_file = NULL;
10701 + dest->root_dir = NULL;
10703 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
10704 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10705 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-07-22 16:31:25.000000000 +0200
10707 +/* pkg_dest.h - the itsy package management system
10711 + Copyright (C) 2001 University of Southern California
10713 + This program is free software; you can redistribute it and/or
10714 + modify it under the terms of the GNU General Public License as
10715 + published by the Free Software Foundation; either version 2, or (at
10716 + your option) any later version.
10718 + This program is distributed in the hope that it will be useful, but
10719 + WITHOUT ANY WARRANTY; without even the implied warranty of
10720 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10721 + General Public License for more details.
10724 +#ifndef PKG_DEST_H
10725 +#define PKG_DEST_H
10727 +typedef struct pkg_dest pkg_dest_t;
10735 + char *status_file_name;
10736 + char *status_file_tmp_name;
10737 + FILE *status_file;
10740 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10741 +void pkg_dest_deinit(pkg_dest_t *dest);
10745 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
10746 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10747 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-07-22 16:31:25.000000000 +0200
10749 +/* pkg_dest_list.c - the itsy package management system
10753 + Copyright (C) 2001 University of Southern California
10755 + This program is free software; you can redistribute it and/or
10756 + modify it under the terms of the GNU General Public License as
10757 + published by the Free Software Foundation; either version 2, or (at
10758 + your option) any later version.
10760 + This program is distributed in the hope that it will be useful, but
10761 + WITHOUT ANY WARRANTY; without even the implied warranty of
10762 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10763 + General Public License for more details.
10768 +#include "pkg_dest.h"
10769 +#include "void_list.h"
10770 +#include "pkg_dest_list.h"
10772 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10774 + return void_list_elt_init((void_list_elt_t *) elt, data);
10777 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10779 + void_list_elt_deinit((void_list_elt_t *) elt);
10782 +int pkg_dest_list_init(pkg_dest_list_t *list)
10784 + return void_list_init((void_list_t *) list);
10787 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10789 + pkg_dest_list_elt_t *iter;
10790 + pkg_dest_t *pkg_dest;
10792 + for (iter = list->head; iter; iter = iter->next) {
10793 + pkg_dest = iter->data;
10794 + pkg_dest_deinit(pkg_dest);
10796 + /* malloced in pkg_dest_list_append */
10798 + iter->data = NULL;
10800 + void_list_deinit((void_list_t *) list);
10803 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10804 + const char *root_dir,const char *lists_dir)
10807 + pkg_dest_t *pkg_dest;
10809 + /* freed in plg_dest_list_deinit */
10810 + pkg_dest = malloc(sizeof(pkg_dest_t));
10811 + if (pkg_dest == NULL) {
10812 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10816 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10817 + err = void_list_append((void_list_t *) list, pkg_dest);
10825 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10827 + return void_list_push((void_list_t *) list, data);
10830 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10832 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10834 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
10835 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10836 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-07-22 16:31:25.000000000 +0200
10838 +/* pkg_dest_list.h - the itsy package management system
10842 + Copyright (C) 2001 University of Southern California
10844 + This program is free software; you can redistribute it and/or
10845 + modify it under the terms of the GNU General Public License as
10846 + published by the Free Software Foundation; either version 2, or (at
10847 + your option) any later version.
10849 + This program is distributed in the hope that it will be useful, but
10850 + WITHOUT ANY WARRANTY; without even the implied warranty of
10851 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10852 + General Public License for more details.
10855 +#ifndef PKG_DEST_LIST_H
10856 +#define PKG_DEST_LIST_H
10858 +#include "pkg_dest.h"
10860 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10861 +struct pkg_dest_list_elt
10863 + pkg_dest_list_elt_t *next;
10864 + pkg_dest_t *data;
10867 +typedef struct pkg_dest_list pkg_dest_list_t;
10868 +struct pkg_dest_list
10870 + pkg_dest_list_elt_t pre_head;
10871 + pkg_dest_list_elt_t *head;
10872 + pkg_dest_list_elt_t *tail;
10875 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10876 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10878 +int pkg_dest_list_init(pkg_dest_list_t *list);
10879 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10881 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10882 + const char *root_dir,const char* lists_dir);
10883 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10884 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10888 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
10889 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10890 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-07-22 16:31:25.000000000 +0200
10892 +/* pkg_extract.c - the itsy package management system
10896 + Copyright (C) 2001 University of Southern California
10898 + This program is free software; you can redistribute it and/or
10899 + modify it under the terms of the GNU General Public License as
10900 + published by the Free Software Foundation; either version 2, or (at
10901 + your option) any later version.
10903 + This program is distributed in the hope that it will be useful, but
10904 + WITHOUT ANY WARRANTY; without even the implied warranty of
10905 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10906 + General Public License for more details.
10910 +#include <errno.h>
10911 +#include <fcntl.h>
10912 +#include <stdio.h>
10914 +#include "pkg_extract.h"
10916 +#include "libbb.h"
10917 +#include "file_util.h"
10918 +#include "sprintf_alloc.h"
10919 +#include "unarchive.h"
10921 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10922 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10923 +#define IPKG_CONTROL_FILE "control"
10925 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10927 + archive_handle_t *archive;
10930 + sprintf_alloc(&path, "%s/", dir);
10931 + archive = init_handle();
10932 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10933 + archive->filter = filter_accept_list;
10934 + llist_add_to(&(archive->accept), (char *)filename);
10935 + archive->buffer = path;
10936 + archive->action_data = data_extract_all_prefix;
10937 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10938 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10939 + close(archive->src_fd);
10940 + free(archive->accept);
10945 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10947 + unsigned int size = strlen(archive->file_header->name) + 2;
10949 + if (archive->buffer == NULL) {
10950 + archive->buffer = xmalloc(size);
10951 + strcpy(archive->buffer, archive->file_header->name);
10953 + size += strlen(archive->buffer);
10954 + archive->buffer = xrealloc(archive->buffer, size);
10955 + strcat(archive->buffer, archive->file_header->name);
10957 + strcat(archive->buffer, "\n");
10958 + data_skip(archive);
10961 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10963 + archive_handle_t *archive;
10966 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10967 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10968 + archive = init_handle();
10969 + archive->src_fd = bb_xopen(name, O_RDONLY);
10970 + archive->filter = filter_accept_list;
10971 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10972 + archive->action_data = data_extract_to_buffer;
10973 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10974 + close(archive->src_fd);
10975 + fputs(archive->buffer, stream);
10976 + free(archive->buffer);
10977 + free(archive->accept);
10984 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10986 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10989 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10991 + archive_handle_t *archive;
10995 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10996 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10997 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10998 + archive = init_handle();
10999 + archive->src_fd = bb_xopen(name, O_RDONLY);
11000 + archive->filter = filter_accept_all;
11001 + archive->buffer = path;
11002 + archive->action_data = data_extract_all_prefix;
11003 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11004 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11005 + close(archive->src_fd);
11013 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11015 + archive_handle_t *archive;
11019 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11020 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11021 + sprintf_alloc(&path, "%s/", dir);
11022 + archive = init_handle();
11023 + archive->src_fd = bb_xopen(name, O_RDONLY);
11024 + archive->filter = filter_accept_all;
11025 + archive->buffer = path;
11026 + archive->action_data = data_extract_all_prefix;
11027 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11028 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11029 + close(archive->src_fd);
11037 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11040 + char *line, *data_file;
11044 + file = fopen(file_name, "w");
11045 + if (file == NULL) {
11046 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11047 + __FUNCTION__, file_name);
11052 + if (pkg->installed_files) {
11053 + str_list_elt_t *elt;
11054 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11055 + fprintf(file, "%s\n", elt->data);
11058 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11065 + /* Fixup data file names by removing the initial '.' */
11068 + line = file_read_line_alloc(tmp);
11069 + if (line == NULL) {
11073 + data_file = line;
11074 + if (*data_file == '.') {
11078 + if (*data_file != '/') {
11079 + fputs("/", file);
11082 + /* I have no idea why, but this is what dpkg does */
11083 + if (strcmp(data_file, "/\n") == 0) {
11084 + fputs("/.\n", file);
11086 + fputs(data_file, file);
11096 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11098 + archive_handle_t *archive;
11101 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11102 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11103 + archive = init_handle();
11104 + archive->src_fd = bb_xopen(name, O_RDONLY);
11105 + archive->filter = filter_accept_all;
11106 + archive->action_data = data_extract_file_name_to_buffer;
11107 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11108 + close(archive->src_fd);
11109 + fputs(archive->buffer, file);
11110 + free(archive->buffer);
11116 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
11117 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11118 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-07-22 16:31:25.000000000 +0200
11120 +/* pkg_extract.c - the itsy package management system
11124 + Copyright (C) 2001 University of Southern California
11126 + This program is free software; you can redistribute it and/or
11127 + modify it under the terms of the GNU General Public License as
11128 + published by the Free Software Foundation; either version 2, or (at
11129 + your option) any later version.
11131 + This program is distributed in the hope that it will be useful, but
11132 + WITHOUT ANY WARRANTY; without even the implied warranty of
11133 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11134 + General Public License for more details.
11137 +#ifndef PKG_EXTRACT_H
11138 +#define PKG_EXTRACT_H
11142 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11143 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11144 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11146 + const char *prefix);
11147 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11148 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11149 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11152 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h
11153 --- busybox-1.2.0-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
11154 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h 2006-07-22 16:31:25.000000000 +0200
11156 +/* pkg.h - the itsy package management system
11160 + Copyright (C) 2001 University of Southern California
11162 + This program is free software; you can redistribute it and/or
11163 + modify it under the terms of the GNU General Public License as
11164 + published by the Free Software Foundation; either version 2, or (at
11165 + your option) any later version.
11167 + This program is distributed in the hope that it will be useful, but
11168 + WITHOUT ANY WARRANTY; without even the implied warranty of
11169 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11170 + General Public License for more details.
11176 +#include <sys/types.h>
11177 +#include <sys/stat.h>
11178 +#include <unistd.h>
11180 +#include "pkg_vec.h"
11181 +#include "str_list.h"
11182 +#include "pkg_src.h"
11183 +#include "pkg_dest.h"
11184 +#include "ipkg_conf.h"
11185 +#include "conffile_list.h"
11190 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11192 +/* I think "Size" is currently the shortest field name */
11193 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11195 +enum pkg_state_want
11201 + SW_LAST_STATE_WANT
11203 +typedef enum pkg_state_want pkg_state_want_t;
11205 +enum pkg_state_flag
11208 + SF_REINSTREQ = 1,
11209 + SF_HOLD = 2, /* do not upgrade version */
11210 + SF_REPLACE = 4, /* replace this package */
11211 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11212 + SF_PREFER = 16, /* prefer this version */
11213 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11214 + SF_MARKED = 64, /* temporary mark */
11215 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11217 + SF_LAST_STATE_FLAG
11219 +typedef enum pkg_state_flag pkg_state_flag_t;
11220 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11222 +enum pkg_state_status
11224 + SS_NOT_INSTALLED = 1,
11226 + SS_HALF_CONFIGURED,
11228 + SS_HALF_INSTALLED,
11230 + SS_POST_INST_FAILED,
11231 + SS_REMOVAL_FAILED,
11232 + SS_LAST_STATE_STATUS
11234 +typedef enum pkg_state_status pkg_state_status_t;
11236 +struct abstract_pkg{
11238 + int dependencies_checked;
11239 + pkg_vec_t * pkgs;
11240 + pkg_state_status_t state_status;
11241 + pkg_state_flag_t state_flag;
11242 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11243 + abstract_pkg_vec_t * provided_by;
11244 + abstract_pkg_vec_t * replaced_by;
11247 +#include "pkg_depends.h"
11249 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11251 + The 3 version fields should go into a single version struct. (This
11252 + is especially important since, currently, pkg->version can easily
11253 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11254 + distinct. This has been the source of multiple bugs.
11256 + The 3 state fields could possibly also go into their own struct.
11258 + All fields which deal with lists of packages, (Depends,
11259 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11260 + be handled by a single struct in pkg_t
11262 + All string fields for which there is a small set of possible
11263 + values, (section, maintainer, architecture, maybe version?), that
11264 + are reused among different packages -- for all such packages we
11265 + should move from "char *"s to some atom datatype to share data
11266 + storage and use less memory. We might even do reference counting,
11267 + but probably not since most often we only create new pkg_t structs,
11268 + we don't often free them. */
11272 + unsigned long epoch;
11275 + char *familiar_revision;
11277 + pkg_dest_t *dest;
11278 + char *architecture;
11280 + char *maintainer;
11281 + char *description;
11282 + pkg_state_want_t state_want;
11283 + pkg_state_flag_t state_flag;
11284 + pkg_state_status_t state_status;
11285 + char **depends_str;
11286 + int depends_count;
11287 + char **pre_depends_str;
11288 + int pre_depends_count;
11289 + char **recommends_str;
11290 + int recommends_count;
11291 + char **suggests_str;
11292 + int suggests_count;
11293 + compound_depend_t * depends;
11295 + /* Abhaya: new conflicts */
11296 + char **conflicts_str;
11297 + compound_depend_t * conflicts;
11298 + int conflicts_count;
11300 + char **replaces_str;
11301 + int replaces_count;
11302 + abstract_pkg_t ** replaces;
11304 + char **provides_str;
11305 + int provides_count;
11306 + abstract_pkg_t ** provides;
11308 + abstract_pkg_t *parent;
11310 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11313 + char *local_filename;
11315 + char *tmp_unpack_dir;
11318 + char *installed_size;
11321 + conffile_list_t conffiles;
11322 + time_t installed_time;
11323 + /* As pointer for lazy evaluation */
11324 + str_list_t *installed_files;
11325 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11326 + mechanism to avoid the problem here, (which is that the
11327 + installed_files list was being freed from an inner loop while
11328 + still being used within an outer loop. */
11329 + int installed_files_ref_cnt;
11331 + int arch_priority;
11332 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11333 + int provided_by_hand;
11336 +pkg_t *pkg_new(void);
11337 +int pkg_init(pkg_t *pkg);
11338 +void pkg_deinit(pkg_t *pkg);
11339 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11340 +abstract_pkg_t *abstract_pkg_new(void);
11341 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11344 + * merges fields from newpkg into oldpkg.
11345 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11347 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11349 +char *pkg_version_str_alloc(pkg_t *pkg);
11351 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11352 +int pkg_name_version_and_architecture_compare(void *a, void *b);
11353 +int abstract_pkg_name_compare(void *a, void *b);
11355 +char * pkg_formatted_info(pkg_t *pkg );
11356 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11358 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11360 +void pkg_print_info(pkg_t *pkg, FILE *file);
11361 +void pkg_print_status(pkg_t * pkg, FILE * file);
11362 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11363 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11364 +int pkg_free_installed_files(pkg_t *pkg);
11365 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11366 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11367 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11368 + const char *script, const char *args);
11370 +/* enum mappings */
11371 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11372 +pkg_state_want_t pkg_state_want_from_str(char *str);
11373 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11374 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11375 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11376 +pkg_state_status_t pkg_state_status_from_str(char *str);
11378 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11380 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11381 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11382 +int pkg_free_installed_files(pkg_t *pkg);
11384 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11385 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11388 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
11389 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11390 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-07-22 16:31:25.000000000 +0200
11392 +/* ipkg_hash.c - the itsy package management system
11396 + Copyright (C) 2002 Compaq Computer Corporation
11398 + This program is free software; you can redistribute it and/or
11399 + modify it under the terms of the GNU General Public License as
11400 + published by the Free Software Foundation; either version 2, or (at
11401 + your option) any later version.
11403 + This program is distributed in the hope that it will be useful, but
11404 + WITHOUT ANY WARRANTY; without even the implied warranty of
11405 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11406 + General Public License for more details.
11410 +#include <errno.h>
11411 +#include <ctype.h>
11412 +#include <stdlib.h>
11413 +#include <string.h>
11415 +#include "hash_table.h"
11417 +#include "ipkg_message.h"
11418 +#include "pkg_vec.h"
11419 +#include "pkg_hash.h"
11420 +#include "pkg_parse.h"
11421 +#include "ipkg_utils.h"
11423 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11426 + * this will talk to both feeds-lists files and installed status files
11429 + * hash_table_t hash;
11430 + * pkg_hash_init(name, &hash, 1000);
11431 + * pkg_hash_add_from_file(<feed filename>);
11433 + * the query function is just there as a shell to prove to me that this
11434 + * sort of works, but isn't far from doing something useful
11437 + * modified: CDW 3 Jan. 2002
11442 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11444 + return hash_table_init(name, hash, len);
11447 +void pkg_hash_deinit(hash_table_t *hash)
11449 + hash_table_deinit(hash);
11453 +/* Find the default arch for a given package status file if none is given. */
11454 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11456 + nv_pair_list_elt_t *l;
11457 + char *def_arch = HOST_CPU_STR; /* Default arch */
11458 + int def_prio = 0; /* Other archs override this */
11460 + l = conf->arch_list.head;
11463 + nv_pair_t *nv = l->data;
11464 + int priority = strtol(nv->value, NULL, 0);
11466 + /* Check if this arch has higher priority, and is valid */
11467 + if ((priority > def_prio) &&
11468 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11469 + /* Our new default */
11470 + def_prio = priority;
11471 + def_arch = nv->name;
11476 + return strdup(def_arch);
11479 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11480 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11482 + hash_table_t *hash = &conf->pkg_hash;
11484 + char **raw_start;
11487 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11491 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11496 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11497 + if (!pkg->architecture) {
11498 + char *version_str = pkg_version_str_alloc(pkg);
11499 + pkg->architecture = pkg_get_default_arch(conf);
11500 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11501 + pkg->name, version_str, pkg->architecture);
11502 + free(version_str);
11504 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11510 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11511 + memory after read_raw_pkgs_from_file */
11520 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11522 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11525 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11527 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11530 + return apkg->provided_by;
11534 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11535 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11538 + int nprovides = 0;
11539 + int nmatching = 0;
11540 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11541 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11542 + abstract_pkg_vec_t *provided_apkg_vec;
11543 + abstract_pkg_t **provided_apkgs;
11544 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11545 + pkg_t *latest_installed_parent = NULL;
11546 + pkg_t *latest_matching = NULL;
11547 + pkg_t *held_pkg = NULL;
11548 + pkg_t *good_pkg_by_name = NULL;
11550 + if (matching_apkgs == NULL || providers == NULL ||
11551 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11554 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11556 + provided_apkg_vec = apkg->provided_by;
11557 + nprovides = provided_apkg_vec->len;
11558 + provided_apkgs = provided_apkg_vec->pkgs;
11559 + if (nprovides > 1)
11560 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11562 + /* accumulate all the providers */
11563 + for (i = 0; i < nprovides; i++) {
11564 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11565 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11566 + abstract_pkg_vec_insert(providers, provider_apkg);
11568 + nprovides = providers->len;
11570 + for (i = 0; i < nprovides; i++) {
11571 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11572 + abstract_pkg_t *replacement_apkg = NULL;
11575 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11576 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11577 + if (provider_apkg->replaced_by->len > 1) {
11578 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11579 + provider_apkg->name, replacement_apkg->name);
11583 + if (replacement_apkg)
11584 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11585 + replacement_apkg->name, provider_apkg->name);
11587 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11588 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11591 + provider_apkg = replacement_apkg;
11594 + if (!(vec = provider_apkg->pkgs)) {
11595 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11600 + /* now check for supported architecture */
11602 + int max_count = 0;
11605 + /* count packages matching max arch priority and keep track of last one */
11606 + for (i = 0; i < vec->len; i++) {
11607 + pkg_t *maybe = vec->pkgs[i];
11608 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11609 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11610 + if (maybe->arch_priority > 0) {
11612 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11613 + pkg_vec_insert(matching_pkgs, maybe);
11619 + if (matching_pkgs->len > 1)
11620 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11621 + if (matching_apkgs->len > 1)
11622 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11624 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11625 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11626 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11627 + Until now I always got the latest, but that breaks the downgrade option.
11628 + If I stop at the first one, I would probably miss the new ones
11629 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11630 + or from a Packages feed.
11631 + 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*/
11634 + for (i = 0; i < matching_pkgs->len; i++) {
11635 + pkg_t *matching = matching_pkgs->pkgs[i];
11636 + if (constraint_fcn(matching, cdata)) { /* We found it */
11637 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11638 + good_pkg_by_name = matching;
11639 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11645 + for (i = 0; i < matching_pkgs->len; i++) {
11646 + pkg_t *matching = matching_pkgs->pkgs[i];
11647 + latest_matching = matching;
11648 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11649 + latest_installed_parent = matching;
11650 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11652 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11653 + held_pkg->name, matching->name);
11654 + held_pkg = matching;
11658 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11659 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11660 + apkg->name, matching_apkgs->len);
11661 + for (i = 0; i < matching_apkgs->len; i++) {
11662 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11663 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11665 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11668 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11669 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11670 + __FUNCTION__, apkg->name, matching_pkgs->len);
11671 + for (i = 0; i < matching_pkgs->len; i++) {
11672 + pkg_t *matching = matching_pkgs->pkgs[i];
11673 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11674 + matching->name, matching->version, matching->architecture);
11678 + nmatching = matching_apkgs->len;
11680 + pkg_vec_free(matching_pkgs);
11681 + abstract_pkg_vec_free(matching_apkgs);
11682 + abstract_pkg_vec_free(providers);
11684 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11685 + return good_pkg_by_name;
11688 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11691 + if (latest_installed_parent) {
11692 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11693 + return latest_installed_parent;
11695 + if (nmatching > 1) {
11696 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11699 + if (latest_matching) {
11700 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11701 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11702 + return latest_matching;
11707 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11709 + const char *name = (const char *)cdata;
11710 + if (strcmp(pkg->name, name) == 0)
11716 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11718 + hash_table_t *hash = &conf->pkg_hash;
11719 + abstract_pkg_t *apkg = NULL;
11721 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11724 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11728 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11729 + const char *pkg_name,
11730 + const char * version)
11734 + char *version_str = NULL;
11736 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11739 + for(i = 0; i < vec->len; i++) {
11740 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11741 + if(!strcmp(version_str, version)) {
11742 + free(version_str);
11745 + free(version_str);
11748 + if(i == vec->len)
11751 + return vec->pkgs[i];
11754 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11755 + const char *pkg_name,
11756 + pkg_dest_t *dest)
11761 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11765 + for(i = 0; i < vec->len; i++)
11766 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11767 + return vec->pkgs[i];
11772 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11773 + const char *pkg_name)
11778 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11782 + for(i = 0; i < vec->len; i++)
11783 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11784 + return vec->pkgs[i];
11790 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11792 + abstract_pkg_t * ab_pkg;
11794 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11798 + if (ab_pkg->pkgs) {
11799 + return ab_pkg->pkgs;
11800 + } else if (ab_pkg->provided_by) {
11801 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11802 + if (abpkg != NULL){
11803 + return abpkg->pkgs;
11805 + return ab_pkg->pkgs;
11812 +static int pkg_compare_names(const void *p1, const void *p2)
11814 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11815 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11816 + if (pkg1->name == NULL)
11818 + if (pkg2->name == NULL)
11820 + return(strcmp(pkg1->name, pkg2->name));
11824 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11827 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11828 + pkg_vec_t *all = (pkg_vec_t *)data;
11829 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11831 + for (j = 0; j < pkg_vec->len; j++) {
11832 + pkg_t *pkg = pkg_vec->pkgs[j];
11833 + pkg_vec_insert(all, pkg);
11838 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11840 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11841 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11844 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11846 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11847 + pkg_vec_t *all = (pkg_vec_t *)data;
11848 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11851 + for (j = 0; j < pkg_vec->len; j++) {
11852 + pkg_t *pkg = pkg_vec->pkgs[j];
11853 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11854 + pkg_vec_insert(all, pkg);
11859 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11861 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11862 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11865 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11869 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11870 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11871 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11872 + fprintf(stdout, "%s\n", ab_pkg->name);
11874 + if (dependents != NULL)
11875 + while (dependents [i] != NULL)
11876 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11877 + dependents = ab_pkg->provided_by->pkgs;
11879 + if (dependents != NULL)
11880 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11881 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11882 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11885 + while (i < pkg->depends_count)
11886 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11889 +void pkg_hash_dump(hash_table_t *hash, void *data)
11892 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11893 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11894 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11897 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11899 + abstract_pkg_t * ab_pkg;
11901 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11902 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11907 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11909 + abstract_pkg_t * ab_pkg;
11910 + int arch_priority;
11915 + arch_priority = pkg->arch_priority;
11917 + if (buildDepends(hash, pkg)<0){
11918 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11921 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11923 + if (set_status) {
11924 + if (pkg->state_status == SS_INSTALLED) {
11925 + ab_pkg->state_status = SS_INSTALLED;
11926 + } else if (pkg->state_status == SS_UNPACKED) {
11927 + ab_pkg->state_status = SS_UNPACKED;
11931 + if(!ab_pkg->pkgs)
11932 + ab_pkg->pkgs = pkg_vec_alloc();
11934 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11935 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11936 + pkg->parent = ab_pkg;
11938 + if (buildProvides(hash, ab_pkg, pkg)<0){
11939 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11942 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11943 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11944 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11947 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11948 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11952 + buildDependedUponBy(pkg, ab_pkg);
11957 + * this will assume that we've already determined that
11958 + * the abstract pkg doesn't exist, 'cause we should know these things...
11960 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11962 + abstract_pkg_t * ab_pkg;
11964 + ab_pkg = abstract_pkg_new();
11965 + if (ab_pkg == NULL) { return NULL; }
11967 + ab_pkg->name = strdup(pkg_name);
11968 + hash_table_insert(hash, pkg_name, ab_pkg);
11974 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11976 + hash_table_t *file_hash = &conf->file_hash;
11978 + return hash_table_get(file_hash, file_name);
11981 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11983 + hash_table_t *file_hash = &conf->file_hash;
11984 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11985 + int file_name_len = strlen(file_name);
11987 + if (file_name[file_name_len -1] == '/')
11990 + if (conf->offline_root) {
11991 + int len = strlen(conf->offline_root);
11992 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11993 + file_name += len;
11997 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11998 + hash_table_insert(file_hash, file_name, owning_pkg);
11999 + if (old_owning_pkg) {
12000 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12001 + /* mark this package to have its filelist written */
12002 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12003 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12009 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
12010 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12011 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-07-22 16:31:25.000000000 +0200
12013 +/* pkg_hash.h - the itsy package management system
12017 + Copyright (C) 2002 Compaq Computer Corporation
12019 + This program is free software; you can redistribute it and/or
12020 + modify it under the terms of the GNU General Public License as
12021 + published by the Free Software Foundation; either version 2, or (at
12022 + your option) any later version.
12024 + This program is distributed in the hope that it will be useful, but
12025 + WITHOUT ANY WARRANTY; without even the implied warranty of
12026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12027 + General Public License for more details.
12030 +#ifndef PKG_HASH_H
12031 +#define PKG_HASH_H
12034 +#include "pkg_vec.h"
12035 +#include "hash_table.h"
12038 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12039 +void pkg_hash_deinit(hash_table_t *hash);
12040 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12042 +void pkg_hash_dump(hash_table_t *hash, void *data);
12043 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12045 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12046 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12047 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12049 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12050 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12051 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12052 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12053 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12054 + const char *pkg_name,
12055 + const char * version);
12056 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12057 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12058 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12059 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12060 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12061 + const char *pkg_name);
12062 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12063 + const char *pkg_name,
12064 + pkg_dest_t *dest);
12066 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12067 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12069 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12070 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12074 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
12075 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12076 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-07-22 16:31:25.000000000 +0200
12078 +/* pkg_parse.c - the itsy package management system
12082 + Copyright (C) 2002 Compaq Computer Corporation
12084 + This program is free software; you can redistribute it and/or
12085 + modify it under the terms of the GNU General Public License as
12086 + published by the Free Software Foundation; either version 2, or (at
12087 + your option) any later version.
12089 + This program is distributed in the hope that it will be useful, but
12090 + WITHOUT ANY WARRANTY; without even the implied warranty of
12091 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12092 + General Public License for more details.
12096 +#include <errno.h>
12097 +#include <ctype.h>
12100 +#include "ipkg_utils.h"
12101 +#include "pkg_parse.h"
12103 +int isGenericFieldType(char * type, char * line)
12105 + if(!strncmp(line, type, strlen(type)))
12110 +char * parseGenericFieldType(char * type, char * raw)
12112 + char * field_value = raw + (strlen(type) + 1);
12113 + return trim_alloc(field_value);
12116 +void parseStatus(pkg_t *pkg, char * raw)
12118 + char sw_str[64], sf_str[64], ss_str[64];
12120 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12121 + pkg->state_want = pkg_state_want_from_str(sw_str);
12122 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12123 + pkg->state_status = pkg_state_status_from_str(ss_str);
12126 +char ** parseDependsString(char * raw, int * depends_count)
12128 + char ** depends = NULL;
12129 + int line_count = 0;
12130 + char buff[2048], * dest;
12132 + while(raw && *raw && !isspace(*raw)) {
12136 + if(line_is_blank(raw)){
12137 + *depends_count = line_count;
12140 + while(raw && *raw){
12141 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12143 + while(isspace(*raw)) raw++;
12146 + while((*raw != ',') && *raw)
12147 + *dest++ = *raw++;
12150 + depends[line_count] = trim_alloc(buff);
12151 + if(depends[line_count] ==NULL)
12157 + *depends_count = line_count;
12161 +void parseConffiles(pkg_t * pkg, char * raw)
12163 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12165 + if(!strncmp(raw, "Conffiles:", 10))
12166 + raw += strlen("Conffiles:");
12168 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12169 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12170 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12171 + while (*raw && isspace(*raw)) {
12174 + raw += strlen(file_name);
12175 + while (*raw && isspace(*raw)) {
12178 + raw += strlen(md5sum);
12182 +int parseVersion(pkg_t *pkg, char *raw)
12184 + char *colon, *eepochcolon;
12185 +#ifdef USE_DEBVERSION
12188 + unsigned long epoch;
12191 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12195 + if (strncmp(raw, "Version:", 8) == 0) {
12198 + while (*raw && isspace(*raw)) {
12202 + colon= strchr(raw,':');
12204 + epoch= strtoul(raw,&eepochcolon,10);
12205 + if (colon != eepochcolon) {
12206 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12210 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12214 + pkg->epoch= epoch;
12219 + pkg->revision = "";
12220 + pkg->familiar_revision = "";
12222 + pkg->version= malloc(strlen(raw)+1);
12223 + if ( pkg->version == NULL ) {
12224 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12227 + strcpy(pkg->version, raw);
12229 +#ifdef USE_DEBVERSION
12230 + hyphen= strrchr(pkg->version,'-');
12234 + if (strncmp("fam", hyphen, 3) == 0) {
12235 + pkg->familiar_revision=hyphen+3;
12236 + hyphen= strrchr(pkg->version,'-');
12239 + pkg->revision = hyphen;
12242 + pkg->revision = hyphen;
12248 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12252 + pkg->familiar_revision);
12259 +/* This code is needed to insert in first position the keyword for the aligning bug */
12261 +int alterProvidesLine(char *raw, char *temp)
12266 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12270 + if ( temp == NULL ) {
12271 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12275 + if (strncmp(raw, "Provides:", 9) == 0) {
12278 + while (*raw && isspace(*raw)) {
12282 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12284 + strncat( temp, raw++, 1);
12290 +/* Some random thoughts from Carl:
12292 + This function could be considerably simplified if we just kept
12293 + an array of all the generic string-valued field names, and looped
12294 + through those looking for a match. Also, these fields could perhaps
12295 + be stored in the package as an array as well, (or, probably better,
12296 + as an nv_pair_list_t).
12298 + Fields which require special parsing or storage, (such as Depends:
12299 + and Status:) could be handled as they are now.
12301 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12302 + to a dependency list. And, since we already have
12303 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12304 + Enhances, perhaps we could generalize all of these and save some
12305 + code duplication.
12307 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12309 + int reading_conffiles, reading_description;
12310 + int pkg_false_provides=1;
12312 + char * provide=NULL;
12315 + pkg->dest = dest;
12317 + reading_conffiles = reading_description = 0;
12319 + for (lines = *raw; *lines; lines++) {
12320 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12321 + if(isGenericFieldType("Package:", *lines))
12322 + pkg->name = parseGenericFieldType("Package", *lines);
12323 + else if(isGenericFieldType("Architecture:", *lines))
12324 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12325 + else if(isGenericFieldType("Filename:", *lines))
12326 + pkg->filename = parseGenericFieldType("Filename", *lines);
12327 + else if(isGenericFieldType("Section:", *lines))
12328 + pkg->section = parseGenericFieldType("Section", *lines);
12329 + else if(isGenericFieldType("MD5sum:", *lines))
12330 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12331 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12332 + let's parse it either way */
12333 + else if(isGenericFieldType("MD5Sum:", *lines))
12334 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12335 + else if(isGenericFieldType("Size:", *lines))
12336 + pkg->size = parseGenericFieldType("Size", *lines);
12337 + else if(isGenericFieldType("Source:", *lines))
12338 + pkg->source = parseGenericFieldType("Source", *lines);
12339 + else if(isGenericFieldType("Installed-Size:", *lines))
12340 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12341 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12342 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12343 + pkg->installed_time = strtoul(time_str, NULL, 0);
12344 + } else if(isGenericFieldType("Priority:", *lines))
12345 + pkg->priority = parseGenericFieldType("Priority", *lines);
12346 + else if(isGenericFieldType("Essential:", *lines)) {
12347 + char *essential_value;
12348 + essential_value = parseGenericFieldType("Essential", *lines);
12349 + if (strcmp(essential_value, "yes") == 0) {
12350 + pkg->essential = 1;
12352 + free(essential_value);
12354 + else if(isGenericFieldType("Status", *lines))
12355 + parseStatus(pkg, *lines);
12356 + else if(isGenericFieldType("Version", *lines))
12357 + parseVersion(pkg, *lines);
12358 + else if(isGenericFieldType("Maintainer", *lines))
12359 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12360 + else if(isGenericFieldType("Conffiles", *lines)){
12361 + parseConffiles(pkg, *lines);
12362 + reading_conffiles = 1;
12364 + else if(isGenericFieldType("Description", *lines)) {
12365 + pkg->description = parseGenericFieldType("Description", *lines);
12366 + reading_conffiles = 0;
12367 + reading_description = 1;
12370 + else if(isGenericFieldType("Provides", *lines)){
12371 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12372 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12373 + if ( alterProvidesLine(*lines,provide) ){
12376 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12377 +/* Let's try to hack a bit here.
12378 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12379 + in alot of other places. We will remove it before writing down the status database */
12380 + pkg_false_provides=0;
12384 + else if(isGenericFieldType("Depends", *lines))
12385 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12386 + else if(isGenericFieldType("Pre-Depends", *lines))
12387 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12388 + else if(isGenericFieldType("Recommends", *lines))
12389 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12390 + else if(isGenericFieldType("Suggests", *lines))
12391 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12392 + /* Abhaya: support for conflicts */
12393 + else if(isGenericFieldType("Conflicts", *lines))
12394 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12395 + else if(isGenericFieldType("Replaces", *lines))
12396 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12397 + else if(line_is_blank(*lines)) {
12401 + else if(**lines == ' '){
12402 + if(reading_description) {
12403 + /* we already know it's not blank, so the rest of description */
12404 + pkg->description = realloc(pkg->description,
12405 + strlen(pkg->description)
12406 + + 1 + strlen(*lines) + 1);
12407 + strcat(pkg->description, "\n");
12408 + strcat(pkg->description, (*lines));
12410 + else if(reading_conffiles)
12411 + parseConffiles(pkg, *lines);
12415 +/* If the ipk has not a Provides line, we insert our false line */
12416 + if ( pkg_false_provides==1)
12417 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12426 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12430 + for (lines = *raw; *lines; lines++) {
12431 + if(isGenericFieldType("Essential:", *lines)) {
12432 + char *essential_value;
12433 + essential_value = parseGenericFieldType("Essential", *lines);
12434 + if (strcmp(essential_value, "yes") == 0) {
12435 + pkg->essential = 1;
12437 + free(essential_value);
12444 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
12445 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12446 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-07-22 16:31:25.000000000 +0200
12448 +/* pkg_parse.h - the itsy package management system
12452 + Copyright (C) 2002 Compaq Computer Corporation
12454 + This program is free software; you can redistribute it and/or
12455 + modify it under the terms of the GNU General Public License as
12456 + published by the Free Software Foundation; either version 2, or (at
12457 + your option) any later version.
12459 + This program is distributed in the hope that it will be useful, but
12460 + WITHOUT ANY WARRANTY; without even the implied warranty of
12461 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12462 + General Public License for more details.
12465 +#ifndef PKG_PARSE_H
12466 +#define PKG_PARSE_H
12468 +int isGenericFieldType(char * type, char * line);
12469 +char * parseGenericFieldType(char * type, char * raw);
12470 +void parseStatus(pkg_t *pkg, char * raw);
12471 +int parseVersion(pkg_t *pkg, char *raw);
12472 +char ** parseDependsString(char * raw, int * depends_count);
12473 +int parseVersion(pkg_t *pkg, char *raw);
12474 +void parseConffiles(pkg_t * pkg, char * raw);
12475 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12476 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12479 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
12480 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12481 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-07-22 16:31:25.000000000 +0200
12483 +/* pkg_src.c - the itsy package management system
12487 + Copyright (C) 2001 University of Southern California
12489 + This program is free software; you can redistribute it and/or
12490 + modify it under the terms of the GNU General Public License as
12491 + published by the Free Software Foundation; either version 2, or (at
12492 + your option) any later version.
12494 + This program is distributed in the hope that it will be useful, but
12495 + WITHOUT ANY WARRANTY; without even the implied warranty of
12496 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12497 + General Public License for more details.
12502 +#include "pkg_src.h"
12503 +#include "str_util.h"
12505 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12507 + src->gzip = gzip;
12508 + src->name = str_dup_safe (name);
12509 + src->value = str_dup_safe (base_url);
12511 + src->extra_data = str_dup_safe (extra_data);
12513 + src->extra_data = NULL;
12517 +void pkg_src_deinit(pkg_src_t *src)
12519 + free (src->name);
12520 + free (src->value);
12521 + if (src->extra_data)
12522 + free (src->extra_data);
12526 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
12527 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12528 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-07-22 16:31:25.000000000 +0200
12530 +/* pkg_src.h - the itsy package management system
12534 + Copyright (C) 2001 University of Southern California
12536 + This program is free software; you can redistribute it and/or
12537 + modify it under the terms of the GNU General Public License as
12538 + published by the Free Software Foundation; either version 2, or (at
12539 + your option) any later version.
12541 + This program is distributed in the hope that it will be useful, but
12542 + WITHOUT ANY WARRANTY; without even the implied warranty of
12543 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12544 + General Public License for more details.
12550 +#include "nv_pair.h"
12556 + char *extra_data;
12560 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12561 +void pkg_src_deinit(pkg_src_t *src);
12564 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
12565 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12566 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-07-22 16:31:25.000000000 +0200
12568 +/* pkg_src_list.c - the itsy package management system
12572 + Copyright (C) 2001 University of Southern California
12574 + This program is free software; you can redistribute it and/or
12575 + modify it under the terms of the GNU General Public License as
12576 + published by the Free Software Foundation; either version 2, or (at
12577 + your option) any later version.
12579 + This program is distributed in the hope that it will be useful, but
12580 + WITHOUT ANY WARRANTY; without even the implied warranty of
12581 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12582 + General Public License for more details.
12587 +#include "pkg_src_list.h"
12588 +#include "void_list.h"
12590 +int pkg_src_list_init(pkg_src_list_t *list)
12592 + return void_list_init((void_list_t *) list);
12595 +void pkg_src_list_deinit(pkg_src_list_t *list)
12597 + pkg_src_list_elt_t *iter;
12598 + pkg_src_t *pkg_src;
12600 + for (iter = list->head; iter; iter = iter->next) {
12601 + pkg_src = iter->data;
12602 + pkg_src_deinit(pkg_src);
12604 + /* malloced in pkg_src_list_append */
12606 + iter->data = NULL;
12608 + void_list_deinit((void_list_t *) list);
12611 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12612 + const char *name, const char *base_url, const char *extra_data,
12617 + /* freed in pkg_src_list_deinit */
12618 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12620 + if (pkg_src == NULL) {
12621 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12624 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12626 + err = void_list_append((void_list_t *) list, pkg_src);
12634 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12636 + return void_list_push((void_list_t *) list, data);
12639 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12641 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12643 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
12644 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12645 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-07-22 16:31:25.000000000 +0200
12647 +/* pkg_src_list.h - the itsy package management system
12651 + Copyright (C) 2001 University of Southern California
12653 + This program is free software; you can redistribute it and/or
12654 + modify it under the terms of the GNU General Public License as
12655 + published by the Free Software Foundation; either version 2, or (at
12656 + your option) any later version.
12658 + This program is distributed in the hope that it will be useful, but
12659 + WITHOUT ANY WARRANTY; without even the implied warranty of
12660 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12661 + General Public License for more details.
12664 +#ifndef PKG_SRC_LIST_H
12665 +#define PKG_SRC_LIST_H
12667 +#include "pkg_src.h"
12669 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12670 +struct pkg_src_list_elt
12672 + pkg_src_list_elt_t *next;
12676 +typedef struct pkg_src_list pkg_src_list_t;
12677 +struct pkg_src_list
12679 + pkg_src_list_elt_t pre_head;
12680 + pkg_src_list_elt_t *head;
12681 + pkg_src_list_elt_t *tail;
12684 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12686 + if (list->head == NULL)
12692 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12693 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12695 +int pkg_src_list_init(pkg_src_list_t *list);
12696 +void pkg_src_list_deinit(pkg_src_list_t *list);
12698 +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);
12699 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12700 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12704 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
12705 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12706 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-07-22 16:31:26.000000000 +0200
12708 +/* pkg_vec.c - the itsy package management system
12712 + Copyright (C) 2002 Compaq Computer Corporation
12714 + This program is free software; you can redistribute it and/or
12715 + modify it under the terms of the GNU General Public License as
12716 + published by the Free Software Foundation; either version 2, or (at
12717 + your option) any later version.
12719 + This program is distributed in the hope that it will be useful, but
12720 + WITHOUT ANY WARRANTY; without even the implied warranty of
12721 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12722 + General Public License for more details.
12725 +#include <stdlib.h>
12726 +#include <fnmatch.h>
12727 +#include "xregex.h"
12731 +pkg_vec_t * pkg_vec_alloc(void)
12733 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12735 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12738 + vec->pkgs = NULL;
12744 +void pkg_vec_free(pkg_vec_t *vec)
12751 + * assumption: all names in a vector are identical
12752 + * assumption: all version strings are trimmed,
12753 + * so identical versions have identical version strings,
12754 + * implying identical packages; let's marry these
12756 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12761 + /* look for a duplicate pkg by name, version, and architecture */
12762 + for (i = 0; i < vec->len; i++){
12763 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12764 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12765 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12766 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12767 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12768 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12770 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12771 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12776 + /* we didn't find one, add it */
12778 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12779 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12781 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12782 + vec->pkgs[vec->len] = pkg;
12786 + /* update the one that we have */
12788 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12789 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12790 + if (set_status) {
12791 + /* this is from the status file, so need to merge with existing database */
12792 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12793 + pkg_merge(vec->pkgs[i], pkg, set_status);
12794 + /* XXX: CLEANUP: It's not so polite to free something here
12795 + that was passed in from above. */
12799 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12800 + /* just overwrite the old one */
12801 + pkg_deinit(vec->pkgs[i]);
12802 + free(vec->pkgs[i]);
12803 + vec->pkgs[i] = pkg;
12805 + return vec->pkgs[i];
12809 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12814 + /* look for a duplicate pkg by name, version, and architecture */
12815 + for (i = 0; i < vec->len; i++)
12816 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12817 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12818 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12823 + /* we didn't find one, add it */
12825 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12826 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12831 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12834 + for (i = 0; i < vec->len; i++)
12835 + if (vec->pkgs[i] == apkg)
12840 +typedef int (*compare_fcn_t)(const void *, const void *);
12841 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12843 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12846 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12848 + int npkgs = vec->len;
12850 + for (i = 0; i < npkgs; i++) {
12851 + pkg_t *pkg = vec->pkgs[i];
12852 + pkg->state_flag &= ~SF_MARKED;
12857 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12859 + int matching_count = 0;
12860 + pkg_t **pkgs = vec->pkgs;
12861 + int npkgs = vec->len;
12863 + for (i = 0; i < npkgs; i++) {
12864 + pkg_t *pkg = pkgs[i];
12865 + if (fnmatch(pattern, pkg->name, 0)==0) {
12866 + pkg->state_flag |= SF_MARKED;
12867 + matching_count++;
12870 + return matching_count;
12874 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12876 + abstract_pkg_vec_t * vec ;
12877 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12879 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12882 + vec->pkgs = NULL;
12888 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12895 + * assumption: all names in a vector are unique
12897 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12901 + /* look for a duplicate pkg by name */
12902 + for(i = 0; i < vec->len; i++)
12903 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12906 + /* we didn't find one, add it */
12907 + if(i == vec->len){
12909 + (abstract_pkg_t **)
12910 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12911 + vec->pkgs[vec->len] = pkg;
12916 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12918 + if (vec->len > i)
12919 + return vec->pkgs[i];
12924 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12927 + for (i = 0; i < vec->len; i++)
12928 + if (vec->pkgs[i] == apkg)
12933 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12935 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12938 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
12939 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12940 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-07-22 16:31:26.000000000 +0200
12942 +/* pkg_vec.h - the itsy package management system
12946 + Copyright (C) 2002 Compaq Computer Corporation
12948 + This program is free software; you can redistribute it and/or
12949 + modify it under the terms of the GNU General Public License as
12950 + published by the Free Software Foundation; either version 2, or (at
12951 + your option) any later version.
12953 + This program is distributed in the hope that it will be useful, but
12954 + WITHOUT ANY WARRANTY; without even the implied warranty of
12955 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12956 + General Public License for more details.
12962 +typedef struct pkg pkg_t;
12963 +typedef struct abstract_pkg abstract_pkg_t;
12970 +typedef struct pkg_vec pkg_vec_t;
12972 +struct abstract_pkg_vec
12974 + abstract_pkg_t **pkgs;
12977 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12980 +pkg_vec_t * pkg_vec_alloc(void);
12981 +void pkg_vec_free(pkg_vec_t *vec);
12982 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12984 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12985 +/* pkg_vec_insert_merge: might munge pkg.
12986 +* returns the pkg that is in the pkg graph */
12987 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12988 +/* this one never munges pkg */
12989 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12990 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12991 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12993 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12994 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12996 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12997 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12998 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12999 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13000 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13001 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13004 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
13005 --- busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13006 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-07-22 16:31:26.000000000 +0200
13008 +/* sprintf_alloca.c -- like sprintf with memory allocation
13012 + Copyright (C) 2001 University of Southern California
13014 + This program is free software; you can redistribute it and/or modify
13015 + it under the terms of the GNU General Public License as published by
13016 + the Free Software Foundation; either version 2, or (at your option)
13017 + any later version.
13019 + This program is distributed in the hope that it will be useful,
13020 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13021 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13022 + GNU General Public License for more details.
13025 +#ifndef SPRINTF_ALLOC_H
13026 +#define SPRINTF_ALLOC_H
13028 +#include "libbb.h"
13030 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13033 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
13034 --- busybox-1.2.0-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13035 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c 2006-07-22 16:31:26.000000000 +0200
13037 +/* str_list.c - the itsy package management system
13041 + Copyright (C) 2001 University of Southern California
13043 + This program is free software; you can redistribute it and/or
13044 + modify it under the terms of the GNU General Public License as
13045 + published by the Free Software Foundation; either version 2, or (at
13046 + your option) any later version.
13048 + This program is distributed in the hope that it will be useful, but
13049 + WITHOUT ANY WARRANTY; without even the implied warranty of
13050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13051 + General Public License for more details.
13056 +#include "str_list.h"
13058 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13060 + return void_list_elt_init((void_list_elt_t *) elt, data);
13063 +void str_list_elt_deinit(str_list_elt_t *elt)
13065 + void_list_elt_deinit((void_list_elt_t *) elt);
13068 +str_list_t *str_list_alloc()
13070 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13072 + str_list_init(list);
13076 +int str_list_init(str_list_t *list)
13078 + return void_list_init((void_list_t *) list);
13081 +void str_list_deinit(str_list_t *list)
13083 + void_list_deinit((void_list_t *) list);
13086 +int str_list_append(str_list_t *list, char *data)
13088 + return void_list_append((void_list_t *) list, data);
13091 +int str_list_push(str_list_t *list, char *data)
13093 + return void_list_push((void_list_t *) list, data);
13096 +str_list_elt_t *str_list_pop(str_list_t *list)
13098 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13101 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13103 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13104 + (void_list_elt_t **) iter);
13107 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13109 + return (char *)void_list_remove_elt((void_list_t *) list,
13110 + (void *)target_str,
13111 + (void_list_cmp_t)strcmp);
13113 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
13114 --- busybox-1.2.0-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13115 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h 2006-07-22 16:31:26.000000000 +0200
13117 +/* str_list.h - the itsy package management system
13121 + Copyright (C) 2001 University of Southern California
13123 + This program is free software; you can redistribute it and/or
13124 + modify it under the terms of the GNU General Public License as
13125 + published by the Free Software Foundation; either version 2, or (at
13126 + your option) any later version.
13128 + This program is distributed in the hope that it will be useful, but
13129 + WITHOUT ANY WARRANTY; without even the implied warranty of
13130 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13131 + General Public License for more details.
13134 +#ifndef STR_LIST_H
13135 +#define STR_LIST_H
13137 +#include "void_list.h"
13139 +typedef struct str_list_elt str_list_elt_t;
13140 +struct str_list_elt
13142 + str_list_elt_t *next;
13146 +typedef struct xstr_list str_list_t;
13149 + str_list_elt_t pre_head;
13150 + str_list_elt_t *head;
13151 + str_list_elt_t *tail;
13154 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13155 +void str_list_elt_deinit(str_list_elt_t *elt);
13157 +str_list_t *str_list_alloc(void);
13158 +int str_list_init(str_list_t *list);
13159 +void str_list_deinit(str_list_t *list);
13161 +int str_list_append(str_list_t *list, char *data);
13162 +int str_list_push(str_list_t *list, char *data);
13163 +str_list_elt_t *str_list_pop(str_list_t *list);
13164 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13165 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13168 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
13169 --- busybox-1.2.0-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13170 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c 2006-07-22 16:31:26.000000000 +0200
13172 +/* str_utils.c - the itsy package management system
13176 + Copyright (C) 2001 University of Southern California
13178 + This program is free software; you can redistribute it and/or
13179 + modify it under the terms of the GNU General Public License as
13180 + published by the Free Software Foundation; either version 2, or (at
13181 + your option) any later version.
13183 + This program is distributed in the hope that it will be useful, but
13184 + WITHOUT ANY WARRANTY; without even the implied warranty of
13185 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13186 + General Public License for more details.
13191 +int str_starts_with(const char *str, const char *prefix)
13193 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13196 +int str_ends_with(const char *str, const char *suffix)
13201 + str_len = strlen(str);
13202 + suffix_len = strlen(suffix);
13204 + if (str_len < suffix_len) {
13208 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13211 +int str_chomp(char *str)
13213 + if (str[strlen(str) - 1] == '\n') {
13214 + str[strlen(str) - 1] = '\0';
13220 +int str_tolower(char *str)
13223 + *str = tolower(*str);
13230 +int str_toupper(char *str)
13233 + *str = toupper(*str);
13240 +char *str_dup_safe(const char *str)
13242 + return str ? strdup(str) : NULL;
13245 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
13246 --- busybox-1.2.0-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13247 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h 2006-07-22 16:31:26.000000000 +0200
13249 +/* str_utils.h - the itsy package management system
13253 + Copyright (C) 2001 University of Southern California
13255 + This program is free software; you can redistribute it and/or
13256 + modify it under the terms of the GNU General Public License as
13257 + published by the Free Software Foundation; either version 2, or (at
13258 + your option) any later version.
13260 + This program is distributed in the hope that it will be useful, but
13261 + WITHOUT ANY WARRANTY; without even the implied warranty of
13262 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13263 + General Public License for more details.
13266 +#ifndef STR_UTILS_H
13267 +#define STR_UTILS_H
13269 +int str_starts_with(const char *str, const char *prefix);
13270 +int str_ends_with(const char *str, const char *suffix);
13271 +int str_chomp(char *str);
13272 +int str_tolower(char *str);
13273 +int str_toupper(char *str);
13274 +char *str_dup_safe(const char *str);
13277 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c
13278 --- busybox-1.2.0-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13279 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c 2006-07-22 16:31:26.000000000 +0200
13281 +/* user.c - the itsy package management system
13285 + Copyright (C) 2002 Hewlett Packard Company
13286 + Copyright (C) 2001 University of Southern California
13288 + This program is free software; you can redistribute it and/or
13289 + modify it under the terms of the GNU General Public License as
13290 + published by the Free Software Foundation; either version 2, or (at
13291 + your option) any later version.
13293 + This program is distributed in the hope that it will be useful, but
13294 + WITHOUT ANY WARRANTY; without even the implied warranty of
13295 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13296 + General Public License for more details.
13299 +#include <stdio.h>
13300 +#include <stdarg.h>
13301 +#include "file_util.h"
13302 +#include "str_util.h"
13304 +#include "libipkg.h"
13309 +static char *question = NULL;
13310 +static int question_len = 255;
13312 +char *get_user_response(const char *format, ...)
13314 + int len = question_len;
13317 + va_start(ap, format);
13320 + vprintf(format, ap);
13322 + response = file_read_line_alloc(stdin);
13323 + } while (response == NULL);
13326 + if (question == NULL || len > question_len) {
13327 + question = realloc(question, len + 1);
13328 + question_len = len;
13330 + len = vsnprintf(question,question_len,format,ap);
13331 + } while (len > question_len);
13332 + response = strdup(ipkg_cb_response(question));
13334 + str_chomp(response);
13335 + str_tolower(response);
13339 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h
13340 --- busybox-1.2.0-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13341 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h 2006-07-22 16:31:26.000000000 +0200
13343 +/* user.c - the itsy package management system
13347 + Copyright (C) 2002 Hewlett Packard Company
13348 + Copyright (C) 2001 University of Southern California
13350 + This program is free software; you can redistribute it and/or
13351 + modify it under the terms of the GNU General Public License as
13352 + published by the Free Software Foundation; either version 2, or (at
13353 + your option) any later version.
13355 + This program is distributed in the hope that it will be useful, but
13356 + WITHOUT ANY WARRANTY; without even the implied warranty of
13357 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13358 + General Public License for more details.
13361 +#include <stdio.h>
13362 +#include <stdarg.h>
13364 +char *get_user_response(const char *format, ...);
13366 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
13367 --- busybox-1.2.0-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13368 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c 2006-07-22 16:31:26.000000000 +0200
13370 +/* void_list.c - the itsy package management system
13374 + Copyright (C) 2001 University of Southern California
13376 + This program is free software; you can redistribute it and/or
13377 + modify it under the terms of the GNU General Public License as
13378 + published by the Free Software Foundation; either version 2, or (at
13379 + your option) any later version.
13381 + This program is distributed in the hope that it will be useful, but
13382 + WITHOUT ANY WARRANTY; without even the implied warranty of
13383 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13384 + General Public License for more details.
13388 +#include <errno.h>
13390 +#include "void_list.h"
13392 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13394 + elt->next = NULL;
13395 + elt->data = data;
13400 +void void_list_elt_deinit(void_list_elt_t *elt)
13402 + void_list_elt_init(elt, NULL);
13405 +int void_list_init(void_list_t *list)
13407 + void_list_elt_init(&list->pre_head, NULL);
13408 + list->head = NULL;
13409 + list->pre_head.next = list->head;
13410 + list->tail = NULL;
13415 +void void_list_deinit(void_list_t *list)
13417 + void_list_elt_t *elt;
13419 + while (list->head) {
13420 + elt = void_list_pop(list);
13421 + void_list_elt_deinit(elt);
13422 + /* malloced in void_list_append */
13427 +int void_list_append(void_list_t *list, void *data)
13429 + void_list_elt_t *elt;
13431 + /* freed in void_list_deinit */
13432 + elt = malloc(sizeof(void_list_elt_t));
13433 + if (elt == NULL) {
13434 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13438 + void_list_elt_init(elt, data);
13440 + if (list->tail) {
13441 + list->tail->next = elt;
13442 + list->tail = elt;
13444 + list->head = elt;
13445 + list->pre_head.next = list->head;
13446 + list->tail = elt;
13452 +int void_list_push(void_list_t *list, void *data)
13454 + void_list_elt_t *elt;
13456 + elt = malloc(sizeof(void_list_elt_t));
13457 + if (elt == NULL) {
13458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13462 + void_list_elt_init(elt, data);
13464 + elt->next = list->head;
13465 + list->head->next = elt;
13466 + if (list->tail == NULL) {
13467 + list->tail = list->head;
13473 +void_list_elt_t *void_list_pop(void_list_t *list)
13475 + void_list_elt_t *elt;
13477 + elt = list->head;
13479 + if (list->head) {
13480 + list->head = list->head->next;
13481 + list->pre_head.next = list->head;
13482 + if (list->head == NULL) {
13483 + list->tail = NULL;
13490 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13492 + void_list_elt_t *prior;
13493 + void_list_elt_t *old_elt;
13497 + old_data = old_elt->data;
13499 + if (old_elt == list->head) {
13500 + prior = &list->pre_head;
13501 + void_list_pop(list);
13503 + for (prior = list->head; prior; prior = prior->next) {
13504 + if (prior->next == old_elt) {
13508 + if (prior == NULL || prior->next != old_elt) {
13509 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13512 + prior->next = old_elt->next;
13514 + if (old_elt == list->tail) {
13515 + list->tail = prior;
13519 + void_list_elt_deinit(old_elt);
13525 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13526 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13528 + void_list_elt_t *prior;
13529 + void_list_elt_t *old_elt = NULL;
13530 + void *old_data = NULL;
13532 + /* first element */
13533 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13534 + old_elt = list->head;
13535 + old_data = list->head->data;
13536 + void_list_pop(list);
13539 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13540 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13541 + old_elt = prior->next;
13542 + old_data = old_elt->data;
13550 + prior->next = old_elt->next;
13552 + if (old_elt == list->tail) {
13553 + list->tail = prior;
13557 + void_list_elt_deinit(old_elt);
13564 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
13565 --- busybox-1.2.0-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13566 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h 2006-07-22 16:31:26.000000000 +0200
13568 +/* void_list.h - the itsy package management system
13572 + Copyright (C) 2001 University of Southern California
13574 + This program is free software; you can redistribute it and/or
13575 + modify it under the terms of the GNU General Public License as
13576 + published by the Free Software Foundation; either version 2, or (at
13577 + your option) any later version.
13579 + This program is distributed in the hope that it will be useful, but
13580 + WITHOUT ANY WARRANTY; without even the implied warranty of
13581 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13582 + General Public License for more details.
13585 +#ifndef VOID_LIST_H
13586 +#define VOID_LIST_H
13588 +typedef struct void_list_elt void_list_elt_t;
13589 +struct void_list_elt
13591 + void_list_elt_t *next;
13595 +typedef struct void_list void_list_t;
13598 + void_list_elt_t pre_head;
13599 + void_list_elt_t *head;
13600 + void_list_elt_t *tail;
13603 +static inline int void_list_empty(void_list_t *list)
13605 + if (list->head == NULL)
13611 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13612 +void void_list_elt_deinit(void_list_elt_t *elt);
13614 +int void_list_init(void_list_t *list);
13615 +void void_list_deinit(void_list_t *list);
13617 +int void_list_append(void_list_t *list, void *data);
13618 +int void_list_push(void_list_t *list, void *data);
13619 +void_list_elt_t *void_list_pop(void_list_t *list);
13621 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13622 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13623 +typedef int (*void_list_cmp_t)(const void *, const void *);
13624 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13627 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c
13628 --- busybox-1.2.0-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13629 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-07-22 16:31:26.000000000 +0200
13631 +/* xsystem.c - system(3) with error messages
13635 + Copyright (C) 2001 University of Southern California
13637 + This program is free software; you can redistribute it and/or
13638 + modify it under the terms of the GNU General Public License as
13639 + published by the Free Software Foundation; either version 2, or (at
13640 + your option) any later version.
13642 + This program is distributed in the hope that it will be useful, but
13643 + WITHOUT ANY WARRANTY; without even the implied warranty of
13644 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13645 + General Public License for more details.
13649 +#include <sys/wait.h>
13651 +#include "xsystem.h"
13653 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13654 + really need the /bin/sh invocation which takes resources and
13655 + introduces security problems. I should switch all of this to a sort
13656 + of execl() or execv() interface/implementation.
13659 +/* Like system(3), but with error messages printed if the fork fails
13660 + or if the child process dies due to an uncaught signal. Also, the
13661 + return value is a bit simpler:
13663 + -1 if there was any problem
13664 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13665 + as defined in <sys/wait.h>.
13667 +int xsystem(const char *cmd)
13671 + err = system(cmd);
13674 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13675 + __FUNCTION__, cmd);
13679 + if (WIFSIGNALED(err)) {
13680 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13681 + __FUNCTION__, WTERMSIG(err), cmd);
13685 + if (WIFEXITED(err)) {
13686 + /* Normal child exit */
13687 + return WEXITSTATUS(err);
13690 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13691 + __FUNCTION__, err);
13695 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h
13696 --- busybox-1.2.0-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13697 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-07-22 16:31:26.000000000 +0200
13699 +/* xsystem.h - system(3) with error messages
13703 + Copyright (C) 2001 University of Southern California
13705 + This program is free software; you can redistribute it and/or
13706 + modify it under the terms of the GNU General Public License as
13707 + published by the Free Software Foundation; either version 2, or (at
13708 + your option) any later version.
13710 + This program is distributed in the hope that it will be useful, but
13711 + WITHOUT ANY WARRANTY; without even the implied warranty of
13712 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13713 + General Public License for more details.
13719 +#include <stdlib.h>
13721 +/* Like system(3), but with error messages printed if the fork fails
13722 + or if the child process dies due to an uncaught signal. Also, the
13723 + return value is a bit simpler:
13725 + -1 if there was any problem
13726 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13727 + as defined in <sys/wait.h>.
13729 +int xsystem(const char *cmd);
13733 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
13734 --- busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c 2006-07-01 00:42:04.000000000 +0200
13735 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-07-22 16:31:26.000000000 +0200
13736 @@ -126,3 +126,17 @@
13737 utime(file_header->name, &t);
13741 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13743 + char *name_ptr = archive_handle->file_header->name;
13745 + name_ptr += strspn(name_ptr, "./");
13746 + if (name_ptr[0] != '\0') {
13747 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13748 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13749 + strcat(archive_handle->file_header->name, name_ptr);
13750 + data_extract_all(archive_handle);
13754 diff -ruN busybox-1.2.0-orig/archival/libunarchive/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in
13755 --- busybox-1.2.0-orig/archival/libunarchive/Makefile.in 2006-07-01 00:42:03.000000000 +0200
13756 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-07-22 16:31:26.000000000 +0200
13758 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13759 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13760 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13761 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13762 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13763 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13764 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13765 diff -ruN busybox-1.2.0-orig/archival/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in
13766 --- busybox-1.2.0-orig/archival/Makefile.in 2006-07-01 00:42:04.000000000 +0200
13767 +++ busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in 2006-07-22 16:31:25.000000000 +0200
13769 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
13770 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
13771 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
13772 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
13773 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
13774 ARCHIVAL-$(CONFIG_RPM) += rpm.o
13775 ARCHIVAL-$(CONFIG_TAR) += tar.o
13776 diff -ruN busybox-1.2.0-orig/include/applets.h busybox-1.2.0+ipkg-0.99.162/include/applets.h
13777 --- busybox-1.2.0-orig/include/applets.h 2006-07-01 00:42:10.000000000 +0200
13778 +++ busybox-1.2.0+ipkg-0.99.162/include/applets.h 2006-07-22 16:35:35.000000000 +0200
13779 @@ -152,6 +152,7 @@
13780 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13781 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13782 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13783 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13784 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13785 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13786 USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER))
13787 diff -ruN busybox-1.2.0-orig/include/unarchive.h busybox-1.2.0+ipkg-0.99.162/include/unarchive.h
13788 --- busybox-1.2.0-orig/include/unarchive.h 2006-07-01 00:42:10.000000000 +0200
13789 +++ busybox-1.2.0+ipkg-0.99.162/include/unarchive.h 2006-07-22 16:31:26.000000000 +0200
13792 extern void data_skip(archive_handle_t *archive_handle);
13793 extern void data_extract_all(archive_handle_t *archive_handle);
13794 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13795 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13796 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13798 diff -ruN busybox-1.2.0-orig/include/usage.h busybox-1.2.0+ipkg-0.99.162/include/usage.h
13799 --- busybox-1.2.0-orig/include/usage.h 2006-07-01 00:42:10.000000000 +0200
13800 +++ busybox-1.2.0+ipkg-0.99.162/include/usage.h 2006-07-22 16:31:26.000000000 +0200
13801 @@ -982,6 +982,82 @@
13802 "$ ls -la /tmp/busybox*\n" \
13803 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13805 +#define ipkg_trivial_usage \
13806 + "[options]... sub-command [arguments]..."
13807 +#define ipkg_full_usage \
13808 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13810 + "Sub-commands:\n" \
13811 + "\nPackage Manipulation:\n" \
13812 + "\tupdate Update list of available packages\n" \
13813 + "\tupgrade Upgrade all installed packages to latest version\n" \
13814 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13815 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13816 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13817 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13818 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13819 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13821 + "Informational Commands:\n" \
13822 + "\tlist List available packages and descriptions\n" \
13823 + "\tlist_installed List all and only the installed packages and description \n" \
13824 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13825 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13826 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13827 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13828 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13829 + "\tcompare_versions <v1> <op> <v2>\n" \
13830 + "\t compare versions using <= < > >= = << >>\n" \
13831 + "\tprint_architecture prints the architecture.\n" \
13832 + "\tprint_installation_architecture\n" \
13833 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13834 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13835 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13836 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13837 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13838 + "\t prints the installation architecture.\n" \
13841 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13842 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13843 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13844 + "\t 0 errors only\n" \
13845 + "\t 1 normal messages (default)\n" \
13846 + "\t 2 informative messages\n" \
13847 + "\t 3 debug output\n" \
13848 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13849 + "\t-conf <conf_file> Default configuration file location\n" \
13850 + " is /etc/ipkg.conf\n" \
13851 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13852 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13853 + " <dest_name> should be a defined dest name from\n" \
13854 + " the configuration file, (but can also be a\n" \
13855 + " directory name in a pinch).\n" \
13856 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13857 + "\t-offline <offline_root> offline installation of packages.\n" \
13858 + "\t-verbose_wget more wget messages\n" \
13860 + "Force Options (use when ipkg is too smart for its own good):\n" \
13861 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13862 + "\t Install/remove package in spite of failed dependences\n" \
13863 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13864 + " (no prompts). Note that this will not prevent\n" \
13865 + " package installation scripts from prompting.\n" \
13866 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13867 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13868 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13869 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13870 + "\t-noaction No action -- test only\n" \
13871 + "\t-nodeps Do not follow dependences\n" \
13872 + "\t-force-removal-of-dependent-packages\n" \
13873 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13874 + "\t-test No action -- test only\n" \
13875 + "\t-t Specify tmp-dir.\n" \
13876 + "\t--tmp-dir Specify tmp-dir.\n" \
13878 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13879 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13881 #define halt_trivial_usage \
13882 "[-d<delay>] [-n<nosync>] [-f<force>]"
13883 #define halt_full_usage \
13884 diff -ruN busybox-1.2.0-orig/Makefile busybox-1.2.0+ipkg-0.99.162/Makefile
13885 --- busybox-1.2.0-orig/Makefile 2006-07-01 00:42:13.000000000 +0200
13886 +++ busybox-1.2.0+ipkg-0.99.162/Makefile 2006-07-22 16:31:25.000000000 +0200
13888 export srctree=$(top_srcdir)
13889 vpath %/Config.in $(srctree)
13891 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
13892 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
13893 debianutils editors findutils init miscutils modutils networking \
13894 networking/libiproute networking/udhcp procps loginutils shell \
13895 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb