Artifact 12b240ba582a5b8fb493ffdd69ecfcd1036d40daec45e2e5867ba44fa2b4eb58:
- File
src/main.c
— part of check-in
[cbd57cce10]
at
2026-11-12 22:50:34
on branch trunk
— A store interrupted mid-update can be repaired, and symlinks are refused
An update now writes a journal before it changes anything and removes it only when the update, or the put-back after a failure, has finished. If the journal is still there, every store command refuses and names the fix. suit store repair restores each file to the version the store was leaving. Tested with a double failure and by killing suit in the middle of a slowed 100-file update: repair restored every byte.
libfossil's checkout writes symlinks as regular files, so suit refuses them outright: store open and update refuse a version that holds one, and commit refuses to check one in. Each names the path.
The fuzz corpus libFuzzer grew is minimized and checked in (300 inputs for the config parser, 83 for the stamp reader), so every push replays it under the sanitizers and Fil-C.
The budget test takes the best of three runs. It measured 0.43 to 0.59 ms quiet and 0.72 to 0.88 ms at a load average of 130 to 170.
243 unit checks, 220 shell cases, 146 store cases. 100% coverage in all ten source files. (user: dmestas, size: 2060) [annotate] [blame] [check-ins using]
#include "bench.h" #include "conf.h" #include "platform.h" #include "stamp.h" #include "store.h" #include <errno.h> #include <string.h> #include <unistd.h> static Conf conf; static int usage(void) { say(STDERR_FILENO, "usage: suit check FILE\n" " suit store open|status|update|repair NAME\n" " suit commit NAME -m TEXT\n" " suit back NAME\n" " suit stamp PATH...\n" " suit run\n" " suit bench [-n N] [-e EMPTY_PROGRAM] [-t MICROSECONDS] [-m KIB]\n"); return 2; } static int cmd_check(const char *path) { ConfError err; if (!conf_load(&conf, path, &err)) { say(STDERR_FILENO, "%s:%d: %s\n", path, err.line, err.msg); return 2; } if (!conf_dump(&conf, STDOUT_FILENO)) { say(STDERR_FILENO, "suit: cannot write the dump: %s\n", strerror(errno)); return 1; } return 0; } static int cmd_store(int argc, char **argv) { if (argc != 4) return usage(); const char *verb = argv[2]; if (strcmp(verb, "open") == 0) return store_open(argv[3]); if (strcmp(verb, "status") == 0) return store_status(argv[3]); if (strcmp(verb, "update") == 0) return store_update(argv[3]); if (strcmp(verb, "repair") == 0) return store_repair(argv[3]); return usage(); } int main(int argc, char **argv) { if (argc < 2) return usage(); const char *cmd = argv[1]; if (strcmp(cmd, "run") == 0) return argc == 2 ? stamp_check(true) : usage(); if (strcmp(cmd, "check") == 0) return argc == 3 ? cmd_check(argv[2]) : usage(); if (strcmp(cmd, "stamp") == 0) return argc >= 3 ? stamp_write(argc - 2, argv + 2) : usage(); if (strcmp(cmd, "store") == 0) return cmd_store(argc, argv); if (strcmp(cmd, "back") == 0) return argc == 3 ? store_back(argv[2]) : usage(); if (strcmp(cmd, "commit") == 0) return argc == 5 && strcmp(argv[3], "-m") == 0 ? store_commit(argv[2], argv[4]) : usage(); if (strcmp(cmd, "bench") == 0) return bench_main(argc - 2, argv + 2); return usage(); }