Version: v0.0.26 Latest Latest

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

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0



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




This section is empty.


View Source
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")


This section is empty.


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.

Jump to

Keyboard shortcuts

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