common: improve performance of find_cached_package

find_cached_package was unnecessarily looping over all packages which
uses a lot of CPU and could be exceptionally slow when PKGDEST contains
a lot of packages.

Fix this by adding the target pkgname, pkgver and arch to the glob and
only process potential candidates.
This commit is contained in:
Felix Yan 2022-10-10 12:53:52 +00:00 committed by Levente Polyak
parent 20f89df443
commit 5d02c6df7f
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 1 additions and 1 deletions

View File

@ -146,7 +146,7 @@ find_cached_package() {
[[ -d $dir ]] || continue
shopt -s extglob nullglob
mapfile -t packages < <(printf "%s\n" "$dir"/*.pkg.tar?(.!(sig|*.*)))
mapfile -t packages < <(printf "%s\n" "$dir"/${targetname}-${targetver}-*${targetarch}.pkg.tar?(.!(sig|*.*)))
shopt -u extglob nullglob
for pkg in "${packages[@]}"; do