Documentation
¶
Index ¶
- Variables
- func DecimalStringToMode(s string) (os.FileMode, error)
- func DecimalToOctalPerm(s string) string
- func FileModeToDecimalString(mode os.FileMode) string
- func OctalToDecimalPerm(s string) string
- type FileOperationFilter
- type FileOperationRecord
- type FileState
- type Permission
- type Registry
- func (r *Registry) Begin(ctx context.Context) (*sql.Tx, error)
- func (r *Registry) Compact(ctx context.Context, tx *sql.Tx) error
- func (r *Registry) GetAllToolInstallations(ctx context.Context) ([]*ToolInstallationRecord, error)
- func (r *Registry) GetBlockState(ctx context.Context, filePath, blockID string) (*FileState, error)
- func (r *Registry) GetFileOperations(ctx context.Context, filter FileOperationFilter) ([]*FileOperationRecord, error)
- func (r *Registry) GetFileState(ctx context.Context, filePath string) (*FileState, error)
- func (r *Registry) GetFileStates(ctx context.Context) ([]*FileState, error)
- func (r *Registry) GetFileStatesForTool(ctx context.Context, toolName string) ([]*FileState, error)
- func (r *Registry) GetRegisteredTools(ctx context.Context) ([]string, error)
- func (r *Registry) GetToolInstallation(ctx context.Context, toolName string) (*ToolInstallationRecord, error)
- func (r *Registry) GetToolUsage(ctx context.Context, toolName, binaryName string) (*ToolUsageRecord, error)
- func (r *Registry) GetToolUsages(ctx context.Context) ([]*ToolUsageRecord, error)
- func (r *Registry) GetToolUsagesForTool(ctx context.Context, toolName string) ([]*ToolUsageRecord, error)
- func (r *Registry) IsToolInstalled(ctx context.Context, toolName string, version string) (bool, error)
- func (r *Registry) RecordFileOperation(ctx context.Context, tx *sql.Tx, record *FileOperationRecord) error
- func (r *Registry) RecordToolInstallation(ctx context.Context, tx *sql.Tx, record *ToolInstallationRecord) error
- func (r *Registry) RecordToolUsage(ctx context.Context, tx *sql.Tx, record *ToolUsageRecord) error
- func (r *Registry) RemoveFileOperationsByTool(ctx context.Context, tx *sql.Tx, toolName string) error
- func (r *Registry) RemoveToolInstallation(ctx context.Context, tx *sql.Tx, toolName string) error
- func (r *Registry) RenameFileOperationPrefix(ctx context.Context, tx *sql.Tx, oldPrefix, newPrefix string) error
- func (r *Registry) UpdateToolInstallation(ctx context.Context, tx *sql.Tx, toolName string, ...) error
- func (r *Registry) Validate(ctx context.Context) (*ValidationResult, error)
- func (r *Registry) WithTx(ctx context.Context, fn func(tx *sql.Tx) error) error
- type ToolInstallationRecord
- type ToolInstallationUpdate
- type ToolUsageRecord
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
var ErrTransactionRequired = fmt.Errorf("transaction is required for database writes")
ErrTransactionRequired is returned when a write operation is attempted without a transaction.
Functions ¶
func DecimalStringToMode ¶
DecimalStringToMode converts a decimal base-10 string representation back to os.FileMode.
func DecimalToOctalPerm ¶
DecimalToOctalPerm converts a decimal permission string (e.g., "493", "420") to an octal string with leading zero (e.g., "0755", "0644").
func FileModeToDecimalString ¶
FileModeToDecimalString converts an os.FileMode to its decimal base-10 string representation.
func OctalToDecimalPerm ¶
OctalToDecimalPerm converts an octal permission string (e.g., "0755", "755", "0644") to a decimal string (e.g., "493", "420").
Types ¶
type FileOperationFilter ¶
type FileOperationFilter struct {
ToolName string
OperationType string
FileType string
FilePath string
CreatedAfter int64
CreatedBefore int64
OperationID string
// BlockID restricts the result to operations owning one managed block. A file
// can hold blocks belonging to several tools, so filtering by path alone would
// mix their histories together.
BlockID string
}
type FileOperationRecord ¶
type FileOperationRecord struct {
ID int64 `db:"id"`
ToolName string `db:"tool_name"`
OperationType string `db:"operation_type"` // e.g., "symlink", "shim", "write"
FilePath string `db:"file_path"`
TargetPath *string `db:"target_path"`
FileType string `db:"file_type"`
Metadata *string `db:"metadata"`
SizeBytes *int64 `db:"size_bytes"`
Permissions *Permission `db:"permissions" json:"permissions"`
CreatedAt int64 `db:"created_at"` // Unix millisecond epoch
OperationID string `db:"operation_id"`
// ContentHash is the SHA-256 of exactly what dotfiles wrote, and is the base
// version a later run measures the file on disk against. It is nil for an
// operation that writes no content of its own, such as a symlink or a chmod.
ContentHash *string `db:"content_hash" json:"contentHash,omitempty"`
// BlockID names the managed block this operation owns within a shared file. It
// is nil when the operation owns the whole file.
BlockID *string `db:"block_id" json:"blockId,omitempty"`
// TargetMode is the permission the tool declared, as opposed to Permissions,
// which is the mode the file was actually written with. Comparing the two is how
// a mode that has drifted away from its declaration is noticed.
TargetMode *Permission `db:"target_mode" json:"targetMode,omitempty"`
}
type FileState ¶
type FileState struct {
FilePath string `json:"filePath"`
ToolName string `json:"toolName"`
FileType string `json:"fileType"`
LastOperation string `json:"lastOperation"`
TargetPath *string `json:"targetPath"`
LastModified int64 `json:"lastModified"`
Metadata *string `json:"metadata"`
SizeBytes *int64 `json:"sizeBytes"`
Permissions *Permission `json:"permissions" db:"permissions"`
ContentHash *string `json:"contentHash"`
BlockID *string `json:"blockId"`
TargetMode *Permission `json:"targetMode"`
}
type Permission ¶
type Permission string
Permission represents a filesystem permission string, serialized to JSON as a base-10 decimal number.
func (Permission) MarshalJSON ¶
func (p Permission) MarshalJSON() ([]byte, error)
func (*Permission) Scan ¶
func (p *Permission) Scan(value interface{}) error
func (*Permission) UnmarshalJSON ¶
func (p *Permission) UnmarshalJSON(b []byte) error
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages database-backed operation and state logging.
func NewRegistry ¶
NewRegistry instantiates a new Registry manager with an active database connection.
func (*Registry) Compact ¶
Compact removes redundant file operation records for files that were ultimately deleted.
func (*Registry) GetAllToolInstallations ¶
func (r *Registry) GetAllToolInstallations(ctx context.Context) ([]*ToolInstallationRecord, error)
GetAllToolInstallations fetches all recorded tool installations.
func (*Registry) GetBlockState ¶
GetBlockState returns the recorded state of one managed block within a file.
A shared file such as ~/.ssh/config can hold blocks belonging to several tools, so the drift engine asks for a block by its own identity rather than folding every operation on the path into a single state. Nil means nothing has ever written that block, which is how a first run tells itself apart from a later one.
func (*Registry) GetFileOperations ¶
func (r *Registry) GetFileOperations(ctx context.Context, filter FileOperationFilter) ([]*FileOperationRecord, error)
GetFileOperations queries file operations filtering by provided parameters.
func (*Registry) GetFileState ¶
GetFileState returns active file state for a specific file path.
func (*Registry) GetFileStates ¶
GetFileStates computes the active file state of every path the registry tracks, across all tools, in stable alphabetical order. A path whose latest operation is a removal is absent, so the result is the set of files currently managed rather than the operation history.
func (*Registry) GetFileStatesForTool ¶
GetFileStatesForTool computes active file states for a given tool name, returned in stable alphabetical order.
func (*Registry) GetRegisteredTools ¶
GetRegisteredTools queries distinct tool names registered in active (non-deleted) file operations.
func (*Registry) GetToolInstallation ¶
func (r *Registry) GetToolInstallation(ctx context.Context, toolName string) (*ToolInstallationRecord, error)
GetToolInstallation retrieves a tool installation by its name.
func (*Registry) GetToolUsage ¶
func (r *Registry) GetToolUsage(ctx context.Context, toolName, binaryName string) (*ToolUsageRecord, error)
GetToolUsage retrieves the usage record for a specific tool binary.
func (*Registry) GetToolUsages ¶
func (r *Registry) GetToolUsages(ctx context.Context) ([]*ToolUsageRecord, error)
GetToolUsages fetches all recorded binary usage records across all tools.
func (*Registry) GetToolUsagesForTool ¶
func (r *Registry) GetToolUsagesForTool(ctx context.Context, toolName string) ([]*ToolUsageRecord, error)
GetToolUsagesForTool fetches all usage records for a specific tool.
func (*Registry) IsToolInstalled ¶
func (r *Registry) IsToolInstalled(ctx context.Context, toolName string, version string) (bool, error)
IsToolInstalled checks if a tool (and optionally a specific version) is recorded as installed.
func (*Registry) RecordFileOperation ¶
func (r *Registry) RecordFileOperation(ctx context.Context, tx *sql.Tx, record *FileOperationRecord) error
RecordFileOperation writes a file operation record in a transaction block.
func (*Registry) RecordToolInstallation ¶
func (r *Registry) RecordToolInstallation(ctx context.Context, tx *sql.Tx, record *ToolInstallationRecord) error
RecordToolInstallation persists a tool installation record.
func (*Registry) RecordToolUsage ¶
RecordToolUsage increments or inserts a binary usage counter.
func (*Registry) RemoveFileOperationsByTool ¶
func (r *Registry) RemoveFileOperationsByTool(ctx context.Context, tx *sql.Tx, toolName string) error
RemoveFileOperationsByTool purges file operation logs for a specific tool.
func (*Registry) RemoveToolInstallation ¶
RemoveToolInstallation removes a tool installation registry entry.
func (*Registry) RenameFileOperationPrefix ¶
func (r *Registry) RenameFileOperationPrefix(ctx context.Context, tx *sql.Tx, oldPrefix, newPrefix string) error
RenameFileOperationPrefix updates file_path in file_operations when a directory is renamed.
func (*Registry) UpdateToolInstallation ¶
func (r *Registry) UpdateToolInstallation(ctx context.Context, tx *sql.Tx, toolName string, updates ToolInstallationUpdate) error
UpdateToolInstallation performs a partial update on a tool installation record.
type ToolInstallationRecord ¶
type ToolInstallationRecord struct {
ID int64 `db:"id"`
ToolName string `db:"tool_name"`
Version string `db:"version"`
InstallPath string `db:"install_path"`
Timestamp string `db:"timestamp"`
InstalledAt int64 `db:"installed_at"` // Unix millisecond epoch
BinaryPaths string `db:"binary_paths"` // JSON array string
DownloadURL *string `db:"download_url"`
AssetName *string `db:"asset_name"`
ConfiguredVersion *string `db:"configured_version"`
OriginalTag *string `db:"original_tag"`
InstallMethod *string `db:"install_method"`
}
type ToolInstallationUpdate ¶
type ToolInstallationUpdate struct {
Version *string
InstallPath *string
Timestamp *string
BinaryPaths *string
DownloadURL *string
AssetName *string
ConfiguredVersion *string
OriginalTag *string
InstallMethod *string
}
ToolInstallationUpdate specifies fields to update on an existing tool installation record.