From 693b4bcdb0f22904a521a7c8ac4f13e697dc4d71 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 27 May 2017 21:49:53 +0000 Subject: version: add support for fuzzy version matching This is useful for requirements such as: python3=~3.6, which would match python3-3.6.[0-9]. This implementation should in theory be backwards compatible with the implementation in Adelie. --- src/version.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/version.c') diff --git a/src/version.c b/src/version.c index eaac762..9bd96cb 100644 --- a/src/version.c +++ b/src/version.c @@ -145,6 +145,9 @@ const char *apk_version_op_string(int mask) return "<"; case APK_VERSION_LESS|APK_VERSION_EQUAL: return "<="; + case APK_VERSION_EQUAL|APK_VERSION_FUZZY: + case APK_VERSION_FUZZY: + return "~"; case APK_VERSION_EQUAL: return "="; case APK_VERSION_GREATER|APK_VERSION_EQUAL: @@ -186,7 +189,7 @@ int apk_version_validate(apk_blob_t ver) return t == TOKEN_END; } -int apk_version_compare_blob(apk_blob_t a, apk_blob_t b) +int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy) { int at = TOKEN_DIGIT, bt = TOKEN_DIGIT, tt; int av = 0, bv = 0; @@ -215,7 +218,7 @@ int apk_version_compare_blob(apk_blob_t a, apk_blob_t b) return APK_VERSION_GREATER; /* both have TOKEN_END or TOKEN_INVALID next? */ - if (at == bt) + if (at == bt || fuzzy) return APK_VERSION_EQUAL; /* if only difference is pkgrev, they are equal. */ @@ -240,6 +243,11 @@ int apk_version_compare_blob(apk_blob_t a, apk_blob_t b) return APK_VERSION_EQUAL; } +int apk_version_compare_blob(apk_blob_t a, apk_blob_t b) +{ + return apk_version_compare_blob_fuzzy(a, b, FALSE); +} + int apk_version_compare(const char *str1, const char *str2) { return apk_version_compare_blob(APK_BLOB_STR(str1), APK_BLOB_STR(str2)); -- cgit v1.2.3-70-g09d2