From 94c47694509b2ff844cbc1019c65308e51b13291 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Nov 10 2022 09:29:33 +0000 Subject: [PATCH 1/2] fix include path Related: https://pagure.io/koji/issue/3553 --- diff --git a/plugins/builder/kiwi.py b/plugins/builder/kiwi.py index b70a13a..4033b52 100644 --- a/plugins/builder/kiwi.py +++ b/plugins/builder/kiwi.py @@ -197,16 +197,17 @@ class KiwiCreateImageTask(BaseBuildTask): for inc_node in image.getElementsByTagName('include'): path = inc_node.getAttribute('from') if path.startswith('this://'): - path = koji.util.joinpath(desc_path, path[7:]) + path = koji.util.joinpath(os.path.dirname(desc_path), path[7:]) else: # we want to reject other protocols, e.g. file://, https:// # reachingoutside of repo raise koji.GenericError(f"Unhandled include protocol in include path: {path}.") inc = xml.dom.minidom.parse(path) # nosec # every included xml has image root element again - for node in inc.getElementsByTagName('image').childNodes: + for node in list(inc.getElementsByTagName('image')[0].childNodes): if node.nodeName != 'repository': image.appendChild(node) + image.removeChild(inc_node) # remove remaining old repos for old_repo in image.getElementsByTagName('repository'): From 1f22e0c5f2e42ca2c1a0770d97163e2cd07a6a5a Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Nov 10 2022 09:42:30 +0000 Subject: [PATCH 2/2] better error for wrong include xml format --- diff --git a/plugins/builder/kiwi.py b/plugins/builder/kiwi.py index 4033b52..bc216c2 100644 --- a/plugins/builder/kiwi.py +++ b/plugins/builder/kiwi.py @@ -204,9 +204,12 @@ class KiwiCreateImageTask(BaseBuildTask): raise koji.GenericError(f"Unhandled include protocol in include path: {path}.") inc = xml.dom.minidom.parse(path) # nosec # every included xml has image root element again - for node in list(inc.getElementsByTagName('image')[0].childNodes): - if node.nodeName != 'repository': - image.appendChild(node) + try: + for node in list(inc.getElementsByTagName('image')[0].childNodes): + if node.nodeName != 'repository': + image.appendChild(node) + except IndexError: + raise koji.GenericError("Included file needs to contain tag.") image.removeChild(inc_node) # remove remaining old repos