44#include "xbps_api_impl.h"
55store_virtualpkg(
struct xbps_handle *xhp,
const char *path,
size_t line,
char *val)
63 if (p == NULL || p[1] ==
'\0') {
64 xbps_dbg_printf(
"%s: ignoring invalid "
65 "virtualpkg option at line %zu\n", path, line);
70 if (!xbps_dictionary_set_cstring(xhp->vpkgd, val, p))
72 if (!xbps_dictionary_set_cstring(xhp->vpkgd_conf, val, p))
74 xbps_dbg_printf(
"%s: added virtualpkg %s for %s\n", path, val, p);
79store_preserved_file(
struct xbps_handle *xhp,
const char *file)
82 char *p = NULL, *rfile = NULL;
86 if (xhp->preserved_files == NULL) {
87 xhp->preserved_files = xbps_array_create();
88 assert(xhp->preserved_files);
93 rv = glob(rfile, 0, NULL, &globbuf);
94 if (rv == GLOB_NOMATCH) {
97 xbps_array_add_cstring(xhp->preserved_files, file);
98 xbps_dbg_printf(
"Added preserved file: %s\n", file);
100 }
else if (rv != 0) {
103 for (
size_t i = 0; i < globbuf.gl_pathc; i++) {
107 len = strlen(globbuf.gl_pathv[i]) - strlen(xhp->
rootdir) + 1;
111 xbps_array_add_cstring(xhp->preserved_files, p);
112 xbps_dbg_printf(
"Added preserved file: %s (expanded from %s)\n", p, file);
121store_repo(
struct xbps_handle *xhp,
const char *repo)
123 if (xhp->
flags & XBPS_FLAG_IGNORE_CONF_REPOS)
130store_ignored_pkg(
struct xbps_handle *xhp,
const char *pkgname)
132 if (xhp->ignored_pkgs == NULL) {
133 xhp->ignored_pkgs = xbps_array_create();
134 assert(xhp->ignored_pkgs);
136 xbps_array_add_cstring(xhp->ignored_pkgs, pkgname);
137 xbps_dbg_printf(
"Added ignored package: %s\n", pkgname);
141store_noextract(
struct xbps_handle *xhp,
const char *value)
145 if (xhp->noextract == NULL) {
146 xhp->noextract = xbps_array_create();
147 assert(xhp->noextract);
149 xbps_array_add_cstring(xhp->noextract, value);
150 xbps_dbg_printf(
"Added noextract pattern: %s\n", value);
169static const struct key {
174 {
"architecture", 12, KEY_ARCHITECTURE },
175 {
"bestmatching", 12, KEY_BESTMATCHING },
176 {
"cachedir", 8, KEY_CACHEDIR },
177 {
"ignorepkg", 9, KEY_IGNOREPKG },
178 {
"include", 7, KEY_INCLUDE },
179 {
"keepconf", 8, KEY_KEEPCONF },
180 {
"noextract", 9, KEY_NOEXTRACT },
181 {
"preserve", 8, KEY_PRESERVE },
182 {
"repository", 10, KEY_REPOSITORY },
183 {
"rootdir", 7, KEY_ROOTDIR },
184 {
"syslog", 6, KEY_SYSLOG },
185 {
"virtualpkg", 10, KEY_VIRTUALPKG },
189cmpkey(
const void *a,
const void *b)
191 const struct key *ka = a;
192 const struct key *kb = b;
193 return strncmp(ka->str, kb->str, ka->len);
197parse_option(
char *line,
size_t linelen,
char **valp,
size_t *vallen)
201 struct key needle, *result;
203 p = strpbrk(line,
" \t=");
209 while (*p && isblank((
unsigned char)*p))
214 result = bsearch(&needle, keys, __arraycount(keys),
sizeof(
struct key), cmpkey);
219 while (isblank((
unsigned char)*p))
222 len = linelen-(p-line);
226 while (len > 0 && isblank((
unsigned char)p[len-1]))
236static int parse_file(
struct xbps_handle *,
const char *,
bool);
239parse_files_glob(
struct xbps_handle *xhp, xbps_dictionary_t seen,
240 const char *cwd,
const char *pat,
bool nested)
242 char tmppath[PATH_MAX];
246 rs = snprintf(tmppath, PATH_MAX,
"%s/%s",
247 pat[0] ==
'/' ? xhp->
rootdir : cwd, pat);
248 if (rs < 0 || rs >= PATH_MAX)
251 switch (glob(tmppath, 0, NULL, &globbuf)) {
253 case GLOB_NOSPACE:
return ENOMEM;
254 case GLOB_NOMATCH:
return 0;
257 for (
size_t i = 0; i < globbuf.gl_pathc; i++) {
261 fname = basename(globbuf.gl_pathv[i]);
262 if (xbps_dictionary_get_bool(seen, fname, &mask) && mask)
264 xbps_dictionary_set_bool(seen, fname,
true);
266 if ((rv2 = parse_file(xhp, globbuf.gl_pathv[i], nested)) != 0)
275parse_file(
struct xbps_handle *xhp,
const char *path,
bool nested)
278 size_t len, nlines = 0;
285 if ((fp = fopen(path,
"r")) == NULL) {
287 xbps_error_printf(
"cannot read configuration file %s: %s\n", path, strerror(rv));
291 xbps_dbg_printf(
"Parsing configuration file: %s\n", path);
293 while ((rd = getline(&line, &len, fp)) != -1) {
297 if (line[rd-1] ==
'\n') {
305 while (isblank((
unsigned char)*line))
308 if (line[0] ==
'#' || line[0] ==
'\0')
311 switch (parse_option(line, rd, &val, &vallen)) {
313 xbps_dbg_printf(
"%s: ignoring invalid option at "
314 "line %zu\n", path, nlines);
318 rs = snprintf(xhp->
rootdir, size,
"%s", val);
319 if (rs < 0 || rs >= size) {
323 xbps_dbg_printf(
"%s: rootdir set to %s\n", path, val);
327 rs = snprintf(xhp->
cachedir, size,
"%s", val);
328 if (rs < 0 || rs >= size) {
332 xbps_dbg_printf(
"%s: cachedir set to %s\n", path, val);
334 case KEY_ARCHITECTURE:
337 if (rs < 0 || rs >= size) {
341 xbps_dbg_printf(
"%s: native architecture set to %s\n", path,
345 if (strcasecmp(val,
"true") == 0) {
346 xhp->
flags &= ~XBPS_FLAG_DISABLE_SYSLOG;
347 xbps_dbg_printf(
"%s: syslog enabled\n", path);
349 xhp->
flags |= XBPS_FLAG_DISABLE_SYSLOG;
350 xbps_dbg_printf(
"%s: syslog disabled\n", path);
354 if (store_repo(xhp, val))
355 xbps_dbg_printf(
"%s: added repository %s\n", path, val);
358 rv = store_virtualpkg(xhp, path, nlines, val);
366 store_preserved_file(xhp, val);
369 if (strcasecmp(val,
"true") == 0) {
370 xhp->
flags |= XBPS_FLAG_KEEP_CONFIG;
371 xbps_dbg_printf(
"%s: config preservation enabled\n", path);
373 xhp->
flags &= ~XBPS_FLAG_KEEP_CONFIG;
374 xbps_dbg_printf(
"%s: config preservation disabled\n", path);
377 case KEY_BESTMATCHING:
378 if (strcasecmp(val,
"true") == 0) {
379 xhp->
flags |= XBPS_FLAG_BESTMATCH;
380 xbps_dbg_printf(
"%s: pkg best matching enabled\n", path);
382 xhp->
flags &= ~XBPS_FLAG_BESTMATCH;
383 xbps_dbg_printf(
"%s: pkg best matching disabled\n", path);
387 store_ignored_pkg(xhp, val);
390 store_noextract(xhp, val);
395 xbps_dbg_printf(
"%s: ignoring nested include\n", path);
399 rv = parse_files_glob(xhp, NULL, dirname(dir), val,
true);
413 xbps_dictionary_t seen;
417 seen = xbps_dictionary_create();
421 xbps_dbg_printf(
"Processing configuration directory: %s\n", xhp->
confdir);
422 if ((rv = parse_files_glob(xhp, seen, xhp->
confdir,
"*.conf",
false)))
425 if (*xhp->sysconfdir) {
426 xbps_dbg_printf(
"Processing system configuration directory: %s\n", xhp->sysconfdir);
427 if ((rv = parse_files_glob(xhp, seen, xhp->sysconfdir,
"*.conf",
false)))
432 xbps_object_release(seen);
char rootdir[XBPS_MAXPATH]
char confdir[XBPS_MAXPATH+sizeof(XBPS_SYSCONF_PATH)]
char cachedir[XBPS_MAXPATH+sizeof(XBPS_CACHE_PATH)]
Generic XBPS structure handler for initialization.
bool xbps_match_string_in_array(xbps_array_t array, const char *val)
bool xbps_repo_store(struct xbps_handle *xhp, const char *url)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
size_t xbps_strlcpy(char *dst, const char *src, size_t dstsize)