Documentation
¶
Index ¶
- Constants
- Variables
- func MergeFolder(backupDir, targetDir string, useSudo bool, summary *MergeSummary) error
- type Adopter
- type Backuper
- type ConflictInfo
- type DotfileManager
- type FailedInfo
- type Lister
- type Manager
- func (m *Manager) Backup() error
- func (m *Manager) BackupWithContext(ctx context.Context) error
- func (m *Manager) Close() error
- func (m *Manager) GetApplications() []config.Application
- func (m *Manager) GetModifiedTemplateFiles(backupDir string) ([]ModifiedTemplate, error)
- func (m *Manager) HasModifiedRenderedFiles(backupDir string) bool
- func (m *Manager) HasOutdatedTemplates(backupDir string) bool
- func (m *Manager) HasTemplateFiles(dir string) bool
- func (m *Manager) InitStateStore() error
- func (m *Manager) List() error
- func (m *Manager) Restore() error
- func (m *Manager) RestoreFiles(subEntry config.SubEntry, source, target string) error
- func (m *Manager) RestoreFolder(subEntry config.SubEntry, source, target string) error
- func (m *Manager) RestoreFolderWithTemplates(subEntry config.SubEntry, source, target string) error
- func (m *Manager) RestoreWithContext(ctx context.Context) error
- func (m *Manager) WithContext(ctx context.Context) *Manager
- func (m *Manager) WithLogger(logger *slog.Logger) *Manager
- func (m *Manager) WithVerbose(verbose bool) *Manager
- type MergeSummary
- type ModifiedTemplate
- type PathError
- type Restorer
Constants ¶
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 ¶
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 ConflictInfo ¶
ConflictInfo tracks files that were renamed due to conflicts
type DotfileManager ¶
DotfileManager combines all manager operations
type FailedInfo ¶
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 ¶
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 ¶
Backup copies configuration files from their target locations to the backup directory.
func (*Manager) BackupWithContext ¶
BackupWithContext backs up configurations with context support
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 ¶
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 ¶
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 ¶
HasTemplateFiles returns true if the directory contains any .tmpl files.
func (*Manager) InitStateStore ¶
InitStateStore initializes the SQLite state store for template render history. The database is placed in the backup root directory.
func (*Manager) Restore ¶
Restore creates symlinks from target locations to backup sources for all managed configuration files.
func (*Manager) RestoreFiles ¶
RestoreFiles creates symlinks from target to source for individual files in an entry.
func (*Manager) RestoreFolder ¶
RestoreFolder creates a symlink from target to source for a folder entry.
func (*Manager) RestoreFolderWithTemplates ¶
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 ¶
RestoreWithContext restores configurations with context support
func (*Manager) WithContext ¶
WithContext returns a new Manager with the given context
func (*Manager) WithLogger ¶
WithLogger sets a custom logger
func (*Manager) WithVerbose ¶
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 ¶
PathError records an error and the operation and path that caused it.
func NewPathError ¶
NewPathError creates a new PathError