osbuild-depsolve-dnf5: Handle null transactions and exclude-specs

The JSON output by go will use 'null' for nil slices, so we need to
use a [] when the field is missing, or when it is set to null.
Previously this was handled by checking the value before iterating but
when the code moved for the directory handling it was changed.

This implements the same behavior in a slightly cleaner way.
This commit is contained in:
Brian C. Lane 2024-04-19 15:34:16 -07:00 committed by Simon de Vlieger
parent 4c3dba0db9
commit ffbf75073a

View file

@ -101,9 +101,11 @@ class Solver():
# Gather up all the exclude packages from all the transactions
exclude_pkgs = []
transactions = arguments.get("transactions", [])
# Return an empty list when 'transactions' key is missing or when it is None
transactions = arguments.get("transactions") or []
for t in transactions:
exclude_pkgs.extend(t.get("exclude-specs", []))
# Return an empty list when 'exclude-specs' key is missing or when it is None
exclude_pkgs.extend(t.get("exclude-specs") or [])
if not exclude_pkgs:
exclude_pkgs = []
@ -358,7 +360,8 @@ class Solver():
def depsolve(self, arguments):
"""depsolve returns a list of the dependencies for the set of transactions
"""
transactions = arguments.get("transactions", [])
# Return an empty list when 'transactions' key is missing or when it is None
transactions = arguments.get("transactions") or []
# collect repo IDs from the request so we know whether to translate gpg key paths
request_repo_ids = set(repo["id"] for repo in arguments.get("repos", []))
root_dir = arguments.get("root_dir")