#!/usr/bin/env python3 """Создаёт и проверяет runtime-cancel рекурсивного группового F8.""" from __future__ import annotations import pathlib import sys DIRECTORY_COUNT = 180 def payload(index: int) -> bytes: return bytes(((offset * 17 + index) & 0xFF) for offset in range(97)) def create(root: pathlib.Path) -> None: panel = root / "CDEL" tree = panel / "TREE" tree.mkdir(parents=True) for index in range(DIRECTORY_COUNT): child = tree / f"D{index:03d}" child.mkdir() (child / "ITEM.BIN").write_bytes(payload(index)) (panel / "TOP.BIN").write_bytes(b"top-level selected file\r\n") (panel / "KEEP.TXT").write_bytes(b"unselected cancel sentinel\r\n") def verify(root: pathlib.Path) -> None: panel = root / "CDEL" failures: list[str] = [] if (panel / "TOP.BIN").exists(): failures.append("завершённое удаление TOP.BIN ошибочно откатилось") keep = panel / "KEEP.TXT" if not keep.is_file() or keep.read_bytes() != b"unselected cancel sentinel\r\n": failures.append("невыбранный KEEP.TXT отсутствует или изменён") tree = panel / "TREE" if not tree.is_dir(): failures.append("TREE успел удалиться целиком: runtime-cancel не подтверждён") else: remaining = list(tree.glob("D*/ITEM.BIN")) if not remaining: failures.append("после cancel не осталось ни одного файла дерева") for path in remaining: index = int(path.parent.name[1:]) if path.read_bytes() != payload(index): failures.append(f"повреждён оставшийся файл: {path.name}") break if failures: for failure in failures: print(f"FAIL: {failure}") raise SystemExit(1) print("PASS: runtime cancel kept remaining tree; completed TOP delete remains.") def main() -> None: if len(sys.argv) != 3 or sys.argv[1] not in {"create", "verify"}: raise SystemExit(f"usage: {sys.argv[0]} create|verify DIR") root = pathlib.Path(sys.argv[2]) if sys.argv[1] == "create": create(root) else: verify(root) if __name__ == "__main__": main()