Added support for shell (and csh as well) patterns for required
dependencies, as specified in blueprint "improved-version-matching". It's possible now to require greater, greater or equal than, less, less or equal than, and equal pkg versions, as well as using '{}' and '[^!]' csh patterns in dependencies. Code lifted from FreeBSD, thanks! :-) Change XBPS_RELVER to 20091107 to match latest additions. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091107035620-3051wcwrirqn2g14
This commit is contained in:
@ -13,7 +13,7 @@ OBJS = fetch/common.o fetch/fetch.o fetch/file.o fetch/ftp.o fetch/http.o
|
||||
OBJS += configure.o cmpver.o depends.o download.o fexec.o findpkg.o
|
||||
OBJS += humanize_number.o orphans.o plist.o purge.o register.o remove.o
|
||||
OBJS += repository.o requiredby.o sha256.o sortdeps.o state.o
|
||||
OBJS += sync_remote_pkgidx.o unpack.o util.o
|
||||
OBJS += sync_remote_pkgidx.o unpack.o util.o pkgmatch.o
|
||||
|
||||
ifdef STATIC
|
||||
all: libfetch libxbps.a
|
||||
|
@ -279,11 +279,15 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
||||
/*
|
||||
* Check if required dep is satisfied and installed.
|
||||
*/
|
||||
if (xbps_check_is_installed_pkg(reqpkg) >= 0)
|
||||
if (xbps_check_is_installed_pkg(reqpkg))
|
||||
continue;
|
||||
|
||||
pkgname = xbps_get_pkg_name(reqpkg);
|
||||
reqvers = xbps_get_pkg_version(reqpkg);
|
||||
pkgname = xbps_get_pkgdep_name(reqpkg);
|
||||
reqvers = xbps_get_pkgdep_version(reqpkg);
|
||||
if (pkgname == NULL || reqvers == NULL) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check if package is already added in the
|
||||
* array of unsorted deps.
|
||||
|
170
lib/pkgmatch.c
Normal file
170
lib/pkgmatch.c
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
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 SYMEXPORT
|
||||
xbps_pkgdep_match(const char *instpkg, char *pattern)
|
||||
{
|
||||
const char *fname = instpkg;
|
||||
char basefname[PATH_MAX], condchar = '\0', *condition;
|
||||
int rv = 0;
|
||||
|
||||
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) {
|
||||
strncpy(basefname, fname, ch - fname);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
@ -153,7 +153,7 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
|
||||
prop_array_t rdeps;
|
||||
prop_object_t obj, obj2;
|
||||
prop_object_iterator_t iter, iter2;
|
||||
const char *reqname, *pkgname, *version;
|
||||
const char *reqname, *pkgname, *version, *str;
|
||||
char *rdepname, *fpkgn;
|
||||
int rv = 0;
|
||||
|
||||
@ -176,7 +176,8 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
|
||||
}
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
rdepname = xbps_get_pkg_name(prop_string_cstring_nocopy(obj));
|
||||
str = prop_string_cstring_nocopy(obj);
|
||||
rdepname = xbps_get_pkgdep_name(str);
|
||||
iter2 = prop_array_iterator(regar);
|
||||
if (iter2 == NULL) {
|
||||
free(rdepname);
|
||||
|
@ -62,7 +62,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
|
||||
prop_object_iterator_t iter, iter2;
|
||||
struct sorted_dependency *sdep;
|
||||
size_t ndeps = 0, rundepscnt = 0, cnt = 0;
|
||||
const char *pkgname;
|
||||
const char *pkgname, *str;
|
||||
char *curpkgnamedep;
|
||||
int rv = 0;
|
||||
|
||||
@ -125,8 +125,8 @@ again:
|
||||
* were already added in the sorted list.
|
||||
*/
|
||||
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
|
||||
curpkgnamedep =
|
||||
xbps_get_pkg_name(prop_string_cstring_nocopy(obj2));
|
||||
str = prop_string_cstring_nocopy(obj2);
|
||||
curpkgnamedep = xbps_get_pkgdep_name(str);
|
||||
/*
|
||||
* If dependency is already installed or queued,
|
||||
* pass to the next one.
|
||||
|
66
lib/util.c
66
lib/util.c
@ -32,6 +32,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <limits.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "sha256.h"
|
||||
@ -113,20 +115,21 @@ int SYMEXPORT
|
||||
xbps_check_is_installed_pkg(const char *pkg)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
const char *reqver, *instver;
|
||||
char *pkgname;
|
||||
const char *instver;
|
||||
char *pkgname, *instpkg;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
pkgname = xbps_get_pkg_name(pkg);
|
||||
reqver = xbps_get_pkg_version(pkg);
|
||||
pkgname = xbps_get_pkgdep_name(pkg);
|
||||
if (pkgname == NULL)
|
||||
return -1;
|
||||
|
||||
dict = xbps_find_pkg_installed_from_plist(pkgname);
|
||||
if (dict == NULL) {
|
||||
free(pkgname);
|
||||
return -1; /* not installed */
|
||||
return 0; /* not installed */
|
||||
}
|
||||
|
||||
/*
|
||||
@ -142,15 +145,19 @@ xbps_check_is_installed_pkg(const char *pkg)
|
||||
|
||||
if (state != XBPS_PKG_STATE_INSTALLED) {
|
||||
prop_object_release(dict);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get version from installed package */
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &instver);
|
||||
|
||||
/* Compare installed and required version. */
|
||||
rv = xbps_cmpver(instver, reqver);
|
||||
|
||||
instpkg = xbps_xasprintf("%s-%s", pkgname, instver);
|
||||
if (instpkg == NULL) {
|
||||
prop_object_release(dict);
|
||||
return -1;
|
||||
}
|
||||
/* Check if installed pkg is matched against pkgdep pattern */
|
||||
rv = xbps_pkgdep_match(instpkg, __UNCONST(pkg));
|
||||
free(instpkg);
|
||||
prop_object_release(dict);
|
||||
|
||||
return rv;
|
||||
@ -219,12 +226,49 @@ xbps_get_pkg_name(const char *pkg)
|
||||
len = strlen(pkg) - strlen(tmp) + 1;
|
||||
|
||||
pkgname = malloc(len);
|
||||
memcpy(pkgname, pkg, len - 1);
|
||||
strncpy(pkgname, pkg, len);
|
||||
pkgname[len - 1] = '\0';
|
||||
|
||||
return pkgname;
|
||||
}
|
||||
|
||||
char SYMEXPORT *
|
||||
xbps_get_pkgdep_name(const char *pkg)
|
||||
{
|
||||
char *res, *pkgname;
|
||||
size_t len;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
res = strpbrk(pkg, "><=");
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(pkg) - strlen(res) + 1;
|
||||
pkgname = malloc(len);
|
||||
if (pkgname == NULL)
|
||||
return NULL;
|
||||
|
||||
strncpy(pkgname, pkg, len);
|
||||
pkgname[len - 1] = '\0';
|
||||
|
||||
return pkgname;
|
||||
}
|
||||
|
||||
const char SYMEXPORT *
|
||||
xbps_get_pkgdep_version(const char *pkg)
|
||||
{
|
||||
char *res;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
res = strpbrk(pkg, "><=");
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_pkg_index_remote_plist(const char *uri, const char *machine)
|
||||
{
|
||||
|
Reference in New Issue
Block a user