Help us shape the future of Go! Take the 2026 Go Developer Survey

snapshot

package
v0.298.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package snapshot provides a service for capturing and comparing point-in-time snapshots of the working directory file system.

Index

Constants

View Source
const (
	SnapshotTypeStart  = "start"  // Created at session start
	SnapshotTypeEnd    = "end"    // Created at session end
	SnapshotTypeManual = "manual" // User-triggered
)

Snapshot type constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements session.SnapshotCreator using a snapshot Service. It bridges the session package (which uses the SnapshotCreator interface to avoid an import cycle) with the concrete snapshot.Service.

func NewAdapter

func NewAdapter(svc Service) *Adapter

NewAdapter wraps a Service in an Adapter that satisfies session.SnapshotCreator.

func (*Adapter) CreateSessionSnapshot

func (a *Adapter) CreateSessionSnapshot(ctx context.Context, sessionID, snapshotType, description string) error

CreateSessionSnapshot delegates to the underlying Service.Create method.

type DiffEntry

type DiffEntry struct {
	Path    string   `json:"path"`
	Type    DiffType `json:"type"`
	OldHash string   `json:"old_hash,omitempty"`
	NewHash string   `json:"new_hash,omitempty"`
	OldSize int64    `json:"old_size,omitempty"`
	NewSize int64    `json:"new_size,omitempty"`
}

DiffEntry represents a single file-level change between two snapshots.

type DiffType

type DiffType string

DiffType describes the kind of change between two snapshots.

const (
	DiffAdded    DiffType = "added"
	DiffModified DiffType = "modified"
	DiffDeleted  DiffType = "deleted"
)

type Manifest

type Manifest struct {
	Snapshot Snapshot       `json:"snapshot"`
	Files    []SnapshotFile `json:"files"`
}

Manifest combines a Snapshot header with its full file list.

type Service

type Service interface {
	pubsub.Suscriber[Snapshot]
	Create(ctx context.Context, sessionID, snapshotType, description string) (Snapshot, error)
	Get(ctx context.Context, id string) (Snapshot, error)
	GetManifest(ctx context.Context, id string) (Manifest, error)
	List(ctx context.Context) ([]Snapshot, error)
	ListBySession(ctx context.Context, sessionID string) ([]Snapshot, error)
	Delete(ctx context.Context, id string) error
	GetFileContent(ctx context.Context, snapshotID, fileHash string) ([]byte, error)
	Compare(ctx context.Context, snapshotID1, snapshotID2 string) ([]DiffEntry, error)
	Cleanup(ctx context.Context, maxAge int, maxCount int) error
	Revert(ctx context.Context, snapshotID string) error
	Apply(ctx context.Context, fromSnapshotID, toSnapshotID string) error
}

Service defines the public interface for the snapshot service.

func NewService

func NewService() (Service, error)

NewService creates and returns a new snapshot Service. It reads the data directory from the application config and initialises both the file-based storage and the file-system scanner.

type Snapshot

type Snapshot struct {
	ID          string `json:"id"`
	SessionID   string `json:"session_id"`
	Type        string `json:"type"` // start, end, manual
	Description string `json:"description"`
	WorkingDir  string `json:"working_dir"`
	FileCount   int    `json:"file_count"`
	TotalSize   int64  `json:"total_size"`
	CreatedAt   int64  `json:"created_at"`
}

Snapshot represents a point-in-time capture of the working directory.

type SnapshotFile

type SnapshotFile struct {
	Path    string `json:"path"`
	Hash    string `json:"hash"` // SHA256 hex digest
	Size    int64  `json:"size"`
	ModTime int64  `json:"mod_time"`
	IsDir   bool   `json:"is_dir"`
}

SnapshotFile represents a single file captured within a snapshot.

Jump to

Keyboard shortcuts

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