packaging: monitor rollback works on Windows (os.rename cannot replace the mkdtemp directory)

This commit is contained in:
Niko1221 committed 2026-10-15 11:05:28 +02:00
1 parent d442b0307f
commit 515e045faf
1 file changed
+5 -1
+5 -1
View File
@@ -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}