store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 18 Imported by: 0 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 store is the SDK's default state file (the reference's storage.ts, storage-fs.ts; sdk-contract.md section 6): where it lives, and how it is read and written so that neither a crash nor a busy disk ever costs a customer their licence.

Index

Constants

View Source
const (
	KeepCorrupt    = 3
	StaleTemp      = 60 * time.Second
	UpdateAttempts = 5
)

What the storage keeps, and how long it tries.

View Source
const LockSuffix = ".lock"

LockSuffix names the lock file beside the state file (<file>.lock): empty, and kept, as every process that saves the state locks the same file.

Variables

View Source
var ErrConflict = errors.New("keygrant: the state was saved by another process")

ErrConflict is a save that found the state changed by another process on every try.

Functions

func DefaultPath

func DefaultPath(product string, sys System) string

DefaultPath is where the default storage keeps a product's state (defaultStoragePath): a folder of this user's on THIS machine, never the working directory and never one that roams:

  • Windows: %LOCALAPPDATA%\KeyGrant, else ~\AppData\Local\KeyGrant
  • macOS: ~/Library/Application Support/KeyGrant
  • anything else: $XDG_CONFIG_HOME/keygrant, else ~/.config/keygrant

An empty or relative variable is taken as unset.

func IsAbs

func IsAbs(platform, p string) bool

IsAbs is whether p is absolute on platform as DefaultPath reads one: Node's path.win32.isAbsolute on Windows, path.posix.isAbsolute elsewhere.

Types

type File

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

File is the state file at a path.

func New

func New(path string) *File

New is the state file at path.

func (*File) Path

func (f *File) Path() string

Path is where the file is.

func (*File) Read

func (f *File) Read(readOnly bool) (state.State, error)

Read is the stored state, or nil for none. readOnly reads and writes nothing else: no set-aside.

func (*File) Update

func (f *File) Update(merge func(latest state.State) (state.State, error)) error

Update saves merge of the state as stored at the moment of saving, stamped with the next revision; when another process saved since it was read, merged again onto that newer state, UpdateAttempts times at most. A merge that fails writes nothing, and its error is Update's.

func (*File) Write

func (f *File) Write(s state.State) error

Write puts a whole state in place.

type System

type System struct {
	Platform string
	Home     string
	Getenv   func(string) string
}

System is what the default path is read from: the platform (Node's name), the home folder and the environment.

Jump to

Keyboard shortcuts

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