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 --passive-ftp %s %s%s %s%s %s -P %s %s",
3475 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3476 + conf->proxy_user ? "--proxy-user=" : "",
3477 + conf->proxy_user ? conf->proxy_user : "",
3478 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3479 + conf->proxy_passwd ? conf->proxy_passwd : "",
3480 + conf->verbose_wget ? "" : "-q",
3483 + err = xsystem(cmd);
3486 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3487 + __FUNCTION__, err, cmd);
3489 + unlink(tmp_file_location);
3490 + free(tmp_file_location);
3497 + err = file_move(tmp_file_location, dest_file_name);
3499 + free(tmp_file_location);
3509 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3514 + if (pkg->src == NULL) {
3515 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3516 + pkg->name, pkg->parent->name);
3520 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3522 + /* XXX: BUG: The pkg->filename might be something like
3523 + "../../foo.ipk". While this is correct, and exactly what we
3524 + want to use to construct url above, here we actually need to
3525 + use just the filename part, without any directory. */
3526 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3528 + err = ipkg_download(conf, url, pkg->local_filename);
3535 + * Downloads file from url, installs in package database, return package name.
3537 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3545 + if (str_starts_with(url, "http://")
3546 + || str_starts_with(url, "ftp://")) {
3548 + char *file_basec = strdup(url);
3549 + char *file_base = basename(file_basec);
3551 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3552 + err = ipkg_download(conf, url, tmp_file);
3556 + err = pkg_init_from_file(pkg, tmp_file);
3559 + pkg->local_filename = strdup(tmp_file);
3564 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3565 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3567 + err = pkg_init_from_file(pkg, url);
3570 + pkg->local_filename = strdup(url);
3571 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand \(%s\).\n", pkg->name,pkg->local_filename);
3572 + pkg->provided_by_hand = 1;
3580 + if (!pkg->architecture) {
3581 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3585 + pkg->dest = conf->default_dest;
3586 + pkg->state_want = SW_INSTALL;
3587 + pkg->state_flag |= SF_PREFER;
3588 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3589 + if ( pkg == NULL ){
3590 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3594 + *namep = strdup(pkg->name);
3598 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
3599 --- busybox-1.2.0-orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
3600 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_download.h 2006-07-22 16:31:25.000000000 +0200
3602 +/* ipkg_download.h - the itsy package management system
3606 + Copyright (C) 2001 University of Southern California
3608 + This program is free software; you can redistribute it and/or
3609 + modify it under the terms of the GNU General Public License as
3610 + published by the Free Software Foundation; either version 2, or (at
3611 + your option) any later version.
3613 + This program is distributed in the hope that it will be useful, but
3614 + WITHOUT ANY WARRANTY; without even the implied warranty of
3615 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3616 + General Public License for more details.
3619 +#ifndef IPKG_DOWNLOAD_H
3620 +#define IPKG_DOWNLOAD_H
3622 +#include "ipkg_conf.h"
3624 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3625 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3627 + * Downloads file from url, installs in package database, return package name.
3629 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3632 diff -ruN busybox-1.2.0-orig/archival/libipkg/ipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h
3633 --- busybox-1.2.0-orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
3634 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg.h 2006-07-22 16:31:25.000000000 +0200
3636 +/* ipkg.h - the itsy package management system
3640 + Copyright (C) 2001 University of Southern California
3642 + This program is free software; you can redistribute it and/or
3643 + modify it under the terms of the GNU General Public License as
3644 + published by the Free Software Foundation; either version 2, or (at
3645 + your option) any later version.
3647 + This program is distributed in the hope that it will be useful, but
3648 + WITHOUT ANY WARRANTY; without even the implied warranty of
3649 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3650 + General Public License for more details.
3657 +#ifdef HAVE_CONFIG_H
3658 +#include "config.h"
3663 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3666 +#include "ipkg_includes.h"
3667 +#include "ipkg_conf.h"
3668 +#include "ipkg_message.h"
3670 +#define IPKG_PKG_EXTENSION ".ipk"
3671 +#define DPKG_PKG_EXTENSION ".deb"
3673 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3674 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3676 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3677 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3678 +#define IPKG_INFO_DIR_SUFFIX "info"
3679 +#define IPKG_STATUS_FILE_SUFFIX "status"
3681 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3683 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3685 +#define IPKG_VERSION "0.99.162"
3690 + IPKG_PKG_DEPS_UNSATISFIED,
3691 + IPKG_PKG_IS_ESSENTIAL,
3692 + IPKG_PKG_HAS_DEPENDENTS,
3693 + IPKG_PKG_HAS_NO_CANDIDATE
3695 +typedef enum ipkg_error ipkg_error_t;
3697 +extern int ipkg_state_changed;
3702 + struct errlist * next;
3705 +extern struct errlist* error_list;
3707 +extern ipkg_conf_t *global_conf;
3710 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
3711 --- busybox-1.2.0-orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
3712 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_includes.h 2006-07-22 16:31:25.000000000 +0200
3714 +#ifndef IPKG_INCLUDES_H
3715 +#define IPKG_INCLUDES_H
3717 +/* Define to 1 if you have the <memory.h> header file. */
3718 +#define HAVE_MEMORY_H 1
3720 +/* Define to 1 if you have the <regex.h> header file. */
3721 +#define HAVE_REGEX_H 1
3723 +/* Define to 1 if you have the <stdlib.h> header file. */
3724 +#define HAVE_STDLIB_H 1
3726 +/* Define to 1 if you have the <strings.h> header file. */
3727 +#define HAVE_STRINGS_H 1
3729 +/* Define to 1 if you have the <string.h> header file. */
3730 +#define HAVE_STRING_H 1
3732 +/* Define to 1 if you have the <sys/stat.h> header file. */
3733 +#define HAVE_SYS_STAT_H 1
3735 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3736 +#define HAVE_SYS_WAIT_H 1
3738 +/* Define to 1 if you have the <unistd.h> header file. */
3739 +#define HAVE_UNISTD_H 1
3741 +/* Define to 1 if you have the ANSI C header files. */
3742 +#define STDC_HEADERS 1
3748 +# include <stdlib.h>
3749 +# include <stdarg.h>
3750 +# include <stddef.h>
3751 +# include <ctype.h>
3752 +# include <errno.h>
3755 +# include <stdlib.h>
3760 +# include <regex.h>
3764 +# if !STDC_HEADERS && HAVE_MEMORY_H
3765 +# include <memory.h>
3767 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3769 +# define __USE_GNU 1
3771 +# include <string.h>
3776 +# include <strings.h>
3779 +#if HAVE_SYS_STAT_H
3780 +# include <sys/stat.h>
3783 +#if HAVE_SYS_WAIT_H
3784 +# include <sys/wait.h>
3788 +# include <sys/types.h>
3789 +# include <unistd.h>
3792 +#endif /* IPKG_INCLUDES_H */
3793 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
3794 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
3795 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.c 2006-07-22 16:31:25.000000000 +0200
3797 +/* ipkg_install.c - the itsy package management system
3801 + Copyright (C) 2001 University of Southern California
3803 + This program is free software; you can redistribute it and/or
3804 + modify it under the terms of the GNU General Public License as
3805 + published by the Free Software Foundation; either version 2, or (at
3806 + your option) any later version.
3808 + This program is distributed in the hope that it will be useful, but
3809 + WITHOUT ANY WARRANTY; without even the implied warranty of
3810 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3811 + General Public License for more details.
3816 +#include <dirent.h>
3819 +#include <signal.h>
3820 +typedef void (*sighandler_t)(int);
3823 +#include "pkg_hash.h"
3824 +#include "pkg_extract.h"
3826 +#include "ipkg_install.h"
3827 +#include "ipkg_configure.h"
3828 +#include "ipkg_download.h"
3829 +#include "ipkg_remove.h"
3831 +#include "ipkg_utils.h"
3832 +#include "ipkg_message.h"
3834 +#include "sprintf_alloc.h"
3835 +#include "file_util.h"
3836 +#include "str_util.h"
3837 +#include "xsystem.h"
3840 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3841 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3842 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3844 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3845 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3846 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3847 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3848 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3849 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3850 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3851 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3852 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3853 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3854 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3855 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3856 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3858 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3859 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3860 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3861 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3862 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3864 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3866 +static int user_prefers_old_conffile(const char *file, const char *backup);
3868 +static char *backup_filename_alloc(const char *file_name);
3869 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3870 +static int backup_exists_for(const char *file_name);
3871 +static int backup_remove(const char *file_name);
3874 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3878 + char *old_version, *new_version;
3881 + if (pkg == NULL) {
3885 + err = pkg_init_from_file(pkg, filename);
3890 + if (!pkg->architecture) {
3891 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3895 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3896 + freeing the pkg that we pass in. It might be nice to clean this up
3898 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3899 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3901 + pkg->local_filename = strdup(filename);
3904 + old_version = pkg_version_str_alloc(old);
3905 + new_version = pkg_version_str_alloc(pkg);
3907 + cmp = pkg_compare_versions(old, pkg);
3908 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3909 + cmp = -1 ; /* then we force ipkg to downgrade */
3910 + /* We need to use a value < 0 because in the 0 case we are asking to */
3911 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3914 + ipkg_message(conf, IPKG_NOTICE,
3915 + "Not downgrading package %s on %s from %s to %s.\n",
3916 + old->name, old->dest->name, old_version, new_version);
3917 + pkg->state_want = SW_DEINSTALL;
3918 + pkg->state_flag |= SF_OBSOLETE;
3919 + free(old_version);
3920 + free(new_version);
3923 + free(old_version);
3924 + free(new_version);
3928 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3929 + return ipkg_install_pkg(conf, pkg,0);
3932 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3936 + char *old_version, *new_version;
3938 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3939 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3941 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3943 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3944 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3946 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3948 +/* Pigi Basically here is broken the version stuff.
3949 + What's happening is that nothing provide the version to differents
3950 + functions, so the returned struct is always the latest.
3951 + That's why the install by name don't work.
3953 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3956 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3958 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3959 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3961 + if (new == NULL) {
3962 + return IPKG_PKG_HAS_NO_CANDIDATE;
3965 + new->state_flag |= SF_USER;
3967 + old_version = pkg_version_str_alloc(old);
3968 + new_version = pkg_version_str_alloc(new);
3970 + cmp = pkg_compare_versions(old, new);
3971 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3972 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
3973 + cmp = -1 ; /* then we force ipkg to downgrade */
3974 + /* We need to use a value < 0 because in the 0 case we are asking to */
3975 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3977 + ipkg_message(conf, IPKG_DEBUG,
3978 + "Comparing visible versions of pkg %s:"
3979 + "\n\t%s is installed "
3980 + "\n\t%s is available "
3981 + "\n\t%d was comparison result\n",
3982 + pkg_name, old_version, new_version, cmp);
3983 + if (cmp == 0 && !conf->force_reinstall) {
3984 + ipkg_message(conf, IPKG_NOTICE,
3985 + "Package %s (%s) installed in %s is up to date.\n",
3986 + old->name, old_version, old->dest->name);
3987 + free(old_version);
3988 + free(new_version);
3990 + } else if (cmp > 0) {
3991 + ipkg_message(conf, IPKG_NOTICE,
3992 + "Not downgrading package %s on %s from %s to %s.\n",
3993 + old->name, old->dest->name, old_version, new_version);
3994 + free(old_version);
3995 + free(new_version);
3997 + } else if (cmp < 0) {
3998 + new->dest = old->dest;
3999 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
4003 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
4004 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
4005 + return any kind of integer, (might be errno from a syscall,
4006 + etc.). This is a real mess and will need to be cleaned up if
4007 + anyone ever wants to make a nice libipkg. */
4009 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4010 + return ipkg_install_pkg(conf, new,0);
4013 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
4015 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
4018 + abstract_pkg_t *ppkg ;
4020 + if (providers == NULL)
4021 + return IPKG_PKG_HAS_NO_CANDIDATE;
4023 + for (i = 0; i < providers->len; i++) {
4024 + ppkg = abstract_pkg_vec_get(providers, i);
4025 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
4026 + err = ipkg_install_by_name(conf, ppkg->name);
4029 +/* XXX Maybe ppkg should be freed ? */
4035 + * Walk dependence graph starting with pkg, collect packages to be
4036 + * installed into pkgs_needed, in dependence order.
4038 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
4041 + pkg_vec_t *depends = pkg_vec_alloc();
4042 + char **unresolved = NULL;
4045 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4050 + ipkg_message(conf, IPKG_ERROR,
4051 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4052 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4053 + while (*unresolved) {
4054 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4057 + ipkg_message(conf, IPKG_ERROR, "\n");
4058 + if (! conf->force_depends) {
4059 + ipkg_message(conf, IPKG_INFO,
4060 + "This could mean that your package list is out of date or that the packages\n"
4061 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4062 + "of this problem try again with the '-force-depends' option.\n");
4063 + pkg_vec_free(depends);
4064 + return IPKG_PKG_DEPS_UNSATISFIED;
4068 + if (ndepends <= 0) {
4069 + pkg_vec_free(depends);
4073 + for (i = 0; i < depends->len; i++) {
4074 + pkg_t *dep = depends->pkgs[i];
4075 + /* The package was uninstalled when we started, but another
4076 + dep earlier in this loop may have depended on it and pulled
4077 + it in, so check first. */
4078 + if ((dep->state_status != SS_INSTALLED)
4079 + && (dep->state_status != SS_UNPACKED)
4080 + && (dep->state_want != SW_INSTALL)) {
4082 + /* Mark packages as to-be-installed */
4083 + dep->state_want = SW_INSTALL;
4085 + /* Dependencies should be installed the same place as pkg */
4086 + if (dep->dest == NULL) {
4087 + dep->dest = pkg->dest;
4090 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4092 + pkg_vec_free(depends);
4098 + pkg_vec_insert(pkgs_needed, pkg);
4100 + pkg_vec_free(depends);
4105 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4109 + char *old_version, *new_version;
4111 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4113 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4114 + if (new == NULL) {
4115 + return IPKG_PKG_HAS_NO_CANDIDATE;
4118 + old_version = pkg_version_str_alloc(old);
4119 + new_version = pkg_version_str_alloc(new);
4121 + cmp = pkg_compare_versions(old, new);
4122 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4123 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4124 + cmp = -1 ; /* then we force ipkg to downgrade */
4125 + /* We need to use a value < 0 because in the 0 case we are asking to */
4126 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4128 + ipkg_message(conf, IPKG_DEBUG,
4129 + "comparing visible versions of pkg %s:"
4130 + "\n\t%s is installed "
4131 + "\n\t%s is available "
4132 + "\n\t%d was comparison result\n",
4133 + pkg_name, old_version, new_version, cmp);
4134 + if (cmp == 0 && !conf->force_reinstall) {
4135 + ipkg_message(conf, IPKG_NOTICE,
4136 + "Package %s (%s) installed in %s is up to date.\n",
4137 + old->name, old_version, old->dest->name);
4138 + free(old_version);
4139 + free(new_version);
4141 + } else if (cmp > 0) {
4142 + ipkg_message(conf, IPKG_NOTICE,
4143 + "Not downgrading package %s on %s from %s to %s.\n",
4144 + old->name, old->dest->name, old_version, new_version);
4145 + free(old_version);
4146 + free(new_version);
4148 + } else if (cmp < 0) {
4149 + new->dest = old->dest;
4150 + old->state_want = SW_DEINSTALL;
4151 + old->state_flag |= SF_OBSOLETE;
4154 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4159 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4162 + pkg_vec_t *depends = pkg_vec_alloc();
4164 + char **unresolved = NULL;
4167 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4172 + ipkg_message(conf, IPKG_ERROR,
4173 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4174 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4175 + while (*unresolved) {
4176 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4179 + ipkg_message(conf, IPKG_ERROR, "\n");
4180 + if (! conf->force_depends) {
4181 + ipkg_message(conf, IPKG_INFO,
4182 + "This could mean that your package list is out of date or that the packages\n"
4183 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4184 + "of this problem try again with the '-force-depends' option.\n");
4185 + pkg_vec_free(depends);
4186 + return IPKG_PKG_DEPS_UNSATISFIED;
4190 + if (ndepends <= 0) {
4194 + /* Mark packages as to-be-installed */
4195 + for (i=0; i < depends->len; i++) {
4196 + /* Dependencies should be installed the same place as pkg */
4197 + if (depends->pkgs[i]->dest == NULL) {
4198 + depends->pkgs[i]->dest = pkg->dest;
4200 + depends->pkgs[i]->state_want = SW_INSTALL;
4203 + for (i = 0; i < depends->len; i++) {
4204 + dep = depends->pkgs[i];
4205 + /* The package was uninstalled when we started, but another
4206 + dep earlier in this loop may have depended on it and pulled
4207 + it in, so check first. */
4208 + if ((dep->state_status != SS_INSTALLED)
4209 + && (dep->state_status != SS_UNPACKED)) {
4210 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4211 + err = ipkg_install_pkg(conf, dep,0);
4213 + pkg_vec_free(depends);
4219 + pkg_vec_free(depends);
4225 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4226 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4228 + if (conf->nodeps == 0) {
4230 + pkg_vec_t *installed = pkg_vec_alloc();
4231 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4232 + for (i = 0; i < installed->len; i++) {
4233 + pkg_t *pkg = installed->pkgs[i];
4234 + satisfy_dependencies_for(conf, pkg);
4236 + pkg_vec_free(installed);
4243 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4246 + pkg_vec_t *conflicts = NULL;
4248 + const char *prefix;
4249 + if (conf->force_depends) {
4250 + level = IPKG_NOTICE;
4251 + prefix = "Warning";
4253 + level = IPKG_ERROR;
4257 + if (!conf->force_depends)
4258 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4261 + ipkg_message(conf, level,
4262 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4264 + while (i < conflicts->len)
4265 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4266 + ipkg_message(conf, level, "\n");
4267 + pkg_vec_free(conflicts);
4268 + return IPKG_PKG_DEPS_UNSATISFIED;
4273 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4275 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4276 + str_list_elt_t *iter;
4278 + for (iter = new_list->head; iter; iter = iter->next) {
4279 + char *new_file = iter->data;
4280 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4282 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4283 + if (!owner || (owner == old_pkg))
4284 + file_hash_set_file_owner(conf, new_file, new_pkg);
4287 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4288 + for (iter = old_list->head; iter; iter = iter->next) {
4289 + char *old_file = iter->data;
4290 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4291 + if (owner == old_pkg) {
4293 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4300 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4302 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4304 + /* sma 6.20.02: yup; here's the first bit */
4306 + * XXX: BUG easy for cworth
4307 + * 1) please point the call below to the correct current root destination
4308 + * 2) we need to resolve how to check the required space for a pending pkg,
4309 + * my diddling with the .ipk file size below isn't going to cut it.
4310 + * 3) return a proper error code instead of 1
4312 + int comp_size, blocks_available;
4314 + if (!conf->force_space && pkg->installed_size != NULL) {
4315 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4317 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4318 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4319 + comp_size = (int)((comp_size + 1023) / 1024);
4321 + if (comp_size >= blocks_available) {
4322 + ipkg_message(conf, IPKG_ERROR,
4323 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4324 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4331 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4334 + char *conffiles_file_name;
4336 + FILE *conffiles_file;
4338 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4340 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4341 + if (pkg->tmp_unpack_dir == NULL) {
4342 + ipkg_message(conf, IPKG_ERROR,
4343 + "%s: Failed to create temporary directory '%s': %s\n",
4344 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4348 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4353 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4354 + conffiles. Seems like I should be able to get everything to go
4355 + through pkg_init_from_file. If so, maybe it would make sense to
4356 + move all of unpack_pkg_control_files to that function. */
4358 + /* Don't need to re-read conffiles if we already have it */
4359 + if (pkg->conffiles.head) {
4363 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4364 + if (! file_exists(conffiles_file_name)) {
4365 + free(conffiles_file_name);
4369 + conffiles_file = fopen(conffiles_file_name, "r");
4370 + if (conffiles_file == NULL) {
4371 + fprintf(stderr, "%s: failed to open %s: %s\n",
4372 + __FUNCTION__, conffiles_file_name, strerror(errno));
4373 + free(conffiles_file_name);
4376 + free(conffiles_file_name);
4380 + char *cf_name_in_dest;
4382 + cf_name = file_read_line_alloc(conffiles_file);
4383 + if (cf_name == NULL) {
4386 + str_chomp(cf_name);
4387 + if (cf_name[0] == '\0') {
4391 + /* Prepend dest->root_dir to conffile name.
4392 + Take pains to avoid multiple slashes. */
4393 + root_dir = pkg->dest->root_dir;
4394 + if (conf->offline_root)
4395 + /* skip the offline_root prefix */
4396 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4397 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4398 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4400 + /* Can't get an md5sum now, (file isn't extracted yet).
4401 + We'll wait until resolve_conffiles */
4402 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4405 + free(cf_name_in_dest);
4408 + fclose(conffiles_file);
4413 +/* returns number of installed replacees */
4414 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4416 + abstract_pkg_t **replaces = pkg->replaces;
4417 + int replaces_count = pkg->replaces_count;
4419 + for (i = 0; i < replaces_count; i++) {
4420 + abstract_pkg_t *ab_pkg = replaces[i];
4421 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4423 + for (j = 0; j < pkg_vec->len; j++) {
4424 + pkg_t *replacee = pkg_vec->pkgs[j];
4425 + if (!pkg_conflicts(pkg, replacee))
4427 + if (replacee->state_status == SS_INSTALLED) {
4428 + pkg_vec_insert(installed_replacees, replacee);
4433 + return installed_replacees->len;
4436 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4439 + int replaces_count = replacees->len;
4440 + for (i = 0; i < replaces_count; i++) {
4441 + pkg_t *replacee = replacees->pkgs[i];
4443 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4444 + err = ipkg_remove_pkg(conf, replacee,0);
4451 +/* to unwind the removal: make sure they are installed */
4452 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4455 + int replaces_count = replacees->len;
4456 + for (i = 0; i < replaces_count; i++) {
4457 + pkg_t *replacee = replacees->pkgs[i];
4458 + if (replacee->state_status != SS_INSTALLED) {
4459 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4460 + err = ipkg_install_pkg(conf, replacee,0);
4468 +int caught_sigint = 0;
4469 +static void ipkg_install_pkg_sigint_handler(int sig)
4471 + caught_sigint = sig;
4474 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4475 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4478 + char message_out[15];
4479 + char *old_version = pkg_version_str_alloc(old_pkg);
4480 + char *new_version = pkg_version_str_alloc(pkg);
4481 + int cmp = pkg_compare_versions(old_pkg, pkg);
4484 + memset(message_out,'\x0',15);
4485 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4486 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4487 + cmp = -1 ; /* then we force ipkg to downgrade */
4488 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4489 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4493 + ipkg_message(conf, IPKG_NOTICE,
4494 + "Not downgrading package %s on %s from %s to %s.\n",
4495 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4497 + } else if (cmp < 0) {
4498 + ipkg_message(conf, IPKG_NOTICE,
4499 + "%s%s on %s from %s to %s...\n",
4500 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4501 + pkg->dest = old_pkg->dest;
4503 + } else /* cmp == 0 */ {
4504 + if (conf->force_reinstall) {
4505 + ipkg_message(conf, IPKG_NOTICE,
4506 + "Reinstalling %s (%s) on %s...\n",
4507 + pkg->name, new_version, old_pkg->dest->name);
4508 + pkg->dest = old_pkg->dest;
4511 + ipkg_message(conf, IPKG_NOTICE,
4512 + "Not installing %s (%s) on %s -- already installed.\n",
4513 + pkg->name, new_version, old_pkg->dest->name);
4517 + free(old_version);
4518 + free(new_version);
4521 + char message_out[15] ;
4522 + memset(message_out,'\x0',15);
4524 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4526 + strncpy( message_out,"Installing ",strlen("Installing ") );
4527 + char *version = pkg_version_str_alloc(pkg);
4529 + ipkg_message(conf, IPKG_NOTICE,
4530 + "%s%s (%s) to %s...\n", message_out,
4531 + pkg->name, version, pkg->dest->name);
4537 +/* and now the meat... */
4538 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4542 + pkg_t *old_pkg = NULL;
4543 + pkg_vec_t *replacees;
4544 + abstract_pkg_t *ab_pkg = NULL;
4545 + int old_state_flag;
4549 + if ( from_upgrade )
4550 + message = 1; /* Coming from an upgrade, and should change the output message */
4553 + ipkg_message(conf, IPKG_ERROR,
4554 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4558 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4560 + if (!pkg_arch_supported(conf, pkg)) {
4561 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4562 + pkg->architecture, pkg->name);
4565 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4566 + err = satisfy_dependencies_for(conf, pkg);
4567 + if (err) { return err; }
4569 + ipkg_message(conf, IPKG_NOTICE,
4570 + "Package %s is already installed in %s.\n",
4571 + pkg->name, pkg->dest->name);
4575 + if (pkg->dest == NULL) {
4576 + pkg->dest = conf->default_dest;
4579 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4581 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4582 + if (err) { return err; }
4584 + pkg->state_want = SW_INSTALL;
4586 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4590 + /* Abhaya: conflicts check */
4591 + err = check_conflicts_for(conf, pkg);
4592 + if (err) { return err; }
4594 + /* this setup is to remove the upgrade scenario in the end when
4595 + installing pkg A, A deps B & B deps on A. So both B and A are
4596 + installed. Then A's installation is started resulting in an
4597 + uncecessary upgrade */
4598 + if (pkg->state_status == SS_INSTALLED
4599 + && conf->force_reinstall == 0) return 0;
4601 + err = verify_pkg_installable(conf, pkg);
4602 + if (err) { return err; }
4604 + if (pkg->local_filename == NULL) {
4605 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4607 + ipkg_message(conf, IPKG_ERROR,
4608 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4614 +/* Check for md5 values */
4617 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4618 + if (strcmp(file_md5, pkg->md5sum))
4620 + ipkg_message(conf, IPKG_ERROR,
4621 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4629 + if (pkg->tmp_unpack_dir == NULL) {
4630 + unpack_pkg_control_files(conf, pkg);
4633 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4634 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4635 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4636 + err = update_file_ownership(conf, pkg, old_pkg);
4637 + if (err) { return err; }
4639 + if (conf->nodeps == 0) {
4640 + err = satisfy_dependencies_for(conf, pkg);
4641 + if (err) { return err; }
4644 + replacees = pkg_vec_alloc();
4645 + pkg_get_installed_replacees(conf, pkg, replacees);
4647 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4649 + sigset_t newset, oldset;
4650 + sighandler_t old_handler = NULL;
4651 + int use_signal = 0;
4652 + caught_sigint = 0;
4654 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4656 + sigemptyset(&newset);
4657 + sigaddset(&newset, SIGINT);
4658 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4661 + ipkg_state_changed++;
4662 + pkg->state_flag |= SF_FILELIST_CHANGED;
4664 + /* XXX: BUG: we really should treat replacement more like an upgrade
4665 + * Instead, we're going to remove the replacees
4667 + err = pkg_remove_installed_replacees(conf, replacees);
4668 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4670 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4671 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4673 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4674 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4676 + err = preinst_configure(conf, pkg, old_pkg);
4677 + if (err) goto UNWIND_PREINST_CONFIGURE;
4679 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4680 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4682 + err = check_data_file_clashes(conf, pkg, old_pkg);
4683 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4685 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4686 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4688 + if (conf->noaction) return 0;
4690 + /* point of no return: no unwinding after this */
4691 + if (old_pkg && !conf->force_reinstall) {
4692 + old_pkg->state_want = SW_DEINSTALL;
4694 + if (old_pkg->state_flag & SF_NOPRUNE) {
4695 + ipkg_message(conf, IPKG_INFO,
4696 + " not removing obsolesced files because package marked noprune\n");
4698 + ipkg_message(conf, IPKG_INFO,
4699 + " removing obsolesced files\n");
4700 + remove_obsolesced_files(conf, pkg, old_pkg);
4702 + /* removing files from old package, to avoid ghost files */
4703 + remove_data_files_and_list(conf, old_pkg);
4704 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4705 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4706 + remove_postrm(conf, old_pkg);
4712 + ipkg_message(conf, IPKG_INFO,
4713 + " installing maintainer scripts\n");
4714 + install_maintainer_scripts(conf, pkg, old_pkg);
4716 + /* the following just returns 0 */
4717 + remove_disappeared(conf, pkg);
4719 + ipkg_message(conf, IPKG_INFO,
4720 + " installing data files\n");
4721 + install_data_files(conf, pkg);
4723 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4724 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4726 + ipkg_message(conf, IPKG_INFO,
4727 + " resolving conf files\n");
4728 + resolve_conffiles(conf, pkg);
4730 + pkg->state_status = SS_UNPACKED;
4731 + old_state_flag = pkg->state_flag;
4732 + pkg->state_flag &= ~SF_PREFER;
4733 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4735 + if (old_pkg && !conf->force_reinstall) {
4736 + old_pkg->state_status = SS_NOT_INSTALLED;
4739 + time(&pkg->installed_time);
4741 + ipkg_message(conf, IPKG_INFO,
4742 + " cleanup temp files\n");
4743 + cleanup_temporary_files(conf, pkg);
4745 + ab_pkg = pkg->parent;
4747 + ab_pkg->state_status = pkg->state_status;
4749 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4752 + signal(SIGINT, old_handler);
4754 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4759 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4760 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4761 + UNWIND_CHECK_DATA_FILE_CLASHES:
4762 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4763 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4764 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4765 + UNWIND_PREINST_CONFIGURE:
4766 + preinst_configure_unwind(conf, pkg, old_pkg);
4767 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4768 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4769 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4770 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4771 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4772 + pkg_remove_installed_replacees_unwind(conf, replacees);
4774 + ipkg_message(conf, IPKG_INFO,
4775 + " cleanup temp files\n");
4776 + cleanup_temporary_files(conf, pkg);
4778 + ipkg_message(conf, IPKG_INFO,
4781 + signal(SIGINT, old_handler);
4783 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4789 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4791 + /* DPKG_INCOMPATIBILITY:
4792 + dpkg does some things here that we don't do yet. Do we care?
4794 + 1. If a version of the package is already installed, call
4795 + old-prerm upgrade new-version
4796 + 2. If the script runs but exits with a non-zero exit status
4797 + new-prerm failed-upgrade old-version
4798 + Error unwind, for both the above cases:
4799 + old-postinst abort-upgrade new-version
4804 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4806 + /* DPKG_INCOMPATIBILITY:
4807 + dpkg does some things here that we don't do yet. Do we care?
4808 + (See prerm_upgrade_old_package for details)
4813 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4815 + /* DPKG_INCOMPATIBILITY:
4816 + dpkg does some things here that we don't do yet. Do we care?
4817 + 2. If a 'conflicting' package is being removed at the same time:
4818 + 1. If any packages depended on that conflicting package and
4819 + --auto-deconfigure is specified, call, for each such package:
4820 + deconfigured's-prerm deconfigure \
4821 + in-favour package-being-installed version \
4822 + removing conflicting-package version
4824 + deconfigured's-postinst abort-deconfigure \
4825 + in-favour package-being-installed-but-failed version \
4826 + removing conflicting-package version
4828 + The deconfigured packages are marked as requiring
4829 + configuration, so that if --install is used they will be
4830 + configured again if possible.
4831 + 2. To prepare for removal of the conflicting package, call:
4832 + conflictor's-prerm remove in-favour package new-version
4834 + conflictor's-postinst abort-remove in-favour package new-version
4839 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4841 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4842 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4847 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4850 + char *preinst_args;
4853 + char *old_version = pkg_version_str_alloc(old_pkg);
4854 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4855 + free(old_version);
4856 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4857 + char *pkg_version = pkg_version_str_alloc(pkg);
4858 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4859 + free(pkg_version);
4861 + preinst_args = strdup("install");
4864 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4866 + ipkg_message(conf, IPKG_ERROR,
4867 + "Aborting installation of %s\n", pkg->name);
4871 + free(preinst_args);
4876 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4878 + /* DPKG_INCOMPATIBILITY:
4879 + dpkg does the following error unwind, should we?
4880 + pkg->postrm abort-upgrade old-version
4881 + OR pkg->postrm abort-install old-version
4882 + OR pkg->postrm abort-install
4887 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4890 + conffile_list_elt_t *iter;
4893 + if (conf->noaction) return 0;
4895 + /* Backup all modified conffiles */
4897 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4901 + cf_name = root_filename_alloc(conf, cf->name);
4903 + /* Don't worry if the conffile is just plain gone */
4904 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4905 + err = backup_make_backup(conf, cf_name);
4914 + /* Backup all conffiles that were not conffiles in old_pkg */
4915 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4918 + cf_name = root_filename_alloc(conf, cf->name);
4919 + /* Ignore if this was a conffile in old_pkg as well */
4920 + if (pkg_get_conffile(old_pkg, cf->name)) {
4924 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4925 + err = backup_make_backup(conf, cf_name);
4936 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4938 + conffile_list_elt_t *iter;
4941 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4942 + backup_remove(iter->data->name);
4946 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4947 + backup_remove(iter->data->name);
4954 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4956 + /* DPKG_INCOMPATIBILITY:
4957 + ipkg takes a slightly different approach than dpkg at this
4958 + point. dpkg installs each file in the new package while
4959 + creating a backup for any file that is replaced, (so that it
4960 + can unwind if necessary). To avoid complexity and redundant
4961 + storage, ipkg doesn't do any installation until later, (at the
4962 + point at which dpkg removes the backups.
4964 + But, we do have to check for data file clashes, since after
4965 + installing a package with a file clash, removing either of the
4966 + packages involved in the clash has the potential to break the
4969 + str_list_t *files_list;
4970 + str_list_elt_t *iter;
4974 + files_list = pkg_get_installed_files(pkg);
4975 + for (iter = files_list->head; iter; iter = iter->next) {
4976 + char *root_filename;
4977 + char *filename = iter->data;
4978 + root_filename = root_filename_alloc(conf, filename);
4979 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4982 + /* Pre-existing conffiles are OK */
4983 + /* @@@@ should have way to check that it is a conffile -Jamey */
4984 + if (backup_exists_for(root_filename)) {
4988 + /* Pre-existing files are OK if force-overwrite was asserted. */
4989 + if (conf->force_overwrite) {
4990 + /* but we need to change who owns this file */
4991 + file_hash_set_file_owner(conf, filename, pkg);
4995 + owner = file_hash_get_file_owner(conf, filename);
4997 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4998 + if (owner && old_pkg) {
4999 + if (strcmp(owner->name, old_pkg->name) == 0) {
5004 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5006 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
5007 + if (pkg_replaces(pkg, owner)) {
5010 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
5011 + then it's ok to overwrite. */
5012 + if (strcmp(owner->name,pkg->name)==0){
5013 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5018 + /* Pre-existing files are OK if they are obsolete */
5019 + obs = hash_table_get(&conf->obs_file_hash, filename);
5021 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
5025 + /* We have found a clash. */
5026 + ipkg_message(conf, IPKG_ERROR,
5027 + "Package %s wants to install file %s\n"
5028 + "\tBut that file is already provided by package ",
5029 + pkg->name, filename);
5031 + ipkg_message(conf, IPKG_ERROR,
5032 + "%s\n", owner->name);
5034 + ipkg_message(conf, IPKG_ERROR,
5035 + "<no package>\nPlease move this file out of the way and try again.\n");
5039 + free(root_filename);
5041 + pkg_free_installed_files(pkg);
5046 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5048 + /* Basically that's the worst hack I could do to be able to change ownership of
5049 + file list, but, being that we have no way to unwind the mods, due to structure
5050 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
5051 + What we do here is change the ownership of file in hash if a replace ( or similar events
5053 + Only the action that are needed to change name should be considered.
5054 + @@@ To change after 1.0 release.
5056 + str_list_t *files_list;
5057 + str_list_elt_t *iter;
5061 + files_list = pkg_get_installed_files(pkg);
5062 + for (iter = files_list->head; iter; iter = iter->next) {
5063 + char *root_filename;
5064 + char *filename = iter->data;
5065 + root_filename = root_filename_alloc(conf, filename);
5066 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5069 + if (conf->force_overwrite) {
5070 + /* but we need to change who owns this file */
5071 + file_hash_set_file_owner(conf, filename, pkg);
5075 + owner = file_hash_get_file_owner(conf, filename);
5077 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5079 + if (pkg_replaces(pkg, owner)) {
5080 +/* It's now time to change the owner of that file.
5081 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5082 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5083 + file_hash_set_file_owner(conf, filename, pkg);
5089 + free(root_filename);
5091 + pkg_free_installed_files(pkg);
5096 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5098 + /* Nothing to do since check_data_file_clashes doesn't change state */
5102 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5104 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5105 + 1. If the package is being upgraded, call
5106 + old-postrm upgrade new-version
5107 + 2. If this fails, attempt:
5108 + new-postrm failed-upgrade old-version
5109 + Error unwind, for both cases:
5110 + old-preinst abort-upgrade new-version */
5114 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5116 + /* DPKG_INCOMPATIBILITY:
5117 + dpkg does some things here that we don't do yet. Do we care?
5118 + (See postrm_upgrade_old_pkg for details)
5123 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5126 + str_list_t *old_files;
5127 + str_list_elt_t *of;
5128 + str_list_t *new_files;
5129 + str_list_elt_t *nf;
5131 + if (old_pkg == NULL) {
5135 + old_files = pkg_get_installed_files(old_pkg);
5136 + new_files = pkg_get_installed_files(pkg);
5138 + for (of = old_files->head; of; of = of->next) {
5142 + for (nf = new_files->head; nf; nf = nf->next) {
5144 + if (strcmp(old, new) == 0) {
5145 + goto NOT_OBSOLETE;
5148 + if (file_is_dir(old)) {
5151 + owner = file_hash_get_file_owner(conf, old);
5152 + if (owner != old_pkg) {
5153 + /* in case obsolete file no longer belongs to old_pkg */
5157 + /* old file is obsolete */
5158 + ipkg_message(conf, IPKG_INFO,
5159 + " removing obsolete file %s\n", old);
5160 + if (!conf->noaction) {
5161 + err = unlink(old);
5163 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5172 + pkg_free_installed_files(old_pkg);
5173 + pkg_free_installed_files(pkg);
5178 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5182 + char *globpattern;
5186 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5189 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5190 + err = glob(globpattern, 0, NULL, &globbuf);
5191 + free(globpattern);
5195 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5196 + for (i = 0; i < globbuf.gl_pathc; i++) {
5197 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5198 + globbuf.gl_pathv[i], old_pkg->name);
5199 + if (!conf->noaction)
5200 + unlink(globbuf.gl_pathv[i]);
5202 + globfree(&globbuf);
5207 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5213 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5214 + sprintf_alloc(&prefix, "%s.", pkg->name);
5215 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5216 + pkg->dest->info_dir,
5222 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5224 + /* DPKG_INCOMPATIBILITY:
5225 + This is a fairly sophisticated dpkg operation. Shall we
5228 + /* Any packages all of whose files have been overwritten during the
5229 + installation, and which aren't required for dependencies, are
5230 + considered to have been removed. For each such package
5231 + 1. disappearer's-postrm disappear overwriter overwriter-version
5232 + 2. The package's maintainer scripts are removed
5233 + 3. It is noted in the status database as being in a sane state,
5234 + namely not installed (any conffiles it may have are ignored,
5235 + rather than being removed by dpkg). Note that disappearing
5236 + packages do not have their prerm called, because dpkg doesn't
5237 + know in advance that the package is going to vanish.
5242 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5246 + /* ipkg takes a slightly different approach to data file backups
5247 + than dpkg. Rather than removing backups at this point, we
5248 + actually do the data file installation now. See comments in
5249 + check_data_file_clashes() for more details. */
5251 + ipkg_message(conf, IPKG_INFO,
5252 + " extracting data files to %s\n", pkg->dest->root_dir);
5253 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5258 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5259 + so we can't save ourself from removing important packages
5260 + At this point we (should) have extracted the .control file, so it
5261 + would be a good idea to reload the data in it, and set the Essential
5262 + state in *pkg. From now on the Essential is back in status file and
5263 + we can protect again.
5264 + We should operate this way:
5265 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5266 + check for "Essential" in it
5267 + set the value in pkg->essential.
5268 + This new routine could be useful also for every other flag
5269 + Pigi: 16/03/2004 */
5270 + set_flags_from_control(conf, pkg) ;
5272 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5273 + err = pkg_write_filelist(conf, pkg);
5277 + /* XXX: FEATURE: ipkg should identify any files which existed
5278 + before installation and which were overwritten, (see
5279 + check_data_file_clashes()). What it must do is remove any such
5280 + files from the filelist of the old package which provided the
5281 + file. Otherwise, if the old package were removed at some point
5282 + it would break the new package. Removing the new package will
5283 + also break the old one, but this cannot be helped since the old
5284 + package's file has already been deleted. This is the importance
5285 + of check_data_file_clashes(), and only allowing ipkg to install
5286 + a clashing package with a user force. */
5291 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5293 + conffile_list_elt_t *iter;
5300 + if (conf->noaction) return 0;
5302 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5303 + char *root_filename;
5305 + root_filename = root_filename_alloc(conf, cf->name);
5307 + /* Might need to initialize the md5sum for each conffile */
5308 + if (cf->value == NULL) {
5309 + cf->value = file_md5sum_alloc(root_filename);
5312 + if (!file_exists(root_filename)) {
5313 + free(root_filename);
5317 + cf_backup = backup_filename_alloc(root_filename);
5320 + if (file_exists(cf_backup)) {
5321 + /* Let's compute md5 to test if files are changed */
5322 + md5sum = file_md5sum_alloc(cf_backup);
5323 + if (strcmp( cf->value,md5sum) != 0 ) {
5324 + if (conf->force_defaults
5325 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5326 + rename(cf_backup, root_filename);
5329 + unlink(cf_backup);
5334 + free(root_filename);
5340 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5343 + const char *short_file_name;
5345 + short_file_name = strrchr(file_name, '/');
5346 + if (short_file_name) {
5347 + short_file_name++;
5349 + short_file_name = file_name;
5353 + response = get_user_response(" Configuration file '%s'\n"
5354 + " ==> File on system created by you or by a script.\n"
5355 + " ==> File also in package provided by package maintainer.\n"
5356 + " What would you like to do about it ? Your options are:\n"
5357 + " Y or I : install the package maintainer's version\n"
5358 + " N or O : keep your currently-installed version\n"
5359 + " D : show the differences between the versions (if diff is installed)\n"
5360 + " The default action is to keep your current version.\n"
5361 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5362 + if (strcmp(response, "y") == 0
5363 + || strcmp(response, "i") == 0
5364 + || strcmp(response, "yes") == 0) {
5369 + if (strcmp(response, "d") == 0) {
5373 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5374 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5377 + printf(" [Press ENTER to continue]\n");
5378 + response = file_read_line_alloc(stdin);
5388 +/* XXX: CLEANUP: I'd like to move all of the code for
5389 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5390 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5391 + pkg_deinit for example). */
5392 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5395 + struct dirent *dirent;
5398 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5400 + ipkg_message(conf, IPKG_DEBUG,
5401 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5402 + __FUNCTION__, pkg->tmp_unpack_dir);
5406 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5407 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5410 + dirent = readdir(tmp_dir);
5411 + if (dirent == NULL) {
5414 + sprintf_alloc(&tmp_file, "%s/%s",
5415 + pkg->tmp_unpack_dir, dirent->d_name);
5416 + if (! file_is_dir(tmp_file)) {
5421 + closedir(tmp_dir);
5422 + rmdir(pkg->tmp_unpack_dir);
5423 + free(pkg->tmp_unpack_dir);
5424 + pkg->tmp_unpack_dir = NULL;
5428 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5429 + pkg->name, pkg->local_filename, conf->tmp_dir);
5430 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5431 + unlink(pkg->local_filename);
5432 + free(pkg->local_filename);
5433 + pkg->local_filename = NULL;
5439 +static char *backup_filename_alloc(const char *file_name)
5443 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5448 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5453 + backup = backup_filename_alloc(file_name);
5454 + err = file_copy(file_name, backup);
5456 + ipkg_message(conf, IPKG_ERROR,
5457 + "%s: Failed to copy %s to %s\n",
5458 + __FUNCTION__, file_name, backup);
5466 +static int backup_exists_for(const char *file_name)
5471 + backup = backup_filename_alloc(file_name);
5473 + ret = file_exists(backup);
5480 +static int backup_remove(const char *file_name)
5484 + backup = backup_filename_alloc(file_name);
5493 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5495 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5497 + /* first, remove the packages that need removing */
5498 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5499 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5500 + err = ipkg_remove_pkg(conf, pkg,0);
5501 + if (err) return err;
5506 +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)
5509 + /* now one more pass checking on the ones that need to be installed */
5510 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5511 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5512 + if (pkg->dest == NULL)
5513 + pkg->dest = conf->default_dest;
5515 + pkg->state_want = SW_INSTALL;
5517 + /* Abhaya: conflicts check */
5518 + err = check_conflicts_for(conf, pkg);
5519 + if (err) { return err; }
5524 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5527 + /* now one more pass checking on the ones that need to be installed */
5528 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5529 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5531 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5532 + pkg_vec_t *replacees = pkg_vec_alloc();
5533 + pkg_get_installed_replacees(conf, pkg, replacees);
5535 + /* XXX: BUG: we really should treat replacement more like an upgrade
5536 + * Instead, we're going to remove the replacees
5538 + err = pkg_remove_installed_replacees(conf, replacees);
5539 + if (err) return err;
5540 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5545 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5548 + /* now one more pass checking on the ones that need to be installed */
5549 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5550 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5551 + if (pkg->local_filename == NULL) {
5552 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5554 + ipkg_message(conf, IPKG_ERROR,
5555 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5560 + if (pkg->tmp_unpack_dir == NULL) {
5561 + err = unpack_pkg_control_files(conf, pkg);
5562 + if (err) return err;
5568 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5571 + /* now one more pass checking on the ones that need to be installed */
5572 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5573 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5574 + pkg_t *old_pkg = pkg->old_pkg;
5576 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5577 + if (err) return err;
5579 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5580 + if (err) return err;
5582 + err = preinst_configure(conf, pkg, old_pkg);
5583 + if (err) return err;
5585 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5586 + if (err) return err;
5588 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5589 + if (err) return err;
5594 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5597 + /* now one more pass checking on the ones that need to be installed */
5598 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5599 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5600 + pkg_t *old_pkg = pkg->old_pkg;
5603 + old_pkg->state_want = SW_DEINSTALL;
5605 + if (old_pkg->state_flag & SF_NOPRUNE) {
5606 + ipkg_message(conf, IPKG_INFO,
5607 + " not removing obsolesced files because package marked noprune\n");
5609 + ipkg_message(conf, IPKG_INFO,
5610 + " removing obsolesced files\n");
5611 + remove_obsolesced_files(conf, pkg, old_pkg);
5615 + ipkg_message(conf, IPKG_INFO,
5616 + " installing maintainer scripts\n");
5617 + install_maintainer_scripts(conf, pkg, old_pkg);
5619 + /* the following just returns 0 */
5620 + remove_disappeared(conf, pkg);
5622 + ipkg_message(conf, IPKG_INFO,
5623 + " installing data files\n");
5624 + install_data_files(conf, pkg);
5626 + ipkg_message(conf, IPKG_INFO,
5627 + " resolving conf files\n");
5628 + resolve_conffiles(conf, pkg);
5630 + pkg->state_status = SS_UNPACKED;
5633 + old_pkg->state_status = SS_NOT_INSTALLED;
5636 + time(&pkg->installed_time);
5638 + ipkg_message(conf, IPKG_INFO,
5639 + " cleanup temp files\n");
5640 + cleanup_temporary_files(conf, pkg);
5643 + pkg->parent->state_status = pkg->state_status;
5648 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5651 + /* now one more pass checking on the ones that need to be installed */
5652 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5653 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5654 + pkg_t *old_pkg = pkg->old_pkg;
5657 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5658 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5659 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5660 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5661 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5662 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5663 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5664 + preinst_configure_unwind(conf, pkg, old_pkg);
5665 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5666 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5667 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5668 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5670 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5671 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5679 + * Perform all the actions.
5681 + * pkgs_to_remove are packages marked for removal.
5682 + * pkgs_superseded are the old packages being replaced by upgrades.
5684 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5686 +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)
5691 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5692 + if (err) return err;
5694 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5695 + if (err) return err;
5697 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5698 + if (err) goto UNWIND;
5700 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5701 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5702 + if (err) goto UNWIND;
5705 + * Now that we have the packages unpacked, we can look for data
5706 + * file clashes. First, we mark the files from the superseded
5707 + * packages as obsolete. Then we scan the files in
5708 + * pkgs_to_install, and only complain about clashes with
5709 + * non-obsolete files.
5712 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5713 + if (err) goto UNWIND;
5715 + /* this was before checking data file clashes */
5716 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5717 + if (err) goto UNWIND;
5719 + /* point of no return: no unwinding after this */
5720 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5721 + if (err) return err;
5723 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5727 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5729 + ipkg_message(conf, IPKG_INFO,
5730 + " cleanup temp files\n");
5731 + cleanup_temporary_files(conf, pkg);
5733 + ipkg_message(conf, IPKG_INFO,
5739 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
5740 --- busybox-1.2.0-orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
5741 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_install.h 2006-07-22 16:31:25.000000000 +0200
5743 +/* ipkg_install.h - the itsy package management system
5747 + Copyright (C) 2001 University of Southern California
5749 + This program is free software; you can redistribute it and/or
5750 + modify it under the terms of the GNU General Public License as
5751 + published by the Free Software Foundation; either version 2, or (at
5752 + your option) any later version.
5754 + This program is distributed in the hope that it will be useful, but
5755 + WITHOUT ANY WARRANTY; without even the implied warranty of
5756 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5757 + General Public License for more details.
5760 +#ifndef IPKG_INSTALL_H
5761 +#define IPKG_INSTALL_H
5764 +#include "ipkg_conf.h"
5766 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5767 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5768 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5769 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5770 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5772 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5774 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5775 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5778 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
5779 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
5780 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.c 2006-07-22 16:31:25.000000000 +0200
5782 +/* ipkg_message.c - the itsy package management system
5784 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5786 + This program is free software; you can redistribute it and/or
5787 + modify it under the terms of the GNU General Public License as
5788 + published by the Free Software Foundation; either version 2, or (at
5789 + your option) any later version.
5791 + This program is distributed in the hope that it will be useful, but
5792 + WITHOUT ANY WARRANTY; without even the implied warranty of
5793 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5794 + General Public License for more details.
5799 +#include "ipkg_conf.h"
5800 +#include "ipkg_message.h"
5805 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5809 + if (conf && (conf->verbosity < level))
5816 + va_start (ap, fmt);
5817 + vprintf (fmt, ap);
5824 +#include "libipkg.h"
5826 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5829 +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
5834 + if (ipkg_cb_message)
5836 + va_start (ap, fmt);
5837 + vsnprintf (ts,256,fmt, ap);
5839 + ipkg_cb_message(conf,level,ts);
5843 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
5844 --- busybox-1.2.0-orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
5845 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_message.h 2006-07-22 16:31:25.000000000 +0200
5847 +/* ipkg_message.h - the itsy package management system
5849 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5851 + This program is free software; you can redistribute it and/or
5852 + modify it under the terms of the GNU General Public License as
5853 + published by the Free Software Foundation; either version 2, or (at
5854 + your option) any later version.
5856 + This program is distributed in the hope that it will be useful, but
5857 + WITHOUT ANY WARRANTY; without even the implied warranty of
5858 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5859 + General Public License for more details.
5862 +#ifndef _IPKG_MESSAGE_H_
5863 +#define _IPKG_MESSAGE_H_
5866 +#include "ipkg_conf.h"
5869 + IPKG_ERROR, /* error conditions */
5870 + IPKG_NOTICE, /* normal but significant condition */
5871 + IPKG_INFO, /* informational message */
5872 + IPKG_DEBUG, /* debug level message */
5873 + IPKG_DEBUG2, /* more debug level message */
5876 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...);
5878 +#endif /* _IPKG_MESSAGE_H_ */
5879 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
5880 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
5881 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.c 2006-07-22 16:31:25.000000000 +0200
5883 +/* ipkg_remove.c - the itsy package management system
5887 + Copyright (C) 2001 University of Southern California
5889 + This program is free software; you can redistribute it and/or
5890 + modify it under the terms of the GNU General Public License as
5891 + published by the Free Software Foundation; either version 2, or (at
5892 + your option) any later version.
5894 + This program is distributed in the hope that it will be useful, but
5895 + WITHOUT ANY WARRANTY; without even the implied warranty of
5896 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5897 + General Public License for more details.
5901 +#include "ipkg_message.h"
5905 +#include "ipkg_remove.h"
5907 +#include "file_util.h"
5908 +#include "sprintf_alloc.h"
5909 +#include "str_util.h"
5911 +#include "ipkg_cmd.h"
5914 + * Returns number of the number of packages depending on the packages provided by this package.
5915 + * Every package implicitly provides itself.
5917 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5919 + int nprovides = pkg->provides_count;
5920 + abstract_pkg_t **provides = pkg->provides;
5921 + int n_installed_dependents = 0;
5923 + for (i = 0; i <= nprovides; i++) {
5924 + abstract_pkg_t *providee = provides[i];
5925 + abstract_pkg_t **dependers = providee->depended_upon_by;
5926 + abstract_pkg_t *dep_ab_pkg;
5927 + if (dependers == NULL)
5929 + while ((dep_ab_pkg = *dependers++) != NULL) {
5930 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5931 + n_installed_dependents++;
5936 + /* if caller requested the set of installed dependents */
5937 + if (pdependents) {
5939 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5941 + if ( dependents == NULL ){
5942 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5946 + *pdependents = dependents;
5947 + for (i = 0; i <= nprovides; i++) {
5948 + abstract_pkg_t *providee = provides[i];
5949 + abstract_pkg_t **dependers = providee->depended_upon_by;
5950 + abstract_pkg_t *dep_ab_pkg;
5951 + if (dependers == NULL)
5953 + while ((dep_ab_pkg = *dependers++) != NULL) {
5954 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5955 + dependents[p++] = dep_ab_pkg;
5956 + dep_ab_pkg->state_flag |= SF_MARKED;
5960 + dependents[p] = NULL;
5961 + /* now clear the marks */
5962 + for (i = 0; i < p; i++) {
5963 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5964 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5967 + return n_installed_dependents;
5970 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5975 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5976 + abstract_pkg_t * ab_pkg;
5978 + if((ab_pkg = pkg->parent) == NULL){
5979 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5980 + __FUNCTION__, pkg->name);
5984 + if (dependents == NULL)
5987 + // here i am using the dependencies_checked
5988 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5989 + return 0; // has already been encountered in the process
5990 + // of marking packages for removal - Karthik
5991 + ab_pkg->dependencies_checked = 2;
5995 + while (dependents [i] != NULL) {
5996 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5998 + if (dep_ab_pkg->dependencies_checked == 2){
6002 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
6003 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
6004 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
6005 + if (dep_pkg->state_status == SS_INSTALLED) {
6006 + pkg_vec_insert(dependent_pkgs, dep_pkg);
6012 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
6013 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
6020 + for (i = 0; i < dependent_pkgs->len; i++) {
6021 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
6028 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
6030 + abstract_pkg_t *dep_ab_pkg;
6031 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
6032 + while ((dep_ab_pkg = *dependents++) != NULL) {
6033 + if (dep_ab_pkg->state_status == SS_INSTALLED)
6034 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
6036 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
6037 + ipkg_message(conf, IPKG_ERROR, "");
6038 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
6039 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
6040 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
6041 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
6042 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
6046 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
6048 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
6049 + thus I wan't check for essential, as I'm upgrading.
6050 + I hope it won't break anything :)
6053 + abstract_pkg_t *parent_pkg = NULL;
6055 + if (pkg->essential && !message) {
6056 + if (conf->force_removal_of_essential_packages) {
6057 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
6058 + "\tIf your system breaks, you get to keep both pieces\n",
6061 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
6062 + "\tRemoving an essential package may lead to an unusable system, but if\n"
6063 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
6064 + "\tits will with the option: -force-removal-of-essential-packages\n",
6066 + return IPKG_PKG_IS_ESSENTIAL;
6070 + if ((parent_pkg = pkg->parent) == NULL)
6073 + /* only attempt to remove dependent installed packages if
6074 + * force_depends is not specified or the package is being
6077 + if (!conf->force_depends
6078 + && !(pkg->state_flag & SF_REPLACE)) {
6079 + abstract_pkg_t **dependents;
6080 + int has_installed_dependents =
6081 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6083 + if (has_installed_dependents) {
6085 + * if this package is depended up by others, then either we should
6086 + * not remove it or we should remove it and all of its dependents
6089 + if (!conf->force_removal_of_dependent_packages
6090 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6091 + return IPKG_PKG_HAS_DEPENDENTS;
6094 + /* remove packages depending on this package - Karthik */
6095 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6097 + if (err) return err;
6101 + if ( message==0 ){
6102 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6105 + pkg->state_flag |= SF_FILELIST_CHANGED;
6107 + pkg->state_want = SW_DEINSTALL;
6108 + ipkg_state_changed++;
6110 + pkg_run_script(conf, pkg, "prerm", "remove");
6112 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6113 + maintains an empty filelist rather than deleting it. That seems
6114 + like a big pain, and I don't see that that should make a big
6115 + difference, but for anyone who wants tighter compatibility,
6116 + feel free to fix this. */
6117 + remove_data_files_and_list(conf, pkg);
6119 + pkg_run_script(conf, pkg, "postrm", "remove");
6121 + remove_maintainer_scripts_except_postrm(conf, pkg);
6123 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6124 + * space, it doesn't make sense to leave extra configurations, files,
6125 + * and maintainer scripts left around. So, we make remove like purge,
6126 + * and take out all the crap :) */
6128 + remove_postrm(conf, pkg);
6129 + pkg->state_status = SS_NOT_INSTALLED;
6132 + parent_pkg->state_status = SS_NOT_INSTALLED;
6137 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6139 + ipkg_remove_pkg(conf, pkg,0);
6143 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6145 + str_list_t installed_dirs;
6146 + str_list_t *installed_files;
6147 + str_list_elt_t *iter;
6149 + conffile_t *conffile;
6150 + int removed_a_dir;
6153 + str_list_init(&installed_dirs);
6154 + installed_files = pkg_get_installed_files(pkg);
6156 + for (iter = installed_files->head; iter; iter = iter->next) {
6157 + file_name = iter->data;
6159 + if (file_is_dir(file_name)) {
6160 + str_list_append(&installed_dirs, strdup(file_name));
6164 + conffile = pkg_get_conffile(pkg, file_name);
6166 + /* XXX: QUESTION: Is this right? I figure we only need to
6167 + save the conffile if it has been modified. Is that what
6168 + dpkg does? Or does dpkg preserve all conffiles? If so,
6169 + this seems like a better thing to do to conserve
6171 + if (conffile_has_been_modified(conf, conffile)) {
6172 + printf(" not deleting modified conffile %s\n", file_name);
6178 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6179 + if (!conf->noaction)
6180 + unlink(file_name);
6183 + if (!conf->noaction) {
6185 + removed_a_dir = 0;
6186 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6187 + file_name = iter->data;
6189 + if (rmdir(file_name) == 0) {
6190 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6191 + removed_a_dir = 1;
6192 + str_list_remove(&installed_dirs, &iter);
6195 + } while (removed_a_dir);
6198 + pkg_free_installed_files(pkg);
6199 + /* We have to remove the file list now, so that
6200 + find_pkg_owning_file does not always just report this package */
6201 + pkg_remove_installed_files_list(conf, pkg);
6203 + /* Don't print warning for dirs that are provided by other packages */
6204 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6205 + file_name = iter->data;
6207 + owner = file_hash_get_file_owner(conf, file_name);
6210 + iter->data = NULL;
6211 + str_list_remove(&installed_dirs, &iter);
6216 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6218 + iter->data = NULL;
6220 + str_list_deinit(&installed_dirs);
6225 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6228 + char *globpattern;
6231 + if (conf->noaction) return 0;
6233 + sprintf_alloc(&globpattern, "%s/%s.*",
6234 + pkg->dest->info_dir, pkg->name);
6235 + err = glob(globpattern, 0, NULL, &globbuf);
6236 + free(globpattern);
6241 + for (i = 0; i < globbuf.gl_pathc; i++) {
6242 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6245 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6246 + unlink(globbuf.gl_pathv[i]);
6248 + globfree(&globbuf);
6253 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6255 + char *postrm_file_name;
6257 + if (conf->noaction) return 0;
6259 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6260 + pkg->dest->info_dir, pkg->name);
6261 + unlink(postrm_file_name);
6262 + free(postrm_file_name);
6266 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
6267 --- busybox-1.2.0-orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
6268 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_remove.h 2006-07-22 16:31:25.000000000 +0200
6270 +/* ipkg_remove.h - the itsy package management system
6274 + Copyright (C) 2001 University of Southern California
6276 + This program is free software; you can redistribute it and/or
6277 + modify it under the terms of the GNU General Public License as
6278 + published by the Free Software Foundation; either version 2, or (at
6279 + your option) any later version.
6281 + This program is distributed in the hope that it will be useful, but
6282 + WITHOUT ANY WARRANTY; without even the implied warranty of
6283 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6284 + General Public License for more details.
6287 +#ifndef IPKG_REMOVE_H
6288 +#define IPKG_REMOVE_H
6291 +#include "ipkg_conf.h"
6293 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6294 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6295 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6296 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6297 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6298 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6299 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6303 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
6304 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
6305 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.c 2006-07-22 16:31:25.000000000 +0200
6307 +/* ipkg_upgrade.c - the itsy package management system
6310 + Copyright (C) 2001 University of Southern California
6312 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6314 + This program is free software; you can redistribute it and/or
6315 + modify it under the terms of the GNU General Public License as
6316 + published by the Free Software Foundation; either version 2, or (at
6317 + your option) any later version.
6319 + This program is distributed in the hope that it will be useful, but
6320 + WITHOUT ANY WARRANTY; without even the implied warranty of
6321 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6322 + General Public License for more details.
6326 +#include "ipkg_install.h"
6327 +#include "ipkg_message.h"
6329 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6333 + char *old_version, *new_version;
6335 + if (old->state_flag & SF_HOLD) {
6336 + ipkg_message(conf, IPKG_NOTICE,
6337 + "Not upgrading package %s which is marked "
6338 + "hold (flags=%#x)\n", old->name, old->state_flag);
6342 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6343 + if (new == NULL) {
6344 + old_version = pkg_version_str_alloc(old);
6345 + ipkg_message(conf, IPKG_NOTICE,
6346 + "Assuming locally installed package %s (%s) "
6347 + "is up to date.\n", old->name, old_version);
6348 + free(old_version);
6352 + old_version = pkg_version_str_alloc(old);
6353 + new_version = pkg_version_str_alloc(new);
6355 + cmp = pkg_compare_versions(old, new);
6356 + ipkg_message(conf, IPKG_DEBUG,
6357 + "comparing visible versions of pkg %s:"
6358 + "\n\t%s is installed "
6359 + "\n\t%s is available "
6360 + "\n\t%d was comparison result\n",
6361 + old->name, old_version, new_version, cmp);
6363 + ipkg_message(conf, IPKG_INFO,
6364 + "Package %s (%s) installed in %s is up to date.\n",
6365 + old->name, old_version, old->dest->name);
6366 + free(old_version);
6367 + free(new_version);
6369 + } else if (cmp > 0) {
6370 + ipkg_message(conf, IPKG_NOTICE,
6371 + "Not downgrading package %s on %s from %s to %s.\n",
6372 + old->name, old->dest->name, old_version, new_version);
6373 + free(old_version);
6374 + free(new_version);
6376 + } else if (cmp < 0) {
6377 + new->dest = old->dest;
6378 + old->state_want = SW_DEINSTALL;
6381 + new->state_flag |= SF_USER;
6382 + return ipkg_install_pkg(conf, new,1);
6384 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
6385 --- busybox-1.2.0-orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
6386 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_upgrade.h 2006-07-22 16:31:25.000000000 +0200
6388 +/* ipkg_upgrade.c - the itsy package management system
6390 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6392 + This program is free software; you can redistribute it and/or
6393 + modify it under the terms of the GNU General Public License as
6394 + published by the Free Software Foundation; either version 2, or (at
6395 + your option) any later version.
6397 + This program is distributed in the hope that it will be useful, but
6398 + WITHOUT ANY WARRANTY; without even the implied warranty of
6399 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6400 + General Public License for more details.
6405 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6406 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
6407 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
6408 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.c 2006-07-22 16:31:25.000000000 +0200
6410 +/* ipkg_utils.c - the itsy package management system
6414 + Copyright (C) 2002 Compaq Computer Corporation
6416 + This program is free software; you can redistribute it and/or
6417 + modify it under the terms of the GNU General Public License as
6418 + published by the Free Software Foundation; either version 2, or (at
6419 + your option) any later version.
6421 + This program is distributed in the hope that it will be useful, but
6422 + WITHOUT ANY WARRANTY; without even the implied warranty of
6423 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6424 + General Public License for more details.
6430 +#include <sys/vfs.h>
6432 +#include "ipkg_utils.h"
6434 +#include "pkg_hash.h"
6436 +struct errlist* error_list;
6438 +int get_available_blocks(char * filesystem)
6440 + struct statfs sfs;
6442 + if(statfs(filesystem, &sfs)){
6443 + fprintf(stderr, "bad statfs\n");
6446 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6447 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6450 +char **read_raw_pkgs_from_file(const char *file_name)
6455 + if(!(fp = fopen(file_name, "r"))){
6456 + fprintf(stderr, "can't get %s open for read\n", file_name);
6460 + ret = read_raw_pkgs_from_stream(fp);
6467 +char **read_raw_pkgs_from_stream(FILE *fp)
6469 + char **raw = NULL, *buf, *scout;
6471 + size_t size = 512;
6473 + buf = malloc (size);
6475 + while (fgets(buf, size, fp)) {
6476 + while (strlen (buf) == (size - 1)
6477 + && buf[size-2] != '\n') {
6478 + size_t o = size - 1;
6480 + buf = realloc (buf, size);
6481 + if (fgets (buf + o, size - o, fp) == NULL)
6486 + raw = realloc(raw, (count + 50) * sizeof(char *));
6488 + if((scout = strchr(buf, '\n')))
6491 + raw[count++] = strdup(buf);
6494 + raw = realloc(raw, (count + 1) * sizeof(char *));
6495 + raw[count] = NULL;
6502 +/* something to remove whitespace, a hash pooper */
6503 +char *trim_alloc(char *line)
6506 + char *dest, *src, *end;
6508 + new = malloc(strlen(line) + 1);
6509 + if ( new == NULL ){
6510 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6513 + dest = new, src = line, end = line + (strlen(line) - 1);
6515 + /* remove it from the front */
6520 + /* and now from the back */
6521 + while((end > src) &&
6527 + /* this does from the first space
6528 + * blasting away any versions stuff in depends
6539 +int line_is_blank(const char *line)
6543 + for (s = line; *s; s++) {
6550 +void push_error_list(struct errlist ** errors, char * msg){
6551 + struct errlist *err_lst_tmp;
6554 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6555 + err_lst_tmp->errmsg=strdup(msg) ;
6556 + err_lst_tmp->next = *errors;
6557 + *errors = err_lst_tmp;
6561 +void reverse_error_list(struct errlist **errors){
6562 + struct errlist *result=NULL;
6563 + struct errlist *current= *errors;
6564 + struct errlist *next;
6566 + while ( current != NULL ) {
6567 + next = current->next;
6568 + current->next=result;
6577 +void free_error_list(struct errlist **errors){
6578 + struct errlist *current = *errors;
6580 + while (current != NULL) {
6581 + free(current->errmsg);
6582 + current = (*errors)->next;
6584 + *errors = current;
6591 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
6592 --- busybox-1.2.0-orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
6593 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/ipkg_utils.h 2006-07-22 16:31:25.000000000 +0200
6595 +/* ipkg_utils.h - the itsy package management system
6599 + Copyright (C) 2002 Compaq Computer Corporation
6601 + This program is free software; you can redistribute it and/or
6602 + modify it under the terms of the GNU General Public License as
6603 + published by the Free Software Foundation; either version 2, or (at
6604 + your option) any later version.
6606 + This program is distributed in the hope that it will be useful, but
6607 + WITHOUT ANY WARRANTY; without even the implied warranty of
6608 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6609 + General Public License for more details.
6612 +#ifndef IPKG_UTILS_H
6613 +#define IPKG_UTILS_H
6617 +int get_available_blocks(char * filesystem);
6618 +char **read_raw_pkgs_from_file(const char *file_name);
6619 +char **read_raw_pkgs_from_stream(FILE *fp);
6620 +char *trim_alloc(char * line);
6621 +int line_is_blank(const char *line);
6624 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c
6625 --- busybox-1.2.0-orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
6626 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.c 2006-07-22 16:31:25.000000000 +0200
6628 +/* ipkglib.c - the itsy package management system
6632 + Copyright (C) 2003 kernel concepts
6634 + This program is free software; you can redistribute it and/or
6635 + modify it under the terms of the GNU General Public License as
6636 + published by the Free Software Foundation; either version 2, or (at
6637 + your option) any later version.
6639 + This program is distributed in the hope that it will be useful, but
6640 + WITHOUT ANY WARRANTY; without even the implied warranty of
6641 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6642 + General Public License for more details.
6648 +#include "ipkg_includes.h"
6649 +#include "libipkg.h"
6652 +#include "ipkg_conf.h"
6653 +#include "ipkg_cmd.h"
6654 +#include "file_util.h"
6658 +ipkg_message_callback ipkg_cb_message = NULL;
6659 +ipkg_response_callback ipkg_cb_response = NULL;
6660 +ipkg_status_callback ipkg_cb_status = NULL;
6661 +ipkg_list_callback ipkg_cb_list = NULL;
6665 +ipkg_init (ipkg_message_callback mcall,
6666 + ipkg_response_callback rcall,
6669 + ipkg_cb_message = mcall;
6670 + ipkg_cb_response = rcall;
6679 +ipkg_deinit (args_t * args)
6681 + args_deinit (args);
6682 + ipkg_cb_message = NULL;
6683 + ipkg_cb_response = NULL;
6685 + /* place other cleanup stuff here */
6692 +ipkg_packages_list(args_t *args,
6693 + const char *packages,
6694 + ipkg_list_callback cblist,
6698 + ipkg_conf_t ipkg_conf;
6701 + err = ipkg_conf_init (&ipkg_conf, args);
6707 + ipkg_cb_list = cblist;
6708 + /* we need to do this because of static declarations,
6709 + * maybe a good idea to change */
6710 + cmd = ipkg_cmd_find ("list");
6712 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6714 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6715 + ipkg_cb_list = NULL;
6716 + ipkg_conf_deinit (&ipkg_conf);
6722 +ipkg_packages_status(args_t *args,
6723 + const char *packages,
6724 + ipkg_status_callback cbstatus,
6728 + ipkg_conf_t ipkg_conf;
6731 + err = ipkg_conf_init (&ipkg_conf, args);
6737 + ipkg_cb_status = cbstatus;
6739 + /* we need to do this because of static declarations,
6740 + * maybe a good idea to change */
6741 + cmd = ipkg_cmd_find ("status");
6743 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6745 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6747 + ipkg_cb_status = NULL;
6748 + ipkg_conf_deinit (&ipkg_conf);
6754 +ipkg_packages_info(args_t *args,
6755 + const char *packages,
6756 + ipkg_status_callback cbstatus,
6760 + ipkg_conf_t ipkg_conf;
6763 + err = ipkg_conf_init (&ipkg_conf, args);
6769 + ipkg_cb_status = cbstatus;
6771 + /* we need to do this because of static declarations,
6772 + * maybe a good idea to change */
6773 + cmd = ipkg_cmd_find ("info");
6775 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6777 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6779 + ipkg_cb_status = NULL;
6780 + ipkg_conf_deinit (&ipkg_conf);
6786 +ipkg_packages_install (args_t * args, const char *name)
6789 + ipkg_conf_t ipkg_conf;
6792 + /* this error should be handled in application */
6793 + if (!name || !strlen (name))
6796 + err = ipkg_conf_init (&ipkg_conf, args);
6802 + /* we need to do this because of static declarations,
6803 + * maybe a good idea to change */
6804 + cmd = ipkg_cmd_find ("install");
6805 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6807 + ipkg_conf_deinit(&ipkg_conf);
6813 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6816 + ipkg_conf_t ipkg_conf;
6819 + /* this error should be handled in application */
6820 + if (!name || !strlen (name))
6823 + err = ipkg_conf_init (&ipkg_conf, args);
6829 + /* we need to do this because of static declarations,
6830 + * maybe a good idea to change */
6832 + cmd = ipkg_cmd_find ("purge");
6834 + cmd = ipkg_cmd_find ("remove");
6836 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6838 + ipkg_conf_deinit(&ipkg_conf);
6844 +ipkg_lists_update(args_t *args)
6847 + ipkg_conf_t ipkg_conf;
6850 + err = ipkg_conf_init (&ipkg_conf, args);
6856 + /* we need to do this because of static declarations,
6857 + * maybe a good idea to change */
6858 + cmd = ipkg_cmd_find ("update");
6860 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6862 + ipkg_conf_deinit(&ipkg_conf);
6868 +ipkg_packages_upgrade(args_t *args)
6871 + ipkg_conf_t ipkg_conf;
6874 + err = ipkg_conf_init (&ipkg_conf, args);
6880 + /* we need to do this because of static declarations,
6881 + * maybe a good idea to change */
6882 + cmd = ipkg_cmd_find ("upgrade");
6884 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6886 + ipkg_conf_deinit(&ipkg_conf);
6892 +ipkg_packages_download (args_t * args, const char *name)
6895 + ipkg_conf_t ipkg_conf;
6898 + /* this error should be handled in application */
6899 + if (!name || !strlen (name))
6902 + err = ipkg_conf_init (&ipkg_conf, args);
6908 + /* we need to do this because of static declarations,
6909 + * maybe a good idea to change */
6910 + cmd = ipkg_cmd_find ("download");
6911 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6913 + ipkg_conf_deinit(&ipkg_conf);
6919 +ipkg_package_files(args_t *args,
6921 + ipkg_list_callback cblist,
6925 + ipkg_conf_t ipkg_conf;
6928 + /* this error should be handled in application */
6929 + if (!name || !strlen (name))
6932 + err = ipkg_conf_init (&ipkg_conf, args);
6938 + ipkg_cb_list = cblist;
6940 + /* we need to do this because of static declarations,
6941 + * maybe a good idea to change */
6942 + cmd = ipkg_cmd_find ("files");
6944 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6946 + ipkg_cb_list = NULL;
6947 + ipkg_conf_deinit(&ipkg_conf);
6953 +ipkg_file_search(args_t *args,
6955 + ipkg_list_callback cblist,
6959 + ipkg_conf_t ipkg_conf;
6962 + /* this error should be handled in application */
6963 + if (!file || !strlen (file))
6966 + err = ipkg_conf_init (&ipkg_conf, args);
6972 + ipkg_cb_list = cblist;
6974 + /* we need to do this because of static declarations,
6975 + * maybe a good idea to change */
6976 + cmd = ipkg_cmd_find ("search");
6977 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6979 + ipkg_cb_list = NULL;
6980 + ipkg_conf_deinit(&ipkg_conf);
6986 +ipkg_file_what(args_t *args, const char *file, const char* command)
6989 + ipkg_conf_t ipkg_conf;
6992 + /* this error should be handled in application */
6993 + if (!file || !strlen (file))
6996 + err = ipkg_conf_init (&ipkg_conf, args);
7002 + /* we need to do this because of static declarations,
7003 + * maybe a good idea to change */
7004 + cmd = ipkg_cmd_find (command);
7005 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
7007 + ipkg_conf_deinit(&ipkg_conf);
7011 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7012 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7013 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7014 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7015 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7018 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7021 + if (conf && (conf->verbosity < level)) {
7025 + if ( level == IPKG_ERROR ){
7026 + push_error_list(&error_list, msg);
7035 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7036 + pkg_state_status_t status, void *userdata)
7039 + printf("%s - %s - %s\n", name, version, desc);
7041 + printf("%s - %s\n", name, version);
7045 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7046 + pkg_state_status_t status, void *userdata)
7049 + printf("%s\n", desc);
7053 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7056 + printf("%s\n", desc);
7060 +char* default_ipkg_response_callback(char *question)
7062 + char *response = NULL;
7066 + response = (char *)file_read_line_alloc(stdin);
7067 + } while (response == NULL);
7071 +/* This is used for backward compatibility */
7073 +ipkg_op (int argc, char *argv[])
7079 + ipkg_conf_t ipkg_conf;
7081 + args_init (&args);
7083 + optind = args_parse (&args, argc, argv);
7084 + if (optind == argc || optind < 0)
7086 + args_usage ("ipkg must have one sub-command argument");
7089 + cmd_name = argv[optind++];
7090 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7091 + read anything from there.
7093 + if ( !strcmp(cmd_name,"print-architecture") ||
7094 + !strcmp(cmd_name,"print_architecture") ||
7095 + !strcmp(cmd_name,"print-installation-architecture") ||
7096 + !strcmp(cmd_name,"print_installation_architecture") )
7097 + args.nocheckfordirorfile = 1;
7099 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7100 + read anything from there.
7102 + if ( !strcmp(cmd_name,"flag") ||
7103 + !strcmp(cmd_name,"configure") ||
7104 + !strcmp(cmd_name,"remove") ||
7105 + !strcmp(cmd_name,"files") ||
7106 + !strcmp(cmd_name,"search") ||
7107 + !strcmp(cmd_name,"compare_versions") ||
7108 + !strcmp(cmd_name,"compare-versions") ||
7109 + !strcmp(cmd_name,"list_installed") ||
7110 + !strcmp(cmd_name,"list-installed") ||
7111 + !strcmp(cmd_name,"status") )
7112 + args.noreadfeedsfile = 1;
7115 + err = ipkg_conf_init (&ipkg_conf, &args);
7121 + args_deinit (&args);
7123 + ipkg_cb_message = default_ipkg_message_callback;
7124 + ipkg_cb_response = default_ipkg_response_callback;
7125 + ipkg_cb_status = default_ipkg_status_callback;
7126 + if ( strcmp(cmd_name, "files")==0)
7127 + ipkg_cb_list = default_ipkg_files_callback;
7129 + ipkg_cb_list = default_ipkg_list_callback;
7131 + cmd = ipkg_cmd_find (cmd_name);
7134 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7136 + args_usage (NULL);
7139 + if (cmd->requires_args && optind == argc)
7142 + "%s: the ``%s'' command requires at least one argument\n",
7143 + __FUNCTION__, cmd_name);
7144 + args_usage (NULL);
7147 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind, (const char **) (argv + optind), NULL);
7149 + ipkg_conf_deinit (&ipkg_conf);
7154 +#endif /* IPKG_LIB */
7155 diff -ruN busybox-1.2.0-orig/archival/libipkg/libipkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h
7156 --- busybox-1.2.0-orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
7157 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/libipkg.h 2006-07-22 16:31:25.000000000 +0200
7159 +/* ipkglib.h - the itsy package management system
7161 + Florian Boor <florian.boor@kernelconcepts.de>
7163 + This program is free software; you can redistribute it and/or
7164 + modify it under the terms of the GNU General Public License as
7165 + published by the Free Software Foundation; either version 2, or (at
7166 + your option) any later version.
7168 + This program is distributed in the hope that it will be useful, but
7169 + WITHOUT ANY WARRANTY; without even the implied warranty of
7170 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7171 + General Public License for more details.
7179 +#include "ipkg_conf.h"
7180 +#include "ipkg_message.h"
7185 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7187 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7188 + pkg_state_status_t status, void *userdata);
7189 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7191 +typedef char* (*ipkg_response_callback)(char *question);
7193 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7194 +extern int ipkg_init (ipkg_message_callback mcall,
7195 + ipkg_response_callback rcall,
7198 +extern int ipkg_deinit (args_t *args);
7199 +extern int ipkg_packages_list(args_t *args,
7200 + const char *packages,
7201 + ipkg_list_callback cblist,
7203 +extern int ipkg_packages_status(args_t *args,
7204 + const char *packages,
7205 + ipkg_status_callback cbstatus,
7207 +extern int ipkg_packages_info(args_t *args,
7208 + const char *packages,
7209 + ipkg_status_callback cbstatus,
7211 +extern int ipkg_packages_install(args_t *args, const char *name);
7212 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7213 +extern int ipkg_lists_update(args_t *args);
7214 +extern int ipkg_packages_upgrade(args_t *args);
7215 +extern int ipkg_packages_download(args_t *args, const char *name);
7216 +extern int ipkg_package_files(args_t *args,
7218 + ipkg_list_callback cblist,
7220 +extern int ipkg_file_search(args_t *args,
7222 + ipkg_list_callback cblist,
7224 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7225 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7226 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7227 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7228 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7230 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7231 +extern ipkg_response_callback ipkg_cb_response;
7232 +extern ipkg_status_callback ipkg_cb_status;
7233 +extern ipkg_list_callback ipkg_cb_list;
7234 +extern void push_error_list(struct errlist **errors,char * msg);
7235 +extern void reverse_error_list(struct errlist **errors);
7236 +extern void free_error_list(struct errlist **errors);
7240 +extern int ipkg_op(int argc, char *argv[]);
7246 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile
7247 --- busybox-1.2.0-orig/archival/libipkg/Makefile 1970-01-01 01:00:00.000000000 +0100
7248 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile 2006-07-22 16:31:25.000000000 +0200
7250 +# Makefile for busybox
7252 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7254 +# This program is free software; you can redistribute it and/or modify
7255 +# it under the terms of the GNU General Public License as published by
7256 +# the Free Software Foundation; either version 2 of the License, or
7257 +# (at your option) any later version.
7259 +# This program is distributed in the hope that it will be useful,
7260 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7261 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7262 +# General Public License for more details.
7264 +# You should have received a copy of the GNU General Public License
7265 +# along with this program; if not, write to the Free Software
7266 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7271 +srcdir=$(top_srcdir)/archival/libipkg
7273 +include $(top_builddir)/Rules.mak
7274 +include $(top_builddir)/.config
7275 +include $(srcdir)/Makefile.in
7276 +all: $(libraries-y)
7277 +-include $(top_builddir)/.depend
7280 + rm -f *.o *.a $(AR_TARGET)
7282 diff -ruN busybox-1.2.0-orig/archival/libipkg/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in
7283 --- busybox-1.2.0-orig/archival/libipkg/Makefile.in 1970-01-01 01:00:00.000000000 +0100
7284 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/Makefile.in 2006-07-22 16:31:25.000000000 +0200
7286 +# Makefile for busybox
7288 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7290 +# This program is free software; you can redistribute it and/or modify
7291 +# it under the terms of the GNU General Public License as published by
7292 +# the Free Software Foundation; either version 2 of the License, or
7293 +# (at your option) any later version.
7295 +# This program is distributed in the hope that it will be useful,
7296 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7297 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7298 +# General Public License for more details.
7300 +# You should have received a copy of the GNU General Public License
7301 +# along with this program; if not, write to the Free Software
7302 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7305 +LIBIPKG_AR:=libipkg.a
7306 +ifndef $(LIBIPKG_DIR)
7307 +LIBIPKG_DIR:=$(top_builddir)/archival/libipkg/
7309 +srcdir=$(top_srcdir)/archival/libipkg
7311 +LIBIPKG_CORE_SOURCES:= \
7316 +LIBIPKG_CMD_SOURCES:= \
7318 + ipkg_configure.c \
7324 +LIBIPKG_DB_SOURCES:= \
7335 +LIBIPKG_LIST_SOURCES:= \
7347 +LIBIPKG_UTIL_SOURCES:= \
7354 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CORE_SOURCES)
7355 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_CMD_SOURCES)
7356 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_DB_SOURCES)
7357 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_LIST_SOURCES)
7358 +LIBIPKG-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_SOURCES)
7359 +LIBIPKG_OBJS=$(patsubst %.c,$(LIBIPKG_DIR)%.o, $(LIBIPKG-y))
7361 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(TARGET_ARCH)\""
7363 +libraries-$(CONFIG_IPKG) += $(LIBIPKG_DIR)$(LIBIPKG_AR)
7365 +$(LIBIPKG_DIR)$(LIBIPKG_AR): $(LIBIPKG_OBJS)
7368 +$(LIBIPKG_OBJS): $(LIBIPKG_DIR)%.o : $(srcdir)/%.c
7371 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c
7372 --- busybox-1.2.0-orig/archival/libipkg/md5.c 1970-01-01 01:00:00.000000000 +0100
7373 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.c 2006-07-22 16:31:25.000000000 +0200
7375 +/* md5.c - wrappers to busybox md5 functions
7377 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7379 + * This program is free software; you can redistribute it and/or modify
7380 + * it under the terms of the GNU General Public License as published by
7381 + * the Free Software Foundation; either version 2, or (at your option)
7382 + * any later version.
7384 + * This program is distributed in the hope that it will be useful,
7385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7387 + * GNU General Public License for more details.
7389 + * You should have received a copy of the GNU General Public License
7390 + * along with this program; if not, write to the Free Software Foundation,
7391 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7399 +int md5_stream(FILE *stream, void *resblock)
7404 + if( (fd = fileno(stream)) == -1 ) {
7405 + bb_error_msg("bad file descriptor");
7409 + hash_fd(fd, HASH_MD5, (uint8_t *)resblock);
7414 +void *md5_buffer(const char *buffer, size_t len, void *resblock)
7418 + md5_begin(&md5_cx);
7419 + md5_hash(buffer, len, &md5_cx);
7420 + return md5_end(resblock, &md5_cx);
7423 diff -ruN busybox-1.2.0-orig/archival/libipkg/md5.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h
7424 --- busybox-1.2.0-orig/archival/libipkg/md5.h 1970-01-01 01:00:00.000000000 +0100
7425 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/md5.h 2006-07-22 16:31:25.000000000 +0200
7427 +/* md5.h - Compute MD5 checksum of files or strings according to the
7428 + * definition of MD5 in RFC 1321 from April 1992.
7429 + * Copyright (C) 1995-1999 Free Software Foundation, Inc.
7431 + * This program is free software; you can redistribute it and/or modify
7432 + * it under the terms of the GNU General Public License as published by
7433 + * the Free Software Foundation; either version 2, or (at your option)
7434 + * any later version.
7436 + * This program is distributed in the hope that it will be useful,
7437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7439 + * GNU General Public License for more details.
7441 + * You should have received a copy of the GNU General Public License
7442 + * along with this program; if not, write to the Free Software Foundation,
7443 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7449 +/* Compute MD5 message digest for bytes read from STREAM. The
7450 + resulting message digest number will be written into the 16 bytes
7451 + beginning at RESBLOCK. */
7452 +int md5_stream(FILE *stream, void *resblock);
7454 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
7455 + result is always in little endian byte order, so that a byte-wise
7456 + output yields to the wanted ASCII representation of the message
7458 +void *md5_buffer(const char *buffer, size_t len, void *resblock);
7462 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
7463 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
7464 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.c 2006-07-22 16:31:25.000000000 +0200
7466 +/* nv_pair.c - the itsy package management system
7470 + Copyright (C) 2001 University of Southern California
7472 + This program is free software; you can redistribute it and/or
7473 + modify it under the terms of the GNU General Public License as
7474 + published by the Free Software Foundation; either version 2, or (at
7475 + your option) any later version.
7477 + This program is distributed in the hope that it will be useful, but
7478 + WITHOUT ANY WARRANTY; without even the implied warranty of
7479 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7480 + General Public License for more details.
7485 +#include "nv_pair.h"
7486 +#include "str_util.h"
7488 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7490 + nv_pair->name = str_dup_safe(name);
7491 + nv_pair->value = str_dup_safe(value);
7496 +void nv_pair_deinit(nv_pair_t *nv_pair)
7498 + free(nv_pair->name);
7499 + nv_pair->name = NULL;
7501 + free(nv_pair->value);
7502 + nv_pair->value = NULL;
7506 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
7507 --- busybox-1.2.0-orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
7508 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair.h 2006-07-22 16:31:25.000000000 +0200
7510 +/* nv_pair.h - the itsy package management system
7514 + Copyright (C) 2001 University of Southern California
7516 + This program is free software; you can redistribute it and/or
7517 + modify it under the terms of the GNU General Public License as
7518 + published by the Free Software Foundation; either version 2, or (at
7519 + your option) any later version.
7521 + This program is distributed in the hope that it will be useful, but
7522 + WITHOUT ANY WARRANTY; without even the implied warranty of
7523 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7524 + General Public License for more details.
7530 +typedef struct nv_pair nv_pair_t;
7537 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7538 +void nv_pair_deinit(nv_pair_t *nv_pair);
7542 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
7543 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
7544 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.c 2006-07-22 16:31:25.000000000 +0200
7546 +/* nv_pair_list.c - the itsy package management system
7550 + Copyright (C) 2001 University of Southern California
7552 + This program is free software; you can redistribute it and/or
7553 + modify it under the terms of the GNU General Public License as
7554 + published by the Free Software Foundation; either version 2, or (at
7555 + your option) any later version.
7557 + This program is distributed in the hope that it will be useful, but
7558 + WITHOUT ANY WARRANTY; without even the implied warranty of
7559 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7560 + General Public License for more details.
7565 +#include "nv_pair.h"
7566 +#include "void_list.h"
7567 +#include "nv_pair_list.h"
7569 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7571 + return void_list_elt_init((void_list_elt_t *) elt, data);
7574 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7576 + void_list_elt_deinit((void_list_elt_t *) elt);
7579 +int nv_pair_list_init(nv_pair_list_t *list)
7581 + return void_list_init((void_list_t *) list);
7584 +void nv_pair_list_deinit(nv_pair_list_t *list)
7586 + nv_pair_list_elt_t *iter;
7587 + nv_pair_t *nv_pair;
7589 + for (iter = list->head; iter; iter = iter->next) {
7590 + nv_pair = iter->data;
7591 + nv_pair_deinit(nv_pair);
7593 + /* malloced in nv_pair_list_append */
7595 + iter->data = NULL;
7597 + void_list_deinit((void_list_t *) list);
7600 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7604 + /* freed in nv_pair_list_deinit */
7605 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7607 + if (nv_pair == NULL) {
7608 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7611 + nv_pair_init(nv_pair, name, value);
7613 + err = void_list_append((void_list_t *) list, nv_pair);
7621 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7623 + return void_list_push((void_list_t *) list, data);
7626 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7628 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7631 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7633 + nv_pair_list_elt_t *iter;
7634 + nv_pair_t *nv_pair;
7636 + for (iter = list->head; iter; iter = iter->next) {
7637 + nv_pair = iter->data;
7638 + if (strcmp(nv_pair->name, name) == 0) {
7639 + return nv_pair->value;
7644 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
7645 --- busybox-1.2.0-orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
7646 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/nv_pair_list.h 2006-07-22 16:31:25.000000000 +0200
7648 +/* nv_pair_list.h - the itsy package management system
7652 + Copyright (C) 2001 University of Southern California
7654 + This program is free software; you can redistribute it and/or
7655 + modify it under the terms of the GNU General Public License as
7656 + published by the Free Software Foundation; either version 2, or (at
7657 + your option) any later version.
7659 + This program is distributed in the hope that it will be useful, but
7660 + WITHOUT ANY WARRANTY; without even the implied warranty of
7661 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7662 + General Public License for more details.
7665 +#ifndef NV_PAIR_LIST_H
7666 +#define NV_PAIR_LIST_H
7668 +#include "nv_pair.h"
7669 +#include "void_list.h"
7671 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7672 +struct nv_pair_list_elt
7674 + nv_pair_list_elt_t *next;
7678 +typedef struct nv_pair_list nv_pair_list_t;
7679 +struct nv_pair_list
7681 + nv_pair_list_elt_t pre_head;
7682 + nv_pair_list_elt_t *head;
7683 + nv_pair_list_elt_t *tail;
7686 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7688 + if (list->head == NULL)
7694 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7695 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7697 +int nv_pair_list_init(nv_pair_list_t *list);
7698 +void nv_pair_list_deinit(nv_pair_list_t *list);
7700 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7701 + const char *name, const char *value);
7702 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7703 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7704 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7708 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c
7709 --- busybox-1.2.0-orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
7710 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.c 2006-07-22 16:31:25.000000000 +0200
7712 +/* pkg.c - the itsy package management system
7716 + Copyright (C) 2001 University of Southern California
7718 + This program is free software; you can redistribute it and/or
7719 + modify it under the terms of the GNU General Public License as
7720 + published by the Free Software Foundation; either version 2, or (at
7721 + your option) any later version.
7723 + This program is distributed in the hope that it will be useful, but
7724 + WITHOUT ANY WARRANTY; without even the implied warranty of
7725 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7726 + General Public License for more details.
7731 +#include <string.h>
7736 +#include "pkg_parse.h"
7737 +#include "pkg_extract.h"
7738 +#include "ipkg_message.h"
7739 +#include "ipkg_utils.h"
7741 +#include "sprintf_alloc.h"
7742 +#include "file_util.h"
7743 +#include "str_util.h"
7744 +#include "xsystem.h"
7745 +#include "ipkg_conf.h"
7747 +typedef struct enum_map enum_map_t;
7754 +static const enum_map_t pkg_state_want_map[] = {
7755 + { SW_UNKNOWN, "unknown"},
7756 + { SW_INSTALL, "install"},
7757 + { SW_DEINSTALL, "deinstall"},
7758 + { SW_PURGE, "purge"}
7761 +static const enum_map_t pkg_state_flag_map[] = {
7763 + { SF_REINSTREQ, "reinstreq"},
7764 + { SF_HOLD, "hold"},
7765 + { SF_REPLACE, "replace"},
7766 + { SF_NOPRUNE, "noprune"},
7767 + { SF_PREFER, "prefer"},
7768 + { SF_OBSOLETE, "obsolete"},
7769 + { SF_USER, "user"},
7772 +static const enum_map_t pkg_state_status_map[] = {
7773 + { SS_NOT_INSTALLED, "not-installed" },
7774 + { SS_UNPACKED, "unpacked" },
7775 + { SS_HALF_CONFIGURED, "half-configured" },
7776 + { SS_INSTALLED, "installed" },
7777 + { SS_HALF_INSTALLED, "half-installed" },
7778 + { SS_CONFIG_FILES, "config-files" },
7779 + { SS_POST_INST_FAILED, "post-inst-failed" },
7780 + { SS_REMOVAL_FAILED, "removal-failed" }
7783 +static int verrevcmp(const char *val, const char *ref);
7786 +pkg_t *pkg_new(void)
7790 + pkg = malloc(sizeof(pkg_t));
7791 + if (pkg == NULL) {
7792 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7801 +int pkg_init(pkg_t *pkg)
7803 + memset(pkg, 0, sizeof(pkg_t));
7806 + pkg->version = NULL;
7807 + pkg->revision = NULL;
7808 + pkg->familiar_revision = NULL;
7811 + pkg->architecture = NULL;
7812 + pkg->maintainer = NULL;
7813 + pkg->section = NULL;
7814 + pkg->description = NULL;
7815 + pkg->state_want = SW_UNKNOWN;
7816 + pkg->state_flag = SF_OK;
7817 + pkg->state_status = SS_NOT_INSTALLED;
7818 + pkg->depends_str = NULL;
7819 + pkg->provides_str = NULL;
7820 + pkg->depends_count = 0;
7821 + pkg->depends = NULL;
7822 + pkg->suggests_str = NULL;
7823 + pkg->recommends_str = NULL;
7824 + pkg->suggests_count = 0;
7825 + pkg->recommends_count = 0;
7827 + /* Abhaya: added init for conflicts fields */
7828 + pkg->conflicts = NULL;
7829 + pkg->conflicts_count = 0;
7831 + /* added for replaces. Jamey 7/23/2002 */
7832 + pkg->replaces = NULL;
7833 + pkg->replaces_count = 0;
7835 + pkg->pre_depends_count = 0;
7836 + pkg->pre_depends_str = NULL;
7837 + pkg->provides_count = 0;
7838 + pkg->provides = NULL;
7839 + pkg->filename = NULL;
7840 + pkg->local_filename = NULL;
7841 + pkg->tmp_unpack_dir = NULL;
7842 + pkg->md5sum = NULL;
7844 + pkg->installed_size = NULL;
7845 + pkg->priority = NULL;
7846 + pkg->source = NULL;
7847 + conffile_list_init(&pkg->conffiles);
7848 + pkg->installed_files = NULL;
7849 + pkg->installed_files_ref_cnt = 0;
7850 + pkg->essential = 0;
7851 + pkg->provided_by_hand = 0;
7856 +void pkg_deinit(pkg_t *pkg)
7861 + free(pkg->version);
7862 + pkg->version = NULL;
7863 + /* revision and familiar_revision share storage with version, so
7865 + pkg->revision = NULL;
7866 + pkg->familiar_revision = NULL;
7867 + /* owned by ipkg_conf_t */
7869 + /* owned by ipkg_conf_t */
7871 + free(pkg->architecture);
7872 + pkg->architecture = NULL;
7873 + free(pkg->maintainer);
7874 + pkg->maintainer = NULL;
7875 + free(pkg->section);
7876 + pkg->section = NULL;
7877 + free(pkg->description);
7878 + pkg->description = NULL;
7879 + pkg->state_want = SW_UNKNOWN;
7880 + pkg->state_flag = SF_OK;
7881 + pkg->state_status = SS_NOT_INSTALLED;
7882 + free(pkg->depends_str);
7883 + pkg->depends_str = NULL;
7884 + free(pkg->provides_str);
7885 + pkg->provides_str = NULL;
7886 + pkg->depends_count = 0;
7887 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7888 + pkg->pre_depends_count = 0;
7889 + free(pkg->pre_depends_str);
7890 + pkg->pre_depends_str = NULL;
7891 + pkg->provides_count = 0;
7892 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7893 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7894 + free(pkg->filename);
7895 + pkg->filename = NULL;
7896 + free(pkg->local_filename);
7897 + pkg->local_filename = NULL;
7898 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7899 + ipkg_install.c here. See comment in
7900 + ipkg_install.c:cleanup_temporary_files */
7901 + free(pkg->tmp_unpack_dir);
7902 + pkg->tmp_unpack_dir = NULL;
7903 + free(pkg->md5sum);
7904 + pkg->md5sum = NULL;
7907 + free(pkg->installed_size);
7908 + pkg->installed_size = NULL;
7909 + free(pkg->priority);
7910 + pkg->priority = NULL;
7911 + free(pkg->source);
7912 + pkg->source = NULL;
7913 + conffile_list_deinit(&pkg->conffiles);
7914 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7915 + since if they are calling deinit, they should know. Maybe do an
7916 + assertion here instead? */
7917 + pkg->installed_files_ref_cnt = 1;
7918 + pkg_free_installed_files(pkg);
7919 + pkg->essential = 0;
7922 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7926 + FILE *control_file;
7928 + err = pkg_init(pkg);
7929 + if (err) { return err; }
7931 + pkg->local_filename = strdup(filename);
7933 + control_file = tmpfile();
7934 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7935 + if (err) { return err; }
7937 + rewind(control_file);
7938 + raw = read_raw_pkgs_from_stream(control_file);
7939 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7941 + fclose(control_file);
7946 +/* Merge any new information in newpkg into oldpkg */
7947 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7948 + newpkg, but should leave it usable. This rework is so that
7949 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7951 + * uh, i thought that i had originally written this so that it took
7952 + * two pkgs and returned a new one? we can do that again... -sma
7954 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7956 + if (oldpkg == newpkg) {
7961 + oldpkg->src = newpkg->src;
7962 + if (!oldpkg->dest)
7963 + oldpkg->dest = newpkg->dest;
7964 + if (!oldpkg->architecture)
7965 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7966 + if (!oldpkg->arch_priority)
7967 + oldpkg->arch_priority = newpkg->arch_priority;
7968 + if (!oldpkg->section)
7969 + oldpkg->section = str_dup_safe(newpkg->section);
7970 + if(!oldpkg->maintainer)
7971 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7972 + if(!oldpkg->description)
7973 + oldpkg->description = str_dup_safe(newpkg->description);
7975 + /* merge the state_flags from the new package */
7976 + oldpkg->state_want = newpkg->state_want;
7977 + oldpkg->state_status = newpkg->state_status;
7978 + oldpkg->state_flag = newpkg->state_flag;
7980 + if (oldpkg->state_want == SW_UNKNOWN)
7981 + oldpkg->state_want = newpkg->state_want;
7982 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7983 + oldpkg->state_status = newpkg->state_status;
7984 + oldpkg->state_flag |= newpkg->state_flag;
7987 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7988 + oldpkg->depends_str = newpkg->depends_str;
7989 + newpkg->depends_str = NULL;
7990 + oldpkg->depends_count = newpkg->depends_count;
7991 + newpkg->depends_count = 0;
7993 + oldpkg->depends = newpkg->depends;
7994 + newpkg->depends = NULL;
7996 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7997 + newpkg->pre_depends_str = NULL;
7998 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7999 + newpkg->pre_depends_count = 0;
8001 + oldpkg->recommends_str = newpkg->recommends_str;
8002 + newpkg->recommends_str = NULL;
8003 + oldpkg->recommends_count = newpkg->recommends_count;
8004 + newpkg->recommends_count = 0;
8006 + oldpkg->suggests_str = newpkg->suggests_str;
8007 + newpkg->suggests_str = NULL;
8008 + oldpkg->suggests_count = newpkg->suggests_count;
8009 + newpkg->suggests_count = 0;
8012 + if (!oldpkg->provides_str) {
8013 + oldpkg->provides_str = newpkg->provides_str;
8014 + newpkg->provides_str = NULL;
8015 + oldpkg->provides_count = newpkg->provides_count;
8016 + newpkg->provides_count = 0;
8018 + oldpkg->provides = newpkg->provides;
8019 + newpkg->provides = NULL;
8022 + if (!oldpkg->conflicts_str) {
8023 + oldpkg->conflicts_str = newpkg->conflicts_str;
8024 + newpkg->conflicts_str = NULL;
8025 + oldpkg->conflicts_count = newpkg->conflicts_count;
8026 + newpkg->conflicts_count = 0;
8028 + oldpkg->conflicts = newpkg->conflicts;
8029 + newpkg->conflicts = NULL;
8032 + if (!oldpkg->replaces_str) {
8033 + oldpkg->replaces_str = newpkg->replaces_str;
8034 + newpkg->replaces_str = NULL;
8035 + oldpkg->replaces_count = newpkg->replaces_count;
8036 + newpkg->replaces_count = 0;
8038 + oldpkg->replaces = newpkg->replaces;
8039 + newpkg->replaces = NULL;
8042 + if (!oldpkg->filename)
8043 + oldpkg->filename = str_dup_safe(newpkg->filename);
8045 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
8046 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
8047 + if (!oldpkg->local_filename)
8048 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
8049 + if (!oldpkg->tmp_unpack_dir)
8050 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
8051 + if (!oldpkg->md5sum)
8052 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
8053 + if (!oldpkg->size)
8054 + oldpkg->size = str_dup_safe(newpkg->size);
8055 + if (!oldpkg->installed_size)
8056 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
8057 + if (!oldpkg->priority)
8058 + oldpkg->priority = str_dup_safe(newpkg->priority);
8059 + if (!oldpkg->source)
8060 + oldpkg->source = str_dup_safe(newpkg->source);
8061 + if (oldpkg->conffiles.head == NULL){
8062 + oldpkg->conffiles = newpkg->conffiles;
8063 + conffile_list_init(&newpkg->conffiles);
8065 + if (!oldpkg->installed_files){
8066 + oldpkg->installed_files = newpkg->installed_files;
8067 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
8068 + newpkg->installed_files = NULL;
8070 + if (!oldpkg->essential)
8071 + oldpkg->essential = newpkg->essential;
8076 +abstract_pkg_t *abstract_pkg_new(void)
8078 + abstract_pkg_t * ab_pkg;
8080 + ab_pkg = malloc(sizeof(abstract_pkg_t));
8082 + if (ab_pkg == NULL) {
8083 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8087 + if ( abstract_pkg_init(ab_pkg) < 0 )
8093 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
8095 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
8097 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
8098 + if (ab_pkg->provided_by==NULL){
8101 + ab_pkg->dependencies_checked = 0;
8102 + ab_pkg->state_status = SS_NOT_INSTALLED;
8107 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
8110 + char **raw_start=NULL;
8112 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
8113 + if (temp_str == NULL ){
8114 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
8117 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
8119 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
8120 + if (raw == NULL ){
8121 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
8126 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
8127 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
8143 +char * pkg_formatted_info(pkg_t *pkg )
8148 + buff = malloc(8192);
8149 + if (buff == NULL) {
8150 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8156 + line = pkg_formatted_field(pkg, "Package");
8157 + strncat(buff ,line, strlen(line));
8160 + line = pkg_formatted_field(pkg, "Version");
8161 + strncat(buff ,line, strlen(line));
8164 + line = pkg_formatted_field(pkg, "Depends");
8165 + strncat(buff ,line, strlen(line));
8168 + line = pkg_formatted_field(pkg, "Recommends");
8169 + strncat(buff ,line, strlen(line));
8172 + line = pkg_formatted_field(pkg, "Suggests");
8173 + strncat(buff ,line, strlen(line));
8176 + line = pkg_formatted_field(pkg, "Provides");
8177 + strncat(buff ,line, strlen(line));
8180 + line = pkg_formatted_field(pkg, "Replaces");
8181 + strncat(buff ,line, strlen(line));
8184 + line = pkg_formatted_field(pkg, "Conflicts");
8185 + strncat(buff ,line, strlen(line));
8188 + line = pkg_formatted_field(pkg, "Status");
8189 + strncat(buff ,line, strlen(line));
8192 + line = pkg_formatted_field(pkg, "Section");
8193 + strncat(buff ,line, strlen(line));
8196 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
8197 + strncat(buff ,line, strlen(line));
8200 + line = pkg_formatted_field(pkg, "Architecture");
8201 + strncat(buff ,line, strlen(line));
8204 + line = pkg_formatted_field(pkg, "Maintainer");
8205 + strncat(buff ,line, strlen(line));
8208 + line = pkg_formatted_field(pkg, "MD5sum");
8209 + strncat(buff ,line, strlen(line));
8212 + line = pkg_formatted_field(pkg, "Size");
8213 + strncat(buff ,line, strlen(line));
8216 + line = pkg_formatted_field(pkg, "Filename");
8217 + strncat(buff ,line, strlen(line));
8220 + line = pkg_formatted_field(pkg, "Conffiles");
8221 + strncat(buff ,line, strlen(line));
8224 + line = pkg_formatted_field(pkg, "Source");
8225 + strncat(buff ,line, strlen(line));
8228 + line = pkg_formatted_field(pkg, "Description");
8229 + strncat(buff ,line, strlen(line));
8232 + line = pkg_formatted_field(pkg, "Installed-Time");
8233 + strncat(buff ,line, strlen(line));
8239 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8241 + static size_t LINE_LEN = 128;
8242 + char * temp = (char *)malloc(1);
8244 + int flag_provide_false = 0;
8247 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8248 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8251 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8252 + goto UNKNOWN_FMT_FIELD;
8261 + if (strcasecmp(field, "Architecture") == 0) {
8262 + /* Architecture */
8263 + if (pkg->architecture) {
8264 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8265 + if ( temp == NULL ){
8266 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8270 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8273 + goto UNKNOWN_FMT_FIELD;
8278 + if (strcasecmp(field, "Conffiles") == 0) {
8280 + conffile_list_elt_t *iter;
8281 + char confstr[LINE_LEN];
8283 + if (pkg->conffiles.head == NULL) {
8288 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8289 + if (iter->data->name && iter->data->value) {
8290 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8293 + temp = (char *)realloc(temp,len);
8294 + if ( temp == NULL ){
8295 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8299 + strncpy(temp, "Conffiles:\n", 12);
8300 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8301 + if (iter->data->name && iter->data->value) {
8302 + snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8303 + strncat(temp, confstr, strlen(confstr));
8306 + } else if (strcasecmp(field, "Conflicts") == 0) {
8309 + if (pkg->conflicts_count) {
8310 + char conflictstr[LINE_LEN];
8312 + for(i = 0; i < pkg->conflicts_count; i++) {
8313 + len = len + (strlen(pkg->conflicts_str[i])+5);
8315 + temp = (char *)realloc(temp,len);
8316 + if ( temp == NULL ){
8317 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8321 + strncpy(temp, "Conflicts:", 11);
8322 + for(i = 0; i < pkg->conflicts_count; i++) {
8323 + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8324 + strncat(temp, conflictstr, strlen(conflictstr));
8326 + strncat(temp, "\n", strlen("\n"));
8329 + goto UNKNOWN_FMT_FIELD;
8334 + if (strcasecmp(field, "Depends") == 0) {
8338 + if (pkg->depends_count) {
8339 + char depstr[LINE_LEN];
8341 + for(i = 0; i < pkg->depends_count; i++) {
8342 + len = len + (strlen(pkg->depends_str[i])+4);
8344 + temp = (char *)realloc(temp,len);
8345 + if ( temp == NULL ){
8346 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8350 + strncpy(temp, "Depends:", 10);
8351 + for(i = 0; i < pkg->depends_count; i++) {
8352 + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8353 + strncat(temp, depstr, strlen(depstr));
8355 + strncat(temp, "\n", strlen("\n"));
8357 + } else if (strcasecmp(field, "Description") == 0) {
8359 + if (pkg->description) {
8360 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8361 + if ( temp == NULL ){
8362 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8366 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8369 + goto UNKNOWN_FMT_FIELD;
8375 + if (pkg->essential) {
8376 + temp = (char *)realloc(temp,16);
8377 + if ( temp == NULL ){
8378 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8382 + snprintf(temp, (16), "Essential: yes\n");
8389 + if (pkg->filename) {
8390 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8391 + if ( temp == NULL ){
8392 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8396 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8402 + if (strcasecmp(field, "Installed-Size") == 0) {
8403 + /* Installed-Size */
8404 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8405 + if ( temp == NULL ){
8406 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8410 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8411 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8412 + temp = (char *)realloc(temp,29);
8413 + if ( temp == NULL ){
8414 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8418 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8424 + /* Maintainer | MD5sum */
8425 + if (strcasecmp(field, "Maintainer") == 0) {
8427 + if (pkg->maintainer) {
8428 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8429 + if ( temp == NULL ){
8430 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8434 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8436 + } else if (strcasecmp(field, "MD5sum") == 0) {
8438 + if (pkg->md5sum) {
8439 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8440 + if ( temp == NULL ){
8441 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8445 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8448 + goto UNKNOWN_FMT_FIELD;
8454 + if (strcasecmp(field, "Package") == 0) {
8456 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8457 + if ( temp == NULL ){
8458 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8462 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8463 + } else if (strcasecmp(field, "Priority") == 0) {
8465 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8466 + if ( temp == NULL ){
8467 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8471 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8472 + } else if (strcasecmp(field, "Provides") == 0) {
8476 + if (pkg->provides_count) {
8477 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8478 + for ( i=0; i < pkg->provides_count; i++ ){
8479 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8480 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8481 + flag_provide_false = 1;
8484 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8485 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8486 + char provstr[LINE_LEN];
8488 + for(i = 0; i < pkg->provides_count; i++) {
8489 + len = len + (strlen(pkg->provides_str[i])+5);
8491 + temp = (char *)realloc(temp,len);
8492 + if ( temp == NULL ){
8493 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8497 + strncpy(temp, "Provides:", 12);
8498 + for(i = 0; i < pkg->provides_count; i++) {
8499 + if (strlen(pkg->provides_str[i])>0){;
8500 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8501 + strncat(temp, provstr, strlen(provstr));
8504 + strncat(temp, "\n", strlen("\n"));
8508 + goto UNKNOWN_FMT_FIELD;
8515 + /* Replaces | Recommends*/
8516 + if (strcasecmp (field, "Replaces") == 0) {
8517 + if (pkg->replaces_count) {
8518 + char replstr[LINE_LEN];
8520 + for (i = 0; i < pkg->replaces_count; i++) {
8521 + len = len + (strlen(pkg->replaces_str[i])+5);
8523 + temp = (char *)realloc(temp,len);
8524 + if ( temp == NULL ){
8525 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8529 + strncpy(temp, "Replaces:", 12);
8530 + for (i = 0; i < pkg->replaces_count; i++) {
8531 + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8532 + strncat(temp, replstr, strlen(replstr));
8534 + strncat(temp, "\n", strlen("\n"));
8536 + } else if (strcasecmp (field, "Recommends") == 0) {
8537 + if (pkg->recommends_count) {
8538 + char recstr[LINE_LEN];
8540 + for(i = 0; i < pkg->recommends_count; i++) {
8541 + len = len + (strlen( pkg->recommends_str[i])+5);
8543 + temp = (char *)realloc(temp,len);
8544 + if ( temp == NULL ){
8545 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8549 + strncpy(temp, "Recommends:", 13);
8550 + for(i = 0; i < pkg->recommends_count; i++) {
8551 + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8552 + strncat(temp, recstr, strlen(recstr));
8554 + strncat(temp, "\n", strlen("\n"));
8557 + goto UNKNOWN_FMT_FIELD;
8563 + /* Section | Size | Source | Status | Suggests */
8564 + if (strcasecmp(field, "Section") == 0) {
8566 + if (pkg->section) {
8567 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8568 + if ( temp == NULL ){
8569 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8573 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8575 + } else if (strcasecmp(field, "Size") == 0) {
8578 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8579 + if ( temp == NULL ){
8580 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8584 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8586 + } else if (strcasecmp(field, "Source") == 0) {
8588 + if (pkg->source) {
8589 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8590 + if ( temp == NULL ){
8591 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8595 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8597 + } else if (strcasecmp(field, "Status") == 0) {
8599 + /* Benjamin Pineau note: we should avoid direct usage of
8600 + * strlen(arg) without keeping "arg" for later free()
8602 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8603 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8604 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8606 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8607 + temp = (char *)realloc(temp,sum_of_sizes);
8608 + if ( temp == NULL ){
8609 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8613 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8616 + if(pstat) /* pfstat can be NULL if ENOMEM */
8618 + } else if (strcasecmp(field, "Suggests") == 0) {
8619 + if (pkg->suggests_count) {
8621 + char sugstr[LINE_LEN];
8623 + for(i = 0; i < pkg->suggests_count; i++) {
8624 + len = len + (strlen(pkg->suggests_str[i])+5);
8626 + temp = (char *)realloc(temp,len);
8627 + if ( temp == NULL ){
8628 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8632 + strncpy(temp, "Suggests:", 10);
8633 + for(i = 0; i < pkg->suggests_count; i++) {
8634 + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8635 + strncat(temp, sugstr, strlen(sugstr));
8637 + strncat(temp, "\n", strlen("\n"));
8640 + goto UNKNOWN_FMT_FIELD;
8647 + char *version = pkg_version_str_alloc(pkg);
8648 + temp = (char *)realloc(temp,strlen(version)+14);
8649 + if ( temp == NULL ){
8650 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8654 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8659 + goto UNKNOWN_FMT_FIELD;
8662 + if ( strlen(temp)<2 ) {
8667 + UNKNOWN_FMT_FIELD:
8668 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8669 + if ( strlen(temp)<2 ) {
8676 +void pkg_print_info(pkg_t *pkg, FILE *file)
8679 + if (pkg == NULL) {
8683 + buff = pkg_formatted_info(pkg);
8684 + if ( buff == NULL )
8686 + if (strlen(buff)>2){
8687 + fwrite(buff, 1, strlen(buff), file);
8692 +void pkg_print_status(pkg_t * pkg, FILE * file)
8694 + if (pkg == NULL) {
8698 + /* XXX: QUESTION: Do we actually want more fields here? The
8699 + original idea was to save space by installing only what was
8700 + needed for actual computation, (package, version, status,
8701 + essential, conffiles). The assumption is that all other fields
8702 + can be found in th available file.
8704 + But, someone proposed the idea to make it possible to
8705 + reconstruct a .ipk from an installed package, (ie. for beaming
8706 + from one handheld to another). So, maybe we actually want a few
8707 + more fields here, (depends, suggests, etc.), so that that would
8708 + be guaranteed to work even in the absence of more information
8709 + from the available file.
8711 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8712 + the essential info needs to be here for all installed packages
8713 + because they may not appear in the Packages files on various
8714 + feeds. Furthermore, one should be able to install from URL or
8715 + local storage without requiring a Packages file from any feed.
8718 + pkg_print_field(pkg, file, "Package");
8719 + pkg_print_field(pkg, file, "Version");
8720 + pkg_print_field(pkg, file, "Depends");
8721 + pkg_print_field(pkg, file, "Recommends");
8722 + pkg_print_field(pkg, file, "Suggests");
8723 + pkg_print_field(pkg, file, "Provides");
8724 + pkg_print_field(pkg, file, "Replaces");
8725 + pkg_print_field(pkg, file, "Conflicts");
8726 + pkg_print_field(pkg, file, "Status");
8727 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8728 + pkg_print_field(pkg, file, "Architecture");
8729 + pkg_print_field(pkg, file, "Conffiles");
8730 + pkg_print_field(pkg, file, "Installed-Time");
8731 + fputs("\n", file);
8734 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8737 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8738 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8739 + __FUNCTION__, field);
8741 + buff = pkg_formatted_field(pkg, field);
8742 + if (strlen(buff)>2) {
8743 + fprintf(file, "%s", buff);
8751 + * libdpkg - Debian packaging suite library routines
8752 + * vercmp.c - comparison of version numbers
8754 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8756 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8760 + if (pkg->epoch > ref_pkg->epoch) {
8764 + if (pkg->epoch < ref_pkg->epoch) {
8768 + r = verrevcmp(pkg->version, ref_pkg->version);
8773 +#ifdef USE_DEBVERSION
8774 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8779 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8785 +int verrevcmp(const char *val, const char *ref)
8789 + const char *vp, *rp;
8790 + const char *vsep, *rsep;
8792 + if (!val) val= "";
8793 + if (!ref) ref= "";
8795 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8796 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8798 + vc= (val == vp) ? 0 : *val++;
8799 + rc= (ref == rp) ? 0 : *ref++;
8800 + if (!rc && !vc) break;
8801 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8802 + if (rc && !isalpha(rc)) rc += 256;
8803 + if (vc != rc) return vc - rc;
8807 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8808 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8809 + if (vl != rl) return vl - rl;
8813 + vsep = strchr(".-", vc);
8814 + rsep = strchr(".-", rc);
8815 + if (vsep && !rsep) return -1;
8816 + if (!vsep && rsep) return +1;
8818 + if (!*val && !*ref) return 0;
8819 + if (!*val) return -1;
8820 + if (!*ref) return +1;
8824 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8828 + r = pkg_compare_versions(it, ref);
8830 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8834 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8838 + if (strcmp(op, "<<") == 0) {
8842 + if (strcmp(op, ">>") == 0) {
8846 + if (strcmp(op, "=") == 0) {
8850 + fprintf(stderr, "unknown operator: %s", op);
8854 +int pkg_name_version_and_architecture_compare(void *p1, void *p2)
8856 + const pkg_t *a = *(const pkg_t **)p1;
8857 + const pkg_t *b = *(const pkg_t **)p2;
8860 + if (!a->name || !b->name) {
8861 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8862 + a, a->name, b, b->name);
8866 + namecmp = strcmp(a->name, b->name);
8869 + vercmp = pkg_compare_versions(a, b);
8872 + if (!a->arch_priority || !b->arch_priority) {
8873 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8874 + a, a->arch_priority, b, b->arch_priority);
8877 + if (a->arch_priority > b->arch_priority)
8879 + if (a->arch_priority < b->arch_priority)
8884 +int abstract_pkg_name_compare(void *p1, void *p2)
8886 + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
8887 + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
8888 + if (!a->name || !b->name) {
8889 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8890 + a, a->name, b, b->name);
8893 + return strcmp(a->name, b->name);
8897 +char *pkg_version_str_alloc(pkg_t *pkg)
8899 + char *complete_version;
8901 +#ifdef USE_DEBVERSION
8902 + char *revision_str;
8903 + char *familiar_revision_str;
8907 + sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
8909 + epoch_str = strdup("");
8912 +#ifdef USE_DEBVERSION
8913 + if (pkg->revision && strlen(pkg->revision)) {
8914 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8916 + revision_str = strdup("");
8919 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8920 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8922 + familiar_revision_str = strdup("");
8926 +#ifdef USE_DEBVERSION
8927 + sprintf_alloc(&complete_version, "%s%s%s%s",
8928 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8930 + sprintf_alloc(&complete_version, "%s%s",
8931 + epoch_str, pkg->version);
8935 +#ifdef USE_DEBVERSION
8936 + free(revision_str);
8937 + free(familiar_revision_str);
8940 + return complete_version;
8943 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8946 + char *list_file_name = NULL;
8947 + FILE *list_file = NULL;
8949 + char *installed_file_name;
8952 + pkg->installed_files_ref_cnt++;
8954 + if (pkg->installed_files) {
8955 + return pkg->installed_files;
8958 + pkg->installed_files = str_list_alloc();
8959 + if (pkg->installed_files == NULL) {
8960 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8964 + /* For uninstalled packages, get the file list firectly from the package.
8965 + For installed packages, look at the package.list file in the database.
8967 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8968 + if (pkg->local_filename == NULL) {
8969 + return pkg->installed_files;
8971 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8972 + file. In other words, change deb_extract so that it can
8973 + simply return the file list as a char *[] rather than
8974 + insisting on writing in to a FILE * as it does now. */
8975 + list_file = tmpfile();
8976 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8978 + fclose(list_file);
8979 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8980 + __FUNCTION__, pkg->local_filename, strerror(err));
8981 + return pkg->installed_files;
8983 + rewind(list_file);
8985 + sprintf_alloc(&list_file_name, "%s/%s.list",
8986 + pkg->dest->info_dir, pkg->name);
8987 + if (! file_exists(list_file_name)) {
8988 + free(list_file_name);
8989 + return pkg->installed_files;
8992 + list_file = fopen(list_file_name, "r");
8993 + if (list_file == NULL) {
8994 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8995 + list_file_name, strerror(errno));
8996 + free(list_file_name);
8997 + return pkg->installed_files;
8999 + free(list_file_name);
9002 + rootdirlen = strlen( pkg->dest->root_dir );
9006 + line = file_read_line_alloc(list_file);
9007 + if (line == NULL) {
9013 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
9014 + if( strncmp( pkg->dest->root_dir,
9017 + if (*file_name == '.') {
9020 + if (*file_name == '/') {
9024 + /* Freed in pkg_free_installed_files */
9025 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
9027 + // already contains root_dir as header -> ABSOLUTE
9028 + sprintf_alloc(&installed_file_name, "%s", file_name);
9030 + str_list_append(pkg->installed_files, installed_file_name);
9034 + fclose(list_file);
9036 + return pkg->installed_files;
9039 +/* XXX: CLEANUP: This function and it's counterpart,
9040 + (pkg_get_installed_files), do not match our init/deinit naming
9041 + convention. Nor the alloc/free convention. But, then again, neither
9042 + of these conventions currrently fit the way these two functions
9044 +int pkg_free_installed_files(pkg_t *pkg)
9046 + str_list_elt_t *iter;
9048 + pkg->installed_files_ref_cnt--;
9049 + if (pkg->installed_files_ref_cnt > 0) {
9053 + if (pkg->installed_files) {
9055 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
9056 + /* malloced in pkg_get_installed_files */
9057 + free (iter->data);
9058 + iter->data = NULL;
9061 + str_list_deinit(pkg->installed_files);
9064 + pkg->installed_files = NULL;
9069 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
9072 + char *list_file_name;
9074 + //I don't think pkg_free_installed_files should be called here. Jamey
9075 + //pkg_free_installed_files(pkg);
9077 + sprintf_alloc(&list_file_name, "%s/%s.list",
9078 + pkg->dest->info_dir, pkg->name);
9079 + if (!conf->noaction) {
9080 + err = unlink(list_file_name);
9081 + free(list_file_name);
9090 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
9092 + conffile_list_elt_t *iter;
9093 + conffile_t *conffile;
9095 + if (pkg == NULL) {
9099 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
9100 + conffile = iter->data;
9102 + if (strcmp(conffile->name, file_name) == 0) {
9110 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
9111 + const char *script, const char *args)
9117 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
9118 + maintainer script within a chroot environment. */
9120 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
9121 + have scripts in pkg->tmp_unpack_dir. */
9122 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
9123 + if (pkg->dest == NULL) {
9124 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
9125 + __FUNCTION__, pkg->name);
9128 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
9130 + if (pkg->tmp_unpack_dir == NULL) {
9131 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
9132 + __FUNCTION__, pkg->name);
9135 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
9138 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
9139 + if (conf->noaction) return 0;
9141 + /* XXX: CLEANUP: There must be a better way to handle maintainer
9142 + scripts when running with offline_root mode and/or a dest other
9143 + than '/'. I've been playing around with some clever chroot
9144 + tricks and I might come up with something workable. */
9145 + if (conf->offline_root) {
9146 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
9149 + setenv("PKG_ROOT",
9150 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
9152 + if (! file_exists(path)) {
9157 + if (conf->offline_root) {
9158 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
9163 + sprintf_alloc(&cmd, "%s %s", path, args);
9166 + err = xsystem(cmd);
9170 + fprintf(stderr, "%s script returned status %d\n", script, err);
9177 +char *pkg_state_want_to_str(pkg_state_want_t sw)
9181 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9182 + if (pkg_state_want_map[i].value == sw) {
9183 + return strdup(pkg_state_want_map[i].str);
9187 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
9188 + __FUNCTION__, sw);
9189 + return strdup("<STATE_WANT_UNKNOWN>");
9192 +pkg_state_want_t pkg_state_want_from_str(char *str)
9196 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
9197 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
9198 + return pkg_state_want_map[i].value;
9202 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
9203 + __FUNCTION__, str);
9204 + return SW_UNKNOWN;
9207 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
9210 + int len = 3; /* ok\000 is minimum */
9213 + /* clear the temporary flags before converting to string */
9214 + sf &= SF_NONVOLATILE_FLAGS;
9217 + return strdup("ok");
9220 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9221 + if (sf & pkg_state_flag_map[i].value) {
9222 + len += strlen(pkg_state_flag_map[i].str) + 1;
9225 + str = malloc(len);
9226 + if ( str == NULL ) {
9227 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9231 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9232 + if (sf & pkg_state_flag_map[i].value) {
9233 + strcat(str, pkg_state_flag_map[i].str);
9237 + len = strlen(str);
9238 + str[len-1] = 0; /* squash last comma */
9243 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9248 + if (strcmp(str, "ok") == 0) {
9251 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9252 + const char *sfname = pkg_state_flag_map[i].str;
9253 + int sfname_len = strlen(sfname);
9254 + if (strncmp(str, sfname, sfname_len) == 0) {
9255 + sf |= pkg_state_flag_map[i].value;
9256 + str += sfname_len;
9257 + if (str[0] == ',') {
9268 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9272 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9273 + if (pkg_state_status_map[i].value == ss) {
9274 + return strdup(pkg_state_status_map[i].str);
9278 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9279 + __FUNCTION__, ss);
9280 + return strdup("<STATE_STATUS_UNKNOWN>");
9283 +pkg_state_status_t pkg_state_status_from_str(char *str)
9287 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9288 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9289 + return pkg_state_status_map[i].value;
9293 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9294 + __FUNCTION__, str);
9295 + return SS_NOT_INSTALLED;
9298 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9300 + nv_pair_list_elt_t *l;
9302 + if (!pkg->architecture)
9305 + l = conf->arch_list.head;
9308 + nv_pair_t *nv = l->data;
9309 + if (strcmp(nv->name, pkg->architecture) == 0) {
9310 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9316 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9320 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9322 + nv_pair_list_elt_t *l;
9324 + l = conf->arch_list.head;
9327 + nv_pair_t *nv = l->data;
9328 + if (strcmp(nv->name, archname) == 0) {
9329 + int priority = strtol(nv->value, NULL, 0);
9337 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9340 + hash_table_t *pkg_hash = &conf->pkg_hash;
9341 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9342 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9344 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9345 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9346 + /* update arch_priority for each package */
9347 + for (i = 0; i < available_pkgs->len; i++) {
9348 + pkg_t *pkg = available_pkgs->pkgs[i];
9349 + int arch_priority = 1;
9352 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9353 + if (pkg->architecture)
9354 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9356 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9357 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9358 + pkg->arch_priority = arch_priority;
9361 + for (i = 0; i < available_pkgs->len; i++) {
9362 + pkg_t *pkg = available_pkgs->pkgs[i];
9363 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9364 + /* clear flags and want for any uninstallable package */
9365 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9366 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9367 + pkg->state_want = SW_UNKNOWN;
9368 + pkg->state_flag = 0;
9371 + pkg_vec_free(available_pkgs);
9373 + /* update the file owner data structure */
9374 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9375 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9376 + for (i = 0; i < installed_pkgs->len; i++) {
9377 + pkg_t *pkg = installed_pkgs->pkgs[i];
9378 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9379 + str_list_elt_t *iter;
9380 + if (installed_files == NULL) {
9381 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9384 + for (iter = installed_files->head; iter; iter = iter->next) {
9385 + char *installed_file = iter->data;
9386 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9387 + file_hash_set_file_owner(conf, installed_file, pkg);
9390 + pkg_vec_free(installed_pkgs);
9395 +struct pkg_write_filelist_data {
9396 + ipkg_conf_t *conf;
9401 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9403 + struct pkg_write_filelist_data *data = data_;
9404 + pkg_t *entry = entry_;
9405 + if (entry == data->pkg) {
9406 + fprintf(data->stream, "%s\n", key);
9410 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9412 + struct pkg_write_filelist_data data;
9413 + char *list_file_name = NULL;
9417 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9420 + ipkg_message(conf, IPKG_INFO,
9421 + " creating %s.list file\n", pkg->name);
9422 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9423 + if (!list_file_name) {
9424 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9427 + ipkg_message(conf, IPKG_INFO,
9428 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9429 + data.stream = fopen(list_file_name, "w");
9430 + if (!data.stream) {
9431 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9432 + list_file_name, strerror(errno));
9437 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9438 + fclose(data.stream);
9439 + free(list_file_name);
9444 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9446 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9447 + hash_table_t *pkg_hash = &conf->pkg_hash;
9450 + if (conf->noaction)
9453 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9454 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9455 + for (i = 0; i < installed_pkgs->len; i++) {
9456 + pkg_t *pkg = installed_pkgs->pkgs[i];
9457 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9458 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9459 + err = pkg_write_filelist(conf, pkg);
9461 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9466 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
9467 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
9468 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.c 2006-07-22 16:31:25.000000000 +0200
9470 +/* pkg_depends.c - the itsy package management system
9474 + Copyright (C) 2002 Compaq Computer Corporation
9476 + This program is free software; you can redistribute it and/or
9477 + modify it under the terms of the GNU General Public License as
9478 + published by the Free Software Foundation; either version 2, or (at
9479 + your option) any later version.
9481 + This program is distributed in the hope that it will be useful, but
9482 + WITHOUT ANY WARRANTY; without even the implied warranty of
9483 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9484 + General Public License for more details.
9492 +#include "ipkg_utils.h"
9493 +#include "pkg_hash.h"
9494 +#include "ipkg_message.h"
9495 +#include "pkg_parse.h"
9496 +#include "hash_table.h"
9498 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9499 +static depend_t * depend_init(void);
9500 +static void depend_deinit(depend_t *d);
9501 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9502 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9503 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9505 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9507 + depend_t *depend = (depend_t *)cdata;
9508 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9514 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9516 + depend_t *depend = (depend_t *)cdata;
9518 + pkg_t * temp = pkg_new();
9520 + parseVersion(temp, depend->version);
9521 + comparison = pkg_compare_versions(pkg, temp);
9524 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9525 + __FUNCTION__, pkg->name, pkg->version,
9526 + depend, depend->constraint, depend->version,
9527 + comparison, version_constraints_satisfied(depend, pkg));
9529 + if (version_constraints_satisfied(depend, pkg))
9535 +/* returns ndependences or negative error value */
9536 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9537 + pkg_vec_t *unsatisfied, char *** unresolved)
9539 + pkg_t * satisfier_entry_pkg;
9540 + register int i, j, k;
9543 + abstract_pkg_t * ab_pkg;
9546 + * this is a setup to check for redundant/cyclic dependency checks,
9547 + * which are marked at the abstract_pkg level
9549 + if (!(ab_pkg = pkg->parent)) {
9550 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9551 + *unresolved = NULL;
9554 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9555 + *unresolved = NULL;
9558 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9562 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9564 + *unresolved = NULL;
9570 + /* foreach dependency */
9571 + for (i = 0; i < count; i++) {
9572 + compound_depend_t * compound_depend = &pkg->depends[i];
9573 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9575 + satisfier_entry_pkg = NULL;
9577 + if (compound_depend->type == GREEDY_DEPEND) {
9578 + /* foreach possible satisfier */
9579 + for (j = 0; j < compound_depend->possibility_count; j++) {
9580 + /* foreach provided_by, which includes the abstract_pkg itself */
9581 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9582 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9583 + int nposs = ab_provider_vec->len;
9584 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9586 + for (l = 0; l < nposs; l++) {
9587 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9588 + /* if no depends on this one, try the first package that Provides this one */
9589 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9593 + /* cruise this possiblity's pkg_vec looking for an installed version */
9594 + for (k = 0; k < test_vec->len; k++) {
9595 + pkg_t *pkg_scout = test_vec->pkgs[k];
9596 + /* not installed, and not already known about? */
9597 + if ((pkg_scout->state_want != SW_INSTALL)
9598 + && !pkg_scout->parent->dependencies_checked
9599 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9600 + char ** newstuff = NULL;
9602 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9603 + /* check for not-already-installed dependencies */
9604 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9608 + if (newstuff == NULL) {
9611 + for (i = 0; i < rc; i++) {
9612 + pkg_t *p = tmp_vec->pkgs[i];
9613 + if (p->state_want == SW_INSTALL)
9615 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9619 + pkg_vec_free (tmp_vec);
9621 + /* mark this one for installation */
9622 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9623 + pkg_vec_insert(unsatisfied, pkg_scout);
9626 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9637 + /* foreach possible satisfier, look for installed package */
9638 + for (j = 0; j < compound_depend->possibility_count; j++) {
9639 + /* foreach provided_by, which includes the abstract_pkg itself */
9640 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9641 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9642 + pkg_t *satisfying_pkg =
9643 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9644 + pkg_installed_and_constraint_satisfied,
9645 + dependence_to_satisfy, 1);
9646 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9647 + if (satisfying_pkg != NULL) {
9648 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9649 + satisfying_pkg = NULL;
9652 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9653 + if (satisfying_pkg != NULL) {
9659 + /* if nothing installed matches, then look for uninstalled satisfier */
9661 + /* foreach possible satisfier, look for installed package */
9662 + for (j = 0; j < compound_depend->possibility_count; j++) {
9663 + /* foreach provided_by, which includes the abstract_pkg itself */
9664 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9665 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9666 + pkg_t *satisfying_pkg =
9667 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9668 + pkg_constraint_satisfied,
9669 + dependence_to_satisfy, 1);
9670 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9671 + if (satisfying_pkg != NULL) {
9672 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9673 + satisfying_pkg = NULL;
9677 + /* user request overrides package recommendation */
9678 + if (satisfying_pkg != NULL
9679 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9680 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9681 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9682 + pkg->name, satisfying_pkg->name);
9686 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9687 + if (satisfying_pkg != NULL) {
9688 + satisfier_entry_pkg = satisfying_pkg;
9694 + /* we didn't find one, add something to the unsatisfied vector */
9696 + if (!satisfier_entry_pkg) {
9697 + /* failure to meet recommendations is not an error */
9698 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9699 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9701 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9702 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9705 + if (compound_depend->type == SUGGEST) {
9706 + /* just mention it politely */
9707 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9708 + pkg->name, satisfier_entry_pkg->name);
9710 + char ** newstuff = NULL;
9712 + if (satisfier_entry_pkg != pkg &&
9713 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9714 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9715 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9716 + satisfier_entry_pkg,
9719 + the_lost = merge_unresolved(the_lost, newstuff);
9725 + *unresolved = the_lost;
9727 + return unsatisfied->len;
9730 +/*checking for conflicts !in replaces
9731 + If a packages conflicts with another but is also replacing it, I should not consider it a
9733 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9735 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9738 + int replaces_count = pkg->replaces_count;
9739 + abstract_pkg_t **replaces;
9741 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9744 + replaces = pkg->replaces;
9746 + for (i = 0; i < replaces_count; i++) {
9747 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9748 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9757 +/* Abhaya: added support for conflicts */
9758 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9760 + pkg_vec_t * installed_conflicts, * test_vec;
9761 + compound_depend_t * conflicts;
9762 + depend_t ** possible_satisfiers;
9763 + depend_t * possible_satisfier;
9764 + register int i, j, k;
9766 + abstract_pkg_t * ab_pkg;
9767 + pkg_t **pkg_scouts;
9771 + * this is a setup to check for redundant/cyclic dependency checks,
9772 + * which are marked at the abstract_pkg level
9774 + if(!(ab_pkg = pkg->parent)){
9775 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9776 + return (pkg_vec_t *)NULL;
9779 + conflicts = pkg->conflicts;
9781 + return (pkg_vec_t *)NULL;
9783 + installed_conflicts = pkg_vec_alloc();
9785 + count = pkg->conflicts_count;
9789 + /* foreach conflict */
9790 + for(i = 0; i < pkg->conflicts_count; i++){
9792 + possible_satisfiers = conflicts->possibilities;
9794 + /* foreach possible satisfier */
9795 + for(j = 0; j < conflicts->possibility_count; j++){
9796 + possible_satisfier = possible_satisfiers[j];
9797 + if (!possible_satisfier)
9798 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9799 + if (!possible_satisfier->pkg)
9800 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9801 + test_vec = possible_satisfier->pkg->pkgs;
9803 + /* pkg_vec found, it is an actual package conflict
9804 + * cruise this possiblity's pkg_vec looking for an installed version */
9805 + pkg_scouts = test_vec->pkgs;
9806 + for(k = 0; k < test_vec->len; k++){
9807 + pkg_scout = pkg_scouts[k];
9809 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9812 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9813 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9814 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9815 + pkg_vec_insert(installed_conflicts, pkg_scout);
9824 + if (installed_conflicts->len)
9825 + return installed_conflicts;
9826 + pkg_vec_free(installed_conflicts);
9827 + return (pkg_vec_t *)NULL;
9830 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9835 + if(depends->constraint == NONE)
9840 + parseVersion(temp, depends->version);
9842 + comparison = pkg_compare_versions(pkg, temp);
9846 + if((depends->constraint == EARLIER) &&
9849 + else if((depends->constraint == LATER) &&
9852 + else if(comparison == 0)
9854 + else if((depends->constraint == LATER_EQUAL) &&
9855 + (comparison >= 0))
9857 + else if((depends->constraint == EARLIER_EQUAL) &&
9858 + (comparison <= 0))
9864 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9866 + abstract_pkg_t *apkg = depend->pkg;
9867 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9868 + int n_providers = provider_apkgs->len;
9869 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9870 + pkg_vec_t *pkg_vec;
9875 + for (i = 0; i < n_providers; i++) {
9876 + abstract_pkg_t *papkg = apkgs[i];
9877 + pkg_vec = papkg->pkgs;
9879 + n_pkgs = pkg_vec->len;
9880 + for (j = 0; j < n_pkgs; j++) {
9881 + pkg_t *pkg = pkg_vec->pkgs[j];
9882 + if (version_constraints_satisfied(depend, pkg)) {
9891 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9893 + abstract_pkg_t *apkg = depend->pkg;
9894 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9895 + int n_providers = provider_apkgs->len;
9896 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9901 + for (i = 0; i < n_providers; i++) {
9902 + abstract_pkg_t *papkg = apkgs[i];
9903 + pkg_vec_t *pkg_vec = papkg->pkgs;
9905 + n_pkgs = pkg_vec->len;
9906 + for (j = 0; j < n_pkgs; j++) {
9907 + pkg_t *pkg = pkg_vec->pkgs[j];
9908 + if (version_constraints_satisfied(depend, pkg)) {
9909 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9918 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9921 + pkg_t ** pkgs = vec->pkgs;
9923 + for(i = 0; i < vec->len; i++)
9924 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9925 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9926 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9934 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9935 + * the same abstract package and 0 otherwise.
9937 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9939 + abstract_pkg_t **provides = pkg->provides;
9940 + int provides_count = pkg->provides_count;
9941 + abstract_pkg_t **replacee_provides = replacee->provides;
9942 + int replacee_provides_count = replacee->provides_count;
9944 + for (i = 0; i < provides_count; i++) {
9945 + abstract_pkg_t *apkg = provides[i];
9946 + for (j = 0; j < replacee_provides_count; j++) {
9947 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9948 + if (apkg == replacee_apkg)
9957 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9958 + * and 0 otherwise.
9960 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9962 + abstract_pkg_t **provides = pkg->provides;
9963 + int provides_count = pkg->provides_count;
9965 + for (i = 0; i < provides_count; i++) {
9966 + if (provides[i] == providee)
9973 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9976 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9978 + abstract_pkg_t **replaces = pkg->replaces;
9979 + int replaces_count = pkg->replaces_count;
9980 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9981 + int replacee_provides_count = pkg->provides_count; */
9983 + for (i = 0; i < replaces_count; i++) {
9984 + abstract_pkg_t *abstract_replacee = replaces[i];
9985 + for (j = 0; j < replaces_count; j++) {
9986 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9987 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9988 + if (replacee->provides[j] == abstract_replacee)
9997 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
10000 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
10002 + compound_depend_t *conflicts = pkg->conflicts;
10003 + int conflicts_count = pkg->conflicts_count;
10005 + for (i = 0; i < conflicts_count; i++) {
10006 + int possibility_count = conflicts[i].possibility_count;
10007 + struct depend **possibilities = conflicts[i].possibilities;
10008 + for (j = 0; j < possibility_count; j++) {
10009 + if (possibilities[j]->pkg == conflictee) {
10018 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
10019 + * conflictee's provides and 0 otherwise.
10021 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
10023 + compound_depend_t *conflicts = pkg->conflicts;
10024 + int conflicts_count = pkg->conflicts_count;
10025 + abstract_pkg_t **conflictee_provides = conflictee->provides;
10026 + int conflictee_provides_count = conflictee->provides_count;
10028 + int possibility_count;
10029 + struct depend **possibilities;
10030 + abstract_pkg_t *possibility ;
10032 + for (i = 0; i < conflicts_count; i++) {
10033 + possibility_count = conflicts[i].possibility_count;
10034 + possibilities = conflicts[i].possibilities;
10035 + for (j = 0; j < possibility_count; j++) {
10036 + possibility = possibilities[j]->pkg;
10037 + for (k = 0; k < conflictee_provides_count; k++) {
10038 + if (possibility == conflictee_provides[k]) {
10047 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
10049 + int oldlen = 0, newlen = 0;
10051 + register int i, j;
10056 + while(oldstuff && oldstuff[oldlen]) oldlen++;
10057 + while(newstuff && newstuff[newlen]) newlen++;
10059 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
10060 + if (result == NULL) {
10061 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10065 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
10066 + *(result + i) = *(newstuff + j);
10068 + *(result + i) = NULL;
10074 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
10075 + * this is null terminated, no count is carried around
10077 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
10081 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
10084 + while(the_lost && the_lost[count]) count++;
10086 + count++; /* need one to hold the null */
10087 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
10088 + if (resized == NULL) {
10089 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10092 + resized[count - 1] = strdup(depend_str);
10093 + resized[count] = NULL;
10098 +void printDepends(pkg_t * pkg)
10100 + register int i, j;
10101 + compound_depend_t * depend;
10104 + count = pkg->pre_depends_count + pkg->depends_count;
10106 + depend = pkg->depends;
10108 + fprintf(stderr, "Depends pointer is NULL\n");
10111 + for(i = 0; i < count; i++){
10112 + fprintf(stderr, "%s has %d possibilities:\n",
10113 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
10114 + depend->possibility_count);
10115 + for(j = 0; j < depend->possibility_count; j++)
10116 + fprintf(stderr, "\t%s version %s (%d)\n",
10117 + depend->possibilities[j]->pkg->name,
10118 + depend->possibilities[j]->version,
10119 + depend->possibilities[j]->constraint);
10124 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10126 + register int i, j;
10128 + /* every pkg provides itself */
10129 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
10131 + if (!pkg->provides_count)
10134 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
10135 + if (pkg->provides == NULL) {
10136 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10139 + pkg->provides[0] = ab_pkg;
10141 + // if (strcmp(ab_pkg->name, pkg->name))
10142 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10144 + for(i = 0; i < pkg->provides_count; i++){
10145 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
10147 + pkg->provides[i+1] = provided_abpkg;
10150 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
10155 +/* Abhaya: added conflicts support */
10156 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10159 + compound_depend_t * conflicts;
10161 + if (!pkg->conflicts_count)
10164 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
10165 + pkg->conflicts_count);
10166 + if (conflicts == NULL) {
10167 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10170 + for (i = 0; i < pkg->conflicts_count; i++) {
10171 + conflicts->type = CONFLICTS;
10172 + parseDepends(conflicts, hash,
10173 + pkg->conflicts_str[i]);
10175 + for (j = 0; j < conflicts->possibility_count; j++) {
10176 + depend_t *possibility = conflicts->possibilities[j];
10177 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
10178 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
10186 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
10188 + register int i, j;
10190 + if (!pkg->replaces_count)
10193 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
10194 + if (pkg->replaces == NULL) {
10195 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10199 + // if (strcmp(ab_pkg->name, pkg->name))
10200 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
10202 + for(i = 0; i < pkg->replaces_count; i++){
10203 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
10205 + pkg->replaces[i] = old_abpkg;
10208 + if (!old_abpkg->replaced_by)
10209 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
10210 + if ( old_abpkg->replaced_by == NULL ){
10213 + /* if a package pkg both replaces and conflicts old_abpkg,
10214 + * then add it to the replaced_by vector so that old_abpkg
10215 + * will be upgraded to ab_pkg automatically */
10216 + if (pkg_conflicts_abstract(pkg, old_abpkg))
10217 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
10222 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
10226 + compound_depend_t * depends;
10228 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
10231 + if (0 && pkg->pre_depends_count)
10232 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10233 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10234 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
10235 + if (depends == NULL) {
10236 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10241 + for(i = 0; i < pkg->pre_depends_count; i++){
10242 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10243 + if (0 && pkg->pre_depends_count)
10244 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10245 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10246 + depends->type = PREDEPEND;
10250 + for(i = 0; i < pkg->recommends_count; i++){
10251 + parseDepends(depends, hash, pkg->recommends_str[i]);
10252 + if (0 && pkg->recommends_count)
10253 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10254 + pkg->recommends_str[i], depends, depends->possibility_count);
10255 + depends->type = RECOMMEND;
10259 + for(i = 0; i < pkg->suggests_count; i++){
10260 + parseDepends(depends, hash, pkg->suggests_str[i]);
10261 + if (0 && pkg->suggests_count)
10262 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10263 + pkg->suggests_str[i], depends, depends->possibility_count);
10264 + depends->type = SUGGEST;
10268 + for(i = 0; i < pkg->depends_count; i++){
10269 + parseDepends(depends, hash, pkg->depends_str[i]);
10270 + if (0 && pkg->depends_count)
10271 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10272 + pkg->depends_str[i], depends, depends->possibility_count);
10279 + * pkg_depend_string: returns the depends string specified by index.
10280 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10281 + * [0,npredepends) -> returns pre_depends_str[index]
10282 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10283 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10284 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10286 +char *pkg_depend_str(pkg_t *pkg, int index)
10288 + if (index < pkg->pre_depends_count) {
10289 + return pkg->pre_depends_str[index];
10291 + index -= pkg->pre_depends_count;
10293 + if (index < pkg->recommends_count) {
10294 + return pkg->recommends_str[index];
10296 + index -= pkg->recommends_count;
10298 + if (index < pkg->suggests_count) {
10299 + return pkg->suggests_str[index];
10301 + index -= pkg->suggests_count;
10303 + if (index < pkg->depends_count) {
10304 + return pkg->depends_str[index];
10306 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
10310 +void freeDepends(pkg_t *pkg)
10314 + if (pkg == NULL || pkg->depends == NULL) {
10318 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10319 + for (i=0; i < pkg->depends->possibility_count; i++) {
10320 + depend_deinit(pkg->depends->possibilities[i]);
10322 + free(pkg->depends->possibilities);
10323 + free(pkg->depends);
10324 + pkg->depends = NULL;
10327 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10329 + compound_depend_t * depends;
10330 + int count, othercount;
10331 + register int i, j;
10332 + abstract_pkg_t * ab_depend;
10333 + abstract_pkg_t ** temp;
10335 + count = pkg->pre_depends_count + pkg->depends_count;
10336 + depends = pkg->depends;
10338 + if (0 && pkg->pre_depends_count)
10339 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10340 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10341 + for (i = 0; i < count; i++) {
10342 + if (0 && pkg->pre_depends_count)
10343 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10344 + for (j = 0; j < depends->possibility_count; j++){
10345 + ab_depend = depends->possibilities[j]->pkg;
10346 + if(!ab_depend->depended_upon_by)
10347 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10349 + temp = ab_depend->depended_upon_by;
10357 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10358 + (othercount + 1) * sizeof(abstract_pkg_t *));
10359 + /* the array may have moved */
10360 + temp = ab_depend->depended_upon_by + othercount;
10367 +static depend_t * depend_init(void)
10369 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10371 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10374 + d->constraint = NONE;
10375 + d->version = NULL;
10381 +static void depend_deinit(depend_t *d)
10386 +static int parseDepends(compound_depend_t *compound_depend,
10387 + hash_table_t * hash, char * depend_str)
10389 + char * pkg_name, buffer[2048];
10390 + int num_of_ors = 0;
10392 + register char * src, * dest;
10393 + depend_t ** possibilities;
10395 + /* first count the number of ored possibilities for satisfying dependency */
10396 + src = depend_str;
10398 + if(*src++ == '|')
10401 + compound_depend->type = DEPEND;
10403 + compound_depend->possibility_count = num_of_ors + 1;
10404 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10405 + if (!possibilities)
10407 + compound_depend->possibilities = possibilities;
10409 + src = depend_str;
10410 + for(i = 0; i < num_of_ors + 1; i++){
10411 + possibilities[i] = depend_init();
10412 + if (!possibilities[i])
10414 + /* gobble up just the name first */
10417 + !isspace(*src) &&
10421 + *dest++ = *src++;
10423 + pkg_name = trim_alloc(buffer);
10424 + if (pkg_name == NULL )
10427 + /* now look at possible version info */
10429 + /* skip to next chars */
10430 + if(isspace(*src))
10431 + while(*src && isspace(*src)) src++;
10433 + /* extract constraint and version */
10436 + if(!strncmp(src, "<<", 2)){
10437 + possibilities[i]->constraint = EARLIER;
10440 + else if(!strncmp(src, "<=", 2)){
10441 + possibilities[i]->constraint = EARLIER_EQUAL;
10444 + else if(!strncmp(src, ">=", 2)){
10445 + possibilities[i]->constraint = LATER_EQUAL;
10448 + else if(!strncmp(src, ">>", 2)){
10449 + possibilities[i]->constraint = LATER;
10452 + else if(!strncmp(src, "=", 1)){
10453 + possibilities[i]->constraint = EQUAL;
10456 + /* should these be here to support deprecated designations; dpkg does */
10457 + else if(!strncmp(src, "<", 1)){
10458 + possibilities[i]->constraint = EARLIER_EQUAL;
10461 + else if(!strncmp(src, ">", 1)){
10462 + possibilities[i]->constraint = LATER_EQUAL;
10466 + /* now we have any constraint, pass space to version string */
10467 + while(isspace(*src)) src++;
10469 + /* this would be the version string */
10471 + while(*src && *src != ')')
10472 + *dest++ = *src++;
10475 + possibilities[i]->version = trim_alloc(buffer);
10476 + /* fprintf(stderr, "let's print the depends version string:");
10477 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10478 + if (possibilities[i]->version == NULL )
10483 + /* hook up the dependency to its abstract pkg */
10484 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10488 + /* now get past the ) and any possible | chars */
10490 + (isspace(*src) ||
10496 + compound_depend->type = GREEDY_DEPEND;
10503 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
10504 --- busybox-1.2.0-orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
10505 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_depends.h 2006-07-22 16:31:25.000000000 +0200
10507 +/* pkg_depends.h - the itsy package management system
10511 + Copyright (C) 2002 Compaq Computer Corporation
10513 + This program is free software; you can redistribute it and/or
10514 + modify it under the terms of the GNU General Public License as
10515 + published by the Free Software Foundation; either version 2, or (at
10516 + your option) any later version.
10518 + This program is distributed in the hope that it will be useful, but
10519 + WITHOUT ANY WARRANTY; without even the implied warranty of
10520 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10521 + General Public License for more details.
10524 +#ifndef PKG_DEPENDS_H
10525 +#define PKG_DEPENDS_H
10528 +#include "pkg_hash.h"
10530 +enum depend_type {
10538 +typedef enum depend_type depend_type_t;
10540 +enum version_constraint {
10548 +typedef enum version_constraint version_constraint_t;
10551 + version_constraint_t constraint;
10553 + abstract_pkg_t * pkg;
10555 +typedef struct depend depend_t;
10557 +struct compound_depend{
10558 + depend_type_t type;
10559 + int possibility_count;
10560 + struct depend ** possibilities;
10562 +typedef struct compound_depend compound_depend_t;
10564 +#include "hash_table.h"
10566 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10567 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10568 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10569 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10572 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10573 + * the same abstract package and 0 otherwise.
10575 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10578 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10581 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10584 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10587 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10590 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10593 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10596 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10599 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10601 +char *pkg_depend_str(pkg_t *pkg, int index);
10602 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10603 +void freeDepends(pkg_t *pkg);
10604 +void printDepends(pkg_t * pkg);
10605 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10606 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10607 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10608 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10609 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10612 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
10613 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
10614 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.c 2006-07-22 16:31:25.000000000 +0200
10616 +/* pkg_dest.c - the itsy package management system
10620 + Copyright (C) 2001 University of Southern California
10622 + This program is free software; you can redistribute it and/or
10623 + modify it under the terms of the GNU General Public License as
10624 + published by the Free Software Foundation; either version 2, or (at
10625 + your option) any later version.
10627 + This program is distributed in the hope that it will be useful, but
10628 + WITHOUT ANY WARRANTY; without even the implied warranty of
10629 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10630 + General Public License for more details.
10635 +#include "pkg_dest.h"
10636 +#include "file_util.h"
10637 +#include "str_util.h"
10638 +#include "sprintf_alloc.h"
10640 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10642 + dest->name = strdup(name);
10644 + /* Guarantee that dest->root_dir ends with a '/' */
10645 + if (str_ends_with(root_dir, "/")) {
10646 + dest->root_dir = strdup(root_dir);
10648 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10650 + file_mkdir_hier(dest->root_dir, 0755);
10652 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10653 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10654 + file_mkdir_hier(dest->ipkg_dir, 0755);
10656 + if (str_starts_with (lists_dir, "/"))
10657 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10659 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10661 + file_mkdir_hier(dest->lists_dir, 0755);
10663 + sprintf_alloc(&dest->info_dir, "%s/%s",
10664 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10665 + file_mkdir_hier(dest->info_dir, 0755);
10667 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10668 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10670 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10671 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10673 + dest->status_file = NULL;
10678 +void pkg_dest_deinit(pkg_dest_t *dest)
10680 + free(dest->name);
10681 + dest->name = NULL;
10683 + free(dest->root_dir);
10684 + dest->root_dir = NULL;
10686 + free(dest->ipkg_dir);
10687 + dest->ipkg_dir = NULL;
10689 + free(dest->lists_dir);
10690 + dest->lists_dir = NULL;
10692 + free(dest->info_dir);
10693 + dest->info_dir = NULL;
10695 + free(dest->status_file_name);
10696 + dest->status_file_name = NULL;
10698 + free(dest->status_file_tmp_name);
10699 + dest->status_file_tmp_name = NULL;
10701 + if (dest->status_file) {
10702 + fclose(dest->status_file);
10704 + dest->status_file = NULL;
10706 + dest->root_dir = NULL;
10708 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
10709 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
10710 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest.h 2006-07-22 16:31:25.000000000 +0200
10712 +/* pkg_dest.h - the itsy package management system
10716 + Copyright (C) 2001 University of Southern California
10718 + This program is free software; you can redistribute it and/or
10719 + modify it under the terms of the GNU General Public License as
10720 + published by the Free Software Foundation; either version 2, or (at
10721 + your option) any later version.
10723 + This program is distributed in the hope that it will be useful, but
10724 + WITHOUT ANY WARRANTY; without even the implied warranty of
10725 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10726 + General Public License for more details.
10729 +#ifndef PKG_DEST_H
10730 +#define PKG_DEST_H
10732 +typedef struct pkg_dest pkg_dest_t;
10740 + char *status_file_name;
10741 + char *status_file_tmp_name;
10742 + FILE *status_file;
10745 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10746 +void pkg_dest_deinit(pkg_dest_t *dest);
10750 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
10751 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
10752 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.c 2006-07-22 16:31:25.000000000 +0200
10754 +/* pkg_dest_list.c - the itsy package management system
10758 + Copyright (C) 2001 University of Southern California
10760 + This program is free software; you can redistribute it and/or
10761 + modify it under the terms of the GNU General Public License as
10762 + published by the Free Software Foundation; either version 2, or (at
10763 + your option) any later version.
10765 + This program is distributed in the hope that it will be useful, but
10766 + WITHOUT ANY WARRANTY; without even the implied warranty of
10767 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10768 + General Public License for more details.
10773 +#include "pkg_dest.h"
10774 +#include "void_list.h"
10775 +#include "pkg_dest_list.h"
10777 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10779 + return void_list_elt_init((void_list_elt_t *) elt, data);
10782 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10784 + void_list_elt_deinit((void_list_elt_t *) elt);
10787 +int pkg_dest_list_init(pkg_dest_list_t *list)
10789 + return void_list_init((void_list_t *) list);
10792 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10794 + pkg_dest_list_elt_t *iter;
10795 + pkg_dest_t *pkg_dest;
10797 + for (iter = list->head; iter; iter = iter->next) {
10798 + pkg_dest = iter->data;
10799 + pkg_dest_deinit(pkg_dest);
10801 + /* malloced in pkg_dest_list_append */
10803 + iter->data = NULL;
10805 + void_list_deinit((void_list_t *) list);
10808 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10809 + const char *root_dir,const char *lists_dir)
10812 + pkg_dest_t *pkg_dest;
10814 + /* freed in plg_dest_list_deinit */
10815 + pkg_dest = malloc(sizeof(pkg_dest_t));
10816 + if (pkg_dest == NULL) {
10817 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10821 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10822 + err = void_list_append((void_list_t *) list, pkg_dest);
10830 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10832 + return void_list_push((void_list_t *) list, data);
10835 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10837 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10839 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
10840 --- busybox-1.2.0-orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
10841 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_dest_list.h 2006-07-22 16:31:25.000000000 +0200
10843 +/* pkg_dest_list.h - the itsy package management system
10847 + Copyright (C) 2001 University of Southern California
10849 + This program is free software; you can redistribute it and/or
10850 + modify it under the terms of the GNU General Public License as
10851 + published by the Free Software Foundation; either version 2, or (at
10852 + your option) any later version.
10854 + This program is distributed in the hope that it will be useful, but
10855 + WITHOUT ANY WARRANTY; without even the implied warranty of
10856 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10857 + General Public License for more details.
10860 +#ifndef PKG_DEST_LIST_H
10861 +#define PKG_DEST_LIST_H
10863 +#include "pkg_dest.h"
10865 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10866 +struct pkg_dest_list_elt
10868 + pkg_dest_list_elt_t *next;
10869 + pkg_dest_t *data;
10872 +typedef struct pkg_dest_list pkg_dest_list_t;
10873 +struct pkg_dest_list
10875 + pkg_dest_list_elt_t pre_head;
10876 + pkg_dest_list_elt_t *head;
10877 + pkg_dest_list_elt_t *tail;
10880 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10881 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10883 +int pkg_dest_list_init(pkg_dest_list_t *list);
10884 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10886 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10887 + const char *root_dir,const char* lists_dir);
10888 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10889 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10893 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
10894 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
10895 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.c 2006-07-22 16:31:25.000000000 +0200
10897 +/* pkg_extract.c - the itsy package management system
10901 + Copyright (C) 2001 University of Southern California
10903 + This program is free software; you can redistribute it and/or
10904 + modify it under the terms of the GNU General Public License as
10905 + published by the Free Software Foundation; either version 2, or (at
10906 + your option) any later version.
10908 + This program is distributed in the hope that it will be useful, but
10909 + WITHOUT ANY WARRANTY; without even the implied warranty of
10910 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10911 + General Public License for more details.
10915 +#include <errno.h>
10916 +#include <fcntl.h>
10917 +#include <stdio.h>
10919 +#include "pkg_extract.h"
10921 +#include "libbb.h"
10922 +#include "file_util.h"
10923 +#include "sprintf_alloc.h"
10924 +#include "unarchive.h"
10926 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10927 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10928 +#define IPKG_CONTROL_FILE "control"
10930 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10932 + archive_handle_t *archive;
10935 + sprintf_alloc(&path, "%s/", dir);
10936 + archive = init_handle();
10937 + archive->src_fd = bb_xopen(pkg->local_filename, O_RDONLY);
10938 + archive->filter = filter_accept_list;
10939 + llist_add_to(&(archive->accept), (char *)filename);
10940 + archive->buffer = path;
10941 + archive->action_data = data_extract_all_prefix;
10942 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10943 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10944 + close(archive->src_fd);
10945 + free(archive->accept);
10950 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10952 + unsigned int size = strlen(archive->file_header->name) + 2;
10954 + if (archive->buffer == NULL) {
10955 + archive->buffer = xmalloc(size);
10956 + strcpy(archive->buffer, archive->file_header->name);
10958 + size += strlen(archive->buffer);
10959 + archive->buffer = xrealloc(archive->buffer, size);
10960 + strcat(archive->buffer, archive->file_header->name);
10962 + strcat(archive->buffer, "\n");
10963 + data_skip(archive);
10966 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10968 + archive_handle_t *archive;
10971 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10972 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10973 + archive = init_handle();
10974 + archive->src_fd = bb_xopen(name, O_RDONLY);
10975 + archive->filter = filter_accept_list;
10976 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10977 + archive->action_data = data_extract_to_buffer;
10978 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10979 + close(archive->src_fd);
10980 + fputs(archive->buffer, stream);
10981 + free(archive->buffer);
10982 + free(archive->accept);
10989 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10991 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10994 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10996 + archive_handle_t *archive;
11000 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
11001 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
11002 + sprintf_alloc(&path, "%s/%s", dir, prefix);
11003 + archive = init_handle();
11004 + archive->src_fd = bb_xopen(name, O_RDONLY);
11005 + archive->filter = filter_accept_all;
11006 + archive->buffer = path;
11007 + archive->action_data = data_extract_all_prefix;
11008 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11009 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11010 + close(archive->src_fd);
11018 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
11020 + archive_handle_t *archive;
11024 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11025 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11026 + sprintf_alloc(&path, "%s/", dir);
11027 + archive = init_handle();
11028 + archive->src_fd = bb_xopen(name, O_RDONLY);
11029 + archive->filter = filter_accept_all;
11030 + archive->buffer = path;
11031 + archive->action_data = data_extract_all_prefix;
11032 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
11033 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11034 + close(archive->src_fd);
11042 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
11045 + char *line, *data_file;
11049 + file = fopen(file_name, "w");
11050 + if (file == NULL) {
11051 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
11052 + __FUNCTION__, file_name);
11057 + if (pkg->installed_files) {
11058 + str_list_elt_t *elt;
11059 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
11060 + fprintf(file, "%s\n", elt->data);
11063 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
11070 + /* Fixup data file names by removing the initial '.' */
11073 + line = file_read_line_alloc(tmp);
11074 + if (line == NULL) {
11078 + data_file = line;
11079 + if (*data_file == '.') {
11083 + if (*data_file != '/') {
11084 + fputs("/", file);
11087 + /* I have no idea why, but this is what dpkg does */
11088 + if (strcmp(data_file, "/\n") == 0) {
11089 + fputs("/.\n", file);
11091 + fputs(data_file, file);
11101 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
11103 + archive_handle_t *archive;
11106 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
11107 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
11108 + archive = init_handle();
11109 + archive->src_fd = bb_xopen(name, O_RDONLY);
11110 + archive->filter = filter_accept_all;
11111 + archive->action_data = data_extract_file_name_to_buffer;
11112 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
11113 + close(archive->src_fd);
11114 + fputs(archive->buffer, file);
11115 + free(archive->buffer);
11121 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
11122 --- busybox-1.2.0-orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
11123 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_extract.h 2006-07-22 16:31:25.000000000 +0200
11125 +/* pkg_extract.c - the itsy package management system
11129 + Copyright (C) 2001 University of Southern California
11131 + This program is free software; you can redistribute it and/or
11132 + modify it under the terms of the GNU General Public License as
11133 + published by the Free Software Foundation; either version 2, or (at
11134 + your option) any later version.
11136 + This program is distributed in the hope that it will be useful, but
11137 + WITHOUT ANY WARRANTY; without even the implied warranty of
11138 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11139 + General Public License for more details.
11142 +#ifndef PKG_EXTRACT_H
11143 +#define PKG_EXTRACT_H
11147 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
11148 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
11149 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
11151 + const char *prefix);
11152 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
11153 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
11154 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
11157 diff -ruN busybox-1.2.0-orig/archival/libipkg/pkg.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h
11158 --- busybox-1.2.0-orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
11159 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg.h 2006-07-22 16:31:25.000000000 +0200
11161 +/* pkg.h - the itsy package management system
11165 + Copyright (C) 2001 University of Southern California
11167 + This program is free software; you can redistribute it and/or
11168 + modify it under the terms of the GNU General Public License as
11169 + published by the Free Software Foundation; either version 2, or (at
11170 + your option) any later version.
11172 + This program is distributed in the hope that it will be useful, but
11173 + WITHOUT ANY WARRANTY; without even the implied warranty of
11174 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11175 + General Public License for more details.
11181 +#include <sys/types.h>
11182 +#include <sys/stat.h>
11183 +#include <unistd.h>
11185 +#include "pkg_vec.h"
11186 +#include "str_list.h"
11187 +#include "pkg_src.h"
11188 +#include "pkg_dest.h"
11189 +#include "ipkg_conf.h"
11190 +#include "conffile_list.h"
11195 +#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
11197 +/* I think "Size" is currently the shortest field name */
11198 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
11200 +enum pkg_state_want
11206 + SW_LAST_STATE_WANT
11208 +typedef enum pkg_state_want pkg_state_want_t;
11210 +enum pkg_state_flag
11213 + SF_REINSTREQ = 1,
11214 + SF_HOLD = 2, /* do not upgrade version */
11215 + SF_REPLACE = 4, /* replace this package */
11216 + SF_NOPRUNE = 8, /* do not remove obsolete files */
11217 + SF_PREFER = 16, /* prefer this version */
11218 + SF_OBSOLETE = 32, /* old package in upgrade pair */
11219 + SF_MARKED = 64, /* temporary mark */
11220 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
11222 + SF_LAST_STATE_FLAG
11224 +typedef enum pkg_state_flag pkg_state_flag_t;
11225 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
11227 +enum pkg_state_status
11229 + SS_NOT_INSTALLED = 1,
11231 + SS_HALF_CONFIGURED,
11233 + SS_HALF_INSTALLED,
11235 + SS_POST_INST_FAILED,
11236 + SS_REMOVAL_FAILED,
11237 + SS_LAST_STATE_STATUS
11239 +typedef enum pkg_state_status pkg_state_status_t;
11241 +struct abstract_pkg{
11243 + int dependencies_checked;
11244 + pkg_vec_t * pkgs;
11245 + pkg_state_status_t state_status;
11246 + pkg_state_flag_t state_flag;
11247 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
11248 + abstract_pkg_vec_t * provided_by;
11249 + abstract_pkg_vec_t * replaced_by;
11252 +#include "pkg_depends.h"
11254 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11256 + The 3 version fields should go into a single version struct. (This
11257 + is especially important since, currently, pkg->version can easily
11258 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11259 + distinct. This has been the source of multiple bugs.
11261 + The 3 state fields could possibly also go into their own struct.
11263 + All fields which deal with lists of packages, (Depends,
11264 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11265 + be handled by a single struct in pkg_t
11267 + All string fields for which there is a small set of possible
11268 + values, (section, maintainer, architecture, maybe version?), that
11269 + are reused among different packages -- for all such packages we
11270 + should move from "char *"s to some atom datatype to share data
11271 + storage and use less memory. We might even do reference counting,
11272 + but probably not since most often we only create new pkg_t structs,
11273 + we don't often free them. */
11277 + unsigned long epoch;
11280 + char *familiar_revision;
11282 + pkg_dest_t *dest;
11283 + char *architecture;
11285 + char *maintainer;
11286 + char *description;
11287 + pkg_state_want_t state_want;
11288 + pkg_state_flag_t state_flag;
11289 + pkg_state_status_t state_status;
11290 + char **depends_str;
11291 + int depends_count;
11292 + char **pre_depends_str;
11293 + int pre_depends_count;
11294 + char **recommends_str;
11295 + int recommends_count;
11296 + char **suggests_str;
11297 + int suggests_count;
11298 + compound_depend_t * depends;
11300 + /* Abhaya: new conflicts */
11301 + char **conflicts_str;
11302 + compound_depend_t * conflicts;
11303 + int conflicts_count;
11305 + char **replaces_str;
11306 + int replaces_count;
11307 + abstract_pkg_t ** replaces;
11309 + char **provides_str;
11310 + int provides_count;
11311 + abstract_pkg_t ** provides;
11313 + abstract_pkg_t *parent;
11315 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11318 + char *local_filename;
11320 + char *tmp_unpack_dir;
11323 + char *installed_size;
11326 + conffile_list_t conffiles;
11327 + time_t installed_time;
11328 + /* As pointer for lazy evaluation */
11329 + str_list_t *installed_files;
11330 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11331 + mechanism to avoid the problem here, (which is that the
11332 + installed_files list was being freed from an inner loop while
11333 + still being used within an outer loop. */
11334 + int installed_files_ref_cnt;
11336 + int arch_priority;
11337 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11338 + int provided_by_hand;
11341 +pkg_t *pkg_new(void);
11342 +int pkg_init(pkg_t *pkg);
11343 +void pkg_deinit(pkg_t *pkg);
11344 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11345 +abstract_pkg_t *abstract_pkg_new(void);
11346 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11349 + * merges fields from newpkg into oldpkg.
11350 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11352 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11354 +char *pkg_version_str_alloc(pkg_t *pkg);
11356 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11357 +int pkg_name_version_and_architecture_compare(void *a, void *b);
11358 +int abstract_pkg_name_compare(void *a, void *b);
11360 +char * pkg_formatted_info(pkg_t *pkg );
11361 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11363 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11365 +void pkg_print_info(pkg_t *pkg, FILE *file);
11366 +void pkg_print_status(pkg_t * pkg, FILE * file);
11367 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11368 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11369 +int pkg_free_installed_files(pkg_t *pkg);
11370 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11371 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11372 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11373 + const char *script, const char *args);
11375 +/* enum mappings */
11376 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11377 +pkg_state_want_t pkg_state_want_from_str(char *str);
11378 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11379 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11380 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11381 +pkg_state_status_t pkg_state_status_from_str(char *str);
11383 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11385 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11386 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11387 +int pkg_free_installed_files(pkg_t *pkg);
11389 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11390 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11393 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
11394 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
11395 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.c 2006-07-22 16:31:25.000000000 +0200
11397 +/* ipkg_hash.c - the itsy package management system
11401 + Copyright (C) 2002 Compaq Computer Corporation
11403 + This program is free software; you can redistribute it and/or
11404 + modify it under the terms of the GNU General Public License as
11405 + published by the Free Software Foundation; either version 2, or (at
11406 + your option) any later version.
11408 + This program is distributed in the hope that it will be useful, but
11409 + WITHOUT ANY WARRANTY; without even the implied warranty of
11410 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11411 + General Public License for more details.
11415 +#include <errno.h>
11416 +#include <ctype.h>
11417 +#include <stdlib.h>
11418 +#include <string.h>
11420 +#include "hash_table.h"
11422 +#include "ipkg_message.h"
11423 +#include "pkg_vec.h"
11424 +#include "pkg_hash.h"
11425 +#include "pkg_parse.h"
11426 +#include "ipkg_utils.h"
11428 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11431 + * this will talk to both feeds-lists files and installed status files
11434 + * hash_table_t hash;
11435 + * pkg_hash_init(name, &hash, 1000);
11436 + * pkg_hash_add_from_file(<feed filename>);
11438 + * the query function is just there as a shell to prove to me that this
11439 + * sort of works, but isn't far from doing something useful
11442 + * modified: CDW 3 Jan. 2002
11447 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11449 + return hash_table_init(name, hash, len);
11452 +void pkg_hash_deinit(hash_table_t *hash)
11454 + hash_table_deinit(hash);
11458 +/* Find the default arch for a given package status file if none is given. */
11459 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11461 + nv_pair_list_elt_t *l;
11462 + char *def_arch = HOST_CPU_STR; /* Default arch */
11463 + int def_prio = 0; /* Other archs override this */
11465 + l = conf->arch_list.head;
11468 + nv_pair_t *nv = l->data;
11469 + int priority = strtol(nv->value, NULL, 0);
11471 + /* Check if this arch has higher priority, and is valid */
11472 + if ((priority > def_prio) &&
11473 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11474 + /* Our new default */
11475 + def_prio = priority;
11476 + def_arch = nv->name;
11481 + return strdup(def_arch);
11484 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11485 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11487 + hash_table_t *hash = &conf->pkg_hash;
11489 + char **raw_start;
11492 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11496 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11501 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11502 + if (!pkg->architecture) {
11503 + char *version_str = pkg_version_str_alloc(pkg);
11504 + pkg->architecture = pkg_get_default_arch(conf);
11505 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11506 + pkg->name, version_str, pkg->architecture);
11507 + free(version_str);
11509 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11515 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11516 + memory after read_raw_pkgs_from_file */
11525 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11527 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11530 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11532 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11535 + return apkg->provided_by;
11539 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11540 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11543 + int nprovides = 0;
11544 + int nmatching = 0;
11545 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11546 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11547 + abstract_pkg_vec_t *provided_apkg_vec;
11548 + abstract_pkg_t **provided_apkgs;
11549 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11550 + pkg_t *latest_installed_parent = NULL;
11551 + pkg_t *latest_matching = NULL;
11552 + pkg_t *held_pkg = NULL;
11553 + pkg_t *good_pkg_by_name = NULL;
11555 + if (matching_apkgs == NULL || providers == NULL ||
11556 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11559 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11561 + provided_apkg_vec = apkg->provided_by;
11562 + nprovides = provided_apkg_vec->len;
11563 + provided_apkgs = provided_apkg_vec->pkgs;
11564 + if (nprovides > 1)
11565 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11567 + /* accumulate all the providers */
11568 + for (i = 0; i < nprovides; i++) {
11569 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11570 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11571 + abstract_pkg_vec_insert(providers, provider_apkg);
11573 + nprovides = providers->len;
11575 + for (i = 0; i < nprovides; i++) {
11576 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11577 + abstract_pkg_t *replacement_apkg = NULL;
11580 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11581 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11582 + if (provider_apkg->replaced_by->len > 1) {
11583 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11584 + provider_apkg->name, replacement_apkg->name);
11588 + if (replacement_apkg)
11589 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11590 + replacement_apkg->name, provider_apkg->name);
11592 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11593 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11596 + provider_apkg = replacement_apkg;
11599 + if (!(vec = provider_apkg->pkgs)) {
11600 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11605 + /* now check for supported architecture */
11607 + int max_count = 0;
11610 + /* count packages matching max arch priority and keep track of last one */
11611 + for (i = 0; i < vec->len; i++) {
11612 + pkg_t *maybe = vec->pkgs[i];
11613 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11614 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11615 + if (maybe->arch_priority > 0) {
11617 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11618 + pkg_vec_insert(matching_pkgs, maybe);
11624 + if (matching_pkgs->len > 1)
11625 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11626 + if (matching_apkgs->len > 1)
11627 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11629 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11630 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11631 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11632 + Until now I always got the latest, but that breaks the downgrade option.
11633 + If I stop at the first one, I would probably miss the new ones
11634 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11635 + or from a Packages feed.
11636 + 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*/
11639 + for (i = 0; i < matching_pkgs->len; i++) {
11640 + pkg_t *matching = matching_pkgs->pkgs[i];
11641 + if (constraint_fcn(matching, cdata)) { /* We found it */
11642 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11643 + good_pkg_by_name = matching;
11644 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11650 + for (i = 0; i < matching_pkgs->len; i++) {
11651 + pkg_t *matching = matching_pkgs->pkgs[i];
11652 + latest_matching = matching;
11653 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11654 + latest_installed_parent = matching;
11655 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11657 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11658 + held_pkg->name, matching->name);
11659 + held_pkg = matching;
11663 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11664 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11665 + apkg->name, matching_apkgs->len);
11666 + for (i = 0; i < matching_apkgs->len; i++) {
11667 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11668 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11670 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11673 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11674 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11675 + __FUNCTION__, apkg->name, matching_pkgs->len);
11676 + for (i = 0; i < matching_pkgs->len; i++) {
11677 + pkg_t *matching = matching_pkgs->pkgs[i];
11678 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11679 + matching->name, matching->version, matching->architecture);
11683 + nmatching = matching_apkgs->len;
11685 + pkg_vec_free(matching_pkgs);
11686 + abstract_pkg_vec_free(matching_apkgs);
11687 + abstract_pkg_vec_free(providers);
11689 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11690 + return good_pkg_by_name;
11693 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11696 + if (latest_installed_parent) {
11697 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11698 + return latest_installed_parent;
11700 + if (nmatching > 1) {
11701 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11704 + if (latest_matching) {
11705 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11706 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11707 + return latest_matching;
11712 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11714 + const char *name = (const char *)cdata;
11715 + if (strcmp(pkg->name, name) == 0)
11721 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11723 + hash_table_t *hash = &conf->pkg_hash;
11724 + abstract_pkg_t *apkg = NULL;
11726 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11729 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11733 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11734 + const char *pkg_name,
11735 + const char * version)
11739 + char *version_str = NULL;
11741 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11744 + for(i = 0; i < vec->len; i++) {
11745 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11746 + if(!strcmp(version_str, version)) {
11747 + free(version_str);
11750 + free(version_str);
11753 + if(i == vec->len)
11756 + return vec->pkgs[i];
11759 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11760 + const char *pkg_name,
11761 + pkg_dest_t *dest)
11766 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11770 + for(i = 0; i < vec->len; i++)
11771 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11772 + return vec->pkgs[i];
11777 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11778 + const char *pkg_name)
11783 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11787 + for(i = 0; i < vec->len; i++)
11788 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11789 + return vec->pkgs[i];
11795 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11797 + abstract_pkg_t * ab_pkg;
11799 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11803 + if (ab_pkg->pkgs) {
11804 + return ab_pkg->pkgs;
11805 + } else if (ab_pkg->provided_by) {
11806 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11807 + if (abpkg != NULL){
11808 + return abpkg->pkgs;
11810 + return ab_pkg->pkgs;
11817 +static int pkg_compare_names(const void *p1, const void *p2)
11819 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11820 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11821 + if (pkg1->name == NULL)
11823 + if (pkg2->name == NULL)
11825 + return(strcmp(pkg1->name, pkg2->name));
11829 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11832 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11833 + pkg_vec_t *all = (pkg_vec_t *)data;
11834 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11836 + for (j = 0; j < pkg_vec->len; j++) {
11837 + pkg_t *pkg = pkg_vec->pkgs[j];
11838 + pkg_vec_insert(all, pkg);
11843 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11845 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11846 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11849 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11851 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11852 + pkg_vec_t *all = (pkg_vec_t *)data;
11853 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11856 + for (j = 0; j < pkg_vec->len; j++) {
11857 + pkg_t *pkg = pkg_vec->pkgs[j];
11858 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11859 + pkg_vec_insert(all, pkg);
11864 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11866 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11867 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11870 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11874 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11875 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11876 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11877 + fprintf(stdout, "%s\n", ab_pkg->name);
11879 + if (dependents != NULL)
11880 + while (dependents [i] != NULL)
11881 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11882 + dependents = ab_pkg->provided_by->pkgs;
11884 + if (dependents != NULL)
11885 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11886 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11887 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11890 + while (i < pkg->depends_count)
11891 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11894 +void pkg_hash_dump(hash_table_t *hash, void *data)
11897 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11898 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11899 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11902 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11904 + abstract_pkg_t * ab_pkg;
11906 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11907 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11912 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11914 + abstract_pkg_t * ab_pkg;
11915 + int arch_priority;
11920 + arch_priority = pkg->arch_priority;
11922 + if (buildDepends(hash, pkg)<0){
11923 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11926 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11928 + if (set_status) {
11929 + if (pkg->state_status == SS_INSTALLED) {
11930 + ab_pkg->state_status = SS_INSTALLED;
11931 + } else if (pkg->state_status == SS_UNPACKED) {
11932 + ab_pkg->state_status = SS_UNPACKED;
11936 + if(!ab_pkg->pkgs)
11937 + ab_pkg->pkgs = pkg_vec_alloc();
11939 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11940 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11941 + pkg->parent = ab_pkg;
11943 + if (buildProvides(hash, ab_pkg, pkg)<0){
11944 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11947 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11948 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11949 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11952 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11953 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11957 + buildDependedUponBy(pkg, ab_pkg);
11962 + * this will assume that we've already determined that
11963 + * the abstract pkg doesn't exist, 'cause we should know these things...
11965 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11967 + abstract_pkg_t * ab_pkg;
11969 + ab_pkg = abstract_pkg_new();
11970 + if (ab_pkg == NULL) { return NULL; }
11972 + ab_pkg->name = strdup(pkg_name);
11973 + hash_table_insert(hash, pkg_name, ab_pkg);
11979 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11981 + hash_table_t *file_hash = &conf->file_hash;
11983 + return hash_table_get(file_hash, file_name);
11986 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11988 + hash_table_t *file_hash = &conf->file_hash;
11989 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11990 + int file_name_len = strlen(file_name);
11992 + if (file_name[file_name_len -1] == '/')
11995 + if (conf->offline_root) {
11996 + int len = strlen(conf->offline_root);
11997 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11998 + file_name += len;
12002 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
12003 + hash_table_insert(file_hash, file_name, owning_pkg);
12004 + if (old_owning_pkg) {
12005 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
12006 + /* mark this package to have its filelist written */
12007 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12008 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
12014 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
12015 --- busybox-1.2.0-orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
12016 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_hash.h 2006-07-22 16:31:25.000000000 +0200
12018 +/* pkg_hash.h - the itsy package management system
12022 + Copyright (C) 2002 Compaq Computer Corporation
12024 + This program is free software; you can redistribute it and/or
12025 + modify it under the terms of the GNU General Public License as
12026 + published by the Free Software Foundation; either version 2, or (at
12027 + your option) any later version.
12029 + This program is distributed in the hope that it will be useful, but
12030 + WITHOUT ANY WARRANTY; without even the implied warranty of
12031 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12032 + General Public License for more details.
12035 +#ifndef PKG_HASH_H
12036 +#define PKG_HASH_H
12039 +#include "pkg_vec.h"
12040 +#include "hash_table.h"
12043 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
12044 +void pkg_hash_deinit(hash_table_t *hash);
12045 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
12047 +void pkg_hash_dump(hash_table_t *hash, void *data);
12048 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
12050 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
12051 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
12052 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
12054 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
12055 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
12056 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12057 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
12058 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
12059 + const char *pkg_name,
12060 + const char * version);
12061 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
12062 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
12063 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
12064 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
12065 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
12066 + const char *pkg_name);
12067 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
12068 + const char *pkg_name,
12069 + pkg_dest_t *dest);
12071 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
12072 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
12074 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
12075 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
12079 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
12080 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
12081 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.c 2006-07-22 16:31:25.000000000 +0200
12083 +/* pkg_parse.c - the itsy package management system
12087 + Copyright (C) 2002 Compaq Computer Corporation
12089 + This program is free software; you can redistribute it and/or
12090 + modify it under the terms of the GNU General Public License as
12091 + published by the Free Software Foundation; either version 2, or (at
12092 + your option) any later version.
12094 + This program is distributed in the hope that it will be useful, but
12095 + WITHOUT ANY WARRANTY; without even the implied warranty of
12096 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12097 + General Public License for more details.
12101 +#include <errno.h>
12102 +#include <ctype.h>
12105 +#include "ipkg_utils.h"
12106 +#include "pkg_parse.h"
12108 +int isGenericFieldType(char * type, char * line)
12110 + if(!strncmp(line, type, strlen(type)))
12115 +char * parseGenericFieldType(char * type, char * raw)
12117 + char * field_value = raw + (strlen(type) + 1);
12118 + return trim_alloc(field_value);
12121 +void parseStatus(pkg_t *pkg, char * raw)
12123 + char sw_str[64], sf_str[64], ss_str[64];
12125 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
12126 + pkg->state_want = pkg_state_want_from_str(sw_str);
12127 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
12128 + pkg->state_status = pkg_state_status_from_str(ss_str);
12131 +char ** parseDependsString(char * raw, int * depends_count)
12133 + char ** depends = NULL;
12134 + int line_count = 0;
12135 + char buff[2048], * dest;
12137 + while(raw && *raw && !isspace(*raw)) {
12141 + if(line_is_blank(raw)){
12142 + *depends_count = line_count;
12145 + while(raw && *raw){
12146 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
12148 + while(isspace(*raw)) raw++;
12151 + while((*raw != ',') && *raw)
12152 + *dest++ = *raw++;
12155 + depends[line_count] = trim_alloc(buff);
12156 + if(depends[line_count] ==NULL)
12162 + *depends_count = line_count;
12166 +void parseConffiles(pkg_t * pkg, char * raw)
12168 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
12170 + if(!strncmp(raw, "Conffiles:", 10))
12171 + raw += strlen("Conffiles:");
12173 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
12174 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
12175 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
12176 + while (*raw && isspace(*raw)) {
12179 + raw += strlen(file_name);
12180 + while (*raw && isspace(*raw)) {
12183 + raw += strlen(md5sum);
12187 +int parseVersion(pkg_t *pkg, char *raw)
12189 + char *colon, *eepochcolon;
12190 +#ifdef USE_DEBVERSION
12193 + unsigned long epoch;
12196 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
12200 + if (strncmp(raw, "Version:", 8) == 0) {
12203 + while (*raw && isspace(*raw)) {
12207 + colon= strchr(raw,':');
12209 + epoch= strtoul(raw,&eepochcolon,10);
12210 + if (colon != eepochcolon) {
12211 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
12215 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
12219 + pkg->epoch= epoch;
12224 + pkg->revision = "";
12225 + pkg->familiar_revision = "";
12227 + pkg->version= malloc(strlen(raw)+1);
12228 + if ( pkg->version == NULL ) {
12229 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12232 + strcpy(pkg->version, raw);
12234 +#ifdef USE_DEBVERSION
12235 + hyphen= strrchr(pkg->version,'-');
12239 + if (strncmp("fam", hyphen, 3) == 0) {
12240 + pkg->familiar_revision=hyphen+3;
12241 + hyphen= strrchr(pkg->version,'-');
12244 + pkg->revision = hyphen;
12247 + pkg->revision = hyphen;
12253 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12257 + pkg->familiar_revision);
12264 +/* This code is needed to insert in first position the keyword for the aligning bug */
12266 +int alterProvidesLine(char *raw, char *temp)
12271 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12275 + if ( temp == NULL ) {
12276 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12280 + if (strncmp(raw, "Provides:", 9) == 0) {
12283 + while (*raw && isspace(*raw)) {
12287 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12289 + strncat( temp, raw++, 1);
12295 +/* Some random thoughts from Carl:
12297 + This function could be considerably simplified if we just kept
12298 + an array of all the generic string-valued field names, and looped
12299 + through those looking for a match. Also, these fields could perhaps
12300 + be stored in the package as an array as well, (or, probably better,
12301 + as an nv_pair_list_t).
12303 + Fields which require special parsing or storage, (such as Depends:
12304 + and Status:) could be handled as they are now.
12306 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12307 + to a dependency list. And, since we already have
12308 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12309 + Enhances, perhaps we could generalize all of these and save some
12310 + code duplication.
12312 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12314 + int reading_conffiles, reading_description;
12315 + int pkg_false_provides=1;
12317 + char * provide=NULL;
12320 + pkg->dest = dest;
12322 + reading_conffiles = reading_description = 0;
12324 + for (lines = *raw; *lines; lines++) {
12325 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12326 + if(isGenericFieldType("Package:", *lines))
12327 + pkg->name = parseGenericFieldType("Package", *lines);
12328 + else if(isGenericFieldType("Architecture:", *lines))
12329 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12330 + else if(isGenericFieldType("Filename:", *lines))
12331 + pkg->filename = parseGenericFieldType("Filename", *lines);
12332 + else if(isGenericFieldType("Section:", *lines))
12333 + pkg->section = parseGenericFieldType("Section", *lines);
12334 + else if(isGenericFieldType("MD5sum:", *lines))
12335 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12336 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12337 + let's parse it either way */
12338 + else if(isGenericFieldType("MD5Sum:", *lines))
12339 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12340 + else if(isGenericFieldType("Size:", *lines))
12341 + pkg->size = parseGenericFieldType("Size", *lines);
12342 + else if(isGenericFieldType("Source:", *lines))
12343 + pkg->source = parseGenericFieldType("Source", *lines);
12344 + else if(isGenericFieldType("Installed-Size:", *lines))
12345 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12346 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12347 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12348 + pkg->installed_time = strtoul(time_str, NULL, 0);
12349 + } else if(isGenericFieldType("Priority:", *lines))
12350 + pkg->priority = parseGenericFieldType("Priority", *lines);
12351 + else if(isGenericFieldType("Essential:", *lines)) {
12352 + char *essential_value;
12353 + essential_value = parseGenericFieldType("Essential", *lines);
12354 + if (strcmp(essential_value, "yes") == 0) {
12355 + pkg->essential = 1;
12357 + free(essential_value);
12359 + else if(isGenericFieldType("Status", *lines))
12360 + parseStatus(pkg, *lines);
12361 + else if(isGenericFieldType("Version", *lines))
12362 + parseVersion(pkg, *lines);
12363 + else if(isGenericFieldType("Maintainer", *lines))
12364 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12365 + else if(isGenericFieldType("Conffiles", *lines)){
12366 + parseConffiles(pkg, *lines);
12367 + reading_conffiles = 1;
12369 + else if(isGenericFieldType("Description", *lines)) {
12370 + pkg->description = parseGenericFieldType("Description", *lines);
12371 + reading_conffiles = 0;
12372 + reading_description = 1;
12375 + else if(isGenericFieldType("Provides", *lines)){
12376 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12377 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12378 + if ( alterProvidesLine(*lines,provide) ){
12381 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12382 +/* Let's try to hack a bit here.
12383 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12384 + in alot of other places. We will remove it before writing down the status database */
12385 + pkg_false_provides=0;
12389 + else if(isGenericFieldType("Depends", *lines))
12390 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12391 + else if(isGenericFieldType("Pre-Depends", *lines))
12392 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12393 + else if(isGenericFieldType("Recommends", *lines))
12394 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12395 + else if(isGenericFieldType("Suggests", *lines))
12396 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12397 + /* Abhaya: support for conflicts */
12398 + else if(isGenericFieldType("Conflicts", *lines))
12399 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12400 + else if(isGenericFieldType("Replaces", *lines))
12401 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12402 + else if(line_is_blank(*lines)) {
12406 + else if(**lines == ' '){
12407 + if(reading_description) {
12408 + /* we already know it's not blank, so the rest of description */
12409 + pkg->description = realloc(pkg->description,
12410 + strlen(pkg->description)
12411 + + 1 + strlen(*lines) + 1);
12412 + strcat(pkg->description, "\n");
12413 + strcat(pkg->description, (*lines));
12415 + else if(reading_conffiles)
12416 + parseConffiles(pkg, *lines);
12420 +/* If the ipk has not a Provides line, we insert our false line */
12421 + if ( pkg_false_provides==1)
12422 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12431 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12435 + for (lines = *raw; *lines; lines++) {
12436 + if(isGenericFieldType("Essential:", *lines)) {
12437 + char *essential_value;
12438 + essential_value = parseGenericFieldType("Essential", *lines);
12439 + if (strcmp(essential_value, "yes") == 0) {
12440 + pkg->essential = 1;
12442 + free(essential_value);
12449 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
12450 --- busybox-1.2.0-orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
12451 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_parse.h 2006-07-22 16:31:25.000000000 +0200
12453 +/* pkg_parse.h - the itsy package management system
12457 + Copyright (C) 2002 Compaq Computer Corporation
12459 + This program is free software; you can redistribute it and/or
12460 + modify it under the terms of the GNU General Public License as
12461 + published by the Free Software Foundation; either version 2, or (at
12462 + your option) any later version.
12464 + This program is distributed in the hope that it will be useful, but
12465 + WITHOUT ANY WARRANTY; without even the implied warranty of
12466 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12467 + General Public License for more details.
12470 +#ifndef PKG_PARSE_H
12471 +#define PKG_PARSE_H
12473 +int isGenericFieldType(char * type, char * line);
12474 +char * parseGenericFieldType(char * type, char * raw);
12475 +void parseStatus(pkg_t *pkg, char * raw);
12476 +int parseVersion(pkg_t *pkg, char *raw);
12477 +char ** parseDependsString(char * raw, int * depends_count);
12478 +int parseVersion(pkg_t *pkg, char *raw);
12479 +void parseConffiles(pkg_t * pkg, char * raw);
12480 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12481 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12484 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
12485 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
12486 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.c 2006-07-22 16:31:25.000000000 +0200
12488 +/* pkg_src.c - the itsy package management system
12492 + Copyright (C) 2001 University of Southern California
12494 + This program is free software; you can redistribute it and/or
12495 + modify it under the terms of the GNU General Public License as
12496 + published by the Free Software Foundation; either version 2, or (at
12497 + your option) any later version.
12499 + This program is distributed in the hope that it will be useful, but
12500 + WITHOUT ANY WARRANTY; without even the implied warranty of
12501 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12502 + General Public License for more details.
12507 +#include "pkg_src.h"
12508 +#include "str_util.h"
12510 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12512 + src->gzip = gzip;
12513 + src->name = str_dup_safe (name);
12514 + src->value = str_dup_safe (base_url);
12516 + src->extra_data = str_dup_safe (extra_data);
12518 + src->extra_data = NULL;
12522 +void pkg_src_deinit(pkg_src_t *src)
12524 + free (src->name);
12525 + free (src->value);
12526 + if (src->extra_data)
12527 + free (src->extra_data);
12531 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
12532 --- busybox-1.2.0-orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
12533 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src.h 2006-07-22 16:31:25.000000000 +0200
12535 +/* pkg_src.h - the itsy package management system
12539 + Copyright (C) 2001 University of Southern California
12541 + This program is free software; you can redistribute it and/or
12542 + modify it under the terms of the GNU General Public License as
12543 + published by the Free Software Foundation; either version 2, or (at
12544 + your option) any later version.
12546 + This program is distributed in the hope that it will be useful, but
12547 + WITHOUT ANY WARRANTY; without even the implied warranty of
12548 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12549 + General Public License for more details.
12555 +#include "nv_pair.h"
12561 + char *extra_data;
12565 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12566 +void pkg_src_deinit(pkg_src_t *src);
12569 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
12570 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
12571 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.c 2006-07-22 16:31:25.000000000 +0200
12573 +/* pkg_src_list.c - the itsy package management system
12577 + Copyright (C) 2001 University of Southern California
12579 + This program is free software; you can redistribute it and/or
12580 + modify it under the terms of the GNU General Public License as
12581 + published by the Free Software Foundation; either version 2, or (at
12582 + your option) any later version.
12584 + This program is distributed in the hope that it will be useful, but
12585 + WITHOUT ANY WARRANTY; without even the implied warranty of
12586 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12587 + General Public License for more details.
12592 +#include "pkg_src_list.h"
12593 +#include "void_list.h"
12595 +int pkg_src_list_init(pkg_src_list_t *list)
12597 + return void_list_init((void_list_t *) list);
12600 +void pkg_src_list_deinit(pkg_src_list_t *list)
12602 + pkg_src_list_elt_t *iter;
12603 + pkg_src_t *pkg_src;
12605 + for (iter = list->head; iter; iter = iter->next) {
12606 + pkg_src = iter->data;
12607 + pkg_src_deinit(pkg_src);
12609 + /* malloced in pkg_src_list_append */
12611 + iter->data = NULL;
12613 + void_list_deinit((void_list_t *) list);
12616 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12617 + const char *name, const char *base_url, const char *extra_data,
12622 + /* freed in pkg_src_list_deinit */
12623 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12625 + if (pkg_src == NULL) {
12626 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12629 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12631 + err = void_list_append((void_list_t *) list, pkg_src);
12639 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12641 + return void_list_push((void_list_t *) list, data);
12644 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12646 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12648 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
12649 --- busybox-1.2.0-orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
12650 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_src_list.h 2006-07-22 16:31:25.000000000 +0200
12652 +/* pkg_src_list.h - the itsy package management system
12656 + Copyright (C) 2001 University of Southern California
12658 + This program is free software; you can redistribute it and/or
12659 + modify it under the terms of the GNU General Public License as
12660 + published by the Free Software Foundation; either version 2, or (at
12661 + your option) any later version.
12663 + This program is distributed in the hope that it will be useful, but
12664 + WITHOUT ANY WARRANTY; without even the implied warranty of
12665 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12666 + General Public License for more details.
12669 +#ifndef PKG_SRC_LIST_H
12670 +#define PKG_SRC_LIST_H
12672 +#include "pkg_src.h"
12674 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12675 +struct pkg_src_list_elt
12677 + pkg_src_list_elt_t *next;
12681 +typedef struct pkg_src_list pkg_src_list_t;
12682 +struct pkg_src_list
12684 + pkg_src_list_elt_t pre_head;
12685 + pkg_src_list_elt_t *head;
12686 + pkg_src_list_elt_t *tail;
12689 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12691 + if (list->head == NULL)
12697 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12698 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12700 +int pkg_src_list_init(pkg_src_list_t *list);
12701 +void pkg_src_list_deinit(pkg_src_list_t *list);
12703 +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);
12704 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12705 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12709 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
12710 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
12711 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.c 2006-07-22 16:31:26.000000000 +0200
12713 +/* pkg_vec.c - the itsy package management system
12717 + Copyright (C) 2002 Compaq Computer Corporation
12719 + This program is free software; you can redistribute it and/or
12720 + modify it under the terms of the GNU General Public License as
12721 + published by the Free Software Foundation; either version 2, or (at
12722 + your option) any later version.
12724 + This program is distributed in the hope that it will be useful, but
12725 + WITHOUT ANY WARRANTY; without even the implied warranty of
12726 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12727 + General Public License for more details.
12730 +#include <stdlib.h>
12731 +#include <fnmatch.h>
12732 +#include "xregex.h"
12736 +pkg_vec_t * pkg_vec_alloc(void)
12738 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12740 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12743 + vec->pkgs = NULL;
12749 +void pkg_vec_free(pkg_vec_t *vec)
12756 + * assumption: all names in a vector are identical
12757 + * assumption: all version strings are trimmed,
12758 + * so identical versions have identical version strings,
12759 + * implying identical packages; let's marry these
12761 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12766 + /* look for a duplicate pkg by name, version, and architecture */
12767 + for (i = 0; i < vec->len; i++){
12768 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12769 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12770 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12771 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12772 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12773 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12775 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12776 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12781 + /* we didn't find one, add it */
12783 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12784 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12786 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12787 + vec->pkgs[vec->len] = pkg;
12791 + /* update the one that we have */
12793 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12794 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12795 + if (set_status) {
12796 + /* this is from the status file, so need to merge with existing database */
12797 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12798 + pkg_merge(vec->pkgs[i], pkg, set_status);
12799 + /* XXX: CLEANUP: It's not so polite to free something here
12800 + that was passed in from above. */
12804 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12805 + /* just overwrite the old one */
12806 + pkg_deinit(vec->pkgs[i]);
12807 + free(vec->pkgs[i]);
12808 + vec->pkgs[i] = pkg;
12810 + return vec->pkgs[i];
12814 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12819 + /* look for a duplicate pkg by name, version, and architecture */
12820 + for (i = 0; i < vec->len; i++)
12821 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12822 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12823 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12828 + /* we didn't find one, add it */
12830 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12831 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12836 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12839 + for (i = 0; i < vec->len; i++)
12840 + if (vec->pkgs[i] == apkg)
12845 +typedef int (*compare_fcn_t)(const void *, const void *);
12846 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12848 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12851 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12853 + int npkgs = vec->len;
12855 + for (i = 0; i < npkgs; i++) {
12856 + pkg_t *pkg = vec->pkgs[i];
12857 + pkg->state_flag &= ~SF_MARKED;
12862 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12864 + int matching_count = 0;
12865 + pkg_t **pkgs = vec->pkgs;
12866 + int npkgs = vec->len;
12868 + for (i = 0; i < npkgs; i++) {
12869 + pkg_t *pkg = pkgs[i];
12870 + if (fnmatch(pattern, pkg->name, 0)==0) {
12871 + pkg->state_flag |= SF_MARKED;
12872 + matching_count++;
12875 + return matching_count;
12879 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12881 + abstract_pkg_vec_t * vec ;
12882 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12884 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12887 + vec->pkgs = NULL;
12893 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12900 + * assumption: all names in a vector are unique
12902 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12906 + /* look for a duplicate pkg by name */
12907 + for(i = 0; i < vec->len; i++)
12908 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12911 + /* we didn't find one, add it */
12912 + if(i == vec->len){
12914 + (abstract_pkg_t **)
12915 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12916 + vec->pkgs[vec->len] = pkg;
12921 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12923 + if (vec->len > i)
12924 + return vec->pkgs[i];
12929 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12932 + for (i = 0; i < vec->len; i++)
12933 + if (vec->pkgs[i] == apkg)
12938 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12940 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12943 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
12944 --- busybox-1.2.0-orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
12945 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/pkg_vec.h 2006-07-22 16:31:26.000000000 +0200
12947 +/* pkg_vec.h - the itsy package management system
12951 + Copyright (C) 2002 Compaq Computer Corporation
12953 + This program is free software; you can redistribute it and/or
12954 + modify it under the terms of the GNU General Public License as
12955 + published by the Free Software Foundation; either version 2, or (at
12956 + your option) any later version.
12958 + This program is distributed in the hope that it will be useful, but
12959 + WITHOUT ANY WARRANTY; without even the implied warranty of
12960 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12961 + General Public License for more details.
12967 +typedef struct pkg pkg_t;
12968 +typedef struct abstract_pkg abstract_pkg_t;
12975 +typedef struct pkg_vec pkg_vec_t;
12977 +struct abstract_pkg_vec
12979 + abstract_pkg_t **pkgs;
12982 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12985 +pkg_vec_t * pkg_vec_alloc(void);
12986 +void pkg_vec_free(pkg_vec_t *vec);
12987 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12989 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12990 +/* pkg_vec_insert_merge: might munge pkg.
12991 +* returns the pkg that is in the pkg graph */
12992 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12993 +/* this one never munges pkg */
12994 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12995 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12996 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12998 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12999 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
13001 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
13002 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
13003 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
13004 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
13005 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
13006 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
13009 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
13010 --- busybox-1.2.0-orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
13011 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/sprintf_alloc.h 2006-07-22 16:31:26.000000000 +0200
13013 +/* sprintf_alloca.c -- like sprintf with memory allocation
13017 + Copyright (C) 2001 University of Southern California
13019 + This program is free software; you can redistribute it and/or modify
13020 + it under the terms of the GNU General Public License as published by
13021 + the Free Software Foundation; either version 2, or (at your option)
13022 + any later version.
13024 + This program is distributed in the hope that it will be useful,
13025 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13026 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13027 + GNU General Public License for more details.
13030 +#ifndef SPRINTF_ALLOC_H
13031 +#define SPRINTF_ALLOC_H
13033 +#include "libbb.h"
13035 +#define sprintf_alloc(str, fmt, args...) *str = bb_xasprintf(fmt, ## args)
13038 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
13039 --- busybox-1.2.0-orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
13040 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.c 2006-07-22 16:31:26.000000000 +0200
13042 +/* str_list.c - the itsy package management system
13046 + Copyright (C) 2001 University of Southern California
13048 + This program is free software; you can redistribute it and/or
13049 + modify it under the terms of the GNU General Public License as
13050 + published by the Free Software Foundation; either version 2, or (at
13051 + your option) any later version.
13053 + This program is distributed in the hope that it will be useful, but
13054 + WITHOUT ANY WARRANTY; without even the implied warranty of
13055 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13056 + General Public License for more details.
13061 +#include "str_list.h"
13063 +int str_list_elt_init(str_list_elt_t *elt, char *data)
13065 + return void_list_elt_init((void_list_elt_t *) elt, data);
13068 +void str_list_elt_deinit(str_list_elt_t *elt)
13070 + void_list_elt_deinit((void_list_elt_t *) elt);
13073 +str_list_t *str_list_alloc()
13075 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
13077 + str_list_init(list);
13081 +int str_list_init(str_list_t *list)
13083 + return void_list_init((void_list_t *) list);
13086 +void str_list_deinit(str_list_t *list)
13088 + void_list_deinit((void_list_t *) list);
13091 +int str_list_append(str_list_t *list, char *data)
13093 + return void_list_append((void_list_t *) list, data);
13096 +int str_list_push(str_list_t *list, char *data)
13098 + return void_list_push((void_list_t *) list, data);
13101 +str_list_elt_t *str_list_pop(str_list_t *list)
13103 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
13106 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
13108 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
13109 + (void_list_elt_t **) iter);
13112 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
13114 + return (char *)void_list_remove_elt((void_list_t *) list,
13115 + (void *)target_str,
13116 + (void_list_cmp_t)strcmp);
13118 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
13119 --- busybox-1.2.0-orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
13120 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_list.h 2006-07-22 16:31:26.000000000 +0200
13122 +/* str_list.h - the itsy package management system
13126 + Copyright (C) 2001 University of Southern California
13128 + This program is free software; you can redistribute it and/or
13129 + modify it under the terms of the GNU General Public License as
13130 + published by the Free Software Foundation; either version 2, or (at
13131 + your option) any later version.
13133 + This program is distributed in the hope that it will be useful, but
13134 + WITHOUT ANY WARRANTY; without even the implied warranty of
13135 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13136 + General Public License for more details.
13139 +#ifndef STR_LIST_H
13140 +#define STR_LIST_H
13142 +#include "void_list.h"
13144 +typedef struct str_list_elt str_list_elt_t;
13145 +struct str_list_elt
13147 + str_list_elt_t *next;
13151 +typedef struct xstr_list str_list_t;
13154 + str_list_elt_t pre_head;
13155 + str_list_elt_t *head;
13156 + str_list_elt_t *tail;
13159 +int str_list_elt_init(str_list_elt_t *elt, char *data);
13160 +void str_list_elt_deinit(str_list_elt_t *elt);
13162 +str_list_t *str_list_alloc(void);
13163 +int str_list_init(str_list_t *list);
13164 +void str_list_deinit(str_list_t *list);
13166 +int str_list_append(str_list_t *list, char *data);
13167 +int str_list_push(str_list_t *list, char *data);
13168 +str_list_elt_t *str_list_pop(str_list_t *list);
13169 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
13170 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
13173 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
13174 --- busybox-1.2.0-orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
13175 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.c 2006-07-22 16:31:26.000000000 +0200
13177 +/* str_utils.c - the itsy package management system
13181 + Copyright (C) 2001 University of Southern California
13183 + This program is free software; you can redistribute it and/or
13184 + modify it under the terms of the GNU General Public License as
13185 + published by the Free Software Foundation; either version 2, or (at
13186 + your option) any later version.
13188 + This program is distributed in the hope that it will be useful, but
13189 + WITHOUT ANY WARRANTY; without even the implied warranty of
13190 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13191 + General Public License for more details.
13196 +int str_starts_with(const char *str, const char *prefix)
13198 + return (strncmp(str, prefix, strlen(prefix)) == 0);
13201 +int str_ends_with(const char *str, const char *suffix)
13206 + str_len = strlen(str);
13207 + suffix_len = strlen(suffix);
13209 + if (str_len < suffix_len) {
13213 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
13216 +int str_chomp(char *str)
13218 + if (str[strlen(str) - 1] == '\n') {
13219 + str[strlen(str) - 1] = '\0';
13225 +int str_tolower(char *str)
13228 + *str = tolower(*str);
13235 +int str_toupper(char *str)
13238 + *str = toupper(*str);
13245 +char *str_dup_safe(const char *str)
13247 + return str ? strdup(str) : NULL;
13250 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
13251 --- busybox-1.2.0-orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
13252 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/str_util.h 2006-07-22 16:31:26.000000000 +0200
13254 +/* str_utils.h - the itsy package management system
13258 + Copyright (C) 2001 University of Southern California
13260 + This program is free software; you can redistribute it and/or
13261 + modify it under the terms of the GNU General Public License as
13262 + published by the Free Software Foundation; either version 2, or (at
13263 + your option) any later version.
13265 + This program is distributed in the hope that it will be useful, but
13266 + WITHOUT ANY WARRANTY; without even the implied warranty of
13267 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13268 + General Public License for more details.
13271 +#ifndef STR_UTILS_H
13272 +#define STR_UTILS_H
13274 +int str_starts_with(const char *str, const char *prefix);
13275 +int str_ends_with(const char *str, const char *suffix);
13276 +int str_chomp(char *str);
13277 +int str_tolower(char *str);
13278 +int str_toupper(char *str);
13279 +char *str_dup_safe(const char *str);
13282 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c
13283 --- busybox-1.2.0-orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
13284 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.c 2006-07-22 16:31:26.000000000 +0200
13286 +/* user.c - the itsy package management system
13290 + Copyright (C) 2002 Hewlett Packard Company
13291 + Copyright (C) 2001 University of Southern California
13293 + This program is free software; you can redistribute it and/or
13294 + modify it under the terms of the GNU General Public License as
13295 + published by the Free Software Foundation; either version 2, or (at
13296 + your option) any later version.
13298 + This program is distributed in the hope that it will be useful, but
13299 + WITHOUT ANY WARRANTY; without even the implied warranty of
13300 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13301 + General Public License for more details.
13304 +#include <stdio.h>
13305 +#include <stdarg.h>
13306 +#include "file_util.h"
13307 +#include "str_util.h"
13309 +#include "libipkg.h"
13314 +static char *question = NULL;
13315 +static int question_len = 255;
13317 +char *get_user_response(const char *format, ...)
13319 + int len = question_len;
13322 + va_start(ap, format);
13325 + vprintf(format, ap);
13327 + response = file_read_line_alloc(stdin);
13328 + } while (response == NULL);
13331 + if (question == NULL || len > question_len) {
13332 + question = realloc(question, len + 1);
13333 + question_len = len;
13335 + len = vsnprintf(question,question_len,format,ap);
13336 + } while (len > question_len);
13337 + response = strdup(ipkg_cb_response(question));
13339 + str_chomp(response);
13340 + str_tolower(response);
13344 diff -ruN busybox-1.2.0-orig/archival/libipkg/user.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h
13345 --- busybox-1.2.0-orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
13346 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/user.h 2006-07-22 16:31:26.000000000 +0200
13348 +/* user.c - the itsy package management system
13352 + Copyright (C) 2002 Hewlett Packard Company
13353 + Copyright (C) 2001 University of Southern California
13355 + This program is free software; you can redistribute it and/or
13356 + modify it under the terms of the GNU General Public License as
13357 + published by the Free Software Foundation; either version 2, or (at
13358 + your option) any later version.
13360 + This program is distributed in the hope that it will be useful, but
13361 + WITHOUT ANY WARRANTY; without even the implied warranty of
13362 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13363 + General Public License for more details.
13366 +#include <stdio.h>
13367 +#include <stdarg.h>
13369 +char *get_user_response(const char *format, ...);
13371 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
13372 --- busybox-1.2.0-orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
13373 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.c 2006-07-22 16:31:26.000000000 +0200
13375 +/* void_list.c - the itsy package management system
13379 + Copyright (C) 2001 University of Southern California
13381 + This program is free software; you can redistribute it and/or
13382 + modify it under the terms of the GNU General Public License as
13383 + published by the Free Software Foundation; either version 2, or (at
13384 + your option) any later version.
13386 + This program is distributed in the hope that it will be useful, but
13387 + WITHOUT ANY WARRANTY; without even the implied warranty of
13388 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13389 + General Public License for more details.
13393 +#include <errno.h>
13395 +#include "void_list.h"
13397 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13399 + elt->next = NULL;
13400 + elt->data = data;
13405 +void void_list_elt_deinit(void_list_elt_t *elt)
13407 + void_list_elt_init(elt, NULL);
13410 +int void_list_init(void_list_t *list)
13412 + void_list_elt_init(&list->pre_head, NULL);
13413 + list->head = NULL;
13414 + list->pre_head.next = list->head;
13415 + list->tail = NULL;
13420 +void void_list_deinit(void_list_t *list)
13422 + void_list_elt_t *elt;
13424 + while (list->head) {
13425 + elt = void_list_pop(list);
13426 + void_list_elt_deinit(elt);
13427 + /* malloced in void_list_append */
13432 +int void_list_append(void_list_t *list, void *data)
13434 + void_list_elt_t *elt;
13436 + /* freed in void_list_deinit */
13437 + elt = malloc(sizeof(void_list_elt_t));
13438 + if (elt == NULL) {
13439 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13443 + void_list_elt_init(elt, data);
13445 + if (list->tail) {
13446 + list->tail->next = elt;
13447 + list->tail = elt;
13449 + list->head = elt;
13450 + list->pre_head.next = list->head;
13451 + list->tail = elt;
13457 +int void_list_push(void_list_t *list, void *data)
13459 + void_list_elt_t *elt;
13461 + elt = malloc(sizeof(void_list_elt_t));
13462 + if (elt == NULL) {
13463 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13467 + void_list_elt_init(elt, data);
13469 + elt->next = list->head;
13470 + list->head->next = elt;
13471 + if (list->tail == NULL) {
13472 + list->tail = list->head;
13478 +void_list_elt_t *void_list_pop(void_list_t *list)
13480 + void_list_elt_t *elt;
13482 + elt = list->head;
13484 + if (list->head) {
13485 + list->head = list->head->next;
13486 + list->pre_head.next = list->head;
13487 + if (list->head == NULL) {
13488 + list->tail = NULL;
13495 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13497 + void_list_elt_t *prior;
13498 + void_list_elt_t *old_elt;
13502 + old_data = old_elt->data;
13504 + if (old_elt == list->head) {
13505 + prior = &list->pre_head;
13506 + void_list_pop(list);
13508 + for (prior = list->head; prior; prior = prior->next) {
13509 + if (prior->next == old_elt) {
13513 + if (prior == NULL || prior->next != old_elt) {
13514 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13517 + prior->next = old_elt->next;
13519 + if (old_elt == list->tail) {
13520 + list->tail = prior;
13524 + void_list_elt_deinit(old_elt);
13530 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13531 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13533 + void_list_elt_t *prior;
13534 + void_list_elt_t *old_elt = NULL;
13535 + void *old_data = NULL;
13537 + /* first element */
13538 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13539 + old_elt = list->head;
13540 + old_data = list->head->data;
13541 + void_list_pop(list);
13544 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13545 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13546 + old_elt = prior->next;
13547 + old_data = old_elt->data;
13555 + prior->next = old_elt->next;
13557 + if (old_elt == list->tail) {
13558 + list->tail = prior;
13562 + void_list_elt_deinit(old_elt);
13569 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
13570 --- busybox-1.2.0-orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
13571 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/void_list.h 2006-07-22 16:31:26.000000000 +0200
13573 +/* void_list.h - the itsy package management system
13577 + Copyright (C) 2001 University of Southern California
13579 + This program is free software; you can redistribute it and/or
13580 + modify it under the terms of the GNU General Public License as
13581 + published by the Free Software Foundation; either version 2, or (at
13582 + your option) any later version.
13584 + This program is distributed in the hope that it will be useful, but
13585 + WITHOUT ANY WARRANTY; without even the implied warranty of
13586 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13587 + General Public License for more details.
13590 +#ifndef VOID_LIST_H
13591 +#define VOID_LIST_H
13593 +typedef struct void_list_elt void_list_elt_t;
13594 +struct void_list_elt
13596 + void_list_elt_t *next;
13600 +typedef struct void_list void_list_t;
13603 + void_list_elt_t pre_head;
13604 + void_list_elt_t *head;
13605 + void_list_elt_t *tail;
13608 +static inline int void_list_empty(void_list_t *list)
13610 + if (list->head == NULL)
13616 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13617 +void void_list_elt_deinit(void_list_elt_t *elt);
13619 +int void_list_init(void_list_t *list);
13620 +void void_list_deinit(void_list_t *list);
13622 +int void_list_append(void_list_t *list, void *data);
13623 +int void_list_push(void_list_t *list, void *data);
13624 +void_list_elt_t *void_list_pop(void_list_t *list);
13626 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13627 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13628 +typedef int (*void_list_cmp_t)(const void *, const void *);
13629 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13632 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.c busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c
13633 --- busybox-1.2.0-orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
13634 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.c 2006-07-22 16:31:26.000000000 +0200
13636 +/* xsystem.c - system(3) with error messages
13640 + Copyright (C) 2001 University of Southern California
13642 + This program is free software; you can redistribute it and/or
13643 + modify it under the terms of the GNU General Public License as
13644 + published by the Free Software Foundation; either version 2, or (at
13645 + your option) any later version.
13647 + This program is distributed in the hope that it will be useful, but
13648 + WITHOUT ANY WARRANTY; without even the implied warranty of
13649 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13650 + General Public License for more details.
13654 +#include <sys/wait.h>
13656 +#include "xsystem.h"
13658 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13659 + really need the /bin/sh invocation which takes resources and
13660 + introduces security problems. I should switch all of this to a sort
13661 + of execl() or execv() interface/implementation.
13664 +/* Like system(3), but with error messages printed if the fork fails
13665 + or if the child process dies due to an uncaught signal. Also, the
13666 + return value is a bit simpler:
13668 + -1 if there was any problem
13669 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13670 + as defined in <sys/wait.h>.
13672 +int xsystem(const char *cmd)
13676 + err = system(cmd);
13679 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13680 + __FUNCTION__, cmd);
13684 + if (WIFSIGNALED(err)) {
13685 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13686 + __FUNCTION__, WTERMSIG(err), cmd);
13690 + if (WIFEXITED(err)) {
13691 + /* Normal child exit */
13692 + return WEXITSTATUS(err);
13695 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13696 + __FUNCTION__, err);
13700 diff -ruN busybox-1.2.0-orig/archival/libipkg/xsystem.h busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h
13701 --- busybox-1.2.0-orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
13702 +++ busybox-1.2.0+ipkg-0.99.162/archival/libipkg/xsystem.h 2006-07-22 16:31:26.000000000 +0200
13704 +/* xsystem.h - system(3) with error messages
13708 + Copyright (C) 2001 University of Southern California
13710 + This program is free software; you can redistribute it and/or
13711 + modify it under the terms of the GNU General Public License as
13712 + published by the Free Software Foundation; either version 2, or (at
13713 + your option) any later version.
13715 + This program is distributed in the hope that it will be useful, but
13716 + WITHOUT ANY WARRANTY; without even the implied warranty of
13717 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13718 + General Public License for more details.
13724 +#include <stdlib.h>
13726 +/* Like system(3), but with error messages printed if the fork fails
13727 + or if the child process dies due to an uncaught signal. Also, the
13728 + return value is a bit simpler:
13730 + -1 if there was any problem
13731 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13732 + as defined in <sys/wait.h>.
13734 +int xsystem(const char *cmd);
13738 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
13739 --- busybox-1.2.0-orig/archival/libunarchive/data_extract_all.c 2006-07-01 00:42:04.000000000 +0200
13740 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/data_extract_all.c 2006-07-22 16:31:26.000000000 +0200
13741 @@ -126,3 +126,17 @@
13742 utime(file_header->name, &t);
13746 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13748 + char *name_ptr = archive_handle->file_header->name;
13750 + name_ptr += strspn(name_ptr, "./");
13751 + if (name_ptr[0] != '\0') {
13752 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13753 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13754 + strcat(archive_handle->file_header->name, name_ptr);
13755 + data_extract_all(archive_handle);
13759 diff -ruN busybox-1.2.0-orig/archival/libunarchive/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in
13760 --- busybox-1.2.0-orig/archival/libunarchive/Makefile.in 2006-07-01 00:42:03.000000000 +0200
13761 +++ busybox-1.2.0+ipkg-0.99.162/archival/libunarchive/Makefile.in 2006-07-22 16:31:26.000000000 +0200
13763 LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13764 LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
13765 LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13766 +LIBUNARCHIVE-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13767 LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
13768 LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
13769 LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
13770 diff -ruN busybox-1.2.0-orig/archival/Makefile.in busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in
13771 --- busybox-1.2.0-orig/archival/Makefile.in 2006-07-01 00:42:04.000000000 +0200
13772 +++ busybox-1.2.0+ipkg-0.99.162/archival/Makefile.in 2006-07-22 16:31:25.000000000 +0200
13774 ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
13775 ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
13776 ARCHIVAL-$(CONFIG_GZIP) += gzip.o
13777 +ARCHIVAL-$(CONFIG_IPKG) += ipkg.o
13778 ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
13779 ARCHIVAL-$(CONFIG_RPM) += rpm.o
13780 ARCHIVAL-$(CONFIG_TAR) += tar.o
13781 diff -ruN busybox-1.2.0-orig/include/applets.h busybox-1.2.0+ipkg-0.99.162/include/applets.h
13782 --- busybox-1.2.0-orig/include/applets.h 2006-07-01 00:42:10.000000000 +0200
13783 +++ busybox-1.2.0+ipkg-0.99.162/include/applets.h 2006-07-22 16:35:35.000000000 +0200
13784 @@ -152,6 +152,7 @@
13785 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13786 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13787 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13788 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13789 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13790 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13791 USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER))
13792 diff -ruN busybox-1.2.0-orig/include/unarchive.h busybox-1.2.0+ipkg-0.99.162/include/unarchive.h
13793 --- busybox-1.2.0-orig/include/unarchive.h 2006-07-01 00:42:10.000000000 +0200
13794 +++ busybox-1.2.0+ipkg-0.99.162/include/unarchive.h 2006-07-22 16:31:26.000000000 +0200
13797 extern void data_skip(archive_handle_t *archive_handle);
13798 extern void data_extract_all(archive_handle_t *archive_handle);
13799 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13800 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13801 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13803 diff -ruN busybox-1.2.0-orig/include/usage.h busybox-1.2.0+ipkg-0.99.162/include/usage.h
13804 --- busybox-1.2.0-orig/include/usage.h 2006-07-01 00:42:10.000000000 +0200
13805 +++ busybox-1.2.0+ipkg-0.99.162/include/usage.h 2006-07-22 16:31:26.000000000 +0200
13806 @@ -982,6 +982,82 @@
13807 "$ ls -la /tmp/busybox*\n" \
13808 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13810 +#define ipkg_trivial_usage \
13811 + "[options]... sub-command [arguments]..."
13812 +#define ipkg_full_usage \
13813 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13815 + "Sub-commands:\n" \
13816 + "\nPackage Manipulation:\n" \
13817 + "\tupdate Update list of available packages\n" \
13818 + "\tupgrade Upgrade all installed packages to latest version\n" \
13819 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13820 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13821 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13822 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13823 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13824 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13826 + "Informational Commands:\n" \
13827 + "\tlist List available packages and descriptions\n" \
13828 + "\tlist_installed List all and only the installed packages and description \n" \
13829 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13830 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13831 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13832 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13833 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13834 + "\tcompare_versions <v1> <op> <v2>\n" \
13835 + "\t compare versions using <= < > >= = << >>\n" \
13836 + "\tprint_architecture prints the architecture.\n" \
13837 + "\tprint_installation_architecture\n" \
13838 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13839 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13840 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13841 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13842 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13843 + "\t prints the installation architecture.\n" \
13846 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13847 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13848 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13849 + "\t 0 errors only\n" \
13850 + "\t 1 normal messages (default)\n" \
13851 + "\t 2 informative messages\n" \
13852 + "\t 3 debug output\n" \
13853 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13854 + "\t-conf <conf_file> Default configuration file location\n" \
13855 + " is /etc/ipkg.conf\n" \
13856 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13857 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13858 + " <dest_name> should be a defined dest name from\n" \
13859 + " the configuration file, (but can also be a\n" \
13860 + " directory name in a pinch).\n" \
13861 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13862 + "\t-offline <offline_root> offline installation of packages.\n" \
13863 + "\t-verbose_wget more wget messages\n" \
13865 + "Force Options (use when ipkg is too smart for its own good):\n" \
13866 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13867 + "\t Install/remove package in spite of failed dependences\n" \
13868 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13869 + " (no prompts). Note that this will not prevent\n" \
13870 + " package installation scripts from prompting.\n" \
13871 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13872 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13873 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13874 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13875 + "\t-noaction No action -- test only\n" \
13876 + "\t-nodeps Do not follow dependences\n" \
13877 + "\t-force-removal-of-dependent-packages\n" \
13878 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13879 + "\t-test No action -- test only\n" \
13880 + "\t-t Specify tmp-dir.\n" \
13881 + "\t--tmp-dir Specify tmp-dir.\n" \
13883 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13884 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13886 #define halt_trivial_usage \
13887 "[-d<delay>] [-n<nosync>] [-f<force>]"
13888 #define halt_full_usage \
13889 diff -ruN busybox-1.2.0-orig/Makefile busybox-1.2.0+ipkg-0.99.162/Makefile
13890 --- busybox-1.2.0-orig/Makefile 2006-07-01 00:42:13.000000000 +0200
13891 +++ busybox-1.2.0+ipkg-0.99.162/Makefile 2006-07-22 16:31:25.000000000 +0200
13893 export srctree=$(top_srcdir)
13894 vpath %/Config.in $(srctree)
13896 -DIRS:=applets archival archival/libunarchive coreutils console-tools \
13897 +DIRS:=applets archival archival/libipkg archival/libunarchive coreutils console-tools \
13898 debianutils editors findutils init miscutils modutils networking \
13899 networking/libiproute networking/udhcp procps loginutils shell \
13900 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb