targetfs

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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 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

Constants

This section is empty.

Variables

View Source
var ErrNotRegular = errors.New("not a regular file")

ErrNotRegular is returned for a directory, a device, a FIFO or a socket

View Source
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

func Cap(g *graph.Graph, rel string) int64

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

func Read(root, rel string, max int64) (data []byte, truncated bool, err error)

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

func ReadDirNames(root, rel string) ([]string, error)

ReadDirNames lists the names in directory rel of the tree, through the scan root

func ReadGraphFile

func ReadGraphFile(g *graph.Graph, rel string) ([]byte, error)

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

func ReadWhole

func ReadWhole(root, rel string, max int64) ([]byte, error)

ReadWhole returns rel whole, or ErrTooLarge when it has more than max bytes

func Refused

func Refused(err error) bool

Refused reports whether err is a refusal rather than a missing file: a link out of the tree, a file that is not regular, one over the cap, or any other error but "does not exist". A caller must not read a refusal as "the file says nothing": a hostile tree can arrange one on purpose.

Types

This section is empty.

Jump to

Keyboard shortcuts

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