Back to godoc.org

Package merkletree

v0.0.15
Latest Go to latest

The latest major version is .

Published: Jul 31, 2020 | License: BSD-3-Clause | Module: go.chromium.org/goma/server

Overview

Package merkletree operates on a merkle tree for remote execution API, https://github.com/bazelbuild/remote-apis/blob/c1c1ad2c97ed18943adb55f06657440daa60d833/build/bazel/remote/execution/v2/remote_execution.proto#L838

see https://en.Wikipedia.org/wiki/Merkle_tree

Index

Variables

var (
	// ErrAbsPath indicates name in Entry is absulute path.
	ErrAbsPath = errors.New("merkletree: absolute path name")

	// ErrAmbigFileSymlink indicates Entry has both `Data` and `Target` fields, cannot determine
	// whether it is File or Symlink.
	ErrAmbigFileSymlink = errors.New("merkletree: unable to determine file vs symlink")

	// ErrBadPath indicates name in Entry contains bad path component
	// e.g. "." or "..".
	ErrBadPath = errors.New("merkletree: bad path component")
)

type Entry

type Entry struct {
	// Name is relative path from root dir.
	// it might not be clean path.
	// 'dir1/../dir2/file' will create
	//  - 'dir1/'
	//  - 'dir2/'
	//  - 'dir2/file'
	// error if name goes out to root.
	Name string

	// Data is entry's content. `nil` for directories and symlinks.
	Data digest.Data

	// IsExecutable is true if the file is executable.
	// no need to set this for directory.
	IsExecutable bool

	// If the file is a symlink, then this should be set to the target of the symlink.
	Target string
}

Entry is an entry in the tree.

type FilePath

type FilePath interface {
	IsAbs(path string) bool
	Join(elem ...string) string
	SplitElem(path string) []string
}

FilePath provides filepath functionalities.

type MerkleTree

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

MerkleTree represents a merkle tree.

func New

func New(filepath FilePath, rootDir string, store *digest.Store) *MerkleTree

New creates new merkle tree under rootDir with cas store.

func (*MerkleTree) Build

func (m *MerkleTree) Build(ctx context.Context) (*rpb.Digest, error)

Build builds merkle tree and returns root's digest.

func (*MerkleTree) RootDir

func (m *MerkleTree) RootDir() string

RootDir returns root dir of merkle tree.

func (*MerkleTree) Set

func (m *MerkleTree) Set(entry Entry) error

Set sets an entry. It may return ErrAbsPath/ErrAmbigFileSymlink/ErrBadPath as error.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier