From b17d1f13ff81481b56a5f2d0e1b6963d68d73f09 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:09:51 +0200 Subject: [PATCH] fix: rank the owner's copy above shared tree names --- scripts/common.py | 10 +++++++--- tests/test_name_tiebreak.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 8b7ff9c1..01d261bc 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -495,16 +495,20 @@ def _by_affinity(paths: list[str], file_entry: dict, dest_hint: str) -> list[str return paths hint = dest_hint or file_entry.get("path") or file_entry.get("destination") or "" wanted = _affinity_tokens(hint.rsplit("/", 1)[0] if "/" in hint else "") + owners: set[str] = set() for owner in (file_entry.get("source_profile"), file_entry.get("source_emulator")): if owner: - wanted |= _affinity_tokens(str(owner).replace(" ", "")) + owners |= _affinity_tokens(str(owner).replace(" ", "")) sized = any(file_entry.get(k) for k in ("size", "min_size", "max_size")) - def score(path: str) -> tuple[int, int]: + def score(path: str) -> tuple[int, bool, int]: fits = 0 if sized and os.path.exists(path): fits = int(size_fits(file_entry, os.path.getsize(path))) - return fits, len(wanted & _affinity_tokens(path.rsplit("/", 1)[0])) + tokens = _affinity_tokens(path.rsplit("/", 1)[0]) + # The owner's own copy ranks above any shared tree segment: NetherSX2's + # shaders/common/ beat armsx2's own fxaa.fx on two directory tokens. + return fits, bool(owners & tokens), len(wanted & tokens) return sorted(paths, key=score, reverse=True) diff --git a/tests/test_name_tiebreak.py b/tests/test_name_tiebreak.py index 0a5439f4..21a2f782 100644 --- a/tests/test_name_tiebreak.py +++ b/tests/test_name_tiebreak.py @@ -32,5 +32,21 @@ class DeclaredSizeOrders(unittest.TestCase): self.assertEqual(kept, [str(big), str(small)]) + +class OwnerOutranksSharedTree(unittest.TestCase): + def test_the_owners_copy_beats_two_matching_segments(self): + """armsx2's fxaa.fx lost to NetherSX2's under shaders/common/.""" + from common import _by_affinity # noqa: PLC0415 + + paths = [ + "bios/Other/nethersx2/assets/shaders/common/fxaa.fx", + "bios/Other/armsx2/fxaa.fx", + ] + ordered = _by_affinity( + paths, {"name": "fxaa.fx", "source_profile": "armsx2"}, + "pcsx2/resources/shaders/common/fxaa.fx", + ) + self.assertEqual(ordered[0], "bios/Other/armsx2/fxaa.fx") + if __name__ == "__main__": unittest.main()