mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-28 04:02:18 +01:00
Stage the nine managed GitHub launcher files through one bounded control command. Preserve per-file locks, content verification, atomic replacement and control-channel dispatch. Real Daytona staging decreased from about one second to 0.24–0.34 seconds. Full CI, E2E, Superagent and Apex 5/5 passed on the reviewed head. Co-Authored-By: Paperclip <noreply@paperclip.ing>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
function shellQuote(value: string) {
|
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
}
|
|
|
|
export function buildRemotePidLockAcquireScript(lockDirExpr: string, timeoutMessage: string): string[] {
|
|
return [
|
|
"attempts=0",
|
|
`while ! mkdir ${lockDirExpr} 2>/dev/null; do`,
|
|
" holder_pid=\"\"",
|
|
` if [ -s ${lockDirExpr}/pid ]; then`,
|
|
` holder_pid="$(cat ${lockDirExpr}/pid 2>/dev/null || true)"`,
|
|
" fi",
|
|
" if [ -n \"$holder_pid\" ] && ! kill -0 \"$holder_pid\" 2>/dev/null; then",
|
|
` rm -rf ${lockDirExpr}`,
|
|
" continue",
|
|
" fi",
|
|
" attempts=$((attempts + 1))",
|
|
" if [ \"$attempts\" -ge 600 ]; then",
|
|
` echo ${shellQuote(timeoutMessage)} >&2`,
|
|
" exit 1",
|
|
" fi",
|
|
" sleep 0.05",
|
|
"done",
|
|
`printf '%s\\n' "$$" > ${lockDirExpr}/pid`,
|
|
];
|
|
}
|
|
|
|
export function buildRemotePidLockCleanupScript(lockDirExpr: string, cleanupLines: string[]): string[] {
|
|
return [
|
|
"cleanup() {",
|
|
...cleanupLines.map((line) => ` ${line}`),
|
|
` rm -rf ${lockDirExpr}`,
|
|
"}",
|
|
"trap cleanup EXIT INT TERM",
|
|
];
|
|
}
|