ports

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ports defines interfaces (contracts) for external dependencies. These enable dependency injection and testability via mock implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archiver

type Archiver interface {
	// Create creates a zip archive of sourceDir at destPath.
	// Returns the number of files archived.
	// exclude is a list of patterns to skip (e.g., "node_modules", "*.pyc").
	Create(destPath, sourceDir string, exclude []string) (fileCount int, err error)

	// Extract extracts a zip archive to destDir.
	Extract(zipPath, destDir string) error

	// List returns a map of file paths to their info from the archive.
	// The path key has the project prefix stripped.
	List(zipPath string) (map[string]FileInfo, error)

	// ReadFile reads the contents of a file from inside a zip archive.
	ReadFile(zipPath, filePath, projectName string) (string, error)
}

Archiver abstracts zip archive operations for testability. Production code uses ZipArchiver adapter; tests use MockArchiver.

type FileInfo

type FileInfo struct {
	Size  int64
	CRC32 uint32
}

FileInfo contains metadata about a file in an archive.

type FileSystem

type FileSystem interface {
	// ReadDir reads the named directory and returns directory entries.
	ReadDir(name string) ([]os.DirEntry, error)

	// Stat returns file info for the named file.
	Stat(name string) (os.FileInfo, error)

	// MkdirAll creates a directory along with any necessary parents.
	MkdirAll(path string, perm os.FileMode) error

	// WriteFile writes data to the named file, creating it if necessary.
	WriteFile(name string, data []byte, perm os.FileMode) error

	// ReadFile reads the named file and returns the contents.
	ReadFile(name string) ([]byte, error)

	// Remove removes the named file or empty directory.
	Remove(name string) error

	// RemoveAll removes path and any children it contains.
	RemoveAll(path string) error

	// Rename renames (moves) oldpath to newpath.
	Rename(oldpath, newpath string) error

	// Open opens the named file for reading.
	Open(name string) (fs.File, error)

	// Create creates or truncates the named file.
	Create(name string) (*os.File, error)

	// Walk walks the file tree rooted at root, calling fn for each file or directory.
	Walk(root string, fn WalkFunc) error
}

FileSystem abstracts filesystem operations for testability. Production code uses OSFileSystem adapter; tests use MockFileSystem.

type GitClient

type GitClient interface {
	// GetHead returns the current HEAD commit hash for the repository.
	// Returns empty string if not a git repo or on error.
	GetHead(repoPath string) string

	// IsRepo checks if the given path is a git repository.
	IsRepo(path string) bool
}

GitClient abstracts git operations for testability. Production code uses ExecGitClient adapter; tests use MockGitClient.

type LaunchdService

type LaunchdService interface {
	// PlistPath returns the path where the plist file should be stored.
	PlistPath() string

	// LogPath returns the path where logs should be written.
	LogPath() string

	// Install creates the plist file and loads the service.
	Install(execPath, configPath string, hour, minute int) error

	// Uninstall unloads the service and removes the plist file.
	Uninstall() error

	// IsInstalled checks if the service is currently installed.
	IsInstalled() bool

	// Status returns the current status of the service.
	// Returns "running", "loaded", "not loaded", or error message.
	Status() string
}

LaunchdService abstracts macOS launchd operations for testability. Production code uses MacLaunchdService adapter; tests use MockLaunchdService.

type ResticClient added in v1.0.0

type ResticClient interface {
	// Init initializes a new restic repository at the given path.
	// Returns an error if the repository already exists or cannot be created.
	Init(repoPath, password string) error

	// Backup creates a new backup of the given paths to the repository.
	// Tags can be used to identify/filter snapshots later.
	// Returns the snapshot ID on success.
	Backup(repoPath, password string, paths []string, tags []string) (string, error)

	// Snapshots returns all snapshots in the repository.
	// Can optionally filter by tags.
	Snapshots(repoPath, password string, tags []string) ([]Snapshot, error)

	// Restore restores a snapshot to the given target directory.
	// Use "latest" as snapshotID to restore the most recent snapshot.
	Restore(repoPath, password, snapshotID, targetDir string) error

	// Forget removes old snapshots according to the retention policy.
	// keepLast specifies how many recent snapshots to keep.
	// If prune is true, also removes unreferenced data from the repository.
	Forget(repoPath, password string, keepLast int, prune bool) error

	// IsInitialized checks if a restic repository exists at the given path.
	IsInitialized(repoPath string) bool
}

ResticClient abstracts restic operations for testability. Production code uses ExecResticClient adapter; tests use MockResticClient.

type Snapshot added in v1.0.0

type Snapshot struct {
	ID       string    `json:"id"`       // Short snapshot ID
	Time     time.Time `json:"time"`     // Snapshot creation time
	Hostname string    `json:"hostname"` // Machine hostname
	Paths    []string  `json:"paths"`    // Backed up paths
	Tags     []string  `json:"tags"`     // Snapshot tags
}

Snapshot represents a restic backup snapshot.

type TUIBackupResult

type TUIBackupResult struct {
	Size    int64
	Error   error
	Skipped bool
	Reason  string
}

TUIBackupResult contains the result of a backup operation.

type TUIProjectInfo

type TUIProjectInfo struct {
	Name        string
	Path        string
	SourceLabel string // Label of the source directory (e.g., "Code", "Work")
	SourceIcon  string // Icon for display (e.g., "📁", "💼", "🔒")
	SourceType  string // Source type: "git" or "sensitive"
	Versions    int
	LastBackup  time.Time
	TotalSize   int64
}

TUIProjectInfo contains project metadata for display.

type TUIService

type TUIService interface {
	// LoadConfig loads the application configuration.
	LoadConfig() (*config.Config, error)

	// ListProjects returns all projects with their metadata.
	ListProjects(cfg *config.Config) ([]TUIProjectInfo, error)

	// ListVersions returns all backup versions for a project.
	ListVersions(cfg *config.Config, project string) ([]TUIVersionInfo, error)

	// ListSnapshots returns all restic snapshots for sensitive sources.
	// Returns snapshots filtered by the given tag (typically "codebak-sensitive").
	ListSnapshots(cfg *config.Config, tag string) ([]TUISnapshotInfo, error)

	// RunBackup performs a backup of the specified project.
	RunBackup(cfg *config.Config, project string) TUIBackupResult

	// VerifyBackup verifies the latest backup of a project.
	// Returns nil if verified successfully, error otherwise.
	VerifyBackup(cfg *config.Config, project string) error
}

TUIService provides operations needed by the TUI. This abstraction allows the TUI to be tested without real filesystem/backup operations.

type TUISnapshotInfo added in v1.0.0

type TUISnapshotInfo struct {
	ID    string    // Short snapshot ID
	Time  time.Time // Snapshot creation time
	Paths []string  // Backed up paths
	Tags  []string  // Snapshot tags
}

TUISnapshotInfo contains restic snapshot metadata for display.

type TUIVersionInfo

type TUIVersionInfo struct {
	File      string
	Size      int64
	FileCount int
	GitHead   string
	CreatedAt time.Time
}

TUIVersionInfo contains backup version metadata for display.

type WalkFunc

type WalkFunc func(path string, info os.FileInfo, err error) error

WalkFunc is the type of function called by Walk.

Jump to

Keyboard shortcuts

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