virtfs

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package virtfs provides a virtual file tree. It is intended to be used to build a tree that can be written to a new file system or archive that takes an io/fs.FS. It supports symbolic links and implements io/fs.ReadLinkFS.

For memory efficiency regular files are not copied into the virtual fs itself. Instead, their original source path is just mapped to the virtual fs path. Opening the virtual file opens the original file underneath.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileNotExist is returned if a tree node that is looked up does not
	// exist.
	ErrFileNotExist = fs.ErrNotExist

	// ErrFileExist is returned if a tree node exists that was not expected.
	ErrFileExist = fs.ErrExist

	// ErrFileInvalid is returned if a file is invalid for the requested
	// operation.
	ErrFileInvalid = fs.ErrInvalid

	// ErrFileNotDir is returned if a file exists but is not a directory.
	ErrFileNotDir = errors.New("not a directory")

	// ErrFileNotRegular is returned if the source is not a regular file.
	ErrFileNotRegular = errors.New("source is not a regular file")

	// ErrInvalidArgument is returned if an invalid argument is given.
	ErrInvalidArgument = errors.New("invalid argument")

	// ErrSymlinkTooDeep is returned if there are too many symbolic links to
	// follow.
	ErrSymlinkTooDeep = errors.New("nested links too deep")
)

Functions

This section is empty.

Types

type FS

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

FS represents a simple fs.FS that supports directories, regular files and symbolic links

Regular files that should be copied from another source can be added with FS.Add.It supports adding symbolic links with FS.Symlink. Use FS.Mkdir or FS.MkdirAll to create any required directories beforehand.

func New

func New() *FS

New creates a new FS.

func (*FS) Add

func (fsys *FS) Add(name string, openFn FileOpenFunc) error

Add creates a new regular file with the given name.

File content is read from the file returned by the given FileOpenFunc. It returns a PathError in case of errors.

func (*FS) Lstat

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

Lstat returns information about the file with the given name.

It returns a PathError in case of errors. It does not follow symbolic links and returns symbolic links directly.

func (*FS) Mkdir

func (fsys *FS) Mkdir(name string) error

Mkdir creates a new directory with the given name.

It returns PathError in case of errors.

func (*FS) MkdirAll

func (fsys *FS) MkdirAll(name string) error

MkdirAll creates a directory with the given name along with all necessary parents.

It returns a PathError in case of errors. If the directory exists already, it does nothing and returns nil.

func (*FS) Open

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

Open opens the named file.

It returns a PathError in case of errors. It does not follow symbolic links and returns symbolic links directly.

func (fsys *FS) ReadLink(name string) (string, error)

ReadLink returns the target of the symbolic link with the given name.

It returns a PathError in case of errors. It returns ErrFileInvalid in case the file is not a symbolic link.

func (fsys *FS) Symlink(oldname, newname string) error

Symlink adds a new symbolic link that links to oldname at newname.

It returns a PathError in case of errors.

type FileOpenFunc

type FileOpenFunc func() (fs.File, error)

FileOpenFunc returns an open fs.File or an error if opening fails.

type PathError

type PathError = fs.PathError

PathError records an error and the operation and file path that caused it.

Jump to

Keyboard shortcuts

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