linkpath

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 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 linkpath resolves symlink chains physically so containment checks can see where a link really points, including links whose final components do not exist yet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escapes

func Escapes(links map[string]string, from string) bool

Escapes reports whether the symlink at from leaves the tree that links describes. The tree is recorded, not read from disk: links maps the slash-separated path of every symlink, relative to the tree root, to its target. Resolution follows the recorded links exactly like Resolve follows physical ones (a dangling tail is resolved lexically), so the answer cannot change when the files the links were read from change afterwards. A link chain that loops does not escape.

func Resolve

func Resolve(target string) (string, error)

Resolve returns the physical absolute path that target refers to. It follows every symlink it meets, like filepath.EvalSymlinks. Unlike EvalSymlinks, it also resolves a path whose tail does not exist: the longest existing prefix is resolved physically, and the missing remainder is joined lexically. A dangling link therefore still reports where it would land once the missing path is created. Parent components are applied only after the symlinks before them are resolved, so "link/../x" is not collapsed to a sibling of "link".

Resolve fails with errUtils.ErrSymlinkLoop when the links form a loop, with errUtils.ErrPathThroughNonDirectory when the path passes through a non-directory, and with another error when it cannot be inspected. Callers decide separately what each failure means.

func ResolveRecorded

func ResolveRecorded(links map[string]string, from string) (string, bool)

ResolveRecorded returns the slash-separated path, relative to the tree root, that from refers to once every recorded link on the way is followed. Like Escapes it reads only links, never the disk, so a caller can test where a captured link lands without looking at the source again. The root itself resolves to the empty path. ResolveRecorded reports false when the chain leaves the tree or loops, because neither names a path inside the tree.

func TraversedRecorded

func TraversedRecorded(links map[string]string, from string) ([]string, bool)

TraversedRecorded returns, in the order the filesystem looks them up, the slash-separated path of every entry that resolving from through the recorded links passes through, relative to the tree root. A parent component is applied only after the directory before it was looked up, so "cache/p/../x" traverses "cache" and "cache/p" even though it reduces to "x". Paths reached through a recorded link are reported by the physical location they resolve to. It reports false when the chain leaves the tree or loops.

func Within

func Within(root, target string) bool

Within reports whether target is root or lies beneath it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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