fix: preserve legacy plugin catalogs and protect helper token initialization

This commit is contained in:
chenmingxuan committed 2026-10-28 17:53:43 +08:00
1 parent 4dc2057d43
commit e90da727d4
8 files changed
+81 -18

No files matched your search

+12 -1
View File
@@ -77,6 +77,8 @@ from typing import Any
import urllib.error
import urllib.request
from filelock import FileLock
from artemis.config.constants import ENV_ARTEMIS_HELPER_AUTO_INSTALL
from artemis.config.paths import get_temp_dir
from artemis.runtime.adb_endpoint import adb_command
@@ -323,7 +325,7 @@ class AccessibilityHelperManager:
if re.fullmatch(r"[0-9a-f]{32,128}", text):
self._token = text
return text
except OSError:
except FileNotFoundError:
pass
token = secrets.token_hex(24)
try:
@@ -550,6 +552,15 @@ class AccessibilityHelperManager:
root.mkdir(parents=True, exist_ok=True)
digest = hashlib.sha256(serial.encode("utf-8")).hexdigest()[:16]
path = root / f"{digest}.mutex"
# An age-based lease alone can be stolen from a live, delayed owner.
# Retain the legacy lease for coexistence with older Artemis processes,
# but serialize current processes with a kernel lock released on exit.
with FileLock(path.with_suffix(".guard"), timeout=_PROVISION_MUTEX_TIMEOUT_SECONDS):
with self._legacy_provision_mutex(path, serial):
yield
@contextmanager
def _legacy_provision_mutex(self, path: Path, serial: str):
started = time.monotonic()
while True:
try: