mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
refactor: name each variant by its md5 prefix
This commit is contained in:
1 parent
f6a509aacc
commit
ed3f61db5d
321 files changed
+97
-23
No files matched your search
@@ -53,7 +53,7 @@ MIN_EXTRA = 1
|
||||
# Kept as they are: rewriting them would drop bytes the collection holds
|
||||
# nowhere else, or they are another emulator's archive under a MAME set name.
|
||||
KEPT = {
|
||||
"bios/Acorn/BBC Micro/.variants/bbcb.zip": (
|
||||
"bios/Acorn/BBC Micro/.variants/bbcb.zip.224779dc": (
|
||||
"MAME 0.150's bbcb loads its DFS ROMs from the machine archive "
|
||||
"(src/mess/drivers/bbc.c ROM_START(bbcb)), older than every imported "
|
||||
"listxml; zdfs-0.90.rom is held only here"
|
||||
|
||||
@@ -1168,7 +1168,8 @@ class ABoardIsAnArcadeMachine(unittest.TestCase):
|
||||
|
||||
|
||||
class TheDreamcastBoardsAreFiledByBoard(unittest.TestCase):
|
||||
"""6.5: the NAOMI and Atomiswave sets under the Dreamcast folder."""
|
||||
"""6.5: the NAOMI sets under the Dreamcast folder. The Atomiswave
|
||||
variants left it for the folder of their primary, Arcade/Arcade."""
|
||||
|
||||
def test_the_board_sets_left_the_dreamcast(self) -> None:
|
||||
sega = _system_page("sega")
|
||||
@@ -1176,7 +1177,6 @@ class TheDreamcastBoardsAreFiledByBoard(unittest.TestCase):
|
||||
for name in ("naomi.zip", "awbios.zip", "naomi2.zip"):
|
||||
self.assertNotIn(f"<code>{name}</code>", dreamcast)
|
||||
self.assertIn("(/retrobios/systems/arcade-sega-naomi/)", dreamcast)
|
||||
self.assertIn("(/retrobios/systems/arcade-sammy-atomiswave/)", dreamcast)
|
||||
|
||||
def test_every_naomi_set_is_on_its_board(self) -> None:
|
||||
db = _database()
|
||||
|
||||
@@ -420,7 +420,7 @@ class EveryFolderIsTheReviewsFolder(_World):
|
||||
f"card/{name}", self.db, platform_hashes, self.profile_hashes)
|
||||
entry = self.entry(name)
|
||||
folder = self.data["folders"][entry["f"]]
|
||||
expected = (f"{folder}.variants/{entry['t']}.{sha1(data)[:8]}" if entry.get("v")
|
||||
expected = (f"{folder}.variants/{entry['t']}.{md5(data)[:8]}" if entry.get("v")
|
||||
else folder + entry["t"])
|
||||
self.assertEqual(result.destination, expected)
|
||||
self.assertEqual(self.data["folders"][self.entry("b.bin")["f"]], "bios/Maker/Console/")
|
||||
@@ -528,7 +528,7 @@ class ThePageReadsTheListAsTheResolverDoes(_World):
|
||||
"https://github.com/Abdess/retrobios/upload/main/bios/Maker/Console")
|
||||
variant = self._page(VARIANT, "v.bin")["place"]
|
||||
self.assertEqual(variant, {"folder": "bios/Maker/Console/.variants/",
|
||||
"name": f"v.bin.{sha1(VARIANT)[:8]}"})
|
||||
"name": f"v.bin.{md5(VARIANT)[:8]}"})
|
||||
|
||||
def test_a_dropped_file_meets_a_name_only_entry_by_its_name(self):
|
||||
out = json.loads(_node(
|
||||
|
||||
@@ -170,7 +170,7 @@ class AFileOnlyACoreReadsIsKnown(_Fixture):
|
||||
self._bios_file("bios/Maker/Console/b.bin", b"another")
|
||||
self.assertEqual(
|
||||
review.validate_file("Downloads/b.bin", db, EMPTY_HASHES, known).destination,
|
||||
f"bios/Maker/Console/.variants/b.bin.{result.sha1[:8]}",
|
||||
f"bios/Maker/Console/.variants/b.bin.{result.md5[:8]}",
|
||||
)
|
||||
# Copied under the declared name, never over a file, and only once.
|
||||
card = self._bios_file("card/B.BIN", missing)
|
||||
@@ -207,7 +207,7 @@ class ADeclaredFileBesideItsHeldNameIsAVariant(_Fixture):
|
||||
known = load_profile_hashes(str(emulators), db)
|
||||
result = review.validate_file(
|
||||
self._bios_file("card/v.bin", data), db, EMPTY_HASHES, known)
|
||||
slot = f"bios/Maker/Console/.variants/v.bin.{result.sha1[:8]}"
|
||||
slot = f"bios/Maker/Console/.variants/v.bin.{result.md5[:8]}"
|
||||
self.assertEqual(result.destination, slot)
|
||||
self.assertIn(("WARN", "File is not under bios/ yet. The collection keeps this name in "
|
||||
f"`bios/Maker/Console/`. --place copies it to `{slot}`"),
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""A .variants/ copy is named <name>.<first 8 hex digits of its md5>.
|
||||
|
||||
Four forms had grown side by side: the md5 prefix the docs named, the sha1
|
||||
prefix validate_pr wrote, a crc32, no suffix at all, and hiscore_<sha1>.dat.
|
||||
A name cut from another digest cannot be checked against the bytes, and a
|
||||
copy with no suffix collides with the next revision of the same name.
|
||||
Reads the repository: skips outside a git checkout.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from resolve.lookup import variant_base_name
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
TAG = re.compile(r"\.([0-9a-f]{8})$")
|
||||
|
||||
|
||||
def misnamed(path: Path, data: bytes) -> str | None:
|
||||
"""Why *path*, a .variants/ copy holding *data*, breaks the rule, or None."""
|
||||
tag = TAG.search(path.name)
|
||||
if tag is None:
|
||||
return "no md5 suffix"
|
||||
if tag.group(1) != hashlib.md5(data).hexdigest()[:8]:
|
||||
return f"suffix {tag.group(1)} is not the md5 prefix"
|
||||
if not variant_base_name(path.name):
|
||||
return "no name before the suffix"
|
||||
return None
|
||||
|
||||
|
||||
class VariantNameRule(unittest.TestCase):
|
||||
def test_the_rule(self):
|
||||
data = b"revision"
|
||||
good = f"rom.bin.{hashlib.md5(data).hexdigest()[:8]}"
|
||||
self.assertIsNone(misnamed(Path(good), data))
|
||||
self.assertEqual(misnamed(Path("rom.bin"), data), "no md5 suffix")
|
||||
sha1_tag = f"rom.bin.{hashlib.sha1(data).hexdigest()[:8]}"
|
||||
self.assertIn("not the md5 prefix", misnamed(Path(sha1_tag), data))
|
||||
self.assertEqual(misnamed(Path("hiscore_2be55274.dat"), data), "no md5 suffix")
|
||||
|
||||
|
||||
class TrackedVariantsFollowTheRule(unittest.TestCase):
|
||||
def test_every_tracked_variant(self):
|
||||
if not (REPO_ROOT / ".git").exists():
|
||||
self.skipTest("not a git checkout")
|
||||
out = subprocess.run(
|
||||
["git", "ls-files", "-z", "bios"], cwd=REPO_ROOT,
|
||||
capture_output=True, check=True,
|
||||
).stdout.decode()
|
||||
variants = [p for p in out.split("\0") if "/.variants/" in p]
|
||||
if not variants:
|
||||
self.skipTest("bios/ not present")
|
||||
wrong = {}
|
||||
for rel in variants:
|
||||
path = REPO_ROOT / rel
|
||||
if not path.is_file():
|
||||
continue
|
||||
reason = misnamed(path, path.read_bytes())
|
||||
if reason:
|
||||
wrong[rel] = reason
|
||||
self.assertEqual(wrong, {})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user