1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/* pkg.h - the opkg package management system
Carl D. Worth
Copyright (C) 2001 University of Southern California
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/
#ifndef PKG_H
#define PKG_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "pkg_vec.h"
#include "str_list.h"
#include "active_list.h"
#include "pkg_src.h"
#include "pkg_dest.h"
#include "opkg_conf.h"
#include "conffile_list.h"
struct opkg_conf;
#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
/* I think "Size" is currently the shortest field name */
#define PKG_MINIMUM_FIELD_NAME_LEN 4
enum pkg_state_want
{
SW_UNKNOWN = 1,
SW_INSTALL,
SW_DEINSTALL,
SW_PURGE,
SW_LAST_STATE_WANT
};
typedef enum pkg_state_want pkg_state_want_t;
enum pkg_state_flag
{
SF_OK = 0,
SF_REINSTREQ = 1,
SF_HOLD = 2, /* do not upgrade version */
SF_REPLACE = 4, /* replace this package */
SF_NOPRUNE = 8, /* do not remove obsolete files */
SF_PREFER = 16, /* prefer this version */
SF_OBSOLETE = 32, /* old package in upgrade pair */
SF_MARKED = 64, /* temporary mark */
SF_FILELIST_CHANGED = 128, /* needs filelist written */
SF_USER = 256,
SF_LAST_STATE_FLAG
};
typedef enum pkg_state_flag pkg_state_flag_t;
#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
enum pkg_state_status
{
SS_NOT_INSTALLED = 1,
SS_UNPACKED,
SS_HALF_CONFIGURED,
SS_INSTALLED,
SS_HALF_INSTALLED,
SS_CONFIG_FILES,
SS_POST_INST_FAILED,
SS_REMOVAL_FAILED,
SS_LAST_STATE_STATUS
};
typedef enum pkg_state_status pkg_state_status_t;
struct abstract_pkg{
char * name;
int dependencies_checked;
pkg_vec_t * pkgs;
pkg_state_status_t state_status;
pkg_state_flag_t state_flag;
struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
abstract_pkg_vec_t * provided_by;
abstract_pkg_vec_t * replaced_by;
};
#include "pkg_depends.h"
/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
The 3 version fields should go into a single version struct. (This
is especially important since, currently, pkg->version can easily
be mistaken for pkg_verson_str_alloc(pkg) although they are very
distinct. This has been the source of multiple bugs.
The 3 state fields could possibly also go into their own struct.
All fields which deal with lists of packages, (Depends,
Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
be handled by a single struct in pkg_t
All string fields for which there is a small set of possible
values, (section, maintainer, architecture, maybe version?), that
are reused among different packages -- for all such packages we
should move from "char *"s to some atom datatype to share data
storage and use less memory. We might even do reference counting,
but probably not since most often we only create new pkg_t structs,
we don't often free them. */
struct pkg
{
char *name;
unsigned long epoch;
char *version;
char *revision;
pkg_src_t *src;
pkg_dest_t *dest;
char *architecture;
char *section;
char *maintainer;
char *description;
char *tags;
pkg_state_want_t state_want;
pkg_state_flag_t state_flag;
pkg_state_status_t state_status;
char **depends_str;
int depends_count;
char **pre_depends_str;
int pre_depends_count;
char **recommends_str;
int recommends_count;
char **suggests_str;
int suggests_count;
struct active_list list; /* Used for installing|upgrading */
compound_depend_t * depends;
/* Abhaya: new conflicts */
char **conflicts_str;
compound_depend_t * conflicts;
int conflicts_count;
char **replaces_str;
int replaces_count;
abstract_pkg_t ** replaces;
char **provides_str;
int provides_count;
abstract_pkg_t ** provides;
abstract_pkg_t *parent;
pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
char *filename;
char *local_filename;
char *url;
char *tmp_unpack_dir;
char *md5sum;
#if defined HAVE_SHA256
char *sha256sum;
#endif
char *size;
char *installed_size;
char *priority;
char *source;
conffile_list_t conffiles;
time_t installed_time;
/* As pointer for lazy evaluation */
str_list_t *installed_files;
/* XXX: CLEANUP: I'd like to perhaps come up with a better
mechanism to avoid the problem here, (which is that the
installed_files list was being freed from an inner loop while
still being used within an outer loop. */
int installed_files_ref_cnt;
int essential;
int arch_priority;
/* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */
int provided_by_hand;
/* this flag specifies whether the package was installed to satisfy another
* package's dependancies */
int auto_installed;
};
pkg_t *pkg_new(void);
int pkg_init(pkg_t *pkg);
void pkg_deinit(pkg_t *pkg);
int pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename);
abstract_pkg_t *abstract_pkg_new(void);
int abstract_pkg_init(abstract_pkg_t *ab_pkg);
/*
* merges fields from newpkg into oldpkg.
* Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
*/
int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
char *pkg_version_str_alloc(pkg_t *pkg);
int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
int pkg_name_version_and_architecture_compare(const void *a, const void *b);
int abstract_pkg_name_compare(const void *a, const void *b);
void pkg_formatted_info(FILE *fp, pkg_t *pkg);
void pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field);
void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg);
void pkg_print_status(pkg_t * pkg, FILE * file);
str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg);
int pkg_free_installed_files(pkg_t *pkg);
int pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg);
conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
int pkg_run_script(struct opkg_conf *conf, pkg_t *pkg,
const char *script, const char *args);
/* enum mappings */
char *pkg_state_want_to_str(pkg_state_want_t sw);
pkg_state_want_t pkg_state_want_from_str(char *str);
char *pkg_state_flag_to_str(pkg_state_flag_t sf);
pkg_state_flag_t pkg_state_flag_from_str(const char *str);
char *pkg_state_status_to_str(pkg_state_status_t ss);
pkg_state_status_t pkg_state_status_from_str(const char *str);
int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg);
int pkg_info_preinstall_check(opkg_conf_t *conf);
int pkg_free_installed_files(pkg_t *pkg);
int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg);
int pkg_write_changed_filelists(opkg_conf_t *conf);
#endif
|