Artifact 0474980a8fdef6ec66e932b7d64fce41c1c5798064ab15598728b874f26c1849:
- File
src/place.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: 2697) [annotate] [blame] [check-ins using]
#ifndef SUIT_PLACE_H #define SUIT_PLACE_H #include "ledger.h" #include "resolve.h" // Place is the only code that changes the disk outside the store. It never // replaces or removes anything suit does not own: what suit owns is what the // ledger lists. constexpr int EXIT_BUSY = 20; constexpr uint32_t DIR_MAX = 4096; constexpr size_t DIR_TEXT_MAX = 262144; typedef enum { ACT_CREATE, ACT_REPLACE, ACT_KEEP, ACT_REMOVE, ACT_CLASH, ACT_DROP, ACT_WRITE, // write a joined file: DEST is its path ACT_FILE, // a joined file that is already right ACT_UNWRITE, // remove a joined file nothing wants any more } ActKind; typedef struct { ActKind kind; const char *dest; const char *src; // the link to make; for ACT_REMOVE the link suit made const char *old; // ACT_REPLACE: the link suit made before; ACT_WRITE: non-null if the ledger has the file const char *reason; // ACT_CLASH const Placement *want; const Join *join; // ACT_WRITE and ACT_FILE } Action; typedef struct { uint32_t n; Action a[PLACE_MAX + LEDGER_ENTRY_MAX + CONF_HARNESS_MAX]; uint32_t ndirs; const char *dirs[DIR_MAX]; // folders to make, parents first char text[DIR_TEXT_MAX]; size_t used; } Actions; // Work out what to do. Reads the disk and the sources of joined files, changes // nothing. Returns 0 or 1 after saying why on stderr. int place_plan(const Plan *plan, const Ledger *ledger, Actions *out); // Take the lock, or wait for it for a moment: 0, EXIT_BUSY or 1. int place_lock(const char *path); void place_unlock(const char *path); // Do ACTS: make the folders, write the joined files, make the links, remove the // links and joined files that are no longer wanted, and keep the ledger at LEDGER_PATH describing what is on disk at every // step. Returns 0 or 1 after saying why. The caller holds the lock. int place_apply(const Ledger *ledger, const Actions *acts, const char *ledger_path); // Remove every link in the ledger that is still the one suit made, then every // joined file, then every folder it made that is empty, print what was done and what was left alone, and // empty the ledger. Returns 0 or 1. The caller holds the lock. int place_off(const Ledger *ledger, const char *ledger_path); // Print the actions the way plan prints them: "+ link DEST -> SOURCE", // "- link DEST", "+ file PATH", "- file PATH", "! clash DEST (reason)", and the plan's "~ skipped ..." lines. void place_print(const Plan *plan, const Actions *acts); // Ledger links whose DEST is gone, written one per line as "missing DEST" and // the number of them; for status. uint32_t place_missing(const Ledger *ledger, bool print); #endif