[Bug] File category is derived from any path segment at any depth, and enum order decides which one wins
RomM version
Observed on 5.2.0. The code path is unchanged on main at the time of writing.
Describe the bug
category_for_path_parts() in backend/handler/filesystem/roms_handler.py matches a category name against every segment of a file's path relative to the library root. Two consequences follow:
- A folder deep inside a console dump whose name happens to equal a category name (
game,demo,patch,mod, …) tags its files with that category, although they are ordinary game data. Wii U and Switch dumps routinely carry such folders insidecontent/. - The result is the first match in
RomFileCategoryenum order, not the outermost folder. SinceGAMEis first in the enum, a baregame/segment anywhere in the path outranks a genuineupdate/ordlc/folder above it.
To Reproduce
roms/wiiu/Some Game/
└─ Some Game [Update]/
└─ content/
└─ Game/
└─ Stats/
└─ archive.bin -> category: gameroms/wiiu/Other Game/
└─ content/
└─ CMCmn/
└─ demo/
└─ effect.szs -> category: demoScan either tree and read the files back (API or rom_files): the nested files carry a category that does not describe them.
Expected behavior The category describes what a file is to the user, so it should be anchored to the folder directly below the ROM's own root, with files nested deeper inheriting from it. Where several segments match, the outermost should win rather than whichever comes first in the enum.
Additional context The field is the natural thing for an API client to filter on — deciding what to download, what to show, what to skip. Today it cannot be trusted for files below the ROM root, and the miscategorisation is silent: the files simply appear under a tag they do not belong to.
Source: rommapp/romm