fix: preserve cron env patch newlines

This commit is contained in:
zhx 2026-07-18 19:14:05 +08:00
parent 16eb283908
commit 655e20e276

View File

@ -342,7 +342,9 @@ for key, value in updates.items():
output.append(f"{{key}}={{json.dumps(str(value))}}")
target.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=target.parent, delete=False) as handle:
handle.write("\n".join(output).rstrip() + "\n")
# 这段 Python 会先嵌入外层远端 shell 模板;必须保留反斜杠,避免外层
# f-string 把 \\n 提前展开成源码换行,导致目标机激活脚本语法错误。
handle.write("\\n".join(output).rstrip() + "\\n")
temp_name = handle.name
os.chmod(temp_name, original_mode)
os.replace(temp_name, target)