From 0b39efa47cfef786449eae678a6592807dc20fca Mon Sep 17 00:00:00 2001 From: Tyler Levy Conde Date: Thu, 21 Mar 2024 12:05:02 -0600 Subject: [PATCH] Fix: Prevent full system upgrade in pkg.installed for Arch Linux This change modifies the logic in the pacman module to only append the '-u' flag to the pacman command if sysupgrade is explicitly set to True. This prevents the pkg.installed state from triggering a full system upgrade by default on Arch Linux systems. --- salt/modules/pacmanpkg.py | 2 +- tests/unit/modules/test_pacmanpkg.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/salt/modules/pacmanpkg.py b/salt/modules/pacmanpkg.py index 462ca405a54d..25c5b0ffa363 100644 --- a/salt/modules/pacmanpkg.py +++ b/salt/modules/pacmanpkg.py @@ -551,7 +551,7 @@ def install(name=None, cmd.append('-S') if refresh is True: cmd.append('-y') - if sysupgrade is True or (sysupgrade is None and refresh is True): + if sysupgrade is True: cmd.append('-u') cmd.extend(['--noprogressbar', '--noconfirm', '--needed']) wildcards = [] diff --git a/tests/unit/modules/test_pacmanpkg.py b/tests/unit/modules/test_pacmanpkg.py index 80c863c6a5e6..f457ccbde397 100644 --- a/tests/unit/modules/test_pacmanpkg.py +++ b/tests/unit/modules/test_pacmanpkg.py @@ -131,3 +131,16 @@ def test_group_diff(self): }): results = pacman.group_diff('testgroup') self.assertEqual(results['default'], {'installed': ['A'], 'not installed': ['C']}) + + def test_pkg_installed_sysupgrade_flag(self): + ''' + Test if the pkg.installed state appends the '-u' flag only when sysupgrade is True + ''' + with patch.dict(pacman.__salt__, {'cmd.run': MagicMock()}): + pacman.pkg_installed(name='somepkg', sysupgrade=True) + args, kwargs = pacman.__salt__['cmd.run'].call_args + self.assertIn('-u', args[0]) + + pacman.pkg_installed(name='somepkg', sysupgrade=None, refresh=True) + args, kwargs = pacman.__salt__['cmd.run'].call_args + self.assertNotIn('-u', args[0])