Artifact 7b7ac4b0ff58af8b3c9dce3543ec5fa365ad1fa36d19a0599a76f5fff27c7e79:
- File
src/conf.h
— part of check-in
[2f274ce15b]
at
2026-11-12 22:28:09
on branch trunk
— Phase 2: the store, a working copy that is never half written
The store is a working copy of a wardrobe, kept through libfossil's C API with suit's own file writer: every file is written beside itself and renamed, so a reader sees the old file or the new one.
suit store open, status and update, suit commit and suit back. An update refuses when there are local changes, runs as a dry run first, and changes nothing if any file would conflict.
Proven here: the store is byte-identical to fossil's own checkout of a 600-file wardrobe at each version; a reader hashing files during a slowed update saw only old or new contents; an update that fails at any call leaves the old bytes and no temporary file. 100% of functions, lines, regions and branches in all ten source files.
Vendored, unedited: libfossil trunk f2983dcd78, SQLite 3.55.0, zlib 1.3.1. The release binary links only the system library.
Speed: with everything linked, suit costs 0.82 ms over an empty program quiet and up to 1.38 ms under load, which is over budget. The timer's entry point is now suit-run, a 35 KB program built from the no-change path alone, at 0.40 ms quiet and about 0.5 ms loaded. It runs suit only when something changed. The budget test is on suit-run.
Known limits, recorded in docs/decisions.md: libfossil's checkout writes symlinks as regular files, so wardrobes may not hold them; suit back undoes an update and not a check-in; and a store left half updated by a double failure has no repair command yet.
Not yet run: Fil-C and the Linux build of this phase. (user: dmestas, size: 2330) [annotate] [blame] [check-ins using]
#ifndef SUIT_CONF_H #define SUIT_CONF_H #include <stddef.h> #include <stdint.h> constexpr size_t CONF_LINE_MAX = 4096; constexpr size_t CONF_FILE_MAX = 1048576; constexpr size_t CONF_NAME_MAX = 128; constexpr uint32_t CONF_HARNESS_MAX = 64; constexpr uint32_t CONF_OUTFIT_MAX = 512; constexpr uint32_t CONF_WEAR_MAX = 256; constexpr uint32_t CONF_NEED_MAX = 256; constexpr uint32_t CONF_UPSTREAM_MAX = 128; constexpr uint32_t CONF_ENTRY_MAX = 8192; constexpr uint32_t CONF_SECTION_MAX = CONF_HARNESS_MAX + CONF_OUTFIT_MAX + CONF_WEAR_MAX + CONF_NEED_MAX + CONF_UPSTREAM_MAX; typedef enum { KIND_HARNESS, KIND_OUTFIT, KIND_WEAR, KIND_NEED, KIND_UPSTREAM, KIND_COUNT } Kind; // Every string points into Conf.buf. A list value is stored with its words // separated by single spaces; walk it with conf_list_next. typedef struct { const char *key; const char *val; int line; } Entry; // harness, outfit, upstream: arg[0] is the name. // need: arg[0] is the harness, arg[1] the name. // wear: arg[0] is the scope, arg[1] the target ("" if none), arg[2] the // machine name ("" if none). typedef struct { Kind kind; const char *arg[3]; int line; uint32_t first; uint32_t count; } Section; typedef struct { uint32_t nsections; uint32_t nentries; uint32_t kind_count[KIND_COUNT]; Section sections[CONF_SECTION_MAX]; Entry entries[CONF_ENTRY_MAX]; char buf[CONF_FILE_MAX + 1]; } Conf; // line is 0 when the error concerns the whole file. typedef struct { int line; char msg[256]; } ConfError; // Parse DATA (LEN bytes) into C. On failure C holds nothing usable and ERR // says what and where. [[nodiscard]] bool conf_parse(Conf *c, const char *data, size_t len, ConfError *err); [[nodiscard]] bool conf_load(Conf *c, const char *path, ConfError *err); // Write the canonical dump to FD: sections and entries in stable order, one // fact per line. Reorders C in place. False if a write fails (errno set). [[nodiscard]] bool conf_dump(Conf *c, int fd); // True if the LEN bytes are a name: 1 to 128 of A-Z a-z 0-9 . _ - (and * // if GLOB). bool conf_name_ok(const char *s, size_t len, bool glob); // Step through a list value. Returns false at the end. bool conf_list_next(const char **cursor, const char **word, size_t *len); #endif