merkletree

package
v0.0.0-...-f4b31ea Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package merkletree operates on a merkle tree for remote execution API.

You can find the Tree proto in REAPI here: https://github.com/bazelbuild/remote-apis/blob/c1c1ad2c97ed18943adb55f06657440daa60d833/build/bazel/remote/execution/v2/remote_execution.proto#L838 See also https://en.Wikipedia.org/wiki/Merkle_tree for general explanations about Merkle tree.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAbsPath indicates name in Entry is absolute 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")

	// ErrBadTree indicates TreeEntry has bad digest.
	ErrBadTree = errors.New("merkletree: bad tree")

	// ErrPrecomputedSubTree indicates to set an entry in precomputed subtree, but we can't change anything under the subtree because it used precomputed digest.
	ErrPrecomputedSubTree = errors.New("merkletree: set in precomputed subtree")
)

Functions

func Traverse

func Traverse(ctx context.Context, base string, dir *rpb.Directory, ds *digest.Store) ([]*rpb.OutputFile, []*rpb.OutputSymlink, []*rpb.OutputDirectory)

Traverse traverses a directory recursively, and returns the found files, symlinks and directories. The base directory name is prepended to each path of the entries. The directories not registered in the digest.Store will be ignored.

Types

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.

func (Entry) IsDir

func (e Entry) IsDir() bool

IsDir returns true when the entry is a directory.

func (e Entry) IsSymlink() bool

IsSymlink returns true when the entry is a symlink.

type MerkleTree

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

MerkleTree represents a merkle tree.

func New

func New(store *digest.Store) *MerkleTree

New creates new merkle tree with digest store.

func (*MerkleTree) Build

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

Build builds merkle tree and returns root's digest.

func (*MerkleTree) Directories

func (m *MerkleTree) Directories() []*rpb.Directory

Directories returns directories in the merkle tree.

func (*MerkleTree) RootDirectory

func (m *MerkleTree) RootDirectory() *rpb.Directory

RootDirectory returns root directory in the merkle tree.

func (*MerkleTree) Set

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

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

func (*MerkleTree) SetTree

func (m *MerkleTree) SetTree(tentry TreeEntry) error

SetTree sets a subtree entry. It may return ErrAbsPath/ErrBadPath/ErrBadTree as error.

type TreeEntry

type TreeEntry struct {
	// Name is relative path from root dir.
	// Name should not end with "." or "..".
	Name string

	// Digest is the digest of this sub tree.
	Digest digest.Digest

	// Store is the digest store used to build the subtree.
	// It may be nil, if it is sure that the subtree was uploaded
	// to CAS and no need to check missing blobs / upload blobs
	// of the subtree.
	Store *digest.Store
}

TreeEntry is a precomputed subtree entry in the tree. When using the same sets in a directory many times, we can precompute digest for the subtree to reduce computation cost and memory cost.

Directories

Path Synopsis
Package exporter is an exporter of directory tree from RBE-CAS.
Package exporter is an exporter of directory tree from RBE-CAS.
Package importer is an importer of directory tree into RBE-CAS.
Package importer is an importer of directory tree into RBE-CAS.

Jump to

Keyboard shortcuts

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