snapshot

package
v0.0.0-...-094e3b7 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package snapshot defines the model for snapshots of a file's history.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current

func Current(ctx context.Context, s Storage, p Path) (*Hash, *File, error)

Current generates a snapshot for the given path, stored in the given store.

The passed in path must be an absolute path.

The returned value is the hash of the generated `snapshot.File` object.

Types

type File

type File struct {
	// Mode is the string representation of a Posix-style file mode.
	//
	// It should be of the form [<FILE_TYPE>]+<FILE_PERMISSIONS>.
	//
	// <FILE_TYPE> is a single character indicating the type of the
	// file, such as `d` for a directory or `L` for a symbolic link, etc.
	//
	// <FILE_PERMISSIONS> is a sequence of 9 characters representing the
	// Unix permission bits.
	Mode string

	// Contents is the hash of the contents for the snapshotted file.
	//
	// If the file is a directory (the mode line starts with `d`), then
	// this will be the hash of a `Tree` object.
	//
	// If the file is a symbolic link (the mode line starts with a `L`),
	// then this will be the hash of another `File` object, unless the
	// link is broken in which case the contents will be nil.
	//
	// In all other cases, the contents is a hash of the sequence of
	// bytes read from the file.
	Contents *Hash

	// Parents stores the hashes for the previous snapshots that
	// immediately preceeded this one.
	Parents []*Hash
}

File is the top-level object in a snapshot.

File encodes the entire, transitive history of a file. If the file is a directory, then this history also includes the histories for all of the children of that directory.

func ParseFile

func ParseFile(encoded string) (*File, error)

ParseFile parses a `File` object from its encoded form.

The input string must match the form returned by the `File.String` method.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir reports whether or not the file is the snapshot of a directory.

func (f *File) IsLink() bool

IsLink reports whether or not the file is the snapshot of a symbolic link.

func (*File) Permissions

func (f *File) Permissions() os.FileMode

Permissions returns the permission subset of the file mode.

The returned `os.FileMode` object does not include any information on the file type (e.g. directory vs. link, etc).

func (*File) String

func (f *File) String() string

String implements the `fmt.Stringer` interface.

The resulting value is suitable for serialization.

type Hash

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

Hash represents a hash/fingerprint of a blob.

func NewHash

func NewHash(reader io.Reader) (*Hash, error)

NewHash constructs a new hash by calculating the checksum of the provided reader.

The caller is responsible for closing the reader.

func ParseHash

func ParseHash(str string) (*Hash, error)

ParseHash parses the string encoding of a hash.

func (*Hash) Equal

func (h *Hash) Equal(other *Hash) bool

Equal reports whether or not two hash objects are equal.

func (*Hash) Function

func (h *Hash) Function() string

Function returns the name of the hash function used (e.g. `sha256`, etc).

func (*Hash) HexContents

func (h *Hash) HexContents() string

HexContents returns the hash value serialized as a hexadecimal string.

func (*Hash) String

func (h *Hash) String() string

String implements the `fmt.Stringer` interface.

The resulting value is used when serializing objects holding a hash.

type Identity

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

Identity represents an identity that can sign a hash.

func ParseIdentity

func ParseIdentity(str string) (*Identity, error)

ParseIdentity parses the string encoding of an identity.

func (*Identity) Algorithm

func (h *Identity) Algorithm() string

Algorithm returns the name of the signing algorithm used (e.g. `ed25519`, etc).

func (*Identity) Contents

func (h *Identity) Contents() string

Contents returns the identity contents.

func (*Identity) Equal

func (h *Identity) Equal(other *Identity) bool

Equal reports whether or not two hash objects are equal.

func (*Identity) String

func (h *Identity) String() string

String implements the `fmt.Stringer` interface.

The resulting value is used when serializing objects holding a hash.

type Path

type Path string

Path represents the filesystem path of a file.

This can be either an absolute or relative path.

func (Path) Join

func (p Path) Join(child Path) Path

Join returns the path corresponding to joining this path with the supplied child path.

type Storage

type Storage interface {
	// StoreObject persists the contents of the given reader, returning the resulting hash of those contents.
	//
	// This is used for persistently storing the contents of individual files.
	StoreObject(context.Context, int64, io.Reader) (*Hash, error)

	// Exclude reports whether or not the given path should be excluded from storage.
	Exclude(Path) bool

	// FindSnapshot reads the latest snapshot (if any) for the given path.
	FindSnapshot(context.Context, Path) (*Hash, *File, error)

	// StoreSnapshot stores a mapping from the given path to the given snapshot.
	StoreSnapshot(context.Context, Path, *File) (*Hash, error)

	// CachePathInfo caches the file information for the given path.
	//
	// This is used to avoid rehashing the contents of files that have
	// not changed since the last time they were snapshotted.
	CachePathInfo(context.Context, Path, os.FileInfo) error

	// PathInfoMatchesCache reports whether or not the given file
	// information matches the file information that was previously cached
	// for the given path.
	PathInfoMatchesCache(context.Context, Path, os.FileInfo) bool
}

Storage defines persistent storage of snapshots.

type Tree

type Tree map[Path]*Hash

Tree represents the contents of a directory.

The keys are relative paths of the directory children, and the values are the hashes of each child's latest snapshot.

func ParseTree

func ParseTree(encoded string) (Tree, error)

ParseTree parses a `Tree` object from its encoded form.

The input string must match the form returned by the `Tree.String` method.

func (Tree) String

func (t Tree) String() string

String implements the `fmt.Stringer` interface.

The resulting value is suitable for serialization.

Jump to

Keyboard shortcuts

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