vfs

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirPerm        = os.ModeDir | os.ModePerm
	FilePerm       = 0666
	NoWriteDirPerm = 0555 | os.ModeDir
	TempDirPerm    = os.ModePerm | os.ModeSticky | os.ModeDir

	// MaxLinkDepth is a maximum number of nested symlinks to resolve
	MaxLinkDepth = 4
)

Variables

This section is empty.

Functions

func ConcatFiles

func ConcatFiles(fs FS, sources []string, target string) (err error)

ConcatFiles copies source files to a target file using the FS interface. Source files are concatenated into the target file in the given order. If the target is a directory, the source is copied into that directory using the name of the first source file. The result keeps the file mode of the first source.

func CopyDir

func CopyDir(vfs FS, srcRoot, destRoot string, recursive bool, onCopy func(destPath string) error) error

CopyDir walks over the provided source directory and copies each file under the destination directory. Optionally, a callback function may be executed for each destination path.

Does nothing if the source directory is an empty string or contains no files.

func CopyFile

func CopyFile(fs FS, source string, target string) error

CopyFile copies source file to a target file using the FS interface. If the target is a directory, the source is copied into that directory using a source name file. File mode is preserved.

func DirSize

func DirSize(fs FS, path string, excludes ...string) (int64, error)

DirSize returns the accumulated size of all files in a directory. The result is in bytes.

func DirSizeMB

func DirSizeMB(fs FS, path string, excludes ...string) (uint, error)

DirSizeMB returns the accumulated size of all files in a directory. The result is in megabytes.

func Exists

func Exists(fs FS, path string, follow ...bool) (bool, error)

Exists verifies if a file or directory exists. Optionally, a follow parameter may be provided to follow symlinks.

func FindFile

func FindFile(vfs FS, rootDir string, patterns ...string) (string, error)

FindFile attempts to find a file from a list of patterns on top of a given root path. Returns first match if any and returns error otherwise.

func FindFiles

func FindFiles(vfs FS, rootDir string, pattern string) ([]string, error)

FindFiles attempts to find files from a given pattern on top of a root path. Returns empty list if no files are found.

func FindKernel

func FindKernel(fs FS, rootDir string) (string, string, error)

FindKernel finds for kernel files inside a given root tree path. Returns kernel file and version. It assumes kernel files match certain patterns

func FindKernelHmac

func FindKernelHmac(fs FS, kernel string) (string, error)

FindKernelHmac returns the path to an existing kernel .hmac file

func ForceRemoveAll

func ForceRemoveAll(vfs FS, path string) error

ForceRemoveAll removes the specified path.

If it fails to remove some paths, it tries to reset the write permission for all files and directories and attempts a removal again.

func IsDir

func IsDir(f FS, path string, follow ...bool) (bool, error)

IsDir checks if a given path is a directory. Optionally, a follow parameter may be provided to follow symlinks.

func LoadEnvFile

func LoadEnvFile(fs FS, file string) (map[string]string, error)

LoadEnvFile parses a file and constructs a map with the respective key-value pairs.

func MkdirAll

func MkdirAll(fileSystem FS, path string, perm fs.FileMode) error

MkdirAll is equivalent to os.MkdirAll but operates on an FS. Code ported from go-vfs library.

func ReadLink(fs FS, name string) (string, error)

ReadLink calls fs.Readlink but trims temporary prefix on the result.

func ResolveLink(vfs FS, path string, rootDir string, depth int) (string, error)

ResolveLink attempts to resolve a symlink, if any. Returns the original path if not a symlink or if it can't be resolved.

func TempDir

func TempDir(fs FS, dir, prefix string) (name string, err error)

TempDir creates a temporary directory in the virtual fs dir defines the parent directory to create into, if empty it relies on the OS default TMP directory. The prefix is used to name new temporary directory.

func TempFile

func TempFile(fs FS, dir, pattern string) (f *os.File, err error)

TempFile creates a temp file in the virtual FS. Took from afero.FS code and adapted.

func WalkDirFs

func WalkDirFs(fs FS, root string, fn fs.WalkDirFunc) error

WalkDirFs is the same as filepath.WalkDir but accepts an FS so it can be run on any FS type.

func WriteEnvFile

func WriteEnvFile(fs FS, envs map[string]string, filename string) error

WriteEnvFile writes an environment file with the given key-value pairs.

Types

type FS

type FS interface {
	Chmod(name string, mode fs.FileMode) error
	Create(name string) (*os.File, error)
	Link(oldname, newname string) error
	Lstat(name string) (fs.FileInfo, error)
	Mkdir(name string, perm fs.FileMode) error
	Open(name string) (fs.File, error)
	OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
	RawPath(name string) (string, error)
	ReadDir(dirname string) ([]fs.DirEntry, error)
	ReadFile(filename string) ([]byte, error)
	Readlink(name string) (string, error)
	Remove(name string) error
	RemoveAll(name string) error
	Rename(oldpath, newpath string) error
	Stat(name string) (fs.FileInfo, error)
	Symlink(oldname, newname string) error
	WriteFile(filename string, data []byte, perm fs.FileMode) error
}

func New

func New() FS

Jump to

Keyboard shortcuts

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