Documentation
¶
Overview ¶
Package snapshot provides types and interfaces for workspace snapshots.
Index ¶
- Constants
- Variables
- func IsAPFS(path string) bool
- func NewID() string
- type APFSBackend
- func (b *APFSBackend) Create(workspacePath, id string) (string, error)
- func (b *APFSBackend) Delete(nativeRef string) error
- func (b *APFSBackend) List(workspacePath string) ([]string, error)
- func (b *APFSBackend) Name() string
- func (b *APFSBackend) Restore(workspacePath, nativeRef string) error
- func (b *APFSBackend) RestoreTo(nativeRef, destPath string) error
- type ArchiveBackend
- func (b *ArchiveBackend) Create(workspacePath, id string) (string, error)
- func (b *ArchiveBackend) Delete(nativeRef string) error
- func (b *ArchiveBackend) List(_ string) ([]string, error)
- func (b *ArchiveBackend) Name() string
- func (b *ArchiveBackend) Restore(workspacePath, nativeRef string) error
- func (b *ArchiveBackend) RestoreTo(nativeRef, destPath string) error
- type ArchiveOptions
- type Backend
- type Engine
- func (e *Engine) Backend() Backend
- func (e *Engine) Create(typ Type, label string) (Metadata, error)
- func (e *Engine) Delete(id string) error
- func (e *Engine) Get(id string) (Metadata, bool)
- func (e *Engine) List() ([]Metadata, error)
- func (e *Engine) Restore(id string) error
- func (e *Engine) RestoreTo(id, destPath string) error
- type EngineOptions
- type Metadata
- type Type
Constants ¶
const ( BackendArchive = "archive" BackendAPFS = "apfs" )
Backend identifiers, used for EngineOptions.ForceBackend and Backend.Name.
Variables ¶
var ErrAPFSNotAvailable = errors.New("APFS snapshots are only available on macOS")
ErrAPFSNotAvailable is returned when APFS operations are attempted on non-Darwin platforms.
Functions ¶
Types ¶
type APFSBackend ¶
type APFSBackend struct {
// contains filtered or unexported fields
}
APFSBackend is a stub for non-darwin platforms. On non-darwin systems, all methods return errors to indicate APFS is unavailable.
func NewAPFSBackend ¶
func NewAPFSBackend(snapshotDir string) *APFSBackend
NewAPFSBackend returns a stub APFSBackend on non-darwin platforms. The snapshotDir parameter is accepted for API compatibility but not used.
func (*APFSBackend) Create ¶
func (b *APFSBackend) Create(workspacePath, id string) (string, error)
Create returns an error on non-darwin platforms.
func (*APFSBackend) Delete ¶
func (b *APFSBackend) Delete(nativeRef string) error
Delete returns an error on non-darwin platforms.
func (*APFSBackend) List ¶
func (b *APFSBackend) List(workspacePath string) ([]string, error)
List returns an error on non-darwin platforms.
func (*APFSBackend) Restore ¶
func (b *APFSBackend) Restore(workspacePath, nativeRef string) error
Restore returns an error on non-darwin platforms.
func (*APFSBackend) RestoreTo ¶
func (b *APFSBackend) RestoreTo(nativeRef, destPath string) error
RestoreTo returns an error on non-darwin platforms.
type ArchiveBackend ¶
type ArchiveBackend struct {
// contains filtered or unexported fields
}
ArchiveBackend implements the Backend interface using tar.gz archives.
func NewArchiveBackend ¶
func NewArchiveBackend(snapshotDir string, opts ArchiveOptions) *ArchiveBackend
NewArchiveBackend creates a new archive-based snapshot backend.
func (*ArchiveBackend) Create ¶
func (b *ArchiveBackend) Create(workspacePath, id string) (string, error)
Create creates a tar.gz archive of the workspace.
func (*ArchiveBackend) Delete ¶
func (b *ArchiveBackend) Delete(nativeRef string) error
Delete removes the archive file.
func (*ArchiveBackend) List ¶
func (b *ArchiveBackend) List(_ string) ([]string, error)
List returns all archive files in the snapshot directory. The workspacePath parameter is unused but required by the Backend interface.
func (*ArchiveBackend) Name ¶
func (b *ArchiveBackend) Name() string
Name returns the backend identifier.
func (*ArchiveBackend) Restore ¶
func (b *ArchiveBackend) Restore(workspacePath, nativeRef string) error
Restore extracts the archive to the workspace, preserving .git directory.
func (*ArchiveBackend) RestoreTo ¶
func (b *ArchiveBackend) RestoreTo(nativeRef, destPath string) error
RestoreTo extracts the archive to an arbitrary destination path.
type ArchiveOptions ¶
type ArchiveOptions struct {
// UseGitignore enables parsing .gitignore files to exclude matching paths.
UseGitignore bool
// Additional specifies extra patterns to exclude (gitignore syntax).
Additional []string
// IncludeGit keeps the .git directory in the archive instead of skipping
// it. Volume mode sets this so agent commits made inside the container
// survive snapshot extraction. Defaults to false (bind-mode behavior),
// which always excludes .git.
IncludeGit bool
}
ArchiveOptions configures the archive backend behavior.
type Backend ¶
type Backend interface {
// Name returns the backend identifier (e.g., "apfs", "zfs", "archive").
Name() string
// Create creates a snapshot of the workspace and returns its native reference.
Create(workspacePath string, id string) (nativeRef string, err error)
// Restore restores a snapshot to the workspace (in-place).
Restore(workspacePath string, nativeRef string) error
// RestoreTo restores a snapshot to a different directory.
RestoreTo(nativeRef string, destPath string) error
// Delete removes a snapshot.
Delete(nativeRef string) error
// List returns all snapshots for a workspace.
List(workspacePath string) ([]string, error)
}
Backend defines the interface for snapshot storage backends.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine manages snapshot operations with automatic backend detection.
func NewEngine ¶
func NewEngine(workspace, snapshotDir string, opts EngineOptions) (*Engine, error)
NewEngine creates a new snapshot engine with automatic backend detection. It loads any existing snapshot metadata from the snapshot directory.
type EngineOptions ¶
type EngineOptions struct {
// UseGitignore enables parsing .gitignore files to exclude matching paths.
UseGitignore bool
// Additional specifies extra patterns to exclude (gitignore syntax).
Additional []string
// ForceBackend forces a specific backend: BackendArchive or BackendAPFS.
ForceBackend string
// IncludeGit keeps the .git directory in archive snapshots. Volume mode
// sets this so agent commits survive extraction; default false preserves
// bind-mode behavior (always exclude .git).
IncludeGit bool
}
EngineOptions configures the snapshot engine behavior.
type Metadata ¶
type Metadata struct {
ID string `json:"id"`
Type Type `json:"type"`
Label string `json:"label,omitempty"`
Backend string `json:"backend"`
CreatedAt time.Time `json:"created_at"`
SizeDelta *int64 `json:"size_delta,omitempty"`
NativeRef string `json:"native_ref,omitempty"`
}
Metadata describes a snapshot.
func ListSnapshots ¶ added in v0.7.0
ListSnapshots reads snapshot metadata directly from a snapshot directory, without constructing an Engine. Unlike NewEngine(...).List(), it does NOT require the run's workspace to still exist on disk, so guards that run after the workspace is gone (e.g. the destroy/clean extraction-snapshot check) get a correct answer instead of failing closed. A missing metadata file is not an error — it yields an empty list (no snapshots taken yet).