diff options
author | William Pitcock <nenolod@dereferenced.org> | 2017-05-27 21:49:53 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2017-05-27 21:49:53 +0000 |
commit | 693b4bcdb0f22904a521a7c8ac4f13e697dc4d71 (patch) | |
tree | a4cdf39e5c4ad6169bf3a3a261d1c833298238f5 /src/version.c | |
parent | ee5ce7284aef8679fabcf728dd5bd5a17c965798 (diff) | |
download | apk-tools-693b4bcdb0f22904a521a7c8ac4f13e697dc4d71.tar.gz apk-tools-693b4bcdb0f22904a521a7c8ac4f13e697dc4d71.tar.bz2 apk-tools-693b4bcdb0f22904a521a7c8ac4f13e697dc4d71.tar.xz apk-tools-693b4bcdb0f22904a521a7c8ac4f13e697dc4d71.zip |
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.
Diffstat (limited to 'src/version.c')
-rw-r--r-- | src/version.c | 12 |
1 files changed, 10 insertions, 2 deletions
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)); |