files

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2015 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanRepo

func ScanRepo() common.Entities

ScanRepo returns a slice of all the TargetFile entities.

Types

type ApplyImpl

type ApplyImpl func(*FileBuffer, *shared.Report) (*FileBuffer, error)

ApplyImpl is the return type for GetApplyImpl.

func GetApplyImpl

func GetApplyImpl(repoFile RepoFile) ApplyImpl

GetApplyImpl returns a function that applies the given RepoFile to a file buffer, as part of the `holo apply` algorithm.

type FileBuffer

type FileBuffer struct {
	//set only for regular files
	Contents []byte
	//set only for symlinks
	SymlinkTarget string
	//used by ResolveSymlink (see doc over there)
	BasePath string
}

FileBuffer represents the contents of a file. It is used in holo.Apply() as an intermediary product of application steps.

func NewFileBuffer

func NewFileBuffer(path string, basePath string) (*FileBuffer, error)

NewFileBuffer creates a FileBuffer object by reading the manageable file at the given path. The basePath is stored in the FileBuffer for use in holo.FileBuffer.ResolveSymlink().

func NewFileBufferFromContents

func NewFileBufferFromContents(fileContents []byte, basePath string) *FileBuffer

NewFileBufferFromContents creates a file buffer containing the given byte array. The basePath is stored in the FileBuffer for use in holo.FileBuffer.ResolveSymlink().

func (*FileBuffer) EqualTo

func (fb *FileBuffer) EqualTo(other *FileBuffer) bool

EqualTo returns whether two file buffers have the same content (or link target).

func (fb *FileBuffer) ResolveSymlink() (*FileBuffer, error)

ResolveSymlink takes a FileBuffer that contains a symlink, resolves it and returns a new FileBuffer containing the contents of the symlink target. This operation is used by application strategies that require text input. If the given FileBuffer contains file contents, the same buffer is returned unaltered.

It uses the FileBuffer's BasePath to resolve relative symlinks. Since file buffers are usually written to the target path of a `holo apply` operation, the BasePath is most likely the target path.

func (*FileBuffer) Write

func (fb *FileBuffer) Write(path string) error

type RepoFile

type RepoFile string

RepoFile represents a single file in the configuration repository. The string stored in it is the path to the repo file (also accessible as Path()).

func NewRepoFile

func NewRepoFile(path string) RepoFile

NewRepoFile creates a RepoFile instance when its path in the file system is known.

func (RepoFile) ApplicationStrategy

func (file RepoFile) ApplicationStrategy() string

ApplicationStrategy returns the human-readable name for the strategy that will be employed to apply this repo file.

func (RepoFile) Path

func (file RepoFile) Path() string

Path returns the path to this repo file in the file system.

func (RepoFile) TargetPath

func (file RepoFile) TargetPath() string

TargetPath returns the path to the corresponding target file.

type RepoFiles

type RepoFiles []RepoFile

RepoFiles holds a slice of RepoFile instances, and implements some methods to satisfy the sort.Interface interface.

func (RepoFiles) Len

func (f RepoFiles) Len() int

func (RepoFiles) Less

func (f RepoFiles) Less(i, j int) bool

func (RepoFiles) Swap

func (f RepoFiles) Swap(i, j int)

type TargetFile

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

TargetFile represents a configuration file that can be provisioned by Holo.

func NewTargetFileFromPathIn

func NewTargetFileFromPathIn(directory, path string) *TargetFile

NewTargetFileFromPathIn creates a TargetFile instance for which a path relative to a known location is known.

target := NewTargetFileFromPathIn(common.TargetDirectory(), targetPath)
target := NewTargetFileFromPathIn(common.ProvisionedDirectory(), provisionedPath)

func (*TargetFile) AddRepoEntry

func (target *TargetFile) AddRepoEntry(entry RepoFile)

AddRepoEntry registers a new repository entry in this TargetFile instance.

func (*TargetFile) Apply

func (target *TargetFile) Apply(withForce bool)

Apply implements the common.Entity interface.

func (*TargetFile) EntityID

func (target *TargetFile) EntityID() string

EntityID implements the common.Entity interface.

func (*TargetFile) PathIn

func (target *TargetFile) PathIn(directory string) string

PathIn returns the path to this target file relative to the given directory.

targetPath := target.pathIn(common.TargetDirectory())           // e.g. "/etc/foo.conf"
targetBasePath := target.pathIn(common.TargetBaseDirectory())   // e.g. "/var/lib/holo/base/etc/foo.conf"
provisionedPath := target.pathIn(common.ProvisionedDirectory()) // e.g. "/var/lib/holo/provisioned/etc/foo.conf"

func (*TargetFile) RenderDiff

func (target *TargetFile) RenderDiff() ([]byte, error)

RenderDiff creates a unified diff of a target file and its last provisioned version, similar to `diff /var/lib/holo/provisioned/$FILE $FILE`, but it also handles symlinks and missing files gracefully. The output is always a patch that can be applied to last provisioned version into the current version.

func (*TargetFile) RepoEntries

func (target *TargetFile) RepoEntries() RepoFiles

RepoEntries returns an ordered list of all repository entries for this TargetFile.

func (*TargetFile) Report

func (target *TargetFile) Report() *shared.Report

Report implements the common.Entity interface.

Jump to

Keyboard shortcuts

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