fix: key filesystem.structure case-insensitively like system.platforms

`system.platforms` lowercases its folder-name keys so lookups ignore case,
but `filesystem.structure` matched `fs_slug` exactly. A folder written the
same way in both blocks (`Atari - 2600`) bound its platform correctly while
its structure template silently did not apply.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-09-07 17:22:23 -04:00
parent 9dcaf89890
commit 3b91f7a112
2 changed files with 22 additions and 2 deletions

View File

@@ -419,13 +419,14 @@ class Config:
"""The custom library structure(s) for a platform, or ``None``.
Opt-in per platform via `filesystem.structure` in config.yml (a map of
``fs_slug -> template`` or ``fs_slug -> [template, ...]``). When unset,
``fs_slug -> template`` or ``fs_slug -> [template, ...]``, keyed
case-insensitively like `system.platforms`). When unset,
the platform uses RomM's default discovery (top-level files and
folders). Returns the parsed structures whose discovery is unioned;
templates are validated at load time, so parsing here is expected to
succeed.
"""
value = getattr(self, "STRUCTURE_TEMPLATES", {}).get(fs_slug)
value = getattr(self, "STRUCTURE_TEMPLATES", {}).get(fs_slug.lower())
if not value:
return None
return parse_platform_structures(value)
@@ -1019,6 +1020,12 @@ class ConfigManager:
"Invalid config.yml: filesystem.structure must be a dictionary"
)
sys.exit(3)
# Folder names are lowercased so lookups ignore case, matching
# `system.platforms`.
self.config.STRUCTURE_TEMPLATES = {
str(fs_slug).lower(): value
for fs_slug, value in self.config.STRUCTURE_TEMPLATES.items()
}
for fs_slug, value in self.config.STRUCTURE_TEMPLATES.items():
is_str = isinstance(value, str)
is_str_list = isinstance(value, list) and all(

View File

@@ -204,6 +204,19 @@ def test_parse_library_structure_names_a_near_miss_terminal():
parse_library_structure("{category}/{gameFolder}")
def test_structure_templates_are_keyed_case_insensitively(monkeypatch, tmp_path):
"""`system.platforms` lowercases its folder names, so `filesystem.structure`
has to as well or the same key works in one block and not the other."""
config_file = tmp_path / "config.yml"
config_file.write_text(
"filesystem:\n structure:\n 'Atari - 2600': '{gameFile}'\n"
)
config = ConfigManager(str(config_file)).get_config()
assert config.platform_structure("Atari - 2600") is not None
assert config.platform_structure("atari - 2600") is not None
def test_parse_platform_structures_string_and_list():
# A bare string yields a single structure.
single = parse_platform_structures("{gameFile}")