Artifact 59cbd4305dbbd99cd6638987d1a5bcb0aba875986ffe002ebfcf417bbed96c87:
- File
src/place.h
— part of check-in
[c3b2afcdc0]
at
2026-11-13 02:12:51
on branch trunk
— Phase 3: the User scope, placed by links that suit owns and nothing else
suit reads suit.conf from the store, works out which links should exist for the User scope, and makes each harness's folders match. suit plan, apply, status and off. suit run now applies when something changed.
The ledger is a text file listing every link suit made. A link is made under a temporary name and renamed into place. A real file, a real folder or someone else's link at a destination is left byte-identical and reported as a clash. suit off leaves a home folder exactly as it was before the first apply.
Proven with a real harness: Claude Code, run against a scratch home through a local proxy on a DeepSeek model, returned the marker word from the instruction file suit placed, listed the skill suit placed, returned a new marker after the file was edited in the store with no suit command run, and no longer saw it after suit off. make live runs this on purpose; it is not part of the automatic gates.
385 unit checks, 227 shell cases, 146 store cases, 157 placement cases. 100% of functions, lines, regions and branches in all 14 source files. The no-change run costs 0.45 to 0.72 ms over an empty program with the stamp now watching 128 paths.
Not yet done in this phase: live proof with Codex and pi, and the document of each harness's paths. (user: dmestas, size: 2262) [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 } 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 const char *reason; // ACT_CLASH const Placement *want; } Action; typedef struct { uint32_t n; Action a[PLACE_MAX + LEDGER_ENTRY_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, 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 and links, remove the links 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 // 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", "! 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