Files
libretro/scripts/packs/executable.py
T
Abdessamad Derraz 7baeb6475c fix: one execute bit rule for pack and manifest
The pack read the git mode and the manifest the file header, so 833
archives extracted 755 from a pack and 644 from install.py, and 75
programs the reverse. packs.executable decides for both. Data tree
members stay 644 as the installer writes them, and the launcher
archives keep the mode ports/ commits.
2026-11-22 00:58:05 +01:00

23 lines
733 B
Python

"""Whether a collection file ships executable, read from its header."""
from __future__ import annotations
# A program (RetroDECK's pico8, Voxatron's vox) has to stay runnable once
# extracted or installed. The git mode cannot say: hundreds of MAME archives
# carry an execute bit nothing reads, and the Lindbergh segaboot is an ELF
# committed without one.
_PROGRAM_MAGIC = (
b"\x7fELF",
b"#!",
b"\xcf\xfa\xed\xfe",
b"\xce\xfa\xed\xfe",
b"\xca\xfe\xba\xbe",
)
def ships_executable(path: str) -> bool:
"""An ELF or Mach-O binary, or a script with an interpreter line."""
with open(path, "rb") as handle:
head = handle.read(4)
return any(head.startswith(magic) for magic in _PROGRAM_MAGIC)