disk

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package disk keeps patty's clone cache within a byte budget and off the last free gigabytes of the drive.

Index

Constants

View Source
const (
	KiB int64 = 1 << 10
	MiB int64 = 1 << 20
	GiB int64 = 1 << 30
	TiB int64 = 1 << 40
)

Variables

View Source
var ErrBudget = errors.New("disk budget")

ErrBudget is returned when a repository does not fit the disk budget.

Functions

func FormatSize

func FormatSize(n int64) string

FormatSize renders bytes with a binary unit and one decimal.

func Free

func Free(path string) (int64, error)

Free returns the bytes available to an unprivileged user on the filesystem holding path.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize parses a human size such as "10G", "512MiB", "1.5T" or a plain number of bytes.

func Touch

func Touch(path string)

Touch records use of a mirror so it is evicted last.

Types

type Cache

type Cache struct {
	Dir string
	// MaxBytes caps the total size of all mirrors in the cache.
	MaxBytes int64
	// MinFree is the free space that must remain on the drive after a clone.
	MinFree int64
	// contains filtered or unexported fields
}

Cache is the directory patty mirrors repositories into. Mirrors live at <Dir>/<host>/<owner>/<repo>.git.

func (*Cache) Admit

func (c *Cache) Admit(path string, estimate int64) error

Admit makes room for a repository of the estimated size and marks its path as in use so concurrent evictions leave it alone. It evicts the least recently used mirrors first and fails with ErrBudget when the repository still would not fit the budget or would push the drive below MinFree. Call Release when done with the path.

func (*Cache) Clean

func (c *Cache) Clean() (int, int64, error)

Clean removes every mirror from the cache.

func (*Cache) Entries

func (c *Cache) Entries() ([]Entry, error)

Entries lists the mirrors in the cache, least recently used first.

func (*Cache) Release

func (c *Cache) Release(path string)

Release marks a path as no longer in use.

func (*Cache) RepoPath

func (c *Cache) RepoPath(host, owner, name string) string

RepoPath returns where the mirror of a repository lives.

func (*Cache) Usage

func (c *Cache) Usage() int64

Usage returns the total size of the cache.

type Entry

type Entry struct {
	Path    string
	Size    int64
	ModTime time.Time
}

Entry is one mirror in the cache.

Jump to

Keyboard shortcuts

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