Documentation
¶
Overview ¶
Package scanner provides pure scanning logic for filesystem traversal. All functions in this package are side-effect free, accepting FS interface for I/O operations.
Index ¶
- func CollectFiles(node domain.Node) []domain.FilePath
- func CountNodes(node domain.Node) int
- func FilterTreeForTest(node domain.Node, ignoreSet *ignore.IgnoreSet) domain.Node
- func GetReservedPackageReason(name string) string
- func IsInteractive() bool
- func IsReservedPackageName(name string) bool
- func RelativePath(base, target domain.FilePath) domain.Result[string]
- func ScanPackage(ctx context.Context, fs domain.FS, path domain.PackagePath, name string, ...) domain.Result[domain.Package]
- func ScanPackageWithConfig(ctx context.Context, fs domain.FS, path domain.PackagePath, name string, ...) domain.Result[domain.Package]
- func ScanTree(ctx context.Context, fs domain.FS, path domain.FilePath) domain.Result[domain.Node]
- func ScanTreeWithConfig(ctx context.Context, fs domain.FS, path domain.FilePath, maxSize int64, ...) domain.Result[domain.Node]
- func TranslateDotfile(name string) string
- func TranslatePackageName(name string) string
- func TranslatePath(path string) string
- func UntranslateDotfile(name string) string
- func UntranslatePath(path string) string
- func Walk(node domain.Node, fn func(domain.Node) error) error
- type BatchPrompter
- type ErrFileTooLarge
- type InteractivePrompter
- type LargeFilePrompter
- type ScanConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectFiles ¶
CollectFiles returns all file paths in a tree. Useful for collecting all files in a package.
func CountNodes ¶
CountNodes returns the total number of nodes in a tree.
func FilterTreeForTest ¶
FilterTreeForTest exports filterTree for testing purposes.
func GetReservedPackageReason ¶
GetReservedPackageReason returns a human-readable reason why a package name is reserved.
func IsInteractive ¶
func IsInteractive() bool
IsInteractive checks if the program is running in an interactive terminal.
func IsReservedPackageName ¶
IsReservedPackageName checks if the given package name is reserved for dot's internal use. Reserved names cannot be managed as packages.
func RelativePath ¶
RelativePath computes the relative path from base to target. Both paths must be absolute. Returns error if target is not under base.
func ScanPackage ¶
func ScanPackage(ctx context.Context, fs domain.FS, path domain.PackagePath, name string, ignoreSet *ignore.IgnoreSet) domain.Result[domain.Package]
ScanPackage scans a single package directory. Returns a Package containing the package metadata and file tree.
The scanner: 1. Verifies package directory exists 2. Scans the directory tree 3. Applies ignore patterns (filtered during tree scan) 4. Returns Package with tree
func ScanPackageWithConfig ¶
func ScanPackageWithConfig(ctx context.Context, fs domain.FS, path domain.PackagePath, name string, globalIgnoreSet *ignore.IgnoreSet, cfg ScanConfig) domain.Result[domain.Package]
ScanPackageWithConfig scans a package with enhanced configuration options. Supports per-package .dotignore files, size filtering, and interactive prompts.
func ScanTree ¶
ScanTree recursively scans a filesystem tree starting at path. Returns a Node representing the tree structure.
The scanning logic: 1. Check if path is a symlink (symlinks are leaf nodes) 2. Check if path is a directory 3. If directory, recursively scan children 4. If file, return file node
This is a pure function - all I/O goes through the FS interface.
func ScanTreeWithConfig ¶
func ScanTreeWithConfig(ctx context.Context, fs domain.FS, path domain.FilePath, maxSize int64, prompter LargeFilePrompter) domain.Result[domain.Node]
ScanTreeWithConfig recursively scans a filesystem tree with size filtering. Returns a Node representing the tree structure. Files exceeding maxSize are handled by the prompter (if provided).
func TranslateDotfile ¶
TranslateDotfile converts "dot-filename" to ".filename". Files with "dot-" prefix become dotfiles in the target directory.
Examples:
- "dot-vimrc" -> ".vimrc"
- "dot-bashrc" -> ".bashrc"
- "README.md" -> "README.md" (no change)
func TranslatePackageName ¶
TranslatePackageName converts package names to target directory names. Package names with "dot-" prefix become dotfiles in the target directory.
This enables intuitive package naming where "dot-gnupg" targets ~/.gnupg/ instead of requiring redundant nesting like dot-gnupg/dot-gnupg/.
Examples:
- "dot-gnupg" -> ".gnupg"
- "dot-config" -> ".config"
- "vim" -> "vim"
- "" -> ""
func TranslatePath ¶
TranslatePath translates the last component of a path if it has dot- prefix. This handles paths like "vim/dot-vimrc" -> "vim/.vimrc".
The function only translates the final component (base name), leaving directory components unchanged.
func UntranslateDotfile ¶
UntranslateDotfile converts ".filename" to "dot-filename". This is the reverse operation of TranslateDotfile.
Examples:
- ".vimrc" -> "dot-vimrc"
- ".bashrc" -> "dot-bashrc"
- "README.md" -> "README.md" (no change)
func UntranslatePath ¶
UntranslatePath translates the last component of a path if it starts with dot. This is the reverse of TranslatePath.
Types ¶
type BatchPrompter ¶
type BatchPrompter struct{}
BatchPrompter automatically skips large files in non-interactive mode.
func NewBatchPrompter ¶
func NewBatchPrompter() *BatchPrompter
NewBatchPrompter creates a new batch prompter.
func (*BatchPrompter) ShouldInclude ¶
func (p *BatchPrompter) ShouldInclude(path string, size int64, limit int64) bool
ShouldInclude always returns false in batch mode.
type ErrFileTooLarge ¶
ErrFileTooLarge indicates a file exceeds the maximum allowed size.
func (ErrFileTooLarge) Error ¶
func (e ErrFileTooLarge) Error() string
type InteractivePrompter ¶
type InteractivePrompter struct {
// contains filtered or unexported fields
}
InteractivePrompter prompts the user for each large file in TTY mode.
func NewInteractivePrompter ¶
func NewInteractivePrompter() *InteractivePrompter
NewInteractivePrompter creates a new interactive prompter using stdin/stderr.
func NewInteractivePrompterWithIO ¶
func NewInteractivePrompterWithIO(input io.Reader, output io.Writer) *InteractivePrompter
NewInteractivePrompterWithIO creates a new interactive prompter with custom I/O.
func (*InteractivePrompter) ShouldInclude ¶
func (p *InteractivePrompter) ShouldInclude(path string, size int64, limit int64) bool
ShouldInclude prompts the user whether to include a large file.
type LargeFilePrompter ¶
type LargeFilePrompter interface {
// ShouldInclude asks whether a large file should be included.
// Returns true to include the file, false to skip it.
ShouldInclude(path string, size int64, limit int64) bool
}
LargeFilePrompter determines whether large files should be included during scanning.
type ScanConfig ¶
type ScanConfig struct {
// PerPackageIgnore enables loading .dotignore files from packages
PerPackageIgnore bool
// MaxFileSize is the maximum file size in bytes (0 = no limit)
MaxFileSize int64
// Interactive enables interactive prompts for large files
Interactive bool
}
ScanConfig contains configuration options for scanning.