Fetch the correct package instead of the first one

When running the patch-builder command with a recipe that includes
packages with similar names to other packages in the base-bullseye.lst,
the code would fetch the first one instead of the correct one. This
change verifies if the package name matches with the package specified
in the patch recipe bofore adding it to the patch.

Test plan:
    PASS - Run patch-builder with packages `gcc` and `cpp`, check if
    correct packages are inside the patch.
    PASS - Run patch-builder with all binaries packages on base-bullseye
    and check if correct packages are inside the patch.
    PASS - Run patch-builder with non-existent package and check if
    warning is shown.

Closes-bug: 2085579

Change-Id: Iee9de9db4ffa79fcfd3bb925258497ea98755770
Signed-off-by: Dostoievski Batista <dostoievski.albinobatista@windriver.com>
This commit is contained in:
Dostoievski Batista 2024-10-24 19:19:13 -03:00
parent 22c2395a58
commit 3e65abd54b

View File

@ -152,10 +152,14 @@ class FetchDebs(object):
logger.debug(f'checking {pkg}')
with open(package_list, 'r') as f:
for line in f.readlines():
if pkg in line:
if pkg == line.split()[0]:
logger.debug(f'Line for package {pkg} found')
pkg_entry = ' '.join(line.split()[:2])
logger.debug(f'Adding "{pkg_entry}" to be downloaded')
all_debs.add(pkg_entry)
break
else:
logger.warning(f"Package '{pkg}' not found in the package list")
logger.debug('Binary packages to download:%s', all_debs)
fetch_ret = self.download(all_debs)