tree

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tree defines directory tree structures for snapshot metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(t *Tree) ([]byte, error)

Marshal serializes a tree to JSON.

Types

type Node

type Node struct {
	Name          string            `json:"name"`
	Type          NodeType          `json:"type"`
	Mode          os.FileMode       `json:"mode"`
	Size          int64             `json:"size,omitempty"`
	UID           uint32            `json:"uid"`
	GID           uint32            `json:"gid"`
	User          string            `json:"user,omitempty"`
	Group         string            `json:"group,omitempty"`
	ModTime       time.Time         `json:"mtime"`
	AccessTime    time.Time         `json:"atime,omitempty"`
	ChangeTime    time.Time         `json:"ctime,omitempty"`
	Xattrs        map[string][]byte `json:"xattrs,omitempty"`
	SymlinkTarget string            `json:"symlink_target,omitempty"`
	DevMajor      uint32            `json:"dev_major,omitempty"`
	DevMinor      uint32            `json:"dev_minor,omitempty"`
	Inode         uint64            `json:"inode,omitempty"`
	Links         uint64            `json:"links,omitempty"`

	// For files: ordered list of content blob IDs
	Content []types.BlobID `json:"content,omitempty"`

	// For directories: the blob ID of the child tree
	Subtree types.BlobID `json:"subtree,omitempty"`
}

Node represents a single filesystem entry within a tree.

type NodeType

type NodeType string

NodeType identifies the type of a filesystem entry.

const (
	NodeTypeFile    NodeType = "file"
	NodeTypeDir     NodeType = "dir"
	NodeTypeSymlink NodeType = "symlink"
	NodeTypeDev     NodeType = "dev"    // device node (metadata only)
	NodeTypeFIFO    NodeType = "fifo"   // named pipe (metadata only)
	NodeTypeSocket  NodeType = "socket" // socket (metadata only)
)

type Tree

type Tree struct {
	Nodes []Node `json:"nodes"`
}

Tree is an ordered list of nodes within a single directory.

func Unmarshal

func Unmarshal(data []byte) (*Tree, error)

Unmarshal deserializes a tree from JSON.

func (*Tree) Find

func (t *Tree) Find(name string) *Node

Find returns the node with the given name, or nil if not found. Uses binary search since nodes are sorted by name during backup. Falls back to linear scan if the slice is unsorted (defensive).

Jump to

Keyboard shortcuts

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