Documentation
¶
Index ¶
- Constants
- Variables
- type FileInfo
- type ScanResult
- type Scanner
- func (s *Scanner) Filter(files []string) []FileInfo
- func (s *Scanner) Scan(rootPath string) (*ScanResult, error)
- func (s *Scanner) ScanSingle(path string) (*ScanResult, error)
- func (s *Scanner) ScanSingleFromHandle(dir *os.File, canonicalPath string) (*ScanResult, error)
- func (s *Scanner) ScanWithFilter(ctx context.Context, rootPath string, maxFiles int, filter string) (*ScanResult, error)
- func (s *Scanner) ScanWithLimits(ctx context.Context, rootPath string, maxFiles int) (*ScanResult, error)
Constants ¶
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 ¶
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
NewScanner creates a new file scanner
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 ¶
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