fsdiff

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func Restore(root string, pre Manifest, get func(digest string) ([]byte, error)) error

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

type Entry struct {
	Path   string `json:"path"`
	Digest string `json:"digest"`
}

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

func Snapshot(root string) (Manifest, error)

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.

func (Manifest) Digest

func (m Manifest) Digest() string

Digest returns the content digest of a manifest (its canonical JSON).

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.

func (Patch) Digest

func (p Patch) Digest() string

Digest returns the content digest of a patch manifest (its canonical JSON).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL