Artifact e1f3453ab3c22074cfb041729a3b574ce2b886eb3739cffdfd19a13cbad58c9f:
- File
src/ledger.h
— part of check-in
[f96cbc3342]
at
2026-11-13 03:51:02
on branch trunk
— Phase 4a: outfits limited to a machine, and instruction files joined
suit machine shows or sets this machine's name. An outfit worn with machine=NAME applies on that machine and nowhere else, and where it and an unlimited outfit supply the same destination the machine's wins.
A harness has one instruction file per scope. When the unlimited and the machine-limited outfit both supply instructions, suit writes one file with the unlimited text first and the machine's after it, and links the harness to that. It is rewritten when either source changes and removed when no longer needed. This is the one case where an edit in the store reaches a harness only after suit's next run.
The ledger gains an entry for a file suit wrote, so suit off removes the joined file too.
420 unit checks, 227 shell cases, 146 store cases, 612 placement cases, under clang and under gcc 16. 100% coverage in all 16 source files. The no-change run costs about 0.46 ms over an empty program quiet and 0.66 to 0.79 ms loaded.
The checked-in fuzz corpus now includes inputs grown for the ledger reader (61) and more for the stamp reader (108), beside the config parser's 300. The replay tool's input table grew, because fuzzing had filled the old one on the development machine. (user: dmestas, size: 1776) [annotate] [blame] [check-ins using]
#ifndef SUIT_LEDGER_H #define SUIT_LEDGER_H #include <stddef.h> #include <stdint.h> // The ledger, $SUIT_HOME/ledger: the only record of what suit owns. One line // per thing suit made: // // link DEST SOURCE a symlink at DEST pointing at SOURCE // dir DEST a folder suit made to hold a link or a file // file DEST a file suit wrote: a joined instruction file // // Paths are absolute, with no space or newline in them. Nothing else is // allowed in the file: a line that is not one of these is an error, and the // whole file is rejected. constexpr size_t LEDGER_FILE_MAX = 1048576; constexpr size_t LEDGER_LINE_MAX = 8192; constexpr uint32_t LEDGER_ENTRY_MAX = 4096; typedef enum { ENTRY_LINK, ENTRY_DIR, ENTRY_FILE } EntryKind; typedef struct { EntryKind kind; const char *dest; const char *src; // nullptr for a dir or a file } LedgerEntry; typedef struct { uint32_t n; LedgerEntry e[LEDGER_ENTRY_MAX]; char buf[LEDGER_FILE_MAX + 1]; } Ledger; // line is 0 when the error concerns the whole file. typedef struct { int line; char msg[256]; } LedgerError; // Parse DATA (LEN bytes). On failure L is empty and ERR says what and where. [[nodiscard]] bool ledger_parse(Ledger *l, const char *data, size_t len, LedgerError *err); // Read PATH. A file that is not there is an empty ledger. [[nodiscard]] bool ledger_load(Ledger *l, const char *path, LedgerError *err); // Write the entries, links then dirs then files, each sorted by path, atomically. Returns 0 // or an errno value. L's entries need not point into L's own buffer. int ledger_write(const Ledger *l, const char *path); // The link entry for DEST, or nullptr. const LedgerEntry *ledger_find_link(const Ledger *l, const char *dest); #endif