backup

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package backup snapshots live copy-mode destinations into the profile before apply overwrites them. Backups are copy-mode only: symlink destinations are recreated as links, and edit entries are marker-scoped, so a copy overwrite is the one apply operation that loses destination content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generations

func Generations(moduleDir string) ([]string, error)

Generations lists a module directory's backup generation names newest-first (generation names are timestamps, so lexical order is time order). A module without a backups/ directory lists empty.

func RestoreItem

func RestoreItem(genDir, target string) error

RestoreItem is Run's inverse for one target: the copy Run wrote to <genDir>/<target-without-leading-slash> lands back at the absolute live target. A symlink currently sitting at the target is removed, not followed — writing through it would clobber whatever it points at (e.g. the profile source after a mode switch). Missing parent directories are created; content and file mode come from the backup. A target with no backup in the generation is an error naming the target.

func Run

func Run(files []File, gen string) (int, error)

Run copies every existing Target to <ModuleDir>/backups/<gen>/<Target>: absolute target paths mirror under the generation directory, so a restore is a plain copy back to the mirrored path. gen identifies the run (one apply = one generation shared by every module). Missing targets are skipped — nothing exists to lose. Returns the number of top-level units (files or directories) written. Any unreadable target is an error, not a skip: the caller asked for a backup before overwrite, so losing the file silently must never happen.

Types

type File

type File struct {
	Target    string
	ModuleDir string
}

File is one copy-mode destination to snapshot. Target is the live absolute path (file or directory); ModuleDir is the module layer directory whose module.toml declared the entry — the backup lands in its backups/ subtree, next to the profile content that replaces it.

Jump to

Keyboard shortcuts

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