Documentation
¶
Overview ¶
Package workingcopy reads files inside a repository working copy without following symbolic links.
A working copy holds content chosen by whoever controls the repository. A symbolic link committed to it can point anywhere on the host: another repository's clone, a configuration file, /proc. Every read of working-copy content must therefore go through this package, which refuses any path whose components (below the working-copy root) include a symbolic link, and opens files through os.Root so a path can never resolve outside the root.
The root itself is trusted: it is a directory kodit created or was configured with, and may legitimately sit under a symlinked parent such as /tmp on macOS.
Index ¶
- Variables
- func File(root, rel string) (string, error)
- func Glob(root, pattern string) ([]string, error)
- func Path(root, rel string) (string, error)
- func ReadDir(root, rel string) ([]fs.DirEntry, error)
- func ReadFile(root, rel string) ([]byte, error)
- func Stat(root, rel string) (fs.FileInfo, error)
- func WalkDir(root, rel string, fn fs.WalkDirFunc) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotRegular = errors.New("not a regular file")
ErrNotRegular is returned when a path names something other than a regular file where file content was requested.
var ErrOutsideRoot = errors.New("path is outside the working copy")
ErrOutsideRoot is returned when a relative path is absolute or leaves the working-copy root.
var ErrSymlink = errors.New("symbolic links in working copies are not followed")
ErrSymlink is returned when a path inside a working copy is, or passes through, a symbolic link.
Functions ¶
func File ¶
File returns the on-disk path of the regular file rel inside root, with the same checks as Path.
func Glob ¶
Glob returns the paths, relative to root, of entries inside root matching pattern (filepath.Match syntax, relative to root) that are not and do not pass through a symbolic link.
func Path ¶
Path returns the on-disk path of rel inside root after checking that rel stays inside root and that neither rel nor any directory leading to it is a symbolic link. Use it only to hand a path to code that opens it itself (document renderers, rasterizers); use ReadFile to read content.
func ReadDir ¶
ReadDir returns the entries of directory rel inside root, leaving out symbolic links. Use "." for the root itself.
Types ¶
This section is empty.