1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

slackpkg: fix name matching in package installation (#450) (#454)

* slackpkg: fix name matching in package installation (#450)

* Escape re parameters and optimize matching as suggested in code review.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/450-slackpkg-package-matching.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
majekw 2020-06-11 09:48:10 +02:00 committed by GitHub
parent 7fd989f7f0
commit 519162443f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- slackpkg - fix name matching in package installation (https://github.com/ansible-collections/community.general/issues/450).

View file

@ -67,12 +67,13 @@ from ansible.module_utils.basic import AnsibleModule
def query_package(module, slackpkg_path, name): def query_package(module, slackpkg_path, name):
import glob
import platform import platform
import os
import re
machine = platform.machine() machine = platform.machine()
packages = glob.glob("/var/log/packages/%s-*-[%s|noarch]*" % (name, pattern = re.compile('^%s-[^-]+-(%s|noarch)-[^-]+$' % (re.escape(name), re.escape(machine)))
machine)) packages = [f for f in os.listdir('/var/log/packages') if pattern.match(f)]
if len(packages) > 0: if len(packages) > 0:
return True return True