diff options
author | Adrian Vovk <adrianvovk@gmail.com> | 2024-06-22 02:03:12 +0200 |
---|---|---|
committer | Adrian Vovk <adrianvovk@gmail.com> | 2024-08-22 22:00:43 +0200 |
commit | 79348036342e80eefd59e9828c664b95c19319bc (patch) | |
tree | ada57bd374c4520ac4e8cddf58b02691f84b438c /src | |
parent | mkosi: Update to latest (diff) | |
download | systemd-79348036342e80eefd59e9828c664b95c19319bc.tar.xz systemd-79348036342e80eefd59e9828c664b95c19319bc.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/sysupdate/sysupdate-resource.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/sysupdate/sysupdate-resource.c b/src/sysupdate/sysupdate-resource.c index 5b7aee2b54..9430899897 100644 --- a/src/sysupdate/sysupdate-resource.c +++ b/src/sysupdate/sysupdate-resource.c @@ -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; |