contentdirs

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package contentdirs keeps content-addressed directories under a shared config root: one directory per build of an embedded bundle, named <base>-<hash>. PiG builds that share a config root (two installed versions, or stock PiG beside a Piglet Binary) each read and write only their own directory, so no build rewrites another's files or strands its extension builds.

A directory records its last use in its modification time. Eviction keeps the most recently used directories and never removes the caller's own, so a build that is still in use keeps its files. A process that reads a directory for as long as it lives, such as a session whose prompt names the pages of its documentation bundle, [Hold]s it: another build's eviction leaves a held directory, whatever its modification time.

Index

Constants

View Source
const (
	// Keep is how many directories of one base survive eviction, the caller's own included. It covers a stock install, a Piglet Binary and an
	// upgrade in progress sharing one config root; each directory holds a few MiB.
	Keep = 4
)

Variables

This section is empty.

Functions

func Dirs

func Dirs(parent, base string) ([]string, error)

Dirs returns the paths of the directories in parent named <base>-<16 hex digits>, most recently used first.

func Evict

func Evict(parent, base, own string) ([]string, error)

Evict removes base's directories in parent beyond the Keep most recently used, never own, and returns the removed paths. A directory some process [Hold]s stays, and does not count among the kept ones. The caller holds whatever lock excludes readers of those directories.

func Hold

func Hold(dir string) (release func())

Hold records that this process reads dir until the returned release runs, which a process that holds a directory for as long as it lives never calls: Evict leaves a held directory, in this process and in every other, whatever its use time. The operating system releases the lease with the process, so a holder that dies leaves nothing behind but a lease file the next eviction removes with the directory. A directory with no lease file has no holder, so a build that never holds one (an older PiG) is evicted as before. Hold is best-effort, like Touch: a parent this user cannot write leaves the directory evictable, and release is then a no-op. Holding a directory twice holds it once.

func Name

func Name(base, hash string) (string, error)

Name is the directory name of base's bundle with content hash, which must be at least 16 hex digits; only the first 16 are used.

func Touch

func Touch(dir string)

Touch records that dir was used now, unless it was recorded within the last hour. It is best-effort: a directory this user cannot write keeps its old time, which only makes it an earlier eviction candidate.

Types

This section is empty.

Jump to

Keyboard shortcuts

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