manager

package
v0.0.0-...-5ba0e3b Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DirPerms are the default permissions for created directories (rwxr-x---)
	// Owner: read, write, execute; Group: read, execute; Other: none
	DirPerms os.FileMode = 0750

	// FilePerms are the default permissions for created files (rw-------)
	// Owner: read, write; Group: none; Other: none
	FilePerms os.FileMode = 0600
)

File permissions constants

Variables

View Source
var (
	ErrBackupNotFound = errors.New("backup not found")
	ErrTargetExists   = errors.New("target already exists")
)

Sentinel errors for common manager operations

Functions

func MergeFolder

func MergeFolder(backupDir, targetDir string, useSudo bool, summary *MergeSummary) error

MergeFolder recursively merges all files from targetDir into backupDir. It walks the target directory tree and calls mergeFile for each file found. Directories are skipped (only files are processed). Individual file errors are logged but don't stop the overall operation.

Parameters:

  • backupDir: Directory where backup files are stored
  • targetDir: Directory to merge files from
  • useSudo: Whether to use sudo for file operations (not yet implemented)
  • summary: MergeSummary to record all operations

Returns error only if the directory walk itself fails.

Types

type Adopter

type Adopter interface {
	Adopt() error
	AdoptWithContext(ctx context.Context) error
}

Adopter defines the interface for adopt operations

type Backuper

type Backuper interface {
	Backup() error
	BackupWithContext(ctx context.Context) error
}

Backuper defines the interface for backup operations

type ConflictInfo

type ConflictInfo struct {
	OriginalName string
	RenamedTo    string
}

ConflictInfo tracks files that were renamed due to conflicts

type DotfileManager

type DotfileManager interface {
	Restorer
	Backuper
	Lister
}

DotfileManager combines all manager operations

type FailedInfo

type FailedInfo struct {
	FileName string
	Error    string
}

FailedInfo tracks files that failed to merge

type Lister

type Lister interface {
	List() error
}

Lister defines the interface for listing operations

type Manager

type Manager struct {
	Config   *config.Config
	Platform *platform.Platform

	DryRun      bool
	Verbose     bool
	NoMerge     bool
	ForceDelete bool
	ForceRender bool
	// contains filtered or unexported fields
}

Manager handles dotfile operations including backup, restore, and listing of configuration entries. It maintains references to the configuration, platform information, and operational settings.

func New

func New(cfg *config.Config, plat *platform.Platform) *Manager

New creates a new Manager instance with the given configuration and platform information. The Manager is initialized with structured logging using slog.

func (*Manager) Backup

func (m *Manager) Backup() error

Backup copies configuration files from their target locations to the backup directory.

func (*Manager) BackupWithContext

func (m *Manager) BackupWithContext(ctx context.Context) error

BackupWithContext backs up configurations with context support

func (*Manager) Close

func (m *Manager) Close() error

Close releases resources held by the Manager, including the state store.

func (*Manager) GetApplications

func (m *Manager) GetApplications() []config.Application

GetApplications returns all filtered applications from the configuration.

func (*Manager) GetModifiedTemplateFiles

func (m *Manager) GetModifiedTemplateFiles(backupDir string) ([]ModifiedTemplate, error)

GetModifiedTemplateFiles returns all .tmpl files in the backup directory whose rendered output on disk differs from the pure render stored in the state DB.

func (*Manager) HasModifiedRenderedFiles

func (m *Manager) HasModifiedRenderedFiles(backupDir string) bool

HasModifiedRenderedFiles returns true if the backup directory contains any .tmpl.rendered files whose content differs from the pure render baseline stored in the state store. This indicates the user has manually edited a rendered template file.

Returns false if the state store is nil, the directory doesn't exist, or has no templates.

func (*Manager) HasOutdatedTemplates

func (m *Manager) HasOutdatedTemplates(backupDir string) bool

HasOutdatedTemplates returns true if the backup directory contains any .tmpl files that need rendering. A template is considered outdated when:

  • It has never been rendered (no render record in state store)
  • Its current SHA256 hash differs from the hash stored at last render

Returns false if the state store is nil, the directory doesn't exist, or has no templates.

func (*Manager) HasTemplateFiles

func (m *Manager) HasTemplateFiles(dir string) bool

HasTemplateFiles returns true if the directory contains any .tmpl files.

func (*Manager) InitStateStore

func (m *Manager) InitStateStore() error

InitStateStore initializes the SQLite state store for template render history. The database is placed in the backup root directory.

func (*Manager) List

func (m *Manager) List() error

List displays all managed configuration entries with their current status.

func (*Manager) Restore

func (m *Manager) Restore() error

Restore creates symlinks from target locations to backup sources for all managed configuration files.

func (*Manager) RestoreFiles

func (m *Manager) RestoreFiles(subEntry config.SubEntry, source, target string) error

RestoreFiles creates symlinks from target to source for individual files in an entry.

func (*Manager) RestoreFolder

func (m *Manager) RestoreFolder(subEntry config.SubEntry, source, target string) error

RestoreFolder creates a symlink from target to source for a folder entry.

func (*Manager) RestoreFolderWithTemplates

func (m *Manager) RestoreFolderWithTemplates(subEntry config.SubEntry, source, target string) error

RestoreFolderWithTemplates handles folders that contain .tmpl files. It delegates folder-level operations (adoption, merge, folder symlink) to RestoreFolder, then renders templates and creates relative symlinks inside the backup directory.

func (*Manager) RestoreWithContext

func (m *Manager) RestoreWithContext(ctx context.Context) error

RestoreWithContext restores configurations with context support

func (*Manager) WithContext

func (m *Manager) WithContext(ctx context.Context) *Manager

WithContext returns a new Manager with the given context

func (*Manager) WithLogger

func (m *Manager) WithLogger(logger *slog.Logger) *Manager

WithLogger sets a custom logger

func (*Manager) WithVerbose

func (m *Manager) WithVerbose(verbose bool) *Manager

WithVerbose returns a new Manager with adjusted log level based on verbose flag. This follows the builder pattern used by WithContext and WithLogger.

type MergeSummary

type MergeSummary struct {
	AppName       string
	MergedFiles   []string
	ConflictFiles []ConflictInfo
	FailedFiles   []FailedInfo
}

MergeSummary tracks merge operations for a single application. This type is not thread-safe and should not be used concurrently.

func NewMergeSummary

func NewMergeSummary(appName string) *MergeSummary

NewMergeSummary creates a new merge summary for an application

func (*MergeSummary) AddConflict

func (s *MergeSummary) AddConflict(originalName, renamedTo string)

AddConflict records a conflict that was resolved by renaming

func (*MergeSummary) AddFailed

func (s *MergeSummary) AddFailed(fileName, errMsg string)

AddFailed records a file that failed to merge

func (*MergeSummary) AddMerged

func (s *MergeSummary) AddMerged(fileName string)

AddMerged records a successfully merged file

func (*MergeSummary) HasOperations

func (s *MergeSummary) HasOperations() bool

HasOperations returns true if any merge operations occurred

type ModifiedTemplate

type ModifiedTemplate struct {
	TemplatePath  string // absolute path to .tmpl source file
	RenderedPath  string // absolute path to .tmpl.rendered file
	RelPath       string // relative path within backup dir
	PureRender    []byte // baseline content from state DB
	CurrentOnDisk []byte // current .tmpl.rendered content on disk
}

ModifiedTemplate contains the diff data for a single modified template file.

type PathError

type PathError struct {
	Err  error
	Op   string
	Path string
}

PathError records an error and the operation and path that caused it.

func NewPathError

func NewPathError(op, path string, err error) *PathError

NewPathError creates a new PathError

func (*PathError) Error

func (e *PathError) Error() string

func (*PathError) Unwrap

func (e *PathError) Unwrap() error

type Restorer

type Restorer interface {
	Restore() error
	RestoreWithContext(ctx context.Context) error
}

Restorer defines the interface for restore operations

Jump to

Keyboard shortcuts

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