fix: report only recorded names as mame clones

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 14:58:03 +01:00
1 parent a0579c687e
commit f77caa1885
2 files changed
+53 -6

No files matched your search

+23 -6
View File
@@ -33,8 +33,16 @@ def _remove_copies(canonical: str, true_dupes_to_remove: list[str], dry_run: boo
return removed
def _settle_group(paths: list[str], true_dupes_to_remove: list[str], dry_run: bool) -> dict:
"""Keep the best copy of one content and remove the others."""
def _settle_group(
paths: list[str], true_dupes_to_remove: list[str], clone_names: list[str], dry_run: bool
) -> dict:
"""Keep the best copy of one content and remove the others.
Only the names the clone map records are MAME clones. A removed variant
is one of the copies, and another name kept beside the canonical file
is one an emulator looks for: printing either as a MAME clone named a
file that stays, or a clone map entry that does not exist.
"""
# Find the best canonical across all paths
all_paths = [p for p in paths if p not in true_dupes_to_remove]
if not all_paths:
@@ -58,8 +66,14 @@ def _settle_group(paths: list[str], true_dupes_to_remove: list[str], dry_run: bo
print(f" {dn} (keep: {canonical})")
if true_dupes_to_remove:
print(f" {action} {len(true_dupes_to_remove)} copies")
if alias_names:
print(f" MAME clones: {alias_names}")
if clone_names:
print(f" MAME clones: {clone_names}")
kept_names = sorted(
{os.path.basename(p) for p in paths if p not in true_dupes_to_remove}
- {canonical_name}
)
if kept_names:
print(f" Kept under other names: {kept_names}")
return {
"canonical": canonical,
"removed": removed,
@@ -99,12 +113,15 @@ def deduplicate(bios_dir: str, dry_run: bool = False) -> dict:
if len(paths) <= 1:
continue
true_dupes_to_remove = plan_group_removals(sha1, paths, mame_clones)
group_clones: dict[str, dict] = {}
true_dupes_to_remove = plan_group_removals(sha1, paths, group_clones)
mame_clones.update(group_clones)
if not true_dupes_to_remove:
continue
settled = _settle_group(paths, true_dupes_to_remove, dry_run)
clone_names = [name for entry in group_clones.values() for name in entry["clones"]]
settled = _settle_group(paths, true_dupes_to_remove, clone_names, dry_run)
total_removed += len(settled["removed"])
total_saved += settled.pop("saved")
results[sha1] = settled