1 --- a/archival/Config.in
2 +++ b/archival/Config.in
4 gzip is used to compress files.
5 It's probably the most widely used UNIX compression program.
14 + ipkg is the itsy package management system.
21 @@ -1482,6 +1482,10 @@
22 return ar_handle->sub_archive->buffer;
27 +// moved to data_extract_all.c
29 static void data_extract_all_prefix(archive_handle_t *archive_handle)
31 char *name_ptr = archive_handle->file_header->name;
38 static void unpack_package(deb_file_t *deb_file)
40 const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
44 +/* ipkg.c - the itsy package management system
48 + Copyright (C) 2003 kernel concepts
50 + This program is free software; you can redistribute it and/or
51 + modify it under the terms of the GNU General Public License as
52 + published by the Free Software Foundation; either version 2, or (at
53 + your option) any later version.
55 + This program is distributed in the hope that it will be useful, but
56 + WITHOUT ANY WARRANTY; without even the implied warranty of
57 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
58 + General Public License for more details.
60 + ipkg command line frontend using libipkg
63 +#include "libipkg/libipkg.h"
66 +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
67 +int ipkg_main(int argc, char **argv)
69 + return ipkg_op(argc, argv);
74 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
75 lib-$(CONFIG_GUNZIP) += bbunzip.o
76 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
77 +lib-$(CONFIG_IPKG) += ipkg.o
78 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
79 lib-$(CONFIG_RPM) += rpm.o
80 lib-$(CONFIG_TAR) += tar.o
82 +++ b/archival/libipkg/args.c
84 +/* args.c - parse command-line args
88 + Copyright 2001 University of Southern California
90 + This program is free software; you can redistribute it and/or modify
91 + it under the terms of the GNU General Public License as published by
92 + the Free Software Foundation; either version 2, or (at your option)
95 + This program is distributed in the hope that it will be useful,
96 + but WITHOUT ANY WARRANTY; without even the implied warranty of
97 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98 + GNU General Public License for more details.
107 +#include "ipkg_message.h"
110 +#include "sprintf_alloc.h"
115 +static void print_version(void);
119 + ARGS_OPT_FORCE_DEFAULTS = 129,
120 + ARGS_OPT_FORCE_DEPENDS,
121 + ARGS_OPT_FORCE_OVERWRITE,
122 + ARGS_OPT_FORCE_DOWNGRADE,
123 + ARGS_OPT_FORCE_REINSTALL,
124 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
125 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
126 + ARGS_OPT_FORCE_SPACE,
129 + ARGS_OPT_VERBOSE_WGET,
130 + ARGS_OPT_VERBOSITY,
131 + ARGS_OPT_MULTIPLE_PROVIDERS
134 +int args_init(args_t *args)
136 + char *conf_file_dir;
138 + memset(args, 0, sizeof(args_t));
140 + args->dest = ARGS_DEFAULT_DEST;
142 + conf_file_dir = getenv("IPKG_CONF_DIR");
143 + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
144 + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
146 + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
147 + ARGS_DEFAULT_CONF_FILE_NAME);
149 + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
150 + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
151 + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
152 + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
153 + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
154 + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
155 + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
156 + args->noaction = ARGS_DEFAULT_NOACTION;
157 + args->nodeps = ARGS_DEFAULT_NODEPS;
158 + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
159 + args->verbosity = ARGS_DEFAULT_VERBOSITY;
160 + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
161 + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
162 + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
163 + args->multiple_providers = 0;
164 + args->nocheckfordirorfile = 0;
165 + args->noreadfeedsfile = 0;
170 +void args_deinit(args_t *args)
172 + free(args->conf_file);
173 + args->conf_file = NULL;
176 +int args_parse(args_t *args, int argc, char *argv[])
179 + int option_index = 0;
181 + static struct option long_options[] = {
182 + {"query-all", 0, 0, 'A'},
183 + {"conf-file", 1, 0, 'f'},
184 + {"conf", 1, 0, 'f'},
185 + {"dest", 1, 0, 'd'},
186 + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
187 + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
188 + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
189 + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
190 + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
191 + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
192 + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
193 + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
194 + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
195 + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
196 + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
197 + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
198 + {"recursive", 0, 0,
199 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
200 + {"force-removal-of-dependent-packages", 0, 0,
201 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
202 + {"force_removal_of_dependent_packages", 0, 0,
203 + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
204 + {"force-removal-of-essential-packages", 0, 0,
205 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
206 + {"force_removal_of_essential_packages", 0, 0,
207 + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
208 + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
209 + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
210 + {"noaction", 0, 0, ARGS_OPT_NOACTION},
211 + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
212 + {"offline", 1, 0, 'o'},
213 + {"offline-root", 1, 0, 'o'},
214 + {"test", 0, 0, ARGS_OPT_NOACTION},
215 + {"tmp-dir", 1, 0, 't'},
216 + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
217 + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
218 + {"verbosity", 2, 0, 'V'},
219 + {"version", 0, 0, 'v'},
224 + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
230 + args->query_all = 1;
233 + args->dest = optarg;
236 + free(args->conf_file);
237 + args->conf_file = strdup(optarg);
240 + args->offline_root = optarg;
243 + args->noaction = 1;
246 + args->tmp_dir = strdup(optarg);
252 + case ARGS_OPT_VERBOSITY:
254 + args->verbosity = atoi(optarg);
256 + args->verbosity += 1;
258 + case ARGS_OPT_FORCE_DEFAULTS:
259 + args->force_defaults = 1;
261 + case ARGS_OPT_FORCE_DEPENDS:
262 + args->force_depends = 1;
264 + case ARGS_OPT_FORCE_OVERWRITE:
265 + args->force_overwrite = 1;
267 + case ARGS_OPT_FORCE_DOWNGRADE:
268 + args->force_downgrade = 1;
270 + case ARGS_OPT_FORCE_REINSTALL:
271 + args->force_reinstall = 1;
273 + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
274 + args->force_removal_of_essential_packages = 1;
276 + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
277 + args->force_removal_of_dependent_packages = 1;
279 + case ARGS_OPT_FORCE_SPACE:
280 + args->force_space = 1;
282 + case ARGS_OPT_VERBOSE_WGET:
283 + args->verbose_wget = 1;
285 + case ARGS_OPT_MULTIPLE_PROVIDERS:
286 + args->multiple_providers = 1;
288 + case ARGS_OPT_NODEPS:
291 + case ARGS_OPT_NOACTION:
292 + args->noaction = 1;
301 + bb_error_msg("Confusion: getopt_long returned %d\n", c);
312 +void args_usage(char *complaint)
315 + bb_error_msg("%s\n", complaint);
322 +static void print_version(void)
324 + bb_error_msg("version %s\n", IPKG_VERSION);
327 +++ b/archival/libipkg/args.h
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);
402 +++ b/archival/libipkg/conffile.c
404 +/* conffile.c - the itsy package management system
408 + Copyright (C) 2001 University of Southern California
410 + This program is free software; you can redistribute it and/or
411 + modify it under the terms of the GNU General Public License as
412 + published by the Free Software Foundation; either version 2, or (at
413 + your option) any later version.
415 + This program is distributed in the hope that it will be useful, but
416 + WITHOUT ANY WARRANTY; without even the implied warranty of
417 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
418 + General Public License for more details.
425 +#include "ipkg_message.h"
427 +#include "conffile.h"
428 +#include "file_util.h"
429 +#include "sprintf_alloc.h"
431 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
433 + return nv_pair_init(conffile, file_name, md5sum);
436 +void conffile_deinit(conffile_t *conffile)
438 + nv_pair_deinit(conffile);
441 +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
444 + char *filename = conffile->name;
445 + char *root_filename;
448 + if (conffile->value == NULL) {
449 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
453 + root_filename = root_filename_alloc(conf, filename);
455 + md5sum = file_md5sum_alloc(root_filename);
457 + ret = strcmp(md5sum, conffile->value);
459 + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
460 + conffile->name, md5sum, conffile->value);
463 + free(root_filename);
469 +++ b/archival/libipkg/conffile.h
471 +/* conffile.h - the itsy package management system
475 + Copyright (C) 2001 University of Southern California
477 + This program is free software; you can redistribute it and/or
478 + modify it under the terms of the GNU General Public License as
479 + published by the Free Software Foundation; either version 2, or (at
480 + your option) any later version.
482 + This program is distributed in the hope that it will be useful, but
483 + WITHOUT ANY WARRANTY; without even the implied warranty of
484 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
485 + General Public License for more details.
491 +#include "nv_pair.h"
493 +typedef struct nv_pair conffile_t;
495 +int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
496 +void conffile_deinit(conffile_t *conffile);
497 +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
502 +++ b/archival/libipkg/conffile_list.c
504 +/* conffile_list.c - the itsy package management system
508 + Copyright (C) 2001 University of Southern California
510 + This program is free software; you can redistribute it and/or
511 + modify it under the terms of the GNU General Public License as
512 + published by the Free Software Foundation; either version 2, or (at
513 + your option) any later version.
515 + This program is distributed in the hope that it will be useful, but
516 + WITHOUT ANY WARRANTY; without even the implied warranty of
517 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
518 + General Public License for more details.
523 +#include "conffile_list.h"
525 +int conffile_list_init(conffile_list_t *list)
527 + return nv_pair_list_init(list);
530 +void conffile_list_deinit(conffile_list_t *list)
532 + nv_pair_list_deinit(list);
535 +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
536 + const char *md5sum)
538 + return nv_pair_list_append(list, file_name, md5sum);
541 +int conffile_list_push(conffile_list_t *list, conffile_t *data)
543 + return nv_pair_list_push(list, data);
546 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
548 + return nv_pair_list_pop(list);
552 +++ b/archival/libipkg/conffile_list.h
554 +/* conffile_list.h - the itsy package management system
558 + Copyright (C) 2001 University of Southern California
560 + This program is free software; you can redistribute it and/or
561 + modify it under the terms of the GNU General Public License as
562 + published by the Free Software Foundation; either version 2, or (at
563 + your option) any later version.
565 + This program is distributed in the hope that it will be useful, but
566 + WITHOUT ANY WARRANTY; without even the implied warranty of
567 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
568 + General Public License for more details.
571 +#ifndef CONFFILE_LIST_H
572 +#define CONFFILE_LIST_H
574 +#include "conffile.h"
575 +#include "nv_pair_list.h"
577 +typedef struct nv_pair_list_elt conffile_list_elt_t;
578 +typedef struct nv_pair_list conffile_list_t;
580 +int conffile_list_init(conffile_list_t *list);
581 +void conffile_list_deinit(conffile_list_t *list);
583 +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
584 + const char *root_dir);
585 +int conffile_list_push(conffile_list_t *list, conffile_t *data);
586 +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
591 +++ b/archival/libipkg/file_util.c
593 +/* file_util.c - convenience routines for common stat operations
597 + Copyright (C) 2001 University of Southern California
599 + This program is free software; you can redistribute it and/or
600 + modify it under the terms of the GNU General Public License as
601 + published by the Free Software Foundation; either version 2, or (at
602 + your option) any later version.
604 + This program is distributed in the hope that it will be useful, but
605 + WITHOUT ANY WARRANTY; without even the implied warranty of
606 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
607 + General Public License for more details.
611 +#include <sys/types.h>
612 +#include <sys/stat.h>
614 +#include "sprintf_alloc.h"
615 +#include "file_util.h"
619 +int file_exists(const char *file_name)
622 + struct stat stat_buf;
624 + err = stat(file_name, &stat_buf);
632 +int file_is_dir(const char *file_name)
635 + struct stat stat_buf;
637 + err = stat(file_name, &stat_buf);
642 + return S_ISDIR(stat_buf.st_mode);
645 +/* read a single line from a file, stopping at a newline or EOF.
646 + If a newline is read, it will appear in the resulting string.
647 + Return value is a malloc'ed char * which should be freed at
648 + some point by the caller.
650 + Return value is NULL if the file is at EOF when called.
652 +#define FILE_READ_LINE_BUF_SIZE 1024
653 +char *file_read_line_alloc(FILE *file)
655 + char buf[FILE_READ_LINE_BUF_SIZE];
660 + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
661 + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
662 + buf_len = strlen(buf);
664 + line_size += buf_len;
665 + line = realloc(line, line_size);
666 + if (line == NULL) {
667 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
672 + line_size = buf_len + 1;
673 + line = strdup(buf);
675 + if (buf[buf_len - 1] == '\n') {
683 +int file_move(const char *src, const char *dest)
687 + err = rename(src, dest);
689 + if (err && errno == EXDEV) {
690 + err = file_copy(src, dest);
693 + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
694 + __FUNCTION__, src, dest, strerror(errno));
700 +/* I put these here to keep libbb dependencies from creeping all over
702 +int file_copy(const char *src, const char *dest)
706 + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
708 + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
709 + __FUNCTION__, src, dest);
715 +int file_mkdir_hier(const char *path, long mode)
717 + return bb_make_directory((char *)path, mode, FILEUTILS_RECUR);
720 +char *file_md5sum_alloc(const char *file_name)
722 + return hash_file(file_name, HASH_MD5);
726 +++ b/archival/libipkg/file_util.h
728 +/* file_util.h - convenience routines for common file operations
732 + Copyright (C) 2001 University of Southern California
734 + This program is free software; you can redistribute it and/or
735 + modify it under the terms of the GNU General Public License as
736 + published by the Free Software Foundation; either version 2, or (at
737 + your option) any later version.
739 + This program is distributed in the hope that it will be useful, but
740 + WITHOUT ANY WARRANTY; without even the implied warranty of
741 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
742 + General Public License for more details.
748 +int file_exists(const char *file_name);
749 +int file_is_dir(const char *file_name);
750 +char *file_read_line_alloc(FILE *file);
751 +int file_move(const char *src, const char *dest);
752 +int file_copy(const char *src, const char *dest);
753 +int file_mkdir_hier(const char *path, long mode);
754 +char *file_md5sum_alloc(const char *file_name);
758 +++ b/archival/libipkg/hash_table.c
760 +/* hash.c - hash tables for ipkg
762 + Steven M. Ayer, Jamey Hicks
764 + Copyright (C) 2002 Compaq Computer Corporation
766 + This program is free software; you can redistribute it and/or
767 + modify it under the terms of the GNU General Public License as
768 + published by the Free Software Foundation; either version 2, or (at
769 + your option) any later version.
771 + This program is distributed in the hope that it will be useful, but
772 + WITHOUT ANY WARRANTY; without even the implied warranty of
773 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
774 + General Public License for more details.
781 +#include "hash_table.h"
782 +#include "ipkg_message.h"
785 +static int hash_index(hash_table_t *hash, const char *pkg_name);
786 +static int rotating(const char *key, int len, int prime);
788 +static int hash_index(hash_table_t *hash, const char *pkg_name)
790 + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
793 +static int rotating(const char *key, int len, int prime)
795 + unsigned int hash, i;
796 + for (hash=len, i=0; i<len; ++i)
797 + hash = (hash<<4)^(hash>>28)^key[i];
798 + return (hash % prime);
803 + * this is an open table keyed by strings
805 +int hash_table_init(const char *name, hash_table_t *hash, int len)
807 + static int primes_table[] = {
808 + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
809 + 19471, 23143, 33961, 46499, 49727, 99529, 0
813 + if (hash->entries != NULL) {
814 + /* we have been here already */
819 + hash->entries = NULL;
820 + hash->n_entries = 0;
821 + hash->hash_entry_key = NULL;
823 + picker = primes_table;
824 + while(*picker && (*picker++ < len));
826 + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
829 + hash->n_entries = *picker;
830 + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
831 + if (hash->entries == NULL) {
832 + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
838 +void hash_table_deinit(hash_table_t *hash)
840 + free(hash->entries);
841 + hash->entries = NULL;
842 + hash->n_entries = 0;
845 +void *hash_table_get(hash_table_t *hash, const char *key)
847 + int ndx= hash_index(hash, key);
848 + hash_entry_t *hash_entry = hash->entries + ndx;
851 + if (hash_entry->key)
853 + if (strcmp(key, hash_entry->key) == 0) {
854 + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
855 + return hash_entry->data;
858 + hash_entry = hash_entry->next;
863 +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
865 + int ndx= hash_index(hash, key);
866 + hash_entry_t *hash_entry = hash->entries + ndx;
867 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
868 + if (hash_entry->key) {
869 + if (strcmp(hash_entry->key, key) == 0) {
870 + /* alread in table, update the value */
871 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
872 + hash_entry->data = value;
876 + * if this is a collision, we have to go to the end of the ll,
877 + * then add a new entry
878 + * before we can hook up the value
880 + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
881 + while (hash_entry->next)
882 + hash_entry = hash_entry->next;
883 + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
884 + if (!hash_entry->next) {
887 + hash_entry = hash_entry->next;
888 + hash_entry->next = NULL;
891 + hash->n_elements++;
892 + hash_entry->key = strdup(key);
893 + hash_entry->data = value;
899 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
905 + for (i = 0; i < hash->n_entries; i++) {
906 + hash_entry_t *hash_entry = (hash->entries + i);
908 + if(hash_entry->key) {
909 + f(hash_entry->key, hash_entry->data, data);
911 + } while((hash_entry = hash_entry->next));
916 +++ b/archival/libipkg/hash_table.h
918 +/* hash.h - hash tables for ipkg
920 + Steven M. Ayer, Jamey Hicks
922 + Copyright (C) 2002 Compaq Computer Corporation
924 + This program is free software; you can redistribute it and/or
925 + modify it under the terms of the GNU General Public License as
926 + published by the Free Software Foundation; either version 2, or (at
927 + your option) any later version.
929 + This program is distributed in the hope that it will be useful, but
930 + WITHOUT ANY WARRANTY; without even the implied warranty of
931 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
932 + General Public License for more details.
935 +#ifndef _HASH_TABLE_H_
936 +#define _HASH_TABLE_H_
938 +typedef struct hash_entry hash_entry_t;
939 +typedef struct hash_table hash_table_t;
944 + struct hash_entry * next;
949 + hash_entry_t * entries;
950 + int n_entries; /* number of buckets */
952 + const char * (*hash_entry_key)(void * data);
955 +int hash_table_init(const char *name, hash_table_t *hash, int len);
956 +void hash_table_deinit(hash_table_t *hash);
957 +void *hash_table_get(hash_table_t *hash, const char *key);
958 +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
959 +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
961 +#endif /* _HASH_TABLE_H_ */
963 +++ b/archival/libipkg/ipkg_cmd.c
965 +/* ipkg_cmd.c - the itsy package management system
969 + Copyright (C) 2001 University of Southern California
971 + This program is free software; you can redistribute it and/or
972 + modify it under the terms of the GNU General Public License as
973 + published by the Free Software Foundation; either version 2, or (at
974 + your option) any later version.
976 + This program is distributed in the hope that it will be useful, but
977 + WITHOUT ANY WARRANTY; without even the implied warranty of
978 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
979 + General Public License for more details.
994 +#include "ipkg_conf.h"
995 +#include "ipkg_cmd.h"
996 +#include "ipkg_message.h"
998 +#include "pkg_dest.h"
999 +#include "pkg_parse.h"
1000 +#include "sprintf_alloc.h"
1002 +#include "file_util.h"
1003 +#include "str_util.h"
1005 +#include "unarchive.h"
1007 +#include <fnmatch.h>
1010 +#include "ipkg_download.h"
1011 +#include "ipkg_install.h"
1012 +#include "ipkg_upgrade.h"
1013 +#include "ipkg_remove.h"
1014 +#include "ipkg_configure.h"
1015 +#include "ipkg_message.h"
1018 +#include "libipkg.h"
1019 +static void *p_userdata = NULL;
1022 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv);
1023 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
1024 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
1025 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
1026 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
1027 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv);
1028 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
1029 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
1030 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
1031 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
1032 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
1033 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
1034 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
1035 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
1036 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1037 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1038 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
1039 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
1040 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
1041 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
1042 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
1043 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
1044 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
1045 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv);
1046 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
1048 +/* XXX: CLEANUP: The usage strings should be incorporated into this
1049 + array for easier maintenance */
1050 +static ipkg_cmd_t cmds[] = {
1051 + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
1052 + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
1053 + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
1054 + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
1055 + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
1056 + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
1057 + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
1058 + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
1059 + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
1060 + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
1061 + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
1062 + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
1063 + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
1064 + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
1065 + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
1066 + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1067 + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
1068 + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1069 + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1070 + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1071 + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
1072 + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
1073 + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
1074 + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
1075 + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
1076 + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
1077 + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
1078 + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
1079 + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
1082 +int ipkg_state_changed;
1083 +static void write_status_files_if_changed(ipkg_conf_t *conf)
1085 + if (ipkg_state_changed && !conf->noaction) {
1086 + ipkg_message(conf, IPKG_INFO,
1087 + " writing status file\n");
1088 + ipkg_conf_write_status_files(conf);
1089 + pkg_write_changed_filelists(conf);
1091 + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
1096 +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
1098 +ipkg_cmd_t *ipkg_cmd_find(const char *name)
1103 + for (i=0; i < num_cmds; i++) {
1105 + if (strcmp(name, cmd->name) == 0) {
1114 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
1117 + p_userdata = userdata;
1120 + result = (cmd->fun)(conf, argc, argv);
1121 + if ( result == 0 ) {
1122 + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
1124 + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
1127 + if ( error_list ) {
1128 + reverse_error_list(&error_list);
1130 + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
1131 + /* Here we print the errors collected and free the list */
1132 + while (error_list != NULL) {
1133 + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
1134 + error_list = error_list->next;
1137 + free_error_list(&error_list);
1141 + p_userdata = NULL;
1145 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
1147 + return (cmd->fun)(conf, argc, argv);
1151 +static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv)
1156 + pkg_src_list_elt_t *iter;
1160 + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
1162 + if (! file_is_dir(lists_dir)) {
1163 + if (file_exists(lists_dir)) {
1164 + ipkg_message(conf, IPKG_ERROR,
1165 + "%s: ERROR: %s exists, but is not a directory\n",
1166 + __FUNCTION__, lists_dir);
1170 + err = file_mkdir_hier(lists_dir, 0755);
1172 + ipkg_message(conf, IPKG_ERROR,
1173 + "%s: ERROR: failed to make directory %s: %s\n",
1174 + __FUNCTION__, lists_dir, strerror(errno));
1181 + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
1182 + char *url, *list_file_name;
1186 + if (src->extra_data) /* debian style? */
1187 + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
1188 + src->gzip ? "Packages.gz" : "Packages");
1190 + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
1192 + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
1195 + char *tmp_file_name;
1198 + tmp = strdup ("/tmp/ipkg.XXXXXX");
1200 + if (mkdtemp (tmp) == NULL) {
1201 + perror ("mkdtemp");
1206 + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
1207 + err = ipkg_download(conf, url, tmp_file_name);
1209 + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
1210 + in = fopen (tmp_file_name, "r");
1211 + out = fopen (list_file_name, "w");
1213 + inflate_unzip_result res;
1214 + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
1221 + unlink (tmp_file_name);
1226 + err = ipkg_download(conf, url, list_file_name);
1230 + ipkg_message(conf, IPKG_NOTICE,
1231 + "Updated list of available packages in %s\n",
1235 + free(list_file_name);
1239 +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
1241 + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
1242 + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
1248 + pkg_vec_t *available = pkg_vec_alloc();
1249 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1250 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
1251 + for (i = 0; i < available->len; i++) {
1252 + pkg_t *pkg = available->pkgs[i];
1253 + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
1254 + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
1255 + pkg->state_want = SW_UNKNOWN;
1259 + pkg_vec_free(available);
1261 + write_status_files_if_changed(conf);
1270 +/* scan the args passed and cache the local filenames of the packages */
1271 +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
1277 + * First scan through package names/urls
1278 + * For any urls, download the packages and install in database.
1279 + * For any files, install package info in database.
1281 + for (i = 0; i < argc; i ++) {
1282 + char *filename = argv [i];
1283 + //char *tmp = basename (tmp);
1284 + //int tmplen = strlen (tmp);
1286 + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
1288 + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
1291 + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
1293 + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
1300 +struct ipkg_intercept
1306 +typedef struct ipkg_intercept *ipkg_intercept_t;
1308 +ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf)
1310 + ipkg_intercept_t ctx;
1314 + ctx = malloc (sizeof (*ctx));
1315 + ctx->oldpath = strdup (getenv ("PATH"));
1317 + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
1318 + setenv ("PATH", newpath, 1);
1323 + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
1324 + if (mkdir (ctx->statedir, 0770) < 0) {
1325 + if (errno == EEXIST) {
1326 + free (ctx->statedir);
1330 + perror (ctx->statedir);
1333 + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
1337 +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
1343 + setenv ("PATH", ctx->oldpath, 1);
1344 + free (ctx->oldpath);
1346 + dir = opendir (ctx->statedir);
1348 + struct dirent *de;
1349 + while (de = readdir (dir), de != NULL) {
1352 + if (de->d_name[0] == '.')
1355 + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
1356 + if (access (path, X_OK) == 0) {
1357 + if (system (path)) {
1359 + perror (de->d_name);
1365 + perror (ctx->statedir);
1367 + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
1371 + free (ctx->statedir);
1377 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
1382 + ipkg_intercept_t ic;
1385 + ipkg_message(conf, IPKG_INFO,
1386 + "Configuring unpacked packages\n");
1389 + all = pkg_vec_alloc();
1390 + pkg_hash_fetch_available(&conf->pkg_hash, all);
1392 + ic = ipkg_prep_intercepts (conf);
1394 + for(i = 0; i < all->len; i++) {
1395 + pkg = all->pkgs[i];
1397 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1400 + if (pkg->state_status == SS_UNPACKED) {
1401 + ipkg_message(conf, IPKG_NOTICE,
1402 + "Configuring %s\n", pkg->name);
1404 + r = ipkg_configure(conf, pkg);
1406 + pkg->state_status = SS_INSTALLED;
1407 + pkg->parent->state_status = SS_INSTALLED;
1408 + pkg->state_flag &= ~SF_PREFER;
1416 + r = ipkg_finalize_intercepts (ic);
1420 + pkg_vec_free(all);
1424 +static void sigint_handler(int sig)
1426 + signal(sig, SIG_DFL);
1427 + ipkg_message(NULL, IPKG_NOTICE,
1428 + "ipkg: interrupted. writing out status database\n");
1429 + write_status_files_if_changed(global_conf);
1433 +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
1439 + global_conf = conf;
1440 + signal(SIGINT, sigint_handler);
1443 + * Now scan through package names and install
1445 + for (i=0; i < argc; i++) {
1448 + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
1449 + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
1450 + if (err != EINVAL && err != 0)
1453 + pkg_info_preinstall_check(conf);
1455 + for (i=0; i < argc; i++) {
1457 + if (conf->multiple_providers)
1458 + err = ipkg_install_multi_by_name(conf, arg);
1460 + err = ipkg_install_by_name(conf, arg);
1462 + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
1463 + ipkg_message(conf, IPKG_ERROR,
1464 + "Cannot find package %s.\n"
1465 + "Check the spelling or perhaps run 'ipkg update'\n",
1470 + /* recheck to verify that all dependences are satisfied */
1471 + if (0) ipkg_satisfy_all_dependences(conf);
1473 + ipkg_configure_packages(conf, NULL);
1475 + write_status_files_if_changed(conf);
1480 +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
1486 + global_conf = conf;
1487 + signal(SIGINT, sigint_handler);
1490 + for (i=0; i < argc; i++) {
1491 + char *arg = argv[i];
1493 + err = ipkg_prepare_url_for_install(conf, arg, &arg);
1494 + if (err != EINVAL && err != 0)
1497 + pkg_info_preinstall_check(conf);
1499 + for (i=0; i < argc; i++) {
1500 + char *arg = argv[i];
1501 + if (conf->restrict_to_default_dest) {
1502 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1504 + conf->default_dest);
1505 + if (pkg == NULL) {
1506 + ipkg_message(conf, IPKG_NOTICE,
1507 + "Package %s not installed in %s\n",
1508 + argv[i], conf->default_dest->name);
1512 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
1516 + ipkg_upgrade_pkg(conf, pkg);
1518 + ipkg_install_by_name(conf, arg);
1522 + pkg_vec_t *installed = pkg_vec_alloc();
1524 + pkg_info_preinstall_check(conf);
1526 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
1527 + for (i = 0; i < installed->len; i++) {
1528 + pkg = installed->pkgs[i];
1529 + ipkg_upgrade_pkg(conf, pkg);
1531 + pkg_vec_free(installed);
1534 + /* recheck to verify that all dependences are satisfied */
1535 + if (0) ipkg_satisfy_all_dependences(conf);
1537 + ipkg_configure_packages(conf, NULL);
1539 + write_status_files_if_changed(conf);
1544 +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
1550 + pkg_info_preinstall_check(conf);
1551 + for (i = 0; i < argc; i++) {
1554 + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
1555 + if (pkg == NULL) {
1556 + ipkg_message(conf, IPKG_ERROR,
1557 + "Cannot find package %s.\n"
1558 + "Check the spelling or perhaps run 'ipkg update'\n",
1563 + err = ipkg_download_pkg(conf, pkg, ".");
1566 + ipkg_message(conf, IPKG_ERROR,
1567 + "Failed to download %s\n", pkg->name);
1569 + ipkg_message(conf, IPKG_NOTICE,
1570 + "Downloaded %s as %s\n",
1571 + pkg->name, pkg->local_filename);
1579 +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
1582 + pkg_vec_t *available;
1584 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1586 + char *pkg_name = NULL;
1587 + char *version_str;
1590 + pkg_name = argv[0];
1592 + available = pkg_vec_alloc();
1593 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1594 + for (i=0; i < available->len; i++) {
1595 + pkg = available->pkgs[i];
1596 + /* if we have package name or pattern and pkg does not match, then skip it */
1597 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1599 + if (pkg->description) {
1600 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1602 + desc_short[0] = '\0';
1604 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1605 + newline = strchr(desc_short, '\n');
1610 + printf("%s - %s\n", pkg->name, desc_short);
1612 + if (ipkg_cb_list) {
1613 + version_str = pkg_version_str_alloc(pkg);
1614 + ipkg_cb_list(pkg->name,desc_short,
1616 + pkg->state_status,
1618 + free(version_str);
1622 + pkg_vec_free(available);
1628 +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
1631 + pkg_vec_t *available;
1633 + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
1635 + char *pkg_name = NULL;
1636 + char *version_str;
1639 + pkg_name = argv[0];
1641 + available = pkg_vec_alloc();
1642 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1643 + for (i=0; i < available->len; i++) {
1644 + pkg = available->pkgs[i];
1645 + /* if we have package name or pattern and pkg does not match, then skip it */
1646 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
1648 + if (pkg->description) {
1649 + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
1651 + desc_short[0] = '\0';
1653 + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
1654 + newline = strchr(desc_short, '\n');
1659 + printf("%s - %s\n", pkg->name, desc_short);
1661 + if (ipkg_cb_list) {
1662 + version_str = pkg_version_str_alloc(pkg);
1663 + ipkg_cb_list(pkg->name,desc_short,
1665 + pkg->state_status,
1667 + free(version_str);
1675 +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
1678 + pkg_vec_t *available;
1680 + char *pkg_name = NULL;
1681 + char **pkg_fields = NULL;
1683 + char *buff ; // = (char *)malloc(1);
1686 + pkg_name = argv[0];
1689 + pkg_fields = &argv[1];
1690 + n_fields = argc - 1;
1693 + available = pkg_vec_alloc();
1694 + if (installed_only)
1695 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1697 + pkg_hash_fetch_available(&conf->pkg_hash, available);
1698 + for (i=0; i < available->len; i++) {
1699 + pkg = available->pkgs[i];
1700 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1705 + for (j = 0; j < n_fields; j++)
1706 + pkg_print_field(pkg, stdout, pkg_fields[j]);
1708 + pkg_print_info(pkg, stdout);
1712 + buff = pkg_formatted_info(pkg);
1714 + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
1715 + pkg->state_status,
1719 + We should not forget that actually the pointer is allocated.
1720 + We need to free it :) ( Thanks florian for seeing the error )
1725 + if (conf->verbosity > 1) {
1726 + conffile_list_elt_t *iter;
1727 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
1728 + conffile_t *cf = iter->data;
1729 + int modified = conffile_has_been_modified(conf, cf);
1730 + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
1731 + cf->name, cf->value, modified);
1739 + pkg_vec_free(available);
1744 +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
1746 + return ipkg_info_status_cmd(conf, argc, argv, 0);
1749 +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
1751 + return ipkg_info_status_cmd(conf, argc, argv, 1);
1754 +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
1759 + char *pkg_name = NULL;
1761 + pkg_name = argv[0];
1763 + err = ipkg_configure_packages (conf, pkg_name);
1766 + err = ipkg_configure_packages (conf, NULL);
1769 + write_status_files_if_changed(conf);
1774 +static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv)
1777 + char *globpattern;
1780 + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
1781 + err = glob(globpattern, 0, NULL, &globbuf);
1782 + free(globpattern);
1787 + ipkg_message(conf, IPKG_NOTICE,
1788 + "The following packages in %s will now be installed.\n",
1789 + conf->pending_dir);
1790 + for (i = 0; i < globbuf.gl_pathc; i++) {
1791 + ipkg_message(conf, IPKG_NOTICE,
1792 + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
1794 + ipkg_message(conf, IPKG_NOTICE, "\n");
1795 + for (i = 0; i < globbuf.gl_pathc; i++) {
1796 + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
1798 + err = unlink(globbuf.gl_pathv[i]);
1800 + ipkg_message(conf, IPKG_ERROR,
1801 + "%s: ERROR: failed to unlink %s: %s\n",
1802 + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
1807 + globfree(&globbuf);
1812 +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
1816 + pkg_t *pkg_to_remove;
1817 + pkg_vec_t *available;
1818 + char *pkg_name = NULL;
1819 + global_conf = conf;
1820 + signal(SIGINT, sigint_handler);
1822 +// ENH: Add the "no pkg removed" just in case.
1826 + available = pkg_vec_alloc();
1827 + pkg_info_preinstall_check(conf);
1829 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
1830 + for (i=0; i < argc; i++) {
1831 + pkg_name = malloc(strlen(argv[i])+2);
1832 + strcpy(pkg_name,argv[i]);
1833 + for (a=0; a < available->len; a++) {
1834 + pkg = available->pkgs[a];
1835 + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
1838 + if (conf->restrict_to_default_dest) {
1839 + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1841 + conf->default_dest);
1843 + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
1846 + if (pkg == NULL) {
1847 + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
1850 + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
1851 + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
1854 + ipkg_remove_pkg(conf, pkg_to_remove,0);
1859 + pkg_vec_free(available);
1861 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
1862 + int flagged_pkg_count = 0;
1865 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
1867 + for (i = 0; i < installed_pkgs->len; i++) {
1868 + pkg = installed_pkgs->pkgs[i];
1869 + if (pkg->state_flag & SF_USER) {
1870 + flagged_pkg_count++;
1872 + if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
1873 + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
1876 + if (!flagged_pkg_count) {
1877 + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
1878 + "so refusing to uninstall unflagged non-leaf packages\n");
1882 + /* find packages not flagged SF_USER (i.e., installed to
1883 + * satisfy a dependence) and not having any dependents, and
1887 + for (i = 0; i < installed_pkgs->len; i++) {
1888 + pkg = installed_pkgs->pkgs[i];
1889 + if (!(pkg->state_flag & SF_USER)
1890 + && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
1892 + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
1893 + ipkg_remove_pkg(conf, pkg,0);
1897 + } while (removed);
1898 + pkg_vec_free(installed_pkgs);
1902 + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
1904 + write_status_files_if_changed(conf);
1908 +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
1913 + global_conf = conf;
1914 + signal(SIGINT, sigint_handler);
1916 + pkg_info_preinstall_check(conf);
1918 + for (i=0; i < argc; i++) {
1919 + if (conf->restrict_to_default_dest) {
1920 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1922 + conf->default_dest);
1924 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1927 + if (pkg == NULL) {
1928 + ipkg_message(conf, IPKG_ERROR,
1929 + "Package %s is not installed.\n", argv[i]);
1932 + ipkg_purge_pkg(conf, pkg);
1935 + write_status_files_if_changed(conf);
1939 +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
1943 + char *flags = argv[0];
1945 + global_conf = conf;
1946 + signal(SIGINT, sigint_handler);
1948 + for (i=1; i < argc; i++) {
1949 + if (conf->restrict_to_default_dest) {
1950 + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
1952 + conf->default_dest);
1954 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
1957 + if (pkg == NULL) {
1958 + ipkg_message(conf, IPKG_ERROR,
1959 + "Package %s is not installed.\n", argv[i]);
1962 + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
1963 + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
1964 + pkg->state_flag = pkg_state_flag_from_str(flags);
1966 +/* pb_ asked this feature 03292004 */
1967 +/* Actually I will use only this two, but this is an open for various status */
1968 + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
1969 + pkg->state_status = pkg_state_status_from_str(flags);
1971 + ipkg_state_changed++;
1972 + ipkg_message(conf, IPKG_NOTICE,
1973 + "Setting flags for package %s to %s\n",
1974 + pkg->name, flags);
1977 + write_status_files_if_changed(conf);
1981 +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
1984 + str_list_t *installed_files;
1985 + str_list_elt_t *iter;
1986 + char *pkg_version;
1987 + size_t buff_len = 8192;
1991 + buff = (char *)malloc(buff_len);
1992 + if ( buff == NULL ) {
1993 + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
2001 + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
2003 + if (pkg == NULL) {
2004 + ipkg_message(conf, IPKG_ERROR,
2005 + "Package %s not installed.\n", argv[0]);
2009 + installed_files = pkg_get_installed_files(pkg);
2010 + pkg_version = pkg_version_str_alloc(pkg);
2013 + printf("Package %s (%s) is installed on %s and has the following files:\n",
2014 + pkg->name, pkg_version, pkg->dest->name);
2015 + for (iter = installed_files->head; iter; iter = iter->next) {
2021 + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
2022 + pkg->name, pkg_version, pkg->dest->name) + 1;
2023 + if (used_len > buff_len) {
2025 + buff = realloc (buff, buff_len);
2028 + for (iter = installed_files->head; iter; iter = iter->next) {
2029 + used_len += strlen (iter->data) + 1;
2030 + while (buff_len <= used_len) {
2032 + buff = realloc (buff, buff_len);
2034 + strncat(buff, iter->data, buff_len);
2035 + strncat(buff, "\n", buff_len);
2037 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2039 + pkg_version_str_alloc(pkg),
2040 + pkg->state_status,
2046 + free(pkg_version);
2047 + pkg_free_installed_files(pkg);
2052 +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2056 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2057 + const char *rel_str = "depends on";
2060 + pkg_info_preinstall_check(conf);
2062 + if (conf->query_all)
2063 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2065 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2066 + for (i = 0; i < argc; i++) {
2067 + const char *target = argv[i];
2070 + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
2072 + for (j = 0; j < available_pkgs->len; j++) {
2073 + pkg_t *pkg = available_pkgs->pkgs[j];
2074 + if (fnmatch(target, pkg->name, 0) == 0) {
2076 + int count = pkg->depends_count + pkg->pre_depends_count;
2077 + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
2078 + target, pkg->architecture, rel_str);
2079 + for (k = 0; k < count; k++) {
2080 + compound_depend_t *cdepend = &pkg->depends[k];
2082 + for (l = 0; l < cdepend->possibility_count; l++) {
2083 + depend_t *possibility = cdepend->possibilities[l];
2084 + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
2085 + if (conf->verbosity > 0) {
2086 + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
2087 + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
2088 + if (possibility->version) {
2089 + char *typestr = NULL;
2090 + switch (possibility->constraint) {
2091 + case NONE: typestr = "none"; break;
2092 + case EARLIER: typestr = "<"; break;
2093 + case EARLIER_EQUAL: typestr = "<="; break;
2094 + case EQUAL: typestr = "="; break;
2095 + case LATER_EQUAL: typestr = ">="; break;
2096 + case LATER: typestr = ">"; break;
2098 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2102 + ipkg_message(conf, IPKG_ERROR, "\n");
2108 + pkg_vec_free(available_pkgs);
2113 +enum what_field_type {
2122 +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
2126 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2127 + const char *rel_str = NULL;
2131 + switch (what_field_type) {
2132 + case WHATDEPENDS: rel_str = "depends on"; break;
2133 + case WHATCONFLICTS: rel_str = "conflicts with"; break;
2134 + case WHATSUGGESTS: rel_str = "suggests"; break;
2135 + case WHATRECOMMENDS: rel_str = "recommends"; break;
2136 + case WHATPROVIDES: rel_str = "provides"; break;
2137 + case WHATREPLACES: rel_str = "replaces"; break;
2140 + if (conf->query_all)
2141 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2143 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2145 + /* mark the root set */
2146 + pkg_vec_clear_marks(available_pkgs);
2147 + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
2148 + for (i = 0; i < argc; i++) {
2149 + const char *dependee_pattern = argv[i];
2150 + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
2152 + for (i = 0; i < available_pkgs->len; i++) {
2153 + pkg_t *pkg = available_pkgs->pkgs[i];
2154 + if (pkg->state_flag & SF_MARKED) {
2155 + /* mark the parent (abstract) package */
2156 + pkg_mark_provides(pkg);
2157 + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
2161 + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
2166 + for (j = 0; j < available_pkgs->len; j++) {
2167 + pkg_t *pkg = available_pkgs->pkgs[j];
2169 + int count = ((what_field_type == WHATCONFLICTS)
2170 + ? pkg->conflicts_count
2171 + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
2172 + /* skip this package if it is already marked */
2173 + if (pkg->parent->state_flag & SF_MARKED) {
2176 + for (k = 0; k < count; k++) {
2177 + compound_depend_t *cdepend =
2178 + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
2180 + for (l = 0; l < cdepend->possibility_count; l++) {
2181 + depend_t *possibility = cdepend->possibilities[l];
2182 + if (possibility->pkg->state_flag & SF_MARKED) {
2183 + /* mark the depending package so we won't visit it again */
2184 + pkg->state_flag |= SF_MARKED;
2185 + pkg_mark_provides(pkg);
2188 + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
2189 + if (conf->verbosity > 0) {
2190 + char *ver = pkg_version_str_alloc(pkg);
2191 + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
2192 + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
2193 + if (possibility->version) {
2194 + char *typestr = NULL;
2195 + switch (possibility->constraint) {
2196 + case NONE: typestr = "none"; break;
2197 + case EARLIER: typestr = "<"; break;
2198 + case EARLIER_EQUAL: typestr = "<="; break;
2199 + case EQUAL: typestr = "="; break;
2200 + case LATER_EQUAL: typestr = ">="; break;
2201 + case LATER: typestr = ">"; break;
2203 + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
2206 + if (!pkg_dependence_satisfiable(conf, possibility))
2207 + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
2209 + ipkg_message(conf, IPKG_NOTICE, "\n");
2210 + goto next_package;
2217 + } while (changed && recursive);
2218 + pkg_vec_free(available_pkgs);
2224 +int pkg_mark_provides(pkg_t *pkg)
2226 + int provides_count = pkg->provides_count;
2227 + abstract_pkg_t **provides = pkg->provides;
2229 + pkg->parent->state_flag |= SF_MARKED;
2230 + for (i = 0; i < provides_count; i++) {
2231 + provides[i]->state_flag |= SF_MARKED;
2236 +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
2238 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
2240 +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2242 + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
2245 +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
2247 + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
2250 +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
2252 + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
2255 +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
2257 + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
2260 +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
2264 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
2265 + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
2268 + pkg_info_preinstall_check(conf);
2270 + if (conf->query_all)
2271 + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
2273 + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
2274 + for (i = 0; i < argc; i++) {
2275 + const char *target = argv[i];
2278 + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
2280 + for (j = 0; j < available_pkgs->len; j++) {
2281 + pkg_t *pkg = available_pkgs->pkgs[j];
2283 + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
2284 + for (k = 0; k < count; k++) {
2285 + abstract_pkg_t *apkg =
2286 + ((what_field_type == WHATPROVIDES)
2287 + ? pkg->provides[k]
2288 + : pkg->replaces[k]);
2289 + if (fnmatch(target, apkg->name, 0) == 0) {
2290 + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
2291 + if (strcmp(target, apkg->name) != 0)
2292 + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
2293 + ipkg_message(conf, IPKG_ERROR, "\n");
2298 + pkg_vec_free(available_pkgs);
2303 +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
2305 + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
2308 +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
2310 + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
2313 +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
2317 + pkg_vec_t *installed;
2319 + str_list_t *installed_files;
2320 + str_list_elt_t *iter;
2321 + char *installed_file;
2327 + installed = pkg_vec_alloc();
2328 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
2330 + for (i=0; i < installed->len; i++) {
2331 + pkg = installed->pkgs[i];
2333 + installed_files = pkg_get_installed_files(pkg);
2335 + for (iter = installed_files->head; iter; iter = iter->next) {
2336 + installed_file = iter->data;
2337 + if (fnmatch(argv[0], installed_file, 0)==0) {
2339 + printf("%s: %s\n", pkg->name, installed_file);
2341 + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
2343 + pkg_version_str_alloc(pkg),
2344 + pkg->state_status, p_userdata);
2349 + pkg_free_installed_files(pkg);
2352 + /* XXX: CLEANUP: It's not obvious from the name of
2353 + pkg_hash_fetch_all_installed that we need to call
2354 + pkg_vec_free to avoid a memory leak. */
2355 + pkg_vec_free(installed);
2360 +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
2363 + /* this is a bit gross */
2364 + struct pkg p1, p2;
2365 + parseVersion(&p1, argv[0]);
2366 + parseVersion(&p2, argv[2]);
2367 + return pkg_version_satisfied(&p1, &p2, argv[1]);
2369 + ipkg_message(conf, IPKG_ERROR,
2370 + "ipkg compare_versions <v1> <op> <v2>\n"
2371 + "<op> is one of <= >= << >> =\n");
2376 +#ifndef HOST_CPU_STR
2377 +#define HOST_CPU_STR__(X) #X
2378 +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
2379 +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
2382 +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv)
2384 + nv_pair_list_elt_t *l;
2386 + l = conf->arch_list.head;
2388 + nv_pair_t *nv = l->data;
2389 + printf("arch %s %s\n", nv->name, nv->value);
2397 +++ b/archival/libipkg/ipkg_cmd.h
2399 +/* ipkg_cmd.h - the itsy package management system
2403 + Copyright (C) 2001 University of Southern California
2405 + This program is free software; you can redistribute it and/or
2406 + modify it under the terms of the GNU General Public License as
2407 + published by the Free Software Foundation; either version 2, or (at
2408 + your option) any later version.
2410 + This program is distributed in the hope that it will be useful, but
2411 + WITHOUT ANY WARRANTY; without even the implied warranty of
2412 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2413 + General Public License for more details.
2419 +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
2424 + int requires_args;
2425 + ipkg_cmd_fun_t fun;
2427 +typedef struct ipkg_cmd ipkg_cmd_t;
2429 +ipkg_cmd_t *ipkg_cmd_find(const char *name);
2431 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
2432 + const char **argv, void *userdata);
2434 +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
2436 +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
2437 +/* install any packges with state_want == SW_INSTALL */
2438 +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
2439 +/* ensure that all dependences are satisfied */
2440 +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
2442 +int pkg_mark_provides(pkg_t *pkg);
2446 +++ b/archival/libipkg/ipkg_conf.c
2448 +/* ipkg_conf.c - the itsy package management system
2452 + Copyright (C) 2001 University of Southern California
2454 + This program is free software; you can redistribute it and/or
2455 + modify it under the terms of the GNU General Public License as
2456 + published by the Free Software Foundation; either version 2, or (at
2457 + your option) any later version.
2459 + This program is distributed in the hope that it will be useful, but
2460 + WITHOUT ANY WARRANTY; without even the implied warranty of
2461 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2462 + General Public License for more details.
2468 +#include "ipkg_conf.h"
2470 +#include "xregex.h"
2471 +#include "sprintf_alloc.h"
2472 +#include "ipkg_conf.h"
2473 +#include "ipkg_message.h"
2474 +#include "file_util.h"
2475 +#include "str_util.h"
2476 +#include "xsystem.h"
2479 +ipkg_conf_t *global_conf;
2481 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2482 + pkg_src_list_t *pkg_src_list,
2483 + nv_pair_list_t *tmp_dest_nv_pair_list,
2484 + char **tmp_lists_dir);
2485 +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
2486 +static int ipkg_conf_set_option(const ipkg_option_t *options,
2487 + const char *name, const char *value);
2488 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2489 + const char *default_dest_name);
2490 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
2491 + pkg_src_list_t *nv_pair_list);
2492 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
2493 + nv_pair_list_t *nv_pair_list, char * lists_dir);
2495 +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
2497 + ipkg_option_t tmp[] = {
2498 + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
2499 + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
2500 + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
2501 + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
2502 + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
2503 + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
2504 + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
2505 + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
2506 + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
2507 + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
2508 + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
2509 + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
2510 + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
2511 + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
2512 + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
2513 + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
2514 + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
2515 + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
2516 + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
2517 + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
2518 + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
2522 + *options = (ipkg_option_t *)malloc(sizeof(tmp));
2523 + if ( options == NULL ){
2524 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
2528 + memcpy(*options, tmp, sizeof(tmp));
2532 +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
2538 + *conf_str = strdup(arg_str);
2542 +static void ipkg_conf_free_string(char **conf_str)
2550 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
2553 + char *tmp_dir_base;
2554 + nv_pair_list_t tmp_dest_nv_pair_list;
2555 + char * lists_dir =NULL;
2557 + char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
2558 + char *pending_dir =NULL;
2560 + memset(conf, 0, sizeof(ipkg_conf_t));
2562 + pkg_src_list_init(&conf->pkg_src_list);
2564 + nv_pair_list_init(&tmp_dest_nv_pair_list);
2565 + pkg_dest_list_init(&conf->pkg_dest_list);
2567 + nv_pair_list_init(&conf->arch_list);
2569 + conf->restrict_to_default_dest = 0;
2570 + conf->default_dest = NULL;
2573 + if (args->tmp_dir)
2574 + tmp_dir_base = args->tmp_dir;
2576 + tmp_dir_base = getenv("TMPDIR");
2577 + sprintf_alloc(&conf->tmp_dir, "%s/%s",
2578 + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
2579 + IPKG_CONF_TMP_DIR_SUFFIX);
2580 + conf->tmp_dir = mkdtemp(conf->tmp_dir);
2581 + if (conf->tmp_dir == NULL) {
2582 + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
2583 + __FUNCTION__, conf->tmp_dir, strerror(errno));
2587 + conf->force_depends = 0;
2588 + conf->force_defaults = 0;
2589 + conf->force_overwrite = 0;
2590 + conf->force_downgrade = 0;
2591 + conf->force_reinstall = 0;
2592 + conf->force_space = 0;
2593 + conf->force_removal_of_essential_packages = 0;
2594 + conf->force_removal_of_dependent_packages = 0;
2596 + conf->verbose_wget = 0;
2597 + conf->offline_root = NULL;
2598 + conf->offline_root_pre_script_cmd = NULL;
2599 + conf->offline_root_post_script_cmd = NULL;
2600 + conf->multiple_providers = 0;
2601 + conf->verbosity = 1;
2602 + conf->noaction = 0;
2604 + conf->http_proxy = NULL;
2605 + conf->ftp_proxy = NULL;
2606 + conf->no_proxy = NULL;
2607 + conf->proxy_user = NULL;
2608 + conf->proxy_passwd = NULL;
2610 + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2611 + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2612 + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
2613 + lists_dir=(char *)malloc(1);
2614 + lists_dir[0]='\0';
2615 + if (args->conf_file) {
2616 + struct stat stat_buf;
2617 + err = stat(args->conf_file, &stat_buf);
2619 + if (ipkg_conf_parse_file(conf, args->conf_file,
2620 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2621 + /* Memory leakage from ipkg_conf_parse-file */
2627 + /* if (!lists_dir ){*/
2628 + if (strlen(lists_dir)<=1 ){
2629 + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
2630 + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
2633 + if (args->offline_root) {
2634 + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
2635 + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
2640 + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
2641 + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
2643 + conf->lists_dir = strdup(lists_dir);
2644 + conf->pending_dir = strdup(pending_dir);
2646 + if (args->offline_root)
2647 + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
2648 + memset(&globbuf, 0, sizeof(globbuf));
2649 + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
2652 + for (i = 0; i < globbuf.gl_pathc; i++) {
2653 + if (globbuf.gl_pathv[i])
2654 + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
2655 + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
2656 + /* Memory leakage from ipkg_conf_parse-file */
2661 + globfree(&globbuf);
2663 + /* if no architectures were defined, then default all, noarch, and host architecture */
2664 + if (nv_pair_list_empty(&conf->arch_list)) {
2665 + nv_pair_list_append(&conf->arch_list, "all", "1");
2666 + nv_pair_list_append(&conf->arch_list, "noarch", "1");
2667 + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
2670 + /* Even if there is no conf file, we'll need at least one dest. */
2671 + if (tmp_dest_nv_pair_list.head == NULL) {
2672 + nv_pair_list_append(&tmp_dest_nv_pair_list,
2673 + IPKG_CONF_DEFAULT_DEST_NAME,
2674 + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
2677 + /* After parsing the file, set options from command-line, (so that
2678 + command-line arguments take precedence) */
2679 + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
2680 + really needs to be cleaned up. There is so much duplication
2681 + right now it is ridiculous. Maybe ipkg_conf_t should just save
2682 + a pointer to args_t (which could then not be freed), rather
2683 + than duplicating every field here? */
2684 + if (args->force_depends) {
2685 + conf->force_depends = 1;
2687 + if (args->force_defaults) {
2688 + conf->force_defaults = 1;
2690 + if (args->force_overwrite) {
2691 + conf->force_overwrite = 1;
2693 + if (args->force_downgrade) {
2694 + conf->force_downgrade = 1;
2696 + if (args->force_reinstall) {
2697 + conf->force_reinstall = 1;
2699 + if (args->force_removal_of_dependent_packages) {
2700 + conf->force_removal_of_dependent_packages = 1;
2702 + if (args->force_removal_of_essential_packages) {
2703 + conf->force_removal_of_essential_packages = 1;
2705 + if (args->nodeps) {
2708 + if (args->noaction) {
2709 + conf->noaction = 1;
2711 + if (args->query_all) {
2712 + conf->query_all = 1;
2714 + if (args->verbose_wget) {
2715 + conf->verbose_wget = 1;
2717 + if (args->multiple_providers) {
2718 + conf->multiple_providers = 1;
2720 + if (args->verbosity != conf->verbosity) {
2721 + conf->verbosity = args->verbosity;
2724 + ipkg_conf_override_string(&conf->offline_root,
2725 + args->offline_root);
2726 + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
2727 + args->offline_root_pre_script_cmd);
2728 + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
2729 + args->offline_root_post_script_cmd);
2731 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
2732 + read anything from there.
2734 + if ( !(args->nocheckfordirorfile)){
2735 + /* need to run load the source list before dest list -Jamey */
2736 + if ( !(args->noreadfeedsfile))
2737 + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
2739 + /* Now that we have resolved conf->offline_root, we can commit to
2740 + the directory names for the dests and load in all the package
2742 + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
2745 + err = ipkg_conf_set_default_dest(conf, args->dest);
2751 + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
2753 + free(pending_dir);
2758 +void ipkg_conf_deinit(ipkg_conf_t *conf)
2760 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
2762 + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
2763 + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
2764 + __FUNCTION__, conf->tmp_dir);
2768 + err = rmdir(conf->tmp_dir);
2770 + if (errno == ENOTEMPTY) {
2772 + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
2773 + err = xsystem(cmd);
2777 + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
2779 +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
2781 + free(conf->tmp_dir); /*XXX*/
2783 + pkg_src_list_deinit(&conf->pkg_src_list);
2784 + pkg_dest_list_deinit(&conf->pkg_dest_list);
2785 + nv_pair_list_deinit(&conf->arch_list);
2786 + if (&conf->pkg_hash)
2787 + pkg_hash_deinit(&conf->pkg_hash);
2788 + if (&conf->file_hash)
2789 + hash_table_deinit(&conf->file_hash);
2790 + if (&conf->obs_file_hash)
2791 + hash_table_deinit(&conf->obs_file_hash);
2793 + ipkg_conf_free_string(&conf->offline_root);
2794 + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
2795 + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
2797 + if (conf->verbosity > 1) {
2799 + hash_table_t *hashes[] = {
2802 + &conf->obs_file_hash };
2803 + for (i = 0; i < 3; i++) {
2804 + hash_table_t *hash = hashes[i];
2806 + int n_conflicts = 0;
2808 + for (j = 0; j < hash->n_entries; j++) {
2810 + hash_entry_t *e = &hash->entries[j];
2813 + while (e && e->key) {
2820 + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
2821 + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
2822 + hash_table_deinit(hash);
2827 +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
2828 + const char *default_dest_name)
2830 + pkg_dest_list_elt_t *iter;
2833 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
2834 + dest = iter->data;
2835 + if (strcmp(dest->name, default_dest_name) == 0) {
2836 + conf->default_dest = dest;
2837 + conf->restrict_to_default_dest = 1;
2842 + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
2847 +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
2849 + pkg_src_list_elt_t *iter;
2853 + for (iter = pkg_src_list->head; iter; iter = iter->next) {
2855 + if (src == NULL) {
2859 + sprintf_alloc(&list_file, "%s/%s",
2860 + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
2863 + if (file_exists(list_file)) {
2864 + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
2872 +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
2874 + nv_pair_list_elt_t *iter;
2875 + nv_pair_t *nv_pair;
2879 + for (iter = nv_pair_list->head; iter; iter = iter->next) {
2880 + nv_pair = iter->data;
2882 + if (conf->offline_root) {
2883 + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
2885 + root_dir = strdup(nv_pair->value);
2887 + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
2889 + if (dest == NULL) {
2892 + if (conf->default_dest == NULL) {
2893 + conf->default_dest = dest;
2895 + if (file_exists(dest->status_file_name)) {
2896 + pkg_hash_add_from_file(conf, dest->status_file_name,
2904 +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
2905 + pkg_src_list_t *pkg_src_list,
2906 + nv_pair_list_t *tmp_dest_nv_pair_list,
2909 + ipkg_option_t * options;
2910 + FILE *file = fopen(filename, "r");
2911 + regex_t valid_line_re, comment_re;
2912 +#define regmatch_size 12
2913 + regmatch_t regmatch[regmatch_size];
2915 + if (ipkg_init_options_array(conf, &options)<0)
2918 + if (file == NULL) {
2919 + fprintf(stderr, "%s: failed to open %s: %s\n",
2920 + __FUNCTION__, filename, strerror(errno));
2924 + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
2926 + xregcomp(&comment_re,
2927 + "^[[:space:]]*(#.*|[[:space:]]*)$",
2929 + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
2934 + char *type, *name, *value, *extra;
2936 + line = file_read_line_alloc(file);
2938 + if (line == NULL) {
2944 + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
2948 + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
2950 + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
2951 + filename, line_num, line);
2955 + /* This has to be so ugly to deal with optional quotation marks */
2956 + if (regmatch[2].rm_so > 0) {
2957 + type = strndup(line + regmatch[2].rm_so,
2958 + regmatch[2].rm_eo - regmatch[2].rm_so);
2960 + type = strndup(line + regmatch[3].rm_so,
2961 + regmatch[3].rm_eo - regmatch[3].rm_so);
2963 + if (regmatch[5].rm_so > 0) {
2964 + name = strndup(line + regmatch[5].rm_so,
2965 + regmatch[5].rm_eo - regmatch[5].rm_so);
2967 + name = strndup(line + regmatch[6].rm_so,
2968 + regmatch[6].rm_eo - regmatch[6].rm_so);
2970 + if (regmatch[8].rm_so > 0) {
2971 + value = strndup(line + regmatch[8].rm_so,
2972 + regmatch[8].rm_eo - regmatch[8].rm_so);
2974 + value = strndup(line + regmatch[9].rm_so,
2975 + regmatch[9].rm_eo - regmatch[9].rm_so);
2978 + if (regmatch[11].rm_so > 0) {
2979 + extra = strndup (line + regmatch[11].rm_so,
2980 + regmatch[11].rm_eo - regmatch[11].rm_so);
2983 + /* We use the tmp_dest_nv_pair_list below instead of
2984 + conf->pkg_dest_list because we might encounter an
2985 + offline_root option later and that would invalidate the
2986 + directories we would have computed in
2987 + pkg_dest_list_init. (We do a similar thing with
2988 + tmp_src_nv_pair_list for sake of symmetry.) */
2989 + if (strcmp(type, "option") == 0) {
2990 + ipkg_conf_set_option(options, name, value);
2991 + } else if (strcmp(type, "src") == 0) {
2992 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
2993 + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
2995 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
2998 + } else if (strcmp(type, "src/gz") == 0) {
2999 + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
3000 + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
3002 + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
3005 + } else if (strcmp(type, "dest") == 0) {
3006 + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
3007 + } else if (strcmp(type, "lists_dir") == 0) {
3008 + *lists_dir = realloc(*lists_dir,strlen(value)+1);
3009 + if (*lists_dir == NULL) {
3010 + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
3014 + sprintf (*lists_dir,"%s",value);
3015 + } else if (strcmp(type, "arch") == 0) {
3016 + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
3018 + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
3019 + value = strdup("10");
3021 + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
3023 + fprintf(stderr, "WARNING: Ignoring unknown configuration "
3024 + "parameter: %s %s %s\n", type, name, value);
3040 + regfree(&comment_re);
3041 + regfree(&valid_line_re);
3047 +static int ipkg_conf_set_option(const ipkg_option_t *options,
3048 + const char *name, const char *value)
3051 + while (options[i].name) {
3052 + if (strcmp(options[i].name, name) == 0) {
3053 + switch (options[i].type) {
3054 + case IPKG_OPT_TYPE_BOOL:
3055 + *((int *)options[i].value) = 1;
3057 + case IPKG_OPT_TYPE_INT:
3059 + *((int *)options[i].value) = atoi(value);
3062 + printf("%s: Option %s need an argument\n",
3063 + __FUNCTION__, name);
3066 + case IPKG_OPT_TYPE_STRING:
3068 + *((char **)options[i].value) = strdup(value);
3071 + printf("%s: Option %s need an argument\n",
3072 + __FUNCTION__, name);
3080 + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
3081 + __FUNCTION__, name, value);
3085 +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
3087 + pkg_dest_list_elt_t *iter;
3094 + if (conf->noaction)
3096 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3097 + dest = iter->data;
3098 + dest->status_file = fopen(dest->status_file_tmp_name, "w");
3099 + if (dest->status_file == NULL) {
3100 + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
3101 + __FUNCTION__, dest->status_file_name, strerror(errno));
3105 + all = pkg_vec_alloc();
3106 + pkg_hash_fetch_available(&conf->pkg_hash, all);
3108 + for(i = 0; i < all->len; i++) {
3109 + pkg = all->pkgs[i];
3110 + /* We don't need most uninstalled packages in the status file */
3111 + if (pkg->state_status == SS_NOT_INSTALLED
3112 + && (pkg->state_want == SW_UNKNOWN
3113 + || pkg->state_want == SW_DEINSTALL
3114 + || pkg->state_want == SW_PURGE)) {
3118 + fprintf(stderr, "Null package\n");
3120 + if (pkg->dest == NULL) {
3121 + fprintf(stderr, "%s: ERROR: Can't write status for "
3122 + "package %s since it has a NULL dest\n",
3123 + __FUNCTION__, pkg->name);
3126 + if (pkg->dest->status_file) {
3127 + pkg_print_status(pkg, pkg->dest->status_file);
3131 + pkg_vec_free(all);
3133 + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
3134 + dest = iter->data;
3135 + if (dest->status_file) {
3136 + err = ferror(dest->status_file);
3137 + fclose(dest->status_file);
3138 + dest->status_file = NULL;
3140 + file_move(dest->status_file_tmp_name, dest->status_file_name);
3142 + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
3143 + "retaining old %s\n", __FUNCTION__,
3144 + dest->status_file_tmp_name, dest->status_file_name);
3153 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
3155 + char *root_filename;
3156 + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
3157 + return root_filename;
3160 +++ b/archival/libipkg/ipkg_conf.h
3162 +/* ipkg_conf.h - the itsy package management system
3166 + Copyright (C) 2001 University of Southern California
3168 + This program is free software; you can redistribute it and/or
3169 + modify it under the terms of the GNU General Public License as
3170 + published by the Free Software Foundation; either version 2, or (at
3171 + your option) any later version.
3173 + This program is distributed in the hope that it will be useful, but
3174 + WITHOUT ANY WARRANTY; without even the implied warranty of
3175 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3176 + General Public License for more details.
3179 +#ifndef IPKG_CONF_H
3180 +#define IPKG_CONF_H
3182 +typedef struct ipkg_conf ipkg_conf_t;
3184 +#include "hash_table.h"
3188 +#include "pkg_hash.h"
3189 +#include "pkg_src_list.h"
3190 +#include "pkg_dest_list.h"
3191 +#include "nv_pair_list.h"
3193 +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
3194 +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
3195 +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
3196 +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
3198 +/* In case the config file defines no dest */
3199 +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
3200 +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
3202 +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
3206 + pkg_src_list_t pkg_src_list;
3207 + pkg_dest_list_t pkg_dest_list;
3208 + nv_pair_list_t arch_list;
3210 + int restrict_to_default_dest;
3211 + pkg_dest_t *default_dest;
3214 + const char *lists_dir;
3215 + const char *pending_dir;
3218 + int force_depends;
3219 + int force_defaults;
3220 + int force_overwrite;
3221 + int force_downgrade;
3222 + int force_reinstall;
3224 + int force_removal_of_dependent_packages;
3225 + int force_removal_of_essential_packages;
3226 + int nodeps; /* do not follow dependences */
3228 + int multiple_providers;
3229 + char *offline_root;
3230 + char *offline_root_pre_script_cmd;
3231 + char *offline_root_post_script_cmd;
3236 + /* proxy options */
3241 + char *proxy_passwd;
3243 + hash_table_t pkg_hash;
3244 + hash_table_t file_hash;
3245 + hash_table_t obs_file_hash;
3248 +enum ipkg_option_type {
3249 + IPKG_OPT_TYPE_BOOL,
3250 + IPKG_OPT_TYPE_INT,
3251 + IPKG_OPT_TYPE_STRING
3253 +typedef enum ipkg_option_type ipkg_option_type_t;
3255 +typedef struct ipkg_option ipkg_option_t;
3256 +struct ipkg_option {
3258 + const ipkg_option_type_t type;
3259 + const void *value;
3262 +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
3263 +void ipkg_conf_deinit(ipkg_conf_t *conf);
3265 +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
3266 +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
3270 +++ b/archival/libipkg/ipkg_configure.c
3272 +/* ipkg_configure.c - the itsy package management system
3276 + Copyright (C) 2001 University of Southern California
3278 + This program is free software; you can redistribute it and/or
3279 + modify it under the terms of the GNU General Public License as
3280 + published by the Free Software Foundation; either version 2, or (at
3281 + your option) any later version.
3283 + This program is distributed in the hope that it will be useful, but
3284 + WITHOUT ANY WARRANTY; without even the implied warranty of
3285 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3286 + General Public License for more details.
3291 +#include "ipkg_configure.h"
3293 +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
3297 + /* DPKG_INCOMPATIBILITY:
3298 + dpkg actually does some conffile handling here, rather than at the
3299 + end of ipkg_install(). Do we care? */
3300 + /* DPKG_INCOMPATIBILITY:
3301 + dpkg actually includes a version number to this script call */
3302 + err = pkg_run_script(conf, pkg, "postinst", "configure");
3304 + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
3308 + ipkg_state_changed++;
3313 +++ b/archival/libipkg/ipkg_configure.h
3315 +/* ipkg_configure.h - the itsy package management system
3319 + Copyright (C) 2001 University of Southern California
3321 + This program is free software; you can redistribute it and/or
3322 + modify it under the terms of the GNU General Public License as
3323 + published by the Free Software Foundation; either version 2, or (at
3324 + your option) any later version.
3326 + This program is distributed in the hope that it will be useful, but
3327 + WITHOUT ANY WARRANTY; without even the implied warranty of
3328 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3329 + General Public License for more details.
3332 +#ifndef IPKG_CONFIGURE_H
3333 +#define IPKG_CONFIGURE_H
3335 +#include "ipkg_conf.h"
3337 +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
3341 +++ b/archival/libipkg/ipkg_download.c
3343 +/* ipkg_download.c - the itsy package management system
3347 + Copyright (C) 2001 University of Southern California
3349 + This program is free software; you can redistribute it and/or
3350 + modify it under the terms of the GNU General Public License as
3351 + published by the Free Software Foundation; either version 2, or (at
3352 + your option) any later version.
3354 + This program is distributed in the hope that it will be useful, but
3355 + WITHOUT ANY WARRANTY; without even the implied warranty of
3356 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3357 + General Public License for more details.
3361 +#include "ipkg_download.h"
3362 +#include "ipkg_message.h"
3364 +#include "sprintf_alloc.h"
3365 +#include "xsystem.h"
3366 +#include "file_util.h"
3367 +#include "str_util.h"
3369 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
3373 + char *src_basec = strdup(src);
3374 + char *src_base = basename(src_basec);
3375 + char *tmp_file_location;
3378 + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
3382 + if (str_starts_with(src, "file:")) {
3384 + const char *file_src = src + 5;
3385 + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
3386 + ret = file_copy(src + 5, dest_file_name);
3387 + ipkg_message(conf,IPKG_INFO,"Done.\n");
3391 + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
3392 + err = unlink(tmp_file_location);
3393 + if (err && errno != ENOENT) {
3394 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
3395 + __FUNCTION__, tmp_file_location, strerror(errno));
3396 + free(tmp_file_location);
3400 + if (conf->http_proxy) {
3401 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
3402 + setenv("http_proxy", conf->http_proxy, 1);
3404 + if (conf->ftp_proxy) {
3405 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
3406 + setenv("ftp_proxy", conf->ftp_proxy, 1);
3408 + if (conf->no_proxy) {
3409 + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
3410 + setenv("no_proxy", conf->no_proxy, 1);
3413 + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
3414 + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
3415 + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
3416 + conf->proxy_user ? "--proxy-user=" : "",
3417 + conf->proxy_user ? conf->proxy_user : "",
3418 + conf->proxy_passwd ? "--proxy-passwd=" : "",
3419 + conf->proxy_passwd ? conf->proxy_passwd : "",
3420 + conf->verbose_wget ? "" : "-q",
3423 + err = xsystem(cmd);
3426 + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
3427 + __FUNCTION__, err, cmd);
3429 + unlink(tmp_file_location);
3430 + free(tmp_file_location);
3437 + err = file_move(tmp_file_location, dest_file_name);
3439 + free(tmp_file_location);
3449 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
3454 + if (pkg->src == NULL) {
3455 + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
3456 + pkg->name, pkg->parent->name);
3460 + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
3462 + /* XXX: BUG: The pkg->filename might be something like
3463 + "../../foo.ipk". While this is correct, and exactly what we
3464 + want to use to construct url above, here we actually need to
3465 + use just the filename part, without any directory. */
3466 + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
3468 + err = ipkg_download(conf, url, pkg->local_filename);
3475 + * Downloads file from url, installs in package database, return package name.
3477 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
3485 + if (str_starts_with(url, "http://")
3486 + || str_starts_with(url, "ftp://")) {
3488 + char *file_basec = strdup(url);
3489 + char *file_base = basename(file_basec);
3491 + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
3492 + err = ipkg_download(conf, url, tmp_file);
3496 + err = pkg_init_from_file(pkg, tmp_file);
3499 + pkg->local_filename = strdup(tmp_file);
3504 + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
3505 + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
3507 + err = pkg_init_from_file(pkg, url);
3510 + pkg->local_filename = strdup(url);
3511 + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
3512 + pkg->provided_by_hand = 1;
3520 + if (!pkg->architecture) {
3521 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3525 + pkg->dest = conf->default_dest;
3526 + pkg->state_want = SW_INSTALL;
3527 + pkg->state_flag |= SF_PREFER;
3528 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3529 + if ( pkg == NULL ){
3530 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
3534 + *namep = strdup(pkg->name);
3539 +++ b/archival/libipkg/ipkg_download.h
3541 +/* ipkg_download.h - the itsy package management system
3545 + Copyright (C) 2001 University of Southern California
3547 + This program is free software; you can redistribute it and/or
3548 + modify it under the terms of the GNU General Public License as
3549 + published by the Free Software Foundation; either version 2, or (at
3550 + your option) any later version.
3552 + This program is distributed in the hope that it will be useful, but
3553 + WITHOUT ANY WARRANTY; without even the implied warranty of
3554 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3555 + General Public License for more details.
3558 +#ifndef IPKG_DOWNLOAD_H
3559 +#define IPKG_DOWNLOAD_H
3561 +#include "ipkg_conf.h"
3563 +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
3564 +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
3566 + * Downloads file from url, installs in package database, return package name.
3568 +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
3572 +++ b/archival/libipkg/ipkg.h
3574 +/* ipkg.h - the itsy package management system
3578 + Copyright (C) 2001 University of Southern California
3580 + This program is free software; you can redistribute it and/or
3581 + modify it under the terms of the GNU General Public License as
3582 + published by the Free Software Foundation; either version 2, or (at
3583 + your option) any later version.
3585 + This program is distributed in the hope that it will be useful, but
3586 + WITHOUT ANY WARRANTY; without even the implied warranty of
3587 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3588 + General Public License for more details.
3595 +#ifdef HAVE_CONFIG_H
3596 +#include "config.h"
3601 +#define IPKG_DEBUG_NO_TMP_CLEANUP
3604 +#include "ipkg_includes.h"
3605 +#include "ipkg_conf.h"
3606 +#include "ipkg_message.h"
3608 +#define IPKG_PKG_EXTENSION ".ipk"
3609 +#define DPKG_PKG_EXTENSION ".deb"
3611 +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
3612 +#define IPKG_PKG_VERSION_SEP_CHAR '_'
3614 +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
3615 +#define IPKG_LISTS_DIR_SUFFIX "lists"
3616 +#define IPKG_INFO_DIR_SUFFIX "info"
3617 +#define IPKG_STATUS_FILE_SUFFIX "status"
3619 +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
3621 +#define IPKG_LIST_DESCRIPTION_LENGTH 128
3623 +#define IPKG_VERSION "0.99.162"
3628 + IPKG_PKG_DEPS_UNSATISFIED,
3629 + IPKG_PKG_IS_ESSENTIAL,
3630 + IPKG_PKG_HAS_DEPENDENTS,
3631 + IPKG_PKG_HAS_NO_CANDIDATE
3633 +typedef enum ipkg_error ipkg_error_t;
3635 +extern int ipkg_state_changed;
3640 + struct errlist * next;
3643 +extern struct errlist* error_list;
3645 +extern ipkg_conf_t *global_conf;
3649 +++ b/archival/libipkg/ipkg_includes.h
3651 +#ifndef IPKG_INCLUDES_H
3652 +#define IPKG_INCLUDES_H
3654 +/* Define to 1 if you have the <memory.h> header file. */
3655 +#define HAVE_MEMORY_H 1
3657 +/* Define to 1 if you have the <regex.h> header file. */
3658 +#define HAVE_REGEX_H 1
3660 +/* Define to 1 if you have the <stdlib.h> header file. */
3661 +#define HAVE_STDLIB_H 1
3663 +/* Define to 1 if you have the <strings.h> header file. */
3664 +#define HAVE_STRINGS_H 1
3666 +/* Define to 1 if you have the <string.h> header file. */
3667 +#define HAVE_STRING_H 1
3669 +/* Define to 1 if you have the <sys/stat.h> header file. */
3670 +#define HAVE_SYS_STAT_H 1
3672 +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
3673 +#define HAVE_SYS_WAIT_H 1
3675 +/* Define to 1 if you have the <unistd.h> header file. */
3676 +#define HAVE_UNISTD_H 1
3678 +/* Define to 1 if you have the ANSI C header files. */
3679 +#define STDC_HEADERS 1
3685 +# include <stdlib.h>
3686 +# include <stdarg.h>
3687 +# include <stddef.h>
3688 +# include <ctype.h>
3689 +# include <errno.h>
3692 +# include <stdlib.h>
3697 +# include <regex.h>
3701 +# if !STDC_HEADERS && HAVE_MEMORY_H
3702 +# include <memory.h>
3704 +/* XXX: What's the right way to pick up GNU's strndup declaration? */
3706 +# define __USE_GNU 1
3708 +# include <string.h>
3713 +# include <strings.h>
3716 +#if HAVE_SYS_STAT_H
3717 +# include <sys/stat.h>
3720 +#if HAVE_SYS_WAIT_H
3721 +# include <sys/wait.h>
3725 +# include <sys/types.h>
3726 +# include <unistd.h>
3729 +#endif /* IPKG_INCLUDES_H */
3731 +++ b/archival/libipkg/ipkg_install.c
3733 +/* ipkg_install.c - the itsy package management system
3737 + Copyright (C) 2001 University of Southern California
3739 + This program is free software; you can redistribute it and/or
3740 + modify it under the terms of the GNU General Public License as
3741 + published by the Free Software Foundation; either version 2, or (at
3742 + your option) any later version.
3744 + This program is distributed in the hope that it will be useful, but
3745 + WITHOUT ANY WARRANTY; without even the implied warranty of
3746 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3747 + General Public License for more details.
3752 +#include <dirent.h>
3755 +#include <signal.h>
3756 +typedef void (*sighandler_t)(int);
3759 +#include "pkg_hash.h"
3760 +#include "pkg_extract.h"
3762 +#include "ipkg_install.h"
3763 +#include "ipkg_configure.h"
3764 +#include "ipkg_download.h"
3765 +#include "ipkg_remove.h"
3767 +#include "ipkg_utils.h"
3768 +#include "ipkg_message.h"
3770 +#include "sprintf_alloc.h"
3771 +#include "file_util.h"
3772 +#include "str_util.h"
3773 +#include "xsystem.h"
3776 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
3777 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
3778 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
3780 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3781 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3782 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3783 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
3784 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3785 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3786 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3787 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3788 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3789 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3790 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3791 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3792 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3794 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3795 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
3796 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
3797 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
3798 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
3800 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
3802 +static int user_prefers_old_conffile(const char *file, const char *backup);
3804 +static char *backup_filename_alloc(const char *file_name);
3805 +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
3806 +static int backup_exists_for(const char *file_name);
3807 +static int backup_remove(const char *file_name);
3810 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
3814 + char *old_version, *new_version;
3817 + if (pkg == NULL) {
3821 + err = pkg_init_from_file(pkg, filename);
3826 + if (!pkg->architecture) {
3827 + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
3831 + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
3832 + freeing the pkg that we pass in. It might be nice to clean this up
3834 + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
3835 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
3837 + pkg->local_filename = strdup(filename);
3840 + old_version = pkg_version_str_alloc(old);
3841 + new_version = pkg_version_str_alloc(pkg);
3843 + cmp = pkg_compare_versions(old, pkg);
3844 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3845 + cmp = -1 ; /* then we force ipkg to downgrade */
3846 + /* We need to use a value < 0 because in the 0 case we are asking to */
3847 + /* reinstall, and some check could fail asking the "force-reinstall" option */
3850 + ipkg_message(conf, IPKG_NOTICE,
3851 + "Not downgrading package %s on %s from %s to %s.\n",
3852 + old->name, old->dest->name, old_version, new_version);
3853 + pkg->state_want = SW_DEINSTALL;
3854 + pkg->state_flag |= SF_OBSOLETE;
3855 + free(old_version);
3856 + free(new_version);
3859 + free(old_version);
3860 + free(new_version);
3864 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3865 + return ipkg_install_pkg(conf, pkg,0);
3868 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
3872 + char *old_version, *new_version;
3874 + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
3875 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
3877 + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
3879 + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
3880 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
3882 + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
3884 +/* Pigi Basically here is broken the version stuff.
3885 + What's happening is that nothing provide the version to differents
3886 + functions, so the returned struct is always the latest.
3887 + That's why the install by name don't work.
3889 + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
3892 + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
3894 + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
3895 + ipkg_message(conf, IPKG_DEBUG2, " \n");
3897 + if (new == NULL) {
3898 + return IPKG_PKG_HAS_NO_CANDIDATE;
3901 + new->state_flag |= SF_USER;
3903 + old_version = pkg_version_str_alloc(old);
3904 + new_version = pkg_version_str_alloc(new);
3906 + cmp = pkg_compare_versions(old, new);
3907 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
3908 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
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 */
3913 + ipkg_message(conf, IPKG_DEBUG,
3914 + "Comparing visible versions of pkg %s:"
3915 + "\n\t%s is installed "
3916 + "\n\t%s is available "
3917 + "\n\t%d was comparison result\n",
3918 + pkg_name, old_version, new_version, cmp);
3919 + if (cmp == 0 && !conf->force_reinstall) {
3920 + ipkg_message(conf, IPKG_NOTICE,
3921 + "Package %s (%s) installed in %s is up to date.\n",
3922 + old->name, old_version, old->dest->name);
3923 + free(old_version);
3924 + free(new_version);
3926 + } else if (cmp > 0) {
3927 + ipkg_message(conf, IPKG_NOTICE,
3928 + "Not downgrading package %s on %s from %s to %s.\n",
3929 + old->name, old->dest->name, old_version, new_version);
3930 + free(old_version);
3931 + free(new_version);
3933 + } else if (cmp < 0) {
3934 + new->dest = old->dest;
3935 + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
3939 + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
3940 + supposed to be an ipkg_error_t, but ipkg_install_pkg could
3941 + return any kind of integer, (might be errno from a syscall,
3942 + etc.). This is a real mess and will need to be cleaned up if
3943 + anyone ever wants to make a nice libipkg. */
3945 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
3946 + return ipkg_install_pkg(conf, new,0);
3949 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
3951 + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
3954 + abstract_pkg_t *ppkg ;
3956 + if (providers == NULL)
3957 + return IPKG_PKG_HAS_NO_CANDIDATE;
3959 + for (i = 0; i < providers->len; i++) {
3960 + ppkg = abstract_pkg_vec_get(providers, i);
3961 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
3962 + err = ipkg_install_by_name(conf, ppkg->name);
3965 +/* XXX Maybe ppkg should be freed ? */
3971 + * Walk dependence graph starting with pkg, collect packages to be
3972 + * installed into pkgs_needed, in dependence order.
3974 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
3977 + pkg_vec_t *depends = pkg_vec_alloc();
3978 + char **unresolved = NULL;
3981 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
3986 + ipkg_message(conf, IPKG_ERROR,
3987 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
3988 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
3989 + while (*unresolved) {
3990 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
3993 + ipkg_message(conf, IPKG_ERROR, "\n");
3994 + if (! conf->force_depends) {
3995 + ipkg_message(conf, IPKG_INFO,
3996 + "This could mean that your package list is out of date or that the packages\n"
3997 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
3998 + "of this problem try again with the '-force-depends' option.\n");
3999 + pkg_vec_free(depends);
4000 + return IPKG_PKG_DEPS_UNSATISFIED;
4004 + if (ndepends <= 0) {
4005 + pkg_vec_free(depends);
4009 + for (i = 0; i < depends->len; i++) {
4010 + pkg_t *dep = depends->pkgs[i];
4011 + /* The package was uninstalled when we started, but another
4012 + dep earlier in this loop may have depended on it and pulled
4013 + it in, so check first. */
4014 + if ((dep->state_status != SS_INSTALLED)
4015 + && (dep->state_status != SS_UNPACKED)
4016 + && (dep->state_want != SW_INSTALL)) {
4018 + /* Mark packages as to-be-installed */
4019 + dep->state_want = SW_INSTALL;
4021 + /* Dependencies should be installed the same place as pkg */
4022 + if (dep->dest == NULL) {
4023 + dep->dest = pkg->dest;
4026 + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
4028 + pkg_vec_free(depends);
4034 + pkg_vec_insert(pkgs_needed, pkg);
4036 + pkg_vec_free(depends);
4041 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
4045 + char *old_version, *new_version;
4047 + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
4049 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
4050 + if (new == NULL) {
4051 + return IPKG_PKG_HAS_NO_CANDIDATE;
4054 + old_version = pkg_version_str_alloc(old);
4055 + new_version = pkg_version_str_alloc(new);
4057 + cmp = pkg_compare_versions(old, new);
4058 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4059 + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
4060 + cmp = -1 ; /* then we force ipkg to downgrade */
4061 + /* We need to use a value < 0 because in the 0 case we are asking to */
4062 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4064 + ipkg_message(conf, IPKG_DEBUG,
4065 + "comparing visible versions of pkg %s:"
4066 + "\n\t%s is installed "
4067 + "\n\t%s is available "
4068 + "\n\t%d was comparison result\n",
4069 + pkg_name, old_version, new_version, cmp);
4070 + if (cmp == 0 && !conf->force_reinstall) {
4071 + ipkg_message(conf, IPKG_NOTICE,
4072 + "Package %s (%s) installed in %s is up to date.\n",
4073 + old->name, old_version, old->dest->name);
4074 + free(old_version);
4075 + free(new_version);
4077 + } else if (cmp > 0) {
4078 + ipkg_message(conf, IPKG_NOTICE,
4079 + "Not downgrading package %s on %s from %s to %s.\n",
4080 + old->name, old->dest->name, old_version, new_version);
4081 + free(old_version);
4082 + free(new_version);
4084 + } else if (cmp < 0) {
4085 + new->dest = old->dest;
4086 + old->state_want = SW_DEINSTALL;
4087 + old->state_flag |= SF_OBSOLETE;
4090 + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
4095 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
4098 + pkg_vec_t *depends = pkg_vec_alloc();
4100 + char **unresolved = NULL;
4103 + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
4108 + ipkg_message(conf, IPKG_ERROR,
4109 + "%s: Cannot satisfy the following dependencies for %s:\n\t",
4110 + conf->force_depends ? "Warning" : "ERROR", pkg->name);
4111 + while (*unresolved) {
4112 + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
4115 + ipkg_message(conf, IPKG_ERROR, "\n");
4116 + if (! conf->force_depends) {
4117 + ipkg_message(conf, IPKG_INFO,
4118 + "This could mean that your package list is out of date or that the packages\n"
4119 + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
4120 + "of this problem try again with the '-force-depends' option.\n");
4121 + pkg_vec_free(depends);
4122 + return IPKG_PKG_DEPS_UNSATISFIED;
4126 + if (ndepends <= 0) {
4130 + /* Mark packages as to-be-installed */
4131 + for (i=0; i < depends->len; i++) {
4132 + /* Dependencies should be installed the same place as pkg */
4133 + if (depends->pkgs[i]->dest == NULL) {
4134 + depends->pkgs[i]->dest = pkg->dest;
4136 + depends->pkgs[i]->state_want = SW_INSTALL;
4139 + for (i = 0; i < depends->len; i++) {
4140 + dep = depends->pkgs[i];
4141 + /* The package was uninstalled when we started, but another
4142 + dep earlier in this loop may have depended on it and pulled
4143 + it in, so check first. */
4144 + if ((dep->state_status != SS_INSTALLED)
4145 + && (dep->state_status != SS_UNPACKED)) {
4146 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4147 + err = ipkg_install_pkg(conf, dep,0);
4149 + pkg_vec_free(depends);
4155 + pkg_vec_free(depends);
4161 +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
4162 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
4164 + if (conf->nodeps == 0) {
4166 + pkg_vec_t *installed = pkg_vec_alloc();
4167 + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
4168 + for (i = 0; i < installed->len; i++) {
4169 + pkg_t *pkg = installed->pkgs[i];
4170 + satisfy_dependencies_for(conf, pkg);
4172 + pkg_vec_free(installed);
4179 +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
4182 + pkg_vec_t *conflicts = NULL;
4184 + const char *prefix;
4185 + if (conf->force_depends) {
4186 + level = IPKG_NOTICE;
4187 + prefix = "Warning";
4189 + level = IPKG_ERROR;
4193 + if (!conf->force_depends)
4194 + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
4197 + ipkg_message(conf, level,
4198 + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
4200 + while (i < conflicts->len)
4201 + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
4202 + ipkg_message(conf, level, "\n");
4203 + pkg_vec_free(conflicts);
4204 + return IPKG_PKG_DEPS_UNSATISFIED;
4209 +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
4211 + str_list_t *new_list = pkg_get_installed_files(new_pkg);
4212 + str_list_elt_t *iter;
4214 + for (iter = new_list->head; iter; iter = iter->next) {
4215 + char *new_file = iter->data;
4216 + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
4218 + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
4219 + if (!owner || (owner == old_pkg))
4220 + file_hash_set_file_owner(conf, new_file, new_pkg);
4223 + str_list_t *old_list = pkg_get_installed_files(old_pkg);
4224 + for (iter = old_list->head; iter; iter = iter->next) {
4225 + char *old_file = iter->data;
4226 + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
4227 + if (owner == old_pkg) {
4229 + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
4236 +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
4238 + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
4240 + /* sma 6.20.02: yup; here's the first bit */
4242 + * XXX: BUG easy for cworth
4243 + * 1) please point the call below to the correct current root destination
4244 + * 2) we need to resolve how to check the required space for a pending pkg,
4245 + * my diddling with the .ipk file size below isn't going to cut it.
4246 + * 3) return a proper error code instead of 1
4248 + int comp_size, blocks_available;
4250 + if (!conf->force_space && pkg->installed_size != NULL) {
4251 + blocks_available = get_available_blocks(conf->default_dest->root_dir);
4253 + comp_size = strtoul(pkg->installed_size, NULL, 0);
4254 + /* round up a blocks count without doing fancy-but-slow casting jazz */
4255 + comp_size = (int)((comp_size + 1023) / 1024);
4257 + if (comp_size >= blocks_available) {
4258 + ipkg_message(conf, IPKG_ERROR,
4259 + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
4260 + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
4267 +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
4270 + char *conffiles_file_name;
4272 + FILE *conffiles_file;
4274 + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
4276 + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
4277 + if (pkg->tmp_unpack_dir == NULL) {
4278 + ipkg_message(conf, IPKG_ERROR,
4279 + "%s: Failed to create temporary directory '%s': %s\n",
4280 + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
4284 + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
4289 + /* XXX: CLEANUP: There might be a cleaner place to read in the
4290 + conffiles. Seems like I should be able to get everything to go
4291 + through pkg_init_from_file. If so, maybe it would make sense to
4292 + move all of unpack_pkg_control_files to that function. */
4294 + /* Don't need to re-read conffiles if we already have it */
4295 + if (pkg->conffiles.head) {
4299 + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
4300 + if (! file_exists(conffiles_file_name)) {
4301 + free(conffiles_file_name);
4305 + conffiles_file = fopen(conffiles_file_name, "r");
4306 + if (conffiles_file == NULL) {
4307 + fprintf(stderr, "%s: failed to open %s: %s\n",
4308 + __FUNCTION__, conffiles_file_name, strerror(errno));
4309 + free(conffiles_file_name);
4312 + free(conffiles_file_name);
4316 + char *cf_name_in_dest;
4318 + cf_name = file_read_line_alloc(conffiles_file);
4319 + if (cf_name == NULL) {
4322 + str_chomp(cf_name);
4323 + if (cf_name[0] == '\0') {
4327 + /* Prepend dest->root_dir to conffile name.
4328 + Take pains to avoid multiple slashes. */
4329 + root_dir = pkg->dest->root_dir;
4330 + if (conf->offline_root)
4331 + /* skip the offline_root prefix */
4332 + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
4333 + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
4334 + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
4336 + /* Can't get an md5sum now, (file isn't extracted yet).
4337 + We'll wait until resolve_conffiles */
4338 + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
4341 + free(cf_name_in_dest);
4344 + fclose(conffiles_file);
4349 +/* returns number of installed replacees */
4350 +int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
4352 + abstract_pkg_t **replaces = pkg->replaces;
4353 + int replaces_count = pkg->replaces_count;
4355 + for (i = 0; i < replaces_count; i++) {
4356 + abstract_pkg_t *ab_pkg = replaces[i];
4357 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
4359 + for (j = 0; j < pkg_vec->len; j++) {
4360 + pkg_t *replacee = pkg_vec->pkgs[j];
4361 + if (!pkg_conflicts(pkg, replacee))
4363 + if (replacee->state_status == SS_INSTALLED) {
4364 + pkg_vec_insert(installed_replacees, replacee);
4369 + return installed_replacees->len;
4372 +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
4375 + int replaces_count = replacees->len;
4376 + for (i = 0; i < replaces_count; i++) {
4377 + pkg_t *replacee = replacees->pkgs[i];
4379 + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
4380 + err = ipkg_remove_pkg(conf, replacee,0);
4387 +/* to unwind the removal: make sure they are installed */
4388 +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
4391 + int replaces_count = replacees->len;
4392 + for (i = 0; i < replaces_count; i++) {
4393 + pkg_t *replacee = replacees->pkgs[i];
4394 + if (replacee->state_status != SS_INSTALLED) {
4395 + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
4396 + err = ipkg_install_pkg(conf, replacee,0);
4404 +int caught_sigint = 0;
4405 +static void ipkg_install_pkg_sigint_handler(int sig)
4407 + caught_sigint = sig;
4410 +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
4411 +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
4414 + char message_out[15];
4415 + char *old_version = pkg_version_str_alloc(old_pkg);
4416 + char *new_version = pkg_version_str_alloc(pkg);
4417 + int cmp = pkg_compare_versions(old_pkg, pkg);
4420 + memset(message_out,'\x0',15);
4421 + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
4422 + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
4423 + cmp = -1 ; /* then we force ipkg to downgrade */
4424 + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
4425 + /* reinstall, and some check could fail asking the "force-reinstall" option */
4429 + ipkg_message(conf, IPKG_NOTICE,
4430 + "Not downgrading package %s on %s from %s to %s.\n",
4431 + old_pkg->name, old_pkg->dest->name, old_version, new_version);
4433 + } else if (cmp < 0) {
4434 + ipkg_message(conf, IPKG_NOTICE,
4435 + "%s%s on %s from %s to %s...\n",
4436 + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
4437 + pkg->dest = old_pkg->dest;
4439 + } else /* cmp == 0 */ {
4440 + if (conf->force_reinstall) {
4441 + ipkg_message(conf, IPKG_NOTICE,
4442 + "Reinstalling %s (%s) on %s...\n",
4443 + pkg->name, new_version, old_pkg->dest->name);
4444 + pkg->dest = old_pkg->dest;
4447 + ipkg_message(conf, IPKG_NOTICE,
4448 + "Not installing %s (%s) on %s -- already installed.\n",
4449 + pkg->name, new_version, old_pkg->dest->name);
4453 + free(old_version);
4454 + free(new_version);
4457 + char message_out[15], *version ;
4458 + memset(message_out,'\x0',15);
4460 + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
4462 + strncpy( message_out,"Installing ",strlen("Installing ") );
4463 + version = pkg_version_str_alloc(pkg);
4465 + ipkg_message(conf, IPKG_NOTICE,
4466 + "%s%s (%s) to %s...\n", message_out,
4467 + pkg->name, version, pkg->dest->name);
4473 +/* and now the meat... */
4474 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
4478 + pkg_t *old_pkg = NULL;
4479 + pkg_vec_t *replacees;
4480 + abstract_pkg_t *ab_pkg = NULL;
4481 + int old_state_flag;
4485 + if ( from_upgrade )
4486 + message = 1; /* Coming from an upgrade, and should change the output message */
4489 + ipkg_message(conf, IPKG_ERROR,
4490 + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
4494 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
4496 + if (!pkg_arch_supported(conf, pkg)) {
4497 + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
4498 + pkg->architecture, pkg->name);
4501 + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
4502 + err = satisfy_dependencies_for(conf, pkg);
4503 + if (err) { return err; }
4505 + ipkg_message(conf, IPKG_NOTICE,
4506 + "Package %s is already installed in %s.\n",
4507 + pkg->name, pkg->dest->name);
4511 + if (pkg->dest == NULL) {
4512 + pkg->dest = conf->default_dest;
4515 + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
4517 + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
4518 + if (err) { return err; }
4520 + pkg->state_want = SW_INSTALL;
4522 + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
4526 + /* Abhaya: conflicts check */
4527 + err = check_conflicts_for(conf, pkg);
4528 + if (err) { return err; }
4530 + /* this setup is to remove the upgrade scenario in the end when
4531 + installing pkg A, A deps B & B deps on A. So both B and A are
4532 + installed. Then A's installation is started resulting in an
4533 + uncecessary upgrade */
4534 + if (pkg->state_status == SS_INSTALLED
4535 + && conf->force_reinstall == 0) return 0;
4537 + err = verify_pkg_installable(conf, pkg);
4538 + if (err) { return err; }
4540 + if (pkg->local_filename == NULL) {
4541 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
4543 + ipkg_message(conf, IPKG_ERROR,
4544 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
4550 +/* Check for md5 values */
4553 + file_md5 = file_md5sum_alloc(pkg->local_filename);
4554 + if (strcmp(file_md5, pkg->md5sum))
4556 + ipkg_message(conf, IPKG_ERROR,
4557 + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
4565 + if (pkg->tmp_unpack_dir == NULL) {
4566 + unpack_pkg_control_files(conf, pkg);
4569 + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
4570 +/* Pigi: check if it will pass from here when replacing. It seems to fail */
4571 +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
4572 + err = update_file_ownership(conf, pkg, old_pkg);
4573 + if (err) { return err; }
4575 + if (conf->nodeps == 0) {
4576 + err = satisfy_dependencies_for(conf, pkg);
4577 + if (err) { return err; }
4580 + replacees = pkg_vec_alloc();
4581 + pkg_get_installed_replacees(conf, pkg, replacees);
4583 + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
4585 + sigset_t newset, oldset;
4586 + sighandler_t old_handler = NULL;
4587 + int use_signal = 0;
4588 + caught_sigint = 0;
4590 + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
4592 + sigemptyset(&newset);
4593 + sigaddset(&newset, SIGINT);
4594 + sigprocmask(SIG_BLOCK, &newset, &oldset);
4597 + ipkg_state_changed++;
4598 + pkg->state_flag |= SF_FILELIST_CHANGED;
4600 + /* XXX: BUG: we really should treat replacement more like an upgrade
4601 + * Instead, we're going to remove the replacees
4603 + err = pkg_remove_installed_replacees(conf, replacees);
4604 + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
4606 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
4607 + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
4609 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
4610 + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
4612 + err = preinst_configure(conf, pkg, old_pkg);
4613 + if (err) goto UNWIND_PREINST_CONFIGURE;
4615 + err = backup_modified_conffiles(conf, pkg, old_pkg);
4616 + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
4618 + err = check_data_file_clashes(conf, pkg, old_pkg);
4619 + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
4621 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
4622 + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
4624 + if (conf->noaction) return 0;
4626 + /* point of no return: no unwinding after this */
4627 + if (old_pkg && !conf->force_reinstall) {
4628 + old_pkg->state_want = SW_DEINSTALL;
4630 + if (old_pkg->state_flag & SF_NOPRUNE) {
4631 + ipkg_message(conf, IPKG_INFO,
4632 + " not removing obsolesced files because package marked noprune\n");
4634 + ipkg_message(conf, IPKG_INFO,
4635 + " removing obsolesced files\n");
4636 + remove_obsolesced_files(conf, pkg, old_pkg);
4638 + /* removing files from old package, to avoid ghost files */
4639 + remove_data_files_and_list(conf, old_pkg);
4640 +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
4641 + remove_maintainer_scripts_except_postrm(conf, old_pkg);
4642 + remove_postrm(conf, old_pkg);
4648 + ipkg_message(conf, IPKG_INFO,
4649 + " installing maintainer scripts\n");
4650 + install_maintainer_scripts(conf, pkg, old_pkg);
4652 + /* the following just returns 0 */
4653 + remove_disappeared(conf, pkg);
4655 + ipkg_message(conf, IPKG_INFO,
4656 + " installing data files\n");
4657 + install_data_files(conf, pkg);
4659 +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
4660 + err = check_data_file_clashes_change(conf, pkg, old_pkg);
4662 + ipkg_message(conf, IPKG_INFO,
4663 + " resolving conf files\n");
4664 + resolve_conffiles(conf, pkg);
4666 + pkg->state_status = SS_UNPACKED;
4667 + old_state_flag = pkg->state_flag;
4668 + pkg->state_flag &= ~SF_PREFER;
4669 + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
4671 + if (old_pkg && !conf->force_reinstall) {
4672 + old_pkg->state_status = SS_NOT_INSTALLED;
4675 + time(&pkg->installed_time);
4677 + ipkg_message(conf, IPKG_INFO,
4678 + " cleanup temp files\n");
4679 + cleanup_temporary_files(conf, pkg);
4681 + ab_pkg = pkg->parent;
4683 + ab_pkg->state_status = pkg->state_status;
4685 + ipkg_message(conf, IPKG_INFO, "Done.\n");
4688 + signal(SIGINT, old_handler);
4690 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4695 + UNWIND_POSTRM_UPGRADE_OLD_PKG:
4696 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4697 + UNWIND_CHECK_DATA_FILE_CLASHES:
4698 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
4699 + UNWIND_BACKUP_MODIFIED_CONFFILES:
4700 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
4701 + UNWIND_PREINST_CONFIGURE:
4702 + preinst_configure_unwind(conf, pkg, old_pkg);
4703 + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
4704 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
4705 + UNWIND_PRERM_UPGRADE_OLD_PKG:
4706 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
4707 + UNWIND_REMOVE_INSTALLED_REPLACEES:
4708 + pkg_remove_installed_replacees_unwind(conf, replacees);
4710 + ipkg_message(conf, IPKG_INFO,
4711 + " cleanup temp files\n");
4712 + cleanup_temporary_files(conf, pkg);
4714 + ipkg_message(conf, IPKG_INFO,
4717 + signal(SIGINT, old_handler);
4719 + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
4725 +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4727 + /* DPKG_INCOMPATIBILITY:
4728 + dpkg does some things here that we don't do yet. Do we care?
4730 + 1. If a version of the package is already installed, call
4731 + old-prerm upgrade new-version
4732 + 2. If the script runs but exits with a non-zero exit status
4733 + new-prerm failed-upgrade old-version
4734 + Error unwind, for both the above cases:
4735 + old-postinst abort-upgrade new-version
4740 +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4742 + /* DPKG_INCOMPATIBILITY:
4743 + dpkg does some things here that we don't do yet. Do we care?
4744 + (See prerm_upgrade_old_package for details)
4749 +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4751 + /* DPKG_INCOMPATIBILITY:
4752 + dpkg does some things here that we don't do yet. Do we care?
4753 + 2. If a 'conflicting' package is being removed at the same time:
4754 + 1. If any packages depended on that conflicting package and
4755 + --auto-deconfigure is specified, call, for each such package:
4756 + deconfigured's-prerm deconfigure \
4757 + in-favour package-being-installed version \
4758 + removing conflicting-package version
4760 + deconfigured's-postinst abort-deconfigure \
4761 + in-favour package-being-installed-but-failed version \
4762 + removing conflicting-package version
4764 + The deconfigured packages are marked as requiring
4765 + configuration, so that if --install is used they will be
4766 + configured again if possible.
4767 + 2. To prepare for removal of the conflicting package, call:
4768 + conflictor's-prerm remove in-favour package new-version
4770 + conflictor's-postinst abort-remove in-favour package new-version
4775 +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
4777 + /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
4778 + do yet. Do we care? (See prerm_deconfigure_conflictors for
4783 +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4786 + char *preinst_args;
4789 + char *old_version = pkg_version_str_alloc(old_pkg);
4790 + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
4791 + free(old_version);
4792 + } else if (pkg->state_status == SS_CONFIG_FILES) {
4793 + char *pkg_version = pkg_version_str_alloc(pkg);
4794 + sprintf_alloc(&preinst_args, "install %s", pkg_version);
4795 + free(pkg_version);
4797 + preinst_args = strdup("install");
4800 + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
4802 + ipkg_message(conf, IPKG_ERROR,
4803 + "Aborting installation of %s\n", pkg->name);
4807 + free(preinst_args);
4812 +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4814 + /* DPKG_INCOMPATIBILITY:
4815 + dpkg does the following error unwind, should we?
4816 + pkg->postrm abort-upgrade old-version
4817 + OR pkg->postrm abort-install old-version
4818 + OR pkg->postrm abort-install
4823 +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4826 + conffile_list_elt_t *iter;
4829 + if (conf->noaction) return 0;
4831 + /* Backup all modified conffiles */
4833 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4837 + cf_name = root_filename_alloc(conf, cf->name);
4839 + /* Don't worry if the conffile is just plain gone */
4840 + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
4841 + err = backup_make_backup(conf, cf_name);
4850 + /* Backup all conffiles that were not conffiles in old_pkg */
4851 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4854 + cf_name = root_filename_alloc(conf, cf->name);
4855 + /* Ignore if this was a conffile in old_pkg as well */
4856 + if (pkg_get_conffile(old_pkg, cf->name)) {
4860 + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
4861 + err = backup_make_backup(conf, cf_name);
4872 +static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4874 + conffile_list_elt_t *iter;
4877 + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
4878 + backup_remove(iter->data->name);
4882 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
4883 + backup_remove(iter->data->name);
4890 +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4892 + /* DPKG_INCOMPATIBILITY:
4893 + ipkg takes a slightly different approach than dpkg at this
4894 + point. dpkg installs each file in the new package while
4895 + creating a backup for any file that is replaced, (so that it
4896 + can unwind if necessary). To avoid complexity and redundant
4897 + storage, ipkg doesn't do any installation until later, (at the
4898 + point at which dpkg removes the backups.
4900 + But, we do have to check for data file clashes, since after
4901 + installing a package with a file clash, removing either of the
4902 + packages involved in the clash has the potential to break the
4905 + str_list_t *files_list;
4906 + str_list_elt_t *iter;
4910 + files_list = pkg_get_installed_files(pkg);
4911 + for (iter = files_list->head; iter; iter = iter->next) {
4912 + char *root_filename;
4913 + char *filename = iter->data;
4914 + root_filename = root_filename_alloc(conf, filename);
4915 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
4918 + /* Pre-existing conffiles are OK */
4919 + /* @@@@ should have way to check that it is a conffile -Jamey */
4920 + if (backup_exists_for(root_filename)) {
4924 + /* Pre-existing files are OK if force-overwrite was asserted. */
4925 + if (conf->force_overwrite) {
4926 + /* but we need to change who owns this file */
4927 + file_hash_set_file_owner(conf, filename, pkg);
4931 + owner = file_hash_get_file_owner(conf, filename);
4933 + /* Pre-existing files are OK if owned by the pkg being upgraded. */
4934 + if (owner && old_pkg) {
4935 + if (strcmp(owner->name, old_pkg->name) == 0) {
4940 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
4942 + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
4943 + if (pkg_replaces(pkg, owner)) {
4946 +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
4947 + then it's ok to overwrite. */
4948 + if (strcmp(owner->name,pkg->name)==0){
4949 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
4954 + /* Pre-existing files are OK if they are obsolete */
4955 + obs = hash_table_get(&conf->obs_file_hash, filename);
4957 + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
4961 + /* We have found a clash. */
4962 + ipkg_message(conf, IPKG_ERROR,
4963 + "Package %s wants to install file %s\n"
4964 + "\tBut that file is already provided by package ",
4965 + pkg->name, filename);
4967 + ipkg_message(conf, IPKG_ERROR,
4968 + "%s\n", owner->name);
4970 + ipkg_message(conf, IPKG_ERROR,
4971 + "<no package>\nPlease move this file out of the way and try again.\n");
4975 + free(root_filename);
4977 + pkg_free_installed_files(pkg);
4982 +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
4984 + /* Basically that's the worst hack I could do to be able to change ownership of
4985 + file list, but, being that we have no way to unwind the mods, due to structure
4986 + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
4987 + What we do here is change the ownership of file in hash if a replace ( or similar events
4989 + Only the action that are needed to change name should be considered.
4990 + @@@ To change after 1.0 release.
4992 + str_list_t *files_list;
4993 + str_list_elt_t *iter;
4997 + files_list = pkg_get_installed_files(pkg);
4998 + for (iter = files_list->head; iter; iter = iter->next) {
4999 + char *root_filename;
5000 + char *filename = iter->data;
5001 + root_filename = root_filename_alloc(conf, filename);
5002 + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
5005 + if (conf->force_overwrite) {
5006 + /* but we need to change who owns this file */
5007 + file_hash_set_file_owner(conf, filename, pkg);
5011 + owner = file_hash_get_file_owner(conf, filename);
5013 + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
5015 + if (pkg_replaces(pkg, owner)) {
5016 +/* It's now time to change the owner of that file.
5017 + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
5018 + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
5019 + file_hash_set_file_owner(conf, filename, pkg);
5025 + free(root_filename);
5027 + pkg_free_installed_files(pkg);
5032 +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5034 + /* Nothing to do since check_data_file_clashes doesn't change state */
5038 +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5040 + /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
5041 + 1. If the package is being upgraded, call
5042 + old-postrm upgrade new-version
5043 + 2. If this fails, attempt:
5044 + new-postrm failed-upgrade old-version
5045 + Error unwind, for both cases:
5046 + old-preinst abort-upgrade new-version */
5050 +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5052 + /* DPKG_INCOMPATIBILITY:
5053 + dpkg does some things here that we don't do yet. Do we care?
5054 + (See postrm_upgrade_old_pkg for details)
5059 +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5062 + str_list_t *old_files;
5063 + str_list_elt_t *of;
5064 + str_list_t *new_files;
5065 + str_list_elt_t *nf;
5067 + if (old_pkg == NULL) {
5071 + old_files = pkg_get_installed_files(old_pkg);
5072 + new_files = pkg_get_installed_files(pkg);
5074 + for (of = old_files->head; of; of = of->next) {
5078 + for (nf = new_files->head; nf; nf = nf->next) {
5080 + if (strcmp(old, new) == 0) {
5081 + goto NOT_OBSOLETE;
5084 + if (file_is_dir(old)) {
5087 + owner = file_hash_get_file_owner(conf, old);
5088 + if (owner != old_pkg) {
5089 + /* in case obsolete file no longer belongs to old_pkg */
5093 + /* old file is obsolete */
5094 + ipkg_message(conf, IPKG_INFO,
5095 + " removing obsolete file %s\n", old);
5096 + if (!conf->noaction) {
5097 + err = unlink(old);
5099 + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
5108 + pkg_free_installed_files(old_pkg);
5109 + pkg_free_installed_files(pkg);
5114 +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5118 + char *globpattern;
5122 + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
5125 + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
5126 + err = glob(globpattern, 0, NULL, &globbuf);
5127 + free(globpattern);
5131 + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
5132 + for (i = 0; i < globbuf.gl_pathc; i++) {
5133 + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
5134 + globbuf.gl_pathv[i], old_pkg->name);
5135 + if (!conf->noaction)
5136 + unlink(globbuf.gl_pathv[i]);
5138 + globfree(&globbuf);
5143 +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
5149 + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
5150 + sprintf_alloc(&prefix, "%s.", pkg->name);
5151 + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
5152 + pkg->dest->info_dir,
5158 +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
5160 + /* DPKG_INCOMPATIBILITY:
5161 + This is a fairly sophisticated dpkg operation. Shall we
5164 + /* Any packages all of whose files have been overwritten during the
5165 + installation, and which aren't required for dependencies, are
5166 + considered to have been removed. For each such package
5167 + 1. disappearer's-postrm disappear overwriter overwriter-version
5168 + 2. The package's maintainer scripts are removed
5169 + 3. It is noted in the status database as being in a sane state,
5170 + namely not installed (any conffiles it may have are ignored,
5171 + rather than being removed by dpkg). Note that disappearing
5172 + packages do not have their prerm called, because dpkg doesn't
5173 + know in advance that the package is going to vanish.
5178 +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
5182 + /* ipkg takes a slightly different approach to data file backups
5183 + than dpkg. Rather than removing backups at this point, we
5184 + actually do the data file installation now. See comments in
5185 + check_data_file_clashes() for more details. */
5187 + ipkg_message(conf, IPKG_INFO,
5188 + " extracting data files to %s\n", pkg->dest->root_dir);
5189 + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
5194 + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
5195 + so we can't save ourself from removing important packages
5196 + At this point we (should) have extracted the .control file, so it
5197 + would be a good idea to reload the data in it, and set the Essential
5198 + state in *pkg. From now on the Essential is back in status file and
5199 + we can protect again.
5200 + We should operate this way:
5201 + fopen the file ( pkg->dest->root_dir/pkg->name.control )
5202 + check for "Essential" in it
5203 + set the value in pkg->essential.
5204 + This new routine could be useful also for every other flag
5205 + Pigi: 16/03/2004 */
5206 + set_flags_from_control(conf, pkg) ;
5208 + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
5209 + err = pkg_write_filelist(conf, pkg);
5213 + /* XXX: FEATURE: ipkg should identify any files which existed
5214 + before installation and which were overwritten, (see
5215 + check_data_file_clashes()). What it must do is remove any such
5216 + files from the filelist of the old package which provided the
5217 + file. Otherwise, if the old package were removed at some point
5218 + it would break the new package. Removing the new package will
5219 + also break the old one, but this cannot be helped since the old
5220 + package's file has already been deleted. This is the importance
5221 + of check_data_file_clashes(), and only allowing ipkg to install
5222 + a clashing package with a user force. */
5227 +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
5229 + conffile_list_elt_t *iter;
5236 + if (conf->noaction) return 0;
5238 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
5239 + char *root_filename;
5241 + root_filename = root_filename_alloc(conf, cf->name);
5243 + /* Might need to initialize the md5sum for each conffile */
5244 + if (cf->value == NULL) {
5245 + cf->value = file_md5sum_alloc(root_filename);
5248 + if (!file_exists(root_filename)) {
5249 + free(root_filename);
5253 + cf_backup = backup_filename_alloc(root_filename);
5256 + if (file_exists(cf_backup)) {
5257 + /* Let's compute md5 to test if files are changed */
5258 + md5sum = file_md5sum_alloc(cf_backup);
5259 + if (strcmp( cf->value,md5sum) != 0 ) {
5260 + if (conf->force_defaults
5261 + || user_prefers_old_conffile(cf->name, cf_backup) ) {
5262 + rename(cf_backup, root_filename);
5265 + unlink(cf_backup);
5270 + free(root_filename);
5276 +static int user_prefers_old_conffile(const char *file_name, const char *backup)
5279 + const char *short_file_name;
5281 + short_file_name = strrchr(file_name, '/');
5282 + if (short_file_name) {
5283 + short_file_name++;
5285 + short_file_name = file_name;
5289 + response = get_user_response(" Configuration file '%s'\n"
5290 + " ==> File on system created by you or by a script.\n"
5291 + " ==> File also in package provided by package maintainer.\n"
5292 + " What would you like to do about it ? Your options are:\n"
5293 + " Y or I : install the package maintainer's version\n"
5294 + " N or O : keep your currently-installed version\n"
5295 + " D : show the differences between the versions (if diff is installed)\n"
5296 + " The default action is to keep your current version.\n"
5297 + " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
5298 + if (strcmp(response, "y") == 0
5299 + || strcmp(response, "i") == 0
5300 + || strcmp(response, "yes") == 0) {
5305 + if (strcmp(response, "d") == 0) {
5309 + /* XXX: BUG rewrite to use exec or busybox's internal diff */
5310 + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
5313 + printf(" [Press ENTER to continue]\n");
5314 + response = file_read_line_alloc(stdin);
5324 +/* XXX: CLEANUP: I'd like to move all of the code for
5325 + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
5326 + it would make sense to cleanup pkg->tmp_unpack_dir directly from
5327 + pkg_deinit for example). */
5328 +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
5331 + struct dirent *dirent;
5334 +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
5336 + ipkg_message(conf, IPKG_DEBUG,
5337 + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
5338 + __FUNCTION__, pkg->tmp_unpack_dir);
5342 + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
5343 + tmp_dir = opendir(pkg->tmp_unpack_dir);
5346 + dirent = readdir(tmp_dir);
5347 + if (dirent == NULL) {
5350 + sprintf_alloc(&tmp_file, "%s/%s",
5351 + pkg->tmp_unpack_dir, dirent->d_name);
5352 + if (! file_is_dir(tmp_file)) {
5357 + closedir(tmp_dir);
5358 + rmdir(pkg->tmp_unpack_dir);
5359 + free(pkg->tmp_unpack_dir);
5360 + pkg->tmp_unpack_dir = NULL;
5364 + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
5365 + pkg->name, pkg->local_filename, conf->tmp_dir);
5366 + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
5367 + unlink(pkg->local_filename);
5368 + free(pkg->local_filename);
5369 + pkg->local_filename = NULL;
5375 +static char *backup_filename_alloc(const char *file_name)
5379 + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
5384 +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
5389 + backup = backup_filename_alloc(file_name);
5390 + err = file_copy(file_name, backup);
5392 + ipkg_message(conf, IPKG_ERROR,
5393 + "%s: Failed to copy %s to %s\n",
5394 + __FUNCTION__, file_name, backup);
5402 +static int backup_exists_for(const char *file_name)
5407 + backup = backup_filename_alloc(file_name);
5409 + ret = file_exists(backup);
5416 +static int backup_remove(const char *file_name)
5420 + backup = backup_filename_alloc(file_name);
5429 +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
5431 +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
5433 + /* first, remove the packages that need removing */
5434 + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
5435 + pkg_t *pkg = pkgs_to_remove->pkgs[i];
5436 + err = ipkg_remove_pkg(conf, pkg,0);
5437 + if (err) return err;
5442 +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)
5445 + /* now one more pass checking on the ones that need to be installed */
5446 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5447 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5448 + if (pkg->dest == NULL)
5449 + pkg->dest = conf->default_dest;
5451 + pkg->state_want = SW_INSTALL;
5453 + /* Abhaya: conflicts check */
5454 + err = check_conflicts_for(conf, pkg);
5455 + if (err) { return err; }
5460 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5463 + /* now one more pass checking on the ones that need to be installed */
5464 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5465 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5467 + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
5468 + pkg_vec_t *replacees = pkg_vec_alloc();
5469 + pkg_get_installed_replacees(conf, pkg, replacees);
5471 + /* XXX: BUG: we really should treat replacement more like an upgrade
5472 + * Instead, we're going to remove the replacees
5474 + err = pkg_remove_installed_replacees(conf, replacees);
5475 + if (err) return err;
5476 + pkg->state_flag |= SF_REMOVED_REPLACEES;
5481 +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
5484 + /* now one more pass checking on the ones that need to be installed */
5485 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5486 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5487 + if (pkg->local_filename == NULL) {
5488 + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
5490 + ipkg_message(conf, IPKG_ERROR,
5491 + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
5496 + if (pkg->tmp_unpack_dir == NULL) {
5497 + err = unpack_pkg_control_files(conf, pkg);
5498 + if (err) return err;
5504 +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5507 + /* now one more pass checking on the ones that need to be installed */
5508 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5509 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5510 + pkg_t *old_pkg = pkg->old_pkg;
5512 + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
5513 + if (err) return err;
5515 + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
5516 + if (err) return err;
5518 + err = preinst_configure(conf, pkg, old_pkg);
5519 + if (err) return err;
5521 + err = backup_modified_conffiles(conf, pkg, old_pkg);
5522 + if (err) return err;
5524 + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
5525 + if (err) return err;
5530 +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5533 + /* now one more pass checking on the ones that need to be installed */
5534 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5535 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5536 + pkg_t *old_pkg = pkg->old_pkg;
5539 + old_pkg->state_want = SW_DEINSTALL;
5541 + if (old_pkg->state_flag & SF_NOPRUNE) {
5542 + ipkg_message(conf, IPKG_INFO,
5543 + " not removing obsolesced files because package marked noprune\n");
5545 + ipkg_message(conf, IPKG_INFO,
5546 + " removing obsolesced files\n");
5547 + remove_obsolesced_files(conf, pkg, old_pkg);
5551 + ipkg_message(conf, IPKG_INFO,
5552 + " installing maintainer scripts\n");
5553 + install_maintainer_scripts(conf, pkg, old_pkg);
5555 + /* the following just returns 0 */
5556 + remove_disappeared(conf, pkg);
5558 + ipkg_message(conf, IPKG_INFO,
5559 + " installing data files\n");
5560 + install_data_files(conf, pkg);
5562 + ipkg_message(conf, IPKG_INFO,
5563 + " resolving conf files\n");
5564 + resolve_conffiles(conf, pkg);
5566 + pkg->state_status = SS_UNPACKED;
5569 + old_pkg->state_status = SS_NOT_INSTALLED;
5572 + time(&pkg->installed_time);
5574 + ipkg_message(conf, IPKG_INFO,
5575 + " cleanup temp files\n");
5576 + cleanup_temporary_files(conf, pkg);
5579 + pkg->parent->state_status = pkg->state_status;
5584 +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
5587 + /* now one more pass checking on the ones that need to be installed */
5588 + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
5589 + pkg_t *pkg = pkgs_to_install->pkgs[i];
5590 + pkg_t *old_pkg = pkg->old_pkg;
5593 + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
5594 + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5595 + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
5596 + check_data_file_clashes_unwind(conf, pkg, old_pkg);
5597 + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
5598 + backup_modified_conffiles_unwind(conf, pkg, old_pkg);
5599 + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
5600 + preinst_configure_unwind(conf, pkg, old_pkg);
5601 + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
5602 + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
5603 + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
5604 + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
5606 + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
5607 + remove_installed_replacees_unwind(conf, pkg, old_pkg);
5615 + * Perform all the actions.
5617 + * pkgs_to_remove are packages marked for removal.
5618 + * pkgs_superseded are the old packages being replaced by upgrades.
5620 + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
5622 +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)
5627 + err = ipkg_remove_packages(conf, pkgs_to_remove);
5628 + if (err) return err;
5630 + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
5631 + if (err) return err;
5633 + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
5634 + if (err) goto UNWIND;
5636 + /* @@@@ look at ipkg_install_pkg for handling replacements */
5637 + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
5638 + if (err) goto UNWIND;
5641 + * Now that we have the packages unpacked, we can look for data
5642 + * file clashes. First, we mark the files from the superseded
5643 + * packages as obsolete. Then we scan the files in
5644 + * pkgs_to_install, and only complain about clashes with
5645 + * non-obsolete files.
5648 + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
5649 + if (err) goto UNWIND;
5651 + /* this was before checking data file clashes */
5652 + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
5653 + if (err) goto UNWIND;
5655 + /* point of no return: no unwinding after this */
5656 + err = ipkg_process_actions_install(conf, pkgs_to_install);
5657 + if (err) return err;
5659 + ipkg_message(conf, IPKG_INFO, "Done.\n");
5663 + ipkg_process_actions_unwind(conf, pkgs_to_install);
5665 + ipkg_message(conf, IPKG_INFO,
5666 + " cleanup temp files\n");
5667 + cleanup_temporary_files(conf, pkg);
5669 + ipkg_message(conf, IPKG_INFO,
5676 +++ b/archival/libipkg/ipkg_install.h
5678 +/* ipkg_install.h - the itsy package management system
5682 + Copyright (C) 2001 University of Southern California
5684 + This program is free software; you can redistribute it and/or
5685 + modify it under the terms of the GNU General Public License as
5686 + published by the Free Software Foundation; either version 2, or (at
5687 + your option) any later version.
5689 + This program is distributed in the hope that it will be useful, but
5690 + WITHOUT ANY WARRANTY; without even the implied warranty of
5691 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5692 + General Public License for more details.
5695 +#ifndef IPKG_INSTALL_H
5696 +#define IPKG_INSTALL_H
5699 +#include "ipkg_conf.h"
5701 +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
5702 +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
5703 +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
5704 +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
5705 +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
5707 +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
5709 +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
5710 +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
5714 +++ b/archival/libipkg/ipkg_message.c
5716 +/* ipkg_message.c - the itsy package management system
5718 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5720 + This program is free software; you can redistribute it and/or
5721 + modify it under the terms of the GNU General Public License as
5722 + published by the Free Software Foundation; either version 2, or (at
5723 + your option) any later version.
5725 + This program is distributed in the hope that it will be useful, but
5726 + WITHOUT ANY WARRANTY; without even the implied warranty of
5727 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5728 + General Public License for more details.
5733 +#include "ipkg_conf.h"
5734 +#include "ipkg_message.h"
5739 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5743 + if (conf && (conf->verbosity < level))
5750 + va_start (ap, fmt);
5751 + vprintf (fmt, ap);
5758 +#include "libipkg.h"
5760 +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
5763 +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
5768 + if (ipkg_cb_message)
5770 + va_start (ap, fmt);
5771 + vsnprintf (ts,256,fmt, ap);
5773 + ipkg_cb_message(conf,level,ts);
5778 +++ b/archival/libipkg/ipkg_message.h
5780 +/* ipkg_message.h - the itsy package management system
5782 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
5784 + This program is free software; you can redistribute it and/or
5785 + modify it under the terms of the GNU General Public License as
5786 + published by the Free Software Foundation; either version 2, or (at
5787 + your option) any later version.
5789 + This program is distributed in the hope that it will be useful, but
5790 + WITHOUT ANY WARRANTY; without even the implied warranty of
5791 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5792 + General Public License for more details.
5795 +#ifndef _IPKG_MESSAGE_H_
5796 +#define _IPKG_MESSAGE_H_
5799 +#include "ipkg_conf.h"
5802 + IPKG_ERROR, /* error conditions */
5803 + IPKG_NOTICE, /* normal but significant condition */
5804 + IPKG_INFO, /* informational message */
5805 + IPKG_DEBUG, /* debug level message */
5806 + IPKG_DEBUG2, /* more debug level message */
5809 +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
5811 +#endif /* _IPKG_MESSAGE_H_ */
5813 +++ b/archival/libipkg/ipkg_remove.c
5815 +/* ipkg_remove.c - the itsy package management system
5819 + Copyright (C) 2001 University of Southern California
5821 + This program is free software; you can redistribute it and/or
5822 + modify it under the terms of the GNU General Public License as
5823 + published by the Free Software Foundation; either version 2, or (at
5824 + your option) any later version.
5826 + This program is distributed in the hope that it will be useful, but
5827 + WITHOUT ANY WARRANTY; without even the implied warranty of
5828 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5829 + General Public License for more details.
5833 +#include "ipkg_message.h"
5837 +#include "ipkg_remove.h"
5839 +#include "file_util.h"
5840 +#include "sprintf_alloc.h"
5841 +#include "str_util.h"
5843 +#include "ipkg_cmd.h"
5846 + * Returns number of the number of packages depending on the packages provided by this package.
5847 + * Every package implicitly provides itself.
5849 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
5851 + int nprovides = pkg->provides_count;
5852 + abstract_pkg_t **provides = pkg->provides;
5853 + int n_installed_dependents = 0;
5855 + for (i = 0; i <= nprovides; i++) {
5856 + abstract_pkg_t *providee = provides[i];
5857 + abstract_pkg_t **dependers = providee->depended_upon_by;
5858 + abstract_pkg_t *dep_ab_pkg;
5859 + if (dependers == NULL)
5861 + while ((dep_ab_pkg = *dependers++) != NULL) {
5862 + if (dep_ab_pkg->state_status == SS_INSTALLED){
5863 + n_installed_dependents++;
5868 + /* if caller requested the set of installed dependents */
5869 + if (pdependents) {
5871 + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
5873 + if ( dependents == NULL ){
5874 + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
5878 + *pdependents = dependents;
5879 + for (i = 0; i <= nprovides; i++) {
5880 + abstract_pkg_t *providee = provides[i];
5881 + abstract_pkg_t **dependers = providee->depended_upon_by;
5882 + abstract_pkg_t *dep_ab_pkg;
5883 + if (dependers == NULL)
5885 + while ((dep_ab_pkg = *dependers++) != NULL) {
5886 + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
5887 + dependents[p++] = dep_ab_pkg;
5888 + dep_ab_pkg->state_flag |= SF_MARKED;
5892 + dependents[p] = NULL;
5893 + /* now clear the marks */
5894 + for (i = 0; i < p; i++) {
5895 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5896 + dep_ab_pkg->state_flag &= ~SF_MARKED;
5899 + return n_installed_dependents;
5902 +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
5907 + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
5908 + abstract_pkg_t * ab_pkg;
5910 + if((ab_pkg = pkg->parent) == NULL){
5911 + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
5912 + __FUNCTION__, pkg->name);
5916 + if (dependents == NULL)
5919 + // here i am using the dependencies_checked
5920 + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
5921 + return 0; // has already been encountered in the process
5922 + // of marking packages for removal - Karthik
5923 + ab_pkg->dependencies_checked = 2;
5927 + while (dependents [i] != NULL) {
5928 + abstract_pkg_t *dep_ab_pkg = dependents[i];
5930 + if (dep_ab_pkg->dependencies_checked == 2){
5934 + if (dep_ab_pkg->state_status == SS_INSTALLED) {
5935 + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
5936 + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
5937 + if (dep_pkg->state_status == SS_INSTALLED) {
5938 + pkg_vec_insert(dependent_pkgs, dep_pkg);
5944 + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
5945 + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
5952 + for (i = 0; i < dependent_pkgs->len; i++) {
5953 + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
5960 +static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
5962 + abstract_pkg_t *dep_ab_pkg;
5963 + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
5964 + while ((dep_ab_pkg = *dependents++) != NULL) {
5965 + if (dep_ab_pkg->state_status == SS_INSTALLED)
5966 + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
5968 + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
5969 + ipkg_message(conf, IPKG_ERROR, "");
5970 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
5971 + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
5972 + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
5973 + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
5974 + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
5978 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
5980 +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
5981 + thus I wan't check for essential, as I'm upgrading.
5982 + I hope it won't break anything :)
5985 + abstract_pkg_t *parent_pkg = NULL;
5987 + if (pkg->essential && !message) {
5988 + if (conf->force_removal_of_essential_packages) {
5989 + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
5990 + "\tIf your system breaks, you get to keep both pieces\n",
5993 + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
5994 + "\tRemoving an essential package may lead to an unusable system, but if\n"
5995 + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
5996 + "\tits will with the option: -force-removal-of-essential-packages\n",
5998 + return IPKG_PKG_IS_ESSENTIAL;
6002 + if ((parent_pkg = pkg->parent) == NULL)
6005 + /* only attempt to remove dependent installed packages if
6006 + * force_depends is not specified or the package is being
6009 + if (!conf->force_depends
6010 + && !(pkg->state_flag & SF_REPLACE)) {
6011 + abstract_pkg_t **dependents;
6012 + int has_installed_dependents =
6013 + pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
6015 + if (has_installed_dependents) {
6017 + * if this package is depended up by others, then either we should
6018 + * not remove it or we should remove it and all of its dependents
6021 + if (!conf->force_removal_of_dependent_packages
6022 + && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) {
6023 + return IPKG_PKG_HAS_DEPENDENTS;
6026 + /* remove packages depending on this package - Karthik */
6027 + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
6029 + if (err) return err;
6033 + if ( message==0 ){
6034 + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
6037 + pkg->state_flag |= SF_FILELIST_CHANGED;
6039 + pkg->state_want = SW_DEINSTALL;
6040 + ipkg_state_changed++;
6042 + pkg_run_script(conf, pkg, "prerm", "remove");
6044 + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
6045 + maintains an empty filelist rather than deleting it. That seems
6046 + like a big pain, and I don't see that that should make a big
6047 + difference, but for anyone who wants tighter compatibility,
6048 + feel free to fix this. */
6049 + remove_data_files_and_list(conf, pkg);
6051 + pkg_run_script(conf, pkg, "postrm", "remove");
6053 + remove_maintainer_scripts_except_postrm(conf, pkg);
6055 + /* Aman Gupta - Since ipkg is made for handheld devices with limited
6056 + * space, it doesn't make sense to leave extra configurations, files,
6057 + * and maintainer scripts left around. So, we make remove like purge,
6058 + * and take out all the crap :) */
6060 + remove_postrm(conf, pkg);
6061 + pkg->state_status = SS_NOT_INSTALLED;
6064 + parent_pkg->state_status = SS_NOT_INSTALLED;
6069 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
6071 + ipkg_remove_pkg(conf, pkg,0);
6075 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
6077 + str_list_t installed_dirs;
6078 + str_list_t *installed_files;
6079 + str_list_elt_t *iter;
6081 + conffile_t *conffile;
6082 + int removed_a_dir;
6085 + str_list_init(&installed_dirs);
6086 + installed_files = pkg_get_installed_files(pkg);
6088 + for (iter = installed_files->head; iter; iter = iter->next) {
6089 + file_name = iter->data;
6091 + if (file_is_dir(file_name)) {
6092 + str_list_append(&installed_dirs, strdup(file_name));
6096 + conffile = pkg_get_conffile(pkg, file_name);
6098 + /* XXX: QUESTION: Is this right? I figure we only need to
6099 + save the conffile if it has been modified. Is that what
6100 + dpkg does? Or does dpkg preserve all conffiles? If so,
6101 + this seems like a better thing to do to conserve
6103 + if (conffile_has_been_modified(conf, conffile)) {
6104 + printf(" not deleting modified conffile %s\n", file_name);
6110 + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
6111 + if (!conf->noaction)
6112 + unlink(file_name);
6115 + if (!conf->noaction) {
6117 + removed_a_dir = 0;
6118 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6119 + file_name = iter->data;
6121 + if (rmdir(file_name) == 0) {
6122 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
6123 + removed_a_dir = 1;
6124 + str_list_remove(&installed_dirs, &iter);
6127 + } while (removed_a_dir);
6130 + pkg_free_installed_files(pkg);
6131 + /* We have to remove the file list now, so that
6132 + find_pkg_owning_file does not always just report this package */
6133 + pkg_remove_installed_files_list(conf, pkg);
6135 + /* Don't print warning for dirs that are provided by other packages */
6136 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6137 + file_name = iter->data;
6139 + owner = file_hash_get_file_owner(conf, file_name);
6142 + iter->data = NULL;
6143 + str_list_remove(&installed_dirs, &iter);
6148 + for (iter = installed_dirs.head; iter; iter = iter->next) {
6150 + iter->data = NULL;
6152 + str_list_deinit(&installed_dirs);
6157 +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6160 + char *globpattern;
6163 + if (conf->noaction) return 0;
6165 + sprintf_alloc(&globpattern, "%s/%s.*",
6166 + pkg->dest->info_dir, pkg->name);
6167 + err = glob(globpattern, 0, NULL, &globbuf);
6168 + free(globpattern);
6173 + for (i = 0; i < globbuf.gl_pathc; i++) {
6174 + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
6177 + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
6178 + unlink(globbuf.gl_pathv[i]);
6180 + globfree(&globbuf);
6185 +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
6187 + char *postrm_file_name;
6189 + if (conf->noaction) return 0;
6191 + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
6192 + pkg->dest->info_dir, pkg->name);
6193 + unlink(postrm_file_name);
6194 + free(postrm_file_name);
6199 +++ b/archival/libipkg/ipkg_remove.h
6201 +/* ipkg_remove.h - the itsy package management system
6205 + Copyright (C) 2001 University of Southern California
6207 + This program is free software; you can redistribute it and/or
6208 + modify it under the terms of the GNU General Public License as
6209 + published by the Free Software Foundation; either version 2, or (at
6210 + your option) any later version.
6212 + This program is distributed in the hope that it will be useful, but
6213 + WITHOUT ANY WARRANTY; without even the implied warranty of
6214 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6215 + General Public License for more details.
6218 +#ifndef IPKG_REMOVE_H
6219 +#define IPKG_REMOVE_H
6222 +#include "ipkg_conf.h"
6224 +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
6225 +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
6226 +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
6227 +int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
6228 +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
6229 +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6230 +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
6235 +++ b/archival/libipkg/ipkg_upgrade.c
6237 +/* ipkg_upgrade.c - the itsy package management system
6240 + Copyright (C) 2001 University of Southern California
6242 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6244 + This program is free software; you can redistribute it and/or
6245 + modify it under the terms of the GNU General Public License as
6246 + published by the Free Software Foundation; either version 2, or (at
6247 + your option) any later version.
6249 + This program is distributed in the hope that it will be useful, but
6250 + WITHOUT ANY WARRANTY; without even the implied warranty of
6251 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6252 + General Public License for more details.
6256 +#include "ipkg_install.h"
6257 +#include "ipkg_message.h"
6259 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
6263 + char *old_version, *new_version;
6265 + if (old->state_flag & SF_HOLD) {
6266 + ipkg_message(conf, IPKG_NOTICE,
6267 + "Not upgrading package %s which is marked "
6268 + "hold (flags=%#x)\n", old->name, old->state_flag);
6272 + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
6273 + if (new == NULL) {
6274 + old_version = pkg_version_str_alloc(old);
6275 + ipkg_message(conf, IPKG_NOTICE,
6276 + "Assuming locally installed package %s (%s) "
6277 + "is up to date.\n", old->name, old_version);
6278 + free(old_version);
6282 + old_version = pkg_version_str_alloc(old);
6283 + new_version = pkg_version_str_alloc(new);
6285 + cmp = pkg_compare_versions(old, new);
6286 + ipkg_message(conf, IPKG_DEBUG,
6287 + "comparing visible versions of pkg %s:"
6288 + "\n\t%s is installed "
6289 + "\n\t%s is available "
6290 + "\n\t%d was comparison result\n",
6291 + old->name, old_version, new_version, cmp);
6293 + ipkg_message(conf, IPKG_INFO,
6294 + "Package %s (%s) installed in %s is up to date.\n",
6295 + old->name, old_version, old->dest->name);
6296 + free(old_version);
6297 + free(new_version);
6299 + } else if (cmp > 0) {
6300 + ipkg_message(conf, IPKG_NOTICE,
6301 + "Not downgrading package %s on %s from %s to %s.\n",
6302 + old->name, old->dest->name, old_version, new_version);
6303 + free(old_version);
6304 + free(new_version);
6306 + } else if (cmp < 0) {
6307 + new->dest = old->dest;
6308 + old->state_want = SW_DEINSTALL;
6311 + new->state_flag |= SF_USER;
6312 + return ipkg_install_pkg(conf, new,1);
6315 +++ b/archival/libipkg/ipkg_upgrade.h
6317 +/* ipkg_upgrade.c - the itsy package management system
6319 + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
6321 + This program is free software; you can redistribute it and/or
6322 + modify it under the terms of the GNU General Public License as
6323 + published by the Free Software Foundation; either version 2, or (at
6324 + your option) any later version.
6326 + This program is distributed in the hope that it will be useful, but
6327 + WITHOUT ANY WARRANTY; without even the implied warranty of
6328 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6329 + General Public License for more details.
6334 +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
6336 +++ b/archival/libipkg/ipkg_utils.c
6338 +/* ipkg_utils.c - the itsy package management system
6342 + Copyright (C) 2002 Compaq Computer Corporation
6344 + This program is free software; you can redistribute it and/or
6345 + modify it under the terms of the GNU General Public License as
6346 + published by the Free Software Foundation; either version 2, or (at
6347 + your option) any later version.
6349 + This program is distributed in the hope that it will be useful, but
6350 + WITHOUT ANY WARRANTY; without even the implied warranty of
6351 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6352 + General Public License for more details.
6358 +#include <sys/vfs.h>
6360 +#include "ipkg_utils.h"
6362 +#include "pkg_hash.h"
6364 +struct errlist* error_list;
6366 +int get_available_blocks(char * filesystem)
6368 + struct statfs sfs;
6370 + if(statfs(filesystem, &sfs)){
6371 + fprintf(stderr, "bad statfs\n");
6374 + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
6375 + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
6378 +char **read_raw_pkgs_from_file(const char *file_name)
6383 + if(!(fp = fopen(file_name, "r"))){
6384 + fprintf(stderr, "can't get %s open for read\n", file_name);
6388 + ret = read_raw_pkgs_from_stream(fp);
6395 +char **read_raw_pkgs_from_stream(FILE *fp)
6397 + char **raw = NULL, *buf, *scout;
6399 + size_t size = 512;
6401 + buf = malloc (size);
6403 + while (fgets(buf, size, fp)) {
6404 + while (strlen (buf) == (size - 1)
6405 + && buf[size-2] != '\n') {
6406 + size_t o = size - 1;
6408 + buf = realloc (buf, size);
6409 + if (fgets (buf + o, size - o, fp) == NULL)
6414 + raw = realloc(raw, (count + 50) * sizeof(char *));
6416 + if((scout = strchr(buf, '\n')))
6419 + raw[count++] = strdup(buf);
6422 + raw = realloc(raw, (count + 1) * sizeof(char *));
6423 + raw[count] = NULL;
6430 +/* something to remove whitespace, a hash pooper */
6431 +char *trim_alloc(char *line)
6434 + char *dest, *src, *end;
6436 + new = malloc(strlen(line) + 1);
6437 + if ( new == NULL ){
6438 + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
6441 + dest = new, src = line, end = line + (strlen(line) - 1);
6443 + /* remove it from the front */
6448 + /* and now from the back */
6449 + while((end > src) &&
6455 + /* this does from the first space
6456 + * blasting away any versions stuff in depends
6467 +int line_is_blank(const char *line)
6471 + for (s = line; *s; s++) {
6478 +void push_error_list(struct errlist ** errors, char * msg){
6479 + struct errlist *err_lst_tmp;
6482 + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
6483 + err_lst_tmp->errmsg=strdup(msg) ;
6484 + err_lst_tmp->next = *errors;
6485 + *errors = err_lst_tmp;
6489 +void reverse_error_list(struct errlist **errors){
6490 + struct errlist *result=NULL;
6491 + struct errlist *current= *errors;
6492 + struct errlist *next;
6494 + while ( current != NULL ) {
6495 + next = current->next;
6496 + current->next=result;
6505 +void free_error_list(struct errlist **errors){
6506 + struct errlist *current = *errors;
6508 + while (current != NULL) {
6509 + free(current->errmsg);
6510 + current = (*errors)->next;
6512 + *errors = current;
6520 +++ b/archival/libipkg/ipkg_utils.h
6522 +/* ipkg_utils.h - the itsy package management system
6526 + Copyright (C) 2002 Compaq Computer Corporation
6528 + This program is free software; you can redistribute it and/or
6529 + modify it under the terms of the GNU General Public License as
6530 + published by the Free Software Foundation; either version 2, or (at
6531 + your option) any later version.
6533 + This program is distributed in the hope that it will be useful, but
6534 + WITHOUT ANY WARRANTY; without even the implied warranty of
6535 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6536 + General Public License for more details.
6539 +#ifndef IPKG_UTILS_H
6540 +#define IPKG_UTILS_H
6544 +int get_available_blocks(char * filesystem);
6545 +char **read_raw_pkgs_from_file(const char *file_name);
6546 +char **read_raw_pkgs_from_stream(FILE *fp);
6547 +char *trim_alloc(char * line);
6548 +int line_is_blank(const char *line);
6552 +++ b/archival/libipkg/Kbuild
6554 +# Makefile for busybox
6556 +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6557 +# Copyright (C) 2006 OpenWrt.org
6559 +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6561 +LIBIPKG_CORE_OBJS:= \
6566 +LIBIPKG_CMD_OBJS:= \
6568 + ipkg_configure.o \
6574 +LIBIPKG_DB_OBJS:= \
6585 +LIBIPKG_LIST_OBJS:= \
6597 +LIBIPKG_UTIL_OBJS:= \
6604 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
6605 +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
6606 +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
6607 +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
6608 +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
6610 +ifeq ($(strip $(IPKG_ARCH)),)
6611 +IPKG_ARCH:=$(TARGET_ARCH)
6613 +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
6615 +++ b/archival/libipkg/libipkg.c
6617 +/* ipkglib.c - the itsy package management system
6621 + Copyright (C) 2003 kernel concepts
6623 + This program is free software; you can redistribute it and/or
6624 + modify it under the terms of the GNU General Public License as
6625 + published by the Free Software Foundation; either version 2, or (at
6626 + your option) any later version.
6628 + This program is distributed in the hope that it will be useful, but
6629 + WITHOUT ANY WARRANTY; without even the implied warranty of
6630 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6631 + General Public License for more details.
6637 +#include "ipkg_includes.h"
6638 +#include "libipkg.h"
6641 +#include "ipkg_conf.h"
6642 +#include "ipkg_cmd.h"
6643 +#include "file_util.h"
6647 +ipkg_message_callback ipkg_cb_message = NULL;
6648 +ipkg_response_callback ipkg_cb_response = NULL;
6649 +ipkg_status_callback ipkg_cb_status = NULL;
6650 +ipkg_list_callback ipkg_cb_list = NULL;
6654 +ipkg_init (ipkg_message_callback mcall,
6655 + ipkg_response_callback rcall,
6658 + ipkg_cb_message = mcall;
6659 + ipkg_cb_response = rcall;
6668 +ipkg_deinit (args_t * args)
6670 + args_deinit (args);
6671 + ipkg_cb_message = NULL;
6672 + ipkg_cb_response = NULL;
6674 + /* place other cleanup stuff here */
6681 +ipkg_packages_list(args_t *args,
6682 + const char *packages,
6683 + ipkg_list_callback cblist,
6687 + ipkg_conf_t ipkg_conf;
6690 + err = ipkg_conf_init (&ipkg_conf, args);
6696 + ipkg_cb_list = cblist;
6697 + /* we need to do this because of static declarations,
6698 + * maybe a good idea to change */
6699 + cmd = ipkg_cmd_find ("list");
6701 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6703 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6704 + ipkg_cb_list = NULL;
6705 + ipkg_conf_deinit (&ipkg_conf);
6711 +ipkg_packages_status(args_t *args,
6712 + const char *packages,
6713 + ipkg_status_callback cbstatus,
6717 + ipkg_conf_t ipkg_conf;
6720 + err = ipkg_conf_init (&ipkg_conf, args);
6726 + ipkg_cb_status = cbstatus;
6728 + /* we need to do this because of static declarations,
6729 + * maybe a good idea to change */
6730 + cmd = ipkg_cmd_find ("status");
6732 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6734 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6736 + ipkg_cb_status = NULL;
6737 + ipkg_conf_deinit (&ipkg_conf);
6743 +ipkg_packages_info(args_t *args,
6744 + const char *packages,
6745 + ipkg_status_callback cbstatus,
6749 + ipkg_conf_t ipkg_conf;
6752 + err = ipkg_conf_init (&ipkg_conf, args);
6758 + ipkg_cb_status = cbstatus;
6760 + /* we need to do this because of static declarations,
6761 + * maybe a good idea to change */
6762 + cmd = ipkg_cmd_find ("info");
6764 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
6766 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
6768 + ipkg_cb_status = NULL;
6769 + ipkg_conf_deinit (&ipkg_conf);
6775 +ipkg_packages_install (args_t * args, const char *name)
6778 + ipkg_conf_t ipkg_conf;
6781 + /* this error should be handled in application */
6782 + if (!name || !strlen (name))
6785 + err = ipkg_conf_init (&ipkg_conf, args);
6791 + /* we need to do this because of static declarations,
6792 + * maybe a good idea to change */
6793 + cmd = ipkg_cmd_find ("install");
6794 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6796 + ipkg_conf_deinit(&ipkg_conf);
6802 +ipkg_packages_remove(args_t *args, const char *name, int purge)
6805 + ipkg_conf_t ipkg_conf;
6808 + /* this error should be handled in application */
6809 + if (!name || !strlen (name))
6812 + err = ipkg_conf_init (&ipkg_conf, args);
6818 + /* we need to do this because of static declarations,
6819 + * maybe a good idea to change */
6821 + cmd = ipkg_cmd_find ("purge");
6823 + cmd = ipkg_cmd_find ("remove");
6825 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6827 + ipkg_conf_deinit(&ipkg_conf);
6833 +ipkg_lists_update(args_t *args)
6836 + ipkg_conf_t ipkg_conf;
6839 + err = ipkg_conf_init (&ipkg_conf, args);
6845 + /* we need to do this because of static declarations,
6846 + * maybe a good idea to change */
6847 + cmd = ipkg_cmd_find ("update");
6849 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6851 + ipkg_conf_deinit(&ipkg_conf);
6857 +ipkg_packages_upgrade(args_t *args)
6860 + ipkg_conf_t ipkg_conf;
6863 + err = ipkg_conf_init (&ipkg_conf, args);
6869 + /* we need to do this because of static declarations,
6870 + * maybe a good idea to change */
6871 + cmd = ipkg_cmd_find ("upgrade");
6873 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
6875 + ipkg_conf_deinit(&ipkg_conf);
6881 +ipkg_packages_download (args_t * args, const char *name)
6884 + ipkg_conf_t ipkg_conf;
6887 + /* this error should be handled in application */
6888 + if (!name || !strlen (name))
6891 + err = ipkg_conf_init (&ipkg_conf, args);
6897 + /* we need to do this because of static declarations,
6898 + * maybe a good idea to change */
6899 + cmd = ipkg_cmd_find ("download");
6900 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
6902 + ipkg_conf_deinit(&ipkg_conf);
6908 +ipkg_package_files(args_t *args,
6910 + ipkg_list_callback cblist,
6914 + ipkg_conf_t ipkg_conf;
6917 + /* this error should be handled in application */
6918 + if (!name || !strlen (name))
6921 + err = ipkg_conf_init (&ipkg_conf, args);
6927 + ipkg_cb_list = cblist;
6929 + /* we need to do this because of static declarations,
6930 + * maybe a good idea to change */
6931 + cmd = ipkg_cmd_find ("files");
6933 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
6935 + ipkg_cb_list = NULL;
6936 + ipkg_conf_deinit(&ipkg_conf);
6942 +ipkg_file_search(args_t *args,
6944 + ipkg_list_callback cblist,
6948 + ipkg_conf_t ipkg_conf;
6951 + /* this error should be handled in application */
6952 + if (!file || !strlen (file))
6955 + err = ipkg_conf_init (&ipkg_conf, args);
6961 + ipkg_cb_list = cblist;
6963 + /* we need to do this because of static declarations,
6964 + * maybe a good idea to change */
6965 + cmd = ipkg_cmd_find ("search");
6966 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
6968 + ipkg_cb_list = NULL;
6969 + ipkg_conf_deinit(&ipkg_conf);
6975 +ipkg_file_what(args_t *args, const char *file, const char* command)
6978 + ipkg_conf_t ipkg_conf;
6981 + /* this error should be handled in application */
6982 + if (!file || !strlen (file))
6985 + err = ipkg_conf_init (&ipkg_conf, args);
6991 + /* we need to do this because of static declarations,
6992 + * maybe a good idea to change */
6993 + cmd = ipkg_cmd_find (command);
6994 + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
6996 + ipkg_conf_deinit(&ipkg_conf);
7000 +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
7001 +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
7002 +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
7003 +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
7004 +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
7007 +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
7010 + if (conf && (conf->verbosity < level)) {
7014 + if ( level == IPKG_ERROR ){
7015 + push_error_list(&error_list, msg);
7024 +int default_ipkg_list_callback(char *name, char *desc, char *version,
7025 + pkg_state_status_t status, void *userdata)
7028 + printf("%s - %s - %s\n", name, version, desc);
7030 + printf("%s - %s\n", name, version);
7034 +int default_ipkg_files_callback(char *name, char *desc, char *version,
7035 + pkg_state_status_t status, void *userdata)
7038 + printf("%s\n", desc);
7042 +int default_ipkg_status_callback(char *name, int istatus, char *desc,
7045 + printf("%s\n", desc);
7049 +char* default_ipkg_response_callback(char *question)
7051 + char *response = NULL;
7055 + response = (char *)file_read_line_alloc(stdin);
7056 + } while (response == NULL);
7060 +/* This is used for backward compatibility */
7062 +ipkg_op (int argc, char *argv[])
7064 + int err, opt_index;
7068 + ipkg_conf_t ipkg_conf;
7070 + args_init (&args);
7072 + opt_index = args_parse (&args, argc, argv);
7073 + if (opt_index == argc || opt_index < 0)
7075 + args_usage ("ipkg must have one sub-command argument");
7078 + cmd_name = argv[opt_index++];
7079 +/* Pigi: added a flag to disable the checking of structures if the command does not need to
7080 + read anything from there.
7082 + if ( !strcmp(cmd_name,"print-architecture") ||
7083 + !strcmp(cmd_name,"print_architecture") ||
7084 + !strcmp(cmd_name,"print-installation-architecture") ||
7085 + !strcmp(cmd_name,"print_installation_architecture") )
7086 + args.nocheckfordirorfile = 1;
7088 +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
7089 + read anything from there.
7091 + if ( !strcmp(cmd_name,"flag") ||
7092 + !strcmp(cmd_name,"configure") ||
7093 + !strcmp(cmd_name,"remove") ||
7094 + !strcmp(cmd_name,"files") ||
7095 + !strcmp(cmd_name,"search") ||
7096 + !strcmp(cmd_name,"compare_versions") ||
7097 + !strcmp(cmd_name,"compare-versions") ||
7098 + !strcmp(cmd_name,"list_installed") ||
7099 + !strcmp(cmd_name,"list-installed") ||
7100 + !strcmp(cmd_name,"status") )
7101 + args.noreadfeedsfile = 1;
7104 + err = ipkg_conf_init (&ipkg_conf, &args);
7110 + args_deinit (&args);
7112 + ipkg_cb_message = default_ipkg_message_callback;
7113 + ipkg_cb_response = default_ipkg_response_callback;
7114 + ipkg_cb_status = default_ipkg_status_callback;
7115 + if ( strcmp(cmd_name, "files")==0)
7116 + ipkg_cb_list = default_ipkg_files_callback;
7118 + ipkg_cb_list = default_ipkg_list_callback;
7120 + cmd = ipkg_cmd_find (cmd_name);
7123 + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
7125 + args_usage (NULL);
7128 + if (cmd->requires_args && opt_index == argc)
7131 + "%s: the ``%s'' command requires at least one argument\n",
7132 + __FUNCTION__, cmd_name);
7133 + args_usage (NULL);
7136 + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL);
7138 + ipkg_conf_deinit (&ipkg_conf);
7143 +#endif /* IPKG_LIB */
7145 +++ b/archival/libipkg/libipkg.h
7147 +/* ipkglib.h - the itsy package management system
7149 + Florian Boor <florian.boor@kernelconcepts.de>
7151 + This program is free software; you can redistribute it and/or
7152 + modify it under the terms of the GNU General Public License as
7153 + published by the Free Software Foundation; either version 2, or (at
7154 + your option) any later version.
7156 + This program is distributed in the hope that it will be useful, but
7157 + WITHOUT ANY WARRANTY; without even the implied warranty of
7158 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7159 + General Public License for more details.
7167 +#include "ipkg_conf.h"
7168 +#include "ipkg_message.h"
7174 +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
7176 +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
7177 + pkg_state_status_t status, void *userdata);
7178 +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
7180 +typedef char* (*ipkg_response_callback)(char *question);
7182 +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
7183 +extern int ipkg_init (ipkg_message_callback mcall,
7184 + ipkg_response_callback rcall,
7187 +extern int ipkg_deinit (args_t *args);
7188 +extern int ipkg_packages_list(args_t *args,
7189 + const char *packages,
7190 + ipkg_list_callback cblist,
7192 +extern int ipkg_packages_status(args_t *args,
7193 + const char *packages,
7194 + ipkg_status_callback cbstatus,
7196 +extern int ipkg_packages_info(args_t *args,
7197 + const char *packages,
7198 + ipkg_status_callback cbstatus,
7200 +extern int ipkg_packages_install(args_t *args, const char *name);
7201 +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
7202 +extern int ipkg_lists_update(args_t *args);
7203 +extern int ipkg_packages_upgrade(args_t *args);
7204 +extern int ipkg_packages_download(args_t *args, const char *name);
7205 +extern int ipkg_package_files(args_t *args,
7207 + ipkg_list_callback cblist,
7209 +extern int ipkg_file_search(args_t *args,
7211 + ipkg_list_callback cblist,
7213 +extern int ipkg_package_whatdepends(args_t *args, const char *file);
7214 +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
7215 +extern int ipkg_package_whatprovides(args_t *args, const char *file);
7216 +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
7217 +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
7219 +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
7220 +extern ipkg_response_callback ipkg_cb_response;
7221 +extern ipkg_status_callback ipkg_cb_status;
7222 +extern ipkg_list_callback ipkg_cb_list;
7223 +extern void push_error_list(struct errlist **errors,char * msg);
7224 +extern void reverse_error_list(struct errlist **errors);
7225 +extern void free_error_list(struct errlist **errors);
7229 +extern int ipkg_op(int argc, char *argv[]);
7236 +++ b/archival/libipkg/nv_pair.c
7238 +/* nv_pair.c - the itsy package management system
7242 + Copyright (C) 2001 University of Southern California
7244 + This program is free software; you can redistribute it and/or
7245 + modify it under the terms of the GNU General Public License as
7246 + published by the Free Software Foundation; either version 2, or (at
7247 + your option) any later version.
7249 + This program is distributed in the hope that it will be useful, but
7250 + WITHOUT ANY WARRANTY; without even the implied warranty of
7251 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7252 + General Public License for more details.
7257 +#include "nv_pair.h"
7258 +#include "str_util.h"
7260 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
7262 + nv_pair->name = str_dup_safe(name);
7263 + nv_pair->value = str_dup_safe(value);
7268 +void nv_pair_deinit(nv_pair_t *nv_pair)
7270 + free(nv_pair->name);
7271 + nv_pair->name = NULL;
7273 + free(nv_pair->value);
7274 + nv_pair->value = NULL;
7279 +++ b/archival/libipkg/nv_pair.h
7281 +/* nv_pair.h - the itsy package management system
7285 + Copyright (C) 2001 University of Southern California
7287 + This program is free software; you can redistribute it and/or
7288 + modify it under the terms of the GNU General Public License as
7289 + published by the Free Software Foundation; either version 2, or (at
7290 + your option) any later version.
7292 + This program is distributed in the hope that it will be useful, but
7293 + WITHOUT ANY WARRANTY; without even the implied warranty of
7294 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7295 + General Public License for more details.
7301 +typedef struct nv_pair nv_pair_t;
7308 +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
7309 +void nv_pair_deinit(nv_pair_t *nv_pair);
7314 +++ b/archival/libipkg/nv_pair_list.c
7316 +/* nv_pair_list.c - the itsy package management system
7320 + Copyright (C) 2001 University of Southern California
7322 + This program is free software; you can redistribute it and/or
7323 + modify it under the terms of the GNU General Public License as
7324 + published by the Free Software Foundation; either version 2, or (at
7325 + your option) any later version.
7327 + This program is distributed in the hope that it will be useful, but
7328 + WITHOUT ANY WARRANTY; without even the implied warranty of
7329 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7330 + General Public License for more details.
7335 +#include "nv_pair.h"
7336 +#include "void_list.h"
7337 +#include "nv_pair_list.h"
7339 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
7341 + return void_list_elt_init((void_list_elt_t *) elt, data);
7344 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
7346 + void_list_elt_deinit((void_list_elt_t *) elt);
7349 +int nv_pair_list_init(nv_pair_list_t *list)
7351 + return void_list_init((void_list_t *) list);
7354 +void nv_pair_list_deinit(nv_pair_list_t *list)
7356 + nv_pair_list_elt_t *iter;
7357 + nv_pair_t *nv_pair;
7359 + for (iter = list->head; iter; iter = iter->next) {
7360 + nv_pair = iter->data;
7361 + nv_pair_deinit(nv_pair);
7363 + /* malloced in nv_pair_list_append */
7365 + iter->data = NULL;
7367 + void_list_deinit((void_list_t *) list);
7370 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
7374 + /* freed in nv_pair_list_deinit */
7375 + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
7377 + if (nv_pair == NULL) {
7378 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7381 + nv_pair_init(nv_pair, name, value);
7383 + err = void_list_append((void_list_t *) list, nv_pair);
7391 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
7393 + return void_list_push((void_list_t *) list, data);
7396 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
7398 + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
7401 +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
7403 + nv_pair_list_elt_t *iter;
7404 + nv_pair_t *nv_pair;
7406 + for (iter = list->head; iter; iter = iter->next) {
7407 + nv_pair = iter->data;
7408 + if (strcmp(nv_pair->name, name) == 0) {
7409 + return nv_pair->value;
7415 +++ b/archival/libipkg/nv_pair_list.h
7417 +/* nv_pair_list.h - the itsy package management system
7421 + Copyright (C) 2001 University of Southern California
7423 + This program is free software; you can redistribute it and/or
7424 + modify it under the terms of the GNU General Public License as
7425 + published by the Free Software Foundation; either version 2, or (at
7426 + your option) any later version.
7428 + This program is distributed in the hope that it will be useful, but
7429 + WITHOUT ANY WARRANTY; without even the implied warranty of
7430 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7431 + General Public License for more details.
7434 +#ifndef NV_PAIR_LIST_H
7435 +#define NV_PAIR_LIST_H
7437 +#include "nv_pair.h"
7438 +#include "void_list.h"
7440 +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
7441 +struct nv_pair_list_elt
7443 + nv_pair_list_elt_t *next;
7447 +typedef struct nv_pair_list nv_pair_list_t;
7448 +struct nv_pair_list
7450 + nv_pair_list_elt_t pre_head;
7451 + nv_pair_list_elt_t *head;
7452 + nv_pair_list_elt_t *tail;
7455 +static inline int nv_pair_list_empty(nv_pair_list_t *list)
7457 + if (list->head == NULL)
7463 +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
7464 +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
7466 +int nv_pair_list_init(nv_pair_list_t *list);
7467 +void nv_pair_list_deinit(nv_pair_list_t *list);
7469 +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
7470 + const char *name, const char *value);
7471 +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
7472 +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
7473 +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
7478 +++ b/archival/libipkg/pkg.c
7480 +/* pkg.c - the itsy package management system
7484 + Copyright (C) 2001 University of Southern California
7486 + This program is free software; you can redistribute it and/or
7487 + modify it under the terms of the GNU General Public License as
7488 + published by the Free Software Foundation; either version 2, or (at
7489 + your option) any later version.
7491 + This program is distributed in the hope that it will be useful, but
7492 + WITHOUT ANY WARRANTY; without even the implied warranty of
7493 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7494 + General Public License for more details.
7499 +#include <string.h>
7504 +#include "pkg_parse.h"
7505 +#include "pkg_extract.h"
7506 +#include "ipkg_message.h"
7507 +#include "ipkg_utils.h"
7509 +#include "sprintf_alloc.h"
7510 +#include "file_util.h"
7511 +#include "str_util.h"
7512 +#include "xsystem.h"
7513 +#include "ipkg_conf.h"
7515 +typedef struct enum_map enum_map_t;
7522 +static const enum_map_t pkg_state_want_map[] = {
7523 + { SW_UNKNOWN, "unknown"},
7524 + { SW_INSTALL, "install"},
7525 + { SW_DEINSTALL, "deinstall"},
7526 + { SW_PURGE, "purge"}
7529 +static const enum_map_t pkg_state_flag_map[] = {
7531 + { SF_REINSTREQ, "reinstreq"},
7532 + { SF_HOLD, "hold"},
7533 + { SF_REPLACE, "replace"},
7534 + { SF_NOPRUNE, "noprune"},
7535 + { SF_PREFER, "prefer"},
7536 + { SF_OBSOLETE, "obsolete"},
7537 + { SF_USER, "user"},
7540 +static const enum_map_t pkg_state_status_map[] = {
7541 + { SS_NOT_INSTALLED, "not-installed" },
7542 + { SS_UNPACKED, "unpacked" },
7543 + { SS_HALF_CONFIGURED, "half-configured" },
7544 + { SS_INSTALLED, "installed" },
7545 + { SS_HALF_INSTALLED, "half-installed" },
7546 + { SS_CONFIG_FILES, "config-files" },
7547 + { SS_POST_INST_FAILED, "post-inst-failed" },
7548 + { SS_REMOVAL_FAILED, "removal-failed" }
7551 +static int verrevcmp(const char *val, const char *ref);
7554 +pkg_t *pkg_new(void)
7558 + pkg = malloc(sizeof(pkg_t));
7559 + if (pkg == NULL) {
7560 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7569 +int pkg_init(pkg_t *pkg)
7571 + memset(pkg, 0, sizeof(pkg_t));
7574 + pkg->version = NULL;
7575 + pkg->revision = NULL;
7576 + pkg->familiar_revision = NULL;
7579 + pkg->architecture = NULL;
7580 + pkg->maintainer = NULL;
7581 + pkg->section = NULL;
7582 + pkg->description = NULL;
7583 + pkg->state_want = SW_UNKNOWN;
7584 + pkg->state_flag = SF_OK;
7585 + pkg->state_status = SS_NOT_INSTALLED;
7586 + pkg->depends_str = NULL;
7587 + pkg->provides_str = NULL;
7588 + pkg->depends_count = 0;
7589 + pkg->depends = NULL;
7590 + pkg->suggests_str = NULL;
7591 + pkg->recommends_str = NULL;
7592 + pkg->suggests_count = 0;
7593 + pkg->recommends_count = 0;
7595 + /* Abhaya: added init for conflicts fields */
7596 + pkg->conflicts = NULL;
7597 + pkg->conflicts_count = 0;
7599 + /* added for replaces. Jamey 7/23/2002 */
7600 + pkg->replaces = NULL;
7601 + pkg->replaces_count = 0;
7603 + pkg->pre_depends_count = 0;
7604 + pkg->pre_depends_str = NULL;
7605 + pkg->provides_count = 0;
7606 + pkg->provides = NULL;
7607 + pkg->filename = NULL;
7608 + pkg->local_filename = NULL;
7609 + pkg->tmp_unpack_dir = NULL;
7610 + pkg->md5sum = NULL;
7612 + pkg->installed_size = NULL;
7613 + pkg->priority = NULL;
7614 + pkg->source = NULL;
7615 + conffile_list_init(&pkg->conffiles);
7616 + pkg->installed_files = NULL;
7617 + pkg->installed_files_ref_cnt = 0;
7618 + pkg->essential = 0;
7619 + pkg->provided_by_hand = 0;
7624 +void pkg_deinit(pkg_t *pkg)
7629 + free(pkg->version);
7630 + pkg->version = NULL;
7631 + /* revision and familiar_revision share storage with version, so
7633 + pkg->revision = NULL;
7634 + pkg->familiar_revision = NULL;
7635 + /* owned by ipkg_conf_t */
7637 + /* owned by ipkg_conf_t */
7639 + free(pkg->architecture);
7640 + pkg->architecture = NULL;
7641 + free(pkg->maintainer);
7642 + pkg->maintainer = NULL;
7643 + free(pkg->section);
7644 + pkg->section = NULL;
7645 + free(pkg->description);
7646 + pkg->description = NULL;
7647 + pkg->state_want = SW_UNKNOWN;
7648 + pkg->state_flag = SF_OK;
7649 + pkg->state_status = SS_NOT_INSTALLED;
7650 + free(pkg->depends_str);
7651 + pkg->depends_str = NULL;
7652 + free(pkg->provides_str);
7653 + pkg->provides_str = NULL;
7654 + pkg->depends_count = 0;
7655 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
7656 + pkg->pre_depends_count = 0;
7657 + free(pkg->pre_depends_str);
7658 + pkg->pre_depends_str = NULL;
7659 + pkg->provides_count = 0;
7660 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
7661 + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
7662 + free(pkg->filename);
7663 + pkg->filename = NULL;
7664 + free(pkg->local_filename);
7665 + pkg->local_filename = NULL;
7666 + /* CLEANUP: It'd be nice to pullin the cleanup function from
7667 + ipkg_install.c here. See comment in
7668 + ipkg_install.c:cleanup_temporary_files */
7669 + free(pkg->tmp_unpack_dir);
7670 + pkg->tmp_unpack_dir = NULL;
7671 + free(pkg->md5sum);
7672 + pkg->md5sum = NULL;
7675 + free(pkg->installed_size);
7676 + pkg->installed_size = NULL;
7677 + free(pkg->priority);
7678 + pkg->priority = NULL;
7679 + free(pkg->source);
7680 + pkg->source = NULL;
7681 + conffile_list_deinit(&pkg->conffiles);
7682 + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
7683 + since if they are calling deinit, they should know. Maybe do an
7684 + assertion here instead? */
7685 + pkg->installed_files_ref_cnt = 1;
7686 + pkg_free_installed_files(pkg);
7687 + pkg->essential = 0;
7690 +int pkg_init_from_file(pkg_t *pkg, const char *filename)
7694 + FILE *control_file;
7696 + err = pkg_init(pkg);
7697 + if (err) { return err; }
7699 + pkg->local_filename = strdup(filename);
7701 + control_file = tmpfile();
7702 + err = pkg_extract_control_file_to_stream(pkg, control_file);
7703 + if (err) { return err; }
7705 + rewind(control_file);
7706 + raw = read_raw_pkgs_from_stream(control_file);
7707 + pkg_parse_raw(pkg, &raw, NULL, NULL);
7709 + fclose(control_file);
7714 +/* Merge any new information in newpkg into oldpkg */
7715 +/* XXX: CLEANUP: This function shouldn't actually modify anything in
7716 + newpkg, but should leave it usable. This rework is so that
7717 + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
7719 + * uh, i thought that i had originally written this so that it took
7720 + * two pkgs and returned a new one? we can do that again... -sma
7722 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
7724 + if (oldpkg == newpkg) {
7729 + oldpkg->src = newpkg->src;
7730 + if (!oldpkg->dest)
7731 + oldpkg->dest = newpkg->dest;
7732 + if (!oldpkg->architecture)
7733 + oldpkg->architecture = str_dup_safe(newpkg->architecture);
7734 + if (!oldpkg->arch_priority)
7735 + oldpkg->arch_priority = newpkg->arch_priority;
7736 + if (!oldpkg->section)
7737 + oldpkg->section = str_dup_safe(newpkg->section);
7738 + if(!oldpkg->maintainer)
7739 + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
7740 + if(!oldpkg->description)
7741 + oldpkg->description = str_dup_safe(newpkg->description);
7743 + /* merge the state_flags from the new package */
7744 + oldpkg->state_want = newpkg->state_want;
7745 + oldpkg->state_status = newpkg->state_status;
7746 + oldpkg->state_flag = newpkg->state_flag;
7748 + if (oldpkg->state_want == SW_UNKNOWN)
7749 + oldpkg->state_want = newpkg->state_want;
7750 + if (oldpkg->state_status == SS_NOT_INSTALLED)
7751 + oldpkg->state_status = newpkg->state_status;
7752 + oldpkg->state_flag |= newpkg->state_flag;
7755 + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
7756 + oldpkg->depends_str = newpkg->depends_str;
7757 + newpkg->depends_str = NULL;
7758 + oldpkg->depends_count = newpkg->depends_count;
7759 + newpkg->depends_count = 0;
7761 + oldpkg->depends = newpkg->depends;
7762 + newpkg->depends = NULL;
7764 + oldpkg->pre_depends_str = newpkg->pre_depends_str;
7765 + newpkg->pre_depends_str = NULL;
7766 + oldpkg->pre_depends_count = newpkg->pre_depends_count;
7767 + newpkg->pre_depends_count = 0;
7769 + oldpkg->recommends_str = newpkg->recommends_str;
7770 + newpkg->recommends_str = NULL;
7771 + oldpkg->recommends_count = newpkg->recommends_count;
7772 + newpkg->recommends_count = 0;
7774 + oldpkg->suggests_str = newpkg->suggests_str;
7775 + newpkg->suggests_str = NULL;
7776 + oldpkg->suggests_count = newpkg->suggests_count;
7777 + newpkg->suggests_count = 0;
7780 + if (!oldpkg->provides_str) {
7781 + oldpkg->provides_str = newpkg->provides_str;
7782 + newpkg->provides_str = NULL;
7783 + oldpkg->provides_count = newpkg->provides_count;
7784 + newpkg->provides_count = 0;
7786 + oldpkg->provides = newpkg->provides;
7787 + newpkg->provides = NULL;
7790 + if (!oldpkg->conflicts_str) {
7791 + oldpkg->conflicts_str = newpkg->conflicts_str;
7792 + newpkg->conflicts_str = NULL;
7793 + oldpkg->conflicts_count = newpkg->conflicts_count;
7794 + newpkg->conflicts_count = 0;
7796 + oldpkg->conflicts = newpkg->conflicts;
7797 + newpkg->conflicts = NULL;
7800 + if (!oldpkg->replaces_str) {
7801 + oldpkg->replaces_str = newpkg->replaces_str;
7802 + newpkg->replaces_str = NULL;
7803 + oldpkg->replaces_count = newpkg->replaces_count;
7804 + newpkg->replaces_count = 0;
7806 + oldpkg->replaces = newpkg->replaces;
7807 + newpkg->replaces = NULL;
7810 + if (!oldpkg->filename)
7811 + oldpkg->filename = str_dup_safe(newpkg->filename);
7813 + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
7814 + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
7815 + if (!oldpkg->local_filename)
7816 + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
7817 + if (!oldpkg->tmp_unpack_dir)
7818 + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
7819 + if (!oldpkg->md5sum)
7820 + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
7821 + if (!oldpkg->size)
7822 + oldpkg->size = str_dup_safe(newpkg->size);
7823 + if (!oldpkg->installed_size)
7824 + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
7825 + if (!oldpkg->priority)
7826 + oldpkg->priority = str_dup_safe(newpkg->priority);
7827 + if (!oldpkg->source)
7828 + oldpkg->source = str_dup_safe(newpkg->source);
7829 + if (oldpkg->conffiles.head == NULL){
7830 + oldpkg->conffiles = newpkg->conffiles;
7831 + conffile_list_init(&newpkg->conffiles);
7833 + if (!oldpkg->installed_files){
7834 + oldpkg->installed_files = newpkg->installed_files;
7835 + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
7836 + newpkg->installed_files = NULL;
7838 + if (!oldpkg->essential)
7839 + oldpkg->essential = newpkg->essential;
7841 + oldpkg->provided_by_hand |= newpkg->provided_by_hand;
7846 +abstract_pkg_t *abstract_pkg_new(void)
7848 + abstract_pkg_t * ab_pkg;
7850 + ab_pkg = malloc(sizeof(abstract_pkg_t));
7852 + if (ab_pkg == NULL) {
7853 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7857 + if ( abstract_pkg_init(ab_pkg) < 0 )
7863 +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
7865 + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
7867 + ab_pkg->provided_by = abstract_pkg_vec_alloc();
7868 + if (ab_pkg->provided_by==NULL){
7871 + ab_pkg->dependencies_checked = 0;
7872 + ab_pkg->state_status = SS_NOT_INSTALLED;
7877 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
7880 + char **raw_start=NULL;
7882 + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
7883 + if (temp_str == NULL ){
7884 + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
7887 + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
7889 + raw = raw_start = read_raw_pkgs_from_file(temp_str);
7890 + if (raw == NULL ){
7891 + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
7896 + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
7897 + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
7913 +char * pkg_formatted_info(pkg_t *pkg )
7918 + buff = malloc(8192);
7919 + if (buff == NULL) {
7920 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
7926 + line = pkg_formatted_field(pkg, "Package");
7927 + strncat(buff ,line, strlen(line));
7930 + line = pkg_formatted_field(pkg, "Version");
7931 + strncat(buff ,line, strlen(line));
7934 + line = pkg_formatted_field(pkg, "Depends");
7935 + strncat(buff ,line, strlen(line));
7938 + line = pkg_formatted_field(pkg, "Recommends");
7939 + strncat(buff ,line, strlen(line));
7942 + line = pkg_formatted_field(pkg, "Suggests");
7943 + strncat(buff ,line, strlen(line));
7946 + line = pkg_formatted_field(pkg, "Provides");
7947 + strncat(buff ,line, strlen(line));
7950 + line = pkg_formatted_field(pkg, "Replaces");
7951 + strncat(buff ,line, strlen(line));
7954 + line = pkg_formatted_field(pkg, "Conflicts");
7955 + strncat(buff ,line, strlen(line));
7958 + line = pkg_formatted_field(pkg, "Status");
7959 + strncat(buff ,line, strlen(line));
7962 + line = pkg_formatted_field(pkg, "Section");
7963 + strncat(buff ,line, strlen(line));
7966 + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
7967 + strncat(buff ,line, strlen(line));
7970 + line = pkg_formatted_field(pkg, "Architecture");
7971 + strncat(buff ,line, strlen(line));
7974 + line = pkg_formatted_field(pkg, "Maintainer");
7975 + strncat(buff ,line, strlen(line));
7978 + line = pkg_formatted_field(pkg, "MD5sum");
7979 + strncat(buff ,line, strlen(line));
7982 + line = pkg_formatted_field(pkg, "Size");
7983 + strncat(buff ,line, strlen(line));
7986 + line = pkg_formatted_field(pkg, "Filename");
7987 + strncat(buff ,line, strlen(line));
7990 + line = pkg_formatted_field(pkg, "Conffiles");
7991 + strncat(buff ,line, strlen(line));
7994 + line = pkg_formatted_field(pkg, "Source");
7995 + strncat(buff ,line, strlen(line));
7998 + line = pkg_formatted_field(pkg, "Description");
7999 + strncat(buff ,line, strlen(line));
8002 + line = pkg_formatted_field(pkg, "Installed-Time");
8003 + strncat(buff ,line, strlen(line));
8009 +char * pkg_formatted_field(pkg_t *pkg, const char *field )
8011 + static size_t LINE_LEN = 128;
8012 + char line_str[LINE_LEN];
8013 + char * temp = (char *)malloc(1);
8015 + int flag_provide_false = 0;
8018 + Pigi: After some discussion with Florian we decided to modify the full procedure in
8019 + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
8022 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8023 + goto UNKNOWN_FMT_FIELD;
8032 + if (strcasecmp(field, "Architecture") == 0) {
8033 + /* Architecture */
8034 + if (pkg->architecture) {
8035 + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
8036 + if ( temp == NULL ){
8037 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8041 + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
8044 + goto UNKNOWN_FMT_FIELD;
8049 + if (strcasecmp(field, "Conffiles") == 0) {
8051 + conffile_list_elt_t *iter;
8053 + if (pkg->conffiles.head == NULL) {
8058 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8059 + if (iter->data->name && iter->data->value) {
8060 + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
8063 + temp = (char *)realloc(temp,len);
8064 + if ( temp == NULL ){
8065 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8069 + strncpy(temp, "Conffiles:\n", 12);
8070 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8071 + if (iter->data->name && iter->data->value) {
8072 + snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
8073 + strncat(temp, line_str, strlen(line_str));
8076 + } else if (strcasecmp(field, "Conflicts") == 0) {
8079 + if (pkg->conflicts_count) {
8081 + for(i = 0; i < pkg->conflicts_count; i++) {
8082 + len = len + (strlen(pkg->conflicts_str[i])+5);
8084 + temp = (char *)realloc(temp,len);
8085 + if ( temp == NULL ){
8086 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8090 + strncpy(temp, "Conflicts:", 11);
8091 + for(i = 0; i < pkg->conflicts_count; i++) {
8092 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
8093 + strncat(temp, line_str, strlen(line_str));
8095 + strncat(temp, "\n", strlen("\n"));
8098 + goto UNKNOWN_FMT_FIELD;
8103 + if (strcasecmp(field, "Depends") == 0) {
8107 + if (pkg->depends_count) {
8109 + for(i = 0; i < pkg->depends_count; i++) {
8110 + len = len + (strlen(pkg->depends_str[i])+4);
8112 + temp = (char *)realloc(temp,len);
8113 + if ( temp == NULL ){
8114 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8118 + strncpy(temp, "Depends:", 10);
8119 + for(i = 0; i < pkg->depends_count; i++) {
8120 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
8121 + strncat(temp, line_str, strlen(line_str));
8123 + strncat(temp, "\n", strlen("\n"));
8125 + } else if (strcasecmp(field, "Description") == 0) {
8127 + if (pkg->description) {
8128 + temp = (char *)realloc(temp,strlen(pkg->description)+16);
8129 + if ( temp == NULL ){
8130 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8134 + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
8137 + goto UNKNOWN_FMT_FIELD;
8143 + if (pkg->essential) {
8144 + temp = (char *)realloc(temp,16);
8145 + if ( temp == NULL ){
8146 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8150 + snprintf(temp, (16), "Essential: yes\n");
8157 + if (pkg->filename) {
8158 + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
8159 + if ( temp == NULL ){
8160 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8164 + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
8170 + if (strcasecmp(field, "Installed-Size") == 0) {
8171 + /* Installed-Size */
8172 + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
8173 + if ( temp == NULL ){
8174 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8178 + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
8179 + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
8180 + temp = (char *)realloc(temp,29);
8181 + if ( temp == NULL ){
8182 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8186 + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
8192 + /* Maintainer | MD5sum */
8193 + if (strcasecmp(field, "Maintainer") == 0) {
8195 + if (pkg->maintainer) {
8196 + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
8197 + if ( temp == NULL ){
8198 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8202 + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
8204 + } else if (strcasecmp(field, "MD5sum") == 0) {
8206 + if (pkg->md5sum) {
8207 + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
8208 + if ( temp == NULL ){
8209 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8213 + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
8216 + goto UNKNOWN_FMT_FIELD;
8222 + if (strcasecmp(field, "Package") == 0) {
8224 + temp = (char *)realloc(temp,strlen(pkg->name)+11);
8225 + if ( temp == NULL ){
8226 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8230 + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
8231 + } else if (strcasecmp(field, "Priority") == 0) {
8233 + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
8234 + if ( temp == NULL ){
8235 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8239 + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
8240 + } else if (strcasecmp(field, "Provides") == 0) {
8244 + if (pkg->provides_count) {
8245 + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
8246 + for ( i=0; i < pkg->provides_count; i++ ){
8247 + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
8248 + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
8249 + flag_provide_false = 1;
8252 + if ( !flag_provide_false || /* Pigi there is not my trick flag */
8253 + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
8254 + char provstr[LINE_LEN];
8256 + for(i = 0; i < pkg->provides_count; i++) {
8257 + len = len + (strlen(pkg->provides_str[i])+5);
8259 + temp = (char *)realloc(temp,len);
8260 + if ( temp == NULL ){
8261 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8265 + strncpy(temp, "Provides:", 12);
8266 + for(i = 0; i < pkg->provides_count; i++) {
8267 + if (strlen(pkg->provides_str[i])>0){;
8268 + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
8269 + strncat(temp, provstr, strlen(provstr));
8272 + strncat(temp, "\n", strlen("\n"));
8276 + goto UNKNOWN_FMT_FIELD;
8283 + /* Replaces | Recommends*/
8284 + if (strcasecmp (field, "Replaces") == 0) {
8285 + if (pkg->replaces_count) {
8287 + for (i = 0; i < pkg->replaces_count; i++) {
8288 + len = len + (strlen(pkg->replaces_str[i])+5);
8290 + temp = (char *)realloc(temp,len);
8291 + if ( temp == NULL ){
8292 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8296 + strncpy(temp, "Replaces:", 12);
8297 + for (i = 0; i < pkg->replaces_count; i++) {
8298 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
8299 + strncat(temp, line_str, strlen(line_str));
8301 + strncat(temp, "\n", strlen("\n"));
8303 + } else if (strcasecmp (field, "Recommends") == 0) {
8304 + if (pkg->recommends_count) {
8306 + for(i = 0; i < pkg->recommends_count; i++) {
8307 + len = len + (strlen( pkg->recommends_str[i])+5);
8309 + temp = (char *)realloc(temp,len);
8310 + if ( temp == NULL ){
8311 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8315 + strncpy(temp, "Recommends:", 13);
8316 + for(i = 0; i < pkg->recommends_count; i++) {
8317 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
8318 + strncat(temp, line_str, strlen(line_str));
8320 + strncat(temp, "\n", strlen("\n"));
8323 + goto UNKNOWN_FMT_FIELD;
8329 + /* Section | Size | Source | Status | Suggests */
8330 + if (strcasecmp(field, "Section") == 0) {
8332 + if (pkg->section) {
8333 + temp = (char *)realloc(temp,strlen(pkg->section)+11);
8334 + if ( temp == NULL ){
8335 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8339 + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
8341 + } else if (strcasecmp(field, "Size") == 0) {
8344 + temp = (char *)realloc(temp,strlen(pkg->size)+8);
8345 + if ( temp == NULL ){
8346 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8350 + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
8352 + } else if (strcasecmp(field, "Source") == 0) {
8354 + if (pkg->source) {
8355 + temp = (char *)realloc(temp,strlen(pkg->source)+10);
8356 + if ( temp == NULL ){
8357 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8361 + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
8363 + } else if (strcasecmp(field, "Status") == 0) {
8365 + /* Benjamin Pineau note: we should avoid direct usage of
8366 + * strlen(arg) without keeping "arg" for later free()
8368 + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
8369 + char *pstat=pkg_state_status_to_str(pkg->state_status);
8370 + char *pwant=pkg_state_want_to_str(pkg->state_want);
8372 + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
8373 + temp = (char *)realloc(temp,sum_of_sizes);
8374 + if ( temp == NULL ){
8375 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8379 + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
8382 + if(pstat) /* pfstat can be NULL if ENOMEM */
8384 + } else if (strcasecmp(field, "Suggests") == 0) {
8385 + if (pkg->suggests_count) {
8388 + for(i = 0; i < pkg->suggests_count; i++) {
8389 + len = len + (strlen(pkg->suggests_str[i])+5);
8391 + temp = (char *)realloc(temp,len);
8392 + if ( temp == NULL ){
8393 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8397 + strncpy(temp, "Suggests:", 10);
8398 + for(i = 0; i < pkg->suggests_count; i++) {
8399 + snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
8400 + strncat(temp, line_str, strlen(line_str));
8402 + strncat(temp, "\n", strlen("\n"));
8405 + goto UNKNOWN_FMT_FIELD;
8412 + char *version = pkg_version_str_alloc(pkg);
8413 + temp = (char *)realloc(temp,strlen(version)+14);
8414 + if ( temp == NULL ){
8415 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8419 + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
8424 + goto UNKNOWN_FMT_FIELD;
8427 + if ( strlen(temp)<2 ) {
8432 + UNKNOWN_FMT_FIELD:
8433 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
8434 + if ( strlen(temp)<2 ) {
8441 +void pkg_print_info(pkg_t *pkg, FILE *file)
8444 + if (pkg == NULL) {
8448 + buff = pkg_formatted_info(pkg);
8449 + if ( buff == NULL )
8451 + if (strlen(buff)>2){
8452 + fwrite(buff, 1, strlen(buff), file);
8457 +void pkg_print_status(pkg_t * pkg, FILE * file)
8459 + if (pkg == NULL) {
8463 + /* XXX: QUESTION: Do we actually want more fields here? The
8464 + original idea was to save space by installing only what was
8465 + needed for actual computation, (package, version, status,
8466 + essential, conffiles). The assumption is that all other fields
8467 + can be found in th available file.
8469 + But, someone proposed the idea to make it possible to
8470 + reconstruct a .ipk from an installed package, (ie. for beaming
8471 + from one handheld to another). So, maybe we actually want a few
8472 + more fields here, (depends, suggests, etc.), so that that would
8473 + be guaranteed to work even in the absence of more information
8474 + from the available file.
8476 + 28-MAR-03: kergoth and I discussed this yesterday. We think
8477 + the essential info needs to be here for all installed packages
8478 + because they may not appear in the Packages files on various
8479 + feeds. Furthermore, one should be able to install from URL or
8480 + local storage without requiring a Packages file from any feed.
8483 + pkg_print_field(pkg, file, "Package");
8484 + pkg_print_field(pkg, file, "Version");
8485 + pkg_print_field(pkg, file, "Depends");
8486 + pkg_print_field(pkg, file, "Recommends");
8487 + pkg_print_field(pkg, file, "Suggests");
8488 + pkg_print_field(pkg, file, "Provides");
8489 + pkg_print_field(pkg, file, "Replaces");
8490 + pkg_print_field(pkg, file, "Conflicts");
8491 + pkg_print_field(pkg, file, "Status");
8492 + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
8493 + pkg_print_field(pkg, file, "Architecture");
8494 + pkg_print_field(pkg, file, "Conffiles");
8495 + pkg_print_field(pkg, file, "Installed-Time");
8496 + fputs("\n", file);
8499 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
8502 + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
8503 + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
8504 + __FUNCTION__, field);
8506 + buff = pkg_formatted_field(pkg, field);
8507 + if (strlen(buff)>2) {
8508 + fprintf(file, "%s", buff);
8516 + * libdpkg - Debian packaging suite library routines
8517 + * vercmp.c - comparison of version numbers
8519 + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
8521 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
8525 + if (pkg->epoch > ref_pkg->epoch) {
8529 + if (pkg->epoch < ref_pkg->epoch) {
8533 + r = verrevcmp(pkg->version, ref_pkg->version);
8538 +#ifdef USE_DEBVERSION
8539 + r = verrevcmp(pkg->revision, ref_pkg->revision);
8544 + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
8550 +int verrevcmp(const char *val, const char *ref)
8554 + const char *vp, *rp;
8555 + const char *vsep, *rsep;
8557 + if (!val) val= "";
8558 + if (!ref) ref= "";
8560 + vp= val; while (*vp && !isdigit(*vp)) vp++;
8561 + rp= ref; while (*rp && !isdigit(*rp)) rp++;
8563 + vc= (val == vp) ? 0 : *val++;
8564 + rc= (ref == rp) ? 0 : *ref++;
8565 + if (!rc && !vc) break;
8566 + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
8567 + if (rc && !isalpha(rc)) rc += 256;
8568 + if (vc != rc) return vc - rc;
8572 + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
8573 + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
8574 + if (vl != rl) return vl - rl;
8578 + vsep = strchr(".-", vc);
8579 + rsep = strchr(".-", rc);
8580 + if (vsep && !rsep) return -1;
8581 + if (!vsep && rsep) return +1;
8583 + if (!*val && !*ref) return 0;
8584 + if (!*val) return -1;
8585 + if (!*ref) return +1;
8589 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
8593 + r = pkg_compare_versions(it, ref);
8595 + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
8599 + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
8603 + if (strcmp(op, "<<") == 0) {
8607 + if (strcmp(op, ">>") == 0) {
8611 + if (strcmp(op, "=") == 0) {
8615 + fprintf(stderr, "unknown operator: %s", op);
8619 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b)
8623 + if (!a->name || !b->name) {
8624 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
8625 + a, a->name, b, b->name);
8629 + namecmp = strcmp(a->name, b->name);
8632 + vercmp = pkg_compare_versions(a, b);
8635 + if (!a->arch_priority || !b->arch_priority) {
8636 + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
8637 + a, a->arch_priority, b, b->arch_priority);
8640 + if (a->arch_priority > b->arch_priority)
8642 + if (a->arch_priority < b->arch_priority)
8647 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b)
8649 + if (!a->name || !b->name) {
8650 + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
8651 + a, a->name, b, b->name);
8654 + return strcmp(a->name, b->name);
8658 +char *pkg_version_str_alloc(pkg_t *pkg)
8660 + char *complete_version;
8662 +#ifdef USE_DEBVERSION
8663 + char *revision_str;
8664 + char *familiar_revision_str;
8668 + sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch));
8670 + epoch_str = strdup("");
8673 +#ifdef USE_DEBVERSION
8674 + if (pkg->revision && strlen(pkg->revision)) {
8675 + sprintf_alloc(&revision_str, "-%s", pkg->revision);
8677 + revision_str = strdup("");
8680 + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
8681 + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
8683 + familiar_revision_str = strdup("");
8687 +#ifdef USE_DEBVERSION
8688 + sprintf_alloc(&complete_version, "%s%s%s%s",
8689 + epoch_str, pkg->version, revision_str, familiar_revision_str);
8691 + sprintf_alloc(&complete_version, "%s%s",
8692 + epoch_str, pkg->version);
8696 +#ifdef USE_DEBVERSION
8697 + free(revision_str);
8698 + free(familiar_revision_str);
8701 + return complete_version;
8704 +str_list_t *pkg_get_installed_files(pkg_t *pkg)
8707 + char *list_file_name = NULL;
8708 + FILE *list_file = NULL;
8710 + char *installed_file_name;
8713 + pkg->installed_files_ref_cnt++;
8715 + if (pkg->installed_files) {
8716 + return pkg->installed_files;
8719 + pkg->installed_files = str_list_alloc();
8720 + if (pkg->installed_files == NULL) {
8721 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8725 + /* For uninstalled packages, get the file list firectly from the package.
8726 + For installed packages, look at the package.list file in the database.
8728 + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
8729 + if (pkg->local_filename == NULL) {
8730 + return pkg->installed_files;
8732 + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
8733 + file. In other words, change deb_extract so that it can
8734 + simply return the file list as a char *[] rather than
8735 + insisting on writing in to a FILE * as it does now. */
8736 + list_file = tmpfile();
8737 + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
8739 + fclose(list_file);
8740 + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
8741 + __FUNCTION__, pkg->local_filename, strerror(err));
8742 + return pkg->installed_files;
8744 + rewind(list_file);
8746 + sprintf_alloc(&list_file_name, "%s/%s.list",
8747 + pkg->dest->info_dir, pkg->name);
8748 + if (! file_exists(list_file_name)) {
8749 + free(list_file_name);
8750 + return pkg->installed_files;
8753 + list_file = fopen(list_file_name, "r");
8754 + if (list_file == NULL) {
8755 + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
8756 + list_file_name, strerror(errno));
8757 + free(list_file_name);
8758 + return pkg->installed_files;
8760 + free(list_file_name);
8763 + rootdirlen = strlen( pkg->dest->root_dir );
8767 + line = file_read_line_alloc(list_file);
8768 + if (line == NULL) {
8774 + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
8775 + if( strncmp( pkg->dest->root_dir,
8778 + if (*file_name == '.') {
8781 + if (*file_name == '/') {
8785 + /* Freed in pkg_free_installed_files */
8786 + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
8788 + // already contains root_dir as header -> ABSOLUTE
8789 + sprintf_alloc(&installed_file_name, "%s", file_name);
8791 + str_list_append(pkg->installed_files, installed_file_name);
8795 + fclose(list_file);
8797 + return pkg->installed_files;
8800 +/* XXX: CLEANUP: This function and it's counterpart,
8801 + (pkg_get_installed_files), do not match our init/deinit naming
8802 + convention. Nor the alloc/free convention. But, then again, neither
8803 + of these conventions currrently fit the way these two functions
8805 +int pkg_free_installed_files(pkg_t *pkg)
8807 + str_list_elt_t *iter;
8809 + pkg->installed_files_ref_cnt--;
8810 + if (pkg->installed_files_ref_cnt > 0) {
8814 + if (pkg->installed_files) {
8816 + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
8817 + /* malloced in pkg_get_installed_files */
8818 + free (iter->data);
8819 + iter->data = NULL;
8822 + str_list_deinit(pkg->installed_files);
8825 + pkg->installed_files = NULL;
8830 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
8833 + char *list_file_name;
8835 + //I don't think pkg_free_installed_files should be called here. Jamey
8836 + //pkg_free_installed_files(pkg);
8838 + sprintf_alloc(&list_file_name, "%s/%s.list",
8839 + pkg->dest->info_dir, pkg->name);
8840 + if (!conf->noaction) {
8841 + err = unlink(list_file_name);
8842 + free(list_file_name);
8851 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
8853 + conffile_list_elt_t *iter;
8854 + conffile_t *conffile;
8856 + if (pkg == NULL) {
8860 + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
8861 + conffile = iter->data;
8863 + if (strcmp(conffile->name, file_name) == 0) {
8871 +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
8872 + const char *script, const char *args)
8878 + /* XXX: FEATURE: When conf->offline_root is set, we should run the
8879 + maintainer script within a chroot environment. */
8881 + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
8882 + have scripts in pkg->tmp_unpack_dir. */
8883 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
8884 + if (pkg->dest == NULL) {
8885 + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
8886 + __FUNCTION__, pkg->name);
8889 + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
8891 + if (pkg->tmp_unpack_dir == NULL) {
8892 + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
8893 + __FUNCTION__, pkg->name);
8896 + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
8899 + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
8900 + if (conf->noaction) return 0;
8902 + /* XXX: CLEANUP: There must be a better way to handle maintainer
8903 + scripts when running with offline_root mode and/or a dest other
8904 + than '/'. I've been playing around with some clever chroot
8905 + tricks and I might come up with something workable. */
8906 + if (conf->offline_root) {
8907 + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
8910 + setenv("PKG_ROOT",
8911 + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
8913 + if (! file_exists(path)) {
8918 + if (conf->offline_root) {
8919 + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
8924 + sprintf_alloc(&cmd, "%s %s", path, args);
8927 + err = xsystem(cmd);
8931 + fprintf(stderr, "%s script returned status %d\n", script, err);
8938 +char *pkg_state_want_to_str(pkg_state_want_t sw)
8942 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8943 + if (pkg_state_want_map[i].value == sw) {
8944 + return strdup(pkg_state_want_map[i].str);
8948 + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
8949 + __FUNCTION__, sw);
8950 + return strdup("<STATE_WANT_UNKNOWN>");
8953 +pkg_state_want_t pkg_state_want_from_str(char *str)
8957 + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
8958 + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
8959 + return pkg_state_want_map[i].value;
8963 + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
8964 + __FUNCTION__, str);
8965 + return SW_UNKNOWN;
8968 +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
8971 + int len = 3; /* ok\000 is minimum */
8974 + /* clear the temporary flags before converting to string */
8975 + sf &= SF_NONVOLATILE_FLAGS;
8978 + return strdup("ok");
8981 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8982 + if (sf & pkg_state_flag_map[i].value) {
8983 + len += strlen(pkg_state_flag_map[i].str) + 1;
8986 + str = malloc(len);
8987 + if ( str == NULL ) {
8988 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
8992 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
8993 + if (sf & pkg_state_flag_map[i].value) {
8994 + strcat(str, pkg_state_flag_map[i].str);
8998 + len = strlen(str);
8999 + str[len-1] = 0; /* squash last comma */
9004 +pkg_state_flag_t pkg_state_flag_from_str(char *str)
9009 + if (strcmp(str, "ok") == 0) {
9012 + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
9013 + const char *sfname = pkg_state_flag_map[i].str;
9014 + int sfname_len = strlen(sfname);
9015 + if (strncmp(str, sfname, sfname_len) == 0) {
9016 + sf |= pkg_state_flag_map[i].value;
9017 + str += sfname_len;
9018 + if (str[0] == ',') {
9029 +char *pkg_state_status_to_str(pkg_state_status_t ss)
9033 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9034 + if (pkg_state_status_map[i].value == ss) {
9035 + return strdup(pkg_state_status_map[i].str);
9039 + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
9040 + __FUNCTION__, ss);
9041 + return strdup("<STATE_STATUS_UNKNOWN>");
9044 +pkg_state_status_t pkg_state_status_from_str(char *str)
9048 + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
9049 + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
9050 + return pkg_state_status_map[i].value;
9054 + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
9055 + __FUNCTION__, str);
9056 + return SS_NOT_INSTALLED;
9059 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
9061 + nv_pair_list_elt_t *l;
9063 + if (!pkg->architecture)
9066 + l = conf->arch_list.head;
9069 + nv_pair_t *nv = l->data;
9070 + if (strcmp(nv->name, pkg->architecture) == 0) {
9071 + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
9077 + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
9081 +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
9083 + nv_pair_list_elt_t *l;
9085 + l = conf->arch_list.head;
9088 + nv_pair_t *nv = l->data;
9089 + if (strcmp(nv->name, archname) == 0) {
9090 + int priority = strtol(nv->value, NULL, 0);
9098 +int pkg_info_preinstall_check(ipkg_conf_t *conf)
9101 + hash_table_t *pkg_hash = &conf->pkg_hash;
9102 + pkg_vec_t *available_pkgs = pkg_vec_alloc();
9103 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9105 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
9106 + pkg_hash_fetch_available(pkg_hash, available_pkgs);
9107 + /* update arch_priority for each package */
9108 + for (i = 0; i < available_pkgs->len; i++) {
9109 + pkg_t *pkg = available_pkgs->pkgs[i];
9110 + int arch_priority = 1;
9113 + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
9114 + if (pkg->architecture)
9115 + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
9117 + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
9118 + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
9119 + pkg->arch_priority = arch_priority;
9122 + for (i = 0; i < available_pkgs->len; i++) {
9123 + pkg_t *pkg = available_pkgs->pkgs[i];
9124 + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
9125 + /* clear flags and want for any uninstallable package */
9126 + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
9127 + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
9128 + pkg->state_want = SW_UNKNOWN;
9129 + pkg->state_flag = 0;
9132 + pkg_vec_free(available_pkgs);
9134 + /* update the file owner data structure */
9135 + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
9136 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9137 + for (i = 0; i < installed_pkgs->len; i++) {
9138 + pkg_t *pkg = installed_pkgs->pkgs[i];
9139 + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
9140 + str_list_elt_t *iter;
9141 + if (installed_files == NULL) {
9142 + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
9145 + for (iter = installed_files->head; iter; iter = iter->next) {
9146 + char *installed_file = iter->data;
9147 + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
9148 + file_hash_set_file_owner(conf, installed_file, pkg);
9151 + pkg_vec_free(installed_pkgs);
9156 +struct pkg_write_filelist_data {
9157 + ipkg_conf_t *conf;
9162 +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
9164 + struct pkg_write_filelist_data *data = data_;
9165 + pkg_t *entry = entry_;
9166 + if (entry == data->pkg) {
9167 + fprintf(data->stream, "%s\n", key);
9171 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
9173 + struct pkg_write_filelist_data data;
9174 + char *list_file_name = NULL;
9178 + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
9181 + ipkg_message(conf, IPKG_INFO,
9182 + " creating %s.list file\n", pkg->name);
9183 + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
9184 + if (!list_file_name) {
9185 + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
9188 + ipkg_message(conf, IPKG_INFO,
9189 + " creating %s file for pkg %s\n", list_file_name, pkg->name);
9190 + data.stream = fopen(list_file_name, "w");
9191 + if (!data.stream) {
9192 + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
9193 + list_file_name, strerror(errno));
9198 + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
9199 + fclose(data.stream);
9200 + free(list_file_name);
9205 +int pkg_write_changed_filelists(ipkg_conf_t *conf)
9207 + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
9208 + hash_table_t *pkg_hash = &conf->pkg_hash;
9211 + if (conf->noaction)
9214 + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
9215 + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
9216 + for (i = 0; i < installed_pkgs->len; i++) {
9217 + pkg_t *pkg = installed_pkgs->pkgs[i];
9218 + if (pkg->state_flag & SF_FILELIST_CHANGED) {
9219 + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
9220 + err = pkg_write_filelist(conf, pkg);
9222 + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
9228 +++ b/archival/libipkg/pkg_depends.c
9230 +/* pkg_depends.c - the itsy package management system
9234 + Copyright (C) 2002 Compaq Computer Corporation
9236 + This program is free software; you can redistribute it and/or
9237 + modify it under the terms of the GNU General Public License as
9238 + published by the Free Software Foundation; either version 2, or (at
9239 + your option) any later version.
9241 + This program is distributed in the hope that it will be useful, but
9242 + WITHOUT ANY WARRANTY; without even the implied warranty of
9243 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9244 + General Public License for more details.
9252 +#include "ipkg_utils.h"
9253 +#include "pkg_hash.h"
9254 +#include "ipkg_message.h"
9255 +#include "pkg_parse.h"
9256 +#include "hash_table.h"
9258 +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
9259 +static depend_t * depend_init(void);
9260 +static void depend_deinit(depend_t *d);
9261 +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
9262 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
9263 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
9265 +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
9267 + depend_t *depend = (depend_t *)cdata;
9268 + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
9274 +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
9276 + depend_t *depend = (depend_t *)cdata;
9278 + pkg_t * temp = pkg_new();
9280 + parseVersion(temp, depend->version);
9281 + comparison = pkg_compare_versions(pkg, temp);
9284 + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
9285 + __FUNCTION__, pkg->name, pkg->version,
9286 + depend, depend->constraint, depend->version,
9287 + comparison, version_constraints_satisfied(depend, pkg));
9289 + if (version_constraints_satisfied(depend, pkg))
9295 +/* returns ndependences or negative error value */
9296 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
9297 + pkg_vec_t *unsatisfied, char *** unresolved)
9299 + pkg_t * satisfier_entry_pkg;
9300 + register int i, j, k, l;
9303 + abstract_pkg_t * ab_pkg;
9306 + * this is a setup to check for redundant/cyclic dependency checks,
9307 + * which are marked at the abstract_pkg level
9309 + if (!(ab_pkg = pkg->parent)) {
9310 + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
9311 + *unresolved = NULL;
9314 + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
9315 + *unresolved = NULL;
9318 + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
9322 + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
9324 + *unresolved = NULL;
9330 + /* foreach dependency */
9331 + for (i = 0; i < count; i++) {
9332 + compound_depend_t * compound_depend = &pkg->depends[i];
9333 + depend_t ** possible_satisfiers = compound_depend->possibilities;;
9335 + satisfier_entry_pkg = NULL;
9337 + if (compound_depend->type == GREEDY_DEPEND) {
9338 + /* foreach possible satisfier */
9339 + for (j = 0; j < compound_depend->possibility_count; j++) {
9340 + /* foreach provided_by, which includes the abstract_pkg itself */
9341 + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
9342 + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
9343 + int nposs = ab_provider_vec->len;
9344 + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
9345 + for (l = 0; l < nposs; l++) {
9346 + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
9347 + /* if no depends on this one, try the first package that Provides this one */
9348 + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
9352 + /* cruise this possiblity's pkg_vec looking for an installed version */
9353 + for (k = 0; k < test_vec->len; k++) {
9354 + pkg_t *pkg_scout = test_vec->pkgs[k];
9355 + /* not installed, and not already known about? */
9356 + if ((pkg_scout->state_want != SW_INSTALL)
9357 + && !pkg_scout->parent->dependencies_checked
9358 + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
9359 + char ** newstuff = NULL;
9361 + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
9362 + /* check for not-already-installed dependencies */
9363 + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
9367 + if (newstuff == NULL) {
9369 + for (l = 0; l < rc; l++) {
9370 + pkg_t *p = tmp_vec->pkgs[l];
9371 + if (p->state_want == SW_INSTALL)
9373 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
9377 + pkg_vec_free (tmp_vec);
9379 + /* mark this one for installation */
9380 + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
9381 + pkg_vec_insert(unsatisfied, pkg_scout);
9384 + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
9395 + /* foreach possible satisfier, look for installed package */
9396 + for (j = 0; j < compound_depend->possibility_count; j++) {
9397 + /* foreach provided_by, which includes the abstract_pkg itself */
9398 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9399 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9400 + pkg_t *satisfying_pkg =
9401 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9402 + pkg_installed_and_constraint_satisfied,
9403 + dependence_to_satisfy, 1);
9404 + /* Being that I can't test constraing in pkg_hash, I will test it here */
9405 + if (satisfying_pkg != NULL) {
9406 + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9407 + satisfying_pkg = NULL;
9410 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
9411 + if (satisfying_pkg != NULL) {
9417 + /* if nothing installed matches, then look for uninstalled satisfier */
9419 + /* foreach possible satisfier, look for installed package */
9420 + for (j = 0; j < compound_depend->possibility_count; j++) {
9421 + /* foreach provided_by, which includes the abstract_pkg itself */
9422 + depend_t *dependence_to_satisfy = possible_satisfiers[j];
9423 + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
9424 + pkg_t *satisfying_pkg =
9425 + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
9426 + pkg_constraint_satisfied,
9427 + dependence_to_satisfy, 1);
9428 + /* Being that I can't test constraing in pkg_hash, I will test it here too */
9429 + if (satisfying_pkg != NULL) {
9430 + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
9431 + satisfying_pkg = NULL;
9435 + /* user request overrides package recommendation */
9436 + if (satisfying_pkg != NULL
9437 + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
9438 + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
9439 + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
9440 + pkg->name, satisfying_pkg->name);
9444 + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
9445 + if (satisfying_pkg != NULL) {
9446 + satisfier_entry_pkg = satisfying_pkg;
9452 + /* we didn't find one, add something to the unsatisfied vector */
9454 + if (!satisfier_entry_pkg) {
9455 + /* failure to meet recommendations is not an error */
9456 + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
9457 + the_lost = add_unresolved_dep(pkg, the_lost, i);
9459 + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
9460 + pkg->name, compound_depend->possibilities[0]->pkg->name);
9463 + if (compound_depend->type == SUGGEST) {
9464 + /* just mention it politely */
9465 + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
9466 + pkg->name, satisfier_entry_pkg->name);
9468 + char ** newstuff = NULL;
9470 + if (satisfier_entry_pkg != pkg &&
9471 + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
9472 + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
9473 + pkg_hash_fetch_unsatisfied_dependencies(conf,
9474 + satisfier_entry_pkg,
9477 + the_lost = merge_unresolved(the_lost, newstuff);
9483 + *unresolved = the_lost;
9485 + return unsatisfied->len;
9488 +/*checking for conflicts !in replaces
9489 + If a packages conflicts with another but is also replacing it, I should not consider it a
9491 + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
9493 +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
9496 + int replaces_count = pkg->replaces_count;
9497 + abstract_pkg_t **replaces;
9499 + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
9502 + replaces = pkg->replaces;
9504 + for (i = 0; i < replaces_count; i++) {
9505 + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
9506 + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
9515 +/* Abhaya: added support for conflicts */
9516 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
9518 + pkg_vec_t * installed_conflicts, * test_vec;
9519 + compound_depend_t * conflicts;
9520 + depend_t ** possible_satisfiers;
9521 + depend_t * possible_satisfier;
9522 + register int i, j, k;
9524 + abstract_pkg_t * ab_pkg;
9525 + pkg_t **pkg_scouts;
9529 + * this is a setup to check for redundant/cyclic dependency checks,
9530 + * which are marked at the abstract_pkg level
9532 + if(!(ab_pkg = pkg->parent)){
9533 + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
9534 + return (pkg_vec_t *)NULL;
9537 + conflicts = pkg->conflicts;
9539 + return (pkg_vec_t *)NULL;
9541 + installed_conflicts = pkg_vec_alloc();
9543 + count = pkg->conflicts_count;
9547 + /* foreach conflict */
9548 + for(i = 0; i < pkg->conflicts_count; i++){
9550 + possible_satisfiers = conflicts->possibilities;
9552 + /* foreach possible satisfier */
9553 + for(j = 0; j < conflicts->possibility_count; j++){
9554 + possible_satisfier = possible_satisfiers[j];
9555 + if (!possible_satisfier)
9556 + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
9557 + if (!possible_satisfier->pkg)
9558 + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
9559 + test_vec = possible_satisfier->pkg->pkgs;
9561 + /* pkg_vec found, it is an actual package conflict
9562 + * cruise this possiblity's pkg_vec looking for an installed version */
9563 + pkg_scouts = test_vec->pkgs;
9564 + for(k = 0; k < test_vec->len; k++){
9565 + pkg_scout = pkg_scouts[k];
9567 + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
9570 + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
9571 + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
9572 + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
9573 + pkg_vec_insert(installed_conflicts, pkg_scout);
9582 + if (installed_conflicts->len)
9583 + return installed_conflicts;
9584 + pkg_vec_free(installed_conflicts);
9585 + return (pkg_vec_t *)NULL;
9588 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
9593 + if(depends->constraint == NONE)
9598 + parseVersion(temp, depends->version);
9600 + comparison = pkg_compare_versions(pkg, temp);
9604 + if((depends->constraint == EARLIER) &&
9607 + else if((depends->constraint == LATER) &&
9610 + else if(comparison == 0)
9612 + else if((depends->constraint == LATER_EQUAL) &&
9613 + (comparison >= 0))
9615 + else if((depends->constraint == EARLIER_EQUAL) &&
9616 + (comparison <= 0))
9622 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend)
9624 + abstract_pkg_t *apkg = depend->pkg;
9625 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9626 + int n_providers = provider_apkgs->len;
9627 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9628 + pkg_vec_t *pkg_vec;
9633 + for (i = 0; i < n_providers; i++) {
9634 + abstract_pkg_t *papkg = apkgs[i];
9635 + pkg_vec = papkg->pkgs;
9637 + n_pkgs = pkg_vec->len;
9638 + for (j = 0; j < n_pkgs; j++) {
9639 + pkg_t *pkg = pkg_vec->pkgs[j];
9640 + if (version_constraints_satisfied(depend, pkg)) {
9649 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend)
9651 + abstract_pkg_t *apkg = depend->pkg;
9652 + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
9653 + int n_providers = provider_apkgs->len;
9654 + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
9659 + for (i = 0; i < n_providers; i++) {
9660 + abstract_pkg_t *papkg = apkgs[i];
9661 + pkg_vec_t *pkg_vec = papkg->pkgs;
9663 + n_pkgs = pkg_vec->len;
9664 + for (j = 0; j < n_pkgs; j++) {
9665 + pkg_t *pkg = pkg_vec->pkgs[j];
9666 + if (version_constraints_satisfied(depend, pkg)) {
9667 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
9676 +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
9679 + pkg_t ** pkgs = vec->pkgs;
9681 + for(i = 0; i < vec->len; i++)
9682 + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
9683 + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
9684 + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
9692 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
9693 + * the same abstract package and 0 otherwise.
9695 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
9697 + abstract_pkg_t **provides = pkg->provides;
9698 + int provides_count = pkg->provides_count;
9699 + abstract_pkg_t **replacee_provides = replacee->provides;
9700 + int replacee_provides_count = replacee->provides_count;
9702 + for (i = 0; i < provides_count; i++) {
9703 + abstract_pkg_t *apkg = provides[i];
9704 + for (j = 0; j < replacee_provides_count; j++) {
9705 + abstract_pkg_t *replacee_apkg = replacee_provides[i];
9706 + if (apkg == replacee_apkg)
9715 + * pkg_provides_abstract returns 1 if pkg->provides contains providee
9716 + * and 0 otherwise.
9718 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
9720 + abstract_pkg_t **provides = pkg->provides;
9721 + int provides_count = pkg->provides_count;
9723 + for (i = 0; i < provides_count; i++) {
9724 + if (provides[i] == providee)
9731 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
9734 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
9736 + abstract_pkg_t **replaces = pkg->replaces;
9737 + int replaces_count = pkg->replaces_count;
9738 + /* abstract_pkg_t **replacee_provides = pkg->provides;
9739 + int replacee_provides_count = pkg->provides_count; */
9741 + for (i = 0; i < replaces_count; i++) {
9742 + abstract_pkg_t *abstract_replacee = replaces[i];
9743 + for (j = 0; j < replaces_count; j++) {
9744 + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
9745 + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
9746 + if (replacee->provides[j] == abstract_replacee)
9755 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
9758 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
9760 + compound_depend_t *conflicts = pkg->conflicts;
9761 + int conflicts_count = pkg->conflicts_count;
9763 + for (i = 0; i < conflicts_count; i++) {
9764 + int possibility_count = conflicts[i].possibility_count;
9765 + struct depend **possibilities = conflicts[i].possibilities;
9766 + for (j = 0; j < possibility_count; j++) {
9767 + if (possibilities[j]->pkg == conflictee) {
9776 + * pkg_conflicts returns 1 if pkg->conflicts contains one of
9777 + * conflictee's provides and 0 otherwise.
9779 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
9781 + compound_depend_t *conflicts = pkg->conflicts;
9782 + int conflicts_count = pkg->conflicts_count;
9783 + abstract_pkg_t **conflictee_provides = conflictee->provides;
9784 + int conflictee_provides_count = conflictee->provides_count;
9786 + int possibility_count;
9787 + struct depend **possibilities;
9788 + abstract_pkg_t *possibility ;
9790 + for (i = 0; i < conflicts_count; i++) {
9791 + possibility_count = conflicts[i].possibility_count;
9792 + possibilities = conflicts[i].possibilities;
9793 + for (j = 0; j < possibility_count; j++) {
9794 + possibility = possibilities[j]->pkg;
9795 + for (k = 0; k < conflictee_provides_count; k++) {
9796 + if (possibility == conflictee_provides[k]) {
9805 +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
9807 + int oldlen = 0, newlen = 0;
9809 + register int i, j;
9814 + while(oldstuff && oldstuff[oldlen]) oldlen++;
9815 + while(newstuff && newstuff[newlen]) newlen++;
9817 + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
9818 + if (result == NULL) {
9819 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9823 + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
9824 + *(result + i) = *(newstuff + j);
9826 + *(result + i) = NULL;
9832 + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
9833 + * this is null terminated, no count is carried around
9835 +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
9839 + char *depend_str = pkg_depend_str(pkg, ref_ndx);
9842 + while(the_lost && the_lost[count]) count++;
9844 + count++; /* need one to hold the null */
9845 + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
9846 + if (resized == NULL) {
9847 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9850 + resized[count - 1] = strdup(depend_str);
9851 + resized[count] = NULL;
9856 +void printDepends(pkg_t * pkg)
9858 + register int i, j;
9859 + compound_depend_t * depend;
9862 + count = pkg->pre_depends_count + pkg->depends_count;
9864 + depend = pkg->depends;
9866 + fprintf(stderr, "Depends pointer is NULL\n");
9869 + for(i = 0; i < count; i++){
9870 + fprintf(stderr, "%s has %d possibilities:\n",
9871 + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
9872 + depend->possibility_count);
9873 + for(j = 0; j < depend->possibility_count; j++)
9874 + fprintf(stderr, "\t%s version %s (%d)\n",
9875 + depend->possibilities[j]->pkg->name,
9876 + depend->possibilities[j]->version,
9877 + depend->possibilities[j]->constraint);
9882 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9884 + register int i, j;
9886 + /* every pkg provides itself */
9887 + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
9889 + if (!pkg->provides_count)
9892 + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
9893 + if (pkg->provides == NULL) {
9894 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9897 + pkg->provides[0] = ab_pkg;
9899 + // if (strcmp(ab_pkg->name, pkg->name))
9900 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9902 + for(i = 0; i < pkg->provides_count; i++){
9903 + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
9905 + pkg->provides[i+1] = provided_abpkg;
9908 + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
9913 +/* Abhaya: added conflicts support */
9914 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9917 + compound_depend_t * conflicts;
9919 + if (!pkg->conflicts_count)
9922 + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
9923 + pkg->conflicts_count);
9924 + if (conflicts == NULL) {
9925 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9928 + for (i = 0; i < pkg->conflicts_count; i++) {
9929 + conflicts->type = CONFLICTS;
9930 + parseDepends(conflicts, hash,
9931 + pkg->conflicts_str[i]);
9933 + for (j = 0; j < conflicts->possibility_count; j++) {
9934 + depend_t *possibility = conflicts->possibilities[j];
9935 + abstract_pkg_t *conflicting_apkg = possibility->pkg;
9936 + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
9944 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
9946 + register int i, j;
9948 + if (!pkg->replaces_count)
9951 + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
9952 + if (pkg->replaces == NULL) {
9953 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9957 + // if (strcmp(ab_pkg->name, pkg->name))
9958 + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
9960 + for(i = 0; i < pkg->replaces_count; i++){
9961 + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
9963 + pkg->replaces[i] = old_abpkg;
9966 + if (!old_abpkg->replaced_by)
9967 + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
9968 + if ( old_abpkg->replaced_by == NULL ){
9971 + /* if a package pkg both replaces and conflicts old_abpkg,
9972 + * then add it to the replaced_by vector so that old_abpkg
9973 + * will be upgraded to ab_pkg automatically */
9974 + if (pkg_conflicts_abstract(pkg, old_abpkg))
9975 + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
9980 +int buildDepends(hash_table_t * hash, pkg_t * pkg)
9984 + compound_depend_t * depends;
9986 + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
9989 + if (0 && pkg->pre_depends_count)
9990 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
9991 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
9992 + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
9993 + if (depends == NULL) {
9994 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
9999 + for(i = 0; i < pkg->pre_depends_count; i++){
10000 + parseDepends(depends, hash, pkg->pre_depends_str[i]);
10001 + if (0 && pkg->pre_depends_count)
10002 + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
10003 + pkg->pre_depends_str[i], depends, depends->possibility_count);
10004 + depends->type = PREDEPEND;
10008 + for(i = 0; i < pkg->recommends_count; i++){
10009 + parseDepends(depends, hash, pkg->recommends_str[i]);
10010 + if (0 && pkg->recommends_count)
10011 + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
10012 + pkg->recommends_str[i], depends, depends->possibility_count);
10013 + depends->type = RECOMMEND;
10017 + for(i = 0; i < pkg->suggests_count; i++){
10018 + parseDepends(depends, hash, pkg->suggests_str[i]);
10019 + if (0 && pkg->suggests_count)
10020 + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
10021 + pkg->suggests_str[i], depends, depends->possibility_count);
10022 + depends->type = SUGGEST;
10026 + for(i = 0; i < pkg->depends_count; i++){
10027 + parseDepends(depends, hash, pkg->depends_str[i]);
10028 + if (0 && pkg->depends_count)
10029 + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
10030 + pkg->depends_str[i], depends, depends->possibility_count);
10037 + * pkg_depend_string: returns the depends string specified by index.
10038 + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
10039 + * [0,npredepends) -> returns pre_depends_str[index]
10040 + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
10041 + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
10042 + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
10044 +char *pkg_depend_str(pkg_t *pkg, int pkg_index)
10046 + if (pkg_index < pkg->pre_depends_count) {
10047 + return pkg->pre_depends_str[pkg_index];
10049 + pkg_index -= pkg->pre_depends_count;
10051 + if (pkg_index < pkg->recommends_count) {
10052 + return pkg->recommends_str[pkg_index];
10054 + pkg_index -= pkg->recommends_count;
10056 + if (pkg_index < pkg->suggests_count) {
10057 + return pkg->suggests_str[pkg_index];
10059 + pkg_index -= pkg->suggests_count;
10061 + if (pkg_index < pkg->depends_count) {
10062 + return pkg->depends_str[pkg_index];
10064 + fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name);
10068 +void freeDepends(pkg_t *pkg)
10072 + if (pkg == NULL || pkg->depends == NULL) {
10076 + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
10077 + for (i=0; i < pkg->depends->possibility_count; i++) {
10078 + depend_deinit(pkg->depends->possibilities[i]);
10080 + free(pkg->depends->possibilities);
10081 + free(pkg->depends);
10082 + pkg->depends = NULL;
10085 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
10087 + compound_depend_t * depends;
10088 + int count, othercount;
10089 + register int i, j;
10090 + abstract_pkg_t * ab_depend;
10091 + abstract_pkg_t ** temp;
10093 + count = pkg->pre_depends_count + pkg->depends_count;
10094 + depends = pkg->depends;
10096 + if (0 && pkg->pre_depends_count)
10097 + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
10098 + pkg->name, pkg->pre_depends_count, pkg->depends_count);
10099 + for (i = 0; i < count; i++) {
10100 + if (0 && pkg->pre_depends_count)
10101 + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
10102 + for (j = 0; j < depends->possibility_count; j++){
10103 + ab_depend = depends->possibilities[j]->pkg;
10104 + if(!ab_depend->depended_upon_by)
10105 + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
10107 + temp = ab_depend->depended_upon_by;
10115 + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
10116 + (othercount + 1) * sizeof(abstract_pkg_t *));
10117 + /* the array may have moved */
10118 + temp = ab_depend->depended_upon_by + othercount;
10125 +static depend_t * depend_init(void)
10127 + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
10129 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10132 + d->constraint = NONE;
10133 + d->version = NULL;
10139 +static void depend_deinit(depend_t *d)
10144 +static int parseDepends(compound_depend_t *compound_depend,
10145 + hash_table_t * hash, char * depend_str)
10147 + char * pkg_name, buffer[2048];
10148 + int num_of_ors = 0;
10150 + register char * src, * dest;
10151 + depend_t ** possibilities;
10153 + /* first count the number of ored possibilities for satisfying dependency */
10154 + src = depend_str;
10156 + if(*src++ == '|')
10159 + compound_depend->type = DEPEND;
10161 + compound_depend->possibility_count = num_of_ors + 1;
10162 + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
10163 + if (!possibilities)
10165 + compound_depend->possibilities = possibilities;
10167 + src = depend_str;
10168 + for(i = 0; i < num_of_ors + 1; i++){
10169 + possibilities[i] = depend_init();
10170 + if (!possibilities[i])
10172 + /* gobble up just the name first */
10175 + !isspace(*src) &&
10179 + *dest++ = *src++;
10181 + pkg_name = trim_alloc(buffer);
10182 + if (pkg_name == NULL )
10185 + /* now look at possible version info */
10187 + /* skip to next chars */
10188 + if(isspace(*src))
10189 + while(*src && isspace(*src)) src++;
10191 + /* extract constraint and version */
10194 + if(!strncmp(src, "<<", 2)){
10195 + possibilities[i]->constraint = EARLIER;
10198 + else if(!strncmp(src, "<=", 2)){
10199 + possibilities[i]->constraint = EARLIER_EQUAL;
10202 + else if(!strncmp(src, ">=", 2)){
10203 + possibilities[i]->constraint = LATER_EQUAL;
10206 + else if(!strncmp(src, ">>", 2)){
10207 + possibilities[i]->constraint = LATER;
10210 + else if(!strncmp(src, "=", 1)){
10211 + possibilities[i]->constraint = EQUAL;
10214 + /* should these be here to support deprecated designations; dpkg does */
10215 + else if(!strncmp(src, "<", 1)){
10216 + possibilities[i]->constraint = EARLIER_EQUAL;
10219 + else if(!strncmp(src, ">", 1)){
10220 + possibilities[i]->constraint = LATER_EQUAL;
10224 + /* now we have any constraint, pass space to version string */
10225 + while(isspace(*src)) src++;
10227 + /* this would be the version string */
10229 + while(*src && *src != ')')
10230 + *dest++ = *src++;
10233 + possibilities[i]->version = trim_alloc(buffer);
10234 + /* fprintf(stderr, "let's print the depends version string:");
10235 + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
10236 + if (possibilities[i]->version == NULL )
10241 + /* hook up the dependency to its abstract pkg */
10242 + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
10246 + /* now get past the ) and any possible | chars */
10248 + (isspace(*src) ||
10254 + compound_depend->type = GREEDY_DEPEND;
10262 +++ b/archival/libipkg/pkg_depends.h
10264 +/* pkg_depends.h - the itsy package management system
10268 + Copyright (C) 2002 Compaq Computer Corporation
10270 + This program is free software; you can redistribute it and/or
10271 + modify it under the terms of the GNU General Public License as
10272 + published by the Free Software Foundation; either version 2, or (at
10273 + your option) any later version.
10275 + This program is distributed in the hope that it will be useful, but
10276 + WITHOUT ANY WARRANTY; without even the implied warranty of
10277 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10278 + General Public License for more details.
10281 +#ifndef PKG_DEPENDS_H
10282 +#define PKG_DEPENDS_H
10285 +#include "pkg_hash.h"
10287 +enum depend_type {
10295 +typedef enum depend_type depend_type_t;
10297 +enum version_constraint {
10305 +typedef enum version_constraint version_constraint_t;
10308 + version_constraint_t constraint;
10310 + abstract_pkg_t * pkg;
10312 +typedef struct depend depend_t;
10314 +struct compound_depend{
10315 + depend_type_t type;
10316 + int possibility_count;
10317 + struct depend ** possibilities;
10319 +typedef struct compound_depend compound_depend_t;
10321 +#include "hash_table.h"
10323 +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10324 +int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10325 +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
10326 +int buildDepends(hash_table_t * hash, pkg_t * pkg);
10329 + * pkg_has_common_provides returns 1 if pkg and replacee both provide
10330 + * the same abstract package and 0 otherwise.
10332 +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
10335 + * pkg_provides returns 1 if pkg->provides contains providee and 0
10338 +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
10341 + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
10344 +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
10347 + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
10350 +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
10353 + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
10356 +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
10358 +char *pkg_depend_str(pkg_t *pkg, int pkg_index);
10359 +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
10360 +void freeDepends(pkg_t *pkg);
10361 +void printDepends(pkg_t * pkg);
10362 +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
10363 +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
10364 +pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
10365 +int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend);
10366 +int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend);
10370 +++ b/archival/libipkg/pkg_dest.c
10372 +/* pkg_dest.c - the itsy package management system
10376 + Copyright (C) 2001 University of Southern California
10378 + This program is free software; you can redistribute it and/or
10379 + modify it under the terms of the GNU General Public License as
10380 + published by the Free Software Foundation; either version 2, or (at
10381 + your option) any later version.
10383 + This program is distributed in the hope that it will be useful, but
10384 + WITHOUT ANY WARRANTY; without even the implied warranty of
10385 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10386 + General Public License for more details.
10391 +#include "pkg_dest.h"
10392 +#include "file_util.h"
10393 +#include "str_util.h"
10394 +#include "sprintf_alloc.h"
10396 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
10398 + dest->name = strdup(name);
10400 + /* Guarantee that dest->root_dir ends with a '/' */
10401 + if (str_ends_with(root_dir, "/")) {
10402 + dest->root_dir = strdup(root_dir);
10404 + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
10406 + file_mkdir_hier(dest->root_dir, 0755);
10408 + sprintf_alloc(&dest->ipkg_dir, "%s%s",
10409 + dest->root_dir, IPKG_STATE_DIR_PREFIX);
10410 + file_mkdir_hier(dest->ipkg_dir, 0755);
10412 + if (str_starts_with (lists_dir, "/"))
10413 + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
10415 + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
10417 + file_mkdir_hier(dest->lists_dir, 0755);
10419 + sprintf_alloc(&dest->info_dir, "%s/%s",
10420 + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
10421 + file_mkdir_hier(dest->info_dir, 0755);
10423 + sprintf_alloc(&dest->status_file_name, "%s/%s",
10424 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10426 + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
10427 + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
10429 + dest->status_file = NULL;
10434 +void pkg_dest_deinit(pkg_dest_t *dest)
10436 + free(dest->name);
10437 + dest->name = NULL;
10439 + free(dest->root_dir);
10440 + dest->root_dir = NULL;
10442 + free(dest->ipkg_dir);
10443 + dest->ipkg_dir = NULL;
10445 + free(dest->lists_dir);
10446 + dest->lists_dir = NULL;
10448 + free(dest->info_dir);
10449 + dest->info_dir = NULL;
10451 + free(dest->status_file_name);
10452 + dest->status_file_name = NULL;
10454 + free(dest->status_file_tmp_name);
10455 + dest->status_file_tmp_name = NULL;
10457 + if (dest->status_file) {
10458 + fclose(dest->status_file);
10460 + dest->status_file = NULL;
10462 + dest->root_dir = NULL;
10465 +++ b/archival/libipkg/pkg_dest.h
10467 +/* pkg_dest.h - the itsy package management system
10471 + Copyright (C) 2001 University of Southern California
10473 + This program is free software; you can redistribute it and/or
10474 + modify it under the terms of the GNU General Public License as
10475 + published by the Free Software Foundation; either version 2, or (at
10476 + your option) any later version.
10478 + This program is distributed in the hope that it will be useful, but
10479 + WITHOUT ANY WARRANTY; without even the implied warranty of
10480 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10481 + General Public License for more details.
10484 +#ifndef PKG_DEST_H
10485 +#define PKG_DEST_H
10487 +typedef struct pkg_dest pkg_dest_t;
10495 + char *status_file_name;
10496 + char *status_file_tmp_name;
10497 + FILE *status_file;
10500 +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
10501 +void pkg_dest_deinit(pkg_dest_t *dest);
10506 +++ b/archival/libipkg/pkg_dest_list.c
10508 +/* pkg_dest_list.c - the itsy package management system
10512 + Copyright (C) 2001 University of Southern California
10514 + This program is free software; you can redistribute it and/or
10515 + modify it under the terms of the GNU General Public License as
10516 + published by the Free Software Foundation; either version 2, or (at
10517 + your option) any later version.
10519 + This program is distributed in the hope that it will be useful, but
10520 + WITHOUT ANY WARRANTY; without even the implied warranty of
10521 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10522 + General Public License for more details.
10527 +#include "pkg_dest.h"
10528 +#include "void_list.h"
10529 +#include "pkg_dest_list.h"
10531 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
10533 + return void_list_elt_init((void_list_elt_t *) elt, data);
10536 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
10538 + void_list_elt_deinit((void_list_elt_t *) elt);
10541 +int pkg_dest_list_init(pkg_dest_list_t *list)
10543 + return void_list_init((void_list_t *) list);
10546 +void pkg_dest_list_deinit(pkg_dest_list_t *list)
10548 + pkg_dest_list_elt_t *iter;
10549 + pkg_dest_t *pkg_dest;
10551 + for (iter = list->head; iter; iter = iter->next) {
10552 + pkg_dest = iter->data;
10553 + pkg_dest_deinit(pkg_dest);
10555 + /* malloced in pkg_dest_list_append */
10557 + iter->data = NULL;
10559 + void_list_deinit((void_list_t *) list);
10562 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10563 + const char *root_dir,const char *lists_dir)
10566 + pkg_dest_t *pkg_dest;
10568 + /* freed in plg_dest_list_deinit */
10569 + pkg_dest = malloc(sizeof(pkg_dest_t));
10570 + if (pkg_dest == NULL) {
10571 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
10575 + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
10576 + err = void_list_append((void_list_t *) list, pkg_dest);
10584 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
10586 + return void_list_push((void_list_t *) list, data);
10589 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
10591 + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
10594 +++ b/archival/libipkg/pkg_dest_list.h
10596 +/* pkg_dest_list.h - the itsy package management system
10600 + Copyright (C) 2001 University of Southern California
10602 + This program is free software; you can redistribute it and/or
10603 + modify it under the terms of the GNU General Public License as
10604 + published by the Free Software Foundation; either version 2, or (at
10605 + your option) any later version.
10607 + This program is distributed in the hope that it will be useful, but
10608 + WITHOUT ANY WARRANTY; without even the implied warranty of
10609 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10610 + General Public License for more details.
10613 +#ifndef PKG_DEST_LIST_H
10614 +#define PKG_DEST_LIST_H
10616 +#include "pkg_dest.h"
10618 +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
10619 +struct pkg_dest_list_elt
10621 + pkg_dest_list_elt_t *next;
10622 + pkg_dest_t *data;
10625 +typedef struct pkg_dest_list pkg_dest_list_t;
10626 +struct pkg_dest_list
10628 + pkg_dest_list_elt_t pre_head;
10629 + pkg_dest_list_elt_t *head;
10630 + pkg_dest_list_elt_t *tail;
10633 +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
10634 +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
10636 +int pkg_dest_list_init(pkg_dest_list_t *list);
10637 +void pkg_dest_list_deinit(pkg_dest_list_t *list);
10639 +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
10640 + const char *root_dir,const char* lists_dir);
10641 +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
10642 +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
10647 +++ b/archival/libipkg/pkg_extract.c
10649 +/* pkg_extract.c - the itsy package management system
10653 + Copyright (C) 2001 University of Southern California
10655 + This program is free software; you can redistribute it and/or
10656 + modify it under the terms of the GNU General Public License as
10657 + published by the Free Software Foundation; either version 2, or (at
10658 + your option) any later version.
10660 + This program is distributed in the hope that it will be useful, but
10661 + WITHOUT ANY WARRANTY; without even the implied warranty of
10662 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10663 + General Public License for more details.
10667 +#include <errno.h>
10668 +#include <fcntl.h>
10669 +#include <stdio.h>
10671 +#include "pkg_extract.h"
10673 +#include "libbb.h"
10674 +#include "file_util.h"
10675 +#include "sprintf_alloc.h"
10676 +#include "unarchive.h"
10678 +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
10679 +#define IPKG_DATA_ARCHIVE "data.tar.gz"
10680 +#define IPKG_CONTROL_FILE "control"
10682 +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
10684 + archive_handle_t *archive;
10687 + sprintf_alloc(&path, "%s/", dir);
10688 + archive = init_handle();
10689 + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
10690 + archive->filter = filter_accept_list;
10691 + llist_add_to(&(archive->accept), (char *)filename);
10692 + archive->buffer = path;
10693 + archive->action_data = data_extract_all_prefix;
10694 + archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
10695 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10696 + close(archive->src_fd);
10697 + free(archive->accept);
10702 +static void data_extract_file_name_to_buffer(archive_handle_t *archive)
10704 + unsigned int size = strlen(archive->file_header->name) + 2;
10706 + if (archive->buffer == NULL) {
10707 + archive->buffer = xmalloc(size);
10708 + strcpy(archive->buffer, archive->file_header->name);
10710 + size += strlen(archive->buffer);
10711 + archive->buffer = xrealloc(archive->buffer, size);
10712 + strcat(archive->buffer, archive->file_header->name);
10714 + strcat(archive->buffer, "\n");
10715 + data_skip(archive);
10718 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
10720 + archive_handle_t *archive;
10723 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10724 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10725 + archive = init_handle();
10726 + archive->src_fd = xopen(name, O_RDONLY);
10727 + archive->filter = filter_accept_list;
10728 + llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE);
10729 + archive->action_data = data_extract_to_buffer;
10730 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10731 + close(archive->src_fd);
10732 + fputs(archive->buffer, stream);
10733 + free(archive->buffer);
10734 + free(archive->accept);
10741 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
10743 + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
10746 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
10748 + archive_handle_t *archive;
10752 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
10753 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
10754 + sprintf_alloc(&path, "%s/%s", dir, prefix);
10755 + archive = init_handle();
10756 + archive->src_fd = xopen(name, O_RDONLY);
10757 + archive->filter = filter_accept_all;
10758 + archive->buffer = path;
10759 + archive->action_data = data_extract_all_prefix;
10760 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10761 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10762 + close(archive->src_fd);
10770 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
10772 + archive_handle_t *archive;
10776 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10777 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10778 + sprintf_alloc(&path, "%s/", dir);
10779 + archive = init_handle();
10780 + archive->src_fd = xopen(name, O_RDONLY);
10781 + archive->filter = filter_accept_all;
10782 + archive->buffer = path;
10783 + archive->action_data = data_extract_all_prefix;
10784 + archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
10785 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10786 + close(archive->src_fd);
10794 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
10797 + char *line, *data_file;
10801 + file = fopen(file_name, "w");
10802 + if (file == NULL) {
10803 + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
10804 + __FUNCTION__, file_name);
10809 + if (pkg->installed_files) {
10810 + str_list_elt_t *elt;
10811 + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
10812 + fprintf(file, "%s\n", elt->data);
10815 + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
10822 + /* Fixup data file names by removing the initial '.' */
10825 + line = file_read_line_alloc(tmp);
10826 + if (line == NULL) {
10830 + data_file = line;
10831 + if (*data_file == '.') {
10835 + if (*data_file != '/') {
10836 + fputs("/", file);
10839 + /* I have no idea why, but this is what dpkg does */
10840 + if (strcmp(data_file, "/\n") == 0) {
10841 + fputs("/.\n", file);
10843 + fputs(data_file, file);
10853 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
10855 + archive_handle_t *archive;
10858 + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
10859 + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
10860 + archive = init_handle();
10861 + archive->src_fd = xopen(name, O_RDONLY);
10862 + archive->filter = filter_accept_all;
10863 + archive->action_data = data_extract_file_name_to_buffer;
10864 + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
10865 + close(archive->src_fd);
10866 + fputs(archive->buffer, file);
10867 + free(archive->buffer);
10874 +++ b/archival/libipkg/pkg_extract.h
10876 +/* pkg_extract.c - the itsy package management system
10880 + Copyright (C) 2001 University of Southern California
10882 + This program is free software; you can redistribute it and/or
10883 + modify it under the terms of the GNU General Public License as
10884 + published by the Free Software Foundation; either version 2, or (at
10885 + your option) any later version.
10887 + This program is distributed in the hope that it will be useful, but
10888 + WITHOUT ANY WARRANTY; without even the implied warranty of
10889 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10890 + General Public License for more details.
10893 +#ifndef PKG_EXTRACT_H
10894 +#define PKG_EXTRACT_H
10898 +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
10899 +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
10900 +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
10902 + const char *prefix);
10903 +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
10904 +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
10905 +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
10909 +++ b/archival/libipkg/pkg.h
10911 +/* pkg.h - the itsy package management system
10915 + Copyright (C) 2001 University of Southern California
10917 + This program is free software; you can redistribute it and/or
10918 + modify it under the terms of the GNU General Public License as
10919 + published by the Free Software Foundation; either version 2, or (at
10920 + your option) any later version.
10922 + This program is distributed in the hope that it will be useful, but
10923 + WITHOUT ANY WARRANTY; without even the implied warranty of
10924 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10925 + General Public License for more details.
10931 +#include <sys/types.h>
10932 +#include <sys/stat.h>
10933 +#include <unistd.h>
10935 +#include "pkg_vec.h"
10936 +#include "str_list.h"
10937 +#include "pkg_src.h"
10938 +#include "pkg_dest.h"
10939 +#include "ipkg_conf.h"
10940 +#include "conffile_list.h"
10944 +/* I think "Size" is currently the shortest field name */
10945 +#define PKG_MINIMUM_FIELD_NAME_LEN 4
10947 +enum pkg_state_want
10953 + SW_LAST_STATE_WANT
10955 +typedef enum pkg_state_want pkg_state_want_t;
10957 +enum pkg_state_flag
10960 + SF_REINSTREQ = 1,
10961 + SF_HOLD = 2, /* do not upgrade version */
10962 + SF_REPLACE = 4, /* replace this package */
10963 + SF_NOPRUNE = 8, /* do not remove obsolete files */
10964 + SF_PREFER = 16, /* prefer this version */
10965 + SF_OBSOLETE = 32, /* old package in upgrade pair */
10966 + SF_MARKED = 64, /* temporary mark */
10967 + SF_FILELIST_CHANGED = 128, /* needs filelist written */
10969 + SF_LAST_STATE_FLAG
10971 +typedef enum pkg_state_flag pkg_state_flag_t;
10972 +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
10974 +enum pkg_state_status
10976 + SS_NOT_INSTALLED = 1,
10978 + SS_HALF_CONFIGURED,
10980 + SS_HALF_INSTALLED,
10982 + SS_POST_INST_FAILED,
10983 + SS_REMOVAL_FAILED,
10984 + SS_LAST_STATE_STATUS
10986 +typedef enum pkg_state_status pkg_state_status_t;
10988 +struct abstract_pkg{
10990 + int dependencies_checked;
10991 + pkg_vec_t * pkgs;
10992 + pkg_state_status_t state_status;
10993 + pkg_state_flag_t state_flag;
10994 + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
10995 + abstract_pkg_vec_t * provided_by;
10996 + abstract_pkg_vec_t * replaced_by;
10999 +#include "pkg_depends.h"
11001 +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
11003 + The 3 version fields should go into a single version struct. (This
11004 + is especially important since, currently, pkg->version can easily
11005 + be mistaken for pkg_verson_str_alloc(pkg) although they are very
11006 + distinct. This has been the source of multiple bugs.
11008 + The 3 state fields could possibly also go into their own struct.
11010 + All fields which deal with lists of packages, (Depends,
11011 + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
11012 + be handled by a single struct in pkg_t
11014 + All string fields for which there is a small set of possible
11015 + values, (section, maintainer, architecture, maybe version?), that
11016 + are reused among different packages -- for all such packages we
11017 + should move from "char *"s to some atom datatype to share data
11018 + storage and use less memory. We might even do reference counting,
11019 + but probably not since most often we only create new pkg_t structs,
11020 + we don't often free them. */
11024 + unsigned long epoch;
11027 + char *familiar_revision;
11029 + pkg_dest_t *dest;
11030 + char *architecture;
11032 + char *maintainer;
11033 + char *description;
11034 + pkg_state_want_t state_want;
11035 + pkg_state_flag_t state_flag;
11036 + pkg_state_status_t state_status;
11037 + char **depends_str;
11038 + int depends_count;
11039 + char **pre_depends_str;
11040 + int pre_depends_count;
11041 + char **recommends_str;
11042 + int recommends_count;
11043 + char **suggests_str;
11044 + int suggests_count;
11045 + compound_depend_t * depends;
11047 + /* Abhaya: new conflicts */
11048 + char **conflicts_str;
11049 + compound_depend_t * conflicts;
11050 + int conflicts_count;
11052 + char **replaces_str;
11053 + int replaces_count;
11054 + abstract_pkg_t ** replaces;
11056 + char **provides_str;
11057 + int provides_count;
11058 + abstract_pkg_t ** provides;
11060 + abstract_pkg_t *parent;
11062 + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
11065 + char *local_filename;
11067 + char *tmp_unpack_dir;
11070 + char *installed_size;
11073 + conffile_list_t conffiles;
11074 + time_t installed_time;
11075 + /* As pointer for lazy evaluation */
11076 + str_list_t *installed_files;
11077 + /* XXX: CLEANUP: I'd like to perhaps come up with a better
11078 + mechanism to avoid the problem here, (which is that the
11079 + installed_files list was being freed from an inner loop while
11080 + still being used within an outer loop. */
11081 + int installed_files_ref_cnt;
11083 + int arch_priority;
11084 +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
11085 + int provided_by_hand;
11088 +pkg_t *pkg_new(void);
11089 +int pkg_init(pkg_t *pkg);
11090 +void pkg_deinit(pkg_t *pkg);
11091 +int pkg_init_from_file(pkg_t *pkg, const char *filename);
11092 +abstract_pkg_t *abstract_pkg_new(void);
11093 +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
11096 + * merges fields from newpkg into oldpkg.
11097 + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
11099 +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
11101 +char *pkg_version_str_alloc(pkg_t *pkg);
11103 +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
11104 +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
11105 +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
11107 +char * pkg_formatted_info(pkg_t *pkg );
11108 +char * pkg_formatted_field(pkg_t *pkg, const char *field );
11110 +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
11112 +void pkg_print_info(pkg_t *pkg, FILE *file);
11113 +void pkg_print_status(pkg_t * pkg, FILE * file);
11114 +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
11115 +str_list_t *pkg_get_installed_files(pkg_t *pkg);
11116 +int pkg_free_installed_files(pkg_t *pkg);
11117 +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
11118 +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
11119 +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
11120 + const char *script, const char *args);
11122 +/* enum mappings */
11123 +char *pkg_state_want_to_str(pkg_state_want_t sw);
11124 +pkg_state_want_t pkg_state_want_from_str(char *str);
11125 +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
11126 +pkg_state_flag_t pkg_state_flag_from_str(char *str);
11127 +char *pkg_state_status_to_str(pkg_state_status_t ss);
11128 +pkg_state_status_t pkg_state_status_from_str(char *str);
11130 +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
11132 +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
11133 +int pkg_info_preinstall_check(ipkg_conf_t *conf);
11134 +int pkg_free_installed_files(pkg_t *pkg);
11136 +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
11137 +int pkg_write_changed_filelists(ipkg_conf_t *conf);
11141 +++ b/archival/libipkg/pkg_hash.c
11143 +/* ipkg_hash.c - the itsy package management system
11147 + Copyright (C) 2002 Compaq Computer Corporation
11149 + This program is free software; you can redistribute it and/or
11150 + modify it under the terms of the GNU General Public License as
11151 + published by the Free Software Foundation; either version 2, or (at
11152 + your option) any later version.
11154 + This program is distributed in the hope that it will be useful, but
11155 + WITHOUT ANY WARRANTY; without even the implied warranty of
11156 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11157 + General Public License for more details.
11161 +#include <errno.h>
11162 +#include <ctype.h>
11163 +#include <stdlib.h>
11164 +#include <string.h>
11166 +#include "hash_table.h"
11168 +#include "ipkg_message.h"
11169 +#include "pkg_vec.h"
11170 +#include "pkg_hash.h"
11171 +#include "pkg_parse.h"
11172 +#include "ipkg_utils.h"
11174 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11177 + * this will talk to both feeds-lists files and installed status files
11180 + * hash_table_t hash;
11181 + * pkg_hash_init(name, &hash, 1000);
11182 + * pkg_hash_add_from_file(<feed filename>);
11184 + * the query function is just there as a shell to prove to me that this
11185 + * sort of works, but isn't far from doing something useful
11188 + * modified: CDW 3 Jan. 2002
11193 +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
11195 + return hash_table_init(name, hash, len);
11198 +void pkg_hash_deinit(hash_table_t *hash)
11200 + hash_table_deinit(hash);
11204 +/* Find the default arch for a given package status file if none is given. */
11205 +static char *pkg_get_default_arch(ipkg_conf_t *conf)
11207 + nv_pair_list_elt_t *l;
11208 + char *def_arch = HOST_CPU_STR; /* Default arch */
11209 + int def_prio = 0; /* Other archs override this */
11211 + l = conf->arch_list.head;
11214 + nv_pair_t *nv = l->data;
11215 + int priority = strtol(nv->value, NULL, 0);
11217 + /* Check if this arch has higher priority, and is valid */
11218 + if ((priority > def_prio) &&
11219 + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
11220 + /* Our new default */
11221 + def_prio = priority;
11222 + def_arch = nv->name;
11227 + return strdup(def_arch);
11230 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11231 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
11233 + hash_table_t *hash = &conf->pkg_hash;
11235 + char **raw_start;
11238 + raw = raw_start = read_raw_pkgs_from_file(file_name);
11242 + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
11247 + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
11248 + if (!pkg->architecture) {
11249 + char *version_str = pkg_version_str_alloc(pkg);
11250 + pkg->architecture = pkg_get_default_arch(conf);
11251 + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
11252 + pkg->name, version_str, pkg->architecture);
11253 + free(version_str);
11255 + hash_insert_pkg(hash, pkg, is_status_file,conf);
11261 + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
11262 + memory after read_raw_pkgs_from_file */
11271 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
11273 + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
11276 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
11278 + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
11281 + return apkg->provided_by;
11285 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11286 + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
11289 + int nprovides = 0;
11290 + int nmatching = 0;
11291 + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
11292 + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
11293 + abstract_pkg_vec_t *provided_apkg_vec;
11294 + abstract_pkg_t **provided_apkgs;
11295 + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
11296 + pkg_t *latest_installed_parent = NULL;
11297 + pkg_t *latest_matching = NULL;
11298 + pkg_t *held_pkg = NULL;
11299 + pkg_t *good_pkg_by_name = NULL;
11301 + if (matching_apkgs == NULL || providers == NULL ||
11302 + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
11305 + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
11307 + provided_apkg_vec = apkg->provided_by;
11308 + nprovides = provided_apkg_vec->len;
11309 + provided_apkgs = provided_apkg_vec->pkgs;
11310 + if (nprovides > 1)
11311 + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
11313 + /* accumulate all the providers */
11314 + for (i = 0; i < nprovides; i++) {
11315 + abstract_pkg_t *provider_apkg = provided_apkgs[i];
11316 + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
11317 + abstract_pkg_vec_insert(providers, provider_apkg);
11319 + nprovides = providers->len;
11321 + for (i = 0; i < nprovides; i++) {
11322 + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
11323 + abstract_pkg_t *replacement_apkg = NULL;
11326 + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
11327 + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
11328 + if (provider_apkg->replaced_by->len > 1) {
11329 + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
11330 + provider_apkg->name, replacement_apkg->name);
11334 + if (replacement_apkg)
11335 + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
11336 + replacement_apkg->name, provider_apkg->name);
11338 + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
11339 + if (abstract_pkg_vec_contains(providers, replacement_apkg))
11342 + provider_apkg = replacement_apkg;
11345 + if (!(vec = provider_apkg->pkgs)) {
11346 + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
11351 + /* now check for supported architecture */
11353 + int max_count = 0;
11355 + /* count packages matching max arch priority and keep track of last one */
11356 + for (j = 0; j < vec->len; j++) {
11357 + pkg_t *maybe = vec->pkgs[j];
11358 + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
11359 + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
11360 + if (maybe->arch_priority > 0) {
11362 + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
11363 + pkg_vec_insert(matching_pkgs, maybe);
11369 + if (matching_pkgs->len > 1)
11370 + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
11371 + if (matching_apkgs->len > 1)
11372 + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
11374 +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
11375 + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
11376 +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
11377 + Until now I always got the latest, but that breaks the downgrade option.
11378 + If I stop at the first one, I would probably miss the new ones
11379 + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
11380 + or from a Packages feed.
11381 + 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*/
11384 + for (i = 0; i < matching_pkgs->len; i++) {
11385 + pkg_t *matching = matching_pkgs->pkgs[i];
11386 + if (constraint_fcn(matching, cdata)) { /* We found it */
11387 + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
11388 + good_pkg_by_name = matching;
11389 + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
11395 + for (i = 0; i < matching_pkgs->len; i++) {
11396 + pkg_t *matching = matching_pkgs->pkgs[i];
11397 + latest_matching = matching;
11398 + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
11399 + latest_installed_parent = matching;
11400 + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
11402 + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
11403 + held_pkg->name, matching->name);
11404 + held_pkg = matching;
11408 + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
11409 + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
11410 + apkg->name, matching_apkgs->len);
11411 + for (i = 0; i < matching_apkgs->len; i++) {
11412 + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
11413 + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
11415 + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
11418 + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
11419 + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
11420 + __FUNCTION__, apkg->name, matching_pkgs->len);
11421 + for (i = 0; i < matching_pkgs->len; i++) {
11422 + pkg_t *matching = matching_pkgs->pkgs[i];
11423 + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
11424 + matching->name, matching->version, matching->architecture);
11428 + nmatching = matching_apkgs->len;
11430 + pkg_vec_free(matching_pkgs);
11431 + abstract_pkg_vec_free(matching_apkgs);
11432 + abstract_pkg_vec_free(providers);
11434 + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
11435 + return good_pkg_by_name;
11438 + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
11441 + if (latest_installed_parent) {
11442 + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
11443 + return latest_installed_parent;
11445 + if (nmatching > 1) {
11446 + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
11449 + if (latest_matching) {
11450 + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
11451 + latest_matching->name, latest_matching->version, latest_matching->architecture);
11452 + return latest_matching;
11457 +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
11459 + const char *name = (const char *)cdata;
11460 + if (strcmp(pkg->name, name) == 0)
11466 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
11468 + hash_table_t *hash = &conf->pkg_hash;
11469 + abstract_pkg_t *apkg = NULL;
11471 + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
11474 + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
11478 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11479 + const char *pkg_name,
11480 + const char * version)
11484 + char *version_str = NULL;
11486 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
11489 + for(i = 0; i < vec->len; i++) {
11490 + version_str = pkg_version_str_alloc(vec->pkgs[i]);
11491 + if(!strcmp(version_str, version)) {
11492 + free(version_str);
11495 + free(version_str);
11498 + if(i == vec->len)
11501 + return vec->pkgs[i];
11504 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11505 + const char *pkg_name,
11506 + pkg_dest_t *dest)
11511 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
11515 + for(i = 0; i < vec->len; i++)
11516 + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
11517 + return vec->pkgs[i];
11522 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11523 + const char *pkg_name)
11528 + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
11532 + for(i = 0; i < vec->len; i++)
11533 + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
11534 + return vec->pkgs[i];
11540 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
11542 + abstract_pkg_t * ab_pkg;
11544 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
11548 + if (ab_pkg->pkgs) {
11549 + return ab_pkg->pkgs;
11550 + } else if (ab_pkg->provided_by) {
11551 + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
11552 + if (abpkg != NULL){
11553 + return abpkg->pkgs;
11555 + return ab_pkg->pkgs;
11562 +static int pkg_compare_names(const void *p1, const void *p2)
11564 + const pkg_t *pkg1 = *(const pkg_t **)p1;
11565 + const pkg_t *pkg2 = *(const pkg_t **)p2;
11566 + if (pkg1->name == NULL)
11568 + if (pkg2->name == NULL)
11570 + return(strcmp(pkg1->name, pkg2->name));
11574 +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
11577 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11578 + pkg_vec_t *all = (pkg_vec_t *)data;
11579 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11581 + for (j = 0; j < pkg_vec->len; j++) {
11582 + pkg_t *pkg = pkg_vec->pkgs[j];
11583 + pkg_vec_insert(all, pkg);
11588 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
11590 + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
11591 + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
11594 +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
11596 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11597 + pkg_vec_t *all = (pkg_vec_t *)data;
11598 + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
11601 + for (j = 0; j < pkg_vec->len; j++) {
11602 + pkg_t *pkg = pkg_vec->pkgs[j];
11603 + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
11604 + pkg_vec_insert(all, pkg);
11609 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
11611 + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
11612 + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
11615 +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
11619 + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
11620 + ipkg_conf_t *conf = (ipkg_conf_t *)data;
11621 + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
11622 + fprintf(stdout, "%s\n", ab_pkg->name);
11624 + if (dependents != NULL)
11625 + while (dependents [i] != NULL)
11626 + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
11627 + dependents = ab_pkg->provided_by->pkgs;
11629 + if (dependents != NULL)
11630 + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
11631 + printf ("\tprovided by - %s\n", dependents [i ++]->name);
11632 + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
11635 + while (i < pkg->depends_count)
11636 + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
11639 +void pkg_hash_dump(hash_table_t *hash, void *data)
11642 + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
11643 + hash_table_foreach(hash, pkg_hash_dump_helper, data);
11644 + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
11647 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11649 + abstract_pkg_t * ab_pkg;
11651 + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
11652 + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
11657 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
11659 + abstract_pkg_t * ab_pkg;
11660 + int arch_priority;
11665 + arch_priority = pkg->arch_priority;
11667 + if (buildDepends(hash, pkg)<0){
11668 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11671 + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
11673 + if (set_status) {
11674 + if (pkg->state_status == SS_INSTALLED) {
11675 + ab_pkg->state_status = SS_INSTALLED;
11676 + } else if (pkg->state_status == SS_UNPACKED) {
11677 + ab_pkg->state_status = SS_UNPACKED;
11681 + if(!ab_pkg->pkgs)
11682 + ab_pkg->pkgs = pkg_vec_alloc();
11684 + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
11685 + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
11686 + pkg->parent = ab_pkg;
11688 + if (buildProvides(hash, ab_pkg, pkg)<0){
11689 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11692 + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
11693 + if (buildConflicts(hash, ab_pkg, pkg)<0){
11694 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11697 + if (buildReplaces(hash, ab_pkg, pkg)<0) {
11698 + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
11702 + buildDependedUponBy(pkg, ab_pkg);
11707 + * this will assume that we've already determined that
11708 + * the abstract pkg doesn't exist, 'cause we should know these things...
11710 +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
11712 + abstract_pkg_t * ab_pkg;
11714 + ab_pkg = abstract_pkg_new();
11715 + if (ab_pkg == NULL) { return NULL; }
11717 + ab_pkg->name = strdup(pkg_name);
11718 + hash_table_insert(hash, pkg_name, ab_pkg);
11724 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
11726 + hash_table_t *file_hash = &conf->file_hash;
11728 + return hash_table_get(file_hash, file_name);
11731 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
11733 + hash_table_t *file_hash = &conf->file_hash;
11734 + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
11735 + int file_name_len = strlen(file_name);
11737 + if (file_name[file_name_len -1] == '/')
11740 + if (conf->offline_root) {
11741 + int len = strlen(conf->offline_root);
11742 + if (strncmp(file_name, conf->offline_root, len) == 0) {
11743 + file_name += len;
11747 + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
11748 + hash_table_insert(file_hash, file_name, owning_pkg);
11749 + if (old_owning_pkg) {
11750 + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
11751 + /* mark this package to have its filelist written */
11752 + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11753 + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
11760 +++ b/archival/libipkg/pkg_hash.h
11762 +/* pkg_hash.h - the itsy package management system
11766 + Copyright (C) 2002 Compaq Computer Corporation
11768 + This program is free software; you can redistribute it and/or
11769 + modify it under the terms of the GNU General Public License as
11770 + published by the Free Software Foundation; either version 2, or (at
11771 + your option) any later version.
11773 + This program is distributed in the hope that it will be useful, but
11774 + WITHOUT ANY WARRANTY; without even the implied warranty of
11775 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11776 + General Public License for more details.
11779 +#ifndef PKG_HASH_H
11780 +#define PKG_HASH_H
11783 +#include "pkg_vec.h"
11784 +#include "hash_table.h"
11787 +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
11788 +void pkg_hash_deinit(hash_table_t *hash);
11789 +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
11791 +void pkg_hash_dump(hash_table_t *hash, void *data);
11792 +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
11794 +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
11795 + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
11796 +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
11798 +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
11799 +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
11800 +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11801 +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
11802 +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
11803 + const char *pkg_name,
11804 + const char * version);
11805 +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
11806 +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
11807 + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
11808 +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
11809 +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
11810 + const char *pkg_name);
11811 +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
11812 + const char *pkg_name,
11813 + pkg_dest_t *dest);
11815 +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
11816 +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
11818 +/* XXX: shouldn't this go in pkg_vec.[ch]? */
11819 +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
11824 +++ b/archival/libipkg/pkg_parse.c
11826 +/* pkg_parse.c - the itsy package management system
11830 + Copyright (C) 2002 Compaq Computer Corporation
11832 + This program is free software; you can redistribute it and/or
11833 + modify it under the terms of the GNU General Public License as
11834 + published by the Free Software Foundation; either version 2, or (at
11835 + your option) any later version.
11837 + This program is distributed in the hope that it will be useful, but
11838 + WITHOUT ANY WARRANTY; without even the implied warranty of
11839 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11840 + General Public License for more details.
11844 +#include <errno.h>
11845 +#include <ctype.h>
11848 +#include "ipkg_utils.h"
11849 +#include "pkg_parse.h"
11851 +int isGenericFieldType(char * type, char * line)
11853 + if(!strncmp(line, type, strlen(type)))
11858 +char * parseGenericFieldType(char * type, char * raw)
11860 + char * field_value = raw + (strlen(type) + 1);
11861 + return trim_alloc(field_value);
11864 +void parseStatus(pkg_t *pkg, char * raw)
11866 + char sw_str[64], sf_str[64], ss_str[64];
11868 + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
11869 + pkg->state_want = pkg_state_want_from_str(sw_str);
11870 + pkg->state_flag = pkg_state_flag_from_str(sf_str);
11871 + pkg->state_status = pkg_state_status_from_str(ss_str);
11874 +char ** parseDependsString(char * raw, int * depends_count)
11876 + char ** depends = NULL;
11877 + int line_count = 0;
11878 + char buff[2048], * dest;
11880 + while(raw && *raw && !isspace(*raw)) {
11884 + if(line_is_blank(raw)){
11885 + *depends_count = line_count;
11888 + while(raw && *raw){
11889 + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
11891 + while(isspace(*raw)) raw++;
11894 + while((*raw != ',') && *raw)
11895 + *dest++ = *raw++;
11898 + depends[line_count] = trim_alloc(buff);
11899 + if(depends[line_count] ==NULL)
11905 + *depends_count = line_count;
11909 +void parseConffiles(pkg_t * pkg, char * raw)
11911 + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
11913 + if(!strncmp(raw, "Conffiles:", 10))
11914 + raw += strlen("Conffiles:");
11916 + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
11917 + conffile_list_append(&pkg->conffiles, file_name, md5sum);
11918 + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
11919 + while (*raw && isspace(*raw)) {
11922 + raw += strlen(file_name);
11923 + while (*raw && isspace(*raw)) {
11926 + raw += strlen(md5sum);
11930 +int parseVersion(pkg_t *pkg, char *raw)
11932 + char *colon, *eepochcolon;
11933 +#ifdef USE_DEBVERSION
11936 + unsigned long epoch;
11939 + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
11943 + if (strncmp(raw, "Version:", 8) == 0) {
11946 + while (*raw && isspace(*raw)) {
11950 + colon= strchr(raw,':');
11952 + epoch= strtoul(raw,&eepochcolon,10);
11953 + if (colon != eepochcolon) {
11954 + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
11958 + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
11962 + pkg->epoch= epoch;
11967 + pkg->revision = "";
11968 + pkg->familiar_revision = "";
11970 + pkg->version= malloc(strlen(raw)+1);
11971 + if ( pkg->version == NULL ) {
11972 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
11975 + strcpy(pkg->version, raw);
11977 +#ifdef USE_DEBVERSION
11978 + hyphen= strrchr(pkg->version,'-');
11982 + if (strncmp("fam", hyphen, 3) == 0) {
11983 + pkg->familiar_revision=hyphen+3;
11984 + hyphen= strrchr(pkg->version,'-');
11987 + pkg->revision = hyphen;
11990 + pkg->revision = hyphen;
11996 + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
12000 + pkg->familiar_revision);
12007 +/* This code is needed to insert in first position the keyword for the aligning bug */
12009 +int alterProvidesLine(char *raw, char *temp)
12014 + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
12018 + if ( temp == NULL ) {
12019 + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
12023 + if (strncmp(raw, "Provides:", 9) == 0) {
12026 + while (*raw && isspace(*raw)) {
12030 + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
12032 + strncat( temp, raw++, 1);
12038 +/* Some random thoughts from Carl:
12040 + This function could be considerably simplified if we just kept
12041 + an array of all the generic string-valued field names, and looped
12042 + through those looking for a match. Also, these fields could perhaps
12043 + be stored in the package as an array as well, (or, probably better,
12044 + as an nv_pair_list_t).
12046 + Fields which require special parsing or storage, (such as Depends:
12047 + and Status:) could be handled as they are now.
12049 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
12050 + to a dependency list. And, since we already have
12051 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
12052 + Enhances, perhaps we could generalize all of these and save some
12053 + code duplication.
12055 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
12057 + int reading_conffiles, reading_description;
12058 + int pkg_false_provides=1;
12060 + char * provide=NULL;
12063 + pkg->dest = dest;
12065 + reading_conffiles = reading_description = 0;
12067 + for (lines = *raw; *lines; lines++) {
12068 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
12069 + if(isGenericFieldType("Package:", *lines))
12070 + pkg->name = parseGenericFieldType("Package", *lines);
12071 + else if(isGenericFieldType("Architecture:", *lines))
12072 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
12073 + else if(isGenericFieldType("Filename:", *lines))
12074 + pkg->filename = parseGenericFieldType("Filename", *lines);
12075 + else if(isGenericFieldType("Section:", *lines))
12076 + pkg->section = parseGenericFieldType("Section", *lines);
12077 + else if(isGenericFieldType("MD5sum:", *lines))
12078 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
12079 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
12080 + let's parse it either way */
12081 + else if(isGenericFieldType("MD5Sum:", *lines))
12082 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
12083 + else if(isGenericFieldType("Size:", *lines))
12084 + pkg->size = parseGenericFieldType("Size", *lines);
12085 + else if(isGenericFieldType("Source:", *lines))
12086 + pkg->source = parseGenericFieldType("Source", *lines);
12087 + else if(isGenericFieldType("Installed-Size:", *lines))
12088 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
12089 + else if(isGenericFieldType("Installed-Time:", *lines)) {
12090 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
12091 + pkg->installed_time = strtoul(time_str, NULL, 0);
12092 + } else if(isGenericFieldType("Priority:", *lines))
12093 + pkg->priority = parseGenericFieldType("Priority", *lines);
12094 + else if(isGenericFieldType("Essential:", *lines)) {
12095 + char *essential_value;
12096 + essential_value = parseGenericFieldType("Essential", *lines);
12097 + if (strcmp(essential_value, "yes") == 0) {
12098 + pkg->essential = 1;
12100 + free(essential_value);
12102 + else if(isGenericFieldType("Status", *lines))
12103 + parseStatus(pkg, *lines);
12104 + else if(isGenericFieldType("Version", *lines))
12105 + parseVersion(pkg, *lines);
12106 + else if(isGenericFieldType("Maintainer", *lines))
12107 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
12108 + else if(isGenericFieldType("Conffiles", *lines)){
12109 + parseConffiles(pkg, *lines);
12110 + reading_conffiles = 1;
12112 + else if(isGenericFieldType("Description", *lines)) {
12113 + pkg->description = parseGenericFieldType("Description", *lines);
12114 + reading_conffiles = 0;
12115 + reading_description = 1;
12118 + else if(isGenericFieldType("Provides", *lines)){
12119 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
12120 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
12121 + if ( alterProvidesLine(*lines,provide) ){
12124 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
12125 +/* Let's try to hack a bit here.
12126 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
12127 + in alot of other places. We will remove it before writing down the status database */
12128 + pkg_false_provides=0;
12132 + else if(isGenericFieldType("Depends", *lines))
12133 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
12134 + else if(isGenericFieldType("Pre-Depends", *lines))
12135 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
12136 + else if(isGenericFieldType("Recommends", *lines))
12137 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
12138 + else if(isGenericFieldType("Suggests", *lines))
12139 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
12140 + /* Abhaya: support for conflicts */
12141 + else if(isGenericFieldType("Conflicts", *lines))
12142 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
12143 + else if(isGenericFieldType("Replaces", *lines))
12144 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
12145 + else if(line_is_blank(*lines)) {
12149 + else if(**lines == ' '){
12150 + if(reading_description) {
12151 + /* we already know it's not blank, so the rest of description */
12152 + pkg->description = realloc(pkg->description,
12153 + strlen(pkg->description)
12154 + + 1 + strlen(*lines) + 1);
12155 + strcat(pkg->description, "\n");
12156 + strcat(pkg->description, (*lines));
12158 + else if(reading_conffiles)
12159 + parseConffiles(pkg, *lines);
12163 +/* If the ipk has not a Provides line, we insert our false line */
12164 + if ( pkg_false_provides==1)
12165 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
12174 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
12178 + for (lines = *raw; *lines; lines++) {
12179 + if(isGenericFieldType("Essential:", *lines)) {
12180 + char *essential_value;
12181 + essential_value = parseGenericFieldType("Essential", *lines);
12182 + if (strcmp(essential_value, "yes") == 0) {
12183 + pkg->essential = 1;
12185 + free(essential_value);
12193 +++ b/archival/libipkg/pkg_parse.h
12195 +/* pkg_parse.h - the itsy package management system
12199 + Copyright (C) 2002 Compaq Computer Corporation
12201 + This program is free software; you can redistribute it and/or
12202 + modify it under the terms of the GNU General Public License as
12203 + published by the Free Software Foundation; either version 2, or (at
12204 + your option) any later version.
12206 + This program is distributed in the hope that it will be useful, but
12207 + WITHOUT ANY WARRANTY; without even the implied warranty of
12208 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12209 + General Public License for more details.
12212 +#ifndef PKG_PARSE_H
12213 +#define PKG_PARSE_H
12215 +int isGenericFieldType(char * type, char * line);
12216 +char * parseGenericFieldType(char * type, char * raw);
12217 +void parseStatus(pkg_t *pkg, char * raw);
12218 +int parseVersion(pkg_t *pkg, char *raw);
12219 +char ** parseDependsString(char * raw, int * depends_count);
12220 +int parseVersion(pkg_t *pkg, char *raw);
12221 +void parseConffiles(pkg_t * pkg, char * raw);
12222 +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
12223 +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
12227 +++ b/archival/libipkg/pkg_src.c
12229 +/* pkg_src.c - the itsy package management system
12233 + Copyright (C) 2001 University of Southern California
12235 + This program is free software; you can redistribute it and/or
12236 + modify it under the terms of the GNU General Public License as
12237 + published by the Free Software Foundation; either version 2, or (at
12238 + your option) any later version.
12240 + This program is distributed in the hope that it will be useful, but
12241 + WITHOUT ANY WARRANTY; without even the implied warranty of
12242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12243 + General Public License for more details.
12248 +#include "pkg_src.h"
12249 +#include "str_util.h"
12251 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
12253 + src->gzip = gzip;
12254 + src->name = str_dup_safe (name);
12255 + src->value = str_dup_safe (base_url);
12257 + src->extra_data = str_dup_safe (extra_data);
12259 + src->extra_data = NULL;
12263 +void pkg_src_deinit(pkg_src_t *src)
12265 + free (src->name);
12266 + free (src->value);
12267 + if (src->extra_data)
12268 + free (src->extra_data);
12273 +++ b/archival/libipkg/pkg_src.h
12275 +/* pkg_src.h - the itsy package management system
12279 + Copyright (C) 2001 University of Southern California
12281 + This program is free software; you can redistribute it and/or
12282 + modify it under the terms of the GNU General Public License as
12283 + published by the Free Software Foundation; either version 2, or (at
12284 + your option) any later version.
12286 + This program is distributed in the hope that it will be useful, but
12287 + WITHOUT ANY WARRANTY; without even the implied warranty of
12288 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12289 + General Public License for more details.
12295 +#include "nv_pair.h"
12301 + char *extra_data;
12305 +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
12306 +void pkg_src_deinit(pkg_src_t *src);
12310 +++ b/archival/libipkg/pkg_src_list.c
12312 +/* pkg_src_list.c - the itsy package management system
12316 + Copyright (C) 2001 University of Southern California
12318 + This program is free software; you can redistribute it and/or
12319 + modify it under the terms of the GNU General Public License as
12320 + published by the Free Software Foundation; either version 2, or (at
12321 + your option) any later version.
12323 + This program is distributed in the hope that it will be useful, but
12324 + WITHOUT ANY WARRANTY; without even the implied warranty of
12325 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12326 + General Public License for more details.
12331 +#include "pkg_src_list.h"
12332 +#include "void_list.h"
12334 +int pkg_src_list_init(pkg_src_list_t *list)
12336 + return void_list_init((void_list_t *) list);
12339 +void pkg_src_list_deinit(pkg_src_list_t *list)
12341 + pkg_src_list_elt_t *iter;
12342 + pkg_src_t *pkg_src;
12344 + for (iter = list->head; iter; iter = iter->next) {
12345 + pkg_src = iter->data;
12346 + pkg_src_deinit(pkg_src);
12348 + /* malloced in pkg_src_list_append */
12350 + iter->data = NULL;
12352 + void_list_deinit((void_list_t *) list);
12355 +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
12356 + const char *name, const char *base_url, const char *extra_data,
12361 + /* freed in pkg_src_list_deinit */
12362 + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
12364 + if (pkg_src == NULL) {
12365 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12368 + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
12370 + err = void_list_append((void_list_t *) list, pkg_src);
12378 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
12380 + return void_list_push((void_list_t *) list, data);
12383 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
12385 + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
12388 +++ b/archival/libipkg/pkg_src_list.h
12390 +/* pkg_src_list.h - the itsy package management system
12394 + Copyright (C) 2001 University of Southern California
12396 + This program is free software; you can redistribute it and/or
12397 + modify it under the terms of the GNU General Public License as
12398 + published by the Free Software Foundation; either version 2, or (at
12399 + your option) any later version.
12401 + This program is distributed in the hope that it will be useful, but
12402 + WITHOUT ANY WARRANTY; without even the implied warranty of
12403 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12404 + General Public License for more details.
12407 +#ifndef PKG_SRC_LIST_H
12408 +#define PKG_SRC_LIST_H
12410 +#include "pkg_src.h"
12412 +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
12413 +struct pkg_src_list_elt
12415 + pkg_src_list_elt_t *next;
12419 +typedef struct pkg_src_list pkg_src_list_t;
12420 +struct pkg_src_list
12422 + pkg_src_list_elt_t pre_head;
12423 + pkg_src_list_elt_t *head;
12424 + pkg_src_list_elt_t *tail;
12427 +static inline int pkg_src_list_empty(pkg_src_list_t *list)
12429 + if (list->head == NULL)
12435 +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
12436 +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
12438 +int pkg_src_list_init(pkg_src_list_t *list);
12439 +void pkg_src_list_deinit(pkg_src_list_t *list);
12441 +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);
12442 +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
12443 +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
12448 +++ b/archival/libipkg/pkg_vec.c
12450 +/* pkg_vec.c - the itsy package management system
12454 + Copyright (C) 2002 Compaq Computer Corporation
12456 + This program is free software; you can redistribute it and/or
12457 + modify it under the terms of the GNU General Public License as
12458 + published by the Free Software Foundation; either version 2, or (at
12459 + your option) any later version.
12461 + This program is distributed in the hope that it will be useful, but
12462 + WITHOUT ANY WARRANTY; without even the implied warranty of
12463 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12464 + General Public License for more details.
12467 +#include <stdlib.h>
12468 +#include <fnmatch.h>
12469 +#include "xregex.h"
12473 +pkg_vec_t * pkg_vec_alloc(void)
12475 + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
12477 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12480 + vec->pkgs = NULL;
12486 +void pkg_vec_free(pkg_vec_t *vec)
12493 + * assumption: all names in a vector are identical
12494 + * assumption: all version strings are trimmed,
12495 + * so identical versions have identical version strings,
12496 + * implying identical packages; let's marry these
12498 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
12503 + /* look for a duplicate pkg by name, version, and architecture */
12504 + for (i = 0; i < vec->len; i++){
12505 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
12506 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
12507 + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
12508 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12509 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12510 + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
12512 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
12513 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12518 + /* we didn't find one, add it */
12520 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
12521 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12523 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12524 + vec->pkgs[vec->len] = pkg;
12528 + /* update the one that we have */
12530 + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
12531 + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
12532 + if (set_status) {
12533 + /* this is from the status file, so need to merge with existing database */
12534 + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
12535 + pkg_merge(vec->pkgs[i], pkg, set_status);
12536 + /* XXX: CLEANUP: It's not so polite to free something here
12537 + that was passed in from above. */
12541 + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
12542 + /* just overwrite the old one */
12543 + pkg_deinit(vec->pkgs[i]);
12544 + free(vec->pkgs[i]);
12545 + vec->pkgs[i] = pkg;
12547 + return vec->pkgs[i];
12551 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
12556 + /* look for a duplicate pkg by name, version, and architecture */
12557 + for (i = 0; i < vec->len; i++)
12558 + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12559 + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
12560 + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
12565 + /* we didn't find one, add it */
12567 + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
12568 + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
12573 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
12576 + for (i = 0; i < vec->len; i++)
12577 + if (vec->pkgs[i] == apkg)
12582 +typedef int (*compare_fcn_t)(const void *, const void *);
12583 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
12585 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12588 +int pkg_vec_clear_marks(pkg_vec_t *vec)
12590 + int npkgs = vec->len;
12592 + for (i = 0; i < npkgs; i++) {
12593 + pkg_t *pkg = vec->pkgs[i];
12594 + pkg->state_flag &= ~SF_MARKED;
12599 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
12601 + int matching_count = 0;
12602 + pkg_t **pkgs = vec->pkgs;
12603 + int npkgs = vec->len;
12605 + for (i = 0; i < npkgs; i++) {
12606 + pkg_t *pkg = pkgs[i];
12607 + if (fnmatch(pattern, pkg->name, 0)==0) {
12608 + pkg->state_flag |= SF_MARKED;
12609 + matching_count++;
12612 + return matching_count;
12616 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
12618 + abstract_pkg_vec_t * vec ;
12619 + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
12621 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
12624 + vec->pkgs = NULL;
12630 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
12637 + * assumption: all names in a vector are unique
12639 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
12643 + /* look for a duplicate pkg by name */
12644 + for(i = 0; i < vec->len; i++)
12645 + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
12648 + /* we didn't find one, add it */
12649 + if(i == vec->len){
12651 + (abstract_pkg_t **)
12652 + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
12653 + vec->pkgs[vec->len] = pkg;
12658 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
12660 + if (vec->len > i)
12661 + return vec->pkgs[i];
12666 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
12669 + for (i = 0; i < vec->len; i++)
12670 + if (vec->pkgs[i] == apkg)
12675 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
12677 + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
12681 +++ b/archival/libipkg/pkg_vec.h
12683 +/* pkg_vec.h - the itsy package management system
12687 + Copyright (C) 2002 Compaq Computer Corporation
12689 + This program is free software; you can redistribute it and/or
12690 + modify it under the terms of the GNU General Public License as
12691 + published by the Free Software Foundation; either version 2, or (at
12692 + your option) any later version.
12694 + This program is distributed in the hope that it will be useful, but
12695 + WITHOUT ANY WARRANTY; without even the implied warranty of
12696 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12697 + General Public License for more details.
12703 +typedef struct pkg pkg_t;
12704 +typedef struct abstract_pkg abstract_pkg_t;
12711 +typedef struct pkg_vec pkg_vec_t;
12713 +struct abstract_pkg_vec
12715 + abstract_pkg_t **pkgs;
12718 +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
12720 +typedef int (*pkg_compar_t)(pkg_t *, pkg_t *);
12721 +typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *);
12723 +pkg_vec_t * pkg_vec_alloc(void);
12724 +void pkg_vec_free(pkg_vec_t *vec);
12725 +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
12727 +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
12728 +/* pkg_vec_insert_merge: might munge pkg.
12729 +* returns the pkg that is in the pkg graph */
12730 +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
12731 +/* this one never munges pkg */
12732 +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
12733 +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
12734 +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
12736 +int pkg_vec_clear_marks(pkg_vec_t *vec);
12737 +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
12739 +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
12740 +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
12741 +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
12742 +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
12743 +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
12744 +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
12748 +++ b/archival/libipkg/sprintf_alloc.h
12750 +/* sprintf_alloca.c -- like sprintf with memory allocation
12754 + Copyright (C) 2001 University of Southern California
12756 + This program is free software; you can redistribute it and/or modify
12757 + it under the terms of the GNU General Public License as published by
12758 + the Free Software Foundation; either version 2, or (at your option)
12759 + any later version.
12761 + This program is distributed in the hope that it will be useful,
12762 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12763 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12764 + GNU General Public License for more details.
12767 +#ifndef SPRINTF_ALLOC_H
12768 +#define SPRINTF_ALLOC_H
12770 +#include "libbb.h"
12772 +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
12776 +++ b/archival/libipkg/str_list.c
12778 +/* str_list.c - the itsy package management system
12782 + Copyright (C) 2001 University of Southern California
12784 + This program is free software; you can redistribute it and/or
12785 + modify it under the terms of the GNU General Public License as
12786 + published by the Free Software Foundation; either version 2, or (at
12787 + your option) any later version.
12789 + This program is distributed in the hope that it will be useful, but
12790 + WITHOUT ANY WARRANTY; without even the implied warranty of
12791 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12792 + General Public License for more details.
12797 +#include "str_list.h"
12799 +int str_list_elt_init(str_list_elt_t *elt, char *data)
12801 + return void_list_elt_init((void_list_elt_t *) elt, data);
12804 +void str_list_elt_deinit(str_list_elt_t *elt)
12806 + void_list_elt_deinit((void_list_elt_t *) elt);
12809 +str_list_t *str_list_alloc()
12811 + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
12813 + str_list_init(list);
12817 +int str_list_init(str_list_t *list)
12819 + return void_list_init((void_list_t *) list);
12822 +void str_list_deinit(str_list_t *list)
12824 + void_list_deinit((void_list_t *) list);
12827 +int str_list_append(str_list_t *list, char *data)
12829 + return void_list_append((void_list_t *) list, data);
12832 +int str_list_push(str_list_t *list, char *data)
12834 + return void_list_push((void_list_t *) list, data);
12837 +str_list_elt_t *str_list_pop(str_list_t *list)
12839 + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
12842 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
12844 + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
12845 + (void_list_elt_t **) iter);
12848 +char *str_list_remove_elt(str_list_t *list, const char *target_str)
12850 + return (char *)void_list_remove_elt((void_list_t *) list,
12851 + (void *)target_str,
12852 + (void_list_cmp_t)strcmp);
12855 +++ b/archival/libipkg/str_list.h
12857 +/* str_list.h - the itsy package management system
12861 + Copyright (C) 2001 University of Southern California
12863 + This program is free software; you can redistribute it and/or
12864 + modify it under the terms of the GNU General Public License as
12865 + published by the Free Software Foundation; either version 2, or (at
12866 + your option) any later version.
12868 + This program is distributed in the hope that it will be useful, but
12869 + WITHOUT ANY WARRANTY; without even the implied warranty of
12870 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12871 + General Public License for more details.
12874 +#ifndef STR_LIST_H
12875 +#define STR_LIST_H
12877 +#include "void_list.h"
12879 +typedef struct str_list_elt str_list_elt_t;
12880 +struct str_list_elt
12882 + str_list_elt_t *next;
12886 +typedef struct xstr_list str_list_t;
12889 + str_list_elt_t pre_head;
12890 + str_list_elt_t *head;
12891 + str_list_elt_t *tail;
12894 +int str_list_elt_init(str_list_elt_t *elt, char *data);
12895 +void str_list_elt_deinit(str_list_elt_t *elt);
12897 +str_list_t *str_list_alloc(void);
12898 +int str_list_init(str_list_t *list);
12899 +void str_list_deinit(str_list_t *list);
12901 +int str_list_append(str_list_t *list, char *data);
12902 +int str_list_push(str_list_t *list, char *data);
12903 +str_list_elt_t *str_list_pop(str_list_t *list);
12904 +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
12905 +char *str_list_remove_elt(str_list_t *list, const char *target_str);
12909 +++ b/archival/libipkg/str_util.c
12911 +/* str_utils.c - the itsy package management system
12915 + Copyright (C) 2001 University of Southern California
12917 + This program is free software; you can redistribute it and/or
12918 + modify it under the terms of the GNU General Public License as
12919 + published by the Free Software Foundation; either version 2, or (at
12920 + your option) any later version.
12922 + This program is distributed in the hope that it will be useful, but
12923 + WITHOUT ANY WARRANTY; without even the implied warranty of
12924 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12925 + General Public License for more details.
12930 +int str_starts_with(const char *str, const char *prefix)
12932 + return (strncmp(str, prefix, strlen(prefix)) == 0);
12935 +int str_ends_with(const char *str, const char *suffix)
12940 + str_len = strlen(str);
12941 + suffix_len = strlen(suffix);
12943 + if (str_len < suffix_len) {
12947 + return (strcmp(str + str_len - suffix_len, suffix) == 0);
12950 +int str_chomp(char *str)
12952 + if (str[strlen(str) - 1] == '\n') {
12953 + str[strlen(str) - 1] = '\0';
12959 +int str_toupper(char *str)
12962 + *str = toupper(*str);
12969 +char *str_dup_safe(const char *str)
12971 + return str ? strdup(str) : NULL;
12975 +++ b/archival/libipkg/str_util.h
12977 +/* str_utils.h - the itsy package management system
12981 + Copyright (C) 2001 University of Southern California
12983 + This program is free software; you can redistribute it and/or
12984 + modify it under the terms of the GNU General Public License as
12985 + published by the Free Software Foundation; either version 2, or (at
12986 + your option) any later version.
12988 + This program is distributed in the hope that it will be useful, but
12989 + WITHOUT ANY WARRANTY; without even the implied warranty of
12990 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12991 + General Public License for more details.
12994 +#ifndef STR_UTILS_H
12995 +#define STR_UTILS_H
12997 +int str_starts_with(const char *str, const char *prefix);
12998 +int str_ends_with(const char *str, const char *suffix);
12999 +int str_chomp(char *str);
13000 +int str_toupper(char *str);
13001 +char *str_dup_safe(const char *str);
13005 +++ b/archival/libipkg/user.c
13007 +/* user.c - the itsy package management system
13011 + Copyright (C) 2002 Hewlett Packard Company
13012 + Copyright (C) 2001 University of Southern California
13014 + This program is free software; you can redistribute it and/or
13015 + modify it under the terms of the GNU General Public License as
13016 + published by the Free Software Foundation; either version 2, or (at
13017 + your option) any later version.
13019 + This program is distributed in the hope that it will be useful, but
13020 + WITHOUT ANY WARRANTY; without even the implied warranty of
13021 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13022 + General Public License for more details.
13025 +#include <stdio.h>
13026 +#include <stdarg.h>
13027 +#include "file_util.h"
13028 +#include "str_util.h"
13030 +#include "libipkg.h"
13035 +static char *question = NULL;
13036 +static int question_len = 255;
13038 +char *get_user_response(const char *format, ...)
13040 + int len = question_len;
13043 + va_start(ap, format);
13046 + vprintf(format, ap);
13048 + response = file_read_line_alloc(stdin);
13049 + } while (response == NULL);
13052 + if (question == NULL || len > question_len) {
13053 + question = realloc(question, len + 1);
13054 + question_len = len;
13056 + len = vsnprintf(question,question_len,format,ap);
13057 + } while (len > question_len);
13058 + response = strdup(ipkg_cb_response(question));
13060 + str_chomp(response);
13061 + str_tolower(response);
13066 +++ b/archival/libipkg/user.h
13068 +/* user.c - the itsy package management system
13072 + Copyright (C) 2002 Hewlett Packard Company
13073 + Copyright (C) 2001 University of Southern California
13075 + This program is free software; you can redistribute it and/or
13076 + modify it under the terms of the GNU General Public License as
13077 + published by the Free Software Foundation; either version 2, or (at
13078 + your option) any later version.
13080 + This program is distributed in the hope that it will be useful, but
13081 + WITHOUT ANY WARRANTY; without even the implied warranty of
13082 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13083 + General Public License for more details.
13086 +#include <stdio.h>
13087 +#include <stdarg.h>
13089 +char *get_user_response(const char *format, ...);
13092 +++ b/archival/libipkg/void_list.c
13094 +/* void_list.c - the itsy package management system
13098 + Copyright (C) 2001 University of Southern California
13100 + This program is free software; you can redistribute it and/or
13101 + modify it under the terms of the GNU General Public License as
13102 + published by the Free Software Foundation; either version 2, or (at
13103 + your option) any later version.
13105 + This program is distributed in the hope that it will be useful, but
13106 + WITHOUT ANY WARRANTY; without even the implied warranty of
13107 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13108 + General Public License for more details.
13112 +#include <errno.h>
13114 +#include "void_list.h"
13116 +int void_list_elt_init(void_list_elt_t *elt, void *data)
13118 + elt->next = NULL;
13119 + elt->data = data;
13124 +void void_list_elt_deinit(void_list_elt_t *elt)
13126 + void_list_elt_init(elt, NULL);
13129 +int void_list_init(void_list_t *list)
13131 + void_list_elt_init(&list->pre_head, NULL);
13132 + list->head = NULL;
13133 + list->pre_head.next = list->head;
13134 + list->tail = NULL;
13139 +void void_list_deinit(void_list_t *list)
13141 + void_list_elt_t *elt;
13143 + while (list->head) {
13144 + elt = void_list_pop(list);
13145 + void_list_elt_deinit(elt);
13146 + /* malloced in void_list_append */
13151 +int void_list_append(void_list_t *list, void *data)
13153 + void_list_elt_t *elt;
13155 + /* freed in void_list_deinit */
13156 + elt = malloc(sizeof(void_list_elt_t));
13157 + if (elt == NULL) {
13158 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13162 + void_list_elt_init(elt, data);
13164 + if (list->tail) {
13165 + list->tail->next = elt;
13166 + list->tail = elt;
13168 + list->head = elt;
13169 + list->pre_head.next = list->head;
13170 + list->tail = elt;
13176 +int void_list_push(void_list_t *list, void *data)
13178 + void_list_elt_t *elt;
13180 + elt = malloc(sizeof(void_list_elt_t));
13181 + if (elt == NULL) {
13182 + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
13186 + void_list_elt_init(elt, data);
13188 + elt->next = list->head;
13189 + list->head->next = elt;
13190 + if (list->tail == NULL) {
13191 + list->tail = list->head;
13197 +void_list_elt_t *void_list_pop(void_list_t *list)
13199 + void_list_elt_t *elt;
13201 + elt = list->head;
13203 + if (list->head) {
13204 + list->head = list->head->next;
13205 + list->pre_head.next = list->head;
13206 + if (list->head == NULL) {
13207 + list->tail = NULL;
13214 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
13216 + void_list_elt_t *prior;
13217 + void_list_elt_t *old_elt;
13221 + old_data = old_elt->data;
13223 + if (old_elt == list->head) {
13224 + prior = &list->pre_head;
13225 + void_list_pop(list);
13227 + for (prior = list->head; prior; prior = prior->next) {
13228 + if (prior->next == old_elt) {
13232 + if (prior == NULL || prior->next != old_elt) {
13233 + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
13236 + prior->next = old_elt->next;
13238 + if (old_elt == list->tail) {
13239 + list->tail = prior;
13243 + void_list_elt_deinit(old_elt);
13249 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13250 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
13252 + void_list_elt_t *prior;
13253 + void_list_elt_t *old_elt = NULL;
13254 + void *old_data = NULL;
13256 + /* first element */
13257 + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
13258 + old_elt = list->head;
13259 + old_data = list->head->data;
13260 + void_list_pop(list);
13263 + for (prior = list->head; prior && prior->next; prior = prior->next) {
13264 + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
13265 + old_elt = prior->next;
13266 + old_data = old_elt->data;
13274 + prior->next = old_elt->next;
13276 + if (old_elt == list->tail) {
13277 + list->tail = prior;
13281 + void_list_elt_deinit(old_elt);
13289 +++ b/archival/libipkg/void_list.h
13291 +/* void_list.h - the itsy package management system
13295 + Copyright (C) 2001 University of Southern California
13297 + This program is free software; you can redistribute it and/or
13298 + modify it under the terms of the GNU General Public License as
13299 + published by the Free Software Foundation; either version 2, or (at
13300 + your option) any later version.
13302 + This program is distributed in the hope that it will be useful, but
13303 + WITHOUT ANY WARRANTY; without even the implied warranty of
13304 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13305 + General Public License for more details.
13308 +#ifndef VOID_LIST_H
13309 +#define VOID_LIST_H
13311 +typedef struct void_list_elt void_list_elt_t;
13312 +struct void_list_elt
13314 + void_list_elt_t *next;
13318 +typedef struct void_list void_list_t;
13321 + void_list_elt_t pre_head;
13322 + void_list_elt_t *head;
13323 + void_list_elt_t *tail;
13326 +static inline int void_list_empty(void_list_t *list)
13328 + if (list->head == NULL)
13334 +int void_list_elt_init(void_list_elt_t *elt, void *data);
13335 +void void_list_elt_deinit(void_list_elt_t *elt);
13337 +int void_list_init(void_list_t *list);
13338 +void void_list_deinit(void_list_t *list);
13340 +int void_list_append(void_list_t *list, void *data);
13341 +int void_list_push(void_list_t *list, void *data);
13342 +void_list_elt_t *void_list_pop(void_list_t *list);
13344 +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
13345 +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
13346 +typedef int (*void_list_cmp_t)(const void *, const void *);
13347 +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
13351 +++ b/archival/libipkg/xsystem.c
13353 +/* xsystem.c - system(3) with error messages
13357 + Copyright (C) 2001 University of Southern California
13359 + This program is free software; you can redistribute it and/or
13360 + modify it under the terms of the GNU General Public License as
13361 + published by the Free Software Foundation; either version 2, or (at
13362 + your option) any later version.
13364 + This program is distributed in the hope that it will be useful, but
13365 + WITHOUT ANY WARRANTY; without even the implied warranty of
13366 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13367 + General Public License for more details.
13371 +#include <sys/wait.h>
13373 +#include "xsystem.h"
13375 +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
13376 + really need the /bin/sh invocation which takes resources and
13377 + introduces security problems. I should switch all of this to a sort
13378 + of execl() or execv() interface/implementation.
13381 +/* Like system(3), but with error messages printed if the fork fails
13382 + or if the child process dies due to an uncaught signal. Also, the
13383 + return value is a bit simpler:
13385 + -1 if there was any problem
13386 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13387 + as defined in <sys/wait.h>.
13389 +int xsystem(const char *cmd)
13393 + err = system(cmd);
13396 + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
13397 + __FUNCTION__, cmd);
13401 + if (WIFSIGNALED(err)) {
13402 + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
13403 + __FUNCTION__, WTERMSIG(err), cmd);
13407 + if (WIFEXITED(err)) {
13408 + /* Normal child exit */
13409 + return WEXITSTATUS(err);
13412 + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
13413 + __FUNCTION__, err);
13418 +++ b/archival/libipkg/xsystem.h
13420 +/* xsystem.h - system(3) with error messages
13424 + Copyright (C) 2001 University of Southern California
13426 + This program is free software; you can redistribute it and/or
13427 + modify it under the terms of the GNU General Public License as
13428 + published by the Free Software Foundation; either version 2, or (at
13429 + your option) any later version.
13431 + This program is distributed in the hope that it will be useful, but
13432 + WITHOUT ANY WARRANTY; without even the implied warranty of
13433 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13434 + General Public License for more details.
13440 +#include <stdlib.h>
13442 +/* Like system(3), but with error messages printed if the fork fails
13443 + or if the child process dies due to an uncaught signal. Also, the
13444 + return value is a bit simpler:
13446 + -1 if there was any problem
13447 + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
13448 + as defined in <sys/wait.h>.
13450 +int xsystem(const char *cmd);
13454 --- a/archival/libunarchive/data_extract_all.c
13455 +++ b/archival/libunarchive/data_extract_all.c
13456 @@ -144,3 +144,17 @@
13461 +extern void data_extract_all_prefix(archive_handle_t *archive_handle)
13463 + char *name_ptr = archive_handle->file_header->name;
13465 + name_ptr += strspn(name_ptr, "./");
13466 + if (name_ptr[0] != '\0') {
13467 + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
13468 + strcpy(archive_handle->file_header->name, archive_handle->buffer);
13469 + strcat(archive_handle->file_header->name, name_ptr);
13470 + data_extract_all(archive_handle);
13474 --- a/archival/libunarchive/Kbuild
13475 +++ b/archival/libunarchive/Kbuild
13477 lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
13478 lib-$(CONFIG_GUNZIP) += decompress_unzip.o
13479 lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
13480 +lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o
13481 lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
13482 lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
13483 lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
13484 --- a/include/applets.h
13485 +++ b/include/applets.h
13486 @@ -200,6 +200,7 @@
13487 USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
13488 USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13489 USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
13490 +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13491 USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
13492 USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
13493 USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
13494 --- a/include/unarchive.h
13495 +++ b/include/unarchive.h
13498 extern void data_skip(archive_handle_t *archive_handle);
13499 extern void data_extract_all(archive_handle_t *archive_handle);
13500 +extern void data_extract_all_prefix(archive_handle_t *archive_handle);
13501 extern void data_extract_to_stdout(archive_handle_t *archive_handle);
13502 extern void data_extract_to_buffer(archive_handle_t *archive_handle);
13504 --- a/include/usage.h
13505 +++ b/include/usage.h
13506 @@ -1425,6 +1425,82 @@
13507 "$ ls -la /tmp/busybox*\n" \
13508 "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
13510 +#define ipkg_trivial_usage \
13511 + "[options]... sub-command [arguments]..."
13512 +#define ipkg_full_usage \
13513 + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
13515 + "Sub-commands:\n" \
13516 + "\nPackage Manipulation:\n" \
13517 + "\tupdate Update list of available packages\n" \
13518 + "\tupgrade Upgrade all installed packages to latest version\n" \
13519 + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
13520 + "\tinstall <file.ipk> Install package <file.ipk>\n" \
13521 + "\tconfigure [<pkg>] Configure unpacked packages\n" \
13522 + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
13523 + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
13524 + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
13526 + "Informational Commands:\n" \
13527 + "\tlist List available packages and descriptions\n" \
13528 + "\tlist_installed List all and only the installed packages and description \n" \
13529 + "\tfiles <pkg> List all files belonging to <pkg>\n" \
13530 + "\tsearch <file|regexp> Search for a package providing <file>\n" \
13531 + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
13532 + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
13533 + "\tdownload <pkg> Download <pkg> to current directory.\n" \
13534 + "\tcompare_versions <v1> <op> <v2>\n" \
13535 + "\t compare versions using <= < > >= = << >>\n" \
13536 + "\tprint_architecture prints the architecture.\n" \
13537 + "\tprint_installation_architecture\n" \
13538 + "\twhatdepends [-A] [pkgname|pat]+\n" \
13539 + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
13540 + "\twhatprovides [-A] [pkgname|pat]+\n" \
13541 + "\twhatconflicts [-A] [pkgname|pat]+\n" \
13542 + "\twhatreplaces [-A] [pkgname|pat]+\n" \
13543 + "\t prints the installation architecture.\n" \
13546 + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
13547 + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
13548 + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
13549 + "\t 0 errors only\n" \
13550 + "\t 1 normal messages (default)\n" \
13551 + "\t 2 informative messages\n" \
13552 + "\t 3 debug output\n" \
13553 + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
13554 + "\t-conf <conf_file> Default configuration file location\n" \
13555 + " is /etc/ipkg.conf\n" \
13556 + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
13557 + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
13558 + " <dest_name> should be a defined dest name from\n" \
13559 + " the configuration file, (but can also be a\n" \
13560 + " directory name in a pinch).\n" \
13561 + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
13562 + "\t-offline <offline_root> offline installation of packages.\n" \
13563 + "\t-verbose_wget more wget messages\n" \
13565 + "Force Options (use when ipkg is too smart for its own good):\n" \
13566 + "\t-force-depends Make dependency checks warnings instead of errors\n" \
13567 + "\t Install/remove package in spite of failed dependences\n" \
13568 + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
13569 + " (no prompts). Note that this will not prevent\n" \
13570 + " package installation scripts from prompting.\n" \
13571 + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
13572 + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
13573 + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
13574 + "\t-force_space Install even if there does not seem to be enough space.\n" \
13575 + "\t-noaction No action -- test only\n" \
13576 + "\t-nodeps Do not follow dependences\n" \
13577 + "\t-force-removal-of-dependent-packages\n" \
13578 + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
13579 + "\t-test No action -- test only\n" \
13580 + "\t-t Specify tmp-dir.\n" \
13581 + "\t--tmp-dir Specify tmp-dir.\n" \
13583 + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
13584 + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
13586 #define halt_trivial_usage \
13587 "[-d delay] [-n] [-f]"
13588 #define halt_full_usage "\n\n" \
13591 @@ -444,6 +444,7 @@
13595 + archival/libipkg/ \
13596 archival/libunarchive/ \