Documentation
¶
Overview ¶
Package docroot keeps a document's reads and writes inside the folder it is in, and out of hidden files: the document's own folder and the folders under it, less any file or folder whose name starts with a dot (.env, .ssh, .git, .zshrc), at any depth. Includes, report images, casts and out= assets go through it, so a document in ~ can't read ~/.ssh/id_ed25519 into its output or write over ~/.zshrc, and one in docs/ can't reach the rest of its repository. Being in a repository changes nothing: a document reaches its own folder only. Callers that trust the document skip it, as mdsh --allow-outside does.
Index ¶
Constants ¶
const MaxRead = 16 << 20
MaxRead is the most ReadFile reads by default: 16 MB.
Variables ¶
var ErrHidden error = hiddenError{}
ErrHidden is returned for a path inside the root that is, or is in, a hidden file or folder: one whose name starts with a dot, at any depth below the root. Those hold settings and secrets (.env, .ssh, .git's config with a token in a remote's URL, .git/hooks that run later), so they count as outside. It matches ErrOutside with errors.Is.
var ErrNotRegular = errors.New("not a regular file")
ErrNotRegular is returned for a folder, device, FIFO or other file that isn't a regular file.
var ErrOutside = errors.New("outside the document's folder (mdsh --allow-outside allows it)")
ErrOutside is returned for a path outside the document's folder.
var ErrTooBig = errors.New("file too large")
ErrTooBig is returned for a file larger than ReadFile's limit.
Functions ¶
func Hidden ¶ added in v1.6.0
Hidden reports whether rel, a clean path relative to a root, names a hidden file or folder or something in one: any part of it starting with a dot. The root itself (".") isn't hidden, so a document kept in a hidden folder still reaches its own folder.
func Inside ¶
Inside reports whether path, absolute and with symlinks resolved, is root or under it, and not hidden: see ErrHidden.
func ReadFile ¶
ReadFile reads path, which must be a regular file of at most max bytes (MaxRead if max <= 0). With root set, it must also be inside root; with root empty, anywhere is allowed.
func Resolve ¶
Resolve returns path with symlinks resolved, or ErrOutside if that is outside root, or ErrHidden if it is hidden. A path that doesn't exist yet, such as a file about to be written, is resolved through its nearest existing folder.
func Root ¶
Root returns the folder files for a document in dir must stay in: dir itself, absolute with symlinks resolved. A repository holding dir makes no difference.
Types ¶
This section is empty.