gopathrs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: BSD-3-Clause, MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gopathrs is a less complete pure Go implementation of some of the APIs provided by libpathrs.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMode = errors.New("invalid permission mode")

ErrInvalidMode is returned from [MkdirAll] when the requested mode is invalid.

Functions

func MkdirAllHandle

func MkdirAllHandle(root *os.File, unsafePath string, mode os.FileMode) (_ *os.File, Err error)

MkdirAllHandle is equivalent to [MkdirAll], except that it is safer to use in two respects:

  • The caller provides the root directory as an *os.File (preferably O_PATH) handle. This means that the caller can be sure which root directory is being used. Note that this can be emulated by using /proc/self/fd/... as the root path with os.MkdirAll.

  • Once all of the directories have been created, an *os.File O_PATH handle to the directory at unsafePath is returned to the caller. This is done in an effectively-race-free way (an attacker would only be able to swap the final directory component), which is not possible to emulate with [MkdirAll].

In addition, the returned handle is obtained far more efficiently than doing a brand new lookup of unsafePath (such as with SecureJoin or openat2) after doing [MkdirAll]. If you intend to open the directory after creating it, you should use MkdirAllHandle.

func OpenatInRoot

func OpenatInRoot(root *os.File, unsafePath string) (*os.File, error)

OpenatInRoot is equivalent to [OpenInRoot], except that the root is provided using an *os.File handle, to ensure that the correct root directory is used.

func PartialLookupInRoot

func PartialLookupInRoot(root fd.Fd, unsafePath string) (*os.File, string, error)

PartialLookupInRoot tries to lookup as much of the request path as possible within the provided root (a-la RESOLVE_IN_ROOT) and opens the final existing component of the requested path, returning a file handle to the final existing component and a string containing the remaining path components.

Types

This section is empty.

Jump to

Keyboard shortcuts

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