Skip to content

Commit

Permalink
Merge pull request #1085 from dcermak/systemd-scriptlets
Browse files Browse the repository at this point in the history
Update search regexes for %service_* macros
  • Loading branch information
dirkmueller authored Oct 27, 2023
2 parents 2713543 + 91645e1 commit 302cf9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .packit/rpmlint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ BuildRequires: dash
BuildRequires: /usr/bin/appstream-util
BuildRequires: /usr/bin/checkbashisms
BuildRequires: /usr/bin/desktop-file-validate
# required for the systemd test
BuildRequires: rpm_macro(_unitdir)

%if 0%{?suse_version}
BuildRequires: myspell-en_US
Expand Down
11 changes: 6 additions & 5 deletions rpmlint/checks/SystemdInstallCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ def check(self, pkg):
processed = {'pre': False, 'post': False, 'preun': False, 'postun': False}

escaped_basename = re.escape(Path(fname).name)
PRE_POST_PATTERN = re.compile(r'for service in .*' + escaped_basename)
PREUN_PATTERN = re.compile(r'systemctl --no-reload disable .*' + escaped_basename)
POSTUN_PATTERN = re.compile(r'(systemctl try-restart .*|# Restart of .*)' + escaped_basename)
PRE_PATTERN = re.compile(r'systemd-update-helper mark-install-system-units .*' + escaped_basename)
POST_PATTERN = re.compile(r'systemd-update-helper install-system-units .*' + escaped_basename)
PREUN_PATTERN = re.compile(r'systemd-update-helper remove-system-units .*' + escaped_basename)
POSTUN_PATTERN = re.compile(r'systemd-update-helper mark-restart-system-units .*' + escaped_basename)

for line in pre.split('\n'):
if PRE_POST_PATTERN.search(line):
if PRE_PATTERN.search(line):
processed['pre'] = True
break
for line in post.split('\n'):
if PRE_POST_PATTERN.search(line):
if POST_PATTERN.search(line):
processed['post'] = True
break
for line in preun.split('\n'):
Expand Down
5 changes: 2 additions & 3 deletions test/test_systemd_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rpmlint.checks.SystemdInstallCheck import SystemdInstallCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package, IS_FEDORA_RELEASE
from Testing import CONFIG, get_tested_package


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -14,8 +14,7 @@ def systemdinstallcheck():


@pytest.mark.parametrize('package', ['binary/dnf-automatic'])
@pytest.mark.skipif(IS_FEDORA_RELEASE, reason='Fedora does not define %{_unitdir} rpm macro')
def test_bashisms(tmp_path, package, systemdinstallcheck):
def test_systemd_service_without_service_macro(tmp_path, package, systemdinstallcheck):
output, test = systemdinstallcheck
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
Expand Down

0 comments on commit 302cf9f

Please sign in to comment.