From 870b0e3b31140721701712dc500f7ae53d51f5fd Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Wed, 6 Nov 2024 10:39:59 +0100 Subject: [PATCH] false positive: systemd-service-without-service_del_postun See https://github.com/openSUSE/rpmlint-checks/issues/72 --- rpmlint/checks/SystemdInstallCheck.py | 3 ++- test/test_systemd_install.py | 29 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/rpmlint/checks/SystemdInstallCheck.py b/rpmlint/checks/SystemdInstallCheck.py index 369010e76..ef6aee125 100644 --- a/rpmlint/checks/SystemdInstallCheck.py +++ b/rpmlint/checks/SystemdInstallCheck.py @@ -49,7 +49,8 @@ def check(self, pkg): break # accept %service_del_postun_without_restart() macro - if not processed['postun'] and ':' == postun.strip(): + postun_without_restart = ':' in (i.strip() for i in postun.split('\n')) + if not processed['postun'] and postun_without_restart: processed['postun'] = True basename = Path(fname).name diff --git a/test/test_systemd_install.py b/test/test_systemd_install.py index ee10768f5..755d39af4 100644 --- a/test/test_systemd_install.py +++ b/test/test_systemd_install.py @@ -50,6 +50,35 @@ def test_systemd_service_without_service_macro(tmp_path, package, systemdinstall files=['/usr/lib/systemd/system/greetd.service'], header={}, ), True), + (get_tested_mock_package( + name='MirrorCache', + files=[ + '/usr/lib/systemd/system/mirrorcache-backstage-hashes.service', + '/usr/lib/systemd/system/mirrorcache-backstage.service', + '/usr/lib/systemd/system/mirrorcache-hypnotoad.service', + '/usr/lib/systemd/system/mirrorcache-subtree.service', + '/usr/lib/systemd/system/mirrorcache.service', + ], + header={ + 'PREUN': '/usr/lib/systemd/systemd-update-helper remove-system-units mirrorcache.service mirrorcache-backstage.service mirrorcache-backstage-hashes.service mirrorcache-subtree.service mirrorcache-hypnotoad.service', + 'PREIN': '/usr/lib/systemd/systemd-update-helper mark-install-system-units mirrorcache.service mirrorcache-backstage.service mirrorcache-backstage-hashes.service mirrorcache-subtree.service mirrorcache-hypnotoad.service', + 'POSTIN': '/usr/lib/systemd/systemd-update-helper install-system-units mirrorcache.service mirrorcache-backstage.service mirrorcache-backstage-hashes.service mirrorcache-subtree.service mirrorcache-hypnotoad.service', + 'POSTUN': """ +if [ $1 -ge 1 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then + # Package upgrade, not uninstall + DISABLE_RESTART_ON_UPDATE=no + [ -e /etc/sysconfig/services ] && . /etc/sysconfig/services || : + case "$DISABLE_RESTART_ON_UPDATE" in + yes|1) ;; + *) /usr/lib/systemd/systemd-update-helper mark-restart-system-units mirrorcache.service mirrorcache-backstage.service mirrorcache-backstage-hashes.service mirrorcache-subtree.service || : + esac +fi + +: + +""", + }, + ), False), ]) def test_systemd_service_without_service_macro2(package, error, systemdinstallcheck): output, test = systemdinstallcheck