29#include <sys/utsname.h>
43#include "xbps_api_impl.h"
46#pragma clang diagnostic ignored "-Wformat-nonliteral"
50is_revision(
const char *str)
52 if (str == NULL || *str ==
'\0')
55 while (isdigit((
unsigned char)*str) || *str ==
'_')
70 if ((strncmp(uri,
"http://", 7) == 0) ||
71 (strncmp(uri,
"https://", 8) == 0) ||
72 (strncmp(uri,
"ftp://", 6) == 0))
81 xbps_dictionary_t dict;
96 if (state == XBPS_PKG_STATE_INSTALLED || state == XBPS_PKG_STATE_UNPACKED)
105 char pkgname[XBPS_NAME_SIZE];
111 if (!xhp->ignored_pkgs)
131 if ((p = strrchr(pkg,
'-')) == NULL)
136 for (
unsigned int i = 0; i < p_len; i++) {
139 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
140 if (!is_revision(r + 1)) {
159 if ((fname = strrchr(pkg,
'/')))
165 if ((len = strlen(fname)) < 5)
171 (void)memcpy(p, fname, len);
173 if (!(p1 = strrchr(p,
'.'))) {
177 p[strlen(p)-strlen(p1)] =
'\0';
201 if ((fname = strrchr(pkg,
'/')))
207 if ((len = strlen(fname)) < 5)
213 (void)memcpy(p, fname, len);
215 if (!(p1 = strrchr(p,
'.'))) {
219 res = strdup(p1 + 1);
234 if ((p = strrchr(pkg,
'-')) == NULL)
239 for (
unsigned int i = 0; i < p_len; i++) {
242 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
243 if (!is_revision(r + 1)) {
246 return strrchr(r,
'_') + 1;
262 if ((p = strrchr(pkg,
'-')) == NULL)
267 for (
unsigned int i = 1; i < plen; i++) {
270 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
271 valid = is_revision(r + 1);
278 plen = strlen(pkg) - strlen(p) + 1;
282 memcpy(dst, pkg, plen-1);
297 if ((res = strpbrk(pkg,
"><*?[]")) == NULL)
300 plen = strlen(pkg) - strlen(res) + 1;
301 if (strlen(pkg) < plen-2)
304 if (pkg[plen-2] ==
'-')
310 memcpy(dst, pkg, plen-1);
321 return strpbrk(pkg,
"><*?[]");
327 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
330 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
331 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
332 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
338 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
339 if (l < 0 || (
size_t)l >= dstsz)
348 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
351 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
352 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
353 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
356 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
357 if (l < 0 || (
size_t)l >= dstsz)
366 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
369 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
370 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
371 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
375 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", xhp->cachedir,
377 if (l < 0 || (
size_t)l >= dstsz)
379 if (access(dst, R_OK) == 0)
385 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
386 if (l < 0 || (
size_t)l >= dstsz)
395 const char *pkgver, *arch, *repoloc;
396 char *lbinpkg = NULL;
399 assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
401 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
404 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
405 "architecture", &arch))
407 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
408 "repository", &repoloc))
417 if (access(lbinpkg, R_OK) == 0)
432 const char *pkgver, *arch, *repoloc;
435 assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY);
437 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
440 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
441 "architecture", &arch))
443 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
444 "repository", &repoloc))
447 snprintf(path,
sizeof(path),
"%s/%s.%s.xbps",
451 return access(path, R_OK) == 0;
458 const char *pkgver, *arch;
461 assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY);
463 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
466 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
467 "architecture", &arch))
470 snprintf(path,
sizeof(path),
"%s/%s.%s.xbps.sig2", xhp->
cachedir,
474 if (access(path, R_OK) != 0)
478 path[strlen(path)-
sizeof (
".sig2")+1] =
'\0';
480 return access(path, R_OK) == 0;
497 if (target == NULL) {
498 if ((strcmp(orig,
"noarch") == 0) ||
499 (strcmp(orig, arch) == 0))
502 if ((strcmp(orig,
"noarch") == 0) ||
503 (strcmp(orig, target) == 0))
516 if (vasprintf(&buf, fmt, ap) == -1) {
536 if (strcmp(pattern, pkg) == 0)
540 if (strpbrk(pattern,
"<>") != NULL)
541 return dewey_match(pattern, pkg);
544 if (strpbrk(pattern,
"*?[]") != NULL)
545 if (fnmatch(pattern, pkg, FNM_PERIOD) == 0)
561 return humanize_number(buf, 7, bytes,
"B",
562 HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE);
571 return strlcat(dest, src, siz);
580 return strlcpy(dest, src, siz);
590 xbps_array_t reverts;
592 const char *revertver = NULL;
597 if ((reverts = xbps_dictionary_get(pkg,
"reverts")) == NULL)
600 for (i = 0; i < xbps_array_count(reverts); i++) {
601 xbps_array_get_cstring_nocopy(reverts, i, &revertver);
602 if (strcmp(version, revertver) == 0) {
621 dest = malloc(len+1);
626 if (*s ==
'/' && *(s+1) ==
'/') {
641 char *res = NULL, *lnk = NULL, *p = NULL, *p1 = NULL, *dname = NULL;
642 char *rootdir = NULL;
649 if (lstat(path, &sb) == -1)
652 lnk = malloc(sb.st_size + 1);
655 r = readlink(path, lnk, sb.st_size + 1);
656 if (r < 0 || r > sb.st_size) {
660 lnk[sb.st_size] =
'\0';
670 rootdir = realpath(xhp->
rootdir, NULL);
671 if (rootdir == NULL) {
676 if (strstr(lnk,
"./")) {
678 p = realpath(path, NULL);
685 if (strcmp(rootdir,
"/") == 0) {
688 p1 = strdup(p + strlen(rootdir));
695 }
else if (lnk[0] !=
'/') {
701 if (strcmp(rootdir,
"/") == 0) {
708 p1 = strdup(dname + strlen(rootdir));
734 if (patterns == NULL)
737 for (
unsigned int i = 0; i < xbps_array_count(patterns); i++) {
738 const char *pattern = NULL;
740 if (!xbps_array_get_cstring_nocopy(patterns, i, &pattern))
744 if ((negate = *pattern ==
'!') || *pattern ==
'\\')
746 if (fnmatch(pattern, path, 0) == 0)
char rootdir[XBPS_MAXPATH]
char cachedir[XBPS_MAXPATH+sizeof(XBPS_CACHE_PATH)]
Generic XBPS structure handler for initialization.
xbps_dictionary_t xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
int xbps_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t *state)
bool xbps_match_string_in_array(xbps_array_t array, const char *val)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
int xbps_humanize_number(char *buf, int64_t bytes)
const char * xbps_pkgpattern_version(const char *pkg)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
char * xbps_sanitize_path(const char *src)
bool xbps_patterns_match(xbps_array_t patterns, const char *path)
bool xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
ssize_t xbps_pkg_url(struct xbps_handle *xhp, char *dst, size_t dstsz, xbps_dictionary_t pkgd)
char * xbps_binpkg_pkgver(const char *pkg)
size_t xbps_strlcpy(char *dest, const char *src, size_t siz)
bool xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver)
bool xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
ssize_t xbps_pkg_path(struct xbps_handle *xhp, char *dst, size_t dstsz, xbps_dictionary_t pkgd)
ssize_t xbps_pkg_path_or_url(struct xbps_handle *xhp, char *dst, size_t dstsz, xbps_dictionary_t pkgd)
int xbps_pkg_is_installed(struct xbps_handle *xhp, const char *pkg)
char * xbps_binpkg_arch(const char *pkg)
int xbps_pkgpattern_match(const char *pkg, const char *pattern)
const char * xbps_pkg_revision(const char *pkg)
const char * xbps_pkg_version(const char *pkg)
bool xbps_repository_is_remote(const char *uri)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pkg)
bool xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
bool xbps_pkg_arch_match(struct xbps_handle *xhp, const char *orig, const char *target)
char * xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
size_t xbps_strlcat(char *dest, const char *src, size_t siz)
char * xbps_repository_pkg_path(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)