vfs

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vfs is the file-access seam between dtctl commands and the filesystem. CLI invocations read and write the host filesystem directly (the default). Embedded invocations (the service engine, `dtctl serve`) install a per-request FS — typically a MapFS built from the request's virtual files — so `apply -f x.yaml` works against files that exist only in the request, and writebacks (e.g. `apply --write-id`) land back in the request instead of on the host (docs/dev/SERVICE_ENGINE_DESIGN.md).

Only user-supplied paths go through this seam. Internal scratch files (editor round-trip temp files, spill buffers, caches) deliberately stay on the host filesystem: they are implementation detail, not request state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(name string) string

Key is the name a MapFS keeps a file under: "x.yaml", "./x.yaml" and "/x.yaml" are one file. A caller matching paths against the files it hands a MapFS uses it instead of a rule of its own.

func ReadFile

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

ReadFile reads a user-supplied path through the active FS.

func ReadFileOrStdin

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

ReadFileOrStdin reads name through the active FS, with "-" meaning the process stdin. It is the shared implementation behind the CLI's file-or-stdin flag convention.

func WriteFile

func WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes a user-supplied path through the active FS.

Types

type Env

type Env struct {
	FS    FS
	Stdin io.Reader
}

Env is one invocation's view of the host for user-supplied paths: the filesystem they resolve against and the stream "-" reads from. An embedder that runs invocations concurrently hands each its own Env, because the package-level state below is swapped for the whole process and so can serve only one invocation at a time.

The zero value is the process default: the installed FS and os.Stdin, so a caller that never sets one behaves exactly as before.

func (Env) ReadFile

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

ReadFile reads a user-supplied path through e's FS.

func (Env) ReadFileOrStdin

func (e Env) ReadFileOrStdin(name string) ([]byte, error)

ReadFileOrStdin reads name through e's FS, with "-" meaning e's stdin.

func (Env) StdinReader

func (e Env) StdinReader() io.Reader

StdinReader is the stream "-" reads from: e's, else the process's.

func (Env) WriteFile

func (e Env) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes a user-supplied path through e's FS.

type FS

type FS interface {
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, data []byte, perm fs.FileMode) error
}

FS is the minimal file-access contract dtctl commands need for user-supplied paths: whole-file reads and whole-file writes.

func SetActive

func SetActive(f FS) FS

SetActive installs f as the file-access implementation and returns the previous one so callers can restore it. nil selects the host filesystem. Callers own serialization: install/restore must not race with an executing invocation.

type MapFS

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

MapFS is an in-memory FS for embedded invocations: the request's virtual files go in, and anything the invocation writes (writebacks, generated files) can be read back out with Files. Safe for concurrent use.

Paths are normalized with path.Clean and a stripped leading "/", so "./x.yaml", "x.yaml" and "/x.yaml" address the same entry — a request's virtual namespace has no meaningful root or working directory.

func NewMapFS

func NewMapFS(files map[string][]byte) *MapFS

NewMapFS builds a MapFS from the given files (copied; the input map is not retained). A nil map yields an empty filesystem.

func (*MapFS) Files

func (m *MapFS) Files() map[string][]byte

Files returns a snapshot of the current contents, keyed by normalized path. Embedders use it to hand written files back to the request's caller.

func (*MapFS) ReadFile

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

func (*MapFS) WriteFile

func (m *MapFS) WriteFile(name string, data []byte, _ fs.FileMode) error

Jump to

Keyboard shortcuts

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