stackedit

package
v0.1.0-beta.15 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stackedit holds the shared primitives for mutating stack.yaml safely: comment-preserving yaml.Node appends, per-path in-process locking, and crash-safe atomic writes. Both the API server's stack editors and the import CLI build on these so there is exactly one write discipline.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoLinkBlock      = errors.New("no link block in stack")
	ErrEntryNotDeclared = errors.New("client not declared in link block")
)

Sentinel errors for link-block edits, so callers can distinguish expected states (nothing declared) from a stack file that failed to parse.

Functions

func AppendResources

func AppendResources(source []byte, key string, snippets ...[]byte) ([]byte, error)

AppendResources appends one or more mapping snippets to the top-level sequence at key in source, in order. The yaml.Node round-trip preserves comments, key ordering, and unrelated formatting; a canonical re-emit from a Go struct would lose all three. Each snippet must parse to a single mapping. A null-valued or absent target sequence is replaced with a fresh sequence in place.

func AtomicWrite

func AtomicWrite(path string, data []byte) error

AtomicWrite writes data to path via a same-directory temp file + fsync + rename. A mid-write crash leaves the original file intact; a mid-rename crash on a POSIX filesystem leaves either the old or the new file at path, never a truncated mix. The original file's permissions are preserved.

func PathLock

func PathLock(path string) *sync.Mutex

PathLock returns the in-process mutex guarding writes to path.

func RemoveLinkEntry

func RemoveLinkEntry(source []byte, client string) ([]byte, error)

RemoveLinkEntry removes the entry for client from the top-level link: sequence. When the last entry goes, the link: key is dropped entirely so the file does not carry an empty block. Returns an error when the block or the entry is absent.

func RemoveResourceByName

func RemoveResourceByName(source []byte, key, name string) ([]byte, error)

RemoveResourceByName removes the entry whose name: field equals name from the top-level sequence at key, preserving comments and ordering elsewhere. Returns an error when the sequence or the named entry is absent.

func UpsertLinkEntry

func UpsertLinkEntry(source []byte, entry config.LinkEntry) ([]byte, error)

UpsertLinkEntry adds or replaces the entry for entry.Client in the top-level link: sequence, preserving comments, ordering, and the form of untouched entries. The link: sequence mixes scalar shorthands ("- cursor") and mappings; a slug-only entry is emitted back as the scalar form. The key is created when absent.

Types

This section is empty.

Jump to

Keyboard shortcuts

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