1 /* pkg.h - the opkg package management system
5 Copyright (C) 2001 University of Southern California
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
23 #include <sys/types.h>
27 #include "active_list.h"
30 #include "opkg_conf.h"
31 #include "conffile_list.h"
36 #define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
38 /* I think "Size" is currently the shortest field name */
39 #define PKG_MINIMUM_FIELD_NAME_LEN 4
49 typedef enum pkg_state_want pkg_state_want_t
;
55 SF_HOLD
= 2, /* do not upgrade version */
56 SF_REPLACE
= 4, /* replace this package */
57 SF_NOPRUNE
= 8, /* do not remove obsolete files */
58 SF_PREFER
= 16, /* prefer this version */
59 SF_OBSOLETE
= 32, /* old package in upgrade pair */
60 SF_MARKED
= 64, /* temporary mark */
61 SF_FILELIST_CHANGED
= 128, /* needs filelist written */
65 typedef enum pkg_state_flag pkg_state_flag_t
;
66 #define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
80 typedef enum pkg_state_status pkg_state_status_t
;
84 int dependencies_checked
;
86 pkg_state_status_t state_status
;
87 pkg_state_flag_t state_flag
;
89 /* XXX: This should be abstract_pkg_vec_t for consistency. */
90 struct abstract_pkg
** depended_upon_by
;
92 abstract_pkg_vec_t
* provided_by
;
93 abstract_pkg_vec_t
* replaced_by
;
96 #include "pkg_depends.h"
98 /* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
100 The 3 version fields should go into a single version struct. (This
101 is especially important since, currently, pkg->version can easily
102 be mistaken for pkg_verson_str_alloc(pkg) although they are very
103 distinct. This has been the source of multiple bugs.
105 The 3 state fields could possibly also go into their own struct.
107 All fields which deal with lists of packages, (Depends,
108 Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
109 be handled by a single struct in pkg_t
111 All string fields for which there is a small set of possible
112 values, (section, maintainer, architecture, maybe version?), that
113 are reused among different packages -- for all such packages we
114 should move from "char *"s to some atom datatype to share data
115 storage and use less memory. We might even do reference counting,
116 but probably not since most often we only create new pkg_t structs,
117 we don't often free them. */
131 pkg_state_want_t state_want
;
132 pkg_state_flag_t state_flag
;
133 pkg_state_status_t state_status
;
135 unsigned int depends_count
;
136 char **pre_depends_str
;
137 unsigned int pre_depends_count
;
138 char **recommends_str
;
139 unsigned int recommends_count
;
141 unsigned int suggests_count
;
142 struct active_list list
; /* Used for installing|upgrading */
143 compound_depend_t
* depends
;
145 char **conflicts_str
;
146 compound_depend_t
* conflicts
;
147 unsigned int conflicts_count
;
150 unsigned int replaces_count
;
151 abstract_pkg_t
** replaces
;
154 unsigned int provides_count
;
155 abstract_pkg_t
** provides
;
157 abstract_pkg_t
*parent
;
160 char *local_filename
;
161 char *tmp_unpack_dir
;
163 #if defined HAVE_SHA256
166 unsigned long size
; /* in bytes */
167 unsigned long installed_size
; /* in bytes */
170 conffile_list_t conffiles
;
171 time_t installed_time
;
172 /* As pointer for lazy evaluation */
173 str_list_t
*installed_files
;
174 /* XXX: CLEANUP: I'd like to perhaps come up with a better
175 mechanism to avoid the problem here, (which is that the
176 installed_files list was being freed from an inner loop while
177 still being used within an outer loop. */
178 int installed_files_ref_cnt
;
181 /* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */
182 int provided_by_hand
;
184 /* this flag specifies whether the package was installed to satisfy another
185 * package's dependancies */
189 pkg_t
*pkg_new(void);
190 void pkg_deinit(pkg_t
*pkg
);
191 int pkg_init_from_file(pkg_t
*pkg
, const char *filename
);
192 abstract_pkg_t
*abstract_pkg_new(void);
195 * merges fields from newpkg into oldpkg.
196 * Forcibly sets oldpkg state_status, state_want and state_flags
198 int pkg_merge(pkg_t
*oldpkg
, pkg_t
*newpkg
);
200 char *pkg_version_str_alloc(pkg_t
*pkg
);
202 int pkg_compare_versions(const pkg_t
*pkg
, const pkg_t
*ref_pkg
);
203 int pkg_name_version_and_architecture_compare(const void *a
, const void *b
);
204 int abstract_pkg_name_compare(const void *a
, const void *b
);
206 void pkg_formatted_info(FILE *fp
, pkg_t
*pkg
);
207 void pkg_formatted_field(FILE *fp
, pkg_t
*pkg
, const char *field
);
209 void set_flags_from_control(pkg_t
*pkg
);
211 void pkg_print_status(pkg_t
* pkg
, FILE * file
);
212 str_list_t
*pkg_get_installed_files(pkg_t
*pkg
);
213 void pkg_free_installed_files(pkg_t
*pkg
);
214 void pkg_remove_installed_files_list(pkg_t
*pkg
);
215 conffile_t
*pkg_get_conffile(pkg_t
*pkg
, const char *file_name
);
216 int pkg_run_script(pkg_t
*pkg
, const char *script
, const char *args
);
219 pkg_state_want_t
pkg_state_want_from_str(char *str
);
220 pkg_state_flag_t
pkg_state_flag_from_str(const char *str
);
221 pkg_state_status_t
pkg_state_status_from_str(const char *str
);
223 int pkg_version_satisfied(pkg_t
*it
, pkg_t
*ref
, const char *op
);
225 int pkg_arch_supported(pkg_t
*pkg
);
226 void pkg_info_preinstall_check(void);
228 int pkg_write_filelist(pkg_t
*pkg
);
229 int pkg_write_changed_filelists(void);