datastore

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package datastore provides a high-level interface for managing dodot's internal state on the filesystem. It abstracts away the physical layout of the data directory, providing a clean API for handlers and executors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataStore

type DataStore interface {
	// CreateDataLink links a source file into the datastore structure.
	// Returns the path to the created link in the datastore.
	// This is step 1 for handlers that need to stage files.
	CreateDataLink(pack, handlerName, sourceFile string) (datastorePath string, err error)

	// CreateUserLink creates a user-visible symlink.
	// This is step 2 for the symlink handler to make files accessible.
	// Other handlers don't need this - their files are accessed via shell init.
	CreateUserLink(datastorePath, userPath string) error

	// RunAndRecord executes a command and records completion with a sentinel.
	// This is idempotent - if the sentinel exists, the command is not re-run.
	// Used by provisioning handlers (install, homebrew) to track completion.
	RunAndRecord(pack, handlerName, command, sentinel string) error

	// HasSentinel checks if an operation has been completed.
	// This enables idempotent operations and status reporting.
	HasSentinel(pack, handlerName, sentinel string) (bool, error)

	// RemoveState removes all state for a handler in a pack.
	// This is used for cleanup/uninstall operations.
	RemoveState(pack, handlerName string) error

	// HasHandlerState checks if any state exists for a handler in a pack.
	// This is useful for determining if a handler has been used/provisioned.
	HasHandlerState(pack, handlerName string) (bool, error)

	// ListPackHandlers returns a list of all handlers that have state for a given pack.
	// This helps identify which handlers have been used in a pack.
	ListPackHandlers(pack string) ([]string, error)

	// ListHandlerSentinels returns all sentinel files for a specific handler in a pack.
	// This provides detailed information about what operations have been completed.
	ListHandlerSentinels(pack, handlerName string) ([]string, error)
}

DataStore represents dodot's simplified storage interface. This interface has only 5 operations instead of the previous 20+. The simplicity is intentional - handlers contain logic, not the storage layer.

func New

func New(fs types.FS, paths paths.Paths) DataStore

New creates a new DataStore instance that interacts with the filesystem.

type MemoryFS

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

MemoryFS implements types.FS interface with in-memory storage for testing

func NewMemoryFS

func NewMemoryFS() *MemoryFS

NewMemoryFS creates a new in-memory filesystem for testing

func (*MemoryFS) ClearErrors

func (m *MemoryFS) ClearErrors()

ClearErrors removes all error injections

func (*MemoryFS) CreateFileWithContent

func (m *MemoryFS) CreateFileWithContent(path string, content string) error

CreateFileWithContent is a helper to create a file with content

func (*MemoryFS) FileExists

func (m *MemoryFS) FileExists(path string) bool

FileExists checks if a file exists

func (*MemoryFS) GetLinkTarget

func (m *MemoryFS) GetLinkTarget(path string) (string, error)

GetLinkTarget returns the target of a symlink

func (*MemoryFS) GetReadCount

func (m *MemoryFS) GetReadCount() int

GetReadCount returns the number of read operations

func (*MemoryFS) GetWriteCount

func (m *MemoryFS) GetWriteCount() int

GetWriteCount returns the number of write operations

func (m *MemoryFS) IsSymlink(path string) bool

IsSymlink checks if a path is a symlink

func (*MemoryFS) Lstat

func (m *MemoryFS) Lstat(name string) (fs.FileInfo, error)

func (*MemoryFS) MkdirAll

func (m *MemoryFS) MkdirAll(path string, perm fs.FileMode) error

func (*MemoryFS) ReadDir

func (m *MemoryFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*MemoryFS) ReadFile

func (m *MemoryFS) ReadFile(name string) ([]byte, error)
func (m *MemoryFS) Readlink(name string) (string, error)

func (*MemoryFS) Remove

func (m *MemoryFS) Remove(name string) error

func (*MemoryFS) RemoveAll

func (m *MemoryFS) RemoveAll(path string) error

func (*MemoryFS) Rename

func (m *MemoryFS) Rename(oldpath, newpath string) error

func (*MemoryFS) SetError

func (m *MemoryFS) SetError(path string, err error)

SetError makes the filesystem return an error for a specific path

func (*MemoryFS) Stat

func (m *MemoryFS) Stat(name string) (fs.FileInfo, error)

func (*MemoryFS) String

func (m *MemoryFS) String() string

String returns a string representation of the filesystem tree

func (m *MemoryFS) Symlink(oldname, newname string) error

func (*MemoryFS) WriteFile

func (m *MemoryFS) WriteFile(name string, data []byte, perm fs.FileMode) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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