Help us shape the future of Go! Take the 2026 Go Developer Survey

memfs

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package memfs implements an in-memory FileSystem suitable for use as the default backing store of a Bash sandbox. It supports regular files, directories, hard links (via shared content), symbolic links, permissions, mtime, and lazy file providers (see fs.FileInit).

All operations are protected by an internal sync.RWMutex. The implementation aims for byte-identical behavior with the just-bash TS in-memory FS where the surfaces overlap.

Index

Constants

MaxFollow caps symlink traversal at the FS layer. Matches fs.MaxSymlinkDepth.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS is the in-memory FileSystem.

func New

func New() *FS

New constructs an empty FS with a single root directory at "/".

func (*FS) AllPaths

func (m *FS) AllPaths() []string

AllPaths returns every regular file path in the FS. Used by glob expansion's getAllPaths in Phase 6.

func (*FS) AppendFile

func (m *FS) AppendFile(name string, data []byte, perm os.FileMode) error

AppendFile appends data to name, creating it if necessary.

func (*FS) Chmod

func (m *FS) Chmod(name string, mode os.FileMode) error

Chmod updates the permissions of name (following symlinks).

func (*FS) Chtimes

func (m *FS) Chtimes(name string, atime, mtime time.Time) error

Chtimes updates atime/mtime on name.

func (*FS) Create

func (m *FS) Create(name string) (gobashfs.File, error)

Create is shorthand for OpenFile(name, O_WRONLY|O_CREATE|O_TRUNC, 0o644).

func (m *FS) Link(oldpath, newpath string) error

Link creates a hard link at newpath pointing to the same content as oldpath. The two paths thereafter share the same content slice (writes through either become visible at the other).

func (*FS) Lstat

func (m *FS) Lstat(name string) (os.FileInfo, error)

Lstat returns a FileInfo without following the final symlink.

func (*FS) Mkdir

func (m *FS) Mkdir(name string, perm os.FileMode) error

Mkdir creates a single directory.

func (*FS) MkdirAll

func (m *FS) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates name and any missing parents.

func (*FS) Open

func (m *FS) Open(name string) (iofs.File, error)

Open implements iofs.FS. Read-only.

func (*FS) OpenFile

func (m *FS) OpenFile(name string, flag int, perm os.FileMode) (gobashfs.File, error)

OpenFile opens or creates a file according to the standard POSIX flags.

func (*FS) ReadDir

func (m *FS) ReadDir(name string) ([]iofs.DirEntry, error)

ReadDir lists the entries in name (a directory). Result is sorted by name to match the io/fs.ReadDirFS contract.

func (*FS) ReadFile

func (m *FS) ReadFile(name string) ([]byte, error)

ReadFile reads the entire contents of name into memory.

func (m *FS) Readlink(name string) (string, error)

Readlink returns the literal target of a symlink at name.

func (*FS) Realpath

func (m *FS) Realpath(name string) (string, error)

Realpath canonicalizes name: cleans the path, follows symlinks, and returns the absolute path to the underlying object. It is *not* an existence check by itself, but a non-existent path returns ErrNotExist.

func (*FS) Remove

func (m *FS) Remove(name string) error

Remove deletes a single file or empty directory.

func (*FS) RemoveAll

func (m *FS) RemoveAll(name string) error

RemoveAll deletes name and any descendants.

func (*FS) Rename

func (m *FS) Rename(oldpath, newpath string) error

Rename moves oldpath to newpath. Cross-directory renames are allowed.

func (*FS) Seed

func (m *FS) Seed(files map[string]gobashfs.FileInit) error

Seed loads the given FileInit map into the FS, creating parent directories as needed. It is intended for use by the gobash New() constructor when honoring BashOptions.Files.

func (*FS) SetMaxBytes

func (m *FS) SetMaxBytes(limit int64) error

SetMaxBytes sets a total regular-file content budget. Zero permits only empty files.

func (*FS) Stat

func (m *FS) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo for the named entry, following symlinks.

func (m *FS) Symlink(target, linkpath string) error

Symlink creates a symbolic link at linkpath pointing to target. The target string is stored verbatim; resolution happens at lookup time.

func (*FS) WriteFile

func (m *FS) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to name, creating or truncating as needed.

Jump to

Keyboard shortcuts

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