fix: skip emulator folders closed to this user

Termux on Android 11 cannot look into another app's Android/data
folder. The standalone-copy probes called Path.is_dir() there, and
PermissionError stopped the run after the install. Closed folders now
count as absent, and --standalone-copies names them as skipped.
This commit is contained in:
Abdessamad Derraz committed 2026-11-12 00:38:30 +01:00
1 parent 85bcfca125
commit 06aeace091
5 files changed
+80 -24

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "26fef8daf6087201d43e1c1cb5b69e255358f38f28ca1e45782984a0240dc7d3"
$defaultInstallSha256 = "a49a36df4dbde3cf0c3f2b5260c44d56f6fd51315272ed773991b27fd6ed67be"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+32 -14
View File
@@ -3162,7 +3162,7 @@ def keeps_case(directory: Path) -> bool:
a casefolded ext4 directory folds it. Unprobeable: the system's default.
"""
probe_dir = directory
while not probe_dir.is_dir() and probe_dir != probe_dir.parent:
while not _is_dir(probe_dir) and probe_dir != probe_dir.parent:
probe_dir = probe_dir.parent
try:
handle, name = tempfile.mkstemp(prefix=".retrobios-case-", dir=str(probe_dir))
@@ -3216,7 +3216,7 @@ def holds_fat_refused_names(directory: Path) -> bool:
if os.name == "nt":
return False
probe_dir = directory
while not probe_dir.is_dir() and probe_dir != probe_dir.parent:
while not _is_dir(probe_dir) and probe_dir != probe_dir.parent:
probe_dir = probe_dir.parent
try:
handle, name = tempfile.mkstemp(prefix=".retrobios-name-", suffix=":",
@@ -5458,7 +5458,7 @@ def save_directory_for(
if override is not None:
return SavePlace(override, by_core, listed)
directory = _retroarch_cfg_dir(cfg_path, "savefile_directory", app_dir, folder)
if directory is None or not directory.is_dir():
if directory is None or not _is_dir(directory):
directory = app_dir / folder
return SavePlace(directory, by_core, listed)
if override is not None:
@@ -5616,7 +5616,7 @@ def place_emulator_entries(
) if matches else None
if (matches and key.lower() not in moved and default is not None
and all(_lexically_under(place, home) for place in [*places, default])):
found = next((place for place in places if place.is_dir()), None)
found = next((place for place in places if _is_dir(place)), None)
_EMULATOR_DIRS[(bios_path, key)] = found or default
kept.append(entry)
continue
@@ -5770,6 +5770,16 @@ def _is_file(path: Path) -> bool:
return _probed(path.is_file, path)
def _closed_to_this_user(path: Path) -> OSError | None:
"""The error that keeps path from being looked at, None when it can
be, there or not."""
try:
os.stat(path)
except OSError as exc:
return None if exc.errno in _ABSENT_ERRNOS else exc
return None
def closed_folder(path: Path) -> tuple[Path, str] | None:
"""The folder above path this user cannot open, and why in words, or
None when path can be looked at, there or not.
@@ -7983,7 +7993,7 @@ def _folder_writable(path: Path) -> bool:
existing folder: a BIOS folder not created yet is as writable as the
folder it would go in."""
probe = path
while not probe.exists() and probe.parent != probe:
while not _exists(probe) and probe.parent != probe:
probe = probe.parent
return os.access(probe, os.W_OK)
@@ -8976,7 +8986,7 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int =
platform of the run installed files.
"""
probe = bios_path
while not probe.exists() and probe != probe.parent:
while not _exists(probe) and probe != probe.parent:
probe = probe.parent
try:
free = shutil.disk_usage(probe).free
@@ -9480,7 +9490,7 @@ def standalone_folders_here(
if "note" in entry:
continue
for folder in _copy_targets(entry, os_type, extra_dirs):
if folder not in found and folder.is_dir():
if folder not in found and _is_dir(folder):
found.append(folder)
return found
@@ -9518,7 +9528,7 @@ def standalone_plan(
held = by_dest.get(copy.get("source") or copy["file"])
sources = [held] if held else []
for folder in _copy_targets(copy, os_type, extra_dirs):
if not sources or not folder.is_dir():
if not sources or not _is_dir(folder):
continue
chosen = plan.setdefault(folder, {})
for entry in sources:
@@ -9659,7 +9669,7 @@ def do_standalone_copies(
detect_paths = entry.get("detect", {}).get("linux", [])
for dp in detect_paths:
expanded = Path(os.path.expandvars(os.path.expanduser(dp)))
if expanded.is_dir():
if _is_dir(expanded):
print(f" {entry['note']}")
break
continue
@@ -9677,13 +9687,21 @@ def do_standalone_copies(
# names it as the registry does for every platform, and laid out
# that way it was missing wherever the pack places it elsewhere.
src = _destination_path(bios_path, entry.get("source") or entry["file"])
sources = [src] if src.exists() else []
sources = [src] if _exists(src) else []
if not sources:
continue
for target_dir in _copy_targets(entry, os_type, extra_dirs):
if not target_dir.is_dir():
closed = _closed_to_this_user(target_dir)
if closed is not None:
# Android 11 and later keep each app's Android/data folder
# to that app, there or not: Termux cannot copy Dolphin's
# IPL.bin there, and cannot tell whether Dolphin is installed.
print(f" {target_dir}: {unreachable_words(closed)}, not copied")
skipped += len(sources)
continue
if not _is_dir(target_dir):
skipped += len(sources)
continue
resolved_dir = target_dir.resolve()
@@ -11449,8 +11467,8 @@ def romm_firmware_layout(
template = _romm_configured_firmware(library.parent / "config" / "config.yml")
if template is not None:
return parse_romm_firmware(template)
platform_first = not (library / "roms").is_dir() and any(
path.is_dir() for path in library.glob("*/roms")
platform_first = not _is_dir(library / "roms") and any(
_is_dir(path) for path in library.glob("*/roms")
)
if platform_first:
raise ValueError(
@@ -18604,7 +18622,7 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None:
)
if copied or skipped or copy_failed:
print(
f" {copied} copied, {skipped} skipped (dir not found), "
f" {copied} copied, {skipped} skipped (folder not found or closed), "
f"{copy_failed} failed"
)
total_errors += copy_failed
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="26fef8daf6087201d43e1c1cb5b69e255358f38f28ca1e45782984a0240dc7d3"
DEFAULT_INSTALL_SHA256="a49a36df4dbde3cf0c3f2b5260c44d56f6fd51315272ed773991b27fd6ed67be"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1285762,
"sha256": "26fef8daf6087201d43e1c1cb5b69e255358f38f28ca1e45782984a0240dc7d3",
"size": 1286526,
"sha256": "a49a36df4dbde3cf0c3f2b5260c44d56f6fd51315272ed773991b27fd6ed67be",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1339387,
"sha256": "7060180b1a8d93573eee7a7a083a3903822743f52d8a06a9691b40a04ecbafb6"
"size": 1340151,
"sha256": "f9934386f72b4166900d9091d8da157be8157d5f2ca95037428978db2a73b50a"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1285762,
"sha256": "26fef8daf6087201d43e1c1cb5b69e255358f38f28ca1e45782984a0240dc7d3",
"size": 1286526,
"sha256": "a49a36df4dbde3cf0c3f2b5260c44d56f6fd51315272ed773991b27fd6ed67be",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1285762,
"sha256": "26fef8daf6087201d43e1c1cb5b69e255358f38f28ca1e45782984a0240dc7d3",
"size": 1286526,
"sha256": "a49a36df4dbde3cf0c3f2b5260c44d56f6fd51315272ed773991b27fd6ed67be",
"executable": false
},
{
+38
View File
@@ -1111,6 +1111,44 @@ class TestStandaloneCopiesExtraDirs(unittest.TestCase):
)
@unittest.skipIf(os.name == "nt" or (hasattr(os, "geteuid") and os.geteuid() == 0),
"a closed folder needs POSIX permissions and a non-root user")
class StandaloneFolderClosedToThisUser(unittest.TestCase):
"""Termux on Android 11 and later cannot look into another app's
Android/data folder: is_dir() on Dolphin's GC/USA raised PermissionError
after the install, and the run stopped with code 1."""
def setUp(self) -> None:
self.bios = Path(_tempdir(self))
(self.bios / "IPL.bin").write_text("ipl")
self.app = Path(_tempdir(self)) / "org.dolphinemu.dolphinemu"
(self.app / "files" / "GC" / "USA").mkdir(parents=True)
self.app.chmod(0)
self.addCleanup(self.app.chmod, 0o755)
self.target = self.app / "files" / "GC" / "USA"
self.manifest = {"files": [{"dest": "IPL.bin"}], "standalone_copies": [
{"file": "IPL.bin", "targets": {"android": [str(self.target)]}},
{"note": "Dolphin reads GC/", "detect": {"android": [str(self.target)]}},
]}
def test_listing_the_folders_here_skips_it(self):
self.assertEqual(install.standalone_folders_here(self.manifest, "android"), [])
def test_planning_skips_it(self):
self.assertEqual(install.standalone_plan([self.manifest], "android"), [])
def test_copying_names_it_and_goes_on(self):
"""Skipped, not failed: Android answers the same refusal for an app
that is not installed, and a run without Dolphin is no failure."""
failures: list[tuple[str, str]] = []
with contextlib.redirect_stdout(io.StringIO()) as out:
result = install.do_standalone_copies(
self.manifest, self.bios, "android", failures=failures)
self.assertEqual(result, (0, 1, 0))
self.assertEqual(failures, [])
self.assertIn(f"{self.target}: could not be read", out.getvalue())
class StandaloneCopiesReadWhereThePackPutTheFile(unittest.TestCase):
"""The registry names Citra/sysdata/aes_keys.txt for every platform,
but EmuDeck's manifest installs it at the root. The installer looked under