diff --git a/src/selfextract.nim b/src/selfextract.nim index 7ed45bb3..b5ada9a7 100644 --- a/src/selfextract.nim +++ b/src/selfextract.nim @@ -390,8 +390,12 @@ proc handleConfigLoad*(inpath: string) = if not alreadyCached or replace: let + lines = newEmbedded.splitLines() useLine = "use " & module & " from \"" & base & "\"" - withUse = newEmbedded & "\n" & useLine + withUse = if useLine in lines: + newEmbedded + else: + newEmbedded & "\n" & useLine newEmbedded = withUse.strip() if chalkConfig.loadConfig.getParamsViaStdin(): diff --git a/tests/chalk/runner.py b/tests/chalk/runner.py index 18af5921..5ae64850 100644 --- a/tests/chalk/runner.py +++ b/tests/chalk/runner.py @@ -352,10 +352,14 @@ def delete(self, artifact: Path) -> ChalkProgram: log_level="error", ) - def dump(self, path: Path) -> ChalkProgram: - assert not path.is_file() - result = self.run(command="dump", params=[str(path)]) - assert path.is_file() + def dump(self, path: Optional[Path] = None) -> ChalkProgram: + args: list[str] = [] + if path is not None: + assert not path.is_file() + args = [str(path)] + result = self.run(command="dump", params=args) + if path is not None: + assert path.is_file() return result def load( diff --git a/tests/test_config.py b/tests/test_config.py index 7824ec46..5071cb13 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -140,6 +140,21 @@ def test_load_url( ) +def test_load_duplicate( + chalk_copy: Chalk, + server_chalkdust: str, +): + """ + even if same component is loaded multiple times, it should be referenced once + """ + for _ in range(4): + chalk_copy.load( + f"{server_chalkdust}/debug.c4m", + ) + config = chalk_copy.dump() + assert len(config.text.splitlines()) == 1 + + # tests for configs that are found in the chalk search path # these configs are NOT loaded directly into the binary # as these configs are global across the system,