safefs

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package safefs provides root-relative filesystem access for paths obtained from a repository or workspace. A Root keeps every operation below one directory, including when a path contains a symlink.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Root

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

Root is a filesystem view rooted at one directory.

The underlying os.Root rejects absolute paths and paths that escape the directory. Keeping that capability behind this small package makes the repository boundary explicit at call sites and gives all readers one common implementation.

func OpenRoot

func OpenRoot(path string) (*Root, error)

OpenRoot opens path as the root of a repository-local filesystem view.

func (*Root) Close

func (r *Root) Close() error

Close releases the resources held by the root.

func (*Root) Lstat

func (r *Root) Lstat(name string) (os.FileInfo, error)

Lstat returns metadata for the path itself, without following its final symlink. This is used when a repository wants to render a link target as text instead of reading the target's contents.

func (*Root) Open

func (r *Root) Open(name string) (*os.File, error)

Open opens a file or directory below the root.

func (*Root) OpenFile

func (r *Root) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile opens a file below the root with the given flags. Callers that must not follow a final symlink pass unix.O_NOFOLLOW (or the platform equivalent) in flag.

func (*Root) OpenRoot

func (r *Root) OpenRoot(name string) (*Root, error)

OpenRoot opens a child directory below the root and returns a filesystem view anchored to that directory. The child is resolved by the parent os.Root, so later path changes cannot turn it into a string-based escape.

func (*Root) ReadDir

func (r *Root) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads directory entries below the root.

func (*Root) ReadFile

func (r *Root) ReadFile(name string) ([]byte, error)

ReadFile reads a regular file below the root.

func (r *Root) Readlink(name string) (string, error)

Readlink reads the link target string for a path below the root. The target is returned as data; it is not followed by this operation.

func (*Root) Stat

func (r *Root) Stat(name string) (os.FileInfo, error)

Stat follows a path below the root and returns its metadata. A symlink that points outside the root is rejected by os.Root rather than followed.

Jump to

Keyboard shortcuts

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