safepath

package
v26.0.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrEscapesBase

type ErrEscapesBase struct {
	Base, Subpath string
}

ErrEscapesBase is returned by Join when the resulting concatenation would point outside of the specified base directory.

func (*ErrEscapesBase) Error

func (e *ErrEscapesBase) Error() string

func (*ErrEscapesBase) InvalidParameter

func (*ErrEscapesBase) InvalidParameter()

type ErrNotAccessible

type ErrNotAccessible struct {
	Path  string
	Cause error
}

ErrNotAccessible is returned by Join when the resulting path doesn't exist, is not accessible, or any of the path components was replaced with a symlink during the path traversal.

func (*ErrNotAccessible) Error

func (e *ErrNotAccessible) Error() string

func (*ErrNotAccessible) NotFound

func (*ErrNotAccessible) NotFound()

func (*ErrNotAccessible) Unwrap

func (e *ErrNotAccessible) Unwrap() error

type SafePath

type SafePath struct {
	// contains filtered or unexported fields
}

func Join

func Join(_ context.Context, path, subpath string) (*SafePath, error)

Join makes sure that the concatenation of path and subpath doesn't resolve to a path outside of path and returns a path to a temporary file that is a bind mount to the exact same file/directory that was validated.

After use, it is the caller's responsibility to call Close on the returned SafePath object, which will unmount the temporary file/directory and remove it.

func (*SafePath) Close

func (s *SafePath) Close(ctx context.Context) error

Close releases the resources used by the path.

func (*SafePath) IsValid

func (s *SafePath) IsValid() bool

IsValid return true when path can still be used and wasn't cleaned up by Close.

func (*SafePath) Path

func (s *SafePath) Path() string

Path returns a safe, temporary path that can be used to access the original path.

func (*SafePath) SourcePath

func (s *SafePath) SourcePath() (string, string)

SourcePath returns the source path the safepath points to.

Jump to

Keyboard shortcuts

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