chezmoi

package
v2.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 65 Imported by: 0

Documentation

Overview

Package chezmoi contains chezmoi's core logic.

Index

Constants

View Source
const (
	Prefix = ".chezmoi"

	RootName         = Prefix + "root"
	TemplatesDirName = Prefix + "templates"
	VersionName      = Prefix + "version"
)

Special file names.

View Source
const (
	TemplateSuffix = ".tmpl"
)

Prefixes and suffixes.

Variables

View Source
var (
	DotAbsPath   = NewAbsPath(".")
	EmptyAbsPath = NewAbsPath("")
	RootAbsPath  = NewAbsPath("/")
)
View Source
var (
	// DefaultTemplateOptions are the default template options.
	DefaultTemplateOptions = []string{"missingkey=error"}

	// Break indicates that a walk should be stopped.
	Break = io.EOF

	// Skip indicates that entry should be skipped.
	Skip = filepath.SkipDir

	// Umask is the process's umask.
	Umask = fs.FileMode(0)
)
View Source
var (
	CutPrefix = strings.CutPrefix
	CutSuffix = strings.CutSuffix
)
View Source
var (
	// FormatsByName is a map of all FormatsByName by name.
	FormatsByName = map[string]Format{
		"jsonc": FormatJSONC,
		"json":  FormatJSON,
		"toml":  FormatTOML,
		"yaml":  FormatYAML,
	}

	// FormatsByExtension is a map of all Formats by extension.
	FormatsByExtension = map[string]Format{
		"jsonc": FormatJSONC,
		"json":  FormatJSON,
		"toml":  FormatTOML,
		"yaml":  FormatYAML,
		"yml":   FormatYAML,
	}
	FormatExtensions = sortedKeys(FormatsByExtension)
)
View Source
var (
	// ConfigStateBucket is the bucket for recording the config state.
	ConfigStateBucket = []byte("configState")

	// EntryStateBucket is the bucket for recording the entry states.
	EntryStateBucket = []byte("entryState")

	// GitRepoExternalStateBucket is the bucket for recording the state of commands
	// that modify directories.
	GitRepoExternalStateBucket = []byte("gitRepoExternalState")

	// ScriptStateBucket is the bucket for recording the state of run once
	// scripts.
	ScriptStateBucket = []byte("scriptState")
)
View Source
var (
	DotRelPath   = NewRelPath(".")
	EmptyRelPath = NewRelPath("")
)
View Source
var FileModeTypeNames = map[fs.FileMode]string{
	0:                 "file",
	fs.ModeDir:        "dir",
	fs.ModeSymlink:    "symlink",
	fs.ModeNamedPipe:  "named pipe",
	fs.ModeSocket:     "socket",
	fs.ModeDevice:     "device",
	fs.ModeCharDevice: "char device",
}
View Source
var ModeFlagCompletionFunc = FlagCompletionFunc([]string{
	string(ModeFile),
	string(ModeSymlink),
})

ModeFlagCompletionFunc is a function that completes the value of mode flags.

View Source
var (
	RefreshExternalsFlagCompletionFunc = FlagCompletionFunc(
		maps.Keys(refreshExternalsWellKnownStrings),
	)
)

Functions

func DiffPatch

func DiffPatch(
	path RelPath,
	fromData []byte, fromMode fs.FileMode,
	toData []byte, toMode fs.FileMode,
) (diff.Patch, error)

DiffPatch returns a github.com/go-git/go-git/plumbing/format/diff.Patch for path from the given data and mode to the given data and mode.

func EntryTypeSetFlagCompletionFunc added in v2.25.0

func EntryTypeSetFlagCompletionFunc(
	cmd *cobra.Command, args []string, toComplete string,
) ([]string, cobra.ShellCompDirective)

EntryTypeSetFlagCompletionFunc completes EntryTypeSet flags.

func FQDNHostname

func FQDNHostname(fileSystem vfs.FS) (string, error)

FQDNHostname returns the FQDN hostname.

func FlagCompletionFunc added in v2.16.0

func FlagCompletionFunc(allCompletions []string) func(*cobra.Command, []string, string) (
	[]string, cobra.ShellCompDirective,
)

FlagCompletionFunc returns a flag completion function.

func Glob added in v2.23.0

func Glob(fileSystem vfs.FS, prefix string) ([]string, error)

Glob is like github.com/bmatcuk/doublestar/v4.Glob except that it does not follow symlinks.

func Kernel

func Kernel(fileSystem vfs.FS) (map[string]any, error)

Kernel returns the kernel information parsed from /proc/sys/kernel.

func LookPath added in v2.13.1

func LookPath(file string) (string, error)

LookPath is like os/exec.LookPath except that the first positive result is cached.

func MkdirAll

func MkdirAll(system System, absPath AbsPath, perm fs.FileMode) error

MkdirAll is the equivalent of os.MkdirAll but operates on system.

func NewGitHubClient added in v2.12.0

func NewGitHubClient(ctx context.Context, httpClient *http.Client) *github.Client

NewGitHubClient returns a new github.Client configured with an access token and a http client, if available.

func OSRelease

func OSRelease(fileSystem vfs.FS) (map[string]any, error)

OSRelease returns the operating system identification data as defined by the os-release specification.

func ParseBool added in v2.23.0

func ParseBool(str string) (bool, error)

ParseBool is like strconv.ParseBool but also accepts on, ON, y, Y, yes, YES, n, N, no, NO, off, and OFF.

func PersistentStateBucketData

func PersistentStateBucketData(s PersistentState, bucket []byte) (map[string]any, error)

PersistentStateBucketData returns the state data in bucket in s.

func PersistentStateData

func PersistentStateData(s PersistentState, buckets map[string][]byte) (map[string]any, error)

PersistentStateData returns the structured data in s.

func PersistentStateGet added in v2.31.0

func PersistentStateGet(s PersistentState, bucket, key []byte, value any) (bool, error)

PersistentStateGet gets the value associated with key in bucket in s, if it exists.

func PersistentStateSet added in v2.31.0

func PersistentStateSet(s PersistentState, bucket, key []byte, value any) error

PersistentStateSet sets the value associated with key in bucket in s.

func RecursiveMerge

func RecursiveMerge(dest, source map[string]any)

RecursiveMerge recursively merges maps in source into dest.

func SHA256Sum

func SHA256Sum(data []byte) []byte

SHA256Sum returns the SHA256 sum of data.

func StringSliceToEntryTypeSetHookFunc

func StringSliceToEntryTypeSetHookFunc() mapstructure.DecodeHookFunc

StringSliceToEntryTypeSetHookFunc is a github.com/mitchellh/mapstructure.DecodeHookFunc that parses an EntryTypeSet from a []string.

func StringToAbsPathHookFunc

func StringToAbsPathHookFunc() mapstructure.DecodeHookFunc

StringToAbsPathHookFunc is a github.com/mitchellh/mapstructure.DecodeHookFunc that parses an AbsPath from a string.

func SuspiciousSourceDirEntry

func SuspiciousSourceDirEntry(base string, fileInfo fs.FileInfo, encryptedSuffixes []string) bool

SuspiciousSourceDirEntry returns true if base is a suspicious dir entry.

func UniqueAbbreviations added in v2.23.0

func UniqueAbbreviations(values []string) map[string]string

UniqueAbbreviations returns a map of unique abbreviations of values to values. Values always map to themselves.

func Walk

func Walk(system System, rootAbsPath AbsPath, walkFunc WalkFunc) error

Walk walks rootAbsPath in system, calling walkFunc for each file or directory in the tree, including rootAbsPath.

Walk does not follow symlinks.

func WalkArchive

func WalkArchive(data []byte, format ArchiveFormat, f WalkArchiveFunc) error

WalkArchive walks over all the entries in an archive.

func WalkSourceDir

func WalkSourceDir(system System, sourceDirAbsPath AbsPath, walkFunc WalkFunc) error

WalkSourceDir walks the source directory rooted at sourceDirAbsPath in system, calling walkFunc for each file or directory in the tree, including sourceDirAbsPath.

WalkSourceDir does not follow symbolic links found in directories, but if sourceDirAbsPath itself is a symbolic link, its target will be walked.

Directory entries .chezmoidata.<format> and .chezmoitemplates are visited before all other entries. All other entries are visited in alphabetical order.

Types

type AbsPath

type AbsPath struct {
	// contains filtered or unexported fields
}

An AbsPath is an absolute path.

func HomeDirAbsPath

func HomeDirAbsPath() (AbsPath, error)

HomeDirAbsPath returns the user's home directory as an AbsPath.

func NewAbsPath

func NewAbsPath(absPath string) AbsPath

NewAbsPath returns a new AbsPath.

func NewAbsPathFromExtPath

func NewAbsPathFromExtPath(extPath string, homeDirAbsPath AbsPath) (AbsPath, error)

NewAbsPathFromExtPath returns a new AbsPath by converting extPath to use slashes, performing tilde expansion, and making the path absolute.

func NormalizePath

func NormalizePath(path string) (AbsPath, error)

NormalizePath returns path normalized. On non-Windows systems, normalized paths are absolute paths.

func (AbsPath) Append

func (p AbsPath) Append(s string) AbsPath

Append appends s to p.

func (AbsPath) Base

func (p AbsPath) Base() string

Base returns p's basename.

func (AbsPath) Bytes

func (p AbsPath) Bytes() []byte

Bytes returns p as a []byte.

func (AbsPath) Dir

func (p AbsPath) Dir() AbsPath

Dir returns p's directory.

func (AbsPath) Empty

func (p AbsPath) Empty() bool

Empty returns if p is empty.

func (AbsPath) Ext

func (p AbsPath) Ext() string

Ext returns p's extension.

func (AbsPath) Join

func (p AbsPath) Join(relPaths ...RelPath) AbsPath

Join returns a new AbsPath with relPaths appended.

func (AbsPath) JoinString

func (p AbsPath) JoinString(ss ...string) AbsPath

JoinString returns a new AbsPath with ss appended.

func (AbsPath) Len

func (p AbsPath) Len() int

Len returns the length of p.

func (AbsPath) Less

func (p AbsPath) Less(other AbsPath) bool

Less returns if p is less than other.

func (AbsPath) MarshalText

func (p AbsPath) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText.

func (AbsPath) MustTrimDirPrefix

func (p AbsPath) MustTrimDirPrefix(dirPrefix AbsPath) RelPath

MustTrimDirPrefix is like TrimPrefix but panics on any error.

func (*AbsPath) Set

func (p *AbsPath) Set(s string) error

Set implements github.com/spf13/pflag.Value.Set.

func (AbsPath) Split

func (p AbsPath) Split() (AbsPath, RelPath)

Split returns p's directory and file.

func (AbsPath) String

func (p AbsPath) String() string

func (AbsPath) ToSlash

func (p AbsPath) ToSlash() AbsPath

ToSlash calls filepath.ToSlash on p.

func (AbsPath) TrimDirPrefix

func (p AbsPath) TrimDirPrefix(dirPrefixAbsPath AbsPath) (RelPath, error)

TrimDirPrefix trims prefix from p.

func (AbsPath) TrimSuffix added in v2.29.0

func (p AbsPath) TrimSuffix(suffix string) AbsPath

TrimSuffix returns p with the optional suffix removed.

func (AbsPath) Type

func (p AbsPath) Type() string

Type implements github.com/spf13/pflag.Value.Type.

func (*AbsPath) UnmarshalText

func (p *AbsPath) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText.

type AbsPaths

type AbsPaths []AbsPath

AbsPaths is a slice of RelPaths that implements sort.Interface.

func (AbsPaths) Len

func (ps AbsPaths) Len() int

func (AbsPaths) Less

func (ps AbsPaths) Less(i, j int) bool

func (AbsPaths) Swap

func (ps AbsPaths) Swap(i, j int)

type ActualStateAbsent

type ActualStateAbsent struct {
	// contains filtered or unexported fields
}

A ActualStateAbsent represents the absence of an entry in the filesystem.

func (*ActualStateAbsent) EntryState

func (s *ActualStateAbsent) EntryState() (*EntryState, error)

EntryState returns s's entry state.

func (*ActualStateAbsent) OriginString added in v2.20.0

func (s *ActualStateAbsent) OriginString() string

OriginString returns s's origin.

func (*ActualStateAbsent) Path

func (s *ActualStateAbsent) Path() AbsPath

Path returns s's path.

func (*ActualStateAbsent) Remove

func (s *ActualStateAbsent) Remove(system System) error

Remove removes s.

type ActualStateDir

type ActualStateDir struct {
	// contains filtered or unexported fields
}

A ActualStateDir represents the state of a directory in the filesystem.

func (*ActualStateDir) EntryState

func (s *ActualStateDir) EntryState() (*EntryState, error)

EntryState returns s's entry state.

func (*ActualStateDir) OriginString added in v2.20.0

func (s *ActualStateDir) OriginString() string

OriginString returns s's origin.

func (*ActualStateDir) Path

func (s *ActualStateDir) Path() AbsPath

Path returns s's path.

func (*ActualStateDir) Remove

func (s *ActualStateDir) Remove(system System) error

Remove removes s.

type ActualStateEntry

type ActualStateEntry interface {
	EntryState() (*EntryState, error)
	Path() AbsPath
	Remove(system System) error
	OriginString() string
}

An ActualStateEntry represents the actual state of an entry in the filesystem.

func NewActualStateEntry

func NewActualStateEntry(
	system System,
	absPath AbsPath,
	fileInfo fs.FileInfo,
	err error,
) (ActualStateEntry, error)

NewActualStateEntry returns a new ActualStateEntry populated with absPath from system.

type ActualStateFile

type ActualStateFile struct {
	// contains filtered or unexported fields
}

A ActualStateFile represents the state of a file in the filesystem.

func (ActualStateFile) Contents

func (lc ActualStateFile) Contents() ([]byte, error)

Contents returns lc's contents.

func (ActualStateFile) ContentsSHA256

func (lc ActualStateFile) ContentsSHA256() ([]byte, error)

ContentsSHA256 returns the SHA256 sum of lc's contents.

func (*ActualStateFile) EntryState

func (s *ActualStateFile) EntryState() (*EntryState, error)

EntryState returns s's entry state.

func (*ActualStateFile) OriginString added in v2.20.0

func (s *ActualStateFile) OriginString() string

OriginString returns s's origin.

func (*ActualStateFile) Path

func (s *ActualStateFile) Path() AbsPath

Path returns s's path.

func (*ActualStateFile) Perm

func (s *ActualStateFile) Perm() fs.FileMode

Perm returns s's perm.

func (*ActualStateFile) Remove

func (s *ActualStateFile) Remove(system System) error

Remove removes s.

type ActualStateSymlink struct {
	// contains filtered or unexported fields
}

A ActualStateSymlink represents the state of a symlink in the filesystem.

func (*ActualStateSymlink) EntryState

func (s *ActualStateSymlink) EntryState() (*EntryState, error)

EntryState returns s's entry state.

func (ActualStateSymlink) Linkname

func (ll ActualStateSymlink) Linkname() (string, error)

Linkname returns s's linkname.

func (ActualStateSymlink) LinknameSHA256

func (ll ActualStateSymlink) LinknameSHA256() ([]byte, error)

LinknameSHA256 returns the SHA256 sum of ll's linkname.

func (*ActualStateSymlink) OriginString added in v2.20.0

func (s *ActualStateSymlink) OriginString() string

OriginString returns s's origin.

func (*ActualStateSymlink) Path

func (s *ActualStateSymlink) Path() AbsPath

Path returns s's path.

func (*ActualStateSymlink) Remove

func (s *ActualStateSymlink) Remove(system System) error

Remove removes s.

type AddOptions

type AddOptions struct {
	Create            bool             // Add create_ entries instead of normal entries.
	Encrypt           bool             // Encrypt files.
	EncryptedSuffix   string           // Suffix for encrypted files.
	Exact             bool             // Add the exact_ attribute to added directories.
	Filter            *EntryTypeFilter // Entry type filter.
	OnIgnoreFunc      func(RelPath)    // Function to call when a target is ignored.
	PreAddFunc        PreAddFunc       // Function to be called before a source entry is added.
	ProtectedAbsPaths []AbsPath        // Paths that must not be added.
	RemoveDir         RelPath          // Directory to remove before adding.
	ReplaceFunc       ReplaceFunc      // Function to be called before a source entry is replaced.
	Template          bool             // Add the .tmpl attribute to added files.
	TemplateSymlinks  bool             // Add symlinks with targets in the source or home directories as templates.
}

AddOptions are options to SourceState.Add.

type AgeEncryption

type AgeEncryption struct {
	UseBuiltin      bool      `json:"useBuiltin"      mapstructure:"useBuiltin"      yaml:"useBuiltin"`
	Command         string    `json:"command"         mapstructure:"command"         yaml:"command"`
	Args            []string  `json:"args"            mapstructure:"args"            yaml:"args"`
	Identity        AbsPath   `json:"identity"        mapstructure:"identity"        yaml:"identity"`
	Identities      []AbsPath `json:"identities"      mapstructure:"identities"      yaml:"identities"`
	Passphrase      bool      `json:"passphrase"      mapstructure:"passphrase"      yaml:"passphrase"`
	Recipient       string    `json:"recipient"       mapstructure:"recipient"       yaml:"recipient"`
	Recipients      []string  `json:"recipients"      mapstructure:"recipients"      yaml:"recipients"`
	RecipientsFile  AbsPath   `json:"recipientsFile"  mapstructure:"recipientsFile"  yaml:"recipientsFile"`
	RecipientsFiles []AbsPath `json:"recipientsFiles" mapstructure:"recipientsFiles" yaml:"recipientsFiles"`
	Suffix          string    `json:"suffix"          mapstructure:"suffix"          yaml:"suffix"`
	Symmetric       bool      `json:"symmetric"       mapstructure:"symmetric"       yaml:"symmetric"`
}

An AgeEncryption uses age for encryption and decryption. See https://age-encryption.org.

func (*AgeEncryption) Decrypt

func (e *AgeEncryption) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt implements Encryption.Decrypt.

func (*AgeEncryption) DecryptToFile

func (e *AgeEncryption) DecryptToFile(plaintextAbsPath AbsPath, ciphertext []byte) error

DecryptToFile implements Encryption.DecryptToFile.

func (*AgeEncryption) Encrypt

func (e *AgeEncryption) Encrypt(plaintext []byte) ([]byte, error)

Encrypt implements Encryption.Encrypt.

func (*AgeEncryption) EncryptFile

func (e *AgeEncryption) EncryptFile(plaintextAbsPath AbsPath) ([]byte, error)

EncryptFile implements Encryption.EncryptFile.

func (*AgeEncryption) EncryptedSuffix

func (e *AgeEncryption) EncryptedSuffix() string

EncryptedSuffix implements Encryption.EncryptedSuffix.

type ApplyOptions

type ApplyOptions struct {
	Filter       *EntryTypeFilter
	PreApplyFunc PreApplyFunc
	Umask        fs.FileMode
}

ApplyOptions are options to SourceState.ApplyAll and SourceState.ApplyOne.

type ArchiveFormat

type ArchiveFormat string

An ArchiveFormat is an archive format and implements the github.com/spf13/pflag.Value interface.

const (
	ArchiveFormatUnknown ArchiveFormat = ""
	ArchiveFormatTar     ArchiveFormat = "tar"
	ArchiveFormatTarBz2  ArchiveFormat = "tar.bz2"
	ArchiveFormatTarGz   ArchiveFormat = "tar.gz"
	ArchiveFormatTarXz   ArchiveFormat = "tar.xz"
	ArchiveFormatTarZst  ArchiveFormat = "tar.zst"
	ArchiveFormatTbz2    ArchiveFormat = "tbz2"
	ArchiveFormatTgz     ArchiveFormat = "tgz"
	ArchiveFormatTxz     ArchiveFormat = "txz"
	ArchiveFormatZip     ArchiveFormat = "zip"
)

Archive formats.

func GuessArchiveFormat

func GuessArchiveFormat(path string, data []byte) ArchiveFormat

GuessArchiveFormat guesses the archive format from the path and data.

func (*ArchiveFormat) Set

func (f *ArchiveFormat) Set(s string) error

Set implements github.com/spf13/pflag.Value.Set.

func (ArchiveFormat) String

func (f ArchiveFormat) String() string

String implements github.com/spf13/pflag.Value.String.

func (ArchiveFormat) Type

func (f ArchiveFormat) Type() string

Type implements github.com/spf13/pflag.Value.Type.

type ArchiveReaderSystem

type ArchiveReaderSystem struct {
	// contains filtered or unexported fields
}

A ArchiveReaderSystem a system constructed from reading an archive.

func NewArchiveReaderSystem

func NewArchiveReaderSystem(
	archivePath string, data []byte, format ArchiveFormat, options ArchiveReaderSystemOptions,
) (*ArchiveReaderSystem, error)

NewArchiveReaderSystem returns a new ArchiveReaderSystem reading from data and using archivePath as a hint for the archive format.

func (ArchiveReaderSystem) Chmod

func (ArchiveReaderSystem) Chmod(name AbsPath, perm fs.FileMode) error

func (ArchiveReaderSystem) Chtimes added in v2.24.0

func (ArchiveReaderSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (*ArchiveReaderSystem) FileInfos

func (s *ArchiveReaderSystem) FileInfos() map[AbsPath]fs.FileInfo

FileInfos returns s's fs.FileInfos.

func (ArchiveReaderSystem) Glob

func (ArchiveReaderSystem) Glob(pattern string) ([]string, error)
func (ArchiveReaderSystem) Link(oldname, newname AbsPath) error

func (*ArchiveReaderSystem) Lstat

func (s *ArchiveReaderSystem) Lstat(filename AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (ArchiveReaderSystem) Mkdir

func (ArchiveReaderSystem) Mkdir(name AbsPath, perm fs.FileMode) error

func (ArchiveReaderSystem) RawPath

func (ArchiveReaderSystem) RawPath(path AbsPath) (AbsPath, error)

func (ArchiveReaderSystem) ReadDir

func (ArchiveReaderSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

func (*ArchiveReaderSystem) ReadFile

func (s *ArchiveReaderSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *ArchiveReaderSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (ArchiveReaderSystem) Remove

func (ArchiveReaderSystem) Remove(name AbsPath) error

func (ArchiveReaderSystem) RemoveAll

func (ArchiveReaderSystem) RemoveAll(name AbsPath) error

func (ArchiveReaderSystem) Rename

func (ArchiveReaderSystem) Rename(oldpath, newpath AbsPath) error

func (ArchiveReaderSystem) RunCmd

func (ArchiveReaderSystem) RunCmd(cmd *exec.Cmd) error

func (ArchiveReaderSystem) RunScript

func (ArchiveReaderSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

func (ArchiveReaderSystem) Stat

func (ArchiveReaderSystem) Stat(name AbsPath) (fs.FileInfo, error)

func (ArchiveReaderSystem) UnderlyingFS

func (ArchiveReaderSystem) UnderlyingFS() vfs.FS

func (*ArchiveReaderSystem) UnderlyingSystem added in v2.34.0

func (s *ArchiveReaderSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (ArchiveReaderSystem) WriteFile

func (ArchiveReaderSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error
func (ArchiveReaderSystem) WriteSymlink(oldname string, newname AbsPath) error

type ArchiveReaderSystemOptions

type ArchiveReaderSystemOptions struct {
	RootAbsPath     AbsPath
	StripComponents int
}

ArchiveReaderSystemOptions are options to NewArchiveReaderSystem.

type BoltPersistentState

type BoltPersistentState struct {
	// contains filtered or unexported fields
}

A BoltPersistentState is a state persisted with bolt.

func NewBoltPersistentState

func NewBoltPersistentState(
	system System,
	path AbsPath,
	mode BoltPersistentStateMode,
) (*BoltPersistentState, error)

NewBoltPersistentState returns a new BoltPersistentState.

func (*BoltPersistentState) Close

func (b *BoltPersistentState) Close() error

Close closes b.

func (*BoltPersistentState) CopyTo

CopyTo copies b to p.

func (*BoltPersistentState) Data

func (b *BoltPersistentState) Data() (any, error)

Data returns all the data in b.

func (*BoltPersistentState) Delete

func (b *BoltPersistentState) Delete(bucket, key []byte) error

Delete deletes the value associate with key in bucket. If bucket or key does not exist then Delete does nothing.

func (*BoltPersistentState) DeleteBucket

func (b *BoltPersistentState) DeleteBucket(bucket []byte) error

DeleteBucket deletes the bucket.

func (*BoltPersistentState) ForEach

func (b *BoltPersistentState) ForEach(bucket []byte, fn func(k, v []byte) error) error

ForEach calls fn for each key, value pair in bucket.

func (*BoltPersistentState) Get

func (b *BoltPersistentState) Get(bucket, key []byte) ([]byte, error)

Get returns the value associated with key in bucket.

func (*BoltPersistentState) Set

func (b *BoltPersistentState) Set(bucket, key, value []byte) error

Set sets the value associated with key in bucket. bucket will be created if it does not already exist.

type BoltPersistentStateMode

type BoltPersistentStateMode int

A BoltPersistentStateMode is a mode for opening a PersistentState.

const (
	BoltPersistentStateReadOnly BoltPersistentStateMode = iota
	BoltPersistentStateReadWrite
)

Persistent state modes.

type DebugEncryption

type DebugEncryption struct {
	// contains filtered or unexported fields
}

A DebugEncryption logs all calls to an Encryption.

func NewDebugEncryption

func NewDebugEncryption(encryption Encryption, logger *zerolog.Logger) *DebugEncryption

NewDebugEncryption returns a new DebugEncryption that logs methods on encryption to logger.

func (*DebugEncryption) Decrypt

func (e *DebugEncryption) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt implements Encryption.Decrypt.

func (*DebugEncryption) DecryptToFile

func (e *DebugEncryption) DecryptToFile(plaintextAbsPath AbsPath, ciphertext []byte) error

DecryptToFile implements Encryption.DecryptToFile.

func (*DebugEncryption) Encrypt

func (e *DebugEncryption) Encrypt(plaintext []byte) ([]byte, error)

Encrypt implements Encryption.Encrypt.

func (*DebugEncryption) EncryptFile

func (e *DebugEncryption) EncryptFile(plaintextAbsPath AbsPath) ([]byte, error)

EncryptFile implements Encryption.EncryptFile.

func (*DebugEncryption) EncryptedSuffix

func (e *DebugEncryption) EncryptedSuffix() string

EncryptedSuffix implements Encryption.EncryptedSuffix.

type DebugPersistentState

type DebugPersistentState struct {
	// contains filtered or unexported fields
}

A DebugPersistentState logs calls to a PersistentState.

func NewDebugPersistentState

func NewDebugPersistentState(
	persistentState PersistentState,
	logger *zerolog.Logger,
) *DebugPersistentState

NewDebugPersistentState returns a new debugPersistentState that logs methods on persistentState to logger.

func (*DebugPersistentState) Close

func (s *DebugPersistentState) Close() error

Close implements PersistentState.Close.

func (*DebugPersistentState) CopyTo

CopyTo implements PersistentState.CopyTo.

func (*DebugPersistentState) Data

func (s *DebugPersistentState) Data() (any, error)

Data implements PersistentState.Data.

func (*DebugPersistentState) Delete

func (s *DebugPersistentState) Delete(bucket, key []byte) error

Delete implements PersistentState.Delete.

func (*DebugPersistentState) DeleteBucket

func (s *DebugPersistentState) DeleteBucket(bucket []byte) error

DeleteBucket implements PersistentState.DeleteBucket.

func (*DebugPersistentState) ForEach

func (s *DebugPersistentState) ForEach(bucket []byte, fn func(k, v []byte) error) error

ForEach implements PersistentState.ForEach.

func (*DebugPersistentState) Get

func (s *DebugPersistentState) Get(bucket, key []byte) ([]byte, error)

Get implements PersistentState.Get.

func (*DebugPersistentState) Set

func (s *DebugPersistentState) Set(bucket, key, value []byte) error

Set implements PersistentState.Set.

type DebugSystem

type DebugSystem struct {
	// contains filtered or unexported fields
}

A DebugSystem logs all calls to a System.

func NewDebugSystem

func NewDebugSystem(system System, logger *zerolog.Logger) *DebugSystem

NewDebugSystem returns a new DebugSystem that logs methods on system to logger.

func (*DebugSystem) Chmod

func (s *DebugSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*DebugSystem) Chtimes added in v2.24.0

func (s *DebugSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements System.Chtimes.

func (*DebugSystem) Glob

func (s *DebugSystem) Glob(name string) ([]string, error)

Glob implements System.Glob.

func (s *DebugSystem) Link(oldpath, newpath AbsPath) error

Link implements System.Link.

func (*DebugSystem) Lstat

func (s *DebugSystem) Lstat(name AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*DebugSystem) Mkdir

func (s *DebugSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*DebugSystem) RawPath

func (s *DebugSystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*DebugSystem) ReadDir

func (s *DebugSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*DebugSystem) ReadFile

func (s *DebugSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *DebugSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*DebugSystem) Remove

func (s *DebugSystem) Remove(name AbsPath) error

Remove implements System.Remove.

func (*DebugSystem) RemoveAll

func (s *DebugSystem) RemoveAll(name AbsPath) error

RemoveAll implements System.RemoveAll.

func (*DebugSystem) Rename

func (s *DebugSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*DebugSystem) RunCmd

func (s *DebugSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*DebugSystem) RunScript

func (s *DebugSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (*DebugSystem) Stat

func (s *DebugSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*DebugSystem) UnderlyingFS

func (s *DebugSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*DebugSystem) UnderlyingSystem added in v2.34.0

func (s *DebugSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*DebugSystem) WriteFile

func (s *DebugSystem) WriteFile(name AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *DebugSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type DirAttr

type DirAttr struct {
	TargetName string
	Type       SourceDirTargetType
	Exact      bool
	External   bool
	Private    bool
	ReadOnly   bool
}

DirAttr holds attributes parsed from a source directory name.

func (DirAttr) MarshalZerologObject

func (da DirAttr) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.ObjectMarshaler.MarshalZerologObject.

func (DirAttr) SourceName

func (da DirAttr) SourceName() string

SourceName returns da's source name.

type DryRunSystem

type DryRunSystem struct {
	// contains filtered or unexported fields
}

DryRunSystem is an System that reads from, but does not write to, to a wrapped System.

func NewDryRunSystem

func NewDryRunSystem(system System) *DryRunSystem

NewDryRunSystem returns a new DryRunSystem that wraps fs.

func (*DryRunSystem) Chmod

func (s *DryRunSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*DryRunSystem) Chtimes added in v2.24.0

func (s *DryRunSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements System.Chtimes.

func (*DryRunSystem) Glob

func (s *DryRunSystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (s *DryRunSystem) Link(oldname, newname AbsPath) error

Link implements System.Link.

func (*DryRunSystem) Lstat

func (s *DryRunSystem) Lstat(name AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*DryRunSystem) Mkdir

func (s *DryRunSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*DryRunSystem) Modified

func (s *DryRunSystem) Modified() bool

Modified returns true if a method that would have modified the wrapped system has been called.

func (*DryRunSystem) RawPath

func (s *DryRunSystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*DryRunSystem) ReadDir

func (s *DryRunSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*DryRunSystem) ReadFile

func (s *DryRunSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *DryRunSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*DryRunSystem) Remove

func (s *DryRunSystem) Remove(AbsPath) error

Remove implements System.Remove.

func (*DryRunSystem) RemoveAll

func (s *DryRunSystem) RemoveAll(AbsPath) error

RemoveAll implements System.RemoveAll.

func (*DryRunSystem) Rename

func (s *DryRunSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*DryRunSystem) RunCmd

func (s *DryRunSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*DryRunSystem) RunScript

func (s *DryRunSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (*DryRunSystem) Stat

func (s *DryRunSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*DryRunSystem) UnderlyingFS

func (s *DryRunSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*DryRunSystem) UnderlyingSystem added in v2.34.0

func (s *DryRunSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*DryRunSystem) WriteFile

func (s *DryRunSystem) WriteFile(AbsPath, []byte, fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *DryRunSystem) WriteSymlink(string, AbsPath) error

WriteSymlink implements System.WriteSymlink.

type DumpSystem

type DumpSystem struct {
	// contains filtered or unexported fields
}

A DumpSystem is a System that writes to a data file.

func NewDumpSystem

func NewDumpSystem() *DumpSystem

NewDumpSystem returns a new DumpSystem that accumulates data.

func (DumpSystem) Chmod

func (DumpSystem) Chmod(name AbsPath, perm fs.FileMode) error

func (DumpSystem) Chtimes added in v2.24.0

func (DumpSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (*DumpSystem) Data

func (s *DumpSystem) Data() any

Data returns s's data.

func (DumpSystem) Glob

func (DumpSystem) Glob(pattern string) ([]string, error)
func (DumpSystem) Link(oldname, newname AbsPath) error

func (DumpSystem) Lstat

func (DumpSystem) Lstat(name AbsPath) (fs.FileInfo, error)

func (*DumpSystem) Mkdir

func (s *DumpSystem) Mkdir(dirname AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (DumpSystem) RawPath

func (DumpSystem) RawPath(path AbsPath) (AbsPath, error)

func (DumpSystem) ReadDir

func (DumpSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

func (DumpSystem) ReadFile

func (DumpSystem) ReadFile(name AbsPath) ([]byte, error)
func (DumpSystem) Readlink(name AbsPath) (string, error)

func (DumpSystem) Remove

func (DumpSystem) Remove(name AbsPath) error

func (DumpSystem) RemoveAll

func (DumpSystem) RemoveAll(name AbsPath) error

func (DumpSystem) Rename

func (DumpSystem) Rename(oldpath, newpath AbsPath) error

func (*DumpSystem) RunCmd

func (s *DumpSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*DumpSystem) RunScript

func (s *DumpSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (DumpSystem) Stat

func (DumpSystem) Stat(name AbsPath) (fs.FileInfo, error)

func (*DumpSystem) UnderlyingFS

func (s *DumpSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*DumpSystem) UnderlyingSystem added in v2.34.0

func (s *DumpSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*DumpSystem) WriteFile

func (s *DumpSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *DumpSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type Duration added in v2.15.4

type Duration time.Duration

A Duration is a time.Duration that implements encoding.TextUnmarshaler.

func (*Duration) UnmarshalText added in v2.15.4

func (d *Duration) UnmarshalText(data []byte) error

type Encryption

type Encryption interface {
	Decrypt(ciphertext []byte) ([]byte, error)
	DecryptToFile(plaintextFilename AbsPath, ciphertext []byte) error
	Encrypt(plaintext []byte) ([]byte, error)
	EncryptFile(plaintextFilename AbsPath) ([]byte, error)
	EncryptedSuffix() string
}

An Encryption encrypts and decrypts files and data.

type EntryState

type EntryState struct {
	Type           EntryStateType `json:"type"                     yaml:"type"`
	Mode           fs.FileMode    `json:"mode,omitempty"           yaml:"mode,omitempty"`
	ContentsSHA256 HexBytes       `json:"contentsSHA256,omitempty" yaml:"contentsSHA256,omitempty"` //nolint:tagliatelle
	// contains filtered or unexported fields
}

An EntryState represents the state of an entry. A nil EntryState is equivalent to EntryStateTypeAbsent.

func (*EntryState) Contents

func (s *EntryState) Contents() []byte

Contents returns s's contents, if available.

func (*EntryState) Equal

func (s *EntryState) Equal(other *EntryState) bool

Equal returns true if s is equal to other.

func (*EntryState) Equivalent

func (s *EntryState) Equivalent(other *EntryState) bool

Equivalent returns true if s is equivalent to other.

func (*EntryState) MarshalZerologObject

func (s *EntryState) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (*EntryState) Overwrite

func (s *EntryState) Overwrite() bool

Overwrite returns true if s should be overwritten by default.

type EntryStateType

type EntryStateType string

An EntryStateType is an entry state type.

const (
	EntryStateTypeDir     EntryStateType = "dir"
	EntryStateTypeFile    EntryStateType = "file"
	EntryStateTypeSymlink EntryStateType = "symlink"
	EntryStateTypeRemove  EntryStateType = "remove"
	EntryStateTypeScript  EntryStateType = "script"
)

Entry state types.

type EntryTypeBits

type EntryTypeBits int

An EntryTypeBits is a bitmask of entry types.

const (
	EntryTypeDirs EntryTypeBits = 1 << iota
	EntryTypeFiles
	EntryTypeRemove
	EntryTypeScripts
	EntryTypeSymlinks
	EntryTypeEncrypted
	EntryTypeExternals
	EntryTypeTemplates
	EntryTypeAlways

	// EntryTypesAll is all entry types.
	EntryTypesAll EntryTypeBits = EntryTypeDirs |
		EntryTypeFiles |
		EntryTypeRemove |
		EntryTypeScripts |
		EntryTypeSymlinks |
		EntryTypeEncrypted |
		EntryTypeExternals |
		EntryTypeTemplates |
		EntryTypeAlways

	// EntryTypesNone is no entry types.
	EntryTypesNone EntryTypeBits = 0
)

Entry type bits.

type EntryTypeFilter added in v2.26.0

type EntryTypeFilter struct {
	Include *EntryTypeSet
	Exclude *EntryTypeSet
}

An EntryTypeFilter filters entries by type and source attributes. Any entry in the include set is included, otherwise if the entry is in the exclude set then it is excluded, otherwise it is included.

func NewEntryTypeFilter added in v2.26.0

func NewEntryTypeFilter(includeEntryTypeBits, excludeEntryTypeBits EntryTypeBits) *EntryTypeFilter

NewEntryTypeFilter returns a new EntryTypeFilter with the given entry type bits.

func (*EntryTypeFilter) IncludeEntryTypeBits added in v2.26.0

func (f *EntryTypeFilter) IncludeEntryTypeBits(entryTypeBits EntryTypeBits) bool

IncludeEntryTypeBits returns if entryTypeBits is included.

func (*EntryTypeFilter) IncludeFileInfo added in v2.26.0

func (f *EntryTypeFilter) IncludeFileInfo(fileInfo fs.FileInfo) bool

IncludeFileInfo returns if fileInfo is included.

func (*EntryTypeFilter) IncludeSourceStateEntry added in v2.26.0

func (f *EntryTypeFilter) IncludeSourceStateEntry(sourceStateEntry SourceStateEntry) bool

IncludeSourceStateEntry returns if sourceStateEntry is included.

func (*EntryTypeFilter) IncludeTargetStateEntry added in v2.26.0

func (f *EntryTypeFilter) IncludeTargetStateEntry(targetStateEntry TargetStateEntry) bool

IncludeTargetStateEntry returns if targetStateEntry is included.

type EntryTypeSet

type EntryTypeSet struct {
	// contains filtered or unexported fields
}

An EntryTypeSet is a set of entry types. It parses and prints as a comma-separated list of strings, but is internally represented as a bitmask. *EntryTypeSet implements the github.com/spf13/pflag.Value interface.

func NewEntryTypeSet

func NewEntryTypeSet(bits EntryTypeBits) *EntryTypeSet

NewEntryTypeSet returns a new IncludeSet.

func (*EntryTypeSet) Bits added in v2.26.0

func (s *EntryTypeSet) Bits() EntryTypeBits

Bits returns s's bits.

func (*EntryTypeSet) ContainsEntryTypeBits added in v2.26.0

func (s *EntryTypeSet) ContainsEntryTypeBits(b EntryTypeBits) bool

ContainsEntryTypeBits returns if s includes b.

func (*EntryTypeSet) ContainsFileInfo added in v2.26.0

func (s *EntryTypeSet) ContainsFileInfo(fileInfo fs.FileInfo) bool

ContainsFileInfo returns true if fileInfo is a member.

func (*EntryTypeSet) ContainsSourceStateEntry added in v2.26.0

func (s *EntryTypeSet) ContainsSourceStateEntry(sourceStateEntry SourceStateEntry) bool

ContainsSourceStateEntry returns true if sourceStateEntry is a member.

func (*EntryTypeSet) ContainsTargetStateEntry added in v2.26.0

func (s *EntryTypeSet) ContainsTargetStateEntry(targetStateEntry TargetStateEntry) bool

ContainsTargetStateEntry returns true if targetStateEntry is a member.

func (*EntryTypeSet) MarshalJSON added in v2.27.0

func (s *EntryTypeSet) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.MarshalJSON.

func (*EntryTypeSet) MarshalYAML added in v2.27.0

func (s *EntryTypeSet) MarshalYAML() (any, error)

MarshalYAML implements gopkg.in/yaml.v3.Marshaler.

func (*EntryTypeSet) Set

func (s *EntryTypeSet) Set(str string) error

Set implements github.com/spf13/pflag.Value.Set.

func (*EntryTypeSet) SetSlice

func (s *EntryTypeSet) SetSlice(ss []string) error

SetSlice sets s from a []string.

func (*EntryTypeSet) String

func (s *EntryTypeSet) String() string

String implements github.com/spf13/pflag.Value.String.

func (*EntryTypeSet) Type

func (s *EntryTypeSet) Type() string

Type implements github.com/spf13/pflag.Value.Type.

type ErrorOnWriteSystem

type ErrorOnWriteSystem struct {
	// contains filtered or unexported fields
}

An ErrorOnWriteSystem is an System that passes reads to the wrapped System and returns an error if it is written to.

func NewErrorOnWriteSystem

func NewErrorOnWriteSystem(system System, err error) *ErrorOnWriteSystem

NewErrorOnWriteSystem returns a new ErrorOnWriteSystem that wraps fs and returns err on any write operation.

func (*ErrorOnWriteSystem) Chmod

func (s *ErrorOnWriteSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*ErrorOnWriteSystem) Chtimes added in v2.24.0

func (s *ErrorOnWriteSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements System.Chtimes.

func (*ErrorOnWriteSystem) Glob

func (s *ErrorOnWriteSystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (s *ErrorOnWriteSystem) Link(oldname, newname AbsPath) error

Link implements System.Link.

func (*ErrorOnWriteSystem) Lstat

func (s *ErrorOnWriteSystem) Lstat(name AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*ErrorOnWriteSystem) Mkdir

func (s *ErrorOnWriteSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*ErrorOnWriteSystem) RawPath

func (s *ErrorOnWriteSystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*ErrorOnWriteSystem) ReadDir

func (s *ErrorOnWriteSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*ErrorOnWriteSystem) ReadFile

func (s *ErrorOnWriteSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *ErrorOnWriteSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*ErrorOnWriteSystem) Remove

func (s *ErrorOnWriteSystem) Remove(AbsPath) error

Remove implements System.Remove.

func (*ErrorOnWriteSystem) RemoveAll

func (s *ErrorOnWriteSystem) RemoveAll(AbsPath) error

RemoveAll implements System.RemoveAll.

func (*ErrorOnWriteSystem) Rename

func (s *ErrorOnWriteSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*ErrorOnWriteSystem) RunCmd

func (s *ErrorOnWriteSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*ErrorOnWriteSystem) RunScript

func (s *ErrorOnWriteSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (*ErrorOnWriteSystem) Stat

func (s *ErrorOnWriteSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*ErrorOnWriteSystem) UnderlyingFS

func (s *ErrorOnWriteSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*ErrorOnWriteSystem) UnderlyingSystem added in v2.34.0

func (s *ErrorOnWriteSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*ErrorOnWriteSystem) WriteFile

func (s *ErrorOnWriteSystem) WriteFile(AbsPath, []byte, fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *ErrorOnWriteSystem) WriteSymlink(string, AbsPath) error

WriteSymlink implements System.WriteSymlink.

type ExecuteTemplateDataOptions added in v2.26.0

type ExecuteTemplateDataOptions struct {
	Name            string
	Data            []byte
	TemplateOptions TemplateOptions
}

ExecuteTemplateDataOptions are options to SourceState.ExecuteTemplateData.

type ExitCodeError

type ExitCodeError int

An ExitCodeError indicates the main program should exit with the given code.

func (ExitCodeError) Error

func (e ExitCodeError) Error() string

type External

type External struct {
	Type       ExternalType `json:"type"            toml:"type"            yaml:"type"`
	Encrypted  bool         `json:"encrypted"       toml:"encrypted"       yaml:"encrypted"`
	Exact      bool         `json:"exact"           toml:"exact"           yaml:"exact"`
	Executable bool         `json:"executable"      toml:"executable"      yaml:"executable"`
	Checksum   struct {
		MD5       HexBytes `json:"md5" toml:"md5" yaml:"md5"`
		RIPEMD160 HexBytes `json:"ripemd160" toml:"ripemd160" yaml:"ripemd160"`
		SHA1      HexBytes `json:"sha1" toml:"sha1" yaml:"sha1"`
		SHA256    HexBytes `json:"sha256" toml:"sha256" yaml:"sha256"`
		SHA384    HexBytes `json:"sha384" toml:"sha384" yaml:"sha384"`
		SHA512    HexBytes `json:"sha512" toml:"sha512" yaml:"sha512"`
		Size      int      `json:"size" toml:"size" yaml:"size"`
	} `json:"checksum"        toml:"checksum"        yaml:"checksum"`
	Clone struct {
		Args []string `json:"args" toml:"args" yaml:"args"`
	} `json:"clone"           toml:"clone"           yaml:"clone"`
	Exclude []string `json:"exclude"         toml:"exclude"         yaml:"exclude"`
	Filter  struct {
		Command string   `json:"command" toml:"command" yaml:"command"`
		Args    []string `json:"args" toml:"args" yaml:"args"`
	} `json:"filter"          toml:"filter"          yaml:"filter"`
	Format      ArchiveFormat `json:"format"          toml:"format"          yaml:"format"`
	Include     []string      `json:"include"         toml:"include"         yaml:"include"`
	ArchivePath string        `json:"path"            toml:"path"            yaml:"path"`
	Pull        struct {
		Args []string `json:"args" toml:"args" yaml:"args"`
	} `json:"pull"            toml:"pull"            yaml:"pull"`
	RefreshPeriod   Duration `json:"refreshPeriod"   toml:"refreshPeriod"   yaml:"refreshPeriod"`
	StripComponents int      `json:"stripComponents" toml:"stripComponents" yaml:"stripComponents"`
	URL             string   `json:"url"             toml:"url"             yaml:"url"`
	// contains filtered or unexported fields
}

An External is an external source.

func (*External) OriginString added in v2.20.0

func (e *External) OriginString() string

func (*External) Path added in v2.20.0

func (e *External) Path() AbsPath

type ExternalDiffSystem

type ExternalDiffSystem struct {
	// contains filtered or unexported fields
}

An ExternalDiffSystem is a DiffSystem that uses an external diff tool.

func NewExternalDiffSystem

func NewExternalDiffSystem(
	system System,
	command string,
	args []string,
	destDirAbsPath AbsPath,
	options *ExternalDiffSystemOptions,
) *ExternalDiffSystem

NewExternalDiffSystem creates a new ExternalDiffSystem.

func (*ExternalDiffSystem) Chmod

func (s *ExternalDiffSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*ExternalDiffSystem) Chtimes added in v2.24.0

func (s *ExternalDiffSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements System.Chtimes.

func (*ExternalDiffSystem) Close

func (s *ExternalDiffSystem) Close() error

Close frees all resources held by s.

func (*ExternalDiffSystem) Glob

func (s *ExternalDiffSystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (s *ExternalDiffSystem) Link(oldname, newname AbsPath) error

Link implements System.Link.

func (*ExternalDiffSystem) Lstat

func (s *ExternalDiffSystem) Lstat(name AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*ExternalDiffSystem) Mkdir

func (s *ExternalDiffSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*ExternalDiffSystem) RawPath

func (s *ExternalDiffSystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*ExternalDiffSystem) ReadDir

func (s *ExternalDiffSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*ExternalDiffSystem) ReadFile

func (s *ExternalDiffSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *ExternalDiffSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*ExternalDiffSystem) Remove

func (s *ExternalDiffSystem) Remove(name AbsPath) error

Remove implements System.Remove.

func (*ExternalDiffSystem) RemoveAll

func (s *ExternalDiffSystem) RemoveAll(name AbsPath) error

RemoveAll implements System.RemoveAll.

func (*ExternalDiffSystem) Rename

func (s *ExternalDiffSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*ExternalDiffSystem) RunCmd

func (s *ExternalDiffSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*ExternalDiffSystem) RunScript

func (s *ExternalDiffSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (*ExternalDiffSystem) Stat

func (s *ExternalDiffSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*ExternalDiffSystem) UnderlyingFS

func (s *ExternalDiffSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*ExternalDiffSystem) UnderlyingSystem added in v2.34.0

func (s *ExternalDiffSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*ExternalDiffSystem) WriteFile

func (s *ExternalDiffSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *ExternalDiffSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type ExternalDiffSystemOptions

type ExternalDiffSystemOptions struct {
	Filter         *EntryTypeFilter
	Reverse        bool
	ScriptContents bool
}

ExternalDiffSystemOptions are options for NewExternalDiffSystem.

type ExternalType

type ExternalType string

An ExternalType is a type of external source.

const (
	ExternalTypeArchive     ExternalType = "archive"
	ExternalTypeArchiveFile ExternalType = "archive-file"
	ExternalTypeFile        ExternalType = "file"
	ExternalTypeGitRepo     ExternalType = "git-repo"
)

ExternalTypes.

type FileAttr

type FileAttr struct {
	TargetName string
	Type       SourceFileTargetType
	Condition  ScriptCondition
	Empty      bool
	Encrypted  bool
	Executable bool
	Order      ScriptOrder
	Private    bool
	ReadOnly   bool
	Template   bool
}

A FileAttr holds attributes parsed from a source file name.

func (FileAttr) MarshalZerologObject

func (fa FileAttr) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (FileAttr) SourceName

func (fa FileAttr) SourceName(encryptedSuffix string) string

SourceName returns fa's source name.

type Format

type Format interface {
	Marshal(value any) ([]byte, error)
	Name() string
	Unmarshal(data []byte, value any) error
}

A Format is a serialization format.

var (
	FormatJSON  Format = formatJSON{}
	FormatJSONC Format = formatJSONC{}
	FormatTOML  Format = formatTOML{}
	FormatYAML  Format = formatYAML{}
)

Formats.

func FormatFromAbsPath added in v2.24.0

func FormatFromAbsPath(absPath AbsPath) (Format, error)

FormatFromAbsPath returns the expected format of absPath.

type GPGEncryption

type GPGEncryption struct {
	Command    string   `json:"command"    mapstructure:"command"    yaml:"command"`
	Args       []string `json:"args"       mapstructure:"args"       yaml:"args"`
	Recipient  string   `json:"recipient"  mapstructure:"recipient"  yaml:"recipient"`
	Recipients []string `json:"recipients" mapstructure:"recipients" yaml:"recipients"`
	Symmetric  bool     `json:"symmetric"  mapstructure:"symmetric"  yaml:"symmetric"`
	Suffix     string   `json:"suffix"     mapstructure:"suffix"     yaml:"suffix"`
}

A GPGEncryption uses gpg for encryption and decryption. See https://gnupg.org/.

func (*GPGEncryption) Decrypt

func (e *GPGEncryption) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt implements Encryption.Decrypt.

func (*GPGEncryption) DecryptToFile

func (e *GPGEncryption) DecryptToFile(plaintextFilename AbsPath, ciphertext []byte) error

DecryptToFile implements Encryption.DecryptToFile.

func (*GPGEncryption) Encrypt

func (e *GPGEncryption) Encrypt(plaintext []byte) ([]byte, error)

Encrypt implements Encryption.Encrypt.

func (*GPGEncryption) EncryptFile

func (e *GPGEncryption) EncryptFile(plaintextFilename AbsPath) ([]byte, error)

EncryptFile implements Encryption.EncryptFile.

func (*GPGEncryption) EncryptedSuffix

func (e *GPGEncryption) EncryptedSuffix() string

EncryptedSuffix implements Encryption.EncryptedSuffix.

type GitDiffSystem

type GitDiffSystem struct {
	// contains filtered or unexported fields
}

A GitDiffSystem wraps a System and logs all of the actions executed as a git diff.

func NewGitDiffSystem

func NewGitDiffSystem(
	system System,
	w io.Writer,
	dirAbsPath AbsPath,
	options *GitDiffSystemOptions,
) *GitDiffSystem

NewGitDiffSystem returns a new GitDiffSystem. Output is written to w, the dirAbsPath is stripped from paths, and color controls whether the output contains ANSI color escape sequences.

func (*GitDiffSystem) Chmod

func (s *GitDiffSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*GitDiffSystem) Chtimes added in v2.24.0

func (s *GitDiffSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements system.Chtimes.

func (*GitDiffSystem) Glob

func (s *GitDiffSystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (s *GitDiffSystem) Link(oldname, newname AbsPath) error

Link implements System.Link.

func (*GitDiffSystem) Lstat

func (s *GitDiffSystem) Lstat(name AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*GitDiffSystem) Mkdir

func (s *GitDiffSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*GitDiffSystem) RawPath

func (s *GitDiffSystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*GitDiffSystem) ReadDir

func (s *GitDiffSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*GitDiffSystem) ReadFile

func (s *GitDiffSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *GitDiffSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*GitDiffSystem) Remove

func (s *GitDiffSystem) Remove(name AbsPath) error

Remove implements System.Remove.

func (*GitDiffSystem) RemoveAll

func (s *GitDiffSystem) RemoveAll(name AbsPath) error

RemoveAll implements System.RemoveAll.

func (*GitDiffSystem) Rename

func (s *GitDiffSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*GitDiffSystem) RunCmd

func (s *GitDiffSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*GitDiffSystem) RunScript

func (s *GitDiffSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (*GitDiffSystem) Stat

func (s *GitDiffSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*GitDiffSystem) UnderlyingFS

func (s *GitDiffSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*GitDiffSystem) UnderlyingSystem added in v2.34.0

func (s *GitDiffSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*GitDiffSystem) WriteFile

func (s *GitDiffSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *GitDiffSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type GitDiffSystemOptions

type GitDiffSystemOptions struct {
	Color          bool
	Filter         *EntryTypeFilter
	Reverse        bool
	ScriptContents bool
	TextConvFunc   TextConvFunc
}

GitDiffSystemOptions are options for NewGitDiffSystem.

type HexBytes

type HexBytes []byte

A HexBytes is a []byte which is marshaled as a hex string.

func (HexBytes) Bytes

func (h HexBytes) Bytes() []byte

Bytes returns h as a []byte.

func (HexBytes) MarshalText

func (h HexBytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText.

func (HexBytes) String

func (h HexBytes) String() string

func (*HexBytes) UnmarshalText

func (h *HexBytes) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText.

type Interpreter

type Interpreter struct {
	Command string   `mapstructure:"command"`
	Args    []string `mapstructure:"args"`
}

An Interpreter interprets scripts.

func (*Interpreter) ExecCommand

func (i *Interpreter) ExecCommand(name string) *exec.Cmd

ExecCommand returns the *exec.Cmd to interpret name.

func (*Interpreter) MarshalZerologObject

func (i *Interpreter) MarshalZerologObject(event *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (*Interpreter) None

func (i *Interpreter) None() bool

None returns if i represents no interpreter.

type MockPersistentState

type MockPersistentState struct {
	// contains filtered or unexported fields
}

A MockPersistentState is a mock persistent state.

func NewMockPersistentState

func NewMockPersistentState() *MockPersistentState

NewMockPersistentState returns a new PersistentState.

func (*MockPersistentState) Close

func (s *MockPersistentState) Close() error

Close closes s.

func (*MockPersistentState) CopyTo

CopyTo implements PersistentState.CopyTo.

func (*MockPersistentState) Data

func (s *MockPersistentState) Data() (any, error)

Data implements PersistentState.Data.

func (*MockPersistentState) Delete

func (s *MockPersistentState) Delete(bucket, key []byte) error

Delete implements PersistentState.Delete.

func (*MockPersistentState) DeleteBucket

func (s *MockPersistentState) DeleteBucket(bucket []byte) error

DeleteBucket implements PersistentState.DeleteBucket.

func (*MockPersistentState) ForEach

func (s *MockPersistentState) ForEach(bucket []byte, fn func(k, v []byte) error) error

ForEach implements PersistentState.ForEach.

func (*MockPersistentState) Get

func (s *MockPersistentState) Get(bucket, key []byte) ([]byte, error)

Get implements PersistentState.Get.

func (*MockPersistentState) Set

func (s *MockPersistentState) Set(bucket, key, value []byte) error

Set implements PersistentState.Set.

type Mode

type Mode string

A Mode is a mode of operation. It implements the github.com/spf13/flag.Value interface.

const (
	ModeFile    Mode = "file"
	ModeSymlink Mode = "symlink"
)

Modes.

func (*Mode) Set

func (m *Mode) Set(s string) error

Set implements github.com/spf13/flag.Value.Set.

func (Mode) String

func (m Mode) String() string

String implements github.com/spf13/flag.Value.String.

func (Mode) Type

func (m Mode) Type() string

Type implements github.com/spf13/flag.Value.Type.

type NoEncryption

type NoEncryption struct{}

NoEncryption returns an error when any method is called.

func (NoEncryption) Decrypt

func (NoEncryption) Decrypt([]byte) ([]byte, error)

Decrypt implements Encryption.Decrypt.

func (NoEncryption) DecryptToFile

func (NoEncryption) DecryptToFile(AbsPath, []byte) error

DecryptToFile implements Encryption.DecryptToFile.

func (NoEncryption) Encrypt

func (NoEncryption) Encrypt([]byte) ([]byte, error)

Encrypt implements Encryption.Encrypt.

func (NoEncryption) EncryptFile

func (NoEncryption) EncryptFile(AbsPath) ([]byte, error)

EncryptFile implements Encryption.EncryptFile.

func (NoEncryption) EncryptedSuffix

func (NoEncryption) EncryptedSuffix() string

EncryptedSuffix implements Encryption.EncryptedSuffix.

type NotInAbsDirError added in v2.17.2

type NotInAbsDirError struct {
	// contains filtered or unexported fields
}

func (*NotInAbsDirError) Error added in v2.17.2

func (e *NotInAbsDirError) Error() string

type NullPersistentState

type NullPersistentState struct{}

A NullPersistentState is an empty PersistentState that returns the zero value for all reads and silently consumes all writes.

func (NullPersistentState) Close

func (NullPersistentState) Close() error

Close does nothing.

func (NullPersistentState) CopyTo

CopyTo does nothing.

func (NullPersistentState) Data

func (NullPersistentState) Data() (any, error)

Data does nothing.

func (NullPersistentState) Delete

func (NullPersistentState) Delete(bucket, key []byte) error

Delete does nothing.

func (NullPersistentState) DeleteBucket

func (NullPersistentState) DeleteBucket(bucket []byte) error

DeleteBucket does nothing.

func (NullPersistentState) ForEach

func (NullPersistentState) ForEach(bucket []byte, fn func(k, v []byte) error) error

ForEach does nothing.

func (NullPersistentState) Get

func (NullPersistentState) Get(bucket, key []byte) ([]byte, error)

Get does nothing.

func (NullPersistentState) Set

func (NullPersistentState) Set(bucket, key, value []byte) error

Set does nothing.

type NullSystem

type NullSystem struct {
	// contains filtered or unexported fields
}

func (NullSystem) Chmod

func (NullSystem) Chmod(name AbsPath, perm fs.FileMode) error

func (NullSystem) Chtimes added in v2.24.0

func (NullSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (NullSystem) Glob

func (NullSystem) Glob(pattern string) ([]string, error)
func (NullSystem) Link(oldname, newname AbsPath) error

func (NullSystem) Lstat

func (NullSystem) Lstat(name AbsPath) (fs.FileInfo, error)

func (NullSystem) Mkdir

func (NullSystem) Mkdir(name AbsPath, perm fs.FileMode) error

func (NullSystem) RawPath

func (NullSystem) RawPath(path AbsPath) (AbsPath, error)

func (NullSystem) ReadDir

func (NullSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

func (NullSystem) ReadFile

func (NullSystem) ReadFile(name AbsPath) ([]byte, error)
func (NullSystem) Readlink(name AbsPath) (string, error)

func (NullSystem) Remove

func (NullSystem) Remove(name AbsPath) error

func (NullSystem) RemoveAll

func (NullSystem) RemoveAll(name AbsPath) error

func (NullSystem) Rename

func (NullSystem) Rename(oldpath, newpath AbsPath) error

func (NullSystem) RunCmd

func (NullSystem) RunCmd(cmd *exec.Cmd) error

func (NullSystem) RunScript

func (NullSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

func (NullSystem) Stat

func (NullSystem) Stat(name AbsPath) (fs.FileInfo, error)

func (NullSystem) UnderlyingFS

func (NullSystem) UnderlyingFS() vfs.FS

func (*NullSystem) UnderlyingSystem added in v2.34.0

func (s *NullSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (NullSystem) WriteFile

func (NullSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error
func (NullSystem) WriteSymlink(oldname string, newname AbsPath) error

type PersistentState

type PersistentState interface {
	Close() error
	CopyTo(s PersistentState) error
	Data() (any, error)
	Delete(bucket, key []byte) error
	DeleteBucket(bucket []byte) error
	ForEach(bucket []byte, fn func(k, v []byte) error) error
	Get(bucket, key []byte) ([]byte, error)
	Set(bucket, key, value []byte) error
}

A PersistentState is a persistent state.

type PreAddFunc

type PreAddFunc func(targetRelPath RelPath) error

A PreAddFunc is called before a new source state entry is added.

type PreApplyFunc

type PreApplyFunc func(
	targetRelPath RelPath, targetEntryState, lastWrittenEntryState, actualEntryState *EntryState,
) error

A PreApplyFunc is called before a target is applied.

type ReadOnlySystem

type ReadOnlySystem struct {
	// contains filtered or unexported fields
}

A ReadOnlySystem is a system that may only be read from.

func NewReadOnlySystem

func NewReadOnlySystem(system System) *ReadOnlySystem

NewReadOnlySystem returns a new ReadOnlySystem that wraps system.

func (ReadOnlySystem) Chmod

func (ReadOnlySystem) Chmod(name AbsPath, perm fs.FileMode) error

func (ReadOnlySystem) Chtimes added in v2.24.0

func (ReadOnlySystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (*ReadOnlySystem) Glob

func (s *ReadOnlySystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (ReadOnlySystem) Link(oldname, newname AbsPath) error

func (*ReadOnlySystem) Lstat

func (s *ReadOnlySystem) Lstat(filename AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (ReadOnlySystem) Mkdir

func (ReadOnlySystem) Mkdir(name AbsPath, perm fs.FileMode) error

func (*ReadOnlySystem) RawPath

func (s *ReadOnlySystem) RawPath(path AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*ReadOnlySystem) ReadDir

func (s *ReadOnlySystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*ReadOnlySystem) ReadFile

func (s *ReadOnlySystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *ReadOnlySystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (ReadOnlySystem) Remove

func (ReadOnlySystem) Remove(name AbsPath) error

func (ReadOnlySystem) RemoveAll

func (ReadOnlySystem) RemoveAll(name AbsPath) error

func (ReadOnlySystem) Rename

func (ReadOnlySystem) Rename(oldpath, newpath AbsPath) error

func (ReadOnlySystem) RunCmd

func (ReadOnlySystem) RunCmd(cmd *exec.Cmd) error

func (ReadOnlySystem) RunScript

func (ReadOnlySystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

func (*ReadOnlySystem) Stat

func (s *ReadOnlySystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*ReadOnlySystem) UnderlyingFS

func (s *ReadOnlySystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*ReadOnlySystem) UnderlyingSystem added in v2.34.0

func (s *ReadOnlySystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (ReadOnlySystem) WriteFile

func (ReadOnlySystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error
func (ReadOnlySystem) WriteSymlink(oldname string, newname AbsPath) error

type ReadOptions

type ReadOptions struct {
	ReadHTTPResponse func(*http.Response) ([]byte, error)
	RefreshExternals RefreshExternals
	TimeNow          func() time.Time
}

ReadOptions are options to SourceState.Read.

type RealSystem

type RealSystem struct {
	// contains filtered or unexported fields
}

An RealSystem is a System that writes to a filesystem and executes scripts.

func NewRealSystem

func NewRealSystem(fileSystem vfs.FS, options ...RealSystemOption) *RealSystem

NewRealSystem returns a System that acts on fileSystem.

func (*RealSystem) Chmod

func (s *RealSystem) Chmod(name AbsPath, mode fs.FileMode) error

Chmod implements System.Chmod.

func (*RealSystem) Chtimes added in v2.24.0

func (s *RealSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

Chtimes implements System.Chtimes.

func (*RealSystem) Glob

func (s *RealSystem) Glob(pattern string) ([]string, error)

Glob implements System.Glob.

func (s *RealSystem) Link(oldname, newname AbsPath) error

Link implements System.Link.

func (*RealSystem) Lstat

func (s *RealSystem) Lstat(filename AbsPath) (fs.FileInfo, error)

Lstat implements System.Lstat.

func (*RealSystem) Mkdir

func (s *RealSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (*RealSystem) RawPath

func (s *RealSystem) RawPath(absPath AbsPath) (AbsPath, error)

RawPath implements System.RawPath.

func (*RealSystem) ReadDir

func (s *RealSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

ReadDir implements System.ReadDir.

func (*RealSystem) ReadFile

func (s *RealSystem) ReadFile(name AbsPath) ([]byte, error)

ReadFile implements System.ReadFile.

func (s *RealSystem) Readlink(name AbsPath) (string, error)

Readlink implements System.Readlink.

func (*RealSystem) Remove

func (s *RealSystem) Remove(name AbsPath) error

Remove implements System.Remove.

func (*RealSystem) RemoveAll

func (s *RealSystem) RemoveAll(name AbsPath) error

RemoveAll implements System.RemoveAll.

func (*RealSystem) Rename

func (s *RealSystem) Rename(oldpath, newpath AbsPath) error

Rename implements System.Rename.

func (*RealSystem) RunCmd

func (s *RealSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*RealSystem) RunScript

func (s *RealSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) (err error)

RunScript implements System.RunScript.

func (*RealSystem) SetScriptEnv added in v2.25.0

func (s *RealSystem) SetScriptEnv(scriptEnv []string)

SetScriptEnv sets the environment variables for scripts.

func (*RealSystem) Stat

func (s *RealSystem) Stat(name AbsPath) (fs.FileInfo, error)

Stat implements System.Stat.

func (*RealSystem) UnderlyingFS

func (s *RealSystem) UnderlyingFS() vfs.FS

UnderlyingFS implements System.UnderlyingFS.

func (*RealSystem) UnderlyingSystem added in v2.34.0

func (s *RealSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*RealSystem) WriteFile

func (s *RealSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) (err error)

WriteFile implements System.WriteFile.

func (s *RealSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type RealSystemOption

type RealSystemOption func(*RealSystem)

A RealSystemOption sets an option on a RealSystem.

func RealSystemWithSafe

func RealSystemWithSafe(safe bool) RealSystemOption

RealSystemWithSafe sets the safe flag of the RealSystem.

func RealSystemWithScriptTempDir added in v2.13.1

func RealSystemWithScriptTempDir(scriptTempDir AbsPath) RealSystemOption

RealSystemWithScriptTempDir sets the script temporary directory of the RealSystem.

type RefreshExternals added in v2.24.0

type RefreshExternals int
const (
	RefreshExternalsAuto RefreshExternals = iota
	RefreshExternalsAlways
	RefreshExternalsNever
)

func (*RefreshExternals) Set added in v2.24.0

func (re *RefreshExternals) Set(s string) error

func (RefreshExternals) String added in v2.24.0

func (re RefreshExternals) String() string

func (RefreshExternals) Type added in v2.24.0

func (re RefreshExternals) Type() string

type RelPath

type RelPath struct {
	// contains filtered or unexported fields
}

A RelPath is a relative path.

func NewRelPath

func NewRelPath(relPath string) RelPath

NewRelPath returns a new RelPath.

func (RelPath) AppendString

func (p RelPath) AppendString(s string) RelPath

AppendString appends s to p.

func (RelPath) Base

func (p RelPath) Base() string

Base returns p's base name.

func (RelPath) Dir

func (p RelPath) Dir() RelPath

Dir returns p's directory.

func (RelPath) Empty

func (p RelPath) Empty() bool

Empty returns if p is empty.

func (RelPath) Ext

func (p RelPath) Ext() string

Ext returns p's extension.

func (RelPath) HasDirPrefix

func (p RelPath) HasDirPrefix(dirPrefix RelPath) bool

HasDirPrefix returns true if p has dir prefix dirPrefix.

func (RelPath) Join

func (p RelPath) Join(relPaths ...RelPath) RelPath

Join appends relPaths to p.

func (RelPath) JoinString

func (p RelPath) JoinString(ss ...string) RelPath

JoinString returns a new RelPath with ss appended.

func (RelPath) Len

func (p RelPath) Len() int

Len returns the length of p.

func (RelPath) Less

func (p RelPath) Less(other RelPath) bool

Less returns true if p is less than other.

func (RelPath) MarshalJSON

func (p RelPath) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding.TextMarshaler.MarshalJSON.

func (RelPath) Slice

func (p RelPath) Slice(begin, end int) RelPath

Slice returns a part of p.

func (RelPath) SourceRelDirPath added in v2.30.0

func (p RelPath) SourceRelDirPath() SourceRelPath

SourceRelDirPath returns p as a directory SourceRelPath.

func (RelPath) SourceRelPath added in v2.30.0

func (p RelPath) SourceRelPath() SourceRelPath

SourceRelPath returns p as a SourceRelPath.

func (RelPath) Split

func (p RelPath) Split() (RelPath, RelPath)

Split returns p's directory and path.

func (RelPath) SplitAll

func (p RelPath) SplitAll() []RelPath

SplitAll returns p's components.

func (RelPath) String

func (p RelPath) String() string

func (RelPath) TrimDirPrefix

func (p RelPath) TrimDirPrefix(dirPrefix RelPath) (RelPath, error)

TrimDirPrefix trims prefix from p.

type RelPaths

type RelPaths []RelPath

RelPaths is a slice of RelPaths that implements sort.Interface.

func (RelPaths) Len

func (ps RelPaths) Len() int

func (RelPaths) Less

func (ps RelPaths) Less(i, j int) bool

func (RelPaths) Swap

func (ps RelPaths) Swap(i, j int)

type ReplaceFunc added in v2.18.0

type ReplaceFunc func(targetRelPath RelPath, newSourceStateEntry, oldSourceStateEntry SourceStateEntry) error

A ReplaceFunc is called before a source state entry is replaced.

type RunScriptOptions added in v2.27.1

type RunScriptOptions struct {
	Interpreter *Interpreter
	Condition   ScriptCondition
}

type ScriptCondition

type ScriptCondition string

A ScriptCondition defines under what conditions a script should be executed.

const (
	ScriptConditionNone     ScriptCondition = ""
	ScriptConditionAlways   ScriptCondition = "always"
	ScriptConditionOnce     ScriptCondition = "once"
	ScriptConditionOnChange ScriptCondition = "onchange"
)

Script conditions.

type ScriptOrder

type ScriptOrder int

A ScriptOrder defines when a script should be executed.

const (
	ScriptOrderBefore ScriptOrder = -1
	ScriptOrderDuring ScriptOrder = 0
	ScriptOrderAfter  ScriptOrder = 1
)

Script orders.

type SourceAttr added in v2.26.0

type SourceAttr struct {
	Condition ScriptCondition
	Encrypted bool
	External  bool
	Template  bool
}

A SourceAttr contains attributes of the source.

type SourceDirTargetType added in v2.33.6

type SourceDirTargetType int

A SourceDirTargetType is the type of a target represented by a directory in the source state.

const (
	SourceDirTypeDir SourceDirTargetType = iota
	SourceDirTypeRemove
)

Source dir types.

type SourceFileTargetType

type SourceFileTargetType int

A SourceFileTargetType is a the type of a target represented by a file in the source state. A file in the source state can represent a file, script, or symlink in the target state.

const (
	SourceFileTypeCreate SourceFileTargetType = iota
	SourceFileTypeFile
	SourceFileTypeModify
	SourceFileTypeRemove
	SourceFileTypeScript
	SourceFileTypeSymlink
)

Source file types.

type SourceRelPath

type SourceRelPath struct {
	// contains filtered or unexported fields
}

A SourceRelPath is a relative path to an entry in the source state.

func NewSourceRelDirPath

func NewSourceRelDirPath(relPath string) SourceRelPath

NewSourceRelDirPath returns a new SourceRelPath for a directory.

func NewSourceRelPath

func NewSourceRelPath(relPath string) SourceRelPath

NewSourceRelPath returns a new SourceRelPath.

func (SourceRelPath) Dir

func (p SourceRelPath) Dir() SourceRelPath

Dir returns p's directory.

func (SourceRelPath) Empty

func (p SourceRelPath) Empty() bool

Empty returns true if p is empty.

func (SourceRelPath) Join

func (p SourceRelPath) Join(sourceRelPaths ...SourceRelPath) SourceRelPath

Join appends sourceRelPaths to p.

func (SourceRelPath) Less

func (p SourceRelPath) Less(other SourceRelPath) bool

Less returns true if p is less than other.

func (SourceRelPath) RelPath

func (p SourceRelPath) RelPath() RelPath

RelPath returns p as a relative path.

func (SourceRelPath) Split

Split returns the p's file and directory.

func (SourceRelPath) String

func (p SourceRelPath) String() string

func (SourceRelPath) TargetRelPath

func (p SourceRelPath) TargetRelPath(encryptedSuffix string) RelPath

TargetRelPath returns the relative path of p's target.

type SourceState

type SourceState struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A SourceState is a source state.

func NewSourceState

func NewSourceState(options ...SourceStateOption) *SourceState

NewSourceState creates a new source state with the given options.

func (*SourceState) Add

func (s *SourceState) Add(
	sourceSystem System,
	persistentState PersistentState,
	destSystem System,
	destAbsPathInfos map[AbsPath]fs.FileInfo,
	options *AddOptions,
) error

Add adds destAbsPathInfos to s.

func (*SourceState) AddDestAbsPathInfos

func (s *SourceState) AddDestAbsPathInfos(
	destAbsPathInfos map[AbsPath]fs.FileInfo,
	system System,
	destAbsPath AbsPath,
	fileInfo fs.FileInfo,
) error

AddDestAbsPathInfos adds an fs.FileInfo to destAbsPathInfos for destAbsPath and any of its parents which are not already known.

func (*SourceState) Apply

func (s *SourceState) Apply(
	targetSystem, destSystem System,
	persistentState PersistentState,
	targetDirAbsPath AbsPath,
	targetRelPath RelPath,
	options ApplyOptions,
) error

Apply updates targetRelPath in targetDirAbsPath in destSystem to match s.

func (*SourceState) Encryption

func (s *SourceState) Encryption() Encryption

Encryption returns s's encryption.

func (*SourceState) ExecuteTemplateData

func (s *SourceState) ExecuteTemplateData(options ExecuteTemplateDataOptions) ([]byte, error)

ExecuteTemplateData returns the result of executing template data.

func (*SourceState) ForEach

func (s *SourceState) ForEach(f func(RelPath, SourceStateEntry) error) error

ForEach calls f for each source state entry.

func (*SourceState) Get added in v2.33.0

func (s *SourceState) Get(targetRelPath RelPath) SourceStateEntry

Get returns the source state entry for targetRelPath.

func (*SourceState) Ignore

func (s *SourceState) Ignore(targetRelPath RelPath) bool

Ignore returns if targetRelPath should be ignored.

func (*SourceState) Ignored added in v2.15.0

func (s *SourceState) Ignored() RelPaths

Ignored returns all ignored RelPaths.

func (*SourceState) MustEntry

func (s *SourceState) MustEntry(targetRelPath RelPath) SourceStateEntry

MustEntry returns the source state entry associated with targetRelPath, and panics if it does not exist.

func (*SourceState) PostApply

func (s *SourceState) PostApply(
	targetSystem System,
	targetDirAbsPath AbsPath,
	targetRelPaths RelPaths,
) error

PostApply performs all updates required after s.Apply.

func (*SourceState) Read

func (s *SourceState) Read(ctx context.Context, options *ReadOptions) error

Read reads the source state from the source directory.

func (*SourceState) TargetRelPaths

func (s *SourceState) TargetRelPaths() []RelPath

TargetRelPaths returns all of s's target relative paths in order.

func (*SourceState) TemplateData

func (s *SourceState) TemplateData() map[string]any

TemplateData returns s's template data.

type SourceStateCommand added in v2.13.0

type SourceStateCommand struct {
	// contains filtered or unexported fields
}

A SourceStateCommand represents a command that should be run.

func (*SourceStateCommand) Evaluate added in v2.13.0

func (s *SourceStateCommand) Evaluate() error

Evaluate evaluates s and returns any error.

func (*SourceStateCommand) MarshalZerologObject added in v2.13.0

func (s *SourceStateCommand) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (*SourceStateCommand) Order added in v2.13.0

func (s *SourceStateCommand) Order() ScriptOrder

Order returns s's order.

func (*SourceStateCommand) Origin added in v2.13.0

Origin returns s's origin.

func (*SourceStateCommand) SourceRelPath added in v2.13.0

func (s *SourceStateCommand) SourceRelPath() SourceRelPath

SourceRelPath returns s's source relative path.

func (*SourceStateCommand) TargetStateEntry added in v2.13.0

func (s *SourceStateCommand) TargetStateEntry(
	destSystem System,
	destDirAbsPath AbsPath,
) (TargetStateEntry, error)

TargetStateEntry returns s's target state entry.

type SourceStateDir

type SourceStateDir struct {
	Attr DirAttr
	// contains filtered or unexported fields
}

A SourceStateDir represents the state of a directory in the source state.

func (*SourceStateDir) Evaluate

func (s *SourceStateDir) Evaluate() error

Evaluate evaluates s and returns any error.

func (*SourceStateDir) MarshalZerologObject

func (s *SourceStateDir) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (*SourceStateDir) Order

func (s *SourceStateDir) Order() ScriptOrder

Order returns s's order.

func (*SourceStateDir) Origin

func (s *SourceStateDir) Origin() SourceStateOrigin

Origin returns s's origin.

func (*SourceStateDir) SourceRelPath

func (s *SourceStateDir) SourceRelPath() SourceRelPath

SourceRelPath returns s's source relative path.

func (*SourceStateDir) TargetStateEntry

func (s *SourceStateDir) TargetStateEntry(
	destSystem System,
	destDirAbsPath AbsPath,
) (TargetStateEntry, error)

TargetStateEntry returns s's target state entry.

type SourceStateEntry

type SourceStateEntry interface {
	zerolog.LogObjectMarshaler
	Evaluate() error
	Order() ScriptOrder
	Origin() SourceStateOrigin
	SourceRelPath() SourceRelPath
	TargetStateEntry(destSystem System, destDirAbsPath AbsPath) (TargetStateEntry, error)
}

A SourceStateEntry represents the state of an entry in the source state.

type SourceStateFile

type SourceStateFile struct {
	Attr FileAttr
	// contains filtered or unexported fields
}

A SourceStateFile represents the state of a file in the source state.

func (SourceStateFile) Contents

func (lc SourceStateFile) Contents() ([]byte, error)

Contents returns lc's contents.

func (SourceStateFile) ContentsSHA256

func (lc SourceStateFile) ContentsSHA256() ([]byte, error)

ContentsSHA256 returns the SHA256 sum of lc's contents.

func (*SourceStateFile) Evaluate

func (s *SourceStateFile) Evaluate() error

Evaluate evaluates s and returns any error.

func (*SourceStateFile) MarshalZerologObject

func (s *SourceStateFile) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements github.com/rs/zerolog.LogObjectMarshaler.MarshalZerologObject.

func (*SourceStateFile) Order

func (s *SourceStateFile) Order() ScriptOrder

Order returns s's order.

func (*SourceStateFile) Origin

func (s *SourceStateFile) Origin() SourceStateOrigin

Origin returns s's origin.

func (*SourceStateFile) SourceRelPath

func (s *SourceStateFile) SourceRelPath() SourceRelPath

SourceRelPath returns s's source relative path.

func (*SourceStateFile) TargetStateEntry

func (s *SourceStateFile) TargetStateEntry(
	destSystem System,
	destDirAbsPath AbsPath,
) (TargetStateEntry, error)

TargetStateEntry returns s's target state entry.

type SourceStateOption

type SourceStateOption func(*SourceState)

A SourceStateOption sets an option on a source state.

func WithBaseSystem

func WithBaseSystem(baseSystem System) SourceStateOption

WithBaseSystem sets the base system.

func WithCacheDir

func WithCacheDir(cacheDirAbsPath AbsPath) SourceStateOption

WithCacheDir sets the cache directory.

func WithDefaultTemplateDataFunc

func WithDefaultTemplateDataFunc(defaultTemplateDataFunc func() map[string]any) SourceStateOption

WithDefaultTemplateDataFunc sets the default template data function.

func WithDestDir

func WithDestDir(destDirAbsPath AbsPath) SourceStateOption

WithDestDir sets the destination directory.

func WithEncryption

func WithEncryption(encryption Encryption) SourceStateOption

WithEncryption sets the encryption.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) SourceStateOption

WithHTTPClient sets the HTTP client.

func WithInterpreters

func WithInterpreters(interpreters map[string]*Interpreter) SourceStateOption

WithInterpreters sets the interpreters.

func WithLogger

func WithLogger(logger *zerolog.Logger) SourceStateOption

WithLogger sets the logger.

func WithMode

func WithMode(mode Mode) SourceStateOption

WithMode sets the mode.

func WithPriorityTemplateData

func WithPriorityTemplateData(priorityTemplateData map[string]any) SourceStateOption

WithPriorityTemplateData adds priority template data.

func WithReadTemplateData

func WithReadTemplateData(readTemplateData bool) SourceStateOption

WithReadTemplateData sets whether to read .chezmoidata.<format> files.

func WithScriptEnv added in v2.33.2

func WithScriptEnv(scriptEnv []string) SourceStateOption

WithScriptEnv sets the script environment variables.

func WithSourceDir

func WithSourceDir(sourceDirAbsPath AbsPath) SourceStateOption

WithSourceDir sets the source directory.

func WithSystem

func WithSystem(system System) SourceStateOption

WithSystem sets the system.

func WithTemplateDataOnly

func WithTemplateDataOnly(templateDataOnly bool) SourceStateOption

WithTemplateDataOnly sets whether only template data should be read.

func WithTemplateFuncs

func WithTemplateFuncs(templateFuncs template.FuncMap) SourceStateOption

WithTemplateFuncs sets the template functions.

func WithTemplateOptions

func WithTemplateOptions(templateOptions []string) SourceStateOption

WithTemplateOptions sets the template options.

func WithUmask added in v2.27.3

func WithUmask(umask fs.FileMode) SourceStateOption

WithUmask sets the umask.

func WithVersion

func WithVersion(version semver.Version) SourceStateOption

WithVersion sets the version.

type SourceStateOrigin added in v2.20.0

type SourceStateOrigin interface {
	Path() AbsPath
	OriginString() string
}

A SourceStateOrigin represents the origin of a source state.

type SourceStateOriginAbsPath added in v2.20.0

type SourceStateOriginAbsPath AbsPath

A SourceStateOriginAbsPath is an absolute path.

func (SourceStateOriginAbsPath) OriginString added in v2.20.0

func (s SourceStateOriginAbsPath) OriginString() string

OriginString returns s's origin.

func (SourceStateOriginAbsPath) Path added in v2.20.0

Path returns s's path.

type SourceStateOriginRemove added in v2.20.0

type SourceStateOriginRemove struct{}

A SourceStateOriginRemove is used for removes. The source of the remove is not currently tracked. The remove could come from an exact_ directory, a non-empty_ file with empty contents, or one of many patterns in many .chezmoiignore files.

FIXME remove this when the sources of all removes are tracked.

func (SourceStateOriginRemove) OriginString added in v2.20.0

func (s SourceStateOriginRemove) OriginString() string

OriginString returns s's origin.

func (SourceStateOriginRemove) Path added in v2.20.0

Path returns s's path.

type SourceStateRemove

type SourceStateRemove struct {
	// contains filtered or unexported fields
}

A SourceStateRemove represents that an entry should be removed.

func (*SourceStateRemove) Evaluate

func (s *SourceStateRemove) Evaluate() error

Evaluate evaluates s and returns any error.

func (*SourceStateRemove) MarshalZerologObject

func (s *SourceStateRemove) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler.

func (*SourceStateRemove) Order

func (s *SourceStateRemove) Order() ScriptOrder

Order returns s's order.

func (*SourceStateRemove) Origin

Origin returns s's origin.

func (*SourceStateRemove) SourceRelPath

func (s *SourceStateRemove) SourceRelPath() SourceRelPath

SourceRelPath returns s's source relative path.

func (*SourceStateRemove) TargetStateEntry

func (s *SourceStateRemove) TargetStateEntry(
	destSystem System,
	destDirAbsPath AbsPath,
) (TargetStateEntry, error)

TargetStateEntry returns s's target state entry.

type System

type System interface {
	Chmod(name AbsPath, mode fs.FileMode) error
	Chtimes(name AbsPath, atime, mtime time.Time) error
	Glob(pattern string) ([]string, error)
	Link(oldname, newname AbsPath) error
	Lstat(filename AbsPath) (fs.FileInfo, error)
	Mkdir(name AbsPath, perm fs.FileMode) error
	RawPath(absPath AbsPath) (AbsPath, error)
	ReadDir(name AbsPath) ([]fs.DirEntry, error)
	ReadFile(name AbsPath) ([]byte, error)
	Readlink(name AbsPath) (string, error)
	Remove(name AbsPath) error
	RemoveAll(name AbsPath) error
	Rename(oldpath, newpath AbsPath) error
	RunCmd(cmd *exec.Cmd) error
	RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error
	Stat(name AbsPath) (fs.FileInfo, error)
	UnderlyingFS() vfs.FS
	UnderlyingSystem() System
	WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error
	WriteSymlink(oldname string, newname AbsPath) error
}

A System reads from and writes to a filesystem, runs scripts, and persists state.

type TarWriterSystem

type TarWriterSystem struct {
	// contains filtered or unexported fields
}

A TarWriterSystem is a System that writes to a tar archive.

func NewTarWriterSystem

func NewTarWriterSystem(w io.Writer, headerTemplate tar.Header) *TarWriterSystem

NewTarWriterSystem returns a new TarWriterSystem that writes a tar file to w.

func (TarWriterSystem) Chmod

func (TarWriterSystem) Chmod(name AbsPath, perm fs.FileMode) error

func (TarWriterSystem) Chtimes added in v2.24.0

func (TarWriterSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (*TarWriterSystem) Close

func (s *TarWriterSystem) Close() error

Close closes m.

func (TarWriterSystem) Glob

func (TarWriterSystem) Glob(pattern string) ([]string, error)
func (TarWriterSystem) Link(oldname, newname AbsPath) error

func (TarWriterSystem) Lstat

func (TarWriterSystem) Lstat(name AbsPath) (fs.FileInfo, error)

func (*TarWriterSystem) Mkdir

func (s *TarWriterSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (TarWriterSystem) RawPath

func (TarWriterSystem) RawPath(path AbsPath) (AbsPath, error)

func (TarWriterSystem) ReadDir

func (TarWriterSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

func (TarWriterSystem) ReadFile

func (TarWriterSystem) ReadFile(name AbsPath) ([]byte, error)
func (TarWriterSystem) Readlink(name AbsPath) (string, error)

func (TarWriterSystem) Remove

func (TarWriterSystem) Remove(name AbsPath) error

func (TarWriterSystem) RemoveAll

func (TarWriterSystem) RemoveAll(name AbsPath) error

func (TarWriterSystem) Rename

func (TarWriterSystem) Rename(oldpath, newpath AbsPath) error

func (*TarWriterSystem) RunCmd

func (s *TarWriterSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*TarWriterSystem) RunScript

func (s *TarWriterSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (TarWriterSystem) Stat

func (TarWriterSystem) Stat(name AbsPath) (fs.FileInfo, error)

func (TarWriterSystem) UnderlyingFS

func (TarWriterSystem) UnderlyingFS() vfs.FS

func (*TarWriterSystem) UnderlyingSystem added in v2.34.0

func (s *TarWriterSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*TarWriterSystem) WriteFile

func (s *TarWriterSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *TarWriterSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

type TargetStateDir

type TargetStateDir struct {
	// contains filtered or unexported fields
}

A TargetStateDir represents the state of a directory in the target state.

func (*TargetStateDir) Apply

func (t *TargetStateDir) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply updates actualStateEntry to match t. It does not recurse.

func (*TargetStateDir) EntryState

func (t *TargetStateDir) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateDir) Evaluate

func (t *TargetStateDir) Evaluate() error

Evaluate evaluates t.

func (*TargetStateDir) SkipApply

func (t *TargetStateDir) SkipApply(
	persistentState PersistentState,
	targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetState.SkipApply.

func (*TargetStateDir) SourceAttr added in v2.26.0

func (t *TargetStateDir) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type TargetStateEntry

type TargetStateEntry interface {
	Apply(
		system System,
		persistentState PersistentState,
		actualStateEntry ActualStateEntry,
	) (bool, error)
	EntryState(umask fs.FileMode) (*EntryState, error)
	Evaluate() error
	SkipApply(persistentState PersistentState, targetAbsPath AbsPath) (bool, error)
	SourceAttr() SourceAttr
}

A TargetStateEntry represents the state of an entry in the target state.

type TargetStateFile

type TargetStateFile struct {
	// contains filtered or unexported fields
}

A TargetStateFile represents the state of a file in the target state.

func (*TargetStateFile) Apply

func (t *TargetStateFile) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply updates actualStateEntry to match t.

func (TargetStateFile) Contents

func (lc TargetStateFile) Contents() ([]byte, error)

Contents returns lc's contents.

func (TargetStateFile) ContentsSHA256

func (lc TargetStateFile) ContentsSHA256() ([]byte, error)

ContentsSHA256 returns the SHA256 sum of lc's contents.

func (*TargetStateFile) EntryState

func (t *TargetStateFile) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateFile) Evaluate

func (t *TargetStateFile) Evaluate() error

Evaluate evaluates t.

func (*TargetStateFile) Perm

func (t *TargetStateFile) Perm(umask fs.FileMode) fs.FileMode

Perm returns t's perm.

func (*TargetStateFile) SkipApply

func (t *TargetStateFile) SkipApply(
	persistentState PersistentState,
	targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetStateEntry.SkipApply.

func (*TargetStateFile) SourceAttr added in v2.26.0

func (t *TargetStateFile) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type TargetStateModifyDirWithCmd added in v2.13.0

type TargetStateModifyDirWithCmd struct {
	// contains filtered or unexported fields
}

A TargetStateModifyDirWithCmd represents running a command that modifies a directory.

func (*TargetStateModifyDirWithCmd) Apply added in v2.13.0

func (t *TargetStateModifyDirWithCmd) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply updates actualStateEntry to match t.

func (*TargetStateModifyDirWithCmd) EntryState added in v2.13.0

func (t *TargetStateModifyDirWithCmd) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateModifyDirWithCmd) Evaluate added in v2.13.0

func (t *TargetStateModifyDirWithCmd) Evaluate() error

Evaluate evaluates t.

func (*TargetStateModifyDirWithCmd) SkipApply added in v2.13.0

func (t *TargetStateModifyDirWithCmd) SkipApply(
	persistentState PersistentState,
	targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetStateEntry.SkipApply.

func (*TargetStateModifyDirWithCmd) SourceAttr added in v2.26.0

func (t *TargetStateModifyDirWithCmd) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type TargetStateRemove

type TargetStateRemove struct{}

A TargetStateRemove represents the absence of an entry in the target state.

func (*TargetStateRemove) Apply

func (t *TargetStateRemove) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply updates actualStateEntry to match t.

func (*TargetStateRemove) EntryState

func (t *TargetStateRemove) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateRemove) Evaluate

func (t *TargetStateRemove) Evaluate() error

Evaluate evaluates t.

func (*TargetStateRemove) SkipApply

func (t *TargetStateRemove) SkipApply(
	persistentState PersistentState,
	targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetStateEntry.SkipApply.

func (*TargetStateRemove) SourceAttr added in v2.26.0

func (t *TargetStateRemove) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type TargetStateScript

type TargetStateScript struct {
	// contains filtered or unexported fields
}

A TargetStateScript represents the state of a script.

func (*TargetStateScript) Apply

func (t *TargetStateScript) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply runs t.

func (TargetStateScript) Contents

func (lc TargetStateScript) Contents() ([]byte, error)

Contents returns lc's contents.

func (TargetStateScript) ContentsSHA256

func (lc TargetStateScript) ContentsSHA256() ([]byte, error)

ContentsSHA256 returns the SHA256 sum of lc's contents.

func (*TargetStateScript) EntryState

func (t *TargetStateScript) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateScript) Evaluate

func (t *TargetStateScript) Evaluate() error

Evaluate evaluates t.

func (*TargetStateScript) SkipApply

func (t *TargetStateScript) SkipApply(
	persistentState PersistentState,
	targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetStateEntry.SkipApply.

func (*TargetStateScript) SourceAttr added in v2.26.0

func (t *TargetStateScript) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type TargetStateSymlink struct {
	// contains filtered or unexported fields
}

A TargetStateSymlink represents the state of a symlink in the target state.

func (*TargetStateSymlink) Apply

func (t *TargetStateSymlink) Apply(
	system System, persistentState PersistentState, actualStateEntry ActualStateEntry,
) (bool, error)

Apply updates actualStateEntry to match t.

func (*TargetStateSymlink) EntryState

func (t *TargetStateSymlink) EntryState(umask fs.FileMode) (*EntryState, error)

EntryState returns t's entry state.

func (*TargetStateSymlink) Evaluate

func (t *TargetStateSymlink) Evaluate() error

Evaluate evaluates t.

func (TargetStateSymlink) Linkname

func (ll TargetStateSymlink) Linkname() (string, error)

Linkname returns s's linkname.

func (TargetStateSymlink) LinknameSHA256

func (ll TargetStateSymlink) LinknameSHA256() ([]byte, error)

LinknameSHA256 returns the SHA256 sum of ll's linkname.

func (*TargetStateSymlink) SkipApply

func (t *TargetStateSymlink) SkipApply(
	persistentState PersistentState, targetAbsPath AbsPath,
) (bool, error)

SkipApply implements TargetStateEntry.SkipApply.

func (*TargetStateSymlink) SourceAttr added in v2.26.0

func (t *TargetStateSymlink) SourceAttr() SourceAttr

SourceAttr implements TargetStateEntry.SourceAttr.

type Template added in v2.27.0

type Template struct {
	// contains filtered or unexported fields
}

A Template extends text/template.Template with support for directives.

func ParseTemplate added in v2.26.0

func ParseTemplate(
	name string,
	data []byte,
	funcs template.FuncMap,
	options TemplateOptions,
) (*Template, error)

ParseTemplate parses a template named name from data with the given funcs and templateOptions.

func (*Template) AddParseTree added in v2.27.0

func (t *Template) AddParseTree(tmpl *Template) (*Template, error)

AddParseTree adds tmpl's parse tree to t.

func (*Template) Execute added in v2.27.0

func (t *Template) Execute(data any) ([]byte, error)

Execute executes t with data.

type TemplateOptions added in v2.26.0

type TemplateOptions struct {
	LeftDelimiter  string
	LineEnding     string
	RightDelimiter string
	Options        []string
}

TemplateOptions are template options that can be set with directives.

type TextConvFunc added in v2.17.2

type TextConvFunc func(string, []byte) ([]byte, error)

A TextConvFunc converts the contents of a file into a more human-readable form.

type TooOldError

type TooOldError struct {
	Have semver.Version
	Need semver.Version
}

A TooOldError is returned when the source state requires a newer version of chezmoi.

func (*TooOldError) Error

func (e *TooOldError) Error() string

type UnknownArchiveFormatError added in v2.23.0

type UnknownArchiveFormatError string

func (UnknownArchiveFormatError) Error added in v2.23.0

type WalkArchiveFunc

type WalkArchiveFunc func(name string, info fs.FileInfo, r io.Reader, linkname string) error

An WalkArchiveFunc is called once for each entry in an archive.

type WalkFunc

type WalkFunc func(absPath AbsPath, fileInfo fs.FileInfo, err error) error

A WalkFunc is called for every entry in a directory.

type ZIPWriterSystem

type ZIPWriterSystem struct {
	// contains filtered or unexported fields
}

A ZIPWriterSystem is a System that writes to a ZIP archive.

func NewZIPWriterSystem

func NewZIPWriterSystem(w io.Writer, modified time.Time) *ZIPWriterSystem

NewZIPWriterSystem returns a new ZIPWriterSystem that writes a ZIP archive to w.

func (ZIPWriterSystem) Chmod

func (ZIPWriterSystem) Chmod(name AbsPath, perm fs.FileMode) error

func (ZIPWriterSystem) Chtimes added in v2.24.0

func (ZIPWriterSystem) Chtimes(name AbsPath, atime, mtime time.Time) error

func (*ZIPWriterSystem) Close

func (s *ZIPWriterSystem) Close() error

Close closes m.

func (ZIPWriterSystem) Glob

func (ZIPWriterSystem) Glob(pattern string) ([]string, error)
func (ZIPWriterSystem) Link(oldname, newname AbsPath) error

func (ZIPWriterSystem) Lstat

func (ZIPWriterSystem) Lstat(name AbsPath) (fs.FileInfo, error)

func (*ZIPWriterSystem) Mkdir

func (s *ZIPWriterSystem) Mkdir(name AbsPath, perm fs.FileMode) error

Mkdir implements System.Mkdir.

func (ZIPWriterSystem) RawPath

func (ZIPWriterSystem) RawPath(path AbsPath) (AbsPath, error)

func (ZIPWriterSystem) ReadDir

func (ZIPWriterSystem) ReadDir(name AbsPath) ([]fs.DirEntry, error)

func (ZIPWriterSystem) ReadFile

func (ZIPWriterSystem) ReadFile(name AbsPath) ([]byte, error)
func (ZIPWriterSystem) Readlink(name AbsPath) (string, error)

func (ZIPWriterSystem) Remove

func (ZIPWriterSystem) Remove(name AbsPath) error

func (ZIPWriterSystem) RemoveAll

func (ZIPWriterSystem) RemoveAll(name AbsPath) error

func (ZIPWriterSystem) Rename

func (ZIPWriterSystem) Rename(oldpath, newpath AbsPath) error

func (*ZIPWriterSystem) RunCmd

func (s *ZIPWriterSystem) RunCmd(cmd *exec.Cmd) error

RunCmd implements System.RunCmd.

func (*ZIPWriterSystem) RunScript

func (s *ZIPWriterSystem) RunScript(
	scriptname RelPath,
	dir AbsPath,
	data []byte,
	options RunScriptOptions,
) error

RunScript implements System.RunScript.

func (ZIPWriterSystem) Stat

func (ZIPWriterSystem) Stat(name AbsPath) (fs.FileInfo, error)

func (ZIPWriterSystem) UnderlyingFS

func (ZIPWriterSystem) UnderlyingFS() vfs.FS

func (*ZIPWriterSystem) UnderlyingSystem added in v2.34.0

func (s *ZIPWriterSystem) UnderlyingSystem() System

UnderlyingSystem implements System.UnderlyingSystem.

func (*ZIPWriterSystem) WriteFile

func (s *ZIPWriterSystem) WriteFile(filename AbsPath, data []byte, perm fs.FileMode) error

WriteFile implements System.WriteFile.

func (s *ZIPWriterSystem) WriteSymlink(oldname string, newname AbsPath) error

WriteSymlink implements System.WriteSymlink.

Jump to

Keyboard shortcuts

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