INNER CODE UNIT · Python
dest
kangarooking/cangjie-skill · scripts/apply_skill_patch.py:37
dest = target / rel
old = dest.read_text(encoding="utf-8") if dest.exists() else ""
new = pf.read_text(encoding="utf-8")
diff_lines.append(f"### {rel}: {'修改' if dest.exists() else '新增'}({len(old)} → {len(new)} 字符)")
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(pf, dest)
check = subprocess.run([sys.executable, str(SCRIPTS / "validate_skill_pack.py"), str(target)],
capture_output=True, text=True)
if check.returncode != 0:
shutil.rmtree(target)
shutil.copytree(snap, target)
print(check.stdout + check.stderr)
raise SystemExit("[rollback] 补丁后校验失败,已自动恢复快照")
print("\n".join(diff_lines))
print(f"补丁已应用并通过校验({len(patch_files)} 个文件)。回滚: apply_skill_patch.py restore --snapshot {snap}")
return 0