29#include <sys/utsname.h>
43#include "xbps_api_impl.h"
46is_revision(
const char *str)
48 if (str == NULL || *str ==
'\0')
51 while (isdigit((
unsigned char)*str) || *str ==
'_')
66 if ((strncmp(uri,
"http://", 7) == 0) ||
67 (strncmp(uri,
"https://", 8) == 0) ||
68 (strncmp(uri,
"ftp://", 6) == 0))
77 xbps_dictionary_t dict;
92 if (state == XBPS_PKG_STATE_INSTALLED || state == XBPS_PKG_STATE_UNPACKED)
101 char pkgname[XBPS_NAME_SIZE];
107 if (!xhp->ignored_pkgs)
127 if ((p = strrchr(pkg,
'-')) == NULL)
132 for (
unsigned int i = 0; i < p_len; i++) {
135 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
136 if (!is_revision(r + 1)) {
155 if ((fname = strrchr(pkg,
'/')))
161 if ((len = strlen(fname)) < 5)
167 (void)memcpy(p, fname, len);
169 if (!(p1 = strrchr(p,
'.'))) {
173 p[strlen(p)-strlen(p1)] =
'\0';
197 if ((fname = strrchr(pkg,
'/')))
203 if ((len = strlen(fname)) < 5)
209 (void)memcpy(p, fname, len);
211 if (!(p1 = strrchr(p,
'.'))) {
215 res = strdup(p1 + 1);
230 if ((p = strrchr(pkg,
'-')) == NULL)
235 for (
unsigned int i = 0; i < p_len; i++) {
238 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
239 if (!is_revision(r + 1)) {
242 return strrchr(r,
'_') + 1;
258 if ((p = strrchr(pkg,
'-')) == NULL)
263 for (
unsigned int i = 1; i < plen; i++) {
266 if (isdigit((
unsigned char)p[i]) && (r = strchr(p + i + 1,
'_'))) {
267 valid = is_revision(r + 1);
274 plen = strlen(pkg) - strlen(p) + 1;
278 memcpy(dst, pkg, plen-1);
293 if ((res = strpbrk(pkg,
"><*?[]")) == NULL)
296 plen = strlen(pkg) - strlen(res) + 1;
297 if (strlen(pkg) < plen-2)
300 if (pkg[plen-2] ==
'-')
306 memcpy(dst, pkg, plen-1);
317 return strpbrk(pkg,
"><*?[]");
323 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
326 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
327 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
328 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
334 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
335 if (l < 0 || (
size_t)l >= dstsz)
344 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
347 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
348 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
349 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
352 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
353 if (l < 0 || (
size_t)l >= dstsz)
362 const char *pkgver = NULL, *arch = NULL, *repoloc = NULL;
365 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver) ||
366 !xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch) ||
367 !xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
371 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", xhp->cachedir,
373 if (l < 0 || (
size_t)l >= dstsz)
375 if (access(dst, R_OK) == 0)
381 l = snprintf(dst, dstsz,
"%s/%s.%s.xbps", repoloc, pkgver, arch);
382 if (l < 0 || (
size_t)l >= dstsz)
391 const char *pkgver, *arch, *repoloc;
392 char *lbinpkg = NULL;
395 assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
397 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
400 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
401 "architecture", &arch))
403 if (!xbps_dictionary_get_cstring_nocopy(pkg_repod,
404 "repository", &repoloc))
413 if (access(lbinpkg, R_OK) == 0)
428 const char *pkgver, *arch, *repoloc;
431 assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY);
433 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
436 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
437 "architecture", &arch))
439 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
440 "repository", &repoloc))
443 snprintf(path,
sizeof(path),
"%s/%s.%s.xbps",
447 return access(path, R_OK) == 0;
454 const char *pkgver, *arch;
457 assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY);
459 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
462 if (!xbps_dictionary_get_cstring_nocopy(pkgd,
463 "architecture", &arch))
466 snprintf(path,
sizeof(path),
"%s/%s.%s.xbps.sig2", xhp->
cachedir,
470 if (access(path, R_OK) != 0)
474 path[strlen(path)-
sizeof (
".sig2")+1] =
'\0';
476 return access(path, R_OK) == 0;
493 if (target == NULL) {
494 if ((strcmp(orig,
"noarch") == 0) ||
495 (strcmp(orig, arch) == 0))
498 if ((strcmp(orig,
"noarch") == 0) ||
499 (strcmp(orig, target) == 0))
512 if (vasprintf(&buf, fmt, ap) == -1) {
532 if (strcmp(pattern, pkg) == 0)
536 if (strpbrk(pattern,
"<>") != NULL)
537 return dewey_match(pattern, pkg);
540 if (strpbrk(pattern,
"*?[]") != NULL)
541 if (fnmatch(pattern, pkg, FNM_PERIOD) == 0)
557 return humanize_number(buf, 7, bytes,
"B",
558 HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE);
567 return strlcat(dest, src, siz);
576 return strlcpy(dest, src, siz);
586 xbps_array_t reverts;
588 const char *revertver = NULL;
593 if ((reverts = xbps_dictionary_get(pkg,
"reverts")) == NULL)
596 for (i = 0; i < xbps_array_count(reverts); i++) {
597 xbps_array_get_cstring_nocopy(reverts, i, &revertver);
598 if (strcmp(version, revertver) == 0) {
617 dest = malloc(len+1);
622 if (*s ==
'/' && *(s+1) ==
'/') {
637 char *res = NULL, *lnk = NULL, *p = NULL, *p1 = NULL, *dname = NULL;
638 char *rootdir = NULL;
645 if (lstat(path, &sb) == -1)
648 lnk = malloc(sb.st_size + 1);
651 r = readlink(path, lnk, sb.st_size + 1);
652 if (r < 0 || r > sb.st_size) {
656 lnk[sb.st_size] =
'\0';
666 rootdir = realpath(xhp->
rootdir, NULL);
667 if (rootdir == NULL) {
672 if (strstr(lnk,
"./")) {
674 p = realpath(path, NULL);
681 if (strcmp(rootdir,
"/") == 0) {
684 p1 = strdup(p + strlen(rootdir));
691 }
else if (lnk[0] !=
'/') {
697 if (strcmp(rootdir,
"/") == 0) {
704 p1 = strdup(dname + strlen(rootdir));
730 if (patterns == NULL)
733 for (
unsigned int i = 0; i < xbps_array_count(patterns); i++) {
734 const char *pattern = NULL;
736 if (!xbps_array_get_cstring_nocopy(patterns, i, &pattern))
740 if ((negate = *pattern ==
'!') || *pattern ==
'\\')
742 if (fnmatch(pattern, path, 0) == 0)
char rootdir[XBPS_MAXPATH]
char cachedir[XBPS_MAXPATH]
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)