Skip to content

Commit

Permalink
Fix: Prevent full system upgrade in pkg.installed for Arch Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Akm0d committed Mar 21, 2024
1 parent 637fe0b commit 0b39efa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion salt/modules/pacmanpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/modules/test_pacmanpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit 0b39efa

Please sign in to comment.