On this page
API reference for the archive package — file and directory archival with atomic renames, cross-device copy-and-verify, and tar+zstd compression.
#internal/archive
#internal/archive
Package archive handles file and directory archival to the saferm archive. It supports atomic same-filesystem renames, cross-device copy-and-verify, and tar+zstd compression for directories.
#KindFile
const KindFile Kind = iotaThe three shapes an archived entry takes on disk.
#KindDirectory
const KindDirectory#KindSymlink
const KindSymlink#ErrFileNotFound
var ErrFileNotFound = errors.New("file not found")Sentinel errors.
#ErrRecursiveRequired
var ErrRecursiveRequired = errors.New("target is a directory; recursive flag required")#ErrConflict
var ErrConflict = errors.New("destination already exists")#ErrHashMismatch
var ErrHashMismatch = errors.New("hash mismatch after copy")#ArchiveResult
type ArchiveResult structArchiveResult holds the outcome of archiving a file or directory.
#Kind
type Kind intKind names what an archival is about to move.
#Plan
type Plan structPlan is everything an archival can determine by reading: what the entry is, where it will land, and (for a symlink) what it points at. Building one mutates nothing, so a caller can render a plan as a preview and stop, or hand it to [Execute] and go through with it.
#NewPlan
func NewPlan(path string, archiveDir string, isRecursive bool) (*Plan, error)NewPlan inspects path and resolves where archiving it would put it. It performs no mutation.
#Execute
func Execute(p *Plan) (*ArchiveResult, error)Execute carries out the archival a [Plan] describes.
#Archive
func Archive(path string, archiveDir string, isRecursive bool) (*ArchiveResult, error)Archive moves a file or directory into archiveDir, returning the result. For files: moved directly (or copied cross-device) with SHA-256 hash. For directories: compressed into a .tar.zst archive.
#Restore
func Restore(uuid string, archiveDir string, destPath string, isDirectory bool, force bool, symlinkTarget string) errorRestore extracts an archived file or directory to destPath. When symlinkTarget is non-empty, the entry is restored as a symlink pointing to that target (no physical archive file is read).