From 1d7d14d82ef2be4fe4fde3514063bb1b873185be Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 12 2020 11:39:26 +0000 Subject: Improve finding the right package when searching by source name Source name are of the type NEVR, ie: name---, so to avoid finding foo1 when we are looking for foo, we've adjusted the logic to look for foo-, but this fails when there is a package such as foo-util. So with this commit, we ensure that the package returned is matching the pattern -. Signed-off-by: Pierre-Yves Chibon --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index bf173fe..c6f4deb 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -24,6 +24,7 @@ Top level of the mdapi aiohttp application. ''' import logging import os +import re import aiosqlite import werkzeug.utils @@ -90,11 +91,14 @@ async def _get_pkg(branch, name=None, action=None, srcname=None): pkg = [Packages(*item) for item in pkg] break elif srcname: + pattern = re.compile(f"{srcname}-[0-9]") async with db.execute(GET_PACKAGE_BY_SRC, (srcname+'-%',)) as cursor: - pkg = await cursor.fetchone() - if pkg: - pkg = Packages(*pkg) - break + pkgc = await cursor.fetchall() + if pkgc: + for pkg_item in pkgc: + if pattern.match(pkg_item[3]): + pkg = Packages(*pkg_item) + break else: async with db.execute(GET_PACKAGE, (name,)) as cursor: pkg = await cursor.fetchone()