From e26516fc0edba72dc116d7def89ee8978b0f8bd9 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 17 Oct 2026 01:58:15 +0200 Subject: [PATCH] fix: write a group's pack under the group's name The RetroArch and Lakka pack was built under RetroArch's own name and renamed afterwards, which overwrote then carried away a --platform retroarch pack in the same directory, and failed on Windows where os.rename refuses an existing target. --- scripts/generate_pack.py | 47 ++++++++++++++++++--------------- tests/test_audit_regressions.py | 12 +++++++++ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index dc3c724d..20a162c2 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -2427,6 +2427,30 @@ def _run_platform_packs( ) print(f" Split into {len(zip_paths)} packs") else: + # A group's pack is written under the group's name from + # the start: built under the representative's and then + # renamed, it overwrote and carried away a + # `--platform retroarch` pack already in the directory, + # and os.rename refused an existing target on Windows. + group_name = None + if aliases: + narrow_tags = "".join( + tag + for tag, _label in _narrowings( + source, + getattr(args, "regions", None), + args.target, + args.one_per_slot, + required_only, + ) + ) + stem = _platform_pack_stem( + group_platforms, representative, args.platforms_dir + ) + group_name = ( + f"{stem}{narrow_tags}_BIOS_Pack" + f"{_system_tag(system_filter)}.zip" + ) zip_path = generate_pack( representative, args.platforms_dir, @@ -2445,29 +2469,8 @@ def _run_platform_packs( target_name=args.target, one_per_slot=args.one_per_slot, offline=args.offline, + pack_name=group_name, ) - if not args.split and zip_path and aliases: - narrow_tags = "".join( - tag - for tag, _label in _narrowings( - source, - getattr(args, "regions", None), - args.target, - args.one_per_slot, - required_only, - ) - ) - stem = _platform_pack_stem( - group_platforms, representative, args.platforms_dir - ) - combined = ( - f"{stem}{narrow_tags}_BIOS_Pack" - f"{_system_tag(system_filter)}.zip" - ) - new_path = os.path.join(os.path.dirname(zip_path), combined) - if new_path != zip_path: - os.rename(zip_path, new_path) - print(f" Renamed -> {os.path.basename(new_path)}") except (FileNotFoundError, OSError, yaml.YAMLError) as e: print(f" ERROR: {e}") failed.append(representative) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index f011880f..821a4b85 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -2207,6 +2207,18 @@ class APackNameFitsAFileName(unittest.TestCase): self.assertIn("pack_name=final_name", source) +class AGroupPackIsWrittenUnderItsOwnName(unittest.TestCase): + """The RetroArch + Lakka pack was written as RetroArch_..._BIOS_Pack.zip + and renamed: a `--platform retroarch` pack already in the directory was + overwritten then carried away, and os.rename refuses an existing target + on Windows.""" + + def test_no_pack_is_renamed_after_its_build(self): + source = (ROOT / "scripts" / "generate_pack.py").read_text(encoding="utf-8") + self.assertNotIn("os.rename(", source) + self.assertIn("pack_name=group_name", source) + + class TheDatabaseCacheIsWrittenWhole(unittest.TestCase): """A crash while serializing left a truncated db_cache.json behind, and the next run rehashed the whole collection from scratch."""