From 515e045fafe0264494f59fc4e75efdf6fbbb1eff Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 15 Oct 2026 11:05:28 +0200 Subject: [PATCH] packaging: monitor rollback works on Windows (os.rename cannot replace the mkdtemp directory) --- packaging/monitor_bundle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packaging/monitor_bundle.py b/packaging/monitor_bundle.py index ea67cddc..0abadadd 100644 --- a/packaging/monitor_bundle.py +++ b/packaging/monitor_bundle.py @@ -259,6 +259,10 @@ def rollback(target: Path, *, plan: bool = False, if if_active_sha256 != active["sha256"] or if_rollback_sha256 != prior["sha256"]: raise ValueError("monitor rollback digests changed or are missing; preview again") swap = Path(tempfile.mkdtemp(prefix=".strata-monitor-swap-", dir=target.parent)) + if os.name == "nt": + # os.rename onto an existing directory fails on Windows (POSIX replaces an empty one): + # keep only the unique name mkdtemp reserved. + swap.rmdir() try: os.rename(target, swap) try: @@ -279,7 +283,7 @@ def rollback(target: Path, *, plan: bool = False, raise OSError(f"monitor rollback interrupted; inspect {target}, {previous} and {swap}") from exc raise finally: - if swap.exists() and not any(swap.iterdir()): + if swap.is_dir() and not any(swap.iterdir()): swap.rmdir() return {**result, "rolled_back": True, "would_rollback": False}