restore

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package restore writes decoded pxar archives to disk.

Extract restores a whole archive in one sequential pass over a pxar.Reader; ExtractPaths restores selected paths through a random-access pxar.FS. Both write through an os.Root, so no entry — whatever its name, symlink or hardlink target — can create or modify anything outside the target directory.

Metadata is applied best-effort through a MetadataWriter, the platform seam mirroring scan.MetadataReader: the Linux writer restores owners, permissions, xattrs, POSIX ACLs, file capabilities, device and fifo nodes and nanosecond mtimes; other platforms restore content, directories, symlinks and hardlinks where the system allows, permissions and mtimes. Whatever cannot be applied (ownership without privilege, a name invalid on Windows) is reported through Options.OnWarn and the restore goes on. Directory metadata is applied last, deepest first, so restoring a directory's content does not disturb its mtime or permissions.

Index

Constants

This section is empty.

Variables

View Source
var ErrTargetNotEmpty = errors.New("restore: target directory is not empty")

ErrTargetNotEmpty is returned for a target directory with content when Options.Overwrite is not set.

Functions

func Extract

func Extract(ctx context.Context, r *pxar.Reader, dir string, opts Options) error

Extract restores every entry r yields below dir, creating dir if needed. The archive root's own metadata is applied to dir.

func ExtractPaths

func ExtractPaths(ctx context.Context, fsys *pxar.FS, paths []string, dir string, opts Options) error

ExtractPaths restores the named archive paths, each with its subtree, below dir at their archive-relative location ("." is the whole archive). Parent directories of a path are created plain. Hardlinks are restored as copies, since the entry they link to may lie outside the selection.

Types

type MetadataWriter

type MetadataWriter interface {
	// Mknod creates a block or char device, fifo or socket.
	Mknod(root *os.Root, name string, n *pxar.Node) error
	// Apply sets n's owner, permissions, xattrs, ACLs, file capabilities and
	// mtime on the existing entry name, reporting each failure to warn.
	Apply(root *os.Root, name string, n *pxar.Node, warn func(error))
}

MetadataWriter is the platform seam: it creates special files and applies an entry's metadata. Names are slash-separated paths relative to root; "." is root itself. Neither method may follow a final symlink.

func DefaultWriter

func DefaultWriter() MetadataWriter

DefaultWriter returns the platform MetadataWriter.

type Options

type Options struct {
	// Overwrite allows a target directory with content: entries replace
	// existing files, symlinks and special files of the same name, and
	// existing directories are merged into. A directory in the way of a
	// non-directory entry (or the reverse) is still an error.
	Overwrite bool
	// Writer overrides the platform MetadataWriter.
	Writer MetadataWriter
	// OnWarn receives non-fatal events; nil discards them.
	OnWarn func(Warning)
	// OnProgress, when set, is called with the archive-relative path and
	// the byte count each time a slice of file content is written. Called
	// from the restoring goroutine; keep it fast.
	OnProgress func(path string, n int)
}

Options configures a restore. The zero value restores into a missing or empty directory with the platform's MetadataWriter.

type Warning

type Warning struct {
	Path string // archive-relative path
	Err  error
}

Warning is a non-fatal restore event: metadata that could not be applied, or an entry that could not be created on this system.

func (Warning) Error

func (w Warning) Error() string

Jump to

Keyboard shortcuts

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