saferm v0.8.1 /internal/archive
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

Go go
const KindFile Kind = iota

The three shapes an archived entry takes on disk.

#KindDirectory

Go go
const KindDirectory
Go go
const KindSymlink

#ErrFileNotFound

Go go
var ErrFileNotFound      = errors.New("file not found")

Sentinel errors.

#ErrRecursiveRequired

Go go
var ErrRecursiveRequired = errors.New("target is a directory; recursive flag required")

#ErrConflict

Go go
var ErrConflict          = errors.New("destination already exists")

#ErrHashMismatch

Go go
var ErrHashMismatch      = errors.New("hash mismatch after copy")

#ArchiveResult

Go go
type ArchiveResult struct

ArchiveResult holds the outcome of archiving a file or directory.

#Kind

Go go
type Kind int

Kind names what an archival is about to move.

#Plan

Go go
type Plan struct

Plan 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

Go go
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

Go go
func Execute(p *Plan) (*ArchiveResult, error)

Execute carries out the archival a [Plan] describes.

#Archive

Go go
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

Go go
func Restore(uuid string, archiveDir string, destPath string, isDirectory bool, force bool, symlinkTarget string) error

Restore 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).

Search