mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: read mountinfo through one helper
The card checks and the FAT32 test each read /proc/self/mountinfo and decoded its escaped mount point. One function reads the table and one decodes a mount point.
This commit is contained in:
1 parent
2502d96734
commit
1f215f1732
6 files changed
+57
-40
No files matched your search
+1
-1
@@ -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 = "6b715a59ffa1b796490f810f2f5ae71ee26430e6049e08d27c08fd656c1083c7"
|
||||
$defaultInstallSha256 = "508ffd2832afe8e14dac09860ea73dcb770874c9683f26f8ea0edddb0f7a469b"
|
||||
# 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
|
||||
|
||||
+23
-15
@@ -2778,6 +2778,20 @@ def hide_from_media_scanner(folder: Path) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def read_mountinfo() -> str | None:
|
||||
"""/proc/self/mountinfo, None where it cannot be read."""
|
||||
try:
|
||||
return Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def mount_point(field: str) -> str:
|
||||
"""Field 5 of a mountinfo line, its space, tab, newline and backslash
|
||||
written as octal escapes (proc(5))."""
|
||||
return re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), field)
|
||||
|
||||
|
||||
def mountinfo_types(text: str) -> list[tuple[str, str]]:
|
||||
"""(mount point, file system type) of each line of /proc/self/mountinfo:
|
||||
the point is field 5, its space, tab and backslash written as octal
|
||||
@@ -2787,7 +2801,7 @@ def mountinfo_types(text: str) -> list[tuple[str, str]]:
|
||||
head, _sep, tail = line.partition(" - ")
|
||||
fields = head.split(" ")
|
||||
if len(fields) > 4 and tail:
|
||||
point = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
point = mount_point(fields[4])
|
||||
mounts.append((point, tail.split(" ")[0]))
|
||||
return mounts
|
||||
|
||||
@@ -2838,10 +2852,10 @@ def fat32_drive(folder: Path) -> bool:
|
||||
listing = subprocess.run(["/sbin/mount"], capture_output=True, text=True,
|
||||
timeout=5, check=False).stdout
|
||||
return fat_mounted(target, mount_list_types(listing))
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
text = read_mountinfo()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return False
|
||||
return fat_mounted(target, mountinfo_types(text))
|
||||
return text is not None and fat_mounted(target, mountinfo_types(text))
|
||||
|
||||
|
||||
# --- installer/local_check.py ------------------------------------------------
|
||||
@@ -4116,11 +4130,8 @@ def _drive_not_removable(mount: Path) -> bool:
|
||||
except (AttributeError, OSError):
|
||||
return False
|
||||
return kind in _NOT_REMOVABLE_TYPES
|
||||
try:
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
return False
|
||||
return _fixed_partition(mount, text, Path("/sys"))
|
||||
text = read_mountinfo()
|
||||
return text is not None and _fixed_partition(mount, text, Path("/sys"))
|
||||
|
||||
|
||||
def _fixed_partition(mount: Path, mountinfo: str, sys_root: Path) -> bool:
|
||||
@@ -4132,7 +4143,7 @@ def _fixed_partition(mount: Path, mountinfo: str, sys_root: Path) -> bool:
|
||||
fields = line.split(" ")
|
||||
if len(fields) < 5:
|
||||
continue
|
||||
point = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
point = mount_point(fields[4])
|
||||
if point != str(mount):
|
||||
continue
|
||||
# Field 4 is the folder of the filesystem mounted there: "/" for a
|
||||
@@ -4525,13 +4536,10 @@ def _mount_points() -> frozenset:
|
||||
"""Every mount point this process sees, from /proc/self/mountinfo where
|
||||
it exists: os.path.ismount compares devices, and misses a bind mount
|
||||
from the same filesystem (a stick bound inside a muOS card's mount)."""
|
||||
try:
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
text = read_mountinfo()
|
||||
if text is None:
|
||||
return frozenset()
|
||||
# Field 5 is the mount point, with space, tab, newline and backslash
|
||||
# written as octal escapes (proc(5)).
|
||||
return frozenset(re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
return frozenset(mount_point(fields[4])
|
||||
for fields in (line.split(" ") for line in text.splitlines())
|
||||
if len(fields) > 4)
|
||||
|
||||
|
||||
+1
-1
@@ -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="6b715a59ffa1b796490f810f2f5ae71ee26430e6049e08d27c08fd656c1083c7"
|
||||
DEFAULT_INSTALL_SHA256="508ffd2832afe8e14dac09860ea73dcb770874c9683f26f8ea0edddb0f7a469b"
|
||||
# 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
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
{
|
||||
"dest": "roms/ports/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450457,
|
||||
"sha256": "6b715a59ffa1b796490f810f2f5ae71ee26430e6049e08d27c08fd656c1083c7",
|
||||
"size": 1450474,
|
||||
"sha256": "508ffd2832afe8e14dac09860ea73dcb770874c9683f26f8ea0edddb0f7a469b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1504082,
|
||||
"sha256": "cd9bb5cabc3ea5f8e3d7f0eaf74d03dc04f51e2a89442da09963cfb4b9362fdf"
|
||||
"size": 1504099,
|
||||
"sha256": "a968c9ea40f3abb96913e9c816b44a43431c60c8ce23bafefc715c1767259ff8"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450457,
|
||||
"sha256": "6b715a59ffa1b796490f810f2f5ae71ee26430e6049e08d27c08fd656c1083c7",
|
||||
"size": 1450474,
|
||||
"sha256": "508ffd2832afe8e14dac09860ea73dcb770874c9683f26f8ea0edddb0f7a469b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450457,
|
||||
"sha256": "6b715a59ffa1b796490f810f2f5ae71ee26430e6049e08d27c08fd656c1083c7",
|
||||
"size": 1450474,
|
||||
"sha256": "508ffd2832afe8e14dac09860ea73dcb770874c9683f26f8ea0edddb0f7a469b",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
+7
-12
@@ -7,6 +7,7 @@ from pathlib import Path, PurePosixPath
|
||||
from typing import NamedTuple
|
||||
|
||||
from installer.embedded import CARD_PLATFORMS, _CARD_RULES, _EMBEDDED_RULES, _STANDIN_MANIFESTS, _OsRule, _a, _built_on
|
||||
from installer.filesystems import mount_point, read_mountinfo
|
||||
from installer.host_fs import _WSL, _exists, _is_dir, _is_file, _probed
|
||||
from installer.paths import shown_path
|
||||
from installer.platforms import AVAILABLE_PLATFORMS, _name_key, display_name
|
||||
@@ -70,11 +71,8 @@ def _drive_not_removable(mount: Path) -> bool:
|
||||
except (AttributeError, OSError):
|
||||
return False
|
||||
return kind in _NOT_REMOVABLE_TYPES
|
||||
try:
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
return False
|
||||
return _fixed_partition(mount, text, Path("/sys"))
|
||||
text = read_mountinfo()
|
||||
return text is not None and _fixed_partition(mount, text, Path("/sys"))
|
||||
|
||||
|
||||
def _fixed_partition(mount: Path, mountinfo: str, sys_root: Path) -> bool:
|
||||
@@ -86,7 +84,7 @@ def _fixed_partition(mount: Path, mountinfo: str, sys_root: Path) -> bool:
|
||||
fields = line.split(" ")
|
||||
if len(fields) < 5:
|
||||
continue
|
||||
point = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
point = mount_point(fields[4])
|
||||
if point != str(mount):
|
||||
continue
|
||||
# Field 4 is the folder of the filesystem mounted there: "/" for a
|
||||
@@ -479,13 +477,10 @@ def _mount_points() -> frozenset:
|
||||
"""Every mount point this process sees, from /proc/self/mountinfo where
|
||||
it exists: os.path.ismount compares devices, and misses a bind mount
|
||||
from the same filesystem (a stick bound inside a muOS card's mount)."""
|
||||
try:
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
text = read_mountinfo()
|
||||
if text is None:
|
||||
return frozenset()
|
||||
# Field 5 is the mount point, with space, tab, newline and backslash
|
||||
# written as octal escapes (proc(5)).
|
||||
return frozenset(re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
return frozenset(mount_point(fields[4])
|
||||
for fields in (line.split(" ") for line in text.splitlines())
|
||||
if len(fields) > 4)
|
||||
|
||||
|
||||
@@ -120,6 +120,20 @@ def hide_from_media_scanner(folder: Path) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def read_mountinfo() -> str | None:
|
||||
"""/proc/self/mountinfo, None where it cannot be read."""
|
||||
try:
|
||||
return Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def mount_point(field: str) -> str:
|
||||
"""Field 5 of a mountinfo line, its space, tab, newline and backslash
|
||||
written as octal escapes (proc(5))."""
|
||||
return re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), field)
|
||||
|
||||
|
||||
def mountinfo_types(text: str) -> list[tuple[str, str]]:
|
||||
"""(mount point, file system type) of each line of /proc/self/mountinfo:
|
||||
the point is field 5, its space, tab and backslash written as octal
|
||||
@@ -129,7 +143,7 @@ def mountinfo_types(text: str) -> list[tuple[str, str]]:
|
||||
head, _sep, tail = line.partition(" - ")
|
||||
fields = head.split(" ")
|
||||
if len(fields) > 4 and tail:
|
||||
point = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), fields[4])
|
||||
point = mount_point(fields[4])
|
||||
mounts.append((point, tail.split(" ")[0]))
|
||||
return mounts
|
||||
|
||||
@@ -180,7 +194,7 @@ def fat32_drive(folder: Path) -> bool:
|
||||
listing = subprocess.run(["/sbin/mount"], capture_output=True, text=True,
|
||||
timeout=5, check=False).stdout
|
||||
return fat_mounted(target, mount_list_types(listing))
|
||||
text = Path("/proc/self/mountinfo").read_text(encoding="utf-8", errors="replace")
|
||||
text = read_mountinfo()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return False
|
||||
return fat_mounted(target, mountinfo_types(text))
|
||||
return text is not None and fat_mounted(target, mountinfo_types(text))
|
||||
Reference in new issue
Block a user