scanner

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectFiles

func CollectFiles(node domain.Node) []domain.FilePath

CollectFiles returns all file paths in a tree. Useful for collecting all files in a package.

func CountNodes

func CountNodes(node domain.Node) int

CountNodes returns the total number of nodes in a tree.

func FilterTreeForTest

func FilterTreeForTest(node domain.Node, ignoreSet *ignore.IgnoreSet) domain.Node

FilterTreeForTest exports filterTree for testing purposes.

func GetReservedPackageReason

func GetReservedPackageReason(name string) string

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

func IsReservedPackageName(name string) bool

IsReservedPackageName checks if the given package name is reserved for dot's internal use. Reserved names cannot be managed as packages.

func RelativePath

func RelativePath(base, target domain.FilePath) domain.Result[string]

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

func ScanTree(ctx context.Context, fs domain.FS, path domain.FilePath) domain.Result[domain.Node]

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

func TranslateDotfile(name string) string

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

func TranslatePackageName(name string) string

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

func TranslatePath(path string) string

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

func UntranslateDotfile(name string) string

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

func UntranslatePath(path string) string

UntranslatePath translates the last component of a path if it starts with dot. This is the reverse of TranslatePath.

func Walk

func Walk(node domain.Node, fn func(domain.Node) error) error

Walk traverses a Node tree, calling fn for each node. Traversal is depth-first pre-order.

If fn returns an error, traversal stops and the error is returned.

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

type ErrFileTooLarge struct {
	Path  string
	Size  int64
	Limit int64
}

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.

Jump to

Keyboard shortcuts

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