mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 21:43:23 -05:00
fix: keep unsourceable files from matching homonyms
This commit is contained in:
1 parent
94512b5acf
commit
e97c1fbbcc
2 files changed
+38
-3
No files matched your search
+12
-3
@@ -680,7 +680,16 @@ def resolve_local_file(
|
|||||||
file_entry, files_db.get(match_sha1, {}).get("size")
|
file_entry, files_db.get(match_sha1, {}).get("size")
|
||||||
)
|
)
|
||||||
|
|
||||||
if not has_strong_hash:
|
# An entry the profile documents as unsourceable is one the collection
|
||||||
|
# cannot hold: a font that only exists inside a paid package, cheat codes
|
||||||
|
# written per title. A file answering to its name is therefore a homonym
|
||||||
|
# from another system, not a stale dump of the same file - kanji.rom names
|
||||||
|
# an FPseNG font, an openMSX one and a 3DO ROM. Content still decides: the
|
||||||
|
# hash and path steps above run first, so collecting the real bytes makes
|
||||||
|
# the entry resolve.
|
||||||
|
unsourceable = bool(file_entry.get("unsourceable"))
|
||||||
|
|
||||||
|
if not has_strong_hash and not unsourceable:
|
||||||
candidates = []
|
candidates = []
|
||||||
for try_name in names_to_try:
|
for try_name in names_to_try:
|
||||||
for match_sha1 in by_name.get(try_name, []):
|
for match_sha1 in by_name.get(try_name, []):
|
||||||
@@ -751,7 +760,7 @@ def resolve_local_file(
|
|||||||
primary = [p for p, _ in valid if "/.variants/" not in p]
|
primary = [p for p, _ in valid if "/.variants/" not in p]
|
||||||
return (primary[0] if primary else valid[0][0]), "hash_mismatch"
|
return (primary[0] if primary else valid[0][0]), "hash_mismatch"
|
||||||
# No candidate contains the zipped_file -fall through to step 5
|
# No candidate contains the zipped_file -fall through to step 5
|
||||||
else:
|
elif not unsourceable:
|
||||||
primary = [p for p, _ in candidates if "/.variants/" not in p]
|
primary = [p for p, _ in candidates if "/.variants/" not in p]
|
||||||
return (primary[0] if primary else candidates[0][0]), "hash_mismatch"
|
return (primary[0] if primary else candidates[0][0]), "hash_mismatch"
|
||||||
|
|
||||||
@@ -853,7 +862,7 @@ def resolve_local_file(
|
|||||||
return candidate, status
|
return candidate, status
|
||||||
data_dir_mismatch = data_dir_mismatch or candidate
|
data_dir_mismatch = data_dir_mismatch or candidate
|
||||||
|
|
||||||
if data_dir_mismatch:
|
if data_dir_mismatch and not unsourceable:
|
||||||
return data_dir_mismatch, "hash_mismatch"
|
return data_dir_mismatch, "hash_mismatch"
|
||||||
|
|
||||||
# Agnostic fallback: for filename-agnostic files, find any DB file
|
# Agnostic fallback: for filename-agnostic files, find any DB file
|
||||||
|
|||||||
@@ -793,6 +793,32 @@ class TestE2E(unittest.TestCase):
|
|||||||
path, status = resolve_local_file(entry, self.db)
|
path, status = resolve_local_file(entry, self.db)
|
||||||
self.assertEqual(status, "hash_mismatch")
|
self.assertEqual(status, "hash_mismatch")
|
||||||
|
|
||||||
|
def test_07b_resolve_unsourceable_ignores_homonym(self):
|
||||||
|
"""An unsourceable entry takes content, never a file of the same name."""
|
||||||
|
entry = {
|
||||||
|
"name": "wrong_hash.bin",
|
||||||
|
"md5": "ffffffffffffffffffffffffffffffff",
|
||||||
|
"unsourceable": "ships inside a paid application package",
|
||||||
|
}
|
||||||
|
path, status = resolve_local_file(entry, self.db)
|
||||||
|
self.assertIsNone(path)
|
||||||
|
self.assertEqual(status, "not_found")
|
||||||
|
|
||||||
|
entry = {"name": "no_md5.bin", "unsourceable": "written per title"}
|
||||||
|
path, status = resolve_local_file(entry, self.db)
|
||||||
|
self.assertIsNone(path)
|
||||||
|
self.assertEqual(status, "not_found")
|
||||||
|
|
||||||
|
# Collecting the real bytes still resolves it.
|
||||||
|
entry = {
|
||||||
|
"name": "present_req.bin",
|
||||||
|
"sha1": self.files["present_req.bin"]["sha1"],
|
||||||
|
"unsourceable": "ships inside a paid application package",
|
||||||
|
}
|
||||||
|
path, status = resolve_local_file(entry, self.db)
|
||||||
|
self.assertEqual(status, "sha1_exact")
|
||||||
|
self.assertIn("present_req.bin", path)
|
||||||
|
|
||||||
def test_08_resolve_variants_deprioritized(self):
|
def test_08_resolve_variants_deprioritized(self):
|
||||||
entry = {"name": "present_req.bin"}
|
entry = {"name": "present_req.bin"}
|
||||||
path, status = resolve_local_file(entry, self.db)
|
path, status = resolve_local_file(entry, self.db)
|
||||||
|
|||||||
Reference in new issue
Block a user