fix(scan): hash game folders in sorted file order (#5421)

This commit is contained in:
Sam Dornan
2026-10-31 15:32:25 -05:00
committed by GitHub
parent 98553f4164
commit d2f90ebba3
2 changed files with 22 additions and 0 deletions

View File

@@ -665,6 +665,8 @@ class FSRomsHandler(FSHandler):
entries.append((f_path, file_name, os.stat(Path(f_path, file_name))))
except OSError as exc:
log.warning(f"Skipping unreadable file {f_path / file_name}: {exc}")
# Listing order is filesystem-specific; the ROM-level hash must not be.
entries.sort(key=lambda e: Path(e[0], e[1]).as_posix())
return entries
async def converto_active(self, platform_slug: str) -> bool:

View File

@@ -1387,6 +1387,26 @@ class TestFSRomsHandler:
if test_file.exists():
test_file.unlink()
def test_list_rom_dir_sorts_regardless_of_listing_order(
self, handler: FSRomsHandler, config, tmp_path
):
rom_dir = tmp_path / "Order Test (World)"
(rom_dir / "sub").mkdir(parents=True)
for name in ("a.bin", "b.bin", "sub/c.bin"):
(rom_dir / name).write_bytes(b"x")
listing = [(rom_dir, "b.bin"), (rom_dir / "sub", "c.bin"), (rom_dir, "a.bin")]
with patch(
"handler.filesystem.roms_handler.iter_files", return_value=iter(listing)
):
entries = handler._list_rom_dir(rom_dir, config)
assert [(p, n) for p, n, _ in entries] == [
(rom_dir, "a.bin"),
(rom_dir, "b.bin"),
(rom_dir / "sub", "c.bin"),
]
def test_failed_7z_extraction_hashes_only_the_raw_archive(
self, handler: FSRomsHandler, tmp_path
):