sysupdate: Fix resource_find_instance

The current implementation will never find a match, because in the event
of a match instance_cmp falls through to comparing paths and the key
we're matching against will always have a path of NULL.

So let's just use a separate compare function, just to make sure future
updates to instance_cmp don't break resource_find_instance again.
This commit is contained in:
Adrian Vovk
2024-08-22 16:00:43 -04:00
parent f134a79ff8
commit 7934803634
+13 -1
View File
@@ -527,13 +527,25 @@ int resource_load_instances(Resource *rr, bool verify, Hashmap **web_cache) {
return 0;
}
static int instance_version_match(Instance *const*a, Instance *const*b) {
assert(a);
assert(b);
assert(*a);
assert(*b);
assert((*a)->metadata.version);
assert((*b)->metadata.version);
/* List is sorted newest-to-oldest */
return -strverscmp_improved((*a)->metadata.version, (*b)->metadata.version);
}
Instance* resource_find_instance(Resource *rr, const char *version) {
Instance key = {
.metadata.version = (char*) version,
}, *k = &key;
Instance **found;
found = typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_cmp);
found = typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_version_match);
if (!found)
return NULL;