XBPS major changes in June 2011.

- A configuration file "xbps-conf.plist" replaces the (un)register target
  in xbps-repo(8) and (un)set-prop in xbps-bin(8). For now, you can set
  the repositories and prefered virtual packages.

- New package pattern matching code from NetBSD. Supports more ways of
  matching patterns in packages.

- Multiple bugs fixed in virtual packages related matching code.

--HG--
rename : LICENSE => COPYING
This commit is contained in:
Juan RP
2011-06-04 13:37:53 +02:00
parent 2d6140f65b
commit 9673c4bd09
59 changed files with 1183 additions and 1416 deletions

View File

@@ -40,12 +40,12 @@ endif
OBJS = package_configure.o package_config_files.o package_orphans.o
OBJS += package_remove.o package_remove_obsoletes.o package_state.o
OBJS += package_unpack.o package_requiredby.o package_register.o
OBJS += package_purge.o package_replaces.o package_properties.o
OBJS += package_purge.o package_replaces.o
OBJS += transaction_dictionary.o transaction_sortdeps.o
OBJS += cmpver.o download.o fexec.o humanize_number.o plist.o
OBJS += plist_archive_entry.o plist_find.o plist_remove.o
OBJS += plist_fetch.o util.o pkgmatch.o mkpath.o initend.o
OBJS += regpkgdb_dictionary.o repository_register.o
OBJS += plist_fetch.o util.o mkpath.o initend.o
OBJS += regpkgdb_dictionary.o match.o dewey.o
OBJS += repository_findpkg.o repository_finddeps.o
OBJS += repository_pool.o repository_sync_index.o
OBJS += $(COMPAT_SRCS)

View File

@@ -25,7 +25,6 @@
#include <strings.h>
#include <ctype.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/*

View File

@@ -19,7 +19,7 @@
#include <sys/types.h>
#include <string.h>
#include "strlcpy.h"
#include "xbps_api_impl.h"
/*
* Copy src to string dst of size siz. At most siz-1 characters

337
lib/dewey.c Normal file
View File

@@ -0,0 +1,337 @@
/* $NetBSD: dewey.c,v 1.1.1.3 2009/03/08 14:51:37 joerg Exp $ */
/*
* Copyright <20> 2002 Alistair G. Crooks. All rights reserved.
*
* 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.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include "xbps_api_impl.h"
#define PKG_PATTERN_MAX 1024
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
enum {
DEWEY_LT,
DEWEY_LE,
DEWEY_EQ,
DEWEY_GE,
DEWEY_GT,
DEWEY_NE
};
/* do not modify these values, or things will NOT work */
enum {
Alpha = -3,
Beta = -2,
RC = -1,
Dot = 0,
Patch = 1
};
/* this struct defines a version number */
typedef struct arr_t {
unsigned c; /* # of version numbers */
unsigned size; /* size of array */
int *v; /* array of decimal numbers */
int netbsd; /* any "nb" suffix */
} arr_t;
/* this struct describes a test */
typedef struct test_t {
const char *s; /* string representation */
unsigned len; /* length of string */
int t; /* enumerated type of test */
} test_t;
/* the tests that are recognised. */
const test_t tests[] = {
{ "<=", 2, DEWEY_LE },
{ "<", 1, DEWEY_LT },
{ ">=", 2, DEWEY_GE },
{ ">", 1, DEWEY_GT },
{ "==", 2, DEWEY_EQ },
{ "!=", 2, DEWEY_NE },
{ NULL, 0, 0 }
};
const test_t modifiers[] = {
{ "alpha", 5, Alpha },
{ "beta", 4, Beta },
{ "pre", 3, RC },
{ "rc", 2, RC },
{ "pl", 2, Dot },
{ "_", 1, Dot },
{ ".", 1, Dot },
{ NULL, 0, 0 }
};
/* locate the test in the tests array */
static int
dewey_mktest(int *op, const char *test)
{
const test_t *tp;
for (tp = tests ; tp->s ; tp++) {
if (strncasecmp(test, tp->s, tp->len) == 0) {
*op = tp->t;
return tp->len;
}
}
return -1;
}
/*
* make a component of a version number.
* '.' encodes as Dot which is '0'
* '_' encodes as 'patch level', or 'Dot', which is 0.
* 'pl' encodes as 'patch level', or 'Dot', which is 0.
* 'alpha' encodes as 'alpha version', or Alpha, which is -3.
* 'beta' encodes as 'beta version', or Beta, which is -2.
* 'rc' encodes as 'release candidate', or RC, which is -1.
* 'nb' encodes as 'netbsd version', which is used after all other tests
*/
static int
mkcomponent(arr_t *ap, const char *num)
{
static const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
const test_t *modp;
int n;
const char *cp;
if (ap->c == ap->size) {
if (ap->size == 0) {
ap->size = 62;
if ((ap->v = malloc(ap->size * sizeof(int))) == NULL) {
xbps_dbg_printf("%s: malloc ENOMEM\n",
__func__);
exit(EXIT_FAILURE);
}
} else {
ap->size *= 2;
if ((ap->v = realloc(ap->v, ap->size * sizeof(int)))
== NULL) {
xbps_dbg_printf("%s: realloc ENOMEM\n",
__func__);
exit(EXIT_FAILURE);
}
}
}
if (isdigit((unsigned char)*num)) {
for (cp = num, n = 0 ; isdigit((unsigned char)*num) ; num++) {
n = (n * 10) + (*num - '0');
}
ap->v[ap->c++] = n;
return (int)(num - cp);
}
for (modp = modifiers ; modp->s ; modp++) {
if (strncasecmp(num, modp->s, modp->len) == 0) {
ap->v[ap->c++] = modp->t;
return modp->len;
}
}
if (strncasecmp(num, "nb", 2) == 0) {
for (cp = num, num += 2, n = 0 ; isdigit((unsigned char)*num) ; num++) {
n = (n * 10) + (*num - '0');
}
ap->netbsd = n;
return (int)(num - cp);
}
if (isalpha((unsigned char)*num)) {
ap->v[ap->c++] = Dot;
cp = strchr(alphas, tolower((unsigned char)*num));
if (ap->c == ap->size) {
ap->size *= 2;
if ((ap->v = realloc(ap->v, ap->size * sizeof(int))) == NULL) {
xbps_dbg_printf("%s: ENOMEM!\n", __func__);
exit(EXIT_FAILURE);
}
}
ap->v[ap->c++] = (int)(cp - alphas) + 1;
return 1;
}
return 1;
}
/* make a version number string into an array of comparable ints */
static int
mkversion(arr_t *ap, const char *num)
{
ap->c = 0;
ap->size = 0;
ap->v = NULL;
ap->netbsd = 0;
while (*num) {
num += mkcomponent(ap, num);
}
return 1;
}
static void
freeversion(arr_t *ap)
{
free(ap->v);
ap->v = NULL;
ap->c = 0;
ap->size = 0;
}
#define DIGIT(v, c, n) (((n) < (c)) ? v[n] : 0)
/* compare the result against the test we were expecting */
static int
result(int cmp, int tst)
{
switch(tst) {
case DEWEY_LT:
return cmp < 0;
case DEWEY_LE:
return cmp <= 0;
case DEWEY_GT:
return cmp > 0;
case DEWEY_GE:
return cmp >= 0;
case DEWEY_EQ:
return cmp == 0;
case DEWEY_NE:
return cmp != 0;
default:
return 0;
}
}
/* do the test on the 2 vectors */
static int
vtest(arr_t *lhs, int tst, arr_t *rhs)
{
int cmp;
unsigned int c, i;
for (i = 0, c = MAX(lhs->c, rhs->c) ; i < c ; i++) {
if ((cmp = DIGIT(lhs->v, lhs->c, i) - DIGIT(rhs->v, rhs->c, i)) != 0) {
return result(cmp, tst);
}
}
return result(lhs->netbsd - rhs->netbsd, tst);
}
/*
* Compare two dewey decimal numbers
*/
static int
dewey_cmp(const char *lhs, int op, const char *rhs)
{
arr_t right;
arr_t left;
int retval;
if (!mkversion(&left, lhs))
return 0;
if (!mkversion(&right, rhs)) {
freeversion(&left);
return 0;
}
retval = vtest(&left, op, &right);
freeversion(&left);
freeversion(&right);
return retval;
}
/*
* Perform dewey match on "pkg" against "pattern".
* Return 1 on match, 0 on non-match, -1 on error.
*/
int HIDDEN
dewey_match(const char *pattern, const char *pkg)
{
const char *version;
const char *sep, *sep2;
int op, op2;
int n;
/* compare names */
if ((version=strrchr(pkg, '-')) == NULL) {
return 0;
}
if ((sep = strpbrk(pattern, "<>")) == NULL)
return -1;
/* compare name lengths */
if ((sep-pattern != version-pkg) ||
strncmp(pkg, pattern, (size_t)(version-pkg)) != 0)
return 0;
version++;
/* extract comparison operator */
if ((n = dewey_mktest(&op, sep)) < 0) {
return 0;
}
/* skip operator */
sep += n;
/* if greater than, look for less than */
sep2 = NULL;
if (op == DEWEY_GT || op == DEWEY_GE) {
if ((sep2 = strchr(sep, '<')) != NULL) {
if ((n = dewey_mktest(&op2, sep2)) < 0) {
return 0;
}
/* compare upper limit */
if (!dewey_cmp(version, op2, sep2+n))
return 0;
}
}
/* compare only pattern / lower limit */
if (sep2) {
char ver[PKG_PATTERN_MAX];
strlcpy(ver, sep, MIN((ssize_t)sizeof(ver), sep2-sep+1));
if (dewey_cmp(version, op, ver))
return 1;
}
else {
if (dewey_cmp(version, op, sep))
return 1;
}
return 0;
}

View File

@@ -40,7 +40,6 @@
#include <errno.h>
#include <fcntl.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
#include "fetch.h"

View File

@@ -35,7 +35,6 @@
#include <string.h>
#include <unistd.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
static int

View File

@@ -29,7 +29,6 @@
#include <errno.h>
#include <stdarg.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -43,9 +42,11 @@
static bool debug;
static struct xbps_handle *xhp;
void
int
xbps_init(struct xbps_handle *xh)
{
int rv;
assert(xh != NULL);
xhp = xh;
@@ -59,6 +60,45 @@ xbps_init(struct xbps_handle *xh)
/* If cachedir not set, defaults to XBPS_CACHE_PATH */
if (xhp->cachedir == NULL)
xhp->cachedir = XBPS_CACHE_PATH;
/* If conffile not set, defaults to XBPS_CONF_PATH */
if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_PATH "/" XBPS_CONF_PLIST;
/*
* Internalize the XBPS_CONF_PLIST dictionary.
*/
xhp->conf_dictionary =
prop_dictionary_internalize_from_file(xhp->conffile);
if (xhp->conf_dictionary == NULL) {
xbps_dbg_printf("%s: cannot internalize conf "
"dictionary: %s\n", strerror(errno));
xbps_end();
return errno;
}
/*
* Initialize repository pool.
*/
if ((rv = xbps_repository_pool_init()) != 0) {
if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize "
"repository pool: %s\n", strerror(rv));
xbps_end();
return rv;
}
}
/*
* Initialize regpkgdb dictionary.
*/
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) {
if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize "
"regpkgdb: %s\n", strerror(rv));
xbps_end();
return rv;
}
}
return 0;
}
void
@@ -67,6 +107,12 @@ xbps_end(void)
xbps_regpkgdb_dictionary_release();
xbps_repository_pool_release();
xbps_fetch_unset_cache_connection();
if (xhp == NULL)
return;
if (prop_object_type(xhp->conf_dictionary) == PROP_TYPE_DICTIONARY)
prop_object_release(xhp->conf_dictionary);
xhp = NULL;
}

161
lib/match.c Normal file
View File

@@ -0,0 +1,161 @@
/* $NetBSD: opattern.c,v 1.5 2009/02/02 12:35:01 joerg Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
*
* 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.
*
* Jordan K. Hubbard
* 18 July 1993
*
* Miscellaneous string utilities.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
#include <ctype.h>
#include <sys/param.h>
#include "xbps_api_impl.h"
/*
* Perform alternate match on "pkg" against "pattern",
* calling pkg_match (recursively) to resolve any other patterns.
* Return 1 on match, 0 otherwise or -1 on error.
*/
static int
alternate_match(const char *pattern, const char *pkg)
{
char *sep;
char buf[PATH_MAX];
char *last;
char *alt;
char *cp;
int cnt;
int found;
if ((sep = strchr(pattern, '{')) == (char *)NULL)
return -1;
(void)strncpy(buf, pattern, (size_t)(sep - pattern));
alt = &buf[sep - pattern];
last = (char *)NULL;
for (cnt = 0, cp = sep; *cp && last == (char *)NULL; cp++) {
if (*cp == '{') {
cnt++;
} else if (*cp == '}' && --cnt == 0 && last == (char *)NULL) {
last = cp + 1;
}
}
if (cnt != 0)
return -1;
for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) {
for (cnt = 0, sep = cp; cnt > 0 || (cnt == 0 && *sep != '}' && *sep != ','); sep++) {
if (*sep == '{') {
cnt++;
} else if (*sep == '}') {
cnt--;
}
}
(void)snprintf(alt, sizeof(buf) - (alt - buf), "%.*s%s", (int)(sep - cp), cp, last);
if (xbps_pkgpattern_match(buf, pkg) == 1)
found = 1;
}
return found;
}
/*
* Perform glob match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
static int
glob_match(const char *pattern, const char *pkg)
{
return fnmatch(pattern, pkg, FNM_PERIOD) == 0;
}
/*
* Perform simple match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
static int
simple_match(const char *pattern, const char *pkg)
{
return strcmp(pattern, pkg) == 0;
}
/*
* Performs a fast check if pattern can ever match pkg.
* Returns 1 if a match is possible and 0 otherwise.
*/
static int
quick_pkg_match(const char *pattern, const char *pkg)
{
#define simple(x) (isalnum((unsigned char)(x)) || (x) == '-')
if (!simple(pattern[0]))
return 1;
if (pattern[0] != pkg[0])
return 0;
if (!simple(pattern[1]))
return 1;
if (pattern[1] != pkg[1])
return 0;
return 1;
#undef simple
}
/*
* Match pkg against pattern, return 1 if matching, 0 otherwise or -1 on error.
*/
int
xbps_pkgpattern_match(const char *pkg, const char *pattern)
{
if (!quick_pkg_match(pattern, pkg))
return 0;
if (strchr(pattern, '{') != (char *)NULL) {
/* emulate csh-type alternates */
return alternate_match(pattern, pkg);
}
if (strpbrk(pattern, "<>") != (char *)NULL) {
/* perform relational dewey match on version number */
return dewey_match(pattern, pkg);
}
if (strpbrk(pattern, "*?[]") != (char *)NULL) {
/* glob match */
if (glob_match(pattern, pkg))
return 1;
}
/* no alternate, dewey or glob match -> simple compare */
if (simple_match(pattern, pkg))
return 1;
/* globbing patterns and simple matches may be specified with or
* without the version number, so check for both cases. */
{
char *pattern_ver;
int retval;
pattern_ver = xbps_xasprintf("%s-[0-9]*", pattern);
if (pattern_ver == NULL)
return -1;
retval = glob_match(pattern_ver, pkg);
free(pattern_ver);
return retval;
}
}

View File

@@ -36,7 +36,6 @@
#include <errno.h>
#include <sys/stat.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
int

View File

@@ -28,7 +28,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/*

View File

@@ -28,7 +28,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -51,21 +50,17 @@
int
xbps_configure_packages(void)
{
prop_dictionary_t d;
const struct xbps_handle *xhp;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *version;
int rv = 0;
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
xhp = xbps_handle_get();
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
if (iter == NULL)
return errno;
iter = xbps_array_iter_from_dict(d, "packages");
if (iter == NULL) {
rv = errno;
goto out;
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
@@ -74,8 +69,6 @@ xbps_configure_packages(void)
break;
}
prop_object_iterator_release(iter);
out:
xbps_regpkgdb_dictionary_release();
return rv;
}

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -162,35 +161,30 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
prop_array_t
xbps_find_pkg_orphans(prop_array_t orphans_user)
{
const struct xbps_handle *xhp;
prop_array_t array = NULL;
prop_dictionary_t dict;
struct orphan_data od;
int rv = 0;
if ((dict = xbps_regpkgdb_dictionary_get()) == NULL)
return NULL;
xhp = xbps_handle_get();
/*
* Prepare an array with all packages previously found.
*/
if ((od.array = prop_array_create()) == NULL)
goto out;
return NULL;
/*
* Find out all orphans by looking at the
* regpkgdb dictionary and iterate in reverse order
* in which packages were installed.
*/
od.orphans_user = orphans_user;
rv = xbps_callback_array_iter_reverse_in_dict(dict, "packages",
find_orphan_pkg, &od);
rv = xbps_callback_array_iter_reverse_in_dict(xhp->regpkgdb_dictionary,
"packages", find_orphan_pkg, &od);
if (rv != 0) {
errno = rv;
prop_object_release(od.array);
array = NULL;
goto out;
return NULL;
}
array = prop_array_copy(od.array);
out:
xbps_regpkgdb_dictionary_release();
return array;
}

View File

@@ -1,272 +0,0 @@
/*-
* Copyright (c) 2011 Juan Romero Pardines.
* All rights reserved.
*
* 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 ``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 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.
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
* @file lib/package_properties.c
* @brief Package properties routines
* @defgroup pkgprops Package property functions
*
* Set and unset global properties for packages in the regpkgdb
* plist file and its "properties" array object.
*/
int
xbps_property_set(const char *key, const char *pkgname)
{
const struct xbps_handle *xhp;
prop_dictionary_t d, repo_pkgd = NULL, pkgd = NULL;
prop_array_t props, provides = NULL, virtual = NULL;
prop_string_t virtualpkg;
char *plist;
int rv = 0;
bool regpkgd_alloc, pkgd_alloc, virtual_alloc, propbool;
assert(key != NULL);
assert(pkgname != NULL);
regpkgd_alloc = pkgd_alloc = virtual_alloc = propbool = false;
xhp = xbps_handle_get();
if ((d = xbps_regpkgdb_dictionary_get()) == NULL) {
/*
* If regpkgdb dictionary doesn't exist, create it
* and the properties array.
*/
d = prop_dictionary_create();
if (d == NULL) {
rv = ENOMEM;
goto out;
}
regpkgd_alloc = true;
props = prop_array_create();
if (props == NULL) {
rv = ENOMEM;
goto out;
}
if (!prop_dictionary_set(d, "properties", props)) {
rv = EINVAL;
prop_object_release(props);
goto out;
}
prop_object_release(props);
}
props = prop_dictionary_get(d, "properties");
if (prop_object_type(props) != PROP_TYPE_ARRAY) {
rv = EINVAL;
goto out;
}
/*
* If package dictionary doesn't exist, create it.
*/
pkgd = xbps_find_pkg_in_array_by_name(props, pkgname);
if (pkgd == NULL) {
pkgd = prop_dictionary_create();
if (pkgd == NULL) {
rv = ENOMEM;
goto out;
}
pkgd_alloc = true;
prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", pkgname);
if (!prop_array_add(props, pkgd)) {
rv = EINVAL;
goto out;
}
}
if (strcmp(key, "virtual") == 0) {
/*
* Sets the "virtual" property in package.
*/
virtual = prop_dictionary_get(pkgd, "provides");
if (virtual == NULL) {
virtual = prop_array_create();
if (virtual == NULL) {
rv = ENOMEM;
goto out;
}
virtual_alloc = true;
virtualpkg = prop_string_create_cstring(pkgname);
if (virtualpkg == NULL) {
rv = ENOMEM;
goto out;
}
prop_string_append_cstring(virtualpkg, ">=0");
prop_dictionary_set(pkgd, "pkgpattern", virtualpkg);
prop_object_release(virtualpkg);
virtualpkg = NULL;
} else {
/* property already set */
xbps_dbg_printf("%s: property `%s' already set!\n",
pkgname, key);
rv = EEXIST;
goto out;
}
/*
* Get the package object from repository pool.
*/
repo_pkgd = xbps_repository_pool_find_pkg(pkgname, false, false);
if (repo_pkgd == NULL) {
xbps_dbg_printf("%s: cannot find pkg dictionary "
"in repository pool.\n", pkgname);
rv = ENOENT;
goto out;
}
provides = prop_dictionary_get(repo_pkgd, "provides");
if (provides == NULL) {
xbps_dbg_printf("%s: pkg dictionary no provides "
"array!\n", pkgname);
prop_object_release(repo_pkgd);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set(pkgd, "provides", provides)) {
prop_object_release(repo_pkgd);
rv = EINVAL;
goto out;
}
prop_object_release(repo_pkgd);
} else if ((strcmp(key, "hold") == 0) ||
(strcmp(key, "update-first") == 0)) {
/*
* Sets the property "key" in package.
*/
if (prop_dictionary_get_bool(pkgd, key, &propbool)) {
rv = EEXIST;
goto out;
}
prop_dictionary_set_bool(pkgd, key, true);
} else {
/* invalid property */
rv = EINVAL;
goto out;
}
/*
* Add array with new properties set into the regpkgdb
* dictionary.
*/
if (!prop_dictionary_set(d, "properties", props)) {
rv = errno;
goto out;
}
/*
* Write regpkgdb dictionary to plist file.
*/
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) {
rv = ENOMEM;
goto out;
}
if (!prop_dictionary_externalize_to_zfile(d, plist)) {
rv = errno;
goto out;
}
out:
if (virtual_alloc)
prop_object_release(virtual);
if (pkgd_alloc)
prop_object_release(pkgd);
if (regpkgd_alloc)
prop_object_release(d);
xbps_regpkgdb_dictionary_release();
return rv;
}
int
xbps_property_unset(const char *key, const char *pkgname)
{
const struct xbps_handle *xhp;
prop_dictionary_t d, pkgd;
prop_array_t props;
char *plist;
int rv = 0;
assert(key != NULL);
assert(pkgname != NULL);
xhp = xbps_handle_get();
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
return ENODEV;
props = prop_dictionary_get(d, "properties");
if (prop_object_type(props) != PROP_TYPE_ARRAY) {
rv = ENODEV;
goto out;
}
pkgd = xbps_find_pkg_in_array_by_name(props, pkgname);
if (pkgd == NULL) {
rv = ENODEV;
goto out;
}
if ((strcmp(key, "virtual") == 0) ||
(strcmp(key, "hold") == 0) ||
(strcmp(key, "update-first") == 0)) {
/* remove the property object matching the key */
prop_dictionary_remove(pkgd, key);
} else {
/* invalid property */
rv = EINVAL;
goto out;
}
/*
* If pkg dictionary does not contain any property, remove
* the object completely.
*/
if (!prop_dictionary_get(d, "virtual") &&
!prop_dictionary_get(d, "hold") &&
!prop_dictionary_get(d, "update-first"))
xbps_remove_pkg_from_array_by_name(props, pkgname);
if (!prop_dictionary_set(d, "properties", props)) {
rv = EINVAL;
goto out;
}
/*
* Write regpkgdb dictionary to plist file.
*/
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) {
rv = ENOMEM;
goto out;
}
if (!prop_dictionary_externalize_to_zfile(d, plist)) {
rv = errno;
goto out;
}
out:
xbps_regpkgdb_dictionary_release();
return rv;
}

View File

@@ -29,7 +29,6 @@
#include <errno.h>
#include <dirent.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -96,31 +95,23 @@ remove_pkg_metadata(const char *pkgname, const char *rootdir)
int
xbps_purge_packages(void)
{
prop_dictionary_t d;
const struct xbps_handle *xhp;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname;
int rv = 0;
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
xhp = xbps_handle_get();
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
if (iter == NULL)
return errno;
iter = xbps_array_iter_from_dict(d, "packages");
if (iter == NULL) {
rv = errno;
goto out;
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_purge_pkg(pkgname, true)) != 0)
break;
}
prop_object_iterator_release(iter);
out:
xbps_regpkgdb_dictionary_release();
return rv;
}
@@ -139,35 +130,31 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
/*
* Firstly let's get the pkg dictionary from regpkgdb.
*/
if ((dict = xbps_regpkgdb_dictionary_get()) == NULL)
pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb_dictionary,
"packages", pkgname);
if (pkgd == NULL)
return errno;
pkgd = xbps_find_pkg_in_dict_by_name(dict, "packages", pkgname);
if (pkgd == NULL) {
rv = errno;
goto out;
}
if (check_state) {
/*
* Skip packages that aren't in "config-files" state.
*/
if ((rv = xbps_pkg_state_dictionary(pkgd, &state)) != 0)
goto out;
return rv;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
goto out;
return rv;
}
/*
* Remove unmodified configuration files.
*/
dict = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
if (dict == NULL) {
rv = errno;
goto out;
}
if (dict == NULL)
return errno;
if (prop_dictionary_get(dict, "conf_files")) {
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
prop_object_release(dict);
goto out;
return rv;
}
}
/*
@@ -178,13 +165,13 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
prop_object_release(dict);
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n",
pkgname, strerror(rv));
goto out;
return rv;
}
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
if (buf == NULL) {
prop_object_release(dict);
rv = ENOMEM;
goto out;
return rv;
}
if (access(buf, X_OK) == 0) {
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
@@ -198,7 +185,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
"REMOVE script: %s\n", pkgname,
strerror(errno));
prop_object_release(dict);
goto out;
return rv;
}
}
}
@@ -210,18 +197,15 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
if ((rv = remove_pkg_metadata(pkgname, xhp->rootdir)) != 0) {
xbps_error_printf("%s: couldn't remove metadata files: %s\n",
pkgname, strerror(rv));
goto out;
return rv;
}
if ((rv = xbps_unregister_pkg(pkgname)) != 0) {
xbps_error_printf("%s: couldn't unregister package: %s\n",
pkgname, strerror(rv));
goto out;
return rv;
}
if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Package %s purged successfully.\n", pkgname);
out:
xbps_regpkgdb_dictionary_release();
return rv;
}

View File

@@ -28,7 +28,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -31,7 +31,6 @@
#include <dirent.h>
#include <libgen.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -33,7 +33,6 @@
#include <unistd.h>
#include <libgen.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
int HIDDEN

View File

@@ -30,7 +30,6 @@
#include <errno.h>
#include <unistd.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
int HIDDEN
@@ -41,7 +40,7 @@ xbps_repository_pkg_replaces(prop_dictionary_t transd,
prop_dictionary_t instd, reppkgd;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pattern;
const char *pattern, *pkgname, *curpkgname;
replaces = prop_dictionary_get(pkg_repod, "replaces");
if (replaces == NULL || prop_array_count(replaces) == 0)
@@ -61,6 +60,16 @@ xbps_repository_pkg_replaces(prop_dictionary_t transd,
instd = xbps_find_pkg_dict_installed(pattern, true);
if (instd == NULL)
continue;
/*
* Check that we are not replacing the same package, due
* to virtual packages.
*/
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(instd, "pkgname", &curpkgname);
if (strcmp(pkgname, curpkgname) == 0) {
prop_object_release(instd);
continue;
}
/*
* Package contains replaces="pkgpattern", but the
* package that should be replaced is also in the

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
static int

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
struct state {

View File

@@ -32,7 +32,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -1,188 +0,0 @@
/*
* FreeBSD install - a package for the installation and maintenance
* of non-core utilities.
*
* 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.
*
* Maxim Sobolev
* 31 July 2001
*
*/
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <limits.h>
#include <fnmatch.h>
#include <xbps_api.h>
#include "config.h"
/**
* @file lib/pkgmatch.c
* @brief Package version matching routines
* @defgroup vermatch Package version matching functions
*/
static int
csh_match(const char *pattern, const char *string, int flags)
{
const char *nextchoice = pattern, *current = NULL;
int ret = FNM_NOMATCH, prefixlen = -1, curlen = 0, level = 0;
do {
const char *pos = nextchoice;
const char *postfix = NULL;
bool quoted = false;
nextchoice = NULL;
do {
const char *eb;
if (!*pos) {
postfix = pos;
} else if (quoted) {
quoted = false;
} else {
switch (*pos) {
case '{':
++level;
if (level == 1) {
current = pos + 1;
prefixlen = pos - pattern;
}
break;
case ',':
if (level == 1 && !nextchoice) {
nextchoice = pos + 1;
curlen = pos - current;
}
break;
case '}':
if (level == 1) {
postfix = pos + 1;
if (!nextchoice)
curlen = pos - current;
}
level--;
break;
case '[':
eb = pos+1;
if (*eb == '!' || *eb == '^')
eb++;
if (*eb == ']')
eb++;
while (*eb && *eb != ']')
eb++;
if (*eb)
pos = eb;
break;
case '\\':
quoted = true;
break;
default:
;
}
}
pos++;
} while (!postfix);
if (current) {
char buf[FILENAME_MAX];
snprintf(buf, sizeof(buf), "%.*s%.*s%s", prefixlen,
pattern, curlen, current, postfix);
ret = csh_match(buf, string, flags);
if (ret) {
current = nextchoice;
level = 1;
} else
current = NULL;
} else
ret = fnmatch(pattern, string, flags);
} while (current);
return ret;
}
int
xbps_pkgpattern_match(const char *instpkg, char *pattern)
{
const char *fname = instpkg;
char *basefname = NULL, condchar = '\0', *condition;
size_t len = 0;
int rv = 0;
/* Check for a full match with strcmp, otherwise try csh_match() */
if (strcmp(instpkg, pattern) == 0)
return 1;
condition = strpbrk(pattern, "><=");
if (condition) {
const char *ch;
if (condition > pattern && condition[-1] == '!')
condition--;
condchar = *condition;
*condition = '\0';
ch = strrchr(fname, '-');
if (ch && ch - fname < PATH_MAX) {
len = ch - fname + 1;
basefname = malloc(len);
if (basefname == NULL)
return -1;
strlcpy(basefname, fname, len);
fname = basefname;
}
}
rv = (csh_match(pattern, fname, 0) == 0) ? 1 : 0;
while (condition) {
*condition = condchar;
if (rv == 1) {
char *nextcondition;
int match = 0;
if (*++condition == '=') {
match = 2;
condition++;
}
switch (condchar) {
case '<':
match |= 1;
break;
case '>':
match |= 4;
break;
case '=':
match |= 2;
break;
case '!':
match = 5;
break;
}
nextcondition = strpbrk(condition, "<>=!");
if (nextcondition) {
condchar = *nextcondition;
*nextcondition = '\0';
}
if ((match &
(1 << (xbps_cmpver(instpkg, condition) + 1))) == 0)
rv = 0;
condition = nextcondition;
} else {
break;
}
}
if (basefname)
free(basefname);
return rv;
}

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -28,9 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <zlib.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/*

View File

@@ -31,7 +31,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
#include "fetch.h"

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -128,7 +127,7 @@ find_pkg_in_array(prop_array_t array, const char *str, bool bypattern)
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
continue;
if (xbps_pkgpattern_match(pkgver, __UNCONST(str)))
if (xbps_pkgpattern_match(pkgver, str))
break;
} else {
if (!prop_dictionary_get_cstring_nocopy(obj,
@@ -165,44 +164,44 @@ xbps_find_pkg_in_array_by_pattern(prop_array_t array, const char *pattern)
}
static const char *
find_virtualpkg_user_in_regpkgdb(const char *virtualpkg, bool bypattern)
find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
{
prop_array_t virtual;
prop_dictionary_t d;
const struct xbps_handle *xhp;
prop_object_iterator_t iter;
prop_object_t obj;
const char *pkg = NULL;
bool found = false;
const char *vpkgver, *pkg = NULL;
char *vpkgname = NULL;
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
xhp = xbps_handle_get();
if ((iter = xbps_array_iter_from_dict(xhp->conf_dictionary,
"package-virtual")) == NULL)
return NULL;
if ((iter = xbps_array_iter_from_dict(d, "properties")) == NULL) {
xbps_regpkgdb_dictionary_release();
return NULL;
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
virtual = prop_dictionary_get(obj, "provides");
if (virtual == NULL)
if (!prop_dictionary_get_cstring_nocopy(obj,
"virtual-pkgver", &vpkgver))
continue;
if (bypattern)
found = xbps_find_pkgpattern_in_array(virtual, virtualpkg);
else
found = xbps_find_pkgname_in_array(virtual, virtualpkg);
if (!found)
continue;
if (bypattern)
prop_dictionary_get_cstring_nocopy(obj,
"pkgpattern", &pkg);
else
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkg);
break;
if (bypattern) {
if (xbps_pkgpattern_match(vpkgver, vpkg)) {
prop_dictionary_get_cstring_nocopy(obj,
"target-pkgpattern", &pkg);
break;
}
} else {
vpkgname = xbps_pkgpattern_name(vpkgver);
if (vpkgname == NULL)
break;
if (strcmp(vpkg, vpkgname) == 0) {
pkg = vpkgname;
free(vpkgname);
break;
}
}
}
prop_object_iterator_release(iter);
xbps_regpkgdb_dictionary_release();
return pkg;
}
@@ -219,7 +218,7 @@ find_virtualpkg_user_in_array(prop_array_t array,
assert(array != NULL);
assert(str != NULL);
virtualpkg = find_virtualpkg_user_in_regpkgdb(str, bypattern);
virtualpkg = find_virtualpkg_user_in_conf(str, bypattern);
if (virtualpkg == NULL)
return NULL;
@@ -231,8 +230,7 @@ find_virtualpkg_user_in_array(prop_array_t array,
if (bypattern) {
prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
if (xbps_pkgpattern_match(pkgver,
__UNCONST(virtualpkg)))
if (xbps_pkgpattern_match(pkgver, virtualpkg))
break;
} else {
prop_dictionary_get_cstring_nocopy(obj,
@@ -303,20 +301,23 @@ xbps_find_virtualpkg_user_in_dict_by_pattern(prop_dictionary_t d,
prop_dictionary_t
xbps_find_pkg_dict_installed(const char *str, bool bypattern)
{
prop_dictionary_t d, pkgd, rpkgd = NULL;
const struct xbps_handle *xhp;
prop_dictionary_t pkgd, rpkgd = NULL;
pkg_state_t state = 0;
assert(str != NULL);
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
xhp = xbps_handle_get();
if (xhp->regpkgdb_dictionary == NULL)
return NULL;
pkgd = find_pkg_in_dict(d, "packages", str, bypattern, false);
pkgd = find_pkg_in_dict(xhp->regpkgdb_dictionary,
"packages", str, bypattern, false);
if (pkgd == NULL)
goto out;
return rpkgd;
if (xbps_pkg_state_dictionary(pkgd, &state) != 0)
goto out;
return rpkgd;
switch (state) {
case XBPS_PKG_STATE_INSTALLED:
@@ -331,8 +332,7 @@ xbps_find_pkg_dict_installed(const char *str, bool bypattern)
default:
break;
}
out:
xbps_regpkgdb_dictionary_release();
return rpkgd;
}
@@ -375,7 +375,7 @@ find_string_in_array(prop_array_t array, const char *str, int mode)
} else if (mode == 2) {
/* match by pkgpattern */
pkgdep = prop_string_cstring_nocopy(obj);
if (xbps_pkgpattern_match(pkgdep, __UNCONST(str))) {
if (xbps_pkgpattern_match(pkgdep, str)) {
found = true;
break;
}

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -28,9 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -58,63 +56,47 @@
* dictionary.
*/
static prop_dictionary_t regpkgdb_dict;
static size_t regpkgdb_refcnt;
static bool regpkgdb_initialized;
static pthread_mutex_t refcnt_mtx = PTHREAD_MUTEX_INITIALIZER;
prop_dictionary_t
xbps_regpkgdb_dictionary_get(void)
int HIDDEN
xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp)
{
const struct xbps_handle *xhp;
char *plist;
if (regpkgdb_initialized) {
pthread_mutex_lock(&refcnt_mtx);
regpkgdb_refcnt++;
pthread_mutex_unlock(&refcnt_mtx);
return regpkgdb_dict;
}
if (regpkgdb_initialized)
return 0;
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL)
return NULL;
return ENOMEM;
regpkgdb_dict = prop_dictionary_internalize_from_zfile(plist);
if (regpkgdb_dict == NULL) {
xhp->regpkgdb_dictionary =
prop_dictionary_internalize_from_zfile(plist);
if (xhp->regpkgdb_dictionary == NULL) {
free(plist);
if (errno != ENOENT)
xbps_dbg_printf("[regpkgdb] cannot internalize "
"regpkgdb_dict %s\n", strerror(errno));
return NULL;
"regpkgdb dictionary: %s\n", strerror(errno));
return errno;
}
free(plist);
regpkgdb_initialized = true;
xbps_dbg_printf("%s: initialized ok.\n", __func__);
pthread_mutex_lock(&refcnt_mtx);
regpkgdb_refcnt = 1;
pthread_mutex_unlock(&refcnt_mtx);
return regpkgdb_dict;
return 0;
}
void
void HIDDEN
xbps_regpkgdb_dictionary_release(void)
{
size_t cnt;
const struct xbps_handle *xhp;
pthread_mutex_lock(&refcnt_mtx);
cnt = regpkgdb_refcnt--;
pthread_mutex_unlock(&refcnt_mtx);
if (cnt != 1)
if (!regpkgdb_initialized)
return;
prop_object_release(regpkgdb_dict);
regpkgdb_dict = NULL;
xhp = xbps_handle_get();
prop_object_release(xhp->regpkgdb_dictionary);
regpkgdb_initialized = false;
xbps_dbg_printf("%s: released ok.\n", __func__);
}

View File

@@ -28,7 +28,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
static int
@@ -36,7 +35,7 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
{
prop_dictionary_t dict;
prop_array_t array;
const char *pkgname, *pkgver, *repoloc;
const char *pkgname, *pkgver, *repoloc, *reason;
int rv = 0;
pkg_state_t state = 0;
@@ -63,15 +62,6 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
prop_object_release(dict);
return errno;
}
/*
* Always set "not-installed" package state. Will be overwritten
* to its correct state later.
*/
rv = xbps_set_pkg_state_dictionary(dict, XBPS_PKG_STATE_NOT_INSTALLED);
if (rv != 0) {
prop_object_release(dict);
return rv;
}
/*
* Overwrite package state in dictionary with same state than the
* package currently uses, otherwise not-installed.
@@ -81,12 +71,27 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
prop_object_release(dict);
return rv;
}
/* pkg not installed */
state = XBPS_PKG_STATE_NOT_INSTALLED;
}
if ((rv = xbps_set_pkg_state_dictionary(dict, state)) != 0) {
prop_object_release(dict);
return rv;
}
/*
* If pkg dependency is already installed, skip it if the transaction
* reason is "install".
*/
if (state == XBPS_PKG_STATE_INSTALLED) {
prop_dictionary_get_cstring_nocopy(repo_pkgd,
"transaction", &reason);
if (strcmp(reason, "install") == 0) {
xbps_dbg_printf("%s: skipping, already installed.\n",
pkgver);
prop_object_release(dict);
return 0;
}
}
/*
* Add required objects into package dep's dictionary.
*/
@@ -321,7 +326,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
break;
}
free(pkgname);
rv = xbps_pkgpattern_match(pkgver_q, __UNCONST(reqpkg));
rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
if (rv == 0) {
/*
* Package is installed but does not match

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
@@ -56,20 +55,18 @@ static int
repository_find_pkg(const char *pattern, const char *reason)
{
prop_dictionary_t pkg_repod = NULL, origin_pkgrd = NULL;
prop_dictionary_t transd, tmpd;
prop_dictionary_t transd;
prop_array_t mdeps, unsorted;
const char *pkgname;
int rv = 0;
bool install, bypattern, bestpkg;
bool bypattern = false, bestpkg;
pkg_state_t state = 0;
assert(pattern != NULL);
assert(reason != NULL);
install = bypattern = false;
if (strcmp(reason, "install") == 0) {
/* install */
install = true;
bypattern = true;
bestpkg = false;
} else {
@@ -109,23 +106,6 @@ repository_find_pkg(const char *pattern, const char *reason)
origin_pkgrd = prop_dictionary_copy(pkg_repod);
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
/*
* Check that this pkg hasn't been added previously into
* the transaction.
*/
if (install) {
tmpd = xbps_find_pkg_in_dict_by_pattern(transd,
"unsorted_pkgs", pattern);
} else {
tmpd = xbps_find_pkg_in_dict_by_name(transd,
"unsorted_pkgs", pattern);
}
if (tmpd) {
xbps_dbg_printf("package '%s' already queued in transaction\n",
pattern);
goto out;
}
/*
* Prepare required package dependencies and add them into the
* "unsorted" array in transaction dictionary.
@@ -193,25 +173,17 @@ out:
int
xbps_repository_update_packages(void)
{
prop_dictionary_t dict;
const struct xbps_handle *xhp;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname;
int rv = 0;
bool newpkg_found = false;
/*
* Prepare dictionary with all registered packages.
*/
dict = xbps_regpkgdb_dictionary_get();
if (dict == NULL)
xhp = xbps_handle_get();
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
if (iter == NULL)
return ENOENT;
iter = xbps_array_iter_from_dict(dict, "packages");
if (iter == NULL) {
xbps_regpkgdb_dictionary_release();
return ENOENT;
}
/*
* Find out if there is a newer version for all currently
* installed packages.
@@ -236,7 +208,6 @@ xbps_repository_update_packages(void)
newpkg_found = true;
}
prop_object_iterator_release(iter);
xbps_regpkgdb_dictionary_release();
if (!newpkg_found)
rv = ENXIO;

View File

@@ -28,11 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
#include "queue.h"
/**
* @file lib/repository_pool.c
@@ -48,56 +45,32 @@ struct repository_pool {
static SIMPLEQ_HEAD(rpool_head, repository_pool) rpool_queue =
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
static size_t repolist_refcnt;
static bool repolist_initialized;
static pthread_mutex_t mtx_refcnt = PTHREAD_MUTEX_INITIALIZER;
int
int HIDDEN
xbps_repository_pool_init(void)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict = NULL;
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter = NULL;
struct repository_pool *rpool;
size_t ntotal = 0, nmissing = 0;
const char *repouri;
char *plist;
int rv = 0;
bool duprepo;
xhp = xbps_handle_get();
xbps_dbg_printf("%s: repolist_refcnt %zu\n", __func__, repolist_refcnt);
if (repolist_initialized) {
pthread_mutex_lock(&mtx_refcnt);
repolist_refcnt++;
pthread_mutex_unlock(&mtx_refcnt);
if (repolist_initialized)
return 0;
}
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL) {
rv = errno;
goto out;
}
dict = prop_dictionary_internalize_from_zfile(plist);
if (dict == NULL) {
rv = errno;
free(plist);
xbps_dbg_printf("%s: cannot internalize plist %s: %s\n",
__func__, plist, strerror(errno));
goto out;
}
free(plist);
array = prop_dictionary_get(dict, "repository-list");
array = prop_dictionary_get(xhp->conf_dictionary, "repositories");
if (array == NULL) {
rv = errno;
goto out;
}
iter = prop_array_iterator(array);
if (iter == NULL) {
rv = errno;
@@ -105,27 +78,58 @@ xbps_repository_pool_init(void)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
/*
* Check that we do not register duplicate repositories.
*/
duprepo = false;
repouri = prop_string_cstring_nocopy(obj);
SIMPLEQ_FOREACH(rpool, &rpool_queue, rp_entries) {
if (strcmp(rpool->rpi->rpi_uri, repouri) == 0) {
duprepo = true;
break;
}
}
if (duprepo)
continue;
plist = xbps_pkg_index_plist(repouri);
if (plist == NULL) {
rv = errno;
goto out;
}
/*
* For remote repositories, check that its pkg-index.plist
* file is there, otherwise we have to fetch it.
*/
if (xbps_check_is_repository_uri_remote(repouri)) {
if ((access(plist, R_OK) == -1) && errno == ENOENT) {
/* file not found, fetch it */
xbps_printf("Synchronizing package index for "
"`%s'...\n", repouri);
if (xbps_repository_sync_pkg_index(repouri) == -1) {
xbps_error_printf("failed to fetch "
"pkg-index.plist for `%s': %s\n",
repouri, xbps_fetch_error_string());
}
}
}
ntotal++;
/*
* Iterate over the repository pool and add the dictionary
* for current repository into the queue.
*/
plist =
xbps_pkg_index_plist(prop_string_cstring_nocopy(obj));
if (plist == NULL) {
rv = errno;
goto out;
}
rpool = malloc(sizeof(struct repository_pool));
if (rpool == NULL) {
rv = errno;
free(plist);
goto out;
}
rpool->rpi = malloc(sizeof(struct repository_pool_index));
if (rpool->rpi == NULL) {
rv = errno;
free(plist);
free(rpool);
goto out;
}
@@ -147,6 +151,8 @@ xbps_repository_pool_init(void)
free(plist);
if (errno == ENOENT) {
errno = 0;
xbps_dbg_printf("%s: missing pkg-index.plist "
"for '%s' repository.\n", __func__, repouri);
nmissing++;
continue;
}
@@ -165,15 +171,10 @@ xbps_repository_pool_init(void)
goto out;
repolist_initialized = true;
pthread_mutex_lock(&mtx_refcnt);
repolist_refcnt = 1;
pthread_mutex_unlock(&mtx_refcnt);
xbps_dbg_printf("%s: initialized ok.\n", __func__);
out:
if (iter)
prop_object_iterator_release(iter);
if (dict)
prop_object_release(dict);
if (rv != 0)
xbps_repository_pool_release();
@@ -181,18 +182,12 @@ out:
}
void
void HIDDEN
xbps_repository_pool_release(void)
{
struct repository_pool *rpool;
size_t cnt;
pthread_mutex_lock(&mtx_refcnt);
cnt = repolist_refcnt--;
pthread_mutex_unlock(&mtx_refcnt);
xbps_dbg_printf("%s: repolist_refcnt %zu\n", __func__, cnt);
if (cnt != 1)
if (!repolist_initialized)
return;
while ((rpool = SIMPLEQ_FIRST(&rpool_queue)) != NULL) {
@@ -221,9 +216,7 @@ xbps_repository_pool_foreach(
bool done = false;
assert(fn != NULL);
if (!repolist_initialized)
return EINVAL;
assert(repolist_initialized != false);
SIMPLEQ_FOREACH_SAFE(rpool, &rpool_queue, rp_entries, rpool_new) {
rv = (*fn)(rpool->rpi, arg, &done);
@@ -354,6 +347,7 @@ xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
int rv = 0;
assert(pkg != NULL);
assert(repolist_initialized != false);
rpf = calloc(1, sizeof(*rpf));
if (rpf == NULL)
@@ -411,15 +405,11 @@ xbps_repository_pool_dictionary_metadata_plist(const char *pkgname,
prop_dictionary_t pkgd = NULL, plistd = NULL;
const char *repoloc;
char *url;
int rv = 0;
assert(pkgname != NULL);
assert(plistf != NULL);
assert(repolist_initialized != false);
if ((rv = xbps_repository_pool_init()) != 0) {
errno = rv;
return NULL;
}
/*
* Iterate over the the repository pool and search for a plist file
* in the binary package named 'pkgname'. The plist file will be
@@ -443,7 +433,6 @@ xbps_repository_pool_dictionary_metadata_plist(const char *pkgname,
free(url);
out:
xbps_repository_pool_release();
if (plistd == NULL)
errno = ENOENT;
if (pkgd)

View File

@@ -1,202 +0,0 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* All rights reserved.
*
* 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 ``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 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libgen.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**
* @file lib/repository_register.c
* @brief Repository registration routines
* @defgroup repo_register Repository registration functions
*/
int
xbps_repository_register(const char *uri)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
prop_array_t array;
prop_object_t obj = NULL;
char *plist;
int rv = 0;
assert(uri != NULL);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL)
return errno;
/* First check if we have the repository plist file. */
dict = prop_dictionary_internalize_from_zfile(plist);
if (dict == NULL) {
/* Looks like not, create it. */
dict = prop_dictionary_create();
if (dict == NULL) {
free(plist);
return errno;
}
/* Create the array and add the repository URI on it. */
array = prop_array_create();
if (array == NULL) {
rv = errno;
goto out;
}
if (!prop_array_set_cstring_nocopy(array, 0, uri)) {
rv = errno;
goto out;
}
/* Add the array obj into the main dictionary. */
if (!xbps_add_obj_to_dict(dict, array, "repository-list")) {
rv = errno;
goto out;
}
xbps_dbg_printf("Added repository into plist: %s\n", uri);
} else {
/* Append into the array, the plist file exists. */
array = prop_dictionary_get(dict, "repository-list");
if (array == NULL) {
rv = errno;
goto out;
}
/* It seems that this object is already there */
if (xbps_find_string_in_array(array, uri)) {
rv = EEXIST;
goto out;
}
obj = prop_string_create_cstring(uri);
if (!xbps_add_obj_to_array(array, obj)) {
prop_object_release(obj);
rv = errno;
goto out;
}
xbps_dbg_printf("Added repository into plist: %s\n", uri);
}
/* Write dictionary into plist file. */
if (!prop_dictionary_externalize_to_zfile(dict, plist)) {
rv = errno;
xbps_dbg_printf("%s: cannot externalize '%s' for '%s': %s\n",
__func__, plist, uri, strerror(errno));
if (obj)
prop_object_release(obj);
}
out:
prop_object_release(dict);
free(plist);
return rv;
}
int
xbps_repository_unregister(const char *uri)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
prop_array_t array;
const char *pkgindexdir;
char *plist, *pkgindex;
int rv = 0;
assert(uri != NULL);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL)
return errno;
dict = prop_dictionary_internalize_from_zfile(plist);
if (dict == NULL) {
free(plist);
return errno;
}
array = prop_dictionary_get(dict, "repository-list");
if (array == NULL) {
rv = errno;
goto out;
}
if (!xbps_remove_string_from_array(array, uri)) {
rv = errno;
goto out;
}
/* Update plist file. */
if (!prop_dictionary_externalize_to_zfile(dict, plist)) {
rv = errno;
goto out;
}
xbps_dbg_printf("Removed repository from plist: %s\n", uri);
/*
* If it's a remote repository, also remove the stored XBPS_PKGINDEX
* file and its directory.
*/
if (xbps_check_is_repository_uri_remote(uri)) {
pkgindex = xbps_pkg_index_plist(uri);
if (pkgindex == NULL) {
rv = errno;
goto out;
}
if (unlink(pkgindex) == -1) {
rv = errno;
if (errno == ENOENT) {
free(pkgindex);
goto out;
}
xbps_dbg_printf("%s cannot remove pkgindex file at "
"%s: %s\n", __func__, pkgindex, strerror(errno));
free(pkgindex);
goto out;
}
pkgindexdir = dirname(pkgindex);
if (rmdir(pkgindexdir) == -1) {
rv = errno;
xbps_dbg_printf("%s: cannot remove pkgindex dir at "
"%s: %s\n", __func__, pkgindexdir, strerror(errno));
free(pkgindex);
goto out;
}
free(pkgindex);
}
out:
prop_object_release(dict);
free(plist);
return rv;
}

View File

@@ -30,7 +30,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
#include "fetch.h"

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**

View File

@@ -28,10 +28,7 @@
#include <string.h>
#include <errno.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
#include "queue.h"
#include "strlcpy.h"
/*
* Sorting algorithm for packages in the transaction dictionary.
@@ -144,12 +141,31 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
static void
pkgdep_end(prop_array_t sorted)
{
prop_dictionary_t sorted_pkgd;
struct pkgdep *pd;
const char *trans;
while ((pd = TAILQ_FIRST(&pkgdep_list)) != NULL) {
TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries);
if (sorted != NULL && pd->d != NULL)
prop_array_add(sorted, pd->d);
if (sorted != NULL && pd->d != NULL) {
/*
* Do not add duplicate pkg dictionaries with the
* same transaction reason into the sorted array.
*/
sorted_pkgd = xbps_find_pkg_in_array_by_name(sorted,
pd->name);
if (sorted_pkgd == NULL) {
prop_array_add(sorted, pd->d);
pkgdep_release(pd);
continue;
}
prop_dictionary_get_cstring_nocopy(sorted_pkgd,
"transaction", &trans);
if (strcmp(trans, pd->trans) == 0) {
pkgdep_release(pd);
continue;
}
}
pkgdep_release(pd);
}
}

View File

@@ -46,7 +46,7 @@
#include "config.h"
#include <openssl/sha.h>
#include <xbps_api.h>
#include "xbps_api_impl.h"
/**