Trigger SaltInvocationError when targeting duplicated package names

This commit is contained in:
Pablo Suárez Hernández 2022-05-03 10:46:46 +01:00
parent 72a673ba2c
commit 113e5de656
No known key found for this signature in database
GPG key ID: A9683F02B512C911

View file

@ -12,7 +12,7 @@ import pprint
import salt.utils.data
import salt.utils.versions
import salt.utils.yaml
from salt.exceptions import SaltInvocationError
from salt.exceptions import CommandExecutionError, SaltInvocationError
log = logging.getLogger(__name__)
__SUFFIX_NOT_NEEDED = ("x86_64", "noarch")
@ -27,11 +27,22 @@ def _repack_pkgs(pkgs, normalize=True):
_normalize_name = __salt__["pkg.normalize_name"]
else:
_normalize_name = lambda pkgname: pkgname
return {
repacked_pkgs = {
_normalize_name(str(x)): str(y) if y is not None else y
for x, y in salt.utils.data.repack_dictlist(pkgs).items()
}
# Check if there were collisions in names
if len(pkgs) != len(repacked_pkgs):
raise CommandExecutionError(
"You are passing a list of packages that contains duplicated packages names: {}. This cannot be processed. In case you are targeting different versions of the same package, please target them individually".format(
pkgs
)
)
return repacked_pkgs
def pack_sources(sources, normalize=True):
"""