stackdir

package
v0.2.43 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package stackdir is a stack version's own directory, handed to a workspace exec as a read-only tree: `WITH cwd = "$TXCO_STACK_DIR"` starts the command in it and sets TXCO_STACK_DIR to its path, so an op can run a program kept beside it by path instead of pasting it into stdin.

When one of a stack's ops names $TXCO_STACK_DIR, `txco apply` packs the stack's directory into one canonical tar (the bundle) and uploads it to the hash-addressed file store (filecas). The stack version then carries one fingerprint-only row:

STACKDIR/<sha256 of the tar>.tar   content "", content_hash = that sha256

so an unchanged tree costs each new version one small row and its bytes are stored once. A run reads the row from the opstack snapshot it pinned, so an activation never changes the tree a running or resumed run sees.

This file is the leaf layer: the reserved-path vocabulary, the caps and the bundle codec, with no dependency on stores, so the CLI, the admin API, the processor and the workspace providers can import it cheaply.

Index

Constants

View Source
const (
	// Dir is the reserved top-level directory for the tree's row.
	Dir = "STACKDIR"
	// Ext is the row's extension: the bundle is a tar.
	Ext = ".tar"
	// Env is the variable a command finds the tree by.
	Env = "TXCO_STACK_DIR"
	// Token is how an op names the tree in `cwd`; `txco apply` packs a
	// stack's tree only when one of its ops contains it.
	Token = "$" + Env

	// MaxFileBytes caps one file, as `&include` caps an included one.
	MaxFileBytes = 1 << 20
	// MaxTreeBytes caps the files of one tree, together.
	MaxTreeBytes = 32 << 20
	// MaxFiles caps how many files one tree holds.
	MaxFiles = 10000
)

Variables

This section is empty.

Functions

func DigestFromPath

func DigestFromPath(p string) string

DigestFromPath returns the digest a well-formed STACKDIR/ path names, or "".

func IsPath

func IsPath(p string) bool

IsPath reports whether a stack_files path lives under STACKDIR/.

func Pack

func Pack(files []File) ([]byte, string, error)

Pack writes the canonical bundle of files: sorted by path, regular files only, every header fixed (mode 0444 or 0555, owner 0, no names, mtime 0), no directory entries. It returns the bytes and their sha256. It refuses what Unpack would refuse, so a bundle that packs also unpacks.

func Path

func Path(digest string) string

Path is the stack_files path of the tree whose bundle hashes to digest (sha256, lowercase hex).

func Unpack

func Unpack(data []byte, fn func(File) error) error

Unpack reads a bundle and hands each file to fn, in the bundle's order. It checks every header against the caps and the path rules before fn sees it, and refuses anything but a regular file.

func ValidDigest

func ValidDigest(d string) bool

ValidDigest reports whether d is a sha256 in lowercase hex.

func ValidPath

func ValidPath(p string) error

ValidPath reports why p cannot name a file in a tree: it must be a clean, relative, slash-separated path with no empty, ".", ".." or dot-prefixed segment.

Types

type File

type File struct {
	// Path is slash-separated and relative to the stack's directory.
	Path string
	// Exec says the source was executable: it is extracted 0555, else 0444,
	// so a program in the tree can be run directly.
	Exec    bool
	Content []byte
}

File is one file of a tree.

Jump to

Keyboard shortcuts

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