tarutil

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package tarutil archives and restores a directory tree as a tar file, preserving the metadata a workload's data directory depends on: modes, ownership, modification times, symlinks, hardlinks, FIFOs, overlay whiteouts, and user.* / overlay extended attributes (as PAX SCHILY.xattr records).

It exists for snapshotting durable-dir volumes and rootfs overlay uppers (see cmd/ateom-microvm): the contents are written by the sandboxed workload under arbitrary uids, shipped to object storage, and restored — possibly onto another node — where the workload must see them unchanged. The upper is why device nodes and overlay xattrs matter: the host kernel's overlayfs records a deleted file as a 0:0 character device (whiteout) and a replaced directory as a trusted.overlay.opaque xattr, and losing either silently resurrects deleted content after a resume.

Extraction is confined to the destination with os.Root, so a crafted archive cannot write outside it via "..", an absolute path, or a symlink. It also refuses device nodes other than whiteouts and restores only the xattrs keepXattr allows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, tarPath, srcDir string) error

Create writes a tar archive of srcDir's contents to tarPath. Entry names are relative to srcDir, so extracting into another directory reproduces the tree. srcDir itself is not an entry.

Regular files, directories, symlinks, FIFOs, and overlay whiteouts are archived with their mode, ownership, modification time, and the xattrs keepXattr allows. A file with multiple links inside srcDir is archived once and referenced as a hardlink thereafter. Sockets and other device nodes are skipped (see writeTree).

func CreateFiltered

func CreateFiltered(ctx context.Context, tarPath, srcDir string, skip SkipFunc) error

CreateFiltered is Create with entries omitted where skip returns true. A nil skip archives everything.

func CreateFilteredWithRoot added in v0.4.0

func CreateFilteredWithRoot(ctx context.Context, tarPath, srcDir string, skip SkipFunc) error

CreateFilteredWithRoot is CreateWithRoot with entries omitted where skip returns true. The root entry is never skipped.

func CreateWithRoot added in v0.4.0

func CreateWithRoot(ctx context.Context, tarPath, srcDir string) error

CreateWithRoot is Create plus a "./" entry carrying srcDir's own mode, ownership, modification time, and xattrs, which Extract applies to dstDir.

func Extract

func Extract(tarPath, dstDir string) error

Extract unpacks tarPath into dstDir, which must already exist. Modes, ownership, modification times, symlinks, and hardlinks are restored.

All writes go through an os.Root rooted at dstDir, so entries naming a path outside it — via "..", an absolute path, or a symlink planted earlier in the same archive — are refused rather than followed. An entry that collides with an existing path replaces it ("later entry wins", standard tar semantics), except that an existing directory is kept when the entry is also a directory.

Types

type SkipFunc

type SkipFunc func(rel string) bool

SkipFunc reports whether an archive entry should be omitted, given its slash-separated path relative to the archive root. Returning true for a directory omits its entire subtree.

Jump to

Keyboard shortcuts

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