placement

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 12 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 placement decides where zip items may be written: the write roots compiled into the build, and the checks every placement path passes before sofcat writes under it. It is portable and holds no service state, so the service and a per-user helper share it.

Index

Constants

This section is empty.

Variables

View Source
var ErrRefused = errors.New("placement refused")

ErrRefused wraps every refusal of a placement path. The item then fails with report.CodePlacementRefused.

Functions

func BinaryDirs

func BinaryDirs(goos string) []string

BinaryDirs returns the directories holding sofcat's binaries: the running executable's, and on macOS /Library/Application Support/<Name>/bin.

func HostOS

func HostOS() string

HostOS is the harness OS key of the running system, or runtime.GOOS when harnesses.yaml has no key for it (no variant then matches).

Types

type Guard

type Guard struct {
	// GOOS picks the harness paths and roots: harness.Darwin or
	// harness.Windows. Paths compare case-insensitively for both.
	GOOS  string
	Roots Roots
	// DataDir is sofcat's data directory; nothing is placed inside it.
	DataDir string
	// BinaryDirs hold sofcat's executables; no placement may be inside one,
	// equal one, or contain one.
	BinaryDirs []string
	// Vars holds values only the caller knows, such as USERPROFILE for a
	// user-scope placement. The service has no user and leaves it empty.
	Vars map[string]string
}

Guard checks placement paths against the write roots and the directories sofcat must never write into.

func MachineGuard

func MachineGuard(dataDir string) Guard

MachineGuard is the service's guard: this OS, the compiled-in roots, the data directory, and the directories holding this build's binaries.

func (Guard) Check

func (g Guard) Check(path, scope string) (string, error)

Check resolves the symlinks of an absolute path and refuses it when the result is outside every write root for scope on g.GOOS, inside the data directory, or inside, equal to or containing a binary directory. It returns the resolved path.

func (Guard) Resolve

func (g Guard) Resolve(raw, scope string) (string, error)

Resolve expands a harness path for scope, resolves its symlinks and checks it (see Check). It returns the resolved path.

type Roots

type Roots struct {
	// Darwin and Windows are the machine-scope roots on each OS. Windows
	// roots may use ${ProgramFiles} and ${ProgramData}.
	Darwin  []string `yaml:"darwin"`
	Windows []string `yaml:"windows"`
	// WindowsUser are the user-scope roots on Windows, relative to the user's
	// profile: either starting with ${USERPROFILE} or a relative path.
	WindowsUser []string `yaml:"windows_user"`
}

Roots are the directories a build may place trees under. They come from the build only (a brand's write-roots.yaml, or the stock defaults), never from runtime config or the harness table.

func Compiled

func Compiled() Roots

Compiled returns the roots compiled into this build.

func ParseRoots

func ParseRoots(data []byte) (Roots, error)

ParseRoots decodes write-roots.yaml, rejecting unknown fields.

func StockRoots

func StockRoots() Roots

StockRoots are the roots of a build without write-roots.yaml: the directory holding its config and Data for machine scope (${ProgramData}\<Name> on Windows, /Library/Application Support/<Name> on macOS), and no user roots. Data itself and the executables' directory stay refused (Guard.Check).

func (Roots) For

func (r Roots) For(goos, scope string) []string

For returns the roots for scope on goos.

Jump to

Keyboard shortcuts

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