pacman: Fail fast when 'rc != 0'
We fail-fast and display 'stderr' in case 'pacman' returns with 'rc != 0'. There is no point computing 'module._diff' in such case anyway. Fixes #23910
This commit is contained in:
parent
58666c0ca4
commit
8c6a2a848c
1 changed files with 11 additions and 9 deletions
|
@ -256,6 +256,9 @@ def remove_packages(module, pacman_path, packages):
|
|||
cmd = "%s -%s %s --noconfirm --noprogressbar" % (pacman_path, args, package)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to remove %s" % (package))
|
||||
|
||||
if module._diff:
|
||||
d = stdout.split('\n')[2].split(' ')[2:]
|
||||
for i, pkg in enumerate(d):
|
||||
|
@ -263,9 +266,6 @@ def remove_packages(module, pacman_path, packages):
|
|||
diff['before'] += "%s\n" % pkg
|
||||
data.append('\n'.join(d))
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to remove %s" % (package))
|
||||
|
||||
remove_c += 1
|
||||
|
||||
if remove_c > 0:
|
||||
|
@ -303,6 +303,10 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
|||
if to_install_repos:
|
||||
cmd = "%s -S %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_repos))
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
|
||||
|
||||
data = stdout.split('\n')[3].split(' ')[2:]
|
||||
data = [ i for i in data if i != '' ]
|
||||
for i, pkg in enumerate(data):
|
||||
|
@ -310,14 +314,15 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
|||
if module._diff:
|
||||
diff['after'] += "%s\n" % pkg
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
|
||||
|
||||
install_c += len(to_install_repos)
|
||||
|
||||
if to_install_files:
|
||||
cmd = "%s -U %s --noconfirm --noprogressbar --needed" % (pacman_path, " ".join(to_install_files))
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
|
||||
|
||||
data = stdout.split('\n')[3].split(' ')[2:]
|
||||
data = [ i for i in data if i != '' ]
|
||||
for i, pkg in enumerate(data):
|
||||
|
@ -325,9 +330,6 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
|||
if module._diff:
|
||||
diff['after'] += "%s\n" % pkg
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
|
||||
|
||||
install_c += len(to_install_files)
|
||||
|
||||
if state == 'latest' and len(package_err) > 0:
|
||||
|
|
Loading…
Add table
Reference in a new issue