libxbps: ABI/API break due to xbps_pkg{,pattern}_name changes.
The funcs xbps_pkg_name() and xbps_pkgpattern_name() were using malloc(3) to return the result, until now. They now have been changed to not allocate the result via malloc, the caller is responsible to provide a buffer at least of XBPS_NAME_SIZE (64). If for whatever reason the pkgname can't be guessed, returns false. This should avoid lots of small allocs around libxbps. New functions have the following prototype: bool xbps_pkg_name(char *dst, size_t len, const char *pkg) bool xbps_pkgpattern_name(char *dst, size_t len, const char *pkg) as suggested by @duncaen.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
RANLIB ?= ranlib
|
||||
|
||||
LIBXBPS_MAJOR = 4
|
||||
LIBXBPS_MINOR = 1
|
||||
LIBXBPS_MAJOR = 5
|
||||
LIBXBPS_MINOR = 0
|
||||
LIBXBPS_MICRO = 0
|
||||
LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO)
|
||||
LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR)
|
||||
|
||||
@@ -331,7 +331,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
|
||||
xbps_array_t allkeys;
|
||||
xbps_dictionary_t alternatives, pkg_alternatives;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
bool update = false;
|
||||
int rv = 0;
|
||||
|
||||
@@ -346,7 +346,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
|
||||
return 0;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
if ((pkgname = xbps_pkg_name(pkgver)) == NULL)
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
||||
return EINVAL;
|
||||
|
||||
xbps_dictionary_get_bool(pkgd, "alternatives-update", &update);
|
||||
@@ -396,7 +396,6 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
|
||||
break;
|
||||
}
|
||||
xbps_object_release(allkeys);
|
||||
free(pkgname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -410,7 +409,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
|
||||
*/
|
||||
static void
|
||||
prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod,
|
||||
char *pkgname, const char *pkgver, const char *keyname)
|
||||
const char *pkgname, const char *pkgver, const char *keyname)
|
||||
{
|
||||
const char *newpkg = NULL, *curpkg = NULL;
|
||||
xbps_array_t array;
|
||||
@@ -533,7 +532,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
||||
xbps_array_t allkeys;
|
||||
xbps_dictionary_t alternatives, pkg_alternatives;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv = 0;
|
||||
|
||||
assert(xhp);
|
||||
@@ -551,8 +550,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
||||
assert(alternatives);
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
if (pkgname == NULL)
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
@@ -612,7 +610,6 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
||||
break;
|
||||
}
|
||||
xbps_object_release(allkeys);
|
||||
free(pkgname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -90,28 +90,26 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
bool update)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
char *pkgname;
|
||||
const char *p;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
mode_t myumask;
|
||||
|
||||
assert(pkgver != NULL);
|
||||
|
||||
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) {
|
||||
xbps_dbg_printf(xhp, "[configure] cannot guess "
|
||||
"pkgname for %s\n", pkgver);
|
||||
/* assume pkgver == pkgname */
|
||||
pkgname = strdup(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
p = pkgver;
|
||||
} else {
|
||||
p = pkgname;
|
||||
}
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, p);
|
||||
if (pkgd == NULL) {
|
||||
xbps_dbg_printf(xhp, "[configure] cannot find %s (%s) "
|
||||
"in pkgdb\n", pkgname, pkgver);
|
||||
free(pkgname);
|
||||
"in pkgdb\n", p, pkgver);
|
||||
return ENOENT;
|
||||
}
|
||||
free(pkgname);
|
||||
|
||||
rv = xbps_pkg_state_dictionary(pkgd, &state);
|
||||
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);
|
||||
|
||||
@@ -145,7 +145,7 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
|
||||
xbps_string_t str;
|
||||
struct item *item, *xitem;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgn;
|
||||
char pkgn[XBPS_NAME_SIZE];
|
||||
|
||||
assert(xhp);
|
||||
assert(pkgd);
|
||||
@@ -154,8 +154,9 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
|
||||
provides = xbps_dictionary_get(pkgd, "provides");
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
|
||||
pkgn = xbps_pkg_name(pkgver);
|
||||
assert(pkgn);
|
||||
if (!xbps_pkg_name(pkgn, sizeof(pkgn), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
item = lookupItem(pkgn);
|
||||
if (item) {
|
||||
add_deps_recursive(item, depth == 0);
|
||||
@@ -165,12 +166,11 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
|
||||
item = addItem(rdeps, pkgn);
|
||||
item->pkgver = pkgver;
|
||||
assert(item);
|
||||
free(pkgn);
|
||||
|
||||
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
||||
xbps_dictionary_t curpkgd;
|
||||
const char *curdep = NULL;
|
||||
char *curdepname;
|
||||
char curdepname[XBPS_NAME_SIZE];
|
||||
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
|
||||
if (rpool) {
|
||||
@@ -189,15 +189,14 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
if ((curdepname = xbps_pkgpattern_name(curdep)) == NULL)
|
||||
curdepname = xbps_pkg_name(curdep);
|
||||
|
||||
assert(curdepname);
|
||||
if ((!xbps_pkgpattern_name(curdepname, XBPS_NAME_SIZE, curdep)) &&
|
||||
(!xbps_pkg_name(curdepname, XBPS_NAME_SIZE, curdep))) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (provides && xbps_match_pkgname_in_array(provides, curdepname)) {
|
||||
xbps_dbg_printf(xhp, "%s: ignoring dependency %s "
|
||||
"already in provides\n", pkgver, curdep);
|
||||
free(curdepname);
|
||||
continue;
|
||||
}
|
||||
xitem = lookupItem(curdepname);
|
||||
@@ -214,7 +213,6 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
|
||||
}
|
||||
assert(xitem);
|
||||
addDepn(item, xitem);
|
||||
free(curdepname);
|
||||
}
|
||||
/* all deps were processed, add item to head */
|
||||
if (depth > 0 && !xbps_match_string_in_array(result, item->pkgver)) {
|
||||
|
||||
@@ -36,12 +36,12 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
|
||||
{
|
||||
xbps_array_t replaces;
|
||||
xbps_dictionary_t pkgd;
|
||||
char outstr[64];
|
||||
char outstr[64], pkgname[XBPS_NAME_SIZE];
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
struct tm *tmp;
|
||||
const char *pkgver;
|
||||
char *pkgname = NULL, *buf, *sha256;
|
||||
char *buf, *sha256;
|
||||
int rv = 0;
|
||||
bool autoinst = false;
|
||||
|
||||
@@ -51,8 +51,11 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
|
||||
pkgd = xbps_dictionary_copy_mutable(pkgrd);
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
xbps_dbg_printf(xhp, "%s: invalid pkgname %s\n", __func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (xhp->flags & XBPS_FLAG_INSTALL_AUTO)
|
||||
autoinst = true;
|
||||
@@ -130,8 +133,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
|
||||
}
|
||||
out:
|
||||
xbps_object_release(pkgd);
|
||||
if (pkgname)
|
||||
free(pkgname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
|
||||
{
|
||||
xbps_dictionary_t pkgd = NULL, obsd = NULL;
|
||||
xbps_array_t obsoletes = NULL;
|
||||
char *pkgname, metafile[PATH_MAX];
|
||||
char pkgname[XBPS_NAME_SIZE], metafile[PATH_MAX];
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
uid_t euid;
|
||||
@@ -119,8 +119,9 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
|
||||
assert(xhp);
|
||||
assert(pkgver);
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
euid = geteuid();
|
||||
|
||||
@@ -181,7 +182,6 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
|
||||
* overwritten later in unpack phase.
|
||||
*/
|
||||
if (update) {
|
||||
free(pkgname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -259,8 +259,6 @@ purge:
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
|
||||
xbps_dictionary_remove(xhp->pkgdb, pkgname);
|
||||
out:
|
||||
if (pkgname != NULL)
|
||||
free(pkgname);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver,
|
||||
"%s: failed to remove package: %s", pkgver, strerror(rv));
|
||||
|
||||
@@ -49,7 +49,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
"/bin/bash",
|
||||
NULL
|
||||
};
|
||||
char *pkgname, *fpath;
|
||||
char pkgname[XBPS_NAME_SIZE], *fpath;
|
||||
int fd, rv;
|
||||
|
||||
assert(blob);
|
||||
@@ -103,8 +103,9 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
close(fd);
|
||||
|
||||
/* exec script */
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
version = xbps_pkg_version(pkgver);
|
||||
assert(version);
|
||||
|
||||
@@ -129,7 +130,6 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
free(pkgname);
|
||||
|
||||
out:
|
||||
remove(fpath);
|
||||
|
||||
@@ -138,7 +138,7 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
pkg_state_t state)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv = 0;
|
||||
|
||||
assert(pkgver != NULL);
|
||||
@@ -158,26 +158,24 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
xbps_object_release(pkgd);
|
||||
return rv;
|
||||
}
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
|
||||
xbps_object_release(pkgd);
|
||||
free(pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(pkgname);
|
||||
xbps_object_release(pkgd);
|
||||
} else {
|
||||
if ((rv = set_new_state(pkgd, state)) != 0)
|
||||
return rv;
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
|
||||
free(pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(pkgname);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
||||
@@ -84,7 +84,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
size_t instbufsiz = 0, rembufsiz = 0;
|
||||
ssize_t entry_size;
|
||||
const char *entry_pname, *transact, *binpkg_pkgver;
|
||||
char *pkgname, *buf = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE], *buf = NULL;
|
||||
int ar_rv, rv, error, entry_type, flags;
|
||||
bool preserve, update, file_exists, keep_conf_file;
|
||||
bool skip_extract, force, xucd_stats;
|
||||
@@ -102,8 +102,9 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
|
||||
euid = geteuid();
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (xhp->flags & XBPS_FLAG_FORCE_UNPACK)
|
||||
force = true;
|
||||
@@ -550,8 +551,6 @@ out:
|
||||
xbps_object_release(binpkg_propsd);
|
||||
if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY)
|
||||
xbps_object_release(binpkg_filesd);
|
||||
if (pkgname != NULL)
|
||||
free(pkgname);
|
||||
if (instbuf != NULL)
|
||||
free(instbuf);
|
||||
if (rembuf != NULL)
|
||||
|
||||
53
lib/pkgdb.c
53
lib/pkgdb.c
@@ -160,7 +160,7 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
|
||||
xbps_array_t provides;
|
||||
xbps_dictionary_t pkgd;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgname = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
provides = xbps_dictionary_get(pkgd, "provides");
|
||||
@@ -168,9 +168,10 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
|
||||
continue;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
|
||||
const char *vpkg = NULL;
|
||||
|
||||
@@ -179,12 +180,14 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
|
||||
xbps_dbg_printf(xhp, "%s: set_cstring vpkg "
|
||||
"%s pkgname %s\n", __func__, vpkg, pkgname);
|
||||
rv = EINVAL;
|
||||
break;
|
||||
} else {
|
||||
xbps_dbg_printf(xhp, "[pkgdb] added vpkg %s for %s\n",
|
||||
vpkg, pkgname);
|
||||
}
|
||||
}
|
||||
free(pkgname);
|
||||
if (rv)
|
||||
break;
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
return rv;
|
||||
@@ -369,28 +372,31 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
for (unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
|
||||
xbps_array_t pkg;
|
||||
const char *pkgdep = NULL, *vpkgname = NULL;
|
||||
char *curpkgname;
|
||||
char *v, curpkgname[XBPS_NAME_SIZE];
|
||||
bool alloc = false;
|
||||
|
||||
xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
|
||||
curpkgname = xbps_pkgpattern_name(pkgdep);
|
||||
if (curpkgname == NULL)
|
||||
curpkgname = xbps_pkg_name(pkgdep);
|
||||
assert(curpkgname);
|
||||
if ((!xbps_pkgpattern_name(curpkgname, sizeof(curpkgname), pkgdep)) &&
|
||||
(!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))) {
|
||||
abort();
|
||||
}
|
||||
vpkgname = vpkg_user_conf(xhp, curpkgname, false);
|
||||
if (vpkgname == NULL)
|
||||
vpkgname = curpkgname;
|
||||
if (vpkgname == NULL) {
|
||||
v = strdup(curpkgname);
|
||||
} else {
|
||||
v = strdup(vpkgname);
|
||||
}
|
||||
|
||||
pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, vpkgname);
|
||||
pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
|
||||
if (pkg == NULL) {
|
||||
alloc = true;
|
||||
pkg = xbps_array_create();
|
||||
}
|
||||
if (!xbps_match_string_in_array(pkg, pkgver)) {
|
||||
xbps_array_add_cstring_nocopy(pkg, pkgver);
|
||||
xbps_dictionary_set(xhp->pkgdb_revdeps, vpkgname, pkg);
|
||||
xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
|
||||
}
|
||||
free(curpkgname);
|
||||
free(v);
|
||||
if (alloc)
|
||||
xbps_object_release(pkg);
|
||||
}
|
||||
@@ -401,23 +407,19 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
xbps_array_t
|
||||
xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
xbps_array_t res;
|
||||
xbps_dictionary_t pkgd;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL)
|
||||
return NULL;
|
||||
|
||||
generate_full_revdeps_tree(xhp);
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
if ((pkgname = xbps_pkg_name(pkgver)) == NULL)
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
||||
return NULL;
|
||||
|
||||
res = xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
|
||||
free(pkgname);
|
||||
|
||||
return res;
|
||||
return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
|
||||
}
|
||||
|
||||
xbps_array_t
|
||||
@@ -431,7 +433,7 @@ xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
xbps_dictionary_t pkgd, pkgfilesd;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgname, *plist;
|
||||
char pkgname[XBPS_NAME_SIZE], *plist;
|
||||
|
||||
if (pkg == NULL)
|
||||
return NULL;
|
||||
@@ -441,11 +443,10 @@ xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
||||
return NULL;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
||||
return NULL;
|
||||
|
||||
plist = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname);
|
||||
free(pkgname);
|
||||
pkgfilesd = xbps_plist_dictionary_from_file(xhp, plist);
|
||||
free(plist);
|
||||
|
||||
|
||||
10
lib/plist.c
10
lib/plist.c
@@ -225,7 +225,7 @@ array_replace_dict(xbps_array_t array,
|
||||
{
|
||||
xbps_object_t obj;
|
||||
const char *curpkgver;
|
||||
char *curpkgname;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
|
||||
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
|
||||
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
|
||||
@@ -249,17 +249,15 @@ array_replace_dict(xbps_array_t array,
|
||||
/* pkgname match */
|
||||
xbps_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &curpkgver);
|
||||
curpkgname = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgname);
|
||||
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
if (!xbps_array_set(array, i, dict)) {
|
||||
free(curpkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(curpkgname);
|
||||
return 0;
|
||||
}
|
||||
free(curpkgname);
|
||||
}
|
||||
}
|
||||
/* no match */
|
||||
|
||||
@@ -47,7 +47,7 @@ get_pkg_in_array(xbps_array_t array, const char *str, const char *trans, bool vi
|
||||
|
||||
while ((obj = xbps_object_iterator_next(iter))) {
|
||||
const char *pkgver;
|
||||
char *dpkgn;
|
||||
char dpkgn[XBPS_NAME_SIZE];
|
||||
|
||||
if (virtual) {
|
||||
/*
|
||||
@@ -80,14 +80,13 @@ get_pkg_in_array(xbps_array_t array, const char *str, const char *trans, bool vi
|
||||
if (!xbps_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &pkgver))
|
||||
continue;
|
||||
dpkgn = xbps_pkg_name(pkgver);
|
||||
assert(dpkgn);
|
||||
if (!xbps_pkg_name(dpkgn, sizeof(dpkgn), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(dpkgn, str) == 0) {
|
||||
free(dpkgn);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(dpkgn);
|
||||
}
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
@@ -139,10 +138,10 @@ match_pkg_by_pkgver(xbps_dictionary_t repod, const char *p)
|
||||
{
|
||||
xbps_dictionary_t d = NULL;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
/* exact match by pkgver */
|
||||
if ((pkgname = xbps_pkg_name(p)) == NULL)
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), p))
|
||||
return NULL;
|
||||
|
||||
d = xbps_dictionary_get(repod, pkgname);
|
||||
@@ -154,7 +153,6 @@ match_pkg_by_pkgver(xbps_dictionary_t repod, const char *p)
|
||||
}
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -163,12 +161,11 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
|
||||
{
|
||||
xbps_dictionary_t d = NULL;
|
||||
const char *pkgver = NULL;
|
||||
char *pkgname = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
/* match by pkgpattern in pkgver */
|
||||
if ((pkgname = xbps_pkgpattern_name(p)) == NULL) {
|
||||
if ((pkgname = xbps_pkg_name(p))) {
|
||||
free(pkgname);
|
||||
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), p)) {
|
||||
if (xbps_pkg_name(pkgname, sizeof(pkgname), p)) {
|
||||
return match_pkg_by_pkgver(repod, p);
|
||||
}
|
||||
return NULL;
|
||||
@@ -184,7 +181,6 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
|
||||
}
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -213,7 +209,8 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
|
||||
|
||||
while ((obj = xbps_object_iterator_next(iter))) {
|
||||
xbps_string_t rpkg;
|
||||
char *dpkgname, *vpkgname;
|
||||
char buf[XBPS_NAME_SIZE];
|
||||
char *vpkgname;
|
||||
const char *vpkg_conf;
|
||||
|
||||
vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
|
||||
@@ -221,12 +218,14 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
|
||||
pkg = xbps_string_cstring_nocopy(rpkg);
|
||||
|
||||
if (xbps_pkg_version(vpkg_conf)) {
|
||||
vpkgname = xbps_pkg_name(vpkg_conf);
|
||||
assert(vpkgname);
|
||||
if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg_conf)) {
|
||||
abort();
|
||||
}
|
||||
vpkgname = strdup(buf);
|
||||
} else {
|
||||
vpkgname = strdup(vpkg_conf);
|
||||
assert(vpkgname);
|
||||
}
|
||||
assert(vpkgname);
|
||||
|
||||
if (xbps_pkgpattern_version(vpkg)) {
|
||||
char *vpkgver;
|
||||
@@ -246,14 +245,13 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
|
||||
free(vpkgver);
|
||||
}
|
||||
} else if (xbps_pkg_version(vpkg)) {
|
||||
dpkgname = xbps_pkg_name(vpkg);
|
||||
assert(dpkgname);
|
||||
if (strcmp(dpkgname, vpkgname)) {
|
||||
free(dpkgname);
|
||||
if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(buf, vpkgname)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
free(dpkgname);
|
||||
} else {
|
||||
if (strcmp(vpkg, vpkgname)) {
|
||||
free(vpkgname);
|
||||
|
||||
@@ -103,7 +103,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode)
|
||||
xbps_object_iterator_t iter;
|
||||
xbps_object_t obj;
|
||||
const char *pkgdep;
|
||||
char *curpkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
bool found = false;
|
||||
|
||||
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
|
||||
@@ -122,27 +122,21 @@ match_string_in_array(xbps_array_t array, const char *str, int mode)
|
||||
} else if (mode == 1) {
|
||||
/* match by pkgname against pkgver */
|
||||
pkgdep = xbps_string_cstring_nocopy(obj);
|
||||
curpkgname = xbps_pkg_name(pkgdep);
|
||||
if (curpkgname == NULL)
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgdep))
|
||||
break;
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
free(curpkgname);
|
||||
if (strcmp(pkgname, str) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(curpkgname);
|
||||
} else if (mode == 2) {
|
||||
/* match by pkgver against pkgname */
|
||||
pkgdep = xbps_string_cstring_nocopy(obj);
|
||||
curpkgname = xbps_pkg_name(str);
|
||||
if (curpkgname == NULL)
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, str))
|
||||
break;
|
||||
if (strcmp(curpkgname, pkgdep) == 0) {
|
||||
free(curpkgname);
|
||||
if (strcmp(pkgname, pkgdep) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(curpkgname);
|
||||
} else if (mode == 3) {
|
||||
/* match pkgpattern against pkgdep */
|
||||
pkgdep = xbps_string_cstring_nocopy(obj);
|
||||
|
||||
@@ -37,7 +37,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
|
||||
xbps_object_iterator_t iter;
|
||||
xbps_object_t obj;
|
||||
const char *curname, *pkgdep;
|
||||
char *curpkgname;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
unsigned int idx = 0;
|
||||
bool found = false;
|
||||
|
||||
@@ -57,15 +57,13 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
|
||||
} else if (mode == 1) {
|
||||
/* match by pkgname, obj is a string */
|
||||
pkgdep = xbps_string_cstring_nocopy(obj);
|
||||
curpkgname = xbps_pkg_name(pkgdep);
|
||||
if (curpkgname == NULL)
|
||||
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))
|
||||
break;
|
||||
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
free(curpkgname);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(curpkgname);
|
||||
} else if (mode == 2) {
|
||||
/* match by pkgname, obj is a dictionary */
|
||||
xbps_dictionary_get_cstring_nocopy(obj,
|
||||
|
||||
@@ -556,17 +556,16 @@ xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg)
|
||||
*/
|
||||
if ((vdeps = xbps_dictionary_get(pkgd, "provides"))) {
|
||||
for (unsigned int i = 0; i < xbps_array_count(vdeps); i++) {
|
||||
char *vpkgn;
|
||||
char vpkgn[XBPS_NAME_SIZE];
|
||||
|
||||
xbps_array_get_cstring_nocopy(vdeps, i, &vpkg);
|
||||
vpkgn = xbps_pkg_name(vpkg);
|
||||
assert(vpkgn);
|
||||
if (!xbps_pkg_name(vpkgn, XBPS_NAME_SIZE, vpkg)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(vpkgn, pkg) == 0) {
|
||||
free(vpkgn);
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
free(vpkgn);
|
||||
vpkg = NULL;
|
||||
}
|
||||
if (match)
|
||||
|
||||
@@ -51,7 +51,8 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
|
||||
|
||||
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
|
||||
const char *curdep, *curver, *pkgver;
|
||||
char *curpkgnamedep = NULL, *pkgnamedep = NULL;
|
||||
char curpkgnamedep[XBPS_NAME_SIZE];
|
||||
char pkgnamedep[XBPS_NAME_SIZE];
|
||||
|
||||
assert(xbps_object_type(obj) == XBPS_TYPE_STRING);
|
||||
curdep = xbps_string_cstring_nocopy(obj);
|
||||
@@ -59,19 +60,15 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
|
||||
pkgver = xbps_pkgpattern_version(reqpkg);
|
||||
if (curver == NULL || pkgver == NULL)
|
||||
goto out;
|
||||
curpkgnamedep = xbps_pkgpattern_name(curdep);
|
||||
if (curpkgnamedep == NULL)
|
||||
if (!xbps_pkgpattern_name(curpkgnamedep, XBPS_NAME_SIZE, curdep)) {
|
||||
goto out;
|
||||
pkgnamedep = xbps_pkgpattern_name(reqpkg);
|
||||
if (pkgnamedep == NULL) {
|
||||
free(curpkgnamedep);
|
||||
}
|
||||
if (!xbps_pkgpattern_name(pkgnamedep, XBPS_NAME_SIZE, reqpkg)) {
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(pkgnamedep, curpkgnamedep) == 0) {
|
||||
pkgfound = true;
|
||||
if (strcmp(curver, pkgver) == 0) {
|
||||
free(curpkgnamedep);
|
||||
free(pkgnamedep);
|
||||
rv = EEXIST;
|
||||
goto out;
|
||||
}
|
||||
@@ -82,15 +79,11 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
|
||||
xbps_dbg_printf(xhp, "Missing pkgdep name matched, curver: %s newver: %s\n", curver, pkgver);
|
||||
if (xbps_cmpver(curver, pkgver) <= 0) {
|
||||
add_pkgdep = false;
|
||||
free(curpkgnamedep);
|
||||
free(pkgnamedep);
|
||||
rv = EEXIST;
|
||||
goto out;
|
||||
}
|
||||
update_pkgdep = true;
|
||||
}
|
||||
free(curpkgnamedep);
|
||||
free(pkgnamedep);
|
||||
if (pkgfound)
|
||||
break;
|
||||
|
||||
@@ -123,13 +116,8 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
const char *curpkg, /* current pkgver */
|
||||
unsigned short *depth) /* max recursion depth */
|
||||
{
|
||||
xbps_dictionary_t curpkgd = NULL;
|
||||
xbps_object_t obj;
|
||||
xbps_object_iterator_t iter;
|
||||
xbps_array_t curpkgrdeps = NULL, curpkgprovides = NULL;
|
||||
pkg_state_t state;
|
||||
const char *reqpkg, *pkgver_q, *reason = NULL;
|
||||
char *pkgname, *reqpkgname;
|
||||
int rv = 0;
|
||||
|
||||
if (*depth >= MAX_DEPTH)
|
||||
@@ -143,7 +131,13 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
assert(iter);
|
||||
|
||||
while ((obj = xbps_object_iterator_next(iter))) {
|
||||
xbps_array_t curpkgrdeps = NULL, curpkgprovides = NULL;
|
||||
xbps_dictionary_t curpkgd = NULL;
|
||||
pkg_state_t state;
|
||||
const char *reqpkg, *pkgver_q, *reason = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE], reqpkgname[XBPS_NAME_SIZE];
|
||||
bool error = false, foundvpkg = false;
|
||||
|
||||
reqpkg = xbps_string_cstring_nocopy(obj);
|
||||
|
||||
if (xhp->flags & XBPS_FLAG_DEBUG) {
|
||||
@@ -153,8 +147,8 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
}
|
||||
xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ", curpkg ? curpkg : " ", reqpkg);
|
||||
}
|
||||
if (((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) &&
|
||||
((pkgname = xbps_pkg_name(reqpkg)) == NULL)) {
|
||||
if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), reqpkg)) &&
|
||||
(!xbps_pkg_name(pkgname, sizeof(pkgname), reqpkg))) {
|
||||
xbps_dbg_printf(xhp, "%s: can't guess pkgname for dependency: %s\n", curpkg, reqpkg);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_INVALID_DEP, ENXIO, NULL,
|
||||
"%s: can't guess pkgname for dependency '%s'", curpkg, reqpkg);
|
||||
@@ -166,7 +160,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
*/
|
||||
if (xbps_pkg_is_ignored(xhp, pkgname)) {
|
||||
xbps_dbg_printf_append(xhp, "%s ignored.\n", pkgname);
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -175,7 +168,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
*/
|
||||
if (pkg_provides && xbps_match_virtual_pkg_in_array(pkg_provides, reqpkg)) {
|
||||
xbps_dbg_printf_append(xhp, "%s is a vpkg provided by %s, ignored.\n", pkgname, curpkg);
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -186,7 +178,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
(curpkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, reqpkg, NULL))) {
|
||||
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
|
||||
xbps_dbg_printf_append(xhp, " (%s queued)\n", pkgver_q);
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -208,15 +199,14 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
curpkgd = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (curpkgd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
/* error */
|
||||
rv = errno;
|
||||
xbps_dbg_printf(xhp, "failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv));
|
||||
free(pkgname);
|
||||
break;
|
||||
}
|
||||
free(pkgname);
|
||||
/* Required dependency not installed */
|
||||
xbps_dbg_printf_append(xhp, "not installed.\n");
|
||||
reason = "install";
|
||||
@@ -230,7 +220,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
|
||||
/* Check its state */
|
||||
if ((rv = xbps_pkg_state_dictionary(curpkgd, &state)) != 0) {
|
||||
free(pkgname);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -240,17 +229,18 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
* by an installed package.
|
||||
*/
|
||||
xbps_dbg_printf_append(xhp, "[virtual] satisfied by `%s'.\n", pkgver_q);
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
|
||||
if (rv == 0) {
|
||||
char *curpkgname;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
/*
|
||||
* The version requirement is not satisfied.
|
||||
*/
|
||||
curpkgname = xbps_pkg_name(pkgver_q);
|
||||
assert(curpkgname);
|
||||
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver_q)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (strcmp(pkgname, curpkgname)) {
|
||||
xbps_dbg_printf_append(xhp, "not installed `%s (vpkg)'", pkgver_q);
|
||||
if (xbps_dictionary_get(curpkgd, "hold")) {
|
||||
@@ -268,13 +258,10 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
reason = "update";
|
||||
}
|
||||
}
|
||||
free(curpkgname);
|
||||
free(pkgname);
|
||||
} else if (rv == 1) {
|
||||
/*
|
||||
* The version requirement is satisfied.
|
||||
*/
|
||||
free(pkgname);
|
||||
rv = 0;
|
||||
if (state == XBPS_PKG_STATE_UNPACKED) {
|
||||
/*
|
||||
@@ -294,7 +281,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
} else {
|
||||
/* error matching pkgpattern */
|
||||
xbps_dbg_printf(xhp, "failed to match pattern %s with %s\n", reqpkg, pkgver_q);
|
||||
free(pkgname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -328,23 +314,25 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
|
||||
reqpkgname = xbps_pkg_name(pkgver_q);
|
||||
assert(reqpkgname);
|
||||
if (!xbps_pkg_name(reqpkgname, sizeof(reqpkgname), pkgver_q)) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check dependency validity.
|
||||
*/
|
||||
pkgname = xbps_pkg_name(curpkg);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkg)) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
if (strcmp(pkgname, reqpkgname) == 0) {
|
||||
xbps_dbg_printf_append(xhp, "[ignoring wrong dependency %s (depends on itself)]\n", reqpkg);
|
||||
xbps_remove_string_from_array(pkg_rdeps_array, reqpkg);
|
||||
free(pkgname);
|
||||
free(reqpkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
free(reqpkgname);
|
||||
/*
|
||||
* Installed package must be updated, check if dependency is
|
||||
* satisfied.
|
||||
@@ -354,8 +342,9 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
case 0: /* nomatch */
|
||||
break;
|
||||
case 1: /* match */
|
||||
pkgname = xbps_pkg_name(pkgver_q);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver_q)) {
|
||||
abort();
|
||||
}
|
||||
/*
|
||||
* If there's an update in transaction,
|
||||
* it's assumed version is greater.
|
||||
@@ -366,7 +355,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
error = true;
|
||||
rv = ENODEV;
|
||||
}
|
||||
free(pkgname);
|
||||
break;
|
||||
default:
|
||||
error = true;
|
||||
|
||||
@@ -40,7 +40,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
xbps_object_t obj;
|
||||
xbps_object_iterator_t iter;
|
||||
const char *cfpkg, *repopkgver, *pkgver, *tract;
|
||||
char *pkgname, *repopkgname, *buf;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
char repopkgname[XBPS_NAME_SIZE];
|
||||
char *buf;
|
||||
|
||||
pkg_cflicts = xbps_dictionary_get(pkg_repod, "conflicts");
|
||||
if (xbps_array_count(pkg_cflicts) == 0)
|
||||
@@ -54,8 +56,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
|
||||
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
|
||||
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
|
||||
repopkgname = xbps_pkg_name(repopkgver);
|
||||
assert(repopkgname);
|
||||
|
||||
if (!xbps_pkg_name(repopkgname, XBPS_NAME_SIZE, repopkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
iter = xbps_array_iterator(pkg_cflicts);
|
||||
assert(iter);
|
||||
@@ -75,10 +79,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
/* Ignore itself */
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(pkgname, repopkgname) == 0) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -92,11 +96,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
!strcmp(tract, "update") ||
|
||||
!strcmp(tract, "remove") ||
|
||||
!strcmp(tract, "hold")) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
free(pkgname);
|
||||
xbps_dbg_printf(xhp, "found conflicting installed "
|
||||
"pkg %s with pkg in transaction %s "
|
||||
"(matched by %s [trans])\n", pkgver, repopkgver, cfpkg);
|
||||
@@ -123,13 +125,12 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
/* ignore itself */
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(pkgname, repopkgname) == 0) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
xbps_dbg_printf(xhp, "found conflicting pkgs in "
|
||||
"transaction %s <-> %s (matched by %s [trans])\n",
|
||||
pkgver, repopkgver, cfpkg);
|
||||
@@ -144,7 +145,6 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
|
||||
}
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
free(repopkgname);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -156,7 +156,9 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
||||
xbps_object_t obj2;
|
||||
xbps_object_iterator_t iter;
|
||||
const char *cfpkg, *repopkgver, *pkgver, *tract;
|
||||
char *pkgname, *repopkgname, *buf;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
char repopkgname[XBPS_NAME_SIZE];
|
||||
char *buf;
|
||||
|
||||
pkg_cflicts = xbps_dictionary_get(obj, "conflicts");
|
||||
if (xbps_array_count(pkg_cflicts) == 0)
|
||||
@@ -164,12 +166,12 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
||||
|
||||
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &repopkgver);
|
||||
repopkgname = xbps_pkg_name(repopkgver);
|
||||
assert(repopkgname);
|
||||
if (!xbps_pkg_name(repopkgname, XBPS_NAME_SIZE, repopkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* if a pkg is in the transaction, ignore the one from pkgdb */
|
||||
if (xbps_find_pkg_in_array(pkgs, repopkgname, NULL)) {
|
||||
free(repopkgname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -189,13 +191,12 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
||||
continue;
|
||||
}
|
||||
/* ignore itself */
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(pkgname, repopkgname) == 0) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
xbps_dbg_printf(xhp, "found conflicting pkgs in "
|
||||
"transaction %s <-> %s (matched by %s [pkgdb])\n",
|
||||
pkgver, repopkgver, cfpkg);
|
||||
@@ -210,7 +211,6 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
||||
}
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
free(repopkgname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -665,15 +665,16 @@ collect_binpkg_files(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod,
|
||||
struct archive_entry *entry;
|
||||
struct stat st;
|
||||
const char *pkgver;
|
||||
char *bpkg, *pkgname;
|
||||
char *bpkg, pkgname[XBPS_NAME_SIZE];
|
||||
/* size_t entry_size; */
|
||||
int rv = 0, pkg_fd = -1;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
||||
assert(pkgver);
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
bpkg = xbps_repository_pkg_path(xhp, pkg_repod);
|
||||
if (bpkg == NULL) {
|
||||
@@ -750,7 +751,6 @@ out:
|
||||
if (ar)
|
||||
archive_read_finish(ar);
|
||||
free(bpkg);
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -768,7 +768,7 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
|
||||
xbps_dictionary_t pkgd, filesd;
|
||||
xbps_object_t obj;
|
||||
const char *trans, *pkgver;
|
||||
char *pkgname = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv = 0;
|
||||
unsigned int idx = 0;
|
||||
|
||||
@@ -795,9 +795,9 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
|
||||
assert(pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
update = strcmp(trans, "update") == 0;
|
||||
|
||||
if (update || (strcmp(trans, "install") == 0)) {
|
||||
@@ -828,8 +828,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
|
||||
|
||||
filesd = xbps_pkgdb_get_pkg_files(xhp, pkgname);
|
||||
if (filesd == NULL) {
|
||||
free(pkgname);
|
||||
pkgname = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -841,8 +839,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
}
|
||||
free(pkgname);
|
||||
pkgname = NULL;
|
||||
}
|
||||
xbps_object_iterator_reset(iter);
|
||||
|
||||
@@ -860,7 +856,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
|
||||
}
|
||||
|
||||
out:
|
||||
free(pkgname);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
return collect_obsoletes(xhp);
|
||||
|
||||
@@ -65,7 +65,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
|
||||
xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL;
|
||||
xbps_array_t pkgs;
|
||||
const char *repoloc, *repopkgver, *instpkgver, *reason;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int action = 0, rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
bool autoinst = false, repolock = false;
|
||||
@@ -75,9 +75,8 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
|
||||
/*
|
||||
* Find out if pkg is installed first.
|
||||
*/
|
||||
if ((pkgname = xbps_pkg_name(pkg))) {
|
||||
if (xbps_pkg_name(pkgname, sizeof(pkgname), pkg)) {
|
||||
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
free(pkgname);
|
||||
} else {
|
||||
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg);
|
||||
}
|
||||
@@ -187,22 +186,21 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
|
||||
}
|
||||
}
|
||||
|
||||
pkgname = xbps_pkg_name(repopkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), repopkgver)) {
|
||||
abort();
|
||||
}
|
||||
/*
|
||||
* Set package state in dictionary with same state than the
|
||||
* package currently uses, otherwise not-installed.
|
||||
*/
|
||||
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
|
||||
if (rv != ENOENT) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
/* Package not installed, don't error out */
|
||||
state = XBPS_PKG_STATE_NOT_INSTALLED;
|
||||
}
|
||||
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -218,15 +216,10 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
|
||||
*/
|
||||
if (!xbps_dictionary_set_cstring_nocopy(pkg_repod,
|
||||
"transaction", reason)) {
|
||||
free(pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false)) != 0) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
free(pkgname);
|
||||
return 0;
|
||||
|
||||
return xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -238,7 +231,7 @@ xbps_autoupdate(struct xbps_handle *xhp)
|
||||
xbps_array_t rdeps;
|
||||
xbps_dictionary_t pkgd;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv;
|
||||
|
||||
/*
|
||||
@@ -250,11 +243,11 @@ xbps_autoupdate(struct xbps_handle *xhp)
|
||||
return 0;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
rv = trans_find_pkg(xhp, pkgname, false, false);
|
||||
free(pkgname);
|
||||
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg xbps: %d\n", __func__, rv);
|
||||
|
||||
@@ -266,15 +259,15 @@ xbps_autoupdate(struct xbps_handle *xhp)
|
||||
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, "xbps");
|
||||
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
||||
const char *curpkgver = NULL;
|
||||
char *curpkgn;
|
||||
char curpkgn[XBPS_NAME_SIZE];
|
||||
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
|
||||
xbps_dbg_printf(xhp, "%s: processing revdep %s\n", __func__, curpkgver);
|
||||
|
||||
curpkgn = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgn);
|
||||
if (!xbps_pkg_name(curpkgn, sizeof(curpkgn), curpkgver)) {
|
||||
abort();
|
||||
}
|
||||
rv = trans_find_pkg(xhp, curpkgn, false, false);
|
||||
free(curpkgn);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv);
|
||||
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
|
||||
return -1;
|
||||
@@ -305,12 +298,9 @@ xbps_autoupdate(struct xbps_handle *xhp)
|
||||
int
|
||||
xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
xbps_object_t obj;
|
||||
xbps_object_iterator_t iter;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
bool hold, newpkg_found = false;
|
||||
bool newpkg_found = false;
|
||||
int rv = 0;
|
||||
|
||||
rv = xbps_autoupdate(xhp);
|
||||
@@ -329,7 +319,11 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
assert(iter);
|
||||
|
||||
while ((obj = xbps_object_iterator_next(iter))) {
|
||||
hold = false;
|
||||
xbps_dictionary_t pkgd;
|
||||
const char *pkgver;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
bool hold = false;
|
||||
|
||||
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver))
|
||||
continue;
|
||||
@@ -338,8 +332,9 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
xbps_dbg_printf(xhp, "[rpool] package `%s' "
|
||||
"on hold, ignoring updates.\n", pkgver);
|
||||
}
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
rv = trans_find_pkg(xhp, pkgname, false, hold);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
||||
if (rv == 0) {
|
||||
@@ -351,7 +346,6 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
*/
|
||||
rv = 0;
|
||||
}
|
||||
free(pkgname);
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
|
||||
@@ -385,15 +379,15 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
|
||||
rdeps = NULL;
|
||||
}
|
||||
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
||||
const char *curpkgver = NULL;
|
||||
char *curpkgn;
|
||||
const char *pkgver = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
|
||||
curpkgn = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgn);
|
||||
rv = trans_find_pkg(xhp, curpkgn, false, false);
|
||||
free(curpkgn);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv);
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
rv = trans_find_pkg(xhp, pkgname, false, false);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
||||
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
|
||||
return rv;
|
||||
}
|
||||
@@ -429,15 +423,15 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
|
||||
rdeps = NULL;
|
||||
}
|
||||
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
||||
const char *curpkgver = NULL;
|
||||
char *curpkgn;
|
||||
const char *pkgver = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
|
||||
curpkgn = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgn);
|
||||
rv = trans_find_pkg(xhp, curpkgn, false, false);
|
||||
free(curpkgn);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv);
|
||||
xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
rv = trans_find_pkg(xhp, pkgname, false, false);
|
||||
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
||||
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
xbps_object_t obj, obj2;
|
||||
xbps_object_iterator_t iter;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
obj = xbps_array_get(pkgs, i);
|
||||
replaces = xbps_dictionary_get(obj, "replaces");
|
||||
@@ -52,13 +52,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
assert(iter);
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
|
||||
xbps_dictionary_t instd, reppkgd;
|
||||
const char *pattern = NULL, *curpkgver = NULL;
|
||||
char *curpkgname;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
bool instd_auto = false, hold = false;
|
||||
|
||||
pattern = xbps_string_cstring_nocopy(obj2);
|
||||
@@ -76,14 +77,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold)
|
||||
continue;
|
||||
|
||||
curpkgname = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgname);
|
||||
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
|
||||
abort();
|
||||
}
|
||||
/*
|
||||
* Check that we are not replacing the same package,
|
||||
* due to virtual packages.
|
||||
*/
|
||||
if (strcmp(pkgname, curpkgname) == 0) {
|
||||
free(curpkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -143,14 +144,10 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
xbps_dictionary_set_bool(instd, "replaced", true);
|
||||
if (!xbps_array_add_first(pkgs, instd)) {
|
||||
xbps_object_iterator_release(iter);
|
||||
free(pkgname);
|
||||
free(curpkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(curpkgname);
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
free(pkgname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -131,12 +131,12 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
*/
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
((strcmp(tract, "update") == 0) && !preserve)) {
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
pkg_metad = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
free(pkgname);
|
||||
if (pkg_metad == NULL)
|
||||
continue;
|
||||
xbps_dictionary_get_uint64(pkg_metad,
|
||||
|
||||
@@ -52,28 +52,30 @@ check_virtual_pkgs(xbps_array_t mdeps,
|
||||
for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
|
||||
xbps_array_t rundeps;
|
||||
const char *pkgver, *revpkgver, *pkgpattern;
|
||||
char *pkgname, *vpkgname, *vpkgver, *str;
|
||||
char pkgname[XBPS_NAME_SIZE], vpkgname[XBPS_NAME_SIZE];
|
||||
char *vpkgver = NULL, *str = NULL;
|
||||
|
||||
pkgver = revpkgver = pkgpattern = NULL;
|
||||
pkgname = vpkgname = vpkgver = str = NULL;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(trans_pkgd, "pkgver", &pkgver);
|
||||
xbps_dictionary_get_cstring_nocopy(rev_pkgd, "pkgver", &revpkgver);
|
||||
xbps_array_get_cstring(provides, i, &vpkgver);
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
assert(vpkgname);
|
||||
|
||||
if (!xbps_pkg_name(vpkgname, sizeof(vpkgname), vpkgver)) {
|
||||
break;
|
||||
}
|
||||
|
||||
rundeps = xbps_dictionary_get(rev_pkgd, "run_depends");
|
||||
for (unsigned int x = 0; x < xbps_array_count(rundeps); x++) {
|
||||
xbps_array_get_cstring_nocopy(rundeps, x, &pkgpattern);
|
||||
if (((pkgname = xbps_pkgpattern_name(pkgpattern)) == NULL) &&
|
||||
((pkgname = xbps_pkg_name(pkgpattern)) == NULL))
|
||||
|
||||
if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgpattern)) &&
|
||||
(!xbps_pkg_name(pkgname, sizeof(pkgname), pkgpattern)))
|
||||
continue;
|
||||
|
||||
if (strcmp(vpkgname, pkgname)) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
if (!strcmp(vpkgver, pkgpattern) ||
|
||||
xbps_pkgpattern_match(vpkgver, pkgpattern)) {
|
||||
continue;
|
||||
@@ -85,7 +87,6 @@ check_virtual_pkgs(xbps_array_t mdeps,
|
||||
free(str);
|
||||
matched = true;
|
||||
}
|
||||
free(vpkgname);
|
||||
free(vpkgver);
|
||||
}
|
||||
return matched;
|
||||
@@ -112,7 +113,7 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
xbps_array_t pkgrdeps;
|
||||
xbps_object_t obj;
|
||||
const char *pkgver, *tract;
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
obj = xbps_array_get(pkgs, i);
|
||||
/*
|
||||
@@ -129,10 +130,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
continue;
|
||||
}
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -141,13 +143,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
*/
|
||||
pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
|
||||
if (!xbps_array_count(pkgrdeps)) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* If pkg is ignored, pass to the next one.
|
||||
*/
|
||||
free(pkgname);
|
||||
if (xbps_pkg_is_ignored(xhp, pkgver)) {
|
||||
continue;
|
||||
}
|
||||
@@ -159,12 +159,15 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
xbps_array_t rundeps;
|
||||
xbps_dictionary_t revpkgd;
|
||||
const char *curpkgver = NULL, *revpkgver, *curdep = NULL, *curtract;
|
||||
char *curpkgname, *curdepname;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
char curdepname[XBPS_NAME_SIZE];
|
||||
bool found = false;
|
||||
|
||||
xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver);
|
||||
pkgname = xbps_pkg_name(curpkgver);
|
||||
assert(pkgname);
|
||||
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkgver)) {
|
||||
abort();
|
||||
}
|
||||
if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL))) {
|
||||
xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract);
|
||||
if (strcmp(curtract, "remove") == 0)
|
||||
@@ -181,14 +184,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
*/
|
||||
if (strcmp(tract, "remove") == 0) {
|
||||
if (xbps_dictionary_get(obj, "replaced")) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
broken_pkg(mdeps, curpkgver, pkgver, tract);
|
||||
continue;
|
||||
}
|
||||
@@ -196,7 +196,6 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
* First try to match any supported virtual package.
|
||||
*/
|
||||
if (check_virtual_pkgs(mdeps, obj, revpkgd)) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -206,30 +205,26 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
/*
|
||||
* Find out what dependency is it.
|
||||
*/
|
||||
curpkgname = xbps_pkg_name(pkgver);
|
||||
assert(curpkgname);
|
||||
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
|
||||
xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
|
||||
if (((curdepname = xbps_pkg_name(curdep)) == NULL) &&
|
||||
((curdepname = xbps_pkgpattern_name(curdep)) == NULL))
|
||||
if ((!xbps_pkgpattern_name(curdepname, sizeof(curdepname), curdep)) &&
|
||||
(!xbps_pkg_name(curdepname, sizeof(curdepname), curdep))) {
|
||||
abort();
|
||||
|
||||
}
|
||||
if (strcmp(curdepname, curpkgname) == 0) {
|
||||
free(curdepname);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(curdepname);
|
||||
}
|
||||
free(curpkgname);
|
||||
|
||||
if (!found) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
@@ -239,10 +234,8 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
|
||||
* is in the transaction.
|
||||
*/
|
||||
if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
broken_pkg(mdeps, curpkgver, pkgver, tract);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,24 +83,23 @@ collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req)
|
||||
assert(iter);
|
||||
while ((obj = xbps_object_iterator_next(iter))) {
|
||||
const char *trans = NULL;
|
||||
char *pkgname = NULL;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
|
||||
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver))
|
||||
continue;
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* ignore shlibs if pkg is on hold mode */
|
||||
if (xbps_dictionary_get_cstring_nocopy(obj, "transaction", &trans)) {
|
||||
if (!strcmp(trans, "hold")) {
|
||||
free(pkgname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
xbps_dictionary_set(pd, pkgname, obj);
|
||||
free(pkgname);
|
||||
}
|
||||
xbps_object_iterator_release(iter);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
|
||||
{
|
||||
xbps_array_t replaces;
|
||||
const char *pkgver, *repo;
|
||||
char *pkgname, *self_replaced;
|
||||
char pkgname[XBPS_NAME_SIZE], *self_replaced;
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo);
|
||||
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
@@ -54,10 +54,10 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
|
||||
if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL)
|
||||
replaces = xbps_array_create();
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
abort();
|
||||
}
|
||||
self_replaced = xbps_xasprintf("%s>=0", pkgname);
|
||||
free(pkgname);
|
||||
xbps_array_add_cstring(replaces, self_replaced);
|
||||
free(self_replaced);
|
||||
|
||||
|
||||
73
lib/util.c
73
lib/util.c
@@ -106,7 +106,7 @@ xbps_pkg_is_installed(struct xbps_handle *xhp, const char *pkg)
|
||||
bool
|
||||
xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
char *pkgname;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
bool rv = false;
|
||||
|
||||
assert(xhp);
|
||||
@@ -115,10 +115,9 @@ xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
|
||||
if (!xhp->ignored_pkgs)
|
||||
return false;
|
||||
|
||||
if ((pkgname = xbps_pkgpattern_name(pkg)) != NULL ||
|
||||
(pkgname = xbps_pkg_name(pkg)) != NULL) {
|
||||
if (xbps_pkgpattern_name(pkgname, XBPS_NAME_SIZE, pkg) ||
|
||||
xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkg)) {
|
||||
rv = xbps_match_string_in_array(xhp->ignored_pkgs, pkgname);
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -246,21 +245,22 @@ xbps_pkg_revision(const char *pkg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_pkg_name(const char *pkg)
|
||||
bool
|
||||
xbps_pkg_name(char *dst, size_t len, const char *pkg)
|
||||
{
|
||||
const char *p, *r;
|
||||
char *buf;
|
||||
unsigned int len;
|
||||
size_t p_len;
|
||||
size_t plen;
|
||||
bool valid = false;
|
||||
|
||||
if ((p = strrchr(pkg, '-')) == NULL)
|
||||
return NULL;
|
||||
assert(dst);
|
||||
assert(pkg);
|
||||
|
||||
p_len = strlen(p);
|
||||
if ((p = strrchr(pkg, '-')) == NULL)
|
||||
return false;
|
||||
|
||||
plen = strlen(p);
|
||||
/* i = 1 skips first '-' */
|
||||
for (unsigned int i = 1; i < p_len; i++) {
|
||||
for (unsigned int i = 1; i < plen; i++) {
|
||||
if (p[i] == '_')
|
||||
break;
|
||||
if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) {
|
||||
@@ -269,43 +269,44 @@ xbps_pkg_name(const char *pkg)
|
||||
}
|
||||
}
|
||||
if (!valid)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
len = strlen(pkg) - strlen(p) + 1;
|
||||
buf = malloc(len);
|
||||
assert(buf != NULL);
|
||||
plen = strlen(pkg) - strlen(p) + 1;
|
||||
if (plen > len)
|
||||
return false;
|
||||
|
||||
memcpy(buf, pkg, len-1);
|
||||
buf[len-1] = '\0';
|
||||
memcpy(dst, pkg, plen-1);
|
||||
dst[plen-1] = '\0';
|
||||
|
||||
return buf;
|
||||
return true;
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_pkgpattern_name(const char *pkg)
|
||||
bool
|
||||
xbps_pkgpattern_name(char *dst, size_t len, const char *pkg)
|
||||
{
|
||||
char *res, *pkgname;
|
||||
unsigned int len;
|
||||
const char *res;
|
||||
size_t plen;
|
||||
|
||||
assert(pkg != NULL);
|
||||
assert(dst);
|
||||
assert(pkg);
|
||||
|
||||
if ((res = strpbrk(pkg, "><*?[]")) == NULL)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
len = strlen(pkg) - strlen(res) + 1;
|
||||
if (strlen(pkg) < len-2)
|
||||
return NULL;
|
||||
plen = strlen(pkg) - strlen(res) + 1;
|
||||
if (strlen(pkg) < plen-2)
|
||||
return false;
|
||||
|
||||
if (pkg[len-2] == '-')
|
||||
len--;
|
||||
if (pkg[plen-2] == '-')
|
||||
plen--;
|
||||
|
||||
pkgname = malloc(len);
|
||||
assert(pkgname != NULL);
|
||||
if (plen > len)
|
||||
return false;
|
||||
|
||||
memcpy(pkgname, pkg, len-1);
|
||||
pkgname[len-1] = '\0';
|
||||
memcpy(dst, pkg, plen-1);
|
||||
dst[plen-1] = '\0';
|
||||
|
||||
return pkgname;
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
||||
Reference in New Issue
Block a user