Preserve staged helper builds and exclude hooks before attachment
This commit is contained in:
1 parent
0db42de77e
commit
989ecb681d
12 files changed
+267
-38
No files matched your search
+41
-19
@@ -16,6 +16,7 @@ from pathlib import Path
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
@@ -98,10 +99,17 @@ def controller_only_arguments(programs: set[str], listed,
|
||||
"""
|
||||
|
||||
names = {name.lower() for name in listed
|
||||
if isinstance(name, str)} if isinstance(listed, (list, tuple)) else set()
|
||||
if isinstance(name, str) and name and not any(
|
||||
char in name for char in "\n\r\0/\\")
|
||||
} if isinstance(listed, (list, tuple)) else set()
|
||||
# Every helper must know the exclusions before a game exists in /proc.
|
||||
# The native hosts check these names before injecting either hook.
|
||||
arguments = []
|
||||
for name in sorted(names):
|
||||
arguments.extend(("--exclude-hook-program", name))
|
||||
if always or programs & names:
|
||||
return ["--no-dialog-reader"]
|
||||
return []
|
||||
arguments.append("--no-dialog-reader")
|
||||
return arguments
|
||||
|
||||
|
||||
def find_helper() -> str | None:
|
||||
@@ -369,22 +377,36 @@ class HelperManager:
|
||||
if "PRESSURE_VESSEL_RUNTIME" not in source:
|
||||
return self.helper
|
||||
origin = Path(self.helper)
|
||||
stage = self.log_directory / "helper"
|
||||
try:
|
||||
stage.mkdir(parents=True, exist_ok=True)
|
||||
names = [origin.name, origin.name + ".so", *HELPER_SIBLINGS]
|
||||
for name in names:
|
||||
source_file = origin.parent / name
|
||||
target = stage / name
|
||||
if not source_file.is_file():
|
||||
continue
|
||||
if target.is_file() and target.read_bytes() == source_file.read_bytes():
|
||||
continue
|
||||
shutil.copy2(source_file, target)
|
||||
except OSError:
|
||||
return self.helper
|
||||
staged = stage / origin.name
|
||||
return str(staged) if staged.is_file() else self.helper
|
||||
names = [origin.name, origin.name + ".so", *HELPER_SIBLINGS]
|
||||
# Read the complete set before publishing anything. Missing files are
|
||||
# a failed start, never a reason to reuse stale staged siblings.
|
||||
contents = {name: (origin.parent / name).read_bytes() for name in names}
|
||||
digest = hashlib.sha256()
|
||||
for name, data in contents.items():
|
||||
digest.update(name.encode() + b"\0")
|
||||
digest.update(len(data).to_bytes(8, "big"))
|
||||
digest.update(data)
|
||||
stageRoot = self.log_directory / "helper"
|
||||
stageRoot.mkdir(parents=True, exist_ok=True)
|
||||
stage = stageRoot / digest.hexdigest()
|
||||
if not stage.exists():
|
||||
with tempfile.TemporaryDirectory(prefix=".stage-", dir=stageRoot) as temporary:
|
||||
pending = Path(temporary) / "complete"
|
||||
pending.mkdir()
|
||||
for name, data in contents.items():
|
||||
target = pending / name
|
||||
target.write_bytes(data)
|
||||
target.chmod(0o755 if os.access(origin.parent / name, os.X_OK) else 0o644)
|
||||
try:
|
||||
pending.rename(stage)
|
||||
except OSError:
|
||||
# Another supervisor may have published the identical set.
|
||||
if not stage.is_dir():
|
||||
raise
|
||||
for name, data in contents.items():
|
||||
if (stage / name).read_bytes() != data:
|
||||
raise OSError("Incomplete or modified staged Wine Access helper")
|
||||
return str(stage / origin.name)
|
||||
|
||||
def _command(self, source: dict[str, str], programs: set[str]) -> list[str]:
|
||||
return [self._helper_for(source), *self.reader_arguments,
|
||||
|
||||
Reference in new issue
Block a user