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 ¶
- type FS
- func (v *FS) Base(p string) string
- func (v *FS) Clean(p string) string
- func (v *FS) HasSubdir(root, dir string) (string, bool)
- func (v *FS) IsAbs(p string) bool
- func (v *FS) IsDir(p string) bool
- func (v *FS) Join(elem ...string) string
- func (v *FS) Open(p string) (io.ReadCloser, error)
- func (v *FS) ReadDir(dir string) ([]fs.FileInfo, error)
- func (v *FS) ReadFile(p string) ([]byte, error)
- func (v *FS) Virtual() bool
- func (v *FS) WalkDirs(root string, yield func(string) error) error
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 (*FS) Base ¶
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 ¶
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.