cas

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package cas holds the atomic content-addressed staging dance shared by baseline materialization and the kustomize stage cache: 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 differ between callers (baseline writes a git tree + .git marker and adopts on a finalized directory; the stage cache copies a file tree and adopts on a sentinel file), so both are callbacks. The temp-dir lifecycle, the rename, and the discard-on-failure cleanup are identical and 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) (adopted bool, err 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 keep each call site's existing error strings intact ("baseline staging"/"baseline finalize", "stage tmp"/"stage finalize").

adopted reports whether the returned slot came from adopting a peer's finalized directory (false on the normal rename-wins path); callers that distinguish "we built it" from "we adopted it" use it, others ignore it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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