cas

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cas holds the atomic content-addressed staging dance used by baseline materialization: build into a sibling temp dir, atomically rename it into the final slot, and — when the rename loses a cross-process race — discard the temp and adopt the winner's already-finalized directory.

What "build" does and how a race is detected are caller-supplied callbacks (baseline writes a git tree and adopts on a finalized directory). The temp-dir lifecycle, the rename, and the discard-on-failure cleanup live here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stage

func Stage(parent, final, tmpPrefix, finalizePrefix string, build func(staging string) error, adopt func() bool) error

Stage builds final atomically. It creates a sibling temp dir (filepath.Base(final)+".tmp.*") under parent, runs build against that temp dir, then renames it onto final. parent must already exist.

  • The MkdirTemp error is wrapped with tmpPrefix ("<tmpPrefix>: %w").
  • On a build error the temp dir is removed and the error is returned unwrapped — the build callback owns its own error context.
  • On rename success final is the built tree.
  • On rename failure the temp dir is removed and adopt is consulted: when adopt reports true a peer already finalized final and we adopt it (no error); otherwise the rename error is wrapped with finalizePrefix ("<finalizePrefix>: %w").

The two prefixes let the caller keep its own error strings intact (baseline passes "baseline staging"/"baseline finalize").

Types

This section is empty.

Jump to

Keyboard shortcuts

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