Help us shape the future of Go! Take the 2026 Go Developer Survey

layer

package
v0.57.29 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package layer builds UnixFS layers from file entries and lays layers onto a root by reference.

Every node a layer writes has the same modification time, so identical content always encodes to identical blocks, and a merge reuses each node it does not change.

Index

Constants

This section is empty.

Variables

View Source
var BaseEntries = []*Entry{
	{Path: "dev", Type: fs.ModeDir, Perm: 0o755},
	{Path: "etc", Type: fs.ModeDir, Perm: 0o755},
	{Path: "proc", Type: fs.ModeDir, Perm: 0o555},
	{Path: "tmp", Type: fs.ModeDir, Perm: 0o777},
	{Path: "usr/bin", Type: fs.ModeDir, Perm: 0o755},
	{Path: "usr/lib", Type: fs.ModeDir, Perm: 0o755},
	{Path: "usr/sbin", Type: fs.ModeDir, Perm: 0o755},
	{Path: "var", Type: fs.ModeDir, Perm: 0o755},
	{Path: "bin", Type: fs.ModeSymlink, Target: "usr/bin"},
	{Path: "lib", Type: fs.ModeSymlink, Target: "usr/lib"},
	{Path: "sbin", Type: fs.ModeSymlink, Target: "usr/sbin"},
}

BaseEntries is the layer every root starts from: the top-level directories and the links that merge /bin, /lib and /sbin into /usr.

Functions

func BuildTree

func BuildTree(ctx context.Context, bls *bucket_lookup.Cursor, entries []*Entry) (*block.BlockRef, error)

BuildTree writes a new UnixFS tree holding the entries, applied in order, through bls and returns its root reference.

func MergeLayers

func MergeLayers(
	ctx context.Context,
	bls *bucket_lookup.Cursor,
	base *block.BlockRef,
	layers []*block.BlockRef,
	collide func(path string),
) (*block.BlockRef, error)

MergeLayers lays each layer onto base in order through bls and returns the merged root. base may be nil for an empty root. Directories present in both trees merge entry by entry; any other node in a later layer replaces the earlier one. Every node the merge does not change keeps its reference, so the merge writes only the directories along the paths where layers meet. collide is called with the path of each node a layer replaces with different content.

Types

type Entry

type Entry struct {
	// Path is the slash-separated path relative to the root, without a
	// leading slash.
	Path string
	// Type is fs.ModeDir, fs.ModeSymlink or 0 for a regular file.
	Type fs.FileMode
	// Perm holds the permission bits.
	Perm fs.FileMode
	// Data is the content of a regular file.
	Data []byte
	// Target is the destination of a symlink.
	Target string
}

Entry is one file, directory or symlink of a layer.

Jump to

Keyboard shortcuts

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