From 1d7d14d82ef2be4fe4fde3514063bb1b873185be Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 12 2020 11:39:26 +0000 Subject: [PATCH 1/2] 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() From d0dc80485274310c5e6d261228564ee1fbb63f35 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 12 2020 11:41:44 +0000 Subject: [PATCH 2/2] Avoid overriding the pkg variable since it's the one returned Otherwise, we end up returning something which is not what the rest of the code expects Signed-off-by: Pierre-Yves Chibon --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index c6f4deb..d9c811e 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -86,9 +86,9 @@ async def _get_pkg(branch, name=None, action=None, srcname=None): # user. query = GET_PACKAGE_BY.format(action) async with db.execute(query, (name,)) as cursor: - pkg = await cursor.fetchall() - if pkg: - pkg = [Packages(*item) for item in pkg] + pkgc = await cursor.fetchall() + if pkgc: + pkg = [Packages(*item) for item in pkgc] break elif srcname: pattern = re.compile(f"{srcname}-[0-9]") @@ -101,9 +101,9 @@ async def _get_pkg(branch, name=None, action=None, srcname=None): break else: async with db.execute(GET_PACKAGE, (name,)) as cursor: - pkg = await cursor.fetchone() - if pkg: - pkg = Packages(*pkg) + pkgc = await cursor.fetchone() + if pkgc: + pkg = Packages(*pkgc) break if wrongdb: raise web.HTTPBadRequest()