fix: read the clone map beside the scanned tree

This commit is contained in:
Abdessamad Derraz committed 2026-10-09 22:45:57 +02:00
1 parent be2daab00c
commit 82bdcfa1b1
5 files changed
+133 -42

No files matched your search

+2 -1
View File
@@ -1,8 +1,9 @@
{ {
"schema_version": 1, "schema_version": 1,
"generated_at": "2026-10-09T20:11:24Z", "generated_at": "2026-10-09T20:41:14Z",
"total_files": 19002, "total_files": 19002,
"total_size": 17497698358, "total_size": 17497698358,
"bios_dir": "bios",
"files": { "files": {
"738c7f5fd0c8b57ee2e87ae7a97bf8e21a821d07": { "738c7f5fd0c8b57ee2e87ae7a97bf8e21a821d07": {
"path": "bios/3D Realms/Duke Nukem 3D/DUKE.RTS", "path": "bios/3D Realms/Duke Nukem 3D/DUKE.RTS",
+105 -24
View File
@@ -4,55 +4,136 @@
"title": "RetroBIOS content database", "title": "RetroBIOS content database",
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": ["schema_version", "generated_at", "total_files", "total_size", "files", "indexes"], "required": [
"schema_version",
"generated_at",
"total_files",
"total_size",
"files",
"indexes"
],
"properties": { "properties": {
"schema_version": { "const": 1 }, "schema_version": {
"generated_at": { "type": "string", "format": "date-time" }, "const": 1
"total_files": { "type": "integer", "minimum": 0 }, },
"total_size": { "type": "integer", "minimum": 0 }, "generated_at": {
"type": "string",
"format": "date-time"
},
"total_files": {
"type": "integer",
"minimum": 0
},
"total_size": {
"type": "integer",
"minimum": 0
},
"bios_dir": {
"type": "string",
"description": "Directory the files were scanned from; _mame_clones.json sits beside it."
},
"files": { "files": {
"type": "object", "type": "object",
"propertyNames": { "pattern": "^[a-f0-9]{40}$" }, "propertyNames": {
"pattern": "^[a-f0-9]{40}$"
},
"additionalProperties": { "additionalProperties": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": ["path", "name", "size", "sha1", "md5", "sha256", "crc32", "adler32"], "required": [
"path",
"name",
"size",
"sha1",
"md5",
"sha256",
"crc32",
"adler32"
],
"properties": { "properties": {
"path": { "type": "string", "minLength": 1 }, "path": {
"name": { "type": "string", "minLength": 1 }, "type": "string",
"size": { "type": "integer", "minimum": 0 }, "minLength": 1
"sha1": { "type": "string", "pattern": "^[a-f0-9]{40}$" }, },
"md5": { "type": "string", "pattern": "^[a-f0-9]{32}$" }, "name": {
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }, "type": "string",
"crc32": { "type": "string", "pattern": "^[a-f0-9]{8}$" }, "minLength": 1
"adler32": { "type": "string", "pattern": "^[a-f0-9]{8}$" }, },
"provenance": { "type": "object" } "size": {
"type": "integer",
"minimum": 0
},
"sha1": {
"type": "string",
"pattern": "^[a-f0-9]{40}$"
},
"md5": {
"type": "string",
"pattern": "^[a-f0-9]{32}$"
},
"sha256": {
"type": "string",
"pattern": "^[a-f0-9]{64}$"
},
"crc32": {
"type": "string",
"pattern": "^[a-f0-9]{8}$"
},
"adler32": {
"type": "string",
"pattern": "^[a-f0-9]{8}$"
},
"provenance": {
"type": "object"
}
} }
} }
}, },
"indexes": { "indexes": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": ["by_md5", "by_name", "by_crc32", "by_sha256", "by_path_suffix"], "required": [
"by_md5",
"by_name",
"by_crc32",
"by_sha256",
"by_path_suffix"
],
"properties": { "properties": {
"by_md5": { "$ref": "#/$defs/hashIndex" }, "by_md5": {
"by_crc32": { "$ref": "#/$defs/hashIndex" }, "$ref": "#/$defs/hashIndex"
"by_sha256": { "$ref": "#/$defs/hashIndex" }, },
"by_name": { "$ref": "#/$defs/listIndex" }, "by_crc32": {
"by_path_suffix": { "$ref": "#/$defs/listIndex" } "$ref": "#/$defs/hashIndex"
},
"by_sha256": {
"$ref": "#/$defs/hashIndex"
},
"by_name": {
"$ref": "#/$defs/listIndex"
},
"by_path_suffix": {
"$ref": "#/$defs/listIndex"
}
} }
} }
}, },
"$defs": { "$defs": {
"hashIndex": { "hashIndex": {
"type": "object", "type": "object",
"additionalProperties": { "type": "string", "pattern": "^[a-f0-9]{40}$" } "additionalProperties": {
"type": "string",
"pattern": "^[a-f0-9]{40}$"
}
}, },
"listIndex": { "listIndex": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"type": "array", "type": "array",
"items": { "type": "string", "pattern": "^[a-f0-9]{40}$" }, "items": {
"type": "string",
"pattern": "^[a-f0-9]{40}$"
},
"minItems": 1, "minItems": 1,
"uniqueItems": true "uniqueItems": true
} }
+22 -16
View File
@@ -912,7 +912,7 @@ def resolve_local_file(
# MAME clone fallback: if a file was deduped, resolve via canonical # MAME clone fallback: if a file was deduped, resolve via canonical
if _depth < 3 and not has_strong_hash: if _depth < 3 and not has_strong_hash:
clone_map = get_mame_clone_map() clone_map = get_mame_clone_map(db.get("bios_dir"))
canonical = clone_map.get(name) canonical = clone_map.get(name)
if canonical and canonical != name: if canonical and canonical != name:
canonical_entry = {"name": canonical} canonical_entry = {"name": canonical}
@@ -960,28 +960,34 @@ def resolve_local_file(
return None, "not_found" return None, "not_found"
_mame_clone_map_cache: dict[str, str] | None = None _mame_clone_map_cache: dict[str, dict[str, str]] = {}
def get_mame_clone_map() -> dict[str, str]: def get_mame_clone_map(bios_dir: str | None = None) -> dict[str, str]:
"""Load and cache the MAME clone map (clone_name -> canonical_name).""" """The MAME clone map (clone_name -> canonical_name) of a scanned tree.
global _mame_clone_map_cache
if _mame_clone_map_cache is not None: dedup.py writes _mame_clones.json beside the tree it scanned, and the
return _mame_clone_map_cache map of one tree says nothing about another: read from the repository
clone_path = os.path.join( root whatever ``--bios-dir`` said, an alternate tree's renamed clones
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), fell out of its packs. Without a tree the repository's own is read.
"_mame_clones.json", """
) if bios_dir is None:
bios_dir = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "bios"
)
clone_path = os.path.join(os.path.dirname(os.path.abspath(bios_dir)), "_mame_clones.json")
cached = _mame_clone_map_cache.get(clone_path)
if cached is not None:
return cached
clone_map: dict[str, str] = {}
if os.path.exists(clone_path): if os.path.exists(clone_path):
with open(clone_path) as f: with open(clone_path) as f:
data = json.load(f) data = json.load(f)
_mame_clone_map_cache = {}
for canonical, info in data.items(): for canonical, info in data.items():
for clone in info.get("clones", []): for clone in info.get("clones", []):
_mame_clone_map_cache[clone] = canonical clone_map[clone] = canonical
else: _mame_clone_map_cache[clone_path] = clone_map
_mame_clone_map_cache = {} return clone_map
return _mame_clone_map_cache
+3
View File
@@ -386,6 +386,9 @@ def main():
"generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), "generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"total_files": len(files), "total_files": len(files),
"total_size": total_size, "total_size": total_size,
# The tree these paths belong to: dedup writes _mame_clones.json
# beside it, and the resolver reads the map there, not at the repo root.
"bios_dir": os.path.normpath(args.bios_dir),
"files": files, "files": files,
"indexes": indexes, "indexes": indexes,
} }
+1 -1
View File
@@ -6356,7 +6356,7 @@ struct BurnDriver BurnDrvneogeo = {
db = self._gap_db("v4bios.zip", "a" * 40, "465c4e1c") db = self._gap_db("v4bios.zip", "a" * 40, "465c4e1c")
original = cross_reference.get_mame_clone_map original = cross_reference.get_mame_clone_map
cross_reference.get_mame_clone_map = lambda: {"bctvidbs.zip": "v4bios.zip"} cross_reference.get_mame_clone_map = lambda *_a: {"bctvidbs.zip": "v4bios.zip"}
try: try:
entry = {"name": "bctvidbs.zip", "required": True} entry = {"name": "bctvidbs.zip", "required": True}
self.assertEqual(self._gap_source(entry, db), "bios") self.assertEqual(self._gap_source(entry, db), "bios")