walk

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package walk lists the files of a target safely. It is the only way Spackle enumerates target source, so the safety rules live in one place: never follow a symlink out of the root, never read huge or binary files, and skip dependency and VCS directories.

Index

Constants

View Source
const MaxFileSize = 1 << 20

MaxFileSize is the largest file Spackle reads as source. Larger files are reported as skipped, not silently ignored.

Variables

This section is empty.

Functions

func Inside

func Inside(root, path string) bool

Inside reports whether path is root or lies beneath it. Both must be absolute and already cleaned of symlinks by the caller.

func LangOf

func LangOf(rel string) string

LangOf returns the language of a path by name and extension. It recognizes Dockerfiles ("dockerfile") and dotenv files ("dotenv") by name.

func ReadText

func ReadText(abs string) (string, error)

ReadText reads a listed file and normalizes CRLF to LF so that line numbers and quoted lines are the same on every platform.

func Resolve

func Resolve(root, untrusted string) (string, error)

Resolve turns a path supplied by an untrusted party (a model, a scanner) into an absolute path inside root, or returns an error. It rejects absolute paths, parent traversal, and symlinks that leave the root.

Types

type File

type File struct {
	Rel  string // forward-slash path relative to the root
	Abs  string // absolute path on this machine
	Size int64
	Lang string // see LangOf; empty when not recognized
}

File is one readable text file in the target.

type Result

type Result struct {
	Files   []File
	Skipped []Skip
}

Result is the outcome of listing a target.

func List

func List(root string) (Result, error)

List returns every readable text file under root, sorted by relative path. Problems with individual files are recorded in Skipped; only a problem with root itself is an error.

type Skip

type Skip struct {
	Rel    string
	Reason string
}

Skip records a path that was not listed, and why.

Jump to

Keyboard shortcuts

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