Documentation
¶
Overview ¶
Package docroot keeps a document's reads and writes inside the folder it belongs to: the root of the git (or Mercurial, Jujutsu or Subversion) repository holding it, or the document's own folder when it isn't in one. Includes, report images, casts and out= assets go through it, so a document can't read ~/.ssh/id_ed25519 into its output or write over ~/.zshrc. 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 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 or repository (mdsh --allow-outside allows it)")
ErrOutside is returned for a path outside the document's root.
var ErrTooBig = errors.New("file too large")
ErrTooBig is returned for a file larger than ReadFile's limit.
Functions ¶
func Inside ¶
Inside reports whether path, absolute and with symlinks resolved, is root or under it.
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. 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: the root of the repository holding dir, else dir itself. A repository at the home folder or the file system's root, such as a dotfiles repository, is not used, as it would let a document reach everything under it; dir is used instead. The result is absolute with symlinks resolved.
Types ¶
This section is empty.