From 1abc5a39ba26f6ee75c6b806124fb4c520fcaf78 Mon Sep 17 00:00:00 2001 From: Joerg Behrmann Date: Tue, 30 Aug 2022 17:08:05 +0200 Subject: [PATCH] Deduplicate paths in find_config_files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörg Behrmann --- synapse/config/_base.py | 51 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 1f6362aedd..857cefbd43 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -876,35 +876,34 @@ def find_config_files(search_paths: List[str]) -> List[str]: A list of file paths. """ - config_files = [] - if search_paths: - for config_path in search_paths: - if os.path.isdir(config_path): - # We accept specifying directories as config paths, we search - # inside that directory for all files matching *.yaml, and then - # we apply them in *sorted* order. - files = [] - for entry in os.listdir(config_path): - entry_path = os.path.join(config_path, entry) - if not os.path.isfile(entry_path): - err = "Found subdirectory in config directory: %r. IGNORING." - print(err % (entry_path,)) - continue + config_files = {config_path: [] for config_path in search_paths} + for config_path, files in config_files.items(): + if os.path.isdir(config_path): + # We accept specifying directories as config paths, we search + # inside that directory for all files matching *.yaml, and then + # we apply them in *sorted* order. + found_files = [] + for entry in os.listdir(config_path): + entry_path = os.path.join(config_path, entry) + if not os.path.isfile(entry_path): + err = "Found subdirectory in config directory: %r. IGNORING." + print(err % (entry_path,)) + continue - if not entry.endswith(".yaml"): - err = ( - "Found file in config directory that does not end in " - "'.yaml': %r. IGNORING." - ) - print(err % (entry_path,)) - continue + if not entry.endswith(".yaml"): + err = ( + "Found file in config directory that does not end in " + "'.yaml': %r. IGNORING." + ) + print(err % (entry_path,)) + continue - files.append(entry_path) + found_files.append(entry_path) - config_files.extend(sorted(files)) - else: - config_files.append(config_path) - return config_files + files.extend(sorted(found_files)) + else: + files.append(config_path) + return list(itertools.chain(*config_files.values())) @attr.s(auto_attribs=True)