lockfile

package
v1.226.0-test.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLockFile indicates the lock file is malformed or missing required fields.
	ErrInvalidLockFile = errors.New("invalid lock file")

	// ErrLockFileNil indicates the lock file is nil.
	ErrLockFileNil = errors.New("lock file is nil")

	// ErrToolMissingVersion indicates a tool entry has no version entries.
	ErrToolMissingVersion = errors.New("tool missing version")

	// ErrToolNoPlatforms indicates a version entry has no platform entries.
	ErrToolNoPlatforms = errors.New("tool has no platform entries")

	// ErrPlatformNoURL indicates a platform entry is missing the URL field.
	ErrPlatformNoURL = errors.New("platform entry missing URL")

	// ErrPlatformNoChecksum indicates a platform entry is missing the checksum field.
	ErrPlatformNoChecksum = errors.New("platform entry missing checksum")

	// ErrToolEntryNil indicates a tool entry in the lock file is nil.
	ErrToolEntryNil = errors.New("tool entry is nil")

	// ErrVersionEntryNil indicates a version entry in the lock file is nil.
	ErrVersionEntryNil = errors.New("version entry is nil")

	// ErrPlatformEntryNil indicates a platform entry in the lock file is nil.
	ErrPlatformEntryNil = errors.New("platform entry is nil")

	// ErrLegacyLockFileMigrationFailed indicates a pre-v2 lock file's raw bytes could not be
	// re-parsed during the v1-to-v2 migration Load performs (see migrateLegacyTools).
	ErrLegacyLockFileMigrationFailed = errors.New("failed to migrate legacy lock file")
)

Error definitions for the lockfile package.

Functions

func Save

func Save(filePath string, lockFile *LockFile) error

Save writes the lock file to disk, updating metadata fields and creating parent directories if needed. The function updates GeneratedAt, AtmosVersion, and Platform fields in the lockfile metadata to reflect the current environment. It creates the parent directory structure if it doesn't exist (with 0o755 permissions) and writes the lockfile with 0o644 permissions. Returns an error if the lockfile is nil, marshaling fails, directory creation fails, or file writing fails.

func Verify

func Verify(filePath string) error

Verify verifies the integrity and validity of the lock file at the specified path. It loads the lockfile from disk and performs comprehensive validation including: version field checks, metadata validation, and per-tool validation (version presence, platform entries existence, and platform-specific URL/checksum requirements). Returns nil if the lockfile is valid, or an error describing the validation failure (e.g., missing required fields, nil entries, empty values).

Types

type LockFile

type LockFile struct {
	Version  int              `yaml:"version"`
	Tools    map[string]*Tool `yaml:"tools"`
	Metadata LockFileMetadata `yaml:"metadata"`
}

LockFile represents the toolchain.lock.yaml structure.

func Load

func Load(filePath string) (*LockFile, error)

Load loads a lock file from disk.

func New

func New() *LockFile

New creates a new empty lock file.

func (*LockFile) GetOrCreateTool

func (lf *LockFile) GetOrCreateTool(tool string) *Tool

GetOrCreateTool gets or creates a tool entry in the lock file.

func (*LockFile) RemoveTool

func (lf *LockFile) RemoveTool(tool string)

RemoveTool removes a tool (all of its locked versions) from the lock file.

type LockFileMetadata

type LockFileMetadata struct {
	GeneratedAt     string `yaml:"generated_at"` // RFC3339
	AtmosVersion    string `yaml:"atmos_version"`
	Platform        string `yaml:"platform"` // GOOS_GOARCH
	LockFileVersion int    `yaml:"lock_file_version"`
}

LockFileMetadata contains metadata about the lock file.

type PlatformEntry

type PlatformEntry struct {
	URL               string   `yaml:"url"`
	Checksum          string   `yaml:"checksum"`
	Size              int64    `yaml:"size"`
	ChecksumAlgorithm string   `yaml:"checksum_algorithm,omitempty"`
	Verification      []string `yaml:"verification,omitempty"`
}

PlatformEntry represents platform-specific download information.

type Tool

type Tool struct {
	Versions map[string]*VersionEntry `yaml:"versions"`
}

Tool represents a locked tool, keyed by owner/repo. Versions holds one entry per pinned version of this tool (keyed by version string) -- a .tool-versions line can legitimately pin more than one version of the same tool (e.g. "yq 4.45.1 4.50.1"), so each version's checksum data must be tracked independently rather than overwriting a single flat entry.

func (*Tool) GetOrCreateVersion

func (t *Tool) GetOrCreateVersion(version string) *VersionEntry

GetOrCreateVersion gets or creates the entry for a specific version of this tool. Locking or installing a second version of an already-locked tool must not disturb any other version's recorded data -- each version's checksum/platform data lives in its own entry.

func (*Tool) RemoveVersion

func (t *Tool) RemoveVersion(version string)

RemoveVersion removes a single locked version of this tool.

type VersionEntry

type VersionEntry struct {
	Source      string                    `yaml:"source,omitempty"`
	Platforms   map[string]*PlatformEntry `yaml:"platforms"`
	BinaryName  string                    `yaml:"binary_name,omitempty"`
	InstalledAt string                    `yaml:"installed_at"` // RFC3339
}

VersionEntry represents a single locked version of a tool.

Jump to

Keyboard shortcuts

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