Merge main (0.2.1.1 long-path hotfix)
This commit is contained in:
commit
bb7e399c30
11 files changed
+424
-30
No files matched your search
+1
-1
@@ -8,7 +8,7 @@
|
||||
# below refuses anything older: silently building for a pre-Ampere arch would produce a binary that runs
|
||||
# and is wrong about its own performance, which is the worst of both outcomes.
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(strata VERSION 0.1.46 LANGUAGES CXX)
|
||||
project(strata VERSION 0.1.46.1 LANGUAGES CXX)
|
||||
# EXPERIMENTAL: the Intel Arc engine, the SYCL port in sycl/ (PR #423; icpx + oneMKL, docs/INTEL_ARC.md). It is its
|
||||
# own project that takes the unported sources from src/; with this on, nothing below is configured.
|
||||
option(STRATA_ENABLE_SYCL "EXPERIMENTAL: build the Intel Arc (SYCL) engine from sycl/ - docs/INTEL_ARC.md" OFF)
|
||||
|
||||
@@ -63,7 +63,7 @@ For a GitHub release the assets are flat: pack with `--url-prefix ""` and upload
|
||||
|
||||
### What an engine update does
|
||||
|
||||
download (resume, progress) -> SHA-256 of the archive = the feed's -> unpack into `components/.updates/staging/` (names and links checked,
|
||||
download (resume, progress) -> SHA-256 of the archive = the feed's -> unpack into `components/.s/<4 hex>/` (short on purpose: Windows paths are limited to 259 characters unless long paths are on; files are written through extended-length paths) (names and links checked,
|
||||
total size limited to the feed's `installed_bytes`) -> the manifest is the one the feed names (`manifest_sha256`) and says what the feed says
|
||||
-> the manifest's own signature verifies -> every file's hash -> fits this PC -> **test-start from the staging folder through the real start
|
||||
path** (isolated owner runtime and profile, `component:strata-engine`, an installed model, one-token probe, stop) -> only then rename
|
||||
|
||||
+10
-2
@@ -504,6 +504,14 @@ def parser() -> argparse.ArgumentParser:
|
||||
return ap
|
||||
|
||||
|
||||
def _file_words(exc: BaseException) -> str:
|
||||
try:
|
||||
from strata_control import longpath
|
||||
except ImportError:
|
||||
return f"local file operation failed ({type(exc).__name__})"
|
||||
return longpath.file_words(exc)
|
||||
|
||||
|
||||
def _error(message: str, code: int, machine: bool = False) -> int:
|
||||
if machine:
|
||||
print(json.dumps({"schema_version": 1, "ok": False, "error": {"code": code, "message": message}}))
|
||||
@@ -2048,8 +2056,8 @@ def _run(a: argparse.Namespace) -> int:
|
||||
if retried is not None:
|
||||
return retried
|
||||
if a.command == "serve" and a.output == "jsonl":
|
||||
return _serve_error(a, f"local file operation failed ({type(e).__name__})", 6)
|
||||
return _error(f"local file operation failed ({type(e).__name__})", 6,
|
||||
return _serve_error(a, _file_words(e), 6)
|
||||
return _error(_file_words(e), 6,
|
||||
bool(getattr(a, "output", None) in ("json", "jsonl")))
|
||||
except ClientError as e:
|
||||
if a.command == "serve" and a.output == "jsonl":
|
||||
|
||||
@@ -397,7 +397,10 @@ class Runner:
|
||||
if ev.get("event") == "progress":
|
||||
self.emit("engine", f"Downloading the engine… {ev.get('percent', 0)}%", float(ev.get("percent", 0)))
|
||||
elif ev.get("event") in ("phase", "waiting"):
|
||||
self.emit("engine", str(ev.get("message") or ""))
|
||||
if ev.get("phase") == "warn":
|
||||
self.emit("engine", str(ev.get("message") or ""), level="warn")
|
||||
else:
|
||||
self.emit("engine", str(ev.get("message") or ""))
|
||||
last = ev
|
||||
code = p.wait()
|
||||
if code == 0:
|
||||
|
||||
@@ -113,6 +113,14 @@ def parser() -> argparse.ArgumentParser:
|
||||
return ap
|
||||
|
||||
|
||||
def _file_words(exc: BaseException) -> str:
|
||||
try:
|
||||
from strata_control import longpath
|
||||
except ImportError: # the standalone monitor bundle does not carry strata_control
|
||||
return f"local file operation failed ({type(exc).__name__})"
|
||||
return longpath.file_words(exc)
|
||||
|
||||
|
||||
def _error(message: str, code: int, machine: bool) -> int:
|
||||
if machine:
|
||||
print(json.dumps({"schema_version": 1, "ok": False, "error": {"code": code, "message": message}}))
|
||||
@@ -229,7 +237,7 @@ def run(a: argparse.Namespace) -> int:
|
||||
except BrokenPipeError:
|
||||
return 0
|
||||
except OSError as e:
|
||||
return _error(f"local file operation failed ({type(e).__name__})", 6, machine)
|
||||
return _error(_file_words(e), 6, machine)
|
||||
except KeyboardInterrupt:
|
||||
if a.command == "logs" and a.follow:
|
||||
return 0
|
||||
|
||||
@@ -48,7 +48,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path, PurePosixPath, PureWindowsPath
|
||||
|
||||
from strata_control import acquisition
|
||||
from strata_control import acquisition, longpath
|
||||
from strata_control.targets import BACKEND_MATRIX, backend_supported, host_platform
|
||||
|
||||
SCHEMA_VERSION = 2
|
||||
@@ -385,19 +385,20 @@ def _sha256(path: Path) -> str:
|
||||
def verify(component: EngineComponent, *, full: bool = False) -> None:
|
||||
"""Raise IntegrityProblem unless the files are what the manifest says. `full` hashes every file; without it only
|
||||
the entrypoint is hashed (sizes are always checked)."""
|
||||
root = component.root.resolve()
|
||||
# extended-length paths: under a long user name an AMD engine's files pass 259 characters, which Windows (long paths off)
|
||||
# reports as "missing" for an ordinary path
|
||||
folder = longpath.long_path(component.root)
|
||||
root = folder.resolve()
|
||||
for rel, digest, size in component.files:
|
||||
target = component.root / rel
|
||||
target = folder / rel
|
||||
try:
|
||||
info = target.lstat()
|
||||
except OSError:
|
||||
raise IntegrityProblem(f"{rel} is missing") from None
|
||||
if target.is_symlink() or not target.is_file():
|
||||
raise IntegrityProblem(f"{rel} is not a regular file")
|
||||
try:
|
||||
target.resolve().relative_to(root)
|
||||
except ValueError:
|
||||
raise IntegrityProblem(f"{rel} resolves outside the component folder") from None
|
||||
if not longpath.same_tree(target.resolve(), root):
|
||||
raise IntegrityProblem(f"{rel} resolves outside the component folder")
|
||||
if info.st_size != size:
|
||||
raise IntegrityProblem(f"{rel} is {info.st_size} bytes, the manifest says {size}")
|
||||
if (full or rel == component.entrypoint) and _sha256(target) != digest:
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
"""Windows path length (MAX_PATH).
|
||||
|
||||
A Windows PC with "long paths" off (the default on a fresh install) refuses any ordinary file path of 260 characters or more.
|
||||
The AMD engine packages hold paths up to 149 characters (hipBLASLt tensile libraries), so under a long user name the unpacked
|
||||
engine can go past the limit. Two defences, neither of which needs a setting from the user:
|
||||
|
||||
* every file Strata itself touches inside a component folder goes through `long_path`, which turns the path into the
|
||||
extended-length form (``\\\\?\\C:\\...``) that Windows accepts at any length (up to 32,767 characters);
|
||||
* when a folder is still too deep for the engine's *own* file loading (the GPU math libraries open their files with ordinary
|
||||
paths), `warning_for` gives one plain sentence with the fix; the install continues (recommend, never refuse).
|
||||
|
||||
Nothing here reads or writes the registry. `plain_long_paths_work` finds out by trying.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
#: the longest ordinary path Windows accepts with long paths off (MAX_PATH is 260 including the terminating null)
|
||||
PLAIN_LIMIT = 259
|
||||
_PREFIX = "\\\\?\\"
|
||||
_UNC_PREFIX = "\\\\?\\UNC\\"
|
||||
|
||||
#: longest path inside an engine package, by backend, as shipped in 0.2.1 (hip: rocm/bin/hipblaslt/library/gfx1200/TensileLibrary_...).
|
||||
#: The warning before a download can only estimate; after unpacking the real manifest is measured.
|
||||
LONGEST_IN_PACKAGE = {"hip": 150}
|
||||
LONGEST_IN_PACKAGE_DEFAULT = 60
|
||||
|
||||
|
||||
def long_path(path) -> Path:
|
||||
"""`path` in the form that works at any length: absolute, normalised, with the ``\\\\?\\`` prefix on Windows. Elsewhere unchanged."""
|
||||
p = Path(path)
|
||||
if os.name != "nt":
|
||||
return p
|
||||
text = str(p)
|
||||
if text.startswith(_PREFIX):
|
||||
return p
|
||||
text = os.path.normpath(os.path.abspath(text))
|
||||
if text.startswith("\\\\"):
|
||||
return Path(_UNC_PREFIX + text[2:])
|
||||
return Path(_PREFIX + text)
|
||||
|
||||
|
||||
def plain(path) -> str:
|
||||
"""The path as a person would read it, without the extended-length prefix."""
|
||||
text = str(path)
|
||||
if text.startswith(_UNC_PREFIX):
|
||||
return "\\\\" + text[len(_UNC_PREFIX):]
|
||||
return text[len(_PREFIX):] if text.startswith(_PREFIX) else text
|
||||
|
||||
|
||||
def same_tree(path: Path, root: Path) -> bool:
|
||||
"""Whether the (already resolved) `path` is `root` or below it; the prefix on either side does not matter."""
|
||||
a, b = os.path.normcase(plain(path)), os.path.normcase(plain(root))
|
||||
return a == b or a.startswith(b.rstrip("\\/") + os.sep)
|
||||
|
||||
|
||||
def too_long(path, *, extra: int = 0) -> bool:
|
||||
"""Would an ordinary (not extended) path be refused? Only ever true on Windows."""
|
||||
if os.name != "nt":
|
||||
return False
|
||||
return len(os.path.abspath(plain(path))) + extra > PLAIN_LIMIT
|
||||
|
||||
|
||||
def plain_long_paths_work(directory: Path) -> bool:
|
||||
"""Whether this process can open a path longer than 259 characters without the extended prefix (so Windows long paths are on).
|
||||
Tried, not read from the registry: a few folders are made through the extended form and reached through the ordinary one."""
|
||||
if os.name != "nt":
|
||||
return True
|
||||
base = long_path(Path(directory) / f".lp-{uuid.uuid4().hex[:6]}")
|
||||
try:
|
||||
deep = base / ("a" * 90) / ("b" * 90) / ("c" * 90)
|
||||
os.makedirs(deep)
|
||||
try:
|
||||
return os.path.isdir(plain(deep)) and len(plain(deep)) > PLAIN_LIMIT
|
||||
except OSError:
|
||||
return False
|
||||
except OSError:
|
||||
return True # could not even test: say nothing rather than warn wrongly
|
||||
finally:
|
||||
shutil.rmtree(base, ignore_errors=True)
|
||||
|
||||
|
||||
def warning_for(folder: Path, longest_inside: int) -> str | None:
|
||||
"""One plain sentence when the files of a package placed in `folder` would pass the ordinary path limit, else None."""
|
||||
if os.name != "nt" or not too_long(Path(folder) / ("x" * (longest_inside + 1))):
|
||||
return None
|
||||
reach = len(plain(folder)) + 1 + longest_inside
|
||||
return (f"Strata's folder is deep: some engine files will have paths of about {reach} characters, and Windows stops at 259 unless "
|
||||
f"long paths are turned on. The install carries on, but the engine's graphics libraries may fail to load those files. "
|
||||
f"To fix it, turn on Windows long paths (Group Policy: Enable Win32 long paths) or put Strata in a shorter folder "
|
||||
f"(for example set STRATA_COMPONENTS_DIR to C:\\Strata) and update again.")
|
||||
|
||||
|
||||
def describe_oserror(exc: BaseException) -> str:
|
||||
"""Plain words for a failed file operation: which file, and when the cause is a path that is too long, that."""
|
||||
name = getattr(exc, "filename", None) or getattr(exc, "filename2", None)
|
||||
kind = type(exc).__name__
|
||||
if name is not None:
|
||||
shown = plain(os.fsdecode(name))
|
||||
if too_long(shown):
|
||||
return (f"a file path is longer than Windows allows ({len(os.path.abspath(shown))} characters, the limit is {PLAIN_LIMIT}): "
|
||||
f"{shown}. Windows long paths are off on this PC. Put Strata in a shorter folder (set STRATA_COMPONENTS_DIR "
|
||||
f"to something short like C:\\Strata) or turn on Windows long paths, then try again ({kind})")
|
||||
if isinstance(exc, FileNotFoundError):
|
||||
return f"Strata could not find or create {shown} ({kind})"
|
||||
if isinstance(exc, PermissionError):
|
||||
return f"Windows or another program would not let Strata use {shown} ({kind})"
|
||||
reason = getattr(exc, "strerror", None)
|
||||
return f"Strata could not use {shown}" + (f": {reason}" if reason else "") + f" ({kind})"
|
||||
return f"a file operation failed ({kind})"
|
||||
|
||||
|
||||
def file_words(exc: BaseException) -> str:
|
||||
"""The one-line message the command line prints for a failed local file operation."""
|
||||
return "local file operation failed: " + describe_oserror(exc)
|
||||
+45
-14
@@ -42,10 +42,11 @@ from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from strata_control import acquisition, components, engine_component as ec, feed as feedmod, preset_marks, signing, transfer
|
||||
from strata_control import acquisition, components, engine_component as ec, feed as feedmod, longpath, preset_marks, signing, transfer
|
||||
from strata_control.targets import host_platform
|
||||
|
||||
STATE_DIR = ".updates"
|
||||
STAGE_DIR = ".s" # staging is short on purpose: <components>\.s\<4 hex>\engine\<folder> (see longpath.py)
|
||||
SKEW_FREE_BYTES = 1.15
|
||||
|
||||
|
||||
@@ -348,6 +349,7 @@ def extract(archive: Path, destination: Path, fmt: str, installed_bytes: int, *,
|
||||
raise UpdateError(f"the downloaded archive cannot be read ({type(exc).__name__})", 5) from None
|
||||
if total > installed_bytes:
|
||||
raise UpdateError(f"the archive holds {total} bytes, the signed feed says the package is {installed_bytes}; not unpacked", 5)
|
||||
destination = longpath.long_path(destination) # extended-length form: a long user name must not stop the unpacking
|
||||
if destination.exists():
|
||||
shutil.rmtree(destination, ignore_errors=True)
|
||||
try:
|
||||
@@ -358,6 +360,9 @@ def extract(archive: Path, destination: Path, fmt: str, installed_bytes: int, *,
|
||||
except components.ComponentError as exc:
|
||||
shutil.rmtree(destination, ignore_errors=True)
|
||||
raise UpdateError(f"the archive was refused: {exc}", 5) from None
|
||||
except OSError as exc:
|
||||
shutil.rmtree(destination, ignore_errors=True)
|
||||
raise UpdateError(f"the package could not be unpacked: {longpath.describe_oserror(exc)}", 6) from None
|
||||
|
||||
|
||||
def _free_space_check(root: Path, need: int) -> None:
|
||||
@@ -492,12 +497,25 @@ def check(ctx: Context) -> dict:
|
||||
return report
|
||||
|
||||
|
||||
def new_stage(root: Path, prefix: str = "") -> Path:
|
||||
r"""A fresh, short staging folder: ``<components>\.s\<4 hex>``. Old leftovers (a crashed update; the update lock is held, so
|
||||
nothing else uses them) are swept first, along with the longer folder older versions used."""
|
||||
base = root / STAGE_DIR
|
||||
for old in [base, updates_dir(root) / "staging"]:
|
||||
if old.exists():
|
||||
shutil.rmtree(longpath.long_path(old), ignore_errors=True)
|
||||
while True:
|
||||
stage = base / (prefix + uuid.uuid4().hex[:4])
|
||||
if not stage.exists():
|
||||
return stage
|
||||
|
||||
|
||||
def stage_engine(ctx: Context, feed: feedmod.Feed, pkg: feedmod.EnginePackage, archive: Path) -> tuple[Path, ec.EngineComponent]:
|
||||
"""Unpack and check a downloaded engine package in a staging component folder. Returns (staging root, component)."""
|
||||
stage_root = updates_dir(ctx.components) / "staging" / uuid.uuid4().hex[:12]
|
||||
stage_root = new_stage(ctx.components)
|
||||
folder = stage_root / "engine" / folder_name(pkg)
|
||||
ctx.say("verify", f"Unpacking {pkg.label}", component="engine")
|
||||
folder.parent.mkdir(parents=True, exist_ok=True)
|
||||
longpath.long_path(folder.parent).mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
extract(archive, folder, pkg.format, pkg.installed_bytes)
|
||||
manifest = folder / ec.MANIFEST
|
||||
@@ -530,9 +548,10 @@ def stage_engine(ctx: Context, feed: feedmod.Feed, pkg: feedmod.EnginePackage, a
|
||||
why = feedmod.engine_fit_reasons(pkg, ctx.hardware)
|
||||
if why:
|
||||
raise UpdateError("; ".join(why), 5)
|
||||
_warn_if_deep(ctx, ctx.components / "engine" / folder_name(pkg), max((len(rel) for rel, _, _ in component.files), default=0) + 1)
|
||||
return stage_root, component
|
||||
except BaseException:
|
||||
shutil.rmtree(stage_root, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(stage_root), ignore_errors=True)
|
||||
raise
|
||||
|
||||
|
||||
@@ -624,6 +643,17 @@ def _keep_log(sandbox: Path, component: ec.EngineComponent, ctx: Context) -> Non
|
||||
pass
|
||||
|
||||
|
||||
def _warn_if_deep(ctx: Context, folder: Path, longest_inside: int) -> None:
|
||||
"""Tell the person, in plain words, when the engine will sit too deep for Windows' ordinary path limit and long paths are
|
||||
off. The install continues: Strata's own file work uses extended paths; only the engine's own loading may not."""
|
||||
if getattr(ctx, "_deep_warned", False):
|
||||
return
|
||||
words = longpath.warning_for(folder, longest_inside)
|
||||
if words and not longpath.plain_long_paths_work(ctx.components):
|
||||
ctx._deep_warned = True
|
||||
ctx.say("warn", words, component="engine")
|
||||
|
||||
|
||||
def default_test_start(stage_root: Path, component: ec.EngineComponent, ctx: Context) -> dict:
|
||||
"""Start the staged engine through the real start path (owner runtime, `component:strata-engine`, a saved model), wait for
|
||||
the one-token generation probe, and stop it. Everything runs in an isolated runtime, profile and component folder, so a
|
||||
@@ -634,7 +664,7 @@ def default_test_start(stage_root: Path, component: ec.EngineComponent, ctx: Con
|
||||
raise TestStartFailed(component.version, "no installed model to test with")
|
||||
return binary_smoke(component)
|
||||
from strata_control import profiles, runtime
|
||||
sandbox = Path(tempfile.mkdtemp(prefix="test-start-", dir=stage_root))
|
||||
sandbox = Path(tempfile.mkdtemp(prefix="t-", dir=stage_root))
|
||||
try:
|
||||
cfg = json.loads(source.read_text(encoding="utf-8-sig"))
|
||||
cfg["exe"] = ec.REFERENCE_PREFIX + ec.COMPONENT_ID
|
||||
@@ -677,7 +707,7 @@ def default_test_start(stage_root: Path, component: ec.EngineComponent, ctx: Con
|
||||
except Exception: # noqa: BLE001 - stopping a sandbox is best effort
|
||||
pass
|
||||
finally:
|
||||
shutil.rmtree(sandbox, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(sandbox), ignore_errors=True)
|
||||
|
||||
|
||||
def _move_dir(source: Path, destination: Path) -> None:
|
||||
@@ -700,7 +730,7 @@ def prune_engines(root: Path, keep: set[str]) -> list[str]:
|
||||
for entry in sorted(folder.iterdir()):
|
||||
if entry.is_dir() and not entry.name.startswith(".") and entry.name not in keep:
|
||||
try:
|
||||
shutil.rmtree(entry)
|
||||
shutil.rmtree(longpath.long_path(entry))
|
||||
removed.append(entry.name)
|
||||
except OSError:
|
||||
pass # in use: it goes with the next update
|
||||
@@ -720,6 +750,7 @@ def update_engine(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
result["reasons"] = decision["reasons"]
|
||||
return result
|
||||
root = ctx.components
|
||||
_warn_if_deep(ctx, ec.engine_dir(root) / folder_name(pkg), longpath.LONGEST_IN_PACKAGE.get(pkg.backend, longpath.LONGEST_IN_PACKAGE_DEFAULT) + 1)
|
||||
_free_space_check(root, pkg.size + pkg.installed_bytes)
|
||||
archive = _download(ctx, "engine", pkg.url, pkg.size, pkg.sha256, f"engine {pkg.label}", feed)
|
||||
# busy check after the long download: a model may have been started meanwhile; the verified archive is kept for the retry
|
||||
@@ -756,7 +787,7 @@ def update_engine(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
staged_folder = stage_root / "engine" / name
|
||||
if final.exists():
|
||||
if (final / ec.MANIFEST).is_file() and _manifest_sha(final) == pkg.manifest_sha256:
|
||||
shutil.rmtree(staged_folder, ignore_errors=True) # already installed byte for byte: only the state changes
|
||||
shutil.rmtree(longpath.long_path(staged_folder), ignore_errors=True) # already installed byte for byte: only the state changes
|
||||
else:
|
||||
final = live / f"{name}-{pkg.manifest_sha256[:8]}"
|
||||
_move_dir(staged_folder, final)
|
||||
@@ -775,7 +806,7 @@ def update_engine(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
section["pinned"] = old_pin
|
||||
state.save()
|
||||
# the rename did not give a working engine: put it back where it cannot be picked
|
||||
shutil.rmtree(live / ".rejected", ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(live / ".rejected"), ignore_errors=True)
|
||||
(live / ".rejected").mkdir(parents=True, exist_ok=True)
|
||||
if final.exists():
|
||||
_move_dir(final, live / ".rejected" / final.name)
|
||||
@@ -800,7 +831,7 @@ def update_engine(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
ctx.say("done", f"Engine {pkg.version} is installed and will be used on the next start", component="engine")
|
||||
return result
|
||||
finally:
|
||||
shutil.rmtree(stage_root, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(stage_root), ignore_errors=True)
|
||||
|
||||
|
||||
def rollback_engine(ctx: Context) -> dict:
|
||||
@@ -888,7 +919,7 @@ def update_control(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
root = ctx.components
|
||||
_free_space_check(root, pkg.size + pkg.installed_bytes)
|
||||
archive = _download(ctx, "control", pkg.url, pkg.size, pkg.sha256, f"Control {pkg.version}", feed)
|
||||
stage = updates_dir(root) / "staging" / ("control-" + uuid.uuid4().hex[:8])
|
||||
stage = new_stage(root, "c")
|
||||
try:
|
||||
ctx.say("verify", f"Unpacking Control {pkg.version}", component="control")
|
||||
extract(archive, stage, pkg.format, pkg.installed_bytes, allow_links=pkg.format != "zip")
|
||||
@@ -909,7 +940,7 @@ def update_control(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
final = control_dir(root) / pkg.version
|
||||
control_dir(root).mkdir(parents=True, exist_ok=True)
|
||||
if final.exists():
|
||||
shutil.rmtree(final, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(final), ignore_errors=True)
|
||||
_move_dir(stage, final)
|
||||
section = state.section("control")
|
||||
previous = active_control(root)
|
||||
@@ -921,7 +952,7 @@ def update_control(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
keep = {pkg.version} | ({previous["folder"]} if previous else set())
|
||||
for entry_dir in control_dir(root).iterdir():
|
||||
if entry_dir.is_dir() and entry_dir.name not in keep:
|
||||
shutil.rmtree(entry_dir, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(entry_dir), ignore_errors=True)
|
||||
state.history({"at": (ctx.now or dt.datetime.now(dt.timezone.utc)).isoformat(), "action": "update-control",
|
||||
"from": decision["installed"], "to": pkg.version, "ok": True})
|
||||
archive.unlink(missing_ok=True)
|
||||
@@ -929,7 +960,7 @@ def update_control(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
|
||||
"note": "Control switches on the next start of the app or the terminal"})
|
||||
return result
|
||||
finally:
|
||||
shutil.rmtree(stage, ignore_errors=True)
|
||||
shutil.rmtree(longpath.long_path(stage), ignore_errors=True)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------- app
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"engines": [
|
||||
{
|
||||
"folder": "0.1.46-windows-x86_64-cuda-cuda12",
|
||||
"longest": [
|
||||
"engine-component.json",
|
||||
"cublasLt64_12.dll",
|
||||
"strata-vision.exe"
|
||||
],
|
||||
"files": 8
|
||||
},
|
||||
{
|
||||
"folder": "0.1.46-windows-x86_64-cuda-cuda13",
|
||||
"longest": [
|
||||
"engine-component.json",
|
||||
"cublasLt64_13.dll",
|
||||
"strata-vision.exe"
|
||||
],
|
||||
"files": 7
|
||||
},
|
||||
{
|
||||
"folder": "0.1.46-windows-x86_64-hip-rdna3",
|
||||
"longest": [
|
||||
"rocm/bin/hipblaslt/library/gfx1100/TensileLibrary_BB_BB_HA_Bias_Aux_SAV_UA_Type_BB_HPA_Contraction_l_Ailk_Bjlk_Cijk_Dijk_gfx1100.dat.zlib",
|
||||
"rocm/bin/hipblaslt/library/gfx1100/TensileLibrary_BB_BB_HA_Bias_Aux_SAV_UA_Type_BB_HPA_Contraction_l_Ailk_Bljk_Cijk_Dijk_gfx1100.dat.zlib",
|
||||
"rocm/bin/hipblaslt/library/gfx1100/TensileLibrary_BB_BB_HA_Bias_Aux_SAV_UA_Type_BB_HPA_Contraction_l_Alik_Bjlk_Cijk_Dijk_gfx1100.dat.zlib"
|
||||
],
|
||||
"files": 1050
|
||||
},
|
||||
{
|
||||
"folder": "0.1.46-windows-x86_64-hip-rx9070",
|
||||
"longest": [
|
||||
"rocm/bin/hipblaslt/library/gfx1200/TensileLibrary_B8F8_B8B8F8_HA_Bias_SAB_SCD_SAV_UA_Type_B8B8_HPA_Contraction_l_Ailk_Bjlk_Cijk_Dijk_gfx1200.dat.zlib",
|
||||
"rocm/bin/hipblaslt/library/gfx1200/TensileLibrary_B8F8_B8B8F8_HA_Bias_SAB_SCD_SAV_UA_Type_B8B8_HPA_Contraction_l_Ailk_Bljk_Cijk_Dijk_gfx1200.dat.zlib",
|
||||
"rocm/bin/hipblaslt/library/gfx1200/TensileLibrary_B8F8_B8B8F8_HA_Bias_SAB_SCD_SAV_UA_Type_B8B8_HPA_Contraction_l_Alik_Bjlk_Cijk_Dijk_gfx1200.dat.zlib"
|
||||
],
|
||||
"files": 831
|
||||
}
|
||||
],
|
||||
"control": [
|
||||
{
|
||||
"version": "0.1.46",
|
||||
"longest": [
|
||||
"python/Lib/site-packages/numpy-2.5.3.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING",
|
||||
"python/Lib/site-packages/numpy-2.5.3.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md",
|
||||
"python/Lib/site-packages/numpy-2.5.3.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt"
|
||||
],
|
||||
"files": 5679
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
"""Windows MAX_PATH (260) and the engine installer.
|
||||
|
||||
A fresh Windows PC has long paths off. `strata launch` on an AMD PC failed with "local file operation failed
|
||||
(FileNotFoundError)" because the staging folder (components\\.updates\\staging\\<12 hex>\\engine\\<folder>) plus the longest file in
|
||||
the hip packages (149 characters) went past 259 under an ordinary user name. This pins the path arithmetic for the real 0.2.1
|
||||
package file lists (tests/terminal/data/windows_package_paths.json, made from the release tarballs) and the behaviour of the fix."""
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path, PureWindowsPath
|
||||
from unittest import mock
|
||||
|
||||
from strata_control import engine_component as ec, longpath, updater
|
||||
|
||||
DATA = json.loads((Path(__file__).parent / "data" / "windows_package_paths.json").read_text(encoding="utf-8"))
|
||||
LIMIT = longpath.PLAIN_LIMIT
|
||||
USER = "u" * 20
|
||||
COMPONENTS = PureWindowsPath(rf"C:\Users\{USER}\AppData\Local\Strata\components") # what components_dir() gives on Windows
|
||||
LEGACY_STAGE = COMPONENTS / ".updates" / "staging" / ("0123456789ab") # what 0.2.1 used
|
||||
NEW_STAGE = COMPONENTS / updater.STAGE_DIR / "0123"
|
||||
WINDOWS = os.name == "nt"
|
||||
|
||||
|
||||
def longest(entry) -> str:
|
||||
return max(entry["longest"], key=len)
|
||||
|
||||
|
||||
class PathArithmetic(unittest.TestCase):
|
||||
def test_the_old_staging_folder_was_past_the_limit(self):
|
||||
"""The reproduction: with the 0.2.1 layout the AMD packages do not fit under a 20-character user name."""
|
||||
too_long = {}
|
||||
for e in DATA["engines"]:
|
||||
n = len(str(LEGACY_STAGE / "engine" / e["folder"] / longest(e)))
|
||||
if n > LIMIT:
|
||||
too_long[e["folder"]] = n
|
||||
self.assertEqual(sorted(too_long), ["0.1.46-windows-x86_64-hip-rdna3", "0.1.46-windows-x86_64-hip-rx9070"], too_long)
|
||||
|
||||
def test_every_staged_path_fits_for_a_20_character_user_name(self):
|
||||
for e in DATA["engines"]:
|
||||
n = len(str(NEW_STAGE / "engine" / e["folder"] / longest(e)))
|
||||
self.assertLessEqual(n, LIMIT, f"{e['folder']}: staged path is {n} characters")
|
||||
|
||||
def test_every_final_path_fits_for_a_20_character_user_name(self):
|
||||
for e in DATA["engines"]:
|
||||
n = len(str(COMPONENTS / "engine" / e["folder"] / longest(e)))
|
||||
self.assertLessEqual(n, LIMIT, f"{e['folder']}: installed path is {n} characters")
|
||||
for c in DATA["control"]:
|
||||
for base in (COMPONENTS / "control" / c["version"], COMPONENTS / updater.STAGE_DIR / "c0123"):
|
||||
n = len(str(base / longest(c)))
|
||||
self.assertLessEqual(n, LIMIT, f"control {c['version']}: path is {n} characters")
|
||||
|
||||
def test_staging_is_no_deeper_than_nine_characters_over_the_install(self):
|
||||
live = COMPONENTS / "engine" / "x"
|
||||
staged = NEW_STAGE / "engine" / "x"
|
||||
self.assertLessEqual(len(str(staged)) - len(str(live)), 9)
|
||||
|
||||
def test_the_hip_estimate_covers_the_real_packages(self):
|
||||
for e in DATA["engines"]:
|
||||
if "-hip-" in e["folder"]:
|
||||
self.assertGreaterEqual(longpath.LONGEST_IN_PACKAGE["hip"], len(longest(e)))
|
||||
|
||||
|
||||
class Messages(unittest.TestCase):
|
||||
def test_a_missing_file_is_named(self):
|
||||
words = longpath.file_words(FileNotFoundError(2, "No such file or directory", r"C:\x\y\z.dat"))
|
||||
self.assertIn(r"C:\x\y\z.dat", words)
|
||||
self.assertIn("FileNotFoundError", words)
|
||||
|
||||
def test_something_without_a_name_still_says_what_kind(self):
|
||||
self.assertIn("(OSError)", longpath.file_words(OSError("boom")))
|
||||
|
||||
@unittest.skipUnless(WINDOWS, "the limit is a Windows one")
|
||||
def test_a_path_that_is_too_long_says_so(self):
|
||||
name = "C:\\" + "\\".join(["d" * 60] * 5) + "\\file.dat"
|
||||
words = longpath.file_words(FileNotFoundError(2, "No such file or directory", name))
|
||||
self.assertIn("longer than Windows allows", words)
|
||||
self.assertIn("STRATA_COMPONENTS_DIR", words)
|
||||
self.assertIn(name, words)
|
||||
|
||||
@unittest.skipUnless(WINDOWS, "the limit is a Windows one")
|
||||
def test_no_warning_for_a_short_folder_and_one_for_a_deep_one(self):
|
||||
self.assertIsNone(longpath.warning_for(Path(r"C:\Strata\engine\0.1.46-windows-x86_64-hip-rdna3"), 150))
|
||||
deep = Path("C:/Users/" + USER + "/AppData/Local/Strata/components/engine/0.1.46-windows-x86_64-hip-rx9070/" + "q" * 30)
|
||||
words = longpath.warning_for(deep, 150)
|
||||
self.assertIn("long paths", words)
|
||||
self.assertIn("carries on", words)
|
||||
|
||||
|
||||
@unittest.skipUnless(WINDOWS, "extended-length paths are a Windows thing")
|
||||
class DeepFolders(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory(prefix="strata-lp-")
|
||||
self.addCleanup(lambda: __import__("shutil").rmtree(longpath.long_path(self.temp.name), ignore_errors=True))
|
||||
self.deep = Path(self.temp.name) / ("p" * 120) / ("q" * 120)
|
||||
|
||||
def archive(self, member, data=b"engine bytes"):
|
||||
raw = io.BytesIO()
|
||||
with tarfile.open(fileobj=raw, mode="w:gz") as tar:
|
||||
info = tarfile.TarInfo(member)
|
||||
info.size = len(data)
|
||||
tar.addfile(info, io.BytesIO(data))
|
||||
path = Path(self.temp.name) / "pkg.tar.gz"
|
||||
path.write_bytes(raw.getvalue())
|
||||
return path
|
||||
|
||||
def test_long_path_adds_the_prefix_once(self):
|
||||
p = longpath.long_path(r"C:\a\b")
|
||||
self.assertTrue(str(p).startswith("\\\\?\\C:\\a"))
|
||||
self.assertEqual(longpath.long_path(p), p)
|
||||
self.assertEqual(longpath.plain(p), r"C:\a\b")
|
||||
|
||||
def test_extract_goes_through_the_extended_form(self):
|
||||
member = "rocm/bin/hipblaslt/library/gfx1151/" + "T" * 137 + ".dat.zlib"
|
||||
archive = self.archive(member)
|
||||
seen = []
|
||||
real = updater.components.safe_extract
|
||||
|
||||
def spy(archive_, destination, **kw):
|
||||
seen.append(str(destination))
|
||||
return real(archive_, destination, **kw)
|
||||
|
||||
with mock.patch.object(updater.components, "safe_extract", spy):
|
||||
updater.extract(archive, self.deep / "engine" / "x", "tar.gz", 1 << 20)
|
||||
self.assertTrue(seen[0].startswith("\\\\?\\"), seen)
|
||||
target = longpath.long_path(self.deep / "engine" / "x") / member
|
||||
self.assertGreater(len(longpath.plain(target)), LIMIT)
|
||||
self.assertEqual(target.read_bytes(), b"engine bytes")
|
||||
|
||||
def test_a_failed_unpack_names_the_file(self):
|
||||
archive = self.archive("a/b.dat")
|
||||
with mock.patch.object(updater.components, "safe_extract", side_effect=FileNotFoundError(3, "The system cannot find the path", r"C:\n\o.dat")):
|
||||
with self.assertRaises(updater.UpdateError) as cm:
|
||||
updater.extract(archive, self.deep, "tar.gz", 1 << 20)
|
||||
self.assertIn(r"C:\n\o.dat", str(cm.exception))
|
||||
self.assertEqual(cm.exception.exit_code, 6)
|
||||
|
||||
def test_verify_reads_files_that_sit_past_the_limit(self):
|
||||
from tests.terminal import update_fixture as fx
|
||||
root = Path(self.temp.name)
|
||||
built = fx.build_package(root / "b", "0.1.45")
|
||||
# a folder deep enough that the stub's files are past 259 characters
|
||||
base = longpath.long_path(root / ("m" * 110) / ("n" * 110))
|
||||
import shutil
|
||||
shutil.copytree(longpath.long_path(built), base / built.name)
|
||||
component = ec.read_manifest(base / built.name)
|
||||
self.assertGreater(len(longpath.plain(base / built.name / component.entrypoint)), 0)
|
||||
ec.verify(component, full=True) # raises IntegrityProblem if a file looks missing
|
||||
|
||||
def test_the_probe_runs_and_cleans_up(self):
|
||||
longpath.plain_long_paths_work(Path(self.temp.name))
|
||||
self.assertEqual([p.name for p in Path(self.temp.name).iterdir() if p.name.startswith(".lp-")], [])
|
||||
|
||||
|
||||
class StagingFolder(unittest.TestCase):
|
||||
def test_new_stage_is_short_and_sweeps_old_staging(self):
|
||||
with tempfile.TemporaryDirectory(prefix="strata-stage-") as tmp:
|
||||
root = Path(tmp)
|
||||
old = root / ".updates" / "staging" / "abc"
|
||||
old.mkdir(parents=True)
|
||||
stale = root / updater.STAGE_DIR / "dead"
|
||||
stale.mkdir(parents=True)
|
||||
stage = updater.new_stage(root)
|
||||
self.assertEqual(stage.parent, root / updater.STAGE_DIR)
|
||||
self.assertEqual(len(stage.name), 4)
|
||||
self.assertFalse(old.exists() or stale.exists())
|
||||
self.assertTrue(updater.new_stage(root, "c").name.startswith("c"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -177,12 +177,12 @@ class EngineUpdate(UpdaterCase):
|
||||
"the previous version stays for a manual rollback")
|
||||
# the test start ran the staged copy, not a file in the live folder
|
||||
ran = (self.root / "ran.txt").read_text().splitlines()[0]
|
||||
self.assertIn(os.sep + ".updates" + os.sep + "staging" + os.sep, ran)
|
||||
self.assertIn(os.sep + ".s" + os.sep, ran)
|
||||
phases = [e.get("phase") for e in events if e.get("event") == "phase"]
|
||||
self.assertEqual(phases, ["feed", "download", "verify", "verify", "test", "switch", "done"])
|
||||
progress = [e for e in events if e.get("event") == "progress"]
|
||||
self.assertTrue(progress and progress[-1]["percent"] == 100 and progress[-1]["done"] == progress[-1]["total"])
|
||||
self.assertEqual(sorted(p.name for p in (self.components / ".updates" / "staging").iterdir()), [], "staging is cleaned")
|
||||
self.assertEqual(sorted(p.name for p in (self.components / ".s").iterdir()), [], "staging is cleaned")
|
||||
self.assertEqual(list((self.components / ".updates" / "partial").iterdir()), [], "the archive is removed after the switch")
|
||||
state = json.loads((self.components / ".updates" / "state.json").read_text())
|
||||
self.assertEqual(state["engine"]["previous"], old.name)
|
||||
@@ -220,7 +220,7 @@ class EngineUpdate(UpdaterCase):
|
||||
self.assertIn("unchanged", result["error"])
|
||||
self.assertEqual(self.resolved(), "0.1.45")
|
||||
self.assertEqual(self.engine_folders(), [f"0.1.45-{PLATFORM}-cuda-cuda13"], "the failed engine was never put in the live folder")
|
||||
self.assertEqual(sorted(p.name for p in (self.components / ".updates" / "staging").iterdir()), [])
|
||||
self.assertEqual(sorted(p.name for p in (self.components / ".s").iterdir()), [])
|
||||
self.assertEqual(preset_marks.pending(self.state_base), [])
|
||||
self.assert_user_data_untouched()
|
||||
# it is not offered again until forced, and the archive is not downloaded twice
|
||||
|
||||
Reference in new issue
Block a user