safepath

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package safepath constrains filesystem paths for user-controlled inputs (cache roots, config discovery, recipe files) and performs reads/writes via os.Root where appropriate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinUnder

func JoinUnder(root string, parts ...string) (string, error)

JoinUnder returns filepath.Join(root, parts...) if the result stays under root.

func OpenReadWriteProbe

func OpenReadWriteProbe(path string) (err error)

OpenReadWriteProbe returns nil if path is a regular file that can be opened read-write via os.Root on the parent directory (used to detect user-writable known_hosts files).

func ReadFile

func ReadFile(path string) (data []byte, err error)

ReadFile reads path using os.Root on the parent directory so the basename cannot traverse.

func Stat

func Stat(path string) (info os.FileInfo, err error)

Stat stats path using os.Root on the parent directory.

func Under

func Under(root, path string) error

Under returns nil if path equals root or is a subdirectory of root (after absolute resolution).

func WriteFile

func WriteFile(path string, data []byte, perm os.FileMode) (err error)

WriteFile writes data to path using a temp file and rename within os.Root of the parent directory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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