scanner

package
v0.3.3-alpha Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxSkippedFiles is the maximum number of skipped file paths to store
	// to prevent unbounded memory growth when scanning directories with millions of non-video files
	MaxSkippedFiles = 1000
)

Variables

View Source
var (
	ErrMaxFilesExceeded = errors.New("maximum file limit exceeded")
	ErrScanTimeout      = errors.New("scan operation timed out")
)

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Path      string    // Full absolute path
	Name      string    // Filename without path
	Extension string    // File extension (e.g., ".mp4")
	Size      int64     // File size in bytes
	ModTime   time.Time // Last modified time
	Dir       string    // Directory containing the file
}

FileInfo represents a discovered video file

type ScanResult

type ScanResult struct {
	Files        []FileInfo // Matched video files
	Skipped      []string   // Sample of skipped files (capped at MaxSkippedFiles)
	SkippedCount int        // Total count of skipped files
	Errors       []error    // Errors encountered during scan
	LimitReached bool       // Whether max file limit was reached
	TimedOut     bool       // Whether scan timed out
	TotalScanned int        // Total number of files scanned before limit/timeout
}

ScanResult contains the results of a directory scan

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner finds video files based on configuration

func NewScanner

func NewScanner(fs afero.Fs, cfg *config.MatchingConfig) *Scanner

func (*Scanner) Filter

func (s *Scanner) Filter(files []string) []FileInfo

Filter filters a list of files based on configuration

func (*Scanner) Scan

func (s *Scanner) Scan(rootPath string) (*ScanResult, error)

Scan recursively scans a directory for video files (no limits)

func (*Scanner) ScanSingle

func (s *Scanner) ScanSingle(path string) (*ScanResult, error)

ScanSingle scans a single file or directory (non-recursive)

WARNING: This method has a TOCTOU vulnerability. Between path validation and the internal Stat/ReadDir calls, the path could be replaced with a symlink. For TOCTOU-safe scanning, use ScanSingleFromHandle with a pre-validated directory handle from ValidateAndOpenPath.

func (*Scanner) ScanSingleFromHandle

func (s *Scanner) ScanSingleFromHandle(dir *os.File, canonicalPath string) (*ScanResult, error)

ScanSingleFromHandle scans an open directory handle (non-recursive, TOCTOU-safe).

This is the TOCTOU-safe version of ScanSingle. It reads directory entries directly from the provided file handle, preventing symlink swap attacks between validation and scanning.

The canonicalPath is used for recording paths in the returned FileInfo structures. It should be the absolute, symlink-resolved path that was validated before opening the handle.

The caller retains ownership of the file handle and must close it after this call returns.

func (*Scanner) ScanWithFilter

func (s *Scanner) ScanWithFilter(ctx context.Context, rootPath string, maxFiles int, filter string) (*ScanResult, error)

ScanWithFilter recursively scans a directory for video files with timeout, file count limits, and optional name filter maxFiles = 0 means no limit filter = "" means no filter; otherwise, only directories/files containing the filter string (case-insensitive) are processed

func (*Scanner) ScanWithLimits

func (s *Scanner) ScanWithLimits(ctx context.Context, rootPath string, maxFiles int) (*ScanResult, error)

ScanWithLimits recursively scans a directory for video files with timeout and file count limits maxFiles = 0 means no limit

Jump to

Keyboard shortcuts

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