Documentation
¶
Overview ¶
Package targetfs reads the files of a scanned tree after the inventory walk.
The tree is hostile input. Git keeps symlinks, so a README.md or a package.json in a cloned repository may point at any file on the scanning machine, and a path may name something that never ends (/dev/zero, a FIFO) or a file far larger than the walk agreed to parse. The inventory walk refuses all of these; every later read of a target file goes through this package so it keeps the same promises:
- it stays under the scan root: the file is opened through an os.Root, so a symlink that leaves the root fails to open, while one that stays inside it is followed;
- it reads regular files only, checked before the open, so a FIFO cannot block it;
- it never reads more than a cap, so a large file cannot exhaust memory.
Index ¶
- Variables
- func Cap(g *graph.Graph, rel string) int64
- func Read(root, rel string, max int64) (data []byte, truncated bool, err error)
- func ReadDirNames(root, rel string) ([]string, error)
- func ReadGraphFile(g *graph.Graph, rel string) ([]byte, error)
- func ReadWhole(root, rel string, max int64) ([]byte, error)
- func Refused(err error) bool
Constants ¶
This section is empty.
Variables ¶
var ErrNotRegular = errors.New("not a regular file")
ErrNotRegular is returned for a directory, a device, a FIFO or a socket
var ErrTooLarge = errors.New("file is larger than the read limit")
ErrTooLarge is returned by ReadWhole for a file larger than its cap
Functions ¶
func Cap ¶
Cap is the number of bytes of a graph file that the source walk read, and so the most any analyzer reading the same file needs: the truncation point of a file the walk found over the per-file limit, the bundle limit for a bundle, and the per-file limit otherwise
func Read ¶
Read returns at most max bytes of rel, a path relative to root (either separator). truncated reports that the file has more than max bytes.
An empty root reads rel as given: graphs built in memory, as tests do, have no root. The regular-file check and the cap still apply.
func ReadDirNames ¶
ReadDirNames lists the names in directory rel of the tree, through the scan root
func ReadGraphFile ¶
ReadGraphFile reads a file of the graph's tree, at most Cap bytes of it: the bytes the source walk parsed, never a file outside the root
Types ¶
This section is empty.