fspath

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 5 Imported by: 0

README

fspath

Go library with functions for performing path lookups in fs.FS file systems

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLoop is returned when attempting to resolve paths that have followed
	// too many symbolic links.
	ErrLoop = errors.New("loop")
)

Functions

func Lookup

func Lookup(fsys fs.FS, name string) (fs.FS, string, error)

Lookup looks for the name if fsys, following symbolic link that are encountered along the path.

The function returns a view of fsys positioned on the last directory, and the base name of the file to look for in this directory. The name is guaranteed not to refer to a symbolic link.

The function guarantees that links never escape the file system root. If a link pointing above the root is encountered, it is rebased off of the root similarly to how "/.." resolves to "/" on posix systems. Lookup can therefore be used as a sandboxing mechanism to prevent escaping the bounds of a read-only file system; beware that if the underlying file system can be modified concurrently, these guarantees do no apply anymore!

func Open

func Open(fsys fs.FS, name string) (fs.File, error)

func ReadDir

func ReadDir(fsys fs.FS, name string) ([]fs.DirEntry, error)

func ReadFile

func ReadFile(fsys fs.FS, name string) ([]byte, error)
func ReadLink(fsys fs.FS, name string) (string, error)

func RootFS

func RootFS(fsys fs.FS) fs.FS

RooFS returns a fs.FS wrapping fsys and using the Lookup function when accesing files (e.g. calling Open, Stat, etc...).

func Stat

func Stat(fsys fs.FS, name string) (fs.FileInfo, error)

func Sub

func Sub(fsys fs.FS, name string) (fs.FS, error)

func Walk

func Walk(name string, fn func(path string) error) error

Walk calls fn for each path prefix of name up to the full name.

For a path such as "a/b/c", calling Walk("a/b/c", fn) will invoke fn with fn("a"), fn("a/b"), then fn("a/b/c"). If any of these calls returns an error, the walk is aborted and the error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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