docroot

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 7 Imported by: ? 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 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

View Source
const MaxRead = 16 << 20

MaxRead is the most ReadFile reads by default: 16 MB.

Variables

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

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

View Source
var ErrTooBig = errors.New("file too large")

ErrTooBig is returned for a file larger than ReadFile's limit.

Functions

func Inside

func Inside(root, path string) bool

Inside reports whether path, absolute and with symlinks resolved, is root or under it.

func ReadFile

func ReadFile(root, path string, max int64) ([]byte, error)

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

func Resolve(root, path string) (string, error)

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

func Root(dir string) string

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.

func WriteFile

func WriteFile(root, path string, data []byte) error

WriteFile writes data to path, making its folder. With root set, the path must be inside root once symlinks in it are resolved, and a symlink at path itself is not followed: the file is written to a temporary file beside it and renamed over it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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