vfs

package
v0.36.4 Latest Latest
Warning

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

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

Documentation

Overview

Package vfs is the loader's single point of filesystem contact.

Every read goes through it: build-constraint matching inside go/build, directory walking during pattern resolution, and source reading before parsing. One place to point at either the real filesystem or an fs.FS allows scanning a tree that was never written to disk possible at all.

It is its own package because both halves of the loader need it and neither owns it — resolution walks directories, and the loader reads the files resolution found.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS is the loader's single point of filesystem contact.

It exists so that every read — build-constraint matching inside go/build, directory walking during pattern resolution, and source reading before parsing — goes through one place that can be pointed at either the real filesystem or an fs.FS.

It is its own package because both halves of the loader need it and neither owns it: resolution walks directories, and the loader reads the files resolution found.

func New

func New(fsys fs.FS) *FS

New returns an FS reading through fsys, or through the os package when fsys is nil.

func (*FS) Base

func (v *FS) Base(p string) string

Base is the last element of a directory path, under whichever convention the path was written with.

path.Base is not a substitute: it looks for a forward slash, so on Windows it hands back "D:\src\vendor" whole, and every caller comparing a directory's name against a fixed one silently stops matching.

func (*FS) Clean

func (v *FS) Clean(p string) string

Clean maps a caller-supplied path onto the convention of the active backend.

io/fs requires slash-separated, unrooted paths, while callers naturally write OS paths and sometimes absolute ones. Normalising here (rather than rejecting) keeps the same patterns working against both backends.

A drive letter goes first, because it is what makes a Windows path absolute and it is not a separator: "D:\a" would otherwise survive as "D:/a" and address nothing inside the FS. Dropping it puts a rooted OS path in the same place the rooted POSIX form lands, which is the convention the option documents.

Both steps read the path rather than the host. A virtual filesystem need not have been built on the machine that is scanning it — an embedded or recorded tree carries the shape it was captured with — so deferring to the host (as filepath.ToSlash and filepath.VolumeName do) would normalise a Windows-shaped tree only when Windows was reading it. The cost is that a backslash cannot be part of a name here, which is already true wherever such a tree came from.

func (*FS) HasSubdir

func (v *FS) HasSubdir(root, dir string) (string, bool)

HasSubdir reports whether dir is within root, and if so its relative path.

func (*FS) IsAbs

func (v *FS) IsAbs(p string) bool

func (*FS) IsDir

func (v *FS) IsDir(p string) bool

func (*FS) Join

func (v *FS) Join(elem ...string) string

func (*FS) Open

func (v *FS) Open(p string) (io.ReadCloser, error)

func (*FS) ReadDir

func (v *FS) ReadDir(dir string) ([]fs.FileInfo, error)

ReadDir returns fs.FileInfo values because that is what go/build's ReadDir hook requires.

func (*FS) ReadFile

func (v *FS) ReadFile(p string) ([]byte, error)

func (*FS) Virtual

func (v *FS) Virtual() bool

func (*FS) WalkDirs

func (v *FS) WalkDirs(root string, yield func(string) error) error

WalkDirs yields every directory at or below root, in lexical order.

Jump to

Keyboard shortcuts

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