state

package
v0.1.0-dev.20260129005948 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package state provides merged deployment state tracking for writ. The state file aggregates all deployed files across multiple deployments, enabling complete status checks and upgrade operations.

Index

Constants

View Source
const CurrentVersion = "1"

CurrentVersion is the state file format version.

Variables

This section is empty.

Functions

func StateDir

func StateDir() string

StateDir returns the writ state directory. Default: ~/.local/state/devlore/writ

func StatePath

func StatePath() string

StatePath returns the path to the state file.

Types

type FileEntry

type FileEntry struct {
	// Source is the absolute path in the layer.
	Source string `json:"source" yaml:"source"`

	// Project this file belongs to.
	Project string `json:"project" yaml:"project"`

	// Layer is the repository layer this file came from (base, team, personal).
	// Empty for single-repo deployments.
	Layer string `json:"layer,omitempty" yaml:"layer,omitempty"`

	// Operations performed: link, expand, copy, decrypt.
	Operations []string `json:"operations" yaml:"operations"`

	// DeployedAt is when the file was deployed.
	DeployedAt time.Time `json:"deployed_at" yaml:"deployed_at"`

	// Receipt is the receipt filename that recorded this deployment.
	Receipt string `json:"receipt" yaml:"receipt"`

	// SourceChecksum is the SHA256 of the source file at deploy time.
	// Only set for copied files (expand, decrypt, copy operations).
	SourceChecksum string `json:"source_checksum,omitempty" yaml:"source_checksum,omitempty"`

	// TargetChecksum is the SHA256 of the target file after deployment.
	// Only set for copied files (expand, decrypt, copy operations).
	TargetChecksum string `json:"target_checksum,omitempty" yaml:"target_checksum,omitempty"`
}

FileEntry represents a single deployed file in the state.

func (*FileEntry) IsCopied

func (e *FileEntry) IsCopied() bool

IsCopied returns true if this entry was copied (not symlinked).

func (*FileEntry) IsLinked

func (e *FileEntry) IsLinked() bool

IsLinked returns true if this entry is a symlink.

type State

type State struct {
	// Version is the state file format version.
	Version string `json:"version" yaml:"version"`

	// LastUpdated is when the state was last modified.
	LastUpdated time.Time `json:"last_updated" yaml:"last_updated"`

	// SourceRoot is the environment layer path.
	// For multi-layer deployments, this is the first layer's path.
	SourceRoot string `json:"source_root" yaml:"source_root"`

	// TargetRoot is the deployment target (e.g., $HOME).
	TargetRoot string `json:"target_root" yaml:"target_root"`

	// Layers lists the repository layers used in the deployment.
	// Empty for single-repo deployments.
	Layers []string `json:"layers,omitempty" yaml:"layers,omitempty"`

	// Files maps relative target paths to their deployment info.
	Files map[string]*FileEntry `json:"files" yaml:"files"`

	// Signature contains the cryptographic signature (optional).
	Signature *receipt.Signature `json:"signature,omitempty" yaml:"signature,omitempty"`
}

State represents the merged deployment state.

func Load

func Load() (*State, error)

Load reads the state file from the default location.

func LoadFrom

func LoadFrom(path string) (*State, error)

LoadFrom reads a state file from a specific path.

func LoadOrCreate

func LoadOrCreate(sourceRoot, targetRoot string) (*State, error)

LoadOrCreate loads the state file or creates a new one if it doesn't exist.

func New

func New(sourceRoot, targetRoot string) *State

New creates a new empty state.

func (*State) AddEntry

func (s *State) AddEntry(relTarget string, entry *FileEntry)

AddEntry adds or updates a file entry in the state.

func (*State) CopiedFiles

func (s *State) CopiedFiles() map[string]*FileEntry

CopiedFiles returns all entries that are copied (not symlinked).

func (*State) EntriesForProject

func (s *State) EntriesForProject(project string) map[string]*FileEntry

EntriesForProject returns all entries for a specific project.

func (*State) GetEntry

func (s *State) GetEntry(relTarget string) *FileEntry

GetEntry returns the entry for a relative target path.

func (*State) IsSigned

func (s *State) IsSigned() bool

IsSigned returns true if the state has a signature.

func (*State) Projects

func (s *State) Projects() []string

Projects returns a list of all projects with deployed files.

func (*State) RemoveEntry

func (s *State) RemoveEntry(relTarget string)

RemoveEntry removes a file entry from the state.

func (*State) RemoveProject

func (s *State) RemoveProject(project string) int

RemoveProject removes all entries for a project from the state.

func (*State) Sign

func (s *State) Sign(identity *age.X25519Identity) error

Sign signs the state using the provided age identity.

func (*State) Summary

func (s *State) Summary() (links, copied int)

Summary returns counts of files by type.

func (*State) UpdateChecksum

func (s *State) UpdateChecksum(relTarget, sourceChecksum, targetChecksum string)

UpdateChecksum updates the checksums for a file entry.

func (*State) UpdateFromReceipt

func (s *State) UpdateFromReceipt(rcpt *receipt.Receipt, receiptFilename string)

UpdateFromReceipt merges nodes from a v4 graph-format receipt into the state.

func (*State) Verify

func (s *State) Verify(identities []age.Identity) error

Verify verifies the state signature using the provided identities.

func (*State) Write

func (s *State) Write() error

Write saves the state file to the default location.

func (*State) WriteTo

func (s *State) WriteTo(path string) error

WriteTo saves the state file to a specific path.

Jump to

Keyboard shortcuts

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