vfs

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package vfs abstracts the file-reading operations the scanner performs during cross-file resolution (Terraform sibling/variable globs, module directory reads, $ref includes). The CLI uses DiskFS — a thin passthrough to the real filesystem, behaviorally identical to direct os.* calls. The HTTP server uses an in-memory implementation built from content pushed over the wire, so it can resolve unsaved editor buffers and browser web-shell files that never touch disk.

The interface deliberately mirrors os/filepath (absolute OS paths, filepath glob semantics) rather than io/fs.FS, because the readers it serves operate on absolute paths and use filepath.Glob.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskFS

type DiskFS struct{}

DiskFS is the real-filesystem implementation used by the CLI. Each method is a direct passthrough to os/filepath, so threading DiskFS through the resolution code is behavior-preserving.

func (DiskFS) Abs

func (DiskFS) Abs(name string) (string, error)

Abs resolves name against the process working directory.

func (DiskFS) Glob

func (DiskFS) Glob(pattern string) ([]string, error)

Glob returns the files on disk matching pattern.

func (DiskFS) ReadDir

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

ReadDir reads the named directory from disk.

func (DiskFS) ReadFile

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

ReadFile reads the named file from disk.

func (DiskFS) Stat

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

Stat stats the named file on disk.

type FS

type FS interface {
	// ReadFile reads the named file and returns its contents.
	ReadFile(name string) ([]byte, error)
	// Stat returns file info for the named file.
	Stat(name string) (fs.FileInfo, error)
	// ReadDir reads the named directory, returning its entries.
	ReadDir(name string) ([]fs.DirEntry, error)
	// Glob returns the names matching pattern (filepath.Glob semantics).
	Glob(pattern string) ([]string, error)
	// Abs resolves name against the filesystem's root.
	Abs(name string) (string, error)
}

FS is the set of read operations the cross-file resolution code performs.

func Default

func Default() FS

Default returns the filesystem used when none is injected (the real disk).

type MemFS

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

MemFS is an in-memory FS built from content pushed over HTTP. Keys are normalized (cleaned, forward-slash) paths. It is request-scoped: a fresh instance is built per analyze request, so the missing-file set it accumulates belongs to exactly one scan and never leaks across requests.

Concurrency: Terraform module enrichment runs reader goroutines, so all access is guarded by a mutex.

func NewMemFS

func NewMemFS(files map[string][]byte) *MemFS

NewMemFS builds a MemFS from a path -> content map. Keys are normalized so they match the paths the Terraform readers compute via filepath.Join/Dir.

func (*MemFS) Abs

func (m *MemFS) Abs(name string) (string, error)

Abs keeps the path workspace-relative. This keeps Terraform module and missing-file paths relative to the request's own workspace, which is correct even when a single server process serves many IDE workspaces.

func (*MemFS) Glob

func (m *MemFS) Glob(pattern string) ([]string, error)

Glob returns pushed paths matching pattern (filepath.Glob semantics over the single directory level the Terraform readers use, e.g. "<dir>/*.tf"). A non-match is never recorded — an empty glob is legal, exactly as on disk.

func (*MemFS) MissingFiles

func (m *MemFS) MissingFiles() []string

MissingFiles returns the sorted set of paths the scan referenced but that were not pushed — the escalation list returned to the IDE.

func (*MemFS) Paths

func (m *MemFS) Paths() []string

Paths returns the sorted set of pushed file paths (used to seed the scan's file set in server mode).

func (*MemFS) ReadDir

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

ReadDir returns the immediate children of a directory synthesized from the pushed file keys. A miss (no file lives under the directory) is recorded: an absent directory is the primary escalation signal (a Terraform module whose source directory was not pushed).

func (*MemFS) ReadFile

func (m *MemFS) ReadFile(name string) ([]byte, error)

ReadFile returns a copy of the named file's content, or fs.ErrNotExist if it was not pushed (recording the miss for the escalation list).

func (*MemFS) Stat

func (m *MemFS) Stat(name string) (fs.FileInfo, error)

Stat reports whether the named file was pushed. A miss is NOT recorded: Stat is only used for speculative existence probes (terraform.tfvars, an optional vars file), so recording it would produce false escalations for files that legitimately do not exist.

Jump to

Keyboard shortcuts

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