filesystem

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	jail.Jailed

	// ReadFile reads the contents of the file at path.
	// Relative paths are resolved from the current working directory.
	ReadFile(path string) ([]byte, error)
	// WriteFile writes data to path with the provided permissions.
	// Relative paths are resolved from the current working directory.
	WriteFile(path string, data []byte, perm os.FileMode) error
	// Mkdir creates a directory at path, using MkdirAll when all is true.
	// Relative paths are resolved from the current working directory.
	Mkdir(path string, perm os.FileMode, all bool) error
	// Remove deletes path, using recursive removal when all is true.
	// Relative paths are resolved from the current working directory.
	Remove(path string, all bool) error
	// Rename moves or renames src to dst.
	// Relative src and dst paths are resolved from the current working directory.
	Rename(src, dst string) error
	// Stat returns file metadata for path, following symlinks when requested.
	// Relative paths are resolved from the current working directory.
	Stat(path string, followSymlinks bool) (os.FileInfo, error)
	// ReadDir reads and returns directory entries for path.
	// Relative paths are resolved from the current working directory.
	ReadDir(path string) ([]os.DirEntry, error)
	// Symlink creates newname as a symbolic link to oldname.
	// Relative oldname and newname paths are resolved from the current working directory.
	Symlink(oldname, newname string) error
	// Glob returns paths matching the provided pattern.
	// Relative patterns are evaluated from the current working directory.
	Glob(pattern string) ([]string, error)
	// AtomicWriteFile writes data to path atomically with the provided permissions.
	// Relative paths are resolved from the current working directory.
	AtomicWriteFile(path string, data []byte, perm os.FileMode) error
	// Rel returns a relative path from basePath to targetPath.
	// Relative paths are resolved from the current working directory.
	Rel(basePath, targetPath string) (string, error)
	// Getwd returns the current working directory used for relative path resolution.
	Getwd() (string, error)
	// Setwd sets the current working directory to path.
	// Relative paths are resolved from the current working directory.
	Setwd(path string) error
	// ResolvePath resolves path to an absolute normalized path, optionally following symlinks.
	// Relative paths are resolved from the current working directory.
	ResolvePath(path string, followSymlinks bool) (string, error)
}

FileSystem defines the contract for filesystem operations operating on resolved/host filesystem paths.

Path and pattern inputs may be absolute or relative. Relative inputs are resolved against the implementation's current working directory as reported by Getwd and changed by Setwd.

type OsFS

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

OsFS is the canonical FileSystem implementation for host and jailed access.

When jail is empty, paths resolve against the host filesystem. When jail is set, all virtual absolute paths are mapped under jail on the host.

func NewOsFS

func NewOsFS(jailPath, wd string) (*OsFS, error)

NewOsFS constructs an OsFS with optional jail and initial working directory.

If wd is empty and jail is set, wd defaults to "/". If wd is empty and jail is not set, wd defaults to the process working directory.

func (*OsFS) AtomicWriteFile

func (fs *OsFS) AtomicWriteFile(path string, data []byte, perm os.FileMode) error

func (*OsFS) GetJail

func (fs *OsFS) GetJail() string

func (*OsFS) Getwd

func (fs *OsFS) Getwd() (string, error)

func (*OsFS) Glob

func (fs *OsFS) Glob(pattern string) ([]string, error)

func (*OsFS) Mkdir

func (fs *OsFS) Mkdir(path string, perm os.FileMode, all bool) error

func (*OsFS) ReadDir

func (fs *OsFS) ReadDir(path string) ([]os.DirEntry, error)

func (*OsFS) ReadFile

func (fs *OsFS) ReadFile(path string) ([]byte, error)

func (*OsFS) Rel

func (fs *OsFS) Rel(basePath, targetPath string) (string, error)

func (*OsFS) Remove

func (fs *OsFS) Remove(path string, all bool) error

func (*OsFS) Rename

func (fs *OsFS) Rename(src, dst string) error

func (*OsFS) ResolvePath

func (fs *OsFS) ResolvePath(path string, followSymlinks bool) (string, error)

func (*OsFS) SetJail

func (fs *OsFS) SetJail(jailPath string) error

func (*OsFS) Setwd

func (fs *OsFS) Setwd(path string) error

func (*OsFS) Stat

func (fs *OsFS) Stat(path string, followSymlinks bool) (os.FileInfo, error)
func (fs *OsFS) Symlink(oldname, newname string) error

func (*OsFS) WriteFile

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

Jump to

Keyboard shortcuts

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