Help us shape the future of Go! Take the 2026 Go Developer Survey

workspace

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package workspace holds fetched files in the lockfile account: one private directory per handle, a random file name, never the source name. Nothing here is shown to the agent but the handle; Info is for the audit.

Index

Constants

View Source
const (
	DefaultMaxBytes   = 1 << 30
	DefaultTTL        = 30 * time.Minute
	DefaultMaxHandles = 64
)

Defaults for zero Config fields.

Variables

View Source
var (
	ErrTooLarge      = errors.New("workspace: file too large")
	ErrExpired       = errors.New("handle_expired")
	ErrUnknownHandle = errors.New("workspace: unknown handle")
	// ErrTooManyHandles refuses a fetch while MaxHandles files are held.
	ErrTooManyHandles = errors.New("workspace: too many handles")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Dir      string
	MaxBytes int64 // all handles together
	TTL      time.Duration
	// MaxHandles bounds the files held (or being fetched) at once.
	MaxHandles int
	Now        func() time.Time
}

type Handle

type Handle string

Handle names a fetched file for the agent: "f_" and 10 base62 characters from crypto/rand, unrelated to anything about the file.

type Info

type Info struct {
	Size   int64
	SHA256 string
}

Info is audit-only data about a fetched file.

type Manager

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

func Open

func Open(c Config) (*Manager, error)

Open prepares the workspace root (0700) and removes everything a previous console left in it.

func (*Manager) Close

func (m *Manager) Close() error

Close deletes every handle's file.

func (*Manager) Create

func (m *Manager) Create(r io.Reader, max int64) (h Handle, info Info, err error)

Create streams r into a new handle, hashing as it copies. It fails with ErrTooLarge, and leaves nothing behind, as soon as the file exceeds max or the space left in the workspace, and with ErrTooManyHandles when MaxHandles files are already held or being fetched. The bytes it may write are reserved before streaming, so concurrent fetches never take more than the workspace budget together; what the file did not use is refunded.

func (*Manager) Dir added in v0.3.0

func (m *Manager) Dir() string

Dir is the workspace root.

func (*Manager) Expire

func (m *Manager) Expire()

Expire deletes the files of every handle past its TTL. The handles keep answering ErrExpired.

func (*Manager) OpenFile

func (m *Manager) OpenFile(h Handle) (*os.File, Info, error)

OpenFile opens a handle's file read-only, from its start.

func (*Manager) Release

func (m *Manager) Release(h Handle) error

Release deletes a handle's file now.

func (*Manager) SetLimits added in v0.3.0

func (m *Manager) SetLimits(maxBytes int64, ttl time.Duration)

SetLimits applies the approved policy's workspace budget and handle TTL to the handles fetched from now on (zero keeps the default). A handle keeps the TTL it was fetched with.

Jump to

Keyboard shortcuts

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