cachedir

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 4 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 cachedir owns udf's derived-data directory: a per-user directory inside the operating system's temporary directory, <temp>/ejfkdev/udf.

Everything in it is derived from an input file and can be deleted at any time — a missing entry is rebuilt by the next command that needs it (an image archive index costs one pass, a listing or a metadata file is milliseconds). Keeping it in the temporary directory means the operating system reclaims it on its own terms: macOS purges entries unused for three days, Linux clears /tmp at boot or after ten days. Where the OS does nothing — Windows leaves %TEMP% alone — udf prunes entries itself, on the first write of a run, so the directory cannot grow without bound anywhere.

Layout:

<dir>/*.json      small derived values: input class, image metadata,
                  archive listings, disk metadata, image summaries
<dir>/idx/*.idx   random-access indexes for large archives
<dir>/tmp/        per-run scratch (disks decompressed from an OVA/VMA/VM
                  export); removed by the run that made it, and pruned when
                  a run is interrupted

The location can be overridden with UDF_CACHE_DIR, which is also how tests keep their cache out of the real one.

Index

Constants

View Source
const (
	// Env is the environment variable that overrides the directory.
	Env = "UDF_CACHE_DIR"

	// CachePruneAge is how long a derived value (a listing, a metadata file, an
	// index) survives without being rewritten. It is deliberately longer than
	// the shortest OS purge (three days on macOS) so that pruning only matters
	// where the OS does not clean up at all.
	CachePruneAge = 7 * 24 * time.Hour

	// ScratchPruneAge is how long a scratch directory from an interrupted run
	// survives. Runs remove their own scratch, so anything this old was left
	// behind by a crash or a kill.
	ScratchPruneAge = 24 * time.Hour
)

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir returns the directory holding udf's derived data. It does not have to exist yet.

func Ensure

func Ensure() string

Ensure creates the directory (and its index subdirectory) and, once per process, prunes entries earlier runs left behind. It returns the directory path, or "" when it cannot be created. The path is read from the environment on every call, so a caller that overrides the location gets that location.

func IndexDir

func IndexDir() string

IndexDir returns the directory holding random-access indexes.

func Prune

func Prune(now time.Time)

Prune removes derived values and scratch left behind by earlier runs. It is best effort: anything it cannot read or remove is ignored, since every entry is expendable.

func ScratchDir

func ScratchDir() string

ScratchDir returns the directory holding per-run scratch files.

func Temp

func Temp(pattern string) (string, error)

Temp creates a scratch directory for this run, under the temporary area of the cache directory.

func TempFile

func TempFile(pattern string) (*os.File, error)

TempFile creates a scratch file for this run, under the temporary area of the cache directory. The pattern may carry a suffix, as in "disk-*.raw".

Types

This section is empty.

Jump to

Keyboard shortcuts

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