Documentation
¶
Overview ¶
Package fsdiff snapshots a directory tree and computes/applies/restores content-addressed file diffs (§36). It is the single implementation shared by the internal implementer (which writes files) and the engine (which applies and reverts the diff), so both sides agree on the representation. The diff is always computed by the orchestrator from a before/after snapshot — never trusted from an agent's self-declaration.
Index ¶
- Variables
- func Commit(root string, changes []domain.FileChange, ...) error
- func Diff(before, after Manifest) []domain.FileChange
- func Restore(root string, pre Manifest, get func(digest string) ([]byte, error)) error
- func StaleBase(root string, changes []domain.FileChange) []string
- type Entry
- type Manifest
- type Patch
Constants ¶
This section is empty.
Variables ¶
var ErrControlPlanePath = errors.New("fsdiff: path is part of the harness control plane and cannot be changed by a change set")
ErrControlPlanePath is returned when a change set names a path that governs the harness itself.
Functions ¶
func Commit ¶
func Commit(root string, changes []domain.FileChange, get func(digest string) ([]byte, error)) error
Commit writes (and deletes) the changes into root, assuming the pre-image was already captured by Prepare. Every Path is containment-checked against root before any write, and writes are atomic (temp file + rename).
func Diff ¶
func Diff(before, after Manifest) []domain.FileChange
Diff computes the changes from before to after. Added/modified files carry their post-image digest; files present only in before are deletions (empty digest). The result is path-sorted.
func Restore ¶
Restore restores a pre-image manifest. Entries with an empty digest did not exist before and are removed; others are rewritten to their prior content.
func StaleBase ¶ added in v0.5.0
func StaleBase(root string, changes []domain.FileChange) []string
StaleBase reports every change whose base no longer matches root, one line per file. An empty result means the patch can be applied without overwriting anything the change was not made against.
Keyed on ChangeType, not on BaseDigest being empty: an all-adds patch has no base digests at all and must still be checked, because "add a file" over a file that now exists is exactly how an agent that never saw the workspace deleted a user's code. A change with no ChangeType predates this check and is applied as before.
Types ¶
type Entry ¶
Entry is one file in a snapshot manifest: a workspace-relative path and the SHA-256 of its content.
type Manifest ¶
type Manifest []Entry
Manifest is a path-sorted snapshot of a directory's regular files.
func Apply ¶
func Apply(root string, changes []domain.FileChange, get func(digest string) ([]byte, error), put func(content []byte) (string, error)) (Manifest, error)
Apply writes changes into root and returns the pre-image manifest of every touched path (for revert). It is the two-phase Prepare+Commit composed for callers that do not need the crash-safety window between them.
func Prepare ¶
func Prepare(root string, changes []domain.FileChange, put func(content []byte) (string, error)) (Manifest, error)
Prepare captures the pre-image of every touched path (persisting each via put) WITHOUT mutating root. It returns the pre-image manifest so a caller can persist it BEFORE any byte is written, making an interrupted apply recoverable (review: full-platform apply atomicity).
func Snapshot ¶
Snapshot walks root and returns a path-sorted manifest of its regular files (content-addressed). Directories, symlinks, and non-regular files are ignored. Symlinks are rejected via Lstat (not followed) so an untrusted executor cannot plant a symlink to a host file and induce the daemon to read it (review: v1 security boundary). A missing root yields an empty manifest.
type Patch ¶
type Patch struct {
BaseSnapshotDigest string `json:"base_snapshot_digest,omitempty"`
Files []domain.FileChange `json:"files"`
}
Patch is the content-addressed diff manifest persisted as a change set's patch. BaseSnapshotDigest references the pre-image snapshot; Files is the ordered change list.