From b7542e78bfa1f38005091c04da67ea22aeacdf9d Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Wed, 19 Aug 2026 17:31:43 +0200 Subject: [PATCH] Fixed file-input overrides when adding files with the same name from different sources Ticket: CFE-4741 Changelog: Title Signed-off-by: Simon Halvorsen --- cfbs/build.py | 15 +++++++-------- cfbs/cfbs_config.py | 7 ++++--- tests/test_build.py | 31 +++++++++++++++++-------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/cfbs/build.py b/cfbs/build.py index 0b1e579f..86af077c 100644 --- a/cfbs/build.py +++ b/cfbs/build.py @@ -293,11 +293,11 @@ def _localize_file_inputs(name, input_data, destination, build_modules): module_dir_name = name[2:] if name.startswith("./") else name module_dir_name = os.path.basename(module_dir_name.rstrip("/")) - def _localize(path): - if not path or not os.path.isfile(path): - return path + def _localize(rel_path): + if not rel_path or not os.path.isfile(rel_path): + return rel_path - already_shipped = _path_if_already_shipped(path, build_modules, destination) + already_shipped = _path_if_already_shipped(rel_path, build_modules, destination) if already_shipped is not None: return already_shipped @@ -305,11 +305,10 @@ def _localize(path): destination, "services", "cfbs", - "modules", - module_dir_name, - os.path.basename(path), + "modules" if rel_path.startswith(module_dir_name) else "", + rel_path, ) - cp(path, dest) + cp(rel_path, dest) return "$(sys.inputdir)/" + os.path.relpath(dest, destination) for element in input_data: diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 832eebc9..635f9610 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -605,12 +605,13 @@ def _one_file(): if "while" not in input_data: return _one_file() - result = [_one_file()] + result = {_one_file()} + while prompt_user_yesno( self.non_interactive, input_data["while"], default="no" ): - result.append(_one_file()) - return result + result.add(_one_file()) + return list(result) def _input_elements(subtype): result = OrderedDict() diff --git a/tests/test_build.py b/tests/test_build.py index 210fb549..7400388c 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -20,47 +20,50 @@ def test_localize_file_inputs_copies_single_file(tmp_path, monkeypatch): _localize_file_inputs("run-a-script", input_data, "out/masterfiles", []) - expected_dest = "out/masterfiles/services/cfbs/modules/run-a-script/deploy.sh" + expected_dest = "out/masterfiles/services/cfbs/deploy.sh" assert os.path.isfile(expected_dest) - assert ( - input_data[0]["response"] - == "$(sys.inputdir)/services/cfbs/modules/run-a-script/deploy.sh" - ) + assert input_data[0]["response"] == "$(sys.inputdir)/services/cfbs/deploy.sh" def test_localize_file_inputs_copies_list_of_files(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) os.makedirs("out/masterfiles") + os.makedirs("run-scripts-module") with open("one.sh", "w") as f: f.write("echo one\n") - with open("two.sh", "w") as f: + with open("run-scripts-module/two.sh", "w") as f: f.write("echo two\n") input_data = [ { "type": "file", "variable": "scripts", - "response": ["one.sh", "two.sh"], + "response": ["one.sh", "run-scripts-module/two.sh"], } ] _localize_file_inputs("run-scripts", input_data, "out/masterfiles", []) assert input_data[0]["response"] == [ - "$(sys.inputdir)/services/cfbs/modules/run-scripts/one.sh", - "$(sys.inputdir)/services/cfbs/modules/run-scripts/two.sh", + "$(sys.inputdir)/services/cfbs/one.sh", + "$(sys.inputdir)/services/cfbs/modules/run-scripts-module/two.sh", ] - assert os.path.isfile("out/masterfiles/services/cfbs/modules/run-scripts/one.sh") - assert os.path.isfile("out/masterfiles/services/cfbs/modules/run-scripts/two.sh") + assert os.path.isfile("out/masterfiles/services/cfbs/one.sh") + assert os.path.isfile( + "out/masterfiles/services/cfbs/modules/run-scripts-module/two.sh" + ) def test_localize_file_inputs_strips_local_module_prefix(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) os.makedirs("out/masterfiles") - with open("deploy.sh", "w") as f: + os.makedirs("run-a-script") + with open("run-a-script/deploy.sh", "w") as f: f.write("echo hi\n") - input_data = [{"type": "file", "variable": "script", "response": "deploy.sh"}] + input_data = [ + {"type": "file", "variable": "script", "response": "run-a-script/deploy.sh"} + ] _localize_file_inputs("./run-a-script", input_data, "out/masterfiles", []) @@ -152,7 +155,7 @@ def test_localize_file_inputs_ignores_non_directory_steps(tmp_path, monkeypatch) } ] input_data = [ - {"type": "file", "variable": "script", "response": "./run-scripts/deploy.sh"} + {"type": "file", "variable": "script", "response": "run-scripts/deploy.sh"} ] _localize_file_inputs("run-scripts", input_data, "out/masterfiles", build_modules)