dispatch

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvCacheDir        = "AL_CACHE_DIR"
	EnvNoNetwork       = "AL_NO_NETWORK"
	EnvVersionOverride = "AL_VERSION"
	EnvShimActive      = "AL_SHIM_ACTIVE"
)

EnvCacheDir, EnvNoNetwork, EnvVersionOverride, and EnvShimActive define dispatch environment keys.

Variables

ErrDispatched signals that execution has been handed off to another binary.

Functions

func MaybeExec

func MaybeExec(args []string, currentVersion string, cwd string, stderr io.Writer, exit func(int)) error

MaybeExec checks for a pinned version and dispatches to it when needed. It returns ErrDispatched if execution was handed off.

func MaybeExecWithSystem added in v0.5.7

func MaybeExecWithSystem(sys System, args []string, currentVersion string, cwd string, exit func(int)) error

MaybeExecWithSystem checks for a pinned version and dispatches to it when needed. It returns ErrDispatched if execution was handed off.

func PrefetchVersion added in v0.8.0

func PrefetchVersion(versionInput string, progressOut io.Writer) error

PrefetchVersion ensures the requested release binary is cached locally. It validates the version, resolves the cache root, downloads the binary when missing, and writes download progress to progressOut.

Types

type RealSystem added in v0.5.7

type RealSystem struct {
	StderrWriter io.Writer
}

RealSystem implements System using the OS and root finder.

func (RealSystem) Chmod added in v0.9.2

func (RealSystem) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file.

func (RealSystem) CreateTemp added in v0.9.2

func (RealSystem) CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp creates a new temporary file in the directory dir.

func (RealSystem) Environ added in v0.5.7

func (RealSystem) Environ() []string

Environ returns a copy of strings representing the environment.

func (RealSystem) ExecBinary added in v0.5.7

func (RealSystem) ExecBinary(path string, args []string, env []string, exit func(int)) error

ExecBinary replaces the current process with the provided binary.

func (RealSystem) FileSync added in v0.9.2

func (RealSystem) FileSync(f *os.File) error

FileSync commits the current contents of the file to stable storage.

func (RealSystem) FindAgentLayerRoot added in v0.5.7

func (RealSystem) FindAgentLayerRoot(start string) (string, bool, error)

FindAgentLayerRoot searches upwards from start for an .agent-layer directory.

func (RealSystem) Flock added in v0.9.2

func (RealSystem) Flock(fd int, how int) error

Flock applies or removes an advisory lock on the file represented by fd.

func (RealSystem) Getenv added in v0.5.7

func (RealSystem) Getenv(key string) string

Getenv returns the value of the environment variable named by key.

func (RealSystem) HTTPClient added in v0.9.2

func (RealSystem) HTTPClient() *http.Client

HTTPClient returns the shared HTTP client for download operations.

func (RealSystem) PlatformStrings added in v0.9.2

func (RealSystem) PlatformStrings() (string, string, error)

PlatformStrings returns the supported OS and architecture strings for release assets.

func (RealSystem) ReadFile added in v0.5.7

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

ReadFile reads the named file and returns the contents.

func (RealSystem) Rename added in v0.9.2

func (RealSystem) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath.

func (RealSystem) Sleep added in v0.9.2

func (RealSystem) Sleep(d time.Duration)

Sleep pauses the current goroutine for at least the duration d.

func (RealSystem) Stat added in v0.9.2

func (RealSystem) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file.

func (RealSystem) Stderr added in v0.7.0

func (r RealSystem) Stderr() io.Writer

Stderr returns the standard error writer.

func (RealSystem) UserCacheDir added in v0.5.7

func (RealSystem) UserCacheDir() (string, error)

UserCacheDir returns the default user cache directory.

type System added in v0.5.7

type System interface {
	UserCacheDir() (string, error)
	ReadFile(name string) ([]byte, error)
	Getenv(key string) string
	Environ() []string
	ExecBinary(path string, args []string, env []string, exit func(int)) error
	FindAgentLayerRoot(start string) (string, bool, error)
	Stderr() io.Writer
	Stat(name string) (os.FileInfo, error)
	Chmod(name string, mode os.FileMode) error
	Rename(oldpath, newpath string) error
	CreateTemp(dir, pattern string) (*os.File, error)
	FileSync(f *os.File) error
	PlatformStrings() (string, string, error)
	Sleep(d time.Duration)
	HTTPClient() *http.Client
	Flock(fd int, how int) error
}

System abstracts OS operations needed by version dispatch. This interface is intentionally package-local per Decision edefea6 to enable parallel-safe unit tests without shared global state. Other packages (install, sync) define their own System interfaces with operations specific to their needs.

Jump to

Keyboard shortcuts

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