forked from NetBSDfr/pkgin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgin.h
291 lines (262 loc) · 8.14 KB
/
pkgin.h
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* $Id: pkgin.h,v 1.41 2012/11/17 14:04:13 imilh Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emile "iMil" Heitor <imil@NetBSD.org> .
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef _PKGIN_H
#define _PKGIN_H
#if HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#endif
#include <fetch.h>
#include <errno.h>
#include "messages.h"
#include "pkgindb.h"
#include "tools.h"
#include "lib.h"
#include "dewey.h"
#ifndef PKGTOOLS
#define PKGTOOLS "/usr/sbin"
#endif
#define PKG_DELETE PKGTOOLS"/pkg_delete"
#define PKG_ADD PKGTOOLS"/pkg_add"
#define PKG_INFO PKGTOOLS"/pkg_info"
#define PKG_SUMMARY "pkg_summary"
#define PKGIN_SQL_LOG PKGIN_DB"/sql.log"
#define PKG_INSTALL_ERR_LOG PKGIN_DB"/pkg_install-err.log"
#define PKGIN_CACHE PKGIN_DB"/cache"
#define PKG_EXT ".tgz"
#define PKGIN_CONF PKG_SYSCONFDIR"/pkgin"
#define REPOS_FILE "repositories.conf"
#define PKG_INSTALL "pkg_install"
#define PREFERRED_PKGS "preferred.conf"
#define LOCAL_SUMMARY 0
#define REMOTE_SUMMARY 1
#define DONOTHING -1
#define TOINSTALL 0
#define TOUPGRADE 1
#define TOREMOVE 2
#define UNMET_REQ 3
#define KEEP 1
#define UNKEEP 0
#define UPGRADE_KEEP 0
#define UPGRADE_ALL 1
#define UPGRADE_NONE -1
#define DO_INST 1
#define DONT_INST 0
#define ALNUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#define DELIMITER '|'
#define ICON_WAIT "-\\|/"
#define PKG_LLIST_CMD 0
#define PKG_RLIST_CMD 1
#define PKG_INST_CMD 2
#define PKG_UPDT_CMD 3
#define PKG_REMV_CMD 4
#define PKG_UPGRD_CMD 5
#define PKG_FUPGRD_CMD 6
#define PKG_SHFDP_CMD 7
#define PKG_SHRDP_CMD 8
#define PKG_SHDDP_CMD 9
#define PKG_KEEP_CMD 10
#define PKG_UNKEEP_CMD 11
#define PKG_SHKP_CMD 12
#define PKG_SHNOKP_CMD 13
#define PKG_SRCH_CMD 14
#define PKG_CLEAN_CMD 15
#define PKG_AUTORM_CMD 16
#define PKG_EXPORT_CMD 17
#define PKG_IMPORT_CMD 18
#define PKG_SHPROV_CMD 19
#define PKG_SHREQ_CMD 20
#define PKG_SHPKGCONT_CMD 21
#define PKG_SHPKGDESC_CMD 22
#define PKG_SHPKGBDEFS_CMD 23
#define PKG_SHCAT_CMD 24
#define PKG_SHPCAT_CMD 25
#define PKG_SHALLCAT_CMD 26
#define PKG_GINTO_CMD 255
#define PKG_EQUAL '='
#define PKG_GREATER '>'
#define PKG_LESSER '<'
#define DEFAULT_NO 0
#define DEFAULT_YES 1
#define TRACE(fmt...) if (tracefp != NULL) fprintf(tracefp, fmt)
typedef struct Dlfile {
char *buf;
size_t size;
} Dlfile;
/**
* \struct Deptree
* \brief Package dependency tree
*/
typedef struct Deptree {
int computed; /*!< recursion memory */
int keep; /*!< autoremovable package ? */
} Deptree;
/**
* \struct Impact
* \brief Impact list
*/
typedef struct Pkgimpact {
int action; /*!< TOINSTALL or TOUPGRADE */
char *old; /*!< package to upgrade: perl-5.8 */
} Impact;
/**
* \struct Pkglist
*
* \brief Master structure for all types of package lists (SLIST)
*/
typedef struct Pkglist {
uint8_t type; /*!< list type (LIST, DEPTREE or IMPACT) */
int64_t size_pkg; /*!< installed package size (list and impact) */
int64_t old_size_pkg; /*!< old installed package size */
int64_t file_size; /*!< binary package size */
int level; /*<! recursion level (deptree and impact) */
char *full; /*!< full package name with version, foo-1.0 */
char *name; /*!< package name, foo */
char *version; /*<! package version, 1.0 */
char *depend; /*!< dewey or glob form for forward (direct)
* dependencies:
* foo>=1.0
* or full package name for reverse dependencies:
* foo-1.0
*/
char *category; /*!< package category */
char *pkgpath; /*!< pkgsrc pkgpath */
union {
char *comment; /*!< package list comment */
Deptree deptree; /*<! dependency tree informations */
Impact impact; /*<! impact list informations */
} p_un;
SLIST_ENTRY(Pkglist) next;
} Pkglist;
#define comment p_un.comment
#define computed p_un.deptree.computed
#define keep p_un.deptree.keep
#define old p_un.impact.old
#define action p_un.impact.action
#define LIST 0
#define DEPTREE 1
#define IMPACT 2
typedef SLIST_HEAD(, Pkglist) Plisthead;
typedef struct Plistnumbered {
Plisthead *P_Plisthead;
int P_count;
} Plistnumbered;
extern uint8_t force_update;
extern uint8_t force_reinstall;
extern uint8_t verbosity;
extern uint8_t package_version;
extern uint8_t pi_upgrade; /* pkg_install upgrade */
extern int r_plistcounter;
extern int l_plistcounter;
extern char *env_repos;
extern char **pkg_repos;
extern const char *pkgin_cache;
extern char lslimit;
extern char pkgtools_flags[];
extern char pkg_dbdir[];
extern Plisthead r_plisthead;
extern Plisthead l_plisthead;
extern FILE *tracefp;
/* download.c*/
Dlfile *download_file(char *, time_t *);
/* summary.c */
int update_db(int, char **);
void split_repos(void);
/* sqlite_callbacks.c */
int pdb_rec_list(void *, int, char **, char **);
int pdb_rec_depends(void *, int, char **, char **);
/* depends.c */
int show_direct_depends(const char *);
int show_full_dep_tree(const char *, const char *, const char *);
void full_dep_tree(const char *, const char *, Plisthead *);
/* pkglist.c */
void init_global_pkglists(void);
void free_global_pkglists(void);
Pkglist *malloc_pkglist(uint8_t);
void free_pkglist_entry(Pkglist **, uint8_t);
void free_pkglist(Plisthead **, uint8_t);
Plisthead *init_head(void);
Plistnumbered *rec_pkglist(const char *, ...);
int pkg_is_installed(Plisthead *, Pkglist *);
void list_pkgs(const char *, int);
int search_pkg(const char *);
void show_category(char *);
void show_pkg_category(char *);
void show_all_categories(void);
/* actions.c */
void do_pkg_remove(Plisthead *);
int pkgin_remove(char **);
int pkgin_install(char **, uint8_t);
char *action_list(char *, char *);
int pkgin_upgrade(int);
char *read_preferred(char *);
/* order.c */
Plisthead *order_remove(Plisthead *);
Plisthead *order_upgrade_remove(Plisthead *);
Plisthead *order_install(Plisthead *);
/* impact.c */
uint8_t pkg_in_impact(Plisthead *, char *);
Plisthead *pkg_impact(char **, int *);
/* autoremove.c */
void pkgin_autoremove(void);
void show_pkg_keep(void);
void show_pkg_nokeep(void);
int pkg_is_kept(Pkglist *);
void pkg_keep(int, char **);
/* fsops.c */
int fs_has_room(const char *, int64_t);
uint64_t fs_room(const char *);
void clean_cache(void);
void create_dirs(void);
char *read_repos(void);
/* pkg_str.c */
char *unique_pkg(const char *, const char *);
Pkglist *map_pkg_to_dep(Plisthead *, char *);
uint8_t non_trivial_glob(char *);
char *get_pkgname_from_depend(char *);
int exact_pkgfmt(const char *);
char *find_exact_pkg(Plisthead *, const char *);
int version_check(char *, char *);
char **glob_to_pkgarg(char **, int *);
/* selection.c */
void export_keep(void);
void import_keep(uint8_t, const char *);
/* pkg_check.c */
int pkg_met_reqs(Plisthead *);
int pkg_has_conflicts(Pkglist *);
void show_prov_req(const char *, const char *);
/* pkg_infos.c */
void show_pkg_info(char, char *);
/* pkgindb.c */
void get_pkg_dbdir(void);
#endif