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 ¶
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 ¶
ParseFile parses a `File` object from its encoded form.
The input string must match the form returned by the `File.String` method.
func (*File) Permissions ¶
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).
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash represents a hash/fingerprint of a blob.
func NewHash ¶
NewHash constructs a new hash by calculating the checksum of the provided reader.
The caller is responsible for closing the reader.
func (*Hash) HexContents ¶
HexContents returns the hash value serialized as a hexadecimal string.
type Identity ¶
type Identity struct {
// contains filtered or unexported fields
}
Identity represents an identity that can sign a hash.
func ParseIdentity ¶
ParseIdentity parses the string encoding of an identity.
func (*Identity) Algorithm ¶
Algorithm returns the name of the signing algorithm used (e.g. `ed25519`, etc).
type Path ¶
type Path string
Path represents the filesystem path of a file.
This can be either an absolute or relative 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 ¶
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.