volume

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package volume provides bounded snapshot and restore mechanics for a caller-selected local volume or directory. Identity, authorization, retention, and transport policy belong to the caller.

Package volume provides bounded snapshot and restore mechanics for a caller-selected local volume or directory. Identity, authorization, retention, and transport policy belong to the caller.

Index

Constants

View Source
const (
	// DefaultMaxEntries bounds the files and directories removal may traverse.
	DefaultMaxEntries = 10_000
	// MaxEntries is the library ceiling for MaxEntries.
	MaxEntries = 1_000_000
	// DefaultMaxBytes bounds the content bytes removal may traverse.
	DefaultMaxBytes int64 = 1 << 30
	// MaxBytes is the library ceiling for MaxBytes.
	MaxBytes int64 = 1 << 40
	// DefaultMaxDepth bounds the number of directory components a path may add.
	DefaultMaxDepth = 32
	// MaxDepth is the library ceiling for MaxDepth.
	MaxDepth = 128
)

Variables

View Source
var (
	// ErrUnsafePath reports a link, reparse point, non-directory, or broad
	// target the caller did not intend to create or delete.
	ErrUnsafePath = errors.New("unsafe private volume path")
	// ErrStale reports a volume whose native identity no longer matches the
	// inspected directory.
	ErrStale = errors.New("private volume identity changed")
	// ErrLimit reports content beyond a caller-selected creation or removal
	// bound.
	ErrLimit = errors.New("private volume limit exceeded")
	// ErrInvalid reports a malformed path or volume value.
	ErrInvalid = errors.New("invalid private volume")
)

Functions

func Export

func Export(ctx context.Context, output io.Writer, root string) error

Export writes a gzip-compressed tar archive containing regular files and directories below root. It refuses symlinks and special files so a snapshot cannot unexpectedly escape onto another host surface.

func ExportRoot

func ExportRoot(ctx context.Context, output io.Writer, root *os.Root) error

ExportRoot exports from a pinned directory handle so concurrent renames cannot redirect traversal outside the selected root.

func FileDigest

func FileDigest(path string) (int64, string, error)

FileDigest returns an archive's byte size and SHA-256 digest.

func RemovePrivate

func RemovePrivate(ctx context.Context, volume PrivateVolume, limits PrivateLimits) error

RemovePrivate removes exactly the inspected directory after revalidating its native identity and bounded contents. It refuses links, reparse points, broad targets, and a directory replaced since inspection. The caller supplies the traversal bounds and authorizes deletion; the library does neither.

func Restore

func Restore(ctx context.Context, archivePath, destination string) error

Restore restores an archive into an empty destination with conservative default extraction limits.

func RestoreRootWithLimits

func RestoreRootWithLimits(ctx context.Context, archivePath string, destination *os.Root, limits Limits) error

RestoreRootWithLimits restores into a pinned empty directory.

func RestoreWithLimits

func RestoreWithLimits(ctx context.Context, archivePath, destination string, limits Limits) error

RestoreWithLimits stages extraction inside the empty destination and moves the validated top-level entries into place only after extraction succeeds.

Types

type Limits

type Limits struct {
	Bytes   int64
	Entries int
}

Limits bounds decompressed archive contents during restore.

type PrivateLimits

type PrivateLimits struct {
	MaxEntries int
	MaxBytes   int64
	MaxDepth   int
}

PrivateLimits bound creation and removal. Zero values select the defaults.

type PrivateVolume

type PrivateVolume struct {
	Path     string
	Identity string
	Created  bool
	Entries  int
	Bytes    int64
	// contains filtered or unexported fields
}

PrivateVolume is an inspected, caller-selected private directory. Identity is an opaque digest for reporting; native same-file checks pin the handle. A PrivateVolume is only usable for removal when produced by InspectPrivate or CreatePrivate.

func CreatePrivate

func CreatePrivate(ctx context.Context, path string, limits PrivateLimits) (PrivateVolume, error)

CreatePrivate creates a caller-selected private directory with 0700 permissions and missing parents. The library never selects the path and never authorizes deletion; the caller does both.

func InspectPrivate

func InspectPrivate(ctx context.Context, path string, limits PrivateLimits) (PrivateVolume, error)

InspectPrivate validates and counts an existing private directory without following links. It refuses a directory readable or writable by another user.

Jump to

Keyboard shortcuts

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