xbps: backport another patch from git.

This commit is contained in:
Juan RP 2013-11-17 12:30:27 +01:00
parent 84879f99db
commit 37d129f87d
2 changed files with 95 additions and 1 deletions

View file

@ -0,0 +1,94 @@
From c9825feb2948476064d895043ef84ebc1a2893a3 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 17 Nov 2013 12:25:02 +0100
Subject: [PATCH] util.c: add stricter checks for pkgver conformance (v2).
There was another case where it now was failing: "fs-utils-v1.00_1".
Previous code didn't take into account that a valid version might also
contain a non digit after '-'.
Added more tests to the testsuite to verify its correctness.
---
lib/util.c | 28 ++++++++++++++++++++--------
tests/xbps/libxbps/util/main.c | 3 +++
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index c2593c3..dcea8a9 100644
--- lib/util.c
+++ lib/util.c
@@ -93,14 +93,20 @@ const char *
xbps_pkg_version(const char *pkg)
{
const char *p;
+ bool valid = false;
if ((p = strrchr(pkg, '-')) == NULL)
return NULL;
- if (!isdigit((unsigned char)p[1]))
- return NULL;
-
- if (strchr(p, '_') == NULL)
+ for (unsigned int i = 0; i < strlen(p); i++) {
+ if (p[i] == '_')
+ break;
+ if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
+ valid = true;
+ break;
+ }
+ }
+ if (!valid)
return NULL;
return p + 1; /* skip first '_' */
@@ -129,14 +135,20 @@ xbps_pkg_name(const char *pkg)
const char *p;
char *buf;
unsigned int len;
+ bool valid = false;
if ((p = strrchr(pkg, '-')) == NULL)
return NULL;
- if (!isdigit((unsigned char)p[1]))
- return NULL;
-
- if (strchr(p, '_') == NULL)
+ for (unsigned int i = 0; i < strlen(p); i++) {
+ if (p[i] == '_')
+ break;
+ if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
+ valid = true;
+ break;
+ }
+ }
+ if (!valid)
return NULL;
len = strlen(pkg) - strlen(p) + 1;
diff --git a/tests/xbps/libxbps/util/main.c b/tests/xbps/libxbps/util/main.c
index cc1cb65..5a720eb 100644
--- tests/libxbps/util/main.c
+++ tests/libxbps/util/main.c
@@ -41,6 +41,8 @@ ATF_TC_BODY(util_test, tc)
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-7.8"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("python-e_dbus"), NULL);
+ ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v1"), NULL);
+ ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v_1"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-7.8"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus"), NULL);
@@ -52,6 +54,7 @@ ATF_TC_BODY(util_test, tc)
ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-7.8_2"), "7.8_2");
ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), "1.8_blah");
ATF_REQUIRE_STREQ(xbps_pkg_version("python-e_dbus-1_1"), "1_1");
+ ATF_REQUIRE_STREQ(xbps_pkg_version("fs-utils-v1_1"), "v1_1");
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0");
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");
--
1.8.4.1

View file

@ -1,7 +1,7 @@
# Template file for 'xbps'
pkgname=xbps
version=0.26.2
revision=2
revision=3
build_style=configure
configure_args="--prefix=/usr --sysconfdir=/etc --enable-static --enable-debug"
makedepends="zlib-devel openssl-devel libarchive-devel>=3.1.2 confuse-devel"