workingcopy

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 7 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 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

Constants

This section is empty.

Variables

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

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

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

func File(root, rel string) (string, error)

File returns the on-disk path of the regular file rel inside root, with the same checks as Path.

func Glob

func Glob(root, pattern string) ([]string, error)

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

func Path(root, rel string) (string, error)

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

func ReadDir(root, rel string) ([]fs.DirEntry, error)

ReadDir returns the entries of directory rel inside root, leaving out symbolic links. Use "." for the root itself.

func ReadFile

func ReadFile(root, rel string) ([]byte, error)

ReadFile returns the content of the regular file rel inside root.

func Stat

func Stat(root, rel string) (fs.FileInfo, error)

Stat returns file information for rel inside root without following symbolic links; a symbolic link is reported as ErrSymlink.

func WalkDir

func WalkDir(root, rel string, fn fs.WalkDirFunc) error

WalkDir walks the tree rooted at rel inside root (use "." for the whole working copy), calling fn with paths relative to root. Symbolic links are skipped: fn never sees one, and they are never descended into.

Types

This section is empty.

Jump to

Keyboard shortcuts

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