fix: keep task completion, cancel, pause, and undo honest

Pending earlier-revision jobs no longer skip completion repair; late
cancels preserve real exits; begin clears pause; partial undo keeps
snapshots; permissions and worktree failure paths are hardened.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
WHC
2026-10-28 22:09:47 +08:00
co-authored by Cursor
parent d971cb02b0
commit acd6f1d998
7 changed files with 111 additions and 17 deletions
+10 -1
View File
@@ -83,12 +83,21 @@ static int save(const cst_perms_t *p) {
cJSON_Delete(root);
if (!txt)
return -1;
FILE *fp = fopen(p->path, "wb");
char tmp[OS_PATH_MAX + 8];
if (snprintf(tmp, sizeof(tmp), "%s.tmp", p->path) >= (int)sizeof(tmp)) {
free(txt);
return -1;
}
FILE *fp = fopen(tmp, "wb");
int rc = -1;
if (fp) {
rc = fputs(txt, fp) >= 0 && fputs("\n", fp) >= 0 ? 0 : -1;
if (fclose(fp) != 0)
rc = -1;
if (rc == 0)
rc = os_rename_replace(tmp, p->path);
if (rc != 0)
remove(tmp);
}
free(txt);
return rc;