mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 21:43:23 -05:00
fix: rank the owner's copy above shared tree names
This commit is contained in:
1 parent
87addda6e1
commit
64ed737ec6
2 files changed
+23
-3
No files matched your search
+7
-3
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user