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
- func CheckPattern(p string) error
- func Inside(root, path string) bool
- func IsTestPath(rel string) bool
- func LangOf(rel string) string
- func Match(patterns []string, rel string) bool
- func ReadText(abs string) (string, error)
- func Resolve(root, untrusted string) (string, error)
- type File
- type Options
- type Result
- type Skip
- type Texts
Constants ¶
const MaxFileSize = 1 << 20
MaxFileSize is the largest file Spackle reads as source. Larger files are reported as skipped, not silently ignored. The same holds for directories that are pruned by default.
const MaxHeldText = 64 << 20
MaxHeldText is the most text, in bytes, that a Texts holds at one time.
const SkippedDirReason = "dependency, cache or build output directory, not scanned by default; name it in [scan] include to read it"
SkippedDirReason is the skip reason of a directory pruned by default.
Variables ¶
This section is empty.
Functions ¶
func CheckPattern ¶ added in v0.2.0
CheckPattern reports whether p is a usable Options pattern.
func Inside ¶
Inside reports whether path is root or lies beneath it. Both must be absolute and already cleaned of symlinks by the caller.
func IsTestPath ¶ added in v0.2.0
IsTestPath reports whether a forward-slash relative path is test code: a file in a test directory, or a file named the way a test runner expects. It is the one definition every stage uses, so the seeders (test code is not attack surface), the mapper (a test is not an entry point) and the fixer (fix the code, not the check) agree on what a test is.
func LangOf ¶
LangOf returns the language of a path by name and extension. It recognizes Dockerfiles ("dockerfile") and dotenv files ("dotenv") by name.
func Match ¶ added in v0.2.0
Match reports whether the forward-slash relative path rel matches one of the patterns, either itself or through one of its parent directories.
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 Options ¶ added in v0.2.0
type Options struct {
// Exclude lists paths that are not read. A pattern that matches a
// directory excludes everything beneath it.
Exclude []string
// Include lists directories that are read although they are pruned by
// default (node_modules, a root build or dist, a vendor tree).
Include []string
}
Options narrow or widen what List reads. Patterns are forward-slash globs relative to the root: "*" and "?" match within one path segment and "**" matches any number of segments. A pattern with no slash is also matched against the file or directory name alone, so "*.min.js" works anywhere.
type Result ¶
Result is the outcome of listing a target.
type Texts ¶ added in v0.2.0
type Texts struct {
// contains filtered or unexported fields
}
Texts hands the text of files from one stage of a scan to the next, so a file the mapper read is not read again by the seeders. A text is held until it is taken, and at most MaxHeldText bytes are held: past that a text is not kept, and the next stage reads that file itself. Memory use is therefore bounded however large the target is.
A nil *Texts holds nothing, so a stage can be run without one. A Texts is safe for concurrent use.