store

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package store defines a narrow, content-addressed interface for storing individual weight files on the local machine.

The store knows only digests. Filenames, layer membership, and registry URIs are Manager-level concerns. Keeping the surface small is what makes the store swappable — a future containerd-backed store can drop in behind the same interface.

Digests are "sha256:<hex>"; v1 implementations may reject other algorithms. Missing digests surface as errors wrapping fs.ErrNotExist.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Digest string
	Size   int64
}

FileInfo describes one stored file.

type FileStore

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

FileStore is a Store backed by a directory on the local filesystem. Files are stored content-addressed under <root>/files/sha256/<ab>/<hex>.

FileStore is safe for concurrent use by multiple goroutines and processes: PutFile writes to a temporary file and atomically renames; reads are stateless.

func NewFileStore

func NewFileStore(dir string) (*FileStore, error)

NewFileStore returns a FileStore rooted at dir. The root and the files/sha256/ subtree are created if they don't exist.

func OpenDefault

func OpenDefault() (*FileStore, error)

OpenDefault opens the per-user weights FileStore at the path returned by paths.WeightsStoreDir. Use this whenever you'd otherwise pair WeightsStoreDir + NewFileStore — same intent, less boilerplate, one error message style across call sites.

func (*FileStore) Delete

func (s *FileStore) Delete(_ context.Context, digest string) error

Delete removes the file at digest. Missing digests are not an error.

func (*FileStore) Exists

func (s *FileStore) Exists(_ context.Context, digest string) (bool, error)

Exists reports whether a file with the given digest is in the store.

func (*FileStore) List

func (s *FileStore) List(ctx context.Context) iter.Seq2[FileInfo, error]

List walks files/sha256/ and yields one FileInfo per entry. Stray files (stale temp files from interrupted writes, anything whose name isn't a 64-char hex digest) are skipped.

func (*FileStore) Path

func (s *FileStore) Path(ctx context.Context, digest string) (string, error)

Path returns the on-disk path for the file at digest, or an error wrapping fs.ErrNotExist if the digest is not in the store.

func (*FileStore) PutFile

func (s *FileStore) PutFile(ctx context.Context, expectedDigest string, expectedSize int64, r io.Reader) error

PutFile writes r to the store under expectedDigest, verifying the computed digest as it streams.

Idempotency: if the digest is already present, r is drained to io.Discard and nil is returned. This matters because Pull streams a whole layer tar and may encounter files already stored from a previous pull — we need those to succeed without desyncing the tar.

func (*FileStore) Root

func (s *FileStore) Root() string

Root returns the on-disk root of the store.

type Store

type Store interface {
	// Exists reports whether a file with the given digest is in the store.
	// A nil error with false is the ordinary "not present" result.
	Exists(ctx context.Context, digest string) (bool, error)

	// PutFile stores r under expectedDigest, hash-verifying as it streams.
	// A digest mismatch leaves the store unchanged.
	//
	// PutFile is idempotent: if the digest is already present, the
	// reader is drained to io.Discard and nil is returned. This lets
	// callers loop over tar entries without branching on Exists first.
	//
	// size is advisory.
	PutFile(ctx context.Context, expectedDigest string, size int64, r io.Reader) error

	// Path returns an on-disk path for the file, suitable for hardlinking.
	// The file MUST be treated as read-only. Not every backend can
	// satisfy this; such backends return an error.
	Path(ctx context.Context, digest string) (string, error)

	// List iterates every file in the store. Walk errors surface as a
	// final (zero, err) pair before the iterator terminates.
	List(ctx context.Context) iter.Seq2[FileInfo, error]

	// Delete removes the file at digest. Missing digests are not an error.
	Delete(ctx context.Context, digest string) error
}

Store is a content-addressed store of individual weight files.

Every method takes a context; implementations SHOULD honor cancellation where it makes sense. Missing digests on Path surface as errors wrapping fs.ErrNotExist.

Jump to

Keyboard shortcuts

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