MCPcopy Create free account
hub / github.com/DSGWJQ/Feagent / _write_rollback_scripts

Function _write_rollback_scripts

scripts/organize_project_files.py:455–480  ·  view source on GitHub ↗
(
    root: Path, moved_pairs: list[tuple[Path, Path]], *, dry_run: bool
)

Source from the content-addressed store, hash-verified

453
454
455def _write_rollback_scripts(
456 root: Path, moved_pairs: list[tuple[Path, Path]], *, dry_run: bool
457) -> None:
458 stamp = _now_stamp()
459 sh_path = root / "logs" / f"undo_organization_{stamp}.sh"
460 ps_path = root / "logs" / f"undo_organization_{stamp}.ps1"
461
462 # 反向执行:从 dst 移回 src。按逆序更安全。
463 lines_sh = ["#!/usr/bin/env bash", "set -euo pipefail", ""]
464 lines_ps = ["Set-StrictMode -Version Latest", "$ErrorActionPreference = 'Stop'", ""]
465 for src, dst in reversed(moved_pairs):
466 lines_sh.append(f"mkdir -p {shlex_quote(str(src.parent))}")
467 lines_sh.append(f"mv {shlex_quote(str(dst))} {shlex_quote(str(src))}")
468 lines_ps.append(
469 f"New-Item -ItemType Directory -Force -Path {ps_quote(str(src.parent))} | Out-Null"
470 )
471 lines_ps.append(
472 f"Move-Item -Force -Path {ps_quote(str(dst))} -Destination {ps_quote(str(src))}"
473 )
474
475 if dry_run:
476 return
477
478 sh_path.parent.mkdir(parents=True, exist_ok=True)
479 sh_path.write_text("\n".join(lines_sh) + "\n", encoding="utf-8")
480 ps_path.write_text("\n".join(lines_ps) + "\n", encoding="utf-8")
481
482
483def shlex_quote(s: str) -> str:

Callers 1

_apply_actionsFunction · 0.85

Calls 4

_now_stampFunction · 0.85
shlex_quoteFunction · 0.85
ps_quoteFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected