From 519162443f91bd2f8dee6782f99e861eb59c37a4 Mon Sep 17 00:00:00 2001 From: majekw Date: Thu, 11 Jun 2020 09:48:10 +0200 Subject: [PATCH] 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 * Update changelogs/fragments/450-slackpkg-package-matching.yml Co-authored-by: Andrew Klychkov Co-authored-by: Felix Fontein Co-authored-by: Andrew Klychkov --- changelogs/fragments/450-slackpkg-package-matching.yml | 2 ++ plugins/modules/packaging/os/slackpkg.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/450-slackpkg-package-matching.yml diff --git a/changelogs/fragments/450-slackpkg-package-matching.yml b/changelogs/fragments/450-slackpkg-package-matching.yml new file mode 100644 index 0000000000..e81115d121 --- /dev/null +++ b/changelogs/fragments/450-slackpkg-package-matching.yml @@ -0,0 +1,2 @@ +bugfixes: + - slackpkg - fix name matching in package installation (https://github.com/ansible-collections/community.general/issues/450). diff --git a/plugins/modules/packaging/os/slackpkg.py b/plugins/modules/packaging/os/slackpkg.py index fcff44a2cb..0ef98c0876 100644 --- a/plugins/modules/packaging/os/slackpkg.py +++ b/plugins/modules/packaging/os/slackpkg.py @@ -67,12 +67,13 @@ from ansible.module_utils.basic import AnsibleModule def query_package(module, slackpkg_path, name): - import glob import platform + import os + import re machine = platform.machine() - packages = glob.glob("/var/log/packages/%s-*-[%s|noarch]*" % (name, - machine)) + pattern = re.compile('^%s-[^-]+-(%s|noarch)-[^-]+$' % (re.escape(name), re.escape(machine))) + packages = [f for f in os.listdir('/var/log/packages') if pattern.match(f)] if len(packages) > 0: return True