pathutil

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(path string) (string, error)

Abs returns an absolute representation of path, but handles case-insensitive filesystems as described in the comment on Getwd for the case where the path is relative and the cwd needs to be obtained

func ExpandHomeDir

func ExpandHomeDir(homeDir string, path string) (string, error)

ExpandHomeDir expands a given path to its absolute form, handling home directory

func GetDrive

func GetDrive(path string) string

GetDrive extracts the drive letter or UNC share from a path.

func Getwd

func Getwd() (string, error)

Getwd returns the current working directory, but handles case-insensitive filesystems (i.e. MacOS defaults) and returns the path with the casing as it appears when doing list dir syscalls. For example, on a case-insensitive filesystem, you can do "cd /FoO/bAr" and os.Getwd will return "/FoO/bAr", but if you do "ls /" you may see "fOO" and if you do "ls /fOO" you may see "BAR", which creates inconsistent paths depending on if you are using Getwd or walking the filesystem.

func LexicalRelativePath

func LexicalRelativePath(cwdPath, modPath string) (string, error)

LexicalRelativePath computes a relative path between the current working directory and modPath without relying on runtime.GOOS to estimate OS-specific separators. This is necessary as the code runs inside a Linux container, but the user might have specified a Windows-style modPath.

func SandboxedRelativePath added in v0.20.0

func SandboxedRelativePath(userPath, root string) (string, error)

SandboxedRelativePath resolves userPath relative to root, ensuring the result stays within root. Absolute paths (including Windows drive-letter paths) are treated as relative to root. Returns an error if the resolved path would escape root via "..".

Both root and the returned path use forward slashes. Backslashes in userPath are normalized to forward slashes so that Windows-style paths are handled correctly even though the engine always runs on Linux.

Types

This section is empty.

Jump to

Keyboard shortcuts

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