installtxn

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 6 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 installtxn provides the cross-process filesystem transaction used by plugin and skill installation. Callers stage content before taking the lock, then commit the content swap and lockfile update together while holding it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitDir

func CommitDir(target string, staged string, publish func() error) error

CommitDir replaces target with staged and runs publish while retaining the previous target. If either the swap or publish fails, the previous target is restored (or the new target is removed for a first install).

The caller must hold the install-root lock returned by Lock.

func Lock

func Lock(dir string) (func(), error)

Lock takes the per-install-root cross-process lock. It blocks until any other installer or remover using dir has completed.

func Recover

func Recover(dir string, reconcile Reconciler) error

Recover resolves the workspaces an earlier run was killed inside, which is what a process killed mid-commit leaves: a tree retained in a workspace nothing else reads. How far that commit got cannot be read off the filesystem. CommitDir swaps the trees and only then publishes, so a kill between the two leaves exactly what a kill after both leaves, and a phase bit written after the publish only inverts which side of the write the ambiguity falls on. Only the caller knows what its published metadata records, so reconcile is asked which of the two trees that is, and its answer decides: the live target stands and the backup beside it is retired, or the backup is the truthful tree and goes back over the target. A nil reconciler means the caller publishes no metadata beside the tree, so a live target is the committed one. With nothing at the target there is no choice to make and the backup, the only copy in existence, is put back.

The returned error means an attributable transaction was left unresolved, never that there was nothing to do. Malformed, legacy, and unattributable workspaces are skipped without error, since they may be somebody's content or somebody else's transaction, but a workspace we own and could not resolve is reported. Every workspace is processed before returning, so one unresolved transaction does not strand the rest.

The caller must hold the install-root lock returned by Lock, and EVERY caller that takes that lock must call this first and abort on its error before it reads the lockfile, inspects the target, installs over it, or reports a successful removal. Recovering only on the install path is worse than not recovering at all: a removal would then report success while the backup it never saw stayed on disk, and the next install would publish it again, reinstating something the user deleted. Recovery is deliberately an explicit call rather than a side effect of Lock, matching how the other staged-swap transactions in this repo invoke their repair pass.

func RemoveDir

func RemoveDir(target string, publish func() error) error

RemoveDir removes target and runs publish while retaining the target until publish succeeds. A publish failure restores the directory.

The caller must hold the install-root lock returned by Lock.

func StageDir

func StageDir(dir string) (stage string, cleanup func(), err error)

StageDir creates an install workspace on the target filesystem. Content must be built and validated in the returned stage directory before CommitDir is called. cleanup is always safe to call.

func WriteFileAtomically

func WriteFileAtomically(path string, data []byte, perm os.FileMode) error

WriteFileAtomically publishes data by renaming a complete sibling temporary file over path. The caller is responsible for any surrounding transaction lock.

Types

type Phase

type Phase int

Phase names which tree in an interrupted workspace the caller's published metadata records.

const (
	// PhaseUnknown means the metadata matches neither tree. Recovery refuses to
	// act and reports the workspace as unresolved.
	PhaseUnknown Phase = iota
	// PhaseCommitted means the live target is what the metadata records: the
	// publish committed, and the backup beside it is superseded.
	PhaseCommitted
	// PhasePrePublish means the metadata still records the retained backup: the
	// tree swap landed but the publish never did.
	PhasePrePublish
)

type Reconciler

type Reconciler func(name string, target string, backup string) (Phase, error)

Reconciler classifies one interrupted workspace for the install named name. target is the live install path, backup the retained tree beside it. An error means the classification could not be made and recovery must not act.

Jump to

Keyboard shortcuts

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