From 9cf661ddd274b51802635322fa9e3bac82833c15 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 30 Jul 2024 13:23:46 -0400 Subject: Add pattern matching mode selector to get_wheel_file() * Adds modes WHEEL_MATCH_EXACT and WHEEL_MATCH_ANY --- include/wheel.h | 5 ++++- src/wheel.c | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/wheel.h b/include/wheel.h index 94cf46a..619e0f7 100644 --- a/include/wheel.h +++ b/include/wheel.h @@ -6,6 +6,9 @@ #include #include "str.h" +#define WHEEL_MATCH_EXACT 0 +#define WHEEL_MATCH_ANY 1 + struct Wheel { char *distribution; char *version; @@ -17,5 +20,5 @@ struct Wheel { char *file_name; }; -struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[]); +struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[], unsigned match_mode); #endif //STASIS_WHEEL_H diff --git a/src/wheel.c b/src/wheel.c index 8f48828..b96df57 100644 --- a/src/wheel.c +++ b/src/wheel.c @@ -1,6 +1,6 @@ #include "wheel.h" -struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[]) { +struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[], unsigned match_mode) { DIR *dp; struct dirent *rec; struct Wheel *result = NULL; @@ -38,7 +38,11 @@ struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_ma } } - if (!startswith(rec->d_name, name) || match != pattern_count) { + if (!startswith(rec->d_name, name)) { + continue; + } + + if (match_mode == WHEEL_MATCH_EXACT && match != pattern_count) { continue; } -- cgit