fsys

Imports

Imports #

"cmd/go/internal/str"
"encoding/json"
"errors"
"fmt"
"internal/godebug"
"io"
"io/fs"
"iter"
"log"
"maps"
"os"
pathpkg "path"
"path/filepath"
"runtime/debug"
"slices"
"strings"
"sync"
"time"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"io/fs"
"path/filepath"

Constants & Variables

OverlayFile var #

OverlayFile is the -overlay flag value. It names a file containing the JSON for an overlayJSON struct.

var OverlayFile string

binds var #

var binds []replace

cwd var #

cwd returns the current directory, caching it on first use.

var cwd = *ast.CallExpr

doTrace var #

var doTrace bool

errNotDir var #

errNotDir is used to communicate from ReadDir to IsGoDir that the argument is not a directory, so that IsGoDir doesn't return an error.

var errNotDir = *ast.CallExpr

gofsystrace var #

var gofsystrace = *ast.CallExpr

gofsystracelog var #

var gofsystracelog = *ast.CallExpr

gofsystracestack var #

var gofsystracestack = *ast.CallExpr

overlay var #

overlay is a list of replacements to be applied, sorted by cmp of the from field. cmp sorts the filepath.Separator less than any other byte so that x is always just before any children x/a, x/b, and so on, before x.go. (This would not be the case with byte-wise sorting, which would produce x, x.go, x/a.) The sorting lets us find the relevant overlay entry quickly even if it is for a parent of the path being searched.

var overlay []replace

traceFile var #

var traceFile *os.File

traceMu var #

var traceMu sync.Mutex

Type Aliases

fakeDir type #

fakeDir provides an fs.FileInfo implementation for directories that are implicitly created by overlaid files. Each directory in the path of an overlaid file is considered to exist in the overlay filesystem.

type fakeDir string

missingFile type #

missingFile provides an fs.FileInfo for an overlaid file where the destination file in the overlay doesn't exist. It returns zero values for the fileInfo methods other than Name, set to the file's name, and Mode set to ModeIrregular.

type missingFile string

Structs

fakeFile struct #

fakeFile provides an fs.FileInfo implementation for an overlaid file, so that the file has the name of the overlaid file, but takes all other characteristics of the replacement file.

type fakeFile struct {
name string
real fs.FileInfo
}

info struct #

info is a summary of the known information about a path being looked up in the virtual file system.

type info struct {
abs string
deleted bool
replaced bool
dir bool
file bool
actual string
}

overlayJSON struct #

overlayJSON is the format for the -overlay file.

type overlayJSON struct {
Replace map[string]string
}

replace struct #

A replace represents a single replaced path.

type replace struct {
from string
to string
}

Functions

Actual function #

Actual returns the actual file system path for the named file. It returns the empty string if name has been deleted in the virtual file system.

func Actual(name string) string

Bind function #

Bind makes the virtual file system use dir as if it were mounted at mtpt, like Plan 9's “bind” or Linux's “mount --bind”, or like os.Symlink but without the symbolic link. For now, the behavior of using Bind on multiple overlapping mountpoints (for example Bind("x", "/a") and Bind("y", "/a/b")) is undefined.

func Bind(dir string, mtpt string)

Glob function #

Glob is like filepath.Glob but uses the overlay file system.

func Glob(pattern string) (matches []string, err error)

Init function #

Init initializes the overlay, if one is being used.

func Init() error

IsDir function #

IsDir returns true if path is a directory on disk or in the overlay.

func IsDir(path string) (bool, error)

IsDir method #

func (f fakeDir) IsDir() bool

IsDir method #

func (f missingFile) IsDir() bool

IsDir method #

func (f fakeFile) IsDir() bool

IsGoDir function #

IsGoDir reports whether the named directory in the virtual file system is a directory containing one or more Go source files.

func IsGoDir(name string) (bool, error)

Lstat function #

Lstat returns a FileInfo describing the named file in the virtual file system. It does not follow symbolic links

func Lstat(name string) (fs.FileInfo, error)

ModTime method #

func (f fakeDir) ModTime() time.Time

ModTime method #

func (f fakeFile) ModTime() time.Time

ModTime method #

func (f missingFile) ModTime() time.Time

Mode method #

func (f missingFile) Mode() fs.FileMode

Mode method #

func (f fakeFile) Mode() fs.FileMode

Mode method #

func (f fakeDir) Mode() fs.FileMode

Name method #

func (f fakeDir) Name() string

Name method #

func (f missingFile) Name() string

Name method #

func (f fakeFile) Name() string

Open function #

Open opens the named file in the virtual file system. It must be an ordinary file, not a directory.

func Open(name string) (*os.File, error)

ReadDir function #

ReadDir reads the named directory in the virtual file system.

func ReadDir(name string) ([]fs.DirEntry, error)

ReadFile function #

ReadFile reads the named file from the virtual file system and returns the contents.

func ReadFile(name string) ([]byte, error)

Replaced function #

Replaced reports whether the named file has been modified in the virtual file system compared to the OS file system.

func Replaced(name string) bool

Size method #

func (f fakeFile) Size() int64

Size method #

func (f fakeDir) Size() int64

Size method #

func (f missingFile) Size() int64

Stat function #

Stat returns a FileInfo describing the named file in the virtual file system. It follows symbolic links.

func Stat(name string) (fs.FileInfo, error)

String method #

func (f fakeDir) String() string

String method #

func (f fakeFile) String() string

String method #

func (f missingFile) String() string

Sys method #

func (f missingFile) Sys() any

Sys method #

func (f fakeDir) Sys() any

Sys method #

func (f fakeFile) Sys() any

Trace function #

Trace emits a trace event for the operation and file path to the trace log, but only when $GODEBUG contains gofsystrace=1. The traces are appended to the file named by the $GODEBUG setting gofsystracelog, or else standard error. For debugging, if the $GODEBUG setting gofsystracestack is non-empty, then trace events for paths matching that glob pattern (using path.Match) will be followed by a full stack trace.

func Trace(op string, path string)

WalkDir function #

WalkDir is like filepath.WalkDir but over the virtual file system.

func WalkDir(root string, fn fs.WalkDirFunc) error

abs function #

abs returns the absolute form of path, for looking up in the overlay map. For the most part, this is filepath.Abs and filepath.Clean, except that Windows requires special handling, as always.

func abs(path string) string

children method #

children returns a sequence of (name, info) for all the children of the directory i implied by the overlay.

func (i *info) children() *ast.IndexListExpr

cleanGlobPath function #

cleanGlobPath prepares path for glob matching.

func cleanGlobPath(path string) string

cleanGlobPathWindows function #

cleanGlobPathWindows is windows version of cleanGlobPath.

func cleanGlobPathWindows(path string) (prefixLen int, cleaned string)

cmp function #

func cmp(x string, y string) int

cwdOnce function #

func cwdOnce() string

glob function #

glob searches for files matching pattern in the directory dir and appends them to matches. If the directory cannot be opened, it returns the existing matches. New matches are added in lexicographical order.

func glob(dir string, pattern string, matches []string) (m []string, e error)

hasMeta function #

hasMeta reports whether path contains any of the magic characters recognized by filepath.Match.

func hasMeta(path string) bool

init function #

func init()

initFromJSON function #

func initFromJSON(js []byte) error

osReadDir function #

osReadDir is like os.ReadDir corrects the error to be errNotDir if the problem is that name exists but is not a directory.

func osReadDir(name string) ([]fs.DirEntry, error)

overlayStat function #

overlayStat implements lstat or Stat (depending on whether os.Lstat or os.Stat is passed in).

func overlayStat(op string, path string, osStat func(string) (fs.FileInfo, error)) (fs.FileInfo, error)

searchcmp function #

func searchcmp(r replace, t string) int

stat function #

stat returns info about the path in the virtual file system.

func stat(path string) info

volumeNameLen function #

func volumeNameLen(path string) int

walkDir function #

walkDir recursively descends path, calling walkDirFn.

func walkDir(path string, d fs.DirEntry, walkDirFn fs.WalkDirFunc) error

Generated with Arrow